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>
8 #include <XGUI_Workshop.h>
9 #include <XGUI_Displayer.h>
11 #include <ModuleBase_IModule.h>
13 #include <ModelAPI_AttributeIntArray.h>
14 #include <ModelAPI_Session.h>
15 #include <Config_PropManager.h>
17 #include <Events_InfoMessage.h>
23 void getColor(ResultPtr theResult, std::vector<int>& theColor)
26 // get color from the attribute of the result
27 if (theResult.get() != NULL && theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
28 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
29 if (aColorAttr.get() && aColorAttr->size()) {
30 theColor.push_back(aColorAttr->value(0));
31 theColor.push_back(aColorAttr->value(1));
32 theColor.push_back(aColorAttr->value(2));
37 void XGUI_CustomPrs::getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid,
38 std::vector<int>& theColor)
41 // get default color from the preferences manager for the given result
42 if (theColor.empty()) {
43 std::string aSection, aName, aDefault;
44 theObject->colorConfigInfo(aSection, aName, aDefault);
45 if (!aSection.empty() && !aName.empty()) {
46 theColor = Config_PropManager::color(aSection, aName, aDefault);
49 if (!isEmptyColorValid && theColor.empty()) {
50 // all AIS objects, where the color is not set, are in black.
51 // The color should be defined in XML or set in the attribute
52 theColor = Config_PropManager::color("Visualization", "object_default_color", "#000000");
53 Events_InfoMessage("XGUI_CustomPrs",
54 "A default color is not defined in the preferences for this kind of result").send();
58 XGUI_CustomPrs::XGUI_CustomPrs(XGUI_Workshop* theWorkshop)
59 : myWorkshop(theWorkshop)
63 void XGUI_CustomPrs::getResultColor(ResultPtr theResult, std::vector<int>& theColor)
65 getColor(theResult, theColor);
67 getDefaultColor(theResult, false, theColor);
70 bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
71 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
73 bool aCustomized = false;
74 if (theResult.get()) {
75 std::vector<int> aColor;
76 getResultColor(theResult, aColor);
78 SessionPtr aMgr = ModelAPI_Session::get();
79 if (aMgr->activeDocument() != theResult->document()) {
80 QColor aQColor(aColor[0], aColor[1], aColor[2]);
81 QColor aNewColor = QColor::fromHsvF(aQColor.hueF(), aQColor.saturationF()/3., aQColor.valueF());
82 aColor[0] = aNewColor.red();
83 aColor[1] = aNewColor.green();
84 aColor[2] = aNewColor.blue();
86 aCustomized = !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);
88 ModuleBase_IModule* aModule = myWorkshop->module();
89 aCustomized = aModule->customisePresentation(theResult, thePrs, theCustomPrs) || aCustomized;