askiff.gritems.GrItem¶
- class askiff.gritems.GrItem¶
Bases:
askiff._auto_serde.AutoSerdeDownCastingAgg
Base class for KiCad graphic items, providing shared serde logic for PCB and schematic graphics.
Do not use directly, use specific subclasses like GrLinePCB, GrCirclePCB, etc.
During deserialization step askiff attempts to downcast each graphic object to the most specific of child classes.
Multi level inheritance of graphic items works nicely for fine grained filtration of objects:
isinstance(item, GrItem) - all kind of graphics (PCB, schematic, footprint, symbol)
isinstance(item, GrItemPCB) - only Graphic items on PCB
isinstance(item, GrShapePCB) - only Graphic primitive shapes on PCB (e.g. circles, rectangles), inherits also from
askiff.common.BaseShapeisinstance(item, GrRectPCB) - only rectangles on PCB
Naming Scheme:
Gr Rect PCB -> graphic object type, e.g. rectangle, circle, image, text, …
- GrRect PCB -> target flavour (ensure that assigned flavour matches type hint in target structure)
Sch - item for usage in schematics, inherits
askiff.gritems.GrItemSchSym - item for usage in symbols, inherits
askiff.gritems.GrItemSymPCB - item for usage in board files, inherits
askiff.gritems.GrItemPCBFp - item for usage in footprints, inherits
askiff.gritems.GrItemFp
Examples
>>> # Get all rectangles in footprint >>> rectangles = (g for g in footprint.graphic_items if isinstance(g, GrRectFp))- classmethod deserialize(sexp: askiff._sexpr.GeneralizedSexpr) Self¶
Deserializes a KiCad sexpr representation into an object instance. :Parameters: sexp – pre-parsed S-Expression AST
- Returns:
Deserialized structure
- Parameters:
- sexp : askiff._sexpr.GeneralizedSexpr¶
- Return type:
Self
Notes
Uses _AutoSerde__deser_field* tables for efficient lookup how to deserialize encountered objects
Places unrecognized field in __extra/__extra_positional and issues warning
Encountered str objects are processed as positional or bare-flag components
Tuples are processed as normal args treating first object as keyword identifying target field
- classmethod deserialize_downcast_agg(sexp: askiff._sexpr.GeneralizedSexpr) Self¶
Deserializes a sexpr into an instance of the class or one of its downcast subclasses
- Parameters:
- sexp : askiff._sexpr.GeneralizedSexpr¶
- Return type:
Self
- serialize() askiff._sexpr.GeneralizedSexpr¶
Serializes the object into a S-Expression AST
Fields are processed in order: __ser_field_positional, __extra_positional, __ser_field & __extra
- Return type:
askiff._sexpr.GeneralizedSexpr