Esempio n. 1
0
    def BuildFootprint(self):
        """
        Actually make the footprint. We defer all but the setup to
        the implmenting class
        """

        self.module = pcbnew.MODULE(None)  # create a new module
        # do it first, so if we return early, we don't segfault KiCad

        if not self.ProcessParameters():
            return

        self.draw = FootprintWizardDrawingAids.FootprintWizardDrawingAids(
            self.module)

        self.module.SetValue(self.GetValue())
        self.module.SetReference("%s**" % self.GetReferencePrefix())

        fpid = pcbnew.FPID(self.module.GetValue())  # the name in library
        self.module.SetFPID(fpid)

        self.SetModule3DModel()  # add a 3d module if specified

        thick = self.GetTextThickness()

        self.module.Reference().SetThickness(thick)
        self.module.Value().SetThickness(thick)

        self.BuildThisFootprint()  # implementer's build function
Esempio n. 2
0
    def compat_libitem_func(instance):
        try:
            test_obj = pcbnew.FPID()
        except AttributeError:
            test_obj = pcbnew.LIB_ID()

        if not hasattr(test_obj, "GetLibItemName"):
            return MethodType(lambda self, x: x.GetFootprintName(), instance)
        else:
            return MethodType(lambda self, x: x.GetLibItemName(), instance)
Esempio n. 3
0
    def save(self, library_path):
        """Save footprint in given library

        library_path should end with .pretty
        """
        self._module.SetFPID(pcbnew.FPID(self._module.GetReference()))

        io = pcbnew.PCB_IO()

        try:
            io.FootprintLibCreate(library_path)
        except IOError:
            pass  # we try to create, but may be it exists already

        io.FootprintSave(library_path, self._module)
Esempio n. 4
0
    def BuildFootprint(self):
        if self.has_errors():
            print "Cannot build footprint: Parameters have errors:"
            print self.parameter_errors
            return

        print "Building new QFP footprint with the following parameters:"
        self.print_parameter_table()

        self.module = pcbnew.MODULE(None)  # create a new module

        pads = self.parameters
        num_pads = int(pads["Pads"]["*n"])
        pad_width = pads["Pads"]["width"]
        pad_length = pads["Pads"]["length"]
        pad_pitch = pads["Pads"]["pitch"]
        pad_horizontal_pitch = pads["Pads"]["horizontal pitch"]
        pad_vertical_pitch = pads["Pads"]["vertical pitch"]

        package_width = pads["Package"]["width"]
        package_height = pads["Package"]["height"]

        side_length = pad_pitch * ((num_pads / 4) - 1)

        offsetX = pad_pitch * ((num_pads / 4) - 1) / 2
        text_size = pcbnew.wxSize(pcbnew.FromMM(0.8), pcbnew.FromMM(0.8))

        self.module.SetReference("QFP %d" % int(num_pads))
        self.module.Reference().SetPos0(pcbnew.wxPoint(0, pcbnew.FromMM(-0.8)))
        self.module.Reference().SetTextPosition(
            self.module.Reference().GetPos0())
        self.module.Reference().SetSize(text_size)

        self.module.SetValue("U**")
        self.module.Value().SetPos0(pcbnew.wxPoint(0, pcbnew.FromMM(+0.8)))
        self.module.Value().SetTextPosition(self.module.Value().GetPos0())
        self.module.Value().SetSize(text_size)

        fpid = pcbnew.FPID(self.module.GetReference())  #the name in library
        self.module.SetFPID(fpid)

        pad_size_left_right = pcbnew.wxSize(pad_length, pad_width)
        pad_size_bottom_top = pcbnew.wxSize(pad_width, pad_length)

        for cur_pad in range(0, num_pads):
            side = int(
                cur_pad /
                (num_pads / 4))  # 0 -> left, 1 -> bottom, 2 -> right, 3 -> top

            if side == 0 or side == 2:
                pad_size = pad_size_left_right

                pad_pos_x = -(pad_horizontal_pitch / 2)
                pad_pos_y = (cur_pad %
                             (num_pads / 4)) * pad_pitch - (side_length / 2)

                if side == 2:
                    pad_pos_x = -pad_pos_x
                    pad_pos_y = -pad_pos_y

            else:
                pad_size = pad_size_bottom_top

                pad_pos_x = (cur_pad %
                             (num_pads / 4)) * pad_pitch - (side_length / 2)
                pad_pos_y = -(pad_vertical_pitch / 2)

                if side == 1:
                    pad_pos_y = -pad_pos_y
                else:
                    pad_pos_x = -pad_pos_x

            pad_pos = pcbnew.wxPoint(pad_pos_x, pad_pos_y)

            pad = self.smd_rect_pad(self.module, pad_size, pad_pos,
                                    str(cur_pad + 1))

            self.module.Add(pad)

        half_package_width = package_width / 2
        half_package_height = package_height / 2

        package_pad_height_offset = abs(package_height -
                                        side_length) / 2 - pad_pitch
        package_pad_width_offset = abs(package_width -
                                       side_length) / 2 - pad_pitch

        # Bottom Left Edge, vertical line
        outline = pcbnew.EDGE_MODULE(self.module)
        outline.SetWidth(pcbnew.FromMM(0.2))
        outline.SetLayer(pcbnew.SILKSCREEN_N_FRONT)
        outline.SetShape(pcbnew.S_SEGMENT)
        start = pcbnew.wxPoint(-half_package_width,
                               half_package_height - package_pad_height_offset)
        end = pcbnew.wxPoint(-half_package_width, half_package_height)
        outline.SetStartEnd(start, end)
        self.module.Add(outline)

        # Bottom Left Edge, horizontal line
        outline = pcbnew.EDGE_MODULE(self.module)
        outline.SetWidth(pcbnew.FromMM(0.2))
        outline.SetLayer(pcbnew.SILKSCREEN_N_FRONT)
        outline.SetShape(pcbnew.S_SEGMENT)
        start = pcbnew.wxPoint(-half_package_width, half_package_height)
        end = pcbnew.wxPoint(-half_package_width + package_pad_width_offset,
                             half_package_height)
        outline.SetStartEnd(start, end)
        self.module.Add(outline)

        # Bottom Right Edge, vertical line
        outline = pcbnew.EDGE_MODULE(self.module)
        outline.SetWidth(pcbnew.FromMM(0.2))
        outline.SetLayer(pcbnew.SILKSCREEN_N_FRONT)
        outline.SetShape(pcbnew.S_SEGMENT)
        start = pcbnew.wxPoint(half_package_width,
                               half_package_height - package_pad_height_offset)
        end = pcbnew.wxPoint(half_package_width, half_package_height)
        outline.SetStartEnd(start, end)
        self.module.Add(outline)

        # Bottom Right Edge, horizontal line
        outline = pcbnew.EDGE_MODULE(self.module)
        outline.SetWidth(pcbnew.FromMM(0.2))
        outline.SetLayer(pcbnew.SILKSCREEN_N_FRONT)
        outline.SetShape(pcbnew.S_SEGMENT)
        start = pcbnew.wxPoint(half_package_width, half_package_height)
        end = pcbnew.wxPoint(half_package_width - package_pad_width_offset,
                             half_package_height)
        outline.SetStartEnd(start, end)
        self.module.Add(outline)

        # Top Right Edge, vertical line
        outline = pcbnew.EDGE_MODULE(self.module)
        outline.SetWidth(pcbnew.FromMM(0.2))
        outline.SetLayer(pcbnew.SILKSCREEN_N_FRONT)
        outline.SetShape(pcbnew.S_SEGMENT)
        start = pcbnew.wxPoint(
            half_package_width,
            -half_package_height + package_pad_height_offset)
        end = pcbnew.wxPoint(half_package_width, -half_package_height)
        outline.SetStartEnd(start, end)
        self.module.Add(outline)

        # Top Right Edge, horizontal line
        outline = pcbnew.EDGE_MODULE(self.module)
        outline.SetWidth(pcbnew.FromMM(0.2))
        outline.SetLayer(pcbnew.SILKSCREEN_N_FRONT)
        outline.SetShape(pcbnew.S_SEGMENT)
        start = pcbnew.wxPoint(half_package_width, -half_package_height)
        end = pcbnew.wxPoint(half_package_width - package_pad_width_offset,
                             -half_package_height)
        outline.SetStartEnd(start, end)
        self.module.Add(outline)

        # Top Left Edge, straight line
        outline = pcbnew.EDGE_MODULE(self.module)
        outline.SetWidth(pcbnew.FromMM(0.2))
        outline.SetLayer(pcbnew.SILKSCREEN_N_FRONT)
        outline.SetShape(pcbnew.S_SEGMENT)
        start = pcbnew.wxPoint(
            -half_package_width,
            -half_package_height + package_pad_height_offset)
        end = pcbnew.wxPoint(-half_package_width + package_pad_width_offset,
                             -half_package_height)
        outline.SetStartEnd(start, end)
        self.module.Add(outline)