toolbars.py 54 KB

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