toolbars.py 67 KB

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