toolbars.py 64 KB

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