r.li.setup.main 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. #!/bin/sh
  2. #
  3. # This program is free software under the GPL (>=v2)
  4. # Read the COPYING file that comes with GRASS for details.
  5. # the next line restarts using wish \
  6. exec $GRASS_WISH "$0" "$@"
  7. lappend auto_path $env(GISBASE)/bwidget
  8. package require -exact BWidget 1.2.1
  9. if {[info exists env(OS)] && $env(OS) == "Windows_NT"} {
  10. set mingw "1"
  11. } else {
  12. set mingw "0"
  13. }
  14. # Include the select dialog code because it defines scroll bindings
  15. source $env(GISBASE)/etc/gtcltk/select.tcl
  16. source $env(GISBASE)/etc/gtcltk/gmsg.tcl
  17. # setting environment variables
  18. set env(GISDBASE) [exec g.gisenv get=GISDBASE]
  19. set env(LOCATION_NAME) [exec g.gisenv get=LOCATION_NAME]
  20. set env(MAPSET) [exec g.gisenv get=MAPSET]
  21. #home directory
  22. set env(HOME) [exec printenv HOME]
  23. #name for temporary files
  24. set env(TMP) [pid]
  25. #name of configuration file
  26. set env(CONF) ""
  27. #name of raster map to use
  28. set env(RASTER) ""
  29. #name of vector map to overlay
  30. set env(VECTOR) ""
  31. #name of site file to overlay
  32. set env(SITE) ""
  33. #X coordinate in cells of sampling frame
  34. set env(SF_X) ""
  35. #Y coordinate in cells of sampling frame
  36. set env(SF_Y) ""
  37. #length in rows of sampling frame
  38. set env(SF_RL) ""
  39. #length in columns of sampling frame
  40. set env(SF_CL) ""
  41. #raster map north-south resolution
  42. set env(SF_NSRES) ""
  43. #raster map easth-west resolution
  44. set env(SF_EWRES) ""
  45. #north boundary of sampling frame
  46. set env(SF_N) ""
  47. #south boundary of sampling frame
  48. set env(SF_S) ""
  49. #easth boundary of sampling frame
  50. set env(SF_E) ""
  51. #west boundary of sampling frame
  52. set env(SF_W) ""
  53. #path of r.li source directory
  54. set env(F_PATH) $env(GISBASE)/etc/r.li.setup
  55. #length in rows of keyboard setted circle
  56. set env(CIR_RL) ""
  57. #lenght in columns of keyboard setted circle
  58. set env(CIR_CL) ""
  59. #file for map browsing
  60. source $env(GISBASE)/etc/gtcltk/select.tcl
  61. #procedures
  62. source $env(F_PATH)/r.li.setup.procedures.tcl
  63. #other windows
  64. source $env(F_PATH)/r.li.windows.tcl
  65. #Create sampling area window
  66. proc setupSamplingArea {widget} {
  67. global env
  68. global win
  69. set win $widget
  70. frame $widget.samplingArea
  71. #wm title .samplingArea "\[r.li.setup\] Setup sampling area"
  72. #wm minsize .samplingArea 350 200
  73. pack $widget.samplingArea
  74. #insert top label
  75. label $widget.samplingArea.topLabel -text "Define sampling areas"
  76. pack $widget.samplingArea.topLabel -side top -pady 10
  77. #choice selection
  78. frame $widget.samplingArea.choice
  79. pack $widget.samplingArea.choice
  80. set selection ""
  81. radiobutton $widget.samplingArea.choice.whole -text "Whole maplayer" -relief flat -variable selection -value whole -width 40 -anchor w
  82. radiobutton $widget.samplingArea.choice.regions -text "Regions" -relief flat -variable selection -value regions -width 40 -anchor w
  83. radiobutton $widget.samplingArea.choice.units -text "Sample units" -relief flat -variable selection -value units -width 40 -anchor w
  84. radiobutton $widget.samplingArea.choice.window -text "Moving window" -relief flat -variable selection -value window -width 40 -anchor w
  85. set vectorAreas [exec cat $env(TMP).set | grep "SAMPLINGFRAME" | tail -n 1 | cut -f2 -d " "]
  86. if { $vectorAreas == "0|0|1|1"} then {
  87. #inserting select areas from the overlayed vector map
  88. radiobutton $widget.samplingArea.choice.vector -text "Select areas from the overlayed vector map" -relief flat -variable selection -value vector -width 40 -anchor w
  89. pack $widget.samplingArea.choice.whole $widget.samplingArea.choice.regions $widget.samplingArea.choice.units $widget.samplingArea.choice.window $widget.samplingArea.choice.vector
  90. } else {
  91. pack $widget.samplingArea.choice.whole $widget.samplingArea.choice.regions $widget.samplingArea.choice.units $widget.samplingArea.choice.window
  92. }
  93. $widget.samplingArea.choice.whole select
  94. # buttons
  95. frame $widget.samplingArea.buttons -relief flat
  96. pack $widget.samplingArea.buttons
  97. button $widget.samplingArea.buttons.ok -text "Ok" -command {
  98. defineSamplingArea $selection $win.samplingArea
  99. $win.samplingArea.buttons.ok configure -state disabled
  100. }
  101. pack $widget.samplingArea.buttons.ok
  102. }
  103. #Create sampling frame window
  104. proc setupSamplingFrame {widget} {
  105. global win
  106. set win $widget
  107. frame $widget.samplingFrame
  108. #wm title .samplingFrame "\[r.li.setup\] Setup sampling frame"
  109. #wm minsize .samplingFrame 350 200
  110. pack $widget.samplingFrame
  111. #insert top label
  112. label $widget.samplingFrame.topLabel -text "Define a sampling frame (region for analysis)"
  113. pack $widget.samplingFrame.topLabel -side top -pady 10
  114. frame $widget.samplingFrame.choice -relief flat
  115. pack $widget.samplingFrame.choice
  116. # choice selection
  117. set selection ""
  118. radiobutton $widget.samplingFrame.choice.whole -text "Whole maplayer" -relief flat -variable selection -value whole -width 25 -anchor w
  119. radiobutton $widget.samplingFrame.choice.keyboard -text "Keyboard setting" -relief flat -variable selection -value keyboard -width 25 -anchor w
  120. radiobutton $widget.samplingFrame.choice.mouse -text "Draw the sampling frame" -relief flat -variable selection -value mouse -width 25 -anchor w
  121. pack $widget.samplingFrame.choice.whole $widget.samplingFrame.choice.keyboard $widget.samplingFrame.choice.mouse
  122. $widget.samplingFrame.choice.whole select
  123. # buttons
  124. frame $widget.samplingFrame.buttons -relief flat
  125. pack $widget.samplingFrame.buttons
  126. button $win.samplingFrame.buttons.ok -text "Ok" -command {
  127. defineSamplingFrame $selection $win.samplingFrame.buttons.ok
  128. set en [$win.samplingFrame.buttons.ok cget -state]
  129. if { $en == "disabled" } then {
  130. $win.buttons.s_area configure -state normal
  131. }
  132. }
  133. pack $widget.samplingFrame.buttons.ok
  134. }
  135. #Create new configuration file window
  136. proc createNewConfiguration {} {
  137. global env
  138. # new popup window
  139. toplevel .newConf
  140. wm title .newConf "\[r.li.setup\] Create new Configuration"
  141. bind .newConf <Destroy> {
  142. exec rm -f $env(TMP).set
  143. exec rm -f *.tmp
  144. destroy .newConf
  145. openDir .files "~/.grass7/r.li"
  146. }
  147. # insert top label
  148. label .newConf.topLabel -text "Insert new sampling area settings"
  149. pack .newConf.topLabel -side top
  150. # frame with config file name, raster map, vector and site to overlay
  151. frame .newConf.frame -relief flat
  152. pack .newConf.frame -side top -fill y -anchor center
  153. set names {{} {Configuration file name:} {Raster map to use to select areas:} {[Vector map to overlay:]}\
  154. {[Site file to overlay:]} }
  155. label .newConf.frame.label1 -text [lindex $names 1] -anchor e
  156. entry .newConf.frame.entry1 -width 35 -textvariable env(CONF)
  157. grid .newConf.frame.label1 .newConf.frame.entry1 -sticky ew -pady 2 -padx 1
  158. label .newConf.frame.label2 -text [lindex $names 2] -anchor e
  159. entry .newConf.frame.entry2 -width 35 -textvariable env(RASTER)
  160. button .newConf.frame.button2 -text "Browse" -command {
  161. set env(RASTER) [GSelect cell]
  162. }
  163. grid .newConf.frame.label2 .newConf.frame.entry2 .newConf.frame.button2 -sticky ew -pady 2 -padx 1
  164. label .newConf.frame.label3 -text [lindex $names 3] -anchor e
  165. entry .newConf.frame.entry3 -width 35 -textvariable env(VECTOR)
  166. button .newConf.frame.button3 -text "Browse" -command {
  167. set env(VECTOR) [GSelect vector]
  168. }
  169. grid .newConf.frame.label3 .newConf.frame.entry3 .newConf.frame.button3 -sticky ew -pady 2 -padx 1
  170. label .newConf.frame.label4 -text [lindex $names 4] -anchor e
  171. entry .newConf.frame.entry4 -width 35 -textvariable env(SITE)
  172. button .newConf.frame.button4 -text "Browse" -command {
  173. set env(SITE) [GSelect vector]
  174. }
  175. grid .newConf.frame.label4 .newConf.frame.entry4 .newConf.frame.button4 -sticky ew -pady 2 -padx 1
  176. # insert buttons
  177. frame .newConf.buttons -relief flat
  178. pack .newConf.buttons -side bottom -anchor center -pady 2
  179. button .newConf.buttons.save -text "Save settings" -state disabled -command {
  180. saveSettings .newConf
  181. }
  182. button .newConf.buttons.s_area -text "Setup sampling areas" -state disabled -command {
  183. setupSamplingArea .newConf
  184. .newConf.buttons.save configure -state active
  185. .newConf.buttons.s_area configure -state disabled
  186. }
  187. button .newConf.buttons.s_frame -text "Setup sampling frame" -command {
  188. setupSamplingFrame .newConf
  189. .newConf.buttons.s_frame configure -state disabled
  190. }
  191. grid .newConf.buttons.s_frame .newConf.buttons.s_area .newConf.buttons.save -pady 20
  192. }
  193. #procedure to set sampling units
  194. proc setSampleUnits {widget} {
  195. global setSampleUnits
  196. set setSampleUnits $widget
  197. #new popup windows
  198. frame $widget.newUni
  199. pack $widget.newUni
  200. #new labels
  201. label $widget.newUni.toplabel -text "Select an option : "
  202. pack $widget.newUni.toplabel -side top
  203. #new frame for load an existing map
  204. frame $widget.newUni.frame
  205. pack $widget.newUni.frame -fill both -anchor center
  206. #new frame buttons
  207. frame $widget.newUni.button
  208. pack $widget.newUni.button -side left -anchor w
  209. #buttons
  210. button $widget.newUni.button.b2 -text " Use keyboard to enter sampling units dimension " -width 50 -command {
  211. setKeyboardUnit
  212. $setSampleUnits.newUni.button.b2 configure -state disabled
  213. $setSampleUnits.newUni.button.b3 configure -state disabled
  214. }
  215. pack $widget.newUni.button.b2 -side top -padx 3 -pady 3
  216. button $widget.newUni.button.b3 -text " Use mouse to draw sampling units " -width 50 -command {
  217. setMouseUnits $setSampleUnits
  218. $setSampleUnits.newUni.button.b2 configure -state disabled
  219. $setSampleUnits.newUni.button.b3 configure -state disabled
  220. }
  221. pack $widget.newUni.button.b3 -side top -padx 3
  222. }
  223. #procedure to set moving windows
  224. proc setMovWindow {widget} {
  225. global setMovWindow
  226. set setMovWindow $widget
  227. #new popup windows
  228. frame $widget.newWin
  229. pack $widget.newWin
  230. #new labels
  231. label $widget.newWin.toplabel -text "Select an option : "
  232. pack $widget.newWin.toplabel -side top
  233. #new frame for load an existing map
  234. frame $widget.newWin.frame
  235. pack $widget.newWin.frame -fill both -anchor center
  236. #new frame buttons
  237. frame $widget.newWin.button
  238. pack $widget.newWin.button -side left -anchor w
  239. #buttons
  240. button $widget.newWin.button.b2 -text " Use keyboard to enter moving window dimension " -width 50 -command {
  241. setKeyboardWindow
  242. $setMovWindow.newWin.button.b2 configure -state disabled
  243. $setMovWindow.newWin.button.b3 configure -state disabled
  244. }
  245. pack $widget.newWin.button.b2 -side top -padx 3 -pady 3
  246. button $widget.newWin.button.b3 -text " Use mouse to draw the moving windows " -width 50 -command {
  247. setMouseWindow $setMovWindow
  248. $setMovWindow.newWin.button.b2 configure -state disabled
  249. $setMovWindow.newWin.button.b3 configure -state disabled
  250. }
  251. pack $widget.newWin.button.b3 -side top -padx 3
  252. }
  253. #draw sampling regions
  254. proc setSampleRegions {widget} {
  255. global globWin
  256. set globWin $widget
  257. frame $widget.regions
  258. pack $widget.regions
  259. frame $widget.regions.grid
  260. pack $widget.regions.grid
  261. label $widget.regions.grid.lnumber -text "Enter the number of region to draw"
  262. entry $widget.regions.grid.enumber -width 10 -textvariable number
  263. grid $widget.regions.grid.lnumber $widget.regions.grid.enumber
  264. frame $widget.regions.buttons
  265. pack $widget.regions.buttons
  266. button $widget.regions.buttons.ok -text Ok -command {
  267. if { [catch { exec printf %i $number } ] } then {
  268. tk_messageBox -message "Please type an integer value for the number of regions" -icon error -type ok
  269. } else {
  270. drawRegions $number
  271. $globWin.regions.buttons.ok configure -state disabled
  272. }
  273. }
  274. pack $widget.regions.buttons.ok
  275. }
  276. ##################################################
  277. #MAIN WINDOW
  278. ##################################################
  279. # create directories
  280. catch { exec mkdir $env(HOME)/.grass7/r.li }
  281. bind . <Control-c> {
  282. exec rm -f $env(TMP).set
  283. destroy .
  284. }
  285. bind . <Destroy> {
  286. exec rm -f $env(TMP).set
  287. destroy .
  288. }
  289. # create tree label
  290. label .filesLabel -text "Available sampling area configuration files"
  291. pack .filesLabel -side top
  292. # create history tree view
  293. listbox .files -selectmode single
  294. pack .files -side right -expand 1 -fill both -padx 7 -pady 7
  295. # show configuration files in ~/.grass7/r.li
  296. openDir .files "~/.grass7/r.li"
  297. #create load button
  298. button .l -text "Load" -width 8 -command {
  299. set selection [.files get active ]
  300. if { $selection != "" } then {
  301. loadConfiguration $selection
  302. }
  303. }
  304. pack .l
  305. #create new button
  306. button .new -text "New" -width 8 -command {
  307. createNewConfiguration
  308. }
  309. pack .new
  310. # create remove button
  311. button .r -text "Remove" -width 8 -command {
  312. global env
  313. set selection [.files get active]
  314. if { $selection =="" } then {
  315. tk_messageBox -message "No file to remove." -type ok -icon error} else {
  316. # new popup windows
  317. toplevel .removeconf
  318. wm title .removeconf "\[r.li.setup\] Remove Window"
  319. # new top label
  320. label .removeconf.topLabel -text "Are You sure to remove the ' $selection ' file ?"
  321. pack .removeconf.topLabel -side top
  322. # create new frame
  323. frame .removeconf.buttons -relief flat
  324. pack .removeconf.buttons -side top -fill y -anchor center
  325. # create yes button
  326. button .removeconf.buttons.y -text "Yes" -width 8 -command {
  327. if { [ catch { exec rm $env(HOME)/.grass7/r.li/$selection } ] } then {
  328. tk_messageBox -message "'$selection' Not deleted" -type ok -icon error} else {
  329. tk_messageBox -message "$selection deleted" -type ok
  330. openDir .files "~/.grass7/r.li"
  331. destroy .removeconf}
  332. }
  333. # create no button
  334. button .removeconf.buttons.n -text "No" -width 8 -command { destroy .removeconf
  335. openDir .files "~/.grass7/r.li"}
  336. grid .removeconf.buttons.y .removeconf.buttons.n
  337. }
  338. }
  339. pack .r
  340. #create help button
  341. button .h -text "Help" -width 8 -command {
  342. if { $mingw == "1" } {
  343. exec -- $env(GRASS_HTML_BROWSER) file://$env(GISBASE)/docs/html/r.li.setup.html &;
  344. } else {
  345. exec -- $env(GRASS_HTML_BROWSER) file://$env(GISBASE)/docs/html/r.li.setup.html >@stdout 2>@stderr &;
  346. }
  347. }
  348. pack .h
  349. #create close button
  350. button .c -text "Close" -width 8 -command {
  351. destroy .
  352. }
  353. pack .c