Skip to content
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.

kicad_mod_generator

Thomas Pointhuber edited this page Jan 16, 2019 · 13 revisions

Idea would be generating models using python as base language. The whole framework/library should be made in a way where scripting a component is as simple as possible without too much general/structural/reppetive code for each component script.

Current project members:

  • @pointhi (irc: pointhi) (footprint generator)
  • @iromero91 (irc: cyborg_ar) (3d model generator)

API-Idea (@pointhi)

The script should be able to be called like:

./demo_footprint.py spec1.csv spec2.csv spec3.yml -v dir=Demo.pretty

But also inside python (where I have to think of an implementation ^^)

using an argparse similar api, which is build in a way to support different types of input (csv, yml, call inside python script) looks like a good idea.

Basic Structure v0.2
from kicad_mod_generator import parser, KicadFootprint

class MyFootprint(KicadFootprint):
    def __init__(self):
        KicadFootprint.__init__(self)

    def write_footprint(self, format):
        return None

    def write_3d_model(self, filename):
        return None

parser = KicadModParser(MyFootprint)
parser.description = "some example footprint"
parser.set_arguments([{'arg':'name', type:str},
                      {'arg':'datasheet', type:str}])
parser.add_argument('dimension_A', type=int) # other way of defining arguments, which would require more coding
parser.add_argument('dimension_B', type=int)
parser.add_argument('dimension_C', type=int)

if __name__ == '__main__':
    parser.run()
class KicadFootprint(object):
    '''
    Handles generation of a single footprint.
    All required arguments for this task have to be defined in KicadModParser
    '''
    def __init__(self):
        self._arg = []  # arguments are set by KicadModParser

    def write_footprint(self, filename):
        raise NotImplementedError("write_footprint has to be implemented by child class")

    def write_3d_model(self, filename):
        raise NotImplementedError("write_3d_mode has to be implemented by child class")
class KicadModParser(object):
    '''
    Handles parsing of definition files, ..., and create KicadFootprint objects from it
    '''
    def __init__(self, footprint):
        self._arg = []
        self._footprint_arg = []
        self.name = footprint.__name__
        self.description = None

    def add_argument(self, **kwarg)
        pass

    def set_arguments(self, arg)
        pass

    def get_arguments(self)
        pass

    def parse_file(self, filename)
        pass

    def run(self):
        pass  # parse cmd and controll all future operations (reading of files, writing of files, ...)

    def generate_footprint_objects(self)
        pass

Grammar for dimensions (@iromero91)

To make an IPC compliant footprint generator, the component dimensions must be specified with tolerances, either as an interval of maximum and minimum, or as a nominal value with a +/- tolerance. Examples:

  1. 4.3 Exact nominal value
  2. 4.3+-0.3 Nominal value and symmetrical tolerance (4.0 to 4.6)
  3. 4.3+0.0-0.5 Nominal value with asymmetrical tolerances (3.8 to 4.3)
  4. 4.0..4.6 Range tolerance (identical to example 2)
  5. <4.6 or ..4.6 Only maximum value
  6. >4.3 or 4.3.. Only minimum value

By default the quantities would be only in mm, but it could be possible to accept other units like mils later on (fairly low priority).

3D-Data generator?