37 """ |
37 """ |
38 |
38 |
39 class FBD_Block(Graphic_Element): |
39 class FBD_Block(Graphic_Element): |
40 |
40 |
41 # Create a new block |
41 # Create a new block |
42 def __init__(self, parent, type, name, id = None, extension = 0, inputs = None): |
42 def __init__(self, parent, type, name, id = None, extension = 0, inputs = None, connectors = {}): |
43 Graphic_Element.__init__(self, parent) |
43 Graphic_Element.__init__(self, parent) |
44 self.Type = None |
44 self.Type = None |
45 self.Extension = None |
45 self.Extension = None |
46 self.Name = name |
46 self.Name = name |
47 self.Id = id |
47 self.Id = id |
48 self.Inputs = [] |
48 self.Inputs = [] |
49 self.Outputs = [] |
49 self.Outputs = [] |
50 self.RefreshNameSize() |
50 self.RefreshNameSize() |
51 self.SetType(type, extension, inputs) |
51 self.Colour = wx.BLACK |
|
52 self.Pen = wx.BLACK_PEN |
|
53 self.SetType(type, extension, inputs, connectors) |
52 |
54 |
53 # Destructor |
55 # Destructor |
54 def __del__(self): |
56 def __del__(self): |
55 self.Inputs = [] |
57 self.Inputs = [] |
56 self.Outputs = [] |
58 self.Outputs = [] |
151 if output.TestPoint(pt, exclude): |
153 if output.TestPoint(pt, exclude): |
152 return output |
154 return output |
153 return None |
155 return None |
154 |
156 |
155 # Changes the block type |
157 # Changes the block type |
156 def SetType(self, type, extension, inputs = None): |
158 def SetType(self, type, extension, inputs = None, connectors = {}): |
157 if type != self.Type or self.Extension != extension: |
159 if type != self.Type or self.Extension != extension: |
158 if type != self.Type: |
160 if type != self.Type: |
159 self.Type = type |
161 self.Type = type |
160 dc = wx.ClientDC(self.Parent) |
162 dc = wx.ClientDC(self.Parent) |
161 self.TypeSize = dc.GetTextExtent(self.Type) |
163 self.TypeSize = dc.GetTextExtent(self.Type) |
162 self.Extension = extension |
164 self.Extension = extension |
163 # Find the block definition from type given and create the corresponding |
165 # Find the block definition from type given and create the corresponding |
164 # inputs and outputs |
166 # inputs and outputs |
165 blocktype = GetBlockType(type, inputs) |
167 blocktype = GetBlockType(type, inputs) |
166 if blocktype: |
168 if blocktype: |
|
169 self.Colour = wx.BLACK |
167 inputs = [input for input in blocktype["inputs"]] |
170 inputs = [input for input in blocktype["inputs"]] |
168 outputs = [output for output in blocktype["outputs"]] |
171 outputs = [output for output in blocktype["outputs"]] |
169 if blocktype["extensible"]: |
172 if blocktype["extensible"]: |
170 start = int(inputs[-1][0].replace("IN", "")) |
173 start = int(inputs[-1][0].replace("IN", "")) |
171 for i in xrange(self.Extension - len(blocktype["inputs"])): |
174 for i in xrange(self.Extension - len(blocktype["inputs"])): |
172 start += 1 |
175 start += 1 |
173 inputs.append(("IN%d"%start, inputs[-1][1], inputs[-1][2])) |
176 inputs.append(("IN%d"%start, inputs[-1][1], inputs[-1][2])) |
174 else: |
177 else: |
175 raise ValueError, "This block type isn't defined" |
178 self.Colour = wx.RED |
|
179 if "inputs" in connectors: |
|
180 inputs = connectors["inputs"] |
|
181 else: |
|
182 inputs = [] |
|
183 if "outputs" in connectors: |
|
184 outputs = connectors["outputs"] |
|
185 else: |
|
186 outputs = [] |
|
187 self.Pen = wx.Pen(self.Colour) |
176 self.Clean() |
188 self.Clean() |
177 # Extract the inputs properties and create the corresponding connector |
189 # Extract the inputs properties and create the corresponding connector |
178 self.Inputs = [] |
190 self.Inputs = [] |
179 for input_name, input_type, input_modifier in inputs: |
191 for input_name, input_type, input_modifier in inputs: |
180 connector = Connector(self, input_name, input_type, wx.Point(0, 0), WEST, onlyone = True) |
192 connector = Connector(self, input_name, input_type, wx.Point(0, 0), WEST, onlyone = True) |
275 for output in self.Outputs: |
287 for output in self.Outputs: |
276 output.RefreshWires() |
288 output.RefreshWires() |
277 |
289 |
278 # Draws block |
290 # Draws block |
279 def Draw(self, dc): |
291 def Draw(self, dc): |
280 dc.SetPen(wx.BLACK_PEN) |
292 dc.SetPen(self.Pen) |
281 dc.SetBrush(wx.WHITE_BRUSH) |
293 dc.SetBrush(wx.WHITE_BRUSH) |
|
294 dc.SetTextForeground(self.Colour) |
282 # Draw a rectangle with the block size |
295 # Draw a rectangle with the block size |
283 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
296 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
284 # Draw block name and block type |
297 # Draw block name and block type |
285 dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2, |
298 dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2, |
286 self.Pos.y - (self.NameSize[1] + 2)) |
299 self.Pos.y - (self.NameSize[1] + 2)) |
290 for input in self.Inputs: |
303 for input in self.Inputs: |
291 input.Draw(dc) |
304 input.Draw(dc) |
292 for output in self.Outputs: |
305 for output in self.Outputs: |
293 output.Draw(dc) |
306 output.Draw(dc) |
294 Graphic_Element.Draw(self, dc) |
307 Graphic_Element.Draw(self, dc) |
|
308 dc.SetTextForeground(wx.BLACK) |
295 |
309 |
296 |
310 |
297 #------------------------------------------------------------------------------- |
311 #------------------------------------------------------------------------------- |
298 # Function Block Diagram Variable |
312 # Function Block Diagram Variable |
299 #------------------------------------------------------------------------------- |
313 #------------------------------------------------------------------------------- |