--- a/graphics/LD_Objects.py Fri Sep 05 18:12:23 2008 +0200
+++ b/graphics/LD_Objects.py Fri Sep 05 18:13:18 2008 +0200
@@ -49,8 +49,10 @@
connectors = [True]
self.SetType(type, connectors)
- # Destructor
- def __del__(self):
+ def Flush(self):
+ for connector in self.Connectors:
+ if connector is not None:
+ connector.Flush()
self.Connectors = []
# Make a clone of this LD_PowerRail
@@ -376,13 +378,45 @@
# Create an input and output connector
self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2 + 1), WEST)
self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST)
+ self.Value = None
+ self.PreviousValue = False
+ self.PreviousSpreading = False
self.RefreshNameSize()
self.RefreshTypeSize()
- # Destructor
- def __del__(self):
- self.Input = None
- self.Output = None
+ def Flush(self):
+ if self.Input is not None:
+ self.Input.Flush()
+ self.Input = None
+ if self.Output is not None:
+ self.Output.Flush()
+ self.Output = None
+
+ def SetValue(self, value):
+ self.PreviousValue = self.Value
+ self.Value = value
+ if self.Value != self.PreviousValue:
+ self.Refresh()
+ self.SpreadCurrent()
+
+ def SpreadCurrent(self):
+ spreading = self.Input.ReceivingCurrent()
+ if self.Value is not None:
+ if self.Type == CONTACT_NORMAL:
+ spreading &= self.Value
+ elif self.Type == CONTACT_REVERSE:
+ spreading &= not self.Value
+ elif self.Type == CONTACT_RISING:
+ spreading &= self.Value and not self.PreviousValue
+ elif self.Type == CONTACT_FALLING:
+ spreading &= self.Value and not self.PreviousValue
+ else:
+ spreading = False
+ if spreading and not self.PreviousSpreading:
+ self.Output.SpreadCurrent(True)
+ elif not spreading and self.PreviousSpreading:
+ self.Output.SpreadCurrent(False)
+ self.PreviousSpreading = spreading
# Make a clone of this LD_Contact
def Clone(self, parent, id = None, pos = None):
@@ -565,7 +599,19 @@
# Draws contact
def Draw(self, dc):
Graphic_Element.Draw(self, dc)
- dc.SetPen(wx.BLACK_PEN)
+ if self.Value is not None:
+ if self.Type == CONTACT_NORMAL and self.Value:
+ dc.SetPen(wx.GREEN_PEN)
+ elif self.Type == CONTACT_REVERSE and not self.Value:
+ dc.SetPen(wx.GREEN_PEN)
+ elif self.Type == CONTACT_RISING and self.Value and not self.PreviousValue:
+ dc.SetPen(wx.GREEN_PEN)
+ elif self.Type == CONTACT_FALLING and self.Value and not self.PreviousValue:
+ dc.SetPen(wx.GREEN_PEN)
+ else:
+ dc.SetPen(wx.BLACK_PEN)
+ else:
+ dc.SetPen(wx.BLACK_PEN)
dc.SetBrush(wx.BLACK_BRUSH)
# Compiling contact type modifier symbol
@@ -628,13 +674,33 @@
# Create an input and output connector
self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2 + 1), WEST)
self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST)
+ self.Value = None
+ self.PreviousValue = False
self.RefreshNameSize()
self.RefreshTypeSize()
- # Destructor
- def __del__(self):
- self.Input = None
- self.Output = None
+ def Flush(self):
+ if self.Input is not None:
+ self.Input.Flush()
+ self.Input = None
+ if self.Output is not None:
+ self.Output.Flush()
+ self.Output = None
+
+ def SetValue(self, value):
+ if self.Value != value:
+ self.Value = value
+ self.Refresh()
+
+ def SpreadCurrent(self):
+ self.PreviousValue = self.Value
+ self.Value = self.Input.ReceivingCurrent()
+ if self.Value and not self.PreviousValue:
+ self.Output.SpreadCurrent(True)
+ elif not self.Value and self.PreviousValue:
+ self.Output.SpreadCurrent(False)
+ if self.Value != self.PreviousValue:
+ self.Refresh()
# Make a clone of this LD_Coil
def Clone(self, parent, id = None, pos = None):
@@ -817,7 +883,10 @@
# Draws coil
def Draw(self, dc):
Graphic_Element.Draw(self, dc)
- dc.SetPen(wx.Pen(wx.BLACK, 2, wx.SOLID))
+ if self.Value is not None and self.Value:
+ dc.SetPen(wx.Pen(wx.GREEN, 2, wx.SOLID))
+ else:
+ dc.SetPen(wx.Pen(wx.BLACK, 2, wx.SOLID))
dc.SetBrush(wx.TRANSPARENT_BRUSH)
# Compiling coil type modifier symbol
@@ -846,7 +915,10 @@
dc.DrawEllipticArc(self.Pos.x, self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1, self.Size[0], int(self.Size[1] * sqrt(2)) - 1, -45, 45)
# Draw a point to avoid hole in left arc
if not getattr(dc, "printing", False):
- dc.SetPen(wx.BLACK_PEN)
+ if self.Value is not None and self.Value:
+ dc.SetPen(wx.GREEN_PEN)
+ else:
+ dc.SetPen(wx.BLACK_PEN)
dc.DrawPoint(self.Pos.x + 1, self.Pos.y + self.Size[1] / 2 + 1)
name_size = self.NameSize
if typetext != "":