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.zoommenu,
  314. self.analyze,
  315. self.printmap):
  316. self.EnableTool(tool, enabled)
  317. class GCPManToolbar(AbstractToolbar):
  318. """!Toolbar for managing ground control points
  319. @param parent reference to GCP widget
  320. """
  321. def __init__(self, parent):
  322. AbstractToolbar.__init__(self, parent)
  323. self.InitToolbar(self._toolbarData())
  324. # realize the toolbar
  325. self.Realize()
  326. def _toolbarData(self):
  327. icons = Icons['georectify']
  328. return self._getToolbarData((('gcpSave', icons["gcpSave"],
  329. self.parent.SaveGCPs),
  330. ('gcpReload', icons["gcpReload"],
  331. self.parent.ReloadGCPs),
  332. (None, ),
  333. ('gcpAdd', icons["gcpAdd"],
  334. self.parent.AddGCP),
  335. ('gcpDelete', icons["gcpDelete"],
  336. self.parent.DeleteGCP),
  337. ('gcpClear', icons["gcpClear"],
  338. self.parent.ClearGCP),
  339. (None, ),
  340. ('rms', icons["gcpRms"],
  341. self.parent.OnRMS),
  342. ('georect', icons["georectify"],
  343. self.parent.OnGeorect))
  344. )
  345. class GCPDisplayToolbar(AbstractToolbar):
  346. """!GCP Display toolbar
  347. """
  348. def __init__(self, parent):
  349. """!GCP Display toolbar constructor
  350. """
  351. AbstractToolbar.__init__(self, parent)
  352. self.InitToolbar(self._toolbarData())
  353. # add tool to toggle active map window
  354. self.togglemapid = wx.NewId()
  355. self.togglemap = wx.Choice(parent = self, id = self.togglemapid,
  356. choices = [_('source'), _('target')],
  357. style = wx.CB_READONLY)
  358. self.InsertControl(10, self.togglemap)
  359. self.SetToolShortHelp(self.togglemapid, '%s %s %s' % (_('Set map canvas for '),
  360. Icons['displayWindow']["zoomBack"].GetLabel(),
  361. _(' / Zoom to map')))
  362. # realize the toolbar
  363. self.Realize()
  364. self.action = { 'id' : self.gcpset }
  365. self.defaultAction = { 'id' : self.gcpset,
  366. 'bind' : self.parent.OnPointer }
  367. self.OnTool(None)
  368. self.EnableTool(self.zoomback, False)
  369. def _toolbarData(self):
  370. """!Toolbar data"""
  371. icons = Icons['displayWindow']
  372. return self._getToolbarData((("displaymap", icons["display"],
  373. self.parent.OnDraw),
  374. ("rendermap", icons["render"],
  375. self.parent.OnRender),
  376. ("erase", icons["erase"],
  377. self.parent.OnErase),
  378. (None, ),
  379. ("gcpset", Icons["georectify"]["gcpSet"],
  380. self.parent.OnPointer),
  381. ("pan", icons["pan"],
  382. self.parent.OnPan),
  383. ("zoomin", icons["zoomIn"],
  384. self.parent.OnZoomIn),
  385. ("zoomout", icons["zoomOut"],
  386. self.parent.OnZoomOut),
  387. ("zoommenu", icons["zoomMenu"],
  388. self.parent.OnZoomMenuGCP),
  389. (None, ),
  390. ("zoomback", icons["zoomBack"],
  391. self.parent.OnZoomBack),
  392. ("zoomtomap", icons["zoomExtent"],
  393. self.parent.OnZoomToMap),
  394. (None, ),
  395. ('settings', Icons["georectify"]["settings"],
  396. self.parent.OnSettings),
  397. ('help', Icons["misc"]["help"],
  398. self.parent.OnHelp),
  399. (None, ),
  400. ('quit', Icons["georectify"]["quit"],
  401. self.parent.OnQuit))
  402. )
  403. class VDigitToolbar(AbstractToolbar):
  404. """!Toolbar for digitization
  405. """
  406. def __init__(self, parent, mapcontent, layerTree = None, log = None):
  407. self.mapcontent = mapcontent # Map class instance
  408. self.layerTree = layerTree # reference to layer tree associated to map display
  409. self.log = log # log area
  410. AbstractToolbar.__init__(self, parent)
  411. self.digit = None
  412. # currently selected map layer for editing (reference to MapLayer instance)
  413. self.mapLayer = None
  414. # list of vector layers from Layer Manager (only in the current mapset)
  415. self.layers = []
  416. self.comboid = None
  417. # only one dialog can be open
  418. self.settingsDialog = None
  419. # create toolbars (two rows optionally)
  420. self.InitToolbar(self._toolbarData())
  421. self.Bind(wx.EVT_TOOL, self.OnTool)
  422. # default action (digitize new point, line, etc.)
  423. self.action = { 'desc' : 'addLine',
  424. 'type' : 'point',
  425. 'id' : self.addPoint }
  426. # list of available vector maps
  427. self.UpdateListOfLayers(updateTool = True)
  428. # realize toolbar
  429. self.Realize()
  430. # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
  431. self.combo.Hide()
  432. self.combo.Show()
  433. # disable undo/redo
  434. self.EnableTool(self.undo, False)
  435. # toogle to pointer by default
  436. self.OnTool(None)
  437. self.FixSize(width = 105)
  438. def _toolbarData(self):
  439. """!Toolbar data
  440. """
  441. data = []
  442. icons = Icons['vdigit']
  443. return self._getToolbarData(((None, ),
  444. ("addPoint", icons["addPoint"],
  445. self.OnAddPoint),
  446. ("addLine", icons["addLine"],
  447. self.OnAddLine,
  448. wx.ITEM_CHECK),
  449. ("addBoundary", icons["addBoundary"],
  450. self.OnAddBoundary,
  451. wx.ITEM_CHECK),
  452. ("addCentroid", icons["addCentroid"],
  453. self.OnAddCentroid,
  454. wx.ITEM_CHECK),
  455. ("addArea", icons["addArea"],
  456. self.OnAddArea,
  457. wx.ITEM_CHECK),
  458. ("moveVertex", icons["moveVertex"],
  459. self.OnMoveVertex,
  460. wx.ITEM_CHECK),
  461. ("addVertex", icons["addVertex"],
  462. self.OnAddVertex,
  463. wx.ITEM_CHECK),
  464. ("removeVertex", icons["removeVertex"],
  465. self.OnRemoveVertex,
  466. wx.ITEM_CHECK),
  467. ("editLine", icons["editLine"],
  468. self.OnEditLine,
  469. wx.ITEM_CHECK),
  470. ("moveLine", icons["moveLine"],
  471. self.OnMoveLine,
  472. wx.ITEM_CHECK),
  473. ("deleteLine", icons["deleteLine"],
  474. self.OnDeleteLine,
  475. wx.ITEM_CHECK),
  476. ("displayCats", icons["displayCats"],
  477. self.OnDisplayCats,
  478. wx.ITEM_CHECK),
  479. ("displayAttr", icons["displayAttr"],
  480. self.OnDisplayAttr,
  481. wx.ITEM_CHECK),
  482. ("additionalTools", icons["additionalTools"],
  483. self.OnAdditionalToolMenu,
  484. wx.ITEM_CHECK),
  485. (None, ),
  486. ("undo", icons["undo"],
  487. self.OnUndo),
  488. ("settings", icons["settings"],
  489. self.OnSettings),
  490. ("quit", icons["quit"],
  491. self.OnExit))
  492. )
  493. def OnTool(self, event):
  494. """!Tool selected -> disable selected tool in map toolbar"""
  495. id = self.parent.toolbars['map'].GetAction(type = 'id')
  496. self.parent.toolbars['map'].ToggleTool(id, False)
  497. # set cursor
  498. cursor = self.parent.cursors["cross"]
  499. self.parent.MapWindow.SetCursor(cursor)
  500. # pointer
  501. self.parent.OnPointer(None)
  502. if event:
  503. # deselect previously selected tool
  504. id = self.action.get('id', -1)
  505. if id != event.GetId():
  506. self.ToggleTool(self.action['id'], False)
  507. else:
  508. self.ToggleTool(self.action['id'], True)
  509. self.action['id'] = event.GetId()
  510. event.Skip()
  511. self.ToggleTool(self.action['id'], True)
  512. # clear tmp canvas
  513. if self.action['id'] != id:
  514. self.parent.MapWindow.ClearLines(pdc = self.parent.MapWindow.pdcTmp)
  515. if self.digit and \
  516. len(self.parent.MapWindow.digit.GetDisplay().GetSelected()) > 0:
  517. # cancel action
  518. self.parent.MapWindow.OnMiddleDown(None)
  519. # set focus
  520. self.parent.MapWindow.SetFocus()
  521. def OnAddPoint(self, event):
  522. """!Add point to the vector map Laier"""
  523. Debug.msg (2, "VDigitToolbar.OnAddPoint()")
  524. self.action = { 'desc' : "addLine",
  525. 'type' : "point",
  526. 'id' : self.addPoint }
  527. self.parent.MapWindow.mouse['box'] = 'point'
  528. def OnAddLine(self, event):
  529. """!Add line to the vector map layer"""
  530. Debug.msg (2, "VDigitToolbar.OnAddLine()")
  531. self.action = { 'desc' : "addLine",
  532. 'type' : "line",
  533. 'id' : self.addLine }
  534. self.parent.MapWindow.mouse['box'] = 'line'
  535. ### self.parent.MapWindow.polycoords = [] # reset temp line
  536. def OnAddBoundary(self, event):
  537. """!Add boundary to the vector map layer"""
  538. Debug.msg (2, "VDigitToolbar.OnAddBoundary()")
  539. if self.action['desc'] != 'addLine' or \
  540. self.action['type'] != 'boundary':
  541. self.parent.MapWindow.polycoords = [] # reset temp line
  542. self.action = { 'desc' : "addLine",
  543. 'type' : "boundary",
  544. 'id' : self.addBoundary }
  545. self.parent.MapWindow.mouse['box'] = 'line'
  546. def OnAddCentroid(self, event):
  547. """!Add centroid to the vector map layer"""
  548. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  549. self.action = { 'desc' : "addLine",
  550. 'type' : "centroid",
  551. 'id' : self.addCentroid }
  552. self.parent.MapWindow.mouse['box'] = 'point'
  553. def OnAddArea(self, event):
  554. """!Add area to the vector map layer"""
  555. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  556. self.action = { 'desc' : "addLine",
  557. 'type' : "area",
  558. 'id' : self.addArea }
  559. self.parent.MapWindow.mouse['box'] = 'line'
  560. def OnExit (self, event=None):
  561. """!Quit digitization tool"""
  562. # stop editing of the currently selected map layer
  563. if self.mapLayer:
  564. self.StopEditing()
  565. # close dialogs if still open
  566. if self.settingsDialog:
  567. self.settingsDialog.OnCancel(None)
  568. # set default mouse settings
  569. self.parent.MapWindow.mouse['use'] = "pointer"
  570. self.parent.MapWindow.mouse['box'] = "point"
  571. self.parent.MapWindow.polycoords = []
  572. # disable the toolbar
  573. self.parent.RemoveToolbar("vdigit")
  574. def OnMoveVertex(self, event):
  575. """!Move line vertex"""
  576. Debug.msg(2, "Digittoolbar.OnMoveVertex():")
  577. self.action = { 'desc' : "moveVertex",
  578. 'id' : self.moveVertex }
  579. self.parent.MapWindow.mouse['box'] = 'point'
  580. def OnAddVertex(self, event):
  581. """!Add line vertex"""
  582. Debug.msg(2, "Digittoolbar.OnAddVertex():")
  583. self.action = { 'desc' : "addVertex",
  584. 'id' : self.addVertex }
  585. self.parent.MapWindow.mouse['box'] = 'point'
  586. def OnRemoveVertex(self, event):
  587. """!Remove line vertex"""
  588. Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
  589. self.action = { 'desc' : "removeVertex",
  590. 'id' : self.removeVertex }
  591. self.parent.MapWindow.mouse['box'] = 'point'
  592. def OnEditLine(self, event):
  593. """!Edit line"""
  594. Debug.msg(2, "Digittoolbar.OnEditLine():")
  595. self.action = { 'desc' : "editLine",
  596. 'id' : self.editLine }
  597. self.parent.MapWindow.mouse['box'] = 'line'
  598. def OnMoveLine(self, event):
  599. """!Move line"""
  600. Debug.msg(2, "Digittoolbar.OnMoveLine():")
  601. self.action = { 'desc' : "moveLine",
  602. 'id' : self.moveLine }
  603. self.parent.MapWindow.mouse['box'] = 'box'
  604. def OnDeleteLine(self, event):
  605. """!Delete line"""
  606. Debug.msg(2, "Digittoolbar.OnDeleteLine():")
  607. self.action = { 'desc' : "deleteLine",
  608. 'id' : self.deleteLine }
  609. self.parent.MapWindow.mouse['box'] = 'box'
  610. def OnDisplayCats(self, event):
  611. """!Display/update categories"""
  612. Debug.msg(2, "Digittoolbar.OnDisplayCats():")
  613. self.action = { 'desc' : "displayCats",
  614. 'id' : self.displayCats }
  615. self.parent.MapWindow.mouse['box'] = 'point'
  616. def OnDisplayAttr(self, event):
  617. """!Display/update attributes"""
  618. Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
  619. self.action = { 'desc' : "displayAttrs",
  620. 'id' : self.displayAttr }
  621. self.parent.MapWindow.mouse['box'] = 'point'
  622. def OnUndo(self, event):
  623. """!Undo previous changes"""
  624. self.digit.Undo()
  625. event.Skip()
  626. def EnableUndo(self, enable=True):
  627. """!Enable 'Undo' in toolbar
  628. @param enable False for disable
  629. """
  630. if enable:
  631. if self.GetToolEnabled(self.undo) is False:
  632. self.EnableTool(self.undo, True)
  633. else:
  634. if self.GetToolEnabled(self.undo) is True:
  635. self.EnableTool(self.undo, False)
  636. def OnSettings(self, event):
  637. """!Show settings dialog"""
  638. if self.digit is None:
  639. try:
  640. self.digit = self.parent.MapWindow.digit = VDigit(mapwindow = self.parent.MapWindow)
  641. except SystemExit:
  642. self.digit = self.parent.MapWindow.digit = None
  643. if not self.settingsDialog:
  644. self.settingsDialog = VDigitSettingsDialog(parent = self.parent, title = _("Digitization settings"),
  645. style = wx.DEFAULT_DIALOG_STYLE)
  646. self.settingsDialog.Show()
  647. def OnAdditionalToolMenu(self, event):
  648. """!Menu for additional tools"""
  649. point = wx.GetMousePosition()
  650. toolMenu = wx.Menu()
  651. for label, itype, handler, desc in (
  652. (_('Break selected lines/boundaries at intersection'),
  653. wx.ITEM_CHECK, self.OnBreak, "breakLine"),
  654. (_('Connect selected lines/boundaries'),
  655. wx.ITEM_CHECK, self.OnConnect, "connectLine"),
  656. (_('Copy categories'),
  657. wx.ITEM_CHECK, self.OnCopyCats, "copyCats"),
  658. (_('Copy features from (background) vector map'),
  659. wx.ITEM_CHECK, self.OnCopy, "copyLine"),
  660. (_('Duplicate attributes'),
  661. wx.ITEM_CHECK, self.OnCopyAttrb, "copyAttrs"),
  662. (_('Feature type conversion'),
  663. wx.ITEM_CHECK, self.OnTypeConversion, "typeConv"),
  664. (_('Flip selected lines/boundaries'),
  665. wx.ITEM_CHECK, self.OnFlip, "flipLine"),
  666. (_('Merge selected lines/boundaries'),
  667. wx.ITEM_CHECK, self.OnMerge, "mergeLine"),
  668. (_('Snap selected lines/boundaries (only to nodes)'),
  669. wx.ITEM_CHECK, self.OnSnap, "snapLine"),
  670. (_('Split line/boundary'),
  671. wx.ITEM_CHECK, self.OnSplitLine, "splitLine"),
  672. (_('Query features'),
  673. wx.ITEM_CHECK, self.OnQuery, "queryLine"),
  674. (_('Z bulk-labeling of 3D lines'),
  675. wx.ITEM_CHECK, self.OnZBulk, "zbulkLine")):
  676. # Add items to the menu
  677. item = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  678. text = label,
  679. kind = itype)
  680. toolMenu.AppendItem(item)
  681. self.parent.MapWindow.Bind(wx.EVT_MENU, handler, item)
  682. if self.action['desc'] == desc:
  683. item.Check(True)
  684. # Popup the menu. If an item is selected then its handler
  685. # will be called before PopupMenu returns.
  686. self.parent.MapWindow.PopupMenu(toolMenu)
  687. toolMenu.Destroy()
  688. if self.action['desc'] == 'addPoint':
  689. self.ToggleTool(self.additionalTools, False)
  690. def OnCopy(self, event):
  691. """!Copy selected features from (background) vector map"""
  692. if self.action['desc'] == 'copyLine': # select previous action
  693. self.ToggleTool(self.addPoint, True)
  694. self.ToggleTool(self.additionalTools, False)
  695. self.OnAddPoint(event)
  696. return
  697. Debug.msg(2, "Digittoolbar.OnCopy():")
  698. self.action = { 'desc' : "copyLine",
  699. 'id' : self.additionalTools }
  700. self.parent.MapWindow.mouse['box'] = 'box'
  701. def OnSplitLine(self, event):
  702. """!Split line"""
  703. if self.action['desc'] == 'splitLine': # select previous action
  704. self.ToggleTool(self.addPoint, True)
  705. self.ToggleTool(self.additionalTools, False)
  706. self.OnAddPoint(event)
  707. return
  708. Debug.msg(2, "Digittoolbar.OnSplitLine():")
  709. self.action = { 'desc' : "splitLine",
  710. 'id' : self.additionalTools }
  711. self.parent.MapWindow.mouse['box'] = 'point'
  712. def OnCopyCats(self, event):
  713. """!Copy categories"""
  714. if self.action['desc'] == 'copyCats': # select previous action
  715. self.ToggleTool(self.addPoint, True)
  716. self.ToggleTool(self.copyCats, False)
  717. self.OnAddPoint(event)
  718. return
  719. Debug.msg(2, "Digittoolbar.OnCopyCats():")
  720. self.action = { 'desc' : "copyCats",
  721. 'id' : self.additionalTools }
  722. self.parent.MapWindow.mouse['box'] = 'point'
  723. def OnCopyAttrb(self, event):
  724. """!Copy attributes"""
  725. if self.action['desc'] == 'copyAttrs': # select previous action
  726. self.ToggleTool(self.addPoint, True)
  727. self.ToggleTool(self.copyCats, False)
  728. self.OnAddPoint(event)
  729. return
  730. Debug.msg(2, "Digittoolbar.OnCopyAttrb():")
  731. self.action = { 'desc' : "copyAttrs",
  732. 'id' : self.additionalTools }
  733. self.parent.MapWindow.mouse['box'] = 'point'
  734. def OnFlip(self, event):
  735. """!Flip selected lines/boundaries"""
  736. if self.action['desc'] == 'flipLine': # select previous action
  737. self.ToggleTool(self.addPoint, True)
  738. self.ToggleTool(self.additionalTools, False)
  739. self.OnAddPoint(event)
  740. return
  741. Debug.msg(2, "Digittoolbar.OnFlip():")
  742. self.action = { 'desc' : "flipLine",
  743. 'id' : self.additionalTools }
  744. self.parent.MapWindow.mouse['box'] = 'box'
  745. def OnMerge(self, event):
  746. """!Merge selected lines/boundaries"""
  747. if self.action['desc'] == 'mergeLine': # select previous action
  748. self.ToggleTool(self.addPoint, True)
  749. self.ToggleTool(self.additionalTools, False)
  750. self.OnAddPoint(event)
  751. return
  752. Debug.msg(2, "Digittoolbar.OnMerge():")
  753. self.action = { 'desc' : "mergeLine",
  754. 'id' : self.additionalTools }
  755. self.parent.MapWindow.mouse['box'] = 'box'
  756. def OnBreak(self, event):
  757. """!Break selected lines/boundaries"""
  758. if self.action['desc'] == 'breakLine': # select previous action
  759. self.ToggleTool(self.addPoint, True)
  760. self.ToggleTool(self.additionalTools, False)
  761. self.OnAddPoint(event)
  762. return
  763. Debug.msg(2, "Digittoolbar.OnBreak():")
  764. self.action = { 'desc' : "breakLine",
  765. 'id' : self.additionalTools }
  766. self.parent.MapWindow.mouse['box'] = 'box'
  767. def OnSnap(self, event):
  768. """!Snap selected features"""
  769. if self.action['desc'] == 'snapLine': # select previous action
  770. self.ToggleTool(self.addPoint, True)
  771. self.ToggleTool(self.additionalTools, False)
  772. self.OnAddPoint(event)
  773. return
  774. Debug.msg(2, "Digittoolbar.OnSnap():")
  775. self.action = { 'desc' : "snapLine",
  776. 'id' : self.additionalTools }
  777. self.parent.MapWindow.mouse['box'] = 'box'
  778. def OnConnect(self, event):
  779. """!Connect selected lines/boundaries"""
  780. if self.action['desc'] == 'connectLine': # select previous action
  781. self.ToggleTool(self.addPoint, True)
  782. self.ToggleTool(self.additionalTools, False)
  783. self.OnAddPoint(event)
  784. return
  785. Debug.msg(2, "Digittoolbar.OnConnect():")
  786. self.action = { 'desc' : "connectLine",
  787. 'id' : self.additionalTools }
  788. self.parent.MapWindow.mouse['box'] = 'box'
  789. def OnQuery(self, event):
  790. """!Query selected lines/boundaries"""
  791. if self.action['desc'] == 'queryLine': # select previous action
  792. self.ToggleTool(self.addPoint, True)
  793. self.ToggleTool(self.additionalTools, False)
  794. self.OnAddPoint(event)
  795. return
  796. Debug.msg(2, "Digittoolbar.OnQuery(): %s" % \
  797. UserSettings.Get(group = 'vdigit', key = 'query', subkey = 'selection'))
  798. self.action = { 'desc' : "queryLine",
  799. 'id' : self.additionalTools }
  800. self.parent.MapWindow.mouse['box'] = 'box'
  801. def OnZBulk(self, event):
  802. """!Z bulk-labeling selected lines/boundaries"""
  803. if not self.digit.IsVector3D():
  804. gcmd.GError(parent = self.parent,
  805. message = _("Vector map is not 3D. Operation canceled."))
  806. return
  807. if self.action['desc'] == 'zbulkLine': # select previous action
  808. self.ToggleTool(self.addPoint, True)
  809. self.ToggleTool(self.additionalTools, False)
  810. self.OnAddPoint(event)
  811. return
  812. Debug.msg(2, "Digittoolbar.OnZBulk():")
  813. self.action = { 'desc' : "zbulkLine",
  814. 'id' : self.additionalTools }
  815. self.parent.MapWindow.mouse['box'] = 'line'
  816. def OnTypeConversion(self, event):
  817. """!Feature type conversion
  818. Supported conversions:
  819. - point <-> centroid
  820. - line <-> boundary
  821. """
  822. if self.action['desc'] == 'typeConv': # select previous action
  823. self.ToggleTool(self.addPoint, True)
  824. self.ToggleTool(self.additionalTools, False)
  825. self.OnAddPoint(event)
  826. return
  827. Debug.msg(2, "Digittoolbar.OnTypeConversion():")
  828. self.action = { 'desc' : "typeConv",
  829. 'id' : self.additionalTools }
  830. self.parent.MapWindow.mouse['box'] = 'box'
  831. def OnSelectMap (self, event):
  832. """!Select vector map layer for editing
  833. If there is a vector map layer already edited, this action is
  834. firstly terminated. The map layer is closed. After this the
  835. selected map layer activated for editing.
  836. """
  837. if event.GetSelection() == 0: # create new vector map layer
  838. if self.mapLayer:
  839. openVectorMap = self.mapLayer.GetName(fullyQualified = False)['name']
  840. else:
  841. openVectorMap = None
  842. dlg = gdialogs.CreateNewVector(self.parent,
  843. exceptMap = openVectorMap, log = self.log,
  844. cmd = (('v.edit',
  845. { 'tool' : 'create' },
  846. 'map')),
  847. disableAdd = True)
  848. if dlg and dlg.GetName():
  849. # add layer to map layer tree
  850. if self.layerTree:
  851. mapName = dlg.GetName() + '@' + grass.gisenv()['MAPSET']
  852. self.layerTree.AddLayer(ltype = 'vector',
  853. lname = mapName,
  854. lcmd = ['d.vect', 'map=%s' % mapName])
  855. vectLayers = self.UpdateListOfLayers(updateTool = True)
  856. selection = vectLayers.index(mapName)
  857. # create table ?
  858. if dlg.IsChecked('table'):
  859. lmgr = self.parent.GetLayerManager()
  860. if lmgr:
  861. lmgr.OnShowAttributeTable(None, selection = 'table')
  862. dlg.Destroy()
  863. else:
  864. self.combo.SetValue(_('Select vector map'))
  865. if dlg:
  866. dlg.Destroy()
  867. return
  868. else:
  869. selection = event.GetSelection() - 1 # first option is 'New vector map'
  870. # skip currently selected map
  871. if self.layers[selection] == self.mapLayer:
  872. return
  873. if self.mapLayer:
  874. # deactive map layer for editing
  875. self.StopEditing()
  876. # select the given map layer for editing
  877. self.StartEditing(self.layers[selection])
  878. event.Skip()
  879. def StartEditing (self, mapLayer):
  880. """!Start editing selected vector map layer.
  881. @param mapLayer MapLayer to be edited
  882. """
  883. # deactive layer
  884. self.mapcontent.ChangeLayerActive(mapLayer, False)
  885. # clean map canvas
  886. self.parent.MapWindow.EraseMap()
  887. # unset background map if needed
  888. if mapLayer:
  889. if UserSettings.Get(group = 'vdigit', key = 'bgmap',
  890. subkey = 'value', internal = True) == mapLayer.GetName():
  891. UserSettings.Set(group = 'vdigit', key = 'bgmap',
  892. subkey = 'value', value = '', internal = True)
  893. self.parent.statusbar.SetStatusText(_("Please wait, "
  894. "opening vector map <%s> for editing...") % mapLayer.GetName(),
  895. 0)
  896. self.parent.MapWindow.pdcVector = wx.PseudoDC()
  897. self.digit = self.parent.MapWindow.digit = VDigit(mapwindow = self.parent.MapWindow)
  898. self.mapLayer = mapLayer
  899. # open vector map
  900. if self.digit.OpenMap(mapLayer.GetName()) is None:
  901. self.mapLayer = None
  902. self.StopEditing()
  903. return False
  904. # update toolbar
  905. self.combo.SetValue(mapLayer.GetName())
  906. self.parent.toolbars['map'].combo.SetValue (_('Digitize'))
  907. lmgr = self.parent.GetLayerManager()
  908. if lmgr:
  909. lmgr.toolbars['tools'].Enable('vdigit', enable = False)
  910. Debug.msg (4, "VDigitToolbar.StartEditing(): layer=%s" % mapLayer.GetName())
  911. # change cursor
  912. if self.parent.MapWindow.mouse['use'] == 'pointer':
  913. self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
  914. if not self.parent.MapWindow.resize:
  915. self.parent.MapWindow.UpdateMap(render = True)
  916. # respect opacity
  917. opacity = mapLayer.GetOpacity(float = True)
  918. if opacity < 1.0:
  919. alpha = int(opacity * 255)
  920. self.digit.GetDisplay().UpdateSettings(alpha = 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. )