36 """ |
36 """ |
37 |
37 |
38 class FBD_Block(Graphic_Element): |
38 class FBD_Block(Graphic_Element): |
39 |
39 |
40 # Create a new block |
40 # Create a new block |
41 def __init__(self, parent, type, name, id = None, extension = 0, inputs = None, connectors = {}, executionOrder = 0): |
41 def __init__(self, parent, type, name, id = None, extension = 0, inputs = None, connectors = {}, executionControl = False, executionOrder = 0): |
42 Graphic_Element.__init__(self, parent) |
42 Graphic_Element.__init__(self, parent) |
43 self.Type = None |
43 self.Type = None |
44 self.Extension = None |
44 self.Extension = None |
|
45 self.ExecutionControl = False |
45 self.Id = id |
46 self.Id = id |
46 self.SetName(name) |
47 self.SetName(name) |
47 self.SetExecutionOrder(executionOrder) |
48 self.SetExecutionOrder(executionOrder) |
48 self.Inputs = [] |
49 self.Inputs = [] |
49 self.Outputs = [] |
50 self.Outputs = [] |
50 self.Colour = wx.BLACK |
51 self.Colour = wx.BLACK |
51 self.Pen = wx.BLACK_PEN |
52 self.Pen = wx.BLACK_PEN |
52 self.SetType(type, extension, inputs, connectors) |
53 self.SetType(type, extension, inputs, connectors, executionControl) |
53 self.Errors = {} |
54 self.Errors = {} |
54 |
55 |
55 # Make a clone of this FBD_Block |
56 # Make a clone of this FBD_Block |
56 def Clone(self, parent, id = None, name = "", pos = None): |
57 def Clone(self, parent, id = None, name = "", pos = None): |
57 if self.Name != "" and name == "": |
58 if self.Name != "" and name == "": |
172 if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
173 if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
173 return output |
174 return output |
174 return None |
175 return None |
175 |
176 |
176 def GetInputTypes(self): |
177 def GetInputTypes(self): |
177 return tuple([input.GetType(True) for input in self.Inputs]) |
178 return tuple([input.GetType(True) for input in self.Inputs if input.GetName() != "EN"]) |
178 |
179 |
179 def SetOutputValues(self, values): |
180 def SetOutputValues(self, values): |
180 for output in self.Outputs: |
181 for output in self.Outputs: |
181 output.SetValue(values.get(ouput.getName(), None)) |
182 output.SetValue(values.get(ouput.getName(), None)) |
182 |
183 |
211 if output.TestPoint(pt, direction, exclude): |
212 if output.TestPoint(pt, direction, exclude): |
212 return output |
213 return output |
213 return None |
214 return None |
214 |
215 |
215 # Changes the block type |
216 # Changes the block type |
216 def SetType(self, type, extension, inputs = None, connectors = {}): |
217 def SetType(self, type, extension, inputs = None, connectors = {}, executionControl = False): |
217 if type != self.Type or self.Extension != extension: |
218 if type != self.Type or self.Extension != extension or executionControl != self.ExecutionControl: |
218 if type != self.Type: |
219 if type != self.Type: |
219 self.Type = type |
220 self.Type = type |
220 self.TypeSize = self.Parent.GetTextExtent(self.Type) |
221 self.TypeSize = self.Parent.GetTextExtent(self.Type) |
221 self.Extension = extension |
222 self.Extension = extension |
|
223 self.ExecutionControl = executionControl |
222 # Find the block definition from type given and create the corresponding |
224 # Find the block definition from type given and create the corresponding |
223 # inputs and outputs |
225 # inputs and outputs |
224 blocktype = self.Parent.GetBlockType(type, inputs) |
226 blocktype = self.Parent.GetBlockType(type, inputs) |
225 if blocktype: |
227 if blocktype: |
226 self.Colour = wx.BLACK |
228 self.Colour = wx.BLACK |
239 inputs = [] |
241 inputs = [] |
240 if "outputs" in connectors: |
242 if "outputs" in connectors: |
241 outputs = connectors["outputs"] |
243 outputs = connectors["outputs"] |
242 else: |
244 else: |
243 outputs = [] |
245 outputs = [] |
|
246 if self.ExecutionControl: |
|
247 inputs.insert(0, ("EN","BOOL","none")) |
|
248 outputs.insert(0, ("ENO","BOOL","none")) |
244 self.Pen = wx.Pen(self.Colour) |
249 self.Pen = wx.Pen(self.Colour) |
245 self.Clean() |
250 self.Clean() |
246 # Extract the inputs properties and create the corresponding connector |
251 # Extract the inputs properties and create the corresponding connector |
247 self.Inputs = [] |
252 self.Inputs = [] |
248 for input_name, input_type, input_modifier in inputs: |
253 for input_name, input_type, input_modifier in inputs: |
292 self.RefreshExecutionOrderSize() |
297 self.RefreshExecutionOrderSize() |
293 |
298 |
294 # Returs the execution order |
299 # Returs the execution order |
295 def GetExecutionOrder(self): |
300 def GetExecutionOrder(self): |
296 return self.ExecutionOrder |
301 return self.ExecutionOrder |
|
302 |
|
303 # Returs the execution order |
|
304 def GetExecutionControl(self): |
|
305 return self.ExecutionControl |
297 |
306 |
298 # Refresh the block minimum size |
307 # Refresh the block minimum size |
299 def RefreshMinSize(self): |
308 def RefreshMinSize(self): |
300 # Calculate the inputs maximum width |
309 # Calculate the inputs maximum width |
301 max_input = 0 |
310 max_input = 0 |