toolbars.py 63 KB

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