[GRASS-SVN] r53658 - grass/branches/releasebranch_6_4/gui/wxpython/gmodeler

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Nov 2 04:34:27 PDT 2012


Author: martinl
Date: 2012-11-02 04:34:26 -0700 (Fri, 02 Nov 2012)
New Revision: 53658

Modified:
   grass/branches/releasebranch_6_4/gui/wxpython/gmodeler/frame.py
Log:
wxGUI Modeler: better positioning new actions
      (merge r53656 from trunk)


Modified: grass/branches/releasebranch_6_4/gui/wxpython/gmodeler/frame.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gmodeler/frame.py	2012-11-02 11:32:07 UTC (rev 53657)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gmodeler/frame.py	2012-11-02 11:34:26 UTC (rev 53658)
@@ -30,11 +30,12 @@
 
 if __name__ == "__main__":
     sys.path.append(os.path.join(os.getenv('GISBASE'), 'etc', 'wxpython'))
-from core                 import globalvar
+
 import wx
-from wx.lib import ogl
+from   wx.lib import ogl
 import wx.lib.flatnotebook    as FN
 
+from core                 import globalvar
 from gui_core.widgets     import GNotebook
 from gui_core.goutput     import GMConsole, PyStc
 from core.debug           import Debug
@@ -620,7 +621,7 @@
             self.searchDialog.CentreOnParent()
         else:
             self.searchDialog.Reset()
-            
+        
         if self.searchDialog.ShowModal() == wx.ID_CANCEL:
             self.searchDialog.Hide()
             return
@@ -631,9 +632,8 @@
         self.ModelChanged()
         
         # add action to canvas
-        width, height = self.canvas.GetSize()
-        
-        action = ModelAction(self.model, cmd = cmd, x = width/2, y = height/2,
+        x, y = self.canvas.GetNewShapePos()
+        action = ModelAction(self.model, cmd = cmd, x = x, y = y,
                              id = self.model.GetNextId())
         overwrite = self.model.GetProperties().get('overwrite', None)
         if overwrite is not None:
@@ -641,7 +641,7 @@
         
         self.canvas.diagram.AddShape(action)
         action.Show(True)
-
+        
         self._addEvent(action)
         self.model.AddItem(action)
         
@@ -1005,6 +1005,22 @@
         
         self.Refresh()
 
+    def GetNewShapePos(self):
+        """!Determine optimal position for newly added object
+
+        @return x,y
+        """
+        xNew, yNew = map(lambda x: x / 2, self.GetSize())
+        diagram = self.GetDiagram()
+        
+        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
+    
 class ModelEvtHandler(ogl.ShapeEvtHandler):
     """!Model event handler class"""
     def __init__(self, log, frame):



More information about the grass-commit mailing list