Salome HOME
Dump Python in the High Level Parameterized Geometry API (issue #1648)
[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 void ModelHighAPI_Interface::setName(const std::string& theName)
51 {
52   feature()->data()->setName(theName);
53 }
54
55 std::list<ModelHighAPI_Selection> ModelHighAPI_Interface::result() const
56 {
57   // TODO(spo): should I use more common function for the whole model to prepare results?
58   const_cast<ModelHighAPI_Interface*>(this)->execute();
59
60   std::list<ModelHighAPI_Selection> aSelectionList;
61
62   std::list<std::shared_ptr<ModelAPI_Result> > aResults = feature()->results();
63   for (auto it = aResults.begin(), end = aResults.end(); it != end; ++it) {
64     aSelectionList.push_back(ModelHighAPI_Selection(*it));
65   }
66
67   return aSelectionList;
68 }
69
70 std::shared_ptr<ModelAPI_Result> ModelHighAPI_Interface::defaultResult() const
71 {
72   const_cast<ModelHighAPI_Interface*>(this)->execute();
73
74   return feature()->lastResult();
75 }
76
77 void ModelHighAPI_Interface::throwException(const std::string & theDescription)
78 {
79   Events_InfoMessage("ModelHighAPI_Interface", theDescription).send();
80 }
81
82 const std::string& ModelHighAPI_Interface::attributeGetter(const std::string& theAttrName)
83 {
84   return myAttrGetter[theAttrName];
85 }