Bug that makes element resizing acting strongly fixed
authorlbessard
Fri, 19 Oct 2007 17:08:08 +0200
changeset 110 29b6b70e1721
parent 109 734e02ab4018
child 111 0ec40799ba11
Bug that makes element resizing acting strongly fixed
graphics/GraphicCommons.py
graphics/LD_Objects.py
graphics/SFC_Objects.py
--- a/graphics/GraphicCommons.py	Fri Oct 19 10:15:23 2007 +0200
+++ b/graphics/GraphicCommons.py	Fri Oct 19 17:08:08 2007 +0200
@@ -451,8 +451,11 @@
                 self.Dragging = True
             # If a dragging have been initiated, refreshes the element state
             if self.Dragging:
-                self.oldPos = pos
-                self.ProcessDragging(movex, movey)
+                dragx, dragy = self.ProcessDragging(movex, movey)
+                if dragx:
+                    self.oldPos.x = pos.x
+                if dragy:
+                    self.oldPos.y = pos.y
             return True
         # If cursor just pass over the element, changes the cursor if it is on a handle
         else:
@@ -483,8 +486,8 @@
         handle_type, handle = self.Handle
         # If it is a resize handle, calculate the values from resizing
         if handle_type == HANDLE_RESIZE:
-            x, y = 0, 0
-            width, height = self.GetSize()
+            x = y = start_x = start_y = 0
+            width, height = start_width, start_height = self.GetSize()
             if handle[0] == 1:
                 x = movex
                 width -= movex
@@ -497,11 +500,23 @@
                 height += movey
             # Verify that new size is not lesser than minimum
             min_width, min_height = self.GetMinSize()
-            if width >= min_width and height >= min_height or width >= self.Size[0] and height >= self.Size[1]:
-                self.Resize(x, y, width, height)
+            dragx = dragy = False
+            if handle[0] != 2 and (width >= min_width or width > self.Size[0]):
+                start_x = x
+                start_width = width
+                dragx = True
+            if handle[1] != 2 and (height >= min_height or height > self.Size[1]):
+                start_y = y
+                start_height = height
+                dragy = True
+            if dragx or dragy:
+                self.Resize(start_x, start_y, start_width, start_height)
+            return dragx, dragy
         # If it is a move handle, Move this element
         elif handle_type == HANDLE_MOVE:
             self.Move(movex, movey)
+            return True, True
+        return False, False
     
     # Override this method for defining the method to call for refreshing the model of this element
     def RefreshModel(self, move=True):
@@ -1691,12 +1706,14 @@
                 if self.EndConnected:
                     self.UnConnectEndPoint()
                 self.MoveEndPoint(new_pos)
+            return True, True
         # A segment has been handled, move a segment
         elif handle_type == HANDLE_SEGMENT:
             self.MoveSegment(handle[0], movex, movey)
+            return True, True
         # Execute the default method for a graphic element
         else:
-            Graphic_Element.ProcessDragging(self, movex, movey)
+            return Graphic_Element.ProcessDragging(self, movex, movey)
     
     # Refreshes the wire model
     def RefreshModel(self, move=True):
--- a/graphics/LD_Objects.py	Fri Oct 19 10:15:23 2007 +0200
+++ b/graphics/LD_Objects.py	Fri Oct 19 17:08:08 2007 +0200
@@ -131,6 +131,7 @@
             for connect in self.Connectors:
                 connect_pos = connect.GetRelPosition()
                 connect.SetPosition(wx.Point(connect_pos.x, connect_pos.y - miny))
+        self.Connectors.sort(lambda x, y: x.Pos.y.__cmp__(y.Pos.y))
         maxy = 0
         for connect in self.Connectors:
             connect_pos = connect.GetRelPosition()
@@ -283,14 +284,15 @@
             # Popup the divergence menu without delete branch
         #    self.Parent.PopupDivergenceMenu(False)
     
-    # Refreshes the divergence state according to move defined and handle selected
+    # Refreshes the powerrail state according to move defined and handle selected
     def ProcessDragging(self, movex, movey):
         handle_type, handle = self.Handle
         # A connector has been handled
         if handle_type == HANDLE_CONNECTOR:
             self.MoveConnector(handle, movey)
-        else:
-            Graphic_Element.ProcessDragging(self, movex, movey)
+            return False, True
+        else:
+            return Graphic_Element.ProcessDragging(self, movex, movey)
     
     # Refreshes the power rail model
     def RefreshModel(self, move=True):
--- a/graphics/SFC_Objects.py	Fri Oct 19 10:15:23 2007 +0200
+++ b/graphics/SFC_Objects.py	Fri Oct 19 17:08:08 2007 +0200
@@ -371,8 +371,9 @@
                 self.Move(movex, 0)
                 self.RefreshInputPosition()
                 self.RefreshOutputPosition()
-        else:
-            Graphic_Element.ProcessDragging(self, movex, movey)
+            return True, False
+        else:
+            return Graphic_Element.ProcessDragging(self, movex, movey)
     
     # Refresh input element model
     def RefreshInputModel(self):
@@ -699,8 +700,9 @@
             self.Move(movex, 0)
             self.RefreshInputPosition()
             self.RefreshOutputPosition()
-        else:
-            Graphic_Element.ProcessDragging(self, movex, movey)
+            return True, False
+        else:
+            return Graphic_Element.ProcessDragging(self, movex, movey)
     
     # Refresh input element model
     def RefreshInputModel(self):
@@ -839,11 +841,11 @@
     # Remove a branch from the divergence
     def RemoveBranch(self, connector):
         if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
-            if connector in self.Outputs:
+            if connector in self.Outputs and len(self.Outputs) > 2:
                 self.Outputs.remove(connector)
                 self.MoveConnector(self.Outputs[0], 0)
         elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
-            if connector in self.Inputs:
+            if connector in self.Inputs and len(self.Inputs) > 2:
                 self.Inputs.remove(connector)
                 self.MoveConnector(self.Inputs[0], 0)
     
@@ -903,6 +905,8 @@
             for output in self.Outputs:
                 output_pos = output.GetRelPosition()
                 output.SetPosition(wx.Point(output_pos.x - minx, output_pos.y))
+        self.Inputs.sort(lambda x, y: x.Pos.x.__cmp__(y.Pos.x))
+        self.Outputs.sort(lambda x, y: x.Pos.x.__cmp__(y.Pos.x))
         self.Pos.x += minx
         self.Size[0] = maxx - minx
         connector.MoveConnected()
@@ -967,11 +971,17 @@
         self.RefreshBoundingBox()
     
     # Returns the divergence minimum size
-    def GetMinSize(self):
+    def GetMinSize(self, default=False):
+        width = 0
+        if default:
+            if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
+                width = (len(self.Outputs) - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL
+            elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
+                width = (len(self.Inputs) - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL
         if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
-            return 0, 1
+            return width, 1
         elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
-            return 0, 3
+            return width, 3
         return 0, 0
     
     # Refresh the position of the block connected to connector
@@ -1093,8 +1103,10 @@
             self.MoveConnector(handle, movex)
             if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
                 self.RefreshConnectedPosition(handle)
+            return True, False
         elif self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
-            Graphic_Element.ProcessDragging(self, movex, movey)
+            return Graphic_Element.ProcessDragging(self, movex, movey)
+        return False, False
     
     # Refresh output element model
     def RefreshOutputModel(self, move=False):
@@ -1265,8 +1277,9 @@
         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
             self.Move(movex, 0)
             self.RefreshInputPosition()
-        else:
-            Graphic_Element.ProcessDragging(self, movex, movey)
+            return True, False
+        else:
+            return Graphic_Element.ProcessDragging(self, movex, movey)
     
     # Refresh input element model
     def RefreshInputModel(self):
@@ -1441,10 +1454,12 @@
                     input_pos = wires[0][0].EndConnected.GetPosition(False)
                     if self.Pos.x - input_pos.x + movex >= SFC_WIRE_MIN_SIZE:
                         self.Move(movex, 0)
+                        return True, False
+                return False, False
             else:
-                Graphic_Element.ProcessDragging(self, movex, movey)
-        else:
-            Graphic_Element.ProcessDragging(self, movex, movey)
+                return Graphic_Element.ProcessDragging(self, movex, movey)
+        else:
+            return Graphic_Element.ProcessDragging(self, movex, movey)
 
     
    # Refreshes the action block model