1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "ModelHighAPI_Interface.h"
21 //--------------------------------------------------------------------------------------
22 #include <Events_InfoMessage.h>
24 #include <ModelAPI_CompositeFeature.h>
25 #include <ModelAPI_Events.h>
26 #include <ModelAPI_Feature.h>
27 #include <ModelAPI_Session.h>
28 #include <ModelAPI_Validator.h>
30 #include "ModelHighAPI_Selection.h"
31 //--------------------------------------------------------------------------------------
32 ModelHighAPI_Interface::ModelHighAPI_Interface(
33 const std::shared_ptr<ModelAPI_Feature> & theFeature)
34 : myFeature(theFeature)
39 ModelHighAPI_Interface::~ModelHighAPI_Interface()
44 //--------------------------------------------------------------------------------------
45 std::shared_ptr<ModelAPI_Feature> ModelHighAPI_Interface::feature() const
50 std::shared_ptr<ModelHighAPI_Interface> ModelHighAPI_Interface::subFeature(const int theIndex) const
52 CompositeFeaturePtr aCompositeFeature =
53 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
54 if(!aCompositeFeature.get()) {
55 return InterfacePtr();
58 FeaturePtr aSubFeature = aCompositeFeature->subFeature(theIndex);
59 if(!aSubFeature.get()) {
60 return InterfacePtr();
63 return InterfacePtr(new ModelHighAPI_Interface(aSubFeature));
66 const std::string& ModelHighAPI_Interface::getKind() const
68 return feature()->getKind();
71 void ModelHighAPI_Interface::execute(bool isForce)
74 SessionPtr aMgr = ModelAPI_Session::get();
75 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
76 FeaturePtr aFeature = feature();
77 if(aFactory->validate(aFeature))
81 Events_Loop* aLoop = Events_Loop::loop();
82 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
83 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
84 //aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
85 //aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
88 void ModelHighAPI_Interface::setName(const std::string& theName)
90 feature()->data()->setName(theName);
93 ModelHighAPI_Selection ModelHighAPI_Interface::result() const
95 const_cast<ModelHighAPI_Interface*>(this)->execute();
97 return ModelHighAPI_Selection(feature()->firstResult());
100 std::list<ModelHighAPI_Selection> ModelHighAPI_Interface::results() const
102 const_cast<ModelHighAPI_Interface*>(this)->execute();
104 std::list<ModelHighAPI_Selection> aSelectionList;
106 std::list<std::shared_ptr<ModelAPI_Result> > aResults = feature()->results();
107 for (auto it = aResults.begin(), end = aResults.end(); it != end; ++it) {
108 aSelectionList.push_back(ModelHighAPI_Selection(*it));
111 return aSelectionList;
114 std::shared_ptr<ModelAPI_Result> ModelHighAPI_Interface::defaultResult() const
116 const_cast<ModelHighAPI_Interface*>(this)->execute();
118 return feature()->lastResult();
121 void ModelHighAPI_Interface::throwException(const std::string & theDescription)
123 Events_InfoMessage("ModelHighAPI_Interface", theDescription).send();
126 const std::string& ModelHighAPI_Interface::attributeGetter(const std::string& theAttrName)
128 return myAttrGetter[theAttrName];