toolbars.py 67 KB

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