1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 // Name : ModelHighAPI_Interface.cpp
6 // 17/05/16 - Sergey POKHODENKO - Creation of the file
8 //--------------------------------------------------------------------------------------
9 #include "ModelHighAPI_Interface.h"
10 //--------------------------------------------------------------------------------------
11 #include <Events_InfoMessage.h>
13 #include <ModelAPI_CompositeFeature.h>
14 #include <ModelAPI_Events.h>
15 #include <ModelAPI_Feature.h>
16 #include <ModelAPI_Session.h>
17 #include <ModelAPI_Validator.h>
19 #include "ModelHighAPI_Selection.h"
20 //--------------------------------------------------------------------------------------
21 ModelHighAPI_Interface::ModelHighAPI_Interface(
22 const std::shared_ptr<ModelAPI_Feature> & theFeature)
23 : myFeature(theFeature)
28 ModelHighAPI_Interface::~ModelHighAPI_Interface()
33 //--------------------------------------------------------------------------------------
34 std::shared_ptr<ModelAPI_Feature> ModelHighAPI_Interface::feature() const
39 std::shared_ptr<ModelHighAPI_Interface> ModelHighAPI_Interface::subFeature(const int theIndex) const
41 CompositeFeaturePtr aCompositeFeature =
42 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
43 if(!aCompositeFeature.get()) {
44 return InterfacePtr();
47 FeaturePtr aSubFeature = aCompositeFeature->subFeature(theIndex);
48 if(!aSubFeature.get()) {
49 return InterfacePtr();
52 return InterfacePtr(new ModelHighAPI_Interface(aSubFeature));
55 const std::string& ModelHighAPI_Interface::getKind() const
57 return feature()->getKind();
60 void ModelHighAPI_Interface::execute(bool isForce)
63 SessionPtr aMgr = ModelAPI_Session::get();
64 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
65 FeaturePtr aFeature = feature();
66 if(aFactory->validate(aFeature))
70 Events_Loop* aLoop = Events_Loop::loop();
71 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
72 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
73 //aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
74 //aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
77 void ModelHighAPI_Interface::setName(const std::string& theName)
79 feature()->data()->setName(theName);
82 ModelHighAPI_Selection ModelHighAPI_Interface::result() const
84 const_cast<ModelHighAPI_Interface*>(this)->execute();
86 return ModelHighAPI_Selection(feature()->firstResult());
89 std::list<ModelHighAPI_Selection> ModelHighAPI_Interface::results() const
91 const_cast<ModelHighAPI_Interface*>(this)->execute();
93 std::list<ModelHighAPI_Selection> aSelectionList;
95 std::list<std::shared_ptr<ModelAPI_Result> > aResults = feature()->results();
96 for (auto it = aResults.begin(), end = aResults.end(); it != end; ++it) {
97 aSelectionList.push_back(ModelHighAPI_Selection(*it));
100 return aSelectionList;
103 std::shared_ptr<ModelAPI_Result> ModelHighAPI_Interface::defaultResult() const
105 const_cast<ModelHighAPI_Interface*>(this)->execute();
107 return feature()->lastResult();
110 void ModelHighAPI_Interface::throwException(const std::string & theDescription)
112 Events_InfoMessage("ModelHighAPI_Interface", theDescription).send();
115 const std::string& ModelHighAPI_Interface::attributeGetter(const std::string& theAttrName)
117 return myAttrGetter[theAttrName];