--- a/graphics/FBD_Objects.py Mon Jul 09 11:10:14 2007 +0200
+++ b/graphics/FBD_Objects.py Tue Jul 10 09:52:53 2007 +0200
@@ -40,7 +40,7 @@
class FBD_Block(Graphic_Element):
# Create a new block
- def __init__(self, parent, type, name, id = None, extension = 0):
+ def __init__(self, parent, type, name, id = None, extension = 0, inputs = None):
Graphic_Element.__init__(self, parent)
self.Type = None
self.Extension = None
@@ -48,7 +48,7 @@
self.Id = id
self.Inputs = []
self.Outputs = []
- self.SetType(type, extension)
+ self.SetType(type, extension, inputs)
# Destructor
def __del__(self):
@@ -129,6 +129,9 @@
return output
return None
+ def GetInputTypes(self):
+ return tuple([input.GetType() for input in self.Inputs])
+
# Returns all the block connectors
def GetConnectors(self):
return {"inputs" : self.Inputs, "outputs" : self.Outputs}
@@ -146,13 +149,13 @@
return None
# Changes the block type
- def SetType(self, type, extension):
+ def SetType(self, type, extension, inputs = None):
if type != self.Type or self.Extension != extension:
self.Type = type
self.Extension = extension
# Find the block definition from type given and create the corresponding
# inputs and outputs
- blocktype = GetBlockType(type)
+ blocktype = GetBlockType(type, inputs)
if blocktype:
inputs = [input for input in blocktype["inputs"]]
outputs = [output for output in blocktype["outputs"]]
@@ -338,7 +341,7 @@
self.Input.SetPosition(wxPoint(0, self.Size[1] / 2))
if self.Output:
self.Output.SetPosition(wxPoint(self.Size[0], self.Size[1] / 2))
- self.RefreshConnected(self)
+ self.RefreshConnected()
# Refresh the position of wires connected to connector
def RefreshConnected(self, exclude = []):
@@ -495,7 +498,7 @@
# Unconnect connector
def Clean(self):
if self.Connector:
- self.Connector.UnConnect()
+ self.Connector.UnConnect(delete = True)
# Delete this connection by calling the appropriate method
def Delete(self):
@@ -517,7 +520,7 @@
self.Connector.SetPosition(wxPoint(0, self.Size[1] / 2))
else:
self.Connector.SetPosition(wxPoint(self.Size[0], self.Size[1] / 2))
- self.RefreshConnected(self)
+ self.RefreshConnected()
# Refresh the position of wires connected to connector
def RefreshConnected(self, exclude = []):
@@ -534,6 +537,18 @@
def GetConnector(self, position = None, name = None):
return self.Connector
+ # Changes the variable type
+ def SetType(self, type):
+ if type != self.Type:
+ self.Type = type
+ self.Clean()
+ # Create an input or output connector according to connection type
+ if self.Type == CONNECTOR:
+ self.Connector = Connector(self, "", "ANY", wxPoint(0, 0), WEST, onlyone = True)
+ else:
+ self.Connector = Connector(self, "", "ANY", wxPoint(0, 0), EAST)
+ self.RefreshConnectors()
+
# Returns the connection type
def GetType(self):
return self.Type
@@ -554,6 +569,11 @@
text_height += 1
return text_width + text_height + 20, text_height + 10
+ # Method called when a LeftDClick event have been generated
+ def OnLeftDClick(self, event, dc, scaling):
+ # Edit the connection properties
+ self.Parent.EditConnectionContent(self)
+
# Method called when a RightUp event have been generated
def OnRightUp(self, event, dc, scaling):
# Popup the default menu