summaryrefslogtreecommitdiff
path: root/gerbonara/cad/kicad
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2023-04-15 22:12:45 +0200
committerjaseg <git@jaseg.de>2023-04-15 22:12:45 +0200
commit4bd1097fc1e161e1c0ecfdfa2be271dfe6f69dfa (patch)
treec6849e1c877366731adda92308599d50907b8947 /gerbonara/cad/kicad
parent3556dc081be6f5cca5f4bea2b3c09e4c9c1a66a8 (diff)
downloadgerbonara-4bd1097fc1e161e1c0ecfdfa2be271dfe6f69dfa.tar.gz
gerbonara-4bd1097fc1e161e1c0ecfdfa2be271dfe6f69dfa.tar.bz2
gerbonara-4bd1097fc1e161e1c0ecfdfa2be271dfe6f69dfa.zip
Bump minimum Python version to 3.10
Diffstat (limited to 'gerbonara/cad/kicad')
-rw-r--r--gerbonara/cad/kicad/base_types.py45
1 files changed, 38 insertions, 7 deletions
diff --git a/gerbonara/cad/kicad/base_types.py b/gerbonara/cad/kicad/base_types.py
index 840b9d5..54437f5 100644
--- a/gerbonara/cad/kicad/base_types.py
+++ b/gerbonara/cad/kicad/base_types.py
@@ -5,6 +5,8 @@ import time
from dataclasses import field
import math
import uuid
+from contextlib import contextmanager
+from itertools import cycle
@sexp_type('color')
@@ -20,14 +22,43 @@ class Stroke:
width: Named(float) = 0.254
type: Named(AtomChoice(Atom.dash, Atom.dot, Atom.dash_dot_dot, Atom.dash_dot, Atom.default, Atom.solid)) = Atom.default
color: Color = None
+
+
+class Dasher:
+ def __init__(self, stroke):
+ self.width = stroke.width
+ gap = 4*stroke.width
+ dot = 0
+ gap = 11*stroke.width
+ self.pattern = {
+ Atom.dash: [dash, gap],
+ Atom.dot: [dot, gap],
+ Atom.dash_dot_dot: [dash, gap, dot, gap, dot, gap],
+ Atom.dash_dot: [dash, gap, dot, gap],
+ Atom.default: [1e99],
+ Atom.solid: [1e99]}[stroke.type]
+ self.start_x, self.start_y = None, None
+ self.cur_x, self.cur_y = None, None
+ self.segments = []
+
+ def move(self, x, y):
+ self.start_x, self.start_y = x, y
+
+ def line(x, y):
+ if x is None or y is None:
+ raise ValueError('line() called before move()')
+ self.segments.append((self.cur_x, self.cur_y, x, y))
+ cur_x, cur_y = x, y
+
+ def close():
+ self.segments.append((self.cur_x, self.cur_y, start_x, start_y))
+
+ def __iter__(self):
+ offset = 0
+ for length, stroked in cycle(zip(self.pattern, cycle([True, False]))):
+ for x1, y1, x2, y2 in segments:
+ segment_length = math.dist((x1, y1), (x2, y2))
- @property
- def width_mil(self):
- return mm_to_mil(self.width)
-
- @width_mil.setter
- def width_mil(self, value):
- self.width = mil_to_mm(value)
@sexp_type('xy')