X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_CustomPrs.cpp;h=f3bd68300687122be19c59e1401ffa328eb69b85;hb=f421ab3932a5e09ae8082215c3eaaa8cc4944e02;hp=8b2b3eee85b409f441d7024acc9c0c0e999c2349;hpb=dc0cabde0516396f5f4458574d1d56c857478200;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_CustomPrs.cpp b/src/XGUI/XGUI_CustomPrs.cpp index 8b2b3eee8..f3bd68300 100644 --- a/src/XGUI/XGUI_CustomPrs.cpp +++ b/src/XGUI/XGUI_CustomPrs.cpp @@ -1,8 +1,21 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: XGUI_CustomPrs.cpp -// Created: 10 Mar 2015 -// Author: Natalia ERMOLAEVA +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include #include @@ -28,7 +41,7 @@ double getDeflection(const ResultPtr& theResult) { double aDeflection = -1; - // get color from the attribute of the result + // get deflection 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()); @@ -45,7 +58,7 @@ void getColor(const ResultPtr& theResult, std::vector& theColor) { theColor.clear(); // get color from the attribute of the result - if (theResult.get() != NULL && + if (theResult.get() != NULL && theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) { AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID()); if (aColorAttr.get() && aColorAttr->size()) { @@ -65,14 +78,14 @@ void XGUI_CustomPrs::getDefaultColor(ObjectPtr theObject, const bool isEmptyColo std::string aSection, aName, aDefault; theObject->colorConfigInfo(aSection, aName, aDefault); if (!aSection.empty() && !aName.empty()) { - theColor = Config_PropManager::color(aSection, aName, aDefault); + theColor = Config_PropManager::color(aSection, aName); } } 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_InfoMessage("XGUI_CustomPrs", + theColor = Config_PropManager::color("Visualization", "object_default_color"); + Events_InfoMessage("XGUI_CustomPrs", "A default color is not defined in the preferences for this kind of result").send(); } } @@ -97,15 +110,32 @@ double XGUI_CustomPrs::getDefaultDeflection(const ObjectPtr& theObject) } } if (isConstruction) - aDeflection = Config_PropManager::real("Visualization", "construction_deflection", - ModelAPI_ResultConstruction::DEFAULT_DEFLECTION()); + aDeflection = Config_PropManager::real("Visualization", "construction_deflection"); else - aDeflection = Config_PropManager::real("Visualization", "body_deflection", - ModelAPI_ResultBody::DEFAULT_DEFLECTION()); + aDeflection = Config_PropManager::real("Visualization", "body_deflection"); } return aDeflection; } +double getTransparency(const ResultPtr& theResult) +{ + double aTransparency = -1; + // get transparency from the attribute of the result + if (theResult.get() != NULL && + theResult->data()->attribute(ModelAPI_Result::TRANSPARENCY_ID()).get() != NULL) { + AttributeDoublePtr aDoubleAttr = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID()); + if (aDoubleAttr.get() && aDoubleAttr->isInitialized()) { + aTransparency = aDoubleAttr->value(); + } + } + return aTransparency; +} + +double getDefaultTransparency(const ResultPtr& theResult) +{ + return Config_PropManager::integer("Visualization", "shaper_default_transparency") / 100.; +} + XGUI_CustomPrs::XGUI_CustomPrs(XGUI_Workshop* theWorkshop) : myWorkshop(theWorkshop) { @@ -126,6 +156,14 @@ double XGUI_CustomPrs::getResultDeflection(const ResultPtr& theResult) return aDeflection; } +double XGUI_CustomPrs::getResultTransparency(const ResultPtr& theResult) +{ + double aTransparency = getTransparency(theResult); + if (aTransparency < 0) + aTransparency = getDefaultTransparency(theResult); + return aTransparency; +} + bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, std::shared_ptr theCustomPrs) { @@ -137,7 +175,7 @@ bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr the SessionPtr aMgr = ModelAPI_Session::get(); if (aMgr->activeDocument() != theResult->document()) { QColor aQColor(aColor[0], aColor[1], aColor[2]); - QColor aNewColor = + QColor aNewColor = QColor::fromHsvF(aQColor.hueF(), aQColor.saturationF()/3., aQColor.valueF()); aColor[0] = aNewColor.red(); aColor[1] = aNewColor.green(); @@ -146,6 +184,8 @@ bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr the aCustomized = !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]); aCustomized = thePrs->setDeflection(getResultDeflection(theResult)) | aCustomized; + + aCustomized = thePrs->setTransparency(getResultTransparency(theResult)) | aCustomized; } ModuleBase_IModule* aModule = myWorkshop->module(); aCustomized = aModule->customisePresentation(theResult, thePrs, theCustomPrs) || aCustomized;