1
################################################################################
5
# PURPOSE: Permits interactive creation of flythrough path for nviz
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
15
################################################################################
20
namespace eval GmDnviz {
41
# G_msg.tcl should be sourced first for internationalized strings.
44
###############################################################################
47
proc GmDnviz::select_map { seltype var } {
49
set m [GSelect $seltype title [G_msg "Select input map"] parent "."]
55
###############################################################################
57
#Create main panel for d.nviz parameter entry
58
proc GmDnviz::main { mapcan mon } {
102
# create nviz path input window
103
if { [winfo exists .dnvizPopup] } {return}
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
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
118
#create the form and buttons
121
set row [ frame $dnviz_win.heading ]
122
Label $row.a -text [G_msg "Create flythough path for NVIZ display"] \
124
pack $row.a -side top -padx 5 -pady 3
125
pack $row -side top -fill x -expand yes
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
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
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
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
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
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
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
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
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
237
bind .dnvizPopup <Destroy> "GmDnviz::cleanup $mon %W"
241
###############################################################################
242
# interactive mouse input of path coordinates
243
proc GmDnviz::setmouse {mapcan mon} {
246
if {$usemouse == 0} {
247
MapCanvas::pointer $mon
251
MapCanvas::setcursor $mon "crosshair"
253
bind $mapcan <ButtonPress-1> "GmDnviz::getcoords $mapcan $mon %x %y"
257
###############################################################################
258
# set coordinate point from mouse click
259
proc GmDnviz::getcoords {mapcan mon x y} {
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]
273
###############################################################################
274
# mark ground control point
275
proc GmDnviz::markpoint { mapcan x y } {
277
# create point for flythrough path on map display canvas for each mouse click
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"
285
###############################################################################
287
# cleanup procedure when window closed
288
proc GmDnviz::cleanup { mon w } {
315
MapCanvas::pointer $mon
316
MapCanvas::request_redraw $mon 0
320
###############################################################################
322
# cleanup procedure when window closed
323
proc GmDnviz::reset_points { mon w } {
328
$coord_entry delete 0 end
330
MapCanvas::request_redraw $mon 0
334
###############################################################################
336
# Run d.nviz to create flythrough path script
337
proc GmDnviz::makescript { w quit } {
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"]
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"]
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"]
380
set cmd "d.nviz input=$inmap output=$outfile name=$prefix route=$pathcoords \
381
dist=$layback ht=$height frames=$frames start=$startframe"
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" }
393
# delete rules file and close popup window if OK pressed