toolbars.py 66 KB

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