toolbars.py 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733
  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, mapcontent, tools = [], layerTree = None, log = None):
  417. self.mapcontent = mapcontent # Map class instance
  418. self.layerTree = layerTree # reference to layer tree associated to map display
  419. self.log = log # log area
  420. self.tools = tools
  421. AbstractToolbar.__init__(self, parent)
  422. self.digit = None
  423. # currently selected map layer for editing (reference to MapLayer instance)
  424. self.mapLayer = None
  425. # list of vector layers from Layer Manager (only in the current mapset)
  426. self.layers = []
  427. self.comboid = self.combo = None
  428. self.undo = -1
  429. # only one dialog can be open
  430. self.settingsDialog = None
  431. # create toolbars (two rows optionally)
  432. self.InitToolbar(self._toolbarData())
  433. self.Bind(wx.EVT_TOOL, self.OnTool)
  434. # default action (digitize new point, line, etc.)
  435. self.action = { 'desc' : '',
  436. 'type' : '',
  437. 'id' : -1 }
  438. # list of available vector maps
  439. self.UpdateListOfLayers(updateTool = True)
  440. # realize toolbar
  441. self.Realize()
  442. # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
  443. if self.combo:
  444. self.combo.Hide()
  445. self.combo.Show()
  446. # disable undo/redo
  447. if self.undo:
  448. self.EnableTool(self.undo, False)
  449. # toogle to pointer by default
  450. self.OnTool(None)
  451. self.FixSize(width = 105)
  452. def _toolbarData(self):
  453. """!Toolbar data
  454. """
  455. data = []
  456. icons = Icons['vdigit']
  457. if not self.tools or 'selector' in self.tools:
  458. data.append((None, ))
  459. if not self.tools or 'addPoint' in self.tools:
  460. data.append(("addPoint", icons["addPoint"],
  461. self.OnAddPoint,
  462. wx.ITEM_CHECK))
  463. if not self.tools or 'addLine' in self.tools:
  464. data.append(("addLine", icons["addLine"],
  465. self.OnAddLine,
  466. wx.ITEM_CHECK))
  467. if not self.tools or 'addBoundary' in self.tools:
  468. data.append(("addBoundary", icons["addBoundary"],
  469. self.OnAddBoundary,
  470. wx.ITEM_CHECK))
  471. if not self.tools or 'addCentroid' in self.tools:
  472. data.append(("addCentroid", icons["addCentroid"],
  473. self.OnAddCentroid,
  474. wx.ITEM_CHECK))
  475. if not self.tools or 'addArea' in self.tools:
  476. data.append(("addArea", icons["addArea"],
  477. self.OnAddArea,
  478. wx.ITEM_CHECK))
  479. if not self.tools or 'moveVertex' in self.tools:
  480. data.append(("moveVertex", icons["moveVertex"],
  481. self.OnMoveVertex,
  482. wx.ITEM_CHECK))
  483. if not self.tools or 'addVertex' in self.tools:
  484. data.append(("addVertex", icons["addVertex"],
  485. self.OnAddVertex,
  486. wx.ITEM_CHECK))
  487. if not self.tools or 'removeVertex' in self.tools:
  488. data.append(("removeVertex", icons["removeVertex"],
  489. self.OnRemoveVertex,
  490. wx.ITEM_CHECK))
  491. if not self.tools or 'editLine' in self.tools:
  492. data.append(("editLine", icons["editLine"],
  493. self.OnEditLine,
  494. wx.ITEM_CHECK))
  495. if not self.tools or 'moveLine' in self.tools:
  496. data.append(("moveLine", icons["moveLine"],
  497. self.OnMoveLine,
  498. wx.ITEM_CHECK))
  499. if not self.tools or 'deleteLine' in self.tools:
  500. data.append(("deleteLine", icons["deleteLine"],
  501. self.OnDeleteLine,
  502. wx.ITEM_CHECK))
  503. if not self.tools or 'displayCats' in self.tools:
  504. data.append(("displayCats", icons["displayCats"],
  505. self.OnDisplayCats,
  506. wx.ITEM_CHECK))
  507. if not self.tools or 'displayAttr' in self.tools:
  508. data.append(("displayAttr", icons["displayAttr"],
  509. self.OnDisplayAttr,
  510. wx.ITEM_CHECK))
  511. if not self.tools or 'additionalSelf.Tools' in self.tools:
  512. data.append(("additionalTools", icons["additionalTools"],
  513. self.OnAdditionalToolMenu,
  514. wx.ITEM_CHECK))
  515. if not self.tools or 'undo' in self.tools or \
  516. 'settings' in self.tools or \
  517. 'quit' in self.tools:
  518. data.append((None, ))
  519. if not self.tools or 'undo' in self.tools:
  520. data.append(("undo", icons["undo"],
  521. self.OnUndo))
  522. if not self.tools or 'settings' in self.tools:
  523. data.append(("settings", icons["settings"],
  524. self.OnSettings))
  525. if not self.tools or 'quit' in self.tools:
  526. data.append(("quit", icons["quit"],
  527. self.OnExit))
  528. return self._getToolbarData(data)
  529. def OnTool(self, event):
  530. """!Tool selected -> disable selected tool in map toolbar"""
  531. aId = self.parent.toolbars['map'].GetAction(type = 'id')
  532. self.parent.toolbars['map'].ToggleTool(aId, False)
  533. # set cursor
  534. cursor = self.parent.cursors["cross"]
  535. self.parent.MapWindow.SetCursor(cursor)
  536. # pointer
  537. self.parent.OnPointer(None)
  538. if event:
  539. # deselect previously selected tool
  540. aId = self.action.get('id', -1)
  541. if aId != event.GetId() and \
  542. self.action['id'] != -1:
  543. self.ToggleTool(self.action['id'], False)
  544. else:
  545. self.ToggleTool(self.action['id'], True)
  546. self.action['id'] = event.GetId()
  547. event.Skip()
  548. if self.action['id'] != -1:
  549. self.ToggleTool(self.action['id'], True)
  550. # clear tmp canvas
  551. if self.action['id'] != aId:
  552. self.parent.MapWindow.ClearLines(pdc = self.parent.MapWindow.pdcTmp)
  553. if self.digit and \
  554. len(self.parent.MapWindow.digit.GetDisplay().GetSelected()) > 0:
  555. # cancel action
  556. self.parent.MapWindow.OnMiddleDown(None)
  557. # set focus
  558. self.parent.MapWindow.SetFocus()
  559. def OnAddPoint(self, event):
  560. """!Add point to the vector map Laier"""
  561. Debug.msg (2, "VDigitToolbar.OnAddPoint()")
  562. self.action = { 'desc' : "addLine",
  563. 'type' : "point",
  564. 'id' : self.addPoint }
  565. self.parent.MapWindow.mouse['box'] = 'point'
  566. def OnAddLine(self, event):
  567. """!Add line to the vector map layer"""
  568. Debug.msg (2, "VDigitToolbar.OnAddLine()")
  569. self.action = { 'desc' : "addLine",
  570. 'type' : "line",
  571. 'id' : self.addLine }
  572. self.parent.MapWindow.mouse['box'] = 'line'
  573. ### self.parent.MapWindow.polycoords = [] # reset temp line
  574. def OnAddBoundary(self, event):
  575. """!Add boundary to the vector map layer"""
  576. Debug.msg (2, "VDigitToolbar.OnAddBoundary()")
  577. if self.action['desc'] != 'addLine' or \
  578. self.action['type'] != 'boundary':
  579. self.parent.MapWindow.polycoords = [] # reset temp line
  580. self.action = { 'desc' : "addLine",
  581. 'type' : "boundary",
  582. 'id' : self.addBoundary }
  583. self.parent.MapWindow.mouse['box'] = 'line'
  584. def OnAddCentroid(self, event):
  585. """!Add centroid to the vector map layer"""
  586. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  587. self.action = { 'desc' : "addLine",
  588. 'type' : "centroid",
  589. 'id' : self.addCentroid }
  590. self.parent.MapWindow.mouse['box'] = 'point'
  591. def OnAddArea(self, event):
  592. """!Add area to the vector map layer"""
  593. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  594. self.action = { 'desc' : "addLine",
  595. 'type' : "area",
  596. 'id' : self.addArea }
  597. self.parent.MapWindow.mouse['box'] = 'line'
  598. def OnExit (self, event=None):
  599. """!Quit digitization tool"""
  600. # stop editing of the currently selected map layer
  601. if self.mapLayer:
  602. self.StopEditing()
  603. # close dialogs if still open
  604. if self.settingsDialog:
  605. self.settingsDialog.OnCancel(None)
  606. # set default mouse settings
  607. self.parent.MapWindow.mouse['use'] = "pointer"
  608. self.parent.MapWindow.mouse['box'] = "point"
  609. self.parent.MapWindow.polycoords = []
  610. # disable the toolbar
  611. self.parent.RemoveToolbar("vdigit")
  612. def OnMoveVertex(self, event):
  613. """!Move line vertex"""
  614. Debug.msg(2, "Digittoolbar.OnMoveVertex():")
  615. self.action = { 'desc' : "moveVertex",
  616. 'id' : self.moveVertex }
  617. self.parent.MapWindow.mouse['box'] = 'point'
  618. def OnAddVertex(self, event):
  619. """!Add line vertex"""
  620. Debug.msg(2, "Digittoolbar.OnAddVertex():")
  621. self.action = { 'desc' : "addVertex",
  622. 'id' : self.addVertex }
  623. self.parent.MapWindow.mouse['box'] = 'point'
  624. def OnRemoveVertex(self, event):
  625. """!Remove line vertex"""
  626. Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
  627. self.action = { 'desc' : "removeVertex",
  628. 'id' : self.removeVertex }
  629. self.parent.MapWindow.mouse['box'] = 'point'
  630. def OnEditLine(self, event):
  631. """!Edit line"""
  632. Debug.msg(2, "Digittoolbar.OnEditLine():")
  633. self.action = { 'desc' : "editLine",
  634. 'id' : self.editLine }
  635. self.parent.MapWindow.mouse['box'] = 'line'
  636. def OnMoveLine(self, event):
  637. """!Move line"""
  638. Debug.msg(2, "Digittoolbar.OnMoveLine():")
  639. self.action = { 'desc' : "moveLine",
  640. 'id' : self.moveLine }
  641. self.parent.MapWindow.mouse['box'] = 'box'
  642. def OnDeleteLine(self, event):
  643. """!Delete line"""
  644. Debug.msg(2, "Digittoolbar.OnDeleteLine():")
  645. self.action = { 'desc' : "deleteLine",
  646. 'id' : self.deleteLine }
  647. self.parent.MapWindow.mouse['box'] = 'box'
  648. def OnDisplayCats(self, event):
  649. """!Display/update categories"""
  650. Debug.msg(2, "Digittoolbar.OnDisplayCats():")
  651. self.action = { 'desc' : "displayCats",
  652. 'id' : self.displayCats }
  653. self.parent.MapWindow.mouse['box'] = 'point'
  654. def OnDisplayAttr(self, event):
  655. """!Display/update attributes"""
  656. Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
  657. self.action = { 'desc' : "displayAttrs",
  658. 'id' : self.displayAttr }
  659. self.parent.MapWindow.mouse['box'] = 'point'
  660. def OnUndo(self, event):
  661. """!Undo previous changes"""
  662. self.digit.Undo()
  663. event.Skip()
  664. def EnableUndo(self, enable = True):
  665. """!Enable 'Undo' in toolbar
  666. @param enable False for disable
  667. """
  668. if enable:
  669. if self.GetToolEnabled(self.undo) is False:
  670. self.EnableTool(self.undo, True)
  671. else:
  672. if self.GetToolEnabled(self.undo) is True:
  673. self.EnableTool(self.undo, False)
  674. def OnSettings(self, event):
  675. """!Show settings dialog"""
  676. if self.digit is None:
  677. try:
  678. self.digit = self.parent.MapWindow.digit = VDigit(mapwindow = self.parent.MapWindow)
  679. except SystemExit:
  680. self.digit = self.parent.MapWindow.digit = None
  681. if not self.settingsDialog:
  682. self.settingsDialog = VDigitSettingsDialog(parent = self.parent, title = _("Digitization settings"),
  683. style = wx.DEFAULT_DIALOG_STYLE)
  684. self.settingsDialog.Show()
  685. def OnAdditionalToolMenu(self, event):
  686. """!Menu for additional tools"""
  687. point = wx.GetMousePosition()
  688. toolMenu = wx.Menu()
  689. for label, itype, handler, desc in (
  690. (_('Break selected lines/boundaries at intersection'),
  691. wx.ITEM_CHECK, self.OnBreak, "breakLine"),
  692. (_('Connect selected lines/boundaries'),
  693. wx.ITEM_CHECK, self.OnConnect, "connectLine"),
  694. (_('Copy categories'),
  695. wx.ITEM_CHECK, self.OnCopyCats, "copyCats"),
  696. (_('Copy features from (background) vector map'),
  697. wx.ITEM_CHECK, self.OnCopy, "copyLine"),
  698. (_('Copy attributes'),
  699. wx.ITEM_CHECK, self.OnCopyAttrb, "copyAttrs"),
  700. (_('Feature type conversion'),
  701. wx.ITEM_CHECK, self.OnTypeConversion, "typeConv"),
  702. (_('Flip selected lines/boundaries'),
  703. wx.ITEM_CHECK, self.OnFlip, "flipLine"),
  704. (_('Merge selected lines/boundaries'),
  705. wx.ITEM_CHECK, self.OnMerge, "mergeLine"),
  706. (_('Snap selected lines/boundaries (only to nodes)'),
  707. wx.ITEM_CHECK, self.OnSnap, "snapLine"),
  708. (_('Split line/boundary'),
  709. wx.ITEM_CHECK, self.OnSplitLine, "splitLine"),
  710. (_('Query features'),
  711. wx.ITEM_CHECK, self.OnQuery, "queryLine"),
  712. (_('Z bulk-labeling of 3D lines'),
  713. wx.ITEM_CHECK, self.OnZBulk, "zbulkLine")):
  714. # Add items to the menu
  715. item = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  716. text = label,
  717. kind = itype)
  718. toolMenu.AppendItem(item)
  719. self.parent.MapWindow.Bind(wx.EVT_MENU, handler, item)
  720. if self.action['desc'] == desc:
  721. item.Check(True)
  722. # Popup the menu. If an item is selected then its handler
  723. # will be called before PopupMenu returns.
  724. self.parent.MapWindow.PopupMenu(toolMenu)
  725. toolMenu.Destroy()
  726. if self.action['desc'] == 'addPoint':
  727. self.ToggleTool(self.additionalTools, False)
  728. def OnCopy(self, event):
  729. """!Copy selected features from (background) vector map"""
  730. if self.action['desc'] == 'copyLine': # select previous action
  731. self.ToggleTool(self.addPoint, True)
  732. self.ToggleTool(self.additionalTools, False)
  733. self.OnAddPoint(event)
  734. return
  735. Debug.msg(2, "Digittoolbar.OnCopy():")
  736. self.action = { 'desc' : "copyLine",
  737. 'id' : self.additionalTools }
  738. self.parent.MapWindow.mouse['box'] = 'box'
  739. def OnSplitLine(self, event):
  740. """!Split line"""
  741. if self.action['desc'] == 'splitLine': # select previous action
  742. self.ToggleTool(self.addPoint, True)
  743. self.ToggleTool(self.additionalTools, False)
  744. self.OnAddPoint(event)
  745. return
  746. Debug.msg(2, "Digittoolbar.OnSplitLine():")
  747. self.action = { 'desc' : "splitLine",
  748. 'id' : self.additionalTools }
  749. self.parent.MapWindow.mouse['box'] = 'point'
  750. def OnCopyCats(self, event):
  751. """!Copy categories"""
  752. if self.action['desc'] == 'copyCats': # select previous action
  753. self.ToggleTool(self.addPoint, True)
  754. self.ToggleTool(self.copyCats, False)
  755. self.OnAddPoint(event)
  756. return
  757. Debug.msg(2, "Digittoolbar.OnCopyCats():")
  758. self.action = { 'desc' : "copyCats",
  759. 'id' : self.additionalTools }
  760. self.parent.MapWindow.mouse['box'] = 'point'
  761. def OnCopyAttrb(self, event):
  762. """!Copy attributes"""
  763. if self.action['desc'] == 'copyAttrs': # select previous action
  764. self.ToggleTool(self.addPoint, True)
  765. self.ToggleTool(self.copyCats, False)
  766. self.OnAddPoint(event)
  767. return
  768. Debug.msg(2, "Digittoolbar.OnCopyAttrb():")
  769. self.action = { 'desc' : "copyAttrs",
  770. 'id' : self.additionalTools }
  771. self.parent.MapWindow.mouse['box'] = 'point'
  772. def OnFlip(self, event):
  773. """!Flip selected lines/boundaries"""
  774. if self.action['desc'] == 'flipLine': # select previous action
  775. self.ToggleTool(self.addPoint, True)
  776. self.ToggleTool(self.additionalTools, False)
  777. self.OnAddPoint(event)
  778. return
  779. Debug.msg(2, "Digittoolbar.OnFlip():")
  780. self.action = { 'desc' : "flipLine",
  781. 'id' : self.additionalTools }
  782. self.parent.MapWindow.mouse['box'] = 'box'
  783. def OnMerge(self, event):
  784. """!Merge selected lines/boundaries"""
  785. if self.action['desc'] == 'mergeLine': # select previous action
  786. self.ToggleTool(self.addPoint, True)
  787. self.ToggleTool(self.additionalTools, False)
  788. self.OnAddPoint(event)
  789. return
  790. Debug.msg(2, "Digittoolbar.OnMerge():")
  791. self.action = { 'desc' : "mergeLine",
  792. 'id' : self.additionalTools }
  793. self.parent.MapWindow.mouse['box'] = 'box'
  794. def OnBreak(self, event):
  795. """!Break selected lines/boundaries"""
  796. if self.action['desc'] == 'breakLine': # select previous action
  797. self.ToggleTool(self.addPoint, True)
  798. self.ToggleTool(self.additionalTools, False)
  799. self.OnAddPoint(event)
  800. return
  801. Debug.msg(2, "Digittoolbar.OnBreak():")
  802. self.action = { 'desc' : "breakLine",
  803. 'id' : self.additionalTools }
  804. self.parent.MapWindow.mouse['box'] = 'box'
  805. def OnSnap(self, event):
  806. """!Snap selected features"""
  807. if self.action['desc'] == 'snapLine': # select previous action
  808. self.ToggleTool(self.addPoint, True)
  809. self.ToggleTool(self.additionalTools, False)
  810. self.OnAddPoint(event)
  811. return
  812. Debug.msg(2, "Digittoolbar.OnSnap():")
  813. self.action = { 'desc' : "snapLine",
  814. 'id' : self.additionalTools }
  815. self.parent.MapWindow.mouse['box'] = 'box'
  816. def OnConnect(self, event):
  817. """!Connect selected lines/boundaries"""
  818. if self.action['desc'] == 'connectLine': # select previous action
  819. self.ToggleTool(self.addPoint, True)
  820. self.ToggleTool(self.additionalTools, False)
  821. self.OnAddPoint(event)
  822. return
  823. Debug.msg(2, "Digittoolbar.OnConnect():")
  824. self.action = { 'desc' : "connectLine",
  825. 'id' : self.additionalTools }
  826. self.parent.MapWindow.mouse['box'] = 'box'
  827. def OnQuery(self, event):
  828. """!Query selected lines/boundaries"""
  829. if self.action['desc'] == 'queryLine': # select previous action
  830. self.ToggleTool(self.addPoint, True)
  831. self.ToggleTool(self.additionalTools, False)
  832. self.OnAddPoint(event)
  833. return
  834. Debug.msg(2, "Digittoolbar.OnQuery(): %s" % \
  835. UserSettings.Get(group = 'vdigit', key = 'query', subkey = 'selection'))
  836. self.action = { 'desc' : "queryLine",
  837. 'id' : self.additionalTools }
  838. self.parent.MapWindow.mouse['box'] = 'box'
  839. def OnZBulk(self, event):
  840. """!Z bulk-labeling selected lines/boundaries"""
  841. if not self.digit.IsVector3D():
  842. GError(parent = self.parent,
  843. message = _("Vector map is not 3D. Operation canceled."))
  844. return
  845. if self.action['desc'] == 'zbulkLine': # select previous action
  846. self.ToggleTool(self.addPoint, True)
  847. self.ToggleTool(self.additionalTools, False)
  848. self.OnAddPoint(event)
  849. return
  850. Debug.msg(2, "Digittoolbar.OnZBulk():")
  851. self.action = { 'desc' : "zbulkLine",
  852. 'id' : self.additionalTools }
  853. self.parent.MapWindow.mouse['box'] = 'line'
  854. def OnTypeConversion(self, event):
  855. """!Feature type conversion
  856. Supported conversions:
  857. - point <-> centroid
  858. - line <-> boundary
  859. """
  860. if self.action['desc'] == 'typeConv': # select previous action
  861. self.ToggleTool(self.addPoint, True)
  862. self.ToggleTool(self.additionalTools, False)
  863. self.OnAddPoint(event)
  864. return
  865. Debug.msg(2, "Digittoolbar.OnTypeConversion():")
  866. self.action = { 'desc' : "typeConv",
  867. 'id' : self.additionalTools }
  868. self.parent.MapWindow.mouse['box'] = 'box'
  869. def OnSelectMap (self, event):
  870. """!Select vector map layer for editing
  871. If there is a vector map layer already edited, this action is
  872. firstly terminated. The map layer is closed. After this the
  873. selected map layer activated for editing.
  874. """
  875. if event.GetSelection() == 0: # create new vector map layer
  876. if self.mapLayer:
  877. openVectorMap = self.mapLayer.GetName(fullyQualified = False)['name']
  878. else:
  879. openVectorMap = None
  880. dlg = CreateNewVector(self.parent,
  881. exceptMap = openVectorMap, log = self.log,
  882. cmd = (('v.edit',
  883. { 'tool' : 'create' },
  884. 'map')),
  885. disableAdd = True)
  886. if dlg and dlg.GetName():
  887. # add layer to map layer tree
  888. if self.layerTree:
  889. mapName = dlg.GetName() + '@' + grass.gisenv()['MAPSET']
  890. self.layerTree.AddLayer(ltype = 'vector',
  891. lname = mapName,
  892. lcmd = ['d.vect', 'map=%s' % mapName])
  893. vectLayers = self.UpdateListOfLayers(updateTool = True)
  894. selection = vectLayers.index(mapName)
  895. # create table ?
  896. if dlg.IsChecked('table'):
  897. lmgr = self.parent.GetLayerManager()
  898. if lmgr:
  899. lmgr.OnShowAttributeTable(None, selection = 'table')
  900. dlg.Destroy()
  901. else:
  902. self.combo.SetValue(_('Select vector map'))
  903. if dlg:
  904. dlg.Destroy()
  905. return
  906. else:
  907. selection = event.GetSelection() - 1 # first option is 'New vector map'
  908. # skip currently selected map
  909. if self.layers[selection] == self.mapLayer:
  910. return
  911. if self.mapLayer:
  912. # deactive map layer for editing
  913. self.StopEditing()
  914. # select the given map layer for editing
  915. self.StartEditing(self.layers[selection])
  916. event.Skip()
  917. def StartEditing (self, mapLayer):
  918. """!Start editing selected vector map layer.
  919. @param mapLayer MapLayer to be edited
  920. """
  921. # deactive layer
  922. self.mapcontent.ChangeLayerActive(mapLayer, False)
  923. # clean map canvas
  924. self.parent.MapWindow.EraseMap()
  925. # unset background map if needed
  926. if mapLayer:
  927. if UserSettings.Get(group = 'vdigit', key = 'bgmap',
  928. subkey = 'value', internal = True) == mapLayer.GetName():
  929. UserSettings.Set(group = 'vdigit', key = 'bgmap',
  930. subkey = 'value', value = '', internal = True)
  931. self.parent.SetStatusText(_("Please wait, "
  932. "opening vector map <%s> for editing...") % mapLayer.GetName(),
  933. 0)
  934. self.parent.MapWindow.pdcVector = wx.PseudoDC()
  935. self.digit = self.parent.MapWindow.digit = VDigit(mapwindow = self.parent.MapWindow)
  936. self.mapLayer = mapLayer
  937. # open vector map
  938. if self.digit.OpenMap(mapLayer.GetName()) is None:
  939. self.mapLayer = None
  940. self.StopEditing()
  941. return False
  942. # check feature type (only for OGR layers)
  943. fType = self.digit.GetFeatureType()
  944. self.EnableAll()
  945. self.EnableUndo(False)
  946. if fType == 'Point':
  947. for tool in (self.addLine, self.addBoundary, self.addCentroid,
  948. self.addArea, self.moveVertex, self.addVertex,
  949. self.removeVertex, self.editLine):
  950. self.EnableTool(tool, False)
  951. elif fType == 'Line String':
  952. for tool in (self.addPoint, self.addBoundary, self.addCentroid,
  953. self.addArea):
  954. self.EnableTool(tool, False)
  955. elif fType == 'Polygon':
  956. for tool in (self.addPoint, self.addLine, self.addBoundary, self.addCentroid):
  957. self.EnableTool(tool, False)
  958. elif fType:
  959. GError(parent = self,
  960. message = _("Unsupported feature type '%s'. Unable to edit "
  961. "OGR layer <%s>.") % (fType, mapLayer.GetName()))
  962. self.digit.CloseMap()
  963. self.mapLayer = None
  964. self.StopEditing()
  965. return False
  966. # update toolbar
  967. if self.combo:
  968. self.combo.SetValue(mapLayer.GetName())
  969. self.parent.toolbars['map'].combo.SetValue (_('Digitize'))
  970. lmgr = self.parent.GetLayerManager()
  971. if lmgr:
  972. lmgr.toolbars['tools'].Enable('vdigit', enable = False)
  973. Debug.msg (4, "VDigitToolbar.StartEditing(): layer=%s" % mapLayer.GetName())
  974. # change cursor
  975. if self.parent.MapWindow.mouse['use'] == 'pointer':
  976. self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
  977. if not self.parent.MapWindow.resize:
  978. self.parent.MapWindow.UpdateMap(render = True)
  979. # respect opacity
  980. opacity = mapLayer.GetOpacity(float = True)
  981. if opacity < 1.0:
  982. alpha = int(opacity * 255)
  983. self.digit.GetDisplay().UpdateSettings(alpha = alpha)
  984. return True
  985. def StopEditing(self):
  986. """!Stop editing of selected vector map layer.
  987. @return True on success
  988. @return False on failure
  989. """
  990. if self.combo:
  991. self.combo.SetValue (_('Select vector map'))
  992. # save changes
  993. if self.mapLayer:
  994. Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % self.mapLayer.GetName())
  995. if UserSettings.Get(group = 'vdigit', key = 'saveOnExit', subkey = 'enabled') is False:
  996. if self.digit.GetUndoLevel() > -1:
  997. dlg = wx.MessageDialog(parent = self.parent,
  998. message = _("Do you want to save changes "
  999. "in vector map <%s>?") % self.mapLayer.GetName(),
  1000. caption = _("Save changes?"),
  1001. style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  1002. if dlg.ShowModal() == wx.ID_NO:
  1003. # revert changes
  1004. self.digit.Undo(0)
  1005. dlg.Destroy()
  1006. self.parent.SetStatusText(_("Please wait, "
  1007. "closing and rebuilding topology of "
  1008. "vector map <%s>...") % self.mapLayer.GetName(),
  1009. 0)
  1010. self.digit.CloseMap()
  1011. lmgr = self.parent.GetLayerManager()
  1012. if lmgr:
  1013. lmgr.toolbars['tools'].Enable('vdigit', enable = True)
  1014. lmgr.GetLogWindow().GetProgressBar().SetValue(0)
  1015. lmgr.GetLogWindow().WriteCmdLog(_("Editing of vector map <%s> successfully finished") % \
  1016. self.mapLayer.GetName(),
  1017. switchPage = False)
  1018. # re-active layer
  1019. item = self.parent.tree.FindItemByData('maplayer', self.mapLayer)
  1020. if item and self.parent.tree.IsItemChecked(item):
  1021. self.mapcontent.ChangeLayerActive(self.mapLayer, True)
  1022. # change cursor
  1023. self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
  1024. self.parent.MapWindow.pdcVector = None
  1025. # close dialogs
  1026. for dialog in ('attributes', 'category'):
  1027. if self.parent.dialogs[dialog]:
  1028. self.parent.dialogs[dialog].Close()
  1029. self.parent.dialogs[dialog] = None
  1030. del self.digit
  1031. del self.parent.MapWindow.digit
  1032. self.mapLayer = None
  1033. self.parent.MapWindow.redrawAll = True
  1034. return True
  1035. def UpdateListOfLayers (self, updateTool = False):
  1036. """!Update list of available vector map layers.
  1037. This list consists only editable layers (in the current mapset)
  1038. @param updateTool True to update also toolbar
  1039. """
  1040. Debug.msg (4, "VDigitToolbar.UpdateListOfLayers(): updateTool=%d" % \
  1041. updateTool)
  1042. layerNameSelected = None
  1043. # name of currently selected layer
  1044. if self.mapLayer:
  1045. layerNameSelected = self.mapLayer.GetName()
  1046. # select vector map layer in the current mapset
  1047. layerNameList = []
  1048. self.layers = self.mapcontent.GetListOfLayers(l_type = "vector",
  1049. l_mapset = grass.gisenv()['MAPSET'])
  1050. for layer in self.layers:
  1051. if not layer.name in layerNameList: # do not duplicate layer
  1052. layerNameList.append (layer.GetName())
  1053. if updateTool: # update toolbar
  1054. if not self.mapLayer:
  1055. value = _('Select vector map')
  1056. else:
  1057. value = layerNameSelected
  1058. if not self.comboid:
  1059. if not self.tools or 'selector' in self.tools:
  1060. self.combo = wx.ComboBox(self, id = wx.ID_ANY, value = value,
  1061. choices = [_('New vector map'), ] + layerNameList, size = (80, -1),
  1062. style = wx.CB_READONLY)
  1063. self.comboid = self.InsertControl(0, self.combo)
  1064. self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectMap, self.comboid)
  1065. else:
  1066. self.combo.SetItems([_('New vector map'), ] + layerNameList)
  1067. self.Realize()
  1068. return layerNameList
  1069. def GetLayer(self):
  1070. """!Get selected layer for editing -- MapLayer instance"""
  1071. return self.mapLayer
  1072. class ProfileToolbar(AbstractToolbar):
  1073. """!Toolbar for profiling raster map
  1074. """
  1075. def __init__(self, parent):
  1076. AbstractToolbar.__init__(self, parent)
  1077. self.InitToolbar(self._toolbarData())
  1078. # realize the toolbar
  1079. self.Realize()
  1080. def _toolbarData(self):
  1081. """!Toolbar data"""
  1082. icons = Icons['plot']
  1083. return self._getToolbarData((('addraster', Icons['layerManager']["addRast"],
  1084. self.parent.OnSelectRaster),
  1085. ('transect', icons["transect"],
  1086. self.parent.OnDrawTransect),
  1087. (None, ),
  1088. ('draw', icons["draw"],
  1089. self.parent.OnCreateProfile),
  1090. ('erase', Icons['displayWindow']["erase"],
  1091. self.parent.OnErase),
  1092. ('drag', Icons['displayWindow']['pan'],
  1093. self.parent.OnDrag),
  1094. ('zoom', Icons['displayWindow']['zoomIn'],
  1095. self.parent.OnZoom),
  1096. ('unzoom', Icons['displayWindow']['zoomBack'],
  1097. self.parent.OnRedraw),
  1098. (None, ),
  1099. ('statistics', icons['statistics'],
  1100. self.parent.OnStats),
  1101. ('datasave', icons["save"],
  1102. self.parent.SaveProfileToFile),
  1103. ('image', Icons['displayWindow']["saveFile"],
  1104. self.parent.SaveToFile),
  1105. ('print', Icons['displayWindow']["print"],
  1106. self.parent.PrintMenu),
  1107. (None, ),
  1108. ('settings', icons["options"],
  1109. self.parent.PlotOptionsMenu),
  1110. ('quit', icons["quit"],
  1111. self.parent.OnQuit),
  1112. ))
  1113. class LMNvizToolbar(AbstractToolbar):
  1114. """!Nviz toolbar
  1115. """
  1116. def __init__(self, parent):
  1117. self.lmgr = parent
  1118. AbstractToolbar.__init__(self, parent)
  1119. # only one dialog can be open
  1120. self.settingsDialog = None
  1121. self.InitToolbar(self._toolbarData())
  1122. # realize the toolbar
  1123. self.Realize()
  1124. def _toolbarData(self):
  1125. """!Toolbar data"""
  1126. icons = Icons['nviz']
  1127. return self._getToolbarData((("nvizCmd", icons['nvizCmd'],
  1128. self.OnNvizCmd),
  1129. (None, ),
  1130. ("settings", icons["settings"],
  1131. self.OnSettings),
  1132. ("help", icons["help"],
  1133. self.OnHelp))
  1134. )
  1135. def OnNvizCmd(self, event):
  1136. """!Show m.nviz.image command"""
  1137. self.lmgr.GetLayerTree().GetMapDisplay().GetWindow().OnNvizCmd()
  1138. def OnHelp(self, event):
  1139. """!Show 3D view mode help"""
  1140. if not self.lmgr:
  1141. RunCommand('g.manual',
  1142. entry = 'wxGUI.Nviz')
  1143. else:
  1144. log = self.lmgr.GetLogWindow()
  1145. log.RunCmd(['g.manual',
  1146. 'entry=wxGUI.Nviz'])
  1147. def OnSettings(self, event):
  1148. """!Show nviz notebook page"""
  1149. if not self.settingsDialog:
  1150. self.settingsDialog = NvizPreferencesDialog(parent = self.parent)
  1151. self.settingsDialog.Show()
  1152. class ModelToolbar(AbstractToolbar):
  1153. """!Graphical modeler toolbar (see gmodeler.py)
  1154. """
  1155. def __init__(self, parent):
  1156. AbstractToolbar.__init__(self, parent)
  1157. self.InitToolbar(self._toolbarData())
  1158. # realize the toolbar
  1159. self.Realize()
  1160. def _toolbarData(self):
  1161. """!Toolbar data"""
  1162. icons = Icons['modeler']
  1163. return self._getToolbarData((('new', icons['new'],
  1164. self.parent.OnModelNew),
  1165. ('open', icons['open'],
  1166. self.parent.OnModelOpen),
  1167. ('save', icons['save'],
  1168. self.parent.OnModelSave),
  1169. ('image', icons['toImage'],
  1170. self.parent.OnExportImage),
  1171. ('python', icons['toPython'],
  1172. self.parent.OnExportPython),
  1173. (None, ),
  1174. ('action', icons['actionAdd'],
  1175. self.parent.OnAddAction),
  1176. ('data', icons['dataAdd'],
  1177. self.parent.OnAddData),
  1178. ('relation', icons['relation'],
  1179. self.parent.OnDefineRelation),
  1180. ('loop', icons['loop'],
  1181. self.parent.OnDefineLoop),
  1182. (None, ),
  1183. ('redraw', icons['redraw'],
  1184. self.parent.OnCanvasRefresh),
  1185. ('validate', icons['validate'],
  1186. self.parent.OnValidateModel),
  1187. ('run', icons['run'],
  1188. self.parent.OnRunModel),
  1189. (None, ),
  1190. ("variables", icons['variables'],
  1191. self.parent.OnVariables),
  1192. ("settings", icons['settings'],
  1193. self.parent.OnPreferences),
  1194. ("help", Icons['misc']['help'],
  1195. self.parent.OnHelp),
  1196. (None, ),
  1197. ('quit', icons['quit'],
  1198. self.parent.OnCloseWindow))
  1199. )
  1200. class HistogramToolbar(AbstractToolbar):
  1201. """!Histogram toolbar (see histogram.py)
  1202. """
  1203. def __init__(self, parent):
  1204. AbstractToolbar.__init__(self, parent)
  1205. self.InitToolbar(self._toolbarData())
  1206. # realize the toolbar
  1207. self.Realize()
  1208. def _toolbarData(self):
  1209. """!Toolbar data"""
  1210. icons = Icons['displayWindow']
  1211. return self._getToolbarData((('histogram', icons["histogram"],
  1212. self.parent.OnOptions),
  1213. ('rendermao', icons["display"],
  1214. self.parent.OnRender),
  1215. ('erase', icons["erase"],
  1216. self.parent.OnErase),
  1217. ('font', Icons['misc']["font"],
  1218. self.parent.SetHistFont),
  1219. (None, ),
  1220. ('save', icons["saveFile"],
  1221. self.parent.SaveToFile),
  1222. ('hprint', icons["print"],
  1223. self.parent.PrintMenu),
  1224. (None, ),
  1225. ('quit', Icons['misc']["quit"],
  1226. self.parent.OnQuit))
  1227. )
  1228. class Histogram2Toolbar(AbstractToolbar):
  1229. """!Toolbar for histogramming raster map
  1230. """
  1231. def __init__(self, parent):
  1232. AbstractToolbar.__init__(self, parent)
  1233. self.InitToolbar(self._toolbarData())
  1234. # realize the toolbar
  1235. self.Realize()
  1236. def _toolbarData(self):
  1237. """!Toolbar data"""
  1238. icons = Icons['plot']
  1239. return self._getToolbarData((('addraster', Icons['layerManager']["addRast"],
  1240. self.parent.OnSelectRaster),
  1241. (None, ),
  1242. ('draw', icons["draw"],
  1243. self.parent.OnCreateHist),
  1244. ('erase', Icons['displayWindow']["erase"],
  1245. self.parent.OnErase),
  1246. ('drag', Icons['displayWindow']['pan'],
  1247. self.parent.OnDrag),
  1248. ('zoom', Icons['displayWindow']['zoomIn'],
  1249. self.parent.OnZoom),
  1250. ('unzoom', Icons['displayWindow']['zoomBack'],
  1251. self.parent.OnRedraw),
  1252. (None, ),
  1253. ('statistics', icons['statistics'],
  1254. self.parent.OnStats),
  1255. ('image', Icons['displayWindow']["saveFile"],
  1256. self.parent.SaveToFile),
  1257. ('print', Icons['displayWindow']["print"],
  1258. self.parent.PrintMenu),
  1259. (None, ),
  1260. ('settings', icons["options"],
  1261. self.parent.PlotOptionsMenu),
  1262. ('quit', icons["quit"],
  1263. self.parent.OnQuit),
  1264. ))
  1265. class ScatterplotToolbar(AbstractToolbar):
  1266. """!Toolbar for bivariate scatterplots of raster map pairs
  1267. """
  1268. def __init__(self, parent):
  1269. AbstractToolbar.__init__(self, parent)
  1270. self.InitToolbar(self._toolbarData())
  1271. # realize the toolbar
  1272. self.Realize()
  1273. def _toolbarData(self):
  1274. """!Toolbar data"""
  1275. icons = Icons['plot']
  1276. # icons2 = Icons['modeler']
  1277. return self._getToolbarData((('addraster', Icons['layerManager']["addRast"],
  1278. self.parent.OnSelectRaster),
  1279. (None, ),
  1280. ('draw', icons["draw"],
  1281. self.parent.OnCreateScatter),
  1282. ('erase', Icons['displayWindow']["erase"],
  1283. self.parent.OnErase),
  1284. ('drag', Icons['displayWindow']['pan'],
  1285. self.parent.OnDrag),
  1286. ('zoom', Icons['displayWindow']['zoomIn'],
  1287. self.parent.OnZoom),
  1288. ('unzoom', Icons['displayWindow']['zoomBack'],
  1289. self.parent.OnRedraw),
  1290. (None, ),
  1291. ('statistics', icons['statistics'],
  1292. self.parent.OnRegression),
  1293. ('image', Icons['displayWindow']["saveFile"],
  1294. self.parent.SaveToFile),
  1295. ('print', Icons['displayWindow']["print"],
  1296. self.parent.PrintMenu),
  1297. (None, ),
  1298. ('settings', icons["options"],
  1299. self.parent.PlotOptionsMenu),
  1300. ('quit', icons["quit"],
  1301. self.parent.OnQuit),
  1302. ))
  1303. class LMWorkspaceToolbar(AbstractToolbar):
  1304. """!Layer Manager `workspace` toolbar
  1305. """
  1306. def __init__(self, parent):
  1307. AbstractToolbar.__init__(self, parent)
  1308. self.InitToolbar(self._toolbarData())
  1309. # realize the toolbar
  1310. self.Realize()
  1311. def _toolbarData(self):
  1312. """!Toolbar data
  1313. """
  1314. icons = Icons['layerManager']
  1315. return self._getToolbarData((('newdisplay', icons["newdisplay"],
  1316. self.parent.OnNewDisplay),
  1317. (None, ),
  1318. ('workspaceNew', icons["workspaceNew"],
  1319. self.parent.OnWorkspaceNew),
  1320. ('workspaceOpen', icons["workspaceOpen"],
  1321. self.parent.OnWorkspaceOpen),
  1322. ('workspaceSave', icons["workspaceSave"],
  1323. self.parent.OnWorkspaceSave),
  1324. ))
  1325. class LMDataToolbar(AbstractToolbar):
  1326. """!Layer Manager `data` toolbar
  1327. """
  1328. def __init__(self, parent):
  1329. AbstractToolbar.__init__(self, parent)
  1330. self.InitToolbar(self._toolbarData())
  1331. # realize the toolbar
  1332. self.Realize()
  1333. def _toolbarData(self):
  1334. """!Toolbar data
  1335. """
  1336. icons = Icons['layerManager']
  1337. return self._getToolbarData((('addMulti', icons["addMulti"],
  1338. self.parent.OnAddMaps),
  1339. ('addrast', icons["addRast"],
  1340. self.parent.OnAddRaster),
  1341. ('rastmisc', icons["rastMisc"],
  1342. self.parent.OnAddRasterMisc),
  1343. ('addvect', icons["addVect"],
  1344. self.parent.OnAddVector),
  1345. ('vectmisc', icons["vectMisc"],
  1346. self.parent.OnAddVectorMisc),
  1347. ('addgrp', icons["addGroup"],
  1348. self.parent.OnAddGroup),
  1349. ('addovl', icons["addOverlay"],
  1350. self.parent.OnAddOverlay),
  1351. ('delcmd', icons["delCmd"],
  1352. self.parent.OnDeleteLayer),
  1353. ))
  1354. class LMToolsToolbar(AbstractToolbar):
  1355. """!Layer Manager `tools` toolbar
  1356. """
  1357. def __init__(self, parent):
  1358. AbstractToolbar.__init__(self, parent)
  1359. self.InitToolbar(self._toolbarData())
  1360. # realize the toolbar
  1361. self.Realize()
  1362. def _toolbarData(self):
  1363. """!Toolbar data
  1364. """
  1365. icons = Icons['layerManager']
  1366. return self._getToolbarData((('importMap', icons["import"],
  1367. self.parent.OnImportMenu),
  1368. (None, ),
  1369. ('mapCalc', icons["mapcalc"],
  1370. self.parent.OnMapCalculator),
  1371. ('georect', Icons["georectify"]["georectify"],
  1372. self.parent.OnGCPManager),
  1373. ('modeler', icons["modeler"],
  1374. self.parent.OnGModeler),
  1375. ('mapOutput', icons['mapOutput'],
  1376. self.parent.OnPsMap)
  1377. ))
  1378. class LMMiscToolbar(AbstractToolbar):
  1379. """!Layer Manager `misc` toolbar
  1380. """
  1381. def __init__(self, parent):
  1382. AbstractToolbar.__init__(self, parent)
  1383. self.InitToolbar(self._toolbarData())
  1384. # realize the toolbar
  1385. self.Realize()
  1386. def _toolbarData(self):
  1387. """!Toolbar data
  1388. """
  1389. icons = Icons['layerManager']
  1390. return self._getToolbarData((('settings', icons["settings"],
  1391. self.parent.OnPreferences),
  1392. ('help', Icons["misc"]["help"],
  1393. self.parent.OnHelp),
  1394. ))
  1395. class LMVectorToolbar(AbstractToolbar):
  1396. """!Layer Manager `vector` toolbar
  1397. """
  1398. def __init__(self, parent):
  1399. AbstractToolbar.__init__(self, parent)
  1400. self.InitToolbar(self._toolbarData())
  1401. # realize the toolbar
  1402. self.Realize()
  1403. def _toolbarData(self):
  1404. """!Toolbar data
  1405. """
  1406. icons = Icons['layerManager']
  1407. return self._getToolbarData((('vdigit', icons["vdigit"],
  1408. self.parent.OnVDigit),
  1409. ('attribute', icons["attrTable"],
  1410. self.parent.OnShowAttributeTable),
  1411. ))
  1412. class PsMapToolbar(AbstractToolbar):
  1413. def __init__(self, parent):
  1414. """!Toolbar Cartographic Composer (psmap.py)
  1415. @param parent parent window
  1416. """
  1417. AbstractToolbar.__init__(self, parent)
  1418. self.InitToolbar(self._toolbarData())
  1419. self.Realize()
  1420. self.action = { 'id' : self.pointer }
  1421. self.defaultAction = { 'id' : self.pointer,
  1422. 'bind' : self.parent.OnPointer }
  1423. self.OnTool(None)
  1424. from psmap import haveImage
  1425. if not haveImage:
  1426. self.EnableTool(self.preview, False)
  1427. def _toolbarData(self):
  1428. """!Toolbar data
  1429. """
  1430. icons = Icons['psMap']
  1431. return self._getToolbarData((('loadFile', icons['scriptLoad'],
  1432. self.parent.OnLoadFile),
  1433. ('instructionFile', icons['scriptSave'],
  1434. self.parent.OnInstructionFile),
  1435. (None, ),
  1436. ('pagesetup', icons['pageSetup'],
  1437. self.parent.OnPageSetup),
  1438. (None, ),
  1439. ("pointer", Icons["displayWindow"]["pointer"],
  1440. self.parent.OnPointer, wx.ITEM_CHECK),
  1441. ('pan', Icons["displayWindow"]['pan'],
  1442. self.parent.OnPan, wx.ITEM_CHECK),
  1443. ("zoomin", Icons["displayWindow"]["zoomIn"],
  1444. self.parent.OnZoomIn, wx.ITEM_CHECK),
  1445. ("zoomout", Icons["displayWindow"]["zoomOut"],
  1446. self.parent.OnZoomOut, wx.ITEM_CHECK),
  1447. ('zoomAll', icons['fullExtent'],
  1448. self.parent.OnZoomAll),
  1449. (None, ),
  1450. ('addMap', icons['addMap'],
  1451. self.parent.OnAddMap, wx.ITEM_CHECK),
  1452. ('addRaster', icons['addRast'],
  1453. self.parent.OnAddRaster),
  1454. ('addVector', icons['addVect'],
  1455. self.parent.OnAddVect),
  1456. ("dec", Icons["displayWindow"]["overlay"],
  1457. self.parent.OnDecoration),
  1458. ("delete", icons["deleteObj"],
  1459. self.parent.OnDelete),
  1460. (None, ),
  1461. ("preview", icons["preview"],
  1462. self.parent.OnPreview),
  1463. ('generatePS', icons['psExport'],
  1464. self.parent.OnPSFile),
  1465. ('generatePDF', icons['pdfExport'],
  1466. self.parent.OnPDFFile),
  1467. (None, ),
  1468. ("help", Icons['misc']['help'],
  1469. self.parent.OnHelp),
  1470. ('quit', icons['quit'],
  1471. self.parent.OnCloseWindow))
  1472. )