Skip to content

Commit

Permalink
Modularize entities
Browse files Browse the repository at this point in the history
  • Loading branch information
rnestler committed Aug 5, 2019
1 parent c3ed43b commit a72c5c7
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -10,8 +10,8 @@ script:
- pytest
- mypy --strict
common.py
entities/*.py
- mypy --check-untyped-defs --warn-return-any
entities.py
test_entities.py
generate_mosfet_dual.py
generate_so.py
Expand Down
Empty file added entities/__init__.py
Empty file.
14 changes: 0 additions & 14 deletions entities.py → entities/common.py
Expand Up @@ -115,20 +115,6 @@ def __init__(self, length: float):
super().__init__('length', length)


class SchematicsPin():
def __init__(self, uuid: str, name: Name, position: Position, rotation: Rotation, length: Length):
self.uuid = uuid
self.name = name
self.position = position
self.rotation = rotation
self.length = length

def __str__(self) -> str:
return '(pin {} {}\n'.format(self.uuid, self.name) +\
' {} {} {}\n'.format(self.position, self.rotation, self.length) +\
')'


class Width(FloatValue):
def __init__(self, width: float):
super().__init__('width', width)
Expand Down
15 changes: 15 additions & 0 deletions entities/symbol.py
@@ -0,0 +1,15 @@
from .common import Name, Position, Rotation, Length


class Pin():
def __init__(self, uuid: str, name: Name, position: Position, rotation: Rotation, length: Length):
self.uuid = uuid
self.name = name
self.position = position
self.rotation = rotation
self.length = length

def __str__(self) -> str:
return '(pin {} {}\n'.format(self.uuid, self.name) +\
' {} {} {}\n'.format(self.position, self.rotation, self.length) +\
')'
5 changes: 3 additions & 2 deletions generate_connectors.py
Expand Up @@ -17,7 +17,8 @@
from uuid import uuid4

from common import now, init_cache, save_cache, format_float as ff, indent
from entities import SchematicsPin, Name, Position, Rotation, Length, Polygon, Layer, Width, Fill, GrabArea, Vertex, Angle
from entities.common import Name, Position, Rotation, Length, Polygon, Layer, Width, Fill, GrabArea, Vertex, Angle
from entities.symbol import Pin as SymbolPin


generator = 'librepcb-parts-generator (generate_connectors.py)'
Expand Down Expand Up @@ -287,7 +288,7 @@ def _uuid(identifier):
lines.append(' (deprecated false)')
lines.append(' (category {})'.format(cmpcat))
for j in range(1, i + 1):
pin = SchematicsPin(uuid_pins[j - 1], Name(str(j)), Position(5.08, get_y(j, i, spacing, True)), Rotation(180.0), Length(3.81))
pin = SymbolPin(uuid_pins[j - 1], Name(str(j)), Position(5.08, get_y(j, i, spacing, True)), Rotation(180.0), Length(3.81))
lines += indent(1, str(pin).splitlines())

# Polygons
Expand Down
9 changes: 5 additions & 4 deletions test_entities.py
@@ -1,4 +1,5 @@
from entities import Name, Description, Position, Rotation, Length, SchematicsPin, Vertex, Angle, Polygon, Width, Fill, GrabArea, Layer, Align, Height, Text, Value
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


def test_name():
Expand Down Expand Up @@ -26,10 +27,10 @@ def test_length():
assert length_s_exp == '(length 3.81)'


def test_schematics_pin():
schematics_pin_s_exp = str(SchematicsPin('my_uuid', Name('foo'), Position(1.0, 2.0), Rotation(180.0), Length(3.81)))
def test_symbol_pin():
symbol_pin_s_exp = str(SymbolPin('my_uuid', Name('foo'), Position(1.0, 2.0), Rotation(180.0), Length(3.81)))

assert schematics_pin_s_exp == '(pin my_uuid (name "foo")\n' + \
assert symbol_pin_s_exp == '(pin my_uuid (name "foo")\n' + \
' (position 1.0 2.0) (rotation 180.0) (length 3.81)\n' + \
')'

Expand Down

0 comments on commit a72c5c7

Please sign in to comment.