Adding support for underlying type incompatible wire loaded instead of removing them
authorlbessard
Fri, 18 Jul 2008 14:34:06 +0200
changeset 222 8ce5c2635976
parent 221 25f2b4924347
child 223 ea857c3a0427
Adding support for underlying type incompatible wire loaded instead of removing them
Viewer.py
graphics/GraphicCommons.py
--- a/Viewer.py	Fri Jul 11 17:16:08 2008 +0200
+++ b/Viewer.py	Fri Jul 18 14:34:06 2008 +0200
@@ -528,13 +528,10 @@
                 self.loadInstance(instance, ids)
         self.RefreshScrollBars()
         
-        to_delete = []
         for wire in self.Wires:
             if not wire.IsConnectedCompatible():
-                to_delete.append(wire)
-        for wire in to_delete:
-            wire.Delete()
-    
+                wire.MarkAsInvalid()
+        
         self.Refresh(False)
     
     def GetMaxSize(self):
--- a/graphics/GraphicCommons.py	Fri Jul 11 17:16:08 2008 +0200
+++ b/graphics/GraphicCommons.py	Fri Jul 18 14:34:06 2008 +0200
@@ -1186,6 +1186,7 @@
             self.Points = []
             self.Segments = []
         self.SelectedSegment = None
+        self.Valid = True
         self.Value = None
         self.OverStart = False
         self.OverEnd = False
@@ -1286,11 +1287,11 @@
         # The segment selected is the first
         elif segment == 0:
             if self.StartConnected:
-                self.StartConnected.SetPen(wx.RED_PEN)
+                self.StartConnected.SetPen(wx.BLUE_PEN)
             if self.EndConnected:
                 # There is only one segment
                 if len(self.Segments) == 1:
-                    self.EndConnected.SetPen(wx.RED_PEN)
+                    self.EndConnected.SetPen(wx.BLUE_PEN)
                 else:
                     self.EndConnected.SetPen(wx.BLACK_PEN)
         # The segment selected is the last
@@ -1298,10 +1299,18 @@
             if self.StartConnected:
                 self.StartConnected.SetPen(wx.BLACK_PEN)
             if self.EndConnected:
-                self.EndConnected.SetPen(wx.RED_PEN)
+                self.EndConnected.SetPen(wx.BLUE_PEN)
         self.SelectedSegment = segment
         self.Refresh()
     
+    # Select a segment and not the whole wire. It's useful for Ladder Diagram
+    def MarkAsInvalid(self):
+        self.Valid = False
+        if self.StartConnected:
+            self.StartConnected.SetPen(wx.RED_PEN)
+        if self.EndConnected:
+            self.EndConnected.SetPen(wx.RED_PEN)
+    
     # Reinitialize the wire points
     def ResetPoints(self):
         if self.StartPoint and self.EndPoint:
@@ -2029,7 +2038,10 @@
     # Draws the wire lines and points
     def Draw(self, dc):
         Graphic_Element.Draw(self, dc)
-        dc.SetPen(wx.BLACK_PEN)
+        if self.Valid:
+            dc.SetPen(wx.BLACK_PEN)
+        else:
+            dc.SetPen(wx.RED_PEN)
         dc.SetBrush(wx.BLACK_BRUSH)
         # Draw the start and end points if they are not connected or the mouse is over them
         if len(self.Points) > 0 and (not self.StartConnected or self.OverStart):