Salome HOME
#1802 Crash when I create a circle on projected axis
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Selection.cpp
1 // Name   : ModelHighAPI_Selection.cpp
2 // Purpose: 
3 //
4 // History:
5 // 06/06/16 - Sergey POKHODENKO - Creation of the file
6
7 //--------------------------------------------------------------------------------------
8 #include "ModelHighAPI_Selection.h"
9
10 #include <ModelAPI_AttributeDouble.h>
11 #include <ModelAPI_AttributeIntArray.h>
12 #include <ModelAPI_AttributeSelection.h>
13 #include <ModelAPI_AttributeSelectionList.h>
14 //--------------------------------------------------------------------------------------
15
16 //--------------------------------------------------------------------------------------
17 ModelHighAPI_Selection::ModelHighAPI_Selection()
18 : myVariantType(VT_Empty)
19 {
20 }
21
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)
26 {
27 }
28
29 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
30                                                const std::string& theSubShapeName)
31 : myVariantType(VT_TypeSubShapeNamePair)
32 , myTypeSubShapeNamePair(theType, theSubShapeName)
33 {
34 }
35
36 ModelHighAPI_Selection::~ModelHighAPI_Selection()
37 {
38 }
39
40 //--------------------------------------------------------------------------------------
41 void ModelHighAPI_Selection::fillAttribute(
42     const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute) const
43 {
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;
48   }
49 }
50
51 //--------------------------------------------------------------------------------------
52 void ModelHighAPI_Selection::appendToList(
53     const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute) const
54 {
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);
61       return;
62   }
63 }
64
65 //==================================================================================================
66 ModelHighAPI_Selection::VariantType ModelHighAPI_Selection::variantType() const
67 {
68   return myVariantType;
69 }
70
71 //==================================================================================================
72 ResultSubShapePair ModelHighAPI_Selection::resultSubShapePair() const
73 {
74   return myResultSubShapePair;
75 }
76
77 //==================================================================================================
78 TypeSubShapeNamePair ModelHighAPI_Selection::typeSubShapeNamePair() const
79 {
80   return myTypeSubShapeNamePair;
81 }
82
83 //==================================================================================================
84 std::string ModelHighAPI_Selection::shapeType() const
85 {
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;
91   }
92
93   return "SHAPE";
94 }
95
96 //==================================================================================================
97 void ModelHighAPI_Selection::setName(const std::string& theName)
98 {
99   if (myVariantType == VT_ResultSubShapePair)
100     myResultSubShapePair.first->data()->setName(theName);
101 }
102
103 void ModelHighAPI_Selection::setColor(int theRed, int theGreen, int theBlue)
104 {
105   if (myVariantType != VT_ResultSubShapePair)
106     return;
107
108   AttributeIntArrayPtr aColor =
109       myResultSubShapePair.first->data()->intArray(ModelAPI_Result::COLOR_ID());
110   aColor->setSize(3);
111   aColor->setValue(0, theRed);
112   aColor->setValue(1, theGreen);
113   aColor->setValue(2, theBlue);
114 }
115
116 void ModelHighAPI_Selection::setDeflection(double theValue)
117 {
118   if (myVariantType != VT_ResultSubShapePair)
119     return;
120
121   AttributeDoublePtr aDeflectionAttr = myResultSubShapePair.first->data()->real(ModelAPI_Result::DEFLECTION_ID());
122
123   aDeflectionAttr->setValue(theValue);
124 }