1
##########################################################################
3
# Routines for raster querying for NVIZ
5
# Original author unknown.
6
# Probably U.S. Army Construction Engineering Research Laboratory
8
# Major update of GUI Nov 2006, Michael Barton, Arizona State University
10
##########################################################################
11
# COPYRIGHT: (C) 2006 by Michael Barton and the GRASS Development Team
13
# This program is free software under the GNU General Public
14
# License (>=v2). Read the file COPYING that comes with GRASS
17
##########################################################################
18
# Default Priority for this panel
20
# priority is from 0 to 10
21
# the lower the number, the quicker it will be bumped
23
# Panels will be loaded by the greater of 5 or their current priority
24
############################################################################
25
# procedure to make main control area
28
set WhatsHere(first) 1
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
41
set Nv_(what_pipe_text) [G_msg "Send results to: (no file selected)"]
43
proc mkqueryPanel { BASE } {
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]
57
frame $BASE -relief flat -borderwidth 0
58
Nv_mkPanelname $BASE [G_msg "Raster Query Panel"]
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 \
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
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]] {
80
$theMenu add checkbutton -label [lindex $i 0] -underline [lindex $i 2] \
81
-offvalue 0 -onvalue 1 -variable Nv_(what_[lindex $i 1])
84
pack $BASE.bf -side top -fill x -padx 3 -pady 5
86
# frrame for close button and saving output to a file
88
Button $BASE.cf.close -text [G_msg "Close"] -command "Nv_closePanel $BASE" \
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"]
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
99
text $BASE.text -wrap word -relief sunken -bd 2 \
100
-yscrollcommand "$BASE.yscroll set" \
103
set WhatsHere(text) $BASE.text
105
# scrollbar $BASE.xscroll -orient horizontal -relief flat
106
# -activebackground gray80 -command "$BASE.text view"
108
scrollbar $BASE.yscroll -orient vertical -relief flat \
109
-command "$BASE.text yview" -activebackground gray80
111
pack $BASE.yscroll -side right -fill y
112
# pack $BASE.xscroll -side bottom -fill x
113
pack $BASE.text -expand yes -fill both
118
proc whats_pipe_bind {BASE} {
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
125
set Nv_(what_pipe) $new_file
126
set Nv_(what_pipe_text) [format [G_msg "Send results to: %s"] $new_file]
132
if {$WhatsHere(on)} {
133
bind $Nv_(TOP).canvas <Button> {whats_here_info %x %y }
135
bind $Nv_(TOP).canvas <Button> {}
139
proc whats_here_info {x y} {
143
set y [expr $Nv_(height) - $y]
147
set text $WhatsHere(text)
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
158
set x [lindex $list 0]
159
set y [lindex $list 1]
160
set z [lindex $list 2]
161
set id [lindex $list 3]
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
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
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
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
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]
202
set str [G_msg "constant"]
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
215
if {$WhatsHere(first) == 0} {
216
set px $WhatsHere(px)
217
set py $WhatsHere(py)
218
set pz $WhatsHere(pz)
220
### NO-NO Change to use lib functions for distance!
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
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
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
246
Ndraw_line_on_surf $id $x $y $px $py
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
257
Ndraw_line_on_surf $id $x $y $px $py
264
$text insert end "\n"
269
set WhatsHere(pid) $id
270
set WhatsHere(first) 0
276
if {$Nv_(what_pipe) != 0} {
277
set out_file [open $Nv_(what_pipe) a]
278
puts $out_file $tot_out
283
proc do_separate {} {
286
set text $WhatsHere(text)
288
$text insert end "___________________________________\n"
289
$text yview -pickplace end
291
if {$Nv_(what_pipe) != 0} {
292
set out_file [open $Nv_(what_pipe) a]
293
puts $out_file "___________________________________"
297
set WhatsHere(first) 1
303
set text $WhatsHere(text)
306
$text yview -pickplace end