toolbars.py 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  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()
  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. if self.parent.digit and \
  513. len(self.parent.digit.driver.GetSelected()) > 0:
  514. # cancel action
  515. self.parent.MapWindow.OnMiddleDown(None)
  516. def OnAddPoint(self, event):
  517. """Add point to the vector map Laier"""
  518. Debug.msg (2, "VDigitToolbar.OnAddPoint()")
  519. self.action = { 'desc' : "addLine",
  520. 'type' : "point",
  521. 'id' : self.addPoint }
  522. self.parent.MapWindow.mouse['box'] = 'point'
  523. def OnAddLine(self, event):
  524. """Add line to the vector map layer"""
  525. Debug.msg (2, "VDigitToolbar.OnAddLine()")
  526. self.action = { 'desc' : "addLine",
  527. 'type' : "line",
  528. 'id' : self.addLine }
  529. self.parent.MapWindow.mouse['box'] = 'line'
  530. ### self.parent.MapWindow.polycoords = [] # reset temp line
  531. def OnAddBoundary(self, event):
  532. """Add boundary to the vector map layer"""
  533. Debug.msg (2, "VDigitToolbar.OnAddBoundary()")
  534. if self.action['desc'] != 'addLine' or \
  535. self.action['type'] != 'boundary':
  536. self.parent.MapWindow.polycoords = [] # reset temp line
  537. self.action = { 'desc' : "addLine",
  538. 'type' : "boundary",
  539. 'id' : self.addBoundary }
  540. self.parent.MapWindow.mouse['box'] = 'line'
  541. def OnAddCentroid(self, event):
  542. """Add centroid to the vector map layer"""
  543. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  544. self.action = { 'desc' : "addLine",
  545. 'type' : "centroid",
  546. 'id' : self.addCentroid }
  547. self.parent.MapWindow.mouse['box'] = 'point'
  548. def OnExit (self, event=None):
  549. """Quit digitization tool"""
  550. # stop editing of the currently selected map layer
  551. if self.mapLayer:
  552. self.StopEditing()
  553. # close dialogs if still open
  554. if self.settingsDialog:
  555. self.settingsDialog.OnCancel(None)
  556. # disable the toolbar
  557. self.parent.RemoveToolbar ("vdigit")
  558. # set default mouse settings
  559. self.parent.MapWindow.mouse['use'] = "pointer"
  560. self.parent.MapWindow.mouse['box'] = "point"
  561. self.parent.MapWindow.polycoords = []
  562. def OnMoveVertex(self, event):
  563. """Move line vertex"""
  564. Debug.msg(2, "Digittoolbar.OnMoveVertex():")
  565. self.action = { 'desc' : "moveVertex",
  566. 'id' : self.moveVertex }
  567. self.parent.MapWindow.mouse['box'] = 'point'
  568. def OnAddVertex(self, event):
  569. """Add line vertex"""
  570. Debug.msg(2, "Digittoolbar.OnAddVertex():")
  571. self.action = { 'desc' : "addVertex",
  572. 'id' : self.addVertex }
  573. self.parent.MapWindow.mouse['box'] = 'point'
  574. def OnRemoveVertex(self, event):
  575. """Remove line vertex"""
  576. Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
  577. self.action = { 'desc' : "removeVertex",
  578. 'id' : self.removeVertex }
  579. self.parent.MapWindow.mouse['box'] = 'point'
  580. def OnSplitLine(self, event):
  581. """Split line"""
  582. Debug.msg(2, "Digittoolbar.OnSplitLine():")
  583. self.action = { 'desc' : "splitLine",
  584. 'id' : self.splitLine }
  585. self.parent.MapWindow.mouse['box'] = 'point'
  586. def OnEditLine(self, event):
  587. """Edit line"""
  588. Debug.msg(2, "Digittoolbar.OnEditLine():")
  589. self.action = { 'desc' : "editLine",
  590. 'id' : self.editLine }
  591. self.parent.MapWindow.mouse['box'] = 'line'
  592. def OnMoveLine(self, event):
  593. """Move line"""
  594. Debug.msg(2, "Digittoolbar.OnMoveLine():")
  595. self.action = { 'desc' : "moveLine",
  596. 'id' : self.moveLine }
  597. self.parent.MapWindow.mouse['box'] = 'box'
  598. def OnDeleteLine(self, event):
  599. """Delete line"""
  600. Debug.msg(2, "Digittoolbar.OnDeleteLine():")
  601. self.action = { 'desc' : "deleteLine",
  602. 'id' : self.deleteLine }
  603. self.parent.MapWindow.mouse['box'] = 'box'
  604. def OnDisplayCats(self, event):
  605. """Display/update categories"""
  606. Debug.msg(2, "Digittoolbar.OnDisplayCats():")
  607. self.action = { 'desc' : "displayCats",
  608. 'id' : self.displayCats }
  609. self.parent.MapWindow.mouse['box'] = 'point'
  610. def OnDisplayAttr(self, event):
  611. """Display/update attributes"""
  612. Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
  613. self.action = { 'desc' : "displayAttrs",
  614. 'id' : self.displayAttr }
  615. self.parent.MapWindow.mouse['box'] = 'point'
  616. def OnCopyCA(self, event):
  617. """Copy categories/attributes menu"""
  618. point = wx.GetMousePosition()
  619. toolMenu = wx.Menu()
  620. # Add items to the menu
  621. cats = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  622. text=_('Copy categories'),
  623. kind=wx.ITEM_CHECK)
  624. toolMenu.AppendItem(cats)
  625. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyCats, cats)
  626. if self.action['desc'] == "copyCats":
  627. cats.Check(True)
  628. attrb = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  629. text=_('Duplicate attributes'),
  630. kind=wx.ITEM_CHECK)
  631. toolMenu.AppendItem(attrb)
  632. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyAttrb, attrb)
  633. if self.action['desc'] == "copyAttrs":
  634. attrb.Check(True)
  635. # Popup the menu. If an item is selected then its handler
  636. # will be called before PopupMenu returns.
  637. self.parent.MapWindow.PopupMenu(toolMenu)
  638. toolMenu.Destroy()
  639. if self.action['desc'] == "addPoint":
  640. self.toolbar[0].ToggleTool(self.copyCats, False)
  641. def OnCopyCats(self, event):
  642. """Copy categories"""
  643. if self.action['desc'] == 'copyCats': # select previous action
  644. self.toolbar[0].ToggleTool(self.addPoint, True)
  645. self.toolbar[0].ToggleTool(self.copyCats, False)
  646. self.OnAddPoint(event)
  647. return
  648. Debug.msg(2, "Digittoolbar.OnCopyCats():")
  649. self.action = { 'desc' : "copyCats",
  650. 'id' : self.copyCats }
  651. self.parent.MapWindow.mouse['box'] = 'point'
  652. def OnCopyAttrb(self, event):
  653. if self.action['desc'] == 'copyAttrs': # select previous action
  654. self.toolbar[0].ToggleTool(self.addPoint, True)
  655. self.toolbar[0].ToggleTool(self.copyCats, False)
  656. self.OnAddPoint(event)
  657. return
  658. Debug.msg(2, "Digittoolbar.OnCopyAttrb():")
  659. self.action = { 'desc' : "copyAttrs",
  660. 'id' : self.copyCats }
  661. self.parent.MapWindow.mouse['box'] = 'point'
  662. def OnUndo(self, event):
  663. """Undo previous changes"""
  664. self.parent.digit.Undo()
  665. event.Skip()
  666. def EnableUndo(self, enable=True):
  667. """Enable 'Undo' in toolbar
  668. @param enable False for disable
  669. """
  670. if enable:
  671. if self.toolbar[0].GetToolEnabled(self.undo) is False:
  672. self.toolbar[0].EnableTool(self.undo, True)
  673. else:
  674. if self.toolbar[0].GetToolEnabled(self.undo) is True:
  675. self.toolbar[0].EnableTool(self.undo, False)
  676. def OnSettings(self, event):
  677. """Show settings dialog"""
  678. if self.parent.digit is None:
  679. reload(vdigit)
  680. from vdigit import Digit as Digit
  681. self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
  682. if not self.settingsDialog:
  683. self.settingsDialog = VDigitSettingsDialog(parent=self.parent, title=_("Digitization settings"),
  684. style=wx.DEFAULT_DIALOG_STYLE)
  685. self.settingsDialog.Show()
  686. def OnAdditionalToolMenu(self, event):
  687. """Menu for additional tools"""
  688. point = wx.GetMousePosition()
  689. toolMenu = wx.Menu()
  690. # Add items to the menu
  691. copy = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  692. text=_('Copy features from (background) vector map'),
  693. kind=wx.ITEM_CHECK)
  694. toolMenu.AppendItem(copy)
  695. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopy, copy)
  696. if self.action['desc'] == "copyLine":
  697. copy.Check(True)
  698. flip = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  699. text=_('Flip selected lines/boundaries'),
  700. kind=wx.ITEM_CHECK)
  701. toolMenu.AppendItem(flip)
  702. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnFlip, flip)
  703. if self.action['desc'] == "flipLine":
  704. flip.Check(True)
  705. merge = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  706. text=_('Merge selected lines/boundaries'),
  707. kind=wx.ITEM_CHECK)
  708. toolMenu.AppendItem(merge)
  709. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnMerge, merge)
  710. if self.action['desc'] == "mergeLine":
  711. merge.Check(True)
  712. breakL = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  713. text=_('Break selected lines/boundaries at intersection'),
  714. kind=wx.ITEM_CHECK)
  715. toolMenu.AppendItem(breakL)
  716. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnBreak, breakL)
  717. if self.action['desc'] == "breakLine":
  718. breakL.Check(True)
  719. snap = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  720. text=_('Snap selected lines/boundaries (only to nodes)'),
  721. kind=wx.ITEM_CHECK)
  722. toolMenu.AppendItem(snap)
  723. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnSnap, snap)
  724. if self.action['desc'] == "snapLine":
  725. snap.Check(True)
  726. connect = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  727. text=_('Connect selected lines/boundaries'),
  728. kind=wx.ITEM_CHECK)
  729. toolMenu.AppendItem(connect)
  730. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnConnect, connect)
  731. if self.action['desc'] == "connectLine":
  732. connect.Check(True)
  733. query = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  734. text=_('Query features'),
  735. kind=wx.ITEM_CHECK)
  736. toolMenu.AppendItem(query)
  737. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnQuery, query)
  738. if self.action['desc'] == "queryLine":
  739. query.Check(True)
  740. zbulk = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  741. text=_('Z bulk-labeling of 3D lines'),
  742. kind=wx.ITEM_CHECK)
  743. toolMenu.AppendItem(zbulk)
  744. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnZBulk, zbulk)
  745. if self.action['desc'] == "zbulkLine":
  746. zbulk.Check(True)
  747. typeconv = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  748. text=_('Feature type conversion'),
  749. kind=wx.ITEM_CHECK)
  750. toolMenu.AppendItem(typeconv)
  751. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnTypeConversion, typeconv)
  752. if self.action['desc'] == "typeConv":
  753. typeconv.Check(True)
  754. # Popup the menu. If an item is selected then its handler
  755. # will be called before PopupMenu returns.
  756. self.parent.MapWindow.PopupMenu(toolMenu)
  757. toolMenu.Destroy()
  758. if self.action['desc'] == 'addPoint':
  759. self.toolbar[0].ToggleTool(self.additionalTools, False)
  760. def OnCopy(self, event):
  761. """Copy selected features from (background) vector map"""
  762. if self.action['desc'] == 'copyLine': # select previous action
  763. self.toolbar[0].ToggleTool(self.addPoint, True)
  764. self.toolbar[0].ToggleTool(self.additionalTools, False)
  765. self.OnAddPoint(event)
  766. return
  767. Debug.msg(2, "Digittoolbar.OnCopy():")
  768. self.action = { 'desc' : "copyLine",
  769. 'id' : self.additionalTools }
  770. self.parent.MapWindow.mouse['box'] = 'box'
  771. def OnFlip(self, event):
  772. """Flip selected lines/boundaries"""
  773. if self.action['desc'] == 'flipLine': # select previous action
  774. self.toolbar[0].ToggleTool(self.addPoint, True)
  775. self.toolbar[0].ToggleTool(self.additionalTools, False)
  776. self.OnAddPoint(event)
  777. return
  778. Debug.msg(2, "Digittoolbar.OnFlip():")
  779. self.action = { 'desc' : "flipLine",
  780. 'id' : self.additionalTools }
  781. self.parent.MapWindow.mouse['box'] = 'box'
  782. def OnMerge(self, event):
  783. """Merge selected lines/boundaries"""
  784. if self.action['desc'] == 'mergeLine': # select previous action
  785. self.toolbar[0].ToggleTool(self.addPoint, True)
  786. self.toolbar[0].ToggleTool(self.additionalTools, False)
  787. self.OnAddPoint(event)
  788. return
  789. Debug.msg(2, "Digittoolbar.OnMerge():")
  790. self.action = { 'desc' : "mergeLine",
  791. 'id' : self.additionalTools }
  792. self.parent.MapWindow.mouse['box'] = 'box'
  793. def OnBreak(self, event):
  794. """Break selected lines/boundaries"""
  795. if self.action['desc'] == 'breakLine': # select previous action
  796. self.toolbar[0].ToggleTool(self.addPoint, True)
  797. self.toolbar[0].ToggleTool(self.additionalTools, False)
  798. self.OnAddPoint(event)
  799. return
  800. Debug.msg(2, "Digittoolbar.OnBreak():")
  801. self.action = { 'desc' : "breakLine",
  802. 'id' : self.additionalTools }
  803. self.parent.MapWindow.mouse['box'] = 'box'
  804. def OnSnap(self, event):
  805. """Snap selected features"""
  806. if self.action['desc'] == 'snapLine': # select previous action
  807. self.toolbar[0].ToggleTool(self.addPoint, True)
  808. self.toolbar[0].ToggleTool(self.additionalTools, False)
  809. self.OnAddPoint(event)
  810. return
  811. Debug.msg(2, "Digittoolbar.OnSnap():")
  812. self.action = { 'desc' : "snapLine",
  813. 'id' : self.additionalTools }
  814. self.parent.MapWindow.mouse['box'] = 'box'
  815. def OnConnect(self, event):
  816. """Connect selected lines/boundaries"""
  817. if self.action['desc'] == 'connectLine': # select previous action
  818. self.toolbar[0].ToggleTool(self.addPoint, True)
  819. self.toolbar[0].ToggleTool(self.additionalTools, False)
  820. self.OnAddPoint(event)
  821. return
  822. Debug.msg(2, "Digittoolbar.OnConnect():")
  823. self.action = { 'desc' : "connectLine",
  824. 'id' : self.additionalTools }
  825. self.parent.MapWindow.mouse['box'] = 'box'
  826. def OnQuery(self, event):
  827. """Query selected lines/boundaries"""
  828. if self.action['desc'] == 'queryLine': # select previous action
  829. self.toolbar[0].ToggleTool(self.addPoint, True)
  830. self.toolbar[0].ToggleTool(self.additionalTools, False)
  831. self.OnAddPoint(event)
  832. return
  833. Debug.msg(2, "Digittoolbar.OnQuery(): %s" % \
  834. UserSettings.Get(group='vdigit', key='query', subkey='selection'))
  835. self.action = { 'desc' : "queryLine",
  836. 'id' : self.additionalTools }
  837. self.parent.MapWindow.mouse['box'] = 'box'
  838. def OnZBulk(self, event):
  839. """Z bulk-labeling selected lines/boundaries"""
  840. if self.action['desc'] == 'zbulkLine': # select previous action
  841. self.toolbar[0].ToggleTool(self.addPoint, True)
  842. self.toolbar[0].ToggleTool(self.additionalTools, False)
  843. self.OnAddPoint(event)
  844. return
  845. Debug.msg(2, "Digittoolbar.OnZBulk():")
  846. self.action = { 'desc' : "zbulkLine",
  847. 'id' : self.additionalTools }
  848. self.parent.MapWindow.mouse['box'] = 'line'
  849. def OnTypeConversion(self, event):
  850. """Feature type conversion
  851. Supported conversions:
  852. - point <-> centroid
  853. - line <-> boundary
  854. """
  855. if self.action['desc'] == 'typeConv': # select previous action
  856. self.toolbar[0].ToggleTool(self.addPoint, True)
  857. self.toolbar[0].ToggleTool(self.additionalTools, False)
  858. self.OnAddPoint(event)
  859. return
  860. Debug.msg(2, "Digittoolbar.OnTypeConversion():")
  861. self.action = { 'desc' : "typeConv",
  862. 'id' : self.additionalTools }
  863. self.parent.MapWindow.mouse['box'] = 'box'
  864. def OnSelectMap (self, event):
  865. """
  866. Select vector map layer for editing
  867. If there is a vector map layer already edited, this action is
  868. firstly terminated. The map layer is closed. After this the
  869. selected map layer activated for editing.
  870. """
  871. if event.GetSelection() == 0: # create new vector map layer
  872. if self.mapLayer:
  873. openVectorMap = self.mapLayer.GetName(fullyQualified=False)['name']
  874. else:
  875. openVectorMap = None
  876. mapName = gdialogs.CreateNewVector(self.parent,
  877. exceptMap = openVectorMap, log = self.log,
  878. cmd = (('v.edit',
  879. { 'tool' : 'create' },
  880. 'map')),
  881. disableAdd=True)[0]
  882. if mapName:
  883. # add layer to map layer tree
  884. if self.layerTree:
  885. self.layerTree.AddLayer(ltype='vector',
  886. lname=mapName,
  887. lchecked=True,
  888. lopacity=1.0,
  889. lcmd=['d.vect', 'map=%s' % mapName])
  890. vectLayers = self.UpdateListOfLayers(updateTool=True)
  891. selection = vectLayers.index(mapName)
  892. else:
  893. pass # TODO (no Layer Manager)
  894. else:
  895. self.combo.SetValue(_('Select vector map'))
  896. return
  897. else:
  898. selection = event.GetSelection() - 1 # first option is 'New vector map'
  899. # skip currently selected map
  900. if self.layers[selection] == self.mapLayer:
  901. return False
  902. if self.mapLayer:
  903. # deactive map layer for editing
  904. self.StopEditing()
  905. # select the given map layer for editing
  906. self.StartEditing(self.layers[selection])
  907. event.Skip()
  908. return True
  909. def StartEditing (self, mapLayer):
  910. """
  911. Start editing selected vector map layer.
  912. @param mapLayer reference to MapLayer instance
  913. """
  914. # deactive layer
  915. self.mapcontent.ChangeLayerActive(mapLayer, False)
  916. # clean map canvas
  917. ### self.parent.MapWindow.EraseMap()
  918. # unset background map if needed
  919. if UserSettings.Get(group='vdigit', key='bgmap',
  920. subkey='value', internal=True) == mapLayer.GetName():
  921. UserSettings.Set(group='vdigit', key='bgmap',
  922. subkey='value', value='', internal=True)
  923. self.parent.statusbar.SetStatusText(_("Please wait, "
  924. "opening vector map <%s> for editing...") % \
  925. mapLayer.GetName(),
  926. 0)
  927. # reload vdigit module
  928. reload(vdigit)
  929. from vdigit import Digit as Digit
  930. self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
  931. self.mapLayer = mapLayer
  932. # open vector map
  933. try:
  934. self.parent.digit.SetMapName(mapLayer.GetName())
  935. except gcmd.DigitError, e:
  936. self.mapLayer = None
  937. print >> sys.stderr, e # wxMessageBox
  938. return False
  939. # update toolbar
  940. self.combo.SetValue(mapLayer.GetName())
  941. self.parent.toolbars['map'].combo.SetValue (_('Digitize'))
  942. Debug.msg (4, "VDigitToolbar.StartEditing(): layer=%s" % mapLayer.GetName())
  943. # change cursor
  944. if self.parent.MapWindow.mouse['use'] == 'pointer':
  945. self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
  946. # create pseudoDC for drawing the map
  947. self.parent.MapWindow.pdcVector = vdigit.PseudoDC()
  948. self.parent.digit.driver.SetDevice(self.parent.MapWindow.pdcVector)
  949. if not self.parent.MapWindow.resize:
  950. self.parent.MapWindow.UpdateMap(render=True)
  951. opacity = mapLayer.GetOpacity(float=True)
  952. if opacity < 1.0:
  953. alpha = int(opacity * 255)
  954. self.parent.digit.driver.UpdateSettings(alpha)
  955. return True
  956. def StopEditing (self):
  957. """Stop editing of selected vector map layer.
  958. @return True on success
  959. @return False on failure
  960. """
  961. if not self.mapLayer:
  962. return False
  963. Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % self.mapLayer.GetName())
  964. self.combo.SetValue (_('Select vector map'))
  965. # save changes
  966. if UserSettings.Get(group='vdigit', key='saveOnExit', subkey='enabled') is False:
  967. if self.parent.digit.GetUndoLevel() > 0:
  968. dlg = wx.MessageDialog(parent=self.parent,
  969. message=_("Do you want to save changes "
  970. "in vector map <%s>?") % self.mapLayer.GetName(),
  971. caption=_("Save changes?"),
  972. style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  973. if dlg.ShowModal() == wx.ID_NO:
  974. # revert changes
  975. self.parent.digit.Undo(0)
  976. dlg.Destroy()
  977. self.parent.statusbar.SetStatusText(_("Please wait, "
  978. "closing and rebuilding topology of "
  979. "vector map <%s>...") % self.mapLayer.GetName(),
  980. 0)
  981. self.parent.digit.SetMapName(None) # -> close map
  982. # re-active layer
  983. item = self.parent.tree.FindItemByData('maplayer', self.mapLayer)
  984. if item and self.parent.tree.IsItemChecked(item):
  985. self.mapcontent.ChangeLayerActive(self.mapLayer, True)
  986. # change cursor
  987. self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
  988. # disable pseudodc for vector map layer
  989. self.parent.MapWindow.pdcVector = None
  990. self.parent.digit.driver.SetDevice(None)
  991. # close dialogs
  992. for dialog in ('attributes', 'category'):
  993. if self.parent.dialogs[dialog]:
  994. self.parent.dialogs[dialog].Close()
  995. self.parent.dialogs[dialog] = None
  996. self.parent.digit.__del__() # FIXME: destructor is not called here (del)
  997. self.parent.digit = None
  998. self.mapLayer = None
  999. self.parent.MapWindow.redrawAll = True
  1000. return True
  1001. def UpdateListOfLayers (self, updateTool=False):
  1002. """
  1003. Update list of available vector map layers.
  1004. This list consists only editable layers (in the current mapset)
  1005. Optionally also update toolbar
  1006. """
  1007. Debug.msg (4, "VDigitToolbar.UpdateListOfLayers(): updateTool=%d" % \
  1008. updateTool)
  1009. layerNameSelected = None
  1010. # name of currently selected layer
  1011. if self.mapLayer:
  1012. layerNameSelected = self.mapLayer.GetName()
  1013. # select vector map layer in the current mapset
  1014. layerNameList = []
  1015. self.layers = self.mapcontent.GetListOfLayers(l_type="vector",
  1016. l_mapset=grass.gisenv()['MAPSET'])
  1017. for layer in self.layers:
  1018. if not layer.name in layerNameList: # do not duplicate layer
  1019. layerNameList.append (layer.GetName())
  1020. if updateTool: # update toolbar
  1021. if not self.mapLayer:
  1022. value = _('Select vector map')
  1023. else:
  1024. value = layerNameSelected
  1025. if not self.comboid:
  1026. self.combo = wx.ComboBox(self.toolbar[self.numOfRows-1], id=wx.ID_ANY, value=value,
  1027. choices=[_('New vector map'), ] + layerNameList, size=(105, -1),
  1028. style=wx.CB_READONLY)
  1029. self.comboid = self.toolbar[self.numOfRows-1].InsertControl(0, self.combo)
  1030. self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectMap, self.comboid)
  1031. else:
  1032. self.combo.SetItems([_('New vector map'), ] + layerNameList)
  1033. self.toolbar[self.numOfRows-1].Realize()
  1034. return layerNameList
  1035. def GetLayer(self):
  1036. """Get selected layer for editing -- MapLayer instance"""
  1037. return self.mapLayer
  1038. class ProfileToolbar(AbstractToolbar):
  1039. """
  1040. Toolbar for profiling raster map
  1041. """
  1042. def __init__(self, parent, tbframe):
  1043. self.parent = parent # GCP
  1044. self.tbframe = tbframe
  1045. self.toolbar = wx.ToolBar(parent=self.tbframe, id=wx.ID_ANY)
  1046. # self.SetToolBar(self.toolbar)
  1047. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  1048. self.InitToolbar(self.tbframe, self.toolbar, self.ToolbarData())
  1049. # realize the toolbar
  1050. self.toolbar.Realize()
  1051. def ToolbarData(self):
  1052. """Toolbar data"""
  1053. self.transect = wx.NewId()
  1054. self.addraster = wx.NewId()
  1055. self.draw = wx.NewId()
  1056. self.options = wx.NewId()
  1057. self.drag = wx.NewId()
  1058. self.zoom = wx.NewId()
  1059. self.unzoom = wx.NewId()
  1060. self.erase = wx.NewId()
  1061. self.save = wx.NewId()
  1062. self.printer = wx.NewId()
  1063. self.quit = wx.NewId()
  1064. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  1065. return (
  1066. (self.addraster, 'raster', Icons["addrast"].GetBitmap(),
  1067. wx.ITEM_NORMAL, Icons["addrast"].GetLabel(), Icons["addrast"].GetDesc(),
  1068. self.parent.OnSelectRaster),
  1069. (self.transect, 'transect', Icons["transect"].GetBitmap(),
  1070. wx.ITEM_NORMAL, Icons["transect"].GetLabel(), Icons["transect"].GetDesc(),
  1071. self.parent.OnDrawTransect),
  1072. (self.draw, 'profiledraw', Icons["profiledraw"].GetBitmap(),
  1073. wx.ITEM_NORMAL, Icons["profiledraw"].GetLabel(), Icons["profiledraw"].GetDesc(),
  1074. self.parent.OnCreateProfile),
  1075. (self.options, 'options', Icons["profileopt"].GetBitmap(),
  1076. wx.ITEM_NORMAL, Icons["profileopt"].GetLabel(), Icons["profileopt"].GetDesc(),
  1077. self.parent.ProfileOptionsMenu),
  1078. (self.drag, 'drag', Icons['pan'].GetBitmap(),
  1079. wx.ITEM_NORMAL, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  1080. self.parent.OnDrag),
  1081. (self.zoom, 'zoom', Icons['zoom_in'].GetBitmap(),
  1082. wx.ITEM_NORMAL, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  1083. self.parent.OnZoom),
  1084. (self.unzoom, 'unzoom', Icons['zoom_back'].GetBitmap(),
  1085. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  1086. self.parent.OnRedraw),
  1087. (self.erase, 'erase', Icons["erase"].GetBitmap(),
  1088. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  1089. self.parent.OnErase),
  1090. ("", "", "", "", "", "", ""),
  1091. (self.save, 'save', Icons["savefile"].GetBitmap(),
  1092. wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
  1093. self.parent.SaveToFile),
  1094. (self.printer, 'print', Icons["printmap"].GetBitmap(),
  1095. wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
  1096. self.parent.PrintMenu),
  1097. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  1098. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  1099. self.parent.OnQuit),
  1100. )
  1101. class NvizToolbar(AbstractToolbar):
  1102. """
  1103. Nviz toolbar
  1104. """
  1105. def __init__(self, parent, map):
  1106. self.parent = parent
  1107. self.mapcontent = map
  1108. self.toolbar = wx.ToolBar(parent=self.parent, id=wx.ID_ANY)
  1109. # self.SetToolBar(self.toolbar)
  1110. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  1111. self.InitToolbar(self.parent, self.toolbar, self.ToolbarData())
  1112. # realize the toolbar
  1113. self.toolbar.Realize()
  1114. def ToolbarData(self):
  1115. """Toolbar data"""
  1116. self.settings = wx.NewId()
  1117. self.quit = wx.NewId()
  1118. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  1119. return (
  1120. (self.settings, "settings", Icons["nvizSettings"].GetBitmap(),
  1121. wx.ITEM_NORMAL, Icons["nvizSettings"].GetLabel(), Icons["nvizSettings"].GetDesc(),
  1122. self.OnSettings),
  1123. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  1124. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  1125. self.OnExit),
  1126. )
  1127. def OnSettings(self, event):
  1128. win = self.parent.nvizToolWin
  1129. if not win.IsShown():
  1130. self.parent.nvizToolWin.Show()
  1131. else:
  1132. self.parent.nvizToolWin.Hide()
  1133. def OnExit (self, event=None):
  1134. """Quit nviz tool (swith to 2D mode)"""
  1135. # hide dialogs if still open
  1136. if self.parent.nvizToolWin:
  1137. self.parent.nvizToolWin.Hide()
  1138. # disable the toolbar
  1139. self.parent.RemoveToolbar ("nviz")
  1140. # set default mouse settings
  1141. self.parent.MapWindow.mouse['use'] = "pointer"
  1142. self.parent.MapWindow.mouse['box'] = "point"
  1143. self.parent.MapWindow.polycoords = []