11
11
#include < BRep_Tool.hxx>
12
12
#include < XCAFDoc_DocumentTool.hxx>
13
13
14
- static std::string GetLabelName (const TDF_Label& label)
14
+ static std::string GetLabelNameNoRef (const TDF_Label& label)
15
15
{
16
16
Handle (TDataStd_Name) nameAttribute = new TDataStd_Name ();
17
17
if (!label.FindAttribute (nameAttribute->GetID (), nameAttribute)) {
18
18
return std::string ();
19
19
}
20
+
20
21
Standard_Integer utf8NameLength = nameAttribute->Get ().LengthOfCString ();
21
22
char * nameBuf = new char [utf8NameLength + 1 ];
22
23
nameAttribute->Get ().ToUTF8CString (nameBuf);
@@ -25,20 +26,14 @@ static std::string GetLabelName (const TDF_Label& label)
25
26
return name;
26
27
}
27
28
28
- static std::string GetLabelName (const Handle (XCAFDoc_ShapeTool)& shapeTool , const TDF_Label& label )
29
+ static std::string GetLabelName (const TDF_Label& label , const Handle (XCAFDoc_ShapeTool)& shapeTool )
29
30
{
30
31
if (XCAFDoc_ShapeTool::IsReference (label)) {
31
- TDF_Label referredShape ;
32
- shapeTool->GetReferredShape (label, referredShape );
33
- return GetLabelName (shapeTool, referredShape );
32
+ TDF_Label referredShapeLabel ;
33
+ shapeTool->GetReferredShape (label, referredShapeLabel );
34
+ return GetLabelName (referredShapeLabel, shapeTool );
34
35
}
35
- return GetLabelName (label);
36
- }
37
-
38
- static bool IsFreeShape (const TDF_Label& label, const Handle (XCAFDoc_ShapeTool)& shapeTool)
39
- {
40
- TopoDS_Shape tmpShape;
41
- return shapeTool->GetShape (label, tmpShape) && shapeTool->IsFree (label);
36
+ return GetLabelNameNoRef (label);
42
37
}
43
38
44
39
static std::string GetShapeName (const TopoDS_Shape& shape, const Handle (XCAFDoc_ShapeTool)& shapeTool)
@@ -47,43 +42,76 @@ static std::string GetShapeName (const TopoDS_Shape& shape, const Handle (XCAFDo
47
42
if (!shapeTool->Search (shape, shapeLabel)) {
48
43
return std::string ();
49
44
}
50
- return GetLabelName (shapeTool, shapeLabel );
45
+ return GetLabelName (shapeLabel, shapeTool );
51
46
}
52
47
53
- static bool GetShapeColor (const TopoDS_Shape& shape , const Handle (XCAFDoc_ColorTool)& colorTool, Color& color)
48
+ static bool GetLabelColorNoRef (const TDF_Label& label , const Handle (XCAFDoc_ColorTool)& colorTool, Color& color)
54
49
{
50
+ static const std::vector<XCAFDoc_ColorType> colorTypes = {
51
+ XCAFDoc_ColorSurf,
52
+ XCAFDoc_ColorCurv,
53
+ XCAFDoc_ColorGen
54
+ };
55
+
55
56
Quantity_Color qColor;
56
- if (colorTool->GetColor (shape, XCAFDoc_ColorSurf, qColor)) {
57
- color = Color (qColor.Red (), qColor.Green (), qColor.Blue ());
58
- return true ;
57
+ for (XCAFDoc_ColorType colorType : colorTypes) {
58
+ if (colorTool->GetColor (label, colorType, qColor)) {
59
+ color = Color (qColor.Red (), qColor.Green (), qColor.Blue ());
60
+ return true ;
61
+ }
59
62
}
60
- if (colorTool->GetColor (shape, XCAFDoc_ColorCurv, qColor)) {
61
- color = Color (qColor.Red (), qColor.Green (), qColor.Blue ());
63
+
64
+ return false ;
65
+ }
66
+
67
+ static bool GetLabelColor (const TDF_Label& label, const Handle (XCAFDoc_ShapeTool)& shapeTool, const Handle (XCAFDoc_ColorTool)& colorTool, Color& color)
68
+ {
69
+ if (GetLabelColorNoRef (label, colorTool, color)) {
62
70
return true ;
63
71
}
64
- if (colorTool->GetColor (shape, XCAFDoc_ColorGen, qColor)) {
65
- color = Color (qColor.Red (), qColor.Green (), qColor.Blue ());
66
- return true ;
72
+
73
+ if (XCAFDoc_ShapeTool::IsReference (label)) {
74
+ TDF_Label referredShape;
75
+ shapeTool->GetReferredShape (label, referredShape);
76
+ return GetLabelColor (referredShape, shapeTool, colorTool, color);
67
77
}
78
+
68
79
return false ;
69
80
}
70
81
82
+ static bool GetShapeColor (const TopoDS_Shape& shape, const Handle (XCAFDoc_ShapeTool)& shapeTool, const Handle (XCAFDoc_ColorTool)& colorTool, Color& color)
83
+ {
84
+ TDF_Label shapeLabel;
85
+ if (!shapeTool->Search (shape, shapeLabel)) {
86
+ return false ;
87
+ }
88
+ return GetLabelColor (shapeLabel, shapeTool, colorTool, color);
89
+ }
90
+
91
+ static bool IsFreeShape (const TDF_Label& label, const Handle (XCAFDoc_ShapeTool)& shapeTool)
92
+ {
93
+ TopoDS_Shape tmpShape;
94
+ return shapeTool->GetShape (label, tmpShape) && shapeTool->IsFree (label);
95
+ }
96
+
71
97
class XcafFace : public OcctFace
72
98
{
73
99
public:
74
- XcafFace (const TopoDS_Face& face, const Handle (XCAFDoc_ColorTool)& colorTool) :
100
+ XcafFace (const TopoDS_Face& face, const Handle (XCAFDoc_ShapeTool)& shapeTool, const Handle ( XCAFDoc_ColorTool)& colorTool) :
75
101
OcctFace (face),
102
+ shapeTool (shapeTool),
76
103
colorTool (colorTool)
77
104
{
78
105
79
106
}
80
107
81
108
virtual bool GetColor (Color& color) const override
82
109
{
83
- return GetShapeColor ((const TopoDS_Shape&) face, colorTool, color);
110
+ return GetShapeColor ((const TopoDS_Shape&) face, shapeTool, colorTool, color);
84
111
}
85
112
86
113
private:
114
+ const Handle (XCAFDoc_ShapeTool)& shapeTool;
87
115
const Handle (XCAFDoc_ColorTool)& colorTool;
88
116
};
89
117
@@ -106,14 +134,14 @@ class XcafShapeMesh : public Mesh
106
134
107
135
virtual bool GetColor (Color& color) const override
108
136
{
109
- return GetShapeColor (shape, colorTool, color);
137
+ return GetShapeColor (shape, shapeTool, colorTool, color);
110
138
}
111
139
112
140
virtual void EnumerateFaces (const std::function<void (const Face& face)>& onFace) const override
113
141
{
114
142
for (TopExp_Explorer ex (shape, TopAbs_FACE); ex.More (); ex.Next ()) {
115
143
const TopoDS_Face& face = TopoDS::Face (ex.Current ());
116
- XcafFace outputFace (face, colorTool);
144
+ XcafFace outputFace (face, shapeTool, colorTool);
117
145
onFace (outputFace);
118
146
}
119
147
}
@@ -127,9 +155,10 @@ class XcafShapeMesh : public Mesh
127
155
class XcafStandaloneFacesMesh : public Mesh
128
156
{
129
157
public:
130
- XcafStandaloneFacesMesh (const TopoDS_Shape& shape, const Handle (XCAFDoc_ColorTool)& colorTool) :
158
+ XcafStandaloneFacesMesh (const TopoDS_Shape& shape, const Handle (XCAFDoc_ShapeTool)& shapeTool, const Handle ( XCAFDoc_ColorTool)& colorTool) :
131
159
Mesh (),
132
160
shape (shape),
161
+ shapeTool (shapeTool),
133
162
colorTool (colorTool)
134
163
{
135
164
@@ -155,13 +184,14 @@ class XcafStandaloneFacesMesh : public Mesh
155
184
{
156
185
for (TopExp_Explorer ex (shape, TopAbs_FACE, TopAbs_SHELL); ex.More (); ex.Next ()) {
157
186
const TopoDS_Face& face = TopoDS::Face (ex.Current ());
158
- XcafFace outputFace (face, colorTool);
187
+ XcafFace outputFace (face, shapeTool, colorTool);
159
188
onFace (outputFace);
160
189
}
161
190
}
162
191
163
192
private:
164
193
const TopoDS_Shape& shape;
194
+ const Handle (XCAFDoc_ShapeTool)& shapeTool;
165
195
const Handle (XCAFDoc_ColorTool)& colorTool;
166
196
};
167
197
@@ -178,7 +208,7 @@ class XcafNode : public Node
178
208
179
209
virtual std::string GetName () const override
180
210
{
181
- return GetLabelName (shapeTool, label );
211
+ return GetLabelName (label, shapeTool );
182
212
}
183
213
184
214
virtual std::vector<NodePtr> GetChildren () const override
@@ -263,7 +293,7 @@ class XcafNode : public Node
263
293
}
264
294
265
295
// Create a mesh from faces that are not part of a shell
266
- XcafStandaloneFacesMesh standaloneFacesMesh (shape, colorTool);
296
+ XcafStandaloneFacesMesh standaloneFacesMesh (shape, shapeTool, colorTool);
267
297
if (standaloneFacesMesh.HasFaces ()) {
268
298
onMesh (standaloneFacesMesh);
269
299
}
0 commit comments