toolbars.py 67 KB

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