diff --git a/src/Mod/Import/App/ExportOCAF.cpp b/src/Mod/Import/App/ExportOCAF.cpp index 8daa0cd823..41b0549d1d 100644 --- a/src/Mod/Import/App/ExportOCAF.cpp +++ b/src/Mod/Import/App/ExportOCAF.cpp @@ -50,20 +50,9 @@ #include #include "ExportOCAF.h" +#include "Tools.h" -#if OCC_VERSION_HEX >= 0x070500 -// See https://dev.opencascade.org/content/occt-3d-viewer-becomes-srgb-aware -#define OCC_COLOR_SPACE Quantity_TOC_sRGB -#else -#define OCC_COLOR_SPACE Quantity_TOC_RGB -#endif - -static inline Quantity_ColorRGBA convertColor(const App::Color& c) -{ - return Quantity_ColorRGBA(Quantity_Color(c.r, c.g, c.b, OCC_COLOR_SPACE), 1.0 - c.a); -} - using namespace Import; @@ -313,7 +302,7 @@ int ExportOCAF::saveShape(Part::Feature* part, if (!faceLabel.IsNull()) { const App::Color& color = colors[index - 1]; - col = convertColor(color); + col = Tools::convertColor(color); aColorTool->SetColor(faceLabel, col, XCAFDoc_ColorSurf); } } @@ -322,7 +311,7 @@ int ExportOCAF::saveShape(Part::Feature* part, } else if (!colors.empty()) { App::Color color = colors.front(); - col = convertColor(color); + col = Tools::convertColor(color); aColorTool->SetColor(shapeLabel, col, XCAFDoc_ColorGen); } @@ -423,7 +412,7 @@ void ExportOCAF::reallocateFreeShape(std::vector hierarchi if (!faceLabel.IsNull()) { const App::Color& color = colors[index - 1]; - col = convertColor(color); + col = Tools::convertColor(color); aColorTool->SetColor(faceLabel, col, XCAFDoc_ColorSurf); } } @@ -433,7 +422,7 @@ void ExportOCAF::reallocateFreeShape(std::vector hierarchi } else if (!colors.empty()) { App::Color color = colors.front(); - col = convertColor(color); + col = Tools::convertColor(color); aColorTool->SetColor(label, col, XCAFDoc_ColorGen); } } diff --git a/src/Mod/Import/App/ImportOCAF.cpp b/src/Mod/Import/App/ImportOCAF.cpp index d46354f4bf..b684ba8a68 100644 --- a/src/Mod/Import/App/ImportOCAF.cpp +++ b/src/Mod/Import/App/ImportOCAF.cpp @@ -55,6 +55,7 @@ #include #include "ImportOCAF.h" +#include "Tools.h" #ifdef HAVE_TBB @@ -65,23 +66,6 @@ using namespace Import; -#if OCC_VERSION_HEX >= 0x070500 -// See https://dev.opencascade.org/content/occt-3d-viewer-becomes-srgb-aware -#define OCC_COLOR_SPACE Quantity_TOC_sRGB -#else -#define OCC_COLOR_SPACE Quantity_TOC_RGB -#endif - -static inline App::Color convertColor(const Quantity_ColorRGBA& c) -{ - Standard_Real r, g, b; - c.GetRGB().Values(r, g, b, OCC_COLOR_SPACE); - return App::Color(static_cast(r), - static_cast(g), - static_cast(b), - 1.0f - static_cast(c.Alpha())); -} - #define OCAF_KEEP_PLACEMENT ImportOCAF::ImportOCAF(Handle(TDocStd_Document) h, App::Document* d, const std::string& name) @@ -414,7 +398,7 @@ void ImportOCAF::loadColors(Part::Feature* part, const TopoDS_Shape& aShape) if (aColorTool->GetColor(aShape, XCAFDoc_ColorGen, aColor) || aColorTool->GetColor(aShape, XCAFDoc_ColorSurf, aColor) || aColorTool->GetColor(aShape, XCAFDoc_ColorCurv, aColor)) { - color = convertColor(aColor); + color = Tools::convertColor(aColor); std::vector colors; colors.push_back(color); applyColors(part, colors); @@ -436,7 +420,7 @@ void ImportOCAF::loadColors(Part::Feature* part, const TopoDS_Shape& aShape) || aColorTool->GetColor(xp.Current(), XCAFDoc_ColorSurf, aColor) || aColorTool->GetColor(xp.Current(), XCAFDoc_ColorCurv, aColor)) { int index = faces.FindIndex(xp.Current()); - color = convertColor(aColor); + color = Tools::convertColor(aColor); faceColors[index - 1] = color; found_face_color = true; } @@ -547,7 +531,7 @@ void ImportXCAF::createShape(const TopoDS_Shape& shape, bool perface, bool setna jt = myColorMap.find(Part::ShapeMapHasher {}(xp.Current())); if (jt != myColorMap.end()) { int index = faces.FindIndex(xp.Current()); - faceColors[index - 1] = convertColor(jt->second); + faceColors[index - 1] = Tools::convertColor(jt->second); } xp.Next(); }