toolbars.py 52 KB

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