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