Salome HOME
Dump Python in the High Level Parameterized Geometry API (issue #1648)
[modules/shaper.git] / src / PartSetAPI / PartSetAPI_Part.cpp
1 // Name   : PartSetAPI_Part.cpp
2 // Purpose: 
3 //
4 // History:
5 // 16/06/16 - Sergey POKHODENKO - Creation of the file
6
7 //--------------------------------------------------------------------------------------
8 #include "PartSetAPI_Part.h"
9 //--------------------------------------------------------------------------------------
10 #include <ModelAPI_ResultPart.h>
11 #include <ModelHighAPI_Dumper.h>
12 //--------------------------------------------------------------------------------------
13 #include <PartSetPlugin_Duplicate.h>
14 #include <PartSetPlugin_Remove.h>
15 //--------------------------------------------------------------------------------------
16 PartSetAPI_Part::PartSetAPI_Part(
17     const std::shared_ptr<ModelAPI_Feature> & theFeature)
18 : ModelHighAPI_Interface(theFeature)
19 {
20   initialize();
21 }
22
23 PartSetAPI_Part::~PartSetAPI_Part()
24 {
25 }
26
27 //--------------------------------------------------------------------------------------
28 std::shared_ptr<ModelAPI_Document> PartSetAPI_Part::document() const
29 {
30   return std::dynamic_pointer_cast<ModelAPI_ResultPart>(defaultResult())->partDoc();
31 }
32
33 void PartSetAPI_Part::dump(ModelHighAPI_Dumper& theDumper) const
34 {
35   FeaturePtr aBase = feature();
36   const std::string& aDocName = theDumper.name(aBase->document());
37
38   theDumper << aBase << " = model.addPart(" << aDocName << ")" << std::endl;
39 }
40
41 //--------------------------------------------------------------------------------------
42 PartPtr addPart(const std::shared_ptr<ModelAPI_Document> & thePart)
43 {
44   // TODO(spo): check that thePart is not empty
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   // TODO(spo): check that thePart is not empty
53   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PartSetPlugin_Duplicate::ID());
54   aFeature->execute();
55   return PartPtr(new PartSetAPI_Part(aFeature));
56 }
57
58 void removePart(const std::shared_ptr<ModelAPI_Document> & thePart)
59 {
60   // TODO(spo): check that thePart is not empty
61   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PartSetPlugin_Remove::ID());
62   aFeature->execute();
63 }