graphics/LD_Objects.py
changeset 144 b67a5de5a24a
parent 140 06d28f03f6f4
child 145 4fb225afddf4
--- a/graphics/LD_Objects.py	Fri Jan 04 17:47:58 2008 +0100
+++ b/graphics/LD_Objects.py	Fri Jan 04 17:49:17 2008 +0100
@@ -67,6 +67,18 @@
                 powerrail.Connectors.append(None)
         return powerrail
     
+    # Returns the RedrawRect
+    def GetRedrawRect(self, movex = 0, movey = 0):
+        rect = Graphic_Element.GetRedrawRect(self, movex, movey)
+        for connector in self.Connectors:
+            if connector is not None:
+                rect = rect.Union(connector.GetRedrawRect(movex, movey))
+        if movex != 0 or movey != 0:
+            for connector in self.Connectors:
+                if connector is not None and connector.IsConnected():
+                    rect = rect.Union(connector.GetConnectedRedrawRect(movex, movey))
+        return rect
+    
     # Forbids to change the power rail size
     def SetSize(self, width, height):
         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
@@ -98,19 +110,19 @@
     # Refresh the power rail bounding box
     def RefreshBoundingBox(self):
         dc = wx.ClientDC(self.Parent)
-        self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0], self.Size[1] + 1)
+        self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
     
     # Refresh the power rail size
     def RefreshSize(self):
-        self.Size = wx.Size(2, LD_LINE_SIZE * len(self.Connectors))
+        self.Size = wx.Size(LD_POWERRAIL_WIDTH, LD_LINE_SIZE * len(self.Connectors))
         self.RefreshBoundingBox()
     
     # Returns the block minimum size
     def GetMinSize(self):
         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
-            return 2, self.Extensions[0] + self.Extensions[1]
-        else:
-            return 2, LD_LINE_SIZE * len(self.Connectors)
+            return LD_POWERRAIL_WIDTH, self.Extensions[0] + self.Extensions[1]
+        else:
+            return LD_POWERRAIL_WIDTH, LD_LINE_SIZE * len(self.Connectors)
     
     # Add a connector or a blank to this power rail at the last place
     def AddConnector(self, connector = True):
@@ -313,6 +325,7 @@
     
     # Draws power rail
     def Draw(self, dc):
+        Graphic_Element.Draw(self, dc)
         dc.SetPen(wx.BLACK_PEN)
         dc.SetBrush(wx.BLACK_BRUSH)
         # Draw a rectangle with the power rail size
@@ -321,7 +334,6 @@
         for connector in self.Connectors:
             if connector:
                 connector.Draw(dc)
-        Graphic_Element.Draw(self, dc)
         
 
 #-------------------------------------------------------------------------------
@@ -362,6 +374,18 @@
         contact.Output = self.Output.Clone(contact)
         return contact
     
+    # Returns the RedrawRect
+    def GetRedrawRect(self, movex = 0, movey = 0):
+        rect = Graphic_Element.GetRedrawRect(self, movex, movey)
+        rect = rect.Union(self.Input.GetRedrawRect(movex, movey))
+        rect = rect.Union(self.Output.GetRedrawRect(movex, movey))
+        if movex != 0 or movey != 0:
+            if self.Input.IsConnected():
+                rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey))
+            if self.Output.IsConnected():
+                rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey))
+        return rect
+    
     # Forbids to change the contact size
     def SetSize(self, width, height):
         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
@@ -503,15 +527,17 @@
     
     # Draws the highlightment of this element if it is highlighted
     def DrawHighlightment(self, dc):
-        if self.Highlighted:
-            dc.SetPen(wx.Pen(HIGHLIGHTCOLOR))
-            dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
-            # Draw two rectangles for representing the contact
-            dc.DrawRectangle(self.Pos.x - 2, self.Pos.y - 2, 6, self.Size[1] + 5)
-            dc.DrawRectangle(self.Pos.x + self.Size[0] - 3, self.Pos.y - 2, 6, self.Size[1] + 5)
+        dc.SetPen(wx.Pen(HIGHLIGHTCOLOR))
+        dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
+        dc.SetLogicalFunction(wx.AND)
+        # Draw two rectangles for representing the contact
+        dc.DrawRectangle(self.Pos.x - 2, self.Pos.y - 2, 6, self.Size[1] + 5)
+        dc.DrawRectangle(self.Pos.x + self.Size[0] - 3, self.Pos.y - 2, 6, self.Size[1] + 5)
+        dc.SetLogicalFunction(wx.COPY)
     
     # Draws contact
     def Draw(self, dc):
+        Graphic_Element.Draw(self, dc)
         dc.SetPen(wx.BLACK_PEN)
         dc.SetBrush(wx.BLACK_BRUSH)
         # Draw two rectangles for representing the contact
@@ -534,7 +560,6 @@
         # Draw input and output connectors
         self.Input.Draw(dc)
         self.Output.Draw(dc)
-        Graphic_Element.Draw(self, dc)
         
 
 #-------------------------------------------------------------------------------
@@ -575,6 +600,18 @@
         coil.Output = self.Output.Clone(coil)
         return coil
     
+    # Returns the RedrawRect
+    def GetRedrawRect(self, movex = 0, movey = 0):
+        rect = Graphic_Element.GetRedrawRect(self, movex, movey)
+        rect = rect.Union(self.Input.GetRedrawRect(movex, movey))
+        rect = rect.Union(self.Output.GetRedrawRect(movex, movey))
+        if movex != 0 or movey != 0:
+            if self.Input.IsConnected():
+                rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey))
+            if self.Output.IsConnected():
+                rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey))
+        return rect
+    
     # Forbids to change the contact size
     def SetSize(self, width, height):
         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
@@ -716,15 +753,17 @@
     
     # Draws the highlightment of this element if it is highlighted
     def DrawHighlightment(self, dc):
-        if self.Highlighted:
-            dc.SetPen(wx.Pen(HIGHLIGHTCOLOR, 6, wx.SOLID))
-            dc.SetBrush(wx.TRANSPARENT_BRUSH)
-            # Draw a two circle arcs for representing the coil
-            dc.DrawEllipticArc(self.Pos.x, self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1, self.Size[0], int(self.Size[1] * sqrt(2)) - 1, 135, 225)
-            dc.DrawEllipticArc(self.Pos.x, self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1, self.Size[0], int(self.Size[1] * sqrt(2)) - 1, -45, 45)
+        dc.SetPen(wx.Pen(HIGHLIGHTCOLOR, 6, wx.SOLID))
+        dc.SetBrush(wx.TRANSPARENT_BRUSH)
+        dc.SetLogicalFunction(wx.AND)
+        # Draw a two circle arcs for representing the coil
+        dc.DrawEllipticArc(self.Pos.x, self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1, self.Size[0], int(self.Size[1] * sqrt(2)) - 1, 135, 225)
+        dc.DrawEllipticArc(self.Pos.x, self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1, self.Size[0], int(self.Size[1] * sqrt(2)) - 1, -45, 45)
+        dc.SetLogicalFunction(wx.COPY)
     
     # Draws coil
     def Draw(self, dc):
+        Graphic_Element.Draw(self, dc)
         dc.SetPen(wx.Pen(wx.BLACK, 2, wx.SOLID))
         dc.SetBrush(wx.TRANSPARENT_BRUSH)
         # Draw a two circle arcs for representing the coil
@@ -749,5 +788,4 @@
         # Draw input and output connectors
         self.Input.Draw(dc)
         self.Output.Draw(dc)
-        Graphic_Element.Draw(self, dc)