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

« back to all changes in this revision

Viewing changes to visualization/nviz/scripts/panel_vect.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 vector visualization 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
 
##########################################################################
26
 
 
27
 
############################################################################
28
 
# procedure to make main control area
29
 
###########################################################################
30
 
source $src_boot/etc/nviz2.2/scripts/config.tcl
31
 
 
32
 
 
33
 
proc mkvectPanel { BASE } {
34
 
    global Nv_
35
 
        global nviztxtfont
36
 
    
37
 
    catch {destroy $BASE}
38
 
 
39
 
    set curr [Nget_current vect]
40
 
    
41
 
    if {$curr != 0}  {
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]
46
 
    } else {
47
 
                set width 1
48
 
        set flat_state 0
49
 
                set height 0
50
 
                set maplist {}
51
 
    }
52
 
    
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]
56
 
    } else {
57
 
                set panel $Nv_($BASE)
58
 
    }
59
 
    frame $BASE -relief flat -borderwidth 0
60
 
    Nv_mkPanelname $BASE [G_msg "Vector Lines Panel"]
61
 
    
62
 
        #create top frame
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
66
 
        
67
 
    mkMapList $tmp.list vect
68
 
    
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
71
 
 
72
 
        pack $tmp.current $tmp.list -side left
73
 
    pack $tmp.list -side left 
74
 
        pack $tmp.delete $tmp.new -side right -expand 0
75
 
    
76
 
    pack $tmp -side top -fill x -expand 1 -padx 3 -pady 5
77
 
    
78
 
    # create bottom frame
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
86
 
 
87
 
    #create mid frame
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]
94
 
    
95
 
    set wlabel [label $row1.wlabel -text [G_msg "line width"] \
96
 
        -font $nviztxtfont -fg black]
97
 
    
98
 
    set vlinewidth [SpinBox $row1.linewidth -range {1 50 1}\
99
 
                -textvariable width \
100
 
                -modifycmd {set_width vect $width} \
101
 
                -command {set_width vect $width} \
102
 
                -width 5 \
103
 
                -entrybg white]
104
 
 
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\]"
109
 
    
110
 
    set rb1 [radiobutton $row2.label2 -text [G_msg "display flat"] \
111
 
                -variable flat_state -value 1 -command "check_list $row3.list"]
112
 
 
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"]
116
 
 
117
 
    set htscale [Nv_mkScale $row4.scale h [G_msg "vector height\nabove surface"] 0 10000 $height set_ht 1]
118
 
 
119
 
 
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
124
 
    pack $rb2 -side left 
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 
129
 
 
130
 
        # Let radiobutton state handle building list
131
 
        # of available surfaces
132
 
    if {$flat_state == 0} {
133
 
                $row2.label1 select
134
 
                check_list $row3.list
135
 
    } else {
136
 
                $row2.label2 select
137
 
                check_list $row3.list
138
 
    }
139
 
 
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
143
 
 
144
 
    return $panel
145
 
}
146
 
 
147
 
# Reset procedure for this panel
148
 
proc Nviz_vect_reset {} {
149
 
    set vect_list [Nget_vect_list]
150
 
 
151
 
    foreach i $vect_list {
152
 
        Nvect$i delete
153
 
    }
154
 
 
155
 
    set_new_curr vect 0
156
 
}
157
 
 
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).
164
 
 
165
 
    # Get the list of vect files
166
 
    set vect_list [Nget_vect_list]
167
 
 
168
 
    # Get the list of surfaces for checking draping
169
 
    set surf_list [Nget_surf_list]
170
 
 
171
 
    # Write out the total number of vector files
172
 
    puts $file_hook ">>>start vect"
173
 
    puts $file_hook "[llength $vect_list]"
174
 
 
175
 
    # For each vector file write out the following:
176
 
    # 1. Logical name
177
 
    # 2. map name
178
 
    # 3. color
179
 
    # 4. width
180
 
    # 5. list of logical names of surfaces displayed on
181
 
    foreach i $vect_list {
182
 
 
183
 
        # logical name
184
 
        puts $file_hook "[Nvect$i get_logical_name]"
185
 
        
186
 
        # map name
187
 
        puts $file_hook "[Nvect$i get_att map]"
188
 
    
189
 
        # color
190
 
        puts $file_hook "[Nvect$i get_att color]"
191
 
    
192
 
        # width
193
 
        puts $file_hook "[Nvect$i get_att width]"
194
 
    
195
 
        # logical names of surfaces displayed on
196
 
        set draped [list]
197
 
        foreach j $surf_list {
198
 
            if {[Nvect$i surf_is_selected Nsurf$j]} then {
199
 
                lappend draped $j
200
 
            }
201
 
        }
202
 
        puts $file_hook "[llength $draped]"
203
 
        foreach j $draped {
204
 
            puts $file_hook "[Nlogical_from_literal Nsurf$j]"
205
 
        }
206
 
    
207
 
        flush $file_hook
208
 
    }
209
 
    # Done...
210
 
}
211
 
 
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
216
 
 
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
222
 
 
223
 
        # Now create a new vect map with the given logical name
224
 
        set new_vect [Nnew_map_obj vect "name=$logical_name"]
225
 
 
226
 
        # Set all attributes as appropriate (i.e. as they are read from the state file)
227
 
        
228
 
        # map
229
 
        gets $file_hook att_data
230
 
        $new_vect set_att map $att_data
231
 
 
232
 
        # color 
233
 
        gets $file_hook att_data
234
 
        $new_vect set_att color $att_data
235
 
 
236
 
        # width
237
 
        gets $file_hook att_data
238
 
        $new_vect set_att width $att_data
239
 
 
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
244
 
 
245
 
            # Select this surf by translating from a logical name and selecting
246
 
            $new_vect select_surf [Nliteral_from_logical $selected_surf]
247
 
        }
248
 
 
249
 
        Nset_current vect [string range $new_vect 5 end]
250
 
    }
251
 
 
252
 
}
253
 
 
254
 
 
255
 
proc change_color { type me } {
256
 
    set curr [Nget_current $type]
257
 
    switch $type {
258
 
        "vect" { set head Nvect }
259
 
        "site" { set head Nsite }
260
 
    }
261
 
 
262
 
    if {0 != $curr} {
263
 
        set clr [$head$curr get_att color]
264
 
        set clr [mkColorPopup .colorpop Color $clr 1]
265
 
        $head$curr set_att color $clr
266
 
    }
267
 
 
268
 
    $me configure -bg [get_curr_sv_color $type]
269
 
}
270
 
 
271
 
proc get_curr_sv_color { type } {
272
 
    set curr [Nget_current $type]
273
 
    switch $type {
274
 
        "vect" { set head Nvect }
275
 
        "site" { set head Nsite }
276
 
    }
277
 
 
278
 
    if {0 == $curr} then {
279
 
        return "gray90"
280
 
    }
281
 
 
282
 
    set color [$head$curr get_att color]
283
 
 
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"
289
 
 
290
 
}
291
 
 
292
 
proc delete_map {type} {
293
 
    set curr [Nget_current $type]
294
 
    switch $type {
295
 
        "vect" { set head Nvect }
296
 
        "site" { set head Nsite }
297
 
    }
298
 
    
299
 
    if {0 != $curr} {
300
 
        $head$curr delete
301
 
        set name 0
302
 
        
303
 
        switch $type {
304
 
            "vect" { set new_list [Nget_vect_list] }
305
 
            "site" { set new_list [Nget_site_list] }
306
 
        }
307
 
        
308
 
        if {[llength $new_list] != 0} then {
309
 
            set name [lindex $new_list 0]
310
 
        } else {
311
 
            set name 0
312
 
        }
313
 
        
314
 
        set_new_curr $type $name
315
 
    }
316
 
    
317
 
}
318
 
 
319
 
# Use this routine when adding a vect or site in a script
320
 
proc script_add_map { type map_name } {
321
 
 
322
 
    set temp [Nnew_map_obj $type]
323
 
    $temp set_att map $map_name
324
 
    set_new_curr $type [string range $temp 5 end]
325
 
    
326
 
    return [string range $temp 5 end]
327
 
}
328
 
 
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]
332
 
 
333
 
    # Let user know that we are busy
334
 
    appBusy
335
 
 
336
 
    if {$new != "-1"} {
337
 
        set temp [Nnew_map_obj $type]
338
 
        $temp set_att map $new
339
 
        set_new_curr $type [string range $temp 5 end]
340
 
    }
341
 
 
342
 
    # Let user know that he may proceed
343
 
    appNotBusy
344
 
}
345
 
 
346
 
proc set_width {type E} {
347
 
        global Nauto_draw
348
 
 
349
 
    set curr [Nget_current $type]
350
 
    switch $type {
351
 
        "vect" { set head Nvect }
352
 
        "site" { set head Nsite }
353
 
    }
354
 
    
355
 
    if {0 != $curr} {
356
 
        $head$curr set_att width $E
357
 
    }
358
 
 
359
 
        if {$Nauto_draw == 1} {Ndraw_all}
360
 
}
361
 
 
362
 
# Procedure to set vector elevation eith above surface
363
 
# or level height
364
 
proc set_ht {h} {
365
 
    global Nv_ vect_height
366
 
 
367
 
    set vect_height $h
368
 
    set curr [Nget_current vect]
369
 
    if {0 != $curr}  {
370
 
    Nvect$curr set_trans 0 0 $vect_height
371
 
    }
372
 
      
373
 
}
374
 
 
375
 
#Procedure to update vect atts from radiobutton
376
 
proc check_list {address} {
377
 
    global Nv_ 
378
 
    global flat_state 
379
 
    global curr 
380
 
    global vect_height
381
 
 
382
 
    set state [winfo exists $address]
383
 
    set curr [Nget_current vect]
384
 
 
385
 
    if {$curr != 0}  {
386
 
        set maplist [Nget_map_list surf]
387
 
 
388
 
        if {$state == 0 && $flat_state == 0 } {
389
 
            #display on surface
390
 
            catch {destroy $address}
391
 
            Nvect$curr set_att flat 0
392
 
            Nv_mkSurfacelist $address $maplist Nvect$curr vect
393
 
            pack $address
394
 
        } 
395
 
        if {$state == 1 && $flat_state == 1} {
396
 
            #display on flat
397
 
            catch {destroy $address}
398
 
            Nvect$curr set_att flat 1
399
 
        }
400
 
    }
401
 
        
402
 
}