Salome HOME
Revert insufficient changes to avoid compilation error on Linux
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_RevolutionBoolean.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        FeaturesAPI_RevolutionBoolean.cpp
4 // Created:     09 June 2016
5 // Author:      Dmitry Bobylev
6
7 #include "FeaturesAPI_RevolutionBoolean.h"
8
9 #include <ModelHighAPI_Double.h>
10 #include <ModelHighAPI_Dumper.h>
11 #include <ModelHighAPI_Reference.h>
12 #include <ModelHighAPI_Tools.h>
13
14 //==================================================================================================
15 FeaturesAPI_RevolutionBoolean::FeaturesAPI_RevolutionBoolean(const std::shared_ptr<ModelAPI_Feature>& theFeature)
16 : ModelHighAPI_Interface(theFeature)
17 {
18 }
19
20 //==================================================================================================
21 FeaturesAPI_RevolutionBoolean::~FeaturesAPI_RevolutionBoolean()
22 {
23 }
24
25 //==================================================================================================
26 void FeaturesAPI_RevolutionBoolean::setNestedSketch(const ModelHighAPI_Reference& theSketch)
27 {
28   mysketch->setValue(theSketch.feature());
29   mybaseObjects->clear();
30   mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
31
32   execIfBaseNotEmpty();
33 }
34
35 //==================================================================================================
36 void FeaturesAPI_RevolutionBoolean::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
37 {
38   mysketch->setValue(ObjectPtr());
39   mybaseObjects->clear();
40   fillAttribute(theBaseObjects, mybaseObjects);
41
42   execIfBaseNotEmpty();
43 }
44
45 //==================================================================================================
46 void FeaturesAPI_RevolutionBoolean::setAxis(const ModelHighAPI_Selection& theAxis)
47 {
48   fillAttribute(theAxis, myaxis);
49
50   execIfBaseNotEmpty();
51 }
52
53 //==================================================================================================
54 void FeaturesAPI_RevolutionBoolean::setAngles(const ModelHighAPI_Double& theToAngle,
55                                               const ModelHighAPI_Double& theFromAngle)
56 {
57   fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
58   fillAttribute(theToAngle, mytoAngle);
59   fillAttribute(theFromAngle, myfromAngle);
60
61   execIfBaseNotEmpty();
62 }
63
64 //==================================================================================================
65 void FeaturesAPI_RevolutionBoolean::setAngle(const ModelHighAPI_Double& theAngle)
66 {
67   fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
68   fillAttribute(theAngle, mytoAngle);
69   fillAttribute(ModelHighAPI_Double(), myfromAngle);
70
71   execIfBaseNotEmpty();
72 }
73
74 //==================================================================================================
75 void FeaturesAPI_RevolutionBoolean::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
76                                                         const ModelHighAPI_Double& theToOffset,
77                                                         const ModelHighAPI_Selection& theFromObject,
78                                                         const ModelHighAPI_Double& theFromOffset)
79 {
80   fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
81   fillAttribute(theToObject, mytoObject);
82   fillAttribute(theToOffset, mytoOffset);
83   fillAttribute(theFromObject, myfromObject);
84   fillAttribute(theFromOffset, myfromOffset);
85
86   execIfBaseNotEmpty();
87 }
88
89 //==================================================================================================
90 void FeaturesAPI_RevolutionBoolean::setBooleanObjects(const std::list<ModelHighAPI_Selection>& theBooleanObjects)
91 {
92   fillAttribute(theBooleanObjects, mybooleanObjects);
93
94   execIfBaseNotEmpty();
95 }
96
97 //==================================================================================================
98 void FeaturesAPI_RevolutionBoolean::dump(ModelHighAPI_Dumper& theDumper) const
99 {
100   FeaturePtr aBase = feature();
101   const std::string& aDocName = theDumper.name(aBase->document());
102
103   AttributeReferencePtr anAttrSketch = aBase->reference(FeaturesPlugin_Revolution::SKETCH_ID());
104   AttributeSelectionListPtr anAttrObjects = aBase->selectionList(FeaturesPlugin_Revolution::BASE_OBJECTS_ID());
105   AttributeSelectionPtr anAttrAxis = aBase->selection(FeaturesPlugin_Revolution::AXIS_OBJECT_ID());
106
107   theDumper << aBase << " = model.addRevolution";
108   if(aBase->getKind() == FeaturesPlugin_RevolutionCut::ID()) {
109     theDumper << "Cut";
110   } else if(aBase->getKind() == FeaturesPlugin_RevolutionFuse::ID()) {
111     theDumper << "Fuse";
112   }
113   theDumper << "(" << aDocName << ", ";
114   anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
115   theDumper << ", " << anAttrAxis;
116
117   std::string aCreationMethod = aBase->string(FeaturesPlugin_Revolution::CREATION_METHOD())->value();
118
119   if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES()) {
120     AttributeDoublePtr anAttrToAngle = aBase->real(FeaturesPlugin_Revolution::TO_ANGLE_ID());
121     AttributeDoublePtr anAttrFromAngle = aBase->real(FeaturesPlugin_Revolution::FROM_ANGLE_ID());
122
123     theDumper << ", " << anAttrToAngle << ", " << anAttrFromAngle;
124   } else if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES()) {
125     AttributeSelectionPtr anAttrToObject = aBase->selection(FeaturesPlugin_Revolution::TO_OBJECT_ID());
126     AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Revolution::TO_OFFSET_ID());
127     AttributeSelectionPtr anAttrFromObject = aBase->selection(FeaturesPlugin_Revolution::FROM_OBJECT_ID());
128     AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Revolution::FROM_OFFSET_ID());
129
130     theDumper << ", " << anAttrToObject << ", " << anAttrToOffset << ", " << anAttrFromObject << ", " << anAttrFromOffset;
131   }
132
133   AttributeSelectionListPtr anAttrBoolObjects = aBase->selectionList(FeaturesPlugin_CompositeBoolean::OBJECTS_ID());
134   theDumper << ", " << anAttrBoolObjects << ")" << std::endl;
135
136   if(anAttrSketch->isInitialized()) {
137     theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
138   }
139 }
140
141 //==================================================================================================
142 void FeaturesAPI_RevolutionBoolean::execIfBaseNotEmpty()
143 {
144   if(mybaseObjects->size() > 0) {
145     execute();
146   }
147 }
148
149 //==================================================================================================
150 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(const std::shared_ptr<ModelAPI_Feature>& theFeature)
151 : FeaturesAPI_RevolutionBoolean(theFeature)
152 {
153   initialize();
154 }
155
156 //==================================================================================================
157 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(const std::shared_ptr<ModelAPI_Feature>& theFeature,
158                                                      const std::list<ModelHighAPI_Selection>& theBaseObjects,
159                                                      const ModelHighAPI_Selection& theAxis,
160                                                      const ModelHighAPI_Double& theSize,
161                                                      const std::list<ModelHighAPI_Selection>& theBooleanObjects)
162 : FeaturesAPI_RevolutionBoolean(theFeature)
163 {
164   if(initialize()) {
165     fillAttribute(theBaseObjects, mybaseObjects);
166     fillAttribute(theAxis, myaxis);
167     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
168     fillAttribute(theSize, mytoAngle);
169     fillAttribute(ModelHighAPI_Double(), myfromAngle);
170     setBooleanObjects(theBooleanObjects);
171   }
172 }
173
174 //==================================================================================================
175 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(const std::shared_ptr<ModelAPI_Feature>& theFeature,
176                                                      const std::list<ModelHighAPI_Selection>& theBaseObjects,
177                                                      const ModelHighAPI_Selection& theAxis,
178                                                      const ModelHighAPI_Double& theToAngle,
179                                                      const ModelHighAPI_Double& theFromAngle,
180                                                      const std::list<ModelHighAPI_Selection>& theBooleanObjects)
181 : FeaturesAPI_RevolutionBoolean(theFeature)
182 {
183   if(initialize()) {
184     fillAttribute(theBaseObjects, mybaseObjects);
185     fillAttribute(theAxis, myaxis);
186     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
187     fillAttribute(theToAngle, mytoAngle);
188     fillAttribute(theFromAngle, myfromAngle);
189     setBooleanObjects(theBooleanObjects);
190   }
191 }
192
193 //==================================================================================================
194 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(const std::shared_ptr<ModelAPI_Feature>& theFeature,
195                                                      const std::list<ModelHighAPI_Selection>& theBaseObjects,
196                                                      const ModelHighAPI_Selection& theAxis,
197                                                      const ModelHighAPI_Selection& theToObject,
198                                                      const ModelHighAPI_Double& theToOffset,
199                                                      const ModelHighAPI_Selection& theFromObject,
200                                                      const ModelHighAPI_Double& theFromOffset,
201                                                      const std::list<ModelHighAPI_Selection>& theBooleanObjects)
202 : FeaturesAPI_RevolutionBoolean(theFeature)
203 {
204   if(initialize()) {
205     fillAttribute(theBaseObjects, mybaseObjects);
206     fillAttribute(theAxis, myaxis);
207     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
208     fillAttribute(theToObject, mytoObject);
209     fillAttribute(theToOffset, mytoOffset);
210     fillAttribute(theFromObject, myfromObject);
211     fillAttribute(theFromOffset, myfromOffset);
212     setBooleanObjects(theBooleanObjects);
213   }
214 }
215
216 //==================================================================================================
217 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
218                                   const std::list<ModelHighAPI_Selection>& theBaseObjects,
219                                   const ModelHighAPI_Selection& theAxis,
220                                   const ModelHighAPI_Double& theSize,
221                                   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
222 {
223   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
224   return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature, theBaseObjects, theAxis, theSize, theBooleanObjects));
225 }
226
227 //==================================================================================================
228 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
229                                   const std::list<ModelHighAPI_Selection>& theBaseObjects,
230                                   const ModelHighAPI_Selection& theAxis,
231                                   const ModelHighAPI_Double& theToAngle,
232                                   const ModelHighAPI_Double& theFromAngle,
233                                   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
234 {
235   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
236   return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
237                                                       theBaseObjects,
238                                                       theAxis,
239                                                       theToAngle,
240                                                       theFromAngle,
241                                                       theBooleanObjects));
242 }
243
244 //==================================================================================================
245 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
246                                   const std::list<ModelHighAPI_Selection>& theBaseObjects,
247                                   const ModelHighAPI_Selection& theAxis,
248                                   const ModelHighAPI_Selection& theToObject,
249                                   const ModelHighAPI_Double& theToOffset,
250                                   const ModelHighAPI_Selection& theFromObject,
251                                   const ModelHighAPI_Double& theFromOffset,
252                                   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
253 {
254   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
255   return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
256                                                       theBaseObjects,
257                                                       theAxis,
258                                                       theToObject,
259                                                       theToOffset,
260                                                       theFromObject,
261                                                       theFromOffset,
262                                                       theBooleanObjects));
263 }
264
265
266 //==================================================================================================
267 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(const std::shared_ptr<ModelAPI_Feature>& theFeature)
268 : FeaturesAPI_RevolutionBoolean(theFeature)
269 {
270   initialize();
271 }
272
273 //==================================================================================================
274 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
275                                                        const std::list<ModelHighAPI_Selection>& theBaseObjects,
276                                                        const ModelHighAPI_Selection& theAxis,
277                                                        const ModelHighAPI_Double& theSize,
278                                                        const std::list<ModelHighAPI_Selection>& theBooleanObjects)
279 : FeaturesAPI_RevolutionBoolean(theFeature)
280 {
281   if(initialize()) {
282     fillAttribute(theBaseObjects, mybaseObjects);
283     fillAttribute(theAxis, myaxis);
284     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
285     fillAttribute(theSize, mytoAngle);
286     fillAttribute(ModelHighAPI_Double(), myfromAngle);
287     setBooleanObjects(theBooleanObjects);
288   }
289 }
290
291 //==================================================================================================
292 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
293                                                        const std::list<ModelHighAPI_Selection>& theBaseObjects,
294                                                        const ModelHighAPI_Selection& theAxis,
295                                                        const ModelHighAPI_Double& theToAngle,
296                                                        const ModelHighAPI_Double& theFromAngle,
297                                                        const std::list<ModelHighAPI_Selection>& theBooleanObjects)
298 : FeaturesAPI_RevolutionBoolean(theFeature)
299 {
300   if(initialize()) {
301     fillAttribute(theBaseObjects, mybaseObjects);
302     fillAttribute(theAxis, myaxis);
303     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
304     fillAttribute(theToAngle, mytoAngle);
305     fillAttribute(theFromAngle, myfromAngle);
306     setBooleanObjects(theBooleanObjects);
307   }
308 }
309
310 //==================================================================================================
311 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
312                                                        const std::list<ModelHighAPI_Selection>& theBaseObjects,
313                                                        const ModelHighAPI_Selection& theAxis,
314                                                        const ModelHighAPI_Selection& theToObject,
315                                                        const ModelHighAPI_Double& theToOffset,
316                                                        const ModelHighAPI_Selection& theFromObject,
317                                                        const ModelHighAPI_Double& theFromOffset,
318                                                        const std::list<ModelHighAPI_Selection>& theBooleanObjects)
319 : FeaturesAPI_RevolutionBoolean(theFeature)
320 {
321   if(initialize()) {
322     fillAttribute(theBaseObjects, mybaseObjects);
323     fillAttribute(theAxis, myaxis);
324     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
325     fillAttribute(theToObject, mytoObject);
326     fillAttribute(theToOffset, mytoOffset);
327     fillAttribute(theFromObject, myfromObject);
328     fillAttribute(theFromOffset, myfromOffset);
329     setBooleanObjects(theBooleanObjects);
330   }
331 }
332
333 //==================================================================================================
334 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
335                                     const std::list<ModelHighAPI_Selection>& theBaseObjects,
336                                     const ModelHighAPI_Selection& theAxis,
337                                     const ModelHighAPI_Double& theSize,
338                                     const std::list<ModelHighAPI_Selection>& theBooleanObjects)
339 {
340   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
341   return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature, theBaseObjects, theAxis, theSize, theBooleanObjects));
342 }
343
344 //==================================================================================================
345 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
346                                     const std::list<ModelHighAPI_Selection>& theBaseObjects,
347                                     const ModelHighAPI_Selection& theAxis,
348                                     const ModelHighAPI_Double& theToAngle,
349                                     const ModelHighAPI_Double& theFromAngle,
350                                     const std::list<ModelHighAPI_Selection>& theBooleanObjects)
351 {
352   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
353   return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,
354                                                         theBaseObjects,
355                                                         theAxis,
356                                                         theToAngle,
357                                                         theFromAngle,
358                                                         theBooleanObjects));
359 }
360
361 //==================================================================================================
362 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
363                                     const std::list<ModelHighAPI_Selection>& theBaseObjects,
364                                     const ModelHighAPI_Selection& theAxis,
365                                     const ModelHighAPI_Selection& theToObject,
366                                     const ModelHighAPI_Double& theToOffset,
367                                     const ModelHighAPI_Selection& theFromObject,
368                                     const ModelHighAPI_Double& theFromOffset,
369                                     const std::list<ModelHighAPI_Selection>& theBooleanObjects)
370 {
371   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
372   return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,
373                                                         theBaseObjects,
374                                                         theAxis,
375                                                         theToObject,
376                                                         theToOffset,
377                                                         theFromObject,
378                                                         theFromOffset,
379                                                         theBooleanObjects));
380 }