frame.py 48 KB

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