toolbars.py 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321
  1. """
  2. @package vdigit.toolbars
  3. @brief wxGUI vector digitizer toolbars
  4. List of classes:
  5. - toolbars::VDigitToolbar
  6. (C) 2007-2015 by the GRASS Development Team
  7. This program is free software under the GNU General Public License
  8. (>=v2). Read the file COPYING that comes with GRASS for details.
  9. @author Martin Landa <landa.martin gmail.com>
  10. @author Stepan Turek <stepan.turek seznam.cz> (handlers support)
  11. """
  12. import wx
  13. from grass import script as grass
  14. from grass.pydispatch.signal import Signal
  15. from gui_core.toolbars import BaseToolbar, BaseIcons
  16. from gui_core.dialogs import CreateNewVector, VectorDialog
  17. from gui_core.wrap import PseudoDC, Menu
  18. from vdigit.preferences import VDigitSettingsDialog
  19. from core.debug import Debug
  20. from core.settings import UserSettings
  21. from core.gcmd import GError, RunCommand
  22. from icons.icon import MetaIcon
  23. from core.giface import Notification
  24. class VDigitToolbar(BaseToolbar):
  25. """Toolbar for digitization"""
  26. def __init__(self, parent, toolSwitcher, MapWindow, digitClass, giface, tools=[]):
  27. self.MapWindow = MapWindow
  28. self.Map = MapWindow.GetMap() # Map class instance
  29. self.tools = tools
  30. self.digitClass = digitClass
  31. BaseToolbar.__init__(self, parent, toolSwitcher)
  32. self.digit = None
  33. self._giface = giface
  34. self.fType = None # feature type for simple features editing
  35. self.editingStarted = Signal("VDigitToolbar.editingStarted")
  36. self.editingStopped = Signal("VDigitToolbar.editingStopped")
  37. self.editingBgMap = Signal("VDigitToolbar.editingBgMap")
  38. self.quitDigitizer = Signal("VDigitToolbar.quitDigitizer")
  39. self.openATM = Signal("VDigitToolbar.openATM")
  40. layerTree = self._giface.GetLayerTree()
  41. if layerTree:
  42. self.editingStarted.connect(layerTree.StartEditing)
  43. self.editingStopped.connect(layerTree.StopEditing)
  44. self.editingBgMap.connect(layerTree.SetBgMapForEditing)
  45. # bind events
  46. self.Bind(wx.EVT_SHOW, self.OnShow)
  47. # currently selected map layer for editing (reference to MapLayer
  48. # instance)
  49. self.mapLayer = None
  50. # list of vector layers from Layer Manager (only in the current mapset)
  51. self.layers = []
  52. self.comboid = self.combo = None
  53. self.undo = -1
  54. self.redo = -1
  55. # only one dialog can be open
  56. self.settingsDialog = None
  57. # create toolbars (two rows optionally)
  58. self.InitToolbar(self._toolbarData())
  59. self._default = -1
  60. # default action (digitize new point, line, etc.)
  61. self.action = {"desc": "", "type": "", "id": -1}
  62. self._currentAreaActionType = None
  63. # list of available vector maps
  64. self.UpdateListOfLayers(updateTool=True)
  65. for tool in (
  66. "addPoint",
  67. "addLine",
  68. "addBoundary",
  69. "addCentroid",
  70. "addArea",
  71. "addVertex",
  72. "deleteLine",
  73. "deleteArea",
  74. "displayAttr",
  75. "displayCats",
  76. "editLine",
  77. "moveLine",
  78. "moveVertex",
  79. "removeVertex",
  80. "additionalTools",
  81. ):
  82. if hasattr(self, tool):
  83. tool = getattr(self, tool)
  84. self.toolSwitcher.AddToolToGroup(
  85. group="mouseUse", toolbar=self, tool=tool
  86. )
  87. else:
  88. Debug.msg(1, "%s skipped" % tool)
  89. # custom button for digitization of area/boundary/centroid
  90. # TODO: could this be somehow generalized?
  91. nAreaTools = 0
  92. if self.tools and "addBoundary" in self.tools:
  93. nAreaTools += 1
  94. if self.tools and "addCentroid" in self.tools:
  95. nAreaTools += 1
  96. if self.tools and "addArea" in self.tools:
  97. nAreaTools += 1
  98. if nAreaTools != 1:
  99. self.areaButton = self.CreateSelectionButton(
  100. _("Select area/boundary/centroid tool")
  101. )
  102. self.areaButtonId = self.InsertControl(5, self.areaButton)
  103. self.areaButton.Bind(wx.EVT_BUTTON, self.OnAddAreaMenu)
  104. # realize toolbar
  105. self.Realize()
  106. # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
  107. if self.combo:
  108. self.combo.Hide()
  109. self.combo.Show()
  110. # disable undo/redo
  111. if self.undo > 0:
  112. self.EnableTool(self.undo, False)
  113. if self.redo > 0:
  114. self.EnableTool(self.redo, False)
  115. self.FixSize(width=105)
  116. def _toolbarData(self):
  117. """Toolbar data"""
  118. data = []
  119. self.icons = {
  120. "addPoint": MetaIcon(
  121. img="point-create",
  122. label=_("Digitize new point"),
  123. desc=_("Left: new point"),
  124. ),
  125. "addLine": MetaIcon(
  126. img="line-create",
  127. label=_("Digitize new line"),
  128. desc=_(
  129. "Left: new point; Ctrl+Left: undo last point; Right: close line"
  130. ),
  131. ),
  132. "addBoundary": MetaIcon(
  133. img="boundary-create",
  134. label=_("Digitize new boundary"),
  135. desc=_(
  136. "Left: new point; Ctrl+Left: undo last point; Right: close line"
  137. ),
  138. ),
  139. "addCentroid": MetaIcon(
  140. img="centroid-create",
  141. label=_("Digitize new centroid"),
  142. desc=_("Left: new point"),
  143. ),
  144. "addArea": MetaIcon(
  145. img="polygon-create",
  146. label=_("Digitize new area (boundary without category)"),
  147. desc=_("Left: new point"),
  148. ),
  149. "addVertex": MetaIcon(
  150. img="vertex-create",
  151. label=_("Add new vertex to line or boundary"),
  152. desc=_("Left: Select; Ctrl+Left: Unselect; Right: Confirm"),
  153. ),
  154. "deleteLine": MetaIcon(
  155. img="line-delete",
  156. label=_(
  157. "Delete selected point(s), line(s), boundary(ies) or centroid(s)"
  158. ),
  159. desc=_("Left: Select; Ctrl+Left: Unselect; Right: Confirm"),
  160. ),
  161. "deleteArea": MetaIcon(
  162. img="polygon-delete",
  163. label=_("Delete selected area(s)"),
  164. desc=_("Left: Select; Ctrl+Left: Unselect; Right: Confirm"),
  165. ),
  166. "displayAttr": MetaIcon(
  167. img="attributes-display",
  168. label=_("Display/update attributes"),
  169. desc=_("Left: Select"),
  170. ),
  171. "displayCats": MetaIcon(
  172. img="cats-display",
  173. label=_("Display/update categories"),
  174. desc=_("Left: Select"),
  175. ),
  176. "editLine": MetaIcon(
  177. img="line-edit",
  178. label=_("Edit selected line/boundary"),
  179. desc=_(
  180. "Left: new point; Ctrl+Left: undo last point; Right: close line"
  181. ),
  182. ),
  183. "moveLine": MetaIcon(
  184. img="line-move",
  185. label=_(
  186. "Move selected point(s), line(s), boundary(ies) or centroid(s)"
  187. ),
  188. desc=_("Left: Select; Ctrl+Left: Unselect; Right: Confirm"),
  189. ),
  190. "moveVertex": MetaIcon(
  191. img="vertex-move",
  192. label=_("Move selected vertex"),
  193. desc=_("Left: Select; Ctrl+Left: Unselect; Right: Confirm"),
  194. ),
  195. "removeVertex": MetaIcon(
  196. img="vertex-delete",
  197. label=_("Remove selected vertex"),
  198. desc=_("Left: Select; Ctrl+Left: Unselect; Right: Confirm"),
  199. ),
  200. "settings": BaseIcons["settings"],
  201. "quit": BaseIcons["quit"].SetLabel(
  202. label=_("Quit"), desc=_("Quit digitizer and save changes")
  203. ),
  204. "help": BaseIcons["help"].SetLabel(
  205. desc=_("Show Vector Digitizer manual"),
  206. ),
  207. "additionalTools": MetaIcon(
  208. img="tools",
  209. label=_("Additional tools " "(copy, flip, connect, etc.)"),
  210. desc=_("Left: Select; Ctrl+Left: Unselect; Right: Confirm"),
  211. ),
  212. "undo": MetaIcon(
  213. img="undo", label=_("Undo"), desc=_("Undo previous change")
  214. ),
  215. "redo": MetaIcon(
  216. img="redo", label=_("Redo"), desc=_("Redo previous change")
  217. ),
  218. }
  219. if not self.tools or "selector" in self.tools:
  220. data.append((None,))
  221. if not self.tools or "addPoint" in self.tools:
  222. data.append(
  223. (
  224. ("addPoint", self.icons["addPoint"].label),
  225. self.icons["addPoint"],
  226. self.OnAddPoint,
  227. wx.ITEM_CHECK,
  228. )
  229. )
  230. if not self.tools or "addLine" in self.tools:
  231. data.append(
  232. (
  233. ("addLine", self.icons["addLine"].label),
  234. self.icons["addLine"],
  235. self.OnAddLine,
  236. wx.ITEM_CHECK,
  237. ),
  238. )
  239. if not self.tools or "addArea" in self.tools:
  240. data.append(
  241. (
  242. ("addArea", self.icons["addArea"].label),
  243. self.icons["addArea"],
  244. self.OnAddAreaTool,
  245. wx.ITEM_CHECK,
  246. ),
  247. )
  248. if not self.tools or "deleteLine" in self.tools:
  249. data.append(
  250. (
  251. ("deleteLine", self.icons["deleteLine"].label),
  252. self.icons["deleteLine"],
  253. self.OnDeleteLine,
  254. wx.ITEM_CHECK,
  255. ),
  256. )
  257. if not self.tools or "deleteArea" in self.tools:
  258. data.append(
  259. (
  260. ("deleteArea", self.icons["deleteArea"].label),
  261. self.icons["deleteArea"],
  262. self.OnDeleteArea,
  263. wx.ITEM_CHECK,
  264. ),
  265. )
  266. if not self.tools or "moveVertex" in self.tools:
  267. data.append(
  268. (
  269. ("moveVertex", self.icons["moveVertex"].label),
  270. self.icons["moveVertex"],
  271. self.OnMoveVertex,
  272. wx.ITEM_CHECK,
  273. ),
  274. )
  275. if not self.tools or "addVertex" in self.tools:
  276. data.append(
  277. (
  278. ("addVertex", self.icons["addVertex"].label),
  279. self.icons["addVertex"],
  280. self.OnAddVertex,
  281. wx.ITEM_CHECK,
  282. ),
  283. )
  284. if not self.tools or "removeVertex" in self.tools:
  285. data.append(
  286. (
  287. ("removeVertex", self.icons["removeVertex"].label),
  288. self.icons["removeVertex"],
  289. self.OnRemoveVertex,
  290. wx.ITEM_CHECK,
  291. ),
  292. )
  293. if not self.tools or "editLine" in self.tools:
  294. data.append(
  295. (
  296. ("editLine", self.icons["editLine"].label),
  297. self.icons["editLine"],
  298. self.OnEditLine,
  299. wx.ITEM_CHECK,
  300. ),
  301. )
  302. if not self.tools or "moveLine" in self.tools:
  303. data.append(
  304. (
  305. ("moveLine", self.icons["moveLine"].label),
  306. self.icons["moveLine"],
  307. self.OnMoveLine,
  308. wx.ITEM_CHECK,
  309. ),
  310. )
  311. if not self.tools or "displayCats" in self.tools:
  312. data.append(
  313. (
  314. ("displayCats", self.icons["displayCats"].label),
  315. self.icons["displayCats"],
  316. self.OnDisplayCats,
  317. wx.ITEM_CHECK,
  318. ),
  319. )
  320. if not self.tools or "displayAttr" in self.tools:
  321. data.append(
  322. (
  323. ("displayAttr", self.icons["displayAttr"].label),
  324. self.icons["displayAttr"],
  325. self.OnDisplayAttr,
  326. wx.ITEM_CHECK,
  327. ),
  328. )
  329. if not self.tools or "additionalSelf.Tools" in self.tools:
  330. data.append(
  331. (
  332. (
  333. "additionalTools",
  334. self.icons["additionalTools"].label,
  335. ),
  336. self.icons["additionalTools"],
  337. self.OnAdditionalToolMenu,
  338. wx.ITEM_CHECK,
  339. ),
  340. )
  341. if not self.tools or "undo" in self.tools or "redo" in self.tools:
  342. data.append((None,))
  343. if not self.tools or "undo" in self.tools:
  344. data.append(
  345. (
  346. ("undo", self.icons["undo"].label),
  347. self.icons["undo"],
  348. self.OnUndo,
  349. ),
  350. )
  351. if not self.tools or "redo" in self.tools:
  352. data.append(
  353. (
  354. ("redo", self.icons["redo"].label),
  355. self.icons["redo"],
  356. self.OnRedo,
  357. ),
  358. )
  359. if (
  360. not self.tools
  361. or "settings" in self.tools
  362. or "help" in self.tools
  363. or "quit" in self.tools
  364. ):
  365. data.append((None,))
  366. if not self.tools or "settings" in self.tools:
  367. data.append(
  368. (
  369. ("settings", self.icons["settings"].label),
  370. self.icons["settings"],
  371. self.OnSettings,
  372. ),
  373. )
  374. if not self.tools or "help" in self.tools:
  375. data.append(
  376. (
  377. ("help", self.icons["help"].label),
  378. self.icons["help"],
  379. self.OnHelp,
  380. ),
  381. )
  382. if not self.tools or "quit" in self.tools:
  383. data.append(
  384. (
  385. ("quit", self.icons["quit"].label),
  386. self.icons["quit"],
  387. self.OnExit,
  388. ),
  389. )
  390. return self._getToolbarData(data)
  391. def _noVMapOpenForEditingErrDlg(self):
  392. """Show error message dialog if no vector map is open for editing
  393. :return: True if no vector map is open for editing else None
  394. """
  395. if not self.digit:
  396. GError(
  397. _(
  398. "No vector map is open for editing. Please select first"
  399. "a vector map from the combo box."
  400. ),
  401. self.parent,
  402. )
  403. return True
  404. def OnTool(self, event):
  405. """Tool selected -> untoggles previusly selected tool in
  406. toolbar"""
  407. Debug.msg(3, "VDigitToolbar.OnTool(): id = %s" % event.GetId())
  408. # set cursor
  409. self.MapWindow.SetNamedCursor("cross")
  410. self.MapWindow.mouse["box"] = "point"
  411. self.MapWindow.mouse["use"] = "pointer"
  412. aId = self.action.get("id", -1)
  413. BaseToolbar.OnTool(self, event)
  414. # clear tmp canvas
  415. if self.action["id"] != aId or aId == -1:
  416. self.MapWindow.polycoords = []
  417. self.MapWindow.ClearLines(pdc=self.MapWindow.pdcTmp)
  418. if self.digit and len(self.MapWindow.digit.GetDisplay().GetSelected()) > 0:
  419. # cancel action
  420. self.MapWindow.OnMiddleDown(None)
  421. # set no action
  422. if self.action["id"] == -1:
  423. self.action = {"desc": "", "type": "", "id": -1}
  424. # set focus
  425. self.MapWindow.SetFocus()
  426. def OnAddPoint(self, event):
  427. """Add point to the vector map Laier"""
  428. Debug.msg(2, "VDigitToolbar.OnAddPoint()")
  429. self.action = {"desc": "addLine", "type": "point", "id": self.addPoint}
  430. self.MapWindow.mouse["box"] = "point"
  431. def OnAddLine(self, event):
  432. """Add line to the vector map layer"""
  433. Debug.msg(2, "VDigitToolbar.OnAddLine()")
  434. self.action = {"desc": "addLine", "type": "line", "id": self.addLine}
  435. self.MapWindow.mouse["box"] = "line"
  436. # self.MapWindow.polycoords = [] # reset temp line
  437. def OnAddBoundary(self, event):
  438. """Add boundary to the vector map layer"""
  439. Debug.msg(2, "VDigitToolbar.OnAddBoundary()")
  440. self._toggleAreaIfNeeded()
  441. # reset temp line
  442. if self.action["desc"] != "addLine" or self.action["type"] != "boundary":
  443. self.MapWindow.polycoords = []
  444. # update icon and tooltip
  445. self.SetToolNormalBitmap(self.addArea, self.icons["addBoundary"].GetBitmap())
  446. self.SetToolShortHelp(self.addArea, self.icons["addBoundary"].GetLabel())
  447. # set action
  448. self.action = {"desc": "addLine", "type": "boundary", "id": self.addArea}
  449. self.MapWindow.mouse["box"] = "line"
  450. self._currentAreaActionType = "boundary"
  451. def OnAddCentroid(self, event):
  452. """Add centroid to the vector map layer"""
  453. Debug.msg(2, "VDigitToolbar.OnAddCentroid()")
  454. self._toggleAreaIfNeeded()
  455. # update icon and tooltip
  456. self.SetToolNormalBitmap(self.addArea, self.icons["addCentroid"].GetBitmap())
  457. self.SetToolShortHelp(self.addArea, self.icons["addCentroid"].GetLabel())
  458. # set action
  459. self.action = {"desc": "addLine", "type": "centroid", "id": self.addArea}
  460. self.MapWindow.mouse["box"] = "point"
  461. self._currentAreaActionType = "centroid"
  462. def OnAddArea(self, event):
  463. """Add area to the vector map layer"""
  464. Debug.msg(2, "VDigitToolbar.OnAddArea()")
  465. self._toggleAreaIfNeeded()
  466. # update icon and tooltip
  467. self.SetToolNormalBitmap(self.addArea, self.icons["addArea"].GetBitmap())
  468. self.SetToolShortHelp(self.addArea, self.icons["addArea"].GetLabel())
  469. # set action
  470. self.action = {"desc": "addLine", "type": "area", "id": self.addArea}
  471. self.MapWindow.mouse["box"] = "line"
  472. self._currentAreaActionType = "area"
  473. def _toggleAreaIfNeeded(self):
  474. """In some cases, the area tool is not toggled, we have to do it manually."""
  475. if not self.GetToolState(self.addArea):
  476. self.ToggleTool(self.addArea, True)
  477. self.toolSwitcher.ToolChanged(self.addArea)
  478. def OnAddAreaTool(self, event):
  479. """Area tool activated."""
  480. Debug.msg(2, "VDigitToolbar.OnAddAreaTool()")
  481. # we need the previous id
  482. if (
  483. not self._currentAreaActionType or self._currentAreaActionType == "area"
  484. ): # default action
  485. self.OnAddArea(event)
  486. elif self._currentAreaActionType == "boundary":
  487. self.OnAddBoundary(event)
  488. elif self._currentAreaActionType == "centroid":
  489. self.OnAddCentroid(event)
  490. def OnAddAreaMenu(self, event):
  491. """Digitize area menu (add area/boundary/centroid)"""
  492. menuItems = []
  493. if not self.tools or "addArea" in self.tools:
  494. menuItems.append((self.icons["addArea"], self.OnAddArea))
  495. if not self.fType and not self.tools or "addBoundary" in self.tools:
  496. menuItems.append((self.icons["addBoundary"], self.OnAddBoundary))
  497. if not self.fType and not self.tools or "addCentroid" in self.tools:
  498. menuItems.append((self.icons["addCentroid"], self.OnAddCentroid))
  499. self._onMenu(menuItems)
  500. def OnExit(self, event=None):
  501. """Quit digitization tool"""
  502. # stop editing of the currently selected map layer
  503. if self.mapLayer:
  504. self.StopEditing()
  505. # close dialogs if still open
  506. if self.settingsDialog:
  507. self.settingsDialog.OnCancel(None)
  508. # set default mouse settings
  509. self.parent.GetMapToolbar().SelectDefault()
  510. self.MapWindow.polycoords = []
  511. self.quitDigitizer.emit()
  512. def OnMoveVertex(self, event):
  513. """Move line vertex"""
  514. Debug.msg(2, "Digittoolbar.OnMoveVertex():")
  515. self.action = {"desc": "moveVertex", "id": self.moveVertex}
  516. self.MapWindow.mouse["box"] = "point"
  517. def OnAddVertex(self, event):
  518. """Add line vertex"""
  519. Debug.msg(2, "Digittoolbar.OnAddVertex():")
  520. self.action = {"desc": "addVertex", "id": self.addVertex}
  521. self.MapWindow.mouse["box"] = "point"
  522. def OnRemoveVertex(self, event):
  523. """Remove line vertex"""
  524. Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
  525. self.action = {"desc": "removeVertex", "id": self.removeVertex}
  526. self.MapWindow.mouse["box"] = "point"
  527. def OnEditLine(self, event):
  528. """Edit line"""
  529. Debug.msg(2, "Digittoolbar.OnEditLine():")
  530. self.action = {"desc": "editLine", "id": self.editLine}
  531. self.MapWindow.mouse["box"] = "line"
  532. def OnMoveLine(self, event):
  533. """Move line"""
  534. Debug.msg(2, "Digittoolbar.OnMoveLine():")
  535. self.action = {"desc": "moveLine", "id": self.moveLine}
  536. self.MapWindow.mouse["box"] = "box"
  537. def OnDeleteLine(self, event):
  538. """Delete line"""
  539. Debug.msg(2, "Digittoolbar.OnDeleteLine():")
  540. self.action = {"desc": "deleteLine", "id": self.deleteLine}
  541. self.MapWindow.mouse["box"] = "box"
  542. def OnDeleteArea(self, event):
  543. """Delete Area"""
  544. Debug.msg(2, "Digittoolbar.OnDeleteArea():")
  545. self.action = {"desc": "deleteArea", "id": self.deleteArea}
  546. self.MapWindow.mouse["box"] = "box"
  547. def OnDisplayCats(self, event):
  548. """Display/update categories"""
  549. Debug.msg(2, "Digittoolbar.OnDisplayCats():")
  550. self.action = {"desc": "displayCats", "id": self.displayCats}
  551. self.MapWindow.mouse["box"] = "point"
  552. def OnDisplayAttr(self, event):
  553. """Display/update attributes"""
  554. Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
  555. self.action = {"desc": "displayAttrs", "id": self.displayAttr}
  556. self.MapWindow.mouse["box"] = "point"
  557. def OnUndo(self, event):
  558. """Undo previous changes"""
  559. if self.digit:
  560. self.digit.Undo()
  561. event.Skip()
  562. def OnRedo(self, event):
  563. """Undo previous changes"""
  564. if self.digit:
  565. self.digit.Undo(level=1)
  566. event.Skip()
  567. def EnableUndo(self, enable=True):
  568. """Enable 'Undo' in toolbar
  569. :param enable: False for disable
  570. """
  571. self._enableTool(self.undo, enable)
  572. def EnableRedo(self, enable=True):
  573. """Enable 'Redo' in toolbar
  574. :param enable: False for disable
  575. """
  576. self._enableTool(self.redo, enable)
  577. def _enableTool(self, tool, enable):
  578. if not self.FindById(tool):
  579. return
  580. if enable:
  581. if self.GetToolEnabled(tool) is False:
  582. self.EnableTool(tool, True)
  583. else:
  584. if self.GetToolEnabled(tool) is True:
  585. self.EnableTool(tool, False)
  586. def GetAction(self, type="desc"):
  587. """Get current action info"""
  588. return self.action.get(type, "")
  589. def OnSettings(self, event):
  590. """Show settings dialog"""
  591. if self.digit is None:
  592. try:
  593. self.digit = self.MapWindow.digit = self.digitClass(
  594. giface=self._giface, mapwindow=self.MapWindow
  595. )
  596. except SystemExit:
  597. self.digit = self.MapWindow.digit = None
  598. if not self.settingsDialog:
  599. self.settingsDialog = VDigitSettingsDialog(
  600. parent=self.parent, giface=self._giface
  601. )
  602. self.settingsDialog.Show()
  603. def OnHelp(self, event):
  604. """Show digitizer help page in web browser"""
  605. self._giface.Help("wxGUI.vdigit")
  606. def OnAdditionalToolMenu(self, event):
  607. """Menu for additional tools"""
  608. point = wx.GetMousePosition()
  609. toolMenu = Menu()
  610. for label, itype, handler, desc in (
  611. (
  612. _("Break selected lines/boundaries at intersection"),
  613. wx.ITEM_CHECK,
  614. self.OnBreak,
  615. "breakLine",
  616. ),
  617. (
  618. _("Connect selected lines/boundaries"),
  619. wx.ITEM_CHECK,
  620. self.OnConnect,
  621. "connectLine",
  622. ),
  623. (_("Copy categories"), wx.ITEM_CHECK, self.OnCopyCats, "copyCats"),
  624. (
  625. _("Copy features from (background) vector map"),
  626. wx.ITEM_CHECK,
  627. self.OnCopy,
  628. "copyLine",
  629. ),
  630. (_("Copy attributes"), wx.ITEM_CHECK, self.OnCopyAttrb, "copyAttrs"),
  631. (
  632. _("Feature type conversion"),
  633. wx.ITEM_CHECK,
  634. self.OnTypeConversion,
  635. "typeConv",
  636. ),
  637. (
  638. _("Flip selected lines/boundaries"),
  639. wx.ITEM_CHECK,
  640. self.OnFlip,
  641. "flipLine",
  642. ),
  643. (
  644. _("Merge selected lines/boundaries"),
  645. wx.ITEM_CHECK,
  646. self.OnMerge,
  647. "mergeLine",
  648. ),
  649. (
  650. _("Snap selected lines/boundaries (only to nodes)"),
  651. wx.ITEM_CHECK,
  652. self.OnSnap,
  653. "snapLine",
  654. ),
  655. (_("Split line/boundary"), wx.ITEM_CHECK, self.OnSplitLine, "splitLine"),
  656. (_("Query features"), wx.ITEM_CHECK, self.OnQuery, "queryLine"),
  657. (
  658. _("Z bulk-labeling of 3D lines"),
  659. wx.ITEM_CHECK,
  660. self.OnZBulk,
  661. "zbulkLine",
  662. ),
  663. ):
  664. # Add items to the menu
  665. item = wx.MenuItem(
  666. parentMenu=toolMenu, id=wx.ID_ANY, text=label, kind=itype
  667. )
  668. toolMenu.AppendItem(item)
  669. self.MapWindow.Bind(wx.EVT_MENU, handler, item)
  670. if self.action["desc"] == desc:
  671. item.Check(True)
  672. # Popup the menu. If an item is selected then its handler
  673. # will be called before PopupMenu returns.
  674. self.MapWindow.PopupMenu(toolMenu)
  675. toolMenu.Destroy()
  676. if self.action["desc"] == "addPoint":
  677. self.ToggleTool(self.additionalTools, False)
  678. def OnCopy(self, event):
  679. """Copy selected features from (background) vector map"""
  680. if self._noVMapOpenForEditingErrDlg():
  681. return
  682. # select background map
  683. dlg = VectorDialog(
  684. self.parent,
  685. title=_("Select background vector map"),
  686. layerTree=self._giface.GetLayerTree(),
  687. )
  688. if dlg.ShowModal() != wx.ID_OK:
  689. dlg.Destroy()
  690. return
  691. mapName = dlg.GetName(full=True)
  692. dlg.Destroy()
  693. # close open background map if any
  694. bgMap = UserSettings.Get(
  695. group="vdigit", key="bgmap", subkey="value", settings_type="internal"
  696. )
  697. if bgMap:
  698. self.digit.CloseBackgroundMap()
  699. self.editingBgMap.emit(mapName=bgMap, unset=True)
  700. # open background map for reading
  701. UserSettings.Set(
  702. group="vdigit",
  703. key="bgmap",
  704. subkey="value",
  705. value=str(mapName),
  706. settings_type="internal",
  707. )
  708. self.digit.OpenBackgroundMap(mapName)
  709. self.editingBgMap.emit(mapName=mapName)
  710. if self.action["desc"] == "copyLine": # select previous action
  711. self.ToggleTool(self.addPoint, True)
  712. self.ToggleTool(self.additionalTools, False)
  713. self.OnAddPoint(event)
  714. return
  715. Debug.msg(2, "Digittoolbar.OnCopy():")
  716. self.action = {"desc": "copyLine", "id": self.additionalTools}
  717. self.MapWindow.mouse["box"] = "box"
  718. def OnSplitLine(self, event):
  719. """Split line"""
  720. if self.action["desc"] == "splitLine": # select previous action
  721. self.ToggleTool(self.addPoint, True)
  722. self.ToggleTool(self.additionalTools, False)
  723. self.OnAddPoint(event)
  724. return
  725. Debug.msg(2, "Digittoolbar.OnSplitLine():")
  726. self.action = {"desc": "splitLine", "id": self.additionalTools}
  727. self.MapWindow.mouse["box"] = "point"
  728. def OnCopyCats(self, event):
  729. """Copy categories"""
  730. if self.action["desc"] == "copyCats": # select previous action
  731. self.ToggleTool(self.addPoint, True)
  732. self.ToggleTool(self.copyCats, False)
  733. self.OnAddPoint(event)
  734. return
  735. Debug.msg(2, "Digittoolbar.OnCopyCats():")
  736. self.action = {"desc": "copyCats", "id": self.additionalTools}
  737. self.MapWindow.mouse["box"] = "point"
  738. def OnCopyAttrb(self, event):
  739. """Copy attributes"""
  740. if self.action["desc"] == "copyAttrs": # select previous action
  741. self.ToggleTool(self.addPoint, True)
  742. self.ToggleTool(self.copyCats, False)
  743. self.OnAddPoint(event)
  744. return
  745. Debug.msg(2, "Digittoolbar.OnCopyAttrb():")
  746. self.action = {"desc": "copyAttrs", "id": self.additionalTools}
  747. self.MapWindow.mouse["box"] = "point"
  748. def OnFlip(self, event):
  749. """Flip selected lines/boundaries"""
  750. if self.action["desc"] == "flipLine": # select previous action
  751. self.ToggleTool(self.addPoint, True)
  752. self.ToggleTool(self.additionalTools, False)
  753. self.OnAddPoint(event)
  754. return
  755. Debug.msg(2, "Digittoolbar.OnFlip():")
  756. self.action = {"desc": "flipLine", "id": self.additionalTools}
  757. self.MapWindow.mouse["box"] = "box"
  758. def OnMerge(self, event):
  759. """Merge selected lines/boundaries"""
  760. if self.action["desc"] == "mergeLine": # select previous action
  761. self.ToggleTool(self.addPoint, True)
  762. self.ToggleTool(self.additionalTools, False)
  763. self.OnAddPoint(event)
  764. return
  765. Debug.msg(2, "Digittoolbar.OnMerge():")
  766. self.action = {"desc": "mergeLine", "id": self.additionalTools}
  767. self.MapWindow.mouse["box"] = "box"
  768. def OnBreak(self, event):
  769. """Break selected lines/boundaries"""
  770. if self.action["desc"] == "breakLine": # select previous action
  771. self.ToggleTool(self.addPoint, True)
  772. self.ToggleTool(self.additionalTools, False)
  773. self.OnAddPoint(event)
  774. return
  775. Debug.msg(2, "Digittoolbar.OnBreak():")
  776. self.action = {"desc": "breakLine", "id": self.additionalTools}
  777. self.MapWindow.mouse["box"] = "box"
  778. def OnSnap(self, event):
  779. """Snap selected features"""
  780. if self.action["desc"] == "snapLine": # select previous action
  781. self.ToggleTool(self.addPoint, True)
  782. self.ToggleTool(self.additionalTools, False)
  783. self.OnAddPoint(event)
  784. return
  785. Debug.msg(2, "Digittoolbar.OnSnap():")
  786. self.action = {"desc": "snapLine", "id": self.additionalTools}
  787. self.MapWindow.mouse["box"] = "box"
  788. def OnConnect(self, event):
  789. """Connect selected lines/boundaries"""
  790. if self.action["desc"] == "connectLine": # select previous action
  791. self.ToggleTool(self.addPoint, True)
  792. self.ToggleTool(self.additionalTools, False)
  793. self.OnAddPoint(event)
  794. return
  795. Debug.msg(2, "Digittoolbar.OnConnect():")
  796. self.action = {"desc": "connectLine", "id": self.additionalTools}
  797. self.MapWindow.mouse["box"] = "box"
  798. def OnQuery(self, event):
  799. """Query selected lines/boundaries"""
  800. if self.action["desc"] == "queryLine": # select previous action
  801. self.ToggleTool(self.addPoint, True)
  802. self.ToggleTool(self.additionalTools, False)
  803. self.OnAddPoint(event)
  804. return
  805. Debug.msg(
  806. 2,
  807. "Digittoolbar.OnQuery(): %s"
  808. % UserSettings.Get(group="vdigit", key="query", subkey="selection"),
  809. )
  810. self.action = {"desc": "queryLine", "id": self.additionalTools}
  811. self.MapWindow.mouse["box"] = "box"
  812. def OnZBulk(self, event):
  813. """Z bulk-labeling selected lines/boundaries"""
  814. if self._noVMapOpenForEditingErrDlg():
  815. return
  816. if not self.digit.IsVector3D():
  817. GError(
  818. parent=self.parent,
  819. message=_("Vector map is not 3D. Operation canceled."),
  820. )
  821. return
  822. if self.action["desc"] == "zbulkLine": # select previous action
  823. self.ToggleTool(self.addPoint, True)
  824. self.ToggleTool(self.additionalTools, False)
  825. self.OnAddPoint(event)
  826. return
  827. Debug.msg(2, "Digittoolbar.OnZBulk():")
  828. self.action = {"desc": "zbulkLine", "id": self.additionalTools}
  829. self.MapWindow.mouse["box"] = "line"
  830. def OnTypeConversion(self, event):
  831. """Feature type conversion
  832. Supported conversions:
  833. - point <-> centroid
  834. - line <-> boundary
  835. """
  836. if self.action["desc"] == "typeConv": # select previous action
  837. self.ToggleTool(self.addPoint, True)
  838. self.ToggleTool(self.additionalTools, False)
  839. self.OnAddPoint(event)
  840. return
  841. Debug.msg(2, "Digittoolbar.OnTypeConversion():")
  842. self.action = {"desc": "typeConv", "id": self.additionalTools}
  843. self.MapWindow.mouse["box"] = "box"
  844. def OnSelectMap(self, event):
  845. """Select vector map layer for editing
  846. If there is a vector map layer already edited, this action is
  847. firstly terminated. The map layer is closed. After this the
  848. selected map layer activated for editing.
  849. """
  850. if event.GetSelection() == 0: # create new vector map layer
  851. if self.mapLayer:
  852. openVectorMap = self.mapLayer.GetName(fullyQualified=False)["name"]
  853. else:
  854. openVectorMap = None
  855. dlg = CreateNewVector(
  856. self.parent,
  857. exceptMap=openVectorMap,
  858. giface=self._giface,
  859. cmd=(("v.edit", {"tool": "create"}, "map")),
  860. disableAdd=True,
  861. )
  862. if dlg and dlg.GetName():
  863. # add layer to map layer tree/map display
  864. mapName = dlg.GetName() + "@" + grass.gisenv()["MAPSET"]
  865. self._giface.GetLayerList().AddLayer(
  866. ltype="vector",
  867. name=mapName,
  868. checked=True,
  869. cmd=["d.vect", "map=%s" % mapName],
  870. )
  871. vectLayers = self.UpdateListOfLayers(updateTool=True)
  872. selection = vectLayers.index(mapName)
  873. # create table ?
  874. if dlg.IsChecked("table"):
  875. # TODO: starting of tools such as atm, iclass,
  876. # plots etc. should be handled in some better way
  877. # than starting randomly from mapdisp and lmgr
  878. self.openATM.emit(selection="table")
  879. dlg.Destroy()
  880. else:
  881. self.combo.SetValue(_("Select vector map"))
  882. if dlg:
  883. dlg.Destroy()
  884. return
  885. else:
  886. selection = event.GetSelection() - 1 # first option is 'New vector map'
  887. # skip currently selected map
  888. if self.layers[selection] == self.mapLayer:
  889. return
  890. if self.mapLayer:
  891. # deactive map layer for editing
  892. self.StopEditing()
  893. # select the given map layer for editing
  894. self.StartEditing(self.layers[selection])
  895. event.Skip()
  896. def StartEditing(self, mapLayer):
  897. """Start editing selected vector map layer.
  898. :param mapLayer: MapLayer to be edited
  899. """
  900. # check if topology is available (skip for hidden - temporary
  901. # maps, see iclass for details)
  902. if (
  903. not mapLayer.IsHidden()
  904. and grass.vector_info(mapLayer.GetName())["level"] != 2
  905. ):
  906. dlg = wx.MessageDialog(
  907. parent=self.MapWindow,
  908. message=_(
  909. "Topology for vector map <%s> is not available. "
  910. "Topology is required by digitizer.\nDo you want to "
  911. "rebuild topology (takes some time) and open the vector map "
  912. "for editing?"
  913. )
  914. % mapLayer.GetName(),
  915. caption=_("Digitizer error"),
  916. style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION | wx.CENTRE,
  917. )
  918. if dlg.ShowModal() == wx.ID_YES:
  919. RunCommand("v.build", map=mapLayer.GetName())
  920. else:
  921. return
  922. # deactive layer
  923. self.Map.ChangeLayerActive(mapLayer, False)
  924. # clean map canvas
  925. self.MapWindow.EraseMap()
  926. # unset background map if needed
  927. if mapLayer:
  928. if (
  929. UserSettings.Get(
  930. group="vdigit",
  931. key="bgmap",
  932. subkey="value",
  933. settings_type="internal",
  934. )
  935. == mapLayer.GetName()
  936. ):
  937. UserSettings.Set(
  938. group="vdigit",
  939. key="bgmap",
  940. subkey="value",
  941. value="",
  942. settings_type="internal",
  943. )
  944. self.parent.SetStatusText(
  945. _("Please wait, " "opening vector map <%s> for editing...")
  946. % mapLayer.GetName(),
  947. 0,
  948. )
  949. self.MapWindow.pdcVector = PseudoDC()
  950. self.digit = self.MapWindow.digit = self.digitClass(
  951. giface=self._giface, mapwindow=self.MapWindow
  952. )
  953. self.mapLayer = mapLayer
  954. # open vector map (assume that 'hidden' map layer is temporary vector
  955. # map)
  956. if self.digit.OpenMap(mapLayer.GetName(), tmp=mapLayer.IsHidden()) is None:
  957. self.mapLayer = None
  958. self.StopEditing()
  959. return False
  960. # check feature type (only for OGR layers)
  961. self.fType = self.digit.GetFeatureType()
  962. self.EnableAll()
  963. self.EnableUndo(False)
  964. self.EnableRedo(False)
  965. if self.fType == "point":
  966. for tool in (
  967. self.addLine,
  968. self.addArea,
  969. self.moveVertex,
  970. self.addVertex,
  971. self.removeVertex,
  972. self.editLine,
  973. ):
  974. self.EnableTool(tool, False)
  975. elif self.fType == "linestring":
  976. for tool in (self.addPoint, self.addArea):
  977. self.EnableTool(tool, False)
  978. elif self.fType == "polygon":
  979. for tool in (self.addPoint, self.addLine):
  980. self.EnableTool(tool, False)
  981. elif self.fType:
  982. GError(
  983. parent=self,
  984. message=_(
  985. "Unsupported feature type '%(type)s'. Unable to edit "
  986. "OGR layer <%(layer)s>."
  987. )
  988. % {"type": self.fType, "layer": mapLayer.GetName()},
  989. )
  990. self.digit.CloseMap()
  991. self.mapLayer = None
  992. self.StopEditing()
  993. return False
  994. # update toolbar
  995. if self.combo:
  996. self.combo.SetValue(mapLayer.GetName())
  997. if "map" in self.parent.toolbars:
  998. self.parent.toolbars["map"].combo.SetValue(_("Vector digitizer"))
  999. # here was dead code to enable vdigit button in toolbar
  1000. # with if to ignore iclass
  1001. # some signal (DigitizerStarted) can be emitted here
  1002. Debug.msg(4, "VDigitToolbar.StartEditing(): layer=%s" % mapLayer.GetName())
  1003. # change cursor
  1004. if self.MapWindow.mouse["use"] == "pointer":
  1005. self.MapWindow.SetNamedCursor("cross")
  1006. if not self.MapWindow.resize:
  1007. self.MapWindow.UpdateMap(render=True)
  1008. # respect opacity
  1009. opacity = mapLayer.GetOpacity()
  1010. if opacity < 1.0:
  1011. alpha = int(opacity * 255)
  1012. self.digit.GetDisplay().UpdateSettings(alpha=alpha)
  1013. # emit signal
  1014. layerTree = self._giface.GetLayerTree()
  1015. if layerTree:
  1016. item = layerTree.FindItemByData("maplayer", self.mapLayer)
  1017. else:
  1018. item = None
  1019. self.editingStarted.emit(
  1020. vectMap=mapLayer.GetName(), digit=self.digit, layerItem=item
  1021. )
  1022. return True
  1023. def StopEditing(self):
  1024. """Stop editing of selected vector map layer.
  1025. :return: True on success
  1026. :return: False on failure
  1027. """
  1028. item = None
  1029. if self.combo:
  1030. self.combo.SetValue(_("Select vector map"))
  1031. # save changes
  1032. if self.mapLayer:
  1033. Debug.msg(
  1034. 4, "VDigitToolbar.StopEditing(): layer=%s" % self.mapLayer.GetName()
  1035. )
  1036. if (
  1037. UserSettings.Get(group="vdigit", key="saveOnExit", subkey="enabled")
  1038. is False
  1039. ):
  1040. if self.digit.GetUndoLevel() > -1:
  1041. dlg = wx.MessageDialog(
  1042. parent=self.parent,
  1043. message=_("Do you want to save changes " "in vector map <%s>?")
  1044. % self.mapLayer.GetName(),
  1045. caption=_("Save changes?"),
  1046. style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION,
  1047. )
  1048. if dlg.ShowModal() == wx.ID_NO:
  1049. # revert changes
  1050. self.digit.Undo(0)
  1051. dlg.Destroy()
  1052. self.parent.SetStatusText(
  1053. _(
  1054. "Please wait, "
  1055. "closing and rebuilding topology of "
  1056. "vector map <%s>..."
  1057. )
  1058. % self.mapLayer.GetName(),
  1059. 0,
  1060. )
  1061. self.digit.CloseMap()
  1062. # close open background map if any
  1063. bgMap = UserSettings.Get(
  1064. group="vdigit", key="bgmap", subkey="value", settings_type="internal"
  1065. )
  1066. if bgMap:
  1067. self.digit.CloseBackgroundMap()
  1068. self.editingBgMap.emit(mapName=bgMap, unset=True)
  1069. self._giface.GetProgress().SetValue(0)
  1070. self._giface.WriteCmdLog(
  1071. _("Editing of vector map <%s> successfully finished")
  1072. % self.mapLayer.GetName(),
  1073. notification=Notification.HIGHLIGHT,
  1074. )
  1075. # re-active layer
  1076. layerTree = self._giface.GetLayerTree()
  1077. if layerTree:
  1078. item = layerTree.FindItemByData("maplayer", self.mapLayer)
  1079. if item and layerTree.IsItemChecked(item):
  1080. self.Map.ChangeLayerActive(self.mapLayer, True)
  1081. # change cursor
  1082. self.MapWindow.SetNamedCursor("default")
  1083. self.MapWindow.pdcVector = None
  1084. # close dialogs
  1085. for dialog in ("attributes", "category"):
  1086. if self.parent.dialogs[dialog]:
  1087. self.parent.dialogs[dialog].Close()
  1088. self.parent.dialogs[dialog] = None
  1089. self.digit = None
  1090. self.MapWindow.digit = None
  1091. self.editingStopped.emit(layerItem=item)
  1092. self.mapLayer = None
  1093. self.MapWindow.redrawAll = True
  1094. return True
  1095. def UpdateListOfLayers(self, updateTool=False):
  1096. """Update list of available vector map layers.
  1097. This list consists only editable layers (in the current mapset)
  1098. :param updateTool: True to update also toolbar
  1099. :type updateTool: bool
  1100. """
  1101. Debug.msg(4, "VDigitToolbar.UpdateListOfLayers(): updateTool=%d" % updateTool)
  1102. layerNameSelected = None
  1103. # name of currently selected layer
  1104. if self.mapLayer:
  1105. layerNameSelected = self.mapLayer.GetName()
  1106. # select vector map layer in the current mapset
  1107. layerNameList = []
  1108. self.layers = self.Map.GetListOfLayers(
  1109. ltype="vector", mapset=grass.gisenv()["MAPSET"]
  1110. )
  1111. for layer in self.layers:
  1112. if layer.name not in layerNameList: # do not duplicate layer
  1113. layerNameList.append(layer.GetName())
  1114. if updateTool: # update toolbar
  1115. if not self.mapLayer:
  1116. value = _("Select vector map")
  1117. else:
  1118. value = layerNameSelected
  1119. if not self.comboid:
  1120. if not self.tools or "selector" in self.tools:
  1121. self.combo = wx.ComboBox(
  1122. self,
  1123. id=wx.ID_ANY,
  1124. value=value,
  1125. choices=[
  1126. _("New vector map"),
  1127. ]
  1128. + layerNameList,
  1129. size=(80, -1),
  1130. style=wx.CB_READONLY,
  1131. )
  1132. self.comboid = self.InsertControl(0, self.combo)
  1133. self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectMap, self.comboid)
  1134. else:
  1135. self.combo.SetItems(
  1136. [
  1137. _("New vector map"),
  1138. ]
  1139. + layerNameList
  1140. )
  1141. self.Realize()
  1142. return layerNameList
  1143. def GetLayer(self):
  1144. """Get selected layer for editing -- MapLayer instance"""
  1145. return self.mapLayer
  1146. def OnShow(self, event):
  1147. """Show frame event"""
  1148. if event.IsShown():
  1149. # list of available vector maps
  1150. self.UpdateListOfLayers(updateTool=True)