Skip to content

Commit

Permalink
Merge branch 'main' of github.com:CadQuery/assembly-mesh-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwright committed Jan 28, 2025
2 parents 798e2eb + 7ef04e5 commit 747e507
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
23 changes: 19 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
16 changes: 15 additions & 1 deletion assembly_mesh_plugin/plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import tempfile

from OCP.TopoDS import TopoDS_Shape
import cadquery as cq
import gmsh
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ name = "assembly_mesh_plugin"
version = "0.1.0"
dependencies = [
"cadquery",
"gmsh",
]
requires-python = ">=3.9"
authors = [
Expand Down

0 comments on commit 747e507

Please sign in to comment.