--- a/graphics/LD_Objects.py Fri Sep 30 17:16:02 2011 +0200
+++ b/graphics/LD_Objects.py Sun Oct 09 19:51:14 2011 +0200
@@ -354,7 +354,7 @@
self.Name = name
self.Id = id
self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1])
- self.Errors = {}
+ self.Highlights = {}
# Create an input and output connector
self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2 + 1), WEST)
self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST)
@@ -595,8 +595,31 @@
dc.SetLogicalFunction(wx.COPY)
dc.SetUserScale(scalex, scaley)
- def AddError(self, infos, start, end):
- self.Errors[infos[0]] = (start[1], end[1])
+ # Adds an highlight to the connection
+ def AddHighlight(self, infos, start, end, highlight_type):
+ highlights = self.Highlights.setdefault(infos[0], [])
+ if infos[0] == "reference":
+ if start[0] == 0 and end[0] == 0:
+ AddHighlight(highlights, (start, end, highlight_type))
+ else:
+ AddHighlight(highlights, ((0, 0), (0, 1), highlight_type))
+
+ # Removes an highlight from the connection
+ def RemoveHighlight(self, infos, start, end, highlight_type):
+ 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 connection
+ 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 contact
def Draw(self, dc):
@@ -651,11 +674,13 @@
# Draw input and output connectors
self.Input.Draw(dc)
self.Output.Draw(dc)
- if self.Errors.has_key("reference"):
- HighlightErrorZone(dc, name_pos[0], name_pos[1], name_size[0], name_size[1])
- if typetext != "" and (self.Errors.has_key("negated") or self.Errors.has_key("rising") or self.Errors.has_key("falling")):
- HighlightErrorZone(dc, type_pos[0], type_pos[1], type_size[0], type_size[1])
-
+
+ if not getattr(dc, "printing", False):
+ for name, highlights in self.Highlights.iteritems():
+ if name == "reference":
+ DrawHighlightedText(dc, self.Name, highlights, name_pos[0], name_pos[1])
+ elif typetext != "":
+ DrawHighlightedText(dc, typetext, highlights, type_pos[0], type_pos[1])
#-------------------------------------------------------------------------------
# Ladder Diagram Coil
@@ -674,7 +699,7 @@
self.Name = name
self.Id = id
self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1])
- self.Errors = {}
+ self.Highlights = {}
# Create an input and output connector
self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2 + 1), WEST)
self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST)
@@ -891,8 +916,31 @@
dc.SetLogicalFunction(wx.COPY)
dc.SetUserScale(scalex, scaley)
- def AddError(self, infos, start, end):
- self.Errors[infos[0]] = (start[1], end[1])
+ # Adds an highlight to the connection
+ def AddHighlight(self, infos, start, end, highlight_type):
+ highlights = self.Highlights.setdefault(infos[0], [])
+ if infos[0] == "reference":
+ if start[0] == 0 and end[0] == 0:
+ AddHighlight(highlights, (start, end, highlight_type))
+ else:
+ AddHighlight(highlights, ((0, 0), (0, 1), highlight_type))
+
+ # Removes an highlight from the connection
+ def RemoveHighlight(self, infos, start, end, highlight_type):
+ 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 connection
+ 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 coil
def Draw(self, dc):
@@ -954,9 +1002,12 @@
# Draw input and output connectors
self.Input.Draw(dc)
self.Output.Draw(dc)
- if self.Errors.has_key("reference"):
- HighlightErrorZone(dc, name_pos[0], name_pos[1], name_size[0], name_size[1])
- if typetext != "" and (self.Errors.has_key("negated") or self.Errors.has_key("rising") or self.Errors.has_key("falling")):
- HighlightErrorZone(dc, type_pos[0], type_pos[1], type_size[0], type_size[1])
+
+ if not getattr(dc, "printing", False):
+ for name, highlights in self.Highlights.iteritems():
+ if name == "reference":
+ DrawHighlightedText(dc, self.Name, highlights, name_pos[0], name_pos[1])
+ elif typetext != "":
+ DrawHighlightedText(dc, typetext, highlights, type_pos[0], type_pos[1])