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>
12 #include <Events_Error.h>
17 void getColor(ResultPtr theResult, std::vector<int>& theColor)
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));
31 void getDefaultColor(ResultPtr theResult, AISObjectPtr thePrs, std::vector<int>& theColor)
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);
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");
50 bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
51 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
53 std::vector<int> aColor;
55 getColor(theResult, aColor);
57 getDefaultColor(theResult, thePrs, aColor);
59 return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);