toolbars.py 56 KB

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