toolbars.py 71 KB

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