toolbars.py 54 KB

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