Salome HOME
Update copyrights
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Recover.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "FeaturesPlugin_Recover.h"
21
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_Session.h>
28 #include <ModelAPI_Validator.h>
29 #include <ModelAPI_Result.h>
30 #include <ModelAPI_ResultBody.h>
31 #include <ModelAPI_Tools.h>
32 #include <GeomAlgoAPI_Copy.h>
33 #include <GeomAlgoAPI_Tools.h>
34
35 FeaturesPlugin_Recover::FeaturesPlugin_Recover()
36 {
37 }
38
39 void FeaturesPlugin_Recover::initAttributes()
40 {
41   data()->addAttribute(BASE_FEATURE(), ModelAPI_AttributeReference::typeId());
42   data()->addAttribute(RECOVERED_ENTITIES(), ModelAPI_AttributeRefList::typeId());
43
44 }
45
46 void FeaturesPlugin_Recover::execute()
47 {
48   std::string anError;
49   int aResultIndex = 0;
50   AttributeRefListPtr aRecovered = reflist(RECOVERED_ENTITIES());
51   for(int anIndex = aRecovered->size() - 1; anIndex >= 0; anIndex--) {
52     ObjectPtr anObj = aRecovered->object(anIndex);
53     if (!anObj.get())
54       continue;
55     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
56     if (!aResult.get())
57       continue;
58     GeomShapePtr aShape = aResult->shape();
59     if (!aShape.get())
60       continue;
61
62     // Copy shape.
63     std::shared_ptr<GeomAlgoAPI_Copy> aCopyAlgo(new GeomAlgoAPI_Copy(aShape));
64     // Check that algo is done.
65     if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aCopyAlgo, getKind(), anError)) {
66       setError(anError);
67       return;
68     }
69
70     // Store result.
71     ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
72     aResultBody->store(aCopyAlgo->shape());//, aCopyAlgo.shape());
73
74     aResultBody->loadModifiedShapes(aCopyAlgo, aShape, GeomAPI_Shape::VERTEX);
75     aResultBody->loadModifiedShapes(aCopyAlgo, aShape, GeomAPI_Shape::EDGE);
76     aResultBody->loadModifiedShapes(aCopyAlgo, aShape, GeomAPI_Shape::FACE);
77
78     setResult(aResultBody, aResultIndex);
79     ++aResultIndex;
80   }
81
82   removeResults(aResultIndex);
83 }