Skip to content

Commit

Permalink
wxGUI: Avoid overlapping module parameters in Graphical modeler (#2991)
Browse files Browse the repository at this point in the history
  • Loading branch information
landam committed Oct 25, 2023
1 parent 493af31 commit ac91f61
Showing 1 changed file with 39 additions and 37 deletions.
76 changes: 39 additions & 37 deletions gui/wxpython/gmodeler/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import stat
import tempfile
import random
import six
import math

import wx
from wx.lib import ogl
Expand Down Expand Up @@ -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)
Expand All @@ -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()

Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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"""
Expand Down

0 comments on commit ac91f61

Please sign in to comment.