diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 889ff02..5c6b544 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -3,7 +3,7 @@ name: Tests on: [push, pull_request] jobs: - tests: + tests-with-conda-install: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -18,12 +18,27 @@ jobs: - shell: bash -el {0} run: | mamba info - mamba install -y -c conda-forge -c cadquery cadquery=master - mamba install -y -c conda-forge gmsh - mamba install -y pytest python -m pytest -v - name: Upload output meshes as artifacts for inspection uses: actions/upload-artifact@v3 with: name: exported-meshes path: "*.msh" + + tests-with-pip-install: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.11 + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y libglu1-mesa + - name: Install dependencies + run: | + python -m pip install .[dev] + - name: Run tests + run: python -m pytest -v diff --git a/assembly_mesh_plugin/plugin.py b/assembly_mesh_plugin/plugin.py index 6ce4b9f..d578079 100644 --- a/assembly_mesh_plugin/plugin.py +++ b/assembly_mesh_plugin/plugin.py @@ -1,3 +1,5 @@ +import tempfile + from OCP.TopoDS import TopoDS_Shape import cadquery as cq import gmsh @@ -44,7 +46,19 @@ def assembly_to_gmsh(self, mesh_path="tagged_mesh.msh"): # All the solids in the current part should be added to the mesh for s in obj.moved(loc).Solids(): # Add the current solid to the mesh - gmsh.model.occ.importShapesNativePointer(s.wrapped._address()) + + with tempfile.NamedTemporaryFile(suffix=".brep") as temp_file: + s.exportBrep(temp_file.name) + gmsh.model.occ.importShapes(temp_file.name) + + # TODO find a way to check if the OCC in gmsh is compatible with the + # OCC in CadQuery. When pip installed they tend to be incompatible + # and this importShapesNativePointer will seg fault. When both + # packages are conda installed the importShapesNativePointer works. + # Work around that works in both cases is to write a brep and import + # it into gmsh. This is slower but works in all cases. + # gmsh.model.occ.importShapesNativePointer(s.wrapped._address()) + gmsh.model.occ.synchronize() # All the faces in the current part should be added to the mesh diff --git a/pyproject.toml b/pyproject.toml index aac093e..2d556aa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,6 +7,7 @@ name = "assembly_mesh_plugin" version = "0.1.0" dependencies = [ "cadquery", + "gmsh", ] requires-python = ">=3.9" authors = [