Skip to content

Commit

Permalink
wxGUI/mapwin: disable auto-rendering map completely (resize Map Displ…
Browse files Browse the repository at this point in the history
…ay window event etc.) (OSGeo#2018)
  • Loading branch information
tmszi authored Jun 16, 2024
1 parent 2c0f5c4 commit 6d42a02
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 129 deletions.
5 changes: 2 additions & 3 deletions gui/wxpython/dbmgr/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,8 @@ def OnClose(self, event):
frame.dialogs["attributes"] = None
if hasattr(self, "digit"):
self.parent.digit.GetDisplay().SetSelected([])
if frame.IsAutoRendered():
self.parent.UpdateMap(render=False)
elif frame.IsAutoRendered():
self.parent.UpdateMap(render=False)
else:
frame.RemoveQueryLayer()
self.parent.UpdateMap(render=True)
if self.IsModal():
Expand Down
2 changes: 2 additions & 0 deletions gui/wxpython/docs/wxGUI.html
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,8 @@ <h4>Map Display</h4>
<dd>Render map (re-renders map)</dd>
<dt>F5</dt>
<dd>Render map (re-renders map)</dd>
<dt>F6</dt>
<dd>Enable/disable auto-rendering map (re-renders map)</dd>
</dl>

<h3>Starting the GUI from command line</h3>
Expand Down
20 changes: 17 additions & 3 deletions gui/wxpython/gcp/mapdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def __init__(
self._giface = giface

self.mapWindowProperties.alignExtent = True
self.mapWindowProperties.autoRenderChanged.connect(self.OnAutoRenderChanged)

#
# Add toolbars
Expand Down Expand Up @@ -367,19 +368,29 @@ def OnFocus(self, event):

def OnDraw(self, event):
"""Re-display current map composition"""
self.MapWindow.UpdateMap(render=False)
kwargs = {}
# Handle display map event (mouse click on toolbar Display map
# tool)
if event and event.GetEventType() == wx.EVT_TOOL.typeId:
kwargs = {"reRenderTool": True}
self.MapWindow.UpdateMap(render=False, **kwargs)

def OnRender(self, event):
"""Re-render map composition (each map layer)"""
kwargs = {}
# Handle re-render map event (mouse click on toolbar Render map
# tool, F5/Ctrl+R keyboard shortcut)
if event and event.GetEventType() == wx.EVT_TOOL.typeId:
kwargs = {"reRenderTool": True}
# FIXME: remove qlayer code or use RemoveQueryLayer() now in mapdisp.frame
# delete tmp map layers (queries)
qlayer = self.Map.GetListOfLayers(name=globalvar.QUERYLAYER)
for layer in qlayer:
self.Map.DeleteLayer(layer)

self.SrcMapWindow.UpdateMap(render=True)
self.SrcMapWindow.UpdateMap(render=True, **kwargs)
if self.show_target:
self.TgtMapWindow.UpdateMap(render=True)
self.TgtMapWindow.UpdateMap(render=True, **kwargs)

# update statusbar
self.StatusbarUpdate()
Expand Down Expand Up @@ -420,6 +431,9 @@ def OnErase(self, event):

win.EraseMap()

def OnAutoRenderChanged(self, value):
self.OnRender(event=None)

def SaveToFile(self, event):
"""Save map to image"""
img = self.MapWindow.img
Expand Down
51 changes: 30 additions & 21 deletions gui/wxpython/gui_core/mapdisp.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ class MapPanelBase(wx.Panel):
Several methods has to be overridden or
\c NotImplementedError("MethodName") will be raised.
If derived class enables and disables auto-rendering,
it should override IsAutoRendered method.
It is expected that derived class will call _setUpMapWindow().
Derived class can has one or more map windows (and map renders)
Expand Down Expand Up @@ -115,6 +112,7 @@ def __init__(
(self.OnCloseWindow, wx.ACCEL_CTRL, ord("W")),
(self.OnRender, wx.ACCEL_CTRL, ord("R")),
(self.OnRender, wx.ACCEL_NORMAL, wx.WXK_F5),
(self.OnEnableDisableRender, wx.ACCEL_NORMAL, wx.WXK_F6),
]

self._initShortcuts()
Expand Down Expand Up @@ -315,14 +313,6 @@ def StatusbarUpdate(self):
Debug.msg(5, "MapPanelBase.StatusbarUpdate()")
self.statusbarManager.Update()

def IsAutoRendered(self):
"""Check if auto-rendering is enabled"""
# TODO: this is now not the right place to access this attribute
# TODO: add mapWindowProperties to init parameters
# and pass the right object in the init of derived class?
# or do not use this method at all, let mapwindow decide
return self.mapWindowProperties.autoRender

def CoordinatesChanged(self):
"""Shows current coordinates on statusbar."""
# assuming that the first mode is coordinates
Expand Down Expand Up @@ -435,6 +425,13 @@ def OnRender(self, event):
"""Re-render map composition (each map layer)"""
raise NotImplementedError("OnRender")

def OnEnableDisableRender(self, event):
"""Enable/disable auto-rendering map composition (each map layer)"""
if self.MapWindow.parent.mapWindowProperties.autoRender:
self.MapWindow.parent.mapWindowProperties.autoRender = False
else:
self.MapWindow.parent.mapWindowProperties.autoRender = True

def OnDraw(self, event):
"""Re-display current map composition"""
self.MapWindow.UpdateMap(render=False)
Expand Down Expand Up @@ -776,13 +773,20 @@ def OnQuery(self, event):

def OnRender(self, event):
"""Re-render map composition (each map layer)"""
self.Render(mapToRender=self.GetFirstWindow())
self.Render(mapToRender=self.GetSecondWindow())

def Render(self, mapToRender):
kwargs = {}
# Handle re-render map event (mouse click on toolbar Render map
# tool, F5/Ctrl + R keyboard shortcut)
if event and event.GetEventType() == wx.EVT_TOOL.typeId:
kwargs = {"reRenderTool": True}
self.Render(mapToRender=self.GetFirstWindow(), **kwargs)
self.Render(mapToRender=self.GetSecondWindow(), **kwargs)

def Render(self, mapToRender, reRenderTool=False):
"""Re-render map composition"""
mapToRender.UpdateMap(
render=True, renderVector=mapToRender == self.GetFirstWindow()
render=True,
renderVector=mapToRender == self.GetFirstWindow(),
reRenderTool=reRenderTool,
)

# update statusbar
Expand All @@ -799,12 +803,17 @@ def Erase(self, mapToErase):

def OnDraw(self, event):
"""Re-display current map composition"""
self.Draw(mapToDraw=self.GetFirstWindow())
self.Draw(mapToDraw=self.GetSecondWindow())

def Draw(self, mapToDraw):
kwargs = {}
# Handle display map event (mouse click on toolbar Display map
# tool)
if event and event.GetEventType() == wx.EVT_TOOL.typeId:
kwargs = {"reRenderTool": True}
self.Draw(mapToDraw=self.GetFirstWindow(), **kwargs)
self.Draw(mapToDraw=self.GetSecondWindow(), **kwargs)

def Draw(self, mapToDraw, reRenderTool=False):
"""Re-display current map composition"""
mapToDraw.UpdateMap(render=False)
mapToDraw.UpdateMap(render=False, reRenderTool=reRenderTool)


class FrameMixin:
Expand Down
27 changes: 16 additions & 11 deletions gui/wxpython/iclass/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def __init__(

# show computation region by default
self.mapWindowProperties.showRegion = True
self.mapWindowProperties.autoRenderChanged.connect(self.OnAutoRenderChanged)

self.firstMapWindow = IClassVDigitWindow(
parent=self,
Expand Down Expand Up @@ -213,13 +214,6 @@ def __init__(

self.SendSizeEvent()

def OnCloseWindow(self, event):
self.GetFirstWindow().GetDigit().CloseMap()
self.plotPanel.CloseWindow()
self._cleanup()
self._mgr.UnInit()
self.Destroy()

def _cleanup(self):
"""Frees C structs and removes vector map and all raster maps."""
I_free_signatures(self.signatures)
Expand All @@ -231,16 +225,27 @@ def _cleanup(self):
for i in self.stats_data.GetCategories():
self.RemoveTempRaster(self.stats_data.GetStatistics(i).rasterName)

def OnHelp(self, event):
"""Show help page"""
self.giface.Help(entry="wxGUI.iclass")

def _getTempVectorName(self):
"""Return new name for temporary vector map (training areas)"""
vectorPath = grass.tempfile(create=False)

return "trAreas" + os.path.basename(vectorPath).replace(".", "")

def OnAutoRenderChanged(self, value):
"""Auto rendering state changed."""
self.OnRender(event=None)

def OnCloseWindow(self, event):
self.GetFirstWindow().GetDigit().CloseMap()
self.plotPanel.CloseWindow()
self._cleanup()
self._mgr.UnInit()
self.Destroy()

def OnHelp(self, event):
"""Show help page"""
self.giface.Help(entry="wxGUI.iclass")

def SetGroup(self, group, subgroup):
"""Set group and subgroup manually"""
self.g = {"group": group, "subgroup": subgroup}
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/lmgr/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2212,8 +2212,7 @@ def OnShowRegionExtent(self, event):
# redraw map if auto-rendering is enabled
# seems little too low level for this place
# no redraw when Render is unchecked
if mapdisp.IsAutoRendered():
mapdisp.GetMapWindow().UpdateMap(render=False)
mapdisp.GetMapWindow().UpdateMap(render=False)

def OnDeleteLayer(self, event):
"""Remove selected map layer from the current layer Tree"""
Expand Down
5 changes: 1 addition & 4 deletions gui/wxpython/lmgr/layertree.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,7 @@ def OnIdle(self, event):
# restart rerender value here before wx.Yield
# can cause another idle event
self.rerender = False
if self.mapdisplay.IsAutoRendered():
self.mapdisplay.GetMapWindow().UpdateMap(render=False)
self.mapdisplay.GetMapWindow().UpdateMap(render=False)

event.Skip()

Expand Down Expand Up @@ -1958,12 +1957,10 @@ def OnChangeSel(self, event):
):
mapLayer = self.GetLayerInfo(layer, key="maplayer")
if mapLayer.GetType() in ("raster", "vector"):
render = self.mapdisplay.IsAutoRendered()
self.mapdisplay.MapWindow.ZoomToMap(
layers=[
mapLayer,
],
render=render,
)

# update nviz tools
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/main_window/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2322,8 +2322,7 @@ def OnShowRegionExtent(self, event):
# redraw map if auto-rendering is enabled
# seems little too low level for this place
# no redraw when Render is unchecked
if mapdisp.IsAutoRendered():
mapdisp.GetMapWindow().UpdateMap(render=False)
mapdisp.GetMapWindow().UpdateMap(render=False)

def OnDeleteLayer(self, event):
"""Remove selected map layer from the current layer Tree"""
Expand Down
8 changes: 6 additions & 2 deletions gui/wxpython/mapdisp/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,13 @@ def OnRender(self, event):
if self.GetToolbar("vdigit"):
if self.MapWindow.digit:
self.MapWindow.digit.GetDisplay().SetSelected([])
self.MapWindow.UpdateMap(render=True, renderVector=True)
self.MapWindow.UpdateMap(
render=True,
renderVector=True,
reRenderTool=True,
)
else:
self.MapWindow.UpdateMap(render=True)
self.MapWindow.UpdateMap(render=True, reRenderTool=True)

# reset dialog with selected features
if self.dialogs["vselect"]:
Expand Down
7 changes: 3 additions & 4 deletions gui/wxpython/mapswipe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def OnAutoRenderChanged(self, value):
style = self.splitter.GetWindowStyle()
style ^= wx.SP_LIVE_UPDATE
self.splitter.SetWindowStyle(style)
self._simpleLmgrChanged()

def AddToolbar(self, name):
"""Add defined toolbar to the window
Expand Down Expand Up @@ -443,8 +444,7 @@ def _connectSimpleLmgr(self, lmgr, renderer):
return converter

def _simpleLmgrChanged(self):
if self.IsAutoRendered():
self.OnRender(event=None)
self.OnRender(event=None)

def OnApplyInputChanges(self):
first, second = self._inputDialog.GetValues()
Expand All @@ -467,8 +467,7 @@ def OnApplyInputChanges(self):
LayerListToRendererConverter(self.GetSecondMap()).ConvertAll(second)

self.SetRasterNames()
if self.IsAutoRendered():
self.OnRender(event=None)
self.OnRender(event=None)

def SetFirstRaster(self, name):
"""Set raster map to first Map"""
Expand Down
23 changes: 22 additions & 1 deletion gui/wxpython/mapwin/buffered.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,13 @@ def SetAlwaysRenderEnabled(self, alwaysRender=True):
def IsAlwaysRenderEnabled(self):
return self.alwaysRender

def UpdateMap(self, render=True, renderVector=True, delay=0.0):
def UpdateMap(
self,
render=True,
renderVector=True,
delay=0.0,
reRenderTool=False,
):
"""Updates the canvas anytime there is a change to the
underlying images or to the geometry of the canvas.
Expand All @@ -870,6 +876,10 @@ def UpdateMap(self, render=True, renderVector=True, delay=0.0):
digitizer)
:param delay: defines time threshold in seconds for postponing
rendering to merge more update requests.
:param reRenderTool bool: enable re-render map if True, when
auto re-render map is disabled and
Display map or Render map tool is
activated from the Map Display toolbar
If another request comes within the limit, rendering is delayed
again. Next delay limit is chosen according to the smallest
Expand All @@ -888,6 +898,9 @@ def UpdateMap(self, render=True, renderVector=True, delay=0.0):
will be updated with the True value of the argument.
"""

if not self._properties.autoRender and not reRenderTool:
return

if self.timerRunId is None or delay < self.updDelay:
self.updDelay = delay

Expand Down Expand Up @@ -1088,6 +1101,14 @@ def DragMap(self, moveto):
:param moveto: dx,dy
"""
# Prevent drag map error if auto re-render map is disabled
# wx._core.wxAssertionError: C++ assertion
# "!wxMouseCapture::IsInCaptureStack(this) failed at
# /tmp/pip-req-build-oxkmg2wi/ext/wxWidgets/src/common/wincmn.cpp(3270) in
# CaptureMouse(): Recapturing the mouse in the same window?
if not self._properties.autoRender:
return

dc = wx.BufferedDC(wx.ClientDC(self))
dc.SetBackground(wx.Brush("White"))
dc.Clear()
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/modules/colorrules.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def _apply(self, updatePreview=True):
if updatePreview:
self.OnPreview(None)
display = self.layerTree.GetMapDisplay()
if display and display.IsAutoRendered():
if display:
display.GetWindow().UpdateMap(render=True)

return ret
Expand Down
9 changes: 8 additions & 1 deletion gui/wxpython/nviz/mapwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1176,13 +1176,20 @@ def UpdateLight(self, event):
if event.refresh:
self.Refresh(False)

def UpdateMap(self, render=True):
def UpdateMap(self, render=True, reRenderTool=False):
"""Updates the canvas anytime there is a change to the
underlying images or to the geometry of the canvas.
:param render: re-render map composition
:type render: bool
:param reRenderTool bool: enable re-render map if True, when
auto re-render map is disabled and
Render map tool is activated from the
Map Display toolbar
"""
if not self.parent.mapWindowProperties.autoRender and not reRenderTool:
return

start = grass.clock()

self.resize = False
Expand Down
Loading

0 comments on commit 6d42a02

Please sign in to comment.