47 def __init__(self, parent, name, initial = False, id = None): |
47 def __init__(self, parent, name, initial = False, id = None): |
48 Graphic_Element.__init__(self, parent) |
48 Graphic_Element.__init__(self, parent) |
49 self.SetName(name) |
49 self.SetName(name) |
50 self.Initial = initial |
50 self.Initial = initial |
51 self.Id = id |
51 self.Id = id |
|
52 self.Error = None |
52 self.Size = wx.Size(SFC_STEP_DEFAULT_SIZE[0], SFC_STEP_DEFAULT_SIZE[1]) |
53 self.Size = wx.Size(SFC_STEP_DEFAULT_SIZE[0], SFC_STEP_DEFAULT_SIZE[1]) |
53 # Create an input and output connector |
54 # Create an input and output connector |
54 if not self.Initial: |
55 if not self.Initial: |
55 self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) |
56 self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) |
56 else: |
57 else: |
473 # Draw two rectangles for representing the step |
478 # Draw two rectangles for representing the step |
474 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
479 dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
475 if self.Initial: |
480 if self.Initial: |
476 dc.DrawRectangle(self.Pos.x + 2, self.Pos.y + 2, self.Size[0] - 3, self.Size[1] - 3) |
481 dc.DrawRectangle(self.Pos.x + 2, self.Pos.y + 2, self.Size[0] - 3, self.Size[1] - 3) |
477 # Draw step name |
482 # Draw step name |
478 dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
483 name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
479 self.Pos.y + (self.Size[1] - name_size[1]) / 2) |
484 self.Pos.y + (self.Size[1] - name_size[1]) / 2) |
|
485 dc.DrawText(self.Name, name_pos[0], name_pos[1]) |
480 # Draw input and output connectors |
486 # Draw input and output connectors |
481 if self.Input: |
487 if self.Input: |
482 self.Input.Draw(dc) |
488 self.Input.Draw(dc) |
483 if self.Output: |
489 if self.Output: |
484 self.Output.Draw(dc) |
490 self.Output.Draw(dc) |
485 if self.Action: |
491 if self.Action: |
486 self.Action.Draw(dc) |
492 self.Action.Draw(dc) |
|
493 if self.Error is not None: |
|
494 HighlightErrorZone(dc, name_pos[0], name_pos[1], name_size[0], name_size[1]) |
487 |
495 |
488 |
496 |
489 #------------------------------------------------------------------------------- |
497 #------------------------------------------------------------------------------- |
490 # Sequencial Function Chart Transition |
498 # Sequencial Function Chart Transition |
491 #------------------------------------------------------------------------------- |
499 #------------------------------------------------------------------------------- |
506 # Create an input and output connector |
514 # Create an input and output connector |
507 self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True) |
515 self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True) |
508 self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone = True) |
516 self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone = True) |
509 self.SetType(type, condition) |
517 self.SetType(type, condition) |
510 self.SetPriority(priority) |
518 self.SetPriority(priority) |
|
519 self.Errors = {} |
511 |
520 |
512 # Destructor |
521 # Destructor |
513 def __del__(self): |
522 def __del__(self): |
514 self.Input = None |
523 self.Input = None |
515 self.Output = None |
524 self.Output = None |
818 self.RefreshInputModel() |
827 self.RefreshInputModel() |
819 self.RefreshOutputModel() |
828 self.RefreshOutputModel() |
820 else: |
829 else: |
821 self.Output.RefreshWires() |
830 self.Output.RefreshWires() |
822 |
831 |
|
832 def AddError(self, infos, start, end): |
|
833 if infos[0] == "priority" and start[0] == 0 and start[1] == 0: |
|
834 self.Errors[infos[0]] = (start[1], end[1]) |
|
835 elif infos[0] == "inline": |
|
836 if infos[0] not in self.Errors: |
|
837 self.Errors[infos[0]] = [] |
|
838 self.Errors[infos[0]].append((start[1], end[1])) |
|
839 else: |
|
840 pass |
|
841 |
823 # Draws transition |
842 # Draws transition |
824 def Draw(self, dc): |
843 def Draw(self, dc): |
825 Graphic_Element.Draw(self, dc) |
844 Graphic_Element.Draw(self, dc) |
826 dc.SetPen(wx.BLACK_PEN) |
845 dc.SetPen(wx.BLACK_PEN) |
827 dc.SetBrush(wx.BLACK_BRUSH) |
846 dc.SetBrush(wx.BLACK_BRUSH) |
848 if self.Type != "connection": |
867 if self.Type != "connection": |
849 if self.Condition != "": |
868 if self.Condition != "": |
850 condition = self.Condition |
869 condition = self.Condition |
851 else: |
870 else: |
852 condition = "Transition" |
871 condition = "Transition" |
853 dc.DrawText(condition, self.Pos.x + self.Size[0] + 5, |
872 condition_pos = (self.Pos.x + self.Size[0] + 5, |
854 self.Pos.y + (self.Size[1] - condition_size[1]) / 2) |
873 self.Pos.y + (self.Size[1] - condition_size[1]) / 2) |
|
874 dc.DrawText(condition, condition_pos[0], condition_pos[1]) |
855 # Draw priority number |
875 # Draw priority number |
856 if self.Priority != 0: |
876 if self.Priority != 0: |
857 dc.DrawText(str(self.Priority), self.Pos.x, self.Pos.y - priority_size[1] - 2) |
877 priority_pos = (self.Pos.x, self.Pos.y - priority_size[1] - 2) |
|
878 dc.DrawText(str(self.Priority), priority_pos[0], priority_pos[1]) |
858 # Draw input and output connectors |
879 # Draw input and output connectors |
859 self.Input.Draw(dc) |
880 self.Input.Draw(dc) |
860 self.Output.Draw(dc) |
881 self.Output.Draw(dc) |
861 if self.Type == "connection": |
882 if self.Type == "connection": |
862 self.Condition.Draw(dc) |
883 self.Condition.Draw(dc) |
863 |
884 if "priority" in self.Errors: |
|
885 HighlightErrorZone(dc, priority_pos[0], priority_pos[1], priority_size[0], priority_size[1]) |
|
886 if "inline" in self.Errors: |
|
887 for start, end in self.Errors["inline"]: |
|
888 offset = dc.GetTextExtent(self.Condition[:start]) |
|
889 size = dc.GetTextExtent(self.Condition[start:end + 1]) |
|
890 HighlightErrorZone(dc, condition_pos[0] + offset[0], condition_pos[1], size[0], size[1]) |
|
891 |
864 |
892 |
865 #------------------------------------------------------------------------------- |
893 #------------------------------------------------------------------------------- |
866 # Sequencial Function Chart Divergence and Convergence |
894 # Sequencial Function Chart Divergence and Convergence |
867 #------------------------------------------------------------------------------- |
895 #------------------------------------------------------------------------------- |
868 |
896 |
1304 def __init__(self, parent, target, id = None): |
1332 def __init__(self, parent, target, id = None): |
1305 Graphic_Element.__init__(self, parent) |
1333 Graphic_Element.__init__(self, parent) |
1306 self.SetTarget(target) |
1334 self.SetTarget(target) |
1307 self.Id = id |
1335 self.Id = id |
1308 self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1]) |
1336 self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1]) |
|
1337 self.Errors = {} |
1309 # Create an input and output connector |
1338 # Create an input and output connector |
1310 self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True) |
1339 self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True) |
1311 |
1340 |
1312 # Destructor |
1341 # Destructor |
1313 def __del__(self): |
1342 def __del__(self): |
1469 self.Parent.RefreshJumpModel(self) |
1498 self.Parent.RefreshJumpModel(self) |
1470 if move: |
1499 if move: |
1471 if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1500 if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1472 self.RefreshInputModel() |
1501 self.RefreshInputModel() |
1473 |
1502 |
|
1503 def AddError(self, infos, start, end): |
|
1504 if infos[0] == "target" and start[0] == 0 and end[0] == 0: |
|
1505 self.Errors[infos[0]] = (start[1], end[1]) |
|
1506 |
1474 # Draws the highlightment of this element if it is highlighted |
1507 # Draws the highlightment of this element if it is highlighted |
1475 def DrawHighlightment(self, dc): |
1508 def DrawHighlightment(self, dc): |
1476 dc.SetPen(wx.Pen(HIGHLIGHTCOLOR)) |
1509 dc.SetPen(wx.Pen(HIGHLIGHTCOLOR)) |
1477 dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) |
1510 dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) |
1478 dc.SetLogicalFunction(wx.AND) |
1511 dc.SetLogicalFunction(wx.AND) |
1498 points = [wx.Point(self.Pos.x, self.Pos.y), |
1531 points = [wx.Point(self.Pos.x, self.Pos.y), |
1499 wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1] / 3), |
1532 wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1] / 3), |
1500 wx.Point(self.Pos.x + self.Size[0], self.Pos.y), |
1533 wx.Point(self.Pos.x + self.Size[0], self.Pos.y), |
1501 wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1])] |
1534 wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1])] |
1502 dc.DrawPolygon(points) |
1535 dc.DrawPolygon(points) |
1503 dc.DrawText(self.Target, self.Pos.x + self.Size[0] + 2, |
1536 target_pos = (self.Pos.x + self.Size[0] + 2, |
1504 self.Pos.y + (self.Size[1] - target_size[1]) / 2) |
1537 self.Pos.y + (self.Size[1] - target_size[1]) / 2) |
|
1538 dc.DrawText(self.Target, target_pos[0], target_pos[1]) |
1505 # Draw input connector |
1539 # Draw input connector |
1506 if self.Input: |
1540 if self.Input: |
1507 self.Input.Draw(dc) |
1541 self.Input.Draw(dc) |
|
1542 if "target" in self.Errors: |
|
1543 HighlightErrorZone(dc, target_pos[0], target_pos[1], target_size[0], target_size[1]) |
1508 |
1544 |
1509 |
1545 |
1510 #------------------------------------------------------------------------------- |
1546 #------------------------------------------------------------------------------- |
1511 # Sequencial Function Chart Action Block |
1547 # Sequencial Function Chart Action Block |
1512 #------------------------------------------------------------------------------- |
1548 #------------------------------------------------------------------------------- |
1521 def __init__(self, parent, actions = [], id = None): |
1557 def __init__(self, parent, actions = [], id = None): |
1522 Graphic_Element.__init__(self, parent) |
1558 Graphic_Element.__init__(self, parent) |
1523 self.Id = id |
1559 self.Id = id |
1524 self.Size = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1]) |
1560 self.Size = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1]) |
1525 self.MinSize = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1]) |
1561 self.MinSize = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1]) |
|
1562 self.Errors = {} |
1526 # Create an input and output connector |
1563 # Create an input and output connector |
1527 self.Input = Connector(self, "", None, wx.Point(0, SFC_ACTION_MIN_SIZE[1] / 2), WEST, onlyone = True) |
1564 self.Input = Connector(self, "", None, wx.Point(0, SFC_ACTION_MIN_SIZE[1] / 2), WEST, onlyone = True) |
1528 self.SetActions(actions) |
1565 self.SetActions(actions) |
1529 |
1566 |
1530 # Destructor |
1567 # Destructor |
1684 |
1721 |
1685 # Refreshes the action block model |
1722 # Refreshes the action block model |
1686 def RefreshModel(self, move=True): |
1723 def RefreshModel(self, move=True): |
1687 self.Parent.RefreshActionBlockModel(self) |
1724 self.Parent.RefreshActionBlockModel(self) |
1688 |
1725 |
|
1726 def AddError(self, infos, start, end): |
|
1727 if infos[0] == "action" and infos[1] < len(self.Actions): |
|
1728 if infos[1] not in self.Errors: |
|
1729 self.Errors[infos[1]] = {} |
|
1730 if infos[2] == "inline": |
|
1731 if infos[2] not in self.Errors[infos[1]]: |
|
1732 self.Errors[infos[1]][infos[2]] = [] |
|
1733 self.Errors[infos[1]][infos[2]].append((start[1], end[1])) |
|
1734 else: |
|
1735 self.Errors[infos[1]][infos[2]] = (start[1], end[1]) |
|
1736 |
1689 # Draws divergence |
1737 # Draws divergence |
1690 def Draw(self, dc): |
1738 def Draw(self, dc): |
1691 Graphic_Element.Draw(self, dc) |
1739 Graphic_Element.Draw(self, dc) |
1692 dc.SetPen(wx.BLACK_PEN) |
1740 dc.SetPen(wx.BLACK_PEN) |
1693 dc.SetBrush(wx.WHITE_BRUSH) |
1741 dc.SetBrush(wx.WHITE_BRUSH) |
1701 line_size = self.GetLineSize() |
1749 line_size = self.GetLineSize() |
1702 for i, action in enumerate(self.Actions): |
1750 for i, action in enumerate(self.Actions): |
1703 if i != 0: |
1751 if i != 0: |
1704 dc.DrawLine(self.Pos.x, self.Pos.y + i * line_size, |
1752 dc.DrawLine(self.Pos.x, self.Pos.y + i * line_size, |
1705 self.Pos.x + self.Size[0], self.Pos.y + i * line_size) |
1753 self.Pos.x + self.Size[0], self.Pos.y + i * line_size) |
1706 text_width, text_height = dc.GetTextExtent(action["qualifier"]) |
1754 qualifier_size = dc.GetTextExtent(action["qualifier"]) |
1707 if "duration" in action: |
1755 if "duration" in action: |
1708 dc.DrawText(action["qualifier"], self.Pos.x + (colsize[0] - text_width) / 2, |
1756 qualifier_pos = (self.Pos.x + (colsize[0] - qualifier_size[0]) / 2, |
1709 self.Pos.y + i * line_size + line_size / 2 - text_height) |
1757 self.Pos.y + i * line_size + line_size / 2 - qualifier_size[1]) |
1710 text_width, text_height = dc.GetTextExtent(action["duration"]) |
1758 duration_size = dc.GetTextExtent(action["duration"]) |
1711 dc.DrawText(action["duration"], self.Pos.x + (colsize[0] - text_width) / 2, |
1759 duration_pos = (self.Pos.x + (colsize[0] - duration_size[0]) / 2, |
1712 self.Pos.y + i * line_size + line_size / 2) |
1760 self.Pos.y + i * line_size + line_size / 2) |
|
1761 dc.DrawText(action["duration"], duration_pos[0], duration_pos[1]) |
1713 else: |
1762 else: |
1714 dc.DrawText(action["qualifier"], self.Pos.x + (colsize[0] - text_width) / 2, |
1763 qualifier_pos = (self.Pos.x + (colsize[0] - qualifier_size[0]) / 2, |
1715 self.Pos.y + i * line_size + (line_size - text_height) / 2) |
1764 self.Pos.y + i * line_size + (line_size - qualifier_size[1]) / 2) |
1716 text_width, text_height = dc.GetTextExtent(action["value"]) |
1765 dc.DrawText(action["qualifier"], qualifier_pos[0], qualifier_pos[1]) |
1717 dc.DrawText(action["value"], self.Pos.x + colsize[0] + (colsize[1] - text_width) / 2, |
1766 content_size = dc.GetTextExtent(action["value"]) |
1718 self.Pos.y + i * line_size + (line_size - text_height) / 2) |
1767 content_pos = (self.Pos.x + colsize[0] + (colsize[1] - content_size[0]) / 2, |
|
1768 self.Pos.y + i * line_size + (line_size - content_size[1]) / 2) |
|
1769 dc.DrawText(action["value"], content_pos[0], content_pos[1]) |
1719 if "indicator" in action: |
1770 if "indicator" in action: |
1720 text_width, text_height = dc.GetTextExtent(action["indicator"]) |
1771 indicator_size = dc.GetTextExtent(action["indicator"]) |
1721 dc.DrawText(action["indicator"], self.Pos.x + colsize[0] + colsize[1] + (colsize[2] - text_width) / 2, |
1772 indicator_pos = (self.Pos.x + colsize[0] + colsize[1] + (colsize[2] - indicator_size[0]) / 2, |
1722 self.Pos.y + i * line_size + (line_size - text_height) / 2) |
1773 self.Pos.y + i * line_size + (line_size - indicator_size[1]) / 2) |
|
1774 dc.DrawText(action["indicator"], indicator_pos[0], indicator_pos[1]) |
|
1775 if i in self.Errors: |
|
1776 if "duration" in self.Errors[i] and "duration" in action: |
|
1777 HighlightErrorZone(dc, duration_pos[0], duration_pos[1], duration_size[0], duration_size[1]) |
|
1778 if "qualifier" in self.Errors[i]: |
|
1779 HighlightErrorZone(dc, qualifier_pos[0], qualifier_pos[1], qualifier_size[0], qualifier_size[1]) |
|
1780 if "reference" in self.Errors[i]: |
|
1781 HighlightErrorZone(dc, content_pos[0], content_pos[1], content_size[0], content_size[1]) |
|
1782 elif "inline" in self.Errors[i]: |
|
1783 for start, end in self.Errors[i]["inline"]: |
|
1784 offset = dc.GetTextExtent(action["value"][:start]) |
|
1785 size = dc.GetTextExtent(action["value"][start:end + 1]) |
|
1786 HighlightErrorZone(dc, content_pos[0] + offset[0], content_pos[1], size[0], size[1]) |
|
1787 if "indicator" in self.Errors[i]: |
|
1788 HighlightErrorZone(dc, indicator_pos[0], indicator_pos[1], indicator_size[0], indicator_size[1]) |
1723 # Draw input connector |
1789 # Draw input connector |
1724 self.Input.Draw(dc) |
1790 self.Input.Draw(dc) |
1725 |
1791 |