]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelHighAPI/ModelHighAPI_Interface.cpp
Salome HOME
Debug for deflection dump
[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(bool isForce)
58 {
59   if (isForce) {
60     SessionPtr aMgr = ModelAPI_Session::get();
61     ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
62     FeaturePtr aFeature = feature();
63     if(aFactory->validate(aFeature))
64       aFeature->execute();
65   }
66
67   Events_Loop* aLoop = Events_Loop::loop();
68   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
69   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
70   //aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
71   //aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
72 }
73
74 void ModelHighAPI_Interface::setName(const std::string& theName)
75 {
76   feature()->data()->setName(theName);
77 }
78
79 std::list<ModelHighAPI_Selection> ModelHighAPI_Interface::result() const
80 {
81   // TODO(spo): should I use more common function for the whole model to prepare results?
82   const_cast<ModelHighAPI_Interface*>(this)->execute();
83
84   std::list<ModelHighAPI_Selection> aSelectionList;
85
86   std::list<std::shared_ptr<ModelAPI_Result> > aResults = feature()->results();
87   for (auto it = aResults.begin(), end = aResults.end(); it != end; ++it) {
88     aSelectionList.push_back(ModelHighAPI_Selection(*it));
89   }
90
91   return aSelectionList;
92 }
93
94 std::shared_ptr<ModelAPI_Result> ModelHighAPI_Interface::defaultResult() const
95 {
96   const_cast<ModelHighAPI_Interface*>(this)->execute();
97
98   return feature()->lastResult();
99 }
100
101 void ModelHighAPI_Interface::throwException(const std::string & theDescription)
102 {
103   Events_InfoMessage("ModelHighAPI_Interface", theDescription).send();
104 }
105
106 const std::string& ModelHighAPI_Interface::attributeGetter(const std::string& theAttrName)
107 {
108   return myAttrGetter[theAttrName];
109 }