Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_RevolutionBoolean.cpp
1 // Copyright (C) 2014-2023  CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "FeaturesAPI_RevolutionBoolean.h"
21
22 #include <ModelHighAPI_Double.h>
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Reference.h>
25 #include <ModelHighAPI_Tools.h>
26
27 //==================================================================================================
28 FeaturesAPI_RevolutionBoolean::FeaturesAPI_RevolutionBoolean(
29   const std::shared_ptr<ModelAPI_Feature>& theFeature)
30 : ModelHighAPI_Interface(theFeature)
31 {
32 }
33
34 //==================================================================================================
35 FeaturesAPI_RevolutionBoolean::~FeaturesAPI_RevolutionBoolean()
36 {
37 }
38
39 //==================================================================================================
40 void FeaturesAPI_RevolutionBoolean::setNestedSketch(const ModelHighAPI_Reference& theSketch)
41 {
42   mysketch->setValue(theSketch.feature());
43
44   // To make Sketch feature execute and subfeatures execute.
45   feature()->document()->setCurrentFeature(feature(), false);
46
47   // to inform that the history is updated due to the sketch moved under the composite feature
48   if (theSketch.feature().get()) {
49     theSketch.feature()->document()->updateHistory(ModelAPI_Feature::group());
50     if (theSketch.feature()->firstResult().get())
51       theSketch.feature()->firstResult()->setDisplayed(false);
52   }
53   mybaseObjects->clear();
54   mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
55
56   execIfBaseNotEmpty();
57 }
58
59 //==================================================================================================
60 void FeaturesAPI_RevolutionBoolean::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
61 {
62   mysketch->setValue(ObjectPtr());
63   mybaseObjects->clear();
64   fillAttribute(theBaseObjects, mybaseObjects);
65
66   execIfBaseNotEmpty();
67 }
68
69 //==================================================================================================
70 void FeaturesAPI_RevolutionBoolean::setAxis(const ModelHighAPI_Selection& theAxis)
71 {
72   fillAttribute(theAxis, myaxis);
73
74   execIfBaseNotEmpty();
75 }
76
77 //==================================================================================================
78 void FeaturesAPI_RevolutionBoolean::setAngles(const ModelHighAPI_Double& theToAngle,
79                                               const ModelHighAPI_Double& theFromAngle)
80 {
81   fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
82   fillAttribute(theToAngle, mytoAngle);
83   fillAttribute(theFromAngle, myfromAngle);
84
85   execIfBaseNotEmpty();
86 }
87
88 //==================================================================================================
89 void FeaturesAPI_RevolutionBoolean::setAngle(const ModelHighAPI_Double& theAngle)
90 {
91   setAngles(theAngle, ModelHighAPI_Double());
92 }
93
94 //==================================================================================================
95 void FeaturesAPI_RevolutionBoolean::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
96                                                         const ModelHighAPI_Double& theToOffset,
97                                                         const ModelHighAPI_Selection& theFromObject,
98                                                         const ModelHighAPI_Double& theFromOffset)
99 {
100   fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
101   fillAttribute(theToObject, mytoObject);
102   fillAttribute(theToOffset, mytoOffset);
103   fillAttribute(theFromObject, myfromObject);
104   fillAttribute(theFromOffset, myfromOffset);
105
106   execIfBaseNotEmpty();
107 }
108
109 //==================================================================================================
110 void FeaturesAPI_RevolutionBoolean::setBooleanObjects(
111   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
112 {
113   fillAttribute(theBooleanObjects, mybooleanObjects);
114
115   execIfBaseNotEmpty();
116 }
117
118 //==================================================================================================
119 void FeaturesAPI_RevolutionBoolean::dump(ModelHighAPI_Dumper& theDumper) const
120 {
121   FeaturePtr aBase = feature();
122   const std::string& aDocName = theDumper.name(aBase->document());
123
124   AttributeReferencePtr anAttrSketch =
125     aBase->reference(FeaturesPlugin_Revolution::SKETCH_ID());
126   AttributeSelectionListPtr anAttrObjects =
127     aBase->selectionList(FeaturesPlugin_Revolution::BASE_OBJECTS_ID());
128   AttributeSelectionPtr anAttrAxis =
129     aBase->selection(FeaturesPlugin_Revolution::AXIS_OBJECT_ID());
130
131   theDumper << aBase << " = model.addRevolution";
132   if(aBase->getKind() == FeaturesPlugin_RevolutionCut::ID()) {
133     theDumper << "Cut";
134   } else if(aBase->getKind() == FeaturesPlugin_RevolutionFuse::ID()) {
135     theDumper << "Fuse";
136   }
137   theDumper << "(" << aDocName << ", ";
138   anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
139   theDumper << ", " << anAttrAxis;
140
141   std::string aCreationMethod =
142     aBase->string(FeaturesPlugin_Revolution::CREATION_METHOD())->value();
143
144   if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES()) {
145     AttributeDoublePtr anAttrToAngle = aBase->real(FeaturesPlugin_Revolution::TO_ANGLE_ID());
146     AttributeDoublePtr anAttrFromAngle = aBase->real(FeaturesPlugin_Revolution::FROM_ANGLE_ID());
147
148     theDumper << ", " << anAttrToAngle << ", " << anAttrFromAngle;
149   } else if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES()) {
150     AttributeSelectionPtr anAttrToObject =
151       aBase->selection(FeaturesPlugin_Revolution::TO_OBJECT_ID());
152     AttributeDoublePtr anAttrToOffset =
153       aBase->real(FeaturesPlugin_Revolution::TO_OFFSET_ID());
154     AttributeSelectionPtr anAttrFromObject =
155       aBase->selection(FeaturesPlugin_Revolution::FROM_OBJECT_ID());
156     AttributeDoublePtr anAttrFromOffset =
157       aBase->real(FeaturesPlugin_Revolution::FROM_OFFSET_ID());
158
159     theDumper << ", " << anAttrToObject << ", " << anAttrToOffset <<
160       ", " << anAttrFromObject << ", " << anAttrFromOffset;
161   } else {
162     // Through All
163   }
164
165   AttributeSelectionListPtr anAttrBoolObjects =
166     aBase->selectionList(FeaturesPlugin_CompositeBoolean::OBJECTS_ID());
167   theDumper << ", " << anAttrBoolObjects << ")" << std::endl;
168
169   if(anAttrSketch->isInitialized()) {
170     theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
171   }
172 }
173
174 //==================================================================================================
175 void FeaturesAPI_RevolutionBoolean::execIfBaseNotEmpty()
176 {
177   if(mybaseObjects->size() > 0) {
178     execute();
179   }
180 }
181
182 //==================================================================================================
183 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
184   const std::shared_ptr<ModelAPI_Feature>& theFeature)
185 : FeaturesAPI_RevolutionBoolean(theFeature)
186 {
187   initialize();
188 }
189
190 //==================================================================================================
191 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
192   const std::shared_ptr<ModelAPI_Feature>& theFeature,
193   const std::list<ModelHighAPI_Selection>& theBaseObjects,
194   const ModelHighAPI_Selection& theAxis,
195   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
196 : FeaturesAPI_RevolutionBoolean(theFeature)
197 {
198   if(initialize()) {
199     fillAttribute(theBaseObjects, mybaseObjects);
200     fillAttribute(theAxis, myaxis);
201     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_THROUGH_ALL(), mycreationMethod);
202     setBooleanObjects(theBooleanObjects);
203   }
204 }
205
206 //==================================================================================================
207 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
208   const std::shared_ptr<ModelAPI_Feature>& theFeature,
209   const std::list<ModelHighAPI_Selection>& theBaseObjects,
210   const ModelHighAPI_Selection& theAxis,
211   const ModelHighAPI_Double& theSize,
212   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
213 : FeaturesAPI_RevolutionBoolean(theFeature)
214 {
215   if(initialize()) {
216     fillAttribute(theBaseObjects, mybaseObjects);
217     fillAttribute(theAxis, myaxis);
218     setAngle(theSize);
219     setBooleanObjects(theBooleanObjects);
220   }
221 }
222
223 //==================================================================================================
224 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
225   const std::shared_ptr<ModelAPI_Feature>& theFeature,
226   const std::list<ModelHighAPI_Selection>& theBaseObjects,
227   const ModelHighAPI_Selection& theAxis,
228   const ModelHighAPI_Double& theToAngle,
229   const ModelHighAPI_Double& theFromAngle,
230   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
231 : FeaturesAPI_RevolutionBoolean(theFeature)
232 {
233   if(initialize()) {
234     fillAttribute(theBaseObjects, mybaseObjects);
235     fillAttribute(theAxis, myaxis);
236     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
237     fillAttribute(theToAngle, mytoAngle);
238     fillAttribute(theFromAngle, myfromAngle);
239     setBooleanObjects(theBooleanObjects);
240   }
241 }
242
243 //==================================================================================================
244 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
245   const std::shared_ptr<ModelAPI_Feature>& theFeature,
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 : FeaturesAPI_RevolutionBoolean(theFeature)
254 {
255   if(initialize()) {
256     fillAttribute(theBaseObjects, mybaseObjects);
257     fillAttribute(theAxis, myaxis);
258     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
259     fillAttribute(theToObject, mytoObject);
260     fillAttribute(theToOffset, mytoOffset);
261     fillAttribute(theFromObject, myfromObject);
262     fillAttribute(theFromOffset, myfromOffset);
263     setBooleanObjects(theBooleanObjects);
264   }
265 }
266
267 //==================================================================================================
268 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
269                                   const std::list<ModelHighAPI_Selection>& theBaseObjects,
270                                   const ModelHighAPI_Selection& theAxis,
271                                   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
272 {
273   std::shared_ptr<ModelAPI_Feature> aFeature =
274     thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
275   return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature, theBaseObjects,
276                                                         theAxis, theBooleanObjects));
277 }
278
279 //==================================================================================================
280 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
281                                   const std::list<ModelHighAPI_Selection>& theBaseObjects,
282                                   const ModelHighAPI_Selection& theAxis,
283                                   const ModelHighAPI_Double& theSize,
284                                   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
285 {
286   std::shared_ptr<ModelAPI_Feature> aFeature =
287     thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
288   return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature, theBaseObjects,
289                                                         theAxis, theSize, theBooleanObjects));
290 }
291
292 //==================================================================================================
293 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
294                                   const std::list<ModelHighAPI_Selection>& theBaseObjects,
295                                   const ModelHighAPI_Selection& theAxis,
296                                   const ModelHighAPI_Double& theToAngle,
297                                   const ModelHighAPI_Double& theFromAngle,
298                                   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
299 {
300   std::shared_ptr<ModelAPI_Feature> aFeature =
301     thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
302   return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
303                                                       theBaseObjects,
304                                                       theAxis,
305                                                       theToAngle,
306                                                       theFromAngle,
307                                                       theBooleanObjects));
308 }
309
310 //==================================================================================================
311 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
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 {
320   std::shared_ptr<ModelAPI_Feature> aFeature =
321     thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
322   return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
323                                                       theBaseObjects,
324                                                       theAxis,
325                                                       theToObject,
326                                                       theToOffset,
327                                                       theFromObject,
328                                                       theFromOffset,
329                                                       theBooleanObjects));
330 }
331
332
333 //==================================================================================================
334 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
335   const std::shared_ptr<ModelAPI_Feature>& theFeature)
336 : FeaturesAPI_RevolutionBoolean(theFeature)
337 {
338   initialize();
339 }
340
341 //==================================================================================================
342 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
343   const std::shared_ptr<ModelAPI_Feature>& theFeature,
344   const std::list<ModelHighAPI_Selection>& theBaseObjects,
345   const ModelHighAPI_Selection& theAxis,
346   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
347 : FeaturesAPI_RevolutionBoolean(theFeature)
348 {
349   if(initialize()) {
350     fillAttribute(theBaseObjects, mybaseObjects);
351     fillAttribute(theAxis, myaxis);
352     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_THROUGH_ALL(), mycreationMethod);
353     setBooleanObjects(theBooleanObjects);
354   }
355 }
356
357 //==================================================================================================
358 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
359   const std::shared_ptr<ModelAPI_Feature>& theFeature,
360   const std::list<ModelHighAPI_Selection>& theBaseObjects,
361   const ModelHighAPI_Selection& theAxis,
362   const ModelHighAPI_Double& theSize,
363   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
364 : FeaturesAPI_RevolutionBoolean(theFeature)
365 {
366   if(initialize()) {
367     fillAttribute(theBaseObjects, mybaseObjects);
368     fillAttribute(theAxis, myaxis);
369     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
370     fillAttribute(theSize, mytoAngle);
371     fillAttribute(ModelHighAPI_Double(), myfromAngle);
372     setBooleanObjects(theBooleanObjects);
373   }
374 }
375
376 //==================================================================================================
377 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
378   const std::shared_ptr<ModelAPI_Feature>& theFeature,
379   const std::list<ModelHighAPI_Selection>& theBaseObjects,
380   const ModelHighAPI_Selection& theAxis,
381   const ModelHighAPI_Double& theToAngle,
382   const ModelHighAPI_Double& theFromAngle,
383   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
384 : FeaturesAPI_RevolutionBoolean(theFeature)
385 {
386   if(initialize()) {
387     fillAttribute(theBaseObjects, mybaseObjects);
388     fillAttribute(theAxis, myaxis);
389     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
390     fillAttribute(theToAngle, mytoAngle);
391     fillAttribute(theFromAngle, myfromAngle);
392     setBooleanObjects(theBooleanObjects);
393   }
394 }
395
396 //==================================================================================================
397 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
398   const std::shared_ptr<ModelAPI_Feature>& theFeature,
399   const std::list<ModelHighAPI_Selection>& theBaseObjects,
400   const ModelHighAPI_Selection& theAxis,
401   const ModelHighAPI_Selection& theToObject,
402   const ModelHighAPI_Double& theToOffset,
403   const ModelHighAPI_Selection& theFromObject,
404   const ModelHighAPI_Double& theFromOffset,
405   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
406 : FeaturesAPI_RevolutionBoolean(theFeature)
407 {
408   if(initialize()) {
409     fillAttribute(theBaseObjects, mybaseObjects);
410     fillAttribute(theAxis, myaxis);
411     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
412     fillAttribute(theToObject, mytoObject);
413     fillAttribute(theToOffset, mytoOffset);
414     fillAttribute(theFromObject, myfromObject);
415     fillAttribute(theFromOffset, myfromOffset);
416     setBooleanObjects(theBooleanObjects);
417   }
418 }
419
420 //==================================================================================================
421 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
422                                     const std::list<ModelHighAPI_Selection>& theBaseObjects,
423                                     const ModelHighAPI_Selection& theAxis,
424                                     const std::list<ModelHighAPI_Selection>& theBooleanObjects)
425 {
426   std::shared_ptr<ModelAPI_Feature> aFeature =
427     thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
428   return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature, theBaseObjects,
429                                                           theAxis, theBooleanObjects));
430 }
431
432 //==================================================================================================
433 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
434                                     const std::list<ModelHighAPI_Selection>& theBaseObjects,
435                                     const ModelHighAPI_Selection& theAxis,
436                                     const ModelHighAPI_Double& theSize,
437                                     const std::list<ModelHighAPI_Selection>& theBooleanObjects)
438 {
439   std::shared_ptr<ModelAPI_Feature> aFeature =
440     thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
441   return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature, theBaseObjects,
442                                                           theAxis, theSize, theBooleanObjects));
443 }
444
445 //==================================================================================================
446 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
447                                     const std::list<ModelHighAPI_Selection>& theBaseObjects,
448                                     const ModelHighAPI_Selection& theAxis,
449                                     const ModelHighAPI_Double& theToAngle,
450                                     const ModelHighAPI_Double& theFromAngle,
451                                     const std::list<ModelHighAPI_Selection>& theBooleanObjects)
452 {
453   std::shared_ptr<ModelAPI_Feature> aFeature =
454     thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
455   return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,
456                                                         theBaseObjects,
457                                                         theAxis,
458                                                         theToAngle,
459                                                         theFromAngle,
460                                                         theBooleanObjects));
461 }
462
463 //==================================================================================================
464 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
465                                     const std::list<ModelHighAPI_Selection>& theBaseObjects,
466                                     const ModelHighAPI_Selection& theAxis,
467                                     const ModelHighAPI_Selection& theToObject,
468                                     const ModelHighAPI_Double& theToOffset,
469                                     const ModelHighAPI_Selection& theFromObject,
470                                     const ModelHighAPI_Double& theFromOffset,
471                                     const std::list<ModelHighAPI_Selection>& theBooleanObjects)
472 {
473   std::shared_ptr<ModelAPI_Feature> aFeature =
474     thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
475   return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,
476                                                         theBaseObjects,
477                                                         theAxis,
478                                                         theToObject,
479                                                         theToOffset,
480                                                         theFromObject,
481                                                         theFromOffset,
482                                                         theBooleanObjects));
483 }