def update_from_string(self, string):
        """Update options from a standard radiance string.

        If the option is not currently part of the collection, it will be added to
        additional_options.
        """
        slots = self.slots
        opt_dict = cutil.parse_radiance_options(string)
        for p, v in opt_dict.items():
            if '_%s' % p in slots:
                setattr(self, p, v)
            else:
                if len(p) > 1:
                    # joined string
                    # catch special case -fio
                    try:
                        if p.startswith('f') and '_fio' in slots:
                            setattr(self, 'fio', p[1:])
                        else:
                            setattr(self, p[1], p[1:])
                    except AttributeError:
                        # fall back to unknown item
                        pass
                    else:
                        # it is assigned - go for the next one
                        continue
                warnings.warn('"%s" is a non-standard option for %s.' %
                              (p, self.__class__.__name__))
                # add to additional options
                self.additional_options[p] = v
Ejemplo n.º 2
0
def test_import_from_string():
    """Test import options form a string."""
    options = cutil.parse_radiance_options(
        '-dj   20  -fo -dc 1 -ab 16    -lw 1e-8')

    assert options['dj'] == '20'
    assert options['fo'] == ''
    assert options['dc'] == '1'
    assert options['ab'] == '16'
    assert options['lw'] == '1e-8'
Ejemplo n.º 3
0
    def from_string(cls, identifier, view_string):
        """Create a view object from a string.

        This method is similar to from_string method for radiance parameters with the
        difference that all the parameters that are not related to view will be ignored.
        """
        mapper = {
            'identifier': identifier,
            'vp': 'position',
            'vd': 'direction',
            'vu': 'up_vector',
            'vh': 'h_size',
            'vv': 'v_size',
            'vs': 'shift',
            'vl': 'lift',
            'vo': 'fore_clip',
            'va': 'aft_clip'
        }

        base = {
            'type': 'View',
            'identifier': identifier,
            'position': None,
            'direction': None,
            'up_vector': None,
            'h_size': None,
            'v_size': None,
            'shift': None,
            'lift': None,
            'view_type': None,
            'fore_clip': None,
            'aft_clip': None
        }

        # parse the string here
        options = parse_radiance_options(view_string)

        for opt, value in options.items():
            if opt in mapper:
                base[mapper[opt]] = value
            elif opt[:2] == 'vt':
                base['view_type'] = opt
            else:
                print('%s is not a view parameter and is ignored.' % opt)

        return cls.from_dict(base)
Ejemplo n.º 4
0
def test_import_view_from_string():
    """Test import options form a string."""
    view = 'rvu -vtv -vp 0.000 0.000 0.000 -vd 0.000 0.000 1.000 ' \
        '-vu 0.000 1.000 0.000 -vh 29.341 -vv 32.204 -x 300 -y 300 ' \
        '-vs -0.500 -vl -0.500 -vo 100.000'

    options = cutil.parse_radiance_options(view)

    assert 'rvu' not in options
    assert options['vtv'] == ''
    assert options['vp'] == ['0.000', '0.000', '0.000']
    assert options['vd'] == ['0.000', '0.000', '1.000']
    assert options['vu'] == ['0.000', '1.000', '0.000']
    assert options['vh'] == '29.341'
    assert options['vv'] == '32.204'
    assert options['x'] == '300'
    assert options['y'] == '300'
    assert options['vs'] == '-0.500'
    assert options['vl'] == '-0.500'
    assert options['vo'] == '100.000'
Ejemplo n.º 5
0
def test_quotes():
    options = parse_radiance_options('" "')
    assert options == {}
Ejemplo n.º 6
0
def test_empty_string():
    options = parse_radiance_options(' ')
    assert options == {}
Ejemplo n.º 7
0
def test_single_quotes():
    options = parse_radiance_options("' ' ")
    assert options == {}