--- a/graphics/SFC_Objects.py Fri Sep 30 17:16:02 2011 +0200
+++ b/graphics/SFC_Objects.py Sun Oct 09 19:51:14 2011 +0200
@@ -50,7 +50,7 @@
self.SetName(name)
self.Initial = initial
self.Id = id
- self.Error = None
+ self.Highlights = []
self.Size = wx.Size(SFC_STEP_DEFAULT_SIZE[0], SFC_STEP_DEFAULT_SIZE[1])
# Create an input and output connector
if not self.Initial:
@@ -513,9 +513,19 @@
elif self.Output:
self.Output.RefreshWires()
- def AddError(self, infos, start, end):
+ # Adds an highlight to the connection
+ def AddHighlight(self, infos, start, end, highlight_type):
if infos[0] == "name" and start[0] == 0 and end[0] == 0:
- self.Error = (start[1], end[1])
+ AddHighlight(self.Highlights, (start, end, highlight_type))
+
+ # Removes an highlight from the connection
+ def RemoveHighlight(self, infos, start, end, highlight_type):
+ if infos[0] == "name":
+ RemoveHighlight(self.Highlights, (start, end, highlight_type))
+
+ # Removes all the highlights of one particular type from the connection
+ def ClearHighlight(self, highlight_type=None):
+ ClearHighlights(self.Highlights, highlight_type)
# Draws step
def Draw(self, dc):
@@ -551,8 +561,9 @@
self.Output.Draw(dc)
if self.Action:
self.Action.Draw(dc)
- if self.Error is not None:
- HighlightErrorZone(dc, name_pos[0], name_pos[1], name_size[0], name_size[1])
+
+ if not getattr(dc, "printing", False):
+ DrawHighlightedText(dc, self.Name, self.Highlights, name_pos[0], name_pos[1])
#-------------------------------------------------------------------------------
@@ -578,7 +589,7 @@
self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone = True)
self.SetType(type, condition)
self.SetPriority(priority)
- self.Errors = {}
+ self.Highlights = {}
self.PreviousValue = None
self.PreviousSpreading = False
@@ -923,15 +934,29 @@
else:
self.Output.RefreshWires()
- def AddError(self, infos, start, end):
- if infos[0] == "priority" and start[0] == 0 and start[1] == 0:
- self.Errors[infos[0]] = (start[1], end[1])
- elif infos[0] == "inline":
- if not self.Errors.has_key(infos[0]):
- self.Errors[infos[0]] = []
- self.Errors[infos[0]].append((start[1], end[1]))
- else:
- pass
+ # Adds an highlight to the block
+ def AddHighlight(self, infos, start, end ,highlight_type):
+ if infos[0] in ["reference", "inline", "priority"] and start[0] == 0 and end[0] == 0:
+ highlights = self.Highlights.setdefault(infos[0], [])
+ AddHighlight(highlights, (start, end, highlight_type))
+
+ # Removes an highlight from the block
+ def RemoveHighlight(self, infos, start, end, highlight_type):
+ if infos[0] in ["reference", "inline", "priority"]:
+ highlights = self.Highlights.get(infos[0], [])
+ if RemoveHighlight(highlights, (start, end, highlight_type)) and len(highlights) == 0:
+ self.Highlights.pop(infos[0])
+
+ # Removes all the highlights of one particular type from the block
+ def ClearHighlight(self, highlight_type=None):
+ if highlight_type is None:
+ self.Highlights = {}
+ else:
+ highlight_items = self.Highlights.items()
+ for name, highlights in highlight_items:
+ highlights = ClearHighlights(highlight, highlight_type)
+ if len(highlights) == 0:
+ self.Highlights.pop(name)
# Draws transition
def Draw(self, dc):
@@ -986,14 +1011,13 @@
self.Output.Draw(dc)
if self.Type == "connection":
self.Condition.Draw(dc)
- if self.Errors.has_key("priority"):
- HighlightErrorZone(dc, priority_pos[0], priority_pos[1], priority_size[0], priority_size[1])
- if self.Errors.has_key("inline"):
- for start, end in self.Errors["inline"]:
- offset = dc.GetTextExtent(self.Condition[:start])
- size = dc.GetTextExtent(self.Condition[start:end + 1])
- HighlightErrorZone(dc, condition_pos[0] + offset[0], condition_pos[1], size[0], size[1])
-
+
+ if not getattr(dc, "printing", False):
+ for name, highlights in self.Highlights.iteritems():
+ if name == "priority":
+ DrawHighlightedText(dc, str(self.Priority), highlights, priority_pos[0], priority_pos[1])
+ else:
+ DrawHighlightedText(dc, condition, highlights, condition_pos[0], condition_pos[1])
#-------------------------------------------------------------------------------
# Sequencial Function Chart Divergence and Convergence
@@ -1474,7 +1498,7 @@
self.SetTarget(target)
self.Id = id
self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1])
- self.Errors = {}
+ self.Highlights = []
# Create an input and output connector
self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True)
self.Value = None
@@ -1659,9 +1683,19 @@
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
self.RefreshInputModel()
- def AddError(self, infos, start, end):
+ # Adds an highlight to the variable
+ def AddHighlight(self, infos, start, end, highlight_type):
if infos[0] == "target" and start[0] == 0 and end[0] == 0:
- self.Errors[infos[0]] = (start[1], end[1])
+ AddHighlight(self.Highlights, (start, end, highlight_type))
+
+ # Removes an highlight from the variable
+ def RemoveHighlight(self, infos, start, end, highlight_type):
+ if infos[0] == "target":
+ RemoveHighlight(self.Highlights, (start, end, highlight_type))
+
+ # Removes all the highlights of one particular type from the variable
+ def ClearHighlight(self, highlight_type=None):
+ ClearHighlights(self.Highlights, highlight_type)
# Draws the highlightment of this element if it is highlighted
def DrawHighlightment(self, dc):
@@ -1708,8 +1742,9 @@
# Draw input connector
if self.Input:
self.Input.Draw(dc)
- if self.Errors.has_key("target"):
- HighlightErrorZone(dc, target_pos[0], target_pos[1], target_size[0], target_size[1])
+
+ if not getattr(dc, "printing", False):
+ DrawHighlightedText(dc, self.Target, self.Highlights, target_pos[0], target_pos[1])
#-------------------------------------------------------------------------------
@@ -1728,7 +1763,7 @@
self.Id = id
self.Size = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1])
self.MinSize = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1])
- self.Errors = {}
+ self.Highlights = {}
# Create an input and output connector
self.Input = Connector(self, "", None, wx.Point(0, SFC_ACTION_MIN_SIZE[1] / 2), WEST, onlyone = True)
self.SetActions(actions)
@@ -1907,20 +1942,41 @@
return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling)
- # Refreshes the action block model
+ # Refreshes the action block model
def RefreshModel(self, move=True):
self.Parent.RefreshActionBlockModel(self)
- def AddError(self, infos, start, end):
+ # Adds an highlight to the variable
+ def AddHighlight(self, infos, start, end, highlight_type):
if infos[0] == "action" and infos[1] < len(self.Actions):
- if not self.Errors.has_key(infos[1]):
- self.Errors[infos[1]] = {}
- if infos[2] == "inline":
- if not self.Errors[infos[1]].has_key(infos[2]):
- self.Errors[infos[1]][infos[2]] = []
- self.Errors[infos[1]][infos[2]].append((start[1], end[1]))
- else:
- self.Errors[infos[1]][infos[2]] = (start[1], end[1])
+ action_highlights = self.Highlights.setdefault(infos[1], {})
+ attribute_highlights = action_highlights.setdefault(infos[2], [])
+ AddHighlight(attribute_highlights, (start, end, highlight_type))
+
+ # Removes an highlight from the block
+ def RemoveHighlight(self, infos, start, end, highlight_type):
+ if infos[0] == "action" and infos[1] < len(self.Actions):
+ action_highlights = self.Highlights.get(infos[1], {})
+ attribute_highlights = action_highlights.setdefault(infos[2], [])
+ if RemoveHighlight(attribute_highlights, (start, end, highlight_type)) and len(attribute_highlights) == 0:
+ action_highlights.pop(infos[2])
+ if len(action_highlights) == 0:
+ self.Highlights.pop(infos[1])
+
+ # Removes all the highlights of one particular type from the block
+ def ClearHighlight(self, highlight_type=None):
+ if highlight_type is None:
+ self.Highlights = {}
+ else:
+ highlight_items = self.Highlights.items()
+ for number, action_highlights in highlight_items:
+ action_highlight_items = action_highlights.items()
+ for name, attribute_highlights in action_highlights:
+ attribute_highlights = ClearHighlights(attribute_highlights, highlight_type)
+ if len(attribute_highlights) == 0:
+ action_highlights.pop(name)
+ if len(action_highlights) == 0:
+ self.Highlights.pop(number)
# Draws divergence
def Draw(self, dc):
@@ -1963,20 +2019,19 @@
indicator_pos = (self.Pos.x + colsize[0] + colsize[1] + (colsize[2] - indicator_size[0]) / 2,
self.Pos.y + i * line_size + (line_size - indicator_size[1]) / 2)
dc.DrawText(action["indicator"], indicator_pos[0], indicator_pos[1])
- if i in self.Errors:
- if self.Errors[i].has_key("duration") and action.has_key("duration"):
- HighlightErrorZone(dc, duration_pos[0], duration_pos[1], duration_size[0], duration_size[1])
- if self.Errors[i].has_key("qualifier"):
- HighlightErrorZone(dc, qualifier_pos[0], qualifier_pos[1], qualifier_size[0], qualifier_size[1])
- if self.Errors[i].has_key("reference"):
- HighlightErrorZone(dc, content_pos[0], content_pos[1], content_size[0], content_size[1])
- elif self.Errors[i].has_key("inline"):
- for start, end in self.Errors[i]["inline"]:
- offset = dc.GetTextExtent(action["value"][:start])
- size = dc.GetTextExtent(action["value"][start:end + 1])
- HighlightErrorZone(dc, content_pos[0] + offset[0], content_pos[1], size[0], size[1])
- if self.Errors[i].has_key("indicator"):
- HighlightErrorZone(dc, indicator_pos[0], indicator_pos[1], indicator_size[0], indicator_size[1])
+
+ if not getattr(dc, "printing", False):
+ action_highlights = self.Highlights.get(i, {})
+ for name, attribute_highlights in action_highlights.iteritems():
+ if name == "qualifier":
+ DrawHighlightedText(dc, action["qualifier"], attribute_highlights, qualifier_pos[0], qualifier_pos[1])
+ elif name == "duration":
+ DrawHighlightedText(dc, action["duration"], attribute_highlights, duration_pos[0], duration_pos[1])
+ elif name in ["reference", "inline"]:
+ DrawHighlightedText(dc, action["value"], attribute_highlights, content_pos[0], content_pos[1])
+ elif name == "indicator":
+ DrawHighlightedText(dc, action["indicator"], attribute_highlights, indicator_pos[0], indicator_pos[1])
+
# Draw input connector
self.Input.Draw(dc)