X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModelHighAPI%2FModelHighAPI_Selection.cpp;h=30f92c2223cdf4d2038aeee867879080eb1ae5eb;hb=2cb4458b35ae6c9561a35b3b18dbdb673d0c12c9;hp=e66fdb5945d41c744a54586400d615a18a4240ff;hpb=625c6cae75d4d29ea4e3b0265d65b9fecc694d87;p=modules%2Fshaper.git diff --git a/src/ModelHighAPI/ModelHighAPI_Selection.cpp b/src/ModelHighAPI/ModelHighAPI_Selection.cpp index e66fdb594..30f92c222 100644 --- a/src/ModelHighAPI/ModelHighAPI_Selection.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Selection.cpp @@ -1,16 +1,33 @@ -// Name : ModelHighAPI_Selection.cpp -// Purpose: +// 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 // -// History: -// 06/06/16 - Sergey POKHODENKO - Creation of the file -//-------------------------------------------------------------------------------------- #include "ModelHighAPI_Selection.h" #include #include #include #include +#include +#include + + +#include //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- @@ -33,6 +50,35 @@ ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType, { } +ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType, + const GeomPointPtr& theSubShapeInnerPoint) +: myVariantType(VT_TypeInnerPointPair) +, myTypeInnerPointPair(theType, theSubShapeInnerPoint) +{ +} + +ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType, + const std::list& theSubShapeInnerPoint) +: myVariantType(VT_TypeInnerPointPair) +{ + double aCoordinates[3] = { 0.0, 0.0, 0.0 }; + double* aCIt = aCoordinates; + std::list::const_iterator aPIt = theSubShapeInnerPoint.begin(); + for (; aPIt != theSubShapeInnerPoint.end(); ++aPIt, ++aCIt) + *aCIt = *aPIt; + + GeomPointPtr anInnerPoint(new GeomAPI_Pnt(aCoordinates[0], aCoordinates[1], aCoordinates[2])); + myTypeInnerPointPair = std::pair(theType, anInnerPoint); +} + +ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType, + const std::string& theContextName, const int theIndex) + : myVariantType(VT_WeakNamingPair) + , myWeakNamingPair(theType, std::pair(theContextName, theIndex)) +{ +} + + ModelHighAPI_Selection::~ModelHighAPI_Selection() { } @@ -43,8 +89,25 @@ void ModelHighAPI_Selection::fillAttribute( { switch(myVariantType) { case VT_Empty: return; - case VT_ResultSubShapePair: theAttribute->setValue(myResultSubShapePair.first, myResultSubShapePair.second); return; - case VT_TypeSubShapeNamePair: theAttribute->selectSubShape(myTypeSubShapeNamePair.first, myTypeSubShapeNamePair.second); return; + case VT_ResultSubShapePair: + theAttribute->setValue(myResultSubShapePair.first, myResultSubShapePair.second); + return; + case VT_TypeSubShapeNamePair: + theAttribute->selectSubShape(myTypeSubShapeNamePair.first, myTypeSubShapeNamePair.second); + break; + case VT_TypeInnerPointPair: + theAttribute->selectSubShape(myTypeInnerPointPair.first, myTypeInnerPointPair.second); + return; + case VT_WeakNamingPair: + theAttribute->selectSubShape( + myWeakNamingPair.first, myWeakNamingPair.second.first, myWeakNamingPair.second.second); + break; + } + + if (theAttribute->isInvalid()) { + FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner()); + aFeature->setError( + std::string("Error: attribute \"") + theAttribute->id() + std::string("\" is invalid.")); } } @@ -54,11 +117,25 @@ void ModelHighAPI_Selection::appendToList( { switch(myVariantType) { case VT_Empty: return; - case VT_ResultSubShapePair: theAttribute->append(myResultSubShapePair.first, myResultSubShapePair.second); return; + case VT_ResultSubShapePair: + theAttribute->append(myResultSubShapePair.first, myResultSubShapePair.second); + return; case VT_TypeSubShapeNamePair: // Note: the reverse order (first - type, second - sub-shape name) theAttribute->append(myTypeSubShapeNamePair.second, myTypeSubShapeNamePair.first); return; + case VT_TypeInnerPointPair: + // Note: the reverse order (first - type, second - selected point) + theAttribute->append(myTypeInnerPointPair.second, myTypeInnerPointPair.first); + return; + case VT_WeakNamingPair: + // Note: the reverse order (first - type, second - selected point) + theAttribute->append( + myWeakNamingPair.first, myWeakNamingPair.second.first, myWeakNamingPair.second.second); + return; + case VT_Filtering: + theAttribute->setFilters(myFilterFeature); + return; } } @@ -80,14 +157,27 @@ TypeSubShapeNamePair ModelHighAPI_Selection::typeSubShapeNamePair() const return myTypeSubShapeNamePair; } +//================================================================================================== +TypeInnerPointPair ModelHighAPI_Selection::typeInnerPointPair() const +{ + return myTypeInnerPointPair; +} + +//================================================================================================== +TypeWeakNamingPair ModelHighAPI_Selection::typeWeakNamingPair() const +{ + return myWeakNamingPair; +} + //================================================================================================== std::string ModelHighAPI_Selection::shapeType() const { switch(myVariantType) { - case VT_ResultSubShapePair: - return myResultSubShapePair.second.get() ? myResultSubShapePair.second->shapeTypeStr() : + case VT_ResultSubShapePair: + return myResultSubShapePair.second.get() ? myResultSubShapePair.second->shapeTypeStr() : myResultSubShapePair.first->shape()->shapeTypeStr(); case VT_TypeSubShapeNamePair: return myTypeSubShapeNamePair.first; + case VT_TypeInnerPointPair: return myTypeInnerPointPair.first; } return "SHAPE"; @@ -96,13 +186,28 @@ std::string ModelHighAPI_Selection::shapeType() const //================================================================================================== void ModelHighAPI_Selection::setName(const std::string& theName) { - if (myVariantType == VT_ResultSubShapePair) - myResultSubShapePair.first->data()->setName(theName); + if (myVariantType == VT_ResultSubShapePair) { + std::shared_ptr aResult = myResultSubShapePair.first; + if(!aResult.get()) { + return; + } + aResult->data()->setName(theName); + } +} + +std::string ModelHighAPI_Selection::name() const +{ + if (myVariantType == VT_ResultSubShapePair) { + std::shared_ptr aResult = myResultSubShapePair.first; + if (aResult.get()) + return aResult->data()->name(); + } + return std::string(); } void ModelHighAPI_Selection::setColor(int theRed, int theGreen, int theBlue) { - if (myVariantType != VT_ResultSubShapePair) + if (myVariantType != VT_ResultSubShapePair || !myResultSubShapePair.first.get()) return; AttributeIntArrayPtr aColor = @@ -118,7 +223,48 @@ void ModelHighAPI_Selection::setDeflection(double theValue) if (myVariantType != VT_ResultSubShapePair) return; - AttributeDoublePtr aDeflectionAttr = myResultSubShapePair.first->data()->real(ModelAPI_Result::DEFLECTION_ID()); + AttributeDoublePtr aDeflectionAttr = + myResultSubShapePair.first->data()->real(ModelAPI_Result::DEFLECTION_ID()); aDeflectionAttr->setValue(theValue); } + +// LCOV_EXCL_START +void ModelHighAPI_Selection::setTransparency(double theValue) +{ + if (myVariantType != VT_ResultSubShapePair) + return; + + AttributeDoublePtr aTransparencyAttr = + myResultSubShapePair.first->data()->real(ModelAPI_Result::TRANSPARENCY_ID()); + + aTransparencyAttr->setValue(theValue); +} +// LCOV_EXCL_STOP + +int ModelHighAPI_Selection::numberOfSubs() const +{ + if (myVariantType != VT_ResultSubShapePair) + return 0; + + ResultBodyPtr aBody = std::dynamic_pointer_cast(myResultSubShapePair.first); + if (!aBody.get()) + return 0; + + return aBody->numberOfSubs(); +} + +ModelHighAPI_Selection ModelHighAPI_Selection::subResult(int theIndex) const +{ + if (myVariantType != VT_ResultSubShapePair) + return ModelHighAPI_Selection(); + + ResultBodyPtr aBody = std::dynamic_pointer_cast(myResultSubShapePair.first); + if (!aBody) + return ModelHighAPI_Selection(); + if (theIndex >= aBody->numberOfSubs()) + return ModelHighAPI_Selection(); + + ResultBodyPtr aResult = aBody->subResult(theIndex); + return ModelHighAPI_Selection(aResult, aResult->shape()); +}