toolbars.py 75 KB

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