]> SALOME platform Git repositories - modules/shaper.git/blob - src/FeaturesAPI/FeaturesAPI_Extrusion.cpp
Salome HOME
Issue #1648: Dump Python in the High Level Parameterized Geometry API
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Extrusion.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        FeaturesAPI_Extrusion.cpp
4 // Created:     09 June 2016
5 // Author:      Dmitry Bobylev
6
7 #include "FeaturesAPI_Extrusion.h"
8
9 #include <ModelHighAPI_Double.h>
10 #include <ModelHighAPI_Dumper.h>
11 #include <ModelHighAPI_Tools.h>
12
13 //==================================================================================================
14 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature)
15 : ModelHighAPI_Interface(theFeature)
16 {
17   initialize();
18 }
19
20 //==================================================================================================
21 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
22                                              const std::list<ModelHighAPI_Selection>& theBaseObjects,
23                                              const ModelHighAPI_Double& theSize)
24 : ModelHighAPI_Interface(theFeature)
25 {
26   if(initialize()) {
27     fillAttribute(theBaseObjects, mybaseObjects);
28     setSizes(theSize, ModelHighAPI_Double());
29   }
30 }
31
32 //==================================================================================================
33 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
34                                              const std::list<ModelHighAPI_Selection>& theBaseObjects,
35                                              const ModelHighAPI_Selection& theDirection,
36                                              const ModelHighAPI_Double& theSize)
37 : ModelHighAPI_Interface(theFeature)
38 {
39   if(initialize()) {
40     fillAttribute(theBaseObjects, mybaseObjects);
41     fillAttribute(theDirection, mydirection);
42     setSizes(theSize, ModelHighAPI_Double());
43   }
44 }
45
46 //==================================================================================================
47 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
48                                              const std::list<ModelHighAPI_Selection>& theBaseObjects,
49                                              const ModelHighAPI_Double& theToSize,
50                                              const ModelHighAPI_Double& theFromSize)
51 : ModelHighAPI_Interface(theFeature)
52 {
53   if(initialize()) {
54     fillAttribute(theBaseObjects, mybaseObjects);
55     setSizes(theToSize, theFromSize);
56   }
57 }
58
59 //==================================================================================================
60 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
61                                              const std::list<ModelHighAPI_Selection>& theBaseObjects,
62                                              const ModelHighAPI_Selection& theDirection,
63                                              const ModelHighAPI_Double& theToSize,
64                                              const ModelHighAPI_Double& theFromSize)
65 : ModelHighAPI_Interface(theFeature)
66 {
67   if(initialize()) {
68     fillAttribute(theBaseObjects, mybaseObjects);
69     fillAttribute(theDirection, mydirection);
70     setSizes(theToSize, theFromSize);
71   }
72 }
73
74 //==================================================================================================
75 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
76                                              const std::list<ModelHighAPI_Selection>& theBaseObjects,
77                                              const ModelHighAPI_Selection& theToObject,
78                                              const ModelHighAPI_Double& theToOffset,
79                                              const ModelHighAPI_Selection& theFromObject,
80                                              const ModelHighAPI_Double& theFromOffset)
81 : ModelHighAPI_Interface(theFeature)
82 {
83   if(initialize()) {
84     fillAttribute(theBaseObjects, mybaseObjects);
85     setPlanesAndOffsets(theToObject, theToOffset, theFromObject, theFromOffset);
86   }
87 }
88
89 //==================================================================================================
90 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
91                                              const std::list<ModelHighAPI_Selection>& theBaseObjects,
92                                              const ModelHighAPI_Selection& theDirection,
93                                              const ModelHighAPI_Selection& theToObject,
94                                              const ModelHighAPI_Double& theToOffset,
95                                              const ModelHighAPI_Selection& theFromObject,
96                                              const ModelHighAPI_Double& theFromOffset)
97 : ModelHighAPI_Interface(theFeature)
98 {
99   if(initialize()) {
100     fillAttribute(theBaseObjects, mybaseObjects);
101     fillAttribute(theDirection, mydirection);
102     setPlanesAndOffsets(theToObject, theToOffset, theFromObject, theFromOffset);
103   }
104 }
105
106 //==================================================================================================
107 FeaturesAPI_Extrusion::~FeaturesAPI_Extrusion()
108 {
109
110 }
111
112 //==================================================================================================
113 void FeaturesAPI_Extrusion::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
114 {
115   fillAttribute(theBaseObjects, mybaseObjects);
116
117   execute();
118 }
119
120 //==================================================================================================
121 void FeaturesAPI_Extrusion::setDirection(const ModelHighAPI_Selection& theDirection)
122 {
123   fillAttribute(theDirection, mydirection);
124
125   execute();
126 }
127
128 //==================================================================================================
129 void FeaturesAPI_Extrusion::setSizes(const ModelHighAPI_Double& theToSize,
130                                      const ModelHighAPI_Double& theFromSize)
131 {
132   fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod);
133   fillAttribute(theToSize, mytoSize);
134   fillAttribute(theFromSize, myfromSize);
135
136   execute();
137 }
138
139 //==================================================================================================
140 void FeaturesAPI_Extrusion::setSize(const ModelHighAPI_Double& theSize)
141 {
142   fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod);
143   fillAttribute(theSize, mytoSize);
144   fillAttribute(ModelHighAPI_Double(), myfromSize);
145
146   execute();
147 }
148
149 //==================================================================================================
150 void FeaturesAPI_Extrusion::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
151                                                 const ModelHighAPI_Double& theToOffset,
152                                                 const ModelHighAPI_Selection& theFromObject,
153                                                 const ModelHighAPI_Double& theFromOffset)
154 {
155   fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_PLANES(), mycreationMethod);
156   fillAttribute(theToObject, mytoObject);
157   fillAttribute(theToOffset, mytoOffset);
158   fillAttribute(theFromObject, myfromObject);
159   fillAttribute(theFromOffset, myfromOffset);
160
161   execute();
162 }
163
164 //==================================================================================================
165 void FeaturesAPI_Extrusion::dump(ModelHighAPI_Dumper& theDumper) const
166 {
167   FeaturePtr aBase = feature();
168   const std::string& aDocName = theDumper.name(aBase->document());
169
170   AttributeSelectionListPtr anObjects = aBase->selectionList(FeaturesPlugin_Extrusion::BASE_OBJECTS_ID());
171   AttributeSelectionPtr aDirection = aBase->selection(FeaturesPlugin_Extrusion::DIRECTION_OBJECT_ID());
172
173   theDumper << aBase << " = model.addExtrusion(" << aDocName << ", " << anObjects << ", " << aDirection;
174
175   std::string aCreationMethod = aBase->string(FeaturesPlugin_Extrusion::CREATION_METHOD())->value();
176
177   if(aCreationMethod == FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES()) {
178     AttributeDoublePtr anAttrToSize = aBase->real(FeaturesPlugin_Extrusion::TO_SIZE_ID());
179     AttributeDoublePtr anAttrFromSize = aBase->real(FeaturesPlugin_Extrusion::FROM_SIZE_ID());
180
181     theDumper << ", " << anAttrToSize << ", " << anAttrFromSize;
182   } else if(aCreationMethod == FeaturesPlugin_Extrusion::CREATION_METHOD_BY_PLANES()) {
183     AttributeSelectionPtr anAttrToObject = aBase->selection(FeaturesPlugin_Extrusion::TO_OBJECT_ID());
184     AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Extrusion::TO_OFFSET_ID());
185     AttributeSelectionPtr anAttrFromObject = aBase->selection(FeaturesPlugin_Extrusion::FROM_OBJECT_ID());
186     AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Extrusion::FROM_OFFSET_ID());
187
188     theDumper << ", " << anAttrToObject << ", " << anAttrToOffset << ", " << anAttrFromObject << ", " << anAttrFromOffset;
189   }
190
191   theDumper << ")" << std::endl;
192 }
193
194 //==================================================================================================
195 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
196                           const std::list<ModelHighAPI_Selection>& theBaseObjects,
197                           const ModelHighAPI_Double& theSize)
198 {
199   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
200   return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theSize));
201 }
202
203 //==================================================================================================
204 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
205                           const std::list<ModelHighAPI_Selection>& theBaseObjects,
206                           const ModelHighAPI_Selection& theDirection,
207                           const ModelHighAPI_Double& theSize)
208 {
209   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
210   return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theDirection, theSize));
211 }
212
213 //==================================================================================================
214 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
215                           const std::list<ModelHighAPI_Selection>& theBaseObjects,
216                           const ModelHighAPI_Double& theToSize,
217                           const ModelHighAPI_Double& theFromSize)
218 {
219   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
220   return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theToSize, theFromSize));
221 }
222
223 //==================================================================================================
224 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
225                           const std::list<ModelHighAPI_Selection>& theBaseObjects,
226                           const ModelHighAPI_Selection& theDirection,
227                           const ModelHighAPI_Double& theToSize,
228                           const ModelHighAPI_Double& theFromSize)
229 {
230   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
231   return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,
232                                                 theBaseObjects,
233                                                 theDirection,
234                                                 theToSize,
235                                                 theFromSize));
236 }
237
238 //==================================================================================================
239 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
240                           const std::list<ModelHighAPI_Selection>& theBaseObjects,
241                           const ModelHighAPI_Selection& theToObject,
242                           const ModelHighAPI_Double& theToOffset,
243                           const ModelHighAPI_Selection& theFromObject,
244                           const ModelHighAPI_Double& theFromOffset)
245 {
246   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
247   return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,
248                                                 theBaseObjects,
249                                                 theToObject,
250                                                 theToOffset,
251                                                 theFromObject,
252                                                 theFromOffset));
253 }
254
255 //==================================================================================================
256 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
257                           const std::list<ModelHighAPI_Selection>& theBaseObjects,
258                           const ModelHighAPI_Selection& theDirection,
259                           const ModelHighAPI_Selection& theToObject,
260                           const ModelHighAPI_Double& theToOffset,
261                           const ModelHighAPI_Selection& theFromObject,
262                           const ModelHighAPI_Double& theFromOffset)
263 {
264   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
265   return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,
266                                                 theBaseObjects,
267                                                 theDirection,
268                                                 theToObject,
269                                                 theToOffset,
270                                                 theFromObject,
271                                                 theFromOffset));
272 }