toolbars.py 55 KB

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