]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelHighAPI/ModelHighAPI_Selection.cpp
Salome HOME
e997aa4e01db5cd53d2304e9e7f9c4de986de32a
[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(const std::shared_ptr<ModelAPI_Result>& theContext,
16                                                const std::shared_ptr<GeomAPI_Shape>& theSubShape)
17 : myValue(ResultSubShapePair(theContext, theSubShape))
18 {
19 }
20
21 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
22                                                const std::string& theSubShapeName)
23 : myValue(TypeSubShapeNamePair(theType, theSubShapeName))
24 {
25 }
26
27 ModelHighAPI_Selection::~ModelHighAPI_Selection()
28 {
29 }
30
31 //--------------------------------------------------------------------------------------
32 struct fill_visitor : boost::static_visitor<void>
33 {
34   mutable std::shared_ptr<ModelAPI_AttributeSelection> myAttribute;
35
36   fill_visitor(const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute)
37   : myAttribute(theAttribute) {}
38
39   void operator()(const ResultSubShapePair & thePair) const { myAttribute->setValue(thePair.first, thePair.second); }
40   void operator()(const TypeSubShapeNamePair & thePair) const { myAttribute->selectSubShape(thePair.first, thePair.second); }
41 };
42
43 void ModelHighAPI_Selection::fillAttribute(
44     const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute) const
45 {
46   boost::apply_visitor(fill_visitor(theAttribute), myValue);
47 }
48
49 //--------------------------------------------------------------------------------------
50 struct append_visitor : boost::static_visitor<void>
51 {
52   mutable std::shared_ptr<ModelAPI_AttributeSelectionList> myAttribute;
53
54   append_visitor(const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute)
55   : myAttribute(theAttribute) {}
56
57   void operator()(const ResultSubShapePair & thePair) const { myAttribute->append(thePair.first, thePair.second); }
58   void operator()(const TypeSubShapeNamePair & thePair) const {
59     // Note: the reverse order (first - type, second - sub-shape name)
60     myAttribute->append(thePair.second, thePair.first);
61   }
62 };
63
64 void ModelHighAPI_Selection::appendToList(
65     const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute) const
66 {
67   boost::apply_visitor(append_visitor(theAttribute), myValue);
68 }