Sat, 12/10/2022 - 12:16
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!
Attachments:
Mon, 12/12/2022 - 21:08
Hello,
The quastion 1:
The relationship between shape label and color is reference. That is why, you can get list of the shapes from color for 3 types of connections (surf, curv and gen) and get one color from shape label for 3 types of connections (surf, curv, general).
Code sample of getting color from shape label:
The code sample how to get shapes from color label (need to be tested):
Quastion 2:
I think you work with only "part" shape name. Assembly components have 2 name (part name and own name).
if (XCAFDoc_ShapeTool::GetReferredShape(InputL, OutPutL)) give you own label of the part ( return false if you have not reference and OutPutL will be equal with InputL.
If you need more information, please let me now.
Thank you for your interest in OCCT.
Best regards, Dmitrii.