Skip to content

Commit e4cdf87

Browse files
authored
Merge pull request LibrePCB#89 from LibrePCB/cherry-pick-entity-contributions
Cherry pick entity contributions from open pull requests
2 parents 7b4872d + 61d25eb commit e4cdf87

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

entities/component.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from typing import List
44

5-
from common import indent
6-
75
from .common import (
86
Author, BoolValue, Category, Created, Deprecated, Description, EnumValue, Keywords, Name, Position, Rotation,
97
StringValue, UUIDValue, Version
@@ -146,14 +144,17 @@ def __init__(self, uuid: str, norm: Norm, name: Name, description: Description,
146144
self.norm = norm
147145
self.name = name
148146
self.description = description
149-
self.gate = gate
147+
self.gates = [gate] # type: List[Gate]
148+
149+
def add_gate(self, gate_map: Gate) -> None:
150+
self.gates.append(gate_map)
150151

151152
def __str__(self) -> str:
152153
ret = '(variant {} {}\n'.format(self.uuid, self.norm) +\
153154
' {}\n'.format(self.name) +\
154155
' {}\n'.format(self.description)
155-
ret += '\n'.join(indent(1, str(self.gate).splitlines()))
156-
ret += '\n)'
156+
ret += indent_entities(sorted(self.gates, key=lambda x: str(x.uuid)))
157+
ret += ')'
157158
return ret
158159

159160

entities/symbol.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import List
22

33
from .common import (
4-
Author, Category, Created, Deprecated, Description, Keywords, Length, Name, Polygon, Position, Rotation, Text,
4+
Author, Category, Circle, Created, Deprecated, Description, Keywords, Length, Name, Polygon, Position, Rotation, Text,
55
Version
66
)
77
from .helper import indent_entities
@@ -37,6 +37,7 @@ def __init__(self, uuid: str, name: Name, description: Description,
3737
self.category = category
3838
self.pins = [] # type: List[Pin]
3939
self.polygons = [] # type: List[Polygon]
40+
self.circles = [] # type: List[Circle]
4041
self.texts = [] # type: List[Text]
4142

4243
def add_pin(self, pin: Pin) -> None:
@@ -45,6 +46,9 @@ def add_pin(self, pin: Pin) -> None:
4546
def add_polygon(self, polygon: Polygon) -> None:
4647
self.polygons.append(polygon)
4748

49+
def add_circle(self, circle: Circle) -> None:
50+
self.circles.append(circle)
51+
4852
def add_text(self, text: Text) -> None:
4953
self.texts.append(text)
5054

@@ -60,6 +64,7 @@ def __str__(self) -> str:
6064
' {}\n'.format(self.category)
6165
ret += indent_entities(self.pins)
6266
ret += indent_entities(self.polygons)
67+
ret += indent_entities(self.circles)
6368
ret += indent_entities(self.texts)
6469
ret += ')'
6570
return ret

test_entities.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from entities.common import (
2-
Align, Angle, Author, Category, Created, Deprecated, Description, Fill, GrabArea, Height, Keywords, Layer, Length,
3-
Name, Polygon, Position, Rotation, Text, Value, Version, Vertex, Width
2+
Align, Angle, Author, Category, Circle, Created, Deprecated, Description, Diameter, Fill, GrabArea, Height,
3+
Keywords, Layer, Length, Name, Polygon, Position, Rotation, Text, Value, Version, Vertex, Width
44
)
55
from entities.component import (
66
Clock, Component, DefaultValue, ForcedNet, Gate, Negated, Norm, PinSignalMap, Prefix, Required, Role, SchematicOnly,
@@ -88,6 +88,7 @@ def test_symbol() -> None:
8888
polygon.add_vertex(Vertex(Position(-2.54, -25.4), Angle(0.0)))
8989
polygon.add_vertex(Vertex(Position(-2.54, 22.86), Angle(0.0)))
9090
symbol.add_polygon(polygon)
91+
symbol.add_circle(Circle('b5599e68-ff6a-464b-9a40-c6ba8ef8daf5', Layer('sym_outlines'), Width(0.254), Fill(False), GrabArea(False), Diameter(1.27), Position(5.715, 0.0)))
9192
symbol.add_text(Text('b9c4aa19-0a46-400c-9c96-e8c3dfb8f83e', Layer('sym_names'), Value('{{NAME}}'), Align('center bottom'), Height(2.54), Position(0.0, 22.86), Rotation(0.0)))
9293

9394
assert str(symbol) == """(librepcb_symbol 01b03c10-7334-4bd5-b2bc-942c18325d2b
@@ -108,6 +109,9 @@ def test_symbol() -> None:
108109
(vertex (position -2.54 -25.4) (angle 0.0))
109110
(vertex (position -2.54 22.86) (angle 0.0))
110111
)
112+
(circle b5599e68-ff6a-464b-9a40-c6ba8ef8daf5 (layer sym_outlines)
113+
(width 0.254) (fill false) (grab_area false) (diameter 1.27) (position 5.715 0.0)
114+
)
111115
(text b9c4aa19-0a46-400c-9c96-e8c3dfb8f83e (layer sym_names) (value "{{NAME}}")
112116
(align center bottom) (height 2.54) (position 0.0 22.86) (rotation 0.0)
113117
)

0 commit comments

Comments
 (0)