--- a/graphics/FBD_Objects.py Fri Sep 30 17:16:02 2011 +0200
+++ b/graphics/FBD_Objects.py Sun Oct 09 19:51:14 2011 +0200
@@ -51,7 +51,7 @@
self.Colour = wx.BLACK
self.Pen = MiterPen(wx.BLACK)
self.SetType(type, extension, inputs, connectors, executionControl)
- self.Errors = {}
+ self.Highlights = {}
# Make a clone of this FBD_Block
def Clone(self, parent, id = None, name = "", pos = None):
@@ -368,13 +368,41 @@
for output in self.Outputs:
output.RefreshWires()
- def AddError(self, infos, start, end):
+ # Adds an highlight to the block
+ def AddHighlight(self, infos, start, end ,highlight_type):
if infos[0] in ["type", "name"] and start[0] == 0 and end[0] == 0:
- self.Errors[infos[0]] = (start, end)
+ highlights = self.Highlights.setdefault(infos[0], [])
+ AddHighlight(highlights, (start, end, highlight_type))
elif infos[0] == "input" and infos[1] < len(self.Inputs):
- self.Inputs[infos[1]].AddError(infos[2:], start, end)
+ self.Inputs[infos[1]].AddHighlight(infos[2:], start, end, highlight_type)
elif infos[0] == "output" and infos[1] < len(self.Outputs):
- self.Outputs[infos[1]].AddError(infos[2:], start, end)
+ self.Outputs[infos[1]].AddHighlight(infos[2:], start, end, highlight_type)
+
+ # Removes an highlight from the block
+ def RemoveHighlight(self, infos, start, end, highlight_type):
+ if infos[0] in ["type", "name"]:
+ highlights = self.Highlights.get(infos[0], [])
+ if RemoveHighlight(highlights, (start, end, highlight_type)) and len(highlights) == 0:
+ self.Highlights.pop(infos[0])
+ elif infos[0] == "input" and infos[1] < len(self.Inputs):
+ self.Inputs[infos[1]].RemoveHighlight(infos[2:], start, end, highlight_type)
+ elif infos[0] == "output" and infos[1] < len(self.Outputs):
+ self.Outputs[infos[1]].RemoveHighlight(infos[2:], start, end, highlight_type)
+
+ # 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(highlights, highlight_type)
+ if len(highlights) == 0:
+ self.Highlights.pop(name)
+ for input in self.Inputs:
+ input.ClearHighlights(highlight_type)
+ for output in self.Outputs:
+ output.ClearHighlights(highlight_type)
# Draws block
def Draw(self, dc):
@@ -410,11 +438,10 @@
# Draw block execution order
dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - executionorder_size[0],
self.Pos.y + self.Size[1] + 2)
- if self.Errors.has_key("name"):
- HighlightErrorZone(dc, name_pos[0], name_pos[1], name_size[0], name_size[1])
- if self.Errors.has_key("type"):
- HighlightErrorZone(dc, type_pos[0], type_pos[1], type_size[0], type_size[1])
- dc.SetTextForeground(wx.BLACK)
+
+ if not getattr(dc, "printing", False):
+ DrawHighlightedText(dc, self.Name, self.Highlights.get("name", []), name_pos[0], name_pos[1])
+ DrawHighlightedText(dc, self.Type, self.Highlights.get("type", []), type_pos[0], type_pos[1])
#-------------------------------------------------------------------------------
@@ -438,7 +465,7 @@
self.Input = None
self.Output = None
self.SetType(type, value_type)
- self.Errors = []
+ self.Highlights = []
# Make a clone of this FBD_Variable
def Clone(self, parent, id = None, pos = None):
@@ -644,9 +671,19 @@
if self.Output:
self.Output.RefreshWires()
- def AddError(self, infos, start, end):
+ # Adds an highlight to the variable
+ def AddHighlight(self, infos, start, end, highlight_type):
if infos[0] == "expression" and start[0] == 0 and end[0] == 0:
- self.Errors.append((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] == "expression":
+ 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 variable
def Draw(self, dc):
@@ -676,11 +713,9 @@
# Draw variable execution order
dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - executionorder_size[0],
self.Pos.y + self.Size[1] + 2)
- for start, end in self.Errors:
- offset = dc.GetTextExtent(self.Name[:start])
- size = dc.GetTextExtent(self.Name[start:end + 1])
- HighlightErrorZone(dc, text_pos[0] + offset[0], text_pos[1], size[0], size[1])
-
+ if not getattr(dc, "printing", False):
+ DrawHighlightedText(dc, self.Name, self.Highlights, text_pos[0], text_pos[1])
+
#-------------------------------------------------------------------------------
# Function Block Diagram Connector
#-------------------------------------------------------------------------------
@@ -699,6 +734,7 @@
self.SetName(name)
self.Pos = wx.Point(0, 0)
self.Size = wx.Size(0, 0)
+ self.Highlights = []
# Create an input or output connector according to connection type
if self.Type == CONNECTOR:
self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone = True)
@@ -851,6 +887,20 @@
if self.Connector:
self.Connector.RefreshWires()
+ # 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:
+ 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 connection
def Draw(self, dc):
Graphic_Element.Draw(self, dc)
@@ -874,9 +924,13 @@
dc.DrawLine(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2,
self.Pos.x + self.Size[0] - arrowsize, self.Pos.y + self.Size[1])
# Draw connection name
- dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - name_size[0]) / 2,
- self.Pos.y + (self.Size[1] - name_size[1]) / 2)
+ text_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, text_pos[0], text_pos[1])
# Draw connector
if self.Connector:
self.Connector.Draw(dc)
+ if not getattr(dc, "printing", False):
+ DrawHighlightedText(dc, self.Name, self.Highlights, text_pos[0], text_pos[1])
+