1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: XGUI_CustomPrs.cpp
4 // Created: 10 Mar 2015
5 // Author: Natalia ERMOLAEVA
7 #include <XGUI_CustomPrs.h>
9 #include <ModelAPI_AttributeIntArray.h>
10 #include <Config_PropManager.h>
15 void getColor(ResultPtr theResult, std::vector<int>& theColor)
18 // get color from the attribute of the result
19 if (theResult.get() != NULL && theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
20 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
21 if (aColorAttr.get() && aColorAttr->size()) {
22 theColor.push_back(aColorAttr->value(0));
23 theColor.push_back(aColorAttr->value(1));
24 theColor.push_back(aColorAttr->value(2));
29 void getDefaultColor(ResultPtr theResult, AISObjectPtr thePrs, std::vector<int>& theColor)
32 // get default color from the preferences manager for the given result
33 if (theColor.empty()) {
34 std::string aSection, aName, aDefault;
35 theResult->colorConfigInfo(aSection, aName, aDefault);
36 if (!aSection.empty() && !aName.empty()) {
37 theColor = Config_PropManager::color(aSection, aName, aDefault);
40 if (theColor.empty()) // all AIS objects, where the color is not set, a white.
41 // The color should be defined in XML or set in the attribute
42 theColor = Config_PropManager::color("Visualization", "object_default_color", "#ffffff");
45 bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
46 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
48 std::vector<int> aColor;
50 getColor(theResult, aColor);
52 getDefaultColor(theResult, thePrs, aColor);
54 return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);