--- a/graphics/FBD_Objects.py Sat Jul 07 11:35:17 2007 +0200
+++ b/graphics/FBD_Objects.py Mon Jul 09 11:10:14 2007 +0200
@@ -40,15 +40,15 @@
class FBD_Block(Graphic_Element):
# Create a new block
- def __init__(self, parent, type, name, id = None, extension = 0, inputs = [], outputs = []):
+ def __init__(self, parent, type, name, id = None, extension = 0):
Graphic_Element.__init__(self, parent)
self.Type = None
+ self.Extension = None
self.Name = name
self.Id = id
- self.Extension = extension
self.Inputs = []
self.Outputs = []
- self.SetType(type)
+ self.SetType(type, extension)
# Destructor
def __del__(self):
@@ -107,7 +107,16 @@
output.MoveConnected(exclude)
# Returns the block connector that starts with the point given if it exists
- def GetConnector(self, position):
+ def GetConnector(self, position, name = None):
+ # if a name is given
+ if name:
+ # Test each input and output connector
+ for input in self.Inputs:
+ if name == input.GetName():
+ return input
+ for output in self.Outputs:
+ if name == output.GetName():
+ return output
# Test each input connector
for input in self.Inputs:
input_pos = input.GetRelPosition()
@@ -137,9 +146,10 @@
return None
# Changes the block type
- def SetType(self, type):
- if type != self.Type:
+ def SetType(self, type, extension):
+ 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)
@@ -150,14 +160,14 @@
start = int(inputs[-1][0].replace("IN", ""))
for i in xrange(self.Extension - len(blocktype["inputs"])):
start += 1
- inputs.append(("IN%d"%start, inputs[-1][1], input[-1][2]))
+ inputs.append(("IN%d"%start, inputs[-1][1], inputs[-1][2]))
else:
raise ValueError, "This block type isn't defined"
self.Clean()
# Extract the inputs properties and create the corresponding connector
self.Inputs = []
for input_name, input_type, input_modifier in inputs:
- connector = Connector(self, input_name, input_type, wxPoint(0, 0), WEST)
+ connector = Connector(self, input_name, input_type, wxPoint(0, 0), WEST, onlyone = True)
if input_modifier == "negated":
connector.SetNegated(True)
elif input_modifier != "none":
@@ -228,13 +238,13 @@
self.RefreshModel(False)
# Method called when a LeftDClick event have been generated
- def OnLeftDClick(self, event, scaling):
+ def OnLeftDClick(self, event, dc, scaling):
# Edit the block properties
self.Parent.EditBlockContent(self)
# Method called when a RightUp event have been generated
- def OnRightUp(self, event, scaling):
- pos = GetScaledEventPosition(event, scaling)
+ def OnRightUp(self, event, dc, scaling):
+ pos = GetScaledEventPosition(event, dc, scaling)
# Popup the menu with special items for a block and a connector if one is handled
connector = self.TestConnector(pos, False)
if connector:
@@ -346,7 +356,14 @@
return None
# Returns the block connector that starts with the point given if it exists
- def GetConnector(self, position):
+ def GetConnector(self, position, name = None):
+ # if a name is given
+ if name:
+ # Test input and output connector if they exists
+ if self.Input and name == self.Input.GetName():
+ return self.Input
+ if self.Output and name == self.Output.GetName():
+ return self.Output
# Test input connector if it exists
if self.Input:
input_pos = self.Input.GetRelPosition()
@@ -380,7 +397,7 @@
self.Output = None
# Create an input or output connector according to variable type
if self.Type != INPUT:
- self.Input = Connector(self, "", value_type, wxPoint(0, 0), WEST)
+ self.Input = Connector(self, "", value_type, wxPoint(0, 0), WEST, onlyone = True)
if self.Type != OUTPUT:
self.Output = Connector(self, "", value_type, wxPoint(0, 0), EAST)
self.RefreshConnectors()
@@ -404,15 +421,15 @@
return text_width + 10, text_height + 10
# Method called when a LeftDClick event have been generated
- def OnLeftDClick(self, event, scaling):
+ def OnLeftDClick(self, event, dc, scaling):
# Edit the variable properties
self.Parent.EditVariableContent(self)
# Method called when a RightUp event have been generated
- def OnRightUp(self, event, scaling):
- pos = GetScaledEventPosition(event, scaling)
+ def OnRightUp(self, event, dc, scaling):
+ pos = GetScaledEventPosition(event, dc, scaling)
# Popup the menu with special items for a variable and a connector if it's handled
- connector = self.TestConnectors(pos, False)
+ connector = self.TestConnector(pos, False)
if connector:
self.Handle = (HANDLE_CONNECTOR, connector)
self.Parent.PopupVariableMenu(connector)
@@ -466,7 +483,7 @@
self.Size = wxSize(0, 0)
# Create an input or output connector according to connection type
if self.Type == CONNECTOR:
- self.Connector = Connector(self, "", "ANY", wxPoint(0, 0), WEST)
+ self.Connector = Connector(self, "", "ANY", wxPoint(0, 0), WEST, onlyone = True)
else:
self.Connector = Connector(self, "", "ANY", wxPoint(0, 0), EAST)
self.RefreshConnectors()
@@ -514,7 +531,7 @@
return None
# Returns the connection connector
- def GetConnector(self, position = None):
+ def GetConnector(self, position = None, name = None):
return self.Connector
# Returns the connection type
@@ -538,7 +555,7 @@
return text_width + text_height + 20, text_height + 10
# Method called when a RightUp event have been generated
- def OnRightUp(self, event, scaling):
+ def OnRightUp(self, event, dc, scaling):
# Popup the default menu
self.Parent.PopupDefaultMenu()