From ac91f61db47217ad909dba6c9c4e8222bef917bb Mon Sep 17 00:00:00 2001 From: Martin Landa Date: Wed, 25 Oct 2023 16:19:58 +0200 Subject: [PATCH] wxGUI: Avoid overlapping module parameters in Graphical modeler (#2991) --- gui/wxpython/gmodeler/frame.py | 76 +++++++++++++++++----------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/gui/wxpython/gmodeler/frame.py b/gui/wxpython/gmodeler/frame.py index 3f04e3eb1f3..b2ffc978219 100644 --- a/gui/wxpython/gmodeler/frame.py +++ b/gui/wxpython/gmodeler/frame.py @@ -26,7 +26,7 @@ import stat import tempfile import random -import six +import math import wx from wx.lib import ogl @@ -839,12 +839,13 @@ def OnAddAction(self, event): action = ModelAction( self.model, cmd=cmd, - x=x + self._randomShift(), - y=y + self._randomShift(), + x=x, + y=y, id=self.model.GetNextId(), label=label, comment=comment, ) + overwrite = self.model.GetProperties().get("overwrite", None) if overwrite is not None: action.GetTask().set_flag("overwrite", overwrite) @@ -862,24 +863,15 @@ def OnAddAction(self, event): # show properties dialog win = action.GetPropDialog() if not win: - cmdLength = len(action.GetLog(string=False)) - if cmdLength > 1 and action.IsValid(): - self.GetOptData( - dcmd=action.GetLog(string=False), - layer=action, - params=action.GetParams(), - propwin=None, - ) - else: - gmodule = GUI( - parent=self, - show=True, - giface=GraphicalModelerGrassInterface(self.model), - ) - gmodule.ParseCommand( - action.GetLog(string=False), - completed=(self.GetOptData, action, action.GetParams()), - ) + gmodule = GUI( + parent=self, + show=True, + giface=GraphicalModelerGrassInterface(self.model), + ) + gmodule.ParseCommand( + action.GetLog(string=False), + completed=(self.GetOptData, action, action.GetParams()), + ) elif win and not win.IsShown(): win.Show() @@ -931,8 +923,8 @@ def OnAddComment(self, event): x, y = self.canvas.GetNewShapePos() commentObj = ModelComment( self.model, - x=x + self._randomShift(), - y=y + self._randomShift(), + x=x, + y=y, id=self.model.GetNextId(), label=comment, ) @@ -968,9 +960,10 @@ def OnAbout(self, event): def GetOptData(self, dcmd, layer, params, propwin): """Process action data""" if params: # add data items - width, height = self.canvas.GetSize() - x = width / 2 - 200 + self._randomShift() - y = height / 2 + self._randomShift() + data_items = [] + x = layer.GetX() + y = layer.GetY() + for p in params["params"]: if p.get("prompt", "") not in ( "raster", @@ -1019,9 +1012,10 @@ def GetOptData(self, dcmd, layer, params, propwin): x=x, y=y, ) + data_items.append(data) self._addEvent(data) self.canvas.diagram.AddShape(data) - data.Show(True) + data.Show(False) if p.get("age", "old") == "old": rel = ModelRelation( @@ -1057,11 +1051,21 @@ def GetOptData(self, dcmd, layer, params, propwin): # valid / parameterized ? layer.SetValid(params) - self.canvas.Refresh() + # arrange data items + if data_items: + dc = wx.ClientDC(self.canvas) + p = 360 / len(data_items) + r = 200 + alpha = 270 * (math.pi / 180) + for data in data_items: + data.Move(dc, x + r * math.sin(alpha), y + r * math.cos(alpha)) + alpha += p * (math.pi / 180) + data.Show(True) if dcmd: layer.SetProperties(params, propwin) + self.canvas.Refresh() self.SetStatusText(layer.GetLog(), 0) def AddLine(self, rel): @@ -1340,21 +1344,19 @@ def RemoveShapes(self, shapes): self.Refresh() - def GetNewShapePos(self): + def GetNewShapePos(self, yoffset=50): """Determine optimal position for newly added object :return: x,y """ - xNew, yNew = map(lambda x: x / 2, self.GetSize()) diagram = self.GetDiagram() + if diagram.GetShapeList(): + last = diagram.GetShapeList()[-1] + y = last.GetY() + last.GetBoundingBoxMin()[1] + else: + y = 20 - for shape in diagram.GetShapeList(): - y = shape.GetY() - yBox = shape.GetBoundingBoxMin()[1] / 2 - if yBox > 0 and y < yNew + yBox and y > yNew - yBox: - yNew += yBox * 3 - - return xNew, yNew + return (self.GetSize()[0] // 2, y + yoffset) def GetShapesSelected(self): """Get list of selected shapes"""