For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

Extracting colours from a STEP file not always working

Tommy Tracey's picture
Forums: 

I am trying to read the Shapes and Colours from STEP files. This seems to work for some STEP models and not others. In one case I cannot get the colours and in another case I am missing lots of sub-shapes.

Can anyone spot if I am missing something

...
Handle(TDocStd_Application) XCAFApp = OCAFApp::GetApplication();
Handle(TDocStd_Document) XCAFDoc;
XCAFApp->NewDocument("MDTV-XCAF", XCAFDoc);

STEPCAFControl_Reader Reader;
Reader.SetColorMode(true);
Reader.SetLayerMode(true);
Reader.SetNameMode(true);
bool Ok = Reader.Perform(m_STEPFilename,XCAFDoc);
if (Ok)
{
Handle(XCAFDoc_ShapeTool) XCAFShapes = XCAFDoc_DocumentTool::ShapeTool(XCAFDoc->Main());
Handle(XCAFDoc_ColorTool) XCAFColours = XCAFDoc_DocumentTool::ColorTool(XCAFDoc->Main());
m_ShapeSequence.Clear();
m_ColourSequence.Clear();
TDF_LabelSequence Labels;
XCAFShapes->GetFreeShapes(Labels);
for ( int i=1; i {
TDF_Label Label=Labels.Value(i);
TraverseLabel(Label,XCAFShapes,XCAFColours);
}
}
...

void CGenerateData::TraverseLabel(TDF_Label &Label,Handle(XCAFDoc_ShapeTool) XCAFShapes,Handle(XCAFDoc_ColorTool) XCAFColours)
{
TopoDS_Shape Shape;
if (XCAFShapes->GetShape(Label,Shape))
{
Quantity_Color Colour;
if (XCAFColours->GetColor(Label, XCAFDoc_ColorGen, Colour) ||
XCAFColours->GetColor(Label, XCAFDoc_ColorSurf, Colour) ||
XCAFColours->GetColor(Label, XCAFDoc_ColorCurv, Colour) )
{
m_ShapeSequence->Append(Shape);
m_ColourSequence.Append(Colour);
}
else
{
if (Label.HasChild())
{
TDF_ChildIterator Iterator;
for (Iterator.Initialize(Label);
Iterator.More();
Iterator.Next())
{
TDF_Label SubShapeLabel=Iterator.Value();
TraverseLabel(SubShapeLabel,XCAFShapes,XCAFColours);
}
}
else
{
m_ShapeSequence->Append(Shape);
Quantity_Color Colour;
if (XCAFColours->GetColor(Label, XCAFDoc_ColorGen, Colour) ||
XCAFColours->GetColor(Label, XCAFDoc_ColorSurf, Colour) ||
XCAFColours->GetColor(Label, XCAFDoc_ColorCurv, Colour) )
{
m_ColourSequence.Append(Colour);
}
else
{
m_ColourSequence.Append(m_DefaultColour);
}
}
}
}
else
{
ASSERT(FALSE);
}
}

Contact us

Attention: DO NOT use this form for all kind of request for the removal of your personal data. Please follow this link for such cases.