From 2400ff8e5fea41c1f8c6251d37a02209ec253f93 Mon Sep 17 00:00:00 2001 From: jaseg Date: Sat, 15 Apr 2023 17:09:20 +0200 Subject: cad: Add KiCad symbol/footprint parser --- gerbonara/cad/kicad/graphical_primitives.py | 111 ++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 gerbonara/cad/kicad/graphical_primitives.py (limited to 'gerbonara/cad/kicad/graphical_primitives.py') diff --git a/gerbonara/cad/kicad/graphical_primitives.py b/gerbonara/cad/kicad/graphical_primitives.py new file mode 100644 index 0000000..391b38b --- /dev/null +++ b/gerbonara/cad/kicad/graphical_primitives.py @@ -0,0 +1,111 @@ + +from .sexp import * +from .base_types import * +from .primitives import * + +@sexp_type('layer') +class TextLayer: + layer: str = '' + knockout: Flag() = False + + +@sexp_type('gr_text') +class Text: + text: str = '' + at: AtPos = field(default_factory=AtPos) + layer: TextLayer = field(default_factory=TextLayer) + tstamp: Timestamp = None + effects: TextEffect = field(default_factory=TextEffect) + + +@sexp_type('gr_text_box') +class TextBox: + locked: Flag() = False + text: str = '' + start: Named(XYCoord) = None + end: Named(XYCoord) = None + pts: PointList = field(default_factory=PointList) + angle: OmitDefault(Named(float)) = 0.0 + layer: Named(str) = "" + tstamp: Timestamp = None + effects: TextEffect = field(default_factory=TextEffect) + stroke: Stroke = field(default_factory=Stroke) + render_cache: RenderCache = None + + +@sexp_type('gr_line') +class Line: + start: Rename(XYCoord) = None + end: Rename(XYCoord) = None + angle: Named(float) = None + layer: Named(str) = None + width: Named(float) = None + tstamp: Timestamp = None + + +@sexp_type('fill') +class FillMode: + # Needed for compatibility with weird files + fill: AtomChoice(Atom.solid, Atom.yes, Atom.no, Atom.none) = False + + @classmethod + def __map__(self, obj, parent=None): + return obj[0] in (Atom.solid, Atom.yes) + + @classmethod + def __sexp__(self, value): + yield [Atom.fill, Atom.solid if value else Atom.none] + +@sexp_type('gr_rect') +class Rectangle: + start: Rename(XYCoord) = None + end: Rename(XYCoord) = None + layer: Named(str) = None + width: Named(float) = None + fill: FillMode = False + tstamp: Timestamp = None + + +@sexp_type('gr_circle') +class Circle: + center: Rename(XYCoord) = None + end: Rename(XYCoord) = None + layer: Named(str) = None + width: Named(float) = None + fill: FillMode = False + tstamp: Timestamp = None + + +@sexp_type('gr_arc') +class Arc: + start: Rename(XYCoord) = None + mid: Rename(XYCoord) = None + end: Rename(XYCoord) = None + layer: Named(str) = None + width: Named(float) = None + tstamp: Timestamp = None + + +@sexp_type('gr_poly') +class Polygon: + pts: PointList = field(default_factory=PointList) + layer: Named(str) = None + width: Named(float) = None + fill: FillMode= False + tstamp: Timestamp = None + + +@sexp_type('gr_curve') +class Curve: + pts: PointList = field(default_factory=PointList) + layer: Named(str) = None + width: Named(float) = None + tstamp: Timestamp = None + + +@sexp_type('gr_bbox') +class AnnotationBBox: + start: Rename(XYCoord) = None + end: Rename(XYCoord) = None + + -- cgit