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