]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelHighAPI/ModelHighAPI_Selection.cpp
Salome HOME
Fix problem with dumping names of entities copied by Multi-Rotation/Translation ...
[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 #include <ModelAPI_ResultCompSolid.h>
16 //--------------------------------------------------------------------------------------
17
18 //--------------------------------------------------------------------------------------
19 ModelHighAPI_Selection::ModelHighAPI_Selection()
20 : myVariantType(VT_Empty)
21 {
22 }
23
24 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::shared_ptr<ModelAPI_Result>& theContext,
25                                                const std::shared_ptr<GeomAPI_Shape>& theSubShape)
26 : myVariantType(VT_ResultSubShapePair)
27 , myResultSubShapePair(theContext, theSubShape)
28 {
29 }
30
31 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
32                                                const std::string& theSubShapeName)
33 : myVariantType(VT_TypeSubShapeNamePair)
34 , myTypeSubShapeNamePair(theType, theSubShapeName)
35 {
36 }
37
38 ModelHighAPI_Selection::~ModelHighAPI_Selection()
39 {
40 }
41
42 //--------------------------------------------------------------------------------------
43 void ModelHighAPI_Selection::fillAttribute(
44     const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute) const
45 {
46   switch(myVariantType) {
47     case VT_Empty: return;
48     case VT_ResultSubShapePair:
49       theAttribute->setValue(myResultSubShapePair.first, myResultSubShapePair.second);
50       return;
51     case VT_TypeSubShapeNamePair:
52       theAttribute->selectSubShape(myTypeSubShapeNamePair.first, myTypeSubShapeNamePair.second);
53       return;
54   }
55 }
56
57 //--------------------------------------------------------------------------------------
58 void ModelHighAPI_Selection::appendToList(
59     const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute) const
60 {
61   switch(myVariantType) {
62     case VT_Empty: return;
63     case VT_ResultSubShapePair:
64       theAttribute->append(myResultSubShapePair.first, myResultSubShapePair.second);
65       return;
66     case VT_TypeSubShapeNamePair:
67       // Note: the reverse order (first - type, second - sub-shape name)
68       theAttribute->append(myTypeSubShapeNamePair.second, myTypeSubShapeNamePair.first);
69       return;
70   }
71 }
72
73 //==================================================================================================
74 ModelHighAPI_Selection::VariantType ModelHighAPI_Selection::variantType() const
75 {
76   return myVariantType;
77 }
78
79 //==================================================================================================
80 ResultSubShapePair ModelHighAPI_Selection::resultSubShapePair() const
81 {
82   return myResultSubShapePair;
83 }
84
85 //==================================================================================================
86 TypeSubShapeNamePair ModelHighAPI_Selection::typeSubShapeNamePair() const
87 {
88   return myTypeSubShapeNamePair;
89 }
90
91 //==================================================================================================
92 std::string ModelHighAPI_Selection::shapeType() const
93 {
94   switch(myVariantType) {
95   case VT_ResultSubShapePair:
96     return myResultSubShapePair.second.get() ? myResultSubShapePair.second->shapeTypeStr() :
97                                                myResultSubShapePair.first->shape()->shapeTypeStr();
98   case VT_TypeSubShapeNamePair: return myTypeSubShapeNamePair.first;
99   }
100
101   return "SHAPE";
102 }
103
104 //==================================================================================================
105 void ModelHighAPI_Selection::setName(const std::string& theName)
106 {
107   if (myVariantType == VT_ResultSubShapePair)
108     myResultSubShapePair.first->data()->setName(theName);
109 }
110
111 void ModelHighAPI_Selection::setColor(int theRed, int theGreen, int theBlue)
112 {
113   if (myVariantType != VT_ResultSubShapePair)
114     return;
115
116   AttributeIntArrayPtr aColor =
117       myResultSubShapePair.first->data()->intArray(ModelAPI_Result::COLOR_ID());
118   aColor->setSize(3);
119   aColor->setValue(0, theRed);
120   aColor->setValue(1, theGreen);
121   aColor->setValue(2, theBlue);
122 }
123
124 void ModelHighAPI_Selection::setDeflection(double theValue)
125 {
126   if (myVariantType != VT_ResultSubShapePair)
127     return;
128
129   AttributeDoublePtr aDeflectionAttr =
130     myResultSubShapePair.first->data()->real(ModelAPI_Result::DEFLECTION_ID());
131
132   aDeflectionAttr->setValue(theValue);
133 }
134
135 ModelHighAPI_Selection ModelHighAPI_Selection::subResult(int theIndex)
136 {
137   if (myVariantType != VT_ResultSubShapePair)
138     return ModelHighAPI_Selection();
139
140   ResultCompSolidPtr aCompSolid =
141       std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myResultSubShapePair.first);
142   if (!aCompSolid)
143     return ModelHighAPI_Selection();
144
145   ResultBodyPtr aResult = aCompSolid->subResult(theIndex);
146   return ModelHighAPI_Selection(aResult, aResult->shape());
147 }