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 <ModelAPI_Session.h>
11 #include <Config_PropManager.h>
13 #include <Events_Error.h>
19 void getColor(ResultPtr theResult, std::vector<int>& theColor)
22 // get color from the attribute of the result
23 if (theResult.get() != NULL && theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
24 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
25 if (aColorAttr.get() && aColorAttr->size()) {
26 theColor.push_back(aColorAttr->value(0));
27 theColor.push_back(aColorAttr->value(1));
28 theColor.push_back(aColorAttr->value(2));
33 void getDefaultColor(ResultPtr theResult, std::vector<int>& theColor)
36 // get default color from the preferences manager for the given result
37 if (theColor.empty()) {
38 std::string aSection, aName, aDefault;
39 theResult->colorConfigInfo(aSection, aName, aDefault);
40 if (!aSection.empty() && !aName.empty()) {
41 theColor = Config_PropManager::color(aSection, aName, aDefault);
44 if (theColor.empty()) {
45 // all AIS objects, where the color is not set, are in black.
46 // The color should be defined in XML or set in the attribute
47 theColor = Config_PropManager::color("Visualization", "object_default_color", "#000000");
48 Events_Error::send("A default color is not defined in the preferences for this kind of result");
52 void XGUI_CustomPrs::getResultColor(ResultPtr theResult, std::vector<int>& theColor)
54 getColor(theResult, theColor);
56 getDefaultColor(theResult, theColor);
59 bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
60 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
62 std::vector<int> aColor;
64 getResultColor(theResult, aColor);
66 SessionPtr aMgr = ModelAPI_Session::get();
67 if (aMgr->activeDocument() != theResult->document()) {
68 QColor aQColor(aColor[0], aColor[1], aColor[2]);
69 QColor aNewColor = QColor::fromHsvF(aQColor.hueF(), aQColor.saturationF()/3., aQColor.valueF());
70 aColor[0] = aNewColor.red();
71 aColor[1] = aNewColor.green();
72 aColor[2] = aNewColor.blue();
74 return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);