Skip to content

Commit 138ea7f

Browse files
committed
gritems: Add support for nets in graphical items
1 parent a536f7e commit 138ea7f

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

src/kiutils/items/gritems.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ class GrText:
6363
6464
Available since KiCad v7"""
6565

66+
net: Optional[int] = None
67+
"""The optional ``net`` token defines by net ordinal number which net in the net section that
68+
the graphical item is part of."""
69+
6670
@classmethod
6771
def from_sexpr(cls, exp: list) -> GrText:
6872
"""Convert the given S-Expresstion into a GrText object
@@ -106,6 +110,8 @@ def from_sexpr(cls, exp: list) -> GrText:
106110
object.tstamp = item[1] # Haha :)
107111
elif item[0] == "render_cache":
108112
object.renderCache = RenderCache.from_sexpr(item)
113+
elif item[0] == "net":
114+
object.net = item[1]
109115
else:
110116
raise ValueError(
111117
f"Unrecognized property key: {item[0]}. Full expression: {item}"
@@ -144,6 +150,9 @@ def _to_sexpr_raw(self):
144150
if layer:
145151
expr.append(layer)
146152

153+
if self.net is not None:
154+
expr.append(["net", self.net])
155+
147156
if self.tstamp is not None:
148157
expr.append(["uuid", quote(self.tstamp)])
149158

@@ -352,6 +361,10 @@ class GrLine:
352361
locked: bool = False
353362
"""The ``locked`` token defines if the object may be moved or not"""
354363

364+
net: Optional[int] = None
365+
"""The optional ``net`` token defines by net ordinal number which net in the net section that
366+
the graphical item is part of."""
367+
355368
@classmethod
356369
def from_sexpr(cls, exp: list) -> GrLine:
357370
"""Convert the given S-Expresstion into a GrLine object
@@ -394,6 +407,8 @@ def from_sexpr(cls, exp: list) -> GrLine:
394407
object.width = item[1]
395408
elif item[0] == "stroke":
396409
object.stroke = GrStroke().from_sexpr(item)
410+
elif item[0] == "net":
411+
object.net = item[1]
397412
else:
398413
raise ValueError(
399414
f"Unrecognized property key: {item[0]}. Full expression: {item}"
@@ -438,6 +453,9 @@ def _to_sexpr_raw(self):
438453
if self.layer is not None:
439454
expr.append(["layer", escape_and_quote(self.layer)])
440455

456+
if self.net is not None:
457+
expr.append(["net", self.net])
458+
441459
if self.tstamp is not None:
442460
expr.append(["uuid", quote(self.tstamp)])
443461

@@ -475,6 +493,10 @@ class GrRect:
475493
locked: bool = False
476494
"""The ``locked`` token defines if the object may be moved or not"""
477495

496+
net: Optional[int] = None
497+
"""The optional ``net`` token defines by net ordinal number which net in the net section that
498+
the graphical item is part of."""
499+
478500
@classmethod
479501
def from_sexpr(cls, exp: list) -> GrRect:
480502
"""Convert the given S-Expresstion into a GrRect object
@@ -519,6 +541,8 @@ def from_sexpr(cls, exp: list) -> GrRect:
519541
object.width = item[1]
520542
elif item[0] == "stroke":
521543
object.stroke = GrStroke().from_sexpr(item)
544+
elif item[0] == "net":
545+
object.net = item[1]
522546
else:
523547
raise ValueError(
524548
f"Unrecognized property key: {item[0]}. Full expression: {item}"
@@ -564,6 +588,9 @@ def _to_sexpr_raw(self):
564588
if self.layer is not None:
565589
expr.append(["layer", escape_and_quote(self.layer)])
566590

591+
if self.net is not None:
592+
expr.append(["net", self.net])
593+
567594
if self.tstamp is not None:
568595
expr.append(["uuid", quote(self.tstamp)])
569596

@@ -601,6 +628,10 @@ class GrCircle:
601628
locked: bool = False
602629
"""The ``locked`` token defines if the object may be moved or not"""
603630

631+
net: Optional[int] = None
632+
"""The optional ``net`` token defines by net ordinal number which net in the net section that
633+
the graphical item is part of."""
634+
604635
@classmethod
605636
def from_sexpr(cls, exp: list) -> GrCircle:
606637
"""Convert the given S-Expresstion into a GrCircle object
@@ -645,6 +676,8 @@ def from_sexpr(cls, exp: list) -> GrCircle:
645676
object.width = item[1]
646677
elif item[0] == "stroke":
647678
object.stroke = GrStroke().from_sexpr(item)
679+
elif item[0] == "net":
680+
object.net = item[1]
648681
else:
649682
raise ValueError(
650683
f"Unrecognized property key: {item[0]}. Full expression: {item}"
@@ -690,6 +723,9 @@ def _to_sexpr_raw(self):
690723
if self.layer is not None:
691724
expr.append(["layer", escape_and_quote(self.layer)])
692725

726+
if self.net is not None:
727+
expr.append(["net", self.net])
728+
693729
if self.tstamp is not None:
694730
expr.append(["uuid", quote(self.tstamp)])
695731

@@ -727,6 +763,10 @@ class GrArc:
727763
locked: bool = False
728764
"""The ``locked`` token defines if the object may be moved or not"""
729765

766+
net: Optional[int] = None
767+
"""The optional ``net`` token defines by net ordinal number which net in the net section that
768+
the graphical item is part of."""
769+
730770
@classmethod
731771
def from_sexpr(cls, exp: list) -> GrArc:
732772
"""Convert the given S-Expresstion into a GrArc object
@@ -771,6 +811,8 @@ def from_sexpr(cls, exp: list) -> GrArc:
771811
object.width = item[1]
772812
elif item[0] == "stroke":
773813
object.stroke = GrStroke().from_sexpr(item)
814+
elif item[0] == "net":
815+
object.net = item[1]
774816
else:
775817
raise ValueError(
776818
f"Unrecognized property key: {item[0]}. Full expression: {item}"
@@ -814,6 +856,9 @@ def _to_sexpr_raw(self):
814856
if self.layer is not None:
815857
expr.append(["layer", escape_and_quote(self.layer)])
816858

859+
if self.net is not None:
860+
expr.append(["net", self.net])
861+
817862
if self.tstamp is not None:
818863
expr.append(["uuid", quote(self.tstamp)])
819864

@@ -848,6 +893,10 @@ class GrPoly:
848893
locked: bool = False
849894
"""The ``locked`` token defines if the object may be moved or not"""
850895

896+
net: Optional[int] = None
897+
"""The optional ``net`` token defines by net ordinal number which net in the net section that
898+
the graphical item is part of."""
899+
851900
@classmethod
852901
def from_sexpr(cls, exp: list) -> GrPoly:
853902
"""Convert the given S-Expresstion into a GrPoly object
@@ -892,6 +941,8 @@ def from_sexpr(cls, exp: list) -> GrPoly:
892941
object.width = item[1]
893942
elif item[0] == "stroke":
894943
object.stroke = GrStroke().from_sexpr(item)
944+
elif item[0] == "net":
945+
object.net = item[1]
895946
else:
896947
raise ValueError(
897948
f"Unrecognized property key: {item[0]}. Full expression: {item}"
@@ -947,6 +998,9 @@ def _to_sexpr_raw(self):
947998
if self.layer is not None:
948999
expr.append(["layer", escape_and_quote(self.layer)])
9491000

1001+
if self.net is not None:
1002+
expr.append(["net", self.net])
1003+
9501004
if self.tstamp is not None:
9511005
expr.append(["uuid", quote(self.tstamp)])
9521006

@@ -978,6 +1032,10 @@ class GrCurve:
9781032
locked: bool = False
9791033
"""The ``locked`` token defines if the object may be moved or not"""
9801034

1035+
net: Optional[int] = None
1036+
"""The optional ``net`` token defines by net ordinal number which net in the net section that
1037+
the graphical item is part of."""
1038+
9811039
@classmethod
9821040
def from_sexpr(cls, exp: list) -> GrCurve:
9831041
"""Convert the given S-Expresstion into a GrCurve object
@@ -1019,6 +1077,8 @@ def from_sexpr(cls, exp: list) -> GrCurve:
10191077
object.width = item[1]
10201078
elif item[0] == "stroke":
10211079
object.stroke = GrStroke().from_sexpr(item)
1080+
elif item[0] == "net":
1081+
object.net = item[1]
10221082
else:
10231083
raise ValueError(
10241084
f"Unrecognized property key: {item[0]}. Full expression: {item}"
@@ -1066,6 +1126,9 @@ def _to_sexpr_raw(self):
10661126
if self.layer is not None:
10671127
expr.append(["layer", escape_and_quote(self.layer)])
10681128

1129+
if self.net is not None:
1130+
expr.append(["net", self.net])
1131+
10691132
if self.tstamp is not None:
10701133
expr.append(["uuid", quote(self.tstamp)])
10711134

@@ -1074,10 +1137,13 @@ def _to_sexpr_raw(self):
10741137

10751138
@dataclass
10761139
class GrStroke:
1140+
"""The ``stroke`` token defines a line-style used to draw the shape's border."""
10771141

10781142
width: float = 0.0
1143+
"""The ``width`` token defines the line width of a stroke."""
10791144

10801145
type: str = ""
1146+
"""The ``type`` token defines the type of the stroke (solid, dashed, etc.)."""
10811147

10821148
@classmethod
10831149
def from_sexpr(cls, exp: list) -> GrStroke:

0 commit comments

Comments
 (0)