当前位置: 首页>>代码示例>>Python>>正文


Python Component.add_symbol方法代码示例

本文整理汇总了Python中upconvert.core.components.Component.add_symbol方法的典型用法代码示例。如果您正苦于以下问题:Python Component.add_symbol方法的具体用法?Python Component.add_symbol怎么用?Python Component.add_symbol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在upconvert.core.components.Component的用法示例。


在下文中一共展示了Component.add_symbol方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_device_component

# 需要导入模块: from upconvert.core.components import Component [as 别名]
# 或者: from upconvert.core.components.Component import add_symbol [as 别名]
    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
开发者ID:EasyPCB,项目名称:schematic-file-converter,代码行数:27,代码来源:__init__.py

示例2: test_bounds_all_elts

# 需要导入模块: from upconvert.core.components import Component [as 别名]
# 或者: from upconvert.core.components.Component import add_symbol [as 别名]
    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)
开发者ID:ncsaba,项目名称:schematic-file-converter,代码行数:27,代码来源:design_t.py

示例3: parse_components

# 需要导入模块: from upconvert.core.components import Component [as 别名]
# 或者: from upconvert.core.components.Component import add_symbol [as 别名]
 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)
开发者ID:aivarsk,项目名称:schematic-file-converter,代码行数:14,代码来源:openjson.py

示例4: make_component

# 需要导入模块: from upconvert.core.components import Component [as 别名]
# 或者: from upconvert.core.components.Component import add_symbol [as 别名]
    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
开发者ID:aivarsk,项目名称:schematic-file-converter,代码行数:14,代码来源:__init__.py

示例5: parse

# 需要导入模块: from upconvert.core.components import Component [as 别名]
# 或者: from upconvert.core.components.Component import add_symbol [as 别名]
    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
开发者ID:BPheiffer,项目名称:schematic-file-converter,代码行数:17,代码来源:viewdraw.py

示例6: parse_components

# 需要导入模块: from upconvert.core.components import Component [as 别名]
# 或者: from upconvert.core.components.Component import add_symbol [as 别名]
 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)
开发者ID:jsharf,项目名称:schematic-file-converter,代码行数:17,代码来源:openjson.py

示例7: test_bounds_parts

# 需要导入模块: from upconvert.core.components import Component [as 别名]
# 或者: from upconvert.core.components.Component import add_symbol [as 别名]
    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)
开发者ID:ncsaba,项目名称:schematic-file-converter,代码行数:19,代码来源:design_t.py

示例8: _convert_library

# 需要导入模块: from upconvert.core.components import Component [as 别名]
# 或者: from upconvert.core.components.Component import add_symbol [as 别名]
 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)
开发者ID:ncsaba,项目名称:schematic-file-converter,代码行数:22,代码来源:specctra.py

示例9: make_deviceset_component

# 需要导入模块: from upconvert.core.components import Component [as 别名]
# 或者: from upconvert.core.components.Component import add_symbol [as 别名]
    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
开发者ID:ncsaba,项目名称:schematic-file-converter,代码行数:25,代码来源:__init__.py

示例10: ComponentParser

# 需要导入模块: from upconvert.core.components import Component [as 别名]
# 或者: from upconvert.core.components.Component import add_symbol [as 别名]
class ComponentParser(object):
    """I parse components from Fritzing libraries."""

    # The svg files in fritzing libraries are specified in pixels that
    # are 72dpi. The schematics are in 90dpi.
    svg_mult = 90.0 / 72.0

    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


    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 connect_point(self, cid, inst, point):
        """ Given a connector id, instance id, and a NetPoint,
        add the appropriate ConnectedComponent to the point """

        termid = self.cid2termid.get(cid)
        pin = self.termid2pin.get(termid)

        if pin is not None:
            ccpt = ConnectedComponent(inst.instance_id, pin.pin_number)
            point.add_connected_component(ccpt)


    def get_next_pin_number(self):
        """ Return the next pin number """

        nextpn = self.next_pin_number
        self.next_pin_number += 1
        return str(nextpn)


    def parse_terminals(self, tree):
        """ Return a dictionary mapping connector id's to terminal id's """

        cid2termid = {}

        for conn in tree.findall('connectors/connector'):
            plug = conn.find('views/schematicView/p')
            if plug is None:
                continue

            termid = plug.get('terminalId')
            if termid is None:
                termid = plug.get('svgId')

            if termid is not None:
                cid2termid[conn.get('id')] = termid

        return cid2termid


    def parse_svg(self, svg_file):
        """ Parse the shapes and pins from an svg file """

        tree = ElementTree(file=svg_file)
        viewbox = tree.getroot().get('viewBox')

        if viewbox != None:
            self.width, self.height = [float(v) for v in viewbox.split()[-2:]]
            self.width *= self.svg_mult
            self.height *= self.svg_mult

        _iter = tree.getroot().getiterator()
        for element in _iter:
            for shape in self.parse_shapes(element):
                self.body.add_shape(shape)
#.........这里部分代码省略.........
开发者ID:EasyPCB,项目名称:schematic-file-converter,代码行数:103,代码来源:fritzing.py

示例11: ComponentParser

# 需要导入模块: from upconvert.core.components import Component [as 别名]
# 或者: from upconvert.core.components.Component import add_symbol [as 别名]
class ComponentParser(object):
    """I parse components from KiCAD libraries."""

    # the column positions of the unit and convert fields
    unit_cols = dict(A=6, C=4, P=2, S=5, T=6, X=9)
    convert_cols = dict((k, v+1) for k, v in unit_cols.items())

    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)


    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)


    def iter_bodies(self, unit, convert, has_convert):
        """ Return an iterator over all the bodies implied by the
        given unit and convert options. A unit of 0 means all units
        for the given convert. A convert of 0 means both converts for
        the given unit. If both are 0 it applies to all bodies."""

        if convert == 0 and has_convert:
            symbol_indices = [0, 1] # both regular and convert
        elif convert in (0, 1):
            symbol_indices = [0] # just regular
        else:
            symbol_indices = [1] # just convert

        if unit == 0:
            body_indices = range(self.num_units) # all bodies
        else:
            body_indices = [unit-1] # one body

        for symbol_index in symbol_indices:
            for body_index in body_indices:
                try:
                    yield self.component.symbols[symbol_index].bodies[body_index]
                except IndexError:
                    pass

    def parse(self, f):
        """ Parse a DEF block and return the Component """

        draw_lines = [] # (unit, convert, prefix, parts)

        for line in f:
            parts = line.split()
            prefix = parts[0]

            if prefix in ('A', 'C', 'P', 'S', 'T', 'X'):
                draw_lines.append((int(parts[self.unit_cols[prefix]]),
                                           int(parts[self.convert_cols[prefix]]),
                                           prefix, parts))
            elif prefix == 'ALIAS':
                self.component.add_attribute('kicad_alias', ' '.join(parts[1:]))
            elif prefix == 'ENDDEF':
                break

        has_convert = any(convert == 2 for _, convert, _, _ in draw_lines)

        self.build_symbols(has_convert)

        for unit, convert, prefix, parts in draw_lines:
            method = getattr(self, 'parse_%s_line' % (prefix.lower(),))

            for body in self.iter_bodies(unit, convert, has_convert):
                obj = method(parts)

                if prefix == 'X':
                    body.add_pin(obj)
                else:
                    if isinstance(obj, (list, tuple)):
                        for o in obj:
                            body.add_shape(o)
                    else:
                        body.add_shape(obj)

        for symbol in self.component.symbols:
            for body in symbol.bodies:
                body.pins.sort(key=lambda pin : pin.pin_number)

        return self.component


    def parse_a_line(self, parts):
        """ Parse an A (Arc) line """
#.........这里部分代码省略.........
开发者ID:BPheiffer,项目名称:schematic-file-converter,代码行数:103,代码来源:kicad.py


注:本文中的upconvert.core.components.Component.add_symbol方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。