toolbars.py 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  1. """
  2. @package toolbar
  3. @brief Toolbars for Map Display window
  4. Classes:
  5. - AbstractToolbar
  6. - MapToolbar
  7. - GRToolbar
  8. - GCPToolbar
  9. - VDigitToolbar
  10. - ProfileToolbar
  11. - NvizToolbar
  12. (C) 2007-2008 by the GRASS Development Team This program is free
  13. software under the GNU General Public License (>=v2). Read the file
  14. COPYING that comes with GRASS for details.
  15. @author Michael Barton
  16. @author Jachym Cepicky
  17. @author Martin Landa <landa.martin gmail.com>
  18. """
  19. import wx
  20. import os, sys
  21. import platform
  22. import grass
  23. import globalvar
  24. import gcmd
  25. import gdialogs
  26. import vdigit
  27. from vdigit import VDigitSettingsDialog as VDigitSettingsDialog
  28. from debug import Debug as Debug
  29. from icon import Icons as Icons
  30. from preferences import globalSettings as UserSettings
  31. gmpath = os.path.join(globalvar.ETCWXDIR, "icons")
  32. sys.path.append(gmpath)
  33. class AbstractToolbar(object):
  34. """Abstract toolbar class"""
  35. def __init__(self):
  36. pass
  37. def InitToolbar(self, parent, toolbar, toolData):
  38. """Initialize toolbar, i.e. add tools to the toolbar
  39. @return list of ids (of added tools)
  40. """
  41. for tool in toolData:
  42. self.CreateTool(parent, toolbar, *tool)
  43. self._toolbar = toolbar
  44. self._data = toolData
  45. self.parent = parent
  46. def ToolbarData(self):
  47. """Toolbar data"""
  48. return None
  49. def CreateTool(self, parent, toolbar, tool, label, bitmap, kind,
  50. shortHelp, longHelp, handler):
  51. """Add tool to the toolbar
  52. @return id of tool
  53. """
  54. bmpDisabled=wx.NullBitmap
  55. if label:
  56. Debug.msg(3, "CreateTool(): tool=%d, label=%s bitmap=%s" % \
  57. (tool, label, bitmap))
  58. toolWin = toolbar.AddLabelTool(tool, label, bitmap,
  59. bmpDisabled, kind,
  60. shortHelp, longHelp)
  61. parent.Bind(wx.EVT_TOOL, handler, toolWin)
  62. else: # add separator
  63. toolbar.AddSeparator()
  64. return tool
  65. def GetToolbar(self):
  66. """Get toolbar widget reference"""
  67. return self._toolbar
  68. def EnableLongHelp(self, enable=True):
  69. """Enable/disable long help
  70. @param enable True for enable otherwise disable
  71. """
  72. for tool in self._data:
  73. if tool[0] == '': # separator
  74. continue
  75. if enable:
  76. self._toolbar.SetToolLongHelp(tool[0], tool[5])
  77. else:
  78. self._toolbar.SetToolLongHelp(tool[0], "")
  79. def OnTool(self, event):
  80. """Tool selected"""
  81. if self.parent.toolbars['vdigit']:
  82. # update vdigit toolbar (unselect currently selected tool)
  83. id = self.parent.toolbars['vdigit'].GetAction(type='id')
  84. self.parent.toolbars['vdigit'].GetToolbar().ToggleTool(id, False)
  85. if event:
  86. # deselect previously selected tool
  87. id = self.action.get('id', -1)
  88. if id != event.GetId():
  89. self._toolbar.ToggleTool(self.action['id'], False)
  90. else:
  91. self._toolbar.ToggleTool(self.action['id'], True)
  92. self.action['id'] = event.GetId()
  93. event.Skip()
  94. else:
  95. # initialize toolbar
  96. self._toolbar.ToggleTool(self.action['id'], True)
  97. def GetAction(self, type='desc'):
  98. """Get current action info"""
  99. return self.action.get(type, '')
  100. def SelectDefault(self, event):
  101. """Select default tool"""
  102. self._toolbar.ToggleTool(self.defaultAction['id'], True)
  103. self.defaultAction['bind'](event)
  104. self.action = { 'id' : self.defaultAction['id'],
  105. 'desc' : self.defaultAction.get('desc', '') }
  106. def FixSize(self, width):
  107. """Fix toolbar width on Windows
  108. @todo Determine why combobox causes problems here
  109. """
  110. if platform.system() == 'Windows':
  111. size = self._toolbar.GetBestSize()
  112. self._toolbar.SetSize((size[0] + width, size[1]))
  113. class MapToolbar(AbstractToolbar):
  114. """
  115. Main Map Display toolbar
  116. """
  117. def __init__(self, mapdisplay, map):
  118. AbstractToolbar.__init__(self)
  119. self.mapcontent = map
  120. self.mapdisplay = mapdisplay
  121. self.toolbar = wx.ToolBar(parent=self.mapdisplay, id=wx.ID_ANY)
  122. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  123. self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())
  124. # optional tools
  125. self.combo = wx.ComboBox(parent=self.toolbar, id=wx.ID_ANY, value=_('2D view'),
  126. choices=[_('2D view'), _('3D view'), _('Digitize')],
  127. style=wx.CB_READONLY, size=(90, -1))
  128. self.comboid = self.toolbar.AddControl(self.combo)
  129. self.mapdisplay.Bind(wx.EVT_COMBOBOX, self.OnSelectTool, self.comboid)
  130. # realize the toolbar
  131. self.toolbar.Realize()
  132. # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
  133. self.combo.Hide()
  134. self.combo.Show()
  135. # default action
  136. self.action = { 'id' : self.pointer }
  137. self.defaultAction = { 'id' : self.pointer,
  138. 'bind' : self.mapdisplay.OnPointer }
  139. self.OnTool(None)
  140. self.FixSize(width = 90)
  141. def ToolbarData(self):
  142. """Toolbar data"""
  143. self.displaymap = wx.NewId()
  144. self.rendermap = wx.NewId()
  145. self.erase = wx.NewId()
  146. self.pointer = wx.NewId()
  147. self.query = wx.NewId()
  148. self.pan = wx.NewId()
  149. self.zoomin = wx.NewId()
  150. self.zoomout = wx.NewId()
  151. self.zoomback = wx.NewId()
  152. self.zoommenu = wx.NewId()
  153. self.analyze = wx.NewId()
  154. self.dec = wx.NewId()
  155. self.savefile = wx.NewId()
  156. self.printmap = wx.NewId()
  157. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  158. return (
  159. (self.displaymap, "displaymap", Icons["displaymap"].GetBitmap(),
  160. wx.ITEM_NORMAL, Icons["displaymap"].GetLabel(), Icons["displaymap"].GetDesc(),
  161. self.mapdisplay.OnDraw),
  162. (self.rendermap, "rendermap", Icons["rendermap"].GetBitmap(),
  163. wx.ITEM_NORMAL, Icons["rendermap"].GetLabel(), Icons["rendermap"].GetDesc(),
  164. self.mapdisplay.OnRender),
  165. (self.erase, "erase", Icons["erase"].GetBitmap(),
  166. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  167. self.mapdisplay.OnErase),
  168. ("", "", "", "", "", "", ""),
  169. (self.pointer, "pointer", Icons["pointer"].GetBitmap(),
  170. wx.ITEM_CHECK, Icons["pointer"].GetLabel(), Icons["pointer"].GetDesc(),
  171. self.mapdisplay.OnPointer),
  172. (self.query, "query", Icons["query"].GetBitmap(),
  173. wx.ITEM_CHECK, Icons["query"].GetLabel(), Icons["query"].GetDesc(),
  174. self.mapdisplay.OnQuery),
  175. (self.pan, "pan", Icons["pan"].GetBitmap(),
  176. wx.ITEM_CHECK, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  177. self.mapdisplay.OnPan),
  178. (self.zoomin, "zoom_in", Icons["zoom_in"].GetBitmap(),
  179. wx.ITEM_CHECK, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  180. self.mapdisplay.OnZoomIn),
  181. (self.zoomout, "zoom_out", Icons["zoom_out"].GetBitmap(),
  182. wx.ITEM_CHECK, Icons["zoom_out"].GetLabel(), Icons["zoom_out"].GetDesc(),
  183. self.mapdisplay.OnZoomOut),
  184. (self.zoomback, "zoom_back", Icons["zoom_back"].GetBitmap(),
  185. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  186. self.mapdisplay.OnZoomBack),
  187. (self.zoommenu, "zoommenu", Icons["zoommenu"].GetBitmap(),
  188. wx.ITEM_NORMAL, Icons["zoommenu"].GetLabel(), Icons["zoommenu"].GetDesc(),
  189. self.mapdisplay.OnZoomMenu),
  190. ("", "", "", "", "", "", ""),
  191. (self.analyze, "analyze", Icons["analyze"].GetBitmap(),
  192. wx.ITEM_NORMAL, Icons["analyze"].GetLabel(), Icons["analyze"].GetDesc(),
  193. self.mapdisplay.OnAnalyze),
  194. ("", "", "", "", "", "", ""),
  195. (self.dec, "overlay", Icons["overlay"].GetBitmap(),
  196. wx.ITEM_NORMAL, Icons["overlay"].GetLabel(), Icons["overlay"].GetDesc(),
  197. self.mapdisplay.OnDecoration),
  198. ("", "", "", "", "", "", ""),
  199. (self.savefile, "savefile", Icons["savefile"].GetBitmap(),
  200. wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
  201. self.mapdisplay.SaveToFile),
  202. (self.printmap, "printmap", Icons["printmap"].GetBitmap(),
  203. wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
  204. self.mapdisplay.PrintMenu),
  205. ("", "", "", "", "", "", "")
  206. )
  207. def OnSelectTool(self, event):
  208. """
  209. Select / enable tool available in tools list
  210. """
  211. tool = event.GetSelection()
  212. if tool == 0:
  213. self.ExitToolbars()
  214. self.Enable2D(True)
  215. elif tool == 1 and not self.mapdisplay.toolbars['nviz']:
  216. self.ExitToolbars()
  217. self.mapdisplay.AddToolbar("nviz")
  218. elif tool == 2 and not self.mapdisplay.toolbars['vdigit']:
  219. self.ExitToolbars()
  220. self.mapdisplay.AddToolbar("vdigit")
  221. def ExitToolbars(self):
  222. if self.mapdisplay.toolbars['vdigit']:
  223. self.mapdisplay.toolbars['vdigit'].OnExit()
  224. if self.mapdisplay.toolbars['nviz']:
  225. self.mapdisplay.toolbars['nviz'].OnExit()
  226. def Enable2D(self, enabled):
  227. """Enable/Disable 2D display mode specific tools"""
  228. for tool in (self.pointer,
  229. self.query,
  230. self.pan,
  231. self.zoomin,
  232. self.zoomout,
  233. self.zoomback,
  234. self.zoommenu,
  235. self.analyze,
  236. self.dec,
  237. self.savefile,
  238. self.printmap):
  239. self.toolbar.EnableTool(tool, enabled)
  240. class GRToolbar(AbstractToolbar):
  241. """
  242. Georectification Display toolbar
  243. """
  244. def __init__(self, mapdisplay, map):
  245. self.mapcontent = map
  246. self.mapdisplay = mapdisplay
  247. self.toolbar = wx.ToolBar(parent=self.mapdisplay, id=wx.ID_ANY)
  248. # self.SetToolBar(self.toolbar)
  249. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  250. self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())
  251. # realize the toolbar
  252. self.toolbar.Realize()
  253. def ToolbarData(self):
  254. """Toolbar data"""
  255. self.displaymap = wx.NewId()
  256. self.rendermap = wx.NewId()
  257. self.erase = wx.NewId()
  258. self.gcpset = wx.NewId()
  259. self.pan = wx.NewId()
  260. self.zoomin = wx.NewId()
  261. self.zoomout = wx.NewId()
  262. self.zoomback = wx.NewId()
  263. self.zoomtomap = wx.NewId()
  264. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  265. return (
  266. (self.displaymap, "displaymap", Icons["displaymap"].GetBitmap(),
  267. wx.ITEM_NORMAL, Icons["displaymap"].GetLabel(), Icons["displaymap"].GetDesc(),
  268. self.mapdisplay.OnDraw),
  269. (self.rendermap, "rendermap", Icons["rendermap"].GetBitmap(),
  270. wx.ITEM_NORMAL, Icons["rendermap"].GetLabel(), Icons["rendermap"].GetDesc(),
  271. self.mapdisplay.OnRender),
  272. (self.erase, "erase", Icons["erase"].GetBitmap(),
  273. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  274. self.mapdisplay.OnErase),
  275. ("", "", "", "", "", "", ""),
  276. (self.gcpset, "grGcpSet", Icons["grGcpSet"].GetBitmap(),
  277. wx.ITEM_RADIO, Icons["grGcpSet"].GetLabel(), Icons["grGcpSet"].GetDesc(),
  278. self.mapdisplay.OnPointer),
  279. (self.pan, "pan", Icons["pan"].GetBitmap(),
  280. wx.ITEM_RADIO, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  281. self.mapdisplay.OnPan),
  282. (self.zoomin, "zoom_in", Icons["zoom_in"].GetBitmap(),
  283. wx.ITEM_RADIO, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  284. self.mapdisplay.OnZoomIn),
  285. (self.zoomout, "zoom_out", Icons["zoom_out"].GetBitmap(),
  286. wx.ITEM_RADIO, Icons["zoom_out"].GetLabel(), Icons["zoom_out"].GetDesc(),
  287. self.mapdisplay.OnZoomOut),
  288. (self.zoomback, "zoom_back", Icons["zoom_back"].GetBitmap(),
  289. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  290. self.mapdisplay.OnZoomBack),
  291. (self.zoomtomap, "zoomtomap", Icons["zoommenu"].GetBitmap(),
  292. wx.ITEM_NORMAL, _("Zoom to map"), _("Zoom to displayed map"),
  293. self.OnZoomMap),
  294. ("", "", "", "", "", "", ""),
  295. )
  296. def OnZoomMap(self, event):
  297. """Zoom to selected map"""
  298. layer = self.mapcontent.GetListOfLayers()[0]
  299. self.mapdisplay.MapWindow.ZoomToMap(layer=layer)
  300. event.Skip()
  301. class GCPToolbar(AbstractToolbar):
  302. """
  303. Toolbar for managing ground control points during georectification
  304. """
  305. def __init__(self, parent, tbframe):
  306. self.parent = parent # GCP
  307. self.tbframe = tbframe
  308. self.toolbar = wx.ToolBar(parent=self.tbframe, id=wx.ID_ANY)
  309. # self.SetToolBar(self.toolbar)
  310. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  311. self.InitToolbar(self.tbframe, self.toolbar, self.ToolbarData())
  312. # realize the toolbar
  313. self.toolbar.Realize()
  314. def ToolbarData(self):
  315. self.gcpSave = wx.NewId()
  316. self.gcpAdd = wx.NewId()
  317. self.gcpDelete = wx.NewId()
  318. self.gcpClear = wx.NewId()
  319. self.gcpReload = wx.NewId()
  320. self.rms = wx.NewId()
  321. self.georect = wx.NewId()
  322. self.settings = wx.NewId()
  323. self.quit = wx.NewId()
  324. return (
  325. (self.gcpSave, 'grGcpSave', Icons["grGcpSave"].GetBitmap(),
  326. wx.ITEM_NORMAL, Icons["grGcpSave"].GetLabel(), Icons["grGcpSave"].GetDesc(),
  327. self.parent.SaveGCPs),
  328. (self.gcpAdd, 'grGrGcpAdd', Icons["grGcpAdd"].GetBitmap(),
  329. wx.ITEM_NORMAL, Icons["grGcpAdd"].GetLabel(), Icons["grGcpAdd"].GetDesc(),
  330. self.parent.AddGCP),
  331. (self.gcpDelete, 'grGrGcpDelete', Icons["grGcpDelete"].GetBitmap(),
  332. wx.ITEM_NORMAL, Icons["grGcpDelete"].GetLabel(), Icons["grGcpDelete"].GetDesc(),
  333. self.parent.DeleteGCP),
  334. (self.gcpClear, 'grGcpClear', Icons["grGcpClear"].GetBitmap(),
  335. wx.ITEM_NORMAL, Icons["grGcpClear"].GetLabel(), Icons["grGcpClear"].GetDesc(),
  336. self.parent.ClearGCP),
  337. (self.gcpReload, 'grGcpReload', Icons["grGcpReload"].GetBitmap(),
  338. wx.ITEM_NORMAL, Icons["grGcpReload"].GetLabel(), Icons["grGcpReload"].GetDesc(),
  339. self.parent.ReloadGCPs),
  340. ("", "", "", "", "", "", ""),
  341. (self.rms, 'grGcpRms', Icons["grGcpRms"].GetBitmap(),
  342. wx.ITEM_NORMAL, Icons["grGcpRms"].GetLabel(), Icons["grGcpRms"].GetDesc(),
  343. self.parent.OnRMS),
  344. (self.georect, 'grGeorect', Icons["grGeorect"].GetBitmap(),
  345. wx.ITEM_NORMAL, Icons["grGeorect"].GetLabel(), Icons["grGeorect"].GetDesc(),
  346. self.parent.OnGeorect),
  347. ("", "", "", "", "", "", ""),
  348. (self.settings, 'grSettings', Icons["grSettings"].GetBitmap(),
  349. wx.ITEM_NORMAL, Icons["grSettings"].GetLabel(), Icons["grSettings"].GetDesc(),
  350. self.parent.OnSettings),
  351. (self.quit, 'grGcpQuit', Icons["grGcpQuit"].GetBitmap(),
  352. wx.ITEM_NORMAL, Icons["grGcpQuit"].GetLabel(), Icons["grGcpQuit"].GetDesc(),
  353. self.parent.OnQuit)
  354. )
  355. class VDigitToolbar(AbstractToolbar):
  356. """
  357. Toolbar for digitization
  358. """
  359. def __init__(self, parent, map, layerTree=None, log=None):
  360. self.mapcontent = map # Map class instance
  361. self.parent = parent # MapFrame
  362. self.layerTree = layerTree # reference to layer tree associated to map display
  363. self.log = log # log area
  364. # currently selected map layer for editing (reference to MapLayer instance)
  365. self.mapLayer = None
  366. # list of vector layers from Layer Manager (only in the current mapset)
  367. self.layers = []
  368. self.comboid = None
  369. # only one dialog can be open
  370. self.settingsDialog = None
  371. # create toolbars (two rows optionally)
  372. self.toolbar = []
  373. self.numOfRows = 1 # number of rows for toolbar
  374. for row in range(0, self.numOfRows):
  375. self.toolbar.append(wx.ToolBar(parent=self.parent, id=wx.ID_ANY))
  376. self.toolbar[row].SetToolBitmapSize(globalvar.toolbarSize)
  377. self.toolbar[row].Bind(wx.EVT_TOOL, self.OnTool)
  378. # create toolbar
  379. if self.numOfRows == 1:
  380. rowdata=None
  381. else:
  382. rowdata = row
  383. self.InitToolbar(self.parent, self.toolbar[row], self.ToolbarData(rowdata))
  384. # default action (digitize new point, line, etc.)
  385. self.action = { 'desc' : 'addLine',
  386. 'type' : 'point',
  387. 'id' : self.addPoint }
  388. # list of available vector maps
  389. self.UpdateListOfLayers(updateTool=True)
  390. # realize toolbar
  391. for row in range(0, self.numOfRows):
  392. self.toolbar[row].Realize()
  393. # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
  394. self.combo.Hide()
  395. self.combo.Show()
  396. # disable undo/redo
  397. self.toolbar[0].EnableTool(self.undo, False)
  398. # toogle to pointer by default
  399. self.OnTool(None)
  400. self.FixSize(width = 105)
  401. def ToolbarData(self, row=None):
  402. """
  403. Toolbar data
  404. """
  405. data = []
  406. if row is None or row == 0:
  407. self.addPoint = wx.NewId()
  408. self.addLine = wx.NewId()
  409. self.addBoundary = wx.NewId()
  410. self.addCentroid = wx.NewId()
  411. self.moveVertex = wx.NewId()
  412. self.addVertex = wx.NewId()
  413. self.removeVertex = wx.NewId()
  414. self.splitLine = wx.NewId()
  415. self.editLine = wx.NewId()
  416. self.moveLine = wx.NewId()
  417. self.deleteLine = wx.NewId()
  418. self.additionalTools = wx.NewId()
  419. self.displayCats = wx.NewId()
  420. self.displayAttr = wx.NewId()
  421. self.copyCats = wx.NewId()
  422. data = [("", "", "", "", "", "", ""),
  423. (self.addPoint, "digAddPoint", Icons["digAddPoint"].GetBitmap(),
  424. wx.ITEM_CHECK, Icons["digAddPoint"].GetLabel(), Icons["digAddPoint"].GetDesc(),
  425. self.OnAddPoint),
  426. (self.addLine, "digAddLine", Icons["digAddLine"].GetBitmap(),
  427. wx.ITEM_CHECK, Icons["digAddLine"].GetLabel(), Icons["digAddLine"].GetDesc(),
  428. self.OnAddLine),
  429. (self.addBoundary, "digAddBoundary", Icons["digAddBoundary"].GetBitmap(),
  430. wx.ITEM_CHECK, Icons["digAddBoundary"].GetLabel(), Icons["digAddBoundary"].GetDesc(),
  431. self.OnAddBoundary),
  432. (self.addCentroid, "digAddCentroid", Icons["digAddCentroid"].GetBitmap(),
  433. wx.ITEM_CHECK, Icons["digAddCentroid"].GetLabel(), Icons["digAddCentroid"].GetDesc(),
  434. self.OnAddCentroid),
  435. (self.moveVertex, "digMoveVertex", Icons["digMoveVertex"].GetBitmap(),
  436. wx.ITEM_CHECK, Icons["digMoveVertex"].GetLabel(), Icons["digMoveVertex"].GetDesc(),
  437. self.OnMoveVertex),
  438. (self.addVertex, "digAddVertex", Icons["digAddVertex"].GetBitmap(),
  439. wx.ITEM_CHECK, Icons["digAddVertex"].GetLabel(), Icons["digAddVertex"].GetDesc(),
  440. self.OnAddVertex),
  441. (self.removeVertex, "digRemoveVertex", Icons["digRemoveVertex"].GetBitmap(),
  442. wx.ITEM_CHECK, Icons["digRemoveVertex"].GetLabel(), Icons["digRemoveVertex"].GetDesc(),
  443. self.OnRemoveVertex),
  444. (self.splitLine, "digSplitLine", Icons["digSplitLine"].GetBitmap(),
  445. wx.ITEM_CHECK, Icons["digSplitLine"].GetLabel(), Icons["digSplitLine"].GetDesc(),
  446. self.OnSplitLine),
  447. (self.editLine, "digEditLine", Icons["digEditLine"].GetBitmap(),
  448. wx.ITEM_CHECK, Icons["digEditLine"].GetLabel(), Icons["digEditLine"].GetDesc(),
  449. self.OnEditLine),
  450. (self.moveLine, "digMoveLine", Icons["digMoveLine"].GetBitmap(),
  451. wx.ITEM_CHECK, Icons["digMoveLine"].GetLabel(), Icons["digMoveLine"].GetDesc(),
  452. self.OnMoveLine),
  453. (self.deleteLine, "digDeleteLine", Icons["digDeleteLine"].GetBitmap(),
  454. wx.ITEM_CHECK, Icons["digDeleteLine"].GetLabel(), Icons["digDeleteLine"].GetDesc(),
  455. self.OnDeleteLine),
  456. (self.displayCats, "digDispCats", Icons["digDispCats"].GetBitmap(),
  457. wx.ITEM_CHECK, Icons["digDispCats"].GetLabel(), Icons["digDispCats"].GetDesc(),
  458. self.OnDisplayCats),
  459. (self.copyCats, "digCopyCats", Icons["digCopyCats"].GetBitmap(),
  460. wx.ITEM_CHECK, Icons["digCopyCats"].GetLabel(), Icons["digCopyCats"].GetDesc(),
  461. self.OnCopyCA),
  462. (self.displayAttr, "digDispAttr", Icons["digDispAttr"].GetBitmap(),
  463. wx.ITEM_CHECK, Icons["digDispAttr"].GetLabel(), Icons["digDispAttr"].GetDesc(),
  464. self.OnDisplayAttr),
  465. (self.additionalTools, "digAdditionalTools", Icons["digAdditionalTools"].GetBitmap(),
  466. wx.ITEM_CHECK, Icons["digAdditionalTools"].GetLabel(),
  467. Icons["digAdditionalTools"].GetDesc(),
  468. self.OnAdditionalToolMenu)]
  469. if row is None or row == 1:
  470. self.undo = wx.NewId()
  471. self.settings = wx.NewId()
  472. self.exit = wx.NewId()
  473. data.append(("", "", "", "", "", "", ""))
  474. data.append((self.undo, "digUndo", Icons["digUndo"].GetBitmap(),
  475. wx.ITEM_NORMAL, Icons["digUndo"].GetLabel(), Icons["digUndo"].GetDesc(),
  476. self.OnUndo))
  477. # data.append((self.undo, "digRedo", Icons["digRedo"].GetBitmap(),
  478. # wx.ITEM_NORMAL, Icons["digRedo"].GetLabel(), Icons["digRedo"].GetDesc(),
  479. # self.OnRedo))
  480. data.append((self.settings, "digSettings", Icons["digSettings"].GetBitmap(),
  481. wx.ITEM_NORMAL, Icons["digSettings"].GetLabel(), Icons["digSettings"].GetDesc(),
  482. self.OnSettings))
  483. data.append((self.exit, "digExit", Icons["quit"].GetBitmap(),
  484. wx.ITEM_NORMAL, Icons["digExit"].GetLabel(), Icons["digExit"].GetDesc(),
  485. self.OnExit))
  486. return data
  487. def OnTool(self, event):
  488. """Tool selected -> disable selected tool in map toolbar"""
  489. # update map toolbar (unselect currently selected tool)
  490. id = self.parent.toolbars['map'].GetAction(type='id')
  491. self.parent.toolbars['map'].toolbar.ToggleTool(id, False)
  492. # set cursor
  493. cursor = self.parent.cursors["cross"]
  494. self.parent.MapWindow.SetCursor(cursor)
  495. # pointer
  496. self.parent.OnPointer(None)
  497. if event:
  498. # deselect previously selected tool
  499. id = self.action.get('id', -1)
  500. if id != event.GetId():
  501. self.toolbar[0].ToggleTool(self.action['id'], False)
  502. else:
  503. self.toolbar[0].ToggleTool(self.action['id'], True)
  504. self.action['id'] = event.GetId()
  505. event.Skip()
  506. else:
  507. # initialize toolbar
  508. self.toolbar[0].ToggleTool(self.action['id'], True)
  509. # clear tmp canvas
  510. if self.action['id'] != id:
  511. self.parent.MapWindow.ClearLines(pdc=self.parent.MapWindow.pdcTmp)
  512. def OnAddPoint(self, event):
  513. """Add point to the vector map Laier"""
  514. Debug.msg (2, "VDigitToolbar.OnAddPoint()")
  515. self.action = { 'desc' : "addLine",
  516. 'type' : "point",
  517. 'id' : self.addPoint }
  518. self.parent.MapWindow.mouse['box'] = 'point'
  519. def OnAddLine(self, event):
  520. """Add line to the vector map layer"""
  521. Debug.msg (2, "VDigitToolbar.OnAddLine()")
  522. self.action = { 'desc' : "addLine",
  523. 'type' : "line",
  524. 'id' : self.addLine }
  525. self.parent.MapWindow.mouse['box'] = 'line'
  526. ### self.parent.MapWindow.polycoords = [] # reset temp line
  527. def OnAddBoundary(self, event):
  528. """Add boundary to the vector map layer"""
  529. Debug.msg (2, "VDigitToolbar.OnAddBoundary()")
  530. if self.action['desc'] != 'addLine' or \
  531. self.action['type'] != 'boundary':
  532. self.parent.MapWindow.polycoords = [] # reset temp line
  533. self.action = { 'desc' : "addLine",
  534. 'type' : "boundary",
  535. 'id' : self.addBoundary }
  536. self.parent.MapWindow.mouse['box'] = 'line'
  537. def OnAddCentroid(self, event):
  538. """Add centroid to the vector map layer"""
  539. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  540. self.action = { 'desc' : "addLine",
  541. 'type' : "centroid",
  542. 'id' : self.addCentroid }
  543. self.parent.MapWindow.mouse['box'] = 'point'
  544. def OnExit (self, event=None):
  545. """Quit digitization tool"""
  546. # stop editing of the currently selected map layer
  547. if self.mapLayer:
  548. self.StopEditing()
  549. # close dialogs if still open
  550. if self.settingsDialog:
  551. self.settingsDialog.OnCancel(None)
  552. # disable the toolbar
  553. self.parent.RemoveToolbar ("vdigit")
  554. # set default mouse settings
  555. self.parent.MapWindow.mouse['use'] = "pointer"
  556. self.parent.MapWindow.mouse['box'] = "point"
  557. self.parent.MapWindow.polycoords = []
  558. def OnMoveVertex(self, event):
  559. """Move line vertex"""
  560. Debug.msg(2, "Digittoolbar.OnMoveVertex():")
  561. self.action = { 'desc' : "moveVertex",
  562. 'id' : self.moveVertex }
  563. self.parent.MapWindow.mouse['box'] = 'point'
  564. def OnAddVertex(self, event):
  565. """Add line vertex"""
  566. Debug.msg(2, "Digittoolbar.OnAddVertex():")
  567. self.action = { 'desc' : "addVertex",
  568. 'id' : self.addVertex }
  569. self.parent.MapWindow.mouse['box'] = 'point'
  570. def OnRemoveVertex(self, event):
  571. """Remove line vertex"""
  572. Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
  573. self.action = { 'desc' : "removeVertex",
  574. 'id' : self.removeVertex }
  575. self.parent.MapWindow.mouse['box'] = 'point'
  576. def OnSplitLine(self, event):
  577. """Split line"""
  578. Debug.msg(2, "Digittoolbar.OnSplitLine():")
  579. self.action = { 'desc' : "splitLine",
  580. 'id' : self.splitLine }
  581. self.parent.MapWindow.mouse['box'] = 'point'
  582. def OnEditLine(self, event):
  583. """Edit line"""
  584. Debug.msg(2, "Digittoolbar.OnEditLine():")
  585. self.action = { 'desc' : "editLine",
  586. 'id' : self.editLine }
  587. self.parent.MapWindow.mouse['box'] = 'line'
  588. def OnMoveLine(self, event):
  589. """Move line"""
  590. Debug.msg(2, "Digittoolbar.OnMoveLine():")
  591. self.action = { 'desc' : "moveLine",
  592. 'id' : self.moveLine }
  593. self.parent.MapWindow.mouse['box'] = 'box'
  594. def OnDeleteLine(self, event):
  595. """Delete line"""
  596. Debug.msg(2, "Digittoolbar.OnDeleteLine():")
  597. self.action = { 'desc' : "deleteLine",
  598. 'id' : self.deleteLine }
  599. self.parent.MapWindow.mouse['box'] = 'box'
  600. def OnDisplayCats(self, event):
  601. """Display/update categories"""
  602. Debug.msg(2, "Digittoolbar.OnDisplayCats():")
  603. self.action = { 'desc' : "displayCats",
  604. 'id' : self.displayCats }
  605. self.parent.MapWindow.mouse['box'] = 'point'
  606. def OnDisplayAttr(self, event):
  607. """Display/update attributes"""
  608. Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
  609. self.action = { 'desc' : "displayAttrs",
  610. 'id' : self.displayAttr }
  611. self.parent.MapWindow.mouse['box'] = 'point'
  612. def OnCopyCA(self, event):
  613. """Copy categories/attributes menu"""
  614. point = wx.GetMousePosition()
  615. toolMenu = wx.Menu()
  616. # Add items to the menu
  617. cats = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  618. text=_('Copy categories'),
  619. kind=wx.ITEM_CHECK)
  620. toolMenu.AppendItem(cats)
  621. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyCats, cats)
  622. if self.action['desc'] == "copyCats":
  623. cats.Check(True)
  624. attrb = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  625. text=_('Duplicate attributes'),
  626. kind=wx.ITEM_CHECK)
  627. toolMenu.AppendItem(attrb)
  628. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyAttrb, attrb)
  629. if self.action['desc'] == "copyAttrs":
  630. attrb.Check(True)
  631. # Popup the menu. If an item is selected then its handler
  632. # will be called before PopupMenu returns.
  633. self.parent.MapWindow.PopupMenu(toolMenu)
  634. toolMenu.Destroy()
  635. if self.action['desc'] == "addPoint":
  636. self.toolbar[0].ToggleTool(self.copyCats, False)
  637. def OnCopyCats(self, event):
  638. """Copy categories"""
  639. if self.action['desc'] == 'copyCats': # select previous action
  640. self.toolbar[0].ToggleTool(self.addPoint, True)
  641. self.toolbar[0].ToggleTool(self.copyCats, False)
  642. self.OnAddPoint(event)
  643. return
  644. Debug.msg(2, "Digittoolbar.OnCopyCats():")
  645. self.action = { 'desc' : "copyCats",
  646. 'id' : self.copyCats }
  647. self.parent.MapWindow.mouse['box'] = 'point'
  648. def OnCopyAttrb(self, event):
  649. if self.action['desc'] == 'copyAttrs': # select previous action
  650. self.toolbar[0].ToggleTool(self.addPoint, True)
  651. self.toolbar[0].ToggleTool(self.copyCats, False)
  652. self.OnAddPoint(event)
  653. return
  654. Debug.msg(2, "Digittoolbar.OnCopyAttrb():")
  655. self.action = { 'desc' : "copyAttrs",
  656. 'id' : self.copyCats }
  657. self.parent.MapWindow.mouse['box'] = 'point'
  658. def OnUndo(self, event):
  659. """Undo previous changes"""
  660. self.parent.digit.Undo()
  661. event.Skip()
  662. def EnableUndo(self, enable=True):
  663. """Enable 'Undo' in toolbar
  664. @param enable False for disable
  665. """
  666. if enable:
  667. if self.toolbar[0].GetToolEnabled(self.undo) is False:
  668. self.toolbar[0].EnableTool(self.undo, True)
  669. else:
  670. if self.toolbar[0].GetToolEnabled(self.undo) is True:
  671. self.toolbar[0].EnableTool(self.undo, False)
  672. def OnSettings(self, event):
  673. """Show settings dialog"""
  674. if self.parent.digit is None:
  675. reload(vdigit)
  676. from vdigit import Digit as Digit
  677. self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
  678. if not self.settingsDialog:
  679. self.settingsDialog = VDigitSettingsDialog(parent=self.parent, title=_("Digitization settings"),
  680. style=wx.DEFAULT_DIALOG_STYLE)
  681. self.settingsDialog.Show()
  682. def OnAdditionalToolMenu(self, event):
  683. """Menu for additional tools"""
  684. point = wx.GetMousePosition()
  685. toolMenu = wx.Menu()
  686. # Add items to the menu
  687. copy = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  688. text=_('Copy features from (background) vector map'),
  689. kind=wx.ITEM_CHECK)
  690. toolMenu.AppendItem(copy)
  691. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopy, copy)
  692. if self.action['desc'] == "copyLine":
  693. copy.Check(True)
  694. flip = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  695. text=_('Flip selected lines/boundaries'),
  696. kind=wx.ITEM_CHECK)
  697. toolMenu.AppendItem(flip)
  698. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnFlip, flip)
  699. if self.action['desc'] == "flipLine":
  700. flip.Check(True)
  701. merge = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  702. text=_('Merge selected lines/boundaries'),
  703. kind=wx.ITEM_CHECK)
  704. toolMenu.AppendItem(merge)
  705. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnMerge, merge)
  706. if self.action['desc'] == "mergeLine":
  707. merge.Check(True)
  708. breakL = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  709. text=_('Break selected lines/boundaries at intersection'),
  710. kind=wx.ITEM_CHECK)
  711. toolMenu.AppendItem(breakL)
  712. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnBreak, breakL)
  713. if self.action['desc'] == "breakLine":
  714. breakL.Check(True)
  715. snap = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  716. text=_('Snap selected lines/boundaries (only to nodes)'),
  717. kind=wx.ITEM_CHECK)
  718. toolMenu.AppendItem(snap)
  719. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnSnap, snap)
  720. if self.action['desc'] == "snapLine":
  721. snap.Check(True)
  722. connect = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  723. text=_('Connect selected lines/boundaries'),
  724. kind=wx.ITEM_CHECK)
  725. toolMenu.AppendItem(connect)
  726. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnConnect, connect)
  727. if self.action['desc'] == "connectLine":
  728. connect.Check(True)
  729. query = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  730. text=_('Query features'),
  731. kind=wx.ITEM_CHECK)
  732. toolMenu.AppendItem(query)
  733. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnQuery, query)
  734. if self.action['desc'] == "queryLine":
  735. query.Check(True)
  736. zbulk = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  737. text=_('Z bulk-labeling of 3D lines'),
  738. kind=wx.ITEM_CHECK)
  739. toolMenu.AppendItem(zbulk)
  740. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnZBulk, zbulk)
  741. if self.action['desc'] == "zbulkLine":
  742. zbulk.Check(True)
  743. typeconv = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  744. text=_('Feature type conversion'),
  745. kind=wx.ITEM_CHECK)
  746. toolMenu.AppendItem(typeconv)
  747. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnTypeConversion, typeconv)
  748. if self.action['desc'] == "typeConv":
  749. typeconv.Check(True)
  750. # Popup the menu. If an item is selected then its handler
  751. # will be called before PopupMenu returns.
  752. self.parent.MapWindow.PopupMenu(toolMenu)
  753. toolMenu.Destroy()
  754. if self.action['desc'] == 'addPoint':
  755. self.toolbar[0].ToggleTool(self.additionalTools, False)
  756. def OnCopy(self, event):
  757. """Copy selected features from (background) vector map"""
  758. if self.action['desc'] == 'copyLine': # select previous action
  759. self.toolbar[0].ToggleTool(self.addPoint, True)
  760. self.toolbar[0].ToggleTool(self.additionalTools, False)
  761. self.OnAddPoint(event)
  762. return
  763. Debug.msg(2, "Digittoolbar.OnCopy():")
  764. self.action = { 'desc' : "copyLine",
  765. 'id' : self.additionalTools }
  766. self.parent.MapWindow.mouse['box'] = 'box'
  767. def OnFlip(self, event):
  768. """Flip selected lines/boundaries"""
  769. if self.action['desc'] == 'flipLine': # select previous action
  770. self.toolbar[0].ToggleTool(self.addPoint, True)
  771. self.toolbar[0].ToggleTool(self.additionalTools, False)
  772. self.OnAddPoint(event)
  773. return
  774. Debug.msg(2, "Digittoolbar.OnFlip():")
  775. self.action = { 'desc' : "flipLine",
  776. 'id' : self.additionalTools }
  777. self.parent.MapWindow.mouse['box'] = 'box'
  778. def OnMerge(self, event):
  779. """Merge selected lines/boundaries"""
  780. if self.action['desc'] == 'mergeLine': # select previous action
  781. self.toolbar[0].ToggleTool(self.addPoint, True)
  782. self.toolbar[0].ToggleTool(self.additionalTools, False)
  783. self.OnAddPoint(event)
  784. return
  785. Debug.msg(2, "Digittoolbar.OnMerge():")
  786. self.action = { 'desc' : "mergeLine",
  787. 'id' : self.additionalTools }
  788. self.parent.MapWindow.mouse['box'] = 'box'
  789. def OnBreak(self, event):
  790. """Break selected lines/boundaries"""
  791. if self.action['desc'] == 'breakLine': # select previous action
  792. self.toolbar[0].ToggleTool(self.addPoint, True)
  793. self.toolbar[0].ToggleTool(self.additionalTools, False)
  794. self.OnAddPoint(event)
  795. return
  796. Debug.msg(2, "Digittoolbar.OnBreak():")
  797. self.action = { 'desc' : "breakLine",
  798. 'id' : self.additionalTools }
  799. self.parent.MapWindow.mouse['box'] = 'box'
  800. def OnSnap(self, event):
  801. """Snap selected features"""
  802. if self.action['desc'] == 'snapLine': # select previous action
  803. self.toolbar[0].ToggleTool(self.addPoint, True)
  804. self.toolbar[0].ToggleTool(self.additionalTools, False)
  805. self.OnAddPoint(event)
  806. return
  807. Debug.msg(2, "Digittoolbar.OnSnap():")
  808. self.action = { 'desc' : "snapLine",
  809. 'id' : self.additionalTools }
  810. self.parent.MapWindow.mouse['box'] = 'box'
  811. def OnConnect(self, event):
  812. """Connect selected lines/boundaries"""
  813. if self.action['desc'] == 'connectLine': # select previous action
  814. self.toolbar[0].ToggleTool(self.addPoint, True)
  815. self.toolbar[0].ToggleTool(self.additionalTools, False)
  816. self.OnAddPoint(event)
  817. return
  818. Debug.msg(2, "Digittoolbar.OnConnect():")
  819. self.action = { 'desc' : "connectLine",
  820. 'id' : self.additionalTools }
  821. self.parent.MapWindow.mouse['box'] = 'box'
  822. def OnQuery(self, event):
  823. """Query selected lines/boundaries"""
  824. if self.action['desc'] == 'queryLine': # select previous action
  825. self.toolbar[0].ToggleTool(self.addPoint, True)
  826. self.toolbar[0].ToggleTool(self.additionalTools, False)
  827. self.OnAddPoint(event)
  828. return
  829. Debug.msg(2, "Digittoolbar.OnQuery(): %s" % \
  830. UserSettings.Get(group='vdigit', key='query', subkey='selection'))
  831. self.action = { 'desc' : "queryLine",
  832. 'id' : self.additionalTools }
  833. self.parent.MapWindow.mouse['box'] = 'box'
  834. def OnZBulk(self, event):
  835. """Z bulk-labeling selected lines/boundaries"""
  836. if self.action['desc'] == 'zbulkLine': # select previous action
  837. self.toolbar[0].ToggleTool(self.addPoint, True)
  838. self.toolbar[0].ToggleTool(self.additionalTools, False)
  839. self.OnAddPoint(event)
  840. return
  841. Debug.msg(2, "Digittoolbar.OnZBulk():")
  842. self.action = { 'desc' : "zbulkLine",
  843. 'id' : self.additionalTools }
  844. self.parent.MapWindow.mouse['box'] = 'line'
  845. def OnTypeConversion(self, event):
  846. """Feature type conversion
  847. Supported conversions:
  848. - point <-> centroid
  849. - line <-> boundary
  850. """
  851. if self.action['desc'] == 'typeConv': # select previous action
  852. self.toolbar[0].ToggleTool(self.addPoint, True)
  853. self.toolbar[0].ToggleTool(self.additionalTools, False)
  854. self.OnAddPoint(event)
  855. return
  856. Debug.msg(2, "Digittoolbar.OnTypeConversion():")
  857. self.action = { 'desc' : "typeConv",
  858. 'id' : self.additionalTools }
  859. self.parent.MapWindow.mouse['box'] = 'box'
  860. def OnSelectMap (self, event):
  861. """
  862. Select vector map layer for editing
  863. If there is a vector map layer already edited, this action is
  864. firstly terminated. The map layer is closed. After this the
  865. selected map layer activated for editing.
  866. """
  867. if event.GetSelection() == 0: # create new vector map layer
  868. if self.mapLayer:
  869. openVectorMap = self.mapLayer.GetName(fullyQualified=False)['name']
  870. else:
  871. openVectorMap = None
  872. mapName = gdialogs.CreateNewVector(self.parent,
  873. exceptMap = openVectorMap, log = self.log,
  874. cmd = (('v.edit',
  875. { 'tool' : 'create' },
  876. 'map')),
  877. disableAdd=True)[0]
  878. if mapName:
  879. # add layer to map layer tree
  880. if self.layerTree:
  881. self.layerTree.AddLayer(ltype='vector',
  882. lname=mapName,
  883. lchecked=True,
  884. lopacity=1.0,
  885. lcmd=['d.vect', 'map=%s' % mapName])
  886. vectLayers = self.UpdateListOfLayers(updateTool=True)
  887. selection = vectLayers.index(mapName)
  888. else:
  889. pass # TODO (no Layer Manager)
  890. else:
  891. self.combo.SetValue(_('Select vector map'))
  892. return
  893. else:
  894. selection = event.GetSelection() - 1 # first option is 'New vector map'
  895. # skip currently selected map
  896. if self.layers[selection] == self.mapLayer:
  897. return False
  898. if self.mapLayer:
  899. # deactive map layer for editing
  900. self.StopEditing()
  901. # select the given map layer for editing
  902. self.StartEditing(self.layers[selection])
  903. event.Skip()
  904. return True
  905. def StartEditing (self, mapLayer):
  906. """
  907. Start editing selected vector map layer.
  908. @param mapLayer reference to MapLayer instance
  909. """
  910. # deactive layer
  911. self.mapcontent.ChangeLayerActive(mapLayer, False)
  912. # clean map canvas
  913. ### self.parent.MapWindow.EraseMap()
  914. # unset background map if needed
  915. if UserSettings.Get(group='vdigit', key='bgmap',
  916. subkey='value', internal=True) == mapLayer.GetName():
  917. UserSettings.Set(group='vdigit', key='bgmap',
  918. subkey='value', value='', internal=True)
  919. self.parent.statusbar.SetStatusText(_("Please wait, "
  920. "opening vector map <%s> for editing...") % \
  921. mapLayer.GetName(),
  922. 0)
  923. # reload vdigit module
  924. reload(vdigit)
  925. from vdigit import Digit as Digit
  926. self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
  927. self.mapLayer = mapLayer
  928. # open vector map
  929. try:
  930. self.parent.digit.SetMapName(mapLayer.GetName())
  931. except gcmd.DigitError, e:
  932. self.mapLayer = None
  933. print >> sys.stderr, e # wxMessageBox
  934. return False
  935. # update toolbar
  936. self.combo.SetValue(mapLayer.GetName())
  937. self.parent.toolbars['map'].combo.SetValue (_('Digitize'))
  938. Debug.msg (4, "VDigitToolbar.StartEditing(): layer=%s" % mapLayer.GetName())
  939. # change cursor
  940. if self.parent.MapWindow.mouse['use'] == 'pointer':
  941. self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
  942. # create pseudoDC for drawing the map
  943. self.parent.MapWindow.pdcVector = vdigit.PseudoDC()
  944. self.parent.digit.driver.SetDevice(self.parent.MapWindow.pdcVector)
  945. if not self.parent.MapWindow.resize:
  946. self.parent.MapWindow.UpdateMap(render=True)
  947. opacity = mapLayer.GetOpacity(float=True)
  948. if opacity < 1.0:
  949. alpha = int(opacity * 255)
  950. self.parent.digit.driver.UpdateSettings(alpha)
  951. return True
  952. def StopEditing (self):
  953. """Stop editing of selected vector map layer.
  954. @return True on success
  955. @return False on failure
  956. """
  957. if not self.mapLayer:
  958. return False
  959. Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % self.mapLayer.GetName())
  960. self.combo.SetValue (_('Select vector map'))
  961. # save changes
  962. if UserSettings.Get(group='vdigit', key='saveOnExit', subkey='enabled') is False:
  963. if self.parent.digit.GetUndoLevel() > 0:
  964. dlg = wx.MessageDialog(parent=self.parent,
  965. message=_("Do you want to save changes "
  966. "in vector map <%s>?") % self.mapLayer.GetName(),
  967. caption=_("Save changes?"),
  968. style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  969. if dlg.ShowModal() == wx.ID_NO:
  970. # revert changes
  971. self.parent.digit.Undo(0)
  972. dlg.Destroy()
  973. self.parent.statusbar.SetStatusText(_("Please wait, "
  974. "closing and rebuilding topology of "
  975. "vector map <%s>...") % self.mapLayer.GetName(),
  976. 0)
  977. self.parent.digit.SetMapName(None) # -> close map
  978. # re-active layer
  979. item = self.parent.tree.FindItemByData('maplayer', self.mapLayer)
  980. if item and self.parent.tree.IsItemChecked(item):
  981. self.mapcontent.ChangeLayerActive(self.mapLayer, True)
  982. # change cursor
  983. self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
  984. # disable pseudodc for vector map layer
  985. self.parent.MapWindow.pdcVector = None
  986. self.parent.digit.driver.SetDevice(None)
  987. # close dialogs
  988. for dialog in ('attributes', 'category'):
  989. if self.parent.dialogs[dialog]:
  990. self.parent.dialogs[dialog].Close()
  991. self.parent.dialogs[dialog] = None
  992. self.parent.digit.__del__() # FIXME: destructor is not called here (del)
  993. self.parent.digit = None
  994. self.mapLayer = None
  995. return True
  996. def UpdateListOfLayers (self, updateTool=False):
  997. """
  998. Update list of available vector map layers.
  999. This list consists only editable layers (in the current mapset)
  1000. Optionally also update toolbar
  1001. """
  1002. Debug.msg (4, "VDigitToolbar.UpdateListOfLayers(): updateTool=%d" % \
  1003. updateTool)
  1004. layerNameSelected = None
  1005. # name of currently selected layer
  1006. if self.mapLayer:
  1007. layerNameSelected = self.mapLayer.GetName()
  1008. # select vector map layer in the current mapset
  1009. layerNameList = []
  1010. self.layers = self.mapcontent.GetListOfLayers(l_type="vector",
  1011. l_mapset=grass.gisenv()['MAPSET'])
  1012. for layer in self.layers:
  1013. if not layer.name in layerNameList: # do not duplicate layer
  1014. layerNameList.append (layer.GetName())
  1015. if updateTool: # update toolbar
  1016. if not self.mapLayer:
  1017. value = _('Select vector map')
  1018. else:
  1019. value = layerNameSelected
  1020. if not self.comboid:
  1021. self.combo = wx.ComboBox(self.toolbar[self.numOfRows-1], id=wx.ID_ANY, value=value,
  1022. choices=[_('New vector map'), ] + layerNameList, size=(105, -1),
  1023. style=wx.CB_READONLY)
  1024. self.comboid = self.toolbar[self.numOfRows-1].InsertControl(0, self.combo)
  1025. self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectMap, self.comboid)
  1026. else:
  1027. self.combo.SetItems([_('New vector map'), ] + layerNameList)
  1028. self.toolbar[self.numOfRows-1].Realize()
  1029. return layerNameList
  1030. def GetLayer(self):
  1031. """Get selected layer for editing -- MapLayer instance"""
  1032. return self.mapLayer
  1033. class ProfileToolbar(AbstractToolbar):
  1034. """
  1035. Toolbar for profiling raster map
  1036. """
  1037. def __init__(self, parent, tbframe):
  1038. self.parent = parent # GCP
  1039. self.tbframe = tbframe
  1040. self.toolbar = wx.ToolBar(parent=self.tbframe, id=wx.ID_ANY)
  1041. # self.SetToolBar(self.toolbar)
  1042. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  1043. self.InitToolbar(self.tbframe, self.toolbar, self.ToolbarData())
  1044. # realize the toolbar
  1045. self.toolbar.Realize()
  1046. def ToolbarData(self):
  1047. """Toolbar data"""
  1048. self.transect = wx.NewId()
  1049. self.addraster = wx.NewId()
  1050. self.draw = wx.NewId()
  1051. self.options = wx.NewId()
  1052. self.drag = wx.NewId()
  1053. self.zoom = wx.NewId()
  1054. self.unzoom = wx.NewId()
  1055. self.erase = wx.NewId()
  1056. self.save = wx.NewId()
  1057. self.printer = wx.NewId()
  1058. self.quit = wx.NewId()
  1059. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  1060. return (
  1061. (self.addraster, 'raster', Icons["addrast"].GetBitmap(),
  1062. wx.ITEM_NORMAL, Icons["addrast"].GetLabel(), Icons["addrast"].GetDesc(),
  1063. self.parent.OnSelectRaster),
  1064. (self.transect, 'transect', Icons["transect"].GetBitmap(),
  1065. wx.ITEM_NORMAL, Icons["transect"].GetLabel(), Icons["transect"].GetDesc(),
  1066. self.parent.OnDrawTransect),
  1067. (self.draw, 'profiledraw', Icons["profiledraw"].GetBitmap(),
  1068. wx.ITEM_NORMAL, Icons["profiledraw"].GetLabel(), Icons["profiledraw"].GetDesc(),
  1069. self.parent.OnCreateProfile),
  1070. (self.options, 'options', Icons["profileopt"].GetBitmap(),
  1071. wx.ITEM_NORMAL, Icons["profileopt"].GetLabel(), Icons["profileopt"].GetDesc(),
  1072. self.parent.ProfileOptionsMenu),
  1073. (self.drag, 'drag', Icons['pan'].GetBitmap(),
  1074. wx.ITEM_NORMAL, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  1075. self.parent.OnDrag),
  1076. (self.zoom, 'zoom', Icons['zoom_in'].GetBitmap(),
  1077. wx.ITEM_NORMAL, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  1078. self.parent.OnZoom),
  1079. (self.unzoom, 'unzoom', Icons['zoom_back'].GetBitmap(),
  1080. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  1081. self.parent.OnRedraw),
  1082. (self.erase, 'erase', Icons["erase"].GetBitmap(),
  1083. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  1084. self.parent.OnErase),
  1085. ("", "", "", "", "", "", ""),
  1086. (self.save, 'save', Icons["savefile"].GetBitmap(),
  1087. wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
  1088. self.parent.SaveToFile),
  1089. (self.printer, 'print', Icons["printmap"].GetBitmap(),
  1090. wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
  1091. self.parent.PrintMenu),
  1092. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  1093. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  1094. self.parent.OnQuit),
  1095. )
  1096. class NvizToolbar(AbstractToolbar):
  1097. """
  1098. Nviz toolbar
  1099. """
  1100. def __init__(self, parent, map):
  1101. self.parent = parent
  1102. self.mapcontent = map
  1103. self.toolbar = wx.ToolBar(parent=self.parent, id=wx.ID_ANY)
  1104. # self.SetToolBar(self.toolbar)
  1105. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  1106. self.InitToolbar(self.parent, self.toolbar, self.ToolbarData())
  1107. # realize the toolbar
  1108. self.toolbar.Realize()
  1109. def ToolbarData(self):
  1110. """Toolbar data"""
  1111. self.settings = wx.NewId()
  1112. self.quit = wx.NewId()
  1113. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  1114. return (
  1115. (self.settings, "settings", Icons["nvizSettings"].GetBitmap(),
  1116. wx.ITEM_NORMAL, Icons["nvizSettings"].GetLabel(), Icons["nvizSettings"].GetDesc(),
  1117. self.OnSettings),
  1118. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  1119. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  1120. self.OnExit),
  1121. )
  1122. def OnSettings(self, event):
  1123. win = self.parent.nvizToolWin
  1124. if not win.IsShown():
  1125. self.parent.nvizToolWin.Show()
  1126. else:
  1127. self.parent.nvizToolWin.Hide()
  1128. def OnExit (self, event=None):
  1129. """Quit nviz tool (swith to 2D mode)"""
  1130. # hide dialogs if still open
  1131. if self.parent.nvizToolWin:
  1132. self.parent.nvizToolWin.Hide()
  1133. # disable the toolbar
  1134. self.parent.RemoveToolbar ("nviz")
  1135. # set default mouse settings
  1136. self.parent.MapWindow.mouse['use'] = "pointer"
  1137. self.parent.MapWindow.mouse['box'] = "point"
  1138. self.parent.MapWindow.polycoords = []