graphics/LD_Objects.py
changeset 80 c798a68c5560
parent 71 0578bc212c20
child 96 d178cfa9e77f
--- a/graphics/LD_Objects.py	Thu Aug 23 09:50:35 2007 +0200
+++ b/graphics/LD_Objects.py	Mon Aug 27 17:37:50 2007 +0200
@@ -103,7 +103,7 @@
     def InsertConnector(self, idx, connector = True):
         if connector:
             if self.Type == LEFTRAIL:
-                connector = Connector(self, "", "BOOL", wx.Point(2, 0), EAST)
+                connector = Connector(self, "", "BOOL", wx.Point(self.Size[0], 0), EAST)
             elif self.Type == RIGHTRAIL:
                 connector = Connector(self, "", "BOOL", wx.Point(0, 0), WEST)
             self.Connectors.insert(idx, connector)
@@ -120,15 +120,19 @@
         maxy = 0
         for connect in self.Connectors:
             connect_pos = connect.GetRelPosition()
-            miny = min(miny, connect_pos.y)
-            maxy = max(maxy, connect_pos.y)
-        min_pos = self.Pos.y + miny - self.Extensions[0]
+            miny = min(miny, connect_pos.y - self.Extensions[0])
+            maxy = max(maxy, connect_pos.y - self.Extensions[0])
+        min_pos = self.Pos.y + miny
         self.Pos.y = min(min_pos, self.Pos.y)
         if min_pos == self.Pos.y:
             for connect in self.Connectors:
                 connect_pos = connect.GetRelPosition()
-                connect.SetPosition(wx.Point(connect_pos.x, connect_pos.y - miny + self.Extensions[0]))
-        self.Size[1] = max(maxy - miny + self.Extensions[0] + self.Extensions[1], self.Size[1])
+                connect.SetPosition(wx.Point(connect_pos.x, connect_pos.y - miny))
+        maxy = 0
+        for connect in self.Connectors:
+            connect_pos = connect.GetRelPosition()
+            maxy = max(maxy, connect_pos.y)
+        self.Size[1] = max(maxy + self.Extensions[1], self.Size[1])
         connector.MoveConnected()
         self.RefreshBoundingBox()
     
@@ -154,13 +158,19 @@
     def RefreshConnectors(self):
         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
             height = self.Size[1] - self.Extensions[0] - self.Extensions[1]
+            interval = float(height) / float(max(len(self.Connectors) - 1, 1))
             for i, connector in enumerate(self.Connectors):
                 position = connector.GetRelPosition()
-                if self.RealConnectors:
-                    if self.Type == LEFTRAIL:
+                if self.Type == LEFTRAIL:
+                    if self.RealConnectors:
                         connector.SetPosition(wx.Point(self.Size[0], self.Extensions[0] + int(round(self.RealConnectors[i] * height))))
-                    elif self.Type == RIGHTRAIL:
+                    else:
+                        connector.SetPosition(wx.Point(self.Size[0], self.Extensions[0] + int(round(i * height))))
+                elif self.Type == RIGHTRAIL:
+                    if self.RealConnectors:
                         connector.SetPosition(wx.Point(0, self.Extensions[0] + int(round(self.RealConnectors[i] * height))))
+                    else:
+                        connector.SetPosition(wx.Point(0, self.Extensions[0] + int(round(i * height))))
         else:
             position = self.Extensions[0]
             for connector in self.Connectors:
@@ -237,7 +247,6 @@
             for connector in self.Connectors:
                 position = connector.GetRelPosition()
                 self.RealConnectors.append(float(position.y - self.Extensions[0])/float(max(1, height)))
-            print self.RealConnectors
             Graphic_Element.OnLeftDown(self, event, dc, scaling)
     
     # Method called when a LeftUp event have been generated
@@ -246,13 +255,12 @@
         handle_type, handle = self.Handle
         if handle_type == HANDLE_CONNECTOR:
             wires = handle.GetWires()
-            if len(wires) != 1:
-                return
-            if handle == wires[0][0].StartConnected:
-                block = wires[0][0].EndConnected.GetParentBlock()
-            else:
-                block = wires[0][0].StartConnected.GetParentBlock()
-            block.RefreshModel(False)
+            if len(wires) == 1:
+                if handle == wires[0][0].StartConnected:
+                    block = wires[0][0].EndConnected.GetParentBlock()
+                else:
+                    block = wires[0][0].StartConnected.GetParentBlock()
+                block.RefreshModel(False)
         Graphic_Element.OnLeftUp(self, event, dc, scaling)
     
     # Method called when a LeftDClick event have been generated