|
32 | 32 | from ansys.geometry.core.math import Plane, Point2D, Point3D, UnitVector3D, Vector3D
|
33 | 33 | from ansys.geometry.core.sketch import Sketch
|
34 | 34 |
|
| 35 | +from ..conftest import are_graphics_available |
35 | 36 | from .conftest import (
|
36 | 37 | FILES_DIR,
|
37 | 38 | skip_if_core_service,
|
@@ -408,3 +409,79 @@ def test_import_export_reimport_design_x_t(
|
408 | 409 | # Assertions to check the number of components and bodies
|
409 | 410 | assert len(design.components[0].bodies) == 1
|
410 | 411 | assert len(design.components[1].components[0].components[0].bodies) == 1
|
| 412 | + |
| 413 | + |
| 414 | +@pytest.mark.skipif( |
| 415 | + not are_graphics_available(), reason="Skipping due to graphics requirements missing" |
| 416 | +) |
| 417 | +def test_import_export_glb(modeler: Modeler, tmp_path_factory: pytest.TempPathFactory): |
| 418 | + """Test exporting a design to GLB format.""" |
| 419 | + from ansys.geometry.core.plotting import GeometryPlotter |
| 420 | + |
| 421 | + working_directory = tmp_path_factory.mktemp("test_import_export_glb") |
| 422 | + design = modeler.create_design("Assembly") |
| 423 | + design.add_component("Component_1") |
| 424 | + file = Path(FILES_DIR, "reactorWNS.scdocx") |
| 425 | + component = design.insert_file(file) |
| 426 | + # Check that the design has components |
| 427 | + assert len(design.components) == 2, "The design does not contain any components." |
| 428 | + |
| 429 | + # Check that the imported component has bodies |
| 430 | + assert len(design.components[1].components[0].bodies) == 3, ( |
| 431 | + "The imported component does not contain any bodies." |
| 432 | + ) |
| 433 | + pl = GeometryPlotter() |
| 434 | + |
| 435 | + output_glb_path = Path(working_directory, "plot_box_glb.glb") |
| 436 | + pl.export_glb(plotting_object=component, filename=output_glb_path) |
| 437 | + assert output_glb_path.exists(), f"GLB file {output_glb_path} does not exist." |
| 438 | + |
| 439 | + # Check that the GLB file size is greater than 0 bytes |
| 440 | + assert output_glb_path.stat().st_size > 0, f"GLB file {output_glb_path} is empty." |
| 441 | + |
| 442 | + |
| 443 | +@pytest.mark.parametrize( |
| 444 | + "file_format, extension, original_file, expected_components, expected_bodies", |
| 445 | + [ |
| 446 | + (DesignFileFormat.PARASOLID_TEXT, "x_t", "rci_std.x_t", 2, 1), |
| 447 | + (DesignFileFormat.SCDOCX, "scdocx", "reactorWNS.scdocx", 1, 3), |
| 448 | + ], |
| 449 | +) |
| 450 | +def test_import_export_open_file_design( |
| 451 | + modeler: Modeler, |
| 452 | + tmp_path_factory: pytest.TempPathFactory, |
| 453 | + file_format, |
| 454 | + extension, |
| 455 | + original_file, |
| 456 | + expected_components, |
| 457 | + expected_bodies, |
| 458 | +): |
| 459 | + """Test importing, exporting, and opening a file in a new design.""" |
| 460 | + # Define the working directory and file paths |
| 461 | + working_directory = tmp_path_factory.mktemp("test_import_export_reimport") |
| 462 | + original_file_path = Path(FILES_DIR, original_file) |
| 463 | + reexported_file = Path(working_directory, f"reexported.{extension}") |
| 464 | + |
| 465 | + # Create a new design |
| 466 | + design = modeler.create_design("Assembly") |
| 467 | + |
| 468 | + # Import the original file |
| 469 | + design.insert_file(original_file_path) |
| 470 | + |
| 471 | + # Export the design to a new file |
| 472 | + design.download(reexported_file, format=file_format) |
| 473 | + |
| 474 | + # Ensure the re-exported file exists |
| 475 | + assert reexported_file.exists(), f"Re-exported file {reexported_file} does not exist." |
| 476 | + |
| 477 | + # Re-import the exported file |
| 478 | + design = modeler.open_file(reexported_file) |
| 479 | + |
| 480 | + # Assertions to check the number of components and bodies |
| 481 | + assert len(design.components) == expected_components, ( |
| 482 | + f"Expected {expected_components} components, but found {len(design.components)}." |
| 483 | + ) |
| 484 | + assert len(design.components[0].components[0].bodies) == expected_bodies, ( |
| 485 | + f"Expected {expected_bodies} bodies, but found " |
| 486 | + f"{len(design.components[0].components[0].bodies)}." |
| 487 | + ) |
0 commit comments