toolbars.py 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742
  1. """!
  2. @package toolbar
  3. @brief wxGUI toolbar widgets
  4. Classes:
  5. - AbstractToolbar
  6. - MapToolbar
  7. - GCPMapToolbar
  8. - GCPDisplayToolbar
  9. - VDigitToolbar
  10. - ProfileToolbar
  11. - NvizToolbar
  12. - ModelToolbar
  13. - HistogramToolbar
  14. - LayerManagerToolbar
  15. - ToolsToolbar
  16. - PsMapToolbar
  17. (C) 2007-2011 by the GRASS Development Team
  18. This program is free software under the GNU General Public License
  19. (>=v2). Read the file COPYING that comes with GRASS for details.
  20. @author Michael Barton
  21. @author Jachym Cepicky
  22. @author Martin Landa <landa.martin gmail.com>
  23. @author Anna Kratochvilova <anna.kratochvilova fsv.cvut.cz>
  24. """
  25. import os
  26. import sys
  27. import platform
  28. from grass.script import core as grass
  29. import wx
  30. import globalvar
  31. import gcmd
  32. import gdialogs
  33. from vdigit import VDigitSettingsDialog, haveVDigit, VDigit
  34. from debug import Debug
  35. from preferences import globalSettings as UserSettings
  36. from nviz import haveNviz
  37. from nviz_preferences import NvizPreferencesDialog
  38. sys.path.append(os.path.join(globalvar.ETCWXDIR, "icons"))
  39. from icon import Icons
  40. class AbstractToolbar(wx.ToolBar):
  41. """!Abstract toolbar class"""
  42. def __init__(self, parent):
  43. self.parent = parent
  44. wx.ToolBar.__init__(self, parent = self.parent, id = wx.ID_ANY)
  45. self.action = dict()
  46. self.Bind(wx.EVT_TOOL, self.OnTool)
  47. self.SetToolBitmapSize(globalvar.toolbarSize)
  48. def InitToolbar(self, toolData):
  49. """!Initialize toolbar, add tools to the toolbar
  50. """
  51. for tool in toolData:
  52. self.CreateTool(*tool)
  53. self._data = toolData
  54. def _toolbarData(self):
  55. """!Toolbar data (virtual)"""
  56. return None
  57. def CreateTool(self, tool, label, bitmap, kind,
  58. shortHelp, longHelp, handler):
  59. """!Add tool to the toolbar
  60. @return id of tool
  61. """
  62. bmpDisabled = wx.NullBitmap
  63. if label:
  64. Debug.msg(3, "CreateTool(): tool=%d, label=%s bitmap=%s" % \
  65. (tool, label, bitmap))
  66. toolWin = self.AddLabelTool(tool, label, bitmap,
  67. bmpDisabled, kind,
  68. shortHelp, longHelp)
  69. self.Bind(wx.EVT_TOOL, handler, toolWin)
  70. else: # separator
  71. self.AddSeparator()
  72. return tool
  73. def EnableLongHelp(self, enable = True):
  74. """!Enable/disable long help
  75. @param enable True for enable otherwise disable
  76. """
  77. for tool in self._data:
  78. if tool[0] == '': # separator
  79. continue
  80. if enable:
  81. self.SetToolLongHelp(tool[0], tool[5])
  82. else:
  83. self.SetToolLongHelp(tool[0], "")
  84. def OnTool(self, event):
  85. """!Tool selected
  86. """
  87. if self.parent.GetName() == "GCPFrame":
  88. return
  89. if hasattr(self.parent, 'toolbars'):
  90. if self.parent.toolbars['vdigit']:
  91. # update vdigit toolbar (unselect currently selected tool)
  92. id = self.parent.toolbars['vdigit'].GetAction(type = 'id')
  93. self.parent.toolbars['vdigit'].ToggleTool(id, False)
  94. if event:
  95. # deselect previously selected tool
  96. id = self.action.get('id', -1)
  97. if id != event.GetId():
  98. self.ToggleTool(self.action['id'], False)
  99. else:
  100. self.ToggleTool(self.action['id'], True)
  101. self.action['id'] = event.GetId()
  102. event.Skip()
  103. else:
  104. # initialize toolbar
  105. self.ToggleTool(self.action['id'], True)
  106. def GetAction(self, type = 'desc'):
  107. """!Get current action info"""
  108. return self.action.get(type, '')
  109. def SelectDefault(self, event):
  110. """!Select default tool"""
  111. self.ToggleTool(self.defaultAction['id'], True)
  112. self.defaultAction['bind'](event)
  113. self.action = { 'id' : self.defaultAction['id'],
  114. 'desc' : self.defaultAction.get('desc', '') }
  115. def FixSize(self, width):
  116. """!Fix toolbar width on Windows
  117. @todo Determine why combobox causes problems here
  118. """
  119. if platform.system() == 'Windows':
  120. size = self.GetBestSize()
  121. self.SetSize((size[0] + width, size[1]))
  122. def Enable(self, tool, enable = True):
  123. """!Enable defined tool
  124. @param tool name
  125. @param enable True to enable otherwise disable tool
  126. """
  127. try:
  128. id = getattr(self, tool)
  129. except AttributeError:
  130. return
  131. self.EnableTool(id, enable)
  132. def _getToolbarData(self, data):
  133. """!Define tool
  134. """
  135. retData = list()
  136. for args in data:
  137. retData.append(self._defineTool(*args))
  138. return retData
  139. def _defineTool(self, key, name = None, icon = None, handler = None, item = wx.ITEM_NORMAL):
  140. """!Define tool
  141. """
  142. if key:
  143. return (key, name, icon.GetBitmap(),
  144. item, icon.GetLabel(), icon.GetDesc(),
  145. handler)
  146. return ("", "", "", "", "", "", "") # separator
  147. class MapToolbar(AbstractToolbar):
  148. """!Map Display toolbar
  149. """
  150. def __init__(self, parent, mapcontent):
  151. """!Map Display constructor
  152. @param parent reference to MapFrame
  153. @param mapcontent reference to render.Map (registred by MapFrame)
  154. """
  155. self.mapcontent = mapcontent # render.Map
  156. AbstractToolbar.__init__(self, parent = parent) # MapFrame
  157. self.InitToolbar(self._toolbarData())
  158. # optional tools
  159. choices = [ _('2D view'), ]
  160. self.toolId = { '2d' : 0 }
  161. if self.parent.GetLayerManager():
  162. log = self.parent.GetLayerManager().GetLogWindow()
  163. if haveNviz:
  164. choices.append(_('3D view'))
  165. self.toolId['3d'] = 1
  166. else:
  167. from nviz import errorMsg
  168. log.WriteCmdLog(_('3D view mode not available'))
  169. log.WriteWarning(_('Reason: %s') % str(errorMsg))
  170. log.WriteLog(_('Note that the wxGUI\'s 3D view mode is currently disabled '
  171. 'on MS Windows (hopefully this will be fixed soon). '
  172. 'Please keep an eye out for updated versions of GRASS. '
  173. 'In the meantime you can use "NVIZ" from the File menu.'), wrap = 60)
  174. self.toolId['3d'] = -1
  175. if haveVDigit:
  176. choices.append(_('Digitize'))
  177. if self.toolId['3d'] > -1:
  178. self.toolId['vdigit'] = 2
  179. else:
  180. self.toolId['vdigit'] = 1
  181. else:
  182. from vdigit import errorMsg
  183. log.WriteCmdLog(_('Vector digitizer not available'))
  184. log.WriteWarning(_('Reason: %s') % errorMsg)
  185. log.WriteLog(_('Note that the wxGUI\'s vector digitizer is currently disabled '
  186. '(hopefully this will be fixed soon). '
  187. 'Please keep an eye out for updated versions of GRASS. '
  188. 'In the meantime you can use "v.digit" from the Develop Vector menu.'), wrap = 60)
  189. self.toolId['vdigit'] = -1
  190. self.combo = wx.ComboBox(parent = self, id = wx.ID_ANY,
  191. choices = choices,
  192. style = wx.CB_READONLY, size = (90, -1))
  193. self.combo.SetSelection(0)
  194. self.comboid = self.AddControl(self.combo)
  195. self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectTool, self.comboid)
  196. # realize the toolbar
  197. self.Realize()
  198. # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
  199. self.combo.Hide()
  200. self.combo.Show()
  201. self.action = { 'id' : self.pointer }
  202. self.defaultAction = { 'id' : self.pointer,
  203. 'bind' : self.parent.OnPointer }
  204. self.OnTool(None)
  205. self.EnableTool(self.zoomback, False)
  206. self.FixSize(width = 90)
  207. def _toolbarData(self):
  208. """!Toolbar data"""
  209. self.displaymap = wx.NewId()
  210. self.rendermap = wx.NewId()
  211. self.erase = wx.NewId()
  212. self.pointer = wx.NewId()
  213. self.query = wx.NewId()
  214. self.pan = wx.NewId()
  215. self.zoomin = wx.NewId()
  216. self.zoomout = wx.NewId()
  217. self.zoomback = wx.NewId()
  218. self.zoommenu = wx.NewId()
  219. self.zoomextent = wx.NewId()
  220. self.analyze = wx.NewId()
  221. self.dec = wx.NewId()
  222. self.savefile = wx.NewId()
  223. self.printmap = wx.NewId()
  224. icons = Icons['displayWindow']
  225. return self._getToolbarData(((self.displaymap, 'display', icons['display'],
  226. self.parent.OnDraw),
  227. (self.rendermap, 'render', icons['render'],
  228. self.parent.OnRender),
  229. (self.erase, 'erase', icons['erase'],
  230. self.parent.OnErase),
  231. (None, ),
  232. (self.pointer, 'pointer', icons['pointer'],
  233. self.parent.OnPointer,
  234. wx.ITEM_CHECK),
  235. (self.query, 'query', icons['query'],
  236. self.parent.OnQuery,
  237. wx.ITEM_CHECK),
  238. (self.pan, 'pan', icons['pan'],
  239. self.parent.OnPan,
  240. wx.ITEM_CHECK),
  241. (self.zoomin, 'zoomIn', icons['zoomIn'],
  242. self.parent.OnZoomIn,
  243. wx.ITEM_CHECK),
  244. (self.zoomout, 'zoomOut', icons['zoomOut'],
  245. self.parent.OnZoomOut,
  246. wx.ITEM_CHECK),
  247. (self.zoomextent, 'zoomExtent', icons['zoomExtent'],
  248. self.parent.OnZoomToMap),
  249. (self.zoomback, 'zoomBack', icons['zoomBack'],
  250. self.parent.OnZoomBack),
  251. (self.zoommenu, 'zoomMenu', icons['zoomMenu'],
  252. self.parent.OnZoomMenu),
  253. (None, ),
  254. (self.analyze, 'analyze', icons['analyze'],
  255. self.parent.OnAnalyze),
  256. (None, ),
  257. (self.dec, 'overlay', icons['overlay'],
  258. self.parent.OnDecoration),
  259. (None, ),
  260. (self.savefile, 'saveFile', icons['saveFile'],
  261. self.parent.SaveToFile),
  262. (self.printmap, 'print', icons['print'],
  263. self.parent.PrintMenu),
  264. (None, ))
  265. )
  266. def OnSelectTool(self, event):
  267. """!Select / enable tool available in tools list
  268. """
  269. tool = event.GetSelection()
  270. if tool == self.toolId['2d']:
  271. self.ExitToolbars()
  272. self.Enable2D(True)
  273. elif tool == self.toolId['3d'] and \
  274. not self.parent.toolbars['nviz']:
  275. self.ExitToolbars()
  276. self.parent.AddToolbar("nviz")
  277. elif tool == self.toolId['vdigit'] and \
  278. not self.parent.toolbars['vdigit']:
  279. self.ExitToolbars()
  280. self.parent.AddToolbar("vdigit")
  281. self.parent.MapWindow.SetFocus()
  282. def ExitToolbars(self):
  283. if self.parent.toolbars['vdigit']:
  284. self.parent.toolbars['vdigit'].OnExit()
  285. if self.parent.toolbars['nviz']:
  286. self.parent.toolbars['nviz'].OnExit()
  287. def Enable2D(self, enabled):
  288. """!Enable/Disable 2D display mode specific tools"""
  289. for tool in (self.pointer,
  290. self.pan,
  291. self.zoomin,
  292. self.zoomout,
  293. self.zoomback,
  294. self.zoommenu,
  295. self.analyze,
  296. self.dec,
  297. self.printmap):
  298. self.EnableTool(tool, enabled)
  299. class GCPManToolbar(AbstractToolbar):
  300. """!Toolbar for managing ground control points
  301. @param parent reference to GCP widget
  302. """
  303. def __init__(self, parent):
  304. AbstractToolbar.__init__(self, parent)
  305. self.InitToolbar(self._toolbarData())
  306. # realize the toolbar
  307. self.Realize()
  308. def _toolbarData(self):
  309. self.gcpSave = wx.NewId()
  310. self.gcpReload = wx.NewId()
  311. self.gcpAdd = wx.NewId()
  312. self.gcpDelete = wx.NewId()
  313. self.gcpClear = wx.NewId()
  314. self.rms = wx.NewId()
  315. self.georect = wx.NewId()
  316. icons = Icons['georectify']
  317. return self._getToolbarData(((self.gcpSave, 'gcpSave', icons["gcpSave"],
  318. self.parent.SaveGCPs),
  319. (self.gcpReload, 'gcpReload', icons["gcpReload"],
  320. self.parent.ReloadGCPs),
  321. (None, ),
  322. (self.gcpAdd, 'gcpAdd', icons["gcpAdd"],
  323. self.parent.AddGCP),
  324. (self.gcpDelete, 'gcpDelete', icons["gcpDelete"],
  325. self.parent.DeleteGCP),
  326. (self.gcpClear, 'gcpClear', icons["gcpClear"],
  327. self.parent.ClearGCP),
  328. (None, ),
  329. (self.rms, 'gcpRms', icons["gcpRms"],
  330. self.parent.OnRMS),
  331. (self.georect, 'georectify', icons["georectify"],
  332. self.parent.OnGeorect))
  333. )
  334. class GCPDisplayToolbar(AbstractToolbar):
  335. """!GCP Display toolbar
  336. """
  337. def __init__(self, parent):
  338. """!GCP Display toolbar constructor
  339. """
  340. AbstractToolbar.__init__(self, parent)
  341. self.InitToolbar(self._toolbarData())
  342. # add tool to toggle active map window
  343. self.togglemapid = wx.NewId()
  344. self.togglemap = wx.Choice(parent = self, id = self.togglemapid,
  345. choices = [_('source'), _('target')],
  346. style = wx.CB_READONLY)
  347. self.InsertControl(10, self.togglemap)
  348. self.SetToolShortHelp(self.togglemapid, '%s %s %s' % (_('Set map canvas for '),
  349. Icons['displayWindow']["zoomBack"].GetLabel(),
  350. _(' / Zoom to map')))
  351. # realize the toolbar
  352. self.Realize()
  353. self.action = { 'id' : self.gcpset }
  354. self.defaultAction = { 'id' : self.gcpset,
  355. 'bind' : self.parent.OnPointer }
  356. self.OnTool(None)
  357. self.EnableTool(self.zoomback, False)
  358. def _toolbarData(self):
  359. """!Toolbar data"""
  360. self.displaymap = wx.NewId()
  361. self.rendermap = wx.NewId()
  362. self.erase = wx.NewId()
  363. self.gcpset = wx.NewId()
  364. self.pan = wx.NewId()
  365. self.zoomin = wx.NewId()
  366. self.zoomout = wx.NewId()
  367. self.zoomback = wx.NewId()
  368. self.zoomtomap = wx.NewId()
  369. self.zoommenu = wx.NewId()
  370. self.settings = wx.NewId()
  371. self.helpid = wx.NewId()
  372. self.quit = wx.NewId()
  373. icons = Icons['displayWindow']
  374. return self._getToolbarData(((self.displaymap, "display", icons["display"],
  375. self.parent.OnDraw),
  376. (self.rendermap, "render", icons["render"],
  377. self.parent.OnRender),
  378. (self.erase, "erase", icons["erase"],
  379. self.parent.OnErase),
  380. (None, ),
  381. (self.gcpset, "gcpSet", Icons["georectify"]["gcpSet"],
  382. self.parent.OnPointer),
  383. (self.pan, "pan", icons["pan"],
  384. self.parent.OnPan),
  385. (self.zoomin, "zoomIn", icons["zoomIn"],
  386. self.parent.OnZoomIn),
  387. (self.zoomout, "zoomOut", icons["zoomOut"],
  388. self.parent.OnZoomOut),
  389. (self.zoommenu, "zoomMenu", icons["zoomMenu"],
  390. self.parent.OnZoomMenuGCP),
  391. (None, ),
  392. (self.zoomback, "zoomBack", icons["zoomBack"],
  393. self.parent.OnZoomBack),
  394. (self.zoomtomap, "zoomtomap", icons["zoomExtent"],
  395. self.parent.OnZoomToMap),
  396. (None, ),
  397. (self.settings, 'settings', Icons["georectify"]["settings"],
  398. self.parent.OnSettings),
  399. (self.helpid, 'help', Icons["misc"]["help"],
  400. self.parent.OnHelp),
  401. (None, ),
  402. (self.quit, 'gcpQuit', Icons["georectify"]["quit"],
  403. self.parent.OnQuit))
  404. )
  405. class VDigitToolbar(AbstractToolbar):
  406. """!Toolbar for digitization
  407. """
  408. def __init__(self, parent, mapcontent, layerTree = None, log = None):
  409. self.mapcontent = mapcontent # Map class instance
  410. self.layerTree = layerTree # reference to layer tree associated to map display
  411. self.log = log # log area
  412. AbstractToolbar.__init__(self, parent)
  413. self.digit = None
  414. # currently selected map layer for editing (reference to MapLayer instance)
  415. self.mapLayer = None
  416. # list of vector layers from Layer Manager (only in the current mapset)
  417. self.layers = []
  418. self.comboid = None
  419. # only one dialog can be open
  420. self.settingsDialog = None
  421. # create toolbars (two rows optionally)
  422. self.InitToolbar(self._toolbarData())
  423. self.Bind(wx.EVT_TOOL, self.OnTool)
  424. # default action (digitize new point, line, etc.)
  425. self.action = { 'desc' : 'addLine',
  426. 'type' : 'point',
  427. 'id' : self.addPoint }
  428. # list of available vector maps
  429. self.UpdateListOfLayers(updateTool = True)
  430. # realize toolbar
  431. self.Realize()
  432. # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
  433. self.combo.Hide()
  434. self.combo.Show()
  435. # disable undo/redo
  436. self.EnableTool(self.undo, False)
  437. # toogle to pointer by default
  438. self.OnTool(None)
  439. self.FixSize(width = 105)
  440. def _toolbarData(self):
  441. """!Toolbar data
  442. """
  443. data = []
  444. self.addPoint = wx.NewId()
  445. self.addLine = wx.NewId()
  446. self.addBoundary = wx.NewId()
  447. self.addCentroid = wx.NewId()
  448. self.addArea = wx.NewId()
  449. self.moveVertex = wx.NewId()
  450. self.addVertex = wx.NewId()
  451. self.removeVertex = wx.NewId()
  452. self.splitLine = wx.NewId()
  453. self.editLine = wx.NewId()
  454. self.moveLine = wx.NewId()
  455. self.deleteLine = wx.NewId()
  456. self.additionalTools = wx.NewId()
  457. self.displayCats = wx.NewId()
  458. self.displayAttr = wx.NewId()
  459. self.copyCats = wx.NewId()
  460. self.undo = wx.NewId()
  461. self.settings = wx.NewId()
  462. self.exit = wx.NewId()
  463. icons = Icons['vdigit']
  464. return self._getToolbarData(((None, ),
  465. (self.addPoint, "addPoint", icons["addPoint"],
  466. self.OnAddPoint),
  467. (self.addLine, "addLine", icons["addLine"],
  468. self.OnAddLine,
  469. wx.ITEM_CHECK),
  470. (self.addBoundary, "addBoundary", icons["addBoundary"],
  471. self.OnAddBoundary,
  472. wx.ITEM_CHECK),
  473. (self.addCentroid, "addCentroid", icons["addCentroid"],
  474. self.OnAddCentroid,
  475. wx.ITEM_CHECK),
  476. (self.addArea, "addArea", icons["addArea"],
  477. self.OnAddArea,
  478. wx.ITEM_CHECK),
  479. (self.moveVertex, "moveVertex", icons["moveVertex"],
  480. self.OnMoveVertex,
  481. wx.ITEM_CHECK),
  482. (self.addVertex, "addVertex", icons["addVertex"],
  483. self.OnAddVertex,
  484. wx.ITEM_CHECK),
  485. (self.removeVertex, "removeVertex", icons["removeVertex"],
  486. self.OnRemoveVertex,
  487. wx.ITEM_CHECK),
  488. (self.splitLine, "splitLine", icons["splitLine"],
  489. self.OnSplitLine,
  490. wx.ITEM_CHECK),
  491. (self.editLine, "editLine", icons["editLine"],
  492. self.OnEditLine,
  493. wx.ITEM_CHECK),
  494. (self.moveLine, "moveLine", icons["moveLine"],
  495. self.OnMoveLine,
  496. wx.ITEM_CHECK),
  497. (self.deleteLine, "deleteLine", icons["deleteLine"],
  498. self.OnDeleteLine,
  499. wx.ITEM_CHECK),
  500. (self.displayCats, "displayCats", icons["displayCats"],
  501. self.OnDisplayCats,
  502. wx.ITEM_CHECK),
  503. (self.copyCats, "copyCats", icons["copyCats"],
  504. self.OnCopyCA,
  505. wx.ITEM_CHECK),
  506. (self.displayAttr, "displayAttr", icons["displayAttr"],
  507. self.OnDisplayAttr,
  508. wx.ITEM_CHECK),
  509. (self.additionalTools, "additionalTools", icons["additionalTools"],
  510. self.OnAdditionalToolMenu,
  511. wx.ITEM_CHECK),
  512. (None, ),
  513. (self.undo, "undo", icons["undo"],
  514. self.OnUndo),
  515. (self.settings, "settings", icons["settings"],
  516. self.OnSettings),
  517. (self.exit, "quit", icons["quit"],
  518. self.OnExit))
  519. )
  520. def OnTool(self, event):
  521. """!Tool selected -> disable selected tool in map toolbar"""
  522. id = self.parent.toolbars['map'].GetAction(type = 'id')
  523. self.parent.toolbars['map'].ToggleTool(id, False)
  524. # set cursor
  525. cursor = self.parent.cursors["cross"]
  526. self.parent.MapWindow.SetCursor(cursor)
  527. # pointer
  528. self.parent.OnPointer(None)
  529. if event:
  530. # deselect previously selected tool
  531. id = self.action.get('id', -1)
  532. if id != event.GetId():
  533. self.ToggleTool(self.action['id'], False)
  534. else:
  535. self.ToggleTool(self.action['id'], True)
  536. self.action['id'] = event.GetId()
  537. event.Skip()
  538. self.ToggleTool(self.action['id'], True)
  539. # clear tmp canvas
  540. if self.action['id'] != id:
  541. self.parent.MapWindow.ClearLines(pdc = self.parent.MapWindow.pdcTmp)
  542. if self.digit and \
  543. len(self.parent.MapWindow.digit.GetDisplay().GetSelected()) > 0:
  544. # cancel action
  545. self.parent.MapWindow.OnMiddleDown(None)
  546. # set focus
  547. self.parent.MapWindow.SetFocus()
  548. def OnAddPoint(self, event):
  549. """!Add point to the vector map Laier"""
  550. Debug.msg (2, "VDigitToolbar.OnAddPoint()")
  551. self.action = { 'desc' : "addLine",
  552. 'type' : "point",
  553. 'id' : self.addPoint }
  554. self.parent.MapWindow.mouse['box'] = 'point'
  555. def OnAddLine(self, event):
  556. """!Add line to the vector map layer"""
  557. Debug.msg (2, "VDigitToolbar.OnAddLine()")
  558. self.action = { 'desc' : "addLine",
  559. 'type' : "line",
  560. 'id' : self.addLine }
  561. self.parent.MapWindow.mouse['box'] = 'line'
  562. ### self.parent.MapWindow.polycoords = [] # reset temp line
  563. def OnAddBoundary(self, event):
  564. """!Add boundary to the vector map layer"""
  565. Debug.msg (2, "VDigitToolbar.OnAddBoundary()")
  566. if self.action['desc'] != 'addLine' or \
  567. self.action['type'] != 'boundary':
  568. self.parent.MapWindow.polycoords = [] # reset temp line
  569. self.action = { 'desc' : "addLine",
  570. 'type' : "boundary",
  571. 'id' : self.addBoundary }
  572. self.parent.MapWindow.mouse['box'] = 'line'
  573. def OnAddCentroid(self, event):
  574. """!Add centroid to the vector map layer"""
  575. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  576. self.action = { 'desc' : "addLine",
  577. 'type' : "centroid",
  578. 'id' : self.addCentroid }
  579. self.parent.MapWindow.mouse['box'] = 'point'
  580. def OnAddArea(self, event):
  581. """!Add area to the vector map layer"""
  582. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  583. self.action = { 'desc' : "addLine",
  584. 'type' : "area",
  585. 'id' : self.addArea }
  586. self.parent.MapWindow.mouse['box'] = 'line'
  587. def OnExit (self, event=None):
  588. """!Quit digitization tool"""
  589. # stop editing of the currently selected map layer
  590. if self.mapLayer:
  591. self.StopEditing()
  592. # close dialogs if still open
  593. if self.settingsDialog:
  594. self.settingsDialog.OnCancel(None)
  595. # set default mouse settings
  596. self.parent.MapWindow.mouse['use'] = "pointer"
  597. self.parent.MapWindow.mouse['box'] = "point"
  598. self.parent.MapWindow.polycoords = []
  599. # disable the toolbar
  600. self.parent.RemoveToolbar("vdigit")
  601. def OnMoveVertex(self, event):
  602. """!Move line vertex"""
  603. Debug.msg(2, "Digittoolbar.OnMoveVertex():")
  604. self.action = { 'desc' : "moveVertex",
  605. 'id' : self.moveVertex }
  606. self.parent.MapWindow.mouse['box'] = 'point'
  607. def OnAddVertex(self, event):
  608. """!Add line vertex"""
  609. Debug.msg(2, "Digittoolbar.OnAddVertex():")
  610. self.action = { 'desc' : "addVertex",
  611. 'id' : self.addVertex }
  612. self.parent.MapWindow.mouse['box'] = 'point'
  613. def OnRemoveVertex(self, event):
  614. """!Remove line vertex"""
  615. Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
  616. self.action = { 'desc' : "removeVertex",
  617. 'id' : self.removeVertex }
  618. self.parent.MapWindow.mouse['box'] = 'point'
  619. def OnSplitLine(self, event):
  620. """!Split line"""
  621. Debug.msg(2, "Digittoolbar.OnSplitLine():")
  622. self.action = { 'desc' : "splitLine",
  623. 'id' : self.splitLine }
  624. self.parent.MapWindow.mouse['box'] = 'point'
  625. def OnEditLine(self, event):
  626. """!Edit line"""
  627. Debug.msg(2, "Digittoolbar.OnEditLine():")
  628. self.action = { 'desc' : "editLine",
  629. 'id' : self.editLine }
  630. self.parent.MapWindow.mouse['box'] = 'line'
  631. def OnMoveLine(self, event):
  632. """!Move line"""
  633. Debug.msg(2, "Digittoolbar.OnMoveLine():")
  634. self.action = { 'desc' : "moveLine",
  635. 'id' : self.moveLine }
  636. self.parent.MapWindow.mouse['box'] = 'box'
  637. def OnDeleteLine(self, event):
  638. """!Delete line"""
  639. Debug.msg(2, "Digittoolbar.OnDeleteLine():")
  640. self.action = { 'desc' : "deleteLine",
  641. 'id' : self.deleteLine }
  642. self.parent.MapWindow.mouse['box'] = 'box'
  643. def OnDisplayCats(self, event):
  644. """!Display/update categories"""
  645. Debug.msg(2, "Digittoolbar.OnDisplayCats():")
  646. self.action = { 'desc' : "displayCats",
  647. 'id' : self.displayCats }
  648. self.parent.MapWindow.mouse['box'] = 'point'
  649. def OnDisplayAttr(self, event):
  650. """!Display/update attributes"""
  651. Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
  652. self.action = { 'desc' : "displayAttrs",
  653. 'id' : self.displayAttr }
  654. self.parent.MapWindow.mouse['box'] = 'point'
  655. def OnCopyCA(self, event):
  656. """!Copy categories/attributes menu"""
  657. point = wx.GetMousePosition()
  658. toolMenu = wx.Menu()
  659. # Add items to the menu
  660. cats = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  661. text = _('Copy categories'),
  662. kind = wx.ITEM_CHECK)
  663. toolMenu.AppendItem(cats)
  664. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyCats, cats)
  665. if self.action['desc'] == "copyCats":
  666. cats.Check(True)
  667. attrb = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  668. text = _('Duplicate attributes'),
  669. kind = wx.ITEM_CHECK)
  670. toolMenu.AppendItem(attrb)
  671. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyAttrb, attrb)
  672. if self.action['desc'] == "copyAttrs":
  673. attrb.Check(True)
  674. # Popup the menu. If an item is selected then its handler
  675. # will be called before PopupMenu returns.
  676. self.parent.MapWindow.PopupMenu(toolMenu)
  677. toolMenu.Destroy()
  678. if self.action['desc'] == "addPoint":
  679. self.ToggleTool(self.copyCats, False)
  680. def OnCopyCats(self, event):
  681. """!Copy categories"""
  682. if self.action['desc'] == 'copyCats': # select previous action
  683. self.ToggleTool(self.addPoint, True)
  684. self.ToggleTool(self.copyCats, False)
  685. self.OnAddPoint(event)
  686. return
  687. Debug.msg(2, "Digittoolbar.OnCopyCats():")
  688. self.action = { 'desc' : "copyCats",
  689. 'id' : self.copyCats }
  690. self.parent.MapWindow.mouse['box'] = 'point'
  691. def OnCopyAttrb(self, event):
  692. if self.action['desc'] == 'copyAttrs': # select previous action
  693. self.ToggleTool(self.addPoint, True)
  694. self.ToggleTool(self.copyCats, False)
  695. self.OnAddPoint(event)
  696. return
  697. Debug.msg(2, "Digittoolbar.OnCopyAttrb():")
  698. self.action = { 'desc' : "copyAttrs",
  699. 'id' : self.copyCats }
  700. self.parent.MapWindow.mouse['box'] = 'point'
  701. def OnUndo(self, event):
  702. """!Undo previous changes"""
  703. self.digit.Undo()
  704. event.Skip()
  705. def EnableUndo(self, enable=True):
  706. """!Enable 'Undo' in toolbar
  707. @param enable False for disable
  708. """
  709. if enable:
  710. if self.GetToolEnabled(self.undo) is False:
  711. self.EnableTool(self.undo, True)
  712. else:
  713. if self.GetToolEnabled(self.undo) is True:
  714. self.EnableTool(self.undo, False)
  715. def OnSettings(self, event):
  716. """!Show settings dialog"""
  717. if self.digit is None:
  718. try:
  719. self.digit = self.parent.MapWindow.digit = VDigit(mapwindow = self.parent.MapWindow)
  720. except SystemExit:
  721. self.digit = self.parent.MapWindow.digit = None
  722. if not self.settingsDialog:
  723. self.settingsDialog = VDigitSettingsDialog(parent = self.parent, title = _("Digitization settings"),
  724. style = wx.DEFAULT_DIALOG_STYLE)
  725. self.settingsDialog.Show()
  726. def OnAdditionalToolMenu(self, event):
  727. """!Menu for additional tools"""
  728. point = wx.GetMousePosition()
  729. toolMenu = wx.Menu()
  730. # Add items to the menu
  731. copy = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  732. text = _('Copy features from (background) vector map'),
  733. kind = wx.ITEM_CHECK)
  734. toolMenu.AppendItem(copy)
  735. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopy, copy)
  736. if self.action['desc'] == "copyLine":
  737. copy.Check(True)
  738. flip = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  739. text = _('Flip selected lines/boundaries'),
  740. kind = wx.ITEM_CHECK)
  741. toolMenu.AppendItem(flip)
  742. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnFlip, flip)
  743. if self.action['desc'] == "flipLine":
  744. flip.Check(True)
  745. merge = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  746. text = _('Merge selected lines/boundaries'),
  747. kind = wx.ITEM_CHECK)
  748. toolMenu.AppendItem(merge)
  749. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnMerge, merge)
  750. if self.action['desc'] == "mergeLine":
  751. merge.Check(True)
  752. breakL = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  753. text = _('Break selected lines/boundaries at intersection'),
  754. kind = wx.ITEM_CHECK)
  755. toolMenu.AppendItem(breakL)
  756. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnBreak, breakL)
  757. if self.action['desc'] == "breakLine":
  758. breakL.Check(True)
  759. snap = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  760. text = _('Snap selected lines/boundaries (only to nodes)'),
  761. kind = wx.ITEM_CHECK)
  762. toolMenu.AppendItem(snap)
  763. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnSnap, snap)
  764. if self.action['desc'] == "snapLine":
  765. snap.Check(True)
  766. connect = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  767. text = _('Connect selected lines/boundaries'),
  768. kind = wx.ITEM_CHECK)
  769. toolMenu.AppendItem(connect)
  770. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnConnect, connect)
  771. if self.action['desc'] == "connectLine":
  772. connect.Check(True)
  773. query = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  774. text = _('Query features'),
  775. kind = wx.ITEM_CHECK)
  776. toolMenu.AppendItem(query)
  777. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnQuery, query)
  778. if self.action['desc'] == "queryLine":
  779. query.Check(True)
  780. zbulk = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  781. text = _('Z bulk-labeling of 3D lines'),
  782. kind = wx.ITEM_CHECK)
  783. toolMenu.AppendItem(zbulk)
  784. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnZBulk, zbulk)
  785. if self.action['desc'] == "zbulkLine":
  786. zbulk.Check(True)
  787. typeconv = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  788. text = _('Feature type conversion'),
  789. kind = wx.ITEM_CHECK)
  790. toolMenu.AppendItem(typeconv)
  791. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnTypeConversion, typeconv)
  792. if self.action['desc'] == "typeConv":
  793. typeconv.Check(True)
  794. # Popup the menu. If an item is selected then its handler
  795. # will be called before PopupMenu returns.
  796. self.parent.MapWindow.PopupMenu(toolMenu)
  797. toolMenu.Destroy()
  798. if self.action['desc'] == 'addPoint':
  799. self.ToggleTool(self.additionalTools, False)
  800. def OnCopy(self, event):
  801. """!Copy selected features from (background) vector map"""
  802. if self.action['desc'] == 'copyLine': # select previous action
  803. self.ToggleTool(self.addPoint, True)
  804. self.ToggleTool(self.additionalTools, False)
  805. self.OnAddPoint(event)
  806. return
  807. Debug.msg(2, "Digittoolbar.OnCopy():")
  808. self.action = { 'desc' : "copyLine",
  809. 'id' : self.additionalTools }
  810. self.parent.MapWindow.mouse['box'] = 'box'
  811. def OnFlip(self, event):
  812. """!Flip selected lines/boundaries"""
  813. if self.action['desc'] == 'flipLine': # select previous action
  814. self.ToggleTool(self.addPoint, True)
  815. self.ToggleTool(self.additionalTools, False)
  816. self.OnAddPoint(event)
  817. return
  818. Debug.msg(2, "Digittoolbar.OnFlip():")
  819. self.action = { 'desc' : "flipLine",
  820. 'id' : self.additionalTools }
  821. self.parent.MapWindow.mouse['box'] = 'box'
  822. def OnMerge(self, event):
  823. """!Merge selected lines/boundaries"""
  824. if self.action['desc'] == 'mergeLine': # select previous action
  825. self.ToggleTool(self.addPoint, True)
  826. self.ToggleTool(self.additionalTools, False)
  827. self.OnAddPoint(event)
  828. return
  829. Debug.msg(2, "Digittoolbar.OnMerge():")
  830. self.action = { 'desc' : "mergeLine",
  831. 'id' : self.additionalTools }
  832. self.parent.MapWindow.mouse['box'] = 'box'
  833. def OnBreak(self, event):
  834. """!Break selected lines/boundaries"""
  835. if self.action['desc'] == 'breakLine': # select previous action
  836. self.ToggleTool(self.addPoint, True)
  837. self.ToggleTool(self.additionalTools, False)
  838. self.OnAddPoint(event)
  839. return
  840. Debug.msg(2, "Digittoolbar.OnBreak():")
  841. self.action = { 'desc' : "breakLine",
  842. 'id' : self.additionalTools }
  843. self.parent.MapWindow.mouse['box'] = 'box'
  844. def OnSnap(self, event):
  845. """!Snap selected features"""
  846. if self.action['desc'] == 'snapLine': # select previous action
  847. self.ToggleTool(self.addPoint, True)
  848. self.ToggleTool(self.additionalTools, False)
  849. self.OnAddPoint(event)
  850. return
  851. Debug.msg(2, "Digittoolbar.OnSnap():")
  852. self.action = { 'desc' : "snapLine",
  853. 'id' : self.additionalTools }
  854. self.parent.MapWindow.mouse['box'] = 'box'
  855. def OnConnect(self, event):
  856. """!Connect selected lines/boundaries"""
  857. if self.action['desc'] == 'connectLine': # select previous action
  858. self.ToggleTool(self.addPoint, True)
  859. self.ToggleTool(self.additionalTools, False)
  860. self.OnAddPoint(event)
  861. return
  862. Debug.msg(2, "Digittoolbar.OnConnect():")
  863. self.action = { 'desc' : "connectLine",
  864. 'id' : self.additionalTools }
  865. self.parent.MapWindow.mouse['box'] = 'box'
  866. def OnQuery(self, event):
  867. """!Query selected lines/boundaries"""
  868. if self.action['desc'] == 'queryLine': # select previous action
  869. self.ToggleTool(self.addPoint, True)
  870. self.ToggleTool(self.additionalTools, False)
  871. self.OnAddPoint(event)
  872. return
  873. Debug.msg(2, "Digittoolbar.OnQuery(): %s" % \
  874. UserSettings.Get(group = 'vdigit', key = 'query', subkey = 'selection'))
  875. self.action = { 'desc' : "queryLine",
  876. 'id' : self.additionalTools }
  877. self.parent.MapWindow.mouse['box'] = 'box'
  878. def OnZBulk(self, event):
  879. """!Z bulk-labeling selected lines/boundaries"""
  880. if not self.digit.IsVector3D():
  881. gcmd.GError(parent = self.parent,
  882. message = _("Vector map is not 3D. Operation canceled."))
  883. return
  884. if self.action['desc'] == 'zbulkLine': # select previous action
  885. self.ToggleTool(self.addPoint, True)
  886. self.ToggleTool(self.additionalTools, False)
  887. self.OnAddPoint(event)
  888. return
  889. Debug.msg(2, "Digittoolbar.OnZBulk():")
  890. self.action = { 'desc' : "zbulkLine",
  891. 'id' : self.additionalTools }
  892. self.parent.MapWindow.mouse['box'] = 'line'
  893. def OnTypeConversion(self, event):
  894. """!Feature type conversion
  895. Supported conversions:
  896. - point <-> centroid
  897. - line <-> boundary
  898. """
  899. if self.action['desc'] == 'typeConv': # select previous action
  900. self.ToggleTool(self.addPoint, True)
  901. self.ToggleTool(self.additionalTools, False)
  902. self.OnAddPoint(event)
  903. return
  904. Debug.msg(2, "Digittoolbar.OnTypeConversion():")
  905. self.action = { 'desc' : "typeConv",
  906. 'id' : self.additionalTools }
  907. self.parent.MapWindow.mouse['box'] = 'box'
  908. def OnSelectMap (self, event):
  909. """
  910. Select vector map layer for editing
  911. If there is a vector map layer already edited, this action is
  912. firstly terminated. The map layer is closed. After this the
  913. selected map layer activated for editing.
  914. """
  915. if event.GetSelection() == 0: # create new vector map layer
  916. if self.mapLayer:
  917. openVectorMap = self.mapLayer.GetName(fullyQualified = False)['name']
  918. else:
  919. openVectorMap = None
  920. mapName = gdialogs.CreateNewVector(self.parent,
  921. exceptMap = openVectorMap, log = self.log,
  922. cmd = (('v.edit',
  923. { 'tool' : 'create' },
  924. 'map')),
  925. disableAdd = True)[0]
  926. if mapName:
  927. # add layer to map layer tree
  928. if self.layerTree:
  929. self.layerTree.AddLayer(ltype = 'vector',
  930. lname = mapName,
  931. lchecked = True,
  932. lopacity = 1.0,
  933. lcmd = ['d.vect', 'map=%s' % mapName])
  934. vectLayers = self.UpdateListOfLayers(updateTool = True)
  935. selection = vectLayers.index(mapName)
  936. else:
  937. pass # TODO (no Layer Manager)
  938. else:
  939. self.combo.SetValue(_('Select vector map'))
  940. return
  941. else:
  942. selection = event.GetSelection() - 1 # first option is 'New vector map'
  943. # skip currently selected map
  944. if self.layers[selection] == self.mapLayer:
  945. return False
  946. if self.mapLayer:
  947. # deactive map layer for editing
  948. self.StopEditing()
  949. # select the given map layer for editing
  950. self.StartEditing(self.layers[selection])
  951. event.Skip()
  952. return True
  953. def StartEditing (self, mapLayer):
  954. """!Start editing selected vector map layer.
  955. @param mapLayer MapLayer to be edited
  956. """
  957. # deactive layer
  958. self.mapcontent.ChangeLayerActive(mapLayer, False)
  959. # clean map canvas
  960. self.parent.MapWindow.EraseMap()
  961. # unset background map if needed
  962. if mapLayer:
  963. if UserSettings.Get(group = 'vdigit', key = 'bgmap',
  964. subkey = 'value', internal = True) == mapLayer.GetName():
  965. UserSettings.Set(group = 'vdigit', key = 'bgmap',
  966. subkey = 'value', value = '', internal = True)
  967. self.parent.statusbar.SetStatusText(_("Please wait, "
  968. "opening vector map <%s> for editing...") % mapLayer.GetName(),
  969. 0)
  970. self.parent.MapWindow.pdcVector = wx.PseudoDC()
  971. self.digit = self.parent.MapWindow.digit = VDigit(mapwindow = self.parent.MapWindow)
  972. self.mapLayer = mapLayer
  973. # open vector map
  974. if self.digit.OpenMap(mapLayer.GetName()) is None:
  975. self.mapLayer = None
  976. self.StopEditing()
  977. return False
  978. # update toolbar
  979. self.combo.SetValue(mapLayer.GetName())
  980. self.parent.toolbars['map'].combo.SetValue (_('Digitize'))
  981. lmgr = self.parent.GetLayerManager()
  982. if lmgr:
  983. lmgr.toolbars['tools'].Enable('vdigit', enable = False)
  984. Debug.msg (4, "VDigitToolbar.StartEditing(): layer=%s" % mapLayer.GetName())
  985. # change cursor
  986. if self.parent.MapWindow.mouse['use'] == 'pointer':
  987. self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
  988. if not self.parent.MapWindow.resize:
  989. self.parent.MapWindow.UpdateMap(render = True)
  990. opacity = mapLayer.GetOpacity(float = True)
  991. if opacity < 1.0:
  992. alpha = int(opacity * 255)
  993. self.digit.UpdateSettings(alpha)
  994. return True
  995. def StopEditing(self):
  996. """!Stop editing of selected vector map layer.
  997. @return True on success
  998. @return False on failure
  999. """
  1000. self.combo.SetValue (_('Select vector map'))
  1001. # save changes
  1002. if self.mapLayer:
  1003. Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % self.mapLayer.GetName())
  1004. if UserSettings.Get(group = 'vdigit', key = 'saveOnExit', subkey = 'enabled') is False:
  1005. if self.digit.GetUndoLevel() > -1:
  1006. dlg = wx.MessageDialog(parent = self.parent,
  1007. message = _("Do you want to save changes "
  1008. "in vector map <%s>?") % self.mapLayer.GetName(),
  1009. caption = _("Save changes?"),
  1010. style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  1011. if dlg.ShowModal() == wx.ID_NO:
  1012. # revert changes
  1013. self.digit.Undo(0)
  1014. dlg.Destroy()
  1015. self.parent.statusbar.SetStatusText(_("Please wait, "
  1016. "closing and rebuilding topology of "
  1017. "vector map <%s>...") % self.mapLayer.GetName(),
  1018. 0)
  1019. lmgr = self.parent.GetLayerManager()
  1020. if lmgr:
  1021. lmgr.toolbars['tools'].Enable('vdigit', enable = True)
  1022. lmgr.notebook.SetSelection(1)
  1023. self.digit.CloseMap()
  1024. if lmgr:
  1025. lmgr.GetLogWindow().GetProgressBar().SetValue(0)
  1026. lmgr.GetLogWindow().WriteCmdLog(_("Editing of vector map <%s> successfully finished") % \
  1027. self.mapLayer.GetName())
  1028. # re-active layer
  1029. item = self.parent.tree.FindItemByData('maplayer', self.mapLayer)
  1030. if item and self.parent.tree.IsItemChecked(item):
  1031. self.mapcontent.ChangeLayerActive(self.mapLayer, True)
  1032. # change cursor
  1033. self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
  1034. self.parent.MapWindow.pdcVector = None
  1035. # close dialogs
  1036. for dialog in ('attributes', 'category'):
  1037. if self.parent.dialogs[dialog]:
  1038. self.parent.dialogs[dialog].Close()
  1039. self.parent.dialogs[dialog] = None
  1040. del self.digit
  1041. del self.parent.MapWindow.digit
  1042. self.mapLayer = None
  1043. self.parent.MapWindow.redrawAll = True
  1044. return True
  1045. def UpdateListOfLayers (self, updateTool = False):
  1046. """!
  1047. Update list of available vector map layers.
  1048. This list consists only editable layers (in the current mapset)
  1049. Optionally also update toolbar
  1050. """
  1051. Debug.msg (4, "VDigitToolbar.UpdateListOfLayers(): updateTool=%d" % \
  1052. updateTool)
  1053. layerNameSelected = None
  1054. # name of currently selected layer
  1055. if self.mapLayer:
  1056. layerNameSelected = self.mapLayer.GetName()
  1057. # select vector map layer in the current mapset
  1058. layerNameList = []
  1059. self.layers = self.mapcontent.GetListOfLayers(l_type = "vector",
  1060. l_mapset = grass.gisenv()['MAPSET'])
  1061. for layer in self.layers:
  1062. if not layer.name in layerNameList: # do not duplicate layer
  1063. layerNameList.append (layer.GetName())
  1064. if updateTool: # update toolbar
  1065. if not self.mapLayer:
  1066. value = _('Select vector map')
  1067. else:
  1068. value = layerNameSelected
  1069. if not self.comboid:
  1070. self.combo = wx.ComboBox(self, id = wx.ID_ANY, value = value,
  1071. choices = [_('New vector map'), ] + layerNameList, size = (115, -1),
  1072. style = wx.CB_READONLY)
  1073. self.comboid = self.InsertControl(0, self.combo)
  1074. self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectMap, self.comboid)
  1075. else:
  1076. self.combo.SetItems([_('New vector map'), ] + layerNameList)
  1077. self.Realize()
  1078. return layerNameList
  1079. def GetLayer(self):
  1080. """!Get selected layer for editing -- MapLayer instance"""
  1081. return self.mapLayer
  1082. class ProfileToolbar(AbstractToolbar):
  1083. """!Toolbar for profiling raster map
  1084. """
  1085. def __init__(self, parent):
  1086. AbstractToolbar.__init__(self, parent)
  1087. self.InitToolbar(self._toolbarData())
  1088. # realize the toolbar
  1089. self.Realize()
  1090. def _toolbarData(self):
  1091. """!Toolbar data"""
  1092. self.transect = wx.NewId()
  1093. self.addraster = wx.NewId()
  1094. self.draw = wx.NewId()
  1095. self.options = wx.NewId()
  1096. self.drag = wx.NewId()
  1097. self.zoom = wx.NewId()
  1098. self.unzoom = wx.NewId()
  1099. self.erase = wx.NewId()
  1100. self.save = wx.NewId()
  1101. self.datasave = wx.NewId()
  1102. self.printer = wx.NewId()
  1103. self.quit = wx.NewId()
  1104. icons = Icons['profile']
  1105. return self._getToolbarData(((self.addraster, 'raster', Icons['layerManager']["addRast"],
  1106. self.parent.OnSelectRaster),
  1107. (self.transect, 'transect', icons["transect"],
  1108. self.parent.OnDrawTransect),
  1109. (None, ),
  1110. (self.draw, 'draw', icons["draw"],
  1111. self.parent.OnCreateProfile),
  1112. (self.erase, 'erase', Icons['displayWindow']["erase"],
  1113. self.parent.OnErase),
  1114. (self.drag, 'drag', Icons['displayWindow']['pan'],
  1115. self.parent.OnDrag),
  1116. (self.zoom, 'zoom', Icons['displayWindow']['zoomIn'],
  1117. self.parent.OnZoom),
  1118. (self.unzoom, 'unzoom', Icons['displayWindow']['zoomBack'],
  1119. self.parent.OnRedraw),
  1120. (None, ),
  1121. (self.datasave, 'save', icons["save"],
  1122. self.parent.SaveProfileToFile),
  1123. (self.save, 'image', Icons['displayWindow']["saveFile"],
  1124. self.parent.SaveToFile),
  1125. (self.printer, 'print', Icons['displayWindow']["print"],
  1126. self.parent.PrintMenu),
  1127. (None, ),
  1128. (self.options, 'options', icons["options"],
  1129. self.parent.ProfileOptionsMenu),
  1130. (self.quit, 'quit', icons["quit"],
  1131. self.parent.OnQuit),
  1132. ))
  1133. class NvizToolbar(AbstractToolbar):
  1134. """!Nviz toolbar
  1135. """
  1136. def __init__(self, parent, mapcontent):
  1137. self.mapcontent = mapcontent
  1138. self.lmgr = parent.GetLayerManager()
  1139. AbstractToolbar.__init__(self, parent)
  1140. # only one dialog can be open
  1141. self.settingsDialog = None
  1142. self.InitToolbar(self._toolbarData())
  1143. # realize the toolbar
  1144. self.Realize()
  1145. def _toolbarData(self):
  1146. """!Toolbar data"""
  1147. self.view = wx.NewId()
  1148. self.surface = wx.NewId()
  1149. self.vector = wx.NewId()
  1150. self.volume = wx.NewId()
  1151. self.light = wx.NewId()
  1152. self.fringe = wx.NewId()
  1153. self.settings = wx.NewId()
  1154. self.help = wx.NewId()
  1155. self.quit = wx.NewId()
  1156. icons = Icons['nviz']
  1157. return self._getToolbarData(((self.view, "view", icons["view"],
  1158. self.OnShowPage),
  1159. (None, ),
  1160. (self.surface, "surface", icons["surface"],
  1161. self.OnShowPage),
  1162. (self.vector, "vector", icons["vector"],
  1163. self.OnShowPage),
  1164. (self.volume, "volume", icons["volume"],
  1165. self.OnShowPage),
  1166. (None, ),
  1167. (self.light, "light", icons["light"],
  1168. self.OnShowPage),
  1169. (self.fringe, "fringe", icons["fringe"],
  1170. self.OnShowPage),
  1171. (None, ),
  1172. (self.settings, "settings", icons["settings"],
  1173. self.OnSettings),
  1174. (self.help, "help", Icons['misc']["help"],
  1175. self.OnHelp),
  1176. (None, ),
  1177. (self.quit, 'quit', icons["quit"],
  1178. self.OnExit))
  1179. )
  1180. def OnShowPage(self, event):
  1181. """!Go to the selected page"""
  1182. if not self.lmgr or not hasattr(self.lmgr, "nviz"):
  1183. event.Skip()
  1184. return
  1185. self.lmgr.notebook.SetSelection(3)
  1186. eId = event.GetId()
  1187. if eId == self.view:
  1188. self.lmgr.nviz.SetPage('view')
  1189. elif eId == self.surface:
  1190. self.lmgr.nviz.SetPage('surface')
  1191. elif eId == self.surface:
  1192. self.lmgr.nviz.SetPage('surface')
  1193. elif eId == self.vector:
  1194. self.lmgr.nviz.SetPage('vector')
  1195. elif eId == self.volume:
  1196. self.lmgr.nviz.SetPage('volume')
  1197. elif eId == self.light:
  1198. self.lmgr.nviz.SetPage('light')
  1199. elif eId == self.fringe:
  1200. self.lmgr.nviz.SetPage('fringe')
  1201. self.lmgr.Raise()
  1202. def OnHelp(self, event):
  1203. """!Show 3D view mode help"""
  1204. if not self.lmgr:
  1205. gcmd.RunCommand('g.manual',
  1206. entry = 'wxGUI.Nviz')
  1207. else:
  1208. log = self.lmgr.GetLogWindow()
  1209. log.RunCmd(['g.manual',
  1210. 'entry=wxGUI.Nviz'])
  1211. def OnSettings(self, event):
  1212. """!Show nviz notebook page"""
  1213. if not self.settingsDialog:
  1214. self.settingsDialog = NvizPreferencesDialog(parent = self.parent)
  1215. self.settingsDialog.Show()
  1216. def OnExit (self, event = None):
  1217. """!Quit nviz tool (swith to 2D mode)"""
  1218. # set default mouse settings
  1219. self.parent.MapWindow.mouse['use'] = "pointer"
  1220. self.parent.MapWindow.mouse['box'] = "point"
  1221. self.parent.MapWindow.polycoords = []
  1222. # return to map layer page (gets rid of ugly exit bug)
  1223. self.lmgr.notebook.SetSelection(0)
  1224. # disable the toolbar
  1225. self.parent.RemoveToolbar("nviz")
  1226. class ModelToolbar(AbstractToolbar):
  1227. """!Graphical modeler toolbar (see gmodeler.py)
  1228. """
  1229. def __init__(self, parent):
  1230. AbstractToolbar.__init__(self, parent)
  1231. self.InitToolbar(self._toolbarData())
  1232. # realize the toolbar
  1233. self.Realize()
  1234. def _toolbarData(self):
  1235. """!Toolbar data"""
  1236. self.new = wx.NewId()
  1237. self.open = wx.NewId()
  1238. self.save = wx.NewId()
  1239. self.image = wx.NewId()
  1240. self.python = wx.NewId()
  1241. self.action = wx.NewId()
  1242. self.data = wx.NewId()
  1243. self.relation = wx.NewId()
  1244. self.run = wx.NewId()
  1245. self.validate = wx.NewId()
  1246. self.settings = wx.NewId()
  1247. self.variables = wx.NewId()
  1248. self.quit = wx.NewId()
  1249. self.redraw = wx.NewId()
  1250. self.help = wx.NewId()
  1251. icons = Icons['modeler']
  1252. return self._getToolbarData(((self.new, 'new', icons['new'],
  1253. self.parent.OnModelNew),
  1254. (self.open, 'open', icons['open'],
  1255. self.parent.OnModelOpen),
  1256. (self.save, 'save', icons['save'],
  1257. self.parent.OnModelSave),
  1258. (self.image, 'image', icons['toImage'],
  1259. self.parent.OnExportImage),
  1260. (self.python, 'python', icons['toPython'],
  1261. self.parent.OnExportPython),
  1262. (None, ),
  1263. (self.action, 'action', icons['actionAdd'],
  1264. self.parent.OnAddAction),
  1265. (self.data, 'data', icons['dataAdd'],
  1266. self.parent.OnAddData),
  1267. (self.relation, 'relation', icons['relation'],
  1268. self.parent.OnDefineRelation),
  1269. (None, ),
  1270. (self.redraw, 'redraw', icons['redraw'],
  1271. self.parent.OnCanvasRefresh),
  1272. (self.validate, 'validate', icons['validate'],
  1273. self.parent.OnValidateModel),
  1274. (self.run, 'run', icons['run'],
  1275. self.parent.OnRunModel),
  1276. (None, ),
  1277. (self.variables, "variables", icons['variables'],
  1278. self.parent.OnVariables),
  1279. (self.settings, "settings", icons['settings'],
  1280. self.parent.OnPreferences),
  1281. (self.help, "help", Icons['misc']['help'],
  1282. self.parent.OnHelp),
  1283. (None, ),
  1284. (self.quit, 'quit', icons['quit'],
  1285. self.parent.OnCloseWindow))
  1286. )
  1287. class HistogramToolbar(AbstractToolbar):
  1288. """!Histogram toolbar (see histogram.py)
  1289. """
  1290. def __init__(self, parent):
  1291. AbstractToolbar.__init__(self, parent)
  1292. self.InitToolbar(self._toolbarData())
  1293. # realize the toolbar
  1294. self.Realize()
  1295. def _toolbarData(self):
  1296. """!Toolbar data"""
  1297. self.histogram = wx.NewId()
  1298. self.rendermap = wx.NewId()
  1299. self.erase = wx.NewId()
  1300. self.font = wx.NewId()
  1301. self.save = wx.NewId()
  1302. self.hprint = wx.NewId()
  1303. self.quit = wx.NewId()
  1304. icons = Icons['displayWindow']
  1305. return self._getToolbarData(((self.histogram, 'histogram', icons["histogram"],
  1306. self.parent.OnOptions),
  1307. (self.rendermap, 'render', icons["display"],
  1308. self.parent.OnRender),
  1309. (self.erase, 'erase', icons["erase"],
  1310. self.parent.OnErase),
  1311. (self.font, 'font', Icons['misc']["font"],
  1312. self.parent.SetHistFont),
  1313. (None, ),
  1314. (self.save, 'save', icons["saveFile"],
  1315. self.parent.SaveToFile),
  1316. (self.hprint, 'print', icons["print"],
  1317. self.parent.PrintMenu),
  1318. (None, ),
  1319. (self.quit, 'quit', Icons['misc']["quit"],
  1320. self.parent.OnQuit))
  1321. )
  1322. class LayerManagerToolbar(AbstractToolbar):
  1323. """!Layer Manager toolbar (see wxgui.py)
  1324. """
  1325. def __init__(self, parent):
  1326. AbstractToolbar.__init__(self, parent)
  1327. self.InitToolbar(self._toolbarData())
  1328. # realize the toolbar
  1329. self.Realize()
  1330. def _toolbarData(self):
  1331. """!Toolbar data
  1332. """
  1333. self.newdisplay = wx.NewId()
  1334. self.workspaceLoad = wx.NewId()
  1335. self.workspaceOpen = wx.NewId()
  1336. self.workspaceSave = wx.NewId()
  1337. self.addrast = wx.NewId()
  1338. self.rastmisc = wx.NewId()
  1339. self.addvect = wx.NewId()
  1340. self.vectmisc = wx.NewId()
  1341. self.addgrp = wx.NewId()
  1342. self.addovl = wx.NewId()
  1343. self.delcmd = wx.NewId()
  1344. self.attribute = wx.NewId()
  1345. self.preferences = wx.NewId()
  1346. self.help = wx.NewId()
  1347. icons = Icons['layerManager']
  1348. return self._getToolbarData(((self.newdisplay, 'newdisplay', icons["newdisplay"],
  1349. self.parent.OnNewMenu),
  1350. (None, ),
  1351. (self.workspaceLoad, 'workspaceLoad', icons["workspaceLoad"],
  1352. self.parent.OnLoadMenu),
  1353. (self.workspaceOpen, 'workspaceOpen', icons["workspaceOpen"],
  1354. self.parent.OnWorkspaceOpen),
  1355. (self.workspaceSave, 'workspaceSave', icons["workspaceSave"],
  1356. self.parent.OnWorkspaceSave),
  1357. (None, ),
  1358. (self.addrast, 'addRast', icons["addRast"],
  1359. self.parent.OnAddRaster),
  1360. (self.rastmisc, 'rastMisc', icons["rastMisc"],
  1361. self.parent.OnAddRasterMisc),
  1362. (self.addvect, 'addVect', icons["addVect"],
  1363. self.parent.OnAddVector),
  1364. (self.vectmisc, 'vectMisc', icons["vectMisc"],
  1365. self.parent.OnAddVectorMisc),
  1366. (self.addgrp, 'addGroup', icons["addGroup"],
  1367. self.parent.OnAddGroup),
  1368. (self.addovl, 'addOverlay', icons["addOverlay"],
  1369. self.parent.OnAddOverlay),
  1370. (self.delcmd, 'delCmd', icons["delCmd"],
  1371. self.parent.OnDeleteLayer),
  1372. (None, ),
  1373. (self.attribute, 'attrTable', icons["attrTable"],
  1374. self.parent.OnShowAttributeTable),
  1375. (None, ),
  1376. (self.preferences, 'preferences', icons["settings"],
  1377. self.parent.OnPreferences),
  1378. (self.help, 'help', Icons["misc"]["help"],
  1379. self.parent.OnHelp),
  1380. ))
  1381. class ToolsToolbar(AbstractToolbar):
  1382. """!Layer Manager Tools toolbar (see wxgui.py)
  1383. """
  1384. def __init__(self, parent):
  1385. AbstractToolbar.__init__(self, parent)
  1386. self.InitToolbar(self._toolbarData())
  1387. # realize the toolbar
  1388. self.Realize()
  1389. def _toolbarData(self):
  1390. """!Toolbar data
  1391. """
  1392. self.georect = wx.NewId()
  1393. self.modeler = wx.NewId()
  1394. self.vdigit = wx.NewId()
  1395. self.mapOutput = wx.NewId()
  1396. self.mapCalc = wx.NewId()
  1397. icons = Icons['layerManager']
  1398. return self._getToolbarData(((self.mapCalc, 'mapCalc', icons["mapcalc"],
  1399. self.parent.OnMapCalculator),
  1400. (self.vdigit, 'vdigit', icons["vdigit"],
  1401. self.parent.OnVDigit),
  1402. (self.georect, 'georectify', Icons["georectify"]["georectify"],
  1403. self.parent.OnGCPManager),
  1404. (self.modeler, 'modeler', icons["modeler"],
  1405. self.parent.OnGModeler),
  1406. (self.mapOutput, 'mapOutput', icons['mapOutput'],
  1407. self.parent.OnPsMap)
  1408. ))
  1409. class PsMapToolbar(AbstractToolbar):
  1410. def __init__(self, parent):
  1411. """!Toolbar Hardcopy Map Output Utility (psmap.py)
  1412. @param parent parent window
  1413. """
  1414. AbstractToolbar.__init__(self, parent)
  1415. self.InitToolbar(self._toolbarData())
  1416. self.Realize()
  1417. self.action = { 'id' : self.pointer }
  1418. self.defaultAction = { 'id' : self.pointer,
  1419. 'bind' : self.parent.OnPointer }
  1420. self.OnTool(None)
  1421. from psmap import haveImage
  1422. if not haveImage:
  1423. self.EnableTool(self.preview, False)
  1424. def _toolbarData(self):
  1425. """!Toolbar data
  1426. """
  1427. self.quit = wx.NewId()
  1428. self.pagesetup = wx.NewId()
  1429. self.pointer = wx.NewId()
  1430. self.zoomIn = wx.NewId()
  1431. self.zoomOut = wx.NewId()
  1432. self.zoomAll = wx.NewId()
  1433. self.addMap = wx.NewId()
  1434. self.addRaster = wx.NewId()
  1435. self.addVector = wx.NewId()
  1436. self.dec = wx.NewId()
  1437. self.delete = wx.NewId()
  1438. self.preview = wx.NewId()
  1439. self.instructionFile = wx.NewId()
  1440. self.generatePS = wx.NewId()
  1441. self.generatePDF = wx.NewId()
  1442. self.loadFile = wx.NewId()
  1443. self.pan = wx.NewId()
  1444. self.help = wx.NewId()
  1445. icons = Icons['psMap']
  1446. return self._getToolbarData(((self.loadFile, 'loadFile', icons['scriptLoad'],
  1447. self.parent.OnLoadFile),
  1448. (self.instructionFile, 'psScript', icons['scriptSave'],
  1449. self.parent.OnInstructionFile),
  1450. (None, ),
  1451. (self.pagesetup, 'page setup', icons['pageSetup'],
  1452. self.parent.OnPageSetup),
  1453. (None, ),
  1454. (self.pointer, "pointer", Icons["displayWindow"]["pointer"],
  1455. self.parent.OnPointer, wx.ITEM_CHECK),
  1456. (self.pan, 'pan', Icons["displayWindow"]['pan'],
  1457. self.parent.OnPan, wx.ITEM_CHECK),
  1458. (self.zoomIn, "zoomin", Icons["displayWindow"]["zoomIn"],
  1459. self.parent.OnZoomIn, wx.ITEM_CHECK),
  1460. (self.zoomOut, "zoomout", Icons["displayWindow"]["zoomOut"],
  1461. self.parent.OnZoomOut, wx.ITEM_CHECK),
  1462. (self.zoomAll, 'full extent', icons['fullExtent'],
  1463. self.parent.OnZoomAll),
  1464. (None, ),
  1465. (self.addMap, 'add map', icons['addMap'],
  1466. self.parent.OnAddMap, wx.ITEM_CHECK),
  1467. (self.addRaster, 'add raster', icons['addRast'],
  1468. self.parent.OnAddRaster),
  1469. (self.addVector, 'add vect', icons['addVect'],
  1470. self.parent.OnAddVect),
  1471. (self.dec, "overlay", Icons["displayWindow"]["overlay"],
  1472. self.parent.OnDecoration),
  1473. (self.delete, "delete", icons["deleteObj"],
  1474. self.parent.OnDelete),
  1475. (None, ),
  1476. (self.preview, "preview", icons["preview"],
  1477. self.parent.OnPreview),
  1478. (self.generatePS, 'generatePS', icons['psExport'],
  1479. self.parent.OnPSFile),
  1480. ( self.generatePDF, 'generatePDF', icons['pdfExport'],
  1481. self.parent.OnPDFFile),
  1482. (None, ),
  1483. (self.help, "help", Icons['misc']['help'],
  1484. self.parent.OnHelp),
  1485. (self.quit, 'quit', icons['quit'],
  1486. self.parent.OnCloseWindow))
  1487. )