1 // Copyright (C) 2014-2022 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
20 #include "FeaturesPlugin_Recover.h"
22 #include <ModelAPI_Data.h>
23 #include <ModelAPI_Document.h>
24 #include <ModelAPI_AttributeReference.h>
25 #include <ModelAPI_AttributeRefList.h>
26 #include <ModelAPI_AttributeBoolean.h>
27 #include <ModelAPI_AttributeString.h>
28 #include <ModelAPI_Session.h>
29 #include <ModelAPI_Validator.h>
30 #include <ModelAPI_Result.h>
31 #include <ModelAPI_ResultBody.h>
32 #include <ModelAPI_Tools.h>
33 #include <GeomAlgoAPI_Copy.h>
34 #include <GeomAlgoAPI_Tools.h>
36 FeaturesPlugin_Recover::FeaturesPlugin_Recover()
37 : myClearListOnTypeChange(true)
41 void FeaturesPlugin_Recover::initAttributes()
43 data()->addAttribute(BASE_FEATURE(), ModelAPI_AttributeReference::typeId());
44 data()->addAttribute(RECOVERED_ENTITIES(), ModelAPI_AttributeRefList::typeId());
46 data()->addAttribute(METHOD(), ModelAPI_AttributeString::typeId());
47 if (!string(METHOD())->isInitialized()) {
48 myClearListOnTypeChange = false;
49 data()->blockSendAttributeUpdated(true, false);
50 string(METHOD())->setValue(METHOD_DEFAULT());
51 data()->blockSendAttributeUpdated(false, false);
52 myClearListOnTypeChange = true;
54 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), METHOD());
57 void FeaturesPlugin_Recover::execute()
61 AttributeRefListPtr aRecovered = reflist(RECOVERED_ENTITIES());
62 for(int anIndex = aRecovered->size() - 1; anIndex >= 0; anIndex--) {
63 ObjectPtr anObj = aRecovered->object(anIndex);
66 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
69 GeomShapePtr aShape = aResult->shape();
74 std::shared_ptr<GeomAlgoAPI_Copy> aCopyAlgo(new GeomAlgoAPI_Copy(aShape));
75 // Check that algo is done.
76 if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aCopyAlgo, getKind(), anError)) {
82 ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
83 aResultBody->store(aCopyAlgo->shape());//, aCopyAlgo.shape());
85 aResultBody->loadModifiedShapes(aCopyAlgo, aShape, GeomAPI_Shape::VERTEX);
86 aResultBody->loadModifiedShapes(aCopyAlgo, aShape, GeomAPI_Shape::EDGE);
87 aResultBody->loadModifiedShapes(aCopyAlgo, aShape, GeomAPI_Shape::FACE);
89 setResult(aResultBody, aResultIndex);
93 removeResults(aResultIndex);
96 void FeaturesPlugin_Recover::attributeChanged(const std::string& theID)
98 if (theID == METHOD() && myClearListOnTypeChange)
99 reflist(RECOVERED_ENTITIES())->clear();