MCPcopy
hub / github.com/CadQuery/cadquery / get_doc_nodes

Function get_doc_nodes

tests/test_assembly.py:459–550  ·  view source on GitHub ↗

Read document and return list of nodes (dicts)

(doc, leaf=False)

Source from the content-addressed store, hash-verified

457
458
459def get_doc_nodes(doc, leaf=False):
460 """Read document and return list of nodes (dicts)"""
461
462 if leaf:
463 flags = XCAFPrs_DocumentExplorerFlags_OnlyLeafNodes
464 else:
465 flags = XCAFPrs_DocumentExplorerFlags_None
466
467 expl = XCAFPrs_DocumentExplorer(doc, flags, XCAFPrs_Style())
468 tool = XCAFDoc_DocumentTool.ShapeTool_s(doc.Main())
469
470 nodes = []
471 while expl.More():
472 node = expl.Current()
473 ctool = expl.ColorTool()
474 style = node.Style
475 label = node.RefLabel
476 label2 = node.Label
477
478 name_att = TDataStd_Name()
479 label.FindAttribute(TDataStd_Name.GetID_s(), name_att)
480
481 if label2.IsAttribute(TDataStd_Name.GetID_s()):
482 name_att = TDataStd_Name()
483 label2.FindAttribute(TDataStd_Name.GetID_s(), name_att)
484
485 color = style.GetColorSurfRGBA()
486 shape = expl.FindShapeFromPathId_s(doc, node.Id)
487 color_shape = Quantity_ColorRGBA()
488 ctool.GetColor(shape, XCAFDoc_ColorType.XCAFDoc_ColorSurf, color_shape)
489
490 # on STEP import colors applied to subshapes; and fused export mode
491 color_subshapes = None
492 color_subshapes_set = set()
493 faces = []
494 if not node.IsAssembly:
495 it = TDF_ChildIterator(label)
496 while it.More():
497 child = it.Value()
498 child_shape = tool.GetShape_s(child)
499 if child_shape.ShapeType() == TopAbs_ShapeEnum.TopAbs_FACE:
500 face = Face(child_shape)
501
502 color_subshape = Quantity_ColorRGBA()
503 face_color = None
504
505 if ctool.GetColor_s(
506 child, XCAFDoc_ColorType.XCAFDoc_ColorGen, color_subshape
507 ) or ctool.GetColor_s(
508 child, XCAFDoc_ColorType.XCAFDoc_ColorSurf, color_subshape
509 ):
510 face_color = (
511 *color_subshape.GetRGB().Values(Quantity_TOC_sRGB),
512 color_subshape.Alpha(),
513 )
514
515 faces.append(
516 {"center": face.Center().toTuple(), "color": face_color}

Callers 3

test_assy_root_nameFunction · 0.85
test_leaf_node_countFunction · 0.85
check_nodesFunction · 0.85

Calls 7

CenterMethod · 0.95
FaceClass · 0.90
appendMethod · 0.80
ShapeTypeMethod · 0.45
toTupleMethod · 0.45
addMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected