equal
deleted
inserted
replaced
38 """ |
38 """ |
39 |
39 |
40 class FBD_Block(Graphic_Element): |
40 class FBD_Block(Graphic_Element): |
41 |
41 |
42 # Create a new block |
42 # Create a new block |
43 def __init__(self, parent, type, name, id = None, extension = 0): |
43 def __init__(self, parent, type, name, id = None, extension = 0, inputs = None): |
44 Graphic_Element.__init__(self, parent) |
44 Graphic_Element.__init__(self, parent) |
45 self.Type = None |
45 self.Type = None |
46 self.Extension = None |
46 self.Extension = None |
47 self.Name = name |
47 self.Name = name |
48 self.Id = id |
48 self.Id = id |
49 self.Inputs = [] |
49 self.Inputs = [] |
50 self.Outputs = [] |
50 self.Outputs = [] |
51 self.SetType(type, extension) |
51 self.SetType(type, extension, inputs) |
52 |
52 |
53 # Destructor |
53 # Destructor |
54 def __del__(self): |
54 def __del__(self): |
55 self.Inputs = [] |
55 self.Inputs = [] |
56 self.Outputs = [] |
56 self.Outputs = [] |
127 output_pos = output.GetRelPosition() |
127 output_pos = output.GetRelPosition() |
128 if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
128 if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
129 return output |
129 return output |
130 return None |
130 return None |
131 |
131 |
|
132 def GetInputTypes(self): |
|
133 return tuple([input.GetType() for input in self.Inputs]) |
|
134 |
132 # Returns all the block connectors |
135 # Returns all the block connectors |
133 def GetConnectors(self): |
136 def GetConnectors(self): |
134 return {"inputs" : self.Inputs, "outputs" : self.Outputs} |
137 return {"inputs" : self.Inputs, "outputs" : self.Outputs} |
135 |
138 |
136 # Test if point given is on one of the block connectors |
139 # Test if point given is on one of the block connectors |
144 if output.TestPoint(pt, exclude): |
147 if output.TestPoint(pt, exclude): |
145 return output |
148 return output |
146 return None |
149 return None |
147 |
150 |
148 # Changes the block type |
151 # Changes the block type |
149 def SetType(self, type, extension): |
152 def SetType(self, type, extension, inputs = None): |
150 if type != self.Type or self.Extension != extension: |
153 if type != self.Type or self.Extension != extension: |
151 self.Type = type |
154 self.Type = type |
152 self.Extension = extension |
155 self.Extension = extension |
153 # Find the block definition from type given and create the corresponding |
156 # Find the block definition from type given and create the corresponding |
154 # inputs and outputs |
157 # inputs and outputs |
155 blocktype = GetBlockType(type) |
158 blocktype = GetBlockType(type, inputs) |
156 if blocktype: |
159 if blocktype: |
157 inputs = [input for input in blocktype["inputs"]] |
160 inputs = [input for input in blocktype["inputs"]] |
158 outputs = [output for output in blocktype["outputs"]] |
161 outputs = [output for output in blocktype["outputs"]] |
159 if blocktype["extensible"]: |
162 if blocktype["extensible"]: |
160 start = int(inputs[-1][0].replace("IN", "")) |
163 start = int(inputs[-1][0].replace("IN", "")) |
336 def RefreshConnectors(self): |
339 def RefreshConnectors(self): |
337 if self.Input: |
340 if self.Input: |
338 self.Input.SetPosition(wxPoint(0, self.Size[1] / 2)) |
341 self.Input.SetPosition(wxPoint(0, self.Size[1] / 2)) |
339 if self.Output: |
342 if self.Output: |
340 self.Output.SetPosition(wxPoint(self.Size[0], self.Size[1] / 2)) |
343 self.Output.SetPosition(wxPoint(self.Size[0], self.Size[1] / 2)) |
341 self.RefreshConnected(self) |
344 self.RefreshConnected() |
342 |
345 |
343 # Refresh the position of wires connected to connector |
346 # Refresh the position of wires connected to connector |
344 def RefreshConnected(self, exclude = []): |
347 def RefreshConnected(self, exclude = []): |
345 if self.Input: |
348 if self.Input: |
346 self.Input.MoveConnected(exclude) |
349 self.Input.MoveConnected(exclude) |
493 self.Connector = None |
496 self.Connector = None |
494 |
497 |
495 # Unconnect connector |
498 # Unconnect connector |
496 def Clean(self): |
499 def Clean(self): |
497 if self.Connector: |
500 if self.Connector: |
498 self.Connector.UnConnect() |
501 self.Connector.UnConnect(delete = True) |
499 |
502 |
500 # Delete this connection by calling the appropriate method |
503 # Delete this connection by calling the appropriate method |
501 def Delete(self): |
504 def Delete(self): |
502 self.Parent.DeleteConnection(self) |
505 self.Parent.DeleteConnection(self) |
503 |
506 |
515 def RefreshConnectors(self): |
518 def RefreshConnectors(self): |
516 if self.Type == CONNECTOR: |
519 if self.Type == CONNECTOR: |
517 self.Connector.SetPosition(wxPoint(0, self.Size[1] / 2)) |
520 self.Connector.SetPosition(wxPoint(0, self.Size[1] / 2)) |
518 else: |
521 else: |
519 self.Connector.SetPosition(wxPoint(self.Size[0], self.Size[1] / 2)) |
522 self.Connector.SetPosition(wxPoint(self.Size[0], self.Size[1] / 2)) |
520 self.RefreshConnected(self) |
523 self.RefreshConnected() |
521 |
524 |
522 # Refresh the position of wires connected to connector |
525 # Refresh the position of wires connected to connector |
523 def RefreshConnected(self, exclude = []): |
526 def RefreshConnected(self, exclude = []): |
524 if self.Connector: |
527 if self.Connector: |
525 self.Connector.MoveConnected(exclude) |
528 self.Connector.MoveConnected(exclude) |
531 return None |
534 return None |
532 |
535 |
533 # Returns the connection connector |
536 # Returns the connection connector |
534 def GetConnector(self, position = None, name = None): |
537 def GetConnector(self, position = None, name = None): |
535 return self.Connector |
538 return self.Connector |
|
539 |
|
540 # Changes the variable type |
|
541 def SetType(self, type): |
|
542 if type != self.Type: |
|
543 self.Type = type |
|
544 self.Clean() |
|
545 # Create an input or output connector according to connection type |
|
546 if self.Type == CONNECTOR: |
|
547 self.Connector = Connector(self, "", "ANY", wxPoint(0, 0), WEST, onlyone = True) |
|
548 else: |
|
549 self.Connector = Connector(self, "", "ANY", wxPoint(0, 0), EAST) |
|
550 self.RefreshConnectors() |
536 |
551 |
537 # Returns the connection type |
552 # Returns the connection type |
538 def GetType(self): |
553 def GetType(self): |
539 return self.Type |
554 return self.Type |
540 |
555 |
551 dc = wxClientDC(self.Parent) |
566 dc = wxClientDC(self.Parent) |
552 text_width, text_height = dc.GetTextExtent(self.Name) |
567 text_width, text_height = dc.GetTextExtent(self.Name) |
553 if text_height % 2 == 1: |
568 if text_height % 2 == 1: |
554 text_height += 1 |
569 text_height += 1 |
555 return text_width + text_height + 20, text_height + 10 |
570 return text_width + text_height + 20, text_height + 10 |
|
571 |
|
572 # Method called when a LeftDClick event have been generated |
|
573 def OnLeftDClick(self, event, dc, scaling): |
|
574 # Edit the connection properties |
|
575 self.Parent.EditConnectionContent(self) |
556 |
576 |
557 # Method called when a RightUp event have been generated |
577 # Method called when a RightUp event have been generated |
558 def OnRightUp(self, event, dc, scaling): |
578 def OnRightUp(self, event, dc, scaling): |
559 # Popup the default menu |
579 # Popup the default menu |
560 self.Parent.PopupDefaultMenu() |
580 self.Parent.PopupDefaultMenu() |