How to get centroid using XDE?


I try to access the attribute of assembly tree of XDE.

I can get names of assembly or component but I can't get centroid.

Here is my code.

Please help me.


    STEPCAFControl_Reader reader;
    IFSelect_ReturnStatus stat = reader.ReadFile("filename");

    Handle(TDocStd_Document) aDoc;

    Handle(XCAFApp_Application) anApp = XCAFApp_Application::GetApplication();

    anApp->NewDocument("MDTV-XCAF", aDoc);

    if (!reader.Transfer(aDoc)) {
        std::cout << "Cannot read any relevant data from the STEP file" << endl;
        // abandon ..

    Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
    TDF_LabelSequence labelSequence;

    for (int i = 1; i <= labelSequence.Length(); i++)
        const TDF_Label& label = labelSequence.Value(i);
        TopoDS_Shape S = myAssembly->GetShape(label);
        Handle(TDataStd_Name) name;
        if (label.FindAttribute(TDataStd_Name::GetID(), name))
            TCollection_ExtendedString extstr = name->Get();
        gp_Pnt pos;
        Handle(XCAFDoc_Centroid) C;
        if (label.FindAttribute(XCAFDoc_Centroid::GetID(), C))
            pos = C->Get();

Yu Nakane's picture

Sorry, I complete it myself.