1
##########################################################################
3
# Routines for vector visualization 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
25
##########################################################################
27
############################################################################
28
# procedure to make main control area
29
###########################################################################
30
source $src_boot/etc/nviz2.2/scripts/config.tcl
33
proc mkvectPanel { BASE } {
39
set curr [Nget_current vect]
42
set width [Nvect$curr get_att width]
43
set flat_state [Nvect$curr get_att flat]
44
set height [expr [lindex [Nvect$curr get_trans] 2] * 10]
45
set maplist [Nget_map_list surf]
53
# Initialize panel info
54
if [catch {set Nv_($BASE)}] {
55
set panel [St_create {window name size priority} $BASE [G_msg "Vector Lines/3D Polygons"] 2 5]
59
frame $BASE -relief flat -borderwidth 0
60
Nv_mkPanelname $BASE [G_msg "Vector Lines Panel"]
63
###### make widgets that control which is current surface (menu, new delete)###
64
set tmp [frame $BASE.top]
65
Label $tmp.current -text [G_msg "Current:"] -anchor w
67
mkMapList $tmp.list vect
69
button $tmp.new -text [G_msg "New"] -anchor center -command "add_map vect" -bd 1
70
button $tmp.delete -text [G_msg "Delete"] -anchor center -command "delete_map vect" -bd 1
72
pack $tmp.current $tmp.list -side left
73
pack $tmp.list -side left
74
pack $tmp.delete $tmp.new -side right -expand 0
76
pack $tmp -side top -fill x -expand 1 -padx 3 -pady 5
79
set tmp [frame $BASE.f]
80
button $tmp.close -text [G_msg "Close"] -command "Nv_closePanel $BASE" -anchor s -bd 1
81
pack $tmp.close -side right
82
button $tmp.draw_current -text [G_msg "DRAW CURRENT"] -bd 1 -fg darkgreen \
83
-command {Nvect_draw_one [Nget_current vect]}
84
pack $tmp.draw_current -side left
85
pack $tmp -side bottom -fill x -expand 1 -padx 3
88
set tmp [frame $BASE.mid]
89
set row1 [frame $tmp.row1]
90
set row2 [frame $tmp.row2]
91
set row3 [frame $tmp.row3]
92
set row4 [frame $tmp.row4]
93
set tmp1a [frame $row1.b]
95
set wlabel [label $row1.wlabel -text [G_msg "line width"] \
96
-font $nviztxtfont -fg black]
98
set vlinewidth [SpinBox $row1.linewidth -range {1 50 1}\
100
-modifycmd {set_width vect $width} \
101
-command {set_width vect $width} \
105
# checkbutton $tmp.load -relief flat -text "Load to memory"
106
set vcolor [button $row1.color -text [G_msg "Color"] -bd 1\
107
-command "change_color vect $row1.color"]
108
bind $row1.color <Expose> "$row1.color configure -bg \[get_curr_sv_color vect\]"
110
set rb1 [radiobutton $row2.label2 -text [G_msg "display flat"] \
111
-variable flat_state -value 1 -command "check_list $row3.list"]
113
set rb2 [radiobutton $row2.label1 -text [G_msg "display on surface(s):"] \
114
-variable flat_state -value 0 \
115
-command "check_list $row3.list"]
117
set htscale [Nv_mkScale $row4.scale h [G_msg "vector height\nabove surface"] 0 10000 $height set_ht 1]
120
pack $wlabel $vlinewidth -side left
121
pack $vcolor -side left -padx 10
122
pack $rb1 -side right -padx 5
123
pack $row1 -expand 1 -fill none -pady 4
125
pack $row2 -side left
126
pack $row3 -side left
127
pack $htscale -side top -anchor w
128
pack $row4 -side top -fill x -expand 1 -pady 4
130
# Let radiobutton state handle building list
131
# of available surfaces
132
if {$flat_state == 0} {
134
check_list $row3.list
137
check_list $row3.list
140
pack $row1 $row2 $row3 -side top -fill both -expand 1
141
pack $row4 -side right -fill both -expand 1
142
pack $tmp -side top -fill both -expand 1 -padx 3
147
# Reset procedure for this panel
148
proc Nviz_vect_reset {} {
149
set vect_list [Nget_vect_list]
151
foreach i $vect_list {
158
# Save procedure for saving state of Nviz vect files
159
proc Nviz_vect_save {file_hook} {
160
# For each vector file we write out all of its attribute information.
161
# Vectors are referenced by logical name so that they are reloadable
162
# (otherwise, they may be assigned different id's each time they are loaded
163
# and scripts won't work correctly).
165
# Get the list of vect files
166
set vect_list [Nget_vect_list]
168
# Get the list of surfaces for checking draping
169
set surf_list [Nget_surf_list]
171
# Write out the total number of vector files
172
puts $file_hook ">>>start vect"
173
puts $file_hook "[llength $vect_list]"
175
# For each vector file write out the following:
180
# 5. list of logical names of surfaces displayed on
181
foreach i $vect_list {
184
puts $file_hook "[Nvect$i get_logical_name]"
187
puts $file_hook "[Nvect$i get_att map]"
190
puts $file_hook "[Nvect$i get_att color]"
193
puts $file_hook "[Nvect$i get_att width]"
195
# logical names of surfaces displayed on
197
foreach j $surf_list {
198
if {[Nvect$i surf_is_selected Nsurf$j]} then {
202
puts $file_hook "[llength $draped]"
204
puts $file_hook "[Nlogical_from_literal Nsurf$j]"
212
# Load procedure for loading state of Nviz vect files
213
proc Nviz_vect_load { file_hook } {
214
# Read the number of surfaces saved in this state file
215
gets $file_hook num_vects
217
# For each vect file, create a new surface with the given logical
218
# name and fill in the attributes as appropriate
219
for {set i 0} {$i < $num_vects} {incr i} {
220
# Read in the logical name for this new vect map
221
gets $file_hook logical_name
223
# Now create a new vect map with the given logical name
224
set new_vect [Nnew_map_obj vect "name=$logical_name"]
226
# Set all attributes as appropriate (i.e. as they are read from the state file)
229
gets $file_hook att_data
230
$new_vect set_att map $att_data
233
gets $file_hook att_data
234
$new_vect set_att color $att_data
237
gets $file_hook att_data
238
$new_vect set_att width $att_data
240
# Select all the appropriate surfaces to put this map on
241
gets $file_hook num_selected_surfs
242
for {set j 0} {$j < $num_selected_surfs} {incr j} {
243
gets $file_hook selected_surf
245
# Select this surf by translating from a logical name and selecting
246
$new_vect select_surf [Nliteral_from_logical $selected_surf]
249
Nset_current vect [string range $new_vect 5 end]
255
proc change_color { type me } {
256
set curr [Nget_current $type]
258
"vect" { set head Nvect }
259
"site" { set head Nsite }
263
set clr [$head$curr get_att color]
264
set clr [mkColorPopup .colorpop Color $clr 1]
265
$head$curr set_att color $clr
268
$me configure -bg [get_curr_sv_color $type]
271
proc get_curr_sv_color { type } {
272
set curr [Nget_current $type]
274
"vect" { set head Nvect }
275
"site" { set head Nsite }
278
if {0 == $curr} then {
282
set color [$head$curr get_att color]
284
set color [expr int([tcl_to_rgb $color])]
285
set blue [hexval [expr int($color & 0x0000ff)]]
286
set green [hexval [expr int(($color & 0x00ff00)>>8)]]
287
set red [hexval [expr int(($color & 0xff0000)>>16)]]
288
return "#$red$green$blue"
292
proc delete_map {type} {
293
set curr [Nget_current $type]
295
"vect" { set head Nvect }
296
"site" { set head Nsite }
304
"vect" { set new_list [Nget_vect_list] }
305
"site" { set new_list [Nget_site_list] }
308
if {[llength $new_list] != 0} then {
309
set name [lindex $new_list 0]
314
set_new_curr $type $name
319
# Use this routine when adding a vect or site in a script
320
proc script_add_map { type map_name } {
322
set temp [Nnew_map_obj $type]
323
$temp set_att map $map_name
324
set_new_curr $type [string range $temp 5 end]
326
return [string range $temp 5 end]
329
proc add_map {type} {
330
if { $type == "site" } { set browse_type "vect" } else { set browse_type $type }
331
set new [create_map_browser .fbrowse $browse_type 1]
333
# Let user know that we are busy
337
set temp [Nnew_map_obj $type]
338
$temp set_att map $new
339
set_new_curr $type [string range $temp 5 end]
342
# Let user know that he may proceed
346
proc set_width {type E} {
349
set curr [Nget_current $type]
351
"vect" { set head Nvect }
352
"site" { set head Nsite }
356
$head$curr set_att width $E
359
if {$Nauto_draw == 1} {Ndraw_all}
362
# Procedure to set vector elevation eith above surface
365
global Nv_ vect_height
368
set curr [Nget_current vect]
370
Nvect$curr set_trans 0 0 $vect_height
375
#Procedure to update vect atts from radiobutton
376
proc check_list {address} {
382
set state [winfo exists $address]
383
set curr [Nget_current vect]
386
set maplist [Nget_map_list surf]
388
if {$state == 0 && $flat_state == 0 } {
390
catch {destroy $address}
391
Nvect$curr set_att flat 0
392
Nv_mkSurfacelist $address $maplist Nvect$curr vect
395
if {$state == 1 && $flat_state == 1} {
397
catch {destroy $address}
398
Nvect$curr set_att flat 1