X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_CustomPrs.cpp;h=373eb2fe6e4569b712544d41efa8ddd7cdff16bc;hb=42d8ecf39798c037945ca4bb9073d8dc31c53008;hp=c074a841e4ab3af76f0b33dee705234510d38f74;hpb=a24b7e6f4d112d5e7889fd76f030298fc428cd01;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_CustomPrs.cpp b/src/XGUI/XGUI_CustomPrs.cpp index c074a841e..373eb2fe6 100644 --- a/src/XGUI/XGUI_CustomPrs.cpp +++ b/src/XGUI/XGUI_CustomPrs.cpp @@ -5,16 +5,35 @@ // Author: Natalia ERMOLAEVA #include +#include +#include + +#include #include +#include +#include #include -#include +#include #include +#include +double getDeflection(const ResultPtr& theResult) +{ + double aDeflection = -1; + // get color from the attribute of the result + if (theResult.get() != NULL && + theResult->data()->attribute(ModelAPI_Result::DEFLECTION_ID()).get() != NULL) { + AttributeDoublePtr aDoubleAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID()); + if (aDoubleAttr.get() && aDoubleAttr->isInitialized()) + aDeflection = aDoubleAttr->value(); + } + return aDeflection; +} -void getColor(ResultPtr theResult, std::vector& theColor) +void getColor(const ResultPtr& theResult, std::vector& theColor) { theColor.clear(); // get color from the attribute of the result @@ -28,33 +47,73 @@ void getColor(ResultPtr theResult, std::vector& theColor) } } -void getDefaultColor(ResultPtr theResult, AISObjectPtr thePrs, std::vector& theColor) +void XGUI_CustomPrs::getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid, + std::vector& theColor) { theColor.clear(); // get default color from the preferences manager for the given result if (theColor.empty()) { std::string aSection, aName, aDefault; - theResult->colorConfigInfo(aSection, aName, aDefault); + theObject->colorConfigInfo(aSection, aName, aDefault); if (!aSection.empty() && !aName.empty()) { theColor = Config_PropManager::color(aSection, aName, aDefault); } } - if (theColor.empty()) { + if (!isEmptyColorValid && theColor.empty()) { // all AIS objects, where the color is not set, are in black. // The color should be defined in XML or set in the attribute theColor = Config_PropManager::color("Visualization", "object_default_color", "#000000"); - Events_Error::send("A default color is not defined in the preferences for this kind of result"); + Events_InfoMessage("XGUI_CustomPrs", + "A default color is not defined in the preferences for this kind of result").send(); } } +double XGUI_CustomPrs::getDefaultDeflection(const ObjectPtr& theObject) +{ + return Config_PropManager::real("Visualization", "result_deflection", "0.001"); +} + +XGUI_CustomPrs::XGUI_CustomPrs(XGUI_Workshop* theWorkshop) +: myWorkshop(theWorkshop) +{ +} + +void XGUI_CustomPrs::getResultColor(const ResultPtr& theResult, std::vector& theColor) +{ + getColor(theResult, theColor); + if (theColor.empty()) + getDefaultColor(theResult, false, theColor); +} + +double XGUI_CustomPrs::getResultDeflection(const ResultPtr& theResult) +{ + double aDeflection = getDeflection(theResult); + if (aDeflection < 0) + aDeflection = getDefaultDeflection(theResult); + return aDeflection; +} + bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, std::shared_ptr theCustomPrs) { - std::vector aColor; + bool aCustomized = false; + if (theResult.get()) { + std::vector aColor; + getResultColor(theResult, aColor); - getColor(theResult, aColor); - if (aColor.empty()) - getDefaultColor(theResult, thePrs, aColor); + SessionPtr aMgr = ModelAPI_Session::get(); + if (aMgr->activeDocument() != theResult->document()) { + QColor aQColor(aColor[0], aColor[1], aColor[2]); + QColor aNewColor = QColor::fromHsvF(aQColor.hueF(), aQColor.saturationF()/3., aQColor.valueF()); + aColor[0] = aNewColor.red(); + aColor[1] = aNewColor.green(); + aColor[2] = aNewColor.blue(); + } + aCustomized = !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]); - return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]); + aCustomized = thePrs->setDeflection(getResultDeflection(theResult)) | aCustomized; + } + ModuleBase_IModule* aModule = myWorkshop->module(); + aCustomized = aModule->customisePresentation(theResult, thePrs, theCustomPrs) || aCustomized; + return aCustomized; }