コード例 #1
0
    def test_lookup_missing(self):
        """ Test looking up a part that is missing """

        name = 'nosuchpart'
        libs = ['nosuchlib', 'jensen', '1wire']

        found = lookup_part(name, libs)

        self.assertEqual(found, None)
コード例 #2
0
    def test_lookup_missing(self):
        """ Test looking up a part that is missing """

        name = 'nosuchpart'
        libs = ['nosuchlib', 'jensen', '1wire']

        found = lookup_part(name, libs)

        self.assertEqual(found, None)
コード例 #3
0
    def test_lookup_present(self):
        """ Test looking up a part that is present """

        name = 'DS18B20Z'
        libs = ['jensen', '1wire']

        found = lookup_part(name, libs)

        self.assertTrue(isinstance(found, Component))
        self.assertEqual(found.name, name)
コード例 #4
0
    def test_lookup_present(self):
        """ Test looking up a part that is present """

        name = 'DS18B20Z'
        libs = ['jensen', '1wire']

        found = lookup_part(name, libs)

        self.assertTrue(isinstance(found, Component))
        self.assertEqual(found.name, name)
コード例 #5
0
    def parse(self, filename, library_filename=None):
        """ Parse a kicad file into a design """

        design = Design()
        segments = set()  # each wire segment
        junctions = set()  # wire junction point (connects all wires under it)

        if library_filename is None:
            library_filename = splitext(filename)[0] + '-cache.lib'
            if exists(library_filename):
                for cpt in parse_library(library_filename):
                    design.add_component(cpt.name, cpt)

        with open(filename) as f:
            libs = []
            line = f.readline().strip()

            # parse the library references
            while line and line != "$EndDescr":
                if line.startswith('LIBS:'):
                    libs.extend(line.split(':', 1)[1].split(','))
                line = f.readline().strip()

            # Now parse wires and components, ignore connections, we get
            # connectivity from wire segments

            line = f.readline()

            while line:
                prefix = line.split()[0]

                if line.startswith('Wire Wire Line'):
                    self.parse_wire(f, segments)
                elif prefix == "Connection":  # Store these to apply later
                    self.parse_connection(line, junctions)
                elif prefix == "Text":
                    design.design_attributes.add_annotation(
                        self.parse_text(f, line))
                elif prefix == "$Comp":  # Component Instance
                    inst = self.parse_component_instance(f)
                    design.add_component_instance(inst)
                    if inst.library_id not in design.components.components:
                        cpt = lookup_part(inst.library_id, libs)
                        if cpt is not None:
                            design.components.add_component(cpt.name, cpt)

                line = f.readline()

        segments = self.divide(segments, junctions)
        design.nets = self.calc_nets(segments)
        self.calc_connected_components(design)

        return design
コード例 #6
0
    def parse(self, filename, library_filename=None):
        """ Parse a kicad file into a design """

        design = Design()
        segments = set() # each wire segment
        junctions = set() # wire junction point (connects all wires under it)

        if library_filename is None:
            library_filename = splitext(filename)[0] + '-cache.lib'
            if exists(library_filename):
                for cpt in parse_library(library_filename):
                    design.add_component(cpt.name, cpt)

        with open(filename) as f:
            libs = []
            line = f.readline().strip()

            # parse the library references
            while line and line != "$EndDescr":
                if line.startswith('LIBS:'):
                    libs.extend(line.split(':', 1)[1].split(','))
                line = f.readline().strip()

            # Now parse wires and components, ignore connections, we get
            # connectivity from wire segments

            line = f.readline()

            while line:
                prefix = line.split()[0]

                if line.startswith('Wire Wire Line'):
                    self.parse_wire(f, segments)
                elif prefix == "Connection": # Store these to apply later
                    self.parse_connection(line, junctions)
                elif prefix == "Text":
                    design.design_attributes.add_annotation(
                        self.parse_text(f, line))
                elif prefix == "$Comp": # Component Instance
                    inst = self.parse_component_instance(f)
                    design.add_component_instance(inst)
                    if inst.library_id not in design.components.components:
                        cpt = lookup_part(inst.library_id, libs)
                        if cpt is not None:
                            design.components.add_component(cpt.name, cpt)

                line = f.readline()

        segments = self.divide(segments, junctions)
        design.nets = self.calc_nets(segments)
        self.calc_connected_components(design)

        return design
コード例 #7
0
    def ensure_component(self, design, name, libs):
        """
        Add a component to the design, it if is not already present.
        """

        if self.library is not None \
                and self.library.lookup_part(name) is not None:
            return

        cpt = lookup_part(name, libs)

        if cpt is None:
            return

        if cpt.name not in design.components.components:
            design.components.add_component(cpt.name, cpt)
コード例 #8
0
    def ensure_component(self, design, name, libs):
        """
        Add a component to the design, it if is not already present.
        """

        if self.library is not None \
                and self.library.lookup_part(name) is not None:
            return

        cpt = lookup_part(name, libs)

        if cpt is None:
            return

        if cpt.name not in design.components.components:
            design.components.add_component(cpt.name, cpt)