1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 // Name : ModelHighAPI_Selection.cpp
6 // 06/06/16 - Sergey POKHODENKO - Creation of the file
8 //--------------------------------------------------------------------------------------
9 #include "ModelHighAPI_Selection.h"
11 #include <ModelAPI_AttributeDouble.h>
12 #include <ModelAPI_AttributeIntArray.h>
13 #include <ModelAPI_AttributeSelection.h>
14 #include <ModelAPI_AttributeSelectionList.h>
15 //--------------------------------------------------------------------------------------
17 //--------------------------------------------------------------------------------------
18 ModelHighAPI_Selection::ModelHighAPI_Selection()
19 : myVariantType(VT_Empty)
23 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::shared_ptr<ModelAPI_Result>& theContext,
24 const std::shared_ptr<GeomAPI_Shape>& theSubShape)
25 : myVariantType(VT_ResultSubShapePair)
26 , myResultSubShapePair(theContext, theSubShape)
30 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
31 const std::string& theSubShapeName)
32 : myVariantType(VT_TypeSubShapeNamePair)
33 , myTypeSubShapeNamePair(theType, theSubShapeName)
37 ModelHighAPI_Selection::~ModelHighAPI_Selection()
41 //--------------------------------------------------------------------------------------
42 void ModelHighAPI_Selection::fillAttribute(
43 const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute) const
45 switch(myVariantType) {
46 case VT_Empty: return;
47 case VT_ResultSubShapePair:
48 theAttribute->setValue(myResultSubShapePair.first, myResultSubShapePair.second);
50 case VT_TypeSubShapeNamePair:
51 theAttribute->selectSubShape(myTypeSubShapeNamePair.first, myTypeSubShapeNamePair.second);
56 //--------------------------------------------------------------------------------------
57 void ModelHighAPI_Selection::appendToList(
58 const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute) const
60 switch(myVariantType) {
61 case VT_Empty: return;
62 case VT_ResultSubShapePair:
63 theAttribute->append(myResultSubShapePair.first, myResultSubShapePair.second);
65 case VT_TypeSubShapeNamePair:
66 // Note: the reverse order (first - type, second - sub-shape name)
67 theAttribute->append(myTypeSubShapeNamePair.second, myTypeSubShapeNamePair.first);
72 //==================================================================================================
73 ModelHighAPI_Selection::VariantType ModelHighAPI_Selection::variantType() const
78 //==================================================================================================
79 ResultSubShapePair ModelHighAPI_Selection::resultSubShapePair() const
81 return myResultSubShapePair;
84 //==================================================================================================
85 TypeSubShapeNamePair ModelHighAPI_Selection::typeSubShapeNamePair() const
87 return myTypeSubShapeNamePair;
90 //==================================================================================================
91 std::string ModelHighAPI_Selection::shapeType() const
93 switch(myVariantType) {
94 case VT_ResultSubShapePair:
95 return myResultSubShapePair.second.get() ? myResultSubShapePair.second->shapeTypeStr() :
96 myResultSubShapePair.first->shape()->shapeTypeStr();
97 case VT_TypeSubShapeNamePair: return myTypeSubShapeNamePair.first;
103 //==================================================================================================
104 void ModelHighAPI_Selection::setName(const std::string& theName)
106 if (myVariantType == VT_ResultSubShapePair)
107 myResultSubShapePair.first->data()->setName(theName);
110 void ModelHighAPI_Selection::setColor(int theRed, int theGreen, int theBlue)
112 if (myVariantType != VT_ResultSubShapePair)
115 AttributeIntArrayPtr aColor =
116 myResultSubShapePair.first->data()->intArray(ModelAPI_Result::COLOR_ID());
118 aColor->setValue(0, theRed);
119 aColor->setValue(1, theGreen);
120 aColor->setValue(2, theBlue);
123 void ModelHighAPI_Selection::setDeflection(double theValue)
125 if (myVariantType != VT_ResultSubShapePair)
128 AttributeDoublePtr aDeflectionAttr =
129 myResultSubShapePair.first->data()->real(ModelAPI_Result::DEFLECTION_ID());
131 aDeflectionAttr->setValue(theValue);