Salome HOME
Avoid SegFault exception
[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_AttributeSelection.h>
11 #include <ModelAPI_AttributeSelectionList.h>
12 //--------------------------------------------------------------------------------------
13
14 //--------------------------------------------------------------------------------------
15 ModelHighAPI_Selection::ModelHighAPI_Selection()
16 : myVariantType(VT_Empty)
17 {
18 }
19
20 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::shared_ptr<ModelAPI_Result>& theContext,
21                                                const std::shared_ptr<GeomAPI_Shape>& theSubShape)
22 : myVariantType(VT_ResultSubShapePair)
23 , myResultSubShapePair(theContext, theSubShape)
24 {
25 }
26
27 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
28                                                const std::string& theSubShapeName)
29 : myVariantType(VT_TypeSubShapeNamePair)
30 , myTypeSubShapeNamePair(theType, theSubShapeName)
31 {
32 }
33
34 ModelHighAPI_Selection::~ModelHighAPI_Selection()
35 {
36 }
37
38 //--------------------------------------------------------------------------------------
39 void ModelHighAPI_Selection::fillAttribute(
40     const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute) const
41 {
42   switch(myVariantType) {
43     case VT_Empty: return;
44     case VT_ResultSubShapePair: theAttribute->setValue(myResultSubShapePair.first, myResultSubShapePair.second); return;
45     case VT_TypeSubShapeNamePair: theAttribute->selectSubShape(myTypeSubShapeNamePair.first, myTypeSubShapeNamePair.second); return;
46   }
47 }
48
49 //--------------------------------------------------------------------------------------
50 void ModelHighAPI_Selection::appendToList(
51     const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute) const
52 {
53   switch(myVariantType) {
54     case VT_Empty: return;
55     case VT_ResultSubShapePair: theAttribute->append(myResultSubShapePair.first, myResultSubShapePair.second); return;
56     case VT_TypeSubShapeNamePair:
57       // Note: the reverse order (first - type, second - sub-shape name)
58       theAttribute->append(myTypeSubShapeNamePair.second, myTypeSubShapeNamePair.first);
59       return;
60   }
61 }
62
63 //==================================================================================================
64 ModelHighAPI_Selection::VariantType ModelHighAPI_Selection::variantType() const
65 {
66   return myVariantType;
67 }
68
69 //==================================================================================================
70 ResultSubShapePair ModelHighAPI_Selection::resultSubShapePair() const
71 {
72   return myResultSubShapePair;
73 }
74
75 //==================================================================================================
76 TypeSubShapeNamePair ModelHighAPI_Selection::typeSubShapeNamePair() const
77 {
78   return myTypeSubShapeNamePair;
79 }
80
81 //==================================================================================================
82 std::string ModelHighAPI_Selection::shapeType() const
83 {
84   switch(myVariantType) {
85   case VT_ResultSubShapePair: 
86     return myResultSubShapePair.second.get() ? myResultSubShapePair.second->shapeTypeStr() : 
87                                                myResultSubShapePair.first->shape()->shapeTypeStr();
88   case VT_TypeSubShapeNamePair: return myTypeSubShapeNamePair.first;
89   }
90
91   return "SHAPE";
92 }