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 a44cdb2c95..0991c0cba0 100644 --- a/src/ansys/geometry/core/designer/design.py +++ b/src/ansys/geometry/core/designer/design.py @@ -427,7 +427,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 @@ -435,6 +437,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 ------- @@ -445,12 +449,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 @@ -458,6 +464,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 ------- @@ -468,7 +476,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 514b913eb5..ef4f6ddca7 100644 --- a/tests/_incompatible_tests.yml +++ b/tests/_incompatible_tests.yml @@ -118,6 +118,7 @@ backends: # Export body facets added 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 # Edge tessellation added in 26.1 - tests/integration/test_tessellation.py::test_body_tessellate_with_edges @@ -232,6 +233,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 # Edge tessellation added in 26.1 - tests/integration/test_tessellation.py::test_body_tessellate_with_edges @@ -315,6 +317,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 # Edge tessellation added in 26.1 @@ -355,6 +358,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 # Edge tessellation added in 26.1 diff --git a/tests/integration/test_design.py b/tests/integration/test_design.py index 11acbbca5b..d92068fcbc 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): @@ -3807,7 +3807,7 @@ def test_vertices(modeler: Modeler, tmp_path_factory: pytest.TempPathFactory): assert design.bodies[1].vertices[0].y.magnitude == pytest.approx(-0.00288675, 1e-6, 1e-6) assert design.bodies[1].vertices[0].z.magnitude == pytest.approx(0.01, 1e-6, 1e-6) - print(design.bodies[1].vertices[0].id == "S,~sEbf61ff70-bc08-477a-8a5e-a7c7dc955f40.853__") + assert design.bodies[1].vertices[0].id == "S,~sEbf61ff70-bc08-477a-8a5e-a7c7dc955f40.853__" assert design.bodies[0].vertices == [] assert design.bodies[1].vertices[1].position == pytest.approx( @@ -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()