//=======================================================================
//function : DisplayText
//purpose :
//=======================================================================
static void DisplayText (const TDF_Label& aLabel,
const Handle(Prs3d_Presentation)& aPrs,
const Handle(Prs3d_TextAspect)& anAspect,
const TopLoc_Location& aLocation)
{
// first label itself 第一个标签本身
Handle (TDataStd_Name) aName;
if (aLabel.FindAttribute (TDataStd_Name::GetID(), aName)) {
TopoDS_Shape aShape;
if (XCAFDoc_ShapeTool::GetShape (aLabel, aShape)) {
// 找到要显示为边界框中间的位置
aShape.Move (aLocation);
Bnd_Box aBox;
BRepBndLib::Add (aShape, aBox);
if ( ! aBox.IsVoid() )
{
Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
aBox.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);//获取形状的包围盒
gp_Pnt aPnt (0.5 * (aXmin + aXmax), 0.5 * (aYmin + aYmax), 0.5 * (aZmin + aZmax));
Prs3d_Text::Draw (aPrs->CurrentGroup(), anAspect, aName->Get(), aPnt);
}
}
}
TDF_LabelSequence seq;
// attributes of subshapes 子形状的属性
if (XCAFDoc_ShapeTool::GetSubShapes (aLabel, seq)) {
Standard_Integer i = 1;
for (i = 1; i <= seq.Length(); i++) {
TDF_Label aL = seq.Value (i);
//suppose that subshapes do not contain locations假设子形状不包含位置
DisplayText (aL, aPrs, anAspect, aLocation);
}
}
// attributes of components 组件的属性
seq.Clear();
if (XCAFDoc_ShapeTool::GetComponents (aLabel, seq)) {
Standard_Integer i = 1;
for (i = 1; i <= seq.Length(); i++) {
TDF_Label aL = seq.Value (i);
DisplayText (aL, aPrs, anAspect, aLocation);
TDF_Label aRefLabel;
// attributes of references 引用的属性
TopLoc_Location aLoc = XCAFDoc_ShapeTool::GetLocation (aL);
if (XCAFDoc_ShapeTool::GetReferredShape (aL, aRefLabel)) {
DisplayText (aRefLabel, aPrs, anAspect, aLoc);
}
}
}
}
1、aLabel.FindAttribute (TDataStd_Name::GetID(), aName) 是从导入的alabel中获取的属性名字到aName,可以使用aName->Get(),获取到字符串名字
2、XCAFDoc_ShapeTool::GetShape (aLabel, aShape) 从aLabel中获取形状aShape
3、XCAFDoc_ShapeTool::GetSubShapes (aLabel, seq),获取子形状