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

« back to all changes in this revision

Viewing changes to gui/tcltk/gis.m/dnviz.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
 
#       FILE:       dnviz.tcl
4
 
#   
5
 
#       PURPOSE:    Permits interactive creation of flythrough path for nviz
6
 
#                   using nviz
7
 
#  
8
 
#       AUTHOR:     Michael Barton, Arizona State University
9
 
#       COPYRIGHT:  (C) 2007 by the GRASS Development Team
10
 
#                   This program is free software under the GNU General Public
11
 
#                   License (>=v2). Read the file COPYING that comes with GRASS
12
 
#                   for details.
13
 
#
14
 
#
15
 
################################################################################
16
 
 
17
 
 
18
 
 
19
 
 
20
 
namespace eval GmDnviz {
21
 
    variable inmap
22
 
    variable outfile
23
 
    variable pathcoords
24
 
    variable prefix
25
 
    variable route
26
 
    variable layback
27
 
    variable height
28
 
    variable frames
29
 
    variable startframe
30
 
    variable usemouse
31
 
    variable coord_entry
32
 
    variable vrender
33
 
    variable fullrender
34
 
    variable offscreen
35
 
    variable ht_elev
36
 
    variable keyframe
37
 
    variable overwrite
38
 
        global env
39
 
 
40
 
}
41
 
# G_msg.tcl should be sourced first for internationalized strings.
42
 
 
43
 
 
44
 
###############################################################################
45
 
 
46
 
# select input map
47
 
proc GmDnviz::select_map { seltype var } {
48
 
 
49
 
    set m [GSelect $seltype title [G_msg "Select input map"] parent "."]
50
 
    if { $m != "" } {
51
 
        set $var $m
52
 
    }
53
 
}
54
 
 
55
 
###############################################################################
56
 
 
57
 
#Create main panel for d.nviz parameter entry
58
 
proc GmDnviz::main { mapcan mon } {
59
 
    variable inmap
60
 
    variable outfile
61
 
    variable pathcoords
62
 
    variable prefix
63
 
    variable route
64
 
    variable layback
65
 
    variable height
66
 
    variable frames
67
 
    variable startframe
68
 
    variable usemouse
69
 
    variable coord_entry
70
 
    variable vrender
71
 
    variable fullrender
72
 
    variable offscreen
73
 
    variable ht_elev
74
 
    variable keyframe
75
 
    variable overwrite
76
 
        global env
77
 
        global iconpath
78
 
        global bgcolor
79
 
                
80
 
        #initialize variables
81
 
        set inmap ""
82
 
        set outfile ""
83
 
        set pathcoords ""
84
 
        set overwrite 0
85
 
        set prefix "NVIZ"
86
 
        set route ""
87
 
        set layback 2000
88
 
        set height 1000
89
 
        set frames 50
90
 
        set startframe 0
91
 
        set usemouse 0
92
 
    set vrender 0
93
 
    set fullrender 0
94
 
    set offscreen 0
95
 
    set ht_elev 0
96
 
    set keyframe 0
97
 
    set overwrite
98
 
 
99
 
        set overwrite 0
100
 
        set selclr #88aa88
101
 
        
102
 
        # create nviz path input window
103
 
    if { [winfo exists .dnvizPopup] } {return}
104
 
 
105
 
        set dnviz_win [toplevel .dnvizPopup]
106
 
        wm title $dnviz_win [ G_msg "NVIZ flythrough path" ]
107
 
        # put it in the middle of the screen
108
 
        update idletasks
109
 
        set winWidth [winfo reqwidth $dnviz_win]
110
 
        set winHeight [winfo reqheight $dnviz_win]
111
 
        set scrnWidth [winfo screenwidth $dnviz_win]
112
 
        set scrnHeight [winfo screenheight $dnviz_win]
113
 
        set x [expr ($scrnWidth - $winWidth) / 2-250]
114
 
        set y [expr ($scrnHeight  - $winHeight) / 2]
115
 
        wm geometry $dnviz_win +$x+$y
116
 
        wm deiconify $dnviz_win
117
 
                
118
 
        #create the form and buttons
119
 
 
120
 
    # Title
121
 
    set row [ frame $dnviz_win.heading ]
122
 
    Label $row.a -text [G_msg "Create flythough path for NVIZ display"] \
123
 
        -fg MediumBlue
124
 
    pack $row.a -side top -padx 5 -pady 3
125
 
    pack $row -side top -fill x -expand yes
126
 
 
127
 
    # input map
128
 
    set row [ frame $dnviz_win.input ]
129
 
    Label $row.a -text [G_msg "Raster surface map "]
130
 
    Button $row.b -image [image create photo -file "$iconpath/element-cell.gif"] \
131
 
        -highlightthickness 0 -takefocus 0 -relief raised -borderwidth 1  \
132
 
        -command "GmDnviz::select_map cell GmDnviz::inmap"
133
 
    Entry $row.c -width 50 -text "$inmap" \
134
 
          -textvariable GmDnviz::inmap
135
 
    pack $row.c $row.b $row.a -side right -padx 3 -anchor e
136
 
    pack $row -side top -fill x -expand no -padx 5
137
 
        
138
 
    # set output script file
139
 
    set row [ frame $dnviz_win.output ]
140
 
    Label $row.a -text [G_msg "Output script file "]
141
 
    Button $row.b -image [image create photo -file "$iconpath/file-open.gif"] \
142
 
        -highlightthickness 0 -takefocus 0 -relief raised -borderwidth 1  \
143
 
        -command "GmDnviz::select_map file GmDnviz::outfile"
144
 
    Entry $row.c -width 50 -text "$outfile" \
145
 
          -textvariable GmDnviz::outfile
146
 
    pack $row.c $row.b $row.a -side right -anchor e -padx 3
147
 
    pack $row -side top -fill x -expand no -padx 5
148
 
    
149
 
    # flythrough path coordinates
150
 
    set row [ frame $dnviz_win.coords ]
151
 
    Label $row.a -text [G_msg "Flythrough path "]
152
 
    set ck_path [checkbutton $row.b -image [image create photo -file "$iconpath/gui-mouse.gif"] \
153
 
        -variable "GmDnviz::usemouse" -command "GmDnviz::setmouse $mapcan $mon"\
154
 
        -indicatoron false -selectcolor $selclr -bg $bgcolor \
155
 
        -highlightthickness 0 -borderwidth 1  \
156
 
                -activebackground $bgcolor -highlightbackground $bgcolor ]
157
 
        DynamicHelp::register $ck_path balloon [G_msg "Create path with mouse in map display"]
158
 
    set coord_entry [Entry $row.c -width 50 -text "$outfile" \
159
 
        -textvariable GmDnviz::pathcoords  -width 50 -xscrollcommand "$row.d set" \
160
 
        -helptext [G_msg "Coordinate pairs for flythrough path (x1,y1,x2,y2,...)"]]
161
 
        scrollbar $row.d -relief sunken -command "$coord_entry xview" -orient horizontal
162
 
    pack $row.d -side bottom -fill x -expand no -anchor e
163
 
    pack $row.c $row.b $row.a -side right -anchor e -padx 3
164
 
    pack $row -side top -fill x -expand no -padx 5
165
 
    
166
 
    # set output images prefix
167
 
    set row [ frame $dnviz_win.prefix ]
168
 
    LabelEntry $row.a -textvariable GmDnviz::prefix -width 50 \
169
 
        -label [G_msg "Flythrough images prefix "] \
170
 
        -helptext [G_msg "Prefix for image series created by flythough"]
171
 
    pack $row.a -side right -anchor e -padx 3
172
 
    pack $row -side top -fill x -expand no -padx 5
173
 
    
174
 
    # Camera position
175
 
    set row [ frame $dnviz_win.camera ]
176
 
    LabelEntry $row.a -textvariable GmDnviz::layback -width 10 \
177
 
        -label [G_msg "Camera layback "] \
178
 
        -helptext [G_msg "Camera layback distance (in map units)"]
179
 
    LabelEntry $row.b -textvariable GmDnviz::height -width 10 \
180
 
        -label [G_msg "Camera height "] \
181
 
        -helptext [G_msg "Camera height above terrain"]
182
 
    pack $row.a $row.b -side right -anchor e -padx 3
183
 
    pack $row -side top -fill x -expand no -padx 5
184
 
   
185
 
    # Frame settings
186
 
    set row [ frame $dnviz_win.frames ]
187
 
    LabelEntry $row.a -textvariable GmDnviz::frames -width 10 \
188
 
        -label [G_msg "Number of frames "] \
189
 
        -helptext [G_msg "Number of frames to create for flythrough"]
190
 
    LabelEntry $row.b -textvariable GmDnviz::startframe -width 10 \
191
 
        -label [G_msg "Start frame "] \
192
 
        -helptext [G_msg "Starting frame number..."]
193
 
    pack $row.a $row.b -side right -anchor e -padx 3
194
 
    pack $row -side top -fill x -expand no -padx 5
195
 
    
196
 
    
197
 
    set row [ frame $dnviz_win.options1 ]
198
 
    checkbutton $row.a -variable GmDnviz::vrender \
199
 
                -text [G_msg "Enable vector rendering"]
200
 
    checkbutton $row.b -variable GmDnviz::fullrender \
201
 
                -text [G_msg "Full render (save images)"]
202
 
    checkbutton $row.c -variable GmDnviz::offscreen \
203
 
                -text [G_msg "Render images offscreen"]
204
 
    pack $row.a $row.b $row.c -side left -anchor w -padx 5
205
 
    pack $row -side top -fill x -expand no
206
 
    
207
 
    set row [ frame $dnviz_win.options2 ]
208
 
    Button $row.a -text [G_msg "Help"] \
209
 
            -image [image create photo -file "$iconpath/gui-help.gif"] \
210
 
            -command "spawn g.manual --q d.nviz" \
211
 
            -background $bgcolor \
212
 
            -helptext [G_msg "Help"]
213
 
    pack $row.a -side right -anchor e -padx 5
214
 
    checkbutton $row.b -variable GmDnviz::ht_elev \
215
 
                -text [G_msg "Height value is elevation"]
216
 
    checkbutton $row.c -variable GmDnviz::keyframe \
217
 
                -text [G_msg "Output keyframe file"]
218
 
    checkbutton $row.d -variable GmDnviz::overwrite \
219
 
                -text [G_msg "Overwrite existing file"]
220
 
    pack $row.b $row.c $row.d -side left -anchor w -padx 5
221
 
    pack $row -side top -fill x -expand no
222
 
    
223
 
    set row [ frame $dnviz_win.buttons ]
224
 
    Button $row.d -text [G_msg "Reset"] -width 8 -bd 1 \
225
 
        -command "GmDnviz::reset_points $mon %W" \
226
 
        -helptext [G_msg "Clear all path coordinates"]
227
 
    pack $row.d -side left -padx 5 -fill none -expand no -anchor w
228
 
    Button $row.a -text [G_msg "OK"] -width 8 -bd 1 \
229
 
        -command "GmDnviz::makescript %W 1" -default active
230
 
    Button $row.b -text [G_msg "Cancel"] -width 8 -bd 1 \
231
 
        -command "destroy .dnvizPopup"
232
 
    Button $row.c -text [G_msg "Apply"] -width 8 -bd 1 \
233
 
        -command "GmDnviz::makescript %W 0"
234
 
    pack $row.a $row.b $row.c -side right -padx 5 -expand no -anchor e
235
 
    pack $row -side bottom -pady 3 -padx 5 -expand yes -fill none
236
 
 
237
 
        bind .dnvizPopup <Destroy> "GmDnviz::cleanup $mon %W"    
238
 
 
239
 
}
240
 
 
241
 
###############################################################################
242
 
# interactive mouse input of path coordinates
243
 
proc GmDnviz::setmouse {mapcan mon} {
244
 
    variable usemouse
245
 
    
246
 
    if {$usemouse == 0} {
247
 
        MapCanvas::pointer $mon
248
 
        return
249
 
    }
250
 
    
251
 
    MapCanvas::setcursor $mon "crosshair"
252
 
 
253
 
    bind $mapcan <ButtonPress-1> "GmDnviz::getcoords $mapcan $mon %x %y"
254
 
    
255
 
}
256
 
 
257
 
###############################################################################
258
 
# set coordinate point from mouse click
259
 
proc GmDnviz::getcoords {mapcan mon x y} {
260
 
    
261
 
    variable coord_entry
262
 
    
263
 
    set eastcoord [eval MapCanvas::scrx2mape $mon $x]
264
 
    set northcoord [eval MapCanvas::scry2mapn $mon $y]
265
 
    set grcoords "$eastcoord,$northcoord,"
266
 
    GmDnviz::markpoint $mapcan $x $y
267
 
    $coord_entry insert end $grcoords
268
 
   # focus -force [tk_focusNext $coord_entry]
269
 
 
270
 
}
271
 
 
272
 
 
273
 
###############################################################################
274
 
# mark ground control point
275
 
proc GmDnviz::markpoint { mapcan x y } {
276
 
 
277
 
    # create point for flythrough path on map display canvas for each mouse click
278
 
 
279
 
    $mapcan create line $x [expr $y-5] $x [expr $y+5] -tag gcpv \
280
 
            -fill DarkGreen -width 2 -tag "ptvert"
281
 
    $mapcan create line [expr $x-5] $y [expr $x+5] $y -tag gcph \
282
 
            -fill red -width 2 -tag "pthoriz"
283
 
}
284
 
 
285
 
###############################################################################
286
 
 
287
 
# cleanup procedure when window closed
288
 
proc GmDnviz::cleanup { mon w } {
289
 
    variable inmap
290
 
    variable outfile
291
 
    variable pathcoords
292
 
    variable prefix
293
 
    variable route
294
 
    variable layback
295
 
    variable height
296
 
    variable frames
297
 
    variable startframe
298
 
    variable usemouse
299
 
    variable coord_entry
300
 
    variable overwrite
301
 
 
302
 
        set inmap ""
303
 
        set outfile ""
304
 
        set pathcoords ""
305
 
        set overwrite 0
306
 
        set prefix "NVIZ"
307
 
        set route ""
308
 
        set layback 2000
309
 
        set height 1000
310
 
        set frames 50
311
 
        set startframe 0
312
 
        set usemouse 0
313
 
        set overwrite 0
314
 
 
315
 
    MapCanvas::pointer $mon
316
 
    MapCanvas::request_redraw $mon 0
317
 
 
318
 
}
319
 
 
320
 
###############################################################################
321
 
 
322
 
# cleanup procedure when window closed
323
 
proc GmDnviz::reset_points { mon w } {
324
 
    variable pathcoords
325
 
    variable coord_entry
326
 
 
327
 
        set pathcoords ""
328
 
    $coord_entry delete 0 end
329
 
 
330
 
    MapCanvas::request_redraw $mon 0
331
 
 
332
 
}
333
 
 
334
 
###############################################################################
335
 
 
336
 
# Run d.nviz to create flythrough path script
337
 
proc GmDnviz::makescript { w quit } {
338
 
    variable inmap
339
 
    variable outfile
340
 
    variable pathcoords
341
 
    variable prefix
342
 
    variable route
343
 
    variable layback
344
 
    variable height
345
 
    variable frames
346
 
    variable startframe
347
 
    variable usemouse
348
 
    variable coord_entry
349
 
    variable vrender
350
 
    variable fullrender
351
 
    variable offscreen
352
 
    variable ht_elev
353
 
    variable keyframe
354
 
    variable overwrite
355
 
    global devnull
356
 
 
357
 
    if { $inmap == ""} {
358
 
        tk_messageBox -type ok -icon warning -parent $w \
359
 
                    -message [G_msg "You must select an input map"] \
360
 
                    -title [G_msg "No input map selected"]
361
 
        return
362
 
    }
363
 
    if { $outfile == ""} {
364
 
        tk_messageBox -type ok -icon warning -parent $w \
365
 
                    -message [G_msg "You must specify an output file"] \
366
 
                    -title [G_msg "No output file specified"]
367
 
        return
368
 
    }    
369
 
    
370
 
    set pathcoords [string trimright $pathcoords ","]
371
 
    set coords_list [split $pathcoords ","] 
372
 
    if { [llength $coords_list] < 8 } {
373
 
        tk_messageBox -type ok -icon warning -parent $w \
374
 
                    -message [G_msg "You must specify at least 4 points (x,y coordinate pairs)"] \
375
 
                    -title [G_msg "Insufficient coordinates specified"]
376
 
        return
377
 
    }    
378
 
        
379
 
    
380
 
    set cmd "d.nviz input=$inmap output=$outfile name=$prefix route=$pathcoords \
381
 
         dist=$layback ht=$height frames=$frames start=$startframe"   
382
 
 
383
 
 
384
 
    if { $vrender == 1 } { lappend cmd " -e" }
385
 
    if { $fullrender == 1 } { lappend cmd " -f" }
386
 
    if { $offscreen == 1 } { lappend cmd " -o" }
387
 
    if { $ht_elev == 1 } { lappend cmd " -c" }
388
 
    if { $keyframe == 1 } { lappend cmd " -k" }
389
 
    if { $overwrite == 1 } { lappend cmd " --o" }
390
 
        
391
 
    run_panel $cmd
392
 
    
393
 
    # delete rules file and close popup window if OK pressed
394
 
    if { $quit == 1 } {
395
 
        destroy .dnvizPopup
396
 
    }
397
 
 
398
 
}
399