frame.py 47 KB

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