X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_CustomPrs.cpp;h=f3bd68300687122be19c59e1401ffa328eb69b85;hb=c7d72b1e9c2bf38f8cb27f9251c7a332401dc2fe;hp=395c7288bb9baadd8b4fbbdfc89ee744b73dfc76;hpb=72a191eb97b744b33d735c8d14f2693dbf3b13c2;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_CustomPrs.cpp b/src/XGUI/XGUI_CustomPrs.cpp index 395c7288b..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 @@ -11,20 +24,42 @@ #include #include +#include #include +#include +#include + +#include + #include -#include +#include #include #include +double getDeflection(const ResultPtr& theResult) +{ + double aDeflection = -1; + // 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()); + if (aDoubleAttr.get() && aDoubleAttr->isInitialized()) { + double aValue = aDoubleAttr->value(); + if (aValue > 0) /// zero value should not be used as a deflection(previous studies) + 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 - if (theResult.get() != NULL && theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).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()) { theColor.push_back(aColorAttr->value(0)); @@ -34,7 +69,8 @@ void getColor(ResultPtr theResult, std::vector& theColor) } } -void getDefaultColor(ObjectPtr theObject, std::vector& theColor, const bool isEmptyColorValid) +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 @@ -42,15 +78,62 @@ void getDefaultColor(ObjectPtr theObject, std::vector& theColor, const bool 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_Error::send("A default color is not defined in the preferences for this kind of result"); + 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(); + } +} + +double XGUI_CustomPrs::getDefaultDeflection(const ObjectPtr& theObject) +{ + double aDeflection = -1; + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + if (aResult.get()) { + bool isConstruction = false; + + std::string aResultGroup = aResult->groupName(); + if (aResultGroup == ModelAPI_ResultConstruction::group()) + isConstruction = true; + else if (aResultGroup == ModelAPI_ResultBody::group()) { + GeomShapePtr aGeomShape = aResult->shape(); + if (aGeomShape.get()) { + // if the shape could not be exploded on faces, it contains only wires, edges, and vertices + // correction of deviation for them should not influence to the application performance + GeomAPI_ShapeExplorer anExp(aGeomShape, GeomAPI_Shape::FACE); + isConstruction = !anExp.more(); + } + } + if (isConstruction) + aDeflection = Config_PropManager::real("Visualization", "construction_deflection"); + else + 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) @@ -58,11 +141,27 @@ XGUI_CustomPrs::XGUI_CustomPrs(XGUI_Workshop* theWorkshop) { } -void XGUI_CustomPrs::getResultColor(ResultPtr theResult, std::vector& theColor) +void XGUI_CustomPrs::getResultColor(const ResultPtr& theResult, std::vector& theColor) { getColor(theResult, theColor); if (theColor.empty()) - getDefaultColor(theResult, theColor, false); + getDefaultColor(theResult, false, theColor); +} + +double XGUI_CustomPrs::getResultDeflection(const ResultPtr& theResult) +{ + double aDeflection = getDeflection(theResult); + if (aDeflection < 0) + aDeflection = getDefaultDeflection(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, @@ -76,25 +175,19 @@ 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::fromHsvF(aQColor.hueF(), aQColor.saturationF()/3., aQColor.valueF()); + 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]); + + aCustomized = thePrs->setDeflection(getResultDeflection(theResult)) | aCustomized; + + aCustomized = thePrs->setTransparency(getResultTransparency(theResult)) | aCustomized; } - else { - XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - ObjectPtr anObject = aDisplayer->getObject(thePrs); - if (anObject.get()) { - std::vector aColor; - ModuleBase_IModule* aModule = myWorkshop->module(); - aModule->getColor(anObject, aColor); - if (aColor.empty()) - getDefaultColor(anObject, aColor, true); - if (!aColor.empty()) - thePrs->setColor(aColor[0], aColor[1], aColor[2]); - } - } + ModuleBase_IModule* aModule = myWorkshop->module(); + aCustomized = aModule->customisePresentation(theResult, thePrs, theCustomPrs) || aCustomized; return aCustomized; }