Salome HOME
72bfdff590b80ac694a7cf688e70d0ac2142610a
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Selection.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 // Name   : ModelHighAPI_Selection.cpp
3 // Purpose: 
4 //
5 // History:
6 // 06/06/16 - Sergey POKHODENKO - Creation of the file
7
8 //--------------------------------------------------------------------------------------
9 #include "ModelHighAPI_Selection.h"
10
11 #include <ModelAPI_AttributeDouble.h>
12 #include <ModelAPI_AttributeIntArray.h>
13 #include <ModelAPI_AttributeSelection.h>
14 #include <ModelAPI_AttributeSelectionList.h>
15 //--------------------------------------------------------------------------------------
16
17 //--------------------------------------------------------------------------------------
18 ModelHighAPI_Selection::ModelHighAPI_Selection()
19 : myVariantType(VT_Empty)
20 {
21 }
22
23 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::shared_ptr<ModelAPI_Result>& theContext,
24                                                const std::shared_ptr<GeomAPI_Shape>& theSubShape)
25 : myVariantType(VT_ResultSubShapePair)
26 , myResultSubShapePair(theContext, theSubShape)
27 {
28 }
29
30 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
31                                                const std::string& theSubShapeName)
32 : myVariantType(VT_TypeSubShapeNamePair)
33 , myTypeSubShapeNamePair(theType, theSubShapeName)
34 {
35 }
36
37 ModelHighAPI_Selection::~ModelHighAPI_Selection()
38 {
39 }
40
41 //--------------------------------------------------------------------------------------
42 void ModelHighAPI_Selection::fillAttribute(
43     const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute) const
44 {
45   switch(myVariantType) {
46     case VT_Empty: return;
47     case VT_ResultSubShapePair: 
48       theAttribute->setValue(myResultSubShapePair.first, myResultSubShapePair.second); 
49       return;
50     case VT_TypeSubShapeNamePair: 
51       theAttribute->selectSubShape(myTypeSubShapeNamePair.first, myTypeSubShapeNamePair.second);
52       return;
53   }
54 }
55
56 //--------------------------------------------------------------------------------------
57 void ModelHighAPI_Selection::appendToList(
58     const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute) const
59 {
60   switch(myVariantType) {
61     case VT_Empty: return;
62     case VT_ResultSubShapePair: 
63       theAttribute->append(myResultSubShapePair.first, myResultSubShapePair.second); 
64       return;
65     case VT_TypeSubShapeNamePair:
66       // Note: the reverse order (first - type, second - sub-shape name)
67       theAttribute->append(myTypeSubShapeNamePair.second, myTypeSubShapeNamePair.first);
68       return;
69   }
70 }
71
72 //==================================================================================================
73 ModelHighAPI_Selection::VariantType ModelHighAPI_Selection::variantType() const
74 {
75   return myVariantType;
76 }
77
78 //==================================================================================================
79 ResultSubShapePair ModelHighAPI_Selection::resultSubShapePair() const
80 {
81   return myResultSubShapePair;
82 }
83
84 //==================================================================================================
85 TypeSubShapeNamePair ModelHighAPI_Selection::typeSubShapeNamePair() const
86 {
87   return myTypeSubShapeNamePair;
88 }
89
90 //==================================================================================================
91 std::string ModelHighAPI_Selection::shapeType() const
92 {
93   switch(myVariantType) {
94   case VT_ResultSubShapePair: 
95     return myResultSubShapePair.second.get() ? myResultSubShapePair.second->shapeTypeStr() : 
96                                                myResultSubShapePair.first->shape()->shapeTypeStr();
97   case VT_TypeSubShapeNamePair: return myTypeSubShapeNamePair.first;
98   }
99
100   return "SHAPE";
101 }
102
103 //==================================================================================================
104 void ModelHighAPI_Selection::setName(const std::string& theName)
105 {
106   if (myVariantType == VT_ResultSubShapePair)
107     myResultSubShapePair.first->data()->setName(theName);
108 }
109
110 void ModelHighAPI_Selection::setColor(int theRed, int theGreen, int theBlue)
111 {
112   if (myVariantType != VT_ResultSubShapePair)
113     return;
114
115   AttributeIntArrayPtr aColor =
116       myResultSubShapePair.first->data()->intArray(ModelAPI_Result::COLOR_ID());
117   aColor->setSize(3);
118   aColor->setValue(0, theRed);
119   aColor->setValue(1, theGreen);
120   aColor->setValue(2, theBlue);
121 }
122
123 void ModelHighAPI_Selection::setDeflection(double theValue)
124 {
125   if (myVariantType != VT_ResultSubShapePair)
126     return;
127
128   AttributeDoublePtr aDeflectionAttr = 
129     myResultSubShapePair.first->data()->real(ModelAPI_Result::DEFLECTION_ID());
130
131   aDeflectionAttr->setValue(theValue);
132 }