toolbars.py 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838
  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. # currently selected map layer for editing (reference to MapLayer instance)
  544. self.mapLayer = None
  545. # list of vector layers from Layer Manager (only in the current mapset)
  546. self.layers = []
  547. self.comboid = None
  548. # only one dialog can be open
  549. self.settingsDialog = None
  550. # create toolbars (two rows optionally)
  551. self.InitToolbar(self._toolbarData())
  552. self.Bind(wx.EVT_TOOL, self.OnTool)
  553. # default action (digitize new point, line, etc.)
  554. self.action = { 'desc' : 'addLine',
  555. 'type' : 'point',
  556. 'id' : self.addPoint }
  557. # list of available vector maps
  558. self.UpdateListOfLayers(updateTool = True)
  559. # realize toolbar
  560. self.Realize()
  561. # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
  562. self.combo.Hide()
  563. self.combo.Show()
  564. # disable undo/redo
  565. self.EnableTool(self.undo, False)
  566. # toogle to pointer by default
  567. self.OnTool(None)
  568. self.FixSize(width = 105)
  569. def _toolbarData(self):
  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.addArea = wx.NewId()
  578. self.moveVertex = wx.NewId()
  579. self.addVertex = wx.NewId()
  580. self.removeVertex = wx.NewId()
  581. self.splitLine = wx.NewId()
  582. self.editLine = wx.NewId()
  583. self.moveLine = wx.NewId()
  584. self.deleteLine = wx.NewId()
  585. self.additionalTools = wx.NewId()
  586. self.displayCats = wx.NewId()
  587. self.displayAttr = wx.NewId()
  588. self.copyCats = wx.NewId()
  589. self.undo = wx.NewId()
  590. self.settings = wx.NewId()
  591. self.exit = wx.NewId()
  592. data = [("", "", "", "", "", "", ""),
  593. (self.addPoint, "digAddPoint", Icons["digAddPoint"].GetBitmap(),
  594. wx.ITEM_CHECK, Icons["digAddPoint"].GetLabel(), Icons["digAddPoint"].GetDesc(),
  595. self.OnAddPoint),
  596. (self.addLine, "digAddLine", Icons["digAddLine"].GetBitmap(),
  597. wx.ITEM_CHECK, Icons["digAddLine"].GetLabel(), Icons["digAddLine"].GetDesc(),
  598. self.OnAddLine),
  599. (self.addBoundary, "digAddBoundary", Icons["digAddBoundary"].GetBitmap(),
  600. wx.ITEM_CHECK, Icons["digAddBoundary"].GetLabel(), Icons["digAddBoundary"].GetDesc(),
  601. self.OnAddBoundary),
  602. (self.addCentroid, "digAddCentroid", Icons["digAddCentroid"].GetBitmap(),
  603. wx.ITEM_CHECK, Icons["digAddCentroid"].GetLabel(), Icons["digAddCentroid"].GetDesc(),
  604. self.OnAddCentroid),
  605. (self.addArea, "digAddArea", Icons["digAddArea"].GetBitmap(),
  606. wx.ITEM_CHECK, Icons["digAddArea"].GetLabel(), Icons["digAddArea"].GetDesc(),
  607. self.OnAddArea),
  608. (self.moveVertex, "digMoveVertex", Icons["digMoveVertex"].GetBitmap(),
  609. wx.ITEM_CHECK, Icons["digMoveVertex"].GetLabel(), Icons["digMoveVertex"].GetDesc(),
  610. self.OnMoveVertex),
  611. (self.addVertex, "digAddVertex", Icons["digAddVertex"].GetBitmap(),
  612. wx.ITEM_CHECK, Icons["digAddVertex"].GetLabel(), Icons["digAddVertex"].GetDesc(),
  613. self.OnAddVertex),
  614. (self.removeVertex, "digRemoveVertex", Icons["digRemoveVertex"].GetBitmap(),
  615. wx.ITEM_CHECK, Icons["digRemoveVertex"].GetLabel(), Icons["digRemoveVertex"].GetDesc(),
  616. self.OnRemoveVertex),
  617. (self.splitLine, "digSplitLine", Icons["digSplitLine"].GetBitmap(),
  618. wx.ITEM_CHECK, Icons["digSplitLine"].GetLabel(), Icons["digSplitLine"].GetDesc(),
  619. self.OnSplitLine),
  620. (self.editLine, "digEditLine", Icons["digEditLine"].GetBitmap(),
  621. wx.ITEM_CHECK, Icons["digEditLine"].GetLabel(), Icons["digEditLine"].GetDesc(),
  622. self.OnEditLine),
  623. (self.moveLine, "digMoveLine", Icons["digMoveLine"].GetBitmap(),
  624. wx.ITEM_CHECK, Icons["digMoveLine"].GetLabel(), Icons["digMoveLine"].GetDesc(),
  625. self.OnMoveLine),
  626. (self.deleteLine, "digDeleteLine", Icons["digDeleteLine"].GetBitmap(),
  627. wx.ITEM_CHECK, Icons["digDeleteLine"].GetLabel(), Icons["digDeleteLine"].GetDesc(),
  628. self.OnDeleteLine),
  629. (self.displayCats, "digDispCats", Icons["digDispCats"].GetBitmap(),
  630. wx.ITEM_CHECK, Icons["digDispCats"].GetLabel(), Icons["digDispCats"].GetDesc(),
  631. self.OnDisplayCats),
  632. (self.copyCats, "digCopyCats", Icons["digCopyCats"].GetBitmap(),
  633. wx.ITEM_CHECK, Icons["digCopyCats"].GetLabel(), Icons["digCopyCats"].GetDesc(),
  634. self.OnCopyCA),
  635. (self.displayAttr, "digDispAttr", Icons["digDispAttr"].GetBitmap(),
  636. wx.ITEM_CHECK, Icons["digDispAttr"].GetLabel(), Icons["digDispAttr"].GetDesc(),
  637. self.OnDisplayAttr),
  638. (self.additionalTools, "digAdditionalTools", Icons["digAdditionalTools"].GetBitmap(),
  639. wx.ITEM_CHECK, Icons["digAdditionalTools"].GetLabel(),
  640. Icons["digAdditionalTools"].GetDesc(),
  641. self.OnAdditionalToolMenu),
  642. ("", "", "", "", "", "", ""),
  643. (self.undo, "digUndo", Icons["digUndo"].GetBitmap(),
  644. wx.ITEM_NORMAL, Icons["digUndo"].GetLabel(), Icons["digUndo"].GetDesc(),
  645. self.OnUndo),
  646. # data.append((self.undo, "digRedo", Icons["digRedo"].GetBitmap(),
  647. # wx.ITEM_NORMAL, Icons["digRedo"].GetLabel(), Icons["digRedo"].GetDesc(),
  648. # self.OnRedo))
  649. (self.settings, "digSettings", Icons["digSettings"].GetBitmap(),
  650. wx.ITEM_NORMAL, Icons["digSettings"].GetLabel(), Icons["digSettings"].GetDesc(),
  651. self.OnSettings),
  652. (self.exit, "digExit", Icons["quit"].GetBitmap(),
  653. wx.ITEM_NORMAL, Icons["digExit"].GetLabel(), Icons["digExit"].GetDesc(),
  654. self.OnExit)]
  655. return data
  656. def OnTool(self, event):
  657. """!Tool selected -> disable selected tool in map toolbar"""
  658. id = self.parent.toolbars['map'].GetAction(type = 'id')
  659. self.parent.toolbars['map'].ToggleTool(id, False)
  660. # set cursor
  661. cursor = self.parent.cursors["cross"]
  662. self.parent.MapWindow.SetCursor(cursor)
  663. # pointer
  664. self.parent.OnPointer(None)
  665. if event:
  666. # deselect previously selected tool
  667. id = self.action.get('id', -1)
  668. if id != event.GetId():
  669. self.ToggleTool(self.action['id'], False)
  670. else:
  671. self.ToggleTool(self.action['id'], True)
  672. self.action['id'] = event.GetId()
  673. event.Skip()
  674. self.ToggleTool(self.action['id'], True)
  675. # clear tmp canvas
  676. if self.action['id'] != id:
  677. self.parent.MapWindow.ClearLines(pdc = self.parent.MapWindow.pdcTmp)
  678. if self.parent.digit and \
  679. len(self.parent.digit.GetDisplay().GetSelected()) > 0:
  680. # cancel action
  681. self.parent.MapWindow.OnMiddleDown(None)
  682. # set focus
  683. self.parent.MapWindow.SetFocus()
  684. def OnAddPoint(self, event):
  685. """!Add point to the vector map Laier"""
  686. Debug.msg (2, "VDigitToolbar.OnAddPoint()")
  687. self.action = { 'desc' : "addLine",
  688. 'type' : "point",
  689. 'id' : self.addPoint }
  690. self.parent.MapWindow.mouse['box'] = 'point'
  691. def OnAddLine(self, event):
  692. """!Add line to the vector map layer"""
  693. Debug.msg (2, "VDigitToolbar.OnAddLine()")
  694. self.action = { 'desc' : "addLine",
  695. 'type' : "line",
  696. 'id' : self.addLine }
  697. self.parent.MapWindow.mouse['box'] = 'line'
  698. ### self.parent.MapWindow.polycoords = [] # reset temp line
  699. def OnAddBoundary(self, event):
  700. """!Add boundary to the vector map layer"""
  701. Debug.msg (2, "VDigitToolbar.OnAddBoundary()")
  702. if self.action['desc'] != 'addLine' or \
  703. self.action['type'] != 'boundary':
  704. self.parent.MapWindow.polycoords = [] # reset temp line
  705. self.action = { 'desc' : "addLine",
  706. 'type' : "boundary",
  707. 'id' : self.addBoundary }
  708. self.parent.MapWindow.mouse['box'] = 'line'
  709. def OnAddCentroid(self, event):
  710. """!Add centroid to the vector map layer"""
  711. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  712. self.action = { 'desc' : "addLine",
  713. 'type' : "centroid",
  714. 'id' : self.addCentroid }
  715. self.parent.MapWindow.mouse['box'] = 'point'
  716. def OnAddArea(self, event):
  717. """!Add area to the vector map layer"""
  718. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  719. self.action = { 'desc' : "addLine",
  720. 'type' : "area",
  721. 'id' : self.addArea }
  722. self.parent.MapWindow.mouse['box'] = 'line'
  723. def OnExit (self, event=None):
  724. """!Quit digitization tool"""
  725. # stop editing of the currently selected map layer
  726. if self.mapLayer:
  727. self.StopEditing()
  728. # close dialogs if still open
  729. if self.settingsDialog:
  730. self.settingsDialog.OnCancel(None)
  731. # set default mouse settings
  732. self.parent.MapWindow.mouse['use'] = "pointer"
  733. self.parent.MapWindow.mouse['box'] = "point"
  734. self.parent.MapWindow.polycoords = []
  735. # disable the toolbar
  736. self.parent.RemoveToolbar("vdigit")
  737. def OnMoveVertex(self, event):
  738. """!Move line vertex"""
  739. Debug.msg(2, "Digittoolbar.OnMoveVertex():")
  740. self.action = { 'desc' : "moveVertex",
  741. 'id' : self.moveVertex }
  742. self.parent.MapWindow.mouse['box'] = 'point'
  743. def OnAddVertex(self, event):
  744. """!Add line vertex"""
  745. Debug.msg(2, "Digittoolbar.OnAddVertex():")
  746. self.action = { 'desc' : "addVertex",
  747. 'id' : self.addVertex }
  748. self.parent.MapWindow.mouse['box'] = 'point'
  749. def OnRemoveVertex(self, event):
  750. """!Remove line vertex"""
  751. Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
  752. self.action = { 'desc' : "removeVertex",
  753. 'id' : self.removeVertex }
  754. self.parent.MapWindow.mouse['box'] = 'point'
  755. def OnSplitLine(self, event):
  756. """!Split line"""
  757. Debug.msg(2, "Digittoolbar.OnSplitLine():")
  758. self.action = { 'desc' : "splitLine",
  759. 'id' : self.splitLine }
  760. self.parent.MapWindow.mouse['box'] = 'point'
  761. def OnEditLine(self, event):
  762. """!Edit line"""
  763. Debug.msg(2, "Digittoolbar.OnEditLine():")
  764. self.action = { 'desc' : "editLine",
  765. 'id' : self.editLine }
  766. self.parent.MapWindow.mouse['box'] = 'line'
  767. def OnMoveLine(self, event):
  768. """!Move line"""
  769. Debug.msg(2, "Digittoolbar.OnMoveLine():")
  770. self.action = { 'desc' : "moveLine",
  771. 'id' : self.moveLine }
  772. self.parent.MapWindow.mouse['box'] = 'box'
  773. def OnDeleteLine(self, event):
  774. """!Delete line"""
  775. Debug.msg(2, "Digittoolbar.OnDeleteLine():")
  776. self.action = { 'desc' : "deleteLine",
  777. 'id' : self.deleteLine }
  778. self.parent.MapWindow.mouse['box'] = 'box'
  779. def OnDisplayCats(self, event):
  780. """!Display/update categories"""
  781. Debug.msg(2, "Digittoolbar.OnDisplayCats():")
  782. self.action = { 'desc' : "displayCats",
  783. 'id' : self.displayCats }
  784. self.parent.MapWindow.mouse['box'] = 'point'
  785. def OnDisplayAttr(self, event):
  786. """!Display/update attributes"""
  787. Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
  788. self.action = { 'desc' : "displayAttrs",
  789. 'id' : self.displayAttr }
  790. self.parent.MapWindow.mouse['box'] = 'point'
  791. def OnCopyCA(self, event):
  792. """!Copy categories/attributes menu"""
  793. point = wx.GetMousePosition()
  794. toolMenu = wx.Menu()
  795. # Add items to the menu
  796. cats = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  797. text = _('Copy categories'),
  798. kind = wx.ITEM_CHECK)
  799. toolMenu.AppendItem(cats)
  800. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyCats, cats)
  801. if self.action['desc'] == "copyCats":
  802. cats.Check(True)
  803. attrb = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  804. text = _('Duplicate attributes'),
  805. kind = wx.ITEM_CHECK)
  806. toolMenu.AppendItem(attrb)
  807. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyAttrb, attrb)
  808. if self.action['desc'] == "copyAttrs":
  809. attrb.Check(True)
  810. # Popup the menu. If an item is selected then its handler
  811. # will be called before PopupMenu returns.
  812. self.parent.MapWindow.PopupMenu(toolMenu)
  813. toolMenu.Destroy()
  814. if self.action['desc'] == "addPoint":
  815. self.ToggleTool(self.copyCats, False)
  816. def OnCopyCats(self, event):
  817. """!Copy categories"""
  818. if self.action['desc'] == 'copyCats': # select previous action
  819. self.ToggleTool(self.addPoint, True)
  820. self.ToggleTool(self.copyCats, False)
  821. self.OnAddPoint(event)
  822. return
  823. Debug.msg(2, "Digittoolbar.OnCopyCats():")
  824. self.action = { 'desc' : "copyCats",
  825. 'id' : self.copyCats }
  826. self.parent.MapWindow.mouse['box'] = 'point'
  827. def OnCopyAttrb(self, event):
  828. if self.action['desc'] == 'copyAttrs': # select previous action
  829. self.ToggleTool(self.addPoint, True)
  830. self.ToggleTool(self.copyCats, False)
  831. self.OnAddPoint(event)
  832. return
  833. Debug.msg(2, "Digittoolbar.OnCopyAttrb():")
  834. self.action = { 'desc' : "copyAttrs",
  835. 'id' : self.copyCats }
  836. self.parent.MapWindow.mouse['box'] = 'point'
  837. def OnUndo(self, event):
  838. """!Undo previous changes"""
  839. self.parent.digit.Undo()
  840. event.Skip()
  841. def EnableUndo(self, enable=True):
  842. """!Enable 'Undo' in toolbar
  843. @param enable False for disable
  844. """
  845. if enable:
  846. if self.GetToolEnabled(self.undo) is False:
  847. self.EnableTool(self.undo, True)
  848. else:
  849. if self.GetToolEnabled(self.undo) is True:
  850. self.EnableTool(self.undo, False)
  851. def OnSettings(self, event):
  852. """!Show settings dialog"""
  853. if self.parent.digit is None:
  854. try:
  855. self.parent.digit = VDigit(mapwindow = self.parent.MapWindow)
  856. except SystemExit:
  857. self.parent.digit = None
  858. if not self.settingsDialog:
  859. self.settingsDialog = VDigitSettingsDialog(parent = self.parent, title = _("Digitization settings"),
  860. style = wx.DEFAULT_DIALOG_STYLE)
  861. self.settingsDialog.Show()
  862. def OnAdditionalToolMenu(self, event):
  863. """!Menu for additional tools"""
  864. point = wx.GetMousePosition()
  865. toolMenu = wx.Menu()
  866. # Add items to the menu
  867. copy = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  868. text = _('Copy features from (background) vector map'),
  869. kind = wx.ITEM_CHECK)
  870. toolMenu.AppendItem(copy)
  871. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopy, copy)
  872. if self.action['desc'] == "copyLine":
  873. copy.Check(True)
  874. flip = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  875. text = _('Flip selected lines/boundaries'),
  876. kind = wx.ITEM_CHECK)
  877. toolMenu.AppendItem(flip)
  878. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnFlip, flip)
  879. if self.action['desc'] == "flipLine":
  880. flip.Check(True)
  881. merge = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  882. text = _('Merge selected lines/boundaries'),
  883. kind = wx.ITEM_CHECK)
  884. toolMenu.AppendItem(merge)
  885. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnMerge, merge)
  886. if self.action['desc'] == "mergeLine":
  887. merge.Check(True)
  888. breakL = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  889. text = _('Break selected lines/boundaries at intersection'),
  890. kind = wx.ITEM_CHECK)
  891. toolMenu.AppendItem(breakL)
  892. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnBreak, breakL)
  893. if self.action['desc'] == "breakLine":
  894. breakL.Check(True)
  895. snap = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  896. text = _('Snap selected lines/boundaries (only to nodes)'),
  897. kind = wx.ITEM_CHECK)
  898. toolMenu.AppendItem(snap)
  899. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnSnap, snap)
  900. if self.action['desc'] == "snapLine":
  901. snap.Check(True)
  902. connect = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  903. text = _('Connect selected lines/boundaries'),
  904. kind = wx.ITEM_CHECK)
  905. toolMenu.AppendItem(connect)
  906. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnConnect, connect)
  907. if self.action['desc'] == "connectLine":
  908. connect.Check(True)
  909. query = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  910. text = _('Query features'),
  911. kind = wx.ITEM_CHECK)
  912. toolMenu.AppendItem(query)
  913. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnQuery, query)
  914. if self.action['desc'] == "queryLine":
  915. query.Check(True)
  916. zbulk = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  917. text = _('Z bulk-labeling of 3D lines'),
  918. kind = wx.ITEM_CHECK)
  919. toolMenu.AppendItem(zbulk)
  920. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnZBulk, zbulk)
  921. if self.action['desc'] == "zbulkLine":
  922. zbulk.Check(True)
  923. typeconv = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  924. text = _('Feature type conversion'),
  925. kind = wx.ITEM_CHECK)
  926. toolMenu.AppendItem(typeconv)
  927. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnTypeConversion, typeconv)
  928. if self.action['desc'] == "typeConv":
  929. typeconv.Check(True)
  930. # Popup the menu. If an item is selected then its handler
  931. # will be called before PopupMenu returns.
  932. self.parent.MapWindow.PopupMenu(toolMenu)
  933. toolMenu.Destroy()
  934. if self.action['desc'] == 'addPoint':
  935. self.ToggleTool(self.additionalTools, False)
  936. def OnCopy(self, event):
  937. """!Copy selected features from (background) vector map"""
  938. if self.action['desc'] == 'copyLine': # 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.OnCopy():")
  944. self.action = { 'desc' : "copyLine",
  945. 'id' : self.additionalTools }
  946. self.parent.MapWindow.mouse['box'] = 'box'
  947. def OnFlip(self, event):
  948. """!Flip selected lines/boundaries"""
  949. if self.action['desc'] == 'flipLine': # 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.OnFlip():")
  955. self.action = { 'desc' : "flipLine",
  956. 'id' : self.additionalTools }
  957. self.parent.MapWindow.mouse['box'] = 'box'
  958. def OnMerge(self, event):
  959. """!Merge selected lines/boundaries"""
  960. if self.action['desc'] == 'mergeLine': # 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.OnMerge():")
  966. self.action = { 'desc' : "mergeLine",
  967. 'id' : self.additionalTools }
  968. self.parent.MapWindow.mouse['box'] = 'box'
  969. def OnBreak(self, event):
  970. """!Break selected lines/boundaries"""
  971. if self.action['desc'] == 'breakLine': # 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.OnBreak():")
  977. self.action = { 'desc' : "breakLine",
  978. 'id' : self.additionalTools }
  979. self.parent.MapWindow.mouse['box'] = 'box'
  980. def OnSnap(self, event):
  981. """!Snap selected features"""
  982. if self.action['desc'] == 'snapLine': # 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.OnSnap():")
  988. self.action = { 'desc' : "snapLine",
  989. 'id' : self.additionalTools }
  990. self.parent.MapWindow.mouse['box'] = 'box'
  991. def OnConnect(self, event):
  992. """!Connect selected lines/boundaries"""
  993. if self.action['desc'] == 'connectLine': # 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.OnConnect():")
  999. self.action = { 'desc' : "connectLine",
  1000. 'id' : self.additionalTools }
  1001. self.parent.MapWindow.mouse['box'] = 'box'
  1002. def OnQuery(self, event):
  1003. """!Query selected lines/boundaries"""
  1004. if self.action['desc'] == 'queryLine': # select previous action
  1005. self.ToggleTool(self.addPoint, True)
  1006. self.ToggleTool(self.additionalTools, False)
  1007. self.OnAddPoint(event)
  1008. return
  1009. Debug.msg(2, "Digittoolbar.OnQuery(): %s" % \
  1010. UserSettings.Get(group = 'vdigit', key = 'query', subkey = 'selection'))
  1011. self.action = { 'desc' : "queryLine",
  1012. 'id' : self.additionalTools }
  1013. self.parent.MapWindow.mouse['box'] = 'box'
  1014. def OnZBulk(self, event):
  1015. """!Z bulk-labeling selected lines/boundaries"""
  1016. if not self.parent.digit.IsVector3D():
  1017. gcmd.GError(parent = self.parent,
  1018. message = _("Vector map is not 3D. Operation canceled."))
  1019. return
  1020. if self.action['desc'] == 'zbulkLine': # select previous action
  1021. self.ToggleTool(self.addPoint, True)
  1022. self.ToggleTool(self.additionalTools, False)
  1023. self.OnAddPoint(event)
  1024. return
  1025. Debug.msg(2, "Digittoolbar.OnZBulk():")
  1026. self.action = { 'desc' : "zbulkLine",
  1027. 'id' : self.additionalTools }
  1028. self.parent.MapWindow.mouse['box'] = 'line'
  1029. def OnTypeConversion(self, event):
  1030. """!Feature type conversion
  1031. Supported conversions:
  1032. - point <-> centroid
  1033. - line <-> boundary
  1034. """
  1035. if self.action['desc'] == 'typeConv': # select previous action
  1036. self.ToggleTool(self.addPoint, True)
  1037. self.ToggleTool(self.additionalTools, False)
  1038. self.OnAddPoint(event)
  1039. return
  1040. Debug.msg(2, "Digittoolbar.OnTypeConversion():")
  1041. self.action = { 'desc' : "typeConv",
  1042. 'id' : self.additionalTools }
  1043. self.parent.MapWindow.mouse['box'] = 'box'
  1044. def OnSelectMap (self, event):
  1045. """
  1046. Select vector map layer for editing
  1047. If there is a vector map layer already edited, this action is
  1048. firstly terminated. The map layer is closed. After this the
  1049. selected map layer activated for editing.
  1050. """
  1051. if event.GetSelection() == 0: # create new vector map layer
  1052. if self.mapLayer:
  1053. openVectorMap = self.mapLayer.GetName(fullyQualified = False)['name']
  1054. else:
  1055. openVectorMap = None
  1056. mapName = gdialogs.CreateNewVector(self.parent,
  1057. exceptMap = openVectorMap, log = self.log,
  1058. cmd = (('v.edit',
  1059. { 'tool' : 'create' },
  1060. 'map')),
  1061. disableAdd = True)[0]
  1062. if mapName:
  1063. # add layer to map layer tree
  1064. if self.layerTree:
  1065. self.layerTree.AddLayer(ltype = 'vector',
  1066. lname = mapName,
  1067. lchecked = True,
  1068. lopacity = 1.0,
  1069. lcmd = ['d.vect', 'map=%s' % mapName])
  1070. vectLayers = self.UpdateListOfLayers(updateTool = True)
  1071. selection = vectLayers.index(mapName)
  1072. else:
  1073. pass # TODO (no Layer Manager)
  1074. else:
  1075. self.combo.SetValue(_('Select vector map'))
  1076. return
  1077. else:
  1078. selection = event.GetSelection() - 1 # first option is 'New vector map'
  1079. # skip currently selected map
  1080. if self.layers[selection] == self.mapLayer:
  1081. return False
  1082. if self.mapLayer:
  1083. # deactive map layer for editing
  1084. self.StopEditing()
  1085. # select the given map layer for editing
  1086. self.StartEditing(self.layers[selection])
  1087. event.Skip()
  1088. return True
  1089. def StartEditing (self, mapLayer):
  1090. """!Start editing selected vector map layer.
  1091. @param mapLayer MapLayer to be edited
  1092. """
  1093. # deactive layer
  1094. self.mapcontent.ChangeLayerActive(mapLayer, False)
  1095. # clean map canvas
  1096. self.parent.MapWindow.EraseMap()
  1097. # unset background map if needed
  1098. if mapLayer:
  1099. if UserSettings.Get(group = 'vdigit', key = 'bgmap',
  1100. subkey = 'value', internal = True) == mapLayer.GetName():
  1101. UserSettings.Set(group = 'vdigit', key = 'bgmap',
  1102. subkey = 'value', value = '', internal = True)
  1103. self.parent.statusbar.SetStatusText(_("Please wait, "
  1104. "opening vector map <%s> for editing...") % mapLayer.GetName(),
  1105. 0)
  1106. self.parent.MapWindow.pdcVector = wx.PseudoDC()
  1107. self.parent.digit = VDigit(mapwindow = self.parent.MapWindow)
  1108. self.mapLayer = mapLayer
  1109. # open vector map
  1110. if self.parent.digit.OpenMap(mapLayer.GetName()) is None:
  1111. self.mapLayer = None
  1112. self.StopEditing()
  1113. return False
  1114. # update toolbar
  1115. self.combo.SetValue(mapLayer.GetName())
  1116. self.parent.toolbars['map'].combo.SetValue (_('Digitize'))
  1117. lmgr = self.parent.GetLayerManager()
  1118. if lmgr:
  1119. lmgr.toolbar.Enable('vdigit', enable = False)
  1120. Debug.msg (4, "VDigitToolbar.StartEditing(): layer=%s" % mapLayer.GetName())
  1121. # change cursor
  1122. if self.parent.MapWindow.mouse['use'] == 'pointer':
  1123. self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
  1124. if not self.parent.MapWindow.resize:
  1125. self.parent.MapWindow.UpdateMap(render = True)
  1126. opacity = mapLayer.GetOpacity(float = True)
  1127. if opacity < 1.0:
  1128. alpha = int(opacity * 255)
  1129. self.parent.digit.driver.UpdateSettings(alpha)
  1130. return True
  1131. def StopEditing(self):
  1132. """!Stop editing of selected vector map layer.
  1133. @return True on success
  1134. @return False on failure
  1135. """
  1136. self.combo.SetValue (_('Select vector map'))
  1137. # save changes
  1138. if self.mapLayer:
  1139. Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % self.mapLayer.GetName())
  1140. if UserSettings.Get(group = 'vdigit', key = 'saveOnExit', subkey = 'enabled') is False:
  1141. if self.parent.digit.GetUndoLevel() > -1:
  1142. dlg = wx.MessageDialog(parent = self.parent,
  1143. message = _("Do you want to save changes "
  1144. "in vector map <%s>?") % self.mapLayer.GetName(),
  1145. caption = _("Save changes?"),
  1146. style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  1147. if dlg.ShowModal() == wx.ID_NO:
  1148. # revert changes
  1149. self.parent.digit.Undo(0)
  1150. dlg.Destroy()
  1151. self.parent.statusbar.SetStatusText(_("Please wait, "
  1152. "closing and rebuilding topology of "
  1153. "vector map <%s>...") % self.mapLayer.GetName(),
  1154. 0)
  1155. lmgr = self.parent.GetLayerManager()
  1156. if lmgr:
  1157. lmgr.toolbar.Enable('vdigit', enable = True)
  1158. lmgr.notebook.SetSelection(1)
  1159. self.parent.digit.CloseMap()
  1160. if lmgr:
  1161. lmgr.GetLogWindow().GetProgressBar().SetValue(0)
  1162. lmgr.GetLogWindow().WriteCmdLog(_("Editing of vector map <%s> successfully finished") % \
  1163. self.mapLayer.GetName())
  1164. # re-active layer
  1165. item = self.parent.tree.FindItemByData('maplayer', self.mapLayer)
  1166. if item and self.parent.tree.IsItemChecked(item):
  1167. self.mapcontent.ChangeLayerActive(self.mapLayer, True)
  1168. # change cursor
  1169. self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
  1170. self.parent.MapWindow.pdcVector = None
  1171. # close dialogs
  1172. for dialog in ('attributes', 'category'):
  1173. if self.parent.dialogs[dialog]:
  1174. self.parent.dialogs[dialog].Close()
  1175. self.parent.dialogs[dialog] = None
  1176. self.parent.digit.__del__() # FIXME: destructor is not called here (del)
  1177. self.parent.digit = None
  1178. self.mapLayer = None
  1179. self.parent.MapWindow.redrawAll = True
  1180. return True
  1181. def UpdateListOfLayers (self, updateTool = False):
  1182. """!
  1183. Update list of available vector map layers.
  1184. This list consists only editable layers (in the current mapset)
  1185. Optionally also update toolbar
  1186. """
  1187. Debug.msg (4, "VDigitToolbar.UpdateListOfLayers(): updateTool=%d" % \
  1188. updateTool)
  1189. layerNameSelected = None
  1190. # name of currently selected layer
  1191. if self.mapLayer:
  1192. layerNameSelected = self.mapLayer.GetName()
  1193. # select vector map layer in the current mapset
  1194. layerNameList = []
  1195. self.layers = self.mapcontent.GetListOfLayers(l_type = "vector",
  1196. l_mapset = grass.gisenv()['MAPSET'])
  1197. for layer in self.layers:
  1198. if not layer.name in layerNameList: # do not duplicate layer
  1199. layerNameList.append (layer.GetName())
  1200. if updateTool: # update toolbar
  1201. if not self.mapLayer:
  1202. value = _('Select vector map')
  1203. else:
  1204. value = layerNameSelected
  1205. if not self.comboid:
  1206. self.combo = wx.ComboBox(self, id = wx.ID_ANY, value = value,
  1207. choices = [_('New vector map'), ] + layerNameList, size = (115, -1),
  1208. style = wx.CB_READONLY)
  1209. self.comboid = self.InsertControl(0, self.combo)
  1210. self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectMap, self.comboid)
  1211. else:
  1212. self.combo.SetItems([_('New vector map'), ] + layerNameList)
  1213. self.Realize()
  1214. return layerNameList
  1215. def GetLayer(self):
  1216. """!Get selected layer for editing -- MapLayer instance"""
  1217. return self.mapLayer
  1218. class ProfileToolbar(AbstractToolbar):
  1219. """!Toolbar for profiling raster map
  1220. """
  1221. def __init__(self, parent):
  1222. AbstractToolbar.__init__(self, parent)
  1223. self.InitToolbar(self._toolbarData())
  1224. # realize the toolbar
  1225. self.Realize()
  1226. def _toolbarData(self):
  1227. """!Toolbar data"""
  1228. self.transect = wx.NewId()
  1229. self.addraster = wx.NewId()
  1230. self.draw = wx.NewId()
  1231. self.options = wx.NewId()
  1232. self.drag = wx.NewId()
  1233. self.zoom = wx.NewId()
  1234. self.unzoom = wx.NewId()
  1235. self.erase = wx.NewId()
  1236. self.save = wx.NewId()
  1237. self.datasave = wx.NewId()
  1238. self.printer = wx.NewId()
  1239. self.quit = wx.NewId()
  1240. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  1241. return (
  1242. (self.addraster, 'raster', Icons["addrast"].GetBitmap(),
  1243. wx.ITEM_NORMAL, Icons["addrast"].GetLabel(), Icons["addrast"].GetDesc(),
  1244. self.parent.OnSelectRaster),
  1245. (self.transect, 'transect', Icons["transect"].GetBitmap(),
  1246. wx.ITEM_NORMAL, Icons["transect"].GetLabel(), Icons["transect"].GetDesc(),
  1247. self.parent.OnDrawTransect),
  1248. ("", "", "", "", "", "", ""),
  1249. (self.draw, 'profiledraw', Icons["profiledraw"].GetBitmap(),
  1250. wx.ITEM_NORMAL, Icons["profiledraw"].GetLabel(), Icons["profiledraw"].GetDesc(),
  1251. self.parent.OnCreateProfile),
  1252. (self.erase, 'erase', Icons["erase"].GetBitmap(),
  1253. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  1254. self.parent.OnErase),
  1255. (self.drag, 'drag', Icons['pan'].GetBitmap(),
  1256. wx.ITEM_NORMAL, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  1257. self.parent.OnDrag),
  1258. (self.zoom, 'zoom', Icons['zoom_in'].GetBitmap(),
  1259. wx.ITEM_NORMAL, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  1260. self.parent.OnZoom),
  1261. (self.unzoom, 'unzoom', Icons['zoom_back'].GetBitmap(),
  1262. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  1263. self.parent.OnRedraw),
  1264. ("", "", "", "", "", "", ""),
  1265. (self.datasave, 'save data', Icons["datasave"].GetBitmap(),
  1266. wx.ITEM_NORMAL, Icons["datasave"].GetLabel(), Icons["datasave"].GetDesc(),
  1267. self.parent.SaveProfileToFile),
  1268. (self.save, 'save image', Icons["savefile"].GetBitmap(),
  1269. wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
  1270. self.parent.SaveToFile),
  1271. (self.printer, 'print', Icons["printmap"].GetBitmap(),
  1272. wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
  1273. self.parent.PrintMenu),
  1274. ("", "", "", "", "", "", ""),
  1275. (self.options, 'options', Icons["profileopt"].GetBitmap(),
  1276. wx.ITEM_NORMAL, Icons["profileopt"].GetLabel(), Icons["profileopt"].GetDesc(),
  1277. self.parent.ProfileOptionsMenu),
  1278. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  1279. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  1280. self.parent.OnQuit),
  1281. )
  1282. class NvizToolbar(AbstractToolbar):
  1283. """!Nviz toolbar
  1284. """
  1285. def __init__(self, parent, mapcontent):
  1286. self.mapcontent = mapcontent
  1287. self.lmgr = parent.GetLayerManager()
  1288. AbstractToolbar.__init__(self, parent)
  1289. # only one dialog can be open
  1290. self.settingsDialog = None
  1291. self.InitToolbar(self._toolbarData())
  1292. # realize the toolbar
  1293. self.Realize()
  1294. def _toolbarData(self):
  1295. """!Toolbar data"""
  1296. self.view = wx.NewId()
  1297. self.surface = wx.NewId()
  1298. self.vector = wx.NewId()
  1299. self.volume = wx.NewId()
  1300. self.light = wx.NewId()
  1301. self.fringe = wx.NewId()
  1302. self.settings = wx.NewId()
  1303. self.help = wx.NewId()
  1304. self.quit = wx.NewId()
  1305. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  1306. return (
  1307. (self.view, "view", Icons["nvizView"].GetBitmap(),
  1308. wx.ITEM_NORMAL, Icons["nvizView"].GetLabel(), Icons["nvizView"].GetDesc(),
  1309. self.OnShowPage),
  1310. ("", "", "", "", "", "", ""),
  1311. (self.surface, "surface", Icons["nvizSurface"].GetBitmap(),
  1312. wx.ITEM_NORMAL, Icons["nvizSurface"].GetLabel(), Icons["nvizSurface"].GetDesc(),
  1313. self.OnShowPage),
  1314. (self.vector, "vector", Icons["nvizVector"].GetBitmap(),
  1315. wx.ITEM_NORMAL, Icons["nvizVector"].GetLabel(), Icons["nvizVector"].GetDesc(),
  1316. self.OnShowPage),
  1317. (self.volume, "volume", Icons["nvizVolume"].GetBitmap(),
  1318. wx.ITEM_NORMAL, Icons["nvizVolume"].GetLabel(), Icons["nvizVolume"].GetDesc(),
  1319. self.OnShowPage),
  1320. ("", "", "", "", "", "", ""),
  1321. (self.light, "light", Icons["nvizLight"].GetBitmap(),
  1322. wx.ITEM_NORMAL, Icons["nvizLight"].GetLabel(), Icons["nvizLight"].GetDesc(),
  1323. self.OnShowPage),
  1324. (self.fringe, "fringe", Icons["nvizFringe"].GetBitmap(),
  1325. wx.ITEM_NORMAL, Icons["nvizFringe"].GetLabel(), Icons["nvizFringe"].GetDesc(),
  1326. self.OnShowPage),
  1327. ("", "", "", "", "", "", ""),
  1328. (self.settings, "settings", Icons["nvizSettings"].GetBitmap(),
  1329. wx.ITEM_NORMAL, Icons["nvizSettings"].GetLabel(), Icons["nvizSettings"].GetDesc(),
  1330. self.OnSettings),
  1331. (self.help, "help", Icons["nvizHelp"].GetBitmap(),
  1332. wx.ITEM_NORMAL, Icons["nvizHelp"].GetLabel(), Icons["nvizHelp"].GetDesc(),
  1333. self.OnHelp),
  1334. ("", "", "", "", "", "", ""),
  1335. (self.quit, 'quit', Icons["nvizQuit"].GetBitmap(),
  1336. wx.ITEM_NORMAL, Icons["nvizQuit"].GetLabel(), Icons["nvizQuit"].GetDesc(),
  1337. self.OnExit),
  1338. )
  1339. def OnShowPage(self, event):
  1340. """!Go to the selected page"""
  1341. if not self.lmgr or not hasattr(self.lmgr, "nviz"):
  1342. event.Skip()
  1343. return
  1344. self.lmgr.notebook.SetSelection(3)
  1345. eId = event.GetId()
  1346. if eId == self.view:
  1347. self.lmgr.nviz.SetPage('view')
  1348. elif eId == self.surface:
  1349. self.lmgr.nviz.SetPage('surface')
  1350. elif eId == self.surface:
  1351. self.lmgr.nviz.SetPage('surface')
  1352. elif eId == self.vector:
  1353. self.lmgr.nviz.SetPage('vector')
  1354. elif eId == self.volume:
  1355. self.lmgr.nviz.SetPage('volume')
  1356. elif eId == self.light:
  1357. self.lmgr.nviz.SetPage('light')
  1358. elif eId == self.fringe:
  1359. self.lmgr.nviz.SetPage('fringe')
  1360. self.lmgr.Raise()
  1361. def OnHelp(self, event):
  1362. """!Show 3D view mode help"""
  1363. if not self.lmgr:
  1364. gcmd.RunCommand('g.manual',
  1365. entry = 'wxGUI.Nviz')
  1366. else:
  1367. log = self.lmgr.GetLogWindow()
  1368. log.RunCmd(['g.manual',
  1369. 'entry=wxGUI.Nviz'])
  1370. def OnSettings(self, event):
  1371. """!Show nviz notebook page"""
  1372. if not self.settingsDialog:
  1373. self.settingsDialog = NvizPreferencesDialog(parent = self.parent)
  1374. self.settingsDialog.Show()
  1375. def OnExit (self, event = None):
  1376. """!Quit nviz tool (swith to 2D mode)"""
  1377. # set default mouse settings
  1378. self.parent.MapWindow.mouse['use'] = "pointer"
  1379. self.parent.MapWindow.mouse['box'] = "point"
  1380. self.parent.MapWindow.polycoords = []
  1381. # return to map layer page (gets rid of ugly exit bug)
  1382. self.lmgr.notebook.SetSelection(0)
  1383. # disable the toolbar
  1384. self.parent.RemoveToolbar("nviz")
  1385. class ModelToolbar(AbstractToolbar):
  1386. """!Graphical modeler toolbar (see gmodeler.py)
  1387. """
  1388. def __init__(self, parent):
  1389. AbstractToolbar.__init__(self, parent)
  1390. self.InitToolbar(self._toolbarData())
  1391. # realize the toolbar
  1392. self.Realize()
  1393. def _toolbarData(self):
  1394. """!Toolbar data"""
  1395. self.new = wx.NewId()
  1396. self.open = wx.NewId()
  1397. self.save = wx.NewId()
  1398. self.image = wx.NewId()
  1399. self.python = wx.NewId()
  1400. self.action = wx.NewId()
  1401. self.data = wx.NewId()
  1402. self.relation = wx.NewId()
  1403. self.run = wx.NewId()
  1404. self.validate = wx.NewId()
  1405. self.settings = wx.NewId()
  1406. self.variables = wx.NewId()
  1407. self.quit = wx.NewId()
  1408. self.redraw = wx.NewId()
  1409. self.help = wx.NewId()
  1410. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  1411. return (
  1412. (self.new, 'new', Icons['modelNew'].GetBitmap(),
  1413. wx.ITEM_NORMAL, Icons['modelNew'].GetLabel(), Icons['modelNew'].GetDesc(),
  1414. self.parent.OnModelNew),
  1415. (self.open, 'open', Icons['modelOpen'].GetBitmap(),
  1416. wx.ITEM_NORMAL, Icons['modelOpen'].GetLabel(), Icons['modelOpen'].GetDesc(),
  1417. self.parent.OnModelOpen),
  1418. (self.save, 'save', Icons['modelSave'].GetBitmap(),
  1419. wx.ITEM_NORMAL, Icons['modelSave'].GetLabel(), Icons['modelSave'].GetDesc(),
  1420. self.parent.OnModelSave),
  1421. (self.image, 'image', Icons['modelToImage'].GetBitmap(),
  1422. wx.ITEM_NORMAL, Icons['modelToImage'].GetLabel(), Icons['modelToImage'].GetDesc(),
  1423. self.parent.OnExportImage),
  1424. (self.python, 'python', Icons['modelToPython'].GetBitmap(),
  1425. wx.ITEM_NORMAL, Icons['modelToPython'].GetLabel(), Icons['modelToPython'].GetDesc(),
  1426. self.parent.OnExportPython),
  1427. ('', '', '', '', '', '', ''),
  1428. (self.action, 'action', Icons['modelActionAdd'].GetBitmap(),
  1429. wx.ITEM_NORMAL, Icons['modelActionAdd'].GetLabel(), Icons['modelActionAdd'].GetDesc(),
  1430. self.parent.OnAddAction),
  1431. (self.data, 'data', Icons['modelDataAdd'].GetBitmap(),
  1432. wx.ITEM_NORMAL, Icons['modelDataAdd'].GetLabel(), Icons['modelDataAdd'].GetDesc(),
  1433. self.parent.OnAddData),
  1434. (self.relation, 'relation', Icons['modelRelation'].GetBitmap(),
  1435. wx.ITEM_NORMAL, Icons['modelRelation'].GetLabel(), Icons['modelRelation'].GetDesc(),
  1436. self.parent.OnDefineRelation),
  1437. ('', '', '', '', '', '', ''),
  1438. (self.redraw, 'redraw', Icons['modelRedraw'].GetBitmap(),
  1439. wx.ITEM_NORMAL, Icons['modelRedraw'].GetLabel(), Icons['modelRedraw'].GetDesc(),
  1440. self.parent.OnCanvasRefresh),
  1441. (self.validate, 'validate', Icons['modelValidate'].GetBitmap(),
  1442. wx.ITEM_NORMAL, Icons['modelValidate'].GetLabel(), Icons['modelValidate'].GetDesc(),
  1443. self.parent.OnValidateModel),
  1444. (self.run, 'run', Icons['modelRun'].GetBitmap(),
  1445. wx.ITEM_NORMAL, Icons['modelRun'].GetLabel(), Icons['modelRun'].GetDesc(),
  1446. self.parent.OnRunModel),
  1447. ('', '', '', '', '', '', ''),
  1448. (self.variables, "variables", Icons["modelVariables"].GetBitmap(),
  1449. wx.ITEM_NORMAL, Icons["modelVariables"].GetLabel(), Icons["modelVariables"].GetDesc(),
  1450. self.parent.OnVariables),
  1451. (self.settings, "settings", Icons["modelSettings"].GetBitmap(),
  1452. wx.ITEM_NORMAL, Icons["modelSettings"].GetLabel(), Icons["modelSettings"].GetDesc(),
  1453. self.parent.OnPreferences),
  1454. (self.help, "help", Icons["modelHelp"].GetBitmap(),
  1455. wx.ITEM_NORMAL, Icons["modelHelp"].GetLabel(), Icons["modelHelp"].GetDesc(),
  1456. self.parent.OnHelp),
  1457. ('', '', '', '', '', '', ''),
  1458. (self.quit, 'quit', Icons['quit'].GetBitmap(),
  1459. wx.ITEM_NORMAL, Icons['quit'].GetLabel(), Icons['quit'].GetDesc(),
  1460. self.parent.OnCloseWindow),
  1461. )
  1462. class HistogramToolbar(AbstractToolbar):
  1463. """!Histogram toolbar (see histogram.py)
  1464. """
  1465. def __init__(self, parent):
  1466. AbstractToolbar.__init__(self, parent)
  1467. self.InitToolbar(self._toolbarData())
  1468. # realize the toolbar
  1469. self.Realize()
  1470. def _toolbarData(self):
  1471. """!Toolbar data"""
  1472. self.histogram = wx.NewId()
  1473. self.rendermap = wx.NewId()
  1474. self.erase = wx.NewId()
  1475. self.font = wx.NewId()
  1476. self.save = wx.NewId()
  1477. self.hprint = wx.NewId()
  1478. self.quit = wx.NewId()
  1479. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  1480. return (
  1481. (self.histogram, 'histogram', Icons["histogram"].GetBitmap(),
  1482. wx.ITEM_NORMAL, Icons["histogram"].GetLabel(), Icons["histogram"].GetDesc(),
  1483. self.parent.OnOptions),
  1484. (self.rendermap, 'rendermap', Icons["displaymap"].GetBitmap(),
  1485. wx.ITEM_NORMAL, Icons["displaymap"].GetLabel(), Icons["displaymap"].GetDesc(),
  1486. self.parent.OnRender),
  1487. (self.erase, 'erase', Icons["erase"].GetBitmap(),
  1488. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  1489. self.parent.OnErase),
  1490. (self.font, 'font', Icons["font"].GetBitmap(),
  1491. wx.ITEM_NORMAL, Icons["font"].GetLabel(), Icons["font"].GetDesc(),
  1492. self.parent.SetHistFont),
  1493. ('', '', '', '', '', '', ''),
  1494. (self.save, 'save', Icons["savefile"].GetBitmap(),
  1495. wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
  1496. self.parent.SaveToFile),
  1497. (self.hprint, 'print', Icons["printmap"].GetBitmap(),
  1498. wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
  1499. self.parent.PrintMenu),
  1500. ('', '', '', '', '', '', ''),
  1501. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  1502. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  1503. self.parent.OnQuit)
  1504. )
  1505. class LayerManagerToolbar(AbstractToolbar):
  1506. """!Layer Manager toolbar (see wxgui.py)
  1507. """
  1508. def __init__(self, parent):
  1509. AbstractToolbar.__init__(self, parent)
  1510. self.InitToolbar(self._toolbarData())
  1511. # realize the toolbar
  1512. self.Realize()
  1513. def _toolbarData(self):
  1514. """!Toolbar data
  1515. """
  1516. self.newdisplay = wx.NewId()
  1517. self.workspaceLoad = wx.NewId()
  1518. self.workspaceOpen = wx.NewId()
  1519. self.workspaceSave = wx.NewId()
  1520. self.addrast = wx.NewId()
  1521. self.rastmisc = wx.NewId()
  1522. self.addvect = wx.NewId()
  1523. self.vectmisc = wx.NewId()
  1524. self.addgrp = wx.NewId()
  1525. self.addovl = wx.NewId()
  1526. self.delcmd = wx.NewId()
  1527. self.attribute = wx.NewId()
  1528. self.vdigit = wx.NewId()
  1529. self.preferences = wx.NewId()
  1530. self.modeler = wx.NewId()
  1531. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  1532. return (
  1533. (self.newdisplay, 'newdisplay', Icons["newdisplay"].GetBitmap(),
  1534. wx.ITEM_NORMAL, _("Start new display / create new workspace"), '',
  1535. self.parent.OnNewMenu),
  1536. ('', '', '', '', '', '', ''),
  1537. (self.workspaceLoad, 'workspaceLoad', Icons["workspaceLoad"].GetBitmap(),
  1538. wx.ITEM_NORMAL, _("Load / import map layers into workspace"), '',
  1539. self.parent.OnLoadMenu),
  1540. (self.workspaceOpen, 'workspaceOpen', Icons["workspaceOpen"].GetBitmap(),
  1541. wx.ITEM_NORMAL, Icons["workspaceOpen"].GetLabel(), Icons["workspaceOpen"].GetDesc(),
  1542. self.parent.OnWorkspaceOpen),
  1543. (self.workspaceSave, 'workspaceSave', Icons["workspaceSave"].GetBitmap(),
  1544. wx.ITEM_NORMAL, Icons["workspaceSave"].GetLabel(), Icons["workspaceSave"].GetDesc(),
  1545. self.parent.OnWorkspaceSave),
  1546. ('', '', '', '', '', '', ''),
  1547. (self.addrast, 'addrast', Icons["addrast"].GetBitmap(),
  1548. wx.ITEM_NORMAL, Icons["addrast"].GetLabel(), Icons["addrast"].GetDesc(),
  1549. self.parent.OnAddRaster),
  1550. (self.rastmisc, 'rastmisc', Icons["rastmisc"].GetBitmap(),
  1551. wx.ITEM_NORMAL, Icons["rastmisc"].GetLabel(), Icons["rastmisc"].GetDesc(),
  1552. self.parent.OnAddRasterMisc),
  1553. (self.addvect, 'addvect', Icons["addvect"].GetBitmap(),
  1554. wx.ITEM_NORMAL, Icons["addvect"].GetLabel(), Icons["addvect"].GetDesc(),
  1555. self.parent.OnAddVector),
  1556. (self.vectmisc, 'vectmisc', Icons["vectmisc"].GetBitmap(),
  1557. wx.ITEM_NORMAL, Icons["vectmisc"].GetLabel(), Icons["vectmisc"].GetDesc(),
  1558. self.parent.OnAddVectorMisc),
  1559. (self.addgrp, 'addgrp', Icons["addgrp"].GetBitmap(),
  1560. wx.ITEM_NORMAL, Icons["addgrp"].GetLabel(), Icons["addgrp"].GetDesc(),
  1561. self.parent.OnAddGroup),
  1562. (self.addovl, 'addovl', Icons["addovl"].GetBitmap(),
  1563. wx.ITEM_NORMAL, Icons["addovl"].GetLabel(), Icons["addovl"].GetDesc(),
  1564. self.parent.OnAddOverlay),
  1565. (self.delcmd, 'delcmd', Icons["delcmd"].GetBitmap(),
  1566. wx.ITEM_NORMAL, Icons["delcmd"].GetLabel(), Icons["delcmd"].GetDesc(),
  1567. self.parent.OnDeleteLayer),
  1568. ('', '', '', '', '', '', ''),
  1569. (self.vdigit, 'vdigit', Icons["vdigit"].GetBitmap(),
  1570. wx.ITEM_NORMAL, Icons["vdigit"].GetLabel(), Icons["vdigit"].GetDesc(),
  1571. self.parent.OnVDigit),
  1572. (self.attribute, 'attrtable', Icons["attrtable"].GetBitmap(),
  1573. wx.ITEM_NORMAL, Icons["attrtable"].GetLabel(), Icons["attrtable"].GetDesc(),
  1574. self.parent.OnShowAttributeTable),
  1575. ('', '', '', '', '', '', ''),
  1576. (self.modeler, 'modeler', Icons["modeler"].GetBitmap(),
  1577. wx.ITEM_NORMAL, Icons["modeler"].GetLabel(), Icons["modeler"].GetDesc(),
  1578. self.parent.OnGModeler),
  1579. (self.preferences, 'preferences', Icons["settings"].GetBitmap(),
  1580. wx.ITEM_NORMAL, Icons["settings"].GetLabel(), Icons["settings"].GetDesc(),
  1581. self.parent.OnPreferences)
  1582. )