Exemplo n.º 1
0
    def test_bounds_all_elts(self):
        '''bounds() with all the elements competing'''
        net = Net('foo')
        mkbounds(net, 3, 3, -1, -2)
        self.des.add_net(net)

        annot = Annotation('foo', 3, 3, 0, True)
        mkbounds(annot, 3, 3, 3, 5)
        self.des.design_attributes.add_annotation(annot)

        libcomp = Component('bar')
        libcomp.add_symbol(Symbol())
        libcomp.symbols[0].add_body(Body())
        mkbounds(libcomp.symbols[0].bodies[0], 0, 0, 3, 3)
        self.des.add_component('foo', libcomp)

        compinst = ComponentInstance('bar', 'foo', 0)
        compinst.add_symbol_attribute(SymbolAttribute(3, 0, 0, False))
        self.des.add_component_instance(compinst)

        top_left, btm_right = self.des.bounds()
        self.assertEqual(top_left.x, -1)
        self.assertEqual(top_left.y, -2)
        self.assertEqual(btm_right.x, 6)
        self.assertEqual(btm_right.y, 5)
Exemplo n.º 2
0
    def make_device_component(self, lib, deviceset, device):
        """ Construct an openjson component for a device in a deviceset. """

        cpt = Component(lib.name + ':' + deviceset.name + ':' + device.name)

        cpt.add_attribute('eaglexml_library', lib.name)
        cpt.add_attribute('eaglexml_deviceset', deviceset.name)
        cpt.add_attribute('eaglexml_device', device.name)

        symbol = Symbol()
        cpt.add_symbol(symbol)

        assignment = PinNumberAssignment(device)

        for i, gate in enumerate(get_subattr(deviceset, 'gates.gate')):
            body, pin_map, ann_map = self.make_body_from_symbol(
                lib, gate.symbol, assignment.get_pin_number_lookup(gate.name))
            symbol.add_body(body)
            cpt.add_attribute('eaglexml_symbol_%d' % i, gate.symbol)
            cpt.add_attribute('eaglexml_gate_%d' % i, gate.name)
            self.cptgate2body_index[cpt, gate.name] = len(symbol.bodies) - 1
            self.cptgate2pin_map[cpt, gate.name] = pin_map
            self.cptgate2ann_map[cpt, gate.name] = ann_map

        return cpt
 def __init__(self, idref):
     self.component = Component(idref)
     self.next_pin_number = 0
     self.cid2termid = {} # connid -> termid
     self.termid2pin = {} # termid -> Pin
     self.terminals = set()
     self.width = 0.0
     self.height = 0.0
Exemplo n.º 4
0
 def __init__(self, line):
     parts = line.split()
     name = parts[1]
     if name.startswith('~'):
         name = name[1:]
     self.component = Component(name)
     self.component.add_attribute('_prefix', parts[2])
     self.num_units = max(int(parts[7]), 1)
Exemplo n.º 5
0
 def parse_components(self, components):
     """ Extract a component library. """
     for library_id, component in components.items():
         name = component.get('name')
         comp = Component(name)
         # Get attributes
         for key, value in component.get('attributes').items():
             comp.add_attribute(key, value)
         for symbol in component.get('symbols'):
             symb = self.parse_symbol(symbol)
             comp.add_symbol(symb)
         self.design.add_component(library_id, comp)
Exemplo n.º 6
0
    def make_component(self, lib, deviceset):
        """ Construct an openjson component for a deviceset in a library. """

        cpt = Component(lib.name + ':' + deviceset.name)

        for gate in get_subattr(deviceset, 'gates.gate'):
            symbol = Symbol()
            cpt.add_symbol(symbol)
            self.cpt2gate2symbol_index[cpt][gate.name] = len(cpt.symbols) - 1
            symbol.add_body(self.make_body_from_symbol(lib, gate.symbol))

        return cpt
Exemplo n.º 7
0
 def parse_components(self, components):
     """ Extract a component library. """
     for library_id, component in components.items():
         name = component.get('name')
         comp = Component(name)
         # Get attributes
         for key, value in component.get('attributes', []).items():
             comp.add_attribute(key, value)
         for symbol_json in component.get('symbols', []):
             symbol = self.parse_symbol(symbol_json)
             comp.add_symbol(symbol)
         for footprint_json in component.get('footprints', []):
             footprint = self.parse_footprint(footprint_json)
             comp.add_footprint(footprint)
         self.design.add_component(library_id, comp)
Exemplo n.º 8
0
    def parse(self):
        """ Parses a component from the library, returns a Compenent. """
        part = Component(self.filename)
        part.add_symbol(Symbol())
        part.symbols[0].add_body(SBody())

        tree = ViewDrawBase.parse(self)
        for k, v in tree['attr']:
            part.add_attribute(k, v)
        for shape in tree['shape'] + sum(tree['lines'], []):
            part.symbols[0].bodies[0].add_shape(shape)
        for pin in tree['pin']:
            part.symbols[0].bodies[0].add_pin(pin)

        return part
Exemplo n.º 9
0
    def test_bounds_parts(self):
        '''test bounds() with just components in the design'''
        libcomp = Component('bar')
        libcomp.add_symbol(Symbol())
        libcomp.symbols[0].add_body(Body())
        mkbounds(libcomp.symbols[0].bodies[0], 0, 0, 10, 10)
        self.des.add_component('foo', libcomp)
        for (x, y) in ((1, 3), (3, 2), (5, 3), (3, 7)):
            compinst = ComponentInstance(str((x, y)), 'foo', 0)
            compinst.add_symbol_attribute(SymbolAttribute(x, y, 0, False))
            self.des.add_component_instance(compinst)

        top_left, btm_right = self.des.bounds()
        self.assertEqual(top_left.x, 1)
        self.assertEqual(top_left.y, 2)
        self.assertEqual(btm_right.x, 15)
        self.assertEqual(btm_right.y, 17)
Exemplo n.º 10
0
    def _convert_library(self, struct):
        """ Convert library """
        for image in struct.library.image:
            component = Component(image.image_id)
            self.design.add_component(image.image_id, component)
            fpt = Footprint()
            body = FBody()
            component.add_footprint(fpt)
            fpt.add_body(body)
            for pad in image.pin:
                body.add_pad(Pad(pad.pad_id, self.to_pixels(pad.vertex), self.to_pixels(pad.vertex)))
                for padstack in struct.library.padstack:
                    if padstack.padstack_id == pad.padstack_id:
                        shapes = [shape.shape for shape in padstack.shape]
                        for shape in self._convert_shapes(shapes, self.to_pixels(pad.vertex)):
                            body.add_shape(shape)
                        break

            for outline in image.outline:
                for shape in self._convert_shapes([outline.shape]):
                    body.add_shape(shape)
Exemplo n.º 11
0
    def _convert_library(self, struct):
        for image in struct.library.image:
            component = Component(image.image_id)
            self.design.add_component(image.image_id, component)
            sym = Symbol()
            body = Body()
            component.add_symbol(sym)
            sym.add_body(body)
            for pin in image.pin:
                body.add_pin(
                    Pin(pin.pin_id, self.to_pixels(pin.vertex),
                        self.to_pixels(pin.vertex)))
                for padstack in struct.library.padstack:
                    if padstack.padstack_id == pin.padstack_id:
                        shapes = [shape.shape for shape in padstack.shape]
                        for shape in self._convert_shapes(
                                shapes, self.to_pixels(pin.vertex)):
                            body.add_shape(shape)
                        break

            for outline in image.outline:
                for shape in self._convert_shapes([outline.shape]):
                    body.add_shape(shape)
Exemplo n.º 12
0
    def make_deviceset_component(self, lib, deviceset):
        """ Construct an openjson component for an eaglexml deviceset
        in a library."""

        cpt = Component(lib.name + ':' + deviceset.name + ':logical')

        cpt.add_attribute('eaglexml_type', 'logical')
        cpt.add_attribute('eaglexml_library', lib.name)
        cpt.add_attribute('eaglexml_deviceset', deviceset.name)

        symbol = Symbol()
        cpt.add_symbol(symbol)

        for i, gate in enumerate(get_subattr(deviceset, 'gates.gate')):
            body, pin_map, ann_map = self.make_body_from_symbol(
                lib, gate.symbol)
            symbol.add_body(body)
            cpt.add_attribute('eaglexml_symbol_%d' % i, gate.symbol)
            cpt.add_attribute('eaglexml_gate_%d' % i, gate.name)
            self.cptgate2body_index[cpt, gate.name] = len(symbol.bodies) - 1
            self.cptgate2pin_map[cpt, gate.name] = pin_map
            self.cptgate2ann_map[cpt, gate.name] = ann_map

        return cpt
Exemplo n.º 13
0
 def __init__(self, line):
     parts = line.split()
     self.component = Component(parts[1])
     self.component.add_attribute('_prefix', parts[2])
     self.num_units = max(int(parts[7]), 1)
Exemplo n.º 14
0
 def test_create_new_component(self):
     """ Test the creation of a new empty component. """
     comp = Component('abc')
     assert comp.name == 'abc'