1 // Name : ModelHighAPI_Selection.cpp
5 // 06/06/16 - Sergey POKHODENKO - Creation of the file
7 //--------------------------------------------------------------------------------------
8 #include "ModelHighAPI_Selection.h"
10 #include <ModelAPI_AttributeIntArray.h>
11 #include <ModelAPI_AttributeSelection.h>
12 #include <ModelAPI_AttributeSelectionList.h>
13 //--------------------------------------------------------------------------------------
15 //--------------------------------------------------------------------------------------
16 ModelHighAPI_Selection::ModelHighAPI_Selection()
17 : myVariantType(VT_Empty)
21 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::shared_ptr<ModelAPI_Result>& theContext,
22 const std::shared_ptr<GeomAPI_Shape>& theSubShape)
23 : myVariantType(VT_ResultSubShapePair)
24 , myResultSubShapePair(theContext, theSubShape)
28 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
29 const std::string& theSubShapeName)
30 : myVariantType(VT_TypeSubShapeNamePair)
31 , myTypeSubShapeNamePair(theType, theSubShapeName)
35 ModelHighAPI_Selection::~ModelHighAPI_Selection()
39 //--------------------------------------------------------------------------------------
40 void ModelHighAPI_Selection::fillAttribute(
41 const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute) const
43 switch(myVariantType) {
44 case VT_Empty: return;
45 case VT_ResultSubShapePair: theAttribute->setValue(myResultSubShapePair.first, myResultSubShapePair.second); return;
46 case VT_TypeSubShapeNamePair: theAttribute->selectSubShape(myTypeSubShapeNamePair.first, myTypeSubShapeNamePair.second); return;
50 //--------------------------------------------------------------------------------------
51 void ModelHighAPI_Selection::appendToList(
52 const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute) const
54 switch(myVariantType) {
55 case VT_Empty: return;
56 case VT_ResultSubShapePair: theAttribute->append(myResultSubShapePair.first, myResultSubShapePair.second); return;
57 case VT_TypeSubShapeNamePair:
58 // Note: the reverse order (first - type, second - sub-shape name)
59 theAttribute->append(myTypeSubShapeNamePair.second, myTypeSubShapeNamePair.first);
64 //==================================================================================================
65 ModelHighAPI_Selection::VariantType ModelHighAPI_Selection::variantType() const
70 //==================================================================================================
71 ResultSubShapePair ModelHighAPI_Selection::resultSubShapePair() const
73 return myResultSubShapePair;
76 //==================================================================================================
77 TypeSubShapeNamePair ModelHighAPI_Selection::typeSubShapeNamePair() const
79 return myTypeSubShapeNamePair;
82 //==================================================================================================
83 std::string ModelHighAPI_Selection::shapeType() const
85 switch(myVariantType) {
86 case VT_ResultSubShapePair:
87 return myResultSubShapePair.second.get() ? myResultSubShapePair.second->shapeTypeStr() :
88 myResultSubShapePair.first->shape()->shapeTypeStr();
89 case VT_TypeSubShapeNamePair: return myTypeSubShapeNamePair.first;
95 //==================================================================================================
96 void ModelHighAPI_Selection::setName(const std::string& theName)
98 if (myVariantType == VT_ResultSubShapePair)
99 myResultSubShapePair.first->data()->setName(theName);
102 void ModelHighAPI_Selection::setColor(int theRed, int theGreen, int theBlue)
104 if (myVariantType != VT_ResultSubShapePair)
107 AttributeIntArrayPtr aColor =
108 myResultSubShapePair.first->data()->intArray(ModelAPI_Result::COLOR_ID());
110 aColor->setValue(0, theRed);
111 aColor->setValue(1, theGreen);
112 aColor->setValue(2, theBlue);