toolbars.py 60 KB

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