Salome HOME
39b076ffbe7df707a4a35f24cf15cb3aeadfce9c
[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_Feature.h>
13 #include <ModelAPI_Session.h>
14 #include <ModelAPI_Validator.h>
15
16 #include "ModelHighAPI_Selection.h"
17 //--------------------------------------------------------------------------------------
18 ModelHighAPI_Interface::ModelHighAPI_Interface(const std::shared_ptr<ModelAPI_Feature> & theFeature)
19 : myFeature(theFeature)
20 {
21
22 }
23
24 ModelHighAPI_Interface::~ModelHighAPI_Interface()
25 {
26
27 }
28
29 //--------------------------------------------------------------------------------------
30 std::shared_ptr<ModelAPI_Feature> ModelHighAPI_Interface::feature() const
31 {
32   return myFeature;
33 }
34
35 const std::string& ModelHighAPI_Interface::getKind() const
36 {
37   return feature()->getKind();
38 }
39
40 void ModelHighAPI_Interface::execute()
41 {
42   SessionPtr aMgr = ModelAPI_Session::get();
43   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
44   FeaturePtr aFeature = feature();
45   if(aFactory->validate(aFeature)) {
46     aFeature->execute();
47   }
48 }
49
50 std::list<ModelHighAPI_Selection> ModelHighAPI_Interface::result() const
51 {
52   // TODO(spo): should I use more common function for the whole model to prepare results?
53   const_cast<ModelHighAPI_Interface*>(this)->execute();
54
55   std::list<ModelHighAPI_Selection> aSelectionList;
56
57   std::list<std::shared_ptr<ModelAPI_Result> > aResults = feature()->results();
58   for (auto it = aResults.begin(), end = aResults.end(); it != end; ++it) {
59     aSelectionList.push_back(ModelHighAPI_Selection(*it));
60   }
61
62   return aSelectionList;
63 }
64
65 std::shared_ptr<ModelAPI_Result> ModelHighAPI_Interface::defaultResult() const
66 {
67   const_cast<ModelHighAPI_Interface*>(this)->execute();
68
69   return feature()->lastResult();
70 }
71
72 void ModelHighAPI_Interface::throwException(const std::string & theDescription)
73 {
74   Events_InfoMessage("ModelHighAPI_Interface", theDescription).send();
75 }
76
77 const std::string& ModelHighAPI_Interface::attributeGetter(const std::string& theAttrName)
78 {
79   return myAttrGetter[theAttrName];
80 }