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_Tools.h>
18 #include <GeomAlgoAPI_Copy.h>
20 FeaturesPlugin_Recover::FeaturesPlugin_Recover()
24 void FeaturesPlugin_Recover::initAttributes()
26 data()->addAttribute(BASE_FEATURE(), ModelAPI_AttributeReference::typeId());
27 data()->addAttribute(RECOVERED_ENTITIES(), ModelAPI_AttributeRefList::typeId());
31 void FeaturesPlugin_Recover::execute()
34 AttributeRefListPtr aRecovered = reflist(RECOVERED_ENTITIES());
35 for(int anIndex = aRecovered->size() - 1; anIndex >= 0; anIndex--) {
36 ObjectPtr anObj = aRecovered->object(anIndex);
39 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
42 GeomShapePtr aShape = aResult->shape();
47 GeomAlgoAPI_Copy aCopyAlgo(aShape);
48 // Check that algo is done.
49 if(!aCopyAlgo.isDone()) {
50 setError("Error: recover algorithm failed.");
53 // Check if shape is not null.
54 if(!aCopyAlgo.shape().get() || aCopyAlgo.shape()->isNull()) {
55 setError("Error: resulting shape is null.");
58 // Check that resulting shape is valid.
59 if(!aCopyAlgo.isValid()) {
60 setError("Error: resulting shape is not valid.");
65 ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
66 aResultBody->store(aCopyAlgo.shape());//, aCopyAlgo.shape());
67 std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = aCopyAlgo.mapOfSubShapes();
68 // like in import: forget any history
70 std::string aNameMS = "Shape";
71 aResultBody->loadFirstLevel(aCopyAlgo.shape(), aNameMS, aTag);
73 setResult(aResultBody, aResultIndex);
77 removeResults(aResultIndex);