graphics/GraphicCommons.py
changeset 414 8d9e7edc0195
parent 399 3b9e0b092298
child 407 0a324a874981
--- a/graphics/GraphicCommons.py	Thu Aug 20 09:03:31 2009 -0600
+++ b/graphics/GraphicCommons.py	Wed Sep 02 08:30:34 2009 -0600
@@ -812,24 +812,25 @@
     
     # Draws the handles of this element if it is selected
     def Draw(self, dc):
-        if self.Highlighted:
-            self.DrawHighlightment(dc)
-        if self.Selected:
-            dc.SetPen(wx.BLACK_PEN)
-            dc.SetBrush(wx.BLACK_BRUSH)
-            dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE)
-            dc.DrawRectangle(self.BoundingBox.x + (self.BoundingBox.width - HANDLE_SIZE) / 2,
-                self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE)
-            dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, 
-                self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE)
-            dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, 
-                self.BoundingBox.y + (self.BoundingBox.height - HANDLE_SIZE) / 2, HANDLE_SIZE, HANDLE_SIZE)
-            dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, 
-                self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE)
-            dc.DrawRectangle(self.BoundingBox.x + (self.BoundingBox.width - HANDLE_SIZE) / 2, 
-                self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE)
-            dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE)
-            dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y + (self.BoundingBox.height - HANDLE_SIZE) / 2, HANDLE_SIZE, HANDLE_SIZE)
+        if not getattr(dc, "printing", False):
+            if self.Highlighted:
+                self.DrawHighlightment(dc)
+            if self.Selected:
+                dc.SetPen(wx.BLACK_PEN)
+                dc.SetBrush(wx.BLACK_BRUSH)
+                dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE)
+                dc.DrawRectangle(self.BoundingBox.x + (self.BoundingBox.width - HANDLE_SIZE) / 2,
+                    self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE)
+                dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, 
+                    self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE)
+                dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, 
+                    self.BoundingBox.y + (self.BoundingBox.height - HANDLE_SIZE) / 2, HANDLE_SIZE, HANDLE_SIZE)
+                dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, 
+                    self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE)
+                dc.DrawRectangle(self.BoundingBox.x + (self.BoundingBox.width - HANDLE_SIZE) / 2, 
+                    self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE)
+                dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE)
+                dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y + (self.BoundingBox.height - HANDLE_SIZE) / 2, HANDLE_SIZE, HANDLE_SIZE)
 
 
 #-------------------------------------------------------------------------------
@@ -1930,15 +1931,21 @@
             self.Segments = []
             i = 0
             while i < len(self.Points) - 1:
-                segment = vector(self.Points[i], self.Points[i + 1])
-                if is_null_vector(segment) and i > 0:
-                    segment = (self.Segments[-1][1], self.Segments[-1][0])
-                if i < len(self.Points) - 2:
-                    next = vector(self.Points[i + 1], self.Points[i + 2])
-                    if next == segment or is_null_vector(add_vectors(segment, next)):
-                        self.Points.insert(i + 1, wx.Point(self.Points[i + 1].x, self.Points[i + 1].y))
-                self.Segments.append(segment)
-                i += 1
+                if 0 < i < len(self.Points) - 2 and \
+                   self.Points[i] == self.Points[i + 1] and \
+                   self.Segments[-1] == vector(self.Points[i + 1], self.Points[i + 2]):
+                    for j in xrange(2):
+                        self.Points.pop(i)
+                else:
+                    segment = vector(self.Points[i], self.Points[i + 1])
+                    if is_null_vector(segment) and i > 0:
+                        segment = (self.Segments[-1][1], self.Segments[-1][0])
+                    if i < len(self.Points) - 2:
+                        next = vector(self.Points[i + 1], self.Points[i + 2])
+                        if next == segment or is_null_vector(add_vectors(segment, next)):
+                            self.Points.insert(i + 1, wx.Point(self.Points[i + 1].x, self.Points[i + 1].y))
+                    self.Segments.append(segment)
+                    i += 1
             self.RefreshBoundingBox()
             self.RefreshRealPoints()
     
@@ -2604,7 +2611,7 @@
         dc.DrawLines(self.Points)
         dc.DrawPoint(self.Points[-1].x, self.Points[-1].y)
         # Draw the segment selected in red
-        if self.SelectedSegment is not None:
+        if not getattr(dc, "printing", False) and self.SelectedSegment is not None:
             dc.SetPen(wx.RED_PEN)
             dc.DrawLine(self.Points[self.SelectedSegment].x, self.Points[self.SelectedSegment].y,
                         self.Points[self.SelectedSegment + 1].x, self.Points[self.SelectedSegment + 1].y)