48 Graphic_Element.__init__(self, parent) |
48 Graphic_Element.__init__(self, parent) |
49 DebugDataConsumer.__init__(self) |
49 DebugDataConsumer.__init__(self) |
50 self.SetName(name) |
50 self.SetName(name) |
51 self.Initial = initial |
51 self.Initial = initial |
52 self.Id = id |
52 self.Id = id |
53 self.Error = None |
53 self.Highlights = [] |
54 self.Size = wx.Size(SFC_STEP_DEFAULT_SIZE[0], SFC_STEP_DEFAULT_SIZE[1]) |
54 self.Size = wx.Size(SFC_STEP_DEFAULT_SIZE[0], SFC_STEP_DEFAULT_SIZE[1]) |
55 # Create an input and output connector |
55 # Create an input and output connector |
56 if not self.Initial: |
56 if not self.Initial: |
57 self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) |
57 self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) |
58 else: |
58 else: |
511 self.RefreshInputModel() |
511 self.RefreshInputModel() |
512 self.RefreshOutputModel(self.Initial) |
512 self.RefreshOutputModel(self.Initial) |
513 elif self.Output: |
513 elif self.Output: |
514 self.Output.RefreshWires() |
514 self.Output.RefreshWires() |
515 |
515 |
516 def AddError(self, infos, start, end): |
516 # Adds an highlight to the connection |
|
517 def AddHighlight(self, infos, start, end, highlight_type): |
517 if infos[0] == "name" and start[0] == 0 and end[0] == 0: |
518 if infos[0] == "name" and start[0] == 0 and end[0] == 0: |
518 self.Error = (start[1], end[1]) |
519 AddHighlight(self.Highlights, (start, end, highlight_type)) |
|
520 |
|
521 # Removes an highlight from the connection |
|
522 def RemoveHighlight(self, infos, start, end, highlight_type): |
|
523 if infos[0] == "name": |
|
524 RemoveHighlight(self.Highlights, (start, end, highlight_type)) |
|
525 |
|
526 # Removes all the highlights of one particular type from the connection |
|
527 def ClearHighlight(self, highlight_type=None): |
|
528 ClearHighlights(self.Highlights, highlight_type) |
519 |
529 |
520 # Draws step |
530 # Draws step |
521 def Draw(self, dc): |
531 def Draw(self, dc): |
522 Graphic_Element.Draw(self, dc) |
532 Graphic_Element.Draw(self, dc) |
523 if self.Value: |
533 if self.Value: |
549 self.Input.Draw(dc) |
559 self.Input.Draw(dc) |
550 if self.Output: |
560 if self.Output: |
551 self.Output.Draw(dc) |
561 self.Output.Draw(dc) |
552 if self.Action: |
562 if self.Action: |
553 self.Action.Draw(dc) |
563 self.Action.Draw(dc) |
554 if self.Error is not None: |
564 |
555 HighlightErrorZone(dc, name_pos[0], name_pos[1], name_size[0], name_size[1]) |
565 if not getattr(dc, "printing", False): |
|
566 DrawHighlightedText(dc, self.Name, self.Highlights, name_pos[0], name_pos[1]) |
556 |
567 |
557 |
568 |
558 #------------------------------------------------------------------------------- |
569 #------------------------------------------------------------------------------- |
559 # Sequencial Function Chart Transition |
570 # Sequencial Function Chart Transition |
560 #------------------------------------------------------------------------------- |
571 #------------------------------------------------------------------------------- |
576 # Create an input and output connector |
587 # Create an input and output connector |
577 self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True) |
588 self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True) |
578 self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone = True) |
589 self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone = True) |
579 self.SetType(type, condition) |
590 self.SetType(type, condition) |
580 self.SetPriority(priority) |
591 self.SetPriority(priority) |
581 self.Errors = {} |
592 self.Highlights = {} |
582 self.PreviousValue = None |
593 self.PreviousValue = None |
583 self.PreviousSpreading = False |
594 self.PreviousSpreading = False |
584 |
595 |
585 def Flush(self): |
596 def Flush(self): |
586 if self.Input is not None: |
597 if self.Input is not None: |
921 self.RefreshInputModel() |
932 self.RefreshInputModel() |
922 self.RefreshOutputModel() |
933 self.RefreshOutputModel() |
923 else: |
934 else: |
924 self.Output.RefreshWires() |
935 self.Output.RefreshWires() |
925 |
936 |
926 def AddError(self, infos, start, end): |
937 # Adds an highlight to the block |
927 if infos[0] == "priority" and start[0] == 0 and start[1] == 0: |
938 def AddHighlight(self, infos, start, end ,highlight_type): |
928 self.Errors[infos[0]] = (start[1], end[1]) |
939 if infos[0] in ["reference", "inline", "priority"] and start[0] == 0 and end[0] == 0: |
929 elif infos[0] == "inline": |
940 highlights = self.Highlights.setdefault(infos[0], []) |
930 if not self.Errors.has_key(infos[0]): |
941 AddHighlight(highlights, (start, end, highlight_type)) |
931 self.Errors[infos[0]] = [] |
942 |
932 self.Errors[infos[0]].append((start[1], end[1])) |
943 # Removes an highlight from the block |
933 else: |
944 def RemoveHighlight(self, infos, start, end, highlight_type): |
934 pass |
945 if infos[0] in ["reference", "inline", "priority"]: |
|
946 highlights = self.Highlights.get(infos[0], []) |
|
947 if RemoveHighlight(highlights, (start, end, highlight_type)) and len(highlights) == 0: |
|
948 self.Highlights.pop(infos[0]) |
|
949 |
|
950 # Removes all the highlights of one particular type from the block |
|
951 def ClearHighlight(self, highlight_type=None): |
|
952 if highlight_type is None: |
|
953 self.Highlights = {} |
|
954 else: |
|
955 highlight_items = self.Highlights.items() |
|
956 for name, highlights in highlight_items: |
|
957 highlights = ClearHighlights(highlight, highlight_type) |
|
958 if len(highlights) == 0: |
|
959 self.Highlights.pop(name) |
935 |
960 |
936 # Draws transition |
961 # Draws transition |
937 def Draw(self, dc): |
962 def Draw(self, dc): |
938 Graphic_Element.Draw(self, dc) |
963 Graphic_Element.Draw(self, dc) |
939 if self.Value: |
964 if self.Value: |
984 # Draw input and output connectors |
1009 # Draw input and output connectors |
985 self.Input.Draw(dc) |
1010 self.Input.Draw(dc) |
986 self.Output.Draw(dc) |
1011 self.Output.Draw(dc) |
987 if self.Type == "connection": |
1012 if self.Type == "connection": |
988 self.Condition.Draw(dc) |
1013 self.Condition.Draw(dc) |
989 if self.Errors.has_key("priority"): |
1014 |
990 HighlightErrorZone(dc, priority_pos[0], priority_pos[1], priority_size[0], priority_size[1]) |
1015 if not getattr(dc, "printing", False): |
991 if self.Errors.has_key("inline"): |
1016 for name, highlights in self.Highlights.iteritems(): |
992 for start, end in self.Errors["inline"]: |
1017 if name == "priority": |
993 offset = dc.GetTextExtent(self.Condition[:start]) |
1018 DrawHighlightedText(dc, str(self.Priority), highlights, priority_pos[0], priority_pos[1]) |
994 size = dc.GetTextExtent(self.Condition[start:end + 1]) |
1019 else: |
995 HighlightErrorZone(dc, condition_pos[0] + offset[0], condition_pos[1], size[0], size[1]) |
1020 DrawHighlightedText(dc, condition, highlights, condition_pos[0], condition_pos[1]) |
996 |
|
997 |
1021 |
998 #------------------------------------------------------------------------------- |
1022 #------------------------------------------------------------------------------- |
999 # Sequencial Function Chart Divergence and Convergence |
1023 # Sequencial Function Chart Divergence and Convergence |
1000 #------------------------------------------------------------------------------- |
1024 #------------------------------------------------------------------------------- |
1001 |
1025 |
1472 def __init__(self, parent, target, id = None): |
1496 def __init__(self, parent, target, id = None): |
1473 Graphic_Element.__init__(self, parent) |
1497 Graphic_Element.__init__(self, parent) |
1474 self.SetTarget(target) |
1498 self.SetTarget(target) |
1475 self.Id = id |
1499 self.Id = id |
1476 self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1]) |
1500 self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1]) |
1477 self.Errors = {} |
1501 self.Highlights = [] |
1478 # Create an input and output connector |
1502 # Create an input and output connector |
1479 self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True) |
1503 self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True) |
1480 self.Value = None |
1504 self.Value = None |
1481 self.PreviousValue = None |
1505 self.PreviousValue = None |
1482 |
1506 |
1657 self.Parent.RefreshJumpModel(self) |
1681 self.Parent.RefreshJumpModel(self) |
1658 if move: |
1682 if move: |
1659 if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1683 if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1660 self.RefreshInputModel() |
1684 self.RefreshInputModel() |
1661 |
1685 |
1662 def AddError(self, infos, start, end): |
1686 # Adds an highlight to the variable |
|
1687 def AddHighlight(self, infos, start, end, highlight_type): |
1663 if infos[0] == "target" and start[0] == 0 and end[0] == 0: |
1688 if infos[0] == "target" and start[0] == 0 and end[0] == 0: |
1664 self.Errors[infos[0]] = (start[1], end[1]) |
1689 AddHighlight(self.Highlights, (start, end, highlight_type)) |
|
1690 |
|
1691 # Removes an highlight from the variable |
|
1692 def RemoveHighlight(self, infos, start, end, highlight_type): |
|
1693 if infos[0] == "target": |
|
1694 RemoveHighlight(self.Highlights, (start, end, highlight_type)) |
|
1695 |
|
1696 # Removes all the highlights of one particular type from the variable |
|
1697 def ClearHighlight(self, highlight_type=None): |
|
1698 ClearHighlights(self.Highlights, highlight_type) |
1665 |
1699 |
1666 # Draws the highlightment of this element if it is highlighted |
1700 # Draws the highlightment of this element if it is highlighted |
1667 def DrawHighlightment(self, dc): |
1701 def DrawHighlightment(self, dc): |
1668 scalex, scaley = dc.GetUserScale() |
1702 scalex, scaley = dc.GetUserScale() |
1669 dc.SetUserScale(1, 1) |
1703 dc.SetUserScale(1, 1) |
1706 self.Pos.y + (self.Size[1] - target_size[1]) / 2) |
1740 self.Pos.y + (self.Size[1] - target_size[1]) / 2) |
1707 dc.DrawText(self.Target, target_pos[0], target_pos[1]) |
1741 dc.DrawText(self.Target, target_pos[0], target_pos[1]) |
1708 # Draw input connector |
1742 # Draw input connector |
1709 if self.Input: |
1743 if self.Input: |
1710 self.Input.Draw(dc) |
1744 self.Input.Draw(dc) |
1711 if self.Errors.has_key("target"): |
1745 |
1712 HighlightErrorZone(dc, target_pos[0], target_pos[1], target_size[0], target_size[1]) |
1746 if not getattr(dc, "printing", False): |
|
1747 DrawHighlightedText(dc, self.Target, self.Highlights, target_pos[0], target_pos[1]) |
1713 |
1748 |
1714 |
1749 |
1715 #------------------------------------------------------------------------------- |
1750 #------------------------------------------------------------------------------- |
1716 # Sequencial Function Chart Action Block |
1751 # Sequencial Function Chart Action Block |
1717 #------------------------------------------------------------------------------- |
1752 #------------------------------------------------------------------------------- |
1726 def __init__(self, parent, actions = [], id = None): |
1761 def __init__(self, parent, actions = [], id = None): |
1727 Graphic_Element.__init__(self, parent) |
1762 Graphic_Element.__init__(self, parent) |
1728 self.Id = id |
1763 self.Id = id |
1729 self.Size = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1]) |
1764 self.Size = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1]) |
1730 self.MinSize = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1]) |
1765 self.MinSize = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1]) |
1731 self.Errors = {} |
1766 self.Highlights = {} |
1732 # Create an input and output connector |
1767 # Create an input and output connector |
1733 self.Input = Connector(self, "", None, wx.Point(0, SFC_ACTION_MIN_SIZE[1] / 2), WEST, onlyone = True) |
1768 self.Input = Connector(self, "", None, wx.Point(0, SFC_ACTION_MIN_SIZE[1] / 2), WEST, onlyone = True) |
1734 self.SetActions(actions) |
1769 self.SetActions(actions) |
1735 self.Value = None |
1770 self.Value = None |
1736 self.PreviousValue = None |
1771 self.PreviousValue = None |
1905 return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling) |
1940 return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling) |
1906 else: |
1941 else: |
1907 return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling) |
1942 return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling) |
1908 |
1943 |
1909 |
1944 |
1910 # Refreshes the action block model |
1945 # Refreshes the action block model |
1911 def RefreshModel(self, move=True): |
1946 def RefreshModel(self, move=True): |
1912 self.Parent.RefreshActionBlockModel(self) |
1947 self.Parent.RefreshActionBlockModel(self) |
1913 |
1948 |
1914 def AddError(self, infos, start, end): |
1949 # Adds an highlight to the variable |
|
1950 def AddHighlight(self, infos, start, end, highlight_type): |
1915 if infos[0] == "action" and infos[1] < len(self.Actions): |
1951 if infos[0] == "action" and infos[1] < len(self.Actions): |
1916 if not self.Errors.has_key(infos[1]): |
1952 action_highlights = self.Highlights.setdefault(infos[1], {}) |
1917 self.Errors[infos[1]] = {} |
1953 attribute_highlights = action_highlights.setdefault(infos[2], []) |
1918 if infos[2] == "inline": |
1954 AddHighlight(attribute_highlights, (start, end, highlight_type)) |
1919 if not self.Errors[infos[1]].has_key(infos[2]): |
1955 |
1920 self.Errors[infos[1]][infos[2]] = [] |
1956 # Removes an highlight from the block |
1921 self.Errors[infos[1]][infos[2]].append((start[1], end[1])) |
1957 def RemoveHighlight(self, infos, start, end, highlight_type): |
1922 else: |
1958 if infos[0] == "action" and infos[1] < len(self.Actions): |
1923 self.Errors[infos[1]][infos[2]] = (start[1], end[1]) |
1959 action_highlights = self.Highlights.get(infos[1], {}) |
|
1960 attribute_highlights = action_highlights.setdefault(infos[2], []) |
|
1961 if RemoveHighlight(attribute_highlights, (start, end, highlight_type)) and len(attribute_highlights) == 0: |
|
1962 action_highlights.pop(infos[2]) |
|
1963 if len(action_highlights) == 0: |
|
1964 self.Highlights.pop(infos[1]) |
|
1965 |
|
1966 # Removes all the highlights of one particular type from the block |
|
1967 def ClearHighlight(self, highlight_type=None): |
|
1968 if highlight_type is None: |
|
1969 self.Highlights = {} |
|
1970 else: |
|
1971 highlight_items = self.Highlights.items() |
|
1972 for number, action_highlights in highlight_items: |
|
1973 action_highlight_items = action_highlights.items() |
|
1974 for name, attribute_highlights in action_highlights: |
|
1975 attribute_highlights = ClearHighlights(attribute_highlights, highlight_type) |
|
1976 if len(attribute_highlights) == 0: |
|
1977 action_highlights.pop(name) |
|
1978 if len(action_highlights) == 0: |
|
1979 self.Highlights.pop(number) |
1924 |
1980 |
1925 # Draws divergence |
1981 # Draws divergence |
1926 def Draw(self, dc): |
1982 def Draw(self, dc): |
1927 Graphic_Element.Draw(self, dc) |
1983 Graphic_Element.Draw(self, dc) |
1928 if self.Value: |
1984 if self.Value: |
1961 if action.has_key("indicator"): |
2017 if action.has_key("indicator"): |
1962 indicator_size = dc.GetTextExtent(action["indicator"]) |
2018 indicator_size = dc.GetTextExtent(action["indicator"]) |
1963 indicator_pos = (self.Pos.x + colsize[0] + colsize[1] + (colsize[2] - indicator_size[0]) / 2, |
2019 indicator_pos = (self.Pos.x + colsize[0] + colsize[1] + (colsize[2] - indicator_size[0]) / 2, |
1964 self.Pos.y + i * line_size + (line_size - indicator_size[1]) / 2) |
2020 self.Pos.y + i * line_size + (line_size - indicator_size[1]) / 2) |
1965 dc.DrawText(action["indicator"], indicator_pos[0], indicator_pos[1]) |
2021 dc.DrawText(action["indicator"], indicator_pos[0], indicator_pos[1]) |
1966 if i in self.Errors: |
2022 |
1967 if self.Errors[i].has_key("duration") and action.has_key("duration"): |
2023 if not getattr(dc, "printing", False): |
1968 HighlightErrorZone(dc, duration_pos[0], duration_pos[1], duration_size[0], duration_size[1]) |
2024 action_highlights = self.Highlights.get(i, {}) |
1969 if self.Errors[i].has_key("qualifier"): |
2025 for name, attribute_highlights in action_highlights.iteritems(): |
1970 HighlightErrorZone(dc, qualifier_pos[0], qualifier_pos[1], qualifier_size[0], qualifier_size[1]) |
2026 if name == "qualifier": |
1971 if self.Errors[i].has_key("reference"): |
2027 DrawHighlightedText(dc, action["qualifier"], attribute_highlights, qualifier_pos[0], qualifier_pos[1]) |
1972 HighlightErrorZone(dc, content_pos[0], content_pos[1], content_size[0], content_size[1]) |
2028 elif name == "duration": |
1973 elif self.Errors[i].has_key("inline"): |
2029 DrawHighlightedText(dc, action["duration"], attribute_highlights, duration_pos[0], duration_pos[1]) |
1974 for start, end in self.Errors[i]["inline"]: |
2030 elif name in ["reference", "inline"]: |
1975 offset = dc.GetTextExtent(action["value"][:start]) |
2031 DrawHighlightedText(dc, action["value"], attribute_highlights, content_pos[0], content_pos[1]) |
1976 size = dc.GetTextExtent(action["value"][start:end + 1]) |
2032 elif name == "indicator": |
1977 HighlightErrorZone(dc, content_pos[0] + offset[0], content_pos[1], size[0], size[1]) |
2033 DrawHighlightedText(dc, action["indicator"], attribute_highlights, indicator_pos[0], indicator_pos[1]) |
1978 if self.Errors[i].has_key("indicator"): |
2034 |
1979 HighlightErrorZone(dc, indicator_pos[0], indicator_pos[1], indicator_size[0], indicator_size[1]) |
|
1980 # Draw input connector |
2035 # Draw input connector |
1981 self.Input.Draw(dc) |
2036 self.Input.Draw(dc) |
1982 |
2037 |