linetypes.py

changeset 7
0ab0d61ccee8
parent 4
8eb83f200486
child 35
865cd526e8b6
equal deleted inserted replaced
6:6da1e81c5652 7:0ab0d61ccee8
11 class EmptyLine: 11 class EmptyLine:
12 def __repr__(self): 12 def __repr__(self):
13 return 'linetypes.EmptyLine()' 13 return 'linetypes.EmptyLine()'
14 def textual_representation(self): 14 def textual_representation(self):
15 return '' 15 return ''
16 def typename(self):
17 return 'empty line'
16 18
17 class Comment: 19 class Comment:
18 def __init__(self, text, style = 'old'): 20 def __init__(self, text, style = 'old'):
19 if style == 'old' and text.startswith('//'): 21 if style == 'old' and text.startswith('//'):
20 self.text = text[2:].strip() 22 self.text = text[2:].strip()
30 def textual_representation(self): 32 def textual_representation(self):
31 if self.style == 'old': 33 if self.style == 'old':
32 return '0 ' + self.text 34 return '0 ' + self.text
33 else: 35 else:
34 return '0 // ' + self.text 36 return '0 // ' + self.text
37 def typename(self):
38 return 'comment'
35 39
36 class SubfileReference: 40 class SubfileReference:
37 def __init__(self, *, colour, subfile_path, anchor, matrix): 41 def __init__(self, *, colour, subfile_path, anchor, matrix):
38 self.colour, self.subfile_path, = colour, subfile_path 42 self.colour, self.subfile_path, = colour, subfile_path
39 self.anchor, self.matrix = anchor, matrix 43 self.anchor, self.matrix = anchor, matrix
50 *self.anchor.coordinates, 54 *self.anchor.coordinates,
51 *self.matrix.values, 55 *self.matrix.values,
52 self.subfile_path, 56 self.subfile_path,
53 ] 57 ]
54 return ' '.join(ldraw_str(arg) for arg in args) 58 return ' '.join(ldraw_str(arg) for arg in args)
59 def typename(self):
60 return 'subfile reference'
55 61
56 class BasePolygon: 62 class BasePolygon:
57 def __init__(self, *, colour, geometry): 63 def __init__(self, *, colour, geometry):
58 self.colour, self.geometry = colour, geometry 64 self.colour, self.geometry = colour, geometry
59 def __repr__(self): 65 def __repr__(self):
71 return ' '.join(ldraw_str(arg) for arg in args) 77 return ' '.join(ldraw_str(arg) for arg in args)
72 78
73 class LineSegment(BasePolygon): 79 class LineSegment(BasePolygon):
74 def textual_representation(self): 80 def textual_representation(self):
75 return '2 ' + self.base_textual_representation() 81 return '2 ' + self.base_textual_representation()
82 def typename(self):
83 return 'line segment'
76 84
77 class Triangle(BasePolygon): 85 class Triangle(BasePolygon):
78 def textual_representation(self): 86 def textual_representation(self):
79 return '3 ' + self.base_textual_representation() 87 return '3 ' + self.base_textual_representation()
88 def typename(self):
89 return 'triangle'
80 90
81 class Quadrilateral(BasePolygon): 91 class Quadrilateral(BasePolygon):
82 def textual_representation(self): 92 def textual_representation(self):
83 return '4 ' + self.base_textual_representation() 93 return '4 ' + self.base_textual_representation()
94 def typename(self):
95 return 'quadrilateral'
84 96
85 class Contour(LineSegment): 97 class Contour(LineSegment):
86 def __init__(self, *, colour, geometry, control_points): 98 def __init__(self, *, colour, geometry, control_points):
87 super().__init__(colour = colour, geometry = geometry) 99 super().__init__(colour = colour, geometry = geometry)
88 self.control_points = control_points 100 self.control_points = control_points
97 for control_point in self.control_points: 109 for control_point in self.control_points:
98 strings = (ldraw_str(value) for value in control_point.coordinates) 110 strings = (ldraw_str(value) for value in control_point.coordinates)
99 result += ' ' 111 result += ' '
100 result += ' '.join(strings) 112 result += ' '.join(strings)
101 return result 113 return result
114 def typename(self):
115 return 'contour line segment'

mercurial