nviz2.2_script 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127
  1. ##########################################################################
  2. #
  3. # Main startup script for NVIZ
  4. # Probably originally written written ca. 1994 by
  5. # U.S. Army Construction Engineering Research Laboratory
  6. #
  7. #
  8. # Major update of GUI Nov 2006, Michael Barton, Arizona State University
  9. #
  10. ##########################################################################
  11. # COPYRIGHT: (C) 1999 - 2008 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. #
  19. #!nviz -f
  20. # Please log changes in the ChangeLog file in this directory
  21. # (Use "C-x 4 a" from emacs to add an entry)
  22. #
  23. # These two lines necessary to allow auto-loading
  24. # If you move nviz then be sure to change these two lines
  25. # to reflect the location of the libraries
  26. # Also, don't forget to change the invocation of nvwish above.
  27. # auto_mkindex /data/stimpy/terry/tcl/nviz *.tcl
  28. # exec chmod ugo+rw tclIndex
  29. global src_boot
  30. global env
  31. global BGColor
  32. set BGColor #FFFFFF
  33. #If set to 1 output debug statements
  34. global DEBUG
  35. set DEBUG 0
  36. #Initialize ProcessName variable
  37. set env(NV_processname) NVIZ
  38. source $src_boot/etc/nviz2.2/scripts/config.tcl
  39. #append bwidget for tooltip stuff
  40. lappend auto_path $env(GISBASE)/bwidget
  41. package require -exact BWidget 1.2.1
  42. # internationalization procedures
  43. source $env(GISBASE)/etc/gtcltk/gmsg.tcl
  44. global Nv_ ScriptState ScriptFile ScriptPlaying NvizLoadState
  45. set ScriptPlaying 0
  46. #Config Tooltip stuff
  47. DynamicHelp::configure -bg "#FFFFAA"
  48. interp alias {} help {} DynamicHelp::register
  49. ##########################################################################
  50. # Constants
  51. ##########################################################################
  52. set Nv_(TOP) ".middle.draw"
  53. set Nv_(APP) "."
  54. set Nv_(P_AREA) ".middle.panelarea.panels"
  55. set Nv_(PAREA) ".middle.panelarea"
  56. set Nv_(AREA) ".top"
  57. set Nv_(CALLED_SET_FOCUS) no
  58. set Nv_(CurrSurf) 0
  59. set Nv_(CurrVect) 0
  60. set Nv_(CurrSite) 0
  61. set Nv_(CurrSdiff) 0
  62. set Nv_(CurrVol) 0
  63. set Nv_(hidemenus) 1
  64. # Some quick code to initialize the CurrSurf, CurrVect and CurrSite variables
  65. set temp [Nget_surf_list]
  66. if {[llength $temp] == 0} then {
  67. set Nv_(CurrSurf) 0
  68. } else {
  69. set Nv_(CurrSurf) [lindex $temp 0]
  70. }
  71. set temp [Nget_vect_list]
  72. if {[llength $temp] == 0} then {
  73. set Nv_(CurrVect) 0
  74. } else {
  75. set Nv_(CurrVect) [lindex $temp 0]
  76. }
  77. set temp [Nget_site_list]
  78. if {[llength $temp] == 0} then {
  79. set Nv_(CurrSite) 0
  80. } else {
  81. set Nv_(CurrSite) [lindex $temp 0]
  82. }
  83. set temp [Nget_vol_list]
  84. if {[llength $temp] == 0} then {
  85. set Nv_(CurrVol) 0
  86. } else {
  87. set Nv_(CurrVol) [lindex $temp 0]
  88. }
  89. ##########################################################################
  90. #*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  91. ##########################################################################
  92. # Load this array with the names of the panels that are to be used
  93. #
  94. # 11/1/95 - This array loaded by searching through all the directories
  95. # in $user_path. For each directory in this path, the contents of
  96. # the file panelIndex is added to this array
  97. # note we need a TRACE proc for whenever this list is changed dynamically
  98. #DEBUG
  99. if {$DEBUG} {puts "Adding panels from $user_path"}
  100. set Nv_(panels) [list]
  101. foreach i $user_path {
  102. set index $i/panelIndex
  103. if {[file exists $index]} then {
  104. set panels [open $index]
  105. while {[gets $panels j] >= 0} {
  106. if {[lsearch -exact $Nv_(panels) $j] == -1} then {
  107. lappend Nv_(panels) $j
  108. }
  109. }
  110. close $panels
  111. }
  112. }
  113. # panels that have code to save status to state file
  114. set Nv_(panelstate) [list main surf vect site vol cutplane color lights]
  115. set Nv_(config) [list]
  116. foreach i $user_path {
  117. set index $i/configIndex
  118. if {[file exists $index]} then {
  119. set config [open $index]
  120. while {[gets $config j] >= 0} {
  121. if {[lsearch -exact $Nv_(config) $j] == -1} then {
  122. lappend Nv_(config) $j
  123. }
  124. }
  125. close $config
  126. }
  127. }
  128. # DEBUG
  129. if {$DEBUG} {puts Nv_(panels)}
  130. ##########################################################################
  131. #*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  132. ##########################################################################
  133. #########################################################################
  134. # Make sure panel has been loaded
  135. #########################################################################
  136. proc Nv_force_panel { name } {
  137. global Nv_
  138. set P $Nv_(P_AREA)
  139. # create panel if it doesn't already exist
  140. set path $P.$name
  141. if [catch {set Nv_($path)}] {
  142. set file panel_$name.tcl
  143. set Nv_($path) [mk$name\Panel $path]
  144. }
  145. }
  146. #########################################################################
  147. proc set_scrollsize {} {
  148. global Nv_
  149. set wid [winfo width $Nv_(P_AREA)]
  150. set ht [winfo height $Nv_(P_AREA)]
  151. set bbox "0 0 $wid $ht"
  152. $Nv_(PAREA).canvas configure -scrollregion $bbox -width [expr $wid+2]
  153. }
  154. ###################################
  155. # Procedure to hide or reveal panels
  156. ###################################
  157. proc hide_menus { } {
  158. global Nv_
  159. global bit_map_path
  160. if {$Nv_(hidemenus) == "1" } {
  161. set Nv_(hidemenus) 0
  162. $Nv_(PAREA).canvas configure -width 0
  163. $Nv_(PAREA).f1.b1 configure -bitmap @$bit_map_path/right \
  164. -width 12 -height 18 -command "hide_menus"
  165. help $Nv_(PAREA).f1.b1 balloon "Show Panels"
  166. #$Nv_(AREA).menu.config.m entryconfigure 1 -label "Show Panels" -command "show_menus"
  167. } else {
  168. set Nv_(hidemenus) 1
  169. $Nv_(PAREA).canvas configure -width [winfo width $Nv_(P_AREA)]
  170. $Nv_(PAREA).f1.b1 configure -bitmap @$bit_map_path/left \
  171. -width 12 -height 18 -command "hide_menus"
  172. help $Nv_(PAREA).f1.b1 balloon "Hide Panels"
  173. #$Nv_(AREA).menu.config.m entryconfigure 1 -label "Hide Panels" -command "hide_menus"
  174. }
  175. update
  176. }
  177. ###########################################################################
  178. # add key bindings so that menu shortcut keys can be used
  179. ###########################################################################
  180. ###########################################################################
  181. # make toplevel
  182. ###########################################################################
  183. proc Nv_makeGUI {{BASE .}} {
  184. global Nv_ ScriptState src_boot env
  185. global DEBUG
  186. global bit_map_path constrained
  187. #DEBUG
  188. if {$DEBUG} {puts "Build toplevel window"}
  189. set Nv_(First) 1
  190. wm geometry . +100+50
  191. wm minsize . 10 10
  192. wm sizefrom . user
  193. #Use three base frames
  194. frame $Nv_(AREA) -relief flat -bd 0
  195. frame .middle -relief flat -bd 0
  196. frame .bottom -relief flat -bd 0
  197. # DEBUG
  198. if {$DEBUG} {puts "toplevel made"}
  199. ###########################################################################
  200. # make informational text widget
  201. ###########################################################################
  202. set Nv_(text) "Start"
  203. set Nv_(height) 720
  204. #panel area frame
  205. frame $Nv_(PAREA) -relief flat -bd 0
  206. pack $Nv_(PAREA) -side left -fill y -expand no
  207. #togl canvas
  208. frame $Nv_(TOP) -relief groove -bd 2
  209. pack $Nv_(TOP) -side left -fill both -expand yes
  210. entry .bottom.entry -relief sunken -state disabled \
  211. -background #FFFFFF -textvariable Nv_(text)
  212. pack .bottom.entry -side left -fill both -expand yes
  213. set cwidth [exec $src_boot/bin/g.gisenv X3D_WIDTH]
  214. set cheight [exec $src_boot/bin/g.gisenv X3D_HEIGHT]
  215. if {$cwidth > 0 && $cheight > 0} {
  216. togl $Nv_(TOP).canvas -rgba true -double true -depth true \
  217. -width $cwidth -height $cheight
  218. pack $Nv_(TOP).canvas -side top -expand no
  219. } elseif {$cwidth == "" && $cheight > 0} {
  220. togl $Nv_(TOP).canvas -rgba true -double true -depth true \
  221. -height $cheight
  222. pack $Nv_(TOP).canvas -side top -fill x -expand yes
  223. } elseif {$cheight == "" && $cwidth > 0} {
  224. togl $Nv_(TOP).canvas -rgba true -double true -depth true \
  225. -width $cwidth
  226. pack $Nv_(TOP).canvas -side top -fill y -expand yes
  227. } else {
  228. #nothing set
  229. set constrained 1
  230. togl $Nv_(TOP).canvas -rgba true -double true -depth true
  231. pack $Nv_(TOP).canvas -side top -fill both -expand yes
  232. }
  233. bind $Nv_(TOP).canvas <Expose> {Nv_expose %W}
  234. bind $Nv_(TOP).canvas <Configure> {set Nv_(height) %h}
  235. set tags [bindtags $Nv_(TOP).canvas]
  236. # the Togl widget can't be redrawn until the main panel has been created
  237. # update
  238. #With widget made reset ProcessName variable
  239. set env(NV_processname) [winfo name .]
  240. #Moved the following packing here to satisfy some TCL versions
  241. #Prevents minimized GUI
  242. #top frame for menubar
  243. pack $Nv_(AREA) -side top -fill x -expand no
  244. #middle frame for menus and togl canvas
  245. pack .middle -side top -fill both -expand yes
  246. #botom frame for statusbar
  247. pack .bottom -side top -fill x -expand no
  248. # DEBUG
  249. if {$DEBUG} {puts "info widget made"}
  250. ###########################################################################
  251. # make panel area
  252. ###########################################################################
  253. canvas $Nv_(PAREA).canvas -yscrollcommand "$Nv_(PAREA).f1.scrolly set" \
  254. -borderwidth 2 -relief sunken
  255. frame $Nv_(PAREA).f1 -borderwidth 0 -relief flat
  256. scrollbar $Nv_(PAREA).f1.scrolly -command "$Nv_(PAREA).canvas yview"
  257. bind all <MouseWheel> {$Nv_(PAREA).canvas yview scroll [expr -1 * %D] units}
  258. button $Nv_(PAREA).f1.b1 -bitmap @$bit_map_path/left \
  259. -width 12 -height 18 -command "hide_menus"
  260. help $Nv_(PAREA).f1.b1 balloon "Hide Panels"
  261. frame $Nv_(P_AREA) -relief flat
  262. # DEBUG
  263. if {$DEBUG} {puts "panel area made"}
  264. ###########################################################################
  265. # make menubar
  266. ###########################################################################
  267. frame $Nv_(AREA).menu -relief flat -borderwidth 0
  268. #pack $Nv_(AREA).menu -side top -fill x -expand no
  269. pack $Nv_(PAREA).canvas -side top -fill both -expand yes
  270. pack $Nv_(PAREA).f1 -side left -before $Nv_(PAREA).canvas -fill y
  271. pack $Nv_(PAREA).f1.scrolly -side top -fill y -expand yes
  272. pack $Nv_(PAREA).f1.b1 -side bottom -fill x
  273. pack $Nv_(P_AREA) -side top -fill y -expand yes
  274. # Make label with invisible text to hold "Please wait..." message
  275. label $Nv_(AREA).menu.wait_pls -text "Please Wait..." -fg red -bg black
  276. #Bind menu area to canvas and scrollbars
  277. $Nv_(PAREA).canvas create window 0 0 -window $Nv_(P_AREA) -anchor nw
  278. bind $Nv_(P_AREA) <Configure> "set_scrollsize"
  279. set helpmenu [Nv_mkMenu $Nv_(AREA).menu.help "Help " \
  280. {"NVIZ Help" "About NVIZ" "NVIZ - Bugs / ToDo"} \
  281. {0 0 0} \
  282. {"nviz_browse nviz_toc.html" "nviz_browse nviz_desc.html" "nviz_browse bugs_todo.html"} ]
  283. # #pack $helpmenu -side right -fill none -expand yes -anchor e
  284. # DEBUG
  285. if {$DEBUG} {puts "Help menu made"}
  286. #set Nv_(AREA).menu [frame $Nv_(AREA).menu.left -relief flat -bd 0]
  287. # file menu
  288. set filemenu [Nv_mkMenu $Nv_(AREA).menu.file "File " \
  289. {"Load State ..." "Save State ..." \
  290. "" \
  291. "Set Canvas Size ..."
  292. "" \
  293. "Load 3d Settings ..." "Save 3d Settings ..." \
  294. "" \
  295. "Save image as ..." \
  296. "" \
  297. "Reset" "Quit" } \
  298. {0 0 0 0 0 0 0 0 0 0 0 0} \
  299. { "load_state" "save_state" \
  300. "Separator" \
  301. "set_canvas_size" \
  302. "Separator" \
  303. "load_3dview" "save_3dview" \
  304. "Separator" \
  305. "Cascade img menu2" \
  306. "Separator" \
  307. "reset_Nviz" "Nv_close_scripting ; exit ; puts"}]
  308. # pack $filemenu -side left -fill x -expand no
  309. # DEBUG
  310. if {$DEBUG} {puts "file menu made"}
  311. # Take these out later when these features are more reliable
  312. # $Nv_(AREA).menu.file.m entryconfigure 3 -state disabled
  313. # $Nv_(AREA).menu.file.m entryconfigure 4 -state disabled
  314. # DEBUG
  315. if {$DEBUG} {puts "disabled made"}
  316. # pack [Nv_mkConfigMenu $Nv_(AREA).menu.config] -side left -fill x -expand no
  317. # pack [Nv_mkPanelMenu $Nv_(AREA).menu.panel] -side left -fill x -expand no
  318. # DEBUG
  319. if {$DEBUG} {puts "scripting menu 0 made"}
  320. # Make a menu entry for scripting
  321. set scriptingbtn [menubutton $Nv_(AREA).menu.scripting -text "Scripting " \
  322. -menu $Nv_(AREA).menu.scripting.m -underline 0 ]
  323. set scriptingmenu [menu $Nv_(AREA).menu.scripting.m]
  324. $scriptingmenu add checkbutton -label "On" \
  325. -onvalue 1 -offvalue 0 -variable ScriptState \
  326. -command "script_handle_on"
  327. $scriptingmenu add separator
  328. $scriptingmenu add command -label "Create New Scriptfile" \
  329. -underline 0 -command SetScriptFile
  330. $scriptingmenu add command -label "Open and Play Script" \
  331. -underline 0 -command {set ScriptPlaying 1 ; exec nviz -f $default_panel_path/script_play &}
  332. $scriptingmenu add command -label "Close Script" \
  333. -underline 1 -command Nv_close_scripting
  334. $scriptingmenu add separator
  335. $scriptingmenu add command -label "Add Script Line" \
  336. -underline 0 -command AddScriptLine
  337. $scriptingmenu add command -label "Add Script Command" \
  338. -underline 1 -command AddScriptCmd
  339. $scriptingmenu add separator
  340. $scriptingmenu add command -label "Script Tools" \
  341. -underline 1 -command {exec nviz -f $default_panel_path/script_tools -q &}
  342. set configmenu [Nv_mkConfigMenu $Nv_(AREA).menu.config]
  343. set panelmenu [Nv_mkPanelMenu $Nv_(AREA).menu.panel]
  344. pack $helpmenu -side right -fill none -expand no -anchor e
  345. pack $filemenu $configmenu $panelmenu $scriptingbtn -side left -fill none -expand no -anchor w
  346. # DEBUG
  347. if {$DEBUG} {puts "scripting menu made"}
  348. pack $Nv_(AREA).menu -side left -fill x -expand yes
  349. tk_menuBar $Nv_(AREA).menu
  350. #tk_menuBar $Nv_(AREA).menu $filemenu $Nv_(AREA).menu.panel \
  351. #$scriptingbtn
  352. set Nv_(Q) [Q_init 2]
  353. #pack $Nv_(AREA).menu.wait_pls -side left -fill x -expand yes
  354. # initialize Main panel
  355. Nv_force_panel main
  356. Nv_openPanel main 0
  357. update
  358. # DEBUG
  359. if {$DEBUG} {puts "menubar made"}
  360. raise .bottom
  361. raise .middle
  362. raise $Nv_(AREA)
  363. focus -force $Nv_(AREA).menu
  364. return $BASE
  365. }
  366. proc menu2 { menu } {
  367. menu $menu \
  368. -tearoff 0
  369. $menu add command \
  370. -command dump_ppm -underline 0 -label "PPM Image"
  371. $menu add command \
  372. -command dump_tif -underline 0 -label "TIFF Image"
  373. $menu add command \
  374. -command {set fname [create_file_browser .file_browser 1]
  375. if {$fname != -1} then {
  376. appBusy
  377. # strip .ppm extension if given
  378. if { [string compare [file extension $fname] ".ppm"] == 0 } then {
  379. set fname [file rootname $fname]
  380. }
  381. set wid [winfo screenwidth .]
  382. set ht [winfo screenheight .]
  383. Nstart_zoom $fname $wid $ht
  384. appNotBusy
  385. }
  386. } -underline 0 -label "Maximum Resolution PPM"
  387. }
  388. proc dump_ppm { } {
  389. # This routine should use: Nwrite_ppm $fname
  390. set fname [create_file_browser .file_browser 1]
  391. # show we are busy
  392. appBusy
  393. if {$fname != -1} then {
  394. if { [string compare [file extension $fname] ".ppm"] != 0 } then {
  395. append fname ".ppm"
  396. }
  397. Ndraw_all
  398. Nwrite_ppm $fname
  399. }
  400. # show user can proceed
  401. appNotBusy
  402. }
  403. proc dump_tif { } {
  404. # This routine should use: Nwrite_tif $fname
  405. set fname [create_file_browser .file_browser 1]
  406. # show we are busy
  407. appBusy
  408. if {$fname != -1} then {
  409. if { [string compare [file extension $fname] ".tif"] != 0 } then {
  410. append fname ".tif"
  411. }
  412. Ndraw_all
  413. Nwrite_tif $fname
  414. }
  415. # show user can proceed
  416. appNotBusy
  417. }
  418. ###########################################################################
  419. # null proc
  420. ###########################################################################
  421. proc null {args} {}
  422. #########################################################################
  423. # open panel P.name with routine mkP and place in appropriate spot
  424. #########################################################################
  425. proc Nv_openPanel { name {pos -1}} {
  426. global Nv_
  427. set P $Nv_(P_AREA)
  428. # create panel if it doesn't already exist
  429. set path $P.$name
  430. # if panel has not yet been created ...
  431. # or panel is one that needs updating ...
  432. if {[catch {set panel $Nv_($path)}]} then {
  433. set panel [mk$name\Panel $path]
  434. set Nv_($path) $panel
  435. } elseif {"site" == "$name"} then {
  436. set panel [mk$name\Panel $path]
  437. set Nv_($path) $panel
  438. } elseif {"vect" == "$name"} then {
  439. set panel [mk$name\Panel $path]
  440. set Nv_($path) $panel
  441. } elseif {"sdiff" == "$name"} then {
  442. set panel [mk$name\Panel $path]
  443. set Nv_($path) $panel
  444. }
  445. # if panel is not already mapped ...
  446. if { [lsearch [place slaves $P] $P.$name] < 0 } {
  447. if {$pos < 0} {
  448. Q_add $Nv_(Q) $panel
  449. } else {
  450. Nv_mapPanel $path $panel $pos
  451. }
  452. }
  453. }
  454. #########################################################################
  455. # open config panel P.name with routine mkP and place in appropriate spot
  456. #########################################################################
  457. proc Nv_openConfig { name {pos -1}} {
  458. global Nv_
  459. set P $Nv_(P_AREA)
  460. # create panel if it doesn't already exist
  461. set path $P.$name
  462. # if panel has not yet been created ...
  463. # or panel is one that needs updating ...
  464. if {[catch {set config $Nv_($path)}]} then {
  465. set config [mk$name\Config $path]
  466. set Nv_($path) $config
  467. }
  468. # if panel is not already mapped ...
  469. if { [lsearch [place slaves $P] $P.$name] < 0 } {
  470. if {$pos < 0} {
  471. Q_add $Nv_(Q) $config
  472. } else {
  473. Nv_mapConfig $path $config $pos
  474. }
  475. }
  476. }
  477. ############################################################################
  478. proc Nv_mapPanel {name panel pos } {
  479. #insert update to fix KDE wm problem
  480. update
  481. set size [St_get $panel size]
  482. if [catch {set height [expr $size * .33]}] { set height 1}
  483. if [catch {set y [expr $pos * .33]}] { set y 0}
  484. pack $name -side top -fill x -expand no -anchor n
  485. # set x [winfo x .top2]
  486. # set y [winfo y .top2]
  487. # if {$x && $y} {
  488. # wm geometry .top2 "+$x+$y"
  489. # }
  490. }
  491. ############################################################################
  492. proc Nv_closePanel { name } {
  493. pack forget $name
  494. }
  495. # Simple routine to uniformly close any opened panels
  496. proc Nv_closeAllPanels { } {
  497. global Nv_
  498. set children [pack slaves $Nv_(P_AREA)]
  499. foreach i $children {
  500. if {[regexp main "$i"] != 1} then {
  501. pack forget $i
  502. }
  503. }
  504. }
  505. ############################################################################
  506. # procedure to make PANEL pulldown menu
  507. ###########################################################################
  508. proc Nv_mkPanelMenu { P { name "Visualize " } } {
  509. global Nv_ DEBUG
  510. menubutton $P -text $name -menu $P.m -underline 0
  511. menu $P.m
  512. if {$DEBUG} {puts "Nv_mkPanelMenu 1"}
  513. set j 0
  514. foreach i $Nv_(panels) {
  515. Nv_force_panel $i
  516. set panel $Nv_($Nv_(P_AREA).$i)
  517. $P.m add command -label [St_get $panel name] \
  518. -command "Nv_openPanel $i"
  519. #Add separators
  520. if {$i == "vol" || $i == "pick" || $i == "query"} {
  521. $P.m add separator
  522. }
  523. if {$DEBUG} {puts "Nv_mkPanelMenu 2 $j [St_get $panel name]"}
  524. incr j
  525. }
  526. return $P
  527. }
  528. ############################################################################
  529. # procedure to make CONFIG pulldown menu
  530. ###########################################################################
  531. proc Nv_mkConfigMenu { P { name "Appearance " } } {
  532. global Nv_ DEBUG
  533. menubutton $P -text $name -menu $P.m -underline 0
  534. menu $P.m
  535. if {$DEBUG} {puts "Nv_mkConfigMenu 1"}
  536. set j 0
  537. $P.m add command -label "Hide Panels" -command "hide_menus"
  538. $P.m add separator
  539. foreach i $Nv_(config) {
  540. Nv_force_panel $i
  541. set config $Nv_($Nv_(P_AREA).$i)
  542. $P.m add command -label [St_get $config name] \
  543. -command "Nv_openPanel $i"
  544. if {$DEBUG} {puts "Nv_mkConfigMenu 2 $j [St_get $config name]"}
  545. incr j
  546. }
  547. return $P
  548. }
  549. ###########################################################################
  550. proc inform {args} {
  551. global Nv_
  552. set Nv_(text) ""
  553. foreach S $args {
  554. set Nv_(text) [concat $Nv_(text) $S]
  555. }
  556. }
  557. proc Nv_expose { W } {
  558. global Nv_
  559. global BGColor
  560. if {$Nv_(First)} then {
  561. init_graphics
  562. set Nv_(First) 0
  563. } else {
  564. Nbackground $BGColor
  565. Nquick_draw
  566. }
  567. }
  568. proc save_3dview { dummy } {
  569. # Ask the user for a file name to save in
  570. set file_name [create_map_browser .browse_3dview_file "3d.view" 1]
  571. if {$file_name == -1} then return
  572. Nsave_3dview $file_name
  573. }
  574. proc load_3dview { dummy } {
  575. global XY Nv_ draw_option Nauto_draw
  576. # Ask the user for a file name to load from
  577. set file_name [create_map_browser .browse_3dview_file "3d.view" 1]
  578. if {$file_name == -1} then return
  579. appBusy
  580. # Do not redraw automaticly display while loading state...
  581. set oNauto_draw $Nauto_draw
  582. set Nauto_draw 0
  583. #do a quick draw to make sure display initialized
  584. Nquick_draw
  585. Nload_3dview $file_name
  586. #Reset position GUI
  587. #set ht [lindex [Nget_real_position 1] 2]
  588. # for some strange reason height gets read/loaded from file correctly
  589. # only if view is loaded for second time
  590. # Also currently light related stuff is not updated
  591. set ht [lindex [Nget_height] 0]
  592. set ex [Nget_exag]
  593. set tw [Nget_twist]
  594. set pe [Nget_fov]
  595. #reset height
  596. Nv_setEntry $Nv_(main_BASE).midf.height.f.entry $ht
  597. Nv_floatscaleCallback $Nv_(main_BASE).midf.height e 2 null $ht
  598. # reset exag
  599. Nv_setEntry $Nv_(main_BASE).midf.zexag.f.entry $ex
  600. Nv_floatscaleCallback $Nv_(main_BASE).midf.zexag b 2 Nchange_exag $ex
  601. # reset twist/perspective
  602. Nv_setEntry $Nv_(main_BASE).bframe.cframe.tw.f.entry $tw
  603. Nv_scaleCallback $Nv_(main_BASE).bframe.cframe.tw b 2 Nchange_twist $tw
  604. Nv_setEntry $Nv_(main_BASE).bframe.cframe.pers.f.entry $pe
  605. Nv_scaleCallback $Nv_(main_BASE).bframe.cframe.pers b 2 Nchange_persp $pe
  606. if { $draw_option == 1 } { change_display 0 } \
  607. elseif { $draw_option == 0 } { change_display 1 }
  608. Nquick_draw
  609. appNotBusy
  610. set Nauto_draw $oNauto_draw
  611. }
  612. ########################################
  613. # Procedure to manually set canvas size
  614. proc set_canvas_size { dummy } {
  615. global cwidth cheight constrained Nv_
  616. set cwidth [lindex [$Nv_(TOP).canvas configure -width] 4]
  617. set cheight [lindex [$Nv_(TOP).canvas configure -height] 4]
  618. #Build size box
  619. toplevel .canvas_size
  620. frame .canvas_size.f1 -borderwidth 2 -relief sunken
  621. frame .canvas_size.f2
  622. frame .canvas_size.f3
  623. pack .canvas_size.f3 .canvas_size.f1 .canvas_size.f2 -side top \
  624. -fill both -expand yes
  625. label .canvas_size.f3.l1 -text "Set Size of Display Canvas"
  626. pack .canvas_size.f3.l1 -side top -fill both -expand no
  627. label .canvas_size.f1.l1 -text "Width"
  628. entry .canvas_size.f1.e1 -textvariable cwidth -width 6
  629. label .canvas_size.f1.l2 -text "Height"
  630. entry .canvas_size.f1.e2 -textvariable cheight -width 6
  631. pack .canvas_size.f1.l1 .canvas_size.f1.e1 \
  632. .canvas_size.f1.l2 .canvas_size.f1.e2 \
  633. -side left -fill y
  634. checkbutton .canvas_size.f2.c1 -text "Unconstrained" -variable constrained \
  635. -onvalue 1 -offvalue 0 -command {
  636. if {$constrained} {
  637. .canvas_size.f1.e1 configure -state disabled -bg grey
  638. .canvas_size.f1.e2 configure -state disabled -bg grey
  639. } else {
  640. .canvas_size.f1.e1 configure -state normal -bg white
  641. .canvas_size.f1.e2 configure -state normal -bg white
  642. }
  643. }
  644. button .canvas_size.f2.b1 -text "Close" \
  645. -command {
  646. if {$constrained} {
  647. pack $Nv_(TOP).canvas -side top -fill both -expand yes
  648. } else {
  649. $Nv_(TOP).canvas configure -width $cwidth -height $cheight
  650. pack $Nv_(TOP).canvas -side top -expand no -fill none
  651. #Need Nset_viewport to make sure reshape is called
  652. Nset_viewport $cwidth $cheight
  653. }
  654. destroy .canvas_size}
  655. if {$constrained} {
  656. .canvas_size.f1.e1 configure -state disabled -bg grey
  657. .canvas_size.f1.e2 configure -state disabled -bg grey
  658. }
  659. pack .canvas_size.f2.c1 -side left -fill both
  660. pack .canvas_size.f2.b1 -side right -fill both
  661. }
  662. # Procedure to load the state of the system, calls a special
  663. # load procedure for each panel in the system.
  664. proc load_state { dummy } {
  665. global Nv_
  666. # First open a file for reading in the state
  667. set new_file [create_file_browser .state_file 1 0]
  668. if {$new_file == -1} then return
  669. # show that we are busy
  670. appBusy
  671. load_state_aux $new_file
  672. # show that we aren't busy anymore
  673. appNotBusy
  674. }
  675. #Procedure to load NVIZ HTML pages
  676. proc nviz_browse { URL dummy } {
  677. global env
  678. exec -- $env(GRASS_HTML_BROWSER) file://$env(GISBASE)/docs/html/nviz/$URL &
  679. }
  680. proc load_state_aux { new_file} {
  681. global Nv_
  682. if {[catch {set file_hook [open $new_file r]} error_code] != 0} then {
  683. display_error "While opening file: $error_code"
  684. return
  685. }
  686. # Close all panels fist
  687. Nv_closeAllPanels
  688. # First line before panel data is marked by ">>>start [name]", where
  689. # [name] is the name of the panel which saved the data.
  690. # Use this name to build the command which will load the state. Then
  691. # continue to read the state file until the next section of panel data.
  692. while {[gets $file_hook i] != -1} {
  693. if {[lindex [split $i] 0] == ">>>start"} {
  694. set paneltype [lindex [split $i] 1]
  695. set cmd_name "Nviz_$paneltype"
  696. append cmd_name "_load"
  697. if {[catch {$cmd_name $file_hook} error_code] != 0} then {
  698. puts "Diagnostic: $error_code -- Load procedure for panel $i may not be defined"
  699. }
  700. } else {
  701. continue
  702. }
  703. }
  704. # Finally, close the file and exit
  705. close $file_hook
  706. # Go through each of the panels one at a time and force them to open
  707. # This should update them all so they display correctly
  708. foreach i $Nv_(config) {
  709. Nv_openPanel $i
  710. update
  711. }
  712. foreach i $Nv_(panels) {
  713. Nv_openPanel $i
  714. update
  715. }
  716. Nv_closeAllPanels
  717. return 1
  718. }
  719. # Procedure to completely reset nviz, calls a special reset procedure
  720. # in each panel in the system
  721. proc reset_Nviz { dummy } {
  722. global Nv_
  723. # Query user to verify this choice
  724. if {[tk_dialog .reset_all "Reset" \
  725. "Really reset Nviz?" {} 1 "Ok" "Cancel"] == 1} then return
  726. # Show that we are busy
  727. appBusy
  728. # Now call each of the panels one at a time and pass the
  729. # file hook so that each panel can write out its state
  730. set tmp_list $Nv_(panels)
  731. lappend tmp_list main
  732. foreach i $Nv_(panels) {
  733. set cmd_name "Nviz_$i"
  734. append cmd_name "_reset"
  735. if {[catch {$cmd_name} error_code] != 0} then {
  736. puts "Diagnostic: $error_code -- Reset procedure for panel $i may not be defined"
  737. }
  738. }
  739. foreach i $Nv_(config) {
  740. set cmd_name "Nviz_$i"
  741. append cmd_name "_reset"
  742. if {[catch {$cmd_name} error_code] != 0} then {
  743. puts "Diagnostic: $error_code -- Reset procedure for panel $i may not be defined"
  744. }
  745. }
  746. # Go through each of the panels one at a time and force them to open
  747. # This should update them all so they display correctly
  748. foreach i $Nv_(panels) {
  749. Nv_openPanel $i
  750. update
  751. }
  752. foreach i $Nv_(config) {
  753. Nv_openPanel $i
  754. update
  755. }
  756. Nv_closeAllPanels
  757. # Show that user may proceed
  758. appNotBusy
  759. }
  760. # This routine is equivalent to the one above except it skips alot of
  761. # the user interface BS
  762. proc reset_nviz_aux { } {
  763. global Nv_
  764. # Now call each of the panels one at a time and pass the
  765. # file hook so that each panel can write out its state
  766. set tmp_list $Nv_(panels)
  767. lappend tmp_list main
  768. foreach i $tmp_list {
  769. set cmd_name "Nviz_$i"
  770. append cmd_name "_reset"
  771. if {[catch {$cmd_name} error_code] != 0} then {
  772. puts "Diagnostic: $error_code -- Reset procedure for panel $i may not be defined"
  773. }
  774. }
  775. foreach i $Nv_(config) {
  776. set cmd_name "Nviz_$i"
  777. append cmd_name "_reset"
  778. if {[catch {$cmd_name} error_code] != 0} then {
  779. puts "Diagnostic: $error_code -- Reset procedure for panel $i may not be defined"
  780. }
  781. }
  782. # Go through each of the panels one at a time and force them to open
  783. # This should update them all so they display correctly
  784. foreach i $Nv_(panels) {
  785. Nv_openPanel $i
  786. update
  787. }
  788. foreach i $Nv_(config) {
  789. Nv_openPanel $i
  790. update
  791. }
  792. Nv_closeAllPanels
  793. }
  794. # Procedure to save the state of the system, calls a special
  795. # save procedure for each panel in the system.
  796. proc save_state { dummy } {
  797. global Nv_
  798. # First open a file for writing out the state
  799. set new_file [create_file_browser .state_file 1 0]
  800. if {$new_file == -1} then return
  801. # append ".nviz" extension to the filename if it doesn't already have one
  802. if { [string compare [file extension $new_file] ".nviz"] != 0 } then {
  803. append new_file ".nviz"
  804. }
  805. if {[catch {set file_hook [open $new_file w]} error_code] != 0} then {
  806. display_error "While opening file: $error_code"
  807. return
  808. }
  809. # Show that we are busy
  810. appBusy
  811. # Now call each of the panels one at a time and pass the
  812. # file hook so that each panel can write out its state
  813. foreach i $Nv_(panelstate) {
  814. set cmd_name "Nviz_$i"
  815. append cmd_name "_save"
  816. if {[catch {$cmd_name $file_hook} error_code] != 0} then {
  817. puts "Diagnostic: $error_code -- Save procedure for panel $i may not be defined"
  818. }
  819. }
  820. # Finally, close the file and exit
  821. close $file_hook
  822. # Show that user may proceed
  823. appNotBusy
  824. }
  825. ###################################################
  826. # Routine to display error
  827. ###################################################
  828. proc display_error { err_string } {
  829. tk_dialog .file_error "File Error" "$err_string" \
  830. error 0 "Dismiss"
  831. }
  832. # Set the cancel function for drawing
  833. Nset_cancel_func update
  834. # and start the ball rolling...
  835. Nv_makeGUI $Nv_(AREA)
  836. # Center the view on initialization
  837. look_center
  838. # *********************************************************************
  839. # ************* Additional Keyframe Animator Channels *****************
  840. # *********************************************************************
  841. # Add cutplane 0 to the keyframe animator
  842. # Create the cutplane entry list
  843. global Nv_
  844. set Nv_(CutPlaneFence) OFF
  845. set entry_list [list [list pos_x dynamic] [list pos_y dynamic] [list pos_z dynamic]]
  846. lappend entry_list [list blend_type static]
  847. lappend entry_list [list rot dynamic] [list tilt dynamic]
  848. keyanimAddChannel $Nv_(P_AREA).kanimator "cplane-0" $entry_list \
  849. cutplane0_get_entries cutplane0_set_entries
  850. # Undo the "Please wait..." message
  851. update
  852. catch {destroy .wait_ok}
  853. # *********************************************************************
  854. # Automatically load state file from command line
  855. # *********************************************************************
  856. if {[catch {set NvizLoadState}] == 0} then {
  857. global Nv_
  858. appBusy
  859. load_state_aux $NvizLoadState
  860. appNotBusy
  861. }
  862. if {$DEBUG} {puts "Finished loading, call draw all"}
  863. Ndraw_all
  864. # *********************************************************************
  865. # Automatics command line script playing functions
  866. # *********************************************************************
  867. # If the -script option was used then we need to immediately start a script
  868. # We kill Nviz after the script has finished playing
  869. if {[catch {set NvizPlayScript}] == 0} then {
  870. global NvizPlayScript NvizPlayScriptProcess ScriptPlaying
  871. global NvizScriptKill
  872. set ScriptPlaying 1
  873. set NvizPlayScriptProcess [exec nviz -f $default_panel_path/script_play $NvizPlayScript &]
  874. if {[catch {set NvizScriptKill}] == 0} then {
  875. after 5000 CheckScriptDone
  876. }
  877. }
  878. proc CheckScriptDone {} {
  879. global NvizPlayScriptProcess
  880. set answer [catch {exec ps -p $NvizPlayScriptProcess | grep $NvizPlayScriptProcess}]
  881. puts "Done check = $answer"
  882. if {$answer == 1} then {
  883. exit
  884. }
  885. after 5000 CheckScriptDone
  886. }