toolbars.py 64 KB

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