Salome HOME
Update copyrights
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_RevolutionBoolean.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
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   }
162
163   AttributeSelectionListPtr anAttrBoolObjects =
164     aBase->selectionList(FeaturesPlugin_CompositeBoolean::OBJECTS_ID());
165   theDumper << ", " << anAttrBoolObjects << ")" << std::endl;
166
167   if(anAttrSketch->isInitialized()) {
168     theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
169   }
170 }
171
172 //==================================================================================================
173 void FeaturesAPI_RevolutionBoolean::execIfBaseNotEmpty()
174 {
175   if(mybaseObjects->size() > 0) {
176     execute();
177   }
178 }
179
180 //==================================================================================================
181 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
182   const std::shared_ptr<ModelAPI_Feature>& theFeature)
183 : FeaturesAPI_RevolutionBoolean(theFeature)
184 {
185   initialize();
186 }
187
188 //==================================================================================================
189 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
190   const std::shared_ptr<ModelAPI_Feature>& theFeature,
191   const std::list<ModelHighAPI_Selection>& theBaseObjects,
192   const ModelHighAPI_Selection& theAxis,
193   const ModelHighAPI_Double& theSize,
194   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
195 : FeaturesAPI_RevolutionBoolean(theFeature)
196 {
197   if(initialize()) {
198     fillAttribute(theBaseObjects, mybaseObjects);
199     fillAttribute(theAxis, myaxis);
200     setAngle(theSize);
201     setBooleanObjects(theBooleanObjects);
202   }
203 }
204
205 //==================================================================================================
206 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
207   const std::shared_ptr<ModelAPI_Feature>& theFeature,
208   const std::list<ModelHighAPI_Selection>& theBaseObjects,
209   const ModelHighAPI_Selection& theAxis,
210   const ModelHighAPI_Double& theToAngle,
211   const ModelHighAPI_Double& theFromAngle,
212   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
213 : FeaturesAPI_RevolutionBoolean(theFeature)
214 {
215   if(initialize()) {
216     fillAttribute(theBaseObjects, mybaseObjects);
217     fillAttribute(theAxis, myaxis);
218     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
219     fillAttribute(theToAngle, mytoAngle);
220     fillAttribute(theFromAngle, myfromAngle);
221     setBooleanObjects(theBooleanObjects);
222   }
223 }
224
225 //==================================================================================================
226 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
227   const std::shared_ptr<ModelAPI_Feature>& theFeature,
228   const std::list<ModelHighAPI_Selection>& theBaseObjects,
229   const ModelHighAPI_Selection& theAxis,
230   const ModelHighAPI_Selection& theToObject,
231   const ModelHighAPI_Double& theToOffset,
232   const ModelHighAPI_Selection& theFromObject,
233   const ModelHighAPI_Double& theFromOffset,
234   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
235 : FeaturesAPI_RevolutionBoolean(theFeature)
236 {
237   if(initialize()) {
238     fillAttribute(theBaseObjects, mybaseObjects);
239     fillAttribute(theAxis, myaxis);
240     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
241     fillAttribute(theToObject, mytoObject);
242     fillAttribute(theToOffset, mytoOffset);
243     fillAttribute(theFromObject, myfromObject);
244     fillAttribute(theFromOffset, myfromOffset);
245     setBooleanObjects(theBooleanObjects);
246   }
247 }
248
249 //==================================================================================================
250 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
251                                   const std::list<ModelHighAPI_Selection>& theBaseObjects,
252                                   const ModelHighAPI_Selection& theAxis,
253                                   const ModelHighAPI_Double& theSize,
254                                   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
255 {
256   std::shared_ptr<ModelAPI_Feature> aFeature =
257     thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
258   return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature, theBaseObjects,
259                                                         theAxis, theSize, theBooleanObjects));
260 }
261
262 //==================================================================================================
263 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
264                                   const std::list<ModelHighAPI_Selection>& theBaseObjects,
265                                   const ModelHighAPI_Selection& theAxis,
266                                   const ModelHighAPI_Double& theToAngle,
267                                   const ModelHighAPI_Double& theFromAngle,
268                                   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
269 {
270   std::shared_ptr<ModelAPI_Feature> aFeature =
271     thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
272   return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
273                                                       theBaseObjects,
274                                                       theAxis,
275                                                       theToAngle,
276                                                       theFromAngle,
277                                                       theBooleanObjects));
278 }
279
280 //==================================================================================================
281 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
282                                   const std::list<ModelHighAPI_Selection>& theBaseObjects,
283                                   const ModelHighAPI_Selection& theAxis,
284                                   const ModelHighAPI_Selection& theToObject,
285                                   const ModelHighAPI_Double& theToOffset,
286                                   const ModelHighAPI_Selection& theFromObject,
287                                   const ModelHighAPI_Double& theFromOffset,
288                                   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
289 {
290   std::shared_ptr<ModelAPI_Feature> aFeature =
291     thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
292   return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
293                                                       theBaseObjects,
294                                                       theAxis,
295                                                       theToObject,
296                                                       theToOffset,
297                                                       theFromObject,
298                                                       theFromOffset,
299                                                       theBooleanObjects));
300 }
301
302
303 //==================================================================================================
304 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
305   const std::shared_ptr<ModelAPI_Feature>& theFeature)
306 : FeaturesAPI_RevolutionBoolean(theFeature)
307 {
308   initialize();
309 }
310
311 //==================================================================================================
312 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
313   const std::shared_ptr<ModelAPI_Feature>& theFeature,
314   const std::list<ModelHighAPI_Selection>& theBaseObjects,
315   const ModelHighAPI_Selection& theAxis,
316   const ModelHighAPI_Double& theSize,
317   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
318 : FeaturesAPI_RevolutionBoolean(theFeature)
319 {
320   if(initialize()) {
321     fillAttribute(theBaseObjects, mybaseObjects);
322     fillAttribute(theAxis, myaxis);
323     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
324     fillAttribute(theSize, mytoAngle);
325     fillAttribute(ModelHighAPI_Double(), myfromAngle);
326     setBooleanObjects(theBooleanObjects);
327   }
328 }
329
330 //==================================================================================================
331 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
332   const std::shared_ptr<ModelAPI_Feature>& theFeature,
333   const std::list<ModelHighAPI_Selection>& theBaseObjects,
334   const ModelHighAPI_Selection& theAxis,
335   const ModelHighAPI_Double& theToAngle,
336   const ModelHighAPI_Double& theFromAngle,
337   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
338 : FeaturesAPI_RevolutionBoolean(theFeature)
339 {
340   if(initialize()) {
341     fillAttribute(theBaseObjects, mybaseObjects);
342     fillAttribute(theAxis, myaxis);
343     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
344     fillAttribute(theToAngle, mytoAngle);
345     fillAttribute(theFromAngle, myfromAngle);
346     setBooleanObjects(theBooleanObjects);
347   }
348 }
349
350 //==================================================================================================
351 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
352   const std::shared_ptr<ModelAPI_Feature>& theFeature,
353   const std::list<ModelHighAPI_Selection>& theBaseObjects,
354   const ModelHighAPI_Selection& theAxis,
355   const ModelHighAPI_Selection& theToObject,
356   const ModelHighAPI_Double& theToOffset,
357   const ModelHighAPI_Selection& theFromObject,
358   const ModelHighAPI_Double& theFromOffset,
359   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
360 : FeaturesAPI_RevolutionBoolean(theFeature)
361 {
362   if(initialize()) {
363     fillAttribute(theBaseObjects, mybaseObjects);
364     fillAttribute(theAxis, myaxis);
365     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
366     fillAttribute(theToObject, mytoObject);
367     fillAttribute(theToOffset, mytoOffset);
368     fillAttribute(theFromObject, myfromObject);
369     fillAttribute(theFromOffset, myfromOffset);
370     setBooleanObjects(theBooleanObjects);
371   }
372 }
373
374 //==================================================================================================
375 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
376                                     const std::list<ModelHighAPI_Selection>& theBaseObjects,
377                                     const ModelHighAPI_Selection& theAxis,
378                                     const ModelHighAPI_Double& theSize,
379                                     const std::list<ModelHighAPI_Selection>& theBooleanObjects)
380 {
381   std::shared_ptr<ModelAPI_Feature> aFeature =
382     thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
383   return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature, theBaseObjects,
384                                                           theAxis, theSize, theBooleanObjects));
385 }
386
387 //==================================================================================================
388 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
389                                     const std::list<ModelHighAPI_Selection>& theBaseObjects,
390                                     const ModelHighAPI_Selection& theAxis,
391                                     const ModelHighAPI_Double& theToAngle,
392                                     const ModelHighAPI_Double& theFromAngle,
393                                     const std::list<ModelHighAPI_Selection>& theBooleanObjects)
394 {
395   std::shared_ptr<ModelAPI_Feature> aFeature =
396     thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
397   return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,
398                                                         theBaseObjects,
399                                                         theAxis,
400                                                         theToAngle,
401                                                         theFromAngle,
402                                                         theBooleanObjects));
403 }
404
405 //==================================================================================================
406 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
407                                     const std::list<ModelHighAPI_Selection>& theBaseObjects,
408                                     const ModelHighAPI_Selection& theAxis,
409                                     const ModelHighAPI_Selection& theToObject,
410                                     const ModelHighAPI_Double& theToOffset,
411                                     const ModelHighAPI_Selection& theFromObject,
412                                     const ModelHighAPI_Double& theFromOffset,
413                                     const std::list<ModelHighAPI_Selection>& theBooleanObjects)
414 {
415   std::shared_ptr<ModelAPI_Feature> aFeature =
416     thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
417   return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,
418                                                         theBaseObjects,
419                                                         theAxis,
420                                                         theToObject,
421                                                         theToOffset,
422                                                         theFromObject,
423                                                         theFromOffset,
424                                                         theBooleanObjects));
425 }