toolbars.py 73 KB

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