graphics/LD_Objects.py
changeset 4007 76dede1e3403
parent 3975 2ef76b61bf1e
equal deleted inserted replaced
4006:e16c8443e877 4007:76dede1e3403
   591         dc.SetUserScale(1, 1)
   591         dc.SetUserScale(1, 1)
   592         dc.SetPen(MiterPen(HIGHLIGHTCOLOR))
   592         dc.SetPen(MiterPen(HIGHLIGHTCOLOR))
   593         dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
   593         dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
   594         dc.SetLogicalFunction(wx.AND)
   594         dc.SetLogicalFunction(wx.AND)
   595         # Draw two rectangles for representing the contact
   595         # Draw two rectangles for representing the contact
   596         left_left = (self.Pos.x - 1) * scalex - 2
   596         left_left = round((self.Pos.x - 1) * scalex) - 2
   597         right_left = (self.Pos.x + self.Size[0] - 2) * scalex - 2
   597         right_left = round((self.Pos.x + self.Size[0] - 2) * scalex) - 2
   598         top = (self.Pos.y - 1) * scaley - 2
   598         top = round((self.Pos.y - 1) * scaley) - 2
   599         width = 4 * scalex + 5
   599         width = round(4 * scalex + 5)
   600         height = (self.Size[1] + 3) * scaley + 5
   600         height = round((self.Size[1] + 3) * scaley) + 5
   601 
   601 
   602         dc.DrawRectangle(left_left, top, width, height)
   602         dc.DrawRectangle(left_left, top, width, height)
   603         dc.DrawRectangle(right_left, top, width, height)
   603         dc.DrawRectangle(right_left, top, width, height)
   604         dc.SetLogicalFunction(wx.COPY)
   604         dc.SetLogicalFunction(wx.COPY)
   605         dc.SetUserScale(scalex, scaley)
   605         dc.SetUserScale(scalex, scaley)
   972         elif self.Type == COIL_RISING:
   972         elif self.Type == COIL_RISING:
   973             typetext = "P"
   973             typetext = "P"
   974         elif self.Type == COIL_FALLING:
   974         elif self.Type == COIL_FALLING:
   975             typetext = "N"
   975             typetext = "N"
   976 
   976 
   977         if getattr(dc, "printing", False) and not isinstance(dc, wx.PostScriptDC):
   977         printing = getattr(dc, "printing", False)
   978             # Draw an clipped ellipse for representing the coil
   978         # Draw a two ellipse arcs for representing the coil
   979             clipping_box = dc.GetClippingBox()
   979         pos = (self.Pos.x,  
   980             dc.SetClippingRegion(self.Pos.x - 1, self.Pos.y, self.Size[0] + 2, self.Size[1] + 1)
   980                self.Pos.y - round(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1, 
   981             dc.DrawEllipse(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)
   981                self.Size[0], round(self.Size[1] * sqrt(2)) - 1)
   982             dc.DestroyClippingRegion()
   982         
   983             if clipping_box != (0, 0, 0, 0):
   983         if printing:
   984                 dc.SetClippingRegion(*clipping_box)
   984             # workaround for printing bug with DrawEllipticArc
   985             name_size = dc.GetTextExtent(self.Name)
   985             # add an offset to the y position proportional to the height of the ellipse
   986             if typetext != "":
   986             # sqrt(2) ratio obtained heuristically
   987                 type_size = dc.GetTextExtent(typetext)
   987             pos = (pos[0], pos[1] + round(sqrt(2)*pos[3]), pos[2], pos[3])
   988         else:
   988             
   989             # Draw a two ellipse arcs for representing the coil
   989         dc.DrawEllipticArc(*pos, 135, 225)
   990             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)
   990         dc.DrawEllipticArc(*pos, -45, 45)
   991             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)
   991         
   992             # Draw a point to avoid hole in left arc
   992         name_size = self.NameSize
   993             if not getattr(dc, "printing", False):
   993         if typetext != "":
   994                 if self.Value is not None and self.Value:
   994             type_size = self.TypeSize
   995                     dc.SetPen(MiterPen(wx.GREEN))
       
   996                 else:
       
   997                     dc.SetPen(MiterPen(wx.BLACK))
       
   998                 dc.DrawPoint(self.Pos.x + 1, self.Pos.y + self.Size[1] // 2 + 1)
       
   999             name_size = self.NameSize
       
  1000             if typetext != "":
       
  1001                 type_size = self.TypeSize
       
  1002 
   995 
  1003         # Draw coil name
   996         # Draw coil name
  1004         name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) // 2,
   997         name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) // 2,
  1005                     self.Pos.y - (name_size[1] + 2))
   998                     self.Pos.y - (name_size[1] + 2))
  1006         dc.DrawText(self.Name, name_pos[0], name_pos[1])
   999         dc.DrawText(self.Name, name_pos[0], name_pos[1])