Salome HOME
Merge branch 'Dev_1.2.0' of newgeom:newgeom into Dev_1.2.0
[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 <Events_Error.h>
13
14 #include <vector>
15
16
17 void getColor(ResultPtr theResult, std::vector<int>& theColor)
18 {
19   theColor.clear();
20   // get color from the attribute of the result
21   if (theResult.get() != NULL && theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
22     AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
23     if (aColorAttr.get() && aColorAttr->size()) {
24       theColor.push_back(aColorAttr->value(0));
25       theColor.push_back(aColorAttr->value(1));
26       theColor.push_back(aColorAttr->value(2));
27     }
28   }
29 }
30
31 void getDefaultColor(ResultPtr theResult, AISObjectPtr thePrs, std::vector<int>& theColor)
32 {
33   theColor.clear();
34   // get default color from the preferences manager for the given result
35   if (theColor.empty()) {
36     std::string aSection, aName, aDefault;
37     theResult->colorConfigInfo(aSection, aName, aDefault);
38     if (!aSection.empty() && !aName.empty()) {
39       theColor = Config_PropManager::color(aSection, aName, aDefault);
40     }
41   }
42   if (theColor.empty()) {
43     // all AIS objects, where the color is not set, are in black.
44     // The color should be defined in XML or set in the attribute
45     theColor = Config_PropManager::color("Visualization", "object_default_color", "#000000");
46     Events_Error::send("A default color is not defined in the preferences for this kind of result");
47   }
48 }
49
50 bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
51                                            std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
52 {
53   std::vector<int> aColor;
54
55   getColor(theResult, aColor);
56   if (aColor.empty())
57     getDefaultColor(theResult, thePrs, aColor);
58
59   return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);
60 }