frame.py 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  1. """!
  2. @package mapdisp.frame
  3. @brief Map display with toolbar for various display management
  4. functions, and additional toolbars (vector digitizer, 3d view).
  5. Can be used either from Layer Manager or as d.mon backend.
  6. Classes:
  7. - mapdisp::MapFrame
  8. (C) 2006-2013 by the GRASS Development Team
  9. This program is free software under the GNU General Public License
  10. (>=v2). Read the file COPYING that comes with GRASS for details.
  11. @author Michael Barton
  12. @author Jachym Cepicky
  13. @author Martin Landa <landa.martin gmail.com>
  14. @author Vaclav Petras <wenzeslaus gmail.com> (SingleMapFrame, handlers support)
  15. @author Anna Kratochvilova <kratochanna gmail.com> (SingleMapFrame)
  16. @author Stepan Turek <stepan.turek seznam.cz> (handlers support)
  17. """
  18. import os
  19. import sys
  20. import copy
  21. from core import globalvar
  22. import wx
  23. import wx.aui
  24. if os.path.join(globalvar.ETCWXDIR, "icons") not in sys.path:
  25. sys.path.append(os.path.join(globalvar.ETCWXDIR, "icons"))
  26. if os.path.join(globalvar.ETCDIR, "python") not in sys.path:
  27. sys.path.append(os.path.join(globalvar.ETCDIR, "python"))
  28. from core import globalvar
  29. from core.render import Map
  30. from vdigit.toolbars import VDigitToolbar
  31. from mapdisp.toolbars import MapToolbar, NvizIcons
  32. from mapdisp.gprint import PrintOptions
  33. from core.gcmd import GError, GMessage
  34. from dbmgr.dialogs import DisplayAttributesDialog
  35. from core.utils import ListOfCatsToRange, GetLayerNameFromCmd, _
  36. from gui_core.dialogs import GetImageHandlers, ImageSizeDialog
  37. from core.debug import Debug
  38. from core.settings import UserSettings
  39. from gui_core.mapdisp import SingleMapFrame
  40. from mapwin.base import MapWindowProperties
  41. from gui_core.query import QueryDialog, PrepareQueryResults
  42. from mapwin.buffered import BufferedMapWindow
  43. from mapwin.decorations import TextLayerDialog, \
  44. LegendController, BarscaleController, ArrowController
  45. from modules.histogram import HistogramFrame
  46. from wxplot.histogram import HistogramPlotFrame
  47. from wxplot.profile import ProfileFrame
  48. from wxplot.scatter import ScatterFrame
  49. from mapwin.analysis import ProfileController, MeasureDistanceController, \
  50. MeasureAreaController
  51. from gui_core.forms import GUI
  52. from core.giface import Notification
  53. from mapdisp import statusbar as sb
  54. import grass.script as grass
  55. from grass.pydispatch.signal import Signal
  56. class MapFrame(SingleMapFrame):
  57. """!Main frame for map display window. Drawing takes place in
  58. child double buffered drawing window.
  59. """
  60. def __init__(self, parent, giface, title = _("GRASS GIS - Map display"),
  61. toolbars = ["map"], tree = None, notebook = None, lmgr = None,
  62. page = None, Map = Map(), auimgr = None, name = 'MapWindow', **kwargs):
  63. """!Main map display window with toolbars, statusbar and
  64. 2D map window, 3D map window and digitizer.
  65. @param toolbars array of activated toolbars, e.g. ['map', 'digit']
  66. @param tree reference to layer tree
  67. @param notebook control book ID in Layer Manager
  68. @param lmgr Layer Manager
  69. @param page notebook page with layer tree
  70. @param Map instance of render.Map
  71. @param auimgs AUI manager
  72. @param name frame name
  73. @param kwargs wx.Frame attributes
  74. """
  75. SingleMapFrame.__init__(self, parent = parent, title = title,
  76. Map = Map, auimgr = auimgr, name = name, **kwargs)
  77. self._giface = giface
  78. # Layer Manager object
  79. # need by GLWindow (a lot), VDigitWindow (a little bit)
  80. self._layerManager = lmgr
  81. # Layer Manager layer tree object
  82. # used for VDigit toolbar and window and GLWindow
  83. self.tree = tree
  84. # Notebook page holding the layer tree
  85. # used only in OnCloseWindow
  86. self.page = page
  87. # Layer Manager layer tree notebook
  88. # used only in OnCloseWindow
  89. self.layerbook = notebook
  90. # Emitted when starting (switching to) 3D mode.
  91. # Parameter firstTime specifies if 3D was already actived.
  92. self.starting3dMode = Signal("MapFrame.starting3dMode")
  93. # Emitted when ending (switching from) 3D mode.
  94. self.ending3dMode = Signal("MapFrame.ending3dMode")
  95. # properties are shared in other objects, so defining here
  96. self.mapWindowProperties = MapWindowProperties()
  97. self.mapWindowProperties.setValuesFromUserSettings()
  98. #
  99. # Add toolbars
  100. #
  101. for toolb in toolbars:
  102. self.AddToolbar(toolb)
  103. #
  104. # Add statusbar
  105. #
  106. # items for choice
  107. self.statusbarItems = [sb.SbCoordinates,
  108. sb.SbRegionExtent,
  109. sb.SbCompRegionExtent,
  110. sb.SbShowRegion,
  111. sb.SbAlignExtent,
  112. sb.SbResolution,
  113. sb.SbDisplayGeometry,
  114. sb.SbMapScale,
  115. sb.SbGoTo,
  116. sb.SbProjection]
  117. self.statusbarItemsHiddenInNviz = (sb.SbAlignExtent,
  118. sb.SbDisplayGeometry,
  119. sb.SbShowRegion,
  120. sb.SbResolution,
  121. sb.SbMapScale)
  122. # create statusbar and its manager
  123. statusbar = self.CreateStatusBar(number = 4, style = 0)
  124. statusbar.SetStatusWidths([-5, -2, -1, -1])
  125. self.statusbarManager = sb.SbManager(mapframe = self, statusbar = statusbar)
  126. # fill statusbar manager
  127. self.statusbarManager.AddStatusbarItemsByClass(self.statusbarItems, mapframe = self, statusbar = statusbar)
  128. self.statusbarManager.AddStatusbarItem(sb.SbMask(self, statusbar = statusbar, position = 2))
  129. sbRender = sb.SbRender(self, statusbar = statusbar, position = 3)
  130. self.statusbarManager.AddStatusbarItem(sbRender)
  131. self.statusbarManager.Update()
  132. #
  133. self.Map.updateProgress.connect(self.statusbarManager.SetProgress)
  134. # init decoration objects
  135. self.decorations = {}
  136. self.legend = LegendController(self.Map, self._giface)
  137. self.barscale = BarscaleController(self.Map, self._giface)
  138. self.arrow = ArrowController(self.Map, self._giface)
  139. self.decorations[self.legend.id] = self.legend
  140. self.decorations[self.barscale.id] = self.barscale
  141. self.decorations[self.arrow.id] = self.arrow
  142. self.mapWindowProperties.autoRenderChanged.connect(
  143. lambda value:
  144. self.OnRender(None) if value else None)
  145. #
  146. # Init map display (buffered DC & set default cursor)
  147. #
  148. self.MapWindow2D = BufferedMapWindow(self, giface = self._giface,
  149. Map=self.Map,
  150. properties=self.mapWindowProperties,
  151. overlays=self.decorations)
  152. self.MapWindow2D.mapQueried.connect(self.Query)
  153. self.MapWindow2D.overlayActivated.connect(self._activateOverlay)
  154. self.MapWindow2D.overlayHidden.connect(self._hideOverlay)
  155. self.MapWindow2D.overlayHidden.connect(self._hideOverlay)
  156. for overlay in (self.legend, self.barscale, self.arrow):
  157. overlay.overlayChanged.connect(lambda: self.MapWindow2D.UpdateMap(render=False, renderVector=False))
  158. self._setUpMapWindow(self.MapWindow2D)
  159. self.MapWindow2D.mouseHandlerUnregistered.connect(self.ResetPointer)
  160. self.MapWindow2D.InitZoomHistory()
  161. self.MapWindow2D.zoomChanged.connect(self.StatusbarUpdate)
  162. self._giface.updateMap.connect(self.MapWindow2D.UpdateMap)
  163. # default is 2D display mode
  164. self.MapWindow = self.MapWindow2D
  165. self.MapWindow.SetNamedCursor('default')
  166. # used by vector digitizer
  167. self.MapWindowVDigit = None
  168. # used by Nviz (3D display mode)
  169. self.MapWindow3D = None
  170. #
  171. # initialize region values
  172. #
  173. self._initMap(Map = self.Map)
  174. self.toolbars['map'].SelectDefault()
  175. #
  176. # Bind various events
  177. #
  178. self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
  179. self.Bind(wx.EVT_SIZE, self.OnSize)
  180. #
  181. # Update fancy gui style
  182. #
  183. self._mgr.AddPane(self.MapWindow, wx.aui.AuiPaneInfo().CentrePane().
  184. Dockable(False).BestSize((-1,-1)).Name('2d').
  185. CloseButton(False).DestroyOnClose(True).
  186. Layer(0))
  187. self._mgr.Update()
  188. #
  189. # Init print module and classes
  190. #
  191. self.printopt = PrintOptions(self, self.MapWindow)
  192. #
  193. # Re-use dialogs
  194. #
  195. self.dialogs = {}
  196. self.dialogs['attributes'] = None
  197. self.dialogs['category'] = None
  198. self.dialogs['vnet'] = None
  199. self.dialogs['query'] = None
  200. self.measureController = None
  201. def GetMapWindow(self):
  202. return self.MapWindow
  203. def _addToolbarVDigit(self):
  204. """!Add vector digitizer toolbar
  205. """
  206. from vdigit.main import haveVDigit, VDigit
  207. if not haveVDigit:
  208. from vdigit import errorMsg
  209. self.toolbars['map'].combo.SetValue(_("2D view"))
  210. GError(_("Unable to start wxGUI vector digitizer.\n"
  211. "Details: %s") % errorMsg, parent = self)
  212. return
  213. if not self.MapWindowVDigit:
  214. from vdigit.mapwindow import VDigitWindow
  215. self.MapWindowVDigit = VDigitWindow(parent=self, giface=self._giface,
  216. properties=self.mapWindowProperties,
  217. Map=self.Map, tree=self.tree,
  218. lmgr=self._layerManager,
  219. overlays=self.decorations)
  220. self._setUpMapWindow(self.MapWindowVDigit)
  221. self.MapWindowVDigit.digitizingInfo.connect(
  222. lambda text:
  223. self.statusbarManager.statusbarItems['coordinates'].SetAdditionalInfo(text))
  224. self.MapWindowVDigit.digitizingInfoUnavailable.connect(
  225. lambda:
  226. self.statusbarManager.statusbarItems['coordinates'].SetAdditionalInfo(None))
  227. self.MapWindowVDigit.Show()
  228. self._mgr.AddPane(self.MapWindowVDigit, wx.aui.AuiPaneInfo().CentrePane().
  229. Dockable(False).BestSize((-1,-1)).Name('vdigit').
  230. CloseButton(False).DestroyOnClose(True).
  231. Layer(0))
  232. self.MapWindow = self.MapWindowVDigit
  233. if self._mgr.GetPane('2d').IsShown():
  234. self._mgr.GetPane('2d').Hide()
  235. elif self._mgr.GetPane('3d').IsShown():
  236. self._mgr.GetPane('3d').Hide()
  237. self._mgr.GetPane('vdigit').Show()
  238. self.toolbars['vdigit'] = VDigitToolbar(parent=self, toolSwitcher=self._toolSwitcher,
  239. MapWindow = self.MapWindow,
  240. digitClass=VDigit, giface=self._giface,
  241. layerTree=self.tree)
  242. self.MapWindowVDigit.SetToolbar(self.toolbars['vdigit'])
  243. self._mgr.AddPane(self.toolbars['vdigit'],
  244. wx.aui.AuiPaneInfo().
  245. Name("vdigittoolbar").Caption(_("Vector Digitizer Toolbar")).
  246. ToolbarPane().Top().Row(1).
  247. LeftDockable(False).RightDockable(False).
  248. BottomDockable(False).TopDockable(True).
  249. CloseButton(False).Layer(2).
  250. BestSize((self.toolbars['vdigit'].GetBestSize())))
  251. # change mouse to draw digitized line
  252. self.MapWindow.mouse['box'] = "point"
  253. self.MapWindow.zoomtype = 0
  254. self.MapWindow.pen = wx.Pen(colour = 'red', width = 2, style = wx.SOLID)
  255. self.MapWindow.polypen = wx.Pen(colour = 'green', width = 2, style = wx.SOLID)
  256. def AddNviz(self):
  257. """!Add 3D view mode window
  258. """
  259. from nviz.main import haveNviz, GLWindow, errorMsg
  260. # check for GLCanvas and OpenGL
  261. if not haveNviz:
  262. self.toolbars['map'].combo.SetValue(_("2D view"))
  263. GError(parent = self,
  264. message = _("Unable to switch to 3D display mode.\nThe Nviz python extension "
  265. "was not found or loaded properly.\n"
  266. "Switching back to 2D display mode.\n\nDetails: %s" % errorMsg))
  267. return
  268. # here was disabling 3D for other displays, now done on starting3dMode
  269. self.toolbars['map'].Enable2D(False)
  270. # add rotate tool to map toolbar
  271. self.toolbars['map'].InsertTool((('rotate', NvizIcons['rotate'],
  272. self.OnRotate, wx.ITEM_CHECK, 7),)) # 7 is position
  273. self._toolSwitcher.AddToolToGroup(group='mouseUse', toolbar=self.toolbars['map'],
  274. tool=self.toolbars['map'].rotate)
  275. self.toolbars['map'].InsertTool((('flyThrough', NvizIcons['flyThrough'],
  276. self.OnFlyThrough, wx.ITEM_CHECK, 8),))
  277. self._toolSwitcher.AddToolToGroup(group='mouseUse', toolbar=self.toolbars['map'],
  278. tool=self.toolbars['map'].flyThrough)
  279. self.toolbars['map'].ChangeToolsDesc(mode2d = False)
  280. # update status bar
  281. self.statusbarManager.HideStatusbarChoiceItemsByClass(self.statusbarItemsHiddenInNviz)
  282. self.statusbarManager.SetMode(0)
  283. # erase map window
  284. self.MapWindow.EraseMap()
  285. self._giface.WriteCmdLog(_("Starting 3D view mode..."), notification=Notification.HIGHLIGHT)
  286. self.SetStatusText(_("Please wait, loading data..."), 0)
  287. # create GL window
  288. if not self.MapWindow3D:
  289. self.MapWindow3D = GLWindow(self, giface = self._giface, id = wx.ID_ANY, frame = self,
  290. Map = self.Map, tree = self.tree, lmgr = self._layerManager)
  291. self._setUpMapWindow(self.MapWindow3D)
  292. self.MapWindow3D.mapQueried.connect(self.Query)
  293. self.MapWindow = self.MapWindow3D
  294. self.MapWindow.SetNamedCursor('default')
  295. # here was AddNvizTools in lmgr
  296. self.starting3dMode.emit(firstTime=True)
  297. # switch from MapWindow to MapWindowGL
  298. self._mgr.GetPane('2d').Hide()
  299. self._mgr.AddPane(self.MapWindow3D, wx.aui.AuiPaneInfo().CentrePane().
  300. Dockable(False).BestSize((-1,-1)).Name('3d').
  301. CloseButton(False).DestroyOnClose(True).
  302. Layer(0))
  303. self.MapWindow3D.Show()
  304. self.MapWindow3D.ResetViewHistory()
  305. self.MapWindow3D.UpdateView(None)
  306. self.MapWindow3D.overlayActivated.connect(self._activateOverlay)
  307. self.MapWindow3D.overlayHidden.connect(self._hideOverlay)
  308. self.legend.overlayChanged.connect(lambda: self.MapWindow3D.UpdateOverlays())
  309. else:
  310. self.MapWindow = self.MapWindow3D
  311. os.environ['GRASS_REGION'] = self.Map.SetRegion(windres = True, windres3 = True)
  312. self.MapWindow3D.GetDisplay().Init()
  313. del os.environ['GRASS_REGION']
  314. # switch from MapWindow to MapWindowGL
  315. self._mgr.GetPane('2d').Hide()
  316. self._mgr.GetPane('3d').Show()
  317. # here was AddNvizTools in lmgr and updating of pages
  318. self.starting3dMode.emit(firstTime=False)
  319. self.MapWindow3D.ResetViewHistory()
  320. self._giface.updateMap.disconnect(self.MapWindow2D.UpdateMap)
  321. self._giface.updateMap.connect(self.MapWindow3D.UpdateMap)
  322. self.MapWindow3D.overlays = self.MapWindow2D.overlays
  323. self.MapWindow3D.textdict = self.MapWindow2D.textdict
  324. # update overlays needs to be called after because getClientSize
  325. # is called during update and it must give reasonable values
  326. wx.CallAfter(self.MapWindow3D.UpdateOverlays)
  327. self.SetStatusText("", 0)
  328. self._mgr.Update()
  329. def Disable3dMode(self):
  330. """Disables 3D mode (NVIZ) in user interface."""
  331. # TODO: this is broken since item is removed but switch is drived by index
  332. if '3D' in self.toolbars['map'].combo.GetString(1):
  333. self.toolbars['map'].combo.Delete(1)
  334. def RemoveNviz(self):
  335. """!Restore 2D view"""
  336. try:
  337. self.toolbars['map'].RemoveTool(self.toolbars['map'].rotate)
  338. self.toolbars['map'].RemoveTool(self.toolbars['map'].flyThrough)
  339. except AttributeError:
  340. pass
  341. # update status bar
  342. self.statusbarManager.ShowStatusbarChoiceItemsByClass(self.statusbarItemsHiddenInNviz)
  343. self.statusbarManager.SetMode(UserSettings.Get(group = 'display',
  344. key = 'statusbarMode',
  345. subkey = 'selection'))
  346. self.SetStatusText(_("Please wait, unloading data..."), 0)
  347. # unloading messages from library cause highlight anyway
  348. self._giface.WriteCmdLog(_("Switching back to 2D view mode..."),
  349. notification=Notification.NO_NOTIFICATION)
  350. if self.MapWindow3D:
  351. self.MapWindow3D.OnClose(event = None)
  352. # switch from MapWindowGL to MapWindow
  353. self._mgr.GetPane('2d').Show()
  354. self._mgr.GetPane('3d').Hide()
  355. self.MapWindow = self.MapWindow2D
  356. # here was RemoveNvizTools form lmgr
  357. self.ending3dMode.emit()
  358. try:
  359. self.MapWindow2D.overlays = self.MapWindow3D.overlays
  360. self.MapWindow2D.textdict = self.MapWindow3D.textdict
  361. except AttributeError:
  362. pass
  363. # TODO: here we end because self.MapWindow3D is None for a while
  364. self._giface.updateMap.disconnect(self.MapWindow3D.UpdateMap)
  365. self._giface.updateMap.connect(self.MapWindow2D.UpdateMap)
  366. self.MapWindow.UpdateMap()
  367. self._mgr.Update()
  368. self.GetMapToolbar().SelectDefault()
  369. def AddToolbar(self, name, fixed = False):
  370. """!Add defined toolbar to the window
  371. Currently recognized toolbars are:
  372. - 'map' - basic map toolbar
  373. - 'vdigit' - vector digitizer
  374. @param name toolbar to add
  375. @param fixed fixed toolbar
  376. """
  377. # default toolbar
  378. if name == "map":
  379. self.toolbars['map'] = MapToolbar(self, toolSwitcher=self._toolSwitcher)
  380. self._mgr.AddPane(self.toolbars['map'],
  381. wx.aui.AuiPaneInfo().
  382. Name("maptoolbar").Caption(_("Map Toolbar")).
  383. ToolbarPane().Top().Name('mapToolbar').
  384. LeftDockable(False).RightDockable(False).
  385. BottomDockable(False).TopDockable(True).
  386. CloseButton(False).Layer(2).
  387. BestSize((self.toolbars['map'].GetBestSize())))
  388. # vector digitizer
  389. elif name == "vdigit":
  390. self.toolbars['map'].combo.SetValue(_("Digitize"))
  391. self._addToolbarVDigit()
  392. if fixed:
  393. self.toolbars['map'].combo.Disable()
  394. self._mgr.Update()
  395. def RemoveToolbar (self, name):
  396. """!Removes defined toolbar from the window
  397. @todo Only hide, activate by calling AddToolbar()
  398. """
  399. # cannot hide main toolbar
  400. if name == "map":
  401. return
  402. self._mgr.DetachPane(self.toolbars[name])
  403. self._toolSwitcher.RemoveToolbarFromGroup('mouseUse', self.toolbars[name])
  404. self.toolbars[name].Destroy()
  405. self.toolbars.pop(name)
  406. if name == 'vdigit':
  407. self._mgr.GetPane('vdigit').Hide()
  408. self._mgr.GetPane('2d').Show()
  409. self.MapWindow = self.MapWindow2D
  410. self.toolbars['map'].combo.SetValue(_("2D view"))
  411. self.toolbars['map'].Enable2D(True)
  412. self._mgr.Update()
  413. def IsPaneShown(self, name):
  414. """!Check if pane (toolbar, mapWindow ...) of given name is currently shown"""
  415. if self._mgr.GetPane(name).IsOk():
  416. return self._mgr.GetPane(name).IsShown()
  417. return False
  418. def RemoveQueryLayer(self):
  419. """!Removes temporary map layers (queries)"""
  420. qlayer = self.GetMap().GetListOfLayers(name = globalvar.QUERYLAYER)
  421. for layer in qlayer:
  422. self.GetMap().DeleteLayer(layer)
  423. def OnRender(self, event):
  424. """!Re-render map composition (each map layer)
  425. """
  426. self.RemoveQueryLayer()
  427. # deselect features in vdigit
  428. if self.GetToolbar('vdigit'):
  429. if self.MapWindow.digit:
  430. self.MapWindow.digit.GetDisplay().SetSelected([])
  431. self.MapWindow.UpdateMap(render = True, renderVector = True)
  432. else:
  433. self.MapWindow.UpdateMap(render = True)
  434. # update statusbar
  435. self.StatusbarUpdate()
  436. def OnPointer(self, event):
  437. """!Pointer button clicked
  438. """
  439. self.MapWindow.SetModePointer()
  440. if self.GetToolbar('vdigit'):
  441. self.toolbars['vdigit'].action['id'] = -1
  442. self.toolbars['vdigit'].action['desc']=''
  443. def OnRotate(self, event):
  444. """!Rotate 3D view
  445. """
  446. self.MapWindow.mouse['use'] = "rotate"
  447. # change the cursor
  448. self.MapWindow.SetNamedCursor('hand')
  449. def OnFlyThrough(self, event):
  450. """!Fly-through mode
  451. """
  452. self.MapWindow.mouse['use'] = "fly"
  453. # change the cursor
  454. self.MapWindow.SetNamedCursor('hand')
  455. self.MapWindow.SetFocus()
  456. def SaveToFile(self, event):
  457. """!Save map to image
  458. """
  459. if self.IsPaneShown('3d'):
  460. filetype = "TIF file (*.tif)|*.tif|PPM file (*.ppm)|*.ppm"
  461. ltype = [{ 'ext' : 'tif', 'type' : 'tif' },
  462. { 'ext' : 'ppm', 'type' : 'ppm' }]
  463. else:
  464. img = self.MapWindow.img
  465. if not img:
  466. GMessage(parent = self,
  467. message = _("Nothing to render (empty map). Operation canceled."))
  468. return
  469. filetype, ltype = GetImageHandlers(img)
  470. # get size
  471. dlg = ImageSizeDialog(self)
  472. dlg.CentreOnParent()
  473. if dlg.ShowModal() != wx.ID_OK:
  474. dlg.Destroy()
  475. return
  476. width, height = dlg.GetValues()
  477. dlg.Destroy()
  478. # get filename
  479. dlg = wx.FileDialog(parent = self,
  480. message = _("Choose a file name to save the image "
  481. "(no need to add extension)"),
  482. wildcard = filetype,
  483. style = wx.SAVE | wx.FD_OVERWRITE_PROMPT)
  484. if dlg.ShowModal() == wx.ID_OK:
  485. path = dlg.GetPath()
  486. if not path:
  487. dlg.Destroy()
  488. return
  489. base, ext = os.path.splitext(path)
  490. fileType = ltype[dlg.GetFilterIndex()]['type']
  491. extType = ltype[dlg.GetFilterIndex()]['ext']
  492. if ext != extType:
  493. path = base + '.' + extType
  494. self.MapWindow.SaveToFile(path, fileType,
  495. width, height)
  496. dlg.Destroy()
  497. def PrintMenu(self, event):
  498. """
  499. Print options and output menu for map display
  500. """
  501. printmenu = wx.Menu()
  502. # Add items to the menu
  503. setup = wx.MenuItem(printmenu, wx.ID_ANY, _('Page setup'))
  504. printmenu.AppendItem(setup)
  505. self.Bind(wx.EVT_MENU, self.printopt.OnPageSetup, setup)
  506. preview = wx.MenuItem(printmenu, wx.ID_ANY, _('Print preview'))
  507. printmenu.AppendItem(preview)
  508. self.Bind(wx.EVT_MENU, self.printopt.OnPrintPreview, preview)
  509. doprint = wx.MenuItem(printmenu, wx.ID_ANY, _('Print display'))
  510. printmenu.AppendItem(doprint)
  511. self.Bind(wx.EVT_MENU, self.printopt.OnDoPrint, doprint)
  512. # Popup the menu. If an item is selected then its handler
  513. # will be called before PopupMenu returns.
  514. self.PopupMenu(printmenu)
  515. printmenu.Destroy()
  516. def OnCloseWindow(self, event):
  517. """!Window closed.
  518. Also close associated layer tree page
  519. """
  520. Debug.msg(2, "MapFrame.OnCloseWindow(): function starts")
  521. pgnum = None
  522. self.Map.Clean()
  523. # close edited map and 3D tools properly
  524. if self.GetToolbar('vdigit'):
  525. maplayer = self.toolbars['vdigit'].GetLayer()
  526. if maplayer:
  527. self.toolbars['vdigit'].OnExit()
  528. if self.IsPaneShown('3d'):
  529. self.RemoveNviz()
  530. if not self._layerManager:
  531. self.Destroy()
  532. elif self.page:
  533. pgnum = self.layerbook.GetPageIndex(self.page)
  534. if pgnum > -1:
  535. self.layerbook.DeletePage(pgnum)
  536. Debug.msg(2, "MapFrame.OnCloseWindow(): function ends")
  537. def Query(self, x, y):
  538. """!Query selected layers.
  539. @param x,y coordinates
  540. @param layers selected tree item layers
  541. """
  542. layers = self._giface.GetLayerList().GetSelectedLayers(checkedOnly=False)
  543. rast = []
  544. vect = []
  545. for layer in layers:
  546. name, found = GetLayerNameFromCmd(layer.cmd)
  547. if not found:
  548. continue
  549. ltype = layer.maplayer.GetType()
  550. if ltype == 'raster':
  551. rast.append(name)
  552. elif ltype in ('rgb', 'his'):
  553. for iname in name.split('\n'):
  554. rast.append(iname)
  555. elif ltype in ('vector', 'thememap', 'themechart'):
  556. vect.append(name)
  557. if vect:
  558. # check for vector maps open to be edited
  559. digitToolbar = self.GetToolbar('vdigit')
  560. if digitToolbar:
  561. lmap = digitToolbar.GetLayer().GetName()
  562. for name in vect:
  563. if lmap == name:
  564. self._giface.WriteWarning(_("Vector map <%s> "
  565. "opened for editing - skipped.") % lmap)
  566. vect.remove(name)
  567. if not (rast + vect):
  568. GMessage(parent = self,
  569. message = _('No raster or vector map layer selected for querying.'))
  570. return
  571. # set query snap distance for v.what at map unit equivalent of 10 pixels
  572. qdist = 10.0 * ((self.Map.region['e'] - self.Map.region['w']) / self.Map.width)
  573. # TODO: replace returning None by exception or so
  574. try:
  575. east, north = self.MapWindow.Pixel2Cell((x, y))
  576. except TypeError:
  577. return
  578. if not self.IsPaneShown('3d'):
  579. self.QueryMap(east, north, qdist, rast, vect)
  580. else:
  581. if rast:
  582. self.MapWindow.QuerySurface(x, y)
  583. if vect:
  584. self.QueryMap(east, north, qdist, rast = [], vect = vect)
  585. def QueryMap(self, east, north, qdist, rast, vect):
  586. """!Query raster or vector map layers by r/v.what
  587. @param east,north coordinates
  588. @param qdist query distance
  589. @param rast raster map names
  590. @param vect vector map names
  591. """
  592. Debug.msg(1, "QueryMap(): raster=%s vector=%s" % (','.join(rast),
  593. ','.join(vect)))
  594. # use display region settings instead of computation region settings
  595. self.tmpreg = os.getenv("GRASS_REGION")
  596. os.environ["GRASS_REGION"] = self.Map.SetRegion(windres = False)
  597. rastQuery = []
  598. vectQuery = []
  599. if rast:
  600. rastQuery = grass.raster_what(map=rast, coord=(east, north))
  601. if vect:
  602. vectQuery = grass.vector_what(map=vect, coord=(east, north), distance=qdist)
  603. self._QueryMapDone()
  604. if 'Id' in vectQuery:
  605. self._queryHighlight(vectQuery)
  606. result = rastQuery + vectQuery
  607. result = PrepareQueryResults(coordinates = (east, north), result = result)
  608. if self.dialogs['query']:
  609. self.dialogs['query'].Raise()
  610. self.dialogs['query'].SetData(result)
  611. else:
  612. self.dialogs['query'] = QueryDialog(parent = self, data = result)
  613. self.dialogs['query'].Bind(wx.EVT_CLOSE, self._oncloseQueryDialog)
  614. self.dialogs['query'].redirectOutput.connect(self._onRedirectQueryOutput)
  615. self.dialogs['query'].Show()
  616. def _oncloseQueryDialog(self, event):
  617. self.dialogs['query'] = None
  618. event.Skip()
  619. def _onRedirectQueryOutput(self, output, style='log'):
  620. """!Writes query output into console"""
  621. if style == 'log':
  622. self._giface.WriteLog(output, notification=Notification.MAKE_VISIBLE)
  623. elif style == 'cmd':
  624. self._giface.WriteCmdLog(output)
  625. def _queryHighlight(self, vectQuery):
  626. """!Highlight category from query."""
  627. cats = name = None
  628. for res in vectQuery:
  629. cats = {res['Layer']: [res['Category']]}
  630. name = res['Map']
  631. try:
  632. qlayer = self.Map.GetListOfLayers(name = globalvar.QUERYLAYER)[0]
  633. except IndexError:
  634. qlayer = None
  635. if not (cats and name):
  636. if qlayer:
  637. self.Map.DeleteLayer(qlayer)
  638. self.MapWindow.UpdateMap(render = False, renderVector = False)
  639. return
  640. if not self.IsPaneShown('3d') and self.IsAutoRendered():
  641. # highlight feature & re-draw map
  642. if qlayer:
  643. qlayer.SetCmd(self.AddTmpVectorMapLayer(name, cats,
  644. useId = False,
  645. addLayer = False))
  646. else:
  647. qlayer = self.AddTmpVectorMapLayer(name, cats, useId = False)
  648. # set opacity based on queried layer
  649. # TODO fix
  650. # opacity = layer.maplayer.GetOpacity(float = True)
  651. # qlayer.SetOpacity(opacity)
  652. self.MapWindow.UpdateMap(render = False, renderVector = False)
  653. def _QueryMapDone(self):
  654. """!Restore settings after querying (restore GRASS_REGION)
  655. """
  656. if hasattr(self, "tmpreg"):
  657. if self.tmpreg:
  658. os.environ["GRASS_REGION"] = self.tmpreg
  659. elif 'GRASS_REGION' in os.environ:
  660. del os.environ["GRASS_REGION"]
  661. elif 'GRASS_REGION' in os.environ:
  662. del os.environ["GRASS_REGION"]
  663. if hasattr(self, "tmpreg"):
  664. del self.tmpreg
  665. def OnQuery(self, event):
  666. """!Query tools menu"""
  667. self.MapWindow.mouse['use'] = "query"
  668. self.MapWindow.mouse['box'] = "point"
  669. self.MapWindow.zoomtype = 0
  670. # change the cursor
  671. self.MapWindow.SetNamedCursor('cross')
  672. def AddTmpVectorMapLayer(self, name, cats, useId = False, addLayer = True):
  673. """!Add temporal vector map layer to map composition
  674. @param name name of map layer
  675. @param useId use feature id instead of category
  676. """
  677. # color settings from ATM
  678. color = UserSettings.Get(group = 'atm', key = 'highlight', subkey = 'color')
  679. colorStr = str(color[0]) + ":" + \
  680. str(color[1]) + ":" + \
  681. str(color[2])
  682. # icon used in vector display and its size
  683. icon = ''
  684. size = 0
  685. # here we know that there is one selected layer and it is vector
  686. vparam = self._giface.GetLayerList().GetSelectedLayers()[0].cmd
  687. for p in vparam:
  688. if '=' in p:
  689. parg,pval = p.split('=', 1)
  690. if parg == 'icon': icon = pval
  691. elif parg == 'size': size = float(pval)
  692. pattern = ["d.vect",
  693. "map=%s" % name,
  694. "color=%s" % colorStr,
  695. "fcolor=%s" % colorStr,
  696. "width=%d" % UserSettings.Get(group = 'atm', key = 'highlight', subkey = 'width')]
  697. if icon != '':
  698. pattern.append('icon=%s' % icon)
  699. if size > 0:
  700. pattern.append('size=%i' % size)
  701. if useId:
  702. cmd = pattern
  703. cmd.append('-i')
  704. cmd.append('cats=%s' % str(cats))
  705. else:
  706. cmd = []
  707. for layer in cats.keys():
  708. cmd.append(copy.copy(pattern))
  709. lcats = cats[layer]
  710. cmd[-1].append("layer=%d" % layer)
  711. cmd[-1].append("cats=%s" % ListOfCatsToRange(lcats))
  712. if addLayer:
  713. if useId:
  714. return self.Map.AddLayer(ltype = 'vector', name = globalvar.QUERYLAYER, command = cmd,
  715. active = True, hidden = True, opacity = 1.0)
  716. else:
  717. return self.Map.AddLayer(ltype = 'command', name = globalvar.QUERYLAYER, command = cmd,
  718. active = True, hidden = True, opacity = 1.0)
  719. else:
  720. return cmd
  721. def OnMeasureDistance(self, event):
  722. self._onMeasure(MeasureDistanceController)
  723. def OnMeasureArea(self, event):
  724. self._onMeasure(MeasureAreaController)
  725. def _onMeasure(self, controller):
  726. """!Starts measurement mode.
  727. @param controller measurement class (MeasureDistanceController, MeasureAreaController)
  728. """
  729. self.measureController = controller(self._giface, mapWindow=self.GetMapWindow())
  730. # assure that the mode is ended and lines are cleared whenever other tool is selected
  731. self._toolSwitcher.toggleToolChanged.connect(lambda: self.measureController.Stop())
  732. self.measureController.Start()
  733. def OnProfile(self, event):
  734. """!Launch profile tool
  735. """
  736. rasters = []
  737. layers = self._giface.GetLayerList().GetSelectedLayers()
  738. for layer in layers:
  739. if layer.type == 'raster':
  740. rasters.append(layer.maplayer.name)
  741. self.Profile(rasters=rasters)
  742. def Profile(self, rasters=None):
  743. """!Launch profile tool"""
  744. self.profileController = ProfileController(self._giface,
  745. mapWindow=self.GetMapWindow())
  746. win = ProfileFrame(parent=self, rasterList=rasters,
  747. units=self.Map.projinfo['units'],
  748. controller=self.profileController)
  749. win.Show()
  750. # Open raster select dialog to make sure that a raster (and
  751. # the desired raster) is selected to be profiled
  752. win.OnSelectRaster(None)
  753. def OnHistogramPyPlot(self, event):
  754. """!Init PyPlot histogram display canvas and tools
  755. """
  756. raster = []
  757. for layer in self._giface.GetLayerList().GetSelectedLayers():
  758. if layer.maplayer.GetType() == 'raster':
  759. raster.append(layer.maplayer.GetName())
  760. win = HistogramPlotFrame(parent = self, rasterList = raster)
  761. win.CentreOnParent()
  762. win.Show()
  763. def OnScatterplot(self, event):
  764. """!Init PyPlot scatterplot display canvas and tools
  765. """
  766. raster = []
  767. for layer in self._giface.GetLayerList().GetSelectedLayers():
  768. if layer.maplayer.GetType() == 'raster':
  769. raster.append(layer.maplayer.GetName())
  770. win = ScatterFrame(parent = self, rasterList = raster)
  771. win.CentreOnParent()
  772. win.Show()
  773. # Open raster select dialog to make sure that at least 2 rasters (and the desired rasters)
  774. # are selected to be plotted
  775. win.OnSelectRaster(None)
  776. def OnHistogram(self, event):
  777. """!Init histogram display canvas and tools
  778. """
  779. win = HistogramFrame(self, giface=self._giface)
  780. win.CentreOnParent()
  781. win.Show()
  782. win.Refresh()
  783. win.Update()
  784. def _activateOverlay(self, overlayId):
  785. """!Launch decoration dialog according to overlay id.
  786. @param overlayId id of overlay
  787. """
  788. if overlayId > 100:
  789. self.OnAddText(None)
  790. elif overlayId == 0:
  791. self.AddLegend(showDialog=True)
  792. elif overlayId == 1:
  793. self.AddBarscale(showDialog=True)
  794. elif overlayId == 2:
  795. self.AddArrow(showDialog=True)
  796. def _hideOverlay(self, overlayId):
  797. """!Hide overlay.
  798. @param overlayId id of overlay
  799. """
  800. self.decorations[overlayId].Hide()
  801. def AddBarscale(self, cmd=None, showDialog=None):
  802. """!Handler for scale bar map decoration menu selection."""
  803. if self.IsPaneShown('3d'):
  804. self.MapWindow3D.SetDrawScalebar((70, 70))
  805. return
  806. if self.barscale.IsShown() and showDialog is None:
  807. self.barscale.Hide()
  808. return
  809. if cmd:
  810. self.barscale.cmd = cmd
  811. if not showDialog:
  812. self.barscale.Show()
  813. return
  814. # Decoration overlay control dialog
  815. if self.barscale.dialog:
  816. if self.barscale.dialog.IsShown():
  817. self.barscale.dialog.SetFocus()
  818. self.barscale.dialog.Raise()
  819. else:
  820. self.barscale.dialog.Show()
  821. else:
  822. # If location is latlon, only display north arrow (scale won't work)
  823. # proj = self.Map.projinfo['proj']
  824. # if proj == 'll':
  825. # barcmd = 'd.barscale -n'
  826. # else:
  827. # barcmd = 'd.barscale'
  828. # decoration overlay control dialog
  829. GUI(parent=self, giface=self._giface, show=True,
  830. modal=False).ParseCommand(self.barscale.cmd,
  831. completed=(self.barscale.GetOptData, None, None))
  832. self.MapWindow.mouse['use'] = 'pointer'
  833. def AddLegend(self, cmd=None, showDialog=None):
  834. """!Handler for legend map decoration menu selection."""
  835. if self.legend.IsShown() and showDialog is None:
  836. self.legend.Hide()
  837. return
  838. if cmd:
  839. self.legend.cmd = cmd
  840. else:
  841. layers = self._giface.GetLayerList().GetSelectedLayers()
  842. for layer in layers:
  843. if layer.type == 'raster':
  844. self.legend.cmd.append('map=%s' % layer.maplayer.name)
  845. break
  846. if not showDialog and self.legend.CmdIsValid():
  847. self.legend.Show()
  848. return
  849. # Decoration overlay control dialog
  850. if self.legend.dialog:
  851. if self.legend.dialog.IsShown():
  852. self.legend.dialog.SetFocus()
  853. self.legend.dialog.Raise()
  854. else:
  855. self.legend.dialog.Show()
  856. else:
  857. GUI(parent=self, giface=self._giface, show=True,
  858. modal=False).ParseCommand(self.legend.cmd,
  859. completed=(self.legend.GetOptData, None, None))
  860. self.MapWindow.mouse['use'] = 'pointer'
  861. def AddArrow(self, cmd=None, showDialog=None):
  862. """!Handler for north arrow menu selection."""
  863. if self.IsPaneShown('3d'):
  864. # here was opening of appearance page of nviz notebook
  865. # but now moved to MapWindow3D where are other problematic nviz calls
  866. self.MapWindow3D.SetDrawArrow((70, 70))
  867. return
  868. if self.arrow.IsShown() and showDialog is None:
  869. self.arrow.Hide()
  870. return
  871. if cmd:
  872. self.arrow.cmd = cmd
  873. if not showDialog:
  874. self.arrow.Show()
  875. return
  876. # Decoration overlay control dialog
  877. if self.arrow.dialog:
  878. if self.arrow.dialog.IsShown():
  879. self.arrow.dialog.SetFocus()
  880. self.arrow.dialog.Raise()
  881. else:
  882. self.arrow.dialog.Show()
  883. else:
  884. GUI(parent=self, giface=self._giface, show=True,
  885. modal=False).ParseCommand(self.arrow.cmd,
  886. completed=(self.arrow.GetOptData, None, None))
  887. self.MapWindow.mouse['use'] = 'pointer'
  888. def OnAddText(self, event):
  889. """!Handler for text decoration menu selection.
  890. """
  891. if self.MapWindow.dragid > -1:
  892. id = self.MapWindow.dragid
  893. self.MapWindow.dragid = -1
  894. else:
  895. # index for overlay layer in render
  896. if len(self.MapWindow.textdict.keys()) > 0:
  897. id = max(self.MapWindow.textdict.keys()) + 1
  898. else:
  899. id = 101
  900. self.dialogs['text'] = TextLayerDialog(parent = self, ovlId = id,
  901. title = _('Add text layer'),
  902. size = (400, 200))
  903. self.dialogs['text'].CenterOnParent()
  904. # If OK button pressed in decoration control dialog
  905. if self.dialogs['text'].ShowModal() == wx.ID_OK:
  906. text = self.dialogs['text'].GetValues()['text']
  907. active = self.dialogs['text'].GetValues()['active']
  908. # delete object if it has no text or is not active
  909. if text == '' or active == False:
  910. try:
  911. self.MapWindow2D.pdc.ClearId(id)
  912. self.MapWindow2D.pdc.RemoveId(id)
  913. del self.MapWindow.textdict[id]
  914. if self.IsPaneShown('3d'):
  915. self.MapWindow3D.UpdateOverlays()
  916. self.MapWindow.UpdateMap()
  917. else:
  918. self.MapWindow2D.UpdateMap(render = False, renderVector = False)
  919. except:
  920. pass
  921. return
  922. self.MapWindow.textdict[id] = self.dialogs['text'].GetValues()
  923. if self.IsPaneShown('3d'):
  924. self.MapWindow3D.UpdateOverlays()
  925. self.MapWindow3D.UpdateMap()
  926. else:
  927. self.MapWindow2D.pdc.ClearId(id)
  928. self.MapWindow2D.pdc.SetId(id)
  929. self.MapWindow2D.UpdateMap(render = False, renderVector = False)
  930. self.MapWindow.mouse['use'] = 'pointer'
  931. def GetOptData(self, dcmd, type, params, propwin):
  932. """!Callback method for decoration overlay command generated by
  933. dialog created in menuform.py
  934. """
  935. # Reset comand and rendering options in render.Map. Always render decoration.
  936. # Showing/hiding handled by PseudoDC
  937. self.Map.ChangeOverlay(ovltype = type, type = 'overlay', name = '', command = dcmd,
  938. active = True, render = False)
  939. self.params[type] = params
  940. self.propwin[type] = propwin
  941. def OnZoomToMap(self, event):
  942. """!Set display extents to match selected raster (including
  943. NULLs) or vector map.
  944. """
  945. Debug.msg(3, "MapFrame.OnZoomToMap()")
  946. layers = None
  947. if self.IsStandalone():
  948. layers = self.MapWindow.GetMap().GetListOfLayers(active = False)
  949. self.MapWindow.ZoomToMap(layers = layers)
  950. def OnZoomToRaster(self, event):
  951. """!Set display extents to match selected raster map (ignore NULLs)
  952. """
  953. self.MapWindow.ZoomToMap(ignoreNulls = True)
  954. def OnZoomToSaved(self, event):
  955. """!Set display geometry to match extents in
  956. saved region file
  957. """
  958. self.MapWindow.SetRegion(zoomOnly=True)
  959. def OnSetDisplayToWind(self, event):
  960. """!Set computational region (WIND file) to match display
  961. extents
  962. """
  963. self.MapWindow.DisplayToWind()
  964. def OnSetWindToRegion(self, event):
  965. """!Set computational region (WIND file) from named region
  966. file
  967. """
  968. self.MapWindow.SetRegion(zoomOnly=False)
  969. def OnSaveDisplayRegion(self, event):
  970. """!Save display extents to named region file.
  971. """
  972. self.MapWindow.SaveRegion(display = True)
  973. def OnSaveWindRegion(self, event):
  974. """!Save computational region to named region file.
  975. """
  976. self.MapWindow.SaveRegion(display = False)
  977. def OnZoomMenu(self, event):
  978. """!Popup Zoom menu
  979. """
  980. zoommenu = wx.Menu()
  981. for label, handler in ((_('Zoom to default region'), self.OnZoomToDefault),
  982. (_('Zoom to saved region'), self.OnZoomToSaved),
  983. (None, None),
  984. (_('Set computational region from display extent'), self.OnSetDisplayToWind),
  985. (_('Set computational region from named region'), self.OnSetWindToRegion),
  986. (None, None),
  987. (_('Save display geometry to named region'), self.OnSaveDisplayRegion),
  988. (_('Save computational region to named region'), self.OnSaveWindRegion)):
  989. if label:
  990. mid = wx.MenuItem(zoommenu, wx.ID_ANY, label)
  991. zoommenu.AppendItem(mid)
  992. self.Bind(wx.EVT_MENU, handler, mid)
  993. else:
  994. zoommenu.AppendSeparator()
  995. # Popup the menu. If an item is selected then its handler will
  996. # be called before PopupMenu returns.
  997. self.PopupMenu(zoommenu)
  998. zoommenu.Destroy()
  999. def SetProperties(self, render = False, mode = 0, showCompExtent = False,
  1000. constrainRes = False, projection = False, alignExtent = True):
  1001. """!Set properies of map display window"""
  1002. self.mapWindowProperties.autoRender = render
  1003. self.statusbarManager.SetMode(mode)
  1004. self.StatusbarUpdate()
  1005. self.mapWindowProperties.showRegion = showCompExtent
  1006. self.mapWindowProperties.alignExtent = alignExtent
  1007. self.mapWindowProperties.resolution = constrainRes
  1008. self.SetProperty('projection', projection)
  1009. def IsStandalone(self):
  1010. """!Check if Map display is standalone
  1011. @depreciated
  1012. """
  1013. # TODO: once it is removed from 2 places in vdigit it can be deleted
  1014. # here and also in base class and other classes in the tree (hopefully)
  1015. # and one place here still uses IsStandalone
  1016. Debug.msg(1, "MapFrame.IsStandalone(): Method IsStandalone is"
  1017. "depreciated, use some general approach instead such as"
  1018. " Signals or giface")
  1019. if self._layerManager:
  1020. return False
  1021. return True
  1022. def GetLayerManager(self):
  1023. """!Get reference to Layer Manager
  1024. @return window reference
  1025. @return None (if standalone)
  1026. @depreciated
  1027. """
  1028. Debug.msg(1, "MapFrame.GetLayerManager(): Method GetLayerManager is"
  1029. "depreciated, use some general approach instead such as"
  1030. " Signals or giface")
  1031. return self._layerManager
  1032. def GetMapToolbar(self):
  1033. """!Returns toolbar with zooming tools"""
  1034. return self.toolbars['map']
  1035. def OnVNet(self, event):
  1036. """!Dialog for v.net* modules
  1037. """
  1038. if self.dialogs['vnet']:
  1039. self.dialogs['vnet'].Raise()
  1040. return
  1041. from vnet.dialogs import VNETDialog
  1042. self.dialogs['vnet'] = VNETDialog(parent=self, giface=self._giface)
  1043. self.dialogs['vnet'].CenterOnScreen()
  1044. self.dialogs['vnet'].Show()
  1045. def ResetPointer(self):
  1046. """Sets pointer mode.
  1047. Sets pointer and toggles it (e.g. after unregistration of mouse
  1048. handler).
  1049. """
  1050. self.GetMapToolbar().SelectDefault()