graphics/GraphicCommons.py
changeset 414 8d9e7edc0195
parent 399 3b9e0b092298
child 407 0a324a874981
equal deleted inserted replaced
413:127d524a5f1d 414:8d9e7edc0195
   810         dc.DrawRectangle(self.Pos.x - 2, self.Pos.y - 2, self.Size.width + 5, self.Size.height + 5)
   810         dc.DrawRectangle(self.Pos.x - 2, self.Pos.y - 2, self.Size.width + 5, self.Size.height + 5)
   811         dc.SetLogicalFunction(wx.COPY)
   811         dc.SetLogicalFunction(wx.COPY)
   812     
   812     
   813     # Draws the handles of this element if it is selected
   813     # Draws the handles of this element if it is selected
   814     def Draw(self, dc):
   814     def Draw(self, dc):
   815         if self.Highlighted:
   815         if not getattr(dc, "printing", False):
   816             self.DrawHighlightment(dc)
   816             if self.Highlighted:
   817         if self.Selected:
   817                 self.DrawHighlightment(dc)
   818             dc.SetPen(wx.BLACK_PEN)
   818             if self.Selected:
   819             dc.SetBrush(wx.BLACK_BRUSH)
   819                 dc.SetPen(wx.BLACK_PEN)
   820             dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE)
   820                 dc.SetBrush(wx.BLACK_BRUSH)
   821             dc.DrawRectangle(self.BoundingBox.x + (self.BoundingBox.width - HANDLE_SIZE) / 2,
   821                 dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE)
   822                 self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE)
   822                 dc.DrawRectangle(self.BoundingBox.x + (self.BoundingBox.width - HANDLE_SIZE) / 2,
   823             dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, 
   823                     self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE)
   824                 self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE)
   824                 dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, 
   825             dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, 
   825                     self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE)
   826                 self.BoundingBox.y + (self.BoundingBox.height - HANDLE_SIZE) / 2, HANDLE_SIZE, HANDLE_SIZE)
   826                 dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, 
   827             dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, 
   827                     self.BoundingBox.y + (self.BoundingBox.height - HANDLE_SIZE) / 2, HANDLE_SIZE, HANDLE_SIZE)
   828                 self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE)
   828                 dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, 
   829             dc.DrawRectangle(self.BoundingBox.x + (self.BoundingBox.width - HANDLE_SIZE) / 2, 
   829                     self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE)
   830                 self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE)
   830                 dc.DrawRectangle(self.BoundingBox.x + (self.BoundingBox.width - HANDLE_SIZE) / 2, 
   831             dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE)
   831                     self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE)
   832             dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y + (self.BoundingBox.height - HANDLE_SIZE) / 2, HANDLE_SIZE, HANDLE_SIZE)
   832                 dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE)
       
   833                 dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y + (self.BoundingBox.height - HANDLE_SIZE) / 2, HANDLE_SIZE, HANDLE_SIZE)
   833 
   834 
   834 
   835 
   835 #-------------------------------------------------------------------------------
   836 #-------------------------------------------------------------------------------
   836 #                           Group of graphic elements
   837 #                           Group of graphic elements
   837 #-------------------------------------------------------------------------------
   838 #-------------------------------------------------------------------------------
  1928             self.Points[-1] = self.EndPoint[0]
  1929             self.Points[-1] = self.EndPoint[0]
  1929             # Calculate the segments directions
  1930             # Calculate the segments directions
  1930             self.Segments = []
  1931             self.Segments = []
  1931             i = 0
  1932             i = 0
  1932             while i < len(self.Points) - 1:
  1933             while i < len(self.Points) - 1:
  1933                 segment = vector(self.Points[i], self.Points[i + 1])
  1934                 if 0 < i < len(self.Points) - 2 and \
  1934                 if is_null_vector(segment) and i > 0:
  1935                    self.Points[i] == self.Points[i + 1] and \
  1935                     segment = (self.Segments[-1][1], self.Segments[-1][0])
  1936                    self.Segments[-1] == vector(self.Points[i + 1], self.Points[i + 2]):
  1936                 if i < len(self.Points) - 2:
  1937                     for j in xrange(2):
  1937                     next = vector(self.Points[i + 1], self.Points[i + 2])
  1938                         self.Points.pop(i)
  1938                     if next == segment or is_null_vector(add_vectors(segment, next)):
  1939                 else:
  1939                         self.Points.insert(i + 1, wx.Point(self.Points[i + 1].x, self.Points[i + 1].y))
  1940                     segment = vector(self.Points[i], self.Points[i + 1])
  1940                 self.Segments.append(segment)
  1941                     if is_null_vector(segment) and i > 0:
  1941                 i += 1
  1942                         segment = (self.Segments[-1][1], self.Segments[-1][0])
       
  1943                     if i < len(self.Points) - 2:
       
  1944                         next = vector(self.Points[i + 1], self.Points[i + 2])
       
  1945                         if next == segment or is_null_vector(add_vectors(segment, next)):
       
  1946                             self.Points.insert(i + 1, wx.Point(self.Points[i + 1].x, self.Points[i + 1].y))
       
  1947                     self.Segments.append(segment)
       
  1948                     i += 1
  1942             self.RefreshBoundingBox()
  1949             self.RefreshBoundingBox()
  1943             self.RefreshRealPoints()
  1950             self.RefreshRealPoints()
  1944     
  1951     
  1945     # Returns the position of the point indicated
  1952     # Returns the position of the point indicated
  1946     def GetPoint(self, index):
  1953     def GetPoint(self, index):
  2602             dc.DrawCircle(self.Points[-1].x, self.Points[-1].y, POINT_RADIUS)
  2609             dc.DrawCircle(self.Points[-1].x, self.Points[-1].y, POINT_RADIUS)
  2603         # Draw the wire lines and the last point (it seems that DrawLines stop before the last point)
  2610         # Draw the wire lines and the last point (it seems that DrawLines stop before the last point)
  2604         dc.DrawLines(self.Points)
  2611         dc.DrawLines(self.Points)
  2605         dc.DrawPoint(self.Points[-1].x, self.Points[-1].y)
  2612         dc.DrawPoint(self.Points[-1].x, self.Points[-1].y)
  2606         # Draw the segment selected in red
  2613         # Draw the segment selected in red
  2607         if self.SelectedSegment is not None:
  2614         if not getattr(dc, "printing", False) and self.SelectedSegment is not None:
  2608             dc.SetPen(wx.RED_PEN)
  2615             dc.SetPen(wx.RED_PEN)
  2609             dc.DrawLine(self.Points[self.SelectedSegment].x, self.Points[self.SelectedSegment].y,
  2616             dc.DrawLine(self.Points[self.SelectedSegment].x, self.Points[self.SelectedSegment].y,
  2610                         self.Points[self.SelectedSegment + 1].x, self.Points[self.SelectedSegment + 1].y)
  2617                         self.Points[self.SelectedSegment + 1].x, self.Points[self.SelectedSegment + 1].y)
  2611             if self.SelectedSegment == len(self.Segments) - 1:
  2618             if self.SelectedSegment == len(self.Segments) - 1:
  2612                 dc.DrawPoint(self.Points[-1].x, self.Points[-1].y)
  2619                 dc.DrawPoint(self.Points[-1].x, self.Points[-1].y)