def parse_component_instance(self, f):
        """ Parse a component instance from a $Comp block """
        # pylint: disable=R0914

        # name & reference
        prefix, name, reference = f.readline().split()
        assert prefix == 'L'

        ref_count_idx = 1
        while reference in self.instance_names:
            ref_count_idx += 1
            reference = reference + '-' + str(ref_count_idx)

        self.instance_names.append(reference)

        comp = None
        if self.library is not None:
            library_part = self.library.lookup_part(name)
            if library_part is not None:
                name = library_part.name

        # unit & convert
        prefix, unit, convert, ar_path = f.readline().split(None, 3)
        unit, convert = int(unit), int(convert)
        assert prefix == 'U'

        # position
        prefix, compx, compy = f.readline().split()
        assert prefix == 'P'
        compx, compy = int(compx), int(compy)

        line = f.readline()
        rotation = 0
        flip = False
        annotations = []

        while line.strip() not in ("$EndComp", ''):
            if line.startswith('F '):
                annotations.append(self.parse_field(compx, compy, line))
            elif line.startswith('\t'):
                parts = line.strip().split()
                if len(parts) == 4:
                    rotation, flip = MATRIX2ROTATIONFLIP.get(
                        tuple(int(i) for i in parts), (0, False))
            elif line.startswith('AR Path'):
                if '?' in reference:
                    path_line = line.strip().split()
                    ar_path_check = path_line[1].strip('"')[7:] #removes Path="/
                    if ar_path.strip() == ar_path_check:
                        reference = path_line[2].strip('"')[5:] #removes Ref="

            line = f.readline()

        inst = ComponentInstance(reference, library_part, name.upper(), convert - 1)
        symbattr = SymbolAttribute(compx, -compy, rotation, flip)
        for ann in annotations:
            symbattr.add_annotation(ann)
        inst.add_symbol_attribute(symbattr)

        return inst, comp
    def parse_symbol_attribute(self, symbol_attribute):
        """ Extract attributes from a symbol. """
        x = int(symbol_attribute.get('x'))
        y = int(symbol_attribute.get('y'))
        rotation = float(symbol_attribute.get('rotation'))

        # Make SymbolAttribute
        symbol_attr = SymbolAttribute(x, y, rotation)

        # Add Annotations
        for annotation in symbol_attribute.get('annotations'):
            anno = self.parse_annotation(annotation)
            symbol_attr.add_annotation(anno)

        # Return SymbolAttribute to be added to it's ComponentInstance
        return symbol_attr
Esempio n. 3
0
    def parse_component_instance(self, f):
        """ Parse a component instance from a $Comp block """
        # pylint: disable=R0914

        # name & reference
        prefix, name, reference = f.readline().split()
        assert prefix == 'L'

        # unit & convert
        prefix, unit, convert, _ = f.readline().split(None, 3)
        unit, convert = int(unit), int(convert)
        assert prefix == 'U'

        # position
        prefix, compx, compy = f.readline().split()
        assert prefix == 'P'
        compx, compy = int(compx), int(compy)

        line = f.readline()
        rotation = 0
        annotations = []

        while line.strip() not in ("$EndComp", ''):
            if line.startswith('F '):
                parts = line.split('"', 2)
                value = parts[1].decode('utf-8', 'replace')
                parts = parts[2].strip().split()
                annotations.append(
                    Annotation(value,
                               make_length(int(parts[1]) - compx),
                               -make_length(int(parts[2]) - compy),
                               0 if parts[0] == 'H' else 1, 'true'))
            elif line.startswith('\t'):
                parts = line.strip().split()
                if len(parts) == 4:
                    rotation = MATRIX2ROTATION.get(
                        tuple(int(i) for i in parts), 0)
            line = f.readline()

        inst = ComponentInstance(reference, name, convert - 1)
        symbattr = SymbolAttribute(make_length(compx), -make_length(compy),
                                   rotation)
        for ann in annotations:
            symbattr.add_annotation(ann)
        inst.add_symbol_attribute(symbattr)

        return inst
Esempio n. 4
0
    def parse_symbol_attribute(self, symbol_attribute):
        """ Extract attributes from a symbol. """
        x = int(symbol_attribute.get('x') or 0)
        y = int(symbol_attribute.get('y') or 0)

        rotation = float(symbol_attribute.get('rotation'))

        # Make SymbolAttribute
        symbol_attr = SymbolAttribute(x, y, rotation)

        # Add Annotations
        for annotation in symbol_attribute.get('annotations'):
            anno = self.parse_annotation(annotation)
            symbol_attr.add_annotation(anno)

        # Return SymbolAttribute to be added to it's ComponentInstance
        return symbol_attr
    def parse_component_instance(self, f):
        """ Parse a component instance from a $Comp block """
        # pylint: disable=R0914

        # name & reference
        prefix, name, reference = f.readline().split()
        assert prefix == 'L'

        if self.library is not None:
            library_part = self.library.lookup_part(name)
            if library_part is not None:
                name = library_part.name

        # unit & convert
        prefix, unit, convert, _ = f.readline().split(None, 3)
        unit, convert = int(unit), int(convert)
        assert prefix == 'U'

        # position
        prefix, compx, compy = f.readline().split()
        assert prefix == 'P'
        compx, compy = int(compx), int(compy)

        line = f.readline()
        rotation = 0
        annotations = []

        while line.strip() not in ("$EndComp", ''):
            if line.startswith('F '):
                annotations.append(self.parse_field(compx, compy, line))
            elif line.startswith('\t'):
                parts = line.strip().split()
                if len(parts) == 4:
                    rotation = MATRIX2ROTATION.get(
                        tuple(int(i) for i in parts), 0)
            line = f.readline()

        inst = ComponentInstance(reference, name.upper(), convert - 1)
        symbattr = SymbolAttribute(make_length(compx), -make_length(compy),
                                   rotation, False)
        for ann in annotations:
            symbattr.add_annotation(ann)
        inst.add_symbol_attribute(symbattr)

        return inst
Esempio n. 6
0
    def parse_symbol_attribute(self, symbol_attribute):
        """ Extract attributes from a symbol. """
        x = int(symbol_attribute.get('x') or 0)
        y = int(symbol_attribute.get('y') or 0)

        rotation = float(symbol_attribute.get('rotation'))
        try:
            flip = (symbol_attribute.get('flip').lower() == "true")
        except:
            flip = False

        # Make SymbolAttribute
        symbol_attr = SymbolAttribute(x, y, rotation, flip)

        # Add Annotations
        for annotation in symbol_attribute.get('annotations'):
            anno = self.parse_annotation(annotation)
            symbol_attr.add_annotation(anno)

        # Return SymbolAttribute to be added to its ComponentInstance
        return symbol_attr
    def parse_symbol_attribute(self, symbol_attribute):
        """ Extract attributes from a symbol. """
        x = int(symbol_attribute.get('x') or 0)
        y = int(symbol_attribute.get('y') or 0)

        rotation = float(symbol_attribute.get('rotation'))
        try:
            flip = (symbol_attribute.get('flip').lower() == "true")
        except:
            flip = False

        # Make SymbolAttribute
        symbol_attr = SymbolAttribute(x, y, rotation, flip)

        # Add Annotations
        for annotation in symbol_attribute.get('annotations'):
            anno = self.parse_annotation(annotation)
            symbol_attr.add_annotation(anno)

        # Return SymbolAttribute to be added to its ComponentInstance
        return symbol_attr
Esempio n. 8
0
    def parse_component_instance(self, f):
        """ Parse a component instance from a $Comp block """
        # pylint: disable=R0914

        # name & reference
        prefix, name, reference = f.readline().split()
        assert prefix == 'L'

        # unit & convert
        prefix, unit, convert, _ = f.readline().split(None, 3)
        unit, convert = int(unit), int(convert)
        assert prefix == 'U'

        # position
        prefix, compx, compy = f.readline().split()
        assert prefix == 'P'
        compx, compy = int(compx), int(compy)

        line = f.readline()
        rotation = 0
        annotations = []

        while line.strip() not in ("$EndComp", ''):
            if line.startswith('F '):
                annotations.append(self.parse_field(compx, compy, line))
            elif line.startswith('\t'):
                parts = line.strip().split()
                if len(parts) == 4:
                    rotation = MATRIX2ROTATION.get(
                        tuple(int(i) for i in parts), 0)
            line = f.readline()

        inst = ComponentInstance(reference, name, convert - 1)
        symbattr = SymbolAttribute(make_length(compx), -make_length(compy),
                                   rotation)
        for ann in annotations:
            symbattr.add_annotation(ann)
        inst.add_symbol_attribute(symbattr)

        return inst
Esempio n. 9
0
    def _parse_component(self, stream, params):
        """ Creates a component instance according to the component *params*.
            If the component is not known in the library, a the component
            will be created according to its description in the embedded
            environment ``[]`` or a symbol file. The component is added
            to the library automatically if necessary.
            An instance of this component will be created and added to
            the design.
            A GEDAError is raised when either the component file
            is invalid or the referenced symbol file cannot be found
            in the known directories.

            Returns a tuple of Component and ComponentInstance objects.
        """
        basename, _ = os.path.splitext(params['basename'])

        component_name = basename
        if params.get('mirror'):
            component_name += '_MIRRORED'

        if component_name in self.design.components.components:
            component = self.design.components.components[component_name]

            ## skipping embedded data might be required
            self.skip_embedded_section(stream)

        else:
            ##check if sym file is embedded or referenced
            if basename.startswith('EMBEDDED'):
                ## embedded only has to be processed when NOT in symbol lookup
                if basename not in self.known_symbols:
                    component = self.parse_component_data(stream, params)
            else:
                if basename not in self.known_symbols:
                    log.warn("referenced symbol file '%s' unknown" % basename)
                    ## create a unknown symbol reference
                    component = self.parse_component_data(
                        StringIO(UNKNOWN_COMPONENT % basename),
                        params
                    )
                    ## parse optional attached environment before continuing
                    self._parse_environment(stream)
                    return None, None

                ## requires parsing of referenced symbol file
                with open(self.known_symbols[basename], "rU") as f_in:
                    self._check_version(f_in)
                    component = self.parse_component_data(f_in, params)

            self.design.add_component(component_name, component)

        ## get all attributes assigned to component instance
        attributes = self._parse_environment(stream)

        ## refdes attribute is name of component (mandatory as of gEDA doc)
        ## examples if gaf repo have components without refdes, use part of
        ## basename
        if attributes is not None:
            instance = ComponentInstance(
                attributes.get('_refdes', component.name),
                component.name, 0
            )
            for key, value in attributes.items():
                instance.add_attribute(key, value)

        else:
            instance = ComponentInstance(
                component.name, component.name, 0
            )

        ## generate a component instance using attributes
        self.design.add_component_instance(instance)

        symbol = SymbolAttribute(
            self.x_to_px(params['x']),
            self.y_to_px(params['y']),
            self.conv_angle(params['angle'],
            False)
        )
        instance.add_symbol_attribute(symbol)

        ## add annotation for special attributes
        for idx, attribute_key in enumerate(['_refdes', 'device']):
            if attribute_key in component.attributes \
               or attribute_key in instance.attributes:

                symbol.add_annotation(
                    Annotation(
                        '{{%s}}' % attribute_key,
                        0, 0+idx*10, 0.0, 'true'
                    )
                )

        return component, instance
Esempio n. 10
0
    def _parse_component(self, stream, params):
        """ Creates a component instance according to the component *params*.
            If the component is not known in the library, a the component
            will be created according to its description in the embedded
            environment ``[]`` or a symbol file. The component is added
            to the library automatically if necessary.
            An instance of this component will be created and added to
            the design.
            A GEDAError is raised when either the component file
            is invalid or the referenced symbol file cannot be found
            in the known directories.

            Returns a tuple of Component and ComponentInstance objects.
        """
        basename, _ = os.path.splitext(params['basename'])

        component_name = basename
        if params.get('mirror'):
            component_name += '_MIRRORED'

        if component_name in self.design.components.components:
            component = self.design.components.components[component_name]

            ## skipping embedded data might be required
            self.skip_embedded_section(stream)

        else:
            ##check if sym file is embedded or referenced
            if basename.startswith('EMBEDDED'):
                ## embedded only has to be processed when NOT in symbol lookup
                if basename not in self.known_symbols:
                    component = self.parse_component_data(stream, params)
            else:
                if basename not in self.known_symbols:
                    log.warn("referenced symbol file '%s' unknown" % basename)
                    ## create a unknown symbol reference
                    component = self.parse_component_data(
                        StringIO(UNKNOWN_COMPONENT % basename), params)
                    ## parse optional attached environment before continuing
                    self._parse_environment(stream)
                    return None, None

                ## requires parsing of referenced symbol file
                with open(self.known_symbols[basename], "rU") as f_in:
                    self._check_version(f_in)
                    component = self.parse_component_data(f_in, params)

            self.design.add_component(component_name, component)

        ## get all attributes assigned to component instance
        attributes = self._parse_environment(stream)

        ## refdes attribute is name of component (mandatory as of gEDA doc)
        ## examples if gaf repo have components without refdes, use part of
        ## basename
        if attributes is not None:
            instance = ComponentInstance(
                attributes.get('_refdes', component.name), component.name, 0)
            for key, value in attributes.items():
                instance.add_attribute(key, value)

        else:
            instance = ComponentInstance(component.name, component.name, 0)

        ## generate a component instance using attributes
        self.design.add_component_instance(instance)

        symbol = SymbolAttribute(self.x_to_px(params['x']),
                                 self.y_to_px(params['y']),
                                 self.conv_angle(params['angle'], False))
        instance.add_symbol_attribute(symbol)

        ## add annotation for special attributes
        for idx, attribute_key in enumerate(['_refdes', 'device']):
            if attribute_key in component.attributes \
               or attribute_key in instance.attributes:

                symbol.add_annotation(
                    Annotation('{{%s}}' % attribute_key, 0, 0 + idx * 10, 0.0,
                               'true'))

        return component, instance
Esempio n. 11
0
    def parse_component_instance(self, f):
        """ Parse a component instance from a $Comp block """
        # pylint: disable=R0914

        # name & reference
        prefix, name, reference = f.readline().split()
        assert prefix == 'L'

        ref_count_idx = 1
        while reference in self.instance_names:
            ref_count_idx += 1
            reference = reference + '-' + str(ref_count_idx)

        self.instance_names.append(reference)

        comp = None
        if self.library is not None:
            library_part = self.library.lookup_part(name)
            if library_part is not None:
                name = library_part.name

        # unit & convert
        prefix, unit, convert, ar_path = f.readline().split(None, 3)
        unit, convert = int(unit), int(convert)
        assert prefix == 'U'

        # position
        prefix, compx, compy = f.readline().split()
        assert prefix == 'P'
        compx, compy = int(compx), int(compy)

        line = f.readline()
        rotation = 0
        flip = False
        annotations = []

        while line.strip() not in ("$EndComp", ''):
            if line.startswith('F '):
                annotations.append(self.parse_field(compx, compy, line))
            elif line.startswith('\t'):
                parts = line.strip().split()
                if len(parts) == 4:
                    rotation, flip = MATRIX2ROTATIONFLIP.get(
                        tuple(int(i) for i in parts), (0, False))
            elif line.startswith('AR Path'):
                if '?' in reference:
                    path_line = line.strip().split()
                    ar_path_check = path_line[1].strip('"')[
                        7:]  #removes Path="/
                    if ar_path.strip() == ar_path_check:
                        reference = path_line[2].strip('"')[5:]  #removes Ref="

            line = f.readline()

        inst = ComponentInstance(reference, library_part, name.upper(),
                                 convert - 1)
        symbattr = SymbolAttribute(compx, -compy, rotation, flip)
        for ann in annotations:
            symbattr.add_annotation(ann)
        inst.add_symbol_attribute(symbattr)

        return inst, comp