Colors added to shapes generated by StdPrs_BRepTextBuilder get lost during STEP export (XCAF)

Hi everyone,

I am experiencing some weird behavior with the STEP export of this 3D Text.
When I save the document in native XBF format everything works fine, just when I export to Step somehow the color is lost.
This only happens with StdPrs_BRepTextBuilder shapes for me, when I generate a BRepPrimAPI_MakeBox(5.0, 5.0, 5.0) the color gets exported without a problem. To verify I open both XBF and STEP with the CAD Assistant. I'm running this on Linux with cmake default options and V7_6_3.

Have a nice day!

Code:

Handle_TDocStd_Application app = new TDocStd_Application;
BinXCAFDrivers::DefineFormat(app);

Handle_TDocStd_Document doc;
app->NewDocument("BinXCAF", doc);

StdPrs_BRepFont brep_font("/usr/share/fonts/truetype/ubuntu/Ubuntu-R.ttf", 11, 0);
StdPrs_BRepTextBuilder builder;
TopoDS_Shape shape = builder.Perform(brep_font, "Awesome");

Handle_XCAFDoc_ShapeTool shapeTool = XCAFDoc_DocumentTool::ShapeTool(doc->Main());
Handle_XCAFDoc_ColorTool colorTool = XCAFDoc_DocumentTool::ColorTool(doc->Main());

TDF_Label label = shapeTool->AddShape(shape);
colorTool->SetColor(label, Quantity_NOC_GOLDENROD3, XCAFDoc_ColorGen);

app->SaveAs(doc, "/home/peterbe/hello_occ.xbf");

STEPCAFControl_Writer writer;
auto result = writer.Transfer(doc, STEPControl_AsIs);

if (result == Standard_True)
result = writer.Write("/home/peterbe/hello_occ.stp") == IFSelect_RetDone;

Dmitrii Pasukhin's picture

Hello,

Can you share a result xbf file?

Best regards, Dmitrii.

Peter Bendel's picture

Hi Dmitrii,

of course, thanks for looking into this :)
I tried another thing. When I load the STEP file in CAD Assistant and set the color there and load it back to my program, I can export and the color gets persisted in STEP.

Best regards,
Peter

Attachments: 
Dmitrii Pasukhin's picture

Thank you for your update.

I detect problem with your generated shape. There incorrect transformation ( I think that result of building has default transformation with error flag SCALED) It can be a regression. I need to check. As a result, when you call AddShape() tool add transform reference label. And you add your color on dummy label. So, I recommended 2 way - clear transformation of build shape (Set default transformation), the second way - use GetRefferedShape to get valid label to put attributes (XCAFDoc_ShapeTool::GetReferredShape(aNotValidL, aValidL)

I will check the status of build alghoritm and its output. But it will impact on the next release.

Best regards, Dmitrii.

Peter Bendel's picture

Hi Dmitrii,

I could not get the fixes working but I probably did something wrong anyway.
As you suggested the new version 7_7_1 fixes the problem so I switched and everything works fine.

Thank you!

Peter Bendel's picture

Hi, I think I found another possible problem regarding the color export. When used as a top level shape as in the code above all works as expected in 7_7_1 , but we do build a hierarchy of assemblies and there the color is missing in the final step file.

Best regards, Peter

Edit: Updated with correct exports

Handle_TDocStd_Application app = new TDocStd_Application;
BinXCAFDrivers::DefineFormat(app);

Handle_TDocStd_Document doc;
app->NewDocument("BinXCAF", doc);

StdPrs_BRepFont brep_font("/usr/share/fonts/truetype/ubuntu/Ubuntu-R.ttf", 11, 0);
StdPrs_BRepTextBuilder builder; 

TopoDS_Shape textShape = builder.Perform(brep_font, "Awesome");
TopoDS_Shape boxShape = BRepPrimAPI_MakeBox(5.0, 5.0, 5.0);

Handle_XCAFDoc_ShapeTool shapeTool = XCAFDoc_DocumentTool::ShapeTool(doc->Main());
Handle_XCAFDoc_ColorTool colorTool = XCAFDoc_DocumentTool::ColorTool(doc->Main());

Quantity_Color color(0.5, 0.2, 0.4, Quantity_TypeOfColor::Quantity_TOC_RGB);

TDF_Label textLabel = shapeTool->AddShape(textShape);
colorTool->SetColor(textLabel,color,XCAFDoc_ColorGen);

TDF_Label boxLabel = shapeTool->AddShape(boxShape);
colorTool->SetColor(boxLabel,color,XCAFDoc_ColorGen);

TDF_Label assembly = shapeTool->NewShape();

shapeTool->AddComponent(assembly, textLabel,TopLoc_Location(gp_Trsf()));
shapeTool->AddComponent(assembly, boxLabel,TopLoc_Location(gp_Trsf()));

shapeTool->UpdateAssemblies(); 
app->SaveAs(doc, "/mnt/d/hello_occ.xbf");

STEPCAFControl_Writer writer;
auto result = writer.Transfer(doc, STEPControl_AsIs);

if (result == Standard_True)
    result = writer.Write("/mnt/d/hello_occ.stp") == IFSelect_RetDone
Dmitrii Pasukhin's picture

Thank you.

You create not usual assembly. Your assembly has 2 level reference.
I will create the ticket, but it has low priority.

Please use the next code to avoid creating dummy reference.

TopoDS_Shape textShape = builder.Perform(brep_font, "Awesome");
TDF_Label textLabel = shapeTool->AddShape(textShape, false, false);
// or
TopoDS_Shape textShape = builder.Perform(brep_font, "Awesome");
textShape.Locate(TopLoc_Location());
TDF_Label textLabel = shapeTool->AddShape(textShape);
// or
TDF_Label textLabel = shapeTool->AddShape(textShape);
shapeTool->GetReferredShape(textLabel,textLabel);
colorTool->SetColor(textLabel,color,XCAFDoc_ColorGen);

Best regards, Dmitrii.