Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewAnsys committed Dec 13, 2024
1 parent 69475d2 commit d4f7540
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/ansys/motorcad/core/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Region(object):
def __init__(self, motorcad_instance=None):
"""Create geometry region and set parameters to defaults."""
self.name = ""
self._base_name = ""
self.material = "air"
self.colour = (0, 0, 0)
self.area = 0.0
Expand Down Expand Up @@ -175,7 +176,14 @@ def _from_json(cls, json, motorcad_instance=None):
new_region._region_type = RegionType(json["region_type"])

# self.Entities = json.Entities
new_region.name = json["name"]

if "name_unique" in json:
new_region.name = json["name_unique"]

Check warning on line 181 in src/ansys/motorcad/core/geometry.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/motorcad/core/geometry.py#L181

Added line #L181 was not covered by tests
else:
new_region.name = json["name"]

new_region._base_name = json["name"]

new_region.material = json["material"]

new_region.colour = (json["colour"]["r"], json["colour"]["g"], json["colour"]["b"])
Expand Down Expand Up @@ -217,6 +225,7 @@ def _to_json(self):

region_dict = {
"name": self.name,
"name_base": self._base_name,
"material": self.material,
"colour": {"r": self.colour[0], "g": self.colour[1], "b": self.colour[2]},
"area": self.area,
Expand Down
4 changes: 4 additions & 0 deletions tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ def test_region_remove_entity():
def test_region_from_json():
raw_region = {
"name": "test_region",
"name_base": "test_region_base",
"material": "copper",
"colour": {"r": 240, "g": 0, "b": 0},
"area": 5.1,
Expand All @@ -359,6 +360,7 @@ def test_region_from_json():

test_region = geometry.Region()
test_region.name = "test_region"
test_region._base_name = "test_region_base"
test_region.material = "copper"
test_region.colour = (240, 0, 0)
test_region.area = 5.1
Expand All @@ -379,6 +381,7 @@ def test_region_from_json():
def test_region_to_json():
raw_region = {
"name": "test_region",
"name_base": "test_region_base",
"material": "copper",
"colour": {"r": 240, "g": 0, "b": 0},
"area": 5.1,
Expand All @@ -396,6 +399,7 @@ def test_region_to_json():

test_region = geometry.Region()
test_region.name = "test_region"
test_region._base_name = "test_region_base"
test_region.material = "copper"
test_region.colour = (240, 0, 0)
test_region.area = 5.1
Expand Down

0 comments on commit d4f7540

Please sign in to comment.