vector.tcl 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. ##########################################################################
  2. # vector.tcl - vector display layer options file for GRASS GIS Manager
  3. # March 2006 Michael Barton, Arizona State University
  4. # COPYRIGHT: (C) 1999 - 2006 by the GRASS Development Team
  5. #
  6. # This program is free software under the GNU General Public
  7. # License (>=v2). Read the file COPYING that comes with GRASS
  8. # for details.
  9. #
  10. ##########################################################################
  11. namespace eval GmVector {
  12. variable array opt # vector current options
  13. variable count 1
  14. variable array lfile # vector
  15. variable array lfilemask # vector
  16. variable optlist
  17. variable array dup # vector
  18. }
  19. ###############################################################################
  20. # set dynamic legend display in layer tree for vectors
  21. proc GmVector::legend { id } {
  22. variable opt
  23. set lh $GmTree::legend_height
  24. set lw $GmTree::legend_width
  25. set mar 2
  26. set leg $opt($id,1,_legend)
  27. $leg delete all
  28. # area
  29. if { $opt($id,1,type_area) || $opt($id,1,type_face)} {
  30. set x1 [expr $mar ]
  31. set x2 [expr {$lw - $mar} ]
  32. set y1 [expr $mar ]
  33. set y2 [expr {$lh - $mar} ]
  34. set lwidth $opt($id,1,lwidth)
  35. if { $lwidth == 0 } { set lwidth 1 }
  36. if {$opt($id,1,_use_color) == 1} {
  37. if {$opt($id,1,_use_fcolor) == 1} {
  38. $leg create rectangle $x1 $y1 $x2 $y2 -outline $opt($id,1,color) \
  39. -fill $opt($id,1,fcolor) -width $lwidth
  40. } else {
  41. $leg create rectangle $x1 $y1 $x2 $y2 -outline $opt($id,1,color) \
  42. -width $lwidth
  43. }
  44. } else {
  45. if {$opt($id,1,_use_fcolor) == 1} {
  46. $leg create rectangle $x1 $y1 $x2 $y2 -fill $opt($id,1,fcolor) \
  47. -width 0
  48. }
  49. }
  50. }
  51. #line
  52. if { $opt($id,1,type_line) || $opt($id,1,type_boundary) } {
  53. set x1 [expr $mar ]
  54. set x2 [expr {$lw - $mar} ]
  55. set y1 [expr $mar ]
  56. set y2 [expr {$lh - $mar} ]
  57. set lwidth $opt($id,1,lwidth)
  58. if { $lwidth == 0 } { set lwidth 1 }
  59. if {$opt($id,1,_use_color) == 1} {
  60. $leg create rectangle $x1 $y1 $x2 $y2 -outline $opt($id,1,color) \
  61. -width $lwidth
  62. }
  63. }
  64. # point
  65. set xc [expr {$lw / 2 + $mar - 1} ]
  66. set yc [expr {$lh / 2} ]
  67. set size $opt($id,1,size)
  68. set maxpsize [expr {$lw / 3 - 2} ]
  69. if { $size > $maxpsize } { set size $maxpsize }
  70. set x1 [expr {$xc - $size / 2} ]
  71. set x2 [expr {$xc + $size / 2 + 1} ]
  72. set y1 [expr {$yc - $size / 2 }]
  73. set y2 [expr {$yc + $size / 2 + 1} ]
  74. if { $opt($id,1,type_point) || $opt($id,1,type_centroid) } {
  75. set lwidth $opt($id,1,lwidth)
  76. if { $lwidth == 0 } { set lwidth 1 }
  77. $leg create line $x1 $yc $x2 $yc -fill $opt($id,1,color) -width $lwidth
  78. $leg create line $xc $y1 $xc $y2 -fill $opt($id,1,color) -width $lwidth
  79. }
  80. set opt($id,1,mod) "1"
  81. }
  82. ###############################################################################
  83. # create new vector layer
  84. proc GmVector::create { tree parent } {
  85. variable optlist
  86. variable lfile
  87. variable lfilemask
  88. variable opt
  89. variable count
  90. variable dup
  91. set node "vector:$count"
  92. set frm [ frame .vectoricon$count]
  93. set check [checkbutton $frm.check \
  94. -variable GmVector::opt($count,1,_check) \
  95. -height 1 -padx 0 -width 0]
  96. set can [ canvas $frm.c -width $GmTree::legend_width \
  97. -height $GmTree::legend_height ]
  98. set opt($count,1,_legend) $can
  99. pack $check $can -side left
  100. bind $can <ButtonPress-1> "GmTree::selectn $tree $node"
  101. #insert new layer
  102. if {[$tree selection get] != "" } {
  103. set sellayer [$tree index [$tree selection get]]
  104. } else {
  105. set sellayer "end"
  106. }
  107. $tree insert $sellayer $parent $node \
  108. -text "vector $count" \
  109. -window $frm \
  110. -drawcross auto
  111. set dup($count) 0
  112. set opt($count,1,_check) 1
  113. set opt($count,1,vect) ""
  114. set opt($count,1,opacity) 1.0
  115. set opt($count,1,display_shape) 1
  116. set opt($count,1,display_cat) 0
  117. set opt($count,1,display_topo) 0
  118. set opt($count,1,display_dir) 0
  119. set opt($count,1,display_attr) 0
  120. set opt($count,1,type_point) 1
  121. set opt($count,1,type_line) 1
  122. set opt($count,1,type_boundary) 1
  123. set opt($count,1,type_centroid) 0
  124. set opt($count,1,type_area) 1
  125. set opt($count,1,type_face) 0
  126. set opt($count,1,color) \#000000
  127. set opt($count,1,sqlcolor) 0
  128. set opt($count,1,rdmcolor) 0
  129. set opt($count,1,fcolor) \#AAAAAA
  130. set opt($count,1,lcolor) \#000000
  131. set opt($count,1,_use_color) 1
  132. set opt($count,1,_use_fcolor) 1
  133. set opt($count,1,lwidth) 1
  134. set opt($count,1,symdir) "basic"
  135. set opt($count,1,icon) "basic/circle"
  136. set opt($count,1,size) 5
  137. set opt($count,1,layer) 1
  138. set opt($count,1,lfield) 1
  139. set opt($count,1,cat) ""
  140. set opt($count,1,where) ""
  141. set opt($count,1,_use_where) 1
  142. set opt($count,1,qmap) ""
  143. set opt($count,1,qsave) 0
  144. set opt($count,1,qoverwrite) 0
  145. set opt($count,1,attribute) ""
  146. set opt($count,1,xref) "left"
  147. set opt($count,1,yref) "center"
  148. set opt($count,1,lsize) 8
  149. set opt($count,1,minreg) ""
  150. set opt($count,1,maxreg) ""
  151. set opt($count,1,mod) 1
  152. set optlist { _check vect opacity display_shape display_cat display_topo display_dir \
  153. display_attr type_point type_line type_boundary type_centroid \
  154. type_area type_face color _use_color fcolor _use_fcolor lcolor \
  155. rdmcolor sqlcolor icon size lwidth layer lfield attribute \
  156. xref yref lsize cat where _use_where qmap qsave qoverwrite \
  157. minreg maxreg}
  158. foreach key $optlist {
  159. set opt($count,0,$key) $opt($count,1,$key)
  160. }
  161. GmVector::legend $count
  162. # create files in tmp diretory for layer output
  163. set mappid [pid]
  164. if {[catch {set lfile($count) [exec g.tempfile pid=$mappid]} error]} {
  165. GmLib::errmsg $error [G_msg "Error creating tempfile"]
  166. }
  167. set lfilemask($count) $lfile($count)
  168. append lfile($count) ".ppm"
  169. append lfilemask($count) ".pgm"
  170. incr count
  171. return $node
  172. }
  173. ###############################################################################
  174. proc GmVector::set_option { node key value } {
  175. variable opt
  176. set id [GmTree::node_id $node]
  177. set opt($id,1,$key) $value
  178. GmVector::legend $id
  179. }
  180. ###############################################################################
  181. # select vector map from list and put its name in layer node
  182. proc GmVector::select_map { id } {
  183. set m [GSelect vector title [G_msg "Vector map"] parent "."]
  184. if { $m != "" } {
  185. set GmVector::opt($id,1,vect) $m
  186. GmTree::autonamel $m
  187. }
  188. }
  189. # select vector for output map from v.extract
  190. proc GmVector::select_qmap { id } {
  191. set m [GSelect vector title [G_msg "Vector output map"] parent "."]
  192. if { $m != "" } {
  193. set GmVector::opt($id,1,qmap) $m
  194. GmTree::autonamel $m
  195. }
  196. }
  197. ###############################################################################
  198. # show attribute columns in output window
  199. proc GmVector::show_columns { id } {
  200. variable opt
  201. set mapname $opt($id,1,vect)
  202. set layernum $opt($id,1,layer)
  203. set cmd "v.info -c map=$mapname layer=$layernum"
  204. run_panel $cmd
  205. }
  206. ###############################################################################
  207. # show attribute data in output window
  208. proc GmVector::show_data { id } {
  209. variable opt
  210. set mapname $opt($id,1,vect)
  211. set layernum $opt($id,1,layer)
  212. if {![catch {open "|v.db.connect map=$mapname layer=$layernum -g" r} vdb]} {
  213. set vectdb [read $vdb]
  214. if {[catch {close $vdb} error]} {
  215. GmLib::errmsg $error
  216. }
  217. set vdblist [split $vectdb " "]
  218. set tbl [lindex $vdblist 1]
  219. set db [lindex $vdblist 3]
  220. set drv [lindex $vdblist 4]
  221. set cmd "db.select table=$tbl database=$db driver=$drv"
  222. run_panel $cmd
  223. }
  224. }
  225. ###############################################################################
  226. # show vector info in output window
  227. proc GmVector::show_info { id } {
  228. variable opt
  229. set mapname $opt($id,1,vect)
  230. set layernum $opt($id,1,layer)
  231. set cmd "v.info map=$mapname layer=$layernum"
  232. run_panel $cmd
  233. }
  234. ###############################################################################
  235. # select point symbols
  236. proc GmVector::select_symbol { id } {
  237. variable opt
  238. set i [GSelect symbol title [G_msg "Vector point symbol"] parent "."]
  239. if { $i != "" } {
  240. set GmVector::opt($id,1,icon) $i
  241. }
  242. }
  243. ###############################################################################
  244. # display and set vector options
  245. proc GmVector::options { id frm } {
  246. variable opt
  247. global bgcolor
  248. global iconpath
  249. set mapname ""
  250. # Panel heading
  251. set row [ frame $frm.heading ]
  252. Label $row.a -text [G_msg "Display vector maps"] \
  253. -fg MediumBlue
  254. pack $row.a -side left
  255. pack $row -side top -fill both -expand yes
  256. #opacity
  257. set row [ frame $frm.opc]
  258. Label $row.a -text [G_msg "Opaque "]
  259. scale $row.b -from 1.0 -to 0.0 -showvalue 1 \
  260. -orient horizontal -length 300 -resolution 0.01 -fg "#656565"\
  261. -variable GmVector::opt($id,1,opacity)
  262. Label $row.c -text [G_msg "Transparent"]
  263. pack $row.a $row.b $row.c -side left
  264. pack $row -side top -fill both -expand yes
  265. # vector name
  266. set row [ frame $frm.name ]
  267. Label $row.a -text [G_msg "Vector map:"]
  268. Button $row.b -image [image create photo -file "$iconpath/element-vector.gif"] \
  269. -highlightthickness 0 -takefocus 0 -relief raised -borderwidth 1 \
  270. -helptext [G_msg "vector map to display"] \
  271. -command "GmVector::select_map $id"
  272. Entry $row.c -width 35 -text "$opt($id,1,vect)" \
  273. -textvariable GmVector::opt($id,1,vect)
  274. Label $row.d -text ""
  275. Button $row.e -text [G_msg "Vector Info"] \
  276. -image [image create photo -file "$iconpath/gui-rv.info.gif"] \
  277. -command "GmVector::show_info $id" \
  278. -background $bgcolor \
  279. -helptext [G_msg "Vector Info"]
  280. Label $row.f -text ""
  281. Button $row.g -text [G_msg "Help"] \
  282. -image [image create photo -file "$iconpath/gui-help.gif"] \
  283. -command "spawn g.manual --q d.vect" \
  284. -background $bgcolor \
  285. -helptext [G_msg "Help"]
  286. pack $row.a $row.b $row.c $row.d $row.e $row.f $row.g -side left
  287. pack $row -side top -fill both -expand yes
  288. # display
  289. set row [ frame $frm.disp ]
  290. Label $row.a -text [G_msg "Display: "]
  291. checkbutton $row.b -text [G_msg "Shapes "] -variable GmVector::opt($id,1,display_shape) \
  292. -command "GmVector::legend $id"
  293. checkbutton $row.c -text [G_msg "Categories "] -variable GmVector::opt($id,1,display_cat) \
  294. -command "GmVector::legend $id"
  295. checkbutton $row.d -text [G_msg "Topology "] -variable GmVector::opt($id,1,display_topo) \
  296. -command "GmVector::legend $id"
  297. checkbutton $row.e -text [G_msg "Line directions "] -variable GmVector::opt($id,1,display_dir) \
  298. -command "GmVector::legend $id"
  299. pack $row.a $row.b $row.c $row.d $row.e -side left
  300. pack $row -side top -fill both -expand yes
  301. # type
  302. set row [ frame $frm.type ]
  303. Label $row.a -text " "
  304. checkbutton $row.b -text [G_msg "Points "] -variable GmVector::opt($id,1,type_point) \
  305. -command "GmVector::legend $id"
  306. checkbutton $row.c -text [G_msg "Lines "] -variable GmVector::opt($id,1,type_line) \
  307. -command "GmVector::legend $id"
  308. checkbutton $row.d -text [G_msg "Boundaries "] -variable GmVector::opt($id,1,type_boundary) \
  309. -command "GmVector::legend $id"
  310. checkbutton $row.e -text [G_msg "Areas "] -variable GmVector::opt($id,1,type_area) \
  311. -command "GmVector::legend $id"
  312. checkbutton $row.f -text [G_msg "Centroids "] -variable GmVector::opt($id,1,type_centroid)\
  313. -command "GmVector::legend $id"
  314. checkbutton $row.g -text [G_msg "Faces "] -variable GmVector::opt($id,1,type_face) \
  315. -command "GmVector::legend $id"
  316. pack $row.a $row.b $row.c $row.d $row.e $row.f $row.g -side left
  317. pack $row -side top -fill both -expand yes
  318. # points
  319. set row [ frame $frm.icon ]
  320. Label $row.a -text [G_msg "Point symbols:"]
  321. Button $row.b -text [G_msg "Icon"] \
  322. -command "GmVector::select_symbol $id"
  323. Entry $row.c -width 15 -text "$opt($id,1,icon)" \
  324. -textvariable GmVector::opt($id,1,icon)
  325. Label $row.d -text [G_msg " Size"]
  326. SpinBox $row.e -range {1 50 1} -textvariable GmVector::opt($id,1,size) \
  327. -width 2 -helptext [G_msg "Icon size"] -modifycmd "GmVector::legend $id"
  328. pack $row.a $row.b $row.c $row.d $row.e -side left
  329. pack $row -side top -fill both -expand yes
  330. # lines
  331. set row [ frame $frm.color ]
  332. Label $row.a -text [G_msg "Draw lines:"]
  333. checkbutton $row.b -variable GmVector::opt($id,1,_use_color) \
  334. -command "GmVector::legend $id"
  335. Label $row.c -text [G_msg "Color"]
  336. SelectColor $row.d -type menubutton -variable GmVector::opt($id,1,color) \
  337. -command "GmVector::legend $id"
  338. Label $row.e -text [G_msg " Width"]
  339. SpinBox $row.f -range {0 50 1} -textvariable GmVector::opt($id,1,lwidth) \
  340. -width 2 -helptext [G_msg "Line width"] \
  341. -modifycmd "GmVector::legend $id"
  342. Label $row.g -text [G_msg "(pixels) "]
  343. pack $row.a $row.b $row.c $row.d $row.e $row.f $row.g -side left
  344. pack $row -side top -fill both -expand yes
  345. # fills
  346. set row [ frame $frm.multicolor ]
  347. Label $row.a -text [G_msg "Fill areas:"]
  348. checkbutton $row.b -variable GmVector::opt($id,1,_use_fcolor) \
  349. -command "GmVector::legend $id"
  350. Label $row.c -text [G_msg "Color"]
  351. SelectColor $row.d -type menubutton -variable GmVector::opt($id,1,fcolor) \
  352. -command "GmVector::legend $id"
  353. Label $row.e -text " "
  354. checkbutton $row.f -text [G_msg "Random colors "] -variable GmVector::opt($id,1,rdmcolor) \
  355. -command "GmVector::legend $id"
  356. checkbutton $row.g -text [G_msg "GRASSRGB column colors"] -variable GmVector::opt($id,1,sqlcolor) \
  357. -command "GmVector::legend $id"
  358. pack $row.a $row.b $row.c $row.d $row.e $row.f $row.g -side left
  359. pack $row -side top -fill both -expand yes
  360. # labels
  361. set row [ frame $frm.label1 ]
  362. Label $row.a -text [G_msg "Label vectors:"]
  363. checkbutton $row.b -text [G_msg "label"] -variable GmVector::opt($id,1,display_attr) \
  364. -command "GmVector::legend $id"
  365. Label $row.c -text [G_msg " Text color"]
  366. SelectColor $row.d -type menubutton -variable GmVector::opt($id,1,lcolor) \
  367. -command "GmVector::legend $id"
  368. Label $row.e -text [G_msg " Text size"]
  369. SpinBox $row.f -range {1 50 1} -textvariable GmVector::opt($id,1,lsize) \
  370. -width 2 -helptext [G_msg "text size"] \
  371. -modifycmd "GmVector::legend $id"
  372. pack $row.a $row.b $row.c $row.d $row.e $row.f -side left
  373. pack $row -side top -fill both -expand yes
  374. # label alighment
  375. set row [ frame $frm.label2 ]
  376. Label $row.a -text " "
  377. ComboBox $row.b -label [G_msg "Label part to align with vector point"] \
  378. -width 6 -textvariable GmVector::opt($id,1,xref) \
  379. -values {"left" "center" "right"} \
  380. -modifycmd "GmVector::legend $id"
  381. ComboBox $row.c -label [G_msg " Justification"] \
  382. -width 6 -textvariable GmVector::opt($id,1,yref) \
  383. -values {"top" "center" "bottom"} \
  384. -modifycmd "GmVector::legend $id"
  385. pack $row.a $row.b $row.c -side left
  386. pack $row -side top -fill both -expand yes
  387. # labels layer and attribute column
  388. set row [ frame $frm.label3 ]
  389. LabelEntry $row.a -label [G_msg " Layer for labels"] \
  390. -textvariable GmVector::opt($id,1,lfield) -width 3
  391. LabelEntry $row.b -label [G_msg " Attribute col for labels"] \
  392. -textvariable GmVector::opt($id,1,attribute) -width 23
  393. pack $row.a $row.b -side left
  394. pack $row -side top -fill both -expand yes
  395. # query
  396. set row [ frame $frm.query1 ]
  397. Label $row.a -text [G_msg "Query vectors for display: "]
  398. LabelEntry $row.b -label [G_msg "layer for query"] \
  399. -textvariable GmVector::opt($id,1,layer) -width 3
  400. pack $row.a $row.b -side left
  401. pack $row -side top -fill both -expand yes
  402. # query cat
  403. set row [ frame $frm.query2 ]
  404. Label $row.a -text " "
  405. LabelEntry $row.b -label [G_msg "Query cat values"] \
  406. -textvariable GmVector::opt($id,1,cat) \
  407. -width 40
  408. pack $row.a $row.b -side left
  409. pack $row -side top -fill both -expand yes
  410. # sql query
  411. set row [ frame $frm.where ]
  412. Label $row.a -text " "
  413. checkbutton $row.b -variable GmVector::opt($id,1,_use_where) \
  414. -command "GmVector::legend $id"
  415. LabelEntry $row.c -label [G_msg "Use SQL query"] \
  416. -textvariable GmVector::opt($id,1,where) \
  417. -width 40
  418. pack $row.a $row.b $row.c -side left
  419. pack $row -side top -fill both -expand yes
  420. #show columns and data
  421. set row [ frame $frm.columns ]
  422. Label $row.a -text [G_msg " Show attribute columns"]
  423. Button $row.b -text [G_msg "columns"] \
  424. -image [image create photo -file "$iconpath/db-columns.gif"] \
  425. -command "GmVector::show_columns $id" \
  426. -background $bgcolor -borderwidth 1\
  427. -helptext [G_msg "Show columns"]
  428. Label $row.c -text [G_msg " Show attribute data"]
  429. Button $row.d -text [G_msg "data"] \
  430. -image [image create photo -file "$iconpath/db-values.gif"] \
  431. -command "GmVector::show_data $id" \
  432. -background $bgcolor -borderwidth 1\
  433. -helptext [G_msg "Show data"]
  434. pack $row.a $row.b $row.c $row.d -side left
  435. pack $row -side top -fill both -expand yes
  436. # save query to new vector file
  437. set row [ frame $frm.qsave ]
  438. Label $row.a -text " "
  439. checkbutton $row.b -text [G_msg "Save displayed objects to new vector file "] \
  440. -variable GmVector::opt($id,1,qsave)
  441. checkbutton $row.c -text [G_msg "Overwrite existing"] \
  442. -variable GmVector::opt($id,1,qoverwrite)
  443. pack $row.a $row.b $row.c -side left
  444. pack $row -side top -fill both -expand yes
  445. # save query vector name
  446. set row [ frame $frm.qname ]
  447. Label $row.a -text [G_msg " New vector"]
  448. Button $row.b -image [image create photo -file "$iconpath/element-vector.gif"] \
  449. -highlightthickness 0 -takefocus 0 -relief raised -borderwidth 1 \
  450. -command "GmVector::select_qmap $id" \
  451. -helptext [G_msg "Select existing vector for saving queried objects"]
  452. Entry $row.c -width 40 -text "$opt($id,1,qmap)" \
  453. -textvariable GmVector::opt($id,1,qmap)
  454. pack $row.a $row.b $row.c -side left
  455. pack $row -side top -fill both -expand yes
  456. # display only in limited region size range
  457. set row [ frame $frm.region ]
  458. Label $row.a -text [G_msg "Display when avg. region dimension is"]
  459. LabelEntry $row.b -label ">" -textvariable GmVector::opt($id,1,minreg) \
  460. -width 8
  461. LabelEntry $row.c -label [G_msg " or <"] -textvariable GmVector::opt($id,1,maxreg) \
  462. -width 8
  463. pack $row.a $row.b $row.c -side left
  464. pack $row -side top -fill both -expand yes
  465. }
  466. ###############################################################################
  467. # save layer in workspace file
  468. proc GmVector::save { tree depth node } {
  469. variable opt
  470. variable optlist
  471. set id [GmTree::node_id $node]
  472. foreach key $optlist {
  473. GmTree::rc_write $depth "$key $opt($id,1,$key)"
  474. }
  475. }
  476. ###############################################################################
  477. # append vector maps to display list for NVIZ display
  478. proc GmVector::addvect {node} {
  479. variable opt
  480. variable tree
  481. global mon
  482. set tree($mon) $GmTree::tree($mon)
  483. set id [GmTree::node_id $node]
  484. if { ! ( $opt($id,1,_check) ) } { return }
  485. set vect $opt($id,1,vect)
  486. return $vect
  487. }
  488. # set vector type for NVIZ display
  489. proc GmVector::vecttype { vect } {
  490. global devnull
  491. set string ""
  492. set points 0
  493. set rest ""
  494. if {![catch {open "|v.info map=$vect 2> $devnull" r} rv]} {
  495. set vinfo [read $rv]
  496. if {[catch {close $rv} error]} {
  497. GmLib::errmsg $error
  498. }
  499. if { $vinfo == "" } {return}
  500. regexp {points: (\d*)} $vinfo string points
  501. if { $points > 0} {
  502. set vecttype "points"
  503. } else {
  504. set vecttype "lines"
  505. }
  506. return $vecttype
  507. } else {
  508. puts $rv
  509. return
  510. }
  511. }
  512. ###############################################################################
  513. # display vector map and output to graphic file for compositing
  514. proc GmVector::display { node mod } {
  515. global mon
  516. variable optlist
  517. variable lfile
  518. variable lfilemask
  519. variable opt
  520. variable tree
  521. variable dup
  522. variable count
  523. set tree($mon) $GmTree::tree($mon)
  524. set id [GmTree::node_id $node]
  525. # If we are told dirty (for zoom) force dirty
  526. # Don't remove a dirty from a previous unrendered zoom
  527. if {$mod} {set opt($id,1,mod) 1}
  528. if { $opt($id,1,vect) == "" } { return }
  529. if { !$opt($id,1,display_shape) && !$opt($id,1,display_cat) &&
  530. !$opt($id,1,display_topo) && !$opt($id,1,display_dir) &&
  531. !$opt($id,1,display_attr) } { return }
  532. if { !$opt($id,1,type_point) && !$opt($id,1,type_line) &&
  533. !$opt($id,1,type_boundary) && !$opt($id,1,type_centroid) &&
  534. !$opt($id,1,type_area) && !$opt($id,1,type_face) } { return }
  535. set cmd "d.vect map=$opt($id,1,vect)"
  536. set cmd2 "v.extract input=$opt($id,1,vect) output=$opt($id,1,qmap)"
  537. # color
  538. if { $opt($id,1,rdmcolor) } { append cmd " -c" }
  539. if { $opt($id,1,sqlcolor) } { append cmd " -a" }
  540. set color [GmLib::color $opt($id,1,color)]
  541. set fcolor [GmLib::color $opt($id,1,fcolor)]
  542. set lcolor [GmLib::color $opt($id,1,lcolor)]
  543. if { $opt($id,1,_use_color) } { append cmd " color=$color" } { append cmd " color=none" }
  544. append cmd " lcolor=$lcolor"
  545. if { $opt($id,1,_use_fcolor) } { append cmd " fcolor=$fcolor" } { append cmd " fcolor=none" }
  546. # display
  547. set dlist [list]
  548. foreach d { shape cat topo dir } {
  549. if { $opt($id,1,display_$d) } { lappend dlist $d }
  550. }
  551. if { $opt($id,1,display_attr) && $opt($id,1,attribute) != "" } { lappend dlist attr }
  552. set display [join $dlist , ]
  553. append cmd " display=$display"
  554. # type
  555. set tlist [list]
  556. foreach t { point line boundary centroid area face } {
  557. if { $opt($id,1,type_$t) } { lappend tlist $t }
  558. }
  559. set type [join $tlist , ]
  560. append cmd " type=$type"
  561. append cmd2 " type=$type"
  562. append cmd " icon=$opt($id,1,icon) size=$opt($id,1,size)"
  563. if { $opt($id,1,lwidth) != 1 } {
  564. append cmd " width=$opt($id,1,lwidth)"
  565. }
  566. if { $opt($id,1,layer) != "" } {
  567. append cmd " layer=$opt($id,1,layer)"
  568. append cmd2 " layer=$opt($id,1,layer)"
  569. }
  570. if { $opt($id,1,attribute) != "" && $opt($id,1,display_attr) } {
  571. append cmd " {att=$opt($id,1,attribute)}"
  572. }
  573. append cmd " lsize=$opt($id,1,lsize)"
  574. append cmd " xref=$opt($id,1,xref) yref=$opt($id,1,yref)"
  575. if { $opt($id,1,lfield) != "" } {
  576. append cmd " llayer=$opt($id,1,lfield)"
  577. }
  578. if { $opt($id,1,cat) != "" } {
  579. append cmd " cat=$opt($id,1,cat)"
  580. append cmd2 " list=$opt($id,1,cat)"
  581. }
  582. if { $opt($id,1,where) != "" && $opt($id,1,_use_where) } {
  583. append cmd " {where=$opt($id,1,where)}"
  584. append cmd2 " {where=$opt($id,1,where)}"
  585. }
  586. if { $opt($id,1,minreg) != "" } {
  587. append cmd " minreg=$opt($id,1,minreg)"
  588. }
  589. if { $opt($id,1,maxreg) != "" } {
  590. append cmd " maxreg=$opt($id,1,maxreg)"
  591. }
  592. if { $opt($id,1,qoverwrite) == 1 } {
  593. append cmd2 " --o"
  594. }
  595. # use v.extract to save queried vector - will not go into redraw
  596. if { $opt($id,1,qsave) == 1 && $opt($id,1,qmap) != "" } {
  597. run_panel $cmd2
  598. }
  599. # Decide whether to run, run command, and copy files to temp
  600. GmCommonLayer::display_command [namespace current] $id $cmd
  601. }
  602. ###############################################################################
  603. # get selected vector map (used for query)
  604. proc GmVector::mapname { node } {
  605. variable opt
  606. variable tree
  607. global mon
  608. set tree($mon) $GmTree::tree($mon)
  609. set id [GmTree::node_id $node]
  610. if { $opt($id,1,vect) == "" } { return ""}
  611. set mapname $opt($id,1,vect)
  612. return $mapname
  613. }
  614. ###############################################################################
  615. # digitize selected map (v.digit) and show currently displayed maps as background
  616. proc GmVector::WorkOnVector { node mod } {
  617. variable opt
  618. variable bg
  619. variable tree
  620. global mon
  621. global env
  622. set tree($mon) $GmTree::tree($mon)
  623. set id [GmTree::node_id $node]
  624. if { ! ( $opt($id,1,_check) ) } { return }
  625. if { $opt($id,1,vect) == "" } { return }
  626. if {[GmLib::element_exists "vector" $opt($id,1,vect)]} {
  627. set cmd [list v.digit "map=$opt($id,1,vect)"]
  628. } else {
  629. set cmd [list v.digit -n "map=$opt($id,1,vect)"]
  630. }
  631. set bg_command [GmGroup::vdigit_display "vector:$id"]
  632. if {$bg_command != ""} {
  633. append cmd " {bgcmd=$bg_command}"
  634. }
  635. spawn_panel $cmd
  636. }
  637. ###############################################################################
  638. # duplicate currently selected vector node
  639. proc GmVector::duplicate { tree parent node id } {
  640. variable optlist
  641. variable lfile
  642. variable lfilemask
  643. variable opt
  644. variable count
  645. variable dup
  646. set node "vector:$count"
  647. set dup($count) 1
  648. set frm [ frame .vectoricon$count]
  649. set check [checkbutton $frm.check \
  650. -variable GmVector::opt($count,1,_check) \
  651. -height 1 -padx 0 -width 0]
  652. set can [ canvas $frm.c -width $GmTree::legend_width \
  653. -height $GmTree::legend_height -borderwidth 0 ]
  654. set opt($count,1,_legend) $can
  655. pack $check $can -side left
  656. bind $can <ButtonPress-1> "GmTree::selectn $tree $node"
  657. #insert new layer
  658. if {[$tree selection get] != "" } {
  659. set sellayer [$tree index [$tree selection get]]
  660. } else {
  661. set sellayer "end"
  662. }
  663. if { $opt($id,1,vect) == ""} {
  664. $tree insert $sellayer $parent $node \
  665. -text "vector $count" \
  666. -window $frm \
  667. -drawcross auto
  668. } else {
  669. $tree insert $sellayer $parent $node \
  670. -text "$opt($id,1,vect)" \
  671. -window $frm \
  672. -drawcross auto
  673. }
  674. set opt($count,1,opacity) $opt($id,1,opacity)
  675. set optlist { _check vect display_shape display_cat display_topo display_dir \
  676. display_attr type_point type_line type_boundary type_centroid \
  677. type_area type_face color _use_color fcolor _use_fcolor lcolor \
  678. rdmcolor sqlcolor icon size lwidth layer lfield attribute \
  679. xref yref lsize cat where _use_where qmap qsave qoverwrite \
  680. minreg maxreg minreg maxreg}
  681. foreach key $optlist {
  682. set opt($count,1,$key) $opt($id,1,$key)
  683. set opt($count,0,$key) $opt($count,1,$key)
  684. }
  685. GmVector::legend $count
  686. set id $count
  687. # create files in tmp directory for layer output
  688. set mappid [pid]
  689. if {[catch {set lfile($count) [exec g.tempfile pid=$mappid]} error]} {
  690. GmLib::errmsg $error [G_msg "Error creating tempfile"]
  691. }
  692. set lfilemask($count) $lfile($count)
  693. append lfile($count) ".ppm"
  694. append lfilemask($count) ".pgm"
  695. incr count
  696. return $node
  697. }