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 myResultSubShapePair.first->data()->setName(theName);
111 void ModelHighAPI_Selection::setColor(int theRed, int theGreen, int theBlue)
113 if (myVariantType != VT_ResultSubShapePair)
116 AttributeIntArrayPtr aColor =
117 myResultSubShapePair.first->data()->intArray(ModelAPI_Result::COLOR_ID());
119 aColor->setValue(0, theRed);
120 aColor->setValue(1, theGreen);
121 aColor->setValue(2, theBlue);
124 void ModelHighAPI_Selection::setDeflection(double theValue)
126 if (myVariantType != VT_ResultSubShapePair)
129 AttributeDoublePtr aDeflectionAttr =
130 myResultSubShapePair.first->data()->real(ModelAPI_Result::DEFLECTION_ID());
132 aDeflectionAttr->setValue(theValue);
135 ModelHighAPI_Selection ModelHighAPI_Selection::subResult(int theIndex)
137 if (myVariantType != VT_ResultSubShapePair)
138 return ModelHighAPI_Selection();
140 ResultCompSolidPtr aCompSolid =
141 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myResultSubShapePair.first);
143 return ModelHighAPI_Selection();
145 ResultBodyPtr aResult = aCompSolid->subResult(theIndex);
146 return ModelHighAPI_Selection(aResult, aResult->shape());