def parse_footprint(self, filename):

        # logger.info('Footprint: {f:s}'.format(f=os.path.basename(filename)))
        try:
            footprint = KicadMod(filename)
        except FileNotFoundError:
            logger.fatal(
                "EXIT: problem reading footprint file {fn:s}".format(fn=filename)
            )
            sys.exit(1)
        try:
            long_reference = footprint.models[0]["file"]
        except IndexError:
            if footprint.attribute == "virtual":
                # count as model found
                self.model_found += 1
            else:
                logger.warning(
                    "- No model file specified in {fp:s}".format(
                        fp=os.path.basename(filename)
                    )
                )
                self.no_model_specified += 1
            return None

        try:
            # Accept both forward and backward slash characters in path
            long_reference = "/".join(long_reference.split("\\"))
            return os.path.basename(long_reference)
        # TODO: determine, which specific problem could happen above ("ValueError" is just a guess)
        except ValueError:
            logger.warning("- Invalid model reference {f:s}".format(f=long_reference))
            self.invalid_model_path += 1
            return None
Example #2
0
def check_library(filename: str, rules, metrics: List[str],
                  args) -> Tuple[int, int]:
    """
    Returns (error count, warning count)
    """

    if not os.path.exists(filename):
        printer.red("File does not exist: %s" % filename)
        return (1, 0)

    if not filename.endswith(".kicad_mod"):
        printer.red("File is not a .kicad_mod : %s" % filename)
        return (1, 0)

    if args.errors:
        module = KicadMod(filename)
    else:
        try:
            module = KicadMod(filename)
        except Exception as e:
            printer.red("Could not parse footprint: %s. (%s)" % (filename, e))
            if args.verbose:
                # printer.red("Error: " + str(e))
                traceback.print_exc()
            return (1, 0)

    if args.rotate != 0:
        module.rotateFootprint(int(args.rotate))
        printer.green(
            "rotated footprint by {deg} degrees".format(deg=int(args.rotate)))

    # check which kind of tests we want to run
    if args.unittest:
        (ec, wc) = do_unittest(module, rules, metrics)
    else:
        (ec, wc) = do_rulecheck(module, rules, metrics)

    # done checking the footpint
    metrics.append("{lib}.errors {n}".format(lib=module.name, n=ec))
    metrics.append("{lib}.warnings {n}".format(lib=module.name, n=wc))
    return (ec, wc)
Example #3
0
    for f in os.listdir(lib_dir):

        # File types to copy across
        allowed = ['.md', '.txt', '.kicad_mod']

        if not any([f.lower().endswith(x) for x in allowed]):
            continue

        fp_file = os.path.join(lib_dir, f)

        files.append(fp_file)

        if f.endswith('.kicad_mod'):
            try:
                fp = KicadMod(fp_file)
                footprints.append(fp)
            except:
                print("Error loading {fp}".format(fp=fp_file))
                # Skip to the next one
                continue

    if args.download:

        archive_dir = os.path.abspath(os.path.join(args.download,
                                                   'footprints'))

        if not os.path.exists(archive_dir):
            os.makedirs(archive_dir)

        archive_file = lib_name + '.pretty.7z'
Example #4
0
# -*- coding: utf-8 -*-

import os
import re

from kicad_mod import KicadMod

dir_kicad_pins = "/usr/share/kicad/modules/Pin_Headers.pretty/"
dir_my_pins = "./"
re_filenames = re.compile(r"Pin_Header_Straight_(\d)x(\d\d).kicad_mod")

for filename in os.walk(dir_kicad_pins).next()[2]:
    matches = re_filenames.match(filename)
    if matches:

        module = KicadMod(dir_kicad_pins + filename)
        shape = matches.groups()

        # Change all drill sizes to 1mm
        for pad in module.pads:
            pad['drill']['size'] = {'x': 1., 'y': 1.}

        module.name = "pin-{}x{}-sq".format(shape[0], shape[1])
        module.description = "Header pin. 2.54mm pitch. 1mm drills. Shape {}x{}. Square pin 1.".format(
            shape[0], shape[1])
        module.value['value'] = module.name
        module.save(filename="{}{}.kicad_mod".format(dir_my_pins, module.name))

        # Now create a similar module without the square pin
        for pad in module.pads:
            pad['shape'] = 'oval'
for pincount in [2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 18, 20, 30]:

    part = "53780-{0:02}70".format(pincount)

    desc = "{0:} {1}".format(manu, series)
    desc += " series connector, {0:.2f}mm pitch, side entry SMT, P/N: {1:}".format(
        pitch, part)
    tags = "conn molex panelmate"

    footprint_name = "{0}-{1}_{2:02}x{3:.2f}mm_{4}".format(
        manu + "_" + series, part, pincount, pitch, suffix)

    print(footprint_name)

    kicad_mod = KicadMod(footprint_name)
    kicad_mod.setDescription(desc)
    kicad_mod.setTags(tags)

    kicad_mod.setAttribute('smd')

    # set general values
    kicad_mod.addText('reference', 'REF**', {'x': 0, 'y': -3}, 'F.SilkS')
    #kicad_mod.addText('user', '%R', {'x':0, 'y':-3}, 'F.Fab')
    kicad_mod.addText('value', footprint_name, {'x': 0, 'y': 7}, 'F.Fab')

    #pin pad size
    pad_w = 0.8
    pad_h = 1.9

    #component values