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