Use XCAFDoc_ColorTool to set the color of a TopoDS_Face, ,then save it as a STEP file.
Viewing with CAD assistant is normal.
Freecad and Solidwork don't show colors.
C++:
Handle(TDocStd_Document) hDoc;
Quantity_Color redColor(Quantity_NOC_RED);
XCAFApp_Application::GetApplication()->NewDocument("MDTV-XCAF", hDoc);
Handle(XCAFDoc_ColorTool) hColorTool = XCAFDoc_DocumentTool::ColorTool(hDoc->Main());
Handle(XCAFDoc_ShapeTool) hShapeTool = XCAFDoc_DocumentTool::ShapeTool(hDoc->Main());
gp_Circ aCirc(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), 100);
BRepBuilderAPI_MakeWire wire;
TopoDS_Edge aEdge = BRepBuilderAPI_MakeEdge(aCirc);
wire.Add(aEdge);
BRepBuilderAPI_MakeFace face(wire.Wire());
TDF_Label aLabel = hShapeTool->NewShape();
TDataStd_Name::Set(aLabel, "testModel");
TDF_Label newLabel = hShapeTool->AddComponent(aLabel, face.Face());
hColorTool->SetColor(newLabel, redColor, XCAFDoc_ColorSurf);
hColorTool->SetColor(newLabel, redColor, XCAFDoc_ColorGen);
hColorTool->SetColor(newLabel, redColor, XCAFDoc_ColorCurv);
hShapeTool->UpdateAssemblies();
STEPCAFControl_Writer aWriter;
aWriter.SetColorMode(Standard_True);
if (aWriter.Transfer(hDoc, STEPControl_AsIs) != IFSelect_RetDone)
{
std::cerr << "Failed to transfer document" << std::endl;
return 0;
}
if (aWriter.Write("myColoredFace.stp") != IFSelect_RetDone)
{
std::cerr << "Failed to write STEP file" << std::endl;
return 0;
}
Viewing with CAD assistant is normal.
Freecad and Solidwork don't show colors.