summaryrefslogtreecommitdiff
path: root/gerbonara
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2024-07-19 19:20:09 +0200
committerjaseg <git@jaseg.de>2024-07-19 19:20:09 +0200
commitbe25b860a975a3a65fc9e434aac332950ace83bb (patch)
treea1ad470ef56079ba30782f5369a5c6500373f813 /gerbonara
parente42b7462c971830367586bc886bcc3225edfc678 (diff)
downloadgerbonara-be25b860a975a3a65fc9e434aac332950ace83bb.tar.gz
gerbonara-be25b860a975a3a65fc9e434aac332950ace83bb.tar.bz2
gerbonara-be25b860a975a3a65fc9e434aac332950ace83bb.zip
kicad: Improve net access
This adds net_name and net_index properties to a bunch of objects that automatically look into the (net s-expr of the object
Diffstat (limited to 'gerbonara')
-rw-r--r--gerbonara/cad/kicad/base_types.py23
-rw-r--r--gerbonara/cad/kicad/footprints.py14
-rw-r--r--gerbonara/cad/kicad/pcb.py6
3 files changed, 29 insertions, 14 deletions
diff --git a/gerbonara/cad/kicad/base_types.py b/gerbonara/cad/kicad/base_types.py
index 358aab7..d800a36 100644
--- a/gerbonara/cad/kicad/base_types.py
+++ b/gerbonara/cad/kicad/base_types.py
@@ -307,6 +307,29 @@ class ArcPointList:
yield [kls.name_atom, *(e for elem in value for e in elem.__sexp__(elem))]
+@sexp_type('net')
+class Net:
+ index: int = 0
+ name: str = ''
+
+
+class NetMixin:
+ def reset_net(self):
+ self.net = Net()
+
+ @property
+ def net_index(self):
+ if self.net is None:
+ return 0
+ return self.net.index
+
+ @property
+ def net_name(self):
+ if self.net is None:
+ return ''
+ return self.net.name
+
+
@sexp_type('xyz')
class XYZCoord:
x: float = 0
diff --git a/gerbonara/cad/kicad/footprints.py b/gerbonara/cad/kicad/footprints.py
index c7bc973..c1655e7 100644
--- a/gerbonara/cad/kicad/footprints.py
+++ b/gerbonara/cad/kicad/footprints.py
@@ -334,12 +334,6 @@ class Drill:
offset: Rename(XYCoord) = None
-@sexp_type('net')
-class NetDef:
- number: int = None
- name: str = None
-
-
@sexp_type('options')
class CustomPadOptions:
clearance: Named(AtomChoice(Atom.outline, Atom.convexhull)) = Atom.outline
@@ -376,7 +370,7 @@ class Chamfer:
@sexp_type('pad')
-class Pad:
+class Pad(NetMixin):
number: str = None
type: AtomChoice(Atom.thru_hole, Atom.smd, Atom.connect, Atom.np_thru_hole) = None
shape: AtomChoice(Atom.circle, Atom.rect, Atom.oval, Atom.trapezoid, Atom.roundrect, Atom.custom) = None
@@ -395,7 +389,7 @@ class Pad:
thermal_bridge_width: Named(float) = 0.5
chamfer_ratio: Named(float) = None
chamfer: Chamfer = None
- net: NetDef = None
+ net: Net = None
tstamp: Timestamp = None
pin_function: Named(str) = None
pintype: Named(str) = None
@@ -709,6 +703,10 @@ class Footprint:
if not self.property_value('Description', None):
self.set_property('Description', self.descr or '', 0, 0, 0)
+ def reset_nets(self):
+ for pad in self.pads:
+ pad.reset_net()
+
@property
def pads_by_number(self):
return {(int(pad.number) if pad.number.isnumeric() else pad.number): pad for pad in self.pads if pad.number}
diff --git a/gerbonara/cad/kicad/pcb.py b/gerbonara/cad/kicad/pcb.py
index 11abf3c..fce4d0e 100644
--- a/gerbonara/cad/kicad/pcb.py
+++ b/gerbonara/cad/kicad/pcb.py
@@ -150,12 +150,6 @@ class BoardSetup:
export_settings: ExportSettings = field(default_factory=ExportSettings)
-@sexp_type('net')
-class Net:
- index: int = 0
- name: str = ''
-
-
@sexp_type('segment')
class TrackSegment(BBoxMixin):
start: Rename(XYCoord) = field(default_factory=XYCoord)