X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModelHighAPI%2FModelHighAPI_Interface.cpp;h=7f9a31d70720157de05cc11ce9c1a4e7f6dc0264;hb=fc72d43b677baa05ae7fd317346fd8b723b799ed;hp=caa3d7acebe5c1d8f8573e28ff5a998f141da3e1;hpb=8631b1948e52fd933156530dcc5785fd1ed6e05f;p=modules%2Fshaper.git diff --git a/src/ModelHighAPI/ModelHighAPI_Interface.cpp b/src/ModelHighAPI/ModelHighAPI_Interface.cpp index caa3d7ace..7f9a31d70 100644 --- a/src/ModelHighAPI/ModelHighAPI_Interface.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Interface.cpp @@ -1,19 +1,37 @@ -// Name : ModelHighAPI_Interface.cpp -// Purpose: +// Copyright (C) 2014-2023 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// History: -// 17/05/16 - Sergey POKHODENKO - Creation of the file -//-------------------------------------------------------------------------------------- #include "ModelHighAPI_Interface.h" //-------------------------------------------------------------------------------------- -#include +#include +#include +#include #include +#include +#include +#include #include "ModelHighAPI_Selection.h" //-------------------------------------------------------------------------------------- -ModelHighAPI_Interface::ModelHighAPI_Interface(const std::shared_ptr & theFeature) +ModelHighAPI_Interface::ModelHighAPI_Interface( + const std::shared_ptr & theFeature) : myFeature(theFeature) { @@ -30,29 +48,96 @@ std::shared_ptr ModelHighAPI_Interface::feature() const return myFeature; } +std::shared_ptr ModelHighAPI_Interface::subFeature(const int theIndex) const +{ + CompositeFeaturePtr aCompositeFeature = + std::dynamic_pointer_cast(myFeature); + if(!aCompositeFeature.get()) { + return InterfacePtr(); + } + + FeaturePtr aSubFeature = aCompositeFeature->subFeature(theIndex); + if(!aSubFeature.get()) { + return InterfacePtr(); + } + + return InterfacePtr(new ModelHighAPI_Interface(aSubFeature)); +} + const std::string& ModelHighAPI_Interface::getKind() const { return feature()->getKind(); } -void ModelHighAPI_Interface::execute() +void ModelHighAPI_Interface::execute(bool isForce) +{ + if (isForce) { + SessionPtr aMgr = ModelAPI_Session::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + FeaturePtr aFeature = feature(); + if(aFactory->validate(aFeature)) + aFeature->execute(); + } + + Events_Loop* aLoop = Events_Loop::loop(); + aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED)); + aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); + aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + //aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED)); +} + +void ModelHighAPI_Interface::setName(const std::wstring& theName) +{ + if (feature().get() && feature()->data()->isValid()) + feature()->data()->setName(theName); + else { + std::cout<<"Error: set name "<data()->name(); +} + +ModelHighAPI_Selection ModelHighAPI_Interface::result() const { - feature()->execute(); + std::list aResults = results(); + if (aResults.empty()) + return ModelHighAPI_Selection(std::shared_ptr()); + return aResults.front(); } -std::list ModelHighAPI_Interface::result() const +std::list ModelHighAPI_Interface::results() const { + const_cast(this)->execute(); + std::list aSelectionList; - std::list > aResults = feature()->results(); - for (auto it = aResults.begin(), end = aResults.end(); it != end; ++it) { - aSelectionList.push_back(ModelHighAPI_Selection(*it)); + if (feature().get()) { + std::list > aResults = feature()->results(); + for (auto it = aResults.begin(), end = aResults.end(); it != end; ++it) { + if (!(*it)->isDisabled()) + aSelectionList.push_back(ModelHighAPI_Selection(*it)); + } } return aSelectionList; } +std::shared_ptr ModelHighAPI_Interface::defaultResult() const +{ + const_cast(this)->execute(); + + return feature()->lastResult(); +} + void ModelHighAPI_Interface::throwException(const std::string & theDescription) { - Events_Error::send(theDescription); + Events_InfoMessage("ModelHighAPI_Interface", theDescription).send(); +} + +const std::string& ModelHighAPI_Interface::attributeGetter(const std::string& theAttrName) +{ + return myAttrGetter[theAttrName]; }