toolbars.py 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317
  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. # clear tmp canvas
  484. if self.action['id'] != id:
  485. self.parent.MapWindow.ClearLines(pdc=self.parent.MapWindow.pdcTmp)
  486. def OnAddPoint(self, event):
  487. """Add point to the vector map Laier"""
  488. Debug.msg (2, "VDigitToolbar.OnAddPoint()")
  489. self.action = { 'desc' : "addLine",
  490. 'type' : "point",
  491. 'id' : self.addPoint }
  492. self.parent.MapWindow.mouse['box'] = 'point'
  493. def OnAddLine(self, event):
  494. """Add line to the vector map layer"""
  495. Debug.msg (2, "VDigitToolbar.OnAddLine()")
  496. self.action = { 'desc' : "addLine",
  497. 'type' : "line",
  498. 'id' : self.addLine }
  499. self.parent.MapWindow.mouse['box'] = 'line'
  500. ### self.parent.MapWindow.polycoords = [] # reset temp line
  501. def OnAddBoundary(self, event):
  502. """Add boundary to the vector map layer"""
  503. Debug.msg (2, "VDigitToolbar.OnAddBoundary()")
  504. if self.action['desc'] != 'addLine' or \
  505. self.action['type'] != 'boundary':
  506. self.parent.MapWindow.polycoords = [] # reset temp line
  507. self.action = { 'desc' : "addLine",
  508. 'type' : "boundary",
  509. 'id' : self.addBoundary }
  510. self.parent.MapWindow.mouse['box'] = 'line'
  511. def OnAddCentroid(self, event):
  512. """Add centroid to the vector map layer"""
  513. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  514. self.action = { 'desc' : "addLine",
  515. 'type' : "centroid",
  516. 'id' : self.addCentroid }
  517. self.parent.MapWindow.mouse['box'] = 'point'
  518. def OnExit (self, event=None):
  519. """Quit digitization tool"""
  520. # stop editing of the currently selected map layer
  521. if self.mapLayer:
  522. self.StopEditing()
  523. # close dialogs if still open
  524. if self.settingsDialog:
  525. self.settingsDialog.OnCancel(None)
  526. # disable the toolbar
  527. self.parent.RemoveToolbar ("vdigit")
  528. def OnMoveVertex(self, event):
  529. """Move line vertex"""
  530. Debug.msg(2, "Digittoolbar.OnMoveVertex():")
  531. self.action = { 'desc' : "moveVertex",
  532. 'id' : self.moveVertex }
  533. self.parent.MapWindow.mouse['box'] = 'point'
  534. def OnAddVertex(self, event):
  535. """Add line vertex"""
  536. Debug.msg(2, "Digittoolbar.OnAddVertex():")
  537. self.action = { 'desc' : "addVertex",
  538. 'id' : self.addVertex }
  539. self.parent.MapWindow.mouse['box'] = 'point'
  540. def OnRemoveVertex(self, event):
  541. """Remove line vertex"""
  542. Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
  543. self.action = { 'desc' : "removeVertex",
  544. 'id' : self.removeVertex }
  545. self.parent.MapWindow.mouse['box'] = 'point'
  546. def OnSplitLine(self, event):
  547. """Split line"""
  548. Debug.msg(2, "Digittoolbar.OnSplitLine():")
  549. self.action = { 'desc' : "splitLine",
  550. 'id' : self.splitLine }
  551. self.parent.MapWindow.mouse['box'] = 'point'
  552. def OnEditLine(self, event):
  553. """Edit line"""
  554. Debug.msg(2, "Digittoolbar.OnEditLine():")
  555. self.action = { 'desc' : "editLine",
  556. 'id' : self.editLine }
  557. self.parent.MapWindow.mouse['box'] = 'line'
  558. def OnMoveLine(self, event):
  559. """Move line"""
  560. Debug.msg(2, "Digittoolbar.OnMoveLine():")
  561. self.action = { 'desc' : "moveLine",
  562. 'id' : self.moveLine }
  563. self.parent.MapWindow.mouse['box'] = 'box'
  564. def OnDeleteLine(self, event):
  565. """Delete line"""
  566. Debug.msg(2, "Digittoolbar.OnDeleteLine():")
  567. self.action = { 'desc' : "deleteLine",
  568. 'id' : self.deleteLine }
  569. self.parent.MapWindow.mouse['box'] = 'box'
  570. def OnDisplayCats(self, event):
  571. """Display/update categories"""
  572. Debug.msg(2, "Digittoolbar.OnDisplayCats():")
  573. self.action = { 'desc' : "displayCats",
  574. 'id' : self.displayCats }
  575. self.parent.MapWindow.mouse['box'] = 'point'
  576. def OnDisplayAttr(self, event):
  577. """Display/update attributes"""
  578. Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
  579. self.action = { 'desc' : "displayAttrs",
  580. 'id' : self.displayAttr }
  581. self.parent.MapWindow.mouse['box'] = 'point'
  582. def OnCopyCA(self, event):
  583. """Copy categories/attributes menu"""
  584. point = wx.GetMousePosition()
  585. toolMenu = wx.Menu()
  586. # Add items to the menu
  587. cats = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  588. text=_('Copy categories'),
  589. kind=wx.ITEM_CHECK)
  590. toolMenu.AppendItem(cats)
  591. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyCats, cats)
  592. if self.action['desc'] == "copyCats":
  593. cats.Check(True)
  594. attrb = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  595. text=_('Duplicate attributes'),
  596. kind=wx.ITEM_CHECK)
  597. toolMenu.AppendItem(attrb)
  598. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyAttrb, attrb)
  599. if self.action['desc'] == "copyAttrs":
  600. attrb.Check(True)
  601. # Popup the menu. If an item is selected then its handler
  602. # will be called before PopupMenu returns.
  603. self.parent.MapWindow.PopupMenu(toolMenu)
  604. toolMenu.Destroy()
  605. if self.action['desc'] == "addPoint":
  606. self.toolbar[0].ToggleTool(self.copyCats, False)
  607. def OnCopyCats(self, event):
  608. """Copy categories"""
  609. if self.action['desc'] == 'copyCats': # select previous action
  610. self.toolbar[0].ToggleTool(self.addPoint, True)
  611. self.toolbar[0].ToggleTool(self.copyCats, False)
  612. self.OnAddPoint(event)
  613. return
  614. Debug.msg(2, "Digittoolbar.OnCopyCats():")
  615. self.action = { 'desc' : "copyCats",
  616. 'id' : self.copyCats }
  617. self.parent.MapWindow.mouse['box'] = 'point'
  618. def OnCopyAttrb(self, event):
  619. if self.action['desc'] == 'copyAttrs': # select previous action
  620. self.toolbar[0].ToggleTool(self.addPoint, True)
  621. self.toolbar[0].ToggleTool(self.copyCats, False)
  622. self.OnAddPoint(event)
  623. return
  624. Debug.msg(2, "Digittoolbar.OnCopyAttrb():")
  625. self.action = { 'desc' : "copyAttrs",
  626. 'id' : self.copyCats }
  627. self.parent.MapWindow.mouse['box'] = 'point'
  628. def OnUndo(self, event):
  629. """Undo previous changes"""
  630. self.parent.digit.Undo()
  631. event.Skip()
  632. def EnableUndo(self, enable=True):
  633. """Enable 'Undo' in toolbar
  634. @param enable False for disable
  635. """
  636. if enable:
  637. if self.toolbar[0].GetToolEnabled(self.undo) is False:
  638. self.toolbar[0].EnableTool(self.undo, True)
  639. else:
  640. if self.toolbar[0].GetToolEnabled(self.undo) is True:
  641. self.toolbar[0].EnableTool(self.undo, False)
  642. def OnSettings(self, event):
  643. """Show settings dialog"""
  644. if self.parent.digit is None:
  645. reload(vdigit)
  646. from vdigit import Digit as Digit
  647. self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
  648. if not self.settingsDialog:
  649. self.settingsDialog = VDigitSettingsDialog(parent=self.parent, title=_("Digitization settings"),
  650. style=wx.DEFAULT_DIALOG_STYLE)
  651. self.settingsDialog.Show()
  652. def OnAdditionalToolMenu(self, event):
  653. """Menu for additional tools"""
  654. point = wx.GetMousePosition()
  655. toolMenu = wx.Menu()
  656. # Add items to the menu
  657. copy = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  658. text=_('Copy features from (background) vector map'),
  659. kind=wx.ITEM_CHECK)
  660. toolMenu.AppendItem(copy)
  661. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopy, copy)
  662. if self.action['desc'] == "copyLine":
  663. copy.Check(True)
  664. flip = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  665. text=_('Flip selected lines/boundaries'),
  666. kind=wx.ITEM_CHECK)
  667. toolMenu.AppendItem(flip)
  668. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnFlip, flip)
  669. if self.action['desc'] == "flipLine":
  670. flip.Check(True)
  671. merge = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  672. text=_('Merge selected lines/boundaries'),
  673. kind=wx.ITEM_CHECK)
  674. toolMenu.AppendItem(merge)
  675. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnMerge, merge)
  676. if self.action['desc'] == "mergeLine":
  677. merge.Check(True)
  678. breakL = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  679. text=_('Break selected lines/boundaries at intersection'),
  680. kind=wx.ITEM_CHECK)
  681. toolMenu.AppendItem(breakL)
  682. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnBreak, breakL)
  683. if self.action['desc'] == "breakLine":
  684. breakL.Check(True)
  685. snap = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  686. text=_('Snap selected lines/boundaries (only to nodes)'),
  687. kind=wx.ITEM_CHECK)
  688. toolMenu.AppendItem(snap)
  689. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnSnap, snap)
  690. if self.action['desc'] == "snapLine":
  691. snap.Check(True)
  692. connect = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  693. text=_('Connect selected lines/boundaries'),
  694. kind=wx.ITEM_CHECK)
  695. toolMenu.AppendItem(connect)
  696. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnConnect, connect)
  697. if self.action['desc'] == "connectLine":
  698. connect.Check(True)
  699. query = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  700. text=_('Query features'),
  701. kind=wx.ITEM_CHECK)
  702. toolMenu.AppendItem(query)
  703. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnQuery, query)
  704. if self.action['desc'] == "queryLine":
  705. query.Check(True)
  706. zbulk = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  707. text=_('Z bulk-labeling of 3D lines'),
  708. kind=wx.ITEM_CHECK)
  709. toolMenu.AppendItem(zbulk)
  710. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnZBulk, zbulk)
  711. if self.action['desc'] == "zbulkLine":
  712. zbulk.Check(True)
  713. typeconv = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  714. text=_('Feature type conversion'),
  715. kind=wx.ITEM_CHECK)
  716. toolMenu.AppendItem(typeconv)
  717. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnTypeConversion, typeconv)
  718. if self.action['desc'] == "typeConv":
  719. typeconv.Check(True)
  720. # Popup the menu. If an item is selected then its handler
  721. # will be called before PopupMenu returns.
  722. self.parent.MapWindow.PopupMenu(toolMenu)
  723. toolMenu.Destroy()
  724. if self.action['desc'] == 'addPoint':
  725. self.toolbar[0].ToggleTool(self.additionalTools, False)
  726. def OnCopy(self, event):
  727. """Copy selected features from (background) vector map"""
  728. if self.action['desc'] == 'copyLine': # select previous action
  729. self.toolbar[0].ToggleTool(self.addPoint, True)
  730. self.toolbar[0].ToggleTool(self.additionalTools, False)
  731. self.OnAddPoint(event)
  732. return
  733. Debug.msg(2, "Digittoolbar.OnCopy():")
  734. self.action = { 'desc' : "copyLine",
  735. 'id' : self.additionalTools }
  736. self.parent.MapWindow.mouse['box'] = 'box'
  737. def OnFlip(self, event):
  738. """Flip selected lines/boundaries"""
  739. if self.action['desc'] == 'flipLine': # select previous action
  740. self.toolbar[0].ToggleTool(self.addPoint, True)
  741. self.toolbar[0].ToggleTool(self.additionalTools, False)
  742. self.OnAddPoint(event)
  743. return
  744. Debug.msg(2, "Digittoolbar.OnFlip():")
  745. self.action = { 'desc' : "flipLine",
  746. 'id' : self.additionalTools }
  747. self.parent.MapWindow.mouse['box'] = 'box'
  748. def OnMerge(self, event):
  749. """Merge selected lines/boundaries"""
  750. if self.action['desc'] == 'mergeLine': # select previous action
  751. self.toolbar[0].ToggleTool(self.addPoint, True)
  752. self.toolbar[0].ToggleTool(self.additionalTools, False)
  753. self.OnAddPoint(event)
  754. return
  755. Debug.msg(2, "Digittoolbar.OnMerge():")
  756. self.action = { 'desc' : "mergeLine",
  757. 'id' : self.additionalTools }
  758. self.parent.MapWindow.mouse['box'] = 'box'
  759. def OnBreak(self, event):
  760. """Break selected lines/boundaries"""
  761. if self.action['desc'] == 'breakLine': # select previous action
  762. self.toolbar[0].ToggleTool(self.addPoint, True)
  763. self.toolbar[0].ToggleTool(self.additionalTools, False)
  764. self.OnAddPoint(event)
  765. return
  766. Debug.msg(2, "Digittoolbar.OnBreak():")
  767. self.action = { 'desc' : "breakLine",
  768. 'id' : self.additionalTools }
  769. self.parent.MapWindow.mouse['box'] = 'box'
  770. def OnSnap(self, event):
  771. """Snap selected features"""
  772. if self.action['desc'] == 'snapLine': # select previous action
  773. self.toolbar[0].ToggleTool(self.addPoint, True)
  774. self.toolbar[0].ToggleTool(self.additionalTools, False)
  775. self.OnAddPoint(event)
  776. return
  777. Debug.msg(2, "Digittoolbar.OnSnap():")
  778. self.action = { 'desc' : "snapLine",
  779. 'id' : self.additionalTools }
  780. self.parent.MapWindow.mouse['box'] = 'box'
  781. def OnConnect(self, event):
  782. """Connect selected lines/boundaries"""
  783. if self.action['desc'] == 'connectLine': # select previous action
  784. self.toolbar[0].ToggleTool(self.addPoint, True)
  785. self.toolbar[0].ToggleTool(self.additionalTools, False)
  786. self.OnAddPoint(event)
  787. return
  788. Debug.msg(2, "Digittoolbar.OnConnect():")
  789. self.action = { 'desc' : "connectLine",
  790. 'id' : self.additionalTools }
  791. self.parent.MapWindow.mouse['box'] = 'box'
  792. def OnQuery(self, event):
  793. """Query selected lines/boundaries"""
  794. if self.action['desc'] == 'queryLine': # select previous action
  795. self.toolbar[0].ToggleTool(self.addPoint, True)
  796. self.toolbar[0].ToggleTool(self.additionalTools, False)
  797. self.OnAddPoint(event)
  798. return
  799. Debug.msg(2, "Digittoolbar.OnQuery(): %s" % \
  800. UserSettings.Get(group='vdigit', key='query', subkey='selection'))
  801. self.action = { 'desc' : "queryLine",
  802. 'id' : self.additionalTools }
  803. self.parent.MapWindow.mouse['box'] = 'box'
  804. def OnZBulk(self, event):
  805. """Z bulk-labeling selected lines/boundaries"""
  806. if self.action['desc'] == 'zbulkLine': # select previous action
  807. self.toolbar[0].ToggleTool(self.addPoint, True)
  808. self.toolbar[0].ToggleTool(self.additionalTools, False)
  809. self.OnAddPoint(event)
  810. return
  811. Debug.msg(2, "Digittoolbar.OnZBulk():")
  812. self.action = { 'desc' : "zbulkLine",
  813. 'id' : self.additionalTools }
  814. self.parent.MapWindow.mouse['box'] = 'line'
  815. def OnTypeConversion(self, event):
  816. """Feature type conversion
  817. Supported conversions:
  818. - point <-> centroid
  819. - line <-> boundary
  820. """
  821. if self.action['desc'] == 'typeConv': # select previous action
  822. self.toolbar[0].ToggleTool(self.addPoint, True)
  823. self.toolbar[0].ToggleTool(self.additionalTools, False)
  824. self.OnAddPoint(event)
  825. return
  826. Debug.msg(2, "Digittoolbar.OnTypeConversion():")
  827. self.action = { 'desc' : "typeConv",
  828. 'id' : self.additionalTools }
  829. self.parent.MapWindow.mouse['box'] = 'box'
  830. def OnSelectMap (self, event):
  831. """
  832. Select vector map layer for editing
  833. If there is a vector map layer already edited, this action is
  834. firstly terminated. The map layer is closed. After this the
  835. selected map layer activated for editing.
  836. """
  837. if event.GetSelection() == 0: # create new vector map layer
  838. if self.mapLayer:
  839. openVectorMap = self.mapLayer.GetName(fullyQualified=False)['name']
  840. else:
  841. openVectorMap = None
  842. mapName = gdialogs.CreateNewVector(self.parent,
  843. exceptMap=openVectorMap, log=self.log,
  844. cmdDef=(['v.edit', 'tool=create'], "map"),
  845. disableAdd=True)[0]
  846. if mapName:
  847. # add layer to map layer tree
  848. if self.layerTree:
  849. self.layerTree.AddLayer(ltype='vector',
  850. lname=mapName,
  851. lchecked=True,
  852. lopacity=1.0,
  853. lcmd=['d.vect', 'map=%s' % mapName])
  854. vectLayers = self.UpdateListOfLayers(updateTool=True)
  855. selection = vectLayers.index(mapName)
  856. else:
  857. pass # TODO (no Layer Manager)
  858. else:
  859. self.combo.SetValue(_('Select vector map'))
  860. return
  861. else:
  862. selection = event.GetSelection() - 1 # first option is 'New vector map'
  863. # skip currently selected map
  864. if self.layers[selection] == self.mapLayer:
  865. return False
  866. if self.mapLayer:
  867. # deactive map layer for editing
  868. self.StopEditing()
  869. # select the given map layer for editing
  870. self.StartEditing(self.layers[selection])
  871. event.Skip()
  872. return True
  873. def StartEditing (self, mapLayer):
  874. """
  875. Start editing selected vector map layer.
  876. @param mapLayer reference to MapLayer instance
  877. """
  878. # deactive layer
  879. self.mapcontent.ChangeLayerActive(mapLayer, False)
  880. # clean map canvas
  881. ### self.parent.MapWindow.EraseMap()
  882. # unset background map if needed
  883. if UserSettings.Get(group='vdigit', key='bgmap',
  884. subkey='value', internal=True) == mapLayer.GetName():
  885. UserSettings.Set(group='vdigit', key='bgmap',
  886. subkey='value', value='', internal=True)
  887. self.parent.statusbar.SetStatusText(_("Please wait, "
  888. "opening vector map <%s> for editing...") % \
  889. mapLayer.GetName(),
  890. 0)
  891. # reload vdigit module
  892. reload(vdigit)
  893. from vdigit import Digit as Digit
  894. self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
  895. self.mapLayer = mapLayer
  896. # open vector map
  897. try:
  898. self.parent.digit.SetMapName(mapLayer.GetName())
  899. except gcmd.DigitError, e:
  900. self.mapLayer = None
  901. print >> sys.stderr, e # wxMessageBox
  902. return False
  903. # update toolbar
  904. self.combo.SetValue(mapLayer.GetName())
  905. self.parent.toolbars['map'].combo.SetValue (_('Digitize'))
  906. Debug.msg (4, "VDigitToolbar.StartEditing(): layer=%s" % mapLayer.GetName())
  907. # change cursor
  908. if self.parent.MapWindow.mouse['use'] == 'pointer':
  909. self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
  910. # create pseudoDC for drawing the map
  911. self.parent.MapWindow.pdcVector = wx.PseudoDC()
  912. self.parent.digit.driver.SetDevice(self.parent.MapWindow.pdcVector)
  913. if not self.parent.MapWindow.resize:
  914. self.parent.MapWindow.UpdateMap(render=True)
  915. opacity = mapLayer.GetOpacity(float=True)
  916. if opacity < 1.0:
  917. alpha = int(opacity * 255)
  918. self.parent.digit.driver.UpdateSettings(alpha)
  919. return True
  920. def StopEditing (self):
  921. """Stop editing of selected vector map layer.
  922. @return True on success
  923. @return False on failure
  924. """
  925. if not self.mapLayer:
  926. return False
  927. Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % self.mapLayer.GetName())
  928. self.combo.SetValue (_('Select vector map'))
  929. # save changes
  930. if UserSettings.Get(group='vdigit', key='saveOnExit', subkey='enabled') is False:
  931. if self.parent.digit.GetUndoLevel() > 0:
  932. dlg = wx.MessageDialog(parent=self.parent,
  933. message=_("Do you want to save changes "
  934. "in vector map <%s>?") % self.mapLayer.GetName(),
  935. caption=_("Save changes?"),
  936. style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  937. if dlg.ShowModal() == wx.ID_NO:
  938. # revert changes
  939. self.parent.digit.Undo(0)
  940. dlg.Destroy()
  941. self.parent.statusbar.SetStatusText(_("Please wait, "
  942. "closing and rebuilding topology of "
  943. "vector map <%s>...") % self.mapLayer.GetName(),
  944. 0)
  945. self.parent.digit.SetMapName(None) # -> close map
  946. # re-active layer
  947. item = self.parent.tree.FindItemByData('maplayer', self.mapLayer)
  948. if item and self.parent.tree.IsItemChecked(item):
  949. self.mapcontent.ChangeLayerActive(self.mapLayer, True)
  950. # change cursor
  951. self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
  952. # disable pseudodc for vector map layer
  953. self.parent.MapWindow.pdcVector = None
  954. self.parent.digit.driver.SetDevice(None)
  955. # close dialogs
  956. for dialog in ('attributes', 'category'):
  957. if self.parent.dialogs[dialog]:
  958. self.parent.dialogs[dialog].Close()
  959. self.parent.dialogs[dialog] = None
  960. self.parent.digit.__del__() # FIXME: destructor is not called here (del)
  961. self.parent.digit = None
  962. self.mapLayer = None
  963. return True
  964. def UpdateListOfLayers (self, updateTool=False):
  965. """
  966. Update list of available vector map layers.
  967. This list consists only editable layers (in the current mapset)
  968. Optionally also update toolbar
  969. """
  970. Debug.msg (4, "VDigitToolbar.UpdateListOfLayers(): updateTool=%d" % \
  971. updateTool)
  972. layerNameSelected = None
  973. # name of currently selected layer
  974. if self.mapLayer:
  975. layerNameSelected = self.mapLayer.GetName()
  976. # select vector map layer in the current mapset
  977. layerNameList = []
  978. self.layers = self.mapcontent.GetListOfLayers(l_type="vector",
  979. l_mapset=grassenv.GetGRASSVariable('MAPSET'))
  980. for layer in self.layers:
  981. if not layer.name in layerNameList: # do not duplicate layer
  982. layerNameList.append (layer.GetName())
  983. if updateTool: # update toolbar
  984. if not self.mapLayer:
  985. value = _('Select vector map')
  986. else:
  987. value = layerNameSelected
  988. if not self.comboid:
  989. self.combo = wx.ComboBox(self.toolbar[self.numOfRows-1], id=wx.ID_ANY, value=value,
  990. choices=[_('New vector map'), ] + layerNameList, size=(105, -1),
  991. style=wx.CB_READONLY)
  992. self.comboid = self.toolbar[self.numOfRows-1].InsertControl(0, self.combo)
  993. self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectMap, self.comboid)
  994. else:
  995. self.combo.SetItems([_('New vector map'), ] + layerNameList)
  996. self.toolbar[self.numOfRows-1].Realize()
  997. return layerNameList
  998. def GetLayer(self):
  999. """Get selected layer for editing -- MapLayer instance"""
  1000. return self.mapLayer
  1001. class ProfileToolbar(AbstractToolbar):
  1002. """
  1003. Toolbar for profiling raster map
  1004. """
  1005. def __init__(self, parent, tbframe):
  1006. self.parent = parent # GCP
  1007. self.tbframe = tbframe
  1008. self.toolbar = wx.ToolBar(parent=self.tbframe, id=wx.ID_ANY)
  1009. # self.SetToolBar(self.toolbar)
  1010. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  1011. self.InitToolbar(self.tbframe, self.toolbar, self.ToolbarData())
  1012. # realize the toolbar
  1013. self.toolbar.Realize()
  1014. def ToolbarData(self):
  1015. """Toolbar data"""
  1016. self.transect = wx.NewId()
  1017. self.addraster = wx.NewId()
  1018. self.draw = wx.NewId()
  1019. self.options = wx.NewId()
  1020. self.drag = wx.NewId()
  1021. self.zoom = wx.NewId()
  1022. self.unzoom = wx.NewId()
  1023. self.erase = wx.NewId()
  1024. self.save = wx.NewId()
  1025. self.printer = wx.NewId()
  1026. self.quit = wx.NewId()
  1027. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  1028. return (
  1029. (self.transect, 'transect', Icons["transect"].GetBitmap(),
  1030. wx.ITEM_NORMAL, Icons["transect"].GetLabel(), Icons["transect"].GetDesc(),
  1031. self.parent.OnDrawTransect),
  1032. (self.addraster, 'raster', Icons["addrast"].GetBitmap(),
  1033. wx.ITEM_NORMAL, Icons["addrast"].GetLabel(), Icons["addrast"].GetDesc(),
  1034. self.parent.OnSelectRaster),
  1035. (self.draw, 'profiledraw', Icons["profiledraw"].GetBitmap(),
  1036. wx.ITEM_NORMAL, Icons["profiledraw"].GetLabel(), Icons["profiledraw"].GetDesc(),
  1037. self.parent.OnCreateProfile),
  1038. (self.options, 'options', Icons["profileopt"].GetBitmap(),
  1039. wx.ITEM_NORMAL, Icons["profileopt"].GetLabel(), Icons["profileopt"].GetDesc(),
  1040. self.parent.ProfileOptionsMenu),
  1041. (self.drag, 'drag', Icons['pan'].GetBitmap(),
  1042. wx.ITEM_NORMAL, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  1043. self.parent.OnDrag),
  1044. (self.zoom, 'zoom', Icons['zoom_in'].GetBitmap(),
  1045. wx.ITEM_NORMAL, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  1046. self.parent.OnZoom),
  1047. (self.unzoom, 'unzoom', Icons['zoom_back'].GetBitmap(),
  1048. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  1049. self.parent.OnRedraw),
  1050. (self.erase, 'erase', Icons["erase"].GetBitmap(),
  1051. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  1052. self.parent.OnErase),
  1053. ("", "", "", "", "", "", ""),
  1054. (self.save, 'save', Icons["savefile"].GetBitmap(),
  1055. wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
  1056. self.parent.SaveToFile),
  1057. (self.printer, 'print', Icons["printmap"].GetBitmap(),
  1058. wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
  1059. self.parent.PrintMenu),
  1060. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  1061. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  1062. self.parent.OnQuit),
  1063. )
  1064. class NvizToolbar(AbstractToolbar):
  1065. """
  1066. Nviz toolbar
  1067. """
  1068. def __init__(self, parent, map):
  1069. self.parent = parent
  1070. self.mapcontent = map
  1071. self.toolbar = wx.ToolBar(parent=self.parent, id=wx.ID_ANY)
  1072. # self.SetToolBar(self.toolbar)
  1073. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  1074. self.InitToolbar(self.parent, self.toolbar, self.ToolbarData())
  1075. # realize the toolbar
  1076. self.toolbar.Realize()
  1077. def ToolbarData(self):
  1078. """Toolbar data"""
  1079. self.settings = wx.NewId()
  1080. self.quit = wx.NewId()
  1081. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  1082. return (
  1083. (self.settings, "settings", Icons["nvizSettings"].GetBitmap(),
  1084. wx.ITEM_NORMAL, Icons["nvizSettings"].GetLabel(), Icons["nvizSettings"].GetDesc(),
  1085. self.OnSettings),
  1086. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  1087. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  1088. self.OnExit),
  1089. )
  1090. def OnSettings(self, event):
  1091. win = self.parent.nvizToolWin
  1092. if not win.IsShown():
  1093. self.parent.nvizToolWin.Show()
  1094. else:
  1095. self.parent.nvizToolWin.Hide()
  1096. def OnExit (self, event=None):
  1097. """Quit nviz tool (swith to 2D mode)"""
  1098. # disable the toolbar
  1099. self.parent.RemoveToolbar ("nviz")