Salome HOME
Issue #1648: Dump Python in the High Level Parameterized Geometry API
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Pipe.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        FeaturesAPI_Pipe.cpp
4 // Created:     09 June 2016
5 // Author:      Dmitry Bobylev
6
7 #include "FeaturesAPI_Pipe.h"
8
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Tools.h>
11
12 //==================================================================================================
13 FeaturesAPI_Pipe::FeaturesAPI_Pipe(const std::shared_ptr<ModelAPI_Feature>& theFeature)
14 : ModelHighAPI_Interface(theFeature)
15 {
16   initialize();
17 }
18
19 //==================================================================================================
20 FeaturesAPI_Pipe::FeaturesAPI_Pipe(const std::shared_ptr<ModelAPI_Feature>& theFeature,
21                                    const std::list<ModelHighAPI_Selection>& theBaseObjects,
22                                    const ModelHighAPI_Selection& thePath)
23 : ModelHighAPI_Interface(theFeature)
24 {
25   if(initialize()) {
26     fillAttribute(theBaseObjects, mybaseObjects);
27     setPath(thePath);
28   }
29 }
30
31 //==================================================================================================
32 FeaturesAPI_Pipe::FeaturesAPI_Pipe(const std::shared_ptr<ModelAPI_Feature>& theFeature,
33                                    const std::list<ModelHighAPI_Selection>& theBaseObjects,
34                                    const ModelHighAPI_Selection& thePath,
35                                    const ModelHighAPI_Selection& theBiNoramal)
36 : ModelHighAPI_Interface(theFeature)
37 {
38   if(initialize()) {
39     setByBasePathBiNormal(theBaseObjects, thePath, theBiNoramal);
40   }
41 }
42
43 //==================================================================================================
44 FeaturesAPI_Pipe::FeaturesAPI_Pipe(const std::shared_ptr<ModelAPI_Feature>& theFeature,
45                                    const std::list<ModelHighAPI_Selection>& theBaseObjects,
46                                    const ModelHighAPI_Selection& thePath,
47                                    const std::list<ModelHighAPI_Selection>& theLocations)
48 : ModelHighAPI_Interface(theFeature)
49 {
50   if(initialize()) {
51     setByBasePathLocations(theBaseObjects, thePath, theLocations);
52   }
53 }
54
55 //==================================================================================================
56 FeaturesAPI_Pipe::~FeaturesAPI_Pipe()
57 {
58
59 }
60
61 //==================================================================================================
62 void FeaturesAPI_Pipe::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
63 {
64   fillAttribute(theBaseObjects, mybaseObjects);
65
66   execute();
67 }
68
69 //==================================================================================================
70 void FeaturesAPI_Pipe::setPath(const ModelHighAPI_Selection& thePath)
71 {
72   fillAttribute(thePath, mypath);
73
74   execute();
75 }
76
77 //==================================================================================================
78 void FeaturesAPI_Pipe::setByBasePath(const std::list<ModelHighAPI_Selection>& theBaseObjects,
79                                      const ModelHighAPI_Selection& thePath)
80 {
81   fillAttribute(FeaturesPlugin_Pipe::CREATION_METHOD_SIMPLE(), mycreationMethod);
82   fillAttribute(theBaseObjects, mybaseObjects);
83   fillAttribute(thePath, mypath);
84
85   execute();
86 }
87
88 //==================================================================================================
89 void FeaturesAPI_Pipe::setByBasePathBiNormal(const std::list<ModelHighAPI_Selection>& theBaseObjects,
90                                              const ModelHighAPI_Selection& thePath,
91                                              const ModelHighAPI_Selection& theBiNoramal)
92 {
93   fillAttribute(FeaturesPlugin_Pipe::CREATION_METHOD_BINORMAL(), mycreationMethod);
94   fillAttribute(theBaseObjects, mybaseObjects);
95   fillAttribute(thePath, mypath);
96   fillAttribute(theBiNoramal, mybiNormal);
97
98   execute();
99 }
100
101 //==================================================================================================
102 void FeaturesAPI_Pipe::setByBasePathLocations(const std::list<ModelHighAPI_Selection>& theBaseObjects,
103                                               const ModelHighAPI_Selection& thePath,
104                                               const std::list<ModelHighAPI_Selection>& theLocations)
105 {
106   fillAttribute(FeaturesPlugin_Pipe::CREATION_METHOD_LOCATIONS(), mycreationMethod);
107   fillAttribute(theBaseObjects, mybaseObjects);
108   fillAttribute(thePath, mypath);
109   fillAttribute(theLocations, mylocations);
110
111   execute();
112 }
113
114 //==================================================================================================
115 void FeaturesAPI_Pipe::dump(ModelHighAPI_Dumper& theDumper) const
116 {
117   FeaturePtr aBase = feature();
118   const std::string& aDocName = theDumper.name(aBase->document());
119
120   AttributeSelectionListPtr anAttrObjects = aBase->selectionList(FeaturesPlugin_Pipe::BASE_OBJECTS_ID());
121   AttributeSelectionPtr anAttrPath = aBase->selection(FeaturesPlugin_Pipe::PATH_OBJECT_ID());
122
123   theDumper << aBase << " = model.addPipe(" << aDocName << ", "
124             << anAttrObjects << ", " << anAttrPath;
125
126   std::string aCreationMethod = aBase->string(FeaturesPlugin_Pipe::CREATION_METHOD())->value();
127
128   if(aCreationMethod == FeaturesPlugin_Pipe::CREATION_METHOD_SIMPLE()) {
129     // Do nothing;
130   } else if(aCreationMethod == FeaturesPlugin_Pipe::CREATION_METHOD_BINORMAL()) {
131     AttributeSelectionPtr anAttrBiNormal = aBase->selection(FeaturesPlugin_Pipe::BINORMAL_ID());
132
133     theDumper << ", " << anAttrBiNormal;
134   } else if(aCreationMethod == FeaturesPlugin_Pipe::CREATION_METHOD_LOCATIONS()) {
135     AttributeSelectionListPtr anAttrLocations = aBase->selectionList(FeaturesPlugin_Pipe::LOCATIONS_ID());
136
137     theDumper << ", " << anAttrLocations;
138   }
139
140   theDumper << ")" << std::endl;
141 }
142
143 //==================================================================================================
144 PipePtr addPipe(const std::shared_ptr<ModelAPI_Document>& thePart,
145                 const std::list<ModelHighAPI_Selection>& theBaseObjects,
146                 const ModelHighAPI_Selection& thePath)
147 {
148   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Pipe::ID());
149   return PipePtr(new FeaturesAPI_Pipe(aFeature, theBaseObjects, thePath));
150 }
151
152 //==================================================================================================
153 PipePtr addPipe(const std::shared_ptr<ModelAPI_Document>& thePart,
154                 const std::list<ModelHighAPI_Selection>& theBaseObjects,
155                 const ModelHighAPI_Selection& thePath,
156                 const ModelHighAPI_Selection& theBiNoramal)
157 {
158   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Pipe::ID());
159   return PipePtr(new FeaturesAPI_Pipe(aFeature, theBaseObjects, thePath, theBiNoramal));
160 }
161
162 //==================================================================================================
163 PipePtr addPipe(const std::shared_ptr<ModelAPI_Document>& thePart,
164                 const std::list<ModelHighAPI_Selection>& theBaseObjects,
165                 const ModelHighAPI_Selection& thePath,
166                 const std::list<ModelHighAPI_Selection>& theLocations)
167 {
168   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Pipe::ID());
169   return PipePtr(new FeaturesAPI_Pipe(aFeature, theBaseObjects, thePath, theLocations));
170 }