Skip to content

Commit

Permalink
Add Symbol entity
Browse files Browse the repository at this point in the history
  • Loading branch information
rnestler committed Aug 5, 2019
1 parent a72c5c7 commit 609b6f4
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 3 deletions.
54 changes: 53 additions & 1 deletion entities/symbol.py
@@ -1,4 +1,6 @@
from .common import Name, Position, Rotation, Length
from .common import Name, Position, Rotation, Length, Description, Keywords, Author, Version, Created, Category, Deprecated, Polygon, Text
from typing import List
from common import indent


class Pin():
Expand All @@ -13,3 +15,53 @@ def __str__(self) -> str:
return '(pin {} {}\n'.format(self.uuid, self.name) +\
' {} {} {}\n'.format(self.position, self.rotation, self.length) +\
')'


class Symbol:
def __init__(self, uuid: str, name: Name, description: Description,
keywords: Keywords, author: Author, version: Version,
created: Created, category: Category,
deprecated: Deprecated = Deprecated(False)):
self.uuid = uuid
self.name = name
self.description = description
self.keywords = keywords
self.author = author
self.version = version
self.created = created
self.deprecated = deprecated
self.category = category
self.pins = [] # type: List[Pin]
self.polygons = [] # type: List[Polygon]
self.texts = [] # type: List[Text]

def add_pin(self, pin: Pin) -> None:
self.pins.append(pin)

def add_polygon(self, polygon: Polygon) -> None:
self.polygons.append(polygon)

def add_text(self, text: Text) -> None:
self.texts.append(text)

def __str__(self) -> str:
ret = '(librepcb_symbol {}\n'.format(self.uuid) +\
' {}\n'.format(self.name) +\
' {}\n'.format(self.description) +\
' {}\n'.format(self.keywords) +\
' {}\n'.format(self.author) +\
' {}\n'.format(self.version) +\
' {}\n'.format(self.created) +\
' {}\n'.format(self.deprecated) +\
' {}\n'.format(self.category)
for pin in self.pins:
ret += '\n'.join(indent(1, str(pin).splitlines()))
ret += '\n'
for polygon in self.polygons:
ret += '\n'.join(indent(1, str(polygon).splitlines()))
ret += '\n'
for text in self.texts:
ret += '\n'.join(indent(1, str(text).splitlines()))
ret += '\n'
ret += ')'
return ret
38 changes: 36 additions & 2 deletions test_entities.py
@@ -1,5 +1,5 @@
from entities.common import Name, Description, Position, Rotation, Length, Vertex, Angle, Polygon, Width, Fill, GrabArea, Layer, Align, Height, Text, Value
from entities.symbol import Pin as SymbolPin
from entities.common import Name, Description, Position, Rotation, Length, Vertex, Angle, Polygon, Width, Fill, GrabArea, Layer, Align, Height, Text, Value, Keywords, Author, Version, Created, Category
from entities.symbol import Pin as SymbolPin, Symbol


def test_name():
Expand Down Expand Up @@ -65,3 +65,37 @@ def test_text():
assert text == '(text b9c4aa19-0a46-400c-9c96-e8c3dfb8f83e (layer sym_names) (value "{{NAME}}")\n' +\
' (align center bottom) (height 2.54) (position 0.0 22.86) (rotation 0.0)\n' +\
')'


def test_symbol():
symbol = Symbol('01b03c10-7334-4bd5-b2bc-942c18325d2b', Name('Sym name'), Description(r'A multiline description.\n\nDescription'), Keywords('my, keywords'), Author('Test'), Version('0.2'), Created('2018-10-17T19:13:41Z'), Category('d0618c29-0436-42da-a388-fdadf7b23892'))
symbol.add_pin(SymbolPin('6da06b2b-7806-4e68-bd0c-e9f18eb2f9d8', Name('1'), Position(5.08, 20.32), Rotation(180.0), Length(3.81)))
polygon = Polygon('743dbf3d-98e8-46f0-9a32-00e00d0e811f', Layer('sym_outlines'), Width(0.25), Fill(False), GrabArea(True))
polygon.add_vertex(Vertex(Position(-2.54, 22.86), Angle(0.0)))
polygon.add_vertex(Vertex(Position(-2.54, -25.4), Angle(0.0)))
polygon.add_vertex(Vertex(Position(-2.54, 22.86), Angle(0.0)))
symbol.add_polygon(polygon)
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)))

assert str(symbol) == """(librepcb_symbol 01b03c10-7334-4bd5-b2bc-942c18325d2b
(name "Sym name")
(description "A multiline description.\\n\\nDescription")
(keywords "my, keywords")
(author "Test")
(version "0.2")
(created 2018-10-17T19:13:41Z)
(deprecated false)
(category d0618c29-0436-42da-a388-fdadf7b23892)
(pin 6da06b2b-7806-4e68-bd0c-e9f18eb2f9d8 (name "1")
(position 5.08 20.32) (rotation 180.0) (length 3.81)
)
(polygon 743dbf3d-98e8-46f0-9a32-00e00d0e811f (layer sym_outlines)
(width 0.25) (fill false) (grab_area true)
(vertex (position -2.54 22.86) (angle 0.0))
(vertex (position -2.54 -25.4) (angle 0.0))
(vertex (position -2.54 22.86) (angle 0.0))
)
(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)
)
)"""

0 comments on commit 609b6f4

Please sign in to comment.