Skip to content

Commit

Permalink
feat: design activation changes (#1707)
Browse files Browse the repository at this point in the history
Co-authored-by: jkerstet <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: pyansys-ci-bot <[email protected]>
  • Loading branch information
4 people authored Jan 30, 2025
1 parent 7b4de97 commit c9d691f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 28 deletions.
1 change: 1 addition & 0 deletions doc/changelog.d/1707.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
design activation changes
22 changes: 1 addition & 21 deletions src/ansys/geometry/core/designer/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,27 +983,7 @@ def insert_file(self, file_location: Path | str) -> Component:
self._design_stub.Insert(InsertRequest(filepath=filepath_server))
self._grpc_client.log.debug(f"File {file_location} successfully inserted into design.")

# Get a temporal design object to update the current one
tmp_design = Design("", self._modeler, read_existing_design=True)

# Update the reference to the design
for component in tmp_design.components:
component._parent_component = self

# Update the design's components - add the new one
#
# If the list is empty, add the components from the new design
if not self._components:
self._components.extend(tmp_design.components)
else:
# Insert operation adds the inserted file as a component to the design.
for tmp_component in tmp_design.components:
# Otherwise, check which is the new component added
for component in self._components:
if component.id == tmp_component.id:
break
# If not equal, add the component - since it has not been found
self._components.append(tmp_component)
self._update_design_inplace()

self._grpc_client.log.debug(f"Design {self.name} is successfully updated.")

Expand Down
10 changes: 3 additions & 7 deletions tests/integration/test_design_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from ansys.geometry.core.sketch import Sketch
from ansys.geometry.core.tools.unsupported import PersistentIdType

from .conftest import FILES_DIR, IMPORT_FILES_DIR, skip_if_core_service
from .conftest import FILES_DIR, IMPORT_FILES_DIR


def _create_flat_design(modeler: Modeler) -> Design:
Expand Down Expand Up @@ -306,9 +306,6 @@ def test_open_file(modeler: Modeler, tmp_path_factory: pytest.TempPathFactory):

def test_design_insert(modeler: Modeler):
"""Test inserting a file into the design."""
# Skip for CoreService
skip_if_core_service(modeler, test_design_insert.__name__, "insert_file")

# Create a design and sketch a circle
design = modeler.create_design("Insert")
sketch = Sketch()
Expand All @@ -321,6 +318,7 @@ def test_design_insert(modeler: Modeler):

# Check that there are two components
assert len(design.components) == 2
assert design._is_active
assert design.components[0].name == "Component_Cylinder"
assert design.components[1].name == "DuplicatesDesign"

Expand All @@ -329,9 +327,6 @@ def test_design_insert_with_import(modeler: Modeler):
"""Test inserting a file into the design through the external format import
process.
"""
# Skip for CoreService
skip_if_core_service(modeler, test_design_insert_with_import.__name__, "insert_file")

# Create a design and sketch a circle
design = modeler.create_design("Insert")
sketch = Sketch()
Expand All @@ -344,5 +339,6 @@ def test_design_insert_with_import(modeler: Modeler):

# Check that there are two components
assert len(design.components) == 2
assert design._is_active
assert design.components[0].name == "Component_Cylinder"
assert design.components[1].name == "Wheel1"

0 comments on commit c9d691f

Please sign in to comment.