Exemplo n.º 1
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
Exemplo n.º 2
0
 def parse_symbol(self, symbol):
     """ Extract a symbol. """
     symb = Symbol()
     for body in symbol.get('bodies'):
         bdy = self.parse_body(body)
         symb.add_body(bdy)
     return symb
    def parse_fzp(self, fzp_file):
        """ Parse the Fritzing component file """

        tree = ElementTree(file=fzp_file)

        try:
            prefix = tree.find('label').text
        except AttributeError:
            pass
        else:
            self.component.add_attribute('_prefix', prefix)

        symbol = Symbol()
        self.component.add_symbol(symbol)

        self.body = SBody()
        symbol.add_body(self.body)

        self.cid2termid.update(self.parse_terminals(tree))
        self.terminals.update(self.cid2termid.values())

        layers = tree.find('views/schematicView/layers')
        if layers is None:
			self.image = None
        else:
			self.image = layers.get('image')
			if self.image == 'schematic/dcpower.svg' :
				self.image='schematic/dc_powersupply.svg'
Exemplo n.º 4
0
    def parse_fzp(self, fzp_file):
        """ Parse the Fritzing component file """

        tree = ElementTree(file=fzp_file)

        try:
            prefix = tree.find('label').text
        except AttributeError:
            pass
        else:
            self.component.add_attribute('_prefix', prefix)

        symbol = Symbol()
        self.component.add_symbol(symbol)

        self.body = SBody()
        symbol.add_body(self.body)

        self.cid2termid.update(self.parse_terminals(tree))
        self.terminals.update(self.cid2termid.values())

        layers = tree.find('views/schematicView/layers')
        if layers is None:
            self.image = None
        else:
            self.image = layers.get('image')
 def parse_symbol(self, symbol_json):
     """ Extract a symbol. """
     symb = Symbol()
     for body in symbol_json.get("bodies"):
         bdy = self.parse_symbol_body(body)
         symb.add_body(bdy)
     return symb
Exemplo n.º 6
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
Exemplo n.º 7
0
 def parse_symbol(self, symbol_json):
     """ Extract a symbol. """
     symb = Symbol()
     for body in symbol_json.get('bodies'):
         bdy = self.parse_symbol_body(body)
         symb.add_body(bdy)
     return symb
Exemplo n.º 8
0
    def build_symbols(self, has_convert):
        """ Build all Symbols and Bodies for this component. The
        has_convert argument should be True if there are DeMorgan
        convert bodies. """

        for _ in range(2 if has_convert else 1):
            symbol = Symbol()
            for _ in range(self.num_units):
                symbol.add_body(Body())
            self.component.add_symbol(symbol)
Exemplo n.º 9
0
    def build_symbols(self, has_convert):
        """ Build all Symbols and Bodies for this component. The
        has_convert argument should be True if there are DeMorgan
        convert bodies. """

        for _ in range(2 if has_convert else 1):
            symbol = Symbol()
            for _ in range(self.num_units):
                symbol.add_body(SBody())
            self.component.add_symbol(symbol)
Exemplo n.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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.º 15
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.º 16
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.º 17
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.º 18
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.º 19
0
 def test_create_new_symbol(self):
     """ Test the creation of a new empty symbol. """
     symb = Symbol()
     assert len(symb.bodies) == 0