1 // Name : ModelHighAPI_Selection.cpp
5 // 06/06/16 - Sergey POKHODENKO - Creation of the file
7 //--------------------------------------------------------------------------------------
8 #include "ModelHighAPI_Selection.h"
10 #include <ModelAPI_AttributeDouble.h>
11 #include <ModelAPI_AttributeIntArray.h>
12 #include <ModelAPI_AttributeSelection.h>
13 #include <ModelAPI_AttributeSelectionList.h>
14 //--------------------------------------------------------------------------------------
16 //--------------------------------------------------------------------------------------
17 ModelHighAPI_Selection::ModelHighAPI_Selection()
18 : myVariantType(VT_Empty)
22 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::shared_ptr<ModelAPI_Result>& theContext,
23 const std::shared_ptr<GeomAPI_Shape>& theSubShape)
24 : myVariantType(VT_ResultSubShapePair)
25 , myResultSubShapePair(theContext, theSubShape)
29 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
30 const std::string& theSubShapeName)
31 : myVariantType(VT_TypeSubShapeNamePair)
32 , myTypeSubShapeNamePair(theType, theSubShapeName)
36 ModelHighAPI_Selection::~ModelHighAPI_Selection()
40 //--------------------------------------------------------------------------------------
41 void ModelHighAPI_Selection::fillAttribute(
42 const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute) const
44 switch(myVariantType) {
45 case VT_Empty: return;
46 case VT_ResultSubShapePair: theAttribute->setValue(myResultSubShapePair.first, myResultSubShapePair.second); return;
47 case VT_TypeSubShapeNamePair: theAttribute->selectSubShape(myTypeSubShapeNamePair.first, myTypeSubShapeNamePair.second); return;
51 //--------------------------------------------------------------------------------------
52 void ModelHighAPI_Selection::appendToList(
53 const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute) const
55 switch(myVariantType) {
56 case VT_Empty: return;
57 case VT_ResultSubShapePair: theAttribute->append(myResultSubShapePair.first, myResultSubShapePair.second); return;
58 case VT_TypeSubShapeNamePair:
59 // Note: the reverse order (first - type, second - sub-shape name)
60 theAttribute->append(myTypeSubShapeNamePair.second, myTypeSubShapeNamePair.first);
65 //==================================================================================================
66 ModelHighAPI_Selection::VariantType ModelHighAPI_Selection::variantType() const
71 //==================================================================================================
72 ResultSubShapePair ModelHighAPI_Selection::resultSubShapePair() const
74 return myResultSubShapePair;
77 //==================================================================================================
78 TypeSubShapeNamePair ModelHighAPI_Selection::typeSubShapeNamePair() const
80 return myTypeSubShapeNamePair;
83 //==================================================================================================
84 std::string ModelHighAPI_Selection::shapeType() const
86 switch(myVariantType) {
87 case VT_ResultSubShapePair:
88 return myResultSubShapePair.second.get() ? myResultSubShapePair.second->shapeTypeStr() :
89 myResultSubShapePair.first->shape()->shapeTypeStr();
90 case VT_TypeSubShapeNamePair: return myTypeSubShapeNamePair.first;
96 //==================================================================================================
97 void ModelHighAPI_Selection::setName(const std::string& theName)
99 if (myVariantType == VT_ResultSubShapePair)
100 myResultSubShapePair.first->data()->setName(theName);
103 void ModelHighAPI_Selection::setColor(int theRed, int theGreen, int theBlue)
105 if (myVariantType != VT_ResultSubShapePair)
108 AttributeIntArrayPtr aColor =
109 myResultSubShapePair.first->data()->intArray(ModelAPI_Result::COLOR_ID());
111 aColor->setValue(0, theRed);
112 aColor->setValue(1, theGreen);
113 aColor->setValue(2, theBlue);
116 void ModelHighAPI_Selection::setDeflection(double theValue)
118 if (myVariantType != VT_ResultSubShapePair)
121 AttributeDoublePtr aDeflectionAttr = myResultSubShapePair.first->data()->real(ModelAPI_Result::DEFLECTION_ID());
123 aDeflectionAttr->setValue(theValue);