Salome HOME
Simplification and refactoring of unit tests for SketchPlugin
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_RefAttr.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 // Name   : ModelHighAPI_RefAttr.cpp
3 // Purpose:
4 //
5 // History:
6 // 08/06/16 - Sergey POKHODENKO - Creation of the file
7
8 //--------------------------------------------------------------------------------------
9 #include "ModelHighAPI_RefAttr.h"
10
11 #include <ModelAPI_AttributeRefAttr.h>
12 #include <ModelAPI_AttributeRefAttrList.h>
13 #include <ModelAPI_Events.h>
14 #include <ModelAPI_Feature.h>
15 #include <ModelAPI_Result.h>
16 #include "ModelHighAPI_Interface.h"
17 //--------------------------------------------------------------------------------------
18 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr()
19 : myVariantType(VT_ATTRIBUTE)
20 {
21 }
22
23 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
24     const std::shared_ptr<ModelAPI_Attribute> & theValue)
25 : myVariantType(VT_ATTRIBUTE)
26 , myAttribute(theValue)
27 {
28 }
29
30 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
31     const std::shared_ptr<ModelAPI_Object> & theValue)
32 : myVariantType(VT_OBJECT)
33 , myObject(theValue)
34 {
35 }
36
37 ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
38     const std::shared_ptr<ModelHighAPI_Interface> & theValue)
39 : myVariantType(VT_OBJECT)
40 , myObject(std::shared_ptr<ModelAPI_Object>(theValue->defaultResult()))
41 {
42 }
43
44 ModelHighAPI_RefAttr::~ModelHighAPI_RefAttr()
45 {
46 }
47
48 //--------------------------------------------------------------------------------------
49 void ModelHighAPI_RefAttr::fillAttribute(
50     const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute) const
51 {
52   switch(myVariantType) {
53     case VT_ATTRIBUTE: theAttribute->setAttr(myAttribute); return;
54     case VT_OBJECT: theAttribute->setObject(myObject); return;
55   }
56 }
57
58 //--------------------------------------------------------------------------------------
59 void ModelHighAPI_RefAttr::appendToList(
60     const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute) const
61 {
62   switch(myVariantType) {
63     case VT_ATTRIBUTE: theAttribute->append(myAttribute); return;
64     case VT_OBJECT: theAttribute->append(myObject); return;
65   }
66 }
67
68 //--------------------------------------------------------------------------------------
69 bool ModelHighAPI_RefAttr::isEmpty() const
70 {
71   return !(myAttribute && myObject);
72 }
73
74 //--------------------------------------------------------------------------------------
75 void ModelHighAPI_RefAttr::fillMessage(
76     const std::shared_ptr<ModelAPI_ObjectMovedMessage>& theMessage) const
77 {
78   switch (myVariantType) {
79   case VT_ATTRIBUTE: theMessage->setMovedAttribute(myAttribute); return;
80   case VT_OBJECT: theMessage->setMovedObject(myObject); return;
81   }
82 }