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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "FeaturesPlugin_Recover.h"
23 #include <ModelAPI_Data.h>
24 #include <ModelAPI_Document.h>
25 #include <ModelAPI_AttributeReference.h>
26 #include <ModelAPI_AttributeRefList.h>
27 #include <ModelAPI_AttributeBoolean.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>
35 FeaturesPlugin_Recover::FeaturesPlugin_Recover()
39 void FeaturesPlugin_Recover::initAttributes()
41 data()->addAttribute(BASE_FEATURE(), ModelAPI_AttributeReference::typeId());
42 data()->addAttribute(RECOVERED_ENTITIES(), ModelAPI_AttributeRefList::typeId());
46 void FeaturesPlugin_Recover::execute()
49 AttributeRefListPtr aRecovered = reflist(RECOVERED_ENTITIES());
50 for(int anIndex = aRecovered->size() - 1; anIndex >= 0; anIndex--) {
51 ObjectPtr anObj = aRecovered->object(anIndex);
54 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
57 GeomShapePtr aShape = aResult->shape();
62 GeomAlgoAPI_Copy aCopyAlgo(aShape);
63 // Check that algo is done.
64 if(!aCopyAlgo.isDone()) {
65 setError("Error: recover algorithm failed.");
68 // Check if shape is not null.
69 if(!aCopyAlgo.shape().get() || aCopyAlgo.shape()->isNull()) {
70 setError("Error: resulting shape is null.");
73 // Check that resulting shape is valid.
74 if(!aCopyAlgo.isValid()) {
75 setError("Error: resulting shape is not valid.");
80 ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
81 aResultBody->store(aCopyAlgo.shape());//, aCopyAlgo.shape());
82 std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = aCopyAlgo.mapOfSubShapes();
83 // like in import: forget any history
85 std::string aNameMS = "Shape";
86 aResultBody->loadFirstLevel(aCopyAlgo.shape(), aNameMS, aTag);
88 setResult(aResultBody, aResultIndex);
92 removeResults(aResultIndex);