Salome HOME
Merge remote-tracking branch 'remotes/origin/HighLevelDump'
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Recover.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        FeaturesAPI_Recover.cpp
4 // Created:     07 June 2016
5 // Author:      Dmitry Bobylev
6
7 #include "FeaturesAPI_Recover.h"
8
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Reference.h>
11 #include <ModelHighAPI_Tools.h>
12
13 //=================================================================================================
14 FeaturesAPI_Recover::FeaturesAPI_Recover(const std::shared_ptr<ModelAPI_Feature>& theFeature)
15 : ModelHighAPI_Interface(theFeature)
16 {
17   initialize();
18 }
19
20 //=================================================================================================
21 FeaturesAPI_Recover::FeaturesAPI_Recover(const std::shared_ptr<ModelAPI_Feature>& theFeature,
22   const ModelHighAPI_Reference& theBaseFeature,
23   const std::list<ModelHighAPI_Selection>& theRecoveredList, const bool thePersistent)
24 : ModelHighAPI_Interface(theFeature)
25 {
26   if(initialize()) {
27     setBaseFeature(theBaseFeature);
28     setRecoveredList(theRecoveredList);
29     setIsPersistent(thePersistent);
30   }
31 }
32
33 //=================================================================================================
34 FeaturesAPI_Recover::~FeaturesAPI_Recover()
35 {}
36
37 //=================================================================================================
38 void FeaturesAPI_Recover::setBaseFeature(const ModelHighAPI_Reference& theBaseFeature)
39 {
40   fillAttribute(theBaseFeature, mybaseFeature);
41   // do not need to execute because on attribute changed it does everything anyway
42 }
43
44 //=================================================================================================
45 void FeaturesAPI_Recover::setRecoveredList(const std::list<ModelHighAPI_Selection>& theRecoverList)
46 {
47   fillAttribute(theRecoverList, myrecoveredList);
48   // do not need to execute because on attribute changed it does everything anyway
49 }
50
51 //=================================================================================================
52 void FeaturesAPI_Recover::setIsPersistent(bool thePersistent)
53 {
54   fillAttribute(thePersistent, myisPersistent);
55   // do not need to execute because on attribute changed it does everything anyway
56 }
57
58 //==================================================================================================
59 void FeaturesAPI_Recover::dump(ModelHighAPI_Dumper& theDumper) const
60 {
61   FeaturePtr aBase = feature();
62   const std::string& aDocName = theDumper.name(aBase->document());
63
64   AttributeReferencePtr anAttrBaseFeature = aBase->reference(FeaturesPlugin_Recover::BASE_FEATURE());
65   AttributeRefListPtr anAttrRecoveredEntities = aBase->reflist(FeaturesPlugin_Recover::RECOVERED_ENTITIES());
66   AttributeBooleanPtr anAttrPersistent = aBase->boolean(FeaturesPlugin_Recover::PERSISTENT());
67
68   FeaturePtr aFeature = ModelAPI_Feature::feature(anAttrBaseFeature->value());
69
70   theDumper << aBase << " = model.addRecover(" << aDocName << ", "
71             << aFeature << ", " << anAttrRecoveredEntities << ", "
72             << anAttrPersistent << ")" << std::endl;
73 }
74
75 //=================================================================================================
76 RecoverPtr addRecover(const std::shared_ptr<ModelAPI_Document>& thePart,
77   const ModelHighAPI_Reference& theBaseFeature,
78   const std::list<ModelHighAPI_Selection>& theRecoveredList, const bool thePersistent)
79 {
80   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Recover::ID());
81   return RecoverPtr(new FeaturesAPI_Recover(
82     aFeature, theBaseFeature, theRecoveredList, thePersistent));
83 }