Salome HOME
Fix tests MakeBrick2 & MakeBrick3. Fix Box macro feature.
[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_Feature.h>
12 #include <ModelAPI_Result.h>
13 #include "ModelHighAPI_Interface.h"
14 //--------------------------------------------------------------------------------------
15 #include <iostream>
16 //--------------------------------------------------------------------------------------
17 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr()
18 {
19 }
20
21 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
22     const std::shared_ptr<ModelAPI_Attribute> & theValue)
23 : myValue(theValue)
24 {
25 }
26
27 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
28     const std::shared_ptr<ModelAPI_Object> & theValue)
29 : myValue(theValue)
30 {
31 }
32
33 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
34     const std::shared_ptr<ModelHighAPI_Interface> & theValue)
35 : myValue(std::shared_ptr<ModelAPI_Object>(theValue->feature()->firstResult()))
36 {
37   // TODO(spo): make firstResult() a member of ModelHighAPI_Interface and use it
38 }
39
40 ModelHighAPI_RefAttr::~ModelHighAPI_RefAttr()
41 {
42 }
43
44 //--------------------------------------------------------------------------------------
45 struct fill_visitor : boost::static_visitor<void>
46 {
47   mutable std::shared_ptr<ModelAPI_AttributeRefAttr> myAttribute;
48
49   fill_visitor(const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute)
50   : myAttribute(theAttribute) {}
51
52   void operator()(const std::shared_ptr<ModelAPI_Attribute>& theValue) const { myAttribute->setAttr(theValue); }
53   void operator()(const std::shared_ptr<ModelAPI_Object>& theValue) const { myAttribute->setObject(theValue); }
54 };
55
56 void ModelHighAPI_RefAttr::fillAttribute(
57     const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute) const
58 {
59   boost::apply_visitor(fill_visitor(theAttribute), myValue);
60 }