Skip to content

Commit 33aff77

Browse files
committed
Orientation property updated.
1 parent f336923 commit 33aff77

File tree

2 files changed

+44
-21
lines changed

2 files changed

+44
-21
lines changed

src/ansys/aedt/core/emit_core/nodes/emit_node.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -406,24 +406,37 @@ def _add_child_node(self, child_type, child_name=None):
406406
return new_id
407407

408408
@property
409-
def reorient(self) -> None:
410-
"""Reorient an emit node in the schematic.
409+
def orientation(self) -> int:
410+
"""Returns the orientation of the component.
411411
412412
Returns:
413-
int: The new orientation of the component (0 or 1).
414-
415-
Raises:
416-
RuntimeError: If the component does not support orientation.
413+
int: The orientation of the component, where valid values range from 0 to 3.
417414
"""
418-
try:
419-
orientation = self._emit_obj.oeditor.GetComponentOrientation(self.name)
420-
new_orientation = 1 - orientation
421-
self._emit_obj.oeditor.ReorientComponent(self.name, new_orientation)
422-
self._emit_obj.logger.info(f"Successfully reoriented component '{self.name}'.")
423-
except Exception as e:
415+
return self._emit_obj.oeditor.GetComponentOrientation(self.name)
416+
417+
@orientation.setter
418+
def orientation(self, value: int) -> None:
419+
if self.properties["Type"] != "Multiplexer" and value not in [0, 1]:
420+
raise ValueError(f"Orientation must be either 0 or 1 for component '{self.name}'.")
421+
elif self.properties["Type"] == "Multiplexer" and value not in [0, 1, 2, 3]:
422+
raise ValueError("Orientation must be one of the following: 0, 1, 2, or 3 for Multiplexer components.")
423+
if self.orintation_count > 1:
424+
self._emit_obj.oeditor.ReorientComponent(self.name, value)
425+
self._emit_obj.logger.info(f"Successfully set orientation to {value} for component '{self.name}'.")
426+
else:
424427
error_message = (
425-
f"Reorientation failed; orientation adjustment is not supported "
426-
f"for component '{self.name}'. Error: {e}"
428+
f"Orientation adjustment is not supported for component '{self.name}'. "
429+
"This component cannot be reoriented."
427430
)
428431
self._emit_obj.logger.error(error_message)
429-
raise RuntimeError(error_message)
432+
raise ValueError(error_message)
433+
434+
@property
435+
def orintation_count(self) -> int:
436+
"""Returns the number of orientations available for the component.
437+
438+
Returns:
439+
int: The number of valid orientations. A value of 1 indicates the component cannot be reoriented,
440+
2 indicates support for basic reorientation, and 4 is used for multiplexer components.
441+
"""
442+
return self._emit_obj.oeditor.GetNumComponentOrientations(self.name)

tests/system/solvers/test_26_emit.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,18 +1681,28 @@ def test_30_connect_components(self, add_app):
16811681
) in str(e.value)
16821682

16831683
@pytest.mark.skipif(config["desktopVersion"] < "2025.2", reason="Skipped on versions earlier than 2025 R2.")
1684-
def test_31_reorient_component(self, add_app):
1684+
def test_31_orientation(self, add_app):
16851685
self.aedtapp = add_app(project_name="reorient_component", application=Emit)
16861686
new_circulator = self.aedtapp.schematic.create_component("Circulator")
1687+
assert 2 == new_circulator.orintation_count
16871688
assert ["2", "3"] == [x for x in new_circulator.properties["AntennaSidePorts"].split("|")]
16881689
assert ["1"] == [x for x in new_circulator.properties["RadioSidePorts"].split("|")]
1689-
new_circulator.reorient
1690+
new_circulator.orientation = 1
16901691
assert ["1"] == [x for x in new_circulator.properties["AntennaSidePorts"].split("|")]
16911692
assert ["3", "2"] == [x for x in new_circulator.properties["RadioSidePorts"].split("|")]
1692-
with pytest.raises(RuntimeError) as e:
1693+
with pytest.raises(ValueError) as e:
1694+
new_circulator.orientation = 3
1695+
assert "Orientation must be either 0 or 1 for component 'Circulator'." in str(e.value)
1696+
new_multiplexer = self.aedtapp.schematic.create_component("5 Port")
1697+
assert 4 == new_multiplexer.orintation_count
1698+
assert ["2", "3", "4", "5"] == [x for x in new_multiplexer.properties["AntennaSidePorts"].split("|")]
1699+
assert ["1"] == [x for x in new_multiplexer.properties["RadioSidePorts"].split("|")]
1700+
new_multiplexer.orientation = 2
1701+
assert ["1"] == [x for x in new_multiplexer.properties["AntennaSidePorts"].split("|")]
1702+
assert ["5", "4", "3", "2"] == [x for x in new_multiplexer.properties["RadioSidePorts"].split("|")]
1703+
with pytest.raises(ValueError) as e:
16931704
new_radio = self.aedtapp.schematic.create_component("New Radio")
1694-
new_radio.reorient
1705+
new_radio.orientation = 1
16951706
assert (
1696-
"Reorientation failed; orientation adjustment is not supported for component 'Radio'. "
1697-
"Error: Failed to execute gRPC AEDT command: ReorientComponent"
1707+
"Orientation adjustment is not supported for component 'Radio'. " "This component cannot be reoriented."
16981708
) in str(e.value)

0 commit comments

Comments
 (0)