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_Feature.h>
16 #include <ModelAPI_ResultCompSolid.h>
17 //--------------------------------------------------------------------------------------
19 //--------------------------------------------------------------------------------------
20 ModelHighAPI_Selection::ModelHighAPI_Selection()
21 : myVariantType(VT_Empty)
25 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::shared_ptr<ModelAPI_Result>& theContext,
26 const std::shared_ptr<GeomAPI_Shape>& theSubShape)
27 : myVariantType(VT_ResultSubShapePair)
28 , myResultSubShapePair(theContext, theSubShape)
32 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
33 const std::string& theSubShapeName)
34 : myVariantType(VT_TypeSubShapeNamePair)
35 , myTypeSubShapeNamePair(theType, theSubShapeName)
39 ModelHighAPI_Selection::~ModelHighAPI_Selection()
43 //--------------------------------------------------------------------------------------
44 void ModelHighAPI_Selection::fillAttribute(
45 const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute) const
47 switch(myVariantType) {
48 case VT_Empty: return;
49 case VT_ResultSubShapePair:
50 theAttribute->setValue(myResultSubShapePair.first, myResultSubShapePair.second);
52 case VT_TypeSubShapeNamePair:
53 theAttribute->selectSubShape(myTypeSubShapeNamePair.first, myTypeSubShapeNamePair.second);
54 if(theAttribute->isInvalid()) {
55 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
57 std::string("Error: attribute \"") + theAttribute->id() + std::string("\" is invalid."));
63 //--------------------------------------------------------------------------------------
64 void ModelHighAPI_Selection::appendToList(
65 const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute) const
67 switch(myVariantType) {
68 case VT_Empty: return;
69 case VT_ResultSubShapePair:
70 theAttribute->append(myResultSubShapePair.first, myResultSubShapePair.second);
72 case VT_TypeSubShapeNamePair:
73 // Note: the reverse order (first - type, second - sub-shape name)
74 theAttribute->append(myTypeSubShapeNamePair.second, myTypeSubShapeNamePair.first);
79 //==================================================================================================
80 ModelHighAPI_Selection::VariantType ModelHighAPI_Selection::variantType() const
85 //==================================================================================================
86 ResultSubShapePair ModelHighAPI_Selection::resultSubShapePair() const
88 return myResultSubShapePair;
91 //==================================================================================================
92 TypeSubShapeNamePair ModelHighAPI_Selection::typeSubShapeNamePair() const
94 return myTypeSubShapeNamePair;
97 //==================================================================================================
98 std::string ModelHighAPI_Selection::shapeType() const
100 switch(myVariantType) {
101 case VT_ResultSubShapePair:
102 return myResultSubShapePair.second.get() ? myResultSubShapePair.second->shapeTypeStr() :
103 myResultSubShapePair.first->shape()->shapeTypeStr();
104 case VT_TypeSubShapeNamePair: return myTypeSubShapeNamePair.first;
110 //==================================================================================================
111 void ModelHighAPI_Selection::setName(const std::string& theName)
113 if (myVariantType == VT_ResultSubShapePair) {
114 std::shared_ptr<ModelAPI_Result> aResult = myResultSubShapePair.first;
118 aResult->data()->setName(theName);
122 void ModelHighAPI_Selection::setColor(int theRed, int theGreen, int theBlue)
124 if (myVariantType != VT_ResultSubShapePair)
127 AttributeIntArrayPtr aColor =
128 myResultSubShapePair.first->data()->intArray(ModelAPI_Result::COLOR_ID());
130 aColor->setValue(0, theRed);
131 aColor->setValue(1, theGreen);
132 aColor->setValue(2, theBlue);
135 void ModelHighAPI_Selection::setDeflection(double theValue)
137 if (myVariantType != VT_ResultSubShapePair)
140 AttributeDoublePtr aDeflectionAttr =
141 myResultSubShapePair.first->data()->real(ModelAPI_Result::DEFLECTION_ID());
143 aDeflectionAttr->setValue(theValue);
146 int ModelHighAPI_Selection::numberOfSubs() const
148 if (myVariantType != VT_ResultSubShapePair)
151 ResultCompSolidPtr aCompSolid =
152 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myResultSubShapePair.first);
156 return aCompSolid->numberOfSubs();
159 ModelHighAPI_Selection ModelHighAPI_Selection::subResult(int theIndex) const
161 if (myVariantType != VT_ResultSubShapePair)
162 return ModelHighAPI_Selection();
164 ResultCompSolidPtr aCompSolid =
165 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myResultSubShapePair.first);
167 return ModelHighAPI_Selection();
169 ResultBodyPtr aResult = aCompSolid->subResult(theIndex);
170 return ModelHighAPI_Selection(aResult, aResult->shape());