Import: Fix export crash when hidden object in Part. (#14567)

This commit is contained in:
PaddleStroke
2025-07-18 14:55:46 +02:00
committed by Chris Hennes
parent 41f539dbaf
commit a897057ebb

View File

@@ -570,15 +570,29 @@ TDF_Label ExportOCAF2::exportObject(App::DocumentObject* parentObj,
// Can be fixed with following
// if ( !override.IsNull() && isComponent )
// setDefaultInstanceColor( override, PSA);
//
auto childShape = aShapeTool->GetShape(childLabel);
Quantity_ColorRGBA col;
if (!aColorTool->GetInstanceColor(childShape, XCAFDoc_ColorGen, col)
&& !aColorTool->GetInstanceColor(childShape, XCAFDoc_ColorSurf, col)
&& !aColorTool->GetInstanceColor(childShape, XCAFDoc_ColorCurv, col)) {
auto& c = options.defaultColor;
aColorTool->SetColor(childLabel, Tools::convertColor(c), XCAFDoc_ColorGen);
FC_WARN(Tools::labelName(childLabel) << " set default color");
// First, check if a color was already set (e.g., for a sub-element).
Quantity_ColorRGBA existingColor;
bool hasExplicitColor =
aColorTool->GetColor(childLabel, XCAFDoc_ColorGen, existingColor)
|| aColorTool->GetColor(childLabel, XCAFDoc_ColorSurf, existingColor)
|| aColorTool->GetColor(childLabel, XCAFDoc_ColorCurv, existingColor);
if (!hasExplicitColor) {
// The label has no color, which would causes a crash.
Quantity_ColorRGBA inheritedColor;
// Fetch the effective color from the shape instance.
auto childShape = aShapeTool->GetShape(childLabel);
if (aColorTool->GetInstanceColor(childShape, XCAFDoc_ColorSurf, inheritedColor)
|| aColorTool->GetInstanceColor(childShape, XCAFDoc_ColorGen, inheritedColor)) {
aColorTool->SetColor(childLabel, inheritedColor, XCAFDoc_ColorSurf);
}
else {
// As a fallback, use the exporter's default color.
auto& c = options.defaultColor;
aColorTool->SetColor(childLabel, Tools::convertColor(c), XCAFDoc_ColorGen);
}
}
aColorTool->SetVisibility(childLabel, Standard_False);
}