]> SALOME platform Git repositories - modules/shaper.git/blob - src/FeaturesPlugin/FeaturesPlugin_Recover.cpp
Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Recover.cpp
1 // Copyright (C) 2014-2017  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<mailto: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
34 FeaturesPlugin_Recover::FeaturesPlugin_Recover()
35 {
36 }
37
38 void FeaturesPlugin_Recover::initAttributes()
39 {
40   data()->addAttribute(BASE_FEATURE(), ModelAPI_AttributeReference::typeId());
41   data()->addAttribute(RECOVERED_ENTITIES(), ModelAPI_AttributeRefList::typeId());
42
43 }
44
45 void FeaturesPlugin_Recover::execute()
46 {
47   int aResultIndex = 0;
48   AttributeRefListPtr aRecovered = reflist(RECOVERED_ENTITIES());
49   for(int anIndex = aRecovered->size() - 1; anIndex >= 0; anIndex--) {
50     ObjectPtr anObj = aRecovered->object(anIndex);
51     if (!anObj.get())
52       continue;
53     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
54     if (!aResult.get())
55       continue;
56     GeomShapePtr aShape = aResult->shape();
57     if (!aShape.get())
58       continue;
59
60     // Copy shape.
61     GeomAlgoAPI_Copy aCopyAlgo(aShape);
62     // Check that algo is done.
63     if(!aCopyAlgo.isDone()) {
64       setError("Error: recover algorithm failed.");
65       return;
66     }
67     // Check if shape is not null.
68     if(!aCopyAlgo.shape().get() || aCopyAlgo.shape()->isNull()) {
69       setError("Error: resulting shape is null.");
70       return;
71     }
72     // Check that resulting shape is valid.
73     if(!aCopyAlgo.isValid()) {
74       setError("Error: resulting shape is not valid.");
75       return;
76     }
77
78     // Store result.
79     ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
80     aResultBody->store(aCopyAlgo.shape());//, aCopyAlgo.shape());
81     std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = aCopyAlgo.mapOfSubShapes();
82     // like in import: forget any history
83     int aTag(1);
84     std::string aNameMS = "Shape";
85     aResultBody->loadFirstLevel(aCopyAlgo.shape(), aNameMS, aTag);
86
87     setResult(aResultBody, aResultIndex);
88     ++aResultIndex;
89   }
90
91   removeResults(aResultIndex);
92 }