120 else: |
119 else: |
121 bbx_y = self.Pos.y - CONNECTOR_SIZE |
120 bbx_y = self.Pos.y - CONNECTOR_SIZE |
122 bbx_height = self.Size[1] + CONNECTOR_SIZE |
121 bbx_height = self.Size[1] + CONNECTOR_SIZE |
123 if self.Output: |
122 if self.Output: |
124 bbx_height += CONNECTOR_SIZE |
123 bbx_height += CONNECTOR_SIZE |
125 #self.BoundingBox = wxRect(self.Pos.x, bbx_y, bbx_width + 1, bbx_height + 1) |
124 #self.BoundingBox = wx.Rect(self.Pos.x, bbx_y, bbx_width + 1, bbx_height + 1) |
126 self.BoundingBox = wxRect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
125 self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
127 |
126 |
128 # Refresh the positions of the step connectors |
127 # Refresh the positions of the step connectors |
129 def RefreshConnectors(self): |
128 def RefreshConnectors(self): |
130 # Update input position if it exists |
129 # Update input position if it exists |
131 if self.Input: |
130 if self.Input: |
132 self.Input.SetPosition(wxPoint(self.Size[0] / 2, 0)) |
131 self.Input.SetPosition(wx.Point(self.Size[0] / 2, 0)) |
133 # Update output position |
132 # Update output position |
134 if self.Output: |
133 if self.Output: |
135 self.Output.SetPosition(wxPoint(self.Size[0] / 2, self.Size[1])) |
134 self.Output.SetPosition(wx.Point(self.Size[0] / 2, self.Size[1])) |
136 # Update action position if it exists |
135 # Update action position if it exists |
137 if self.Action: |
136 if self.Action: |
138 self.Action.SetPosition(wxPoint(self.Size[0], self.Size[1] / 2)) |
137 self.Action.SetPosition(wx.Point(self.Size[0], self.Size[1] / 2)) |
139 self.RefreshConnected() |
138 self.RefreshConnected() |
140 |
139 |
141 # Refresh the position of wires connected to step |
140 # Refresh the position of wires connected to step |
142 def RefreshConnected(self, exclude = []): |
141 def RefreshConnected(self, exclude = []): |
143 if self.Input: |
142 if self.Input: |
283 wire_size = SFC_WIRE_MIN_SIZE + self.GetActionExtraLineNumber() * SFC_ACTION_MIN_SIZE[1] |
282 wire_size = SFC_WIRE_MIN_SIZE + self.GetActionExtraLineNumber() * SFC_ACTION_MIN_SIZE[1] |
284 diffy = wire_size - output_pos.y + current_pos.y |
283 diffy = wire_size - output_pos.y + current_pos.y |
285 if diffy != 0: |
284 if diffy != 0: |
286 if isinstance(output_block, SFC_Step): |
285 if isinstance(output_block, SFC_Step): |
287 output_block.MoveActionBlock((diffx, diffy)) |
286 output_block.MoveActionBlock((diffx, diffy)) |
288 wires[0][0].SetPoints([wxPoint(current_pos.x, current_pos.y + wire_size), |
287 wires[0][0].SetPoints([wx.Point(current_pos.x, current_pos.y + wire_size), |
289 wxPoint(current_pos.x, current_pos.y)]) |
288 wx.Point(current_pos.x, current_pos.y)]) |
290 if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0: |
289 if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0: |
291 output_block.Move(diffx, diffy, self.Parent.Wires) |
290 output_block.Move(diffx, diffy, self.Parent.Wires) |
292 output_block.RefreshOutputPosition((diffx, diffy)) |
291 output_block.RefreshOutputPosition((diffx, diffy)) |
293 else: |
292 else: |
294 output_block.RefreshPosition() |
293 output_block.RefreshPosition() |
422 """ |
421 """ |
423 |
422 |
424 class SFC_Transition(Graphic_Element): |
423 class SFC_Transition(Graphic_Element): |
425 |
424 |
426 # Create a new transition |
425 # Create a new transition |
427 def __init__(self, parent, type = "reference", condition = "", id = None): |
426 def __init__(self, parent, type = "reference", condition = None, id = None): |
428 Graphic_Element.__init__(self, parent) |
427 Graphic_Element.__init__(self, parent) |
429 self.Type = type |
428 self.Type = None |
430 self.Condition = condition |
|
431 self.Id = id |
429 self.Id = id |
432 self.Size = wxSize(SFC_TRANSITION_SIZE[0], SFC_TRANSITION_SIZE[1]) |
430 self.Size = wx.Size(SFC_TRANSITION_SIZE[0], SFC_TRANSITION_SIZE[1]) |
433 # Create an input and output connector |
431 # Create an input and output connector |
434 self.Input = Connector(self, "", "ANY", wxPoint(self.Size[0] / 2, 0), NORTH) |
432 self.Input = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, 0), NORTH) |
435 self.Output = Connector(self, "", "ANY", wxPoint(self.Size[0] / 2, self.Size[1]), SOUTH) |
433 self.Output = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH) |
|
434 self.SetType(type, condition) |
436 |
435 |
437 # Destructor |
436 # Destructor |
438 def __del__(self): |
437 def __del__(self): |
439 self.Input = None |
438 self.Input = None |
440 self.Output = None |
439 self.Output = None |
|
440 if self.Type == "connection": |
|
441 self.Condition = None |
441 |
442 |
442 # Forbids to change the transition size |
443 # Forbids to change the transition size |
443 def SetSize(self, width, height): |
444 def SetSize(self, width, height): |
444 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
445 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
445 Graphic_Element.SetSize(self, width, height) |
446 Graphic_Element.SetSize(self, width, height) |
447 # Forbids to resize the transition |
448 # Forbids to resize the transition |
448 def Resize(self, x, y, width, height): |
449 def Resize(self, x, y, width, height): |
449 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
450 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
450 Graphic_Element.Resize(self, x, y, width, height) |
451 Graphic_Element.Resize(self, x, y, width, height) |
451 |
452 |
|
453 # Refresh the size of text for name |
|
454 def RefreshConditionSize(self): |
|
455 if self.Type != "connection": |
|
456 dc = wx.ClientDC(self.Parent) |
|
457 if self.Condition != "": |
|
458 self.ConditionSize = dc.GetTextExtent(self.Condition) |
|
459 else: |
|
460 self.ConditionSize = dc.GetTextExtent("Transition") |
|
461 |
452 # Delete this transition by calling the appropriate method |
462 # Delete this transition by calling the appropriate method |
453 def Delete(self): |
463 def Delete(self): |
454 self.Parent.DeleteTransition(self) |
464 self.Parent.DeleteTransition(self) |
455 |
465 |
456 # Unconnect input and output |
466 # Unconnect input and output |
457 def Clean(self): |
467 def Clean(self): |
458 self.Input.UnConnect() |
468 self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
459 self.Output.UnConnect() |
469 self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
|
470 if self.Type == "connection": |
|
471 self.Condition.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
460 |
472 |
461 # Refresh the transition bounding box |
473 # Refresh the transition bounding box |
462 def RefreshBoundingBox(self): |
474 def RefreshBoundingBox(self): |
463 dc = wxClientDC(self.Parent) |
475 dc = wx.ClientDC(self.Parent) |
464 if self.Condition != "": |
476 if self.Type == "connection": |
465 text_width, text_height = dc.GetTextExtent(self.Condition) |
477 bbx_x = self.Pos.x - CONNECTOR_SIZE |
466 else: |
478 bbx_width = self.Size[0] + CONNECTOR_SIZE |
467 text_width, text_height = dc.GetTextExtent("Transition") |
479 bbx_y = self.Pos.y |
468 # Calculate the bounding box size |
480 bbx_height = self.Size[1] |
469 bbx_width = self.Size[0] + 5 + text_width |
481 else: |
470 bbx_y = self.Pos.y - max(0, (text_height - 5 - self.Size[1]) / 2) |
482 text_width, text_height = self.ConditionSize |
471 bbx_height = max(self.Size[1], text_height) |
483 # Calculate the bounding box size |
472 self.BoundingBox = wxRect(self.Pos.x, bbx_y, bbx_width + 1, bbx_height - 4) |
484 bbx_x = self.Pos.x |
|
485 bbx_width = self.Size[0] + 5 + text_width |
|
486 bbx_y = self.Pos.y - max(0, (text_height - 5 - self.Size[1]) / 2) |
|
487 bbx_height = max(self.Size[1], text_height) - 5 |
|
488 self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) |
473 |
489 |
474 # Returns the connector connected to input |
490 # Returns the connector connected to input |
475 def GetPreviousConnector(self): |
491 def GetPreviousConnector(self): |
476 wires = self.Input.GetWires() |
492 wires = self.Input.GetWires() |
477 if len(wires) == 1: |
493 if len(wires) == 1: |
486 return None |
502 return None |
487 |
503 |
488 # Refresh the positions of the transition connectors |
504 # Refresh the positions of the transition connectors |
489 def RefreshConnectors(self): |
505 def RefreshConnectors(self): |
490 # Update input position |
506 # Update input position |
491 self.Input.SetPosition(wxPoint(self.Size[0] / 2, 0)) |
507 self.Input.SetPosition(wx.Point(self.Size[0] / 2, 0)) |
492 # Update output position |
508 # Update output position |
493 self.Output.SetPosition(wxPoint(self.Size[0] / 2, self.Size[1])) |
509 self.Output.SetPosition(wx.Point(self.Size[0] / 2, self.Size[1])) |
|
510 if self.Type == "connection": |
|
511 self.Condition.SetPosition(wx.Point(0, self.Size[1] / 2)) |
494 self.RefreshConnected() |
512 self.RefreshConnected() |
495 |
513 |
496 # Refresh the position of the wires connected to transition |
514 # Refresh the position of the wires connected to transition |
497 def RefreshConnected(self, exclude = []): |
515 def RefreshConnected(self, exclude = []): |
498 self.Input.MoveConnected(exclude) |
516 self.Input.MoveConnected(exclude) |
499 self.Output.MoveConnected(exclude) |
517 self.Output.MoveConnected(exclude) |
|
518 if self.Type == "connection": |
|
519 self.Condition.MoveConnected(exclude) |
500 |
520 |
501 # Returns the transition connector that starts with the point given if it exists |
521 # Returns the transition connector that starts with the point given if it exists |
502 def GetConnector(self, position, name = None): |
522 def GetConnector(self, position, name = None): |
503 # if a name is given |
523 # if a name is given |
504 if name: |
524 if name: |
505 # Test input and output connector |
525 # Test input and output connector |
506 if name == self.Input.GetName(): |
526 if name == self.Input.GetName(): |
507 return self.Input |
527 return self.Input |
508 if name == self.Output.GetName(): |
528 if name == self.Output.GetName(): |
509 return self.Output |
529 return self.Output |
|
530 if self.Type == "connection" and name == self.Condition.GetName(): |
|
531 return self.Condition |
510 # Test input connector |
532 # Test input connector |
511 input_pos = self.Input.GetRelPosition() |
533 input_pos = self.Input.GetRelPosition() |
512 if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: |
534 if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: |
513 return self.Input |
535 return self.Input |
514 # Test output connector |
536 # Test output connector |
515 output_pos = self.Output.GetRelPosition() |
537 output_pos = self.Output.GetRelPosition() |
516 if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
538 if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
517 return self.Output |
539 return self.Output |
|
540 if self.Type == "connection": |
|
541 # Test condition connector |
|
542 condition_pos = self.Condition.GetRelPosition() |
|
543 if position.x == self.Pos.x + condition_pos.x and position.y == self.Pos.y + condition_pos.y: |
|
544 return self.Condition |
518 return None |
545 return None |
519 |
546 |
520 # Returns input and output transition connectors |
547 # Returns input and output transition connectors |
521 def GetConnectors(self): |
548 def GetConnectors(self): |
522 return {"input":self.Input,"output":self.Output} |
549 connectors = {"input":self.Input,"output":self.Output} |
|
550 if self.Type == "connection": |
|
551 connectors["connection"] = self.Condition |
|
552 return connectors |
523 |
553 |
524 # Test if point given is on transition input or output connector |
554 # Test if point given is on transition input or output connector |
525 def TestConnector(self, pt, exclude=True): |
555 def TestConnector(self, pt, exclude=True): |
526 # Test input connector |
556 # Test input connector |
527 if self.Input.TestPoint(pt, exclude): |
557 if self.Input.TestPoint(pt, exclude): |
528 return self.Input |
558 return self.Input |
529 # Test output connector |
559 # Test output connector |
530 if self.Output.TestPoint(pt, exclude): |
560 if self.Output.TestPoint(pt, exclude): |
531 return self.Output |
561 return self.Output |
|
562 # Test condition connector |
|
563 if self.Type == "connection" and self.Condition.TestPoint(pt, exclude): |
|
564 return self.Condition |
532 return None |
565 return None |
533 |
566 |
534 # Changes the transition type |
567 # Changes the transition type |
535 def SetType(self, type): |
568 def SetType(self, type, condition = None): |
536 self.Type = type |
569 if self.Type != type: |
|
570 if self.Type == "connection": |
|
571 self.Condition.UnConnect() |
|
572 self.Type = type |
|
573 if type == "connection": |
|
574 self.Condition = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2), WEST) |
|
575 else: |
|
576 if condition == None: |
|
577 condition = "" |
|
578 self.Condition = condition |
|
579 self.RefreshConditionSize() |
|
580 elif self.Type != "connection": |
|
581 if condition == None: |
|
582 condition = "" |
|
583 self.Condition = condition |
|
584 self.RefreshConditionSize() |
|
585 self.RefreshBoundingBox() |
537 |
586 |
538 # Returns the transition type |
587 # Returns the transition type |
539 def GetType(self): |
588 def GetType(self): |
540 return self.Type |
589 return self.Type |
541 |
590 |
542 # Changes the transition condition |
|
543 def SetCondition(self, condition): |
|
544 self.Condition = condition |
|
545 self.RefreshBoundingBox() |
|
546 |
|
547 # Returns the transition condition |
591 # Returns the transition condition |
548 def GetCondition(self): |
592 def GetCondition(self): |
549 return self.Condition |
593 if self.Type != "connection": |
|
594 return self.Condition |
|
595 return None |
550 |
596 |
551 # Returns the transition minimum size |
597 # Returns the transition minimum size |
552 def GetMinSize(self): |
598 def GetMinSize(self): |
553 return SFC_TRANSITION_SIZE |
599 return SFC_TRANSITION_SIZE |
554 |
600 |
645 else: |
691 else: |
646 self.Output.RefreshWires() |
692 self.Output.RefreshWires() |
647 |
693 |
648 # Draws transition |
694 # Draws transition |
649 def Draw(self, dc): |
695 def Draw(self, dc): |
650 dc.SetPen(wxBLACK_PEN) |
696 dc.SetPen(wx.BLACK_PEN) |
651 dc.SetBrush(wxBLACK_BRUSH) |
697 dc.SetBrush(wx.BLACK_BRUSH) |
652 # Draw plain rectangle for representing the transition |
698 # Draw plain rectangle for representing the transition |
653 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
699 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
654 # Draw transition condition |
700 # Draw transition condition |
655 if self.Condition != "": |
701 if self.Type != "connection": |
656 text_width, text_height = dc.GetTextExtent(self.Condition) |
702 text_width, text_height = self.ConditionSize |
657 condition = self.Condition |
703 if self.Condition != "": |
658 else: |
704 condition = self.Condition |
659 text_width, text_height = dc.GetTextExtent("Transition") |
705 else: |
660 condition = "Transition" |
706 condition = "Transition" |
661 dc.DrawText(condition, self.Pos.x + self.Size[0] + 5, |
707 dc.DrawText(condition, self.Pos.x + self.Size[0] + 5, |
662 self.Pos.y + (self.Size[1] - text_height) / 2) |
708 self.Pos.y + (self.Size[1] - text_height) / 2) |
663 # Draw input and output connectors |
709 # Draw input and output connectors |
664 self.Input.Draw(dc) |
710 self.Input.Draw(dc) |
665 self.Output.Draw(dc) |
711 self.Output.Draw(dc) |
|
712 if self.Type == "connection": |
|
713 self.Condition.Draw(dc) |
666 Graphic_Element.Draw(self, dc) |
714 Graphic_Element.Draw(self, dc) |
667 |
715 |
668 #------------------------------------------------------------------------------- |
716 #------------------------------------------------------------------------------- |
669 # Sequencial Function Chart Divergence and Convergence |
717 # Sequencial Function Chart Divergence and Convergence |
670 #------------------------------------------------------------------------------- |
718 #------------------------------------------------------------------------------- |
682 self.Type = type |
730 self.Type = type |
683 self.Id = id |
731 self.Id = id |
684 self.RealConnectors = None |
732 self.RealConnectors = None |
685 number = max(2, number) |
733 number = max(2, number) |
686 if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
734 if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
687 self.Size = wxSize((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, 1) |
735 self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, 1) |
688 elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
736 elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
689 self.Size = wxSize((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, 3) |
737 self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, 3) |
690 # Create an input and output connector |
738 # Create an input and output connector |
691 if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
739 if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
692 self.Inputs = [Connector(self, "", "ANY", wxPoint(self.Size[0] / 2, 0), NORTH)] |
740 self.Inputs = [Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, 0), NORTH)] |
693 self.Outputs = [] |
741 self.Outputs = [] |
694 for i in xrange(number): |
742 for i in xrange(number): |
695 self.Outputs.append(Connector(self, "", "ANY", wxPoint(i * SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH)) |
743 self.Outputs.append(Connector(self, "", "ANY", wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH)) |
696 elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
744 elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
697 self.Inputs = [] |
745 self.Inputs = [] |
698 for i in xrange(number): |
746 for i in xrange(number): |
699 self.Inputs.append(Connector(self, "", "ANY", wxPoint(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH)) |
747 self.Inputs.append(Connector(self, "", "ANY", wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH)) |
700 self.Outputs = [Connector(self, "", "ANY", wxPoint(self.Size[0] / 2, self.Size[1]), SOUTH)] |
748 self.Outputs = [Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH)] |
701 |
749 |
702 # Destructor |
750 # Destructor |
703 def __del__(self): |
751 def __del__(self): |
704 self.Inputs = [] |
752 self.Inputs = [] |
705 self.Outputs = [] |
753 self.Outputs = [] |
718 return self.Type |
766 return self.Type |
719 |
767 |
720 # Unconnect input and output |
768 # Unconnect input and output |
721 def Clean(self): |
769 def Clean(self): |
722 for input in self.Inputs: |
770 for input in self.Inputs: |
723 input.UnConnect() |
771 input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
724 for output in self.Outputs: |
772 for output in self.Outputs: |
725 output.UnConnect() |
773 output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
726 |
774 |
727 # Add a branch to the divergence |
775 # Add a branch to the divergence |
728 def AddBranch(self): |
776 def AddBranch(self): |
729 if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
777 if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
730 maxx = 0 |
778 maxx = 0 |
731 for output in self.Outputs: |
779 for output in self.Outputs: |
732 pos = output.GetRelPosition() |
780 pos = output.GetRelPosition() |
733 maxx = max(maxx, pos.x) |
781 maxx = max(maxx, pos.x) |
734 connector = Connector(self, "", "ANY", wxPoint(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH) |
782 connector = Connector(self, "", "ANY", wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH) |
735 self.Outputs.append(connector) |
783 self.Outputs.append(connector) |
736 self.MoveConnector(connector, 0) |
784 self.MoveConnector(connector, 0) |
737 elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
785 elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
738 maxx = 0 |
786 maxx = 0 |
739 for input in self.Inputs: |
787 for input in self.Inputs: |
740 pos = input.GetRelPosition() |
788 pos = input.GetRelPosition() |
741 maxx = max(maxx, pos.x) |
789 maxx = max(maxx, pos.x) |
742 connector = Connector(self, "", "ANY", wxPoint(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH) |
790 connector = Connector(self, "", "ANY", wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH) |
743 self.Inputs.append(connector) |
791 self.Inputs.append(connector) |
744 self.MoveConnector(connector, SFC_DEFAULT_SEQUENCE_INTERVAL) |
792 self.MoveConnector(connector, SFC_DEFAULT_SEQUENCE_INTERVAL) |
745 |
793 |
746 # Remove a branch from the divergence |
794 # Remove a branch from the divergence |
747 def RemoveBranch(self, connector): |
795 def RemoveBranch(self, connector): |
767 return rect.InsideXY(pt.x, pt.y) or self.TestConnector(pt, False) != None |
815 return rect.InsideXY(pt.x, pt.y) or self.TestConnector(pt, False) != None |
768 |
816 |
769 # Refresh the divergence bounding box |
817 # Refresh the divergence bounding box |
770 def RefreshBoundingBox(self): |
818 def RefreshBoundingBox(self): |
771 if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
819 if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
772 self.BoundingBox = wxRect(self.Pos.x, self.Pos.y - 2, |
820 self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y - 2, |
773 self.Size[0] + 1, self.Size[1] + 5) |
821 self.Size[0] + 1, self.Size[1] + 5) |
774 elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
822 elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
775 self.BoundingBox = wxRect(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y - 2, |
823 self.BoundingBox = wx.Rect(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y - 2, |
776 self.Size[0] + 2 * SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Size[1] + 5) |
824 self.Size[0] + 2 * SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Size[1] + 5) |
777 |
825 |
778 # Refresh the position of wires connected to divergence |
826 # Refresh the position of wires connected to divergence |
779 def RefreshConnected(self, exclude = []): |
827 def RefreshConnected(self, exclude = []): |
780 for input in self.Inputs: |
828 for input in self.Inputs: |
850 # Changes the divergence size |
898 # Changes the divergence size |
851 def SetSize(self, width, height): |
899 def SetSize(self, width, height): |
852 for i, input in enumerate(self.Inputs): |
900 for i, input in enumerate(self.Inputs): |
853 position = input.GetRelPosition() |
901 position = input.GetRelPosition() |
854 if self.RealConnectors: |
902 if self.RealConnectors: |
855 input.SetPosition(wxPoint(int(round(self.RealConnectors["Inputs"][i] * width)), 0)) |
903 input.SetPosition(wx.Point(int(round(self.RealConnectors["Inputs"][i] * width)), 0)) |
856 else: |
904 else: |
857 input.SetPosition(wxPoint(int(round(float(position.x)*float(width)/float(self.Size[0]))), 0)) |
905 input.SetPosition(wx.Point(int(round(float(position.x)*float(width)/float(self.Size[0]))), 0)) |
858 input.MoveConnected() |
906 input.MoveConnected() |
859 for i, output in enumerate(self.Outputs): |
907 for i, output in enumerate(self.Outputs): |
860 position = output.GetRelPosition() |
908 position = output.GetRelPosition() |
861 if self.RealConnectors: |
909 if self.RealConnectors: |
862 output.SetPosition(wxPoint(int(round(self.RealConnectors["Outputs"][i] * width)), self.Size[1])) |
910 output.SetPosition(wx.Point(int(round(self.RealConnectors["Outputs"][i] * width)), self.Size[1])) |
863 else: |
911 else: |
864 output.SetPosition(wxPoint(int(round(float(position.x)*float(width)/float(self.Size[0]))), self.Size[1])) |
912 output.SetPosition(wx.Point(int(round(float(position.x)*float(width)/float(self.Size[0]))), self.Size[1])) |
865 output.MoveConnected() |
913 output.MoveConnected() |
866 self.Size = wxSize(width, height) |
914 self.Size = wx.Size(width, height) |
867 self.RefreshBoundingBox() |
915 self.RefreshBoundingBox() |
868 |
916 |
869 # Returns the divergence minimum size |
917 # Returns the divergence minimum size |
870 def GetMinSize(self): |
918 def GetMinSize(self): |
871 if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
919 if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
1075 def Delete(self): |
1123 def Delete(self): |
1076 self.Parent.DeleteJump(self) |
1124 self.Parent.DeleteJump(self) |
1077 |
1125 |
1078 # Unconnect input |
1126 # Unconnect input |
1079 def Clean(self): |
1127 def Clean(self): |
1080 self.Input.UnConnect() |
1128 self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
1081 |
1129 |
1082 # Refresh the jump bounding box |
1130 # Refresh the jump bounding box |
1083 def RefreshBoundingBox(self): |
1131 def RefreshBoundingBox(self): |
1084 dc = wxClientDC(self.Parent) |
1132 dc = wx.ClientDC(self.Parent) |
1085 text_width, text_height = dc.GetTextExtent(self.Target) |
1133 text_width, text_height = dc.GetTextExtent(self.Target) |
1086 # Calculate the bounding box size |
1134 # Calculate the bounding box size |
1087 bbx_width = self.Size[0] + 2 + text_width |
1135 bbx_width = self.Size[0] + 2 + text_width |
1088 self.BoundingBox = wxRect(self.Pos.x, self.Pos.y - CONNECTOR_SIZE, |
1136 self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y - CONNECTOR_SIZE, |
1089 bbx_width + 1, self.Size[1] + CONNECTOR_SIZE + 1) |
1137 bbx_width + 1, self.Size[1] + CONNECTOR_SIZE + 1) |
1090 |
1138 |
1091 # Returns the connector connected to input |
1139 # Returns the connector connected to input |
1092 def GetPreviousConnector(self): |
1140 def GetPreviousConnector(self): |
1093 wires = self.Input.GetWires() |
1141 wires = self.Input.GetWires() |
1189 if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1237 if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1190 self.RefreshInputModel() |
1238 self.RefreshInputModel() |
1191 |
1239 |
1192 # Draws divergence |
1240 # Draws divergence |
1193 def Draw(self, dc): |
1241 def Draw(self, dc): |
1194 dc.SetPen(wxBLACK_PEN) |
1242 dc.SetPen(wx.BLACK_PEN) |
1195 dc.SetBrush(wxBLACK_BRUSH) |
1243 dc.SetBrush(wx.BLACK_BRUSH) |
1196 # Draw plain rectangle for representing the divergence |
1244 # Draw plain rectangle for representing the divergence |
1197 dc.DrawLine(self.Pos.x + self.Size[0] / 2, self.Pos.y, self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1]) |
1245 dc.DrawLine(self.Pos.x + self.Size[0] / 2, self.Pos.y, self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1]) |
1198 points = [wxPoint(self.Pos.x, self.Pos.y), |
1246 points = [wx.Point(self.Pos.x, self.Pos.y), |
1199 wxPoint(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1] / 3), |
1247 wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1] / 3), |
1200 wxPoint(self.Pos.x + self.Size[0], self.Pos.y), |
1248 wx.Point(self.Pos.x + self.Size[0], self.Pos.y), |
1201 wxPoint(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1])] |
1249 wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1])] |
1202 dc.DrawPolygon(points) |
1250 dc.DrawPolygon(points) |
1203 text_width, text_height = dc.GetTextExtent(self.Target) |
1251 text_width, text_height = dc.GetTextExtent(self.Target) |
1204 dc.DrawText(self.Target, self.Pos.x + self.Size[0] + 2, |
1252 dc.DrawText(self.Target, self.Pos.x + self.Size[0] + 2, |
1205 self.Pos.y + (self.Size[1] - text_height) / 2) |
1253 self.Pos.y + (self.Size[1] - text_height) / 2) |
1206 # Draw input connector |
1254 # Draw input connector |
1293 if "indicator" in action and action["indicator"] != "": |
1341 if "indicator" in action and action["indicator"] != "": |
1294 width, height = dc.GetTextExtent(action["indicator"]) |
1342 width, height = dc.GetTextExtent(action["indicator"]) |
1295 self.ColSize[2] = max(self.ColSize[2], width + 10) |
1343 self.ColSize[2] = max(self.ColSize[2], width + 10) |
1296 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
1344 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
1297 line_size = self.GetLineSize() |
1345 line_size = self.GetLineSize() |
1298 self.Size = wxSize(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], len(self.Actions) * line_size) |
1346 self.Size = wx.Size(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], len(self.Actions) * line_size) |
1299 else: |
1347 else: |
1300 self.Size = wxSize(max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], |
1348 self.Size = wx.Size(max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], |
1301 SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1]) |
1349 SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1]) |
1302 self.RefreshBoundingBox() |
1350 self.RefreshBoundingBox() |
1303 if self.Input: |
1351 if self.Input: |
1304 wires = self.Input.GetWires() |
1352 wires = self.Input.GetWires() |
1305 if len(wires) == 1: |
1353 if len(wires) == 1: |
1341 def RefreshModel(self, move=True): |
1389 def RefreshModel(self, move=True): |
1342 self.Parent.RefreshActionBlockModel(self) |
1390 self.Parent.RefreshActionBlockModel(self) |
1343 |
1391 |
1344 # Draws divergence |
1392 # Draws divergence |
1345 def Draw(self, dc): |
1393 def Draw(self, dc): |
1346 dc.SetPen(wxBLACK_PEN) |
1394 dc.SetPen(wx.BLACK_PEN) |
1347 dc.SetBrush(wxWHITE_BRUSH) |
1395 dc.SetBrush(wx.WHITE_BRUSH) |
1348 colsize = [self.ColSize[0], self.Size[0] - self.ColSize[0] - self.ColSize[2], self.ColSize[2]] |
1396 colsize = [self.ColSize[0], self.Size[0] - self.ColSize[0] - self.ColSize[2], self.ColSize[2]] |
1349 # Draw plain rectangle for representing the action block |
1397 # Draw plain rectangle for representing the action block |
1350 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
1398 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
1351 dc.DrawLine(self.Pos.x + colsize[0], self.Pos.y, |
1399 dc.DrawLine(self.Pos.x + colsize[0], self.Pos.y, |
1352 self.Pos.x + colsize[0], self.Pos.y + self.Size[1]) |
1400 self.Pos.x + colsize[0], self.Pos.y + self.Size[1]) |