Salome HOME
Correct naming of results while dumping
[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_AttributeIntArray.h>
11 #include <ModelAPI_AttributeSelection.h>
12 #include <ModelAPI_AttributeSelectionList.h>
13 //--------------------------------------------------------------------------------------
14
15 //--------------------------------------------------------------------------------------
16 ModelHighAPI_Selection::ModelHighAPI_Selection()
17 : myVariantType(VT_Empty)
18 {
19 }
20
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)
25 {
26 }
27
28 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
29                                                const std::string& theSubShapeName)
30 : myVariantType(VT_TypeSubShapeNamePair)
31 , myTypeSubShapeNamePair(theType, theSubShapeName)
32 {
33 }
34
35 ModelHighAPI_Selection::~ModelHighAPI_Selection()
36 {
37 }
38
39 //--------------------------------------------------------------------------------------
40 void ModelHighAPI_Selection::fillAttribute(
41     const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute) const
42 {
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;
47   }
48 }
49
50 //--------------------------------------------------------------------------------------
51 void ModelHighAPI_Selection::appendToList(
52     const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute) const
53 {
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);
60       return;
61   }
62 }
63
64 //==================================================================================================
65 ModelHighAPI_Selection::VariantType ModelHighAPI_Selection::variantType() const
66 {
67   return myVariantType;
68 }
69
70 //==================================================================================================
71 ResultSubShapePair ModelHighAPI_Selection::resultSubShapePair() const
72 {
73   return myResultSubShapePair;
74 }
75
76 //==================================================================================================
77 TypeSubShapeNamePair ModelHighAPI_Selection::typeSubShapeNamePair() const
78 {
79   return myTypeSubShapeNamePair;
80 }
81
82 //==================================================================================================
83 std::string ModelHighAPI_Selection::shapeType() const
84 {
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;
90   }
91
92   return "SHAPE";
93 }
94
95 //==================================================================================================
96 void ModelHighAPI_Selection::setName(const std::string& theName)
97 {
98   if (myVariantType == VT_ResultSubShapePair)
99     myResultSubShapePair.first->data()->setName(theName);
100 }
101
102 void ModelHighAPI_Selection::setColor(int theRed, int theGreen, int theBlue)
103 {
104   if (myVariantType != VT_ResultSubShapePair)
105     return;
106
107   AttributeIntArrayPtr aColor =
108       myResultSubShapePair.first->data()->intArray(ModelAPI_Result::COLOR_ID());
109   aColor->setSize(3);
110   aColor->setValue(0, theRed);
111   aColor->setValue(1, theGreen);
112   aColor->setValue(2, theBlue);
113 }