33 |
33 |
34 """ |
34 """ |
35 Class that implements the graphic representation of a function block |
35 Class that implements the graphic representation of a function block |
36 """ |
36 """ |
37 |
37 |
|
38 def TestConnectorName(name, block_type): |
|
39 return name in ["OUT", "MN", "MX"] or name.startswith("IN") and (block_type, name) != ("EXPT", "IN2") |
|
40 |
38 class FBD_Block(Graphic_Element): |
41 class FBD_Block(Graphic_Element): |
39 |
42 |
40 # Create a new block |
43 # Create a new block |
41 def __init__(self, parent, type, name, id = None, extension = 0, inputs = None, connectors = {}, executionControl = False, executionOrder = 0): |
44 def __init__(self, parent, type, name, id = None, extension = 0, inputs = None, connectors = {}, executionControl = False, executionOrder = 0): |
42 Graphic_Element.__init__(self, parent) |
45 Graphic_Element.__init__(self, parent) |
176 def SetOutputValues(self, values): |
179 def SetOutputValues(self, values): |
177 for output in self.Outputs: |
180 for output in self.Outputs: |
178 output.SetValue(values.get(ouput.getName(), None)) |
181 output.SetValue(values.get(ouput.getName(), None)) |
179 |
182 |
180 def GetConnectionResultType(self, connector, connectortype): |
183 def GetConnectionResultType(self, connector, connectortype): |
|
184 if not TestConnectorName(connector.GetName(), self.Type): |
|
185 return connectortype |
181 resulttype = connectortype |
186 resulttype = connectortype |
182 undefined = True |
|
183 for input in self.Inputs: |
187 for input in self.Inputs: |
184 name = input.GetName() |
188 if input != connector and TestConnectorName(input.GetName(), self.Type): |
185 undefined = undefined and input.GetType(True) == "ANY" |
|
186 if input != connector and (name.startswith("IN") or name in ["MN", "MX"]): |
|
187 inputtype = input.GetConnectedType() |
189 inputtype = input.GetConnectedType() |
188 if resulttype is None or inputtype is not None and self.IsOfType(inputtype, resulttype): |
190 if resulttype is None or inputtype is not None and self.IsOfType(inputtype, resulttype): |
189 resulttype = inputtype |
191 resulttype = inputtype |
190 for output in self.Outputs: |
192 for output in self.Outputs: |
191 name = output.GetName() |
193 if output != connector and TestConnectorName(output.GetName(), self.Type): |
192 undefined = undefined and output.GetType(True) == "ANY" |
|
193 if output != connector and name == "OUT" and not self.IsEndType(output.GetType()): |
|
194 outputtype = output.GetConnectedType() |
194 outputtype = output.GetConnectedType() |
195 if resulttype is None or outputtype is not None and self.IsOfType(outputtype, resulttype): |
195 if resulttype is None or outputtype is not None and self.IsOfType(outputtype, resulttype): |
196 resulttype = outputtype |
196 resulttype = outputtype |
197 if not undefined: |
197 return resulttype |
198 return resulttype |
198 |
199 return "ANY" |
|
200 |
|
201 # Returns all the block connectors |
199 # Returns all the block connectors |
202 def GetConnectors(self): |
200 def GetConnectors(self): |
203 return {"inputs" : self.Inputs, "outputs" : self.Outputs} |
201 return {"inputs" : self.Inputs, "outputs" : self.Outputs} |
204 |
202 |
205 # Test if point given is on one of the block connectors |
203 # Test if point given is on one of the block connectors |