Example #1
0
    def __getitem__(self, axis):
        """ Get coordinate for 'axis'.

        PARAMETER
            axis: 0, 1, 2 or 'x', 'y', 'z'
            axis: 'xz' returns a list of 'x' and 'z' any combination of 'x', 'y'
            and 'z' is valid, ('xyz', 'zyx', 'xxy', 'xxxxx')
        """
        if axis in (0, 1, 2):
            try:
                return self.point[axis].value
            except IndexError:
                raise IndexError("DXF-Point has no '%s'-coordinate!" %
                                 ('x', 'y', 'z')[axis])
        elif is_string(axis):
            if axis in ('x', 'y', 'z'):
                try:
                    index = ord(axis) - ord('x')
                    return self.point[index].value
                except IndexError:
                    raise IndexError("DXF-Point has no '%s'-coordinate!" %
                                     axis)
            elif len(axis) > 1:  # 'xy' or 'zx' get coords in letter order
                return [self.__getitem__(index) for index in axis]
            else:
                raise IndexError("Invalid axis name '%s'" % axis)
        else:
            raise IndexError("Invalid axis name '%s'" % axis)
Example #2
0
    def __getitem__(self, axis):
        """ Get coordinate for 'axis'.

        PARAMETER
            axis: 0, 1, 2 or 'x', 'y', 'z'
            axis: 'xz' returns a list of 'x' and 'z' any combination of 'x', 'y'
            and 'z' is valid, ('xyz', 'zyx', 'xxy', 'xxxxx')
        """
        if axis in (0, 1, 2):
            try:
                return self.point[axis].value
            except IndexError:
                raise IndexError("DXF-Point has no '%s'-coordinate!" % ('x', 'y', 'z')[axis])
        elif is_string(axis):
            if axis in ('x', 'y', 'z'):
                try:
                    index = ord(axis) - ord('x')
                    return self.point[index].value
                except IndexError:
                    raise IndexError("DXF-Point has no '%s'-coordinate!" % axis)
            elif len(axis) > 1: # 'xy' or 'zx' get coords in letter order
                return [ self.__getitem__(index) for index in axis ]
            else:
                raise IndexError("Invalid axis name '%s'" % axis)
        else:
            raise IndexError("Invalid axis name '%s'" % axis)
Example #3
0
 def check(self, value, code):
     try:
         typestr = self.group_code_type(code)
     except KeyError:
         raise ValueError("Unknown group code '%s'" % str(code))
     if typestr == 'string':
         return is_string(value)
     elif typestr == 'bool':
         return value in (0, 1)
     elif typestr == 'float':
         return isinstance(value, float)
     elif typestr == 'int':
         return isinstance(value, int)
Example #4
0
 def check(self, value, code):
     try:
         typestr = self.group_code_type(code)
     except KeyError:
         raise ValueError("Unknown group code '%s'" % str(code))
     if typestr == 'string':
         return is_string(value)
     elif typestr == 'bool':
         return value in (0, 1)
     elif typestr == 'float':
         return isinstance(value, float)
     elif typestr == 'int':
         return isinstance(value, int)
Example #5
0
 def test_atom_cast(self):
     atom = DXFAtom(1.0, 365) # string
     self.assertTrue(is_string(atom._value))
     atom = DXFString('', 1) # empty string
     self.assertEqual(atom._value, '')
     atom = DXFAtom('1.0', 210) # float
     self.assertTrue(isinstance(atom._value, float))
     atom = DXFAtom('7', 295) # bool
     self.assertEqual(atom._value, 1)
     atom = DXFAtom(1.77, 371) # int16
     self.assertTrue(isinstance(atom._value, int))
     self.assertEqual(atom._value, 1)
     atom = DXFAtom('177', 445) # int32
     self.assertTrue(isinstance(atom._value, int))
Example #6
0
 def test_atom_cast(self):
     atom = DXFAtom(1.0, 365)  # string
     self.assertTrue(is_string(atom._value))
     atom = DXFString('', 1)  # empty string
     self.assertEqual(atom._value, '')
     atom = DXFAtom('1.0', 210)  # float
     self.assertTrue(isinstance(atom._value, float))
     atom = DXFAtom('7', 295)  # bool
     self.assertEqual(atom._value, 1)
     atom = DXFAtom(1.77, 371)  # int16
     self.assertTrue(isinstance(atom._value, int))
     self.assertEqual(atom._value, 1)
     atom = DXFAtom('177', 445)  # int32
     self.assertTrue(isinstance(atom._value, int))
Example #7
0
 def test_drawing(self):
     dwg = dxf.drawing()
     res1 = dwg.__dxf__()
     self.assertTrue(is_string(res1))
Example #8
0
 def test_drawing(self):
     dwg = dxf.drawing()
     res1 = dwg.__dxf__()
     self.assertTrue(is_string(res1))