~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to visualization/nviz/scripts/panel_pos.tcl

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
##########################################################################
2
 
3
 
# Panel to provide d.3d type interface for manually entering position 
4
 
#       for view.
5
 
6
 
# Original author unknown.
7
 
#
8
 
#
9
 
# Major update of GUI Nov 2006, Michael Barton, Arizona State University
10
 
#
11
 
##########################################################################
12
 
# COPYRIGHT:    (C) 2006 by Michael Barton and the GRASS Development Team
13
 
#
14
 
#               This program is free software under the GNU General Public
15
 
#               License (>=v2). Read the file COPYING that comes with GRASS
16
 
#               for details.
17
 
#
18
 
##########################################################################
19
 
 
20
 
proc mkposPanel { BASE } {
21
 
    global Nv_ bearing_calc
22
 
    global nviztxtfont
23
 
    
24
 
    catch {destroy $BASE}
25
 
    
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]
29
 
    } else {
30
 
        set panel $Nv_($BASE)
31
 
    }
32
 
    
33
 
    frame $BASE -relief flat -borderwidth 0
34
 
    Nv_mkPanelname $BASE [G_msg "Position Panel"]
35
 
 
36
 
#################################
37
 
# Positioning menus    
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]
43
 
    
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
51
 
        
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
59
 
        
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
67
 
        
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
75
 
 
76
 
        pack $col1 $col2 $col3 $col4 -side left -padx 3
77
 
        pack $tmp1 -side top -pady 4
78
 
    
79
 
#################################
80
 
   
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
87
 
    
88
 
    pack $tmp3 -side top -fill x -expand 1 -pady 4
89
 
 
90
 
    
91
 
#################################
92
 
# Buttons menu       
93
 
    set tmp4 [frame $BASE.top4]
94
 
    
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]]
101
 
                        
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]]
105
 
        
106
 
                        show_bearing
107
 
                        }
108
 
    
109
 
    button $tmp4.b2 -text [G_msg "Apply"] -bd 1 \
110
 
        -command {
111
 
                        #Set To coords
112
 
                        Nset_focus_real $Nv_(east2) $Nv_(north2) $Nv_(ht2)              
113
 
                        #Set From coords
114
 
                        Nmove_to_real $Nv_(east1) $Nv_(north1) $Nv_(ht1)
115
 
                        #reset height
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)}
118
 
                        #reset XY canvas
119
 
                        change_display 1
120
 
                
121
 
                        #Nquick_draw
122
 
                        Ndraw_all
123
 
                        }
124
 
    
125
 
    button $tmp4.b3 -text [G_msg "Close"] -command "Nv_closePanel $BASE" -bd 1
126
 
        
127
 
    pack $tmp4.b1 $tmp4.b2 -side left 
128
 
    pack $tmp4.b3 -side right
129
 
 
130
 
    pack $tmp4 -side top -fill x -expand 1 -padx 3 -pady 4
131
 
    
132
 
    #set radiobutton
133
 
    set bearing_calc 1
134
 
        
135
 
return $panel
136
 
   
137
 
}
138
 
 
139
 
########################################
140
 
# Proc format_number to format float to reasonable
141
 
# number of decimals -- max = 3
142
 
proc format_number {n} {
143
 
 
144
 
set num_tmp $n
145
 
 
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]
152
 
} else {
153
 
        set val [format %.3f $n]
154
 
}
155
 
 
156
 
return $val
157
 
 
158
 
}
159
 
 
160
 
########################################
161
 
# Proc calc_position to coordinate from
162
 
# rangle bearing and elev.
163
 
proc calc_position {flag} {
164
 
    global Nv_
165
 
    
166
 
    set RAD 0.0174532925199432958
167
 
    
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)]
173
 
    
174
 
    if {$flag == 1} {
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]]
178
 
        #always look down
179
 
        set Nv_(ht2) [format_number [expr $Nv_(ht1) - $zz]]
180
 
    } else {
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]]
184
 
        #always look up
185
 
        set Nv_(ht1) [format_number [expr $Nv_(ht2) + $zz]]
186
 
    }
187
 
}
188
 
 
189
 
########################################
190
 
# Proc show_bearing to calculate and show
191
 
# current range and bearing
192
 
proc show_bearing {} {
193
 
    global Nv_ bearing_calc
194
 
 
195
 
    set RAD 0.0174532925199432958
196
 
 
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)]
201
 
    } else {
202
 
            set xx [expr $Nv_(east1) - $Nv_(east2)]
203
 
            set yy [expr $Nv_(north1) - $Nv_(north2)]
204
 
            set zz [expr $Nv_(ht1) - $Nv_(ht2)]
205
 
    }
206
 
    
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 ]]
209
 
    
210
 
    if {$yy == 0. && $xx == 0.} {
211
 
            set bear_tmp 0.
212
 
    } elseif {$yy == 0.} {
213
 
            set bear_tmp 90.
214
 
    } elseif {$xx == 0.} {
215
 
            set bear_tmp 0.
216
 
    } else {
217
 
            set bear_tmp [expr atan(abs($xx)/abs($yy)) / $RAD]
218
 
    }
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]]
227
 
    } else {
228
 
            set Nv_(bearing) 999
229
 
    }
230
 
        
231
 
}