一.概述
TDF_Label是OCAF中核心数据结构,与TDF_Attribute结合使用,实现对模型的各种操作。
以下摘自OCCT7.7.0官方文档
A class each application has to implement. It is used to contain the application data. This abstract class, alongwith Label, is one of the cornerstones of Model Editor. The groundwork is to define the root of information. This information is to be attached to a Label, and could be of any of the following types:
- a feature
- a constraint
- a comment
通过TDF_Attribute派生类,我们可以实现对TDF_Label附加OCCT支持的且自己需要的任何模型信息,也可以从TDF_Label 获取对应的信息做其它处理。具体使用可以参考FreeCad,下图可以作为字典查询使用,也对TDF_Label 整体有一个认识
二.TDF_Attribute类图
三.简单的测试案例代码
//创建Doc数据TopoDS_Shape BoxOne = BRepPrimAPI_MakeBox(gp_Pnt(0.0, 0.0, 0.0), 30.0, 40.0, 50.0).Shape();TopoDS_Shape BoxTwo = BRepPrimAPI_MakeBox(gp_Pnt(100.0, 150.0, 150.0), 30.0, 40.0, 50.0).Shape();TopoDS_Shape BoxThree = BRepPrimAPI_MakeBox(gp_Pnt(300.0, 350.0, 350.0), 30.0, 40.0, 50.0).Shape();//顶层topo添加TDF_Label labelTempOne = m_shapeTool->AddShape(BoxOne);TDF_Label labelTempTwo = m_shapeTool->AddShape(BoxTwo);TDF_Label labelTempThree = m_shapeTool->NewShape();m_shapeTool->SetShape(labelTempThree, BoxThree);TDataStd_Name::Set(labelTempOne, TCollection_ExtendedString("BoxOne", true));TDataStd_Real::Set(labelTempOne, 0.01);TDataStd_Name::Set(labelTempTwo, TCollection_ExtendedString("BoxTwo", true));TDataStd_Real::Set(labelTempTwo, 0.02);TDataStd_Name::Set(labelTempThree, TCollection_ExtendedString("BoxThree", true));TDataStd_Real::Set(labelTempThree, 0.03);SetTextureToModel(labelTempOne, "D:\\11111.png");m_colorTool->SetColor(labelTempOne, Quantity_NOC_WHITE, XCAFDoc_ColorSurf);m_colorTool->SetColor(labelTempTwo, Quantity_NOC_BLUE3, XCAFDoc_ColorSurf);m_colorTool->SetColor(labelTempThree, Quantity_NOC_GREEN3, XCAFDoc_ColorSurf);TDF_LabelSequence FreeLabels;TDF_LabelSequence Labels;m_shapeTool->GetFreeShapes(FreeLabels);for (TDF_LabelSequence::Iterator aRootIter(FreeLabels); aRootIter.More(); aRootIter.Next()){const TDF_Label& aRootLabel = aRootIter.Value();// 读取标签属性TCollection_AsciiString strT;if (aRootLabel.IsAttribute(TDataStd_Name::GetID())){Handle(TDataStd_Name) nameAttr;aRootLabel.FindAttribute(TDataStd_Name::GetID(), nameAttr);if (!nameAttr.IsNull()){strT = nameAttr->Get();}}double realAttrValue = 0.0;if (aRootLabel.IsAttribute(TDataStd_Real::GetID())){Handle(TDataStd_Real) realAttr;aRootLabel.FindAttribute(TDataStd_Real::GetID(), realAttr);if (!realAttr.IsNull()){realAttrValue = realAttr->Get();}}if (m_visMaterialTool->IsSetShapeMaterial(aRootLabel)){Handle(XCAFDoc_VisMaterial) VMAttr = m_visMaterialTool->GetShapeMaterial(aRootLabel);if (!VMAttr.IsNull()){XCAFDoc_VisMaterialCommon XVMC = VMAttr->CommonMaterial();Handle(Image_Texture) DiffuseTexture = XVMC.DiffuseTexture;DiffuseTexture->WriteImage("D:\\tetureOut.png");}}}