1 // Name : ModelHighAPI_Interface.cpp
5 // 17/05/16 - Sergey POKHODENKO - Creation of the file
7 //--------------------------------------------------------------------------------------
8 #include "ModelHighAPI_Interface.h"
9 //--------------------------------------------------------------------------------------
10 #include <Events_InfoMessage.h>
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>
18 #include "ModelHighAPI_Selection.h"
19 //--------------------------------------------------------------------------------------
20 ModelHighAPI_Interface::ModelHighAPI_Interface(const std::shared_ptr<ModelAPI_Feature> & theFeature)
21 : myFeature(theFeature)
26 ModelHighAPI_Interface::~ModelHighAPI_Interface()
31 //--------------------------------------------------------------------------------------
32 std::shared_ptr<ModelAPI_Feature> ModelHighAPI_Interface::feature() const
37 std::shared_ptr<ModelHighAPI_Interface> ModelHighAPI_Interface::subFeature(const int theIndex) const
39 CompositeFeaturePtr aCompositeFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
40 if(!aCompositeFeature.get()) {
41 return InterfacePtr();
44 FeaturePtr aSubFeature = aCompositeFeature->subFeature(theIndex);
45 if(!aSubFeature.get()) {
46 return InterfacePtr();
49 return InterfacePtr(new ModelHighAPI_Interface(aSubFeature));
52 const std::string& ModelHighAPI_Interface::getKind() const
54 return feature()->getKind();
57 void ModelHighAPI_Interface::execute()
59 //SessionPtr aMgr = ModelAPI_Session::get();
60 //ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
61 //FeaturePtr aFeature = feature();
62 //if(aFactory->validate(aFeature)) {
63 // aFeature->execute();
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));
73 void ModelHighAPI_Interface::setName(const std::string& theName)
75 feature()->data()->setName(theName);
78 std::list<ModelHighAPI_Selection> ModelHighAPI_Interface::result() const
80 // TODO(spo): should I use more common function for the whole model to prepare results?
81 const_cast<ModelHighAPI_Interface*>(this)->execute();
83 std::list<ModelHighAPI_Selection> aSelectionList;
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));
90 return aSelectionList;
93 std::shared_ptr<ModelAPI_Result> ModelHighAPI_Interface::defaultResult() const
95 const_cast<ModelHighAPI_Interface*>(this)->execute();
97 return feature()->lastResult();
100 void ModelHighAPI_Interface::throwException(const std::string & theDescription)
102 Events_InfoMessage("ModelHighAPI_Interface", theDescription).send();
105 const std::string& ModelHighAPI_Interface::attributeGetter(const std::string& theAttrName)
107 return myAttrGetter[theAttrName];