graphics/FBD_Objects.py
changeset 90 2245e8776086
parent 64 dd6f693e46a1
child 99 2b18a72dcaf0
--- a/graphics/FBD_Objects.py	Mon Sep 10 16:12:29 2007 +0200
+++ b/graphics/FBD_Objects.py	Mon Sep 10 18:16:07 2007 +0200
@@ -39,7 +39,7 @@
 class FBD_Block(Graphic_Element):
     
     # Create a new block
-    def __init__(self, parent, type, name, id = None, extension = 0, inputs = None):
+    def __init__(self, parent, type, name, id = None, extension = 0, inputs = None, connectors = {}):
         Graphic_Element.__init__(self, parent)
         self.Type = None
         self.Extension = None
@@ -48,7 +48,9 @@
         self.Inputs = []
         self.Outputs = []
         self.RefreshNameSize()
-        self.SetType(type, extension, inputs)
+        self.Colour = wx.BLACK
+        self.Pen = wx.BLACK_PEN
+        self.SetType(type, extension, inputs, connectors)
     
     # Destructor
     def __del__(self):
@@ -153,7 +155,7 @@
         return None
     
     # Changes the block type
-    def SetType(self, type, extension, inputs = None):
+    def SetType(self, type, extension, inputs = None, connectors = {}):
         if type != self.Type or self.Extension != extension: 
             if type != self.Type:
                 self.Type = type
@@ -164,6 +166,7 @@
             # inputs and outputs
             blocktype = GetBlockType(type, inputs)
             if blocktype:
+                self.Colour = wx.BLACK
                 inputs = [input for input in blocktype["inputs"]]
                 outputs = [output for output in blocktype["outputs"]]
                 if blocktype["extensible"]:
@@ -172,7 +175,16 @@
                         start += 1
                         inputs.append(("IN%d"%start, inputs[-1][1], inputs[-1][2]))
             else:
-                raise ValueError, "This block type isn't defined"
+                self.Colour = wx.RED
+                if "inputs" in connectors:
+                    inputs = connectors["inputs"]
+                else:
+                    inputs = []
+                if "outputs" in connectors:
+                    outputs = connectors["outputs"]
+                else:
+                    outputs = []
+            self.Pen = wx.Pen(self.Colour)
             self.Clean()
             # Extract the inputs properties and create the corresponding connector
             self.Inputs = []
@@ -277,8 +289,9 @@
     
     # Draws block
     def Draw(self, dc):
-        dc.SetPen(wx.BLACK_PEN)
+        dc.SetPen(self.Pen)
         dc.SetBrush(wx.WHITE_BRUSH)
+        dc.SetTextForeground(self.Colour)
         # Draw a rectangle with the block size
         dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
         # Draw block name and block type
@@ -292,6 +305,7 @@
         for output in self.Outputs:
             output.Draw(dc)
         Graphic_Element.Draw(self, dc)
+        dc.SetTextForeground(wx.BLACK)
 
 
 #-------------------------------------------------------------------------------