Salome HOME
63b3def93b085a5e39e54cdd75969212cb934e46
[modules/shaper.git] / src / PartSetAPI / PartSetAPI_Part.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 // Name   : PartSetAPI_Part.cpp
3 // Purpose:
4 //
5 // History:
6 // 16/06/16 - Sergey POKHODENKO - Creation of the file
7
8 //--------------------------------------------------------------------------------------
9 #include "PartSetAPI_Part.h"
10 //--------------------------------------------------------------------------------------
11 #include <ModelAPI_ResultPart.h>
12 #include <ModelHighAPI_Dumper.h>
13 //--------------------------------------------------------------------------------------
14 #include <PartSetPlugin_Duplicate.h>
15 #include <PartSetPlugin_Remove.h>
16 //--------------------------------------------------------------------------------------
17 PartSetAPI_Part::PartSetAPI_Part(
18     const std::shared_ptr<ModelAPI_Feature> & theFeature)
19 : ModelHighAPI_Interface(theFeature)
20 {
21   initialize();
22 }
23
24 PartSetAPI_Part::~PartSetAPI_Part()
25 {
26 }
27
28 //--------------------------------------------------------------------------------------
29 std::shared_ptr<ModelAPI_Document> PartSetAPI_Part::document() const
30 {
31   return std::dynamic_pointer_cast<ModelAPI_ResultPart>(defaultResult())->partDoc();
32 }
33
34 void PartSetAPI_Part::dump(ModelHighAPI_Dumper& theDumper) const
35 {
36   FeaturePtr aBase = feature();
37   const std::string& aDocName = theDumper.name(aBase->document());
38
39   theDumper << aBase << " = model.addPart(" << aDocName << ")" << std::endl;
40 }
41
42 //--------------------------------------------------------------------------------------
43 PartPtr addPart(const std::shared_ptr<ModelAPI_Document> & thePart)
44 {
45   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PartSetAPI_Part::ID());
46   aFeature->execute();
47   return PartPtr(new PartSetAPI_Part(aFeature));
48 }
49
50 PartPtr duplicatePart(const std::shared_ptr<ModelAPI_Document> & thePart)
51 {
52   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PartSetPlugin_Duplicate::ID());
53   aFeature->execute();
54   return PartPtr(new PartSetAPI_Part(aFeature));
55 }
56
57 void removePart(const std::shared_ptr<ModelAPI_Document> & thePart)
58 {
59   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PartSetPlugin_Remove::ID());
60   aFeature->execute();
61 }