toolbars.py 65 KB

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