1
##########################################################################
3
# Panel to provide d.3d type interface for manually entering position
6
# Original author unknown.
9
# Major update of GUI Nov 2006, Michael Barton, Arizona State University
11
##########################################################################
12
# COPYRIGHT: (C) 2006 by Michael Barton and the GRASS Development Team
14
# This program is free software under the GNU General Public
15
# License (>=v2). Read the file COPYING that comes with GRASS
18
##########################################################################
20
proc mkposPanel { BASE } {
21
global Nv_ bearing_calc
26
# Initialize panel info
27
if [catch {set Nv_($BASE)}] {
28
set panel [St_create {window name size priority} $BASE [G_msg "Position"] 1 5]
33
frame $BASE -relief flat -borderwidth 0
34
Nv_mkPanelname $BASE [G_msg "Position Panel"]
36
#################################
38
set tmp1 [frame $BASE.top1]
39
set col1 [frame $BASE.top1.col1]
40
set col2 [frame $BASE.top1.col2]
41
set col3 [frame $BASE.top1.col3]
42
set col4 [frame $BASE.top1.col4]
44
set c1r1 [label $col1.1 -text " "]
45
set c1r2 [label $col1.2 -text [G_msg "From (eye):"]]
46
set c1r3 [label $col1.3 -text [G_msg "To (surface):"]]
47
set c1r4 [label $col1.4 -text " "]
48
set c1r5 [label $col1.5 -text " "]
49
set c1r6 [label $col1.6 -text [G_msg "Range/bearing:"]]
50
pack $c1r1 $c1r2 $c1r3 $c1r4 $c1r5 $c1r6 -side top -anchor e
52
set c2r1 [label $col2.1 -text [G_msg "East"] -fg black -font $nviztxtfont]
53
set c2r2 [entry $col2.2 -width 10 -textvariable Nv_(east1) -bg white]
54
set c2r3 [entry $col2.3 -width 10 -textvariable Nv_(east2) -bg white]
55
set c2r4 [label $col2.4 -text " "]
56
set c2r5 [label $col2.5 -text [G_msg "Range"] -fg black -font $nviztxtfont]
57
set c2r6 [entry $col2.6 -width 10 -textvariable Nv_(range) -bg white]
58
pack $c2r1 $c2r2 $c2r3 $c2r4 $c2r5 $c2r6 -side top
60
set c3r1 [label $col3.1 -text [G_msg "North"] -fg black -font $nviztxtfont]
61
set c3r2 [entry $col3.2 -width 10 -textvariable Nv_(north1) -bg white]
62
set c3r3 [entry $col3.3 -width 10 -textvariable Nv_(north2) -bg white]
63
set c3r4 [label $col3.4 -text " "]
64
set c3r5 [label $col3.5 -text [G_msg "Bearing"] -fg black -font $nviztxtfont]
65
set c3r6 [entry $col3.6 -width 10 -textvariable Nv_(bearing) -bg white]
66
pack $c3r1 $c3r2 $c3r3 $c3r4 $c3r5 $c3r6 -side top
68
set c4r1 [label $col4.1 -text [G_msg "Height"] -fg black -font $nviztxtfont]
69
set c4r2 [entry $col4.2 -width 8 -textvariable Nv_(ht1) -bg white]
70
set c4r3 [entry $col4.3 -width 8 -textvariable Nv_(ht2) -bg white]
71
set c4r4 [label $col4.4 -text " "]
72
set c4r5 [label $col4.5 -text [G_msg "Elev"] -fg black -font $nviztxtfont]
73
set c4r6 [entry $col4.6 -width 8 -textvariable Nv_(elev) -bg white]
74
pack $c4r1 $c4r2 $c4r3 $c4r4 $c4r5 $c4r6 -side top
76
pack $col1 $col2 $col3 $col4 -side left -padx 3
77
pack $tmp1 -side top -pady 4
79
#################################
81
# Mode setting radiobuttons
82
set tmp3 [frame $BASE.top3]
83
radiobutton $tmp3.r1 -text [G_msg "Eye to surface"] -variable "bearing_calc" -value "1" -command "catch {show_bearing}"
84
radiobutton $tmp3.r2 -text [G_msg "Surface to eye"] -variable "bearing_calc" -value "2" -command "catch {show_bearing}"
85
button $tmp3.b1 -text [G_msg "Calculate"] -command "catch {calc_position $bearing_calc};catch {show_bearing}" -bd 1
86
pack $tmp3.r1 $tmp3.r2 $tmp3.b1 -side left -padx 3 -expand 1 -fill x
88
pack $tmp3 -side top -fill x -expand 1 -pady 4
91
#################################
93
set tmp4 [frame $BASE.top4]
95
button $tmp4.b1 -text [G_msg "Refresh"] -bd 1 \
96
-command {set from_loc [Nget_real_position 1]
97
set to_loc [Nget_real_position 2]
98
set Nv_(east1) [format_number [lindex $from_loc 0]]
99
set Nv_(north1) [format_number [lindex $from_loc 1]]
100
set Nv_(ht1) [format_number [lindex $from_loc 2]]
102
set Nv_(east2) [format_number [lindex $to_loc 0]]
103
set Nv_(north2) [format_number [lindex $to_loc 1]]
104
set Nv_(ht2) [format_number [lindex $to_loc 2]]
109
button $tmp4.b2 -text [G_msg "Apply"] -bd 1 \
112
Nset_focus_real $Nv_(east2) $Nv_(north2) $Nv_(ht2)
114
Nmove_to_real $Nv_(east1) $Nv_(north1) $Nv_(ht1)
116
Nv_setEntry $Nv_(main_BASE).midf.height.f.entry $Nv_(ht1)
117
catch {Nv_floatscaleCallback $Nv_(main_BASE).midf.height e 2 null $Nv_(ht1)}
125
button $tmp4.b3 -text [G_msg "Close"] -command "Nv_closePanel $BASE" -bd 1
127
pack $tmp4.b1 $tmp4.b2 -side left
128
pack $tmp4.b3 -side right
130
pack $tmp4 -side top -fill x -expand 1 -padx 3 -pady 4
139
########################################
140
# Proc format_number to format float to reasonable
141
# number of decimals -- max = 3
142
proc format_number {n} {
146
if {$n == [expr int($num_tmp)] } {
147
set val [format %.0f $n]
148
} elseif { [expr $n*10.] == [expr int($num_tmp*10.)] } {
149
set val [format %.1f $n]
150
} elseif { [expr $n*100.] == [expr int($num_tmp*100.)] } {
151
set val [format %.2f $n]
153
set val [format %.3f $n]
160
########################################
161
# Proc calc_position to coordinate from
162
# rangle bearing and elev.
163
proc calc_position {flag} {
166
set RAD 0.0174532925199432958
168
#convert range to 2D range
169
set range_xy [expr (cos($Nv_(elev)*$RAD) * $Nv_(range))]
170
set zz [expr (sin($Nv_(elev)*$RAD) * $Nv_(range))]
171
set xx [expr (sin($Nv_(bearing)*$RAD) * $range_xy)]
172
set yy [expr (cos($Nv_(bearing)*$RAD) * $range_xy)]
175
#Calculate new surface center from eye position
176
set Nv_(east2) [format_number [expr $Nv_(east1) + $xx]]
177
set Nv_(north2) [format_number [expr $Nv_(north1) + $yy]]
179
set Nv_(ht2) [format_number [expr $Nv_(ht1) - $zz]]
181
#Calculate new eye position from surface center coord
182
set Nv_(east1) [format_number [expr $Nv_(east2) + $xx]]
183
set Nv_(north1) [format_number [expr $Nv_(north2) + $yy]]
185
set Nv_(ht1) [format_number [expr $Nv_(ht2) + $zz]]
189
########################################
190
# Proc show_bearing to calculate and show
191
# current range and bearing
192
proc show_bearing {} {
193
global Nv_ bearing_calc
195
set RAD 0.0174532925199432958
197
if {$bearing_calc == 1} {
198
set xx [expr $Nv_(east2) - $Nv_(east1)]
199
set yy [expr $Nv_(north2) - $Nv_(north1)]
200
set zz [expr $Nv_(ht2) - $Nv_(ht1)]
202
set xx [expr $Nv_(east1) - $Nv_(east2)]
203
set yy [expr $Nv_(north1) - $Nv_(north2)]
204
set zz [expr $Nv_(ht1) - $Nv_(ht2)]
207
set Nv_(range) [format_number [expr sqrt( ($xx*$xx) + ($yy*$yy) + ($zz*$zz) )]]
208
set Nv_(elev) [format_number [expr sinh(abs($zz)/$Nv_(range))/$RAD ]]
210
if {$yy == 0. && $xx == 0.} {
212
} elseif {$yy == 0.} {
214
} elseif {$xx == 0.} {
217
set bear_tmp [expr atan(abs($xx)/abs($yy)) / $RAD]
219
if {$xx >= 0. && $yy > 0.} {
220
set Nv_(bearing) [format_number $bear_tmp]
221
} elseif {$xx > 0. && $yy <= 0.} {
222
set Nv_(bearing) [format_number [expr 180. - $bear_tmp]]
223
} elseif {$xx <= 0. && $yy < 0.} {
224
set Nv_(bearing) [format_number [expr $bear_tmp + 180.]]
225
} elseif {$xx < 0. && $yy >= 0.} {
226
set Nv_(bearing) [format_number [expr 360. - $bear_tmp]]