Salome HOME
401ba5467ed6f5a64f615c07ecb271b77b7dfd7e
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Interface.cpp
1 // Name   : ModelHighAPI_Interface.cpp
2 // Purpose: 
3 //
4 // History:
5 // 17/05/16 - Sergey POKHODENKO - Creation of the file
6
7 //--------------------------------------------------------------------------------------
8 #include "ModelHighAPI_Interface.h"
9 //--------------------------------------------------------------------------------------
10 #include <Events_InfoMessage.h>
11
12 #include <ModelAPI_CompositeFeature.h>
13 #include <ModelAPI_Events.h>
14 #include <ModelAPI_Feature.h>
15 #include <ModelAPI_Session.h>
16 #include <ModelAPI_Validator.h>
17
18 #include "ModelHighAPI_Selection.h"
19 //--------------------------------------------------------------------------------------
20 ModelHighAPI_Interface::ModelHighAPI_Interface(const std::shared_ptr<ModelAPI_Feature> & theFeature)
21 : myFeature(theFeature)
22 {
23
24 }
25
26 ModelHighAPI_Interface::~ModelHighAPI_Interface()
27 {
28
29 }
30
31 //--------------------------------------------------------------------------------------
32 std::shared_ptr<ModelAPI_Feature> ModelHighAPI_Interface::feature() const
33 {
34   return myFeature;
35 }
36
37 std::shared_ptr<ModelHighAPI_Interface> ModelHighAPI_Interface::subFeature(const int theIndex) const
38 {
39   CompositeFeaturePtr aCompositeFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
40   if(!aCompositeFeature.get()) {
41     return InterfacePtr();
42   }
43
44   FeaturePtr aSubFeature = aCompositeFeature->subFeature(theIndex);
45   if(!aSubFeature.get()) {
46     return InterfacePtr();
47   }
48
49   return InterfacePtr(new ModelHighAPI_Interface(aSubFeature));
50 }
51
52 const std::string& ModelHighAPI_Interface::getKind() const
53 {
54   return feature()->getKind();
55 }
56
57 void ModelHighAPI_Interface::execute()
58 {
59   //SessionPtr aMgr = ModelAPI_Session::get();
60   //ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
61   //FeaturePtr aFeature = feature();
62   //if(aFactory->validate(aFeature)) {
63   //  aFeature->execute();
64   //}
65
66   Events_Loop* aLoop = Events_Loop::loop();
67   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
68   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
69   //aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
70   //aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
71 }
72
73 void ModelHighAPI_Interface::setName(const std::string& theName)
74 {
75   feature()->data()->setName(theName);
76 }
77
78 std::list<ModelHighAPI_Selection> ModelHighAPI_Interface::result() const
79 {
80   // TODO(spo): should I use more common function for the whole model to prepare results?
81   const_cast<ModelHighAPI_Interface*>(this)->execute();
82
83   std::list<ModelHighAPI_Selection> aSelectionList;
84
85   std::list<std::shared_ptr<ModelAPI_Result> > aResults = feature()->results();
86   for (auto it = aResults.begin(), end = aResults.end(); it != end; ++it) {
87     aSelectionList.push_back(ModelHighAPI_Selection(*it));
88   }
89
90   return aSelectionList;
91 }
92
93 std::shared_ptr<ModelAPI_Result> ModelHighAPI_Interface::defaultResult() const
94 {
95   const_cast<ModelHighAPI_Interface*>(this)->execute();
96
97   return feature()->lastResult();
98 }
99
100 void ModelHighAPI_Interface::throwException(const std::string & theDescription)
101 {
102   Events_InfoMessage("ModelHighAPI_Interface", theDescription).send();
103 }
104
105 const std::string& ModelHighAPI_Interface::attributeGetter(const std::string& theAttrName)
106 {
107   return myAttrGetter[theAttrName];
108 }