Skip to content

Commit d881053

Browse files
committed
Names don't work in case of reference shapes #24
1 parent 60057e4 commit d881053

File tree

4 files changed

+48
-7
lines changed

4 files changed

+48
-7
lines changed

dist/occt-import-js.wasm

457 Bytes
Binary file not shown.

occt-import-js/example/main.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,34 @@ static void WriteNode (const NodePtr& node, ObjWriter& writer)
7171
}
7272
}
7373

74+
static void DumpNode (const NodePtr& node, int level)
75+
{
76+
auto writeIndent = [](int indentLevel) {
77+
for (int i = 0; i < indentLevel; i++) {
78+
std::cout << " ";
79+
}
80+
};
81+
82+
writeIndent (level);
83+
std::cout << "-> Node: " << node->GetName ();
84+
std::cout << std::endl;
85+
86+
node->EnumerateMeshes ([&](const Mesh& mesh) {
87+
writeIndent (level);
88+
std::cout << " Mesh: " << mesh.GetName ();
89+
Color color;
90+
if (mesh.GetColor (color)) {
91+
std::cout << " (" << color.r << ", " << color.g << ", " << color.b << ")";
92+
}
93+
std::cout << std::endl;
94+
});
95+
96+
std::vector<NodePtr> children = node->GetChildren ();
97+
for (const NodePtr& child : children) {
98+
DumpNode (child, level + 1);
99+
}
100+
}
101+
74102
int main (int argc, const char* argv[])
75103
{
76104
if (argc < 2) {
@@ -104,8 +132,11 @@ int main (int argc, const char* argv[])
104132
return 1;
105133
}
106134

107-
ObjWriter writer;
108-
WriteNode (importer->GetRootNode (), writer);
135+
//ObjWriter writer;
136+
//WriteNode (importer->GetRootNode (), writer);
137+
138+
DumpNode (importer->GetRootNode (), 0);
109139

140+
system ("PAUSE");
110141
return 0;
111142
}

occt-import-js/src/importer-xcaf.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ static std::string GetLabelName (const TDF_Label& label)
2525
return name;
2626
}
2727

28+
static std::string GetLabelName (const Handle (XCAFDoc_ShapeTool)& shapeTool, const TDF_Label& label)
29+
{
30+
if (XCAFDoc_ShapeTool::IsReference (label)) {
31+
TDF_Label referredShape;
32+
shapeTool->GetReferredShape (label, referredShape);
33+
return GetLabelName (shapeTool, referredShape);
34+
}
35+
return GetLabelName (label);
36+
}
37+
2838
static bool IsFreeShape (const TDF_Label& label, const Handle (XCAFDoc_ShapeTool)& shapeTool)
2939
{
3040
TopoDS_Shape tmpShape;
@@ -37,7 +47,7 @@ static std::string GetShapeName (const TopoDS_Shape& shape, const Handle (XCAFDo
3747
if (!shapeTool->Search (shape, shapeLabel)) {
3848
return std::string ();
3949
}
40-
return GetLabelName (shapeLabel);
50+
return GetLabelName (shapeTool, shapeLabel);
4151
}
4252

4353
static bool GetShapeColor (const TopoDS_Shape& shape, const Handle (XCAFDoc_ColorTool)& colorTool, Color& color)
@@ -168,7 +178,7 @@ class XcafNode : public Node
168178

169179
virtual std::string GetName () const override
170180
{
171-
return GetLabelName (label);
181+
return GetLabelName (shapeTool, label);
172182
}
173183

174184
virtual std::vector<NodePtr> GetChildren () const override

test/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,17 @@ it ('as1_pe_203', function () {
9797
children : []
9898
},
9999
{
100-
name : "L_BRACKET_ASSEMBLY",
100+
name : "L_BRACKET_ASSEMBLY_ASM",
101101
meshes : [1, 2, 3, 4, 5, 6, 7],
102102
children : []
103103
},
104104
{
105-
name : "L_BRACKET_ASSEMBLY",
105+
name : "L_BRACKET_ASSEMBLY_ASM",
106106
meshes : [8, 9, 10, 11, 12, 13, 14],
107107
children : []
108108
},
109109
{
110-
name : "ROD",
110+
name : "ROD_ASM",
111111
meshes : [15, 16, 17],
112112
children : []
113113
}

0 commit comments

Comments
 (0)