summaryrefslogtreecommitdiff
path: root/gerbonara/cad/kicad
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2023-07-21 13:27:02 +0200
committerjaseg <git@jaseg.de>2023-07-21 13:27:02 +0200
commita39af853c833c524a43b8a953cce60e07bb14dfb (patch)
tree17089a9a59b3c9a5cec290af463f4ce8d5dce367 /gerbonara/cad/kicad
parentb69e9fded4d3c135e4b729a2c2bca247a9ebda82 (diff)
downloadgerbonara-a39af853c833c524a43b8a953cce60e07bb14dfb.tar.gz
gerbonara-a39af853c833c524a43b8a953cce60e07bb14dfb.tar.bz2
gerbonara-a39af853c833c524a43b8a953cce60e07bb14dfb.zip
Schematics WIP
Diffstat (limited to 'gerbonara/cad/kicad')
-rw-r--r--gerbonara/cad/kicad/base_types.py15
-rw-r--r--gerbonara/cad/kicad/symbols.py90
2 files changed, 56 insertions, 49 deletions
diff --git a/gerbonara/cad/kicad/base_types.py b/gerbonara/cad/kicad/base_types.py
index d29586e..3d0b0c4 100644
--- a/gerbonara/cad/kicad/base_types.py
+++ b/gerbonara/cad/kicad/base_types.py
@@ -270,6 +270,20 @@ class Justify:
v: AtomChoice(Atom.top, Atom.bottom) = None
mirror: Flag() = False
+ @property
+ def h_str(self):
+ if self.h is None:
+ return 'center'
+ else:
+ return str(self.h)
+
+ @property
+ def v_str(self):
+ if self.v is None:
+ return 'middle'
+ else:
+ return str(self.v)
+
@sexp_type('effects')
class TextEffect:
@@ -277,6 +291,7 @@ class TextEffect:
hide: Flag() = False
justify: OmitDefault(Justify) = field(default_factory=Justify)
+
class TextMixin:
@property
def size(self):
diff --git a/gerbonara/cad/kicad/symbols.py b/gerbonara/cad/kicad/symbols.py
index 4767b88..94d30d3 100644
--- a/gerbonara/cad/kicad/symbols.py
+++ b/gerbonara/cad/kicad/symbols.py
@@ -54,6 +54,11 @@ class Pin:
name: Rename(StyledText) = field(default_factory=StyledText)
number: Rename(StyledText) = field(default_factory=StyledText)
alternates: List(AltFunction) = field(default_factory=list)
+ _: SEXP_END = None
+ unit: object = None
+
+ def __after_parse__(self, parent=None):
+ self.unit = parent
@property
def direction(self):
@@ -96,6 +101,9 @@ class Pin:
return (x1, y1), (x2, y2)
def to_svg(self, colorscheme=Colorscheme.KiCad):
+ if self.hide:
+ return
+
x1, y1 = 0, 0
x2, y2 = self.length, 0
xform = {'transform': f'translate({self.at.x:.3f} {self.at.y:.3f}) rotate({self.at.rotation})'}
@@ -109,68 +117,52 @@ class Pin:
'inverted': [
Tag('circle', **xform, **style, cx=x2-eps/3-0.2, cy=y2, r=eps/3)],
'clock': [
- Tag('path', **xform, **style, d=f'M {x2} {y2-eps/2} L {x2+eps/2} {y2} L {x2} {y2+eps/2}')], # NOQA: E501
+ Tag('path', **xform, **style, d=f'M {x2} {y2-eps/2} L {x2+eps/2} {y2} L {x2} {y2+eps/2}')],
'inverted_clock': [
Tag('circle', **xform, **style, cx=x2-eps/3-0.2, cy=y2, r=eps/3),
- Tag('path', **xform, **style, d=f'M {x2} {y2-eps/2} L {x2+eps/2} {y2} L {x2} {y2+eps/2}')], # NOQA: E501
+ Tag('path', **xform, **style, d=f'M {x2} {y2-eps/2} L {x2+eps/2} {y2} L {x2} {y2+eps/2}')],
'input_low': [
- Tag('path', **xform, **style, d=f'M {x2} {y2} L {x2-eps} {y2-eps} L {x2-eps} {y2}')], # NOQA: E501
+ Tag('path', **xform, **style, d=f'M {x2} {y2} L {x2-eps} {y2-eps} L {x2-eps} {y2}')],
'clock_low': [
- Tag('path', **xform, **style, d=f'M {x2} {y2} L {x2-eps} {y2-eps} L {x2-eps} {y2}'), # NOQA: E501
- Tag('path', **xform, **style, d=f'M {x2} {y2-eps/2} L {x2+eps/2} {y2} L {x2} {y2+eps/2}')], # NOQA: E501
+ Tag('path', **xform, **style, d=f'M {x2} {y2} L {x2-eps} {y2-eps} L {x2-eps} {y2}'),
+ Tag('path', **xform, **style, d=f'M {x2} {y2-eps/2} L {x2+eps/2} {y2} L {x2} {y2+eps/2}')],
'output_low': [
- Tag('path', **xform, **style, d=f'M {x2} {y2-eps} L {x2-eps} {y2}')], # NOQA: E501
+ Tag('path', **xform, **style, d=f'M {x2} {y2-eps} L {x2-eps} {y2}')],
'edge_clock_high': [
- Tag('path', **xform, **style, d=f'M {x2} {y2} L {x2-eps} {y2-eps} L {x2-eps} {y2}'), # NOQA: E501
- Tag('path', **xform, **style, d=f'M {x2} {y2-eps/2} L {x2+eps/2} {y2} L {x2} {y2+eps/2}')], # NOQA: E501
+ Tag('path', **xform, **style, d=f'M {x2} {y2} L {x2-eps} {y2-eps} L {x2-eps} {y2}'),
+ Tag('path', **xform, **style, d=f'M {x2} {y2-eps/2} L {x2+eps/2} {y2} L {x2} {y2+eps/2}')],
'non_logic': [
- Tag('path', **xform, **style, d=f'M {x2-eps/2} {y2-eps/2} L {x2+eps/2} {y2+eps/2}'), # NOQA: E501
- Tag('path', **xform, **style, d=f'M {x2-eps/2} {y2+eps/2} L {x2+eps/2} {y2-eps/2}')], # NOQA: E501
+ Tag('path', **xform, **style, d=f'M {x2-eps/2} {y2-eps/2} L {x2+eps/2} {y2+eps/2}'),
+ Tag('path', **xform, **style, d=f'M {x2-eps/2} {y2+eps/2} L {x2+eps/2} {y2-eps/2}')],
# FIXME...
}.get(self.style, []):
yield tag
- if self.at.rotation in (90, 270):
- t_rot = 90
- else:
- t_rot = 0
-
- size = self.name.effects.font.size.y or 1.27
font = Newstroke.load()
- strokes = list(font.render(self.name.value, size=size))
- min_x = min(x for st in strokes for x, y in st) if strokes else 0
- min_y = min(y for st in strokes for x, y in st) if strokes else 0
- max_x = max(x for st in strokes for x, y in st) if strokes else 0
- max_y = max(y for st in strokes for x, y in st) if strokes else 0
- w = max_x - min_x
- h = max_y - min_y
-
- if self.at.rotation == 0:
- offx = -min_x + self.length + 0.2
- offy = h/2
- elif self.at.rotation == 180:
- offx = min_x - self.length - 0.2 - w
- offy = h/2
- elif self.at.rotation == 90:
- offx = -h/2
- offy = min_x - self.length - 0.2 - w
- elif self.at.rotation == 270:
- offx = -h/2
- offy = -min_x + self.length + 0.2
- else:
- raise ValueError(f'Invalid pin rotation {self.at.rotation}')
+ if self.name.value != '~' and not self.unit.symbol.pin_names.hide:
+ yield font.render_svg(self.name.value,
+ size=self.name.effects.font.size.y or 1.27,
+ x0=self.length + 0.2,
+ y0=0,
+ h_align='left',
+ v_align='middle',
+ rotation=self.at.rotation,
+ stroke=colorscheme.text,
+ transform=f'translate({self.at.x:.3f} {self.at.y:.3f})',
+ )
+
+ if self.number.value != '~' and not self.unit.symbol.pin_numbers.hide:
+ yield font.render_svg(self.number.value,
+ size=self.number.effects.font.size.y or 1.27,
+ x0=self.length-0.2,
+ y0=0.4,
+ h_align='right',
+ v_align='bottom',
+ rotation=self.at.rotation,
+ stroke=colorscheme.text,
+ transform=f'translate({self.at.x:.3f} {self.at.y:.3f})',
+ )
- d = []
- for stroke in strokes:
- points = []
- for x, y in stroke:
- x, y = x+offx, y+offy
- x, y = rotate_point(x, y, math.radians(self.at.rotation or 0))
- x, y = x+self.at.x, y+self.at.y
- points.append(f'{x:.3f} {y:.3f}')
- d.append('M '+ ' L '.join(points) + ' ')
- yield Tag('path', d=' '.join(d), fill='none', stroke=colorscheme.text, stroke_width='0.254', stroke_linecap='round', stroke_linejoin='round')
- print('name', self.name.value)
@sexp_type('fill')