toolbars.py 53 KB

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