Name and Color display using XDE

Hi All,

I have an issue while using XDE. I am able to read and display .STEP assembly but not able to read component names and colors. I have tried the following code:-

{

    Handle(TopTools_HSequenceOfShape) aHSequenceOfShape= new TopTools_HSequenceOfShape();

      aHSequenceOfShape->Clear();

      //Create Document

      Handle(TDocStd_Document) aDoc;

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

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

 

      // create additional log file

      STEPCAFControl_Reader aReader;

      aReader.SetColorMode(true);

      aReader.SetNameMode(true);

      aReader.SetLayerMode(true);

      

 

      IFSelect_ReturnStatus status = aReader.ReadFile("Assem1.STEP");

 

      if (status != IFSelect_RetDone)

        //  return NO;
          qDebug() <<" Status fail";

      if (!aReader.Transfer(aDoc))

      {

          qDebug() <<"STEP File could not be transfered";

         // return NO;

      }

 

      Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(aDoc->Main ());

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

     TDF_LabelSequence frshapes;

/*

     Standard_Boolean findInstance = Standard_False;
     // (this is default value)
     TDF_Label aLabel = myAssembly->FindShape(aShape, findInstance);
     if (aLabel.IsNull()) {
     // no label found for this shape
     }*/

 

      myAssembly->GetFreeShapes(frshapes);

 

      TopoDS_Compound C;
      BRep_Builder B;
      B.MakeCompound(C);
        qDebug() <<" Status fail 1 check" << frshapes.Length();

      for(Standard_Integer i=1; i<=frshapes.Length(); i++) {
      TopoDS_Shape S = myAssembly->GetShape(frshapes.Value(i));
      B.Add(C,S);
        qDebug() <<" Status fail check";

     // get the shapes and attributes

         const TDF_Label& label = frshapes.Value(i);

         Handle(TDataStd_Name) name;

         if (label.FindAttribute(TDataStd_Name::GetID(),name))

         {

             TCollection_ExtendedString extstr = name->Get();

             cout << extstr << "test";

         }

 

         TopoDS_Shape shape;

        myAssembly->GetShape(label, shape);

         aHSequenceOfShape->Append(shape);
          anBisBox->SetColor(Quantity_NOC_RED);
         mContext->Display(anBisBox);

      }

 

please find attached step file.

Thanks in Advance.....

 

Attachments: 
Alexander Luger's picture

Hello shamsher!

As far as I know, names and colors are not stored in assembly-labels, but in components or simple shapes. Try to loop recursively through the assembly structure:

for(Standard_Integer i=1; i<=frshapes.Length(); i++) {

const TDF_Label& label = frshapes.Value(i);

if(myAssembly->isAssembly(label) { myAssembly->GetComponents(label) }

else if(myAssembly->isComponent(label) { myAssembly->GetReferredShape(label) }

else { myAssembly->GetShape(label) }

}

Regards,Alex