1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: FeaturesPlugin_Recover.cpp
4 // Created: 29 Jul 2016
5 // Author: Natalia ERMOLAEVA
7 #include "FeaturesPlugin_Recover.h"
9 #include <ModelAPI_Data.h>
10 #include <ModelAPI_Document.h>
11 #include <ModelAPI_AttributeReference.h>
12 #include <ModelAPI_AttributeRefList.h>
13 #include <ModelAPI_AttributeBoolean.h>
14 #include <ModelAPI_Session.h>
15 #include <ModelAPI_Validator.h>
16 #include <ModelAPI_Result.h>
17 #include <ModelAPI_ResultBody.h>
18 #include <ModelAPI_Tools.h>
19 #include <GeomAlgoAPI_Copy.h>
21 FeaturesPlugin_Recover::FeaturesPlugin_Recover()
25 void FeaturesPlugin_Recover::initAttributes()
27 data()->addAttribute(BASE_FEATURE(), ModelAPI_AttributeReference::typeId());
28 data()->addAttribute(RECOVERED_ENTITIES(), ModelAPI_AttributeRefList::typeId());
32 void FeaturesPlugin_Recover::execute()
35 AttributeRefListPtr aRecovered = reflist(RECOVERED_ENTITIES());
36 for(int anIndex = aRecovered->size() - 1; anIndex >= 0; anIndex--) {
37 ObjectPtr anObj = aRecovered->object(anIndex);
40 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
43 GeomShapePtr aShape = aResult->shape();
48 GeomAlgoAPI_Copy aCopyAlgo(aShape);
49 // Check that algo is done.
50 if(!aCopyAlgo.isDone()) {
51 setError("Error: recover algorithm failed.");
54 // Check if shape is not null.
55 if(!aCopyAlgo.shape().get() || aCopyAlgo.shape()->isNull()) {
56 setError("Error: resulting shape is null.");
59 // Check that resulting shape is valid.
60 if(!aCopyAlgo.isValid()) {
61 setError("Error: resulting shape is not valid.");
66 ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
67 aResultBody->store(aCopyAlgo.shape());//, aCopyAlgo.shape());
68 std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = aCopyAlgo.mapOfSubShapes();
69 // like in import: forget any history
71 std::string aNameMS = "Shape";
72 aResultBody->loadFirstLevel(aCopyAlgo.shape(), aNameMS, aTag);
74 setResult(aResultBody, aResultIndex);
78 removeResults(aResultIndex);