toolbars.py 66 KB

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