toolbars.py 73 KB

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