toolbars.py 76 KB

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