52 self.Pen = wx.BLACK_PEN |
52 self.Pen = wx.BLACK_PEN |
53 self.SetType(type, extension, inputs, connectors) |
53 self.SetType(type, extension, inputs, connectors) |
54 |
54 |
55 # Make a clone of this FBD_Block |
55 # Make a clone of this FBD_Block |
56 def Clone(self, id = None, name = "", pos = None): |
56 def Clone(self, id = None, name = "", pos = None): |
|
57 if self.Name != "" and name == "": |
|
58 name = self.Name |
57 block = FBD_Block(self.Parent, self.Type, name, id, self.Extension) |
59 block = FBD_Block(self.Parent, self.Type, name, id, self.Extension) |
58 block.SetSize(self.Size[0], self.Size[1]) |
60 block.SetSize(self.Size[0], self.Size[1]) |
59 if pos is not None: |
61 if pos is not None: |
60 block.SetPosition(pos.x, pos.y) |
62 block.SetPosition(pos.x, pos.y) |
61 block.Inputs = [input.Clone(block) for input in self.Inputs] |
63 block.Inputs = [input.Clone(block) for input in self.Inputs] |
64 |
66 |
65 # Destructor |
67 # Destructor |
66 def __del__(self): |
68 def __del__(self): |
67 self.Inputs = [] |
69 self.Inputs = [] |
68 self.Outputs = [] |
70 self.Outputs = [] |
|
71 |
|
72 # Returns the RedrawRect |
|
73 def GetRedrawRect(self, movex = 0, movey = 0): |
|
74 rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
75 if movex != 0 or movey != 0: |
|
76 for input in self.Inputs: |
|
77 if input.IsConnected(): |
|
78 rect = rect.Union(input.GetConnectedRedrawRect(movex, movey)) |
|
79 for output in self.Outputs: |
|
80 if output.IsConnected(): |
|
81 rect = rect.Union(output.GetConnectedRedrawRect(movex, movey)) |
|
82 return rect |
69 |
83 |
70 # Delete this block by calling the appropriate method |
84 # Delete this block by calling the appropriate method |
71 def Delete(self): |
85 def Delete(self): |
72 self.Parent.DeleteBlock(self) |
86 self.Parent.DeleteBlock(self) |
73 |
87 |
170 inputtype = input.GetConnectedType() |
184 inputtype = input.GetConnectedType() |
171 if resulttype is None or inputtype is not None and IsOfType(inputtype, resulttype): |
185 if resulttype is None or inputtype is not None and IsOfType(inputtype, resulttype): |
172 resulttype = inputtype |
186 resulttype = inputtype |
173 for output in self.Outputs: |
187 for output in self.Outputs: |
174 name = output.GetName() |
188 name = output.GetName() |
175 if output != connector and name == "OUT": |
189 if output != connector and name == "OUT" and not IsEndType(output.GetType()): |
176 outputtype = output.GetConnectedType() |
190 outputtype = output.GetConnectedType() |
177 if resulttype is None or outputtype is not None and IsOfType(outputtype, resulttype): |
191 if resulttype is None or outputtype is not None and IsOfType(outputtype, resulttype): |
178 resulttype = outputtype |
192 resulttype = outputtype |
179 return resulttype |
193 return resulttype |
180 |
194 |
336 for output in self.Outputs: |
350 for output in self.Outputs: |
337 output.RefreshWires() |
351 output.RefreshWires() |
338 |
352 |
339 # Draws block |
353 # Draws block |
340 def Draw(self, dc): |
354 def Draw(self, dc): |
|
355 Graphic_Element.Draw(self, dc) |
341 dc.SetPen(self.Pen) |
356 dc.SetPen(self.Pen) |
342 dc.SetBrush(wx.WHITE_BRUSH) |
357 dc.SetBrush(wx.WHITE_BRUSH) |
343 dc.SetTextForeground(self.Colour) |
358 dc.SetTextForeground(self.Colour) |
344 # Draw a rectangle with the block size |
359 # Draw a rectangle with the block size |
345 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
360 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
356 if self.ExecutionOrder != 0: |
371 if self.ExecutionOrder != 0: |
357 # Draw block execution order |
372 # Draw block execution order |
358 dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0], |
373 dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0], |
359 self.Pos.y + self.Size[1] + 2) |
374 self.Pos.y + self.Size[1] + 2) |
360 dc.SetTextForeground(wx.BLACK) |
375 dc.SetTextForeground(wx.BLACK) |
361 Graphic_Element.Draw(self, dc) |
|
362 |
376 |
363 |
377 |
364 #------------------------------------------------------------------------------- |
378 #------------------------------------------------------------------------------- |
365 # Function Block Diagram Variable |
379 # Function Block Diagram Variable |
366 #------------------------------------------------------------------------------- |
380 #------------------------------------------------------------------------------- |
387 def Clone(self, id = None, pos = None): |
401 def Clone(self, id = None, pos = None): |
388 variable = FBD_Variable(self.Parent, self.Type, self.Name, self.ValueType, id) |
402 variable = FBD_Variable(self.Parent, self.Type, self.Name, self.ValueType, id) |
389 variable.SetSize(self.Size[0], self.Size[1]) |
403 variable.SetSize(self.Size[0], self.Size[1]) |
390 if pos is not None: |
404 if pos is not None: |
391 variable.SetPosition(pos.x, pos.y) |
405 variable.SetPosition(pos.x, pos.y) |
392 variable.Input = self.Input.Clone(variable) |
406 if self.Input: |
393 variable.Output = self.Output.Clone(variable) |
407 variable.Input = self.Input.Clone(variable) |
|
408 if self.Output: |
|
409 variable.Output = self.Output.Clone(variable) |
394 return variable |
410 return variable |
395 |
411 |
396 # Destructor |
412 # Destructor |
397 def __del__(self): |
413 def __del__(self): |
398 self.Input = None |
414 self.Input = None |
399 self.Output = None |
415 self.Output = None |
|
416 |
|
417 # Returns the RedrawRect |
|
418 def GetRedrawRect(self, movex = 0, movey = 0): |
|
419 rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
420 if movex != 0 or movey != 0: |
|
421 if self.Input and self.Input.IsConnected(): |
|
422 rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
423 if self.Output and self.Output.IsConnected(): |
|
424 rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
425 return rect |
400 |
426 |
401 # Unconnect connector |
427 # Unconnect connector |
402 def Clean(self): |
428 def Clean(self): |
403 if self.Input: |
429 if self.Input: |
404 self.Input.UnConnect(delete = True) |
430 self.Input.UnConnect(delete = True) |
555 if self.Output: |
581 if self.Output: |
556 self.Output.RefreshWires() |
582 self.Output.RefreshWires() |
557 |
583 |
558 # Draws variable |
584 # Draws variable |
559 def Draw(self, dc): |
585 def Draw(self, dc): |
|
586 Graphic_Element.Draw(self, dc) |
560 dc.SetPen(wx.BLACK_PEN) |
587 dc.SetPen(wx.BLACK_PEN) |
561 dc.SetBrush(wx.WHITE_BRUSH) |
588 dc.SetBrush(wx.WHITE_BRUSH) |
562 # Draw a rectangle with the variable size |
589 # Draw a rectangle with the variable size |
563 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
590 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
564 # Draw variable name |
591 # Draw variable name |
571 self.Output.Draw(dc) |
598 self.Output.Draw(dc) |
572 if self.ExecutionOrder != 0: |
599 if self.ExecutionOrder != 0: |
573 # Draw variable execution order |
600 # Draw variable execution order |
574 dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0], |
601 dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0], |
575 self.Pos.y + self.Size[1] + 2) |
602 self.Pos.y + self.Size[1] + 2) |
576 Graphic_Element.Draw(self, dc) |
|
577 |
603 |
578 |
604 |
579 #------------------------------------------------------------------------------- |
605 #------------------------------------------------------------------------------- |
580 # Function Block Diagram Connector |
606 # Function Block Diagram Connector |
581 #------------------------------------------------------------------------------- |
607 #------------------------------------------------------------------------------- |
604 |
630 |
605 # Destructor |
631 # Destructor |
606 def __del__(self): |
632 def __del__(self): |
607 self.Connector = None |
633 self.Connector = None |
608 |
634 |
|
635 # Returns the RedrawRect |
|
636 def GetRedrawRect(self, movex = 0, movey = 0): |
|
637 rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
638 if movex != 0 or movey != 0: |
|
639 if self.Connector and self.Connector.IsConnected(): |
|
640 rect = rect.Union(self.Connector.GetConnectedRedrawRect(movex, movey)) |
|
641 return rect |
|
642 |
609 # Make a clone of this FBD_Connector |
643 # Make a clone of this FBD_Connector |
610 def Clone(self, id = None, pos = None): |
644 def Clone(self, id = None, pos = None): |
611 connection = FBD_Connector(self.Parent, self.Type, self.Name, id) |
645 connection = FBD_Connector(self.Parent, self.Type, self.Name, id) |
612 connection.SetSize(self.Size[0], self.Size[1]) |
646 connection.SetSize(self.Size[0], self.Size[1]) |
613 if pos is not None: |
647 if pos is not None: |
712 if self.Connector: |
746 if self.Connector: |
713 self.Connector.RefreshWires() |
747 self.Connector.RefreshWires() |
714 |
748 |
715 # Draws connection |
749 # Draws connection |
716 def Draw(self, dc): |
750 def Draw(self, dc): |
|
751 Graphic_Element.Draw(self, dc) |
717 dc.SetPen(wx.BLACK_PEN) |
752 dc.SetPen(wx.BLACK_PEN) |
718 dc.SetBrush(wx.WHITE_BRUSH) |
753 dc.SetBrush(wx.WHITE_BRUSH) |
719 # Draw a rectangle with the connection size with arrows in |
754 # Draw a rectangle with the connection size with arrows in |
720 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
755 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
721 arrowsize = min(self.Size[1] / 2, (self.Size[0] - self.NameSize[0] - 10) / 2) |
756 arrowsize = min(self.Size[1] / 2, (self.Size[0] - self.NameSize[0] - 10) / 2) |
731 dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2, |
766 dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2, |
732 self.Pos.y + (self.Size[1] - self.NameSize[1]) / 2) |
767 self.Pos.y + (self.Size[1] - self.NameSize[1]) / 2) |
733 # Draw connector |
768 # Draw connector |
734 if self.Connector: |
769 if self.Connector: |
735 self.Connector.Draw(dc) |
770 self.Connector.Draw(dc) |
736 Graphic_Element.Draw(self, dc) |
|
737 |
771 |