X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_Recover.cpp;h=ba575fbeaa74c39f6926550eeef953aee90006ff;hb=fbb1e5c91c5d6ed1862a7621baca9db73433689e;hp=59a2526ca7b1c359250c4ba782151abf9ec607cf;hpb=43a163739b4d3c740fd4a319b6d6c5815ee68f64;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp b/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp index 59a2526ca..ba575fbea 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp @@ -1,8 +1,22 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> - -// File: FeaturesPlugin_Recover.cpp -// Created: 29 Jul 2016 -// Author: Natalia ERMOLAEVA +// Copyright (C) 2014-2017 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 +// #include "FeaturesPlugin_Recover.h" @@ -14,9 +28,9 @@ #include #include #include +#include #include - -using namespace std; +#include FeaturesPlugin_Recover::FeaturesPlugin_Recover() { @@ -26,105 +40,54 @@ void FeaturesPlugin_Recover::initAttributes() { data()->addAttribute(BASE_FEATURE(), ModelAPI_AttributeReference::typeId()); data()->addAttribute(RECOVERED_ENTITIES(), ModelAPI_AttributeRefList::typeId()); - data()->addAttribute(PERSISTENT(), ModelAPI_AttributeBoolean::typeId()); - myPersistent = boolean(PERSISTENT())->value(); - synchronizeRegistered(); } void FeaturesPlugin_Recover::execute() { - synchronizeRegistered(); -} - -void FeaturesPlugin_Recover::attributeChanged(const std::string& theID) -{ - synchronizeRegistered(); -} - -void FeaturesPlugin_Recover::synchronizeRegistered() -{ - FeaturePtr aBase = baseFeature(); - bool aNewPersistent = boolean(PERSISTENT())->value(); - if (aNewPersistent != myPersistent || myCurrentBase != aBase) - clearRegistered(); - - std::set aRecoveredInList; - // add unconcealed which are not in the myRegistered map - if (isStable() && !isDisabled()) { // if unstable, clear any unconcealment effect - AttributeRefListPtr aRecovered = reflist(RECOVERED_ENTITIES()); - for(int anIndex = aRecovered->size() - 1; anIndex >= 0; anIndex--) { - ObjectPtr anObj = aRecovered->object(anIndex); - aRecoveredInList.insert(anObj); - if (myRegistered.find(anObj) == myRegistered.end()) { - // not found, so register a new - ResultPtr aRes = std::dynamic_pointer_cast(anObj); - if (aRes.get()) { // this may be on first update after "open" - ModelAPI_Session::get()->validators()->registerUnconcealment( - aRes, aNewPersistent ? FeaturePtr() : aBase); - myRegistered.insert(anObj); - } - } + int aResultIndex = 0; + AttributeRefListPtr aRecovered = reflist(RECOVERED_ENTITIES()); + for(int anIndex = aRecovered->size() - 1; anIndex >= 0; anIndex--) { + ObjectPtr anObj = aRecovered->object(anIndex); + if (!anObj.get()) + continue; + ResultPtr aResult = std::dynamic_pointer_cast(anObj); + if (!aResult.get()) + continue; + GeomShapePtr aShape = aResult->shape(); + if (!aShape.get()) + continue; + + // Copy shape. + GeomAlgoAPI_Copy aCopyAlgo(aShape); + // Check that algo is done. + if(!aCopyAlgo.isDone()) { + setError("Error: recover algorithm failed."); + return; } - } - // remove unconcealed which are not in the stored list, but in the map - std::set >::iterator aMyReg = myRegistered.begin(); - while(aMyReg != myRegistered.end()) { - if (aRecoveredInList.find(*aMyReg) == aRecoveredInList.end()) { - ResultPtr aRes = std::dynamic_pointer_cast(*aMyReg); - ModelAPI_Session::get()->validators()->disableUnconcealment( - aRes, aNewPersistent ? FeaturePtr() : myCurrentBase); - myRegistered.erase(aMyReg); - aMyReg = myRegistered.begin(); // restart iteration because after erase iterator may be bad - } else { - aMyReg++; + // Check if shape is not null. + if(!aCopyAlgo.shape().get() || aCopyAlgo.shape()->isNull()) { + setError("Error: resulting shape is null."); + return; + } + // Check that resulting shape is valid. + if(!aCopyAlgo.isValid()) { + setError("Error: resulting shape is not valid."); + return; } - } - myCurrentBase = aBase; - myPersistent = aNewPersistent; -} - -void FeaturesPlugin_Recover::erase() -{ - // clears myRegistered before all information is destroyed - clearRegistered(); - ModelAPI_Feature::erase(); -} - -bool FeaturesPlugin_Recover::setStable(const bool theFlag) -{ - bool aRes = ModelAPI_Feature::setStable(theFlag); - synchronizeRegistered(); - return aRes; -} - -bool FeaturesPlugin_Recover::setDisabled(const bool theFlag) -{ - bool aRes = ModelAPI_Feature::setDisabled(theFlag); - synchronizeRegistered(); - return aRes; -} - -FeaturePtr FeaturesPlugin_Recover::baseFeature() -{ - // for the current moment it can be result of feature of feature: GUI is not debugged - ObjectPtr aBaseObj = reference(BASE_FEATURE())->value(); - FeaturePtr aResult; - if (aBaseObj.get() == NULL) - return aResult; - aResult = std::dynamic_pointer_cast(aBaseObj); - if (aResult.get() == NULL) - aResult = aBaseObj->document()->feature(std::dynamic_pointer_cast(aBaseObj)); - return aResult; -} -void FeaturesPlugin_Recover::clearRegistered() -{ - std::set >::iterator aMyReg = myRegistered.begin(); - for(; aMyReg != myRegistered.end(); aMyReg++) { - ResultPtr aRes = std::dynamic_pointer_cast(*aMyReg); - ModelAPI_Session::get()->validators()->disableUnconcealment( - aRes, myPersistent ? FeaturePtr() : myCurrentBase); + // Store result. + ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + aResultBody->store(aCopyAlgo.shape());//, aCopyAlgo.shape()); + std::shared_ptr aSubShapes = aCopyAlgo.mapOfSubShapes(); + // like in import: forget any history + int aTag(1); + std::string aNameMS = "Shape"; + aResultBody->loadFirstLevel(aCopyAlgo.shape(), aNameMS); + + setResult(aResultBody, aResultIndex); + ++aResultIndex; } - myRegistered.clear(); + + removeResults(aResultIndex); }