--- a/graphics/SFC_Objects.py Tue Aug 12 18:15:35 2008 +0200
+++ b/graphics/SFC_Objects.py Tue Aug 12 18:16:09 2008 +0200
@@ -49,6 +49,7 @@
self.SetName(name)
self.Initial = initial
self.Id = id
+ self.Error = None
self.Size = wx.Size(SFC_STEP_DEFAULT_SIZE[0], SFC_STEP_DEFAULT_SIZE[1])
# Create an input and output connector
if not self.Initial:
@@ -459,6 +460,10 @@
elif self.Output:
self.Output.RefreshWires()
+ def AddError(self, infos, start, end):
+ if infos[0] == "name" and start[0] == 0 and end[0] == 0:
+ self.Error = (start[1], end[1])
+
# Draws step
def Draw(self, dc):
Graphic_Element.Draw(self, dc)
@@ -475,8 +480,9 @@
if self.Initial:
dc.DrawRectangle(self.Pos.x + 2, self.Pos.y + 2, self.Size[0] - 3, self.Size[1] - 3)
# Draw step name
- dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - name_size[0]) / 2,
+ name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2,
self.Pos.y + (self.Size[1] - name_size[1]) / 2)
+ dc.DrawText(self.Name, name_pos[0], name_pos[1])
# Draw input and output connectors
if self.Input:
self.Input.Draw(dc)
@@ -484,6 +490,8 @@
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])
#-------------------------------------------------------------------------------
@@ -508,6 +516,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 = {}
# Destructor
def __del__(self):
@@ -820,6 +829,16 @@
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 infos[0] not in self.Errors:
+ self.Errors[infos[0]] = []
+ self.Errors[infos[0]].append((start[1], end[1]))
+ else:
+ pass
+
# Draws transition
def Draw(self, dc):
Graphic_Element.Draw(self, dc)
@@ -850,17 +869,26 @@
condition = self.Condition
else:
condition = "Transition"
- dc.DrawText(condition, self.Pos.x + self.Size[0] + 5,
- self.Pos.y + (self.Size[1] - condition_size[1]) / 2)
+ condition_pos = (self.Pos.x + self.Size[0] + 5,
+ self.Pos.y + (self.Size[1] - condition_size[1]) / 2)
+ dc.DrawText(condition, condition_pos[0], condition_pos[1])
# Draw priority number
if self.Priority != 0:
- dc.DrawText(str(self.Priority), self.Pos.x, self.Pos.y - priority_size[1] - 2)
+ priority_pos = (self.Pos.x, self.Pos.y - priority_size[1] - 2)
+ dc.DrawText(str(self.Priority), priority_pos[0], priority_pos[1])
# Draw input and output connectors
self.Input.Draw(dc)
self.Output.Draw(dc)
if self.Type == "connection":
self.Condition.Draw(dc)
-
+ if "priority" in self.Errors:
+ HighlightErrorZone(dc, priority_pos[0], priority_pos[1], priority_size[0], priority_size[1])
+ if "inline" in self.Errors:
+ 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])
+
#-------------------------------------------------------------------------------
# Sequencial Function Chart Divergence and Convergence
@@ -1306,6 +1334,7 @@
self.SetTarget(target)
self.Id = id
self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1])
+ self.Errors = {}
# Create an input and output connector
self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True)
@@ -1471,6 +1500,10 @@
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
self.RefreshInputModel()
+ def AddError(self, infos, start, end):
+ if infos[0] == "target" and start[0] == 0 and end[0] == 0:
+ self.Errors[infos[0]] = (start[1], end[1])
+
# Draws the highlightment of this element if it is highlighted
def DrawHighlightment(self, dc):
dc.SetPen(wx.Pen(HIGHLIGHTCOLOR))
@@ -1500,11 +1533,14 @@
wx.Point(self.Pos.x + self.Size[0], self.Pos.y),
wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1])]
dc.DrawPolygon(points)
- dc.DrawText(self.Target, self.Pos.x + self.Size[0] + 2,
- self.Pos.y + (self.Size[1] - target_size[1]) / 2)
+ target_pos = (self.Pos.x + self.Size[0] + 2,
+ self.Pos.y + (self.Size[1] - target_size[1]) / 2)
+ dc.DrawText(self.Target, target_pos[0], target_pos[1])
# Draw input connector
if self.Input:
self.Input.Draw(dc)
+ if "target" in self.Errors:
+ HighlightErrorZone(dc, target_pos[0], target_pos[1], target_size[0], target_size[1])
#-------------------------------------------------------------------------------
@@ -1523,6 +1559,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 = {}
# 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)
@@ -1686,6 +1723,17 @@
def RefreshModel(self, move=True):
self.Parent.RefreshActionBlockModel(self)
+ def AddError(self, infos, start, end):
+ if infos[0] == "action" and infos[1] < len(self.Actions):
+ if infos[1] not in self.Errors:
+ self.Errors[infos[1]] = {}
+ if infos[2] == "inline":
+ if infos[2] not in self.Errors[infos[1]]:
+ 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])
+
# Draws divergence
def Draw(self, dc):
Graphic_Element.Draw(self, dc)
@@ -1703,23 +1751,41 @@
if i != 0:
dc.DrawLine(self.Pos.x, self.Pos.y + i * line_size,
self.Pos.x + self.Size[0], self.Pos.y + i * line_size)
- text_width, text_height = dc.GetTextExtent(action["qualifier"])
+ qualifier_size = dc.GetTextExtent(action["qualifier"])
if "duration" in action:
- dc.DrawText(action["qualifier"], self.Pos.x + (colsize[0] - text_width) / 2,
- self.Pos.y + i * line_size + line_size / 2 - text_height)
- text_width, text_height = dc.GetTextExtent(action["duration"])
- dc.DrawText(action["duration"], self.Pos.x + (colsize[0] - text_width) / 2,
- self.Pos.y + i * line_size + line_size / 2)
+ qualifier_pos = (self.Pos.x + (colsize[0] - qualifier_size[0]) / 2,
+ self.Pos.y + i * line_size + line_size / 2 - qualifier_size[1])
+ duration_size = dc.GetTextExtent(action["duration"])
+ duration_pos = (self.Pos.x + (colsize[0] - duration_size[0]) / 2,
+ self.Pos.y + i * line_size + line_size / 2)
+ dc.DrawText(action["duration"], duration_pos[0], duration_pos[1])
else:
- dc.DrawText(action["qualifier"], self.Pos.x + (colsize[0] - text_width) / 2,
- self.Pos.y + i * line_size + (line_size - text_height) / 2)
- text_width, text_height = dc.GetTextExtent(action["value"])
- dc.DrawText(action["value"], self.Pos.x + colsize[0] + (colsize[1] - text_width) / 2,
- self.Pos.y + i * line_size + (line_size - text_height) / 2)
+ qualifier_pos = (self.Pos.x + (colsize[0] - qualifier_size[0]) / 2,
+ self.Pos.y + i * line_size + (line_size - qualifier_size[1]) / 2)
+ dc.DrawText(action["qualifier"], qualifier_pos[0], qualifier_pos[1])
+ content_size = dc.GetTextExtent(action["value"])
+ content_pos = (self.Pos.x + colsize[0] + (colsize[1] - content_size[0]) / 2,
+ self.Pos.y + i * line_size + (line_size - content_size[1]) / 2)
+ dc.DrawText(action["value"], content_pos[0], content_pos[1])
if "indicator" in action:
- text_width, text_height = dc.GetTextExtent(action["indicator"])
- dc.DrawText(action["indicator"], self.Pos.x + colsize[0] + colsize[1] + (colsize[2] - text_width) / 2,
- self.Pos.y + i * line_size + (line_size - text_height) / 2)
+ indicator_size = dc.GetTextExtent(action["indicator"])
+ 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 "duration" in self.Errors[i] and "duration" in action:
+ HighlightErrorZone(dc, duration_pos[0], duration_pos[1], duration_size[0], duration_size[1])
+ if "qualifier" in self.Errors[i]:
+ HighlightErrorZone(dc, qualifier_pos[0], qualifier_pos[1], qualifier_size[0], qualifier_size[1])
+ if "reference" in self.Errors[i]:
+ HighlightErrorZone(dc, content_pos[0], content_pos[1], content_size[0], content_size[1])
+ elif "inline" in self.Errors[i]:
+ 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 "indicator" in self.Errors[i]:
+ HighlightErrorZone(dc, indicator_pos[0], indicator_pos[1], indicator_size[0], indicator_size[1])
# Draw input connector
self.Input.Draw(dc)