commonlayer.tcl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. ##########################################################################
  2. #
  3. # commonlayer.tcl
  4. #
  5. # Common layer code for GIS Manager: GUI for GRASS 6
  6. # Authors: Cedric Shock
  7. # Based in part on histogram.tcl of GIS Manager
  8. #
  9. # April 2006
  10. #
  11. # COPYRIGHT: (C) 1999 - 2006 by 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. # Common layer code for gis.m
  19. # This is code that happens in the namespace of the layer that,
  20. # except for namespace, is the same for many types of layers.
  21. # It could also be code that is just shared in common.
  22. namespace eval GmCommonLayer {
  23. #pass
  24. }
  25. # Import variables from a namespace into the current stack frame:
  26. proc namespace_import_variables {namespace args} {
  27. foreach arg $args {
  28. uplevel "upvar 0 ${namespace}::$arg $arg"
  29. }
  30. }
  31. # Display some things on the canvas
  32. # (actually just run the command, copy its result to the temporary
  33. # directory and add it to the compositing list)
  34. proc GmCommonLayer::display_commands {namespace id cmds} {
  35. global mon
  36. global commandlist
  37. namespace_import_variables $namespace lfile lfilemask opt optlist dup first
  38. set mapfile($mon) $MapCanvas::mapfile($mon)
  39. set maskfile($mon) $MapCanvas::maskfile($mon)
  40. if {[info exists $mapfile($mon)] == ""} {return}
  41. if {![info exists first]} {set first 0}
  42. # There's no point in doing any of this unless the layer is actually on
  43. if {! $opt($id,1,_check) } {
  44. return 0
  45. }
  46. if {![info exists opt($id,1,mod)]} {
  47. set opt($id,1,mod) 0
  48. }
  49. # check to see if options have changed
  50. foreach key $optlist {
  51. if {$opt($id,0,$key) != $opt($id,1,$key)} {
  52. set opt($id,1,mod) 1
  53. set opt($id,0,$key) $opt($id,1,$key)
  54. }
  55. }
  56. # if options have changed (or mod flag set by other procedures) re-render map
  57. if {$opt($id,1,mod) == 1 || $dup($id) == 1 || $first == 1} {
  58. foreach cmd $cmds {
  59. if {$cmd != ""} {
  60. run_panel $cmd
  61. }
  62. }
  63. # work around MS-Windows TclTk bug:
  64. # file rename -force returns bad code.
  65. catch {file delete $lfile($id)}
  66. catch {file delete $lfilemask($id)}
  67. catch {file rename -force $mapfile($mon) $lfile($id)}
  68. catch {file rename -force $maskfile($mon) $lfilemask($id)}
  69. # reset options changed flag
  70. set opt($id,1,mod) 0
  71. set dup($id) 0
  72. set first 0
  73. }
  74. if {![file exists $lfile($id)]} {return}
  75. #add lfile, maskfile, and opacity to compositing lists
  76. if {$MapCanvas::complist($mon) != "" } {
  77. append MapCanvas::complist($mon) ","
  78. append MapCanvas::complist($mon) [file tail $lfile($id)]
  79. } else {
  80. append MapCanvas::complist($mon) [file tail $lfile($id)]
  81. }
  82. if {$MapCanvas::masklist($mon) != "" } {
  83. append MapCanvas::masklist($mon) ","
  84. append MapCanvas::masklist($mon) [file tail $lfilemask($id)]
  85. } else {
  86. append MapCanvas::masklist($mon) [file tail $lfilemask($id)]
  87. }
  88. if {$MapCanvas::opclist($mon) != "" } {
  89. append MapCanvas::opclist($mon) ","
  90. append MapCanvas::opclist($mon) $opt($id,1,opacity)
  91. } else {
  92. append MapCanvas::opclist($mon) $opt($id,1,opacity)
  93. }
  94. # create list of commands for current display
  95. # used for v.digit background, but could be used for other things
  96. append commandlist " $cmds"
  97. }
  98. # Display something on the canvas
  99. proc GmCommonLayer::display_command {namespace id cmd} {
  100. GmCommonLayer::display_commands $namespace $id [list $cmd]
  101. }