• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python components.Component类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_bounds_all_elts

    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,代码行数:25,代码来源:design_t.py


示例2: parse_components

 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,代码行数:12,代码来源:openjson.py


示例3: make_component

    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,代码行数:12,代码来源:__init__.py


示例4: parse

    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,代码行数:15,代码来源:viewdraw.py


示例5: __init__

 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
开发者ID:EasyPCB,项目名称:schematic-file-converter,代码行数:8,代码来源:fritzing.py


示例6: __init__

 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)
开发者ID:BPheiffer,项目名称:schematic-file-converter,代码行数:8,代码来源:kicad.py


示例7: test_bounds_parts

    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,代码行数:17,代码来源:design_t.py


示例8: _convert_library

 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,代码行数:20,代码来源:specctra.py


示例9: _convert_library

    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)
开发者ID:BPheiffer,项目名称:schematic-file-converter,代码行数:21,代码来源:specctra.py


示例10: parse_components

 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,代码行数:15,代码来源:openjson.py


示例11: make_deviceset_component

    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,代码行数:23,代码来源:__init__.py


示例12: ComponentParser

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,代码行数:101,代码来源:fritzing.py


示例13: ComponentParser

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,代码行数:101,代码来源:kicad.py


示例14: make_device_component

    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,代码行数:25,代码来源:__init__.py


示例15: __init__

 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)
开发者ID:ncsaba,项目名称:schematic-file-converter,代码行数:5,代码来源:kicad.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python design.Design类代码示例发布时间:2022-05-27
下一篇:
Python component_instance.ComponentInstance类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap