toolbars.py 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362
  1. """!
  2. @package toolbar
  3. @brief wxGUI toolbar widgets
  4. Classes:
  5. - AbstractToolbar
  6. - MapToolbar
  7. - GRToolbar
  8. - GCPToolbar
  9. - VDigitToolbar
  10. - ProfileToolbar
  11. - NvizToolbar
  12. (C) 2007-2010 by the GRASS Development Team
  13. This program is free software under the GNU General Public License
  14. (>=v2). Read the file COPYING that comes with GRASS for details.
  15. @author Michael Barton
  16. @author Jachym Cepicky
  17. @author Martin Landa <landa.martin gmail.com>
  18. """
  19. import os
  20. import sys
  21. import platform
  22. from grass.script import core as grass
  23. import wx
  24. import globalvar
  25. import gcmd
  26. import gdialogs
  27. import vdigit
  28. from vdigit import VDigitSettingsDialog as VDigitSettingsDialog
  29. from debug import Debug as Debug
  30. from icon import Icons as Icons
  31. from preferences import globalSettings as UserSettings
  32. gmpath = os.path.join(globalvar.ETCWXDIR, "icons")
  33. sys.path.append(gmpath)
  34. class AbstractToolbar(wx.ToolBar):
  35. """!Abstract toolbar class"""
  36. def __init__(self, parent):
  37. self.parent = parent
  38. wx.ToolBar.__init__(self, parent = self.parent, id = wx.ID_ANY)
  39. self.Bind(wx.EVT_TOOL, self.OnTool)
  40. self.SetToolBitmapSize(globalvar.toolbarSize)
  41. def InitToolbar(self, toolData):
  42. """!Initialize toolbar, add tools to the toolbar
  43. """
  44. for tool in toolData:
  45. self.CreateTool(*tool)
  46. self._data = toolData
  47. def ToolbarData(self):
  48. """!Toolbar data (virtual)"""
  49. return None
  50. def CreateTool(self, tool, label, bitmap, kind,
  51. shortHelp, longHelp, handler):
  52. """!Add tool to the toolbar
  53. @return id of tool
  54. """
  55. bmpDisabled=wx.NullBitmap
  56. if label:
  57. Debug.msg(3, "CreateTool(): tool=%d, label=%s bitmap=%s" % \
  58. (tool, label, bitmap))
  59. toolWin = self.AddLabelTool(tool, label, bitmap,
  60. bmpDisabled, kind,
  61. shortHelp, longHelp)
  62. self.Bind(wx.EVT_TOOL, handler, toolWin)
  63. else: # separator
  64. self.AddSeparator()
  65. return tool
  66. def EnableLongHelp(self, enable=True):
  67. """!Enable/disable long help
  68. @param enable True for enable otherwise disable
  69. """
  70. for tool in self._data:
  71. if tool[0] == '': # separator
  72. continue
  73. if enable:
  74. self.SetToolLongHelp(tool[0], tool[5])
  75. else:
  76. self.SetToolLongHelp(tool[0], "")
  77. def OnTool(self, event):
  78. """!Tool selected"""
  79. if self.parent.toolbars['vdigit']:
  80. # update vdigit toolbar (unselect currently selected tool)
  81. id = self.parent.toolbars['vdigit'].GetAction(type='id')
  82. self.parent.toolbars['vdigit'].ToggleTool(id, False)
  83. if event:
  84. # deselect previously selected tool
  85. id = self.action.get('id', -1)
  86. if id != event.GetId():
  87. self.ToggleTool(self.action['id'], False)
  88. else:
  89. self.ToggleTool(self.action['id'], True)
  90. self.action['id'] = event.GetId()
  91. event.Skip()
  92. else:
  93. # initialize toolbar
  94. self.ToggleTool(self.action['id'], True)
  95. def GetAction(self, type='desc'):
  96. """!Get current action info"""
  97. return self.action.get(type, '')
  98. def SelectDefault(self, event):
  99. """!Select default tool"""
  100. self.ToggleTool(self.defaultAction['id'], True)
  101. self.defaultAction['bind'](event)
  102. self.action = { 'id' : self.defaultAction['id'],
  103. 'desc' : self.defaultAction.get('desc', '') }
  104. def FixSize(self, width):
  105. """!Fix toolbar width on Windows
  106. @todo Determine why combobox causes problems here
  107. """
  108. if platform.system() == 'Windows':
  109. size = self.GetBestSize()
  110. self.SetSize((size[0] + width, size[1]))
  111. class MapToolbar(AbstractToolbar):
  112. """!Map Display toolbar
  113. """
  114. def __init__(self, parent, mapcontent):
  115. """!Map Display constructor
  116. @param parent reference to MapFrame
  117. @param mapcontent reference to render.Map (registred by MapFrame)
  118. """
  119. self.mapcontent = mapcontent # render.Map
  120. AbstractToolbar.__init__(self, parent = parent) # MapFrame
  121. self.InitToolbar(self.ToolbarData())
  122. # optional tools
  123. self.combo = wx.ComboBox(parent=self, id=wx.ID_ANY, value=_('2D view'),
  124. choices=[_('2D view'), _('3D view'), _('Digitize')],
  125. style=wx.CB_READONLY, size=(90, -1))
  126. self.comboid = self.AddControl(self.combo)
  127. self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectTool, self.comboid)
  128. # realize the toolbar
  129. self.Realize()
  130. # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
  131. self.combo.Hide()
  132. self.combo.Show()
  133. # default action
  134. self.action = { 'id' : self.pointer }
  135. self.defaultAction = { 'id' : self.pointer,
  136. 'bind' : self.parent.OnPointer }
  137. self.OnTool(None)
  138. self.EnableTool(self.zoomback, False)
  139. self.FixSize(width = 90)
  140. def ToolbarData(self):
  141. """!Toolbar data"""
  142. self.displaymap = wx.NewId()
  143. self.rendermap = wx.NewId()
  144. self.erase = wx.NewId()
  145. self.pointer = wx.NewId()
  146. self.query = wx.NewId()
  147. self.pan = wx.NewId()
  148. self.zoomin = wx.NewId()
  149. self.zoomout = wx.NewId()
  150. self.zoomback = wx.NewId()
  151. self.zoommenu = wx.NewId()
  152. self.analyze = wx.NewId()
  153. self.dec = wx.NewId()
  154. self.savefile = wx.NewId()
  155. self.printmap = wx.NewId()
  156. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  157. return (
  158. (self.displaymap, "displaymap", Icons["displaymap"].GetBitmap(),
  159. wx.ITEM_NORMAL, Icons["displaymap"].GetLabel(), Icons["displaymap"].GetDesc(),
  160. self.parent.OnDraw),
  161. (self.rendermap, "rendermap", Icons["rendermap"].GetBitmap(),
  162. wx.ITEM_NORMAL, Icons["rendermap"].GetLabel(), Icons["rendermap"].GetDesc(),
  163. self.parent.OnRender),
  164. (self.erase, "erase", Icons["erase"].GetBitmap(),
  165. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  166. self.parent.OnErase),
  167. ("", "", "", "", "", "", ""),
  168. (self.pointer, "pointer", Icons["pointer"].GetBitmap(),
  169. wx.ITEM_CHECK, Icons["pointer"].GetLabel(), Icons["pointer"].GetDesc(),
  170. self.parent.OnPointer),
  171. (self.query, "query", Icons["query"].GetBitmap(),
  172. wx.ITEM_CHECK, Icons["query"].GetLabel(), Icons["query"].GetDesc(),
  173. self.parent.OnQuery),
  174. (self.pan, "pan", Icons["pan"].GetBitmap(),
  175. wx.ITEM_CHECK, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  176. self.parent.OnPan),
  177. (self.zoomin, "zoom_in", Icons["zoom_in"].GetBitmap(),
  178. wx.ITEM_CHECK, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  179. self.parent.OnZoomIn),
  180. (self.zoomout, "zoom_out", Icons["zoom_out"].GetBitmap(),
  181. wx.ITEM_CHECK, Icons["zoom_out"].GetLabel(), Icons["zoom_out"].GetDesc(),
  182. self.parent.OnZoomOut),
  183. (self.zoomback, "zoom_back", Icons["zoom_back"].GetBitmap(),
  184. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  185. self.parent.OnZoomBack),
  186. (self.zoommenu, "zoommenu", Icons["zoommenu"].GetBitmap(),
  187. wx.ITEM_NORMAL, Icons["zoommenu"].GetLabel(), Icons["zoommenu"].GetDesc(),
  188. self.parent.OnZoomMenu),
  189. ("", "", "", "", "", "", ""),
  190. (self.analyze, "analyze", Icons["analyze"].GetBitmap(),
  191. wx.ITEM_NORMAL, Icons["analyze"].GetLabel(), Icons["analyze"].GetDesc(),
  192. self.parent.OnAnalyze),
  193. ("", "", "", "", "", "", ""),
  194. (self.dec, "overlay", Icons["overlay"].GetBitmap(),
  195. wx.ITEM_NORMAL, Icons["overlay"].GetLabel(), Icons["overlay"].GetDesc(),
  196. self.parent.OnDecoration),
  197. ("", "", "", "", "", "", ""),
  198. (self.savefile, "savefile", Icons["savefile"].GetBitmap(),
  199. wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
  200. self.parent.SaveToFile),
  201. (self.printmap, "printmap", Icons["printmap"].GetBitmap(),
  202. wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
  203. self.parent.PrintMenu),
  204. ("", "", "", "", "", "", "")
  205. )
  206. def OnSelectTool(self, event):
  207. """!
  208. Select / enable tool available in tools list
  209. """
  210. tool = event.GetSelection()
  211. if tool == 0:
  212. self.ExitToolbars()
  213. self.Enable2D(True)
  214. elif tool == 1 and not self.parent.toolbars['nviz']:
  215. self.ExitToolbars()
  216. self.parent.AddToolbar("nviz")
  217. elif tool == 2 and not self.parent.toolbars['vdigit']:
  218. self.ExitToolbars()
  219. self.parent.AddToolbar("vdigit")
  220. self.parent.MapWindow.SetFocus()
  221. def ExitToolbars(self):
  222. if self.parent.toolbars['vdigit']:
  223. self.parent.toolbars['vdigit'].OnExit()
  224. if self.parent.toolbars['nviz']:
  225. self.parent.toolbars['nviz'].OnExit()
  226. def Enable2D(self, enabled):
  227. """!Enable/Disable 2D display mode specific tools"""
  228. for tool in (self.pointer,
  229. self.query,
  230. self.pan,
  231. self.zoomin,
  232. self.zoomout,
  233. self.zoomback,
  234. self.zoommenu,
  235. self.analyze,
  236. self.dec,
  237. self.savefile,
  238. self.printmap):
  239. self.EnableTool(tool, enabled)
  240. def Enable(self, tool, enable = True):
  241. """!Enable defined tool
  242. @param tool name
  243. @param enable True to enable otherwise disable tool
  244. """
  245. try:
  246. id = getattr(self, tool)
  247. except AttributeError:
  248. return
  249. self.EnableTool(self.zoomback, enable)
  250. class GRToolbar(AbstractToolbar):
  251. """
  252. Georectification toolbar
  253. """
  254. def __init__(self, parent, mapcontent):
  255. """!
  256. Georectification toolbar constructor
  257. @param parent reference to MapFrame
  258. @param mapcontent reference to render.Map (registred by MapFrame)
  259. """
  260. self.mapcontent = map
  261. AbstractToolbar.__init__(self, parent)
  262. self.InitToolbar(self.ToolbarData())
  263. # realize the toolbar
  264. self.Realize()
  265. def ToolbarData(self):
  266. """!Toolbar data"""
  267. self.displaymap = wx.NewId()
  268. self.rendermap = wx.NewId()
  269. self.erase = wx.NewId()
  270. self.gcpset = wx.NewId()
  271. self.pan = wx.NewId()
  272. self.zoomin = wx.NewId()
  273. self.zoomout = wx.NewId()
  274. self.zoomback = wx.NewId()
  275. self.zoomtomap = wx.NewId()
  276. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  277. return (
  278. (self.displaymap, "displaymap", Icons["displaymap"].GetBitmap(),
  279. wx.ITEM_NORMAL, Icons["displaymap"].GetLabel(), Icons["displaymap"].GetDesc(),
  280. self.parent.OnDraw),
  281. (self.rendermap, "rendermap", Icons["rendermap"].GetBitmap(),
  282. wx.ITEM_NORMAL, Icons["rendermap"].GetLabel(), Icons["rendermap"].GetDesc(),
  283. self.parent.OnRender),
  284. (self.erase, "erase", Icons["erase"].GetBitmap(),
  285. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  286. self.parent.OnErase),
  287. ("", "", "", "", "", "", ""),
  288. (self.gcpset, "grGcpSet", Icons["grGcpSet"].GetBitmap(),
  289. wx.ITEM_RADIO, Icons["grGcpSet"].GetLabel(), Icons["grGcpSet"].GetDesc(),
  290. self.parent.OnPointer),
  291. (self.pan, "pan", Icons["pan"].GetBitmap(),
  292. wx.ITEM_RADIO, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  293. self.parent.OnPan),
  294. (self.zoomin, "zoom_in", Icons["zoom_in"].GetBitmap(),
  295. wx.ITEM_RADIO, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  296. self.parent.OnZoomIn),
  297. (self.zoomout, "zoom_out", Icons["zoom_out"].GetBitmap(),
  298. wx.ITEM_RADIO, Icons["zoom_out"].GetLabel(), Icons["zoom_out"].GetDesc(),
  299. self.parent.OnZoomOut),
  300. (self.zoomback, "zoom_back", Icons["zoom_back"].GetBitmap(),
  301. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  302. self.parent.OnZoomBack),
  303. (self.zoomtomap, "zoomtomap", Icons["zoommenu"].GetBitmap(),
  304. wx.ITEM_NORMAL, _("Zoom to map"), _("Zoom to displayed map"),
  305. self.OnZoomMap),
  306. ("", "", "", "", "", "", ""),
  307. )
  308. def OnZoomMap(self, event):
  309. """!Zoom to selected map"""
  310. self.parent.MapWindow.ZoomToMap(layers = self.mapcontent.GetListOfLayers())
  311. event.Skip()
  312. class GCPToolbar(AbstractToolbar):
  313. """!
  314. Toolbar for managing ground control points during georectification
  315. @param parent reference to GCP widget
  316. """
  317. def __init__(self, parent):
  318. AbstractToolbar.__init__(self, parent)
  319. self.InitToolbar(self.ToolbarData())
  320. # realize the toolbar
  321. self.Realize()
  322. def ToolbarData(self):
  323. self.gcpSave = wx.NewId()
  324. self.gcpAdd = wx.NewId()
  325. self.gcpDelete = wx.NewId()
  326. self.gcpClear = wx.NewId()
  327. self.gcpReload = wx.NewId()
  328. self.rms = wx.NewId()
  329. self.georect = wx.NewId()
  330. self.settings = wx.NewId()
  331. self.quit = wx.NewId()
  332. return (
  333. (self.gcpSave, 'grGcpSave', Icons["grGcpSave"].GetBitmap(),
  334. wx.ITEM_NORMAL, Icons["grGcpSave"].GetLabel(), Icons["grGcpSave"].GetDesc(),
  335. self.parent.SaveGCPs),
  336. (self.gcpAdd, 'grGrGcpAdd', Icons["grGcpAdd"].GetBitmap(),
  337. wx.ITEM_NORMAL, Icons["grGcpAdd"].GetLabel(), Icons["grGcpAdd"].GetDesc(),
  338. self.parent.AddGCP),
  339. (self.gcpDelete, 'grGrGcpDelete', Icons["grGcpDelete"].GetBitmap(),
  340. wx.ITEM_NORMAL, Icons["grGcpDelete"].GetLabel(), Icons["grGcpDelete"].GetDesc(),
  341. self.parent.DeleteGCP),
  342. (self.gcpClear, 'grGcpClear', Icons["grGcpClear"].GetBitmap(),
  343. wx.ITEM_NORMAL, Icons["grGcpClear"].GetLabel(), Icons["grGcpClear"].GetDesc(),
  344. self.parent.ClearGCP),
  345. (self.gcpReload, 'grGcpReload', Icons["grGcpReload"].GetBitmap(),
  346. wx.ITEM_NORMAL, Icons["grGcpReload"].GetLabel(), Icons["grGcpReload"].GetDesc(),
  347. self.parent.ReloadGCPs),
  348. ("", "", "", "", "", "", ""),
  349. (self.rms, 'grGcpRms', Icons["grGcpRms"].GetBitmap(),
  350. wx.ITEM_NORMAL, Icons["grGcpRms"].GetLabel(), Icons["grGcpRms"].GetDesc(),
  351. self.parent.OnRMS),
  352. (self.georect, 'grGeorect', Icons["grGeorect"].GetBitmap(),
  353. wx.ITEM_NORMAL, Icons["grGeorect"].GetLabel(), Icons["grGeorect"].GetDesc(),
  354. self.parent.OnGeorect),
  355. ("", "", "", "", "", "", ""),
  356. (self.settings, 'grSettings', Icons["grSettings"].GetBitmap(),
  357. wx.ITEM_NORMAL, Icons["grSettings"].GetLabel(), Icons["grSettings"].GetDesc(),
  358. self.parent.OnSettings),
  359. (self.quit, 'grGcpQuit', Icons["grGcpQuit"].GetBitmap(),
  360. wx.ITEM_NORMAL, Icons["grGcpQuit"].GetLabel(), Icons["grGcpQuit"].GetDesc(),
  361. self.parent.OnQuit)
  362. )
  363. class VDigitToolbar(AbstractToolbar):
  364. """
  365. Toolbar for digitization
  366. """
  367. def __init__(self, parent, mapcontent, layerTree=None, log=None):
  368. self.mapcontent = mapcontent # Map class instance
  369. self.layerTree = layerTree # reference to layer tree associated to map display
  370. self.log = log # log area
  371. AbstractToolbar.__init__(self, parent)
  372. # currently selected map layer for editing (reference to MapLayer instance)
  373. self.mapLayer = None
  374. # list of vector layers from Layer Manager (only in the current mapset)
  375. self.layers = []
  376. self.comboid = None
  377. # only one dialog can be open
  378. self.settingsDialog = None
  379. # create toolbars (two rows optionally)
  380. self.InitToolbar(self.ToolbarData())
  381. self.Bind(wx.EVT_TOOL, self.OnTool)
  382. # default action (digitize new point, line, etc.)
  383. self.action = { 'desc' : 'addLine',
  384. 'type' : 'point',
  385. 'id' : self.addPoint }
  386. # list of available vector maps
  387. self.UpdateListOfLayers(updateTool=True)
  388. # realize toolbar
  389. self.Realize()
  390. # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
  391. self.combo.Hide()
  392. self.combo.Show()
  393. # disable undo/redo
  394. self.EnableTool(self.undo, False)
  395. # toogle to pointer by default
  396. self.OnTool(None)
  397. self.FixSize(width = 105)
  398. def ToolbarData(self):
  399. """!
  400. Toolbar data
  401. """
  402. data = []
  403. self.addPoint = wx.NewId()
  404. self.addLine = wx.NewId()
  405. self.addBoundary = wx.NewId()
  406. self.addCentroid = wx.NewId()
  407. self.moveVertex = wx.NewId()
  408. self.addVertex = wx.NewId()
  409. self.removeVertex = wx.NewId()
  410. self.splitLine = wx.NewId()
  411. self.editLine = wx.NewId()
  412. self.moveLine = wx.NewId()
  413. self.deleteLine = wx.NewId()
  414. self.additionalTools = wx.NewId()
  415. self.displayCats = wx.NewId()
  416. self.displayAttr = wx.NewId()
  417. self.copyCats = wx.NewId()
  418. self.undo = wx.NewId()
  419. self.settings = wx.NewId()
  420. self.exit = wx.NewId()
  421. data = [("", "", "", "", "", "", ""),
  422. (self.addPoint, "digAddPoint", Icons["digAddPoint"].GetBitmap(),
  423. wx.ITEM_CHECK, Icons["digAddPoint"].GetLabel(), Icons["digAddPoint"].GetDesc(),
  424. self.OnAddPoint),
  425. (self.addLine, "digAddLine", Icons["digAddLine"].GetBitmap(),
  426. wx.ITEM_CHECK, Icons["digAddLine"].GetLabel(), Icons["digAddLine"].GetDesc(),
  427. self.OnAddLine),
  428. (self.addBoundary, "digAddBoundary", Icons["digAddBoundary"].GetBitmap(),
  429. wx.ITEM_CHECK, Icons["digAddBoundary"].GetLabel(), Icons["digAddBoundary"].GetDesc(),
  430. self.OnAddBoundary),
  431. (self.addCentroid, "digAddCentroid", Icons["digAddCentroid"].GetBitmap(),
  432. wx.ITEM_CHECK, Icons["digAddCentroid"].GetLabel(), Icons["digAddCentroid"].GetDesc(),
  433. self.OnAddCentroid),
  434. (self.moveVertex, "digMoveVertex", Icons["digMoveVertex"].GetBitmap(),
  435. wx.ITEM_CHECK, Icons["digMoveVertex"].GetLabel(), Icons["digMoveVertex"].GetDesc(),
  436. self.OnMoveVertex),
  437. (self.addVertex, "digAddVertex", Icons["digAddVertex"].GetBitmap(),
  438. wx.ITEM_CHECK, Icons["digAddVertex"].GetLabel(), Icons["digAddVertex"].GetDesc(),
  439. self.OnAddVertex),
  440. (self.removeVertex, "digRemoveVertex", Icons["digRemoveVertex"].GetBitmap(),
  441. wx.ITEM_CHECK, Icons["digRemoveVertex"].GetLabel(), Icons["digRemoveVertex"].GetDesc(),
  442. self.OnRemoveVertex),
  443. (self.splitLine, "digSplitLine", Icons["digSplitLine"].GetBitmap(),
  444. wx.ITEM_CHECK, Icons["digSplitLine"].GetLabel(), Icons["digSplitLine"].GetDesc(),
  445. self.OnSplitLine),
  446. (self.editLine, "digEditLine", Icons["digEditLine"].GetBitmap(),
  447. wx.ITEM_CHECK, Icons["digEditLine"].GetLabel(), Icons["digEditLine"].GetDesc(),
  448. self.OnEditLine),
  449. (self.moveLine, "digMoveLine", Icons["digMoveLine"].GetBitmap(),
  450. wx.ITEM_CHECK, Icons["digMoveLine"].GetLabel(), Icons["digMoveLine"].GetDesc(),
  451. self.OnMoveLine),
  452. (self.deleteLine, "digDeleteLine", Icons["digDeleteLine"].GetBitmap(),
  453. wx.ITEM_CHECK, Icons["digDeleteLine"].GetLabel(), Icons["digDeleteLine"].GetDesc(),
  454. self.OnDeleteLine),
  455. (self.displayCats, "digDispCats", Icons["digDispCats"].GetBitmap(),
  456. wx.ITEM_CHECK, Icons["digDispCats"].GetLabel(), Icons["digDispCats"].GetDesc(),
  457. self.OnDisplayCats),
  458. (self.copyCats, "digCopyCats", Icons["digCopyCats"].GetBitmap(),
  459. wx.ITEM_CHECK, Icons["digCopyCats"].GetLabel(), Icons["digCopyCats"].GetDesc(),
  460. self.OnCopyCA),
  461. (self.displayAttr, "digDispAttr", Icons["digDispAttr"].GetBitmap(),
  462. wx.ITEM_CHECK, Icons["digDispAttr"].GetLabel(), Icons["digDispAttr"].GetDesc(),
  463. self.OnDisplayAttr),
  464. (self.additionalTools, "digAdditionalTools", Icons["digAdditionalTools"].GetBitmap(),
  465. wx.ITEM_CHECK, Icons["digAdditionalTools"].GetLabel(),
  466. Icons["digAdditionalTools"].GetDesc(),
  467. self.OnAdditionalToolMenu),
  468. ("", "", "", "", "", "", ""),
  469. (self.undo, "digUndo", Icons["digUndo"].GetBitmap(),
  470. wx.ITEM_NORMAL, Icons["digUndo"].GetLabel(), Icons["digUndo"].GetDesc(),
  471. self.OnUndo),
  472. # data.append((self.undo, "digRedo", Icons["digRedo"].GetBitmap(),
  473. # wx.ITEM_NORMAL, Icons["digRedo"].GetLabel(), Icons["digRedo"].GetDesc(),
  474. # self.OnRedo))
  475. (self.settings, "digSettings", Icons["digSettings"].GetBitmap(),
  476. wx.ITEM_NORMAL, Icons["digSettings"].GetLabel(), Icons["digSettings"].GetDesc(),
  477. self.OnSettings),
  478. (self.exit, "digExit", Icons["quit"].GetBitmap(),
  479. wx.ITEM_NORMAL, Icons["digExit"].GetLabel(), Icons["digExit"].GetDesc(),
  480. self.OnExit)]
  481. return data
  482. def OnTool(self, event):
  483. """!Tool selected -> disable selected tool in map toolbar"""
  484. id = self.parent.toolbars['map'].GetAction(type='id')
  485. self.parent.toolbars['map'].ToggleTool(id, False)
  486. # set cursor
  487. cursor = self.parent.cursors["cross"]
  488. self.parent.MapWindow.SetCursor(cursor)
  489. # pointer
  490. self.parent.OnPointer(None)
  491. if event:
  492. # deselect previously selected tool
  493. id = self.action.get('id', -1)
  494. if id != event.GetId():
  495. self.ToggleTool(self.action['id'], False)
  496. else:
  497. self.ToggleTool(self.action['id'], True)
  498. self.action['id'] = event.GetId()
  499. event.Skip()
  500. self.ToggleTool(self.action['id'], True)
  501. # clear tmp canvas
  502. if self.action['id'] != id:
  503. self.parent.MapWindow.ClearLines(pdc=self.parent.MapWindow.pdcTmp)
  504. if self.parent.digit and \
  505. len(self.parent.digit.driver.GetSelected()) > 0:
  506. # cancel action
  507. self.parent.MapWindow.OnMiddleDown(None)
  508. # set focus
  509. self.parent.MapWindow.SetFocus()
  510. def OnAddPoint(self, event):
  511. """!Add point to the vector map Laier"""
  512. Debug.msg (2, "VDigitToolbar.OnAddPoint()")
  513. self.action = { 'desc' : "addLine",
  514. 'type' : "point",
  515. 'id' : self.addPoint }
  516. self.parent.MapWindow.mouse['box'] = 'point'
  517. def OnAddLine(self, event):
  518. """!Add line to the vector map layer"""
  519. Debug.msg (2, "VDigitToolbar.OnAddLine()")
  520. self.action = { 'desc' : "addLine",
  521. 'type' : "line",
  522. 'id' : self.addLine }
  523. self.parent.MapWindow.mouse['box'] = 'line'
  524. ### self.parent.MapWindow.polycoords = [] # reset temp line
  525. def OnAddBoundary(self, event):
  526. """!Add boundary to the vector map layer"""
  527. Debug.msg (2, "VDigitToolbar.OnAddBoundary()")
  528. if self.action['desc'] != 'addLine' or \
  529. self.action['type'] != 'boundary':
  530. self.parent.MapWindow.polycoords = [] # reset temp line
  531. self.action = { 'desc' : "addLine",
  532. 'type' : "boundary",
  533. 'id' : self.addBoundary }
  534. self.parent.MapWindow.mouse['box'] = 'line'
  535. def OnAddCentroid(self, event):
  536. """!Add centroid to the vector map layer"""
  537. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  538. self.action = { 'desc' : "addLine",
  539. 'type' : "centroid",
  540. 'id' : self.addCentroid }
  541. self.parent.MapWindow.mouse['box'] = 'point'
  542. def OnExit (self, event=None):
  543. """!Quit digitization tool"""
  544. # stop editing of the currently selected map layer
  545. if self.mapLayer:
  546. self.StopEditing()
  547. # close dialogs if still open
  548. if self.settingsDialog:
  549. self.settingsDialog.OnCancel(None)
  550. # set default mouse settings
  551. self.parent.MapWindow.mouse['use'] = "pointer"
  552. self.parent.MapWindow.mouse['box'] = "point"
  553. self.parent.MapWindow.polycoords = []
  554. # disable the toolbar
  555. self.parent.RemoveToolbar("vdigit")
  556. def OnMoveVertex(self, event):
  557. """!Move line vertex"""
  558. Debug.msg(2, "Digittoolbar.OnMoveVertex():")
  559. self.action = { 'desc' : "moveVertex",
  560. 'id' : self.moveVertex }
  561. self.parent.MapWindow.mouse['box'] = 'point'
  562. def OnAddVertex(self, event):
  563. """!Add line vertex"""
  564. Debug.msg(2, "Digittoolbar.OnAddVertex():")
  565. self.action = { 'desc' : "addVertex",
  566. 'id' : self.addVertex }
  567. self.parent.MapWindow.mouse['box'] = 'point'
  568. def OnRemoveVertex(self, event):
  569. """!Remove line vertex"""
  570. Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
  571. self.action = { 'desc' : "removeVertex",
  572. 'id' : self.removeVertex }
  573. self.parent.MapWindow.mouse['box'] = 'point'
  574. def OnSplitLine(self, event):
  575. """!Split line"""
  576. Debug.msg(2, "Digittoolbar.OnSplitLine():")
  577. self.action = { 'desc' : "splitLine",
  578. 'id' : self.splitLine }
  579. self.parent.MapWindow.mouse['box'] = 'point'
  580. def OnEditLine(self, event):
  581. """!Edit line"""
  582. Debug.msg(2, "Digittoolbar.OnEditLine():")
  583. self.action = { 'desc' : "editLine",
  584. 'id' : self.editLine }
  585. self.parent.MapWindow.mouse['box'] = 'line'
  586. def OnMoveLine(self, event):
  587. """!Move line"""
  588. Debug.msg(2, "Digittoolbar.OnMoveLine():")
  589. self.action = { 'desc' : "moveLine",
  590. 'id' : self.moveLine }
  591. self.parent.MapWindow.mouse['box'] = 'box'
  592. def OnDeleteLine(self, event):
  593. """!Delete line"""
  594. Debug.msg(2, "Digittoolbar.OnDeleteLine():")
  595. self.action = { 'desc' : "deleteLine",
  596. 'id' : self.deleteLine }
  597. self.parent.MapWindow.mouse['box'] = 'box'
  598. def OnDisplayCats(self, event):
  599. """!Display/update categories"""
  600. Debug.msg(2, "Digittoolbar.OnDisplayCats():")
  601. self.action = { 'desc' : "displayCats",
  602. 'id' : self.displayCats }
  603. self.parent.MapWindow.mouse['box'] = 'point'
  604. def OnDisplayAttr(self, event):
  605. """!Display/update attributes"""
  606. Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
  607. self.action = { 'desc' : "displayAttrs",
  608. 'id' : self.displayAttr }
  609. self.parent.MapWindow.mouse['box'] = 'point'
  610. def OnCopyCA(self, event):
  611. """!Copy categories/attributes menu"""
  612. point = wx.GetMousePosition()
  613. toolMenu = wx.Menu()
  614. # Add items to the menu
  615. cats = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  616. text=_('Copy categories'),
  617. kind=wx.ITEM_CHECK)
  618. toolMenu.AppendItem(cats)
  619. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyCats, cats)
  620. if self.action['desc'] == "copyCats":
  621. cats.Check(True)
  622. attrb = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  623. text=_('Duplicate attributes'),
  624. kind=wx.ITEM_CHECK)
  625. toolMenu.AppendItem(attrb)
  626. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyAttrb, attrb)
  627. if self.action['desc'] == "copyAttrs":
  628. attrb.Check(True)
  629. # Popup the menu. If an item is selected then its handler
  630. # will be called before PopupMenu returns.
  631. self.parent.MapWindow.PopupMenu(toolMenu)
  632. toolMenu.Destroy()
  633. if self.action['desc'] == "addPoint":
  634. self.ToggleTool(self.copyCats, False)
  635. def OnCopyCats(self, event):
  636. """!Copy categories"""
  637. if self.action['desc'] == 'copyCats': # select previous action
  638. self.ToggleTool(self.addPoint, True)
  639. self.ToggleTool(self.copyCats, False)
  640. self.OnAddPoint(event)
  641. return
  642. Debug.msg(2, "Digittoolbar.OnCopyCats():")
  643. self.action = { 'desc' : "copyCats",
  644. 'id' : self.copyCats }
  645. self.parent.MapWindow.mouse['box'] = 'point'
  646. def OnCopyAttrb(self, event):
  647. if self.action['desc'] == 'copyAttrs': # select previous action
  648. self.ToggleTool(self.addPoint, True)
  649. self.ToggleTool(self.copyCats, False)
  650. self.OnAddPoint(event)
  651. return
  652. Debug.msg(2, "Digittoolbar.OnCopyAttrb():")
  653. self.action = { 'desc' : "copyAttrs",
  654. 'id' : self.copyCats }
  655. self.parent.MapWindow.mouse['box'] = 'point'
  656. def OnUndo(self, event):
  657. """!Undo previous changes"""
  658. self.parent.digit.Undo()
  659. event.Skip()
  660. def EnableUndo(self, enable=True):
  661. """!Enable 'Undo' in toolbar
  662. @param enable False for disable
  663. """
  664. if enable:
  665. if self.GetToolEnabled(self.undo) is False:
  666. self.EnableTool(self.undo, True)
  667. else:
  668. if self.GetToolEnabled(self.undo) is True:
  669. self.EnableTool(self.undo, False)
  670. def OnSettings(self, event):
  671. """!Show settings dialog"""
  672. if self.parent.digit is None:
  673. reload(vdigit)
  674. from vdigit import VDigit as VDigit
  675. try:
  676. self.parent.digit = VDigit(mapwindow=self.parent.MapWindow)
  677. except SystemExit:
  678. self.parent.digit = None
  679. if not self.settingsDialog:
  680. self.settingsDialog = VDigitSettingsDialog(parent=self.parent, title=_("Digitization settings"),
  681. style=wx.DEFAULT_DIALOG_STYLE)
  682. self.settingsDialog.Show()
  683. def OnAdditionalToolMenu(self, event):
  684. """!Menu for additional tools"""
  685. point = wx.GetMousePosition()
  686. toolMenu = wx.Menu()
  687. # Add items to the menu
  688. copy = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  689. text=_('Copy features from (background) vector map'),
  690. kind=wx.ITEM_CHECK)
  691. toolMenu.AppendItem(copy)
  692. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopy, copy)
  693. if self.action['desc'] == "copyLine":
  694. copy.Check(True)
  695. flip = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  696. text=_('Flip selected lines/boundaries'),
  697. kind=wx.ITEM_CHECK)
  698. toolMenu.AppendItem(flip)
  699. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnFlip, flip)
  700. if self.action['desc'] == "flipLine":
  701. flip.Check(True)
  702. merge = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  703. text=_('Merge selected lines/boundaries'),
  704. kind=wx.ITEM_CHECK)
  705. toolMenu.AppendItem(merge)
  706. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnMerge, merge)
  707. if self.action['desc'] == "mergeLine":
  708. merge.Check(True)
  709. breakL = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  710. text=_('Break selected lines/boundaries at intersection'),
  711. kind=wx.ITEM_CHECK)
  712. toolMenu.AppendItem(breakL)
  713. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnBreak, breakL)
  714. if self.action['desc'] == "breakLine":
  715. breakL.Check(True)
  716. snap = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  717. text=_('Snap selected lines/boundaries (only to nodes)'),
  718. kind=wx.ITEM_CHECK)
  719. toolMenu.AppendItem(snap)
  720. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnSnap, snap)
  721. if self.action['desc'] == "snapLine":
  722. snap.Check(True)
  723. connect = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  724. text=_('Connect selected lines/boundaries'),
  725. kind=wx.ITEM_CHECK)
  726. toolMenu.AppendItem(connect)
  727. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnConnect, connect)
  728. if self.action['desc'] == "connectLine":
  729. connect.Check(True)
  730. query = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  731. text=_('Query features'),
  732. kind=wx.ITEM_CHECK)
  733. toolMenu.AppendItem(query)
  734. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnQuery, query)
  735. if self.action['desc'] == "queryLine":
  736. query.Check(True)
  737. zbulk = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  738. text=_('Z bulk-labeling of 3D lines'),
  739. kind=wx.ITEM_CHECK)
  740. toolMenu.AppendItem(zbulk)
  741. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnZBulk, zbulk)
  742. if self.action['desc'] == "zbulkLine":
  743. zbulk.Check(True)
  744. typeconv = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  745. text=_('Feature type conversion'),
  746. kind=wx.ITEM_CHECK)
  747. toolMenu.AppendItem(typeconv)
  748. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnTypeConversion, typeconv)
  749. if self.action['desc'] == "typeConv":
  750. typeconv.Check(True)
  751. # Popup the menu. If an item is selected then its handler
  752. # will be called before PopupMenu returns.
  753. self.parent.MapWindow.PopupMenu(toolMenu)
  754. toolMenu.Destroy()
  755. if self.action['desc'] == 'addPoint':
  756. self.ToggleTool(self.additionalTools, False)
  757. def OnCopy(self, event):
  758. """!Copy selected features from (background) vector map"""
  759. if self.action['desc'] == 'copyLine': # select previous action
  760. self.ToggleTool(self.addPoint, True)
  761. self.ToggleTool(self.additionalTools, False)
  762. self.OnAddPoint(event)
  763. return
  764. Debug.msg(2, "Digittoolbar.OnCopy():")
  765. self.action = { 'desc' : "copyLine",
  766. 'id' : self.additionalTools }
  767. self.parent.MapWindow.mouse['box'] = 'box'
  768. def OnFlip(self, event):
  769. """!Flip selected lines/boundaries"""
  770. if self.action['desc'] == 'flipLine': # select previous action
  771. self.ToggleTool(self.addPoint, True)
  772. self.ToggleTool(self.additionalTools, False)
  773. self.OnAddPoint(event)
  774. return
  775. Debug.msg(2, "Digittoolbar.OnFlip():")
  776. self.action = { 'desc' : "flipLine",
  777. 'id' : self.additionalTools }
  778. self.parent.MapWindow.mouse['box'] = 'box'
  779. def OnMerge(self, event):
  780. """!Merge selected lines/boundaries"""
  781. if self.action['desc'] == 'mergeLine': # select previous action
  782. self.ToggleTool(self.addPoint, True)
  783. self.ToggleTool(self.additionalTools, False)
  784. self.OnAddPoint(event)
  785. return
  786. Debug.msg(2, "Digittoolbar.OnMerge():")
  787. self.action = { 'desc' : "mergeLine",
  788. 'id' : self.additionalTools }
  789. self.parent.MapWindow.mouse['box'] = 'box'
  790. def OnBreak(self, event):
  791. """!Break selected lines/boundaries"""
  792. if self.action['desc'] == 'breakLine': # select previous action
  793. self.ToggleTool(self.addPoint, True)
  794. self.ToggleTool(self.additionalTools, False)
  795. self.OnAddPoint(event)
  796. return
  797. Debug.msg(2, "Digittoolbar.OnBreak():")
  798. self.action = { 'desc' : "breakLine",
  799. 'id' : self.additionalTools }
  800. self.parent.MapWindow.mouse['box'] = 'box'
  801. def OnSnap(self, event):
  802. """!Snap selected features"""
  803. if self.action['desc'] == 'snapLine': # select previous action
  804. self.ToggleTool(self.addPoint, True)
  805. self.ToggleTool(self.additionalTools, False)
  806. self.OnAddPoint(event)
  807. return
  808. Debug.msg(2, "Digittoolbar.OnSnap():")
  809. self.action = { 'desc' : "snapLine",
  810. 'id' : self.additionalTools }
  811. self.parent.MapWindow.mouse['box'] = 'box'
  812. def OnConnect(self, event):
  813. """!Connect selected lines/boundaries"""
  814. if self.action['desc'] == 'connectLine': # select previous action
  815. self.ToggleTool(self.addPoint, True)
  816. self.ToggleTool(self.additionalTools, False)
  817. self.OnAddPoint(event)
  818. return
  819. Debug.msg(2, "Digittoolbar.OnConnect():")
  820. self.action = { 'desc' : "connectLine",
  821. 'id' : self.additionalTools }
  822. self.parent.MapWindow.mouse['box'] = 'box'
  823. def OnQuery(self, event):
  824. """!Query selected lines/boundaries"""
  825. if self.action['desc'] == 'queryLine': # select previous action
  826. self.ToggleTool(self.addPoint, True)
  827. self.ToggleTool(self.additionalTools, False)
  828. self.OnAddPoint(event)
  829. return
  830. Debug.msg(2, "Digittoolbar.OnQuery(): %s" % \
  831. UserSettings.Get(group='vdigit', key='query', subkey='selection'))
  832. self.action = { 'desc' : "queryLine",
  833. 'id' : self.additionalTools }
  834. self.parent.MapWindow.mouse['box'] = 'box'
  835. def OnZBulk(self, event):
  836. """!Z bulk-labeling selected lines/boundaries"""
  837. if not self.parent.digit.driver.Is3D():
  838. wx.MessageBox(parent=self.parent,
  839. message=_("Vector map is not 3D. Operation canceled."),
  840. caption=_("Error"), style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
  841. return
  842. if self.action['desc'] == 'zbulkLine': # select previous action
  843. self.ToggleTool(self.addPoint, True)
  844. self.ToggleTool(self.additionalTools, False)
  845. self.OnAddPoint(event)
  846. return
  847. Debug.msg(2, "Digittoolbar.OnZBulk():")
  848. self.action = { 'desc' : "zbulkLine",
  849. 'id' : self.additionalTools }
  850. self.parent.MapWindow.mouse['box'] = 'line'
  851. def OnTypeConversion(self, event):
  852. """!Feature type conversion
  853. Supported conversions:
  854. - point <-> centroid
  855. - line <-> boundary
  856. """
  857. if self.action['desc'] == 'typeConv': # select previous action
  858. self.ToggleTool(self.addPoint, True)
  859. self.ToggleTool(self.additionalTools, False)
  860. self.OnAddPoint(event)
  861. return
  862. Debug.msg(2, "Digittoolbar.OnTypeConversion():")
  863. self.action = { 'desc' : "typeConv",
  864. 'id' : self.additionalTools }
  865. self.parent.MapWindow.mouse['box'] = 'box'
  866. def OnSelectMap (self, event):
  867. """
  868. Select vector map layer for editing
  869. If there is a vector map layer already edited, this action is
  870. firstly terminated. The map layer is closed. After this the
  871. selected map layer activated for editing.
  872. """
  873. if event.GetSelection() == 0: # create new vector map layer
  874. if self.mapLayer:
  875. openVectorMap = self.mapLayer.GetName(fullyQualified=False)['name']
  876. else:
  877. openVectorMap = None
  878. mapName = gdialogs.CreateNewVector(self.parent,
  879. exceptMap = openVectorMap, log = self.log,
  880. cmd = (('v.edit',
  881. { 'tool' : 'create' },
  882. 'map')),
  883. disableAdd=True)[0]
  884. if mapName:
  885. # add layer to map layer tree
  886. if self.layerTree:
  887. self.layerTree.AddLayer(ltype='vector',
  888. lname=mapName,
  889. lchecked=True,
  890. lopacity=1.0,
  891. lcmd=['d.vect', 'map=%s' % mapName])
  892. vectLayers = self.UpdateListOfLayers(updateTool=True)
  893. selection = vectLayers.index(mapName)
  894. else:
  895. pass # TODO (no Layer Manager)
  896. else:
  897. self.combo.SetValue(_('Select vector map'))
  898. return
  899. else:
  900. selection = event.GetSelection() - 1 # first option is 'New vector map'
  901. # skip currently selected map
  902. if self.layers[selection] == self.mapLayer:
  903. return False
  904. if self.mapLayer:
  905. # deactive map layer for editing
  906. self.StopEditing()
  907. # select the given map layer for editing
  908. self.StartEditing(self.layers[selection])
  909. event.Skip()
  910. return True
  911. def StartEditing (self, mapLayer):
  912. """
  913. Start editing selected vector map layer.
  914. @param mapLayer reference to MapLayer instance
  915. """
  916. # deactive layer
  917. self.mapcontent.ChangeLayerActive(mapLayer, False)
  918. # clean map canvas
  919. ### self.parent.MapWindow.EraseMap()
  920. # unset background map if needed
  921. if mapLayer:
  922. if UserSettings.Get(group='vdigit', key='bgmap',
  923. subkey='value', internal=True) == mapLayer.GetName():
  924. UserSettings.Set(group='vdigit', key='bgmap',
  925. subkey='value', value='', internal=True)
  926. self.parent.statusbar.SetStatusText(_("Please wait, "
  927. "opening vector map <%s> for editing...") % \
  928. mapLayer.GetName(),
  929. 0)
  930. # reload vdigit module
  931. reload(vdigit)
  932. from vdigit import VDigit as VDigit
  933. # use vdigit's PseudoDC
  934. self.parent.MapWindow.DefinePseudoDC(vdigit = True)
  935. self.parent.digit = VDigit(mapwindow=self.parent.MapWindow)
  936. self.mapLayer = mapLayer
  937. # open vector map
  938. try:
  939. if not self.parent.MapWindow.CheckPseudoDC():
  940. raise gcmd.DigitError(parent=self.parent,
  941. message=_("Unable to initialize display driver of vector "
  942. "digitizer. See 'Command output' for details."))
  943. self.parent.digit.SetMapName(mapLayer.GetName())
  944. except gcmd.DigitError, e:
  945. self.mapLayer = None
  946. self.StopEditing()
  947. print >> sys.stderr, e # wxMessageBox
  948. return False
  949. # update toolbar
  950. self.combo.SetValue(mapLayer.GetName())
  951. self.parent.toolbars['map'].combo.SetValue (_('Digitize'))
  952. Debug.msg (4, "VDigitToolbar.StartEditing(): layer=%s" % mapLayer.GetName())
  953. # change cursor
  954. if self.parent.MapWindow.mouse['use'] == 'pointer':
  955. self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
  956. # create pseudoDC for drawing the map
  957. self.parent.MapWindow.pdcVector = vdigit.PseudoDC()
  958. self.parent.digit.driver.SetDevice(self.parent.MapWindow.pdcVector)
  959. if not self.parent.MapWindow.resize:
  960. self.parent.MapWindow.UpdateMap(render=True)
  961. opacity = mapLayer.GetOpacity(float=True)
  962. if opacity < 1.0:
  963. alpha = int(opacity * 255)
  964. self.parent.digit.driver.UpdateSettings(alpha)
  965. return True
  966. def StopEditing(self):
  967. """!Stop editing of selected vector map layer.
  968. @return True on success
  969. @return False on failure
  970. """
  971. # use wx's PseudoDC
  972. self.parent.MapWindow.DefinePseudoDC(vdigit = False)
  973. self.combo.SetValue (_('Select vector map'))
  974. # save changes
  975. if self.mapLayer:
  976. Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % self.mapLayer.GetName())
  977. if UserSettings.Get(group='vdigit', key='saveOnExit', subkey='enabled') is False:
  978. if self.parent.digit.GetUndoLevel() > 0:
  979. dlg = wx.MessageDialog(parent=self.parent,
  980. message=_("Do you want to save changes "
  981. "in vector map <%s>?") % self.mapLayer.GetName(),
  982. caption=_("Save changes?"),
  983. style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  984. if dlg.ShowModal() == wx.ID_NO:
  985. # revert changes
  986. self.parent.digit.Undo(0)
  987. dlg.Destroy()
  988. self.parent.statusbar.SetStatusText(_("Please wait, "
  989. "closing and rebuilding topology of "
  990. "vector map <%s>...") % self.mapLayer.GetName(),
  991. 0)
  992. self.parent.digit.SetMapName(None) # -> close map
  993. # re-active layer
  994. item = self.parent.tree.FindItemByData('maplayer', self.mapLayer)
  995. if item and self.parent.tree.IsItemChecked(item):
  996. self.mapcontent.ChangeLayerActive(self.mapLayer, True)
  997. # change cursor
  998. self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
  999. # disable pseudodc for vector map layer
  1000. self.parent.MapWindow.pdcVector = None
  1001. self.parent.digit.driver.SetDevice(None)
  1002. # close dialogs
  1003. for dialog in ('attributes', 'category'):
  1004. if self.parent.dialogs[dialog]:
  1005. self.parent.dialogs[dialog].Close()
  1006. self.parent.dialogs[dialog] = None
  1007. self.parent.digit.__del__() # FIXME: destructor is not called here (del)
  1008. self.parent.digit = None
  1009. self.mapLayer = None
  1010. self.parent.MapWindow.redrawAll = True
  1011. return True
  1012. def UpdateListOfLayers (self, updateTool=False):
  1013. """!
  1014. Update list of available vector map layers.
  1015. This list consists only editable layers (in the current mapset)
  1016. Optionally also update toolbar
  1017. """
  1018. Debug.msg (4, "VDigitToolbar.UpdateListOfLayers(): updateTool=%d" % \
  1019. updateTool)
  1020. layerNameSelected = None
  1021. # name of currently selected layer
  1022. if self.mapLayer:
  1023. layerNameSelected = self.mapLayer.GetName()
  1024. # select vector map layer in the current mapset
  1025. layerNameList = []
  1026. self.layers = self.mapcontent.GetListOfLayers(l_type="vector",
  1027. l_mapset=grass.gisenv()['MAPSET'])
  1028. for layer in self.layers:
  1029. if not layer.name in layerNameList: # do not duplicate layer
  1030. layerNameList.append (layer.GetName())
  1031. if updateTool: # update toolbar
  1032. if not self.mapLayer:
  1033. value = _('Select vector map')
  1034. else:
  1035. value = layerNameSelected
  1036. if not self.comboid:
  1037. self.combo = wx.ComboBox(self, id=wx.ID_ANY, value=value,
  1038. choices=[_('New vector map'), ] + layerNameList, size=(115, -1),
  1039. style=wx.CB_READONLY)
  1040. self.comboid = self.InsertControl(0, self.combo)
  1041. self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectMap, self.comboid)
  1042. else:
  1043. self.combo.SetItems([_('New vector map'), ] + layerNameList)
  1044. self.Realize()
  1045. return layerNameList
  1046. def GetLayer(self):
  1047. """!Get selected layer for editing -- MapLayer instance"""
  1048. return self.mapLayer
  1049. class ProfileToolbar(AbstractToolbar):
  1050. """!
  1051. Toolbar for profiling raster map
  1052. """
  1053. def __init__(self, parent):
  1054. AbstractToolbar.__init__(self, parent)
  1055. self.InitToolbar(self.ToolbarData())
  1056. # realize the toolbar
  1057. self.Realize()
  1058. def ToolbarData(self):
  1059. """!Toolbar data"""
  1060. self.transect = wx.NewId()
  1061. self.addraster = wx.NewId()
  1062. self.draw = wx.NewId()
  1063. self.options = wx.NewId()
  1064. self.drag = wx.NewId()
  1065. self.zoom = wx.NewId()
  1066. self.unzoom = wx.NewId()
  1067. self.erase = wx.NewId()
  1068. self.save = wx.NewId()
  1069. self.printer = wx.NewId()
  1070. self.quit = wx.NewId()
  1071. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  1072. return (
  1073. (self.addraster, 'raster', Icons["addrast"].GetBitmap(),
  1074. wx.ITEM_NORMAL, Icons["addrast"].GetLabel(), Icons["addrast"].GetDesc(),
  1075. self.parent.OnSelectRaster),
  1076. (self.transect, 'transect', Icons["transect"].GetBitmap(),
  1077. wx.ITEM_NORMAL, Icons["transect"].GetLabel(), Icons["transect"].GetDesc(),
  1078. self.parent.OnDrawTransect),
  1079. (self.draw, 'profiledraw', Icons["profiledraw"].GetBitmap(),
  1080. wx.ITEM_NORMAL, Icons["profiledraw"].GetLabel(), Icons["profiledraw"].GetDesc(),
  1081. self.parent.OnCreateProfile),
  1082. (self.options, 'options', Icons["profileopt"].GetBitmap(),
  1083. wx.ITEM_NORMAL, Icons["profileopt"].GetLabel(), Icons["profileopt"].GetDesc(),
  1084. self.parent.ProfileOptionsMenu),
  1085. (self.drag, 'drag', Icons['pan'].GetBitmap(),
  1086. wx.ITEM_NORMAL, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  1087. self.parent.OnDrag),
  1088. (self.zoom, 'zoom', Icons['zoom_in'].GetBitmap(),
  1089. wx.ITEM_NORMAL, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  1090. self.parent.OnZoom),
  1091. (self.unzoom, 'unzoom', Icons['zoom_back'].GetBitmap(),
  1092. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  1093. self.parent.OnRedraw),
  1094. (self.erase, 'erase', Icons["erase"].GetBitmap(),
  1095. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  1096. self.parent.OnErase),
  1097. ("", "", "", "", "", "", ""),
  1098. (self.save, 'save', Icons["savefile"].GetBitmap(),
  1099. wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
  1100. self.parent.SaveToFile),
  1101. (self.printer, 'print', Icons["printmap"].GetBitmap(),
  1102. wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
  1103. self.parent.PrintMenu),
  1104. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  1105. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  1106. self.parent.OnQuit),
  1107. )
  1108. class NvizToolbar(AbstractToolbar):
  1109. """!
  1110. Nviz toolbar
  1111. """
  1112. def __init__(self, parent, mapcontent):
  1113. self.mapcontent = mapcontent
  1114. AbstractToolbar.__init__(self, parent)
  1115. self.InitToolbar(self.ToolbarData())
  1116. # realize the toolbar
  1117. self.Realize()
  1118. def ToolbarData(self):
  1119. """!Toolbar data"""
  1120. self.settings = wx.NewId()
  1121. self.quit = wx.NewId()
  1122. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  1123. return (
  1124. (self.settings, "settings", Icons["nvizSettings"].GetBitmap(),
  1125. wx.ITEM_NORMAL, Icons["nvizSettings"].GetLabel(), Icons["nvizSettings"].GetDesc(),
  1126. self.OnSettings),
  1127. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  1128. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  1129. self.OnExit),
  1130. )
  1131. def OnSettings(self, event):
  1132. win = self.parent.nvizToolWin
  1133. if not win.IsShown():
  1134. self.parent.nvizToolWin.Show()
  1135. else:
  1136. self.parent.nvizToolWin.Hide()
  1137. def OnExit (self, event=None):
  1138. """!Quit nviz tool (swith to 2D mode)"""
  1139. # hide dialogs if still open
  1140. if self.parent.nvizToolWin:
  1141. self.parent.nvizToolWin.Hide()
  1142. # set default mouse settings
  1143. self.parent.MapWindow.mouse['use'] = "pointer"
  1144. self.parent.MapWindow.mouse['box'] = "point"
  1145. self.parent.MapWindow.polycoords = []
  1146. # disable the toolbar
  1147. self.parent.RemoveToolbar("nviz")