X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModelHighAPI%2FModelHighAPI_Selection.cpp;h=fb0697635dd2b855552aa3ebd974c3a54e6a6524;hb=2054879244f3323c305222c79c57d2db6a487538;hp=1c2cca5bfdc887257dcecda85949cd7c6b3cd807;hpb=5c2ba91e54934c258b5c5caffd3adf347c5c1180;p=modules%2Fshaper.git diff --git a/src/ModelHighAPI/ModelHighAPI_Selection.cpp b/src/ModelHighAPI/ModelHighAPI_Selection.cpp index 1c2cca5bf..fb0697635 100644 --- a/src/ModelHighAPI/ModelHighAPI_Selection.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Selection.cpp @@ -1,5 +1,6 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D // Name : ModelHighAPI_Selection.cpp -// Purpose: +// Purpose: // // History: // 06/06/16 - Sergey POKHODENKO - Creation of the file @@ -7,19 +8,29 @@ //-------------------------------------------------------------------------------------- #include "ModelHighAPI_Selection.h" +#include +#include #include +#include //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- +ModelHighAPI_Selection::ModelHighAPI_Selection() +: myVariantType(VT_Empty) +{ +} + ModelHighAPI_Selection::ModelHighAPI_Selection(const std::shared_ptr& theContext, const std::shared_ptr& theSubShape) -: myValue(ResultSubShapePair(theContext, theSubShape)) +: myVariantType(VT_ResultSubShapePair) +, myResultSubShapePair(theContext, theSubShape) { } ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType, const std::string& theSubShapeName) -: myValue(TypeSubShapeNamePair(theType, theSubShapeName)) +: myVariantType(VT_TypeSubShapeNamePair) +, myTypeSubShapeNamePair(theType, theSubShapeName) { } @@ -28,19 +39,94 @@ ModelHighAPI_Selection::~ModelHighAPI_Selection() } //-------------------------------------------------------------------------------------- -struct fill_visitor : boost::static_visitor +void ModelHighAPI_Selection::fillAttribute( + const std::shared_ptr & theAttribute) const { - mutable std::shared_ptr myAttribute; + 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; + } +} - fill_visitor(std::shared_ptr & theAttribute) - : myAttribute(theAttribute) {} +//-------------------------------------------------------------------------------------- +void ModelHighAPI_Selection::appendToList( + const std::shared_ptr & theAttribute) const +{ + switch(myVariantType) { + case VT_Empty: 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; + } +} - void operator()(const ResultSubShapePair & thePair) const { myAttribute->setValue(thePair.first, thePair.second); } - void operator()(const TypeSubShapeNamePair & thePair) const { myAttribute->selectSubShape(thePair.first, thePair.second); } -}; +//================================================================================================== +ModelHighAPI_Selection::VariantType ModelHighAPI_Selection::variantType() const +{ + return myVariantType; +} -void ModelHighAPI_Selection::fillAttribute( - std::shared_ptr & theAttribute) const +//================================================================================================== +ResultSubShapePair ModelHighAPI_Selection::resultSubShapePair() const +{ + return myResultSubShapePair; +} + +//================================================================================================== +TypeSubShapeNamePair ModelHighAPI_Selection::typeSubShapeNamePair() const +{ + return myTypeSubShapeNamePair; +} + +//================================================================================================== +std::string ModelHighAPI_Selection::shapeType() const +{ + switch(myVariantType) { + case VT_ResultSubShapePair: + return myResultSubShapePair.second.get() ? myResultSubShapePair.second->shapeTypeStr() : + myResultSubShapePair.first->shape()->shapeTypeStr(); + case VT_TypeSubShapeNamePair: return myTypeSubShapeNamePair.first; + } + + return "SHAPE"; +} + +//================================================================================================== +void ModelHighAPI_Selection::setName(const std::string& theName) { - boost::apply_visitor(fill_visitor(theAttribute), myValue); + if (myVariantType == VT_ResultSubShapePair) + myResultSubShapePair.first->data()->setName(theName); +} + +void ModelHighAPI_Selection::setColor(int theRed, int theGreen, int theBlue) +{ + if (myVariantType != VT_ResultSubShapePair) + return; + + AttributeIntArrayPtr aColor = + myResultSubShapePair.first->data()->intArray(ModelAPI_Result::COLOR_ID()); + aColor->setSize(3); + aColor->setValue(0, theRed); + aColor->setValue(1, theGreen); + aColor->setValue(2, theBlue); +} + +void ModelHighAPI_Selection::setDeflection(double theValue) +{ + if (myVariantType != VT_ResultSubShapePair) + return; + + AttributeDoublePtr aDeflectionAttr = + myResultSubShapePair.first->data()->real(ModelAPI_Result::DEFLECTION_ID()); + + aDeflectionAttr->setValue(theValue); }