toolbars.py 54 KB

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