toolbars.py 76 KB

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