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 #include <ModelAPI_ResultCompSolid.h>
16 //--------------------------------------------------------------------------------------
18 //--------------------------------------------------------------------------------------
19 ModelHighAPI_Selection::ModelHighAPI_Selection()
20 : myVariantType(VT_Empty)
24 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::shared_ptr<ModelAPI_Result>& theContext,
25 const std::shared_ptr<GeomAPI_Shape>& theSubShape)
26 : myVariantType(VT_ResultSubShapePair)
27 , myResultSubShapePair(theContext, theSubShape)
31 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
32 const std::string& theSubShapeName)
33 : myVariantType(VT_TypeSubShapeNamePair)
34 , myTypeSubShapeNamePair(theType, theSubShapeName)
38 ModelHighAPI_Selection::~ModelHighAPI_Selection()
42 //--------------------------------------------------------------------------------------
43 void ModelHighAPI_Selection::fillAttribute(
44 const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute) const
46 switch(myVariantType) {
47 case VT_Empty: return;
48 case VT_ResultSubShapePair:
49 theAttribute->setValue(myResultSubShapePair.first, myResultSubShapePair.second);
51 case VT_TypeSubShapeNamePair:
52 theAttribute->selectSubShape(myTypeSubShapeNamePair.first, myTypeSubShapeNamePair.second);
57 //--------------------------------------------------------------------------------------
58 void ModelHighAPI_Selection::appendToList(
59 const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute) const
61 switch(myVariantType) {
62 case VT_Empty: return;
63 case VT_ResultSubShapePair:
64 theAttribute->append(myResultSubShapePair.first, myResultSubShapePair.second);
66 case VT_TypeSubShapeNamePair:
67 // Note: the reverse order (first - type, second - sub-shape name)
68 theAttribute->append(myTypeSubShapeNamePair.second, myTypeSubShapeNamePair.first);
73 //==================================================================================================
74 ModelHighAPI_Selection::VariantType ModelHighAPI_Selection::variantType() const
79 //==================================================================================================
80 ResultSubShapePair ModelHighAPI_Selection::resultSubShapePair() const
82 return myResultSubShapePair;
85 //==================================================================================================
86 TypeSubShapeNamePair ModelHighAPI_Selection::typeSubShapeNamePair() const
88 return myTypeSubShapeNamePair;
91 //==================================================================================================
92 std::string ModelHighAPI_Selection::shapeType() const
94 switch(myVariantType) {
95 case VT_ResultSubShapePair:
96 return myResultSubShapePair.second.get() ? myResultSubShapePair.second->shapeTypeStr() :
97 myResultSubShapePair.first->shape()->shapeTypeStr();
98 case VT_TypeSubShapeNamePair: return myTypeSubShapeNamePair.first;
104 //==================================================================================================
105 void ModelHighAPI_Selection::setName(const std::string& theName)
107 if (myVariantType == VT_ResultSubShapePair) {
108 std::shared_ptr<ModelAPI_Result> aResult = myResultSubShapePair.first;
112 aResult->data()->setName(theName);
116 void ModelHighAPI_Selection::setColor(int theRed, int theGreen, int theBlue)
118 if (myVariantType != VT_ResultSubShapePair)
121 AttributeIntArrayPtr aColor =
122 myResultSubShapePair.first->data()->intArray(ModelAPI_Result::COLOR_ID());
124 aColor->setValue(0, theRed);
125 aColor->setValue(1, theGreen);
126 aColor->setValue(2, theBlue);
129 void ModelHighAPI_Selection::setDeflection(double theValue)
131 if (myVariantType != VT_ResultSubShapePair)
134 AttributeDoublePtr aDeflectionAttr =
135 myResultSubShapePair.first->data()->real(ModelAPI_Result::DEFLECTION_ID());
137 aDeflectionAttr->setValue(theValue);
140 int ModelHighAPI_Selection::numberOfSubs() const
142 if (myVariantType != VT_ResultSubShapePair)
145 ResultCompSolidPtr aCompSolid =
146 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myResultSubShapePair.first);
150 return aCompSolid->numberOfSubs();
153 ModelHighAPI_Selection ModelHighAPI_Selection::subResult(int theIndex) const
155 if (myVariantType != VT_ResultSubShapePair)
156 return ModelHighAPI_Selection();
158 ResultCompSolidPtr aCompSolid =
159 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myResultSubShapePair.first);
161 return ModelHighAPI_Selection();
163 ResultBodyPtr aResult = aCompSolid->subResult(theIndex);
164 return ModelHighAPI_Selection(aResult, aResult->shape());