How can I split every parts of STEP file and thier names?
Question1 : Now I could use XCAFDoc_ShapeTool
and XCAFDoc_ColorTool
to get all shapes and all colors in XDE document.However, I don’t know how to attach these colors to their shapes.How can I get the relationship between colors and their shapes?This is my code:
std::vector<Handle(AIS_Shape)> myReadSTEP(QString &modelFileName)
{
Handle(TDocStd_Document) doc;
XCAFApp_Application::GetApplication()->NewDocument("MDTV-XCAF", doc);
STEPCAFControl_Reader myReader;
myReader.ReadFile(modelFileName.toStdString().c_str());
myReader.SetColorMode(true);
myReader.SetNameMode(true);
myReader.SetLayerMode(true);
myReader.Transfer(doc);
TDF_Label mainLabel = doc->Main();
Handle(XCAFDoc_ShapeTool) myShapeTool = XCAFDoc_DocumentTool::ShapeTool(mainLabel);
Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(mainLabel);
TDF_LabelSequence FreeShape;
myShapeTool->GetFreeShapes(FreeShape);
TDF_LabelSequence FreeSubShape;
std::vector<Handle(AIS_Shape)> shapeList;
TDF_LabelSequence aColLabels;
myColors->GetColors(aColLabels);
// color
for(TDF_LabelSequence::Iterator aColIter(aColLabels);aColIter.More();aColIter.Next())
{
Quantity_Color aCol; // to receive the values
TDF_Label aColLabel = aColIter.Value();
Handle(XCAFDoc_Color) aColorAttr;
if (!myColors->GetColor (aColLabel, aCol)) { continue; }
qDebug() << aCol.Red() << aCol.Green() << aCol.Blue();
}
// get every sub-shape
if(myShapeTool->GetComponents(FreeShape.First(),FreeSubShape,true))
{
for (int index = 1;index <= FreeSubShape.Size();index++)
{
TDF_Label label = FreeSubShape.Value(index);
TopoDS_Shape aShape = myShapeTool->GetShape(label);
Handle(AIS_Shape) ais_shape = new AIS_Shape(aShape);
shapeList.push_back(ais_shape);
// ------------------------------Name------------------------------
// Handle(TDataStd_Name) aNameAttr;
// if(!label.FindAttribute(TDataStd_Name::GetID(), aNameAttr))
// {
// qDebug() << "no name is attached!";
// }
// TCollection_ExtendedString aName = aNameAttr->Get();
// TCollection_AsciiString Asciiname(aName);
// std::string stringName= Asciiname.ToCString();
// qDebug() << QString().fromStdString(stringName);
}
}
return shapeList;
}
I found that This data structure is fitted for data exchange, rather than for use by the final application;
in OCCT manual.Is XDE not the best option to display STEP file? Does XDE need XCAFPrs_AISObject
to solve problems?
Question 2: Annotated code can get the name of sub-shape.However , the output only is NAUO01
or NAUOXX
.What is the reason for this quesiton?
Thanks in advance!
Read more here: Source link