--- a/graphics/GraphicCommons.py Tue Aug 12 18:15:35 2008 +0200
+++ b/graphics/GraphicCommons.py Tue Aug 12 18:16:09 2008 +0200
@@ -24,7 +24,6 @@
import wx
from math import *
-from plcopen.structures import IsOfType, IsEndType
#-------------------------------------------------------------------------------
# Common constants
@@ -275,6 +274,20 @@
self.currentBox.height)
#-------------------------------------------------------------------------------
+# Helper for highlighting error in drawn text
+#-------------------------------------------------------------------------------
+
+def HighlightErrorZone(dc, x, y, width, height):
+ dc.SetPen(wx.TRANSPARENT_PEN)
+ dc.SetLogicalFunction(wx.AND)
+ dc.SetBrush(wx.Brush(wx.Colour(0,255,0)))
+ dc.DrawRectangle(x, y, width, height)
+ dc.SetLogicalFunction(wx.XOR)
+ dc.SetBrush(wx.Brush(wx.Colour(255,0,0)))
+ dc.DrawRectangle(x, y, width, height)
+ dc.SetLogicalFunction(wx.COPY)
+
+#-------------------------------------------------------------------------------
# Graphic element base class
#-------------------------------------------------------------------------------
@@ -299,6 +312,12 @@
self.CurrentCursor = 0
ResetCursors()
+ def IsOfType(self, type, reference):
+ return self.Parent.IsOfType(type, reference)
+
+ def IsEndType(self, type):
+ return self.Parent.IsEndType(type)
+
def GetDragging(self):
return self.Dragging
@@ -586,6 +605,9 @@
return movex, movey
return 0, 0
+ def AddError(self, infos, start, end):
+ pass
+
# Override this method for defining the method to call for refreshing the model of this element
def RefreshModel(self, move=True):
pass
@@ -833,7 +855,7 @@
self.Pos = position
self.Direction = direction
self.Wires = []
- if IsOfType("BOOL", type):
+ if self.ParentBlock.IsOfType("BOOL", type):
self.Negated = negated
self.Edge = edge
else:
@@ -841,6 +863,7 @@
self.Edge = "none"
self.OneConnected = onlyone
self.Pen = wx.BLACK_PEN
+ self.Errors = {}
self.RefreshNameSize()
# Returns the RedrawRect
@@ -875,16 +898,16 @@
# Returns the connector type
def GetType(self, raw = False):
- if IsEndType(self.Type) or raw:
+ if self.ParentBlock.IsEndType(self.Type) or raw:
return self.Type
- elif (self.Negated or self.Edge != "none") and IsOfType("BOOL", self.Type):
+ elif (self.Negated or self.Edge != "none") and self.ParentBlock.IsOfType("BOOL", self.Type):
return "BOOL"
else:
return self.ParentBlock.GetConnectionResultType(self, self.Type)
# Returns the connector type
def GetConnectedType(self):
- if IsEndType(self.Type):
+ if self.ParentBlock.IsEndType(self.Type):
return self.Type
elif len(self.Wires) == 1:
return self.Wires[0][0].GetOtherConnectedType(self.Wires[0][1])
@@ -903,7 +926,7 @@
# Returns if connector type is compatible with type given
def IsCompatible(self, type):
reference = self.GetType()
- return IsOfType(type, reference) or IsOfType(reference, type)
+ return self.ParentBlock.IsOfType(type, reference) or self.ParentBlock.IsOfType(reference, type)
# Changes the connector name
def SetType(self, type):
@@ -1065,7 +1088,7 @@
# Changes the connector negated property
def SetNegated(self, negated):
- if IsOfType("BOOL", self.Type):
+ if self.ParentBlock.IsOfType("BOOL", self.Type):
self.Negated = negated
self.Edge = "none"
@@ -1075,7 +1098,7 @@
# Changes the connector edge property
def SetEdge(self, edge):
- if IsOfType("BOOL", self.Type):
+ if self.ParentBlock.IsOfType("BOOL", self.Type):
self.Edge = edge
self.Negated = False
@@ -1115,10 +1138,21 @@
dc.DrawRectangle(posx, posy, width, height)
dc.SetLogicalFunction(wx.COPY)
+ def AddError(self, infos, start, end):
+ if len(infos) == 0:
+ for wire, handle in self.Wires:
+ wire.MarkAsInvalid()
+ else:
+ self.Errors[infos[0]] = (start, end)
+
# Draws the connector
def Draw(self, dc):
- dc.SetPen(self.Pen)
- dc.SetBrush(wx.WHITE_BRUSH)
+ if len(self.Errors) > 0:
+ dc.SetPen(wx.RED_PEN)
+ dc.SetBrush(wx.Brush(wx.Colour(255, 255, 0)))
+ else:
+ dc.SetPen(self.Pen)
+ dc.SetBrush(wx.WHITE_BRUSH)
parent_pos = self.ParentBlock.GetPosition()
if getattr(dc, "printing", False):
@@ -1145,6 +1179,9 @@
xend = xstart + CONNECTOR_SIZE * self.Direction[0]
yend = ystart + CONNECTOR_SIZE * self.Direction[1]
dc.DrawLine(xstart + self.Direction[0], ystart + self.Direction[1], xend, yend)
+ if len(self.Errors) > 0:
+ dc.SetPen(self.Pen)
+ dc.SetBrush(wx.WHITE_BRUSH)
if self.Direction[0] != 0:
ytext = parent_pos[1] + self.Pos.y - name_size[1] / 2
if self.Direction[0] < 0: