toolbars.py 76 KB

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