Ejemplo n.º 1
0
    def test_convert_label(self):
        """ Tests converting Lable objects to label commands. """
        label = shape.Label(0, 0, 'test label', align='center', rotation=0.0)
        command = self.geda_writer._convert_label(label)
        self.assertEquals(command, ['T 0 0 9 10 1 1 0 3 1', 'test label'])

        label = shape.Label(0, 0, 'test label', align='left', rotation=0.5)
        command = self.geda_writer._convert_label(label)
        self.assertEquals(command, ['T 0 0 9 10 1 1 270 0 1', 'test label'])
Ejemplo n.º 2
0
    def _parse_P(self, stream, params, pinnumber=0):
        """ Creates a Pin object from the parameters in *param* and
            text attributes provided in the following environment. The
            environment is enclosed in ``{}`` and is required. If no
            attributes can be extracted form *stream* an GEDAError
            is raised.
            The *pin_id* is retrieved from the 'pinnumber' attribute and
            all other attributes are ignored. The conneted end of the
            pin is taken from the 'whichend' parameter as defined in
            the gEDA documentation.

            Returns a Pin object.
        """
        ## pin requires an attribute enviroment, so parse it first
        attributes = self._parse_environment(stream)

        if attributes is None:
            log.warn('mandatory pin attributes missing')
            attributes = {
                '_pinnumber': pinnumber,
            }

        if '_pinnumber' not in attributes:
            attributes['_pinnumber'] = pinnumber
            log.warn("mandatory attribute '_pinnumber' not assigned to pin")

        whichend = params['whichend']

        pin_x1, pin_x2 = params['x1'], params['x2']
        if self._is_mirrored_command(params):
            pin_x1 = 0 - pin_x1
            pin_x2 = 0 - pin_x2

        ## determine wich end of the pin is the connected end
        ## 0: first point is connector
        ## 1: second point is connector
        if whichend == 0:
            connect_end = self.conv_coords(pin_x1, params['y1'])
            null_end = self.conv_coords(pin_x2, params['y2'])
        else:
            null_end = self.conv_coords(pin_x1, params['y1'])
            connect_end = self.conv_coords(pin_x2, params['y2'])

        label = None
        if '_pinlabel' in attributes:
            label = shape.Label(connect_end[0], connect_end[1],
                                attributes.get('_pinlabel'), 'left', 0.0)

        pin = components.Pin(
            attributes['_pinnumber'],  #pin number
            null_end,
            connect_end,
            label=label)
        ## store style parameters in shape's style dict
        self._save_parameters_to_object(pin, params)
        return pin
Ejemplo n.º 3
0
    def as_label(self):
        """
        Generate label from text object using parsed parameters.

        Returns ``Label`` instance.
        """
        text_x = self.params.get('x', 0)

        if self.params.get('mirrored', False):
            text_x = 0 - text_x

        label = shape.Label(
            text_x,
            self.params.get('y', 0),
            self.content,
            'left',
            self.params.get('angle', 0),
        )
        return self.store_styles_in_label(label)
Ejemplo n.º 4
0
    def test_create_pin(self):
        """ Tests creating pin commands. """
        pin = components.Pin('E', (0, 0), (0, 30))
        command = self.geda_writer._create_pin(1, pin)

        self.assertEquals(command, [
            'P 0 300 0 0 1 0 0', '{', 'T 100 400 5 10 0 1 0 0 1', 'pinseq=1',
            'T 100 500 5 10 0 1 0 0 1', 'pinnumber=E', '}'
        ])

        label = shape.Label(10, 0, 'p1', align='left', rotation=0.5)

        pin = components.Pin('E', (0, 0), (0, 30), label=label)
        command = self.geda_writer._create_pin(1, pin)

        self.assertEquals(command, [
            'P 0 300 0 0 1 0 0', '{', 'T 100 0 5 10 1 1 270 0 1',
            'pinlabel=p1', 'T 100 400 5 10 0 1 0 0 1', 'pinseq=1',
            'T 100 500 5 10 0 1 0 0 1', 'pinnumber=E', '}'
        ])