Skip to content

Commit 09dd45d

Browse files
aidanc-ansysmatthewAnsysjgsdavies
authored
Lossless adaptive templates (#569)
* Initial commit * Update src/ansys/motorcad/core/geometry.py * Update src/ansys/motorcad/core/geometry.py * Update src/ansys/motorcad/core/geometry.py * Update formatting * Update formatting 1 * Update formatting 2 * Fix failing set/get geometry region json tests * Update linked regions to use names and fetch regions * Add docstrings * Fix to_json error * Updated GeometryTrees to support new linked_regions * Removed poorly structured test * Changed linked_regions in Region to be fetched along with region, along with test fixes * Make sure information is not lost when Regions are converted to JSON for sending and receiving to and from motorCAD * Apply suggestion from @jgsdavies * Apply suggestion from @jgsdavies --------- Co-authored-by: matthewAnsys <[email protected]> Co-authored-by: Matthew Jones <[email protected]> Co-authored-by: Jack Davies <[email protected]>
1 parent 7e3d2dd commit 09dd45d

File tree

1 file changed

+36
-19
lines changed

1 file changed

+36
-19
lines changed

src/ansys/motorcad/core/geometry.py

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ def _from_json(cls, json, motorcad_instance=None):
320320
if "lamination_type" in json:
321321
new_region._lamination_type = json["lamination_type"]
322322

323+
new_region._raw_region = json
324+
323325
return new_region
324326

325327
# method to convert python object to send to Motor-CAD
@@ -336,26 +338,41 @@ def _to_json(self):
336338
else:
337339
lamination_type = ""
338340

339-
region_dict = {
340-
"name": self._name,
341-
"name_base": self._base_name,
342-
"material": self._material,
343-
"colour": {"r": self._colour[0], "g": self._colour[1], "b": self._colour[2]},
344-
"area": self._area,
345-
"centroid": {"x": self._centroid.x, "y": self._centroid.y},
346-
"region_coordinate": {"x": self._region_coordinate.x, "y": self._region_coordinate.y},
347-
"duplications": self._duplications,
348-
"entities": _convert_entities_to_json(self.entities),
349-
"parent_name": self._parent_name,
350-
"region_type": self._region_type.value,
351-
"mesh_length": self.mesh_length,
352-
"linked_regions": self.linked_region_names,
353-
"on_boundary": False if len(self.linked_regions) == 0 else True,
354-
"singular": self._singular,
355-
"lamination_type": lamination_type,
341+
try:
342+
self._raw_region
343+
except AttributeError:
344+
self._raw_region = dict()
345+
# Previous implementations had users only generally interact with the unique name,
346+
# assigning it as the name attribute if possible. This behaviour is maintained for
347+
# now, though it is a piece of information lost that future users may want control over
348+
349+
self._raw_region["name"] = self._name
350+
if "name_unique" in self._raw_region:
351+
self._raw_region["name_unique"] = self._name
352+
self._raw_region["name_base"] = self._base_name
353+
self._raw_region["material"] = self._material
354+
self._raw_region["colour"] = {
355+
"r": self._colour[0],
356+
"g": self._colour[1],
357+
"b": self._colour[2],
356358
}
357-
358-
return region_dict
359+
self._raw_region["area"] = self._area
360+
self._raw_region["centroid"] = {"x": self._centroid.x, "y": self._centroid.y}
361+
self._raw_region["region_coordinate"] = {
362+
"x": self._region_coordinate.x,
363+
"y": self._region_coordinate.y,
364+
}
365+
self._raw_region["duplications"] = self._duplications
366+
self._raw_region["entities"] = _convert_entities_to_json(self.entities)
367+
self._raw_region["parent_name"] = self.parent_name
368+
self._raw_region["region_type"] = self._region_type.value
369+
self._raw_region["mesh_length"] = self.mesh_length
370+
self._raw_region["linked_regions"] = self.linked_region_names
371+
self._raw_region["on_boundary"] = False if len(self.linked_regions) == 0 else True
372+
self._raw_region["singular"] = self._singular
373+
self._raw_region["lamination_type"] = lamination_type
374+
375+
return self._raw_region
359376

360377
@property
361378
def parent_name(self):

0 commit comments

Comments
 (0)