toolbars.py 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838
  1. """!
  2. @package toolbar
  3. @brief wxGUI toolbar widgets
  4. Classes:
  5. - AbstractToolbar
  6. - MapToolbar
  7. - GRToolbar
  8. - GCPToolbar
  9. - VDigitToolbar
  10. - ProfileToolbar
  11. - NvizToolbar
  12. - ModelToolbar
  13. - HistogramToolbar
  14. - LayerManagerToolbar
  15. (C) 2007-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. """!Toolbar for managing ground control points
  293. @param parent reference to GCP widget
  294. """
  295. def __init__(self, parent):
  296. AbstractToolbar.__init__(self, parent)
  297. self.InitToolbar(self.ToolbarData())
  298. # realize the toolbar
  299. self.Realize()
  300. def ToolbarData(self):
  301. self.gcpSave = wx.NewId()
  302. self.gcpReload = wx.NewId()
  303. self.gcpAdd = wx.NewId()
  304. self.gcpDelete = wx.NewId()
  305. self.gcpClear = wx.NewId()
  306. self.rms = wx.NewId()
  307. self.georect = wx.NewId()
  308. return (
  309. (self.gcpSave, 'grGcpSave', Icons["grGcpSave"].GetBitmap(),
  310. wx.ITEM_NORMAL, Icons["grGcpSave"].GetLabel(), Icons["grGcpSave"].GetDesc(),
  311. self.parent.SaveGCPs),
  312. (self.gcpReload, 'grGcpReload', Icons["grGcpReload"].GetBitmap(),
  313. wx.ITEM_NORMAL, Icons["grGcpReload"].GetLabel(), Icons["grGcpReload"].GetDesc(),
  314. self.parent.ReloadGCPs),
  315. ("", "", "", "", "", "", ""),
  316. (self.gcpAdd, 'grGrGcpAdd', Icons["grGcpAdd"].GetBitmap(),
  317. wx.ITEM_NORMAL, Icons["grGcpAdd"].GetLabel(), Icons["grGcpAdd"].GetDesc(),
  318. self.parent.AddGCP),
  319. (self.gcpDelete, 'grGrGcpDelete', Icons["grGcpDelete"].GetBitmap(),
  320. wx.ITEM_NORMAL, Icons["grGcpDelete"].GetLabel(), Icons["grGcpDelete"].GetDesc(),
  321. self.parent.DeleteGCP),
  322. (self.gcpClear, 'grGcpClear', Icons["grGcpClear"].GetBitmap(),
  323. wx.ITEM_NORMAL, Icons["grGcpClear"].GetLabel(), Icons["grGcpClear"].GetDesc(),
  324. self.parent.ClearGCP),
  325. ("", "", "", "", "", "", ""),
  326. (self.rms, 'grGcpRms', Icons["grGcpRms"].GetBitmap(),
  327. wx.ITEM_NORMAL, Icons["grGcpRms"].GetLabel(), Icons["grGcpRms"].GetDesc(),
  328. self.parent.OnRMS),
  329. (self.georect, 'grGeorect', Icons["grGeorect"].GetBitmap(),
  330. wx.ITEM_NORMAL, Icons["grGeorect"].GetLabel(), Icons["grGeorect"].GetDesc(),
  331. self.parent.OnGeorect),
  332. )
  333. class GCPDisplayToolbar(AbstractToolbar):
  334. """!GCP Display toolbar
  335. """
  336. def __init__(self, parent):
  337. """!GCP Display toolbar constructor
  338. """
  339. AbstractToolbar.__init__(self, parent)
  340. self.InitToolbar(self.ToolbarData())
  341. # add tool to toggle active map window
  342. self.togglemapid = wx.NewId()
  343. self.togglemap = wx.Choice(parent = self, id = self.togglemapid,
  344. choices = [_('source'), _('target')],
  345. style = wx.CB_READONLY)
  346. self.InsertControl(10, self.togglemap)
  347. self.SetToolShortHelp(self.togglemapid, '%s %s %s' % (_('Set map canvas for '),
  348. Icons["zoom_back"].GetLabel(),
  349. _(' / Zoom to map')))
  350. # realize the toolbar
  351. self.Realize()
  352. self.action = { 'id' : self.gcpset }
  353. self.defaultAction = { 'id' : self.gcpset,
  354. 'bind' : self.parent.OnPointer }
  355. self.OnTool(None)
  356. self.EnableTool(self.zoomback, False)
  357. def ToolbarData(self):
  358. """!Toolbar data"""
  359. self.displaymap = wx.NewId()
  360. self.rendermap = wx.NewId()
  361. self.erase = wx.NewId()
  362. self.gcpset = wx.NewId()
  363. self.pan = wx.NewId()
  364. self.zoomin = wx.NewId()
  365. self.zoomout = wx.NewId()
  366. self.zoomback = wx.NewId()
  367. self.zoomtomap = wx.NewId()
  368. self.zoommenu = wx.NewId()
  369. self.settings = wx.NewId()
  370. self.helpid = wx.NewId()
  371. self.quit = wx.NewId()
  372. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  373. return (
  374. (self.displaymap, "displaymap", Icons["displaymap"].GetBitmap(),
  375. wx.ITEM_NORMAL, Icons["displaymap"].GetLabel(), Icons["displaymap"].GetDesc(),
  376. self.parent.OnDraw),
  377. (self.rendermap, "rendermap", Icons["rendermap"].GetBitmap(),
  378. wx.ITEM_NORMAL, Icons["rendermap"].GetLabel(), Icons["rendermap"].GetDesc(),
  379. self.parent.OnRender),
  380. (self.erase, "erase", Icons["erase"].GetBitmap(),
  381. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  382. self.parent.OnErase),
  383. ("", "", "", "", "", "", ""),
  384. (self.gcpset, "grGcpSet", Icons["grGcpSet"].GetBitmap(),
  385. wx.ITEM_RADIO, Icons["grGcpSet"].GetLabel(), Icons["grGcpSet"].GetDesc(),
  386. self.parent.OnPointer),
  387. (self.pan, "pan", Icons["pan"].GetBitmap(),
  388. wx.ITEM_RADIO, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  389. self.parent.OnPan),
  390. (self.zoomin, "zoom_in", Icons["zoom_in"].GetBitmap(),
  391. wx.ITEM_RADIO, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  392. self.parent.OnZoomIn),
  393. (self.zoomout, "zoom_out", Icons["zoom_out"].GetBitmap(),
  394. wx.ITEM_RADIO, Icons["zoom_out"].GetLabel(), Icons["zoom_out"].GetDesc(),
  395. self.parent.OnZoomOut),
  396. (self.zoommenu, "zoommenu", Icons["zoommenu"].GetBitmap(),
  397. wx.ITEM_NORMAL, _("Adjust display zoom"), Icons["zoommenu"].GetDesc(),
  398. self.parent.OnZoomMenuGCP),
  399. ("", "", "", "", "", "", ""),
  400. (self.zoomback, "zoom_back", Icons["zoom_back"].GetBitmap(),
  401. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  402. self.parent.OnZoomBack),
  403. (self.zoomtomap, "zoomtomap", Icons["zoom_extent"].GetBitmap(),
  404. wx.ITEM_NORMAL, _("Zoom to map"), _("Zoom to displayed map"),
  405. self.parent.OnZoomToMap),
  406. ("", "", "", "", "", "", ""),
  407. (self.settings, 'grSettings', Icons["grSettings"].GetBitmap(),
  408. wx.ITEM_NORMAL, Icons["grSettings"].GetLabel(), Icons["grSettings"].GetDesc(),
  409. self.parent.OnSettings),
  410. (self.helpid, 'grHelp', Icons["grHelp"].GetBitmap(),
  411. wx.ITEM_NORMAL, Icons["grHelp"].GetLabel(), Icons["grHelp"].GetDesc(),
  412. self.parent.OnHelp),
  413. ("", "", "", "", "", "", ""),
  414. (self.quit, 'grGcpQuit', Icons["grGcpQuit"].GetBitmap(),
  415. wx.ITEM_NORMAL, Icons["grGcpQuit"].GetLabel(), Icons["grGcpQuit"].GetDesc(),
  416. self.parent.OnQuit)
  417. )
  418. class GRToolbar(AbstractToolbar):
  419. """!Georectification toolbar
  420. """
  421. def __init__(self, parent, mapcontent):
  422. """!Georectification toolbar constructor
  423. @param parent reference to MapFrame
  424. @param mapcontent reference to render.Map (registred by MapFrame)
  425. """
  426. self.mapcontent = mapcontent
  427. AbstractToolbar.__init__(self, parent)
  428. self.InitToolbar(self.ToolbarData())
  429. # realize the toolbar
  430. self.Realize()
  431. self.action = { 'id' : self.gcpset }
  432. self.defaultAction = { 'id' : self.gcpset,
  433. 'bind' : self.parent.OnPointer }
  434. self.OnTool(None)
  435. self.EnableTool(self.zoomback, False)
  436. def ToolbarData(self):
  437. """!Toolbar data"""
  438. self.displaymap = wx.NewId()
  439. self.rendermap = wx.NewId()
  440. self.erase = wx.NewId()
  441. self.gcpset = wx.NewId()
  442. self.pan = wx.NewId()
  443. self.zoomin = wx.NewId()
  444. self.zoomout = wx.NewId()
  445. self.zoomback = wx.NewId()
  446. self.zoomtomap = wx.NewId()
  447. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  448. return (
  449. (self.displaymap, "displaymap", Icons["displaymap"].GetBitmap(),
  450. wx.ITEM_NORMAL, Icons["displaymap"].GetLabel(), Icons["displaymap"].GetDesc(),
  451. self.parent.OnDraw),
  452. (self.rendermap, "rendermap", Icons["rendermap"].GetBitmap(),
  453. wx.ITEM_NORMAL, Icons["rendermap"].GetLabel(), Icons["rendermap"].GetDesc(),
  454. self.parent.OnRender),
  455. (self.erase, "erase", Icons["erase"].GetBitmap(),
  456. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  457. self.parent.OnErase),
  458. ("", "", "", "", "", "", ""),
  459. (self.gcpset, "grGcpSet", Icons["grGcpSet"].GetBitmap(),
  460. wx.ITEM_RADIO, Icons["grGcpSet"].GetLabel(), Icons["grGcpSet"].GetDesc(),
  461. self.parent.OnPointer),
  462. (self.pan, "pan", Icons["pan"].GetBitmap(),
  463. wx.ITEM_RADIO, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  464. self.parent.OnPan),
  465. (self.zoomin, "zoom_in", Icons["zoom_in"].GetBitmap(),
  466. wx.ITEM_RADIO, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  467. self.parent.OnZoomIn),
  468. (self.zoomout, "zoom_out", Icons["zoom_out"].GetBitmap(),
  469. wx.ITEM_RADIO, Icons["zoom_out"].GetLabel(), Icons["zoom_out"].GetDesc(),
  470. self.parent.OnZoomOut),
  471. (self.zoomback, "zoom_back", Icons["zoom_back"].GetBitmap(),
  472. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  473. self.parent.OnZoomBack),
  474. (self.zoomtomap, "zoomtomap", Icons["zoommenu"].GetBitmap(),
  475. wx.ITEM_NORMAL, _("Zoom to map"), _("Zoom to displayed map"),
  476. self.OnZoomMap),
  477. )
  478. def OnZoomMap(self, event):
  479. """!Zoom to selected map"""
  480. self.parent.MapWindow.ZoomToMap(layers = self.mapcontent.GetListOfLayers())
  481. if event:
  482. event.Skip()
  483. class GCPToolbar(AbstractToolbar):
  484. """!Toolbar for managing ground control points during
  485. georectification
  486. @param parent reference to GCP widget
  487. """
  488. def __init__(self, parent):
  489. AbstractToolbar.__init__(self, parent)
  490. self.InitToolbar(self.ToolbarData())
  491. # realize the toolbar
  492. self.Realize()
  493. def ToolbarData(self):
  494. self.gcpSave = wx.NewId()
  495. self.gcpAdd = wx.NewId()
  496. self.gcpDelete = wx.NewId()
  497. self.gcpClear = wx.NewId()
  498. self.gcpReload = wx.NewId()
  499. self.rms = wx.NewId()
  500. self.georect = wx.NewId()
  501. self.settings = wx.NewId()
  502. self.quit = wx.NewId()
  503. return (
  504. (self.gcpSave, 'grGcpSave', Icons["grGcpSave"].GetBitmap(),
  505. wx.ITEM_NORMAL, Icons["grGcpSave"].GetLabel(), Icons["grGcpSave"].GetDesc(),
  506. self.parent.SaveGCPs),
  507. (self.gcpAdd, 'grGrGcpAdd', Icons["grGcpAdd"].GetBitmap(),
  508. wx.ITEM_NORMAL, Icons["grGcpAdd"].GetLabel(), Icons["grGcpAdd"].GetDesc(),
  509. self.parent.AddGCP),
  510. (self.gcpDelete, 'grGrGcpDelete', Icons["grGcpDelete"].GetBitmap(),
  511. wx.ITEM_NORMAL, Icons["grGcpDelete"].GetLabel(), Icons["grGcpDelete"].GetDesc(),
  512. self.parent.DeleteGCP),
  513. (self.gcpClear, 'grGcpClear', Icons["grGcpClear"].GetBitmap(),
  514. wx.ITEM_NORMAL, Icons["grGcpClear"].GetLabel(), Icons["grGcpClear"].GetDesc(),
  515. self.parent.ClearGCP),
  516. (self.gcpReload, 'grGcpReload', Icons["grGcpReload"].GetBitmap(),
  517. wx.ITEM_NORMAL, Icons["grGcpReload"].GetLabel(), Icons["grGcpReload"].GetDesc(),
  518. self.parent.ReloadGCPs),
  519. ("", "", "", "", "", "", ""),
  520. (self.rms, 'grGcpRms', Icons["grGcpRms"].GetBitmap(),
  521. wx.ITEM_NORMAL, Icons["grGcpRms"].GetLabel(), Icons["grGcpRms"].GetDesc(),
  522. self.parent.OnRMS),
  523. (self.georect, 'grGeorect', Icons["grGeorect"].GetBitmap(),
  524. wx.ITEM_NORMAL, Icons["grGeorect"].GetLabel(), Icons["grGeorect"].GetDesc(),
  525. self.parent.OnGeorect),
  526. ("", "", "", "", "", "", ""),
  527. (self.settings, 'grSettings', Icons["grSettings"].GetBitmap(),
  528. wx.ITEM_NORMAL, Icons["grSettings"].GetLabel(), Icons["grSettings"].GetDesc(),
  529. self.parent.OnSettings),
  530. (self.quit, 'grGcpQuit', Icons["grGcpQuit"].GetBitmap(),
  531. wx.ITEM_NORMAL, Icons["grGcpQuit"].GetLabel(), Icons["grGcpQuit"].GetDesc(),
  532. self.parent.OnQuit)
  533. )
  534. class VDigitToolbar(AbstractToolbar):
  535. """
  536. Toolbar for digitization
  537. """
  538. def __init__(self, parent, mapcontent, layerTree = None, log = None):
  539. self.mapcontent = mapcontent # Map class instance
  540. self.layerTree = layerTree # reference to layer tree associated to map display
  541. self.log = log # log area
  542. AbstractToolbar.__init__(self, parent)
  543. # currently selected map layer for editing (reference to MapLayer instance)
  544. self.mapLayer = None
  545. # list of vector layers from Layer Manager (only in the current mapset)
  546. self.layers = []
  547. self.comboid = None
  548. # only one dialog can be open
  549. self.settingsDialog = None
  550. # create toolbars (two rows optionally)
  551. self.InitToolbar(self.ToolbarData())
  552. self.Bind(wx.EVT_TOOL, self.OnTool)
  553. # default action (digitize new point, line, etc.)
  554. self.action = { 'desc' : 'addLine',
  555. 'type' : 'point',
  556. 'id' : self.addPoint }
  557. # list of available vector maps
  558. self.UpdateListOfLayers(updateTool = True)
  559. # realize toolbar
  560. self.Realize()
  561. # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
  562. self.combo.Hide()
  563. self.combo.Show()
  564. # disable undo/redo
  565. self.EnableTool(self.undo, False)
  566. # toogle to pointer by default
  567. self.OnTool(None)
  568. self.FixSize(width = 105)
  569. def ToolbarData(self):
  570. """!
  571. Toolbar data
  572. """
  573. data = []
  574. self.addPoint = wx.NewId()
  575. self.addLine = wx.NewId()
  576. self.addBoundary = wx.NewId()
  577. self.addCentroid = wx.NewId()
  578. self.moveVertex = wx.NewId()
  579. self.addVertex = wx.NewId()
  580. self.removeVertex = wx.NewId()
  581. self.splitLine = wx.NewId()
  582. self.editLine = wx.NewId()
  583. self.moveLine = wx.NewId()
  584. self.deleteLine = wx.NewId()
  585. self.additionalTools = wx.NewId()
  586. self.displayCats = wx.NewId()
  587. self.displayAttr = wx.NewId()
  588. self.copyCats = wx.NewId()
  589. self.undo = wx.NewId()
  590. self.settings = wx.NewId()
  591. self.exit = wx.NewId()
  592. data = [("", "", "", "", "", "", ""),
  593. (self.addPoint, "digAddPoint", Icons["digAddPoint"].GetBitmap(),
  594. wx.ITEM_CHECK, Icons["digAddPoint"].GetLabel(), Icons["digAddPoint"].GetDesc(),
  595. self.OnAddPoint),
  596. (self.addLine, "digAddLine", Icons["digAddLine"].GetBitmap(),
  597. wx.ITEM_CHECK, Icons["digAddLine"].GetLabel(), Icons["digAddLine"].GetDesc(),
  598. self.OnAddLine),
  599. (self.addBoundary, "digAddBoundary", Icons["digAddBoundary"].GetBitmap(),
  600. wx.ITEM_CHECK, Icons["digAddBoundary"].GetLabel(), Icons["digAddBoundary"].GetDesc(),
  601. self.OnAddBoundary),
  602. (self.addCentroid, "digAddCentroid", Icons["digAddCentroid"].GetBitmap(),
  603. wx.ITEM_CHECK, Icons["digAddCentroid"].GetLabel(), Icons["digAddCentroid"].GetDesc(),
  604. self.OnAddCentroid),
  605. (self.moveVertex, "digMoveVertex", Icons["digMoveVertex"].GetBitmap(),
  606. wx.ITEM_CHECK, Icons["digMoveVertex"].GetLabel(), Icons["digMoveVertex"].GetDesc(),
  607. self.OnMoveVertex),
  608. (self.addVertex, "digAddVertex", Icons["digAddVertex"].GetBitmap(),
  609. wx.ITEM_CHECK, Icons["digAddVertex"].GetLabel(), Icons["digAddVertex"].GetDesc(),
  610. self.OnAddVertex),
  611. (self.removeVertex, "digRemoveVertex", Icons["digRemoveVertex"].GetBitmap(),
  612. wx.ITEM_CHECK, Icons["digRemoveVertex"].GetLabel(), Icons["digRemoveVertex"].GetDesc(),
  613. self.OnRemoveVertex),
  614. (self.splitLine, "digSplitLine", Icons["digSplitLine"].GetBitmap(),
  615. wx.ITEM_CHECK, Icons["digSplitLine"].GetLabel(), Icons["digSplitLine"].GetDesc(),
  616. self.OnSplitLine),
  617. (self.editLine, "digEditLine", Icons["digEditLine"].GetBitmap(),
  618. wx.ITEM_CHECK, Icons["digEditLine"].GetLabel(), Icons["digEditLine"].GetDesc(),
  619. self.OnEditLine),
  620. (self.moveLine, "digMoveLine", Icons["digMoveLine"].GetBitmap(),
  621. wx.ITEM_CHECK, Icons["digMoveLine"].GetLabel(), Icons["digMoveLine"].GetDesc(),
  622. self.OnMoveLine),
  623. (self.deleteLine, "digDeleteLine", Icons["digDeleteLine"].GetBitmap(),
  624. wx.ITEM_CHECK, Icons["digDeleteLine"].GetLabel(), Icons["digDeleteLine"].GetDesc(),
  625. self.OnDeleteLine),
  626. (self.displayCats, "digDispCats", Icons["digDispCats"].GetBitmap(),
  627. wx.ITEM_CHECK, Icons["digDispCats"].GetLabel(), Icons["digDispCats"].GetDesc(),
  628. self.OnDisplayCats),
  629. (self.copyCats, "digCopyCats", Icons["digCopyCats"].GetBitmap(),
  630. wx.ITEM_CHECK, Icons["digCopyCats"].GetLabel(), Icons["digCopyCats"].GetDesc(),
  631. self.OnCopyCA),
  632. (self.displayAttr, "digDispAttr", Icons["digDispAttr"].GetBitmap(),
  633. wx.ITEM_CHECK, Icons["digDispAttr"].GetLabel(), Icons["digDispAttr"].GetDesc(),
  634. self.OnDisplayAttr),
  635. (self.additionalTools, "digAdditionalTools", Icons["digAdditionalTools"].GetBitmap(),
  636. wx.ITEM_CHECK, Icons["digAdditionalTools"].GetLabel(),
  637. Icons["digAdditionalTools"].GetDesc(),
  638. self.OnAdditionalToolMenu),
  639. ("", "", "", "", "", "", ""),
  640. (self.undo, "digUndo", Icons["digUndo"].GetBitmap(),
  641. wx.ITEM_NORMAL, Icons["digUndo"].GetLabel(), Icons["digUndo"].GetDesc(),
  642. self.OnUndo),
  643. # data.append((self.undo, "digRedo", Icons["digRedo"].GetBitmap(),
  644. # wx.ITEM_NORMAL, Icons["digRedo"].GetLabel(), Icons["digRedo"].GetDesc(),
  645. # self.OnRedo))
  646. (self.settings, "digSettings", Icons["digSettings"].GetBitmap(),
  647. wx.ITEM_NORMAL, Icons["digSettings"].GetLabel(), Icons["digSettings"].GetDesc(),
  648. self.OnSettings),
  649. (self.exit, "digExit", Icons["quit"].GetBitmap(),
  650. wx.ITEM_NORMAL, Icons["digExit"].GetLabel(), Icons["digExit"].GetDesc(),
  651. self.OnExit)]
  652. return data
  653. def OnTool(self, event):
  654. """!Tool selected -> disable selected tool in map toolbar"""
  655. id = self.parent.toolbars['map'].GetAction(type = 'id')
  656. self.parent.toolbars['map'].ToggleTool(id, False)
  657. # set cursor
  658. cursor = self.parent.cursors["cross"]
  659. self.parent.MapWindow.SetCursor(cursor)
  660. # pointer
  661. self.parent.OnPointer(None)
  662. if event:
  663. # deselect previously selected tool
  664. id = self.action.get('id', -1)
  665. if id != event.GetId():
  666. self.ToggleTool(self.action['id'], False)
  667. else:
  668. self.ToggleTool(self.action['id'], True)
  669. self.action['id'] = event.GetId()
  670. event.Skip()
  671. self.ToggleTool(self.action['id'], True)
  672. # clear tmp canvas
  673. if self.action['id'] != id:
  674. self.parent.MapWindow.ClearLines(pdc = self.parent.MapWindow.pdcTmp)
  675. if self.parent.digit and \
  676. len(self.parent.digit.driver.GetSelected()) > 0:
  677. # cancel action
  678. self.parent.MapWindow.OnMiddleDown(None)
  679. # set focus
  680. self.parent.MapWindow.SetFocus()
  681. def OnAddPoint(self, event):
  682. """!Add point to the vector map Laier"""
  683. Debug.msg (2, "VDigitToolbar.OnAddPoint()")
  684. self.action = { 'desc' : "addLine",
  685. 'type' : "point",
  686. 'id' : self.addPoint }
  687. self.parent.MapWindow.mouse['box'] = 'point'
  688. def OnAddLine(self, event):
  689. """!Add line to the vector map layer"""
  690. Debug.msg (2, "VDigitToolbar.OnAddLine()")
  691. self.action = { 'desc' : "addLine",
  692. 'type' : "line",
  693. 'id' : self.addLine }
  694. self.parent.MapWindow.mouse['box'] = 'line'
  695. ### self.parent.MapWindow.polycoords = [] # reset temp line
  696. def OnAddBoundary(self, event):
  697. """!Add boundary to the vector map layer"""
  698. Debug.msg (2, "VDigitToolbar.OnAddBoundary()")
  699. if self.action['desc'] != 'addLine' or \
  700. self.action['type'] != 'boundary':
  701. self.parent.MapWindow.polycoords = [] # reset temp line
  702. self.action = { 'desc' : "addLine",
  703. 'type' : "boundary",
  704. 'id' : self.addBoundary }
  705. self.parent.MapWindow.mouse['box'] = 'line'
  706. def OnAddCentroid(self, event):
  707. """!Add centroid to the vector map layer"""
  708. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  709. self.action = { 'desc' : "addLine",
  710. 'type' : "centroid",
  711. 'id' : self.addCentroid }
  712. self.parent.MapWindow.mouse['box'] = 'point'
  713. def OnExit (self, event=None):
  714. """!Quit digitization tool"""
  715. # stop editing of the currently selected map layer
  716. if self.mapLayer:
  717. self.StopEditing()
  718. # close dialogs if still open
  719. if self.settingsDialog:
  720. self.settingsDialog.OnCancel(None)
  721. # set default mouse settings
  722. self.parent.MapWindow.mouse['use'] = "pointer"
  723. self.parent.MapWindow.mouse['box'] = "point"
  724. self.parent.MapWindow.polycoords = []
  725. # disable the toolbar
  726. self.parent.RemoveToolbar("vdigit")
  727. def OnMoveVertex(self, event):
  728. """!Move line vertex"""
  729. Debug.msg(2, "Digittoolbar.OnMoveVertex():")
  730. self.action = { 'desc' : "moveVertex",
  731. 'id' : self.moveVertex }
  732. self.parent.MapWindow.mouse['box'] = 'point'
  733. def OnAddVertex(self, event):
  734. """!Add line vertex"""
  735. Debug.msg(2, "Digittoolbar.OnAddVertex():")
  736. self.action = { 'desc' : "addVertex",
  737. 'id' : self.addVertex }
  738. self.parent.MapWindow.mouse['box'] = 'point'
  739. def OnRemoveVertex(self, event):
  740. """!Remove line vertex"""
  741. Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
  742. self.action = { 'desc' : "removeVertex",
  743. 'id' : self.removeVertex }
  744. self.parent.MapWindow.mouse['box'] = 'point'
  745. def OnSplitLine(self, event):
  746. """!Split line"""
  747. Debug.msg(2, "Digittoolbar.OnSplitLine():")
  748. self.action = { 'desc' : "splitLine",
  749. 'id' : self.splitLine }
  750. self.parent.MapWindow.mouse['box'] = 'point'
  751. def OnEditLine(self, event):
  752. """!Edit line"""
  753. Debug.msg(2, "Digittoolbar.OnEditLine():")
  754. self.action = { 'desc' : "editLine",
  755. 'id' : self.editLine }
  756. self.parent.MapWindow.mouse['box'] = 'line'
  757. def OnMoveLine(self, event):
  758. """!Move line"""
  759. Debug.msg(2, "Digittoolbar.OnMoveLine():")
  760. self.action = { 'desc' : "moveLine",
  761. 'id' : self.moveLine }
  762. self.parent.MapWindow.mouse['box'] = 'box'
  763. def OnDeleteLine(self, event):
  764. """!Delete line"""
  765. Debug.msg(2, "Digittoolbar.OnDeleteLine():")
  766. self.action = { 'desc' : "deleteLine",
  767. 'id' : self.deleteLine }
  768. self.parent.MapWindow.mouse['box'] = 'box'
  769. def OnDisplayCats(self, event):
  770. """!Display/update categories"""
  771. Debug.msg(2, "Digittoolbar.OnDisplayCats():")
  772. self.action = { 'desc' : "displayCats",
  773. 'id' : self.displayCats }
  774. self.parent.MapWindow.mouse['box'] = 'point'
  775. def OnDisplayAttr(self, event):
  776. """!Display/update attributes"""
  777. Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
  778. self.action = { 'desc' : "displayAttrs",
  779. 'id' : self.displayAttr }
  780. self.parent.MapWindow.mouse['box'] = 'point'
  781. def OnCopyCA(self, event):
  782. """!Copy categories/attributes menu"""
  783. point = wx.GetMousePosition()
  784. toolMenu = wx.Menu()
  785. # Add items to the menu
  786. cats = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  787. text = _('Copy categories'),
  788. kind = wx.ITEM_CHECK)
  789. toolMenu.AppendItem(cats)
  790. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyCats, cats)
  791. if self.action['desc'] == "copyCats":
  792. cats.Check(True)
  793. attrb = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  794. text = _('Duplicate attributes'),
  795. kind = wx.ITEM_CHECK)
  796. toolMenu.AppendItem(attrb)
  797. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyAttrb, attrb)
  798. if self.action['desc'] == "copyAttrs":
  799. attrb.Check(True)
  800. # Popup the menu. If an item is selected then its handler
  801. # will be called before PopupMenu returns.
  802. self.parent.MapWindow.PopupMenu(toolMenu)
  803. toolMenu.Destroy()
  804. if self.action['desc'] == "addPoint":
  805. self.ToggleTool(self.copyCats, False)
  806. def OnCopyCats(self, event):
  807. """!Copy categories"""
  808. if self.action['desc'] == 'copyCats': # select previous action
  809. self.ToggleTool(self.addPoint, True)
  810. self.ToggleTool(self.copyCats, False)
  811. self.OnAddPoint(event)
  812. return
  813. Debug.msg(2, "Digittoolbar.OnCopyCats():")
  814. self.action = { 'desc' : "copyCats",
  815. 'id' : self.copyCats }
  816. self.parent.MapWindow.mouse['box'] = 'point'
  817. def OnCopyAttrb(self, event):
  818. if self.action['desc'] == 'copyAttrs': # select previous action
  819. self.ToggleTool(self.addPoint, True)
  820. self.ToggleTool(self.copyCats, False)
  821. self.OnAddPoint(event)
  822. return
  823. Debug.msg(2, "Digittoolbar.OnCopyAttrb():")
  824. self.action = { 'desc' : "copyAttrs",
  825. 'id' : self.copyCats }
  826. self.parent.MapWindow.mouse['box'] = 'point'
  827. def OnUndo(self, event):
  828. """!Undo previous changes"""
  829. self.parent.digit.Undo()
  830. event.Skip()
  831. def EnableUndo(self, enable=True):
  832. """!Enable 'Undo' in toolbar
  833. @param enable False for disable
  834. """
  835. if enable:
  836. if self.GetToolEnabled(self.undo) is False:
  837. self.EnableTool(self.undo, True)
  838. else:
  839. if self.GetToolEnabled(self.undo) is True:
  840. self.EnableTool(self.undo, False)
  841. def OnSettings(self, event):
  842. """!Show settings dialog"""
  843. if self.parent.digit is None:
  844. reload(vdigit)
  845. from vdigit import VDigit as VDigit
  846. try:
  847. self.parent.digit = VDigit(mapwindow=self.parent.MapWindow)
  848. except SystemExit:
  849. self.parent.digit = None
  850. if not self.settingsDialog:
  851. self.settingsDialog = VDigitSettingsDialog(parent = self.parent, title = _("Digitization settings"),
  852. style = wx.DEFAULT_DIALOG_STYLE)
  853. self.settingsDialog.Show()
  854. def OnAdditionalToolMenu(self, event):
  855. """!Menu for additional tools"""
  856. point = wx.GetMousePosition()
  857. toolMenu = wx.Menu()
  858. # Add items to the menu
  859. copy = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  860. text = _('Copy features from (background) vector map'),
  861. kind = wx.ITEM_CHECK)
  862. toolMenu.AppendItem(copy)
  863. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopy, copy)
  864. if self.action['desc'] == "copyLine":
  865. copy.Check(True)
  866. flip = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  867. text = _('Flip selected lines/boundaries'),
  868. kind = wx.ITEM_CHECK)
  869. toolMenu.AppendItem(flip)
  870. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnFlip, flip)
  871. if self.action['desc'] == "flipLine":
  872. flip.Check(True)
  873. merge = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  874. text = _('Merge selected lines/boundaries'),
  875. kind = wx.ITEM_CHECK)
  876. toolMenu.AppendItem(merge)
  877. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnMerge, merge)
  878. if self.action['desc'] == "mergeLine":
  879. merge.Check(True)
  880. breakL = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  881. text = _('Break selected lines/boundaries at intersection'),
  882. kind = wx.ITEM_CHECK)
  883. toolMenu.AppendItem(breakL)
  884. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnBreak, breakL)
  885. if self.action['desc'] == "breakLine":
  886. breakL.Check(True)
  887. snap = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  888. text = _('Snap selected lines/boundaries (only to nodes)'),
  889. kind = wx.ITEM_CHECK)
  890. toolMenu.AppendItem(snap)
  891. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnSnap, snap)
  892. if self.action['desc'] == "snapLine":
  893. snap.Check(True)
  894. connect = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  895. text = _('Connect selected lines/boundaries'),
  896. kind = wx.ITEM_CHECK)
  897. toolMenu.AppendItem(connect)
  898. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnConnect, connect)
  899. if self.action['desc'] == "connectLine":
  900. connect.Check(True)
  901. query = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  902. text = _('Query features'),
  903. kind = wx.ITEM_CHECK)
  904. toolMenu.AppendItem(query)
  905. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnQuery, query)
  906. if self.action['desc'] == "queryLine":
  907. query.Check(True)
  908. zbulk = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  909. text = _('Z bulk-labeling of 3D lines'),
  910. kind = wx.ITEM_CHECK)
  911. toolMenu.AppendItem(zbulk)
  912. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnZBulk, zbulk)
  913. if self.action['desc'] == "zbulkLine":
  914. zbulk.Check(True)
  915. typeconv = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  916. text = _('Feature type conversion'),
  917. kind = wx.ITEM_CHECK)
  918. toolMenu.AppendItem(typeconv)
  919. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnTypeConversion, typeconv)
  920. if self.action['desc'] == "typeConv":
  921. typeconv.Check(True)
  922. # Popup the menu. If an item is selected then its handler
  923. # will be called before PopupMenu returns.
  924. self.parent.MapWindow.PopupMenu(toolMenu)
  925. toolMenu.Destroy()
  926. if self.action['desc'] == 'addPoint':
  927. self.ToggleTool(self.additionalTools, False)
  928. def OnCopy(self, event):
  929. """!Copy selected features from (background) vector map"""
  930. if self.action['desc'] == 'copyLine': # select previous action
  931. self.ToggleTool(self.addPoint, True)
  932. self.ToggleTool(self.additionalTools, False)
  933. self.OnAddPoint(event)
  934. return
  935. Debug.msg(2, "Digittoolbar.OnCopy():")
  936. self.action = { 'desc' : "copyLine",
  937. 'id' : self.additionalTools }
  938. self.parent.MapWindow.mouse['box'] = 'box'
  939. def OnFlip(self, event):
  940. """!Flip selected lines/boundaries"""
  941. if self.action['desc'] == 'flipLine': # select previous action
  942. self.ToggleTool(self.addPoint, True)
  943. self.ToggleTool(self.additionalTools, False)
  944. self.OnAddPoint(event)
  945. return
  946. Debug.msg(2, "Digittoolbar.OnFlip():")
  947. self.action = { 'desc' : "flipLine",
  948. 'id' : self.additionalTools }
  949. self.parent.MapWindow.mouse['box'] = 'box'
  950. def OnMerge(self, event):
  951. """!Merge selected lines/boundaries"""
  952. if self.action['desc'] == 'mergeLine': # select previous action
  953. self.ToggleTool(self.addPoint, True)
  954. self.ToggleTool(self.additionalTools, False)
  955. self.OnAddPoint(event)
  956. return
  957. Debug.msg(2, "Digittoolbar.OnMerge():")
  958. self.action = { 'desc' : "mergeLine",
  959. 'id' : self.additionalTools }
  960. self.parent.MapWindow.mouse['box'] = 'box'
  961. def OnBreak(self, event):
  962. """!Break selected lines/boundaries"""
  963. if self.action['desc'] == 'breakLine': # select previous action
  964. self.ToggleTool(self.addPoint, True)
  965. self.ToggleTool(self.additionalTools, False)
  966. self.OnAddPoint(event)
  967. return
  968. Debug.msg(2, "Digittoolbar.OnBreak():")
  969. self.action = { 'desc' : "breakLine",
  970. 'id' : self.additionalTools }
  971. self.parent.MapWindow.mouse['box'] = 'box'
  972. def OnSnap(self, event):
  973. """!Snap selected features"""
  974. if self.action['desc'] == 'snapLine': # select previous action
  975. self.ToggleTool(self.addPoint, True)
  976. self.ToggleTool(self.additionalTools, False)
  977. self.OnAddPoint(event)
  978. return
  979. Debug.msg(2, "Digittoolbar.OnSnap():")
  980. self.action = { 'desc' : "snapLine",
  981. 'id' : self.additionalTools }
  982. self.parent.MapWindow.mouse['box'] = 'box'
  983. def OnConnect(self, event):
  984. """!Connect selected lines/boundaries"""
  985. if self.action['desc'] == 'connectLine': # select previous action
  986. self.ToggleTool(self.addPoint, True)
  987. self.ToggleTool(self.additionalTools, False)
  988. self.OnAddPoint(event)
  989. return
  990. Debug.msg(2, "Digittoolbar.OnConnect():")
  991. self.action = { 'desc' : "connectLine",
  992. 'id' : self.additionalTools }
  993. self.parent.MapWindow.mouse['box'] = 'box'
  994. def OnQuery(self, event):
  995. """!Query selected lines/boundaries"""
  996. if self.action['desc'] == 'queryLine': # select previous action
  997. self.ToggleTool(self.addPoint, True)
  998. self.ToggleTool(self.additionalTools, False)
  999. self.OnAddPoint(event)
  1000. return
  1001. Debug.msg(2, "Digittoolbar.OnQuery(): %s" % \
  1002. UserSettings.Get(group = 'vdigit', key = 'query', subkey = 'selection'))
  1003. self.action = { 'desc' : "queryLine",
  1004. 'id' : self.additionalTools }
  1005. self.parent.MapWindow.mouse['box'] = 'box'
  1006. def OnZBulk(self, event):
  1007. """!Z bulk-labeling selected lines/boundaries"""
  1008. if not self.parent.digit.driver.Is3D():
  1009. wx.MessageBox(parent = self.parent,
  1010. message = _("Vector map is not 3D. Operation canceled."),
  1011. caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1012. return
  1013. if self.action['desc'] == 'zbulkLine': # select previous action
  1014. self.ToggleTool(self.addPoint, True)
  1015. self.ToggleTool(self.additionalTools, False)
  1016. self.OnAddPoint(event)
  1017. return
  1018. Debug.msg(2, "Digittoolbar.OnZBulk():")
  1019. self.action = { 'desc' : "zbulkLine",
  1020. 'id' : self.additionalTools }
  1021. self.parent.MapWindow.mouse['box'] = 'line'
  1022. def OnTypeConversion(self, event):
  1023. """!Feature type conversion
  1024. Supported conversions:
  1025. - point <-> centroid
  1026. - line <-> boundary
  1027. """
  1028. if self.action['desc'] == 'typeConv': # select previous action
  1029. self.ToggleTool(self.addPoint, True)
  1030. self.ToggleTool(self.additionalTools, False)
  1031. self.OnAddPoint(event)
  1032. return
  1033. Debug.msg(2, "Digittoolbar.OnTypeConversion():")
  1034. self.action = { 'desc' : "typeConv",
  1035. 'id' : self.additionalTools }
  1036. self.parent.MapWindow.mouse['box'] = 'box'
  1037. def OnSelectMap (self, event):
  1038. """
  1039. Select vector map layer for editing
  1040. If there is a vector map layer already edited, this action is
  1041. firstly terminated. The map layer is closed. After this the
  1042. selected map layer activated for editing.
  1043. """
  1044. if event.GetSelection() == 0: # create new vector map layer
  1045. if self.mapLayer:
  1046. openVectorMap = self.mapLayer.GetName(fullyQualified = False)['name']
  1047. else:
  1048. openVectorMap = None
  1049. mapName = gdialogs.CreateNewVector(self.parent,
  1050. exceptMap = openVectorMap, log = self.log,
  1051. cmd = (('v.edit',
  1052. { 'tool' : 'create' },
  1053. 'map')),
  1054. disableAdd = True)[0]
  1055. if mapName:
  1056. # add layer to map layer tree
  1057. if self.layerTree:
  1058. self.layerTree.AddLayer(ltype = 'vector',
  1059. lname = mapName,
  1060. lchecked = True,
  1061. lopacity = 1.0,
  1062. lcmd = ['d.vect', 'map=%s' % mapName])
  1063. vectLayers = self.UpdateListOfLayers(updateTool = True)
  1064. selection = vectLayers.index(mapName)
  1065. else:
  1066. pass # TODO (no Layer Manager)
  1067. else:
  1068. self.combo.SetValue(_('Select vector map'))
  1069. return
  1070. else:
  1071. selection = event.GetSelection() - 1 # first option is 'New vector map'
  1072. # skip currently selected map
  1073. if self.layers[selection] == self.mapLayer:
  1074. return False
  1075. if self.mapLayer:
  1076. # deactive map layer for editing
  1077. self.StopEditing()
  1078. # select the given map layer for editing
  1079. self.StartEditing(self.layers[selection])
  1080. event.Skip()
  1081. return True
  1082. def StartEditing (self, mapLayer):
  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. gcmd.GError(parent = self.parent,
  1117. message = str(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. # return to map layer page (gets rid of ugly exit bug)
  1383. self.lmgr.notebook.SetSelection(0)
  1384. # disable the toolbar
  1385. self.parent.RemoveToolbar("nviz")
  1386. class ModelToolbar(AbstractToolbar):
  1387. """!Graphical modeler toolbar (see gmodeler.py)
  1388. """
  1389. def __init__(self, parent):
  1390. AbstractToolbar.__init__(self, parent)
  1391. self.InitToolbar(self.ToolbarData())
  1392. # realize the toolbar
  1393. self.Realize()
  1394. def ToolbarData(self):
  1395. """!Toolbar data"""
  1396. self.new = wx.NewId()
  1397. self.open = wx.NewId()
  1398. self.save = wx.NewId()
  1399. self.image = wx.NewId()
  1400. self.python = wx.NewId()
  1401. self.action = wx.NewId()
  1402. self.data = wx.NewId()
  1403. self.relation = wx.NewId()
  1404. self.run = wx.NewId()
  1405. self.validate = wx.NewId()
  1406. self.settings = wx.NewId()
  1407. self.variables = wx.NewId()
  1408. self.quit = wx.NewId()
  1409. self.redraw = wx.NewId()
  1410. self.help = wx.NewId()
  1411. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  1412. return (
  1413. (self.new, 'new', Icons['modelNew'].GetBitmap(),
  1414. wx.ITEM_NORMAL, Icons['modelNew'].GetLabel(), Icons['modelNew'].GetDesc(),
  1415. self.parent.OnModelNew),
  1416. (self.open, 'open', Icons['modelOpen'].GetBitmap(),
  1417. wx.ITEM_NORMAL, Icons['modelOpen'].GetLabel(), Icons['modelOpen'].GetDesc(),
  1418. self.parent.OnModelOpen),
  1419. (self.save, 'save', Icons['modelSave'].GetBitmap(),
  1420. wx.ITEM_NORMAL, Icons['modelSave'].GetLabel(), Icons['modelSave'].GetDesc(),
  1421. self.parent.OnModelSave),
  1422. (self.image, 'image', Icons['modelToImage'].GetBitmap(),
  1423. wx.ITEM_NORMAL, Icons['modelToImage'].GetLabel(), Icons['modelToImage'].GetDesc(),
  1424. self.parent.OnExportImage),
  1425. (self.python, 'python', Icons['modelToPython'].GetBitmap(),
  1426. wx.ITEM_NORMAL, Icons['modelToPython'].GetLabel(), Icons['modelToPython'].GetDesc(),
  1427. self.parent.OnExportPython),
  1428. ('', '', '', '', '', '', ''),
  1429. (self.action, 'action', Icons['modelActionAdd'].GetBitmap(),
  1430. wx.ITEM_NORMAL, Icons['modelActionAdd'].GetLabel(), Icons['modelActionAdd'].GetDesc(),
  1431. self.parent.OnAddAction),
  1432. (self.data, 'data', Icons['modelDataAdd'].GetBitmap(),
  1433. wx.ITEM_NORMAL, Icons['modelDataAdd'].GetLabel(), Icons['modelDataAdd'].GetDesc(),
  1434. self.parent.OnAddData),
  1435. (self.relation, 'relation', Icons['modelRelation'].GetBitmap(),
  1436. wx.ITEM_NORMAL, Icons['modelRelation'].GetLabel(), Icons['modelRelation'].GetDesc(),
  1437. self.parent.OnDefineRelation),
  1438. ('', '', '', '', '', '', ''),
  1439. (self.redraw, 'redraw', Icons['modelRedraw'].GetBitmap(),
  1440. wx.ITEM_NORMAL, Icons['modelRedraw'].GetLabel(), Icons['modelRedraw'].GetDesc(),
  1441. self.parent.OnCanvasRefresh),
  1442. (self.validate, 'validate', Icons['modelValidate'].GetBitmap(),
  1443. wx.ITEM_NORMAL, Icons['modelValidate'].GetLabel(), Icons['modelValidate'].GetDesc(),
  1444. self.parent.OnValidateModel),
  1445. (self.run, 'run', Icons['modelRun'].GetBitmap(),
  1446. wx.ITEM_NORMAL, Icons['modelRun'].GetLabel(), Icons['modelRun'].GetDesc(),
  1447. self.parent.OnRunModel),
  1448. ('', '', '', '', '', '', ''),
  1449. (self.variables, "variables", Icons["modelVariables"].GetBitmap(),
  1450. wx.ITEM_NORMAL, Icons["modelVariables"].GetLabel(), Icons["modelVariables"].GetDesc(),
  1451. self.parent.OnVariables),
  1452. (self.settings, "settings", Icons["modelSettings"].GetBitmap(),
  1453. wx.ITEM_NORMAL, Icons["modelSettings"].GetLabel(), Icons["modelSettings"].GetDesc(),
  1454. self.parent.OnPreferences),
  1455. (self.help, "help", Icons["modelHelp"].GetBitmap(),
  1456. wx.ITEM_NORMAL, Icons["modelHelp"].GetLabel(), Icons["modelHelp"].GetDesc(),
  1457. self.parent.OnHelp),
  1458. ('', '', '', '', '', '', ''),
  1459. (self.quit, 'quit', Icons['quit'].GetBitmap(),
  1460. wx.ITEM_NORMAL, Icons['quit'].GetLabel(), Icons['quit'].GetDesc(),
  1461. self.parent.OnCloseWindow),
  1462. )
  1463. class HistogramToolbar(AbstractToolbar):
  1464. """!Histogram toolbar (see histogram.py)
  1465. """
  1466. def __init__(self, parent):
  1467. AbstractToolbar.__init__(self, parent)
  1468. self.InitToolbar(self.ToolbarData())
  1469. # realize the toolbar
  1470. self.Realize()
  1471. def ToolbarData(self):
  1472. """!Toolbar data"""
  1473. self.histogram = wx.NewId()
  1474. self.rendermap = wx.NewId()
  1475. self.erase = wx.NewId()
  1476. self.font = wx.NewId()
  1477. self.save = wx.NewId()
  1478. self.hprint = wx.NewId()
  1479. self.quit = wx.NewId()
  1480. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  1481. return (
  1482. (self.histogram, 'histogram', Icons["histogram"].GetBitmap(),
  1483. wx.ITEM_NORMAL, Icons["histogram"].GetLabel(), Icons["histogram"].GetDesc(),
  1484. self.parent.OnOptions),
  1485. (self.rendermap, 'rendermap', Icons["displaymap"].GetBitmap(),
  1486. wx.ITEM_NORMAL, Icons["displaymap"].GetLabel(), Icons["displaymap"].GetDesc(),
  1487. self.parent.OnRender),
  1488. (self.erase, 'erase', Icons["erase"].GetBitmap(),
  1489. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  1490. self.parent.OnErase),
  1491. (self.font, 'font', Icons["font"].GetBitmap(),
  1492. wx.ITEM_NORMAL, Icons["font"].GetLabel(), Icons["font"].GetDesc(),
  1493. self.parent.SetHistFont),
  1494. ('', '', '', '', '', '', ''),
  1495. (self.save, 'save', Icons["savefile"].GetBitmap(),
  1496. wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
  1497. self.parent.SaveToFile),
  1498. (self.hprint, 'print', Icons["printmap"].GetBitmap(),
  1499. wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
  1500. self.parent.PrintMenu),
  1501. ('', '', '', '', '', '', ''),
  1502. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  1503. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  1504. self.parent.OnQuit)
  1505. )
  1506. class LayerManagerToolbar(AbstractToolbar):
  1507. """!Layer Manager toolbar (see wxgui.py)
  1508. """
  1509. def __init__(self, parent):
  1510. AbstractToolbar.__init__(self, parent)
  1511. self.InitToolbar(self.ToolbarData())
  1512. # realize the toolbar
  1513. self.Realize()
  1514. def ToolbarData(self):
  1515. """!Toolbar data"""
  1516. self.newdisplay = wx.NewId()
  1517. self.workspaceLoad = wx.NewId()
  1518. self.workspaceOpen = wx.NewId()
  1519. self.workspaceSave = wx.NewId()
  1520. self.addrast = wx.NewId()
  1521. self.rastmisc = wx.NewId()
  1522. self.addvect = wx.NewId()
  1523. self.vectmisc = wx.NewId()
  1524. self.addgrp = wx.NewId()
  1525. self.addovl = wx.NewId()
  1526. self.delcmd = wx.NewId()
  1527. self.attribute = wx.NewId()
  1528. self.preferences = wx.NewId()
  1529. self.modeler = wx.NewId()
  1530. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  1531. return (
  1532. (self.newdisplay, 'newdisplay', Icons["newdisplay"].GetBitmap(),
  1533. wx.ITEM_NORMAL, Icons["newdisplay"].GetLabel(), Icons["newdisplay"].GetDesc(),
  1534. self.parent.OnNewDisplay),
  1535. ('', '', '', '', '', '', ''),
  1536. (self.workspaceLoad, 'workspaceLoad', Icons["workspaceLoad"].GetBitmap(),
  1537. wx.ITEM_NORMAL, Icons["workspaceLoad"].GetLabel(), Icons["workspaceLoad"].GetDesc(),
  1538. self.parent.OnWorkspace),
  1539. (self.workspaceOpen, 'workspaceOpen', Icons["workspaceOpen"].GetBitmap(),
  1540. wx.ITEM_NORMAL, Icons["workspaceOpen"].GetLabel(), Icons["workspaceOpen"].GetDesc(),
  1541. self.parent.OnWorkspaceOpen),
  1542. (self.workspaceSave, 'workspaceSave', Icons["workspaceSave"].GetBitmap(),
  1543. wx.ITEM_NORMAL, Icons["workspaceSave"].GetLabel(), Icons["workspaceSave"].GetDesc(),
  1544. self.parent.OnWorkspaceSave),
  1545. ('', '', '', '', '', '', ''),
  1546. (self.addrast, 'addrast', Icons["addrast"].GetBitmap(),
  1547. wx.ITEM_NORMAL, Icons["addrast"].GetLabel(), Icons["addrast"].GetDesc(),
  1548. self.parent.OnAddRaster),
  1549. (self.rastmisc, 'rastmisc', Icons["rastmisc"].GetBitmap(),
  1550. wx.ITEM_NORMAL, Icons["rastmisc"].GetLabel(), Icons["rastmisc"].GetDesc(),
  1551. self.parent.OnAddRasterMisc),
  1552. (self.addvect, 'addvect', Icons["addvect"].GetBitmap(),
  1553. wx.ITEM_NORMAL, Icons["addvect"].GetLabel(), Icons["addvect"].GetDesc(),
  1554. self.parent.OnAddVector),
  1555. (self.vectmisc, 'vectmisc', Icons["vectmisc"].GetBitmap(),
  1556. wx.ITEM_NORMAL, Icons["vectmisc"].GetLabel(), Icons["vectmisc"].GetDesc(),
  1557. self.parent.OnAddVectorMisc),
  1558. (self.addgrp, 'addgrp', Icons["addgrp"].GetBitmap(),
  1559. wx.ITEM_NORMAL, Icons["addgrp"].GetLabel(), Icons["addgrp"].GetDesc(),
  1560. self.parent.OnAddGroup),
  1561. (self.addovl, 'addovl', Icons["addovl"].GetBitmap(),
  1562. wx.ITEM_NORMAL, Icons["addovl"].GetLabel(), Icons["addovl"].GetDesc(),
  1563. self.parent.OnAddOverlay),
  1564. (self.delcmd, 'delcmd', Icons["delcmd"].GetBitmap(),
  1565. wx.ITEM_NORMAL, Icons["delcmd"].GetLabel(), Icons["delcmd"].GetDesc(),
  1566. self.parent.OnDeleteLayer),
  1567. ('', '', '', '', '', '', ''),
  1568. (self.attribute, 'attrtable', Icons["attrtable"].GetBitmap(),
  1569. wx.ITEM_NORMAL, Icons["attrtable"].GetLabel(), Icons["attrtable"].GetDesc(),
  1570. self.parent.OnShowAttributeTable),
  1571. ('', '', '', '', '', '', ''),
  1572. (self.modeler, 'modeler', Icons["modeler"].GetBitmap(),
  1573. wx.ITEM_NORMAL, Icons["modeler"].GetLabel(), Icons["modeler"].GetDesc(),
  1574. self.parent.OnGModeler),
  1575. (self.preferences, 'preferences', Icons["settings"].GetBitmap(),
  1576. wx.ITEM_NORMAL, Icons["settings"].GetLabel(), Icons["settings"].GetDesc(),
  1577. self.parent.OnPreferences)
  1578. )