| 1 |
from dataclasses import dataclass |
| 2 |
|
| 3 |
|
| 4 |
@dataclass |
| 5 |
class Node: |
| 6 |
x: int = 0 |
| 7 |
y: int = 0 |
| 8 |
type: str = "c" |
| 9 |
userdata: str = None |
| 10 |
|
| 11 |
_to_pen_type = {"o": None, "c": "curve", "l": "line", "q": "qcurve"} |
| 12 |
_from_pen_type = {v: k for k, v in _to_pen_type.items()} |
| 13 |
|
| 14 |
def write(self, stream, indent): |
| 15 |
if not self.userdata: |
| 16 |
stream.write(('[%i,%i,"%s"]' % (self.x, self.y, self.type)).encode()) |
| 17 |
else: |
| 18 |
stream.write( |
| 19 |
( |
| 20 |
'[%i,%i,"%s", "%s"]' % (self.x, self.y, self.type, self.userdata) |
| 21 |
).encode() |
| 22 |
) |
| 23 |
|
| 24 |
@property |
| 25 |
def is_smooth(self): |
| 26 |
return self.type.endswith("s") |
| 27 |
|
| 28 |
@property |
| 29 |
def pen_type(self): |
| 30 |
return self._to_pen_type[self.type[0]] |