Sun, 10 Dec 2017 15:46:47 +0200
Moved the parsing function into a new file
0 | 1 | class EmptyLine: |
2 | def __repr__(self): | |
3 | return 'linetypes.EmptyLine()' | |
4 | ||
5 | class Comment: | |
6 | def __init__(self, text, style = 'old'): | |
7 | if style == 'old' and text.startswith('//'): | |
8 | self.text = text[3:].strip() | |
9 | self.style = 'new' | |
10 | else: | |
11 | self.text = text | |
12 | self.style = style | |
13 | def __repr__(self): | |
14 | return str.format('linetypes.Comment({text!r}, {style!r})', | |
15 | text = self.text, | |
16 | style = self.style, | |
17 | ) | |
18 | ||
19 | class SubfileReference: | |
20 | def __init__(self, *, color, subfile_path, anchor, matrix): | |
21 | self.color, self.subfile_path, = color, subfile_path | |
22 | self.anchor, self.matrix = anchor, matrix | |
23 | def __repr__(self): | |
24 | return str.format('linetypes.SubfileReference(' \ | |
25 | 'color = {color!r}, ' \ | |
26 | 'subfile_path = {subfile_path!r}, ' \ | |
27 | 'anchor = {anchor!r}, ' \ | |
28 | 'matrix = {matrix!r})', **self.__dict__) | |
29 | ||
30 | class LineSegment: | |
31 | def __init__(self, *, color, geometry): | |
32 | self.color, self.geometry = color, geometry | |
33 | def __repr__(self): | |
34 | return str.format('linetypes.{typename}(' \ | |
35 | 'color = {color!r}, ' \ | |
36 | 'geometry = {geometry!r})', | |
37 | typename = type(self).__name__, | |
38 | color = self.color, | |
39 | geometry = self.geometry, | |
40 | ) | |
41 | ||
42 | class Triangle(LineSegment): | |
43 | pass | |
44 | ||
45 | class Quadrilateral(LineSegment): | |
46 | pass | |
1 | 47 | |
48 | class Contour(LineSegment): | |
49 | def __init__(self, *, color, geometry, control_points): | |
50 | super().__init__(color = color, geometry = geometry) | |
51 | self.control_points = control_points | |
52 | assert(len(self.control_points) == 2) | |
53 | def __repr__(self): | |
54 | return str.format('linetypes.Contour(' \ | |
55 | 'color = {color!r}, ' \ | |
56 | 'geometry = {geometry!r}, ' \ | |
57 | 'control_points = {control_points!r})', **self.__dict__) |