Skip to content

Commit 01b4820

Browse files
committed
Do not change toCAF signature
1 parent 392e6f4 commit 01b4820

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

cadquery/occ_impl/assembly.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
from OCP.TDF import TDF_Label
1111
from OCP.TopLoc import TopLoc_Location
1212
from OCP.Quantity import Quantity_ColorRGBA
13+
from OCP.XCAFPrs import (
14+
XCAFPrs_DocumentExplorer,
15+
XCAFPrs_DocumentExplorerFlags_None,
16+
XCAFPrs_Style,
17+
)
1318

1419
from vtkmodules.vtkRenderingCore import (
1520
vtkActor,
@@ -140,7 +145,7 @@ def toCAF(
140145
mesh: bool = False,
141146
tolerance: float = 1e-3,
142147
angularTolerance: float = 0.1,
143-
) -> TDocStd_Document:
148+
) -> Tuple[TDF_Label, TDocStd_Document]:
144149

145150
# prepare a doc
146151
app = XCAFApp_Application.GetApplication_s()
@@ -211,8 +216,14 @@ def _toCAF(el, ancestor, color):
211216
_toCAF(assy, None, None)
212217

213218
tool.UpdateAssemblies()
214-
215-
return doc
219+
return (
220+
XCAFPrs_DocumentExplorer(
221+
doc, XCAFPrs_DocumentExplorerFlags_None, XCAFPrs_Style()
222+
)
223+
.Current()
224+
.Label,
225+
doc,
226+
)
216227

217228

218229
def toVTK(

cadquery/occ_impl/exporters/assembly.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def exportAssembly(assy: AssemblyProtocol, path: str, **kwargs) -> bool:
5050
pcurves = 0
5151
precision_mode = kwargs["precision_mode"] if "precision_mode" in kwargs else 0
5252

53-
doc = toCAF(assy, True)
53+
_, doc = toCAF(assy, True)
5454

5555
session = XSControl_WorkSession()
5656
writer = STEPCAFControl_Writer(session, False)
@@ -75,7 +75,7 @@ def exportCAF(assy: AssemblyProtocol, path: str) -> bool:
7575
name, ext = os.path.splitext(fname)
7676
ext = ext[1:] if ext[0] == "." else ext
7777

78-
doc = toCAF(assy)
78+
_, doc = toCAF(assy)
7979
app = XCAFApp_Application.GetApplication_s()
8080

8181
store = XmlDrivers_DocumentStorageDriver(
@@ -167,7 +167,7 @@ def exportGLTF(
167167
orig_loc = assy.loc
168168
assy.loc *= Location((0, 0, 0), (1, 0, 0), -90)
169169

170-
doc = toCAF(assy, True, True, tolerance, angularTolerance)
170+
_, doc = toCAF(assy, True, True, tolerance, angularTolerance)
171171

172172
writer = RWGltf_CafWriter(TCollection_AsciiString(path), binary)
173173
result = writer.Perform(

tests/test_assembly.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ def test_assembly(simple_assy, nested_assy):
484484
)
485485
def test_assy_root_name(assy_fixture, root_name, request):
486486
assy = request.getfixturevalue(assy_fixture)
487-
doc = toCAF(assy, True)
487+
_, doc = toCAF(assy, True)
488488
root = get_doc_nodes(doc, False)[0]
489489
if root_name:
490490
assert root["name"] == root_name
@@ -615,7 +615,7 @@ def test_save_raises(nested_assy):
615615
def test_leaf_node_count(assy_fixture, count, request):
616616

617617
assy = request.getfixturevalue(assy_fixture)
618-
doc = toCAF(assy, True)
618+
_, doc = toCAF(assy, True)
619619

620620
assert len(get_doc_nodes(doc, True)) == count
621621

@@ -674,7 +674,7 @@ def check_nodes(doc, expected):
674674
assert pytest.approx(n[k], abs=1e-3) == v
675675

676676
assy = request.getfixturevalue(assy_fixture)
677-
doc = toCAF(assy, False)
677+
_, doc = toCAF(assy, False)
678678
check_nodes(doc, expected)
679679

680680

@@ -822,7 +822,7 @@ def check_nodes(doc, expected, is_STEP=False):
822822
assert pytest.approx(n[k], abs=1e-3) == v
823823

824824
assy = request.getfixturevalue(assy_fixture)
825-
doc = toCAF(assy, True)
825+
_, doc = toCAF(assy, True)
826826
check_nodes(doc, expected)
827827

828828
# repeat color check again - after STEP export round trip

0 commit comments

Comments
 (0)