The function GetColor in XCAFDoc_ColorTool can not work?

hi, all!

       I try to get the color of shapes by OCAF, but it seems the function GetColor in XCAFDoc_ColorTool can not work?

       In addition, is there any other way to get the related color of a shape?

 

The following code:

---------------------------------------------------

Standard_CString strFileName = T2A(lpszFile);

IGESCAFControl_Reader Reader; 

IFSelect_ReturnStatus readstatus = Reader.ReadFile(strFileName); 

if (readstatus != IFSelect_RetDone) {

return FALSE;

}

//Get Doc

Handle(TDocStd_Document) m_myOcafDoc;

if (!Reader.Transfer(m_myOcafDoc)) {

return FALSE;

//Get Shape Tool

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

//Get Color Tool

Handle(XCAFDoc_ColorTool) m_myColors = XCAFDoc_DocumentTool::ColorTool(m_myOcafDoc->Main());

TDF_LabelSequence labels;

myAssembly->GetShapes(labels);

//step Shapes

Standard_Integer i=0;

Standard_Integer iLen = labels.Length();

for (i=1; i<=iLen; i++)

{

TDF_Label aLabel = labels.Value(i);

Handle(TDataStd_Name) N;

if (!aLabel.FindAttribute(TDataStd_Name::GetID(), N)){

continue;

}

TCollection_ExtendedString name = N->Get();

CString sName = name.ToWideString();

 

Quantity_Color col;

//Here ,why always return false when i called GetColor function?

Standard_Integer bCol = m_myColors->GetColor(aLabel, col);

}

Kirill Gavrilov's picture

> TDF_LabelSequence labels;
> myAssembly->GetShapes(labels);
> Standard_Integer bCol = m_myColors->GetColor(aLabel, col);

This wouldn't work like this - colors can be assigned not just to the root elements, but also at every level of assembly hierarchy as well as on sub-shape level.
In many cases, the colors are actually assigned to Faces.

Handling colors properly is tricky - you need to go from top to the bottom level of the tree and pick up styles at every level.
See XCAFPrs::CollectStyleSettings() and XCAFPrs_AISObject for details.

JIN JIN's picture

hello, Kirill!

Thank you for your help, Your suggestion is very useful, I have already got the color!

warm regards,

Jin.