Exemple #1
0
 def build(self,
           board: pcbnew.BOARD,
           external_signals: dict[str, pcbnew.NETINFO_ITEM] = {},
           path: list[str] = []):
     o = pcbnew.PCB_TEXT(board)
     o.SetText(self.text)
     o.SetHorizJustify(pcbnew.GR_TEXT_HJUSTIFY_CENTER)
     o.SetTextSize(
         pcbnew.wxSize(pcbnew.FromMM(self.size), pcbnew.FromMM(self.size)))
     o.SetTextThickness(pcbnew.FromMM(self.size * self.thickness * 0.15))
     o.SetLayer(self.layer)
     set_pcb_position(o, self.pcbpos)
     board.Add(o)
Exemple #2
0
    def _renderVCutH(self, layer=Layer.Cmts_User):
        """ return list of PCB_SHAPE V-Cuts """
        bBox = self.boardSubstrate.boundingBox()
        minX, maxX = bBox.GetX() - fromMm(
            3), bBox.GetX() + bBox.GetWidth() + fromMm(3)
        segments = []
        for cut in self.hVCuts:
            segment = pcbnew.PCB_SHAPE()
            self._setVCutSegmentStyle(segment, layer)
            segment.SetStart(pcbnew.wxPoint(minX, cut))
            segment.SetEnd(pcbnew.wxPoint(maxX, cut))
            segments.append(segment)

            label = pcbnew.PCB_TEXT(segment)
            self._setVCutLabelStyle(label, layer)
            label.SetPosition(wxPoint(maxX + fromMm(3), cut))
            segments.append(label)
        return segments
Exemple #3
0
    def _renderVCutV(self, layer=Layer.Cmts_User):
        """ return list of PCB_SHAPE V-Cuts """
        bBox = self.boardSubstrate.boundingBox()
        minY, maxY = bBox.GetY() - fromMm(
            3), bBox.GetY() + bBox.GetHeight() + fromMm(3)
        segments = []
        for cut in self.vVCuts:
            segment = pcbnew.PCB_SHAPE()
            self._setVCutSegmentStyle(segment, layer)
            segment.SetStart(pcbnew.wxPoint(cut, minY))
            segment.SetEnd(pcbnew.wxPoint(cut, maxY))
            segments.append(segment)

            label = pcbnew.PCB_TEXT(segment)
            self._setVCutLabelStyle(label, layer)
            label.SetPosition(wxPoint(cut, minY - fromMm(3)))
            label.SetTextAngle(900)
            segments.append(label)
        return segments
    def Run(self):
        pcb = pcbnew.GetBoard()

        min_x = None
        min_y = None
        max_x = None
        max_y = None

        # Small board outline
        pcbdrawings = pcb.GetDrawings()
        design_settings = pcb.GetDesignSettings()
        i = 0
        for f in pcbdrawings:
            if (f.GetLayerName() == "Edge.Cuts"):
                f.SetWidth(pcbnew.FromMM(0.01))
                if (i == 0):
                    min_x = f.GetStart().x
                    min_y = f.GetStart().y
                    max_x = f.GetStart().x
                    max_y = f.GetStart().y

                if (f.GetShape() == 3):
                    rad = ((f.GetStart()[0] - f.GetEnd()[0])**2 +
                           (f.GetStart()[1] - f.GetEnd()[1])**2)**0.5
                    min_x = min(f.GetStart().x - rad, min_x)
                    min_y = min(f.GetStart().y - rad, min_y)
                    max_x = max(f.GetStart().x + rad, max_x)
                    max_y = max(f.GetStart().y + rad, max_y)

                else:
                    if (f.GetShape() == 2):
                        rad = ((f.GetStart()[0] - f.GetEnd()[0])**2 +
                               (f.GetStart()[1] - f.GetEnd()[1])**2)**0.5
                        ang = int(f.GetAngle())
                        ang_start = int(f.GetArcAngleStart())

                        if (ang < 0):
                            ang_range = range(ang_start, ang_start + ang - 1,
                                              -1)
                        else:
                            ang_range = range(ang_start, ang_start + ang + 1,
                                              1)

                        for ll in ang_range:
                            px = f.GetStart()[0] + rad * math.cos(
                                math.radians(ll / 10))
                            py = f.GetStart()[1] + rad * math.sin(
                                math.radians(ll / 10))
                            min_x = min(px, min_x)
                            min_y = min(py, min_y)
                            max_x = max(px, max_x)
                            max_y = max(py, max_y)

                    else:
                        min_x = min(f.GetStart().x, min_x)
                        min_y = min(f.GetStart().y, min_y)
                        max_x = max(f.GetStart().x, max_x)
                        max_y = max(f.GetStart().y, max_y)
                        min_x = min(f.GetEnd().x, min_x)
                        min_y = min(f.GetEnd().y, min_y)
                        max_x = max(f.GetEnd().x, max_x)
                        max_y = max(f.GetEnd().y, max_y)

                i += 1

        if (i > 0):
            dim_x = math.ceil(pcbnew.ToMM(max_x - min_x))
            dim_y = math.ceil(pcbnew.ToMM(max_y - min_y))

            addnew = True
            tt = pcbnew.PCB_TEXT(pcb)

            for drawing in pcb.GetDrawings():
                if isinstance(drawing, pcbnew.PCB_TEXT):
                    if (drawing.GetText().split(':',
                                                1)[0] == "Board dimensions"
                            and drawing.GetLayer() == pcbnew.Cmts_User
                            and drawing.GetPosition()[0] == 178300000
                            and drawing.GetPosition()[1] == 174000000):
                        tt = drawing
                        addnew = False

            tt.SetText("Board dimensions: %dmm x %dmm" % (dim_x, dim_y))
            tt.SetHorizJustify(-1)
            tt.SetTextThickness(pcbnew.FromMM(0.2))
            tt.SetPosition(pcbnew.wxPointMM(178.3, 174))
            tt.SetLayer(pcbnew.Cmts_User)

            if (addnew):
                pcb.Add(tt)

            design_settings.m_AuxOrigin = (pcbnew.wxPoint(min_x, min_y))
            design_settings.m_GridOrigin = (pcbnew.wxPoint(min_x, min_y))