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

« back to all changes in this revision

Viewing changes to visualization/nviz/scripts/panel_rquery.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
 
# Routines for raster querying for NVIZ
4
 
5
 
# Original author unknown.
6
 
# Probably U.S. Army Construction Engineering Research Laboratory
7
 
#
8
 
# Major update of GUI Nov 2006, Michael Barton, Arizona State University
9
 
#
10
 
##########################################################################
11
 
# COPYRIGHT:    (C) 2006 by Michael Barton and the GRASS Development Team
12
 
#
13
 
#               This program is free software under the GNU General Public
14
 
#               License (>=v2). Read the file COPYING that comes with GRASS
15
 
#               for details.
16
 
#
17
 
##########################################################################
18
 
# Default Priority for this panel
19
 
20
 
# priority is from 0 to 10
21
 
#  the lower the number, the quicker it will be bumped
22
 
#  10 cannot be bumped
23
 
#  Panels will be loaded by the greater of 5 or their current priority
24
 
############################################################################
25
 
# procedure to make main control area
26
 
 
27
 
global WhatsHere Nv
28
 
set WhatsHere(first) 1
29
 
 
30
 
# Globals to track what's here attributes
31
 
set Nv_(what_mapname)            1
32
 
set Nv_(what_easting)            1
33
 
set Nv_(what_northing)           1
34
 
set Nv_(what_elevation)          1
35
 
set Nv_(what_colorcat)           1
36
 
set Nv_(what_xydiff)             0
37
 
set Nv_(what_xyzdiff)            0
38
 
set Nv_(what_surfdist)           1
39
 
set Nv_(what_exagsurfdist)       1
40
 
set Nv_(what_pipe)               0
41
 
set Nv_(what_pipe_text)          [G_msg "Send results to: (no file selected)"]
42
 
 
43
 
proc mkqueryPanel { BASE } {
44
 
    
45
 
    global WhatsHere
46
 
    global Nv_
47
 
    
48
 
    catch {destroy $BASE}
49
 
    
50
 
    # Initialize panel info
51
 
    if [catch {set Nv_($BASE)}] {
52
 
        set panel [St_create {window name size priority} $BASE [G_msg "Raster Query"] 1 5]
53
 
    } else {
54
 
        set panel $Nv_($BASE)
55
 
    }
56
 
    
57
 
    frame $BASE  -relief flat -borderwidth 0
58
 
    Nv_mkPanelname $BASE [G_msg "Raster Query Panel"]
59
 
    
60
 
    # Create frame, buttons, and attributes menu
61
 
    frame $BASE.bf -relief flat -borderwidth 0
62
 
    checkbutton $BASE.bf.what -text [G_msg "query on/off"] \
63
 
                -command whats_here -variable WhatsHere(on)
64
 
    Button $BASE.bf.separate -text [G_msg "Reset"] -command do_separate \
65
 
        -bd 1 -width 6 -helptext [G_msg "Reset most recent query"]
66
 
    Button $BASE.bf.clear -text [G_msg "Clear"] -command clear_text \
67
 
        -bd 1 -width 6 -helptext [G_msg "Clear all queries"]
68
 
    menubutton $BASE.bf.atts -text [G_msg "Attributes"] \
69
 
        -menu $BASE.bf.atts.m -relief raised \
70
 
        -indicatoron 1 -bd 1
71
 
    menu $BASE.bf.atts.m
72
 
    pack $BASE.bf.clear $BASE.bf.separate -side right -expand 0 -fill none
73
 
    pack $BASE.bf.what -side left -expand 0 -fill x
74
 
    pack $BASE.bf.atts -side left -expand 0 -fill x -padx 3
75
 
    
76
 
    # Add menu entries for menu
77
 
    set theMenu $BASE.bf.atts.m
78
 
    foreach i [list [list [G_msg "Map name"] "mapname" 0] [list [G_msg "Easting"] "easting" 0] [list [G_msg "Northing"] "northing" 0] [list [G_msg "Elevation"] "elevation" 1] [list [G_msg "Category of color map"] "colorcat" 0] [list [G_msg "XY dist from prev"] "xydiff" 0] [list [G_msg "XYZ dist from prev"] "xyzdiff" 2] [list [G_msg "Dist along surface"] "surfdist" 0] [list [G_msg "Dist along exag surface"] "exagsurfdist" 5]] {
79
 
 
80
 
                $theMenu add checkbutton -label [lindex $i 0] -underline [lindex $i 2] \
81
 
                        -offvalue 0 -onvalue 1 -variable Nv_(what_[lindex $i 1])
82
 
    }
83
 
 
84
 
    pack $BASE.bf -side top -fill x -padx 3 -pady 5
85
 
    
86
 
    # frrame for close button and saving output to a file
87
 
    frame $BASE.cf
88
 
    Button $BASE.cf.close -text [G_msg "Close"] -command "Nv_closePanel $BASE" \
89
 
        -bd 1 -width 6
90
 
    
91
 
    Button $BASE.cf.output -textvariable Nv_(what_pipe_text) \
92
 
                -command "whats_pipe_bind $BASE" -bd 1 \
93
 
                -helptext [G_msg "Select file to receive all future query results"]
94
 
 
95
 
    pack $BASE.cf.close $BASE.cf.output -side right -expand 0 -fill none
96
 
    pack $BASE.cf.output -side left
97
 
    pack $BASE.cf -side bottom -fill x -padx 3 -pady 5
98
 
    
99
 
    text $BASE.text -wrap word -relief sunken -bd 2 \
100
 
                -yscrollcommand "$BASE.yscroll set"  \
101
 
                -width 40 -height 10
102
 
    
103
 
    set WhatsHere(text) $BASE.text
104
 
    
105
 
    # scrollbar $BASE.xscroll -orient horizontal -relief flat 
106
 
    # -activebackground gray80 -command "$BASE.text view"
107
 
    
108
 
    scrollbar $BASE.yscroll -orient vertical -relief flat \
109
 
                -command "$BASE.text yview" -activebackground gray80 
110
 
    
111
 
    pack $BASE.yscroll -side right -fill y
112
 
    # pack $BASE.xscroll -side bottom -fill x
113
 
    pack $BASE.text -expand yes -fill both
114
 
    
115
 
    return $panel
116
 
}
117
 
 
118
 
proc whats_pipe_bind {BASE} {
119
 
    global Nv_
120
 
 
121
 
    # Allow the user to set a file for piping the output 
122
 
    set new_file [create_file_browser .whats_file 1 0]
123
 
    if {$new_file == -1} then return
124
 
 
125
 
    set Nv_(what_pipe) $new_file
126
 
    set Nv_(what_pipe_text) [format [G_msg "Send results to: %s"] $new_file]
127
 
}
128
 
 
129
 
proc whats_here {} {
130
 
    global WhatsHere Nv_
131
 
    
132
 
    if {$WhatsHere(on)} {
133
 
        bind $Nv_(TOP).canvas <Button> {whats_here_info %x %y }
134
 
    } else {
135
 
        bind $Nv_(TOP).canvas <Button> {}       
136
 
    }
137
 
}
138
 
 
139
 
proc whats_here_info {x y} {
140
 
    global WhatsHere
141
 
    global Nv_
142
 
    
143
 
    set y [expr $Nv_(height) - $y]
144
 
 
145
 
#puts "DEBUG $x $y"
146
 
    
147
 
    set text $WhatsHere(text)
148
 
    set tot_out ""
149
 
 
150
 
    set list [Nget_point_on_surf $x $y]
151
 
    if {[llength $list] < 4} {
152
 
        $text insert end [G_msg "Point not on surface\n"]
153
 
        append tot_out [G_msg "Point not on surface\n"]
154
 
        $text yview -pickplace end
155
 
        return
156
 
    }
157
 
    
158
 
    set x [lindex $list 0]
159
 
    set y [lindex $list 1]
160
 
    set z [lindex $list 2]
161
 
    set id [lindex $list 3]
162
 
    
163
 
    if {$Nv_(what_easting)} then {
164
 
        set str [format [G_msg "Easting: %15.4f\n"] $x]
165
 
        $text insert end "$str"
166
 
        append tot_out "$str"
167
 
        $text yview -pickplace end
168
 
    }
169
 
 
170
 
    if {$Nv_(what_northing)} then {
171
 
        set str [format [G_msg "Northing: %15.4f\n"] $y]
172
 
        $text insert end "$str"
173
 
        append tot_out "$str"
174
 
        $text yview -pickplace end
175
 
    }
176
 
 
177
 
    if {$Nv_(what_elevation)} then {
178
 
        set str [format [G_msg "Elevation: %15.4f\n"] $z]
179
 
        $text insert end "$str"
180
 
        append tot_out "$str"
181
 
        $text yview -pickplace end
182
 
    }
183
 
    
184
 
    if {$Nv_(what_mapname)} then {
185
 
        set str [Nget_map_name [string range $id 5 end] surf]
186
 
        $text insert end [format [G_msg "Surf map: %s"] $str]
187
 
        append tot_out [format [G_msg "Surf map: %s"] $str]
188
 
        set str [Nget_cat_at_xy $id topo $x $y]
189
 
        $text insert end "\t$str\n"
190
 
        append tot_out "\t$str\n"
191
 
        set str [Nget_val_at_xy $id topo $x $y]
192
 
        $text insert end "\t$str\n"
193
 
        append tot_out "\t$str\n"
194
 
        $text yview -pickplace end
195
 
    }
196
 
 
197
 
    if {$Nv_(what_colorcat)} then {
198
 
        set map_name [$id get_att color]
199
 
        if {[lindex $map_name 0] == "map"} then {
200
 
            set str [lindex $map_name 1]
201
 
        } else {
202
 
            set str [G_msg "constant"]
203
 
        }
204
 
        $text insert end [format [G_msg "Color map: %s"] $str]
205
 
        append tot_out [format [G_msg "Color map: %s"] $str]
206
 
        set str [Nget_cat_at_xy $id color $x $y]
207
 
        $text insert end "\t$str\n"
208
 
        append tot_out "\t$str\n"
209
 
        set str [Nget_val_at_xy $id color $x $y]
210
 
        $text insert end "\t$str\n"
211
 
        append tot_out "\t$str\n"
212
 
        $text yview -pickplace end
213
 
    }
214
 
 
215
 
    if {$WhatsHere(first) == 0} {
216
 
        set px $WhatsHere(px)
217
 
        set py $WhatsHere(py)
218
 
        set pz $WhatsHere(pz)
219
 
 
220
 
### NO-NO Change to use lib functions for distance!
221
 
        
222
 
        if {$Nv_(what_xydiff)} then {
223
 
            set val [expr sqrt(($px-$x)*($px-$x)+($py-$y)*($py-$y))]
224
 
            set str [format [G_msg "XY distance from previous: \t%15.4f\n"] $val]
225
 
            $text insert end "$str"
226
 
            append tot_out "$str"
227
 
            $text yview -pickplace end
228
 
        }
229
 
 
230
 
        if {$Nv_(what_xyzdiff)} then {
231
 
            set val [expr sqrt(($px-$x)*($px-$x)+($py-$y)*($py-$y)+($pz-$z)*($pz-$z))]
232
 
            set str [format [G_msg "XYZ distance from previous: \t%15.4f\n"] $val]
233
 
            $text insert end "$str"
234
 
            append tot_out "$str"
235
 
            $text yview -pickplace end
236
 
        }
237
 
        
238
 
        if {$WhatsHere(pid) == $id} {
239
 
            if {$Nv_(what_surfdist)} then {
240
 
                set dist [Nget_dist_along_surf $id $x $y $px $py 0]
241
 
                set str [format [G_msg "Distance along surface: \t%15.4f\n"] $dist]
242
 
                $text insert end "$str"
243
 
                append tot_out "$str"
244
 
                $text yview -pickplace end
245
 
                Nset_draw front
246
 
                Ndraw_line_on_surf $id $x $y $px $py
247
 
                Nset_draw back
248
 
            }
249
 
 
250
 
            if {$Nv_(what_exagsurfdist)} then {
251
 
                set dist [Nget_dist_along_surf $id $x $y $px $py 1]
252
 
                set str [format [G_msg "Distance along exag. surface:%15.4f\n"] $dist]
253
 
                $text insert end "$str"
254
 
                append tot_out "$str"
255
 
                $text yview -pickplace end
256
 
                Nset_draw front
257
 
                Ndraw_line_on_surf $id $x $y $px $py
258
 
                Nset_draw back
259
 
            }
260
 
            
261
 
        }
262
 
    }
263
 
 
264
 
    $text insert end "\n"
265
 
 
266
 
    set WhatsHere(px) $x
267
 
    set WhatsHere(py) $y
268
 
    set WhatsHere(pz) $z
269
 
    set WhatsHere(pid) $id
270
 
    set WhatsHere(first) 0
271
 
    
272
 
    Nset_draw front
273
 
    Ndraw_X $id $x $y
274
 
    Nset_draw back
275
 
 
276
 
    if {$Nv_(what_pipe) != 0} {
277
 
        set out_file [open $Nv_(what_pipe) a]
278
 
        puts $out_file $tot_out
279
 
        close $out_file
280
 
    }
281
 
}
282
 
 
283
 
proc do_separate {} {
284
 
    global WhatsHere Nv_
285
 
    
286
 
    set text $WhatsHere(text)
287
 
    
288
 
    $text insert end "___________________________________\n"
289
 
    $text yview -pickplace end
290
 
 
291
 
    if {$Nv_(what_pipe) != 0} {
292
 
        set out_file [open $Nv_(what_pipe) a]
293
 
        puts $out_file "___________________________________"
294
 
        close $out_file
295
 
    }
296
 
 
297
 
    set WhatsHere(first) 1
298
 
}
299
 
 
300
 
proc clear_text {} {
301
 
    global WhatsHere
302
 
    
303
 
    set text $WhatsHere(text)
304
 
    
305
 
    $text delete 1.0 end
306
 
    $text yview -pickplace end
307
 
}
308