]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_CustomPrs.cpp
Salome HOME
Change color for construction/body/group.
[modules/shaper.git] / src / XGUI / XGUI_CustomPrs.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        XGUI_CustomPrs.cpp
4 // Created:     10 Mar 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #include <XGUI_CustomPrs.h>
8
9 #include <ModelAPI_AttributeIntArray.h>
10 #include <Config_PropManager.h>
11
12 #include <vector>
13
14
15 void getColor(ResultPtr theResult, std::vector<int>& theColor)
16 {
17   theColor.clear();
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));
25     }
26   }
27 }
28
29 void getDefaultColor(ResultPtr theResult, AISObjectPtr thePrs, std::vector<int>& theColor)
30 {
31   theColor.clear();
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);
38     }
39   }
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");
43 }
44
45 bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
46                                            std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
47 {
48   std::vector<int> aColor;
49
50   getColor(theResult, aColor);
51   if (aColor.empty())
52     getDefaultColor(theResult, thePrs, aColor);
53
54   return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);
55 }