diff --git a/doc/changelog.d/2231.fixed.md b/doc/changelog.d/2231.fixed.md new file mode 100644 index 0000000000..5b60051f51 --- /dev/null +++ b/doc/changelog.d/2231.fixed.md @@ -0,0 +1 @@ +Add option to write body facets to explicit export methods diff --git a/src/ansys/geometry/core/designer/design.py b/src/ansys/geometry/core/designer/design.py index d929cc9c3e..ee74fbe082 100644 --- a/src/ansys/geometry/core/designer/design.py +++ b/src/ansys/geometry/core/designer/design.py @@ -430,7 +430,9 @@ def __build_export_file_location(self, location: Path | str | None, ext: str) -> """ return (Path(location) if location else Path.cwd()) / f"{self.name}.{ext}" - def export_to_scdocx(self, location: Path | str | None = None) -> Path: + def export_to_scdocx( + self, location: Path | str | None = None, write_body_facets: bool = False + ) -> Path: """Export the design to an scdocx file. Parameters @@ -438,6 +440,8 @@ def export_to_scdocx(self, location: Path | str | None = None) -> Path: location : ~pathlib.Path | str, optional Location on disk to save the file to. If None, the file will be saved in the current working directory. + write_body_facets : bool, default: False + Option to write body facets into the saved file. SCDOCX and DISCO only, 26R1 and later. Returns ------- @@ -448,12 +452,14 @@ def export_to_scdocx(self, location: Path | str | None = None) -> Path: file_location = self.__build_export_file_location(location, "scdocx") # Export the design to an scdocx file - self.download(file_location, DesignFileFormat.SCDOCX) + self.download(file_location, DesignFileFormat.SCDOCX, write_body_facets) # Return the file location return file_location - def export_to_disco(self, location: Path | str | None = None) -> Path: + def export_to_disco( + self, location: Path | str | None = None, write_body_facets: bool = False + ) -> Path: """Export the design to an dsco file. Parameters @@ -461,6 +467,8 @@ def export_to_disco(self, location: Path | str | None = None) -> Path: location : ~pathlib.Path | str, optional Location on disk to save the file to. If None, the file will be saved in the current working directory. + write_body_facets : bool, default: False + Option to write body facets into the saved file. SCDOCX and DISCO only, 26R1 and later. Returns ------- @@ -471,7 +479,7 @@ def export_to_disco(self, location: Path | str | None = None) -> Path: file_location = self.__build_export_file_location(location, "dsco") # Export the design to an dsco file - self.download(file_location, DesignFileFormat.DISCO) + self.download(file_location, DesignFileFormat.DISCO, write_body_facets) # Return the file location return file_location diff --git a/tests/_incompatible_tests.yml b/tests/_incompatible_tests.yml index b189e1e208..76e807eb93 100644 --- a/tests/_incompatible_tests.yml +++ b/tests/_incompatible_tests.yml @@ -118,6 +118,7 @@ backends: # Export body facets add in 26.1 - tests/integration/test_design.py::test_write_body_facets_on_save[scdocx-None] - tests/integration/test_design.py::test_write_body_facets_on_save[dsco-DISCO] + - tests/integration/test_design_export.py::test_export_to_disco_with_facets - version: "24.2" incompatible_tests: @@ -230,6 +231,7 @@ backends: # Export body facets add in 26.1 - tests/integration/test_design.py::test_write_body_facets_on_save[scdocx-None] - tests/integration/test_design.py::test_write_body_facets_on_save[dsco-DISCO] + - tests/integration/test_design_export.py::test_export_to_disco_with_facets - version: "25.1" incompatible_tests: @@ -311,6 +313,7 @@ backends: # Export body facets add in 26.1 - tests/integration/test_design.py::test_write_body_facets_on_save[scdocx-None] - tests/integration/test_design.py::test_write_body_facets_on_save[dsco-DISCO] + - tests/integration/test_design_export.py::test_export_to_disco_with_facets # NURBS surface creation only available from 26.1 onwards - tests/integration/test_design.py::test_nurbs_surface_body_creation @@ -349,5 +352,6 @@ backends: # Export body facets add in 26.1 - tests/integration/test_design.py::test_write_body_facets_on_save[scdocx-None] - tests/integration/test_design.py::test_write_body_facets_on_save[dsco-DISCO] + - tests/integration/test_design_export.py::test_export_to_disco_with_facets # NURBS surface creation only available from 26.1 onwards - tests/integration/test_design.py::test_nurbs_surface_body_creation diff --git a/tests/integration/test_design.py b/tests/integration/test_design.py index 906d493742..b1dfe0b178 100644 --- a/tests/integration/test_design.py +++ b/tests/integration/test_design.py @@ -1225,7 +1225,7 @@ def test_download_file(modeler: Modeler, tmp_path_factory: pytest.TempPathFactor else: file_save = tmp_path_factory.mktemp("scdoc_files_save") / "cylinder.scdocx" - design.save(file_location=file_save) + design.save(file_location=file_save, write_body_facets=True) # Check for other exports - Windows backend... if not BackendType.is_core_service(modeler.client.backend_type): @@ -3899,7 +3899,8 @@ def test_vertices(modeler: Modeler, tmp_path_factory: pytest.TempPathFactory): location = tmp_path_factory.mktemp("test_export_to_scdocx") file_location = location / f"{design.name}.scdocx" - design.export_to_scdocx(location) + exported_file = design.export_to_scdocx(location, write_body_facets=True) + assert exported_file.stat().st_size == pytest.approx(209996, 1e-3, 100) assert file_location.exists() design_read = modeler.open_file(file_location) assert len(design_read.named_selections) == 5 diff --git a/tests/integration/test_design_export.py b/tests/integration/test_design_export.py index 44c4269149..1be2e0298e 100644 --- a/tests/integration/test_design_export.py +++ b/tests/integration/test_design_export.py @@ -219,7 +219,37 @@ def test_export_to_disco(modeler: Modeler, tmp_path_factory: pytest.TempPathFact file_location = location / f"{design.name}.dsco" # Export to dsco - design.export_to_disco(location) + exported_file = design.export_to_disco(location) + + # Checking file size to ensure facets are exported + assert exported_file.stat().st_size == pytest.approx(20464, 1e-3, 100) + + # Check the exported file + assert file_location.exists() + + # Import the dsco + design_read = modeler.open_file(file_location) + + # Check the imported design + _checker_method(design_read, design, True) + + +def test_export_to_disco_with_facets(modeler: Modeler, tmp_path_factory: pytest.TempPathFactory): + """Test exporting a design to dsco format with facets only available. in 261""" + """This is a duplicate to ensure disco exporting is still covered before 261""" + skip_if_spaceclaim(modeler, test_export_to_disco.__name__, "disco export") + # Create a demo design + design = _create_demo_design(modeler) + + # Define the location and expected file location + location = tmp_path_factory.mktemp("test_export_to_disco") + file_location = location / f"{design.name}.dsco" + + # Export to dsco + exported_file = design.export_to_disco(location, write_body_facets=True) + + # Checking file size to ensure facets are exported + assert exported_file.stat().st_size == pytest.approx(53844, 1e-3, 100) # Check the exported file assert file_location.exists()