Salome HOME
4f00429c14ce22dcd6cfd0572d303d1c0b9327a3
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_RefAttr.cpp
1 // Name   : ModelHighAPI_RefAttr.cpp
2 // Purpose: 
3 //
4 // History:
5 // 08/06/16 - Sergey POKHODENKO - Creation of the file
6
7 //--------------------------------------------------------------------------------------
8 #include "ModelHighAPI_RefAttr.h"
9
10 #include <ModelAPI_AttributeRefAttr.h>
11 #include <ModelAPI_AttributeRefAttrList.h>
12 #include <ModelAPI_Feature.h>
13 #include <ModelAPI_Result.h>
14 #include "ModelHighAPI_Interface.h"
15 //--------------------------------------------------------------------------------------
16 #include <iostream>
17 //--------------------------------------------------------------------------------------
18 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr()
19 {
20 }
21
22 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
23     const std::shared_ptr<ModelAPI_Attribute> & theValue)
24 : myValue(theValue)
25 {
26 }
27
28 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
29     const std::shared_ptr<ModelAPI_Object> & theValue)
30 : myValue(theValue)
31 {
32 }
33
34 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
35     const std::shared_ptr<ModelHighAPI_Interface> & theValue)
36 : myValue(std::shared_ptr<ModelAPI_Object>(theValue->feature()->firstResult()))
37 {
38   // TODO(spo): make firstResult() a member of ModelHighAPI_Interface and use it
39 }
40
41 ModelHighAPI_RefAttr::~ModelHighAPI_RefAttr()
42 {
43 }
44
45 //--------------------------------------------------------------------------------------
46 struct fill_visitor : boost::static_visitor<void>
47 {
48   mutable std::shared_ptr<ModelAPI_AttributeRefAttr> myAttribute;
49
50   fill_visitor(const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute)
51   : myAttribute(theAttribute) {}
52
53   void operator()(const std::shared_ptr<ModelAPI_Attribute>& theValue) const { myAttribute->setAttr(theValue); }
54   void operator()(const std::shared_ptr<ModelAPI_Object>& theValue) const { myAttribute->setObject(theValue); }
55 };
56
57 void ModelHighAPI_RefAttr::fillAttribute(
58     const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute) const
59 {
60   boost::apply_visitor(fill_visitor(theAttribute), myValue);
61 }
62
63 //--------------------------------------------------------------------------------------
64 struct append_visitor : boost::static_visitor<void>
65 {
66   mutable std::shared_ptr<ModelAPI_AttributeRefAttrList> myAttribute;
67
68   append_visitor(const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute)
69   : myAttribute(theAttribute) {}
70
71   void operator()(const std::shared_ptr<ModelAPI_Attribute>& theValue) const { myAttribute->append(theValue); }
72   void operator()(const std::shared_ptr<ModelAPI_Object>& theValue) const { myAttribute->append(theValue); }
73 };
74
75 void ModelHighAPI_RefAttr::appendToList(
76     const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute) const
77 {
78   boost::apply_visitor(append_visitor(theAttribute), myValue);
79 }