linetypes.py

changeset 91
c71a7d863c2e
parent 38
66c9591b733d
equal deleted inserted replaced
90:6ae063fd27dc 91:c71a7d863c2e
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'
18 16
19 class MetaCommand: 17 class MetaCommand:
20 def __init__(self, text, style = 'old'): 18 def __init__(self, text, style = 'old'):
21 self.text = text 19 self.text = text
22 def __repr__(self): 20 def __repr__(self):
23 return str.format('linetypes.MetaCommand({text!r})', 21 return str.format('linetypes.MetaCommand({text!r})',
24 text = self.text, 22 text = self.text,
25 ) 23 )
26 def textual_representation(self): 24 def textual_representation(self):
27 return ('0 ' + self.text).strip() 25 return ('0 ' + self.text).strip()
28 def typename(self):
29 return 'metacommand'
30 26
31 class Comment: 27 class Comment:
32 def __init__(self, text, style = 'old'): 28 def __init__(self, text, style = 'old'):
33 self.text = text 29 self.text = text
34 def __repr__(self): 30 def __repr__(self):
35 return str.format('linetypes.Comment({text!r})', 31 return str.format('linetypes.Comment({text!r})',
36 text = self.text, 32 text = self.text,
37 ) 33 )
38 def textual_representation(self): 34 def textual_representation(self):
39 return '0 //' + self.text 35 return '0 //' + self.text
40 def typename(self):
41 return 'comment'
42 36
43 class SubfileReference: 37 class SubfileReference:
44 def __init__(self, *, colour, subfile_path, anchor, matrix): 38 def __init__(self, *, colour, subfile_path, anchor, matrix):
45 self.colour, self.subfile_path, = colour, subfile_path 39 self.colour, self.subfile_path, = colour, subfile_path
46 self.anchor, self.matrix = anchor, matrix 40 self.anchor, self.matrix = anchor, matrix
57 *self.anchor.coordinates, 51 *self.anchor.coordinates,
58 *self.matrix.values, 52 *self.matrix.values,
59 self.subfile_path, 53 self.subfile_path,
60 ] 54 ]
61 return ' '.join(ldraw_str(arg) for arg in args) 55 return ' '.join(ldraw_str(arg) for arg in args)
62 def typename(self):
63 return 'subfile reference'
64 56
65 class BasePolygon: 57 class BasePolygon:
66 def __init__(self, *, colour, geometry): 58 def __init__(self, *, colour, geometry):
67 self.colour, self.geometry = colour, geometry 59 self.colour, self.geometry = colour, geometry
68 def __repr__(self): 60 def __repr__(self):
80 return ' '.join(ldraw_str(arg) for arg in args) 72 return ' '.join(ldraw_str(arg) for arg in args)
81 73
82 class LineSegment(BasePolygon): 74 class LineSegment(BasePolygon):
83 def textual_representation(self): 75 def textual_representation(self):
84 return '2 ' + self.base_textual_representation() 76 return '2 ' + self.base_textual_representation()
85 def typename(self):
86 return 'line segment'
87 77
88 class Triangle(BasePolygon): 78 class Triangle(BasePolygon):
89 def textual_representation(self): 79 def textual_representation(self):
90 return '3 ' + self.base_textual_representation() 80 return '3 ' + self.base_textual_representation()
91 def typename(self):
92 return 'triangle'
93 81
94 class Quadrilateral(BasePolygon): 82 class Quadrilateral(BasePolygon):
95 def textual_representation(self): 83 def textual_representation(self):
96 return '4 ' + self.base_textual_representation() 84 return '4 ' + self.base_textual_representation()
97 def typename(self):
98 return 'quadrilateral'
99 85
100 class ConditionalLine(LineSegment): 86 class ConditionalLine(LineSegment):
101 def __init__(self, *, colour, geometry, control_points): 87 def __init__(self, *, colour, geometry, control_points):
102 super().__init__(colour = colour, geometry = geometry) 88 super().__init__(colour = colour, geometry = geometry)
103 self.control_points = control_points 89 self.control_points = control_points
112 for control_point in self.control_points: 98 for control_point in self.control_points:
113 strings = (ldraw_str(value) for value in control_point.coordinates) 99 strings = (ldraw_str(value) for value in control_point.coordinates)
114 result += ' ' 100 result += ' '
115 result += ' '.join(strings) 101 result += ' '.join(strings)
116 return result 102 return result
117 def typename(self):
118 return 'contour line segment'
119 103
120 class Error: 104 class Error:
121 def __init__(self, line, reason): 105 def __init__(self, line, reason):
122 self.line = line 106 self.line = line
123 self.reason = reason 107 self.reason = reason

mercurial