]> SALOME platform Git repositories - modules/shaper.git/blob - src/FeaturesAPI/FeaturesAPI_RevolutionBoolean.cpp
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 email : webmaster.salome@opencascade.com<mailto: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   fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
92   fillAttribute(theAngle, mytoAngle);
93   fillAttribute(ModelHighAPI_Double(), myfromAngle);
94
95   execIfBaseNotEmpty();
96 }
97
98 //==================================================================================================
99 void FeaturesAPI_RevolutionBoolean::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
100                                                         const ModelHighAPI_Double& theToOffset,
101                                                       const ModelHighAPI_Selection& theFromObject,
102                                                         const ModelHighAPI_Double& theFromOffset)
103 {
104   fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
105   fillAttribute(theToObject, mytoObject);
106   fillAttribute(theToOffset, mytoOffset);
107   fillAttribute(theFromObject, myfromObject);
108   fillAttribute(theFromOffset, myfromOffset);
109
110   execIfBaseNotEmpty();
111 }
112
113 //==================================================================================================
114 void FeaturesAPI_RevolutionBoolean::setBooleanObjects(
115   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
116 {
117   fillAttribute(theBooleanObjects, mybooleanObjects);
118
119   execIfBaseNotEmpty();
120 }
121
122 //==================================================================================================
123 void FeaturesAPI_RevolutionBoolean::dump(ModelHighAPI_Dumper& theDumper) const
124 {
125   FeaturePtr aBase = feature();
126   const std::string& aDocName = theDumper.name(aBase->document());
127
128   AttributeReferencePtr anAttrSketch =
129     aBase->reference(FeaturesPlugin_Revolution::SKETCH_ID());
130   AttributeSelectionListPtr anAttrObjects =
131     aBase->selectionList(FeaturesPlugin_Revolution::BASE_OBJECTS_ID());
132   AttributeSelectionPtr anAttrAxis =
133     aBase->selection(FeaturesPlugin_Revolution::AXIS_OBJECT_ID());
134
135   theDumper << aBase << " = model.addRevolution";
136   if(aBase->getKind() == FeaturesPlugin_RevolutionCut::ID()) {
137     theDumper << "Cut";
138   } else if(aBase->getKind() == FeaturesPlugin_RevolutionFuse::ID()) {
139     theDumper << "Fuse";
140   }
141   theDumper << "(" << aDocName << ", ";
142   anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
143   theDumper << ", " << anAttrAxis;
144
145   std::string aCreationMethod =
146     aBase->string(FeaturesPlugin_Revolution::CREATION_METHOD())->value();
147
148   if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES()) {
149     AttributeDoublePtr anAttrToAngle = aBase->real(FeaturesPlugin_Revolution::TO_ANGLE_ID());
150     AttributeDoublePtr anAttrFromAngle = aBase->real(FeaturesPlugin_Revolution::FROM_ANGLE_ID());
151
152     theDumper << ", " << anAttrToAngle << ", " << anAttrFromAngle;
153   } else if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES()) {
154     AttributeSelectionPtr anAttrToObject =
155       aBase->selection(FeaturesPlugin_Revolution::TO_OBJECT_ID());
156     AttributeDoublePtr anAttrToOffset =
157       aBase->real(FeaturesPlugin_Revolution::TO_OFFSET_ID());
158     AttributeSelectionPtr anAttrFromObject =
159       aBase->selection(FeaturesPlugin_Revolution::FROM_OBJECT_ID());
160     AttributeDoublePtr anAttrFromOffset =
161       aBase->real(FeaturesPlugin_Revolution::FROM_OFFSET_ID());
162
163     theDumper << ", " << anAttrToObject << ", " << anAttrToOffset <<
164       ", " << anAttrFromObject << ", " << anAttrFromOffset;
165   }
166
167   AttributeSelectionListPtr anAttrBoolObjects =
168     aBase->selectionList(FeaturesPlugin_CompositeBoolean::OBJECTS_ID());
169   theDumper << ", " << anAttrBoolObjects << ")" << std::endl;
170
171   if(anAttrSketch->isInitialized()) {
172     theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
173   }
174 }
175
176 //==================================================================================================
177 void FeaturesAPI_RevolutionBoolean::execIfBaseNotEmpty()
178 {
179   if(mybaseObjects->size() > 0) {
180     execute();
181   }
182 }
183
184 //==================================================================================================
185 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
186   const std::shared_ptr<ModelAPI_Feature>& theFeature)
187 : FeaturesAPI_RevolutionBoolean(theFeature)
188 {
189   initialize();
190 }
191
192 //==================================================================================================
193 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
194   const std::shared_ptr<ModelAPI_Feature>& theFeature,
195   const std::list<ModelHighAPI_Selection>& theBaseObjects,
196   const ModelHighAPI_Selection& theAxis,
197   const ModelHighAPI_Double& theSize,
198   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
199 : FeaturesAPI_RevolutionBoolean(theFeature)
200 {
201   if(initialize()) {
202     fillAttribute(theBaseObjects, mybaseObjects);
203     fillAttribute(theAxis, myaxis);
204     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
205     fillAttribute(theSize, mytoAngle);
206     fillAttribute(ModelHighAPI_Double(), myfromAngle);
207     setBooleanObjects(theBooleanObjects);
208   }
209 }
210
211 //==================================================================================================
212 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
213   const std::shared_ptr<ModelAPI_Feature>& theFeature,
214   const std::list<ModelHighAPI_Selection>& theBaseObjects,
215   const ModelHighAPI_Selection& theAxis,
216   const ModelHighAPI_Double& theToAngle,
217   const ModelHighAPI_Double& theFromAngle,
218   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
219 : FeaturesAPI_RevolutionBoolean(theFeature)
220 {
221   if(initialize()) {
222     fillAttribute(theBaseObjects, mybaseObjects);
223     fillAttribute(theAxis, myaxis);
224     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
225     fillAttribute(theToAngle, mytoAngle);
226     fillAttribute(theFromAngle, myfromAngle);
227     setBooleanObjects(theBooleanObjects);
228   }
229 }
230
231 //==================================================================================================
232 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
233   const std::shared_ptr<ModelAPI_Feature>& theFeature,
234   const std::list<ModelHighAPI_Selection>& theBaseObjects,
235   const ModelHighAPI_Selection& theAxis,
236   const ModelHighAPI_Selection& theToObject,
237   const ModelHighAPI_Double& theToOffset,
238   const ModelHighAPI_Selection& theFromObject,
239   const ModelHighAPI_Double& theFromOffset,
240   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
241 : FeaturesAPI_RevolutionBoolean(theFeature)
242 {
243   if(initialize()) {
244     fillAttribute(theBaseObjects, mybaseObjects);
245     fillAttribute(theAxis, myaxis);
246     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
247     fillAttribute(theToObject, mytoObject);
248     fillAttribute(theToOffset, mytoOffset);
249     fillAttribute(theFromObject, myfromObject);
250     fillAttribute(theFromOffset, myfromOffset);
251     setBooleanObjects(theBooleanObjects);
252   }
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& theSize,
260                                   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
261 {
262   std::shared_ptr<ModelAPI_Feature> aFeature =
263     thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
264   return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature, theBaseObjects,
265                                                         theAxis, theSize, theBooleanObjects));
266 }
267
268 //==================================================================================================
269 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
270                                   const std::list<ModelHighAPI_Selection>& theBaseObjects,
271                                   const ModelHighAPI_Selection& theAxis,
272                                   const ModelHighAPI_Double& theToAngle,
273                                   const ModelHighAPI_Double& theFromAngle,
274                                   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
275 {
276   std::shared_ptr<ModelAPI_Feature> aFeature =
277     thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
278   return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
279                                                       theBaseObjects,
280                                                       theAxis,
281                                                       theToAngle,
282                                                       theFromAngle,
283                                                       theBooleanObjects));
284 }
285
286 //==================================================================================================
287 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
288                                   const std::list<ModelHighAPI_Selection>& theBaseObjects,
289                                   const ModelHighAPI_Selection& theAxis,
290                                   const ModelHighAPI_Selection& theToObject,
291                                   const ModelHighAPI_Double& theToOffset,
292                                   const ModelHighAPI_Selection& theFromObject,
293                                   const ModelHighAPI_Double& theFromOffset,
294                                   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
295 {
296   std::shared_ptr<ModelAPI_Feature> aFeature =
297     thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
298   return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
299                                                       theBaseObjects,
300                                                       theAxis,
301                                                       theToObject,
302                                                       theToOffset,
303                                                       theFromObject,
304                                                       theFromOffset,
305                                                       theBooleanObjects));
306 }
307
308
309 //==================================================================================================
310 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
311   const std::shared_ptr<ModelAPI_Feature>& theFeature)
312 : FeaturesAPI_RevolutionBoolean(theFeature)
313 {
314   initialize();
315 }
316
317 //==================================================================================================
318 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
319   const std::shared_ptr<ModelAPI_Feature>& theFeature,
320   const std::list<ModelHighAPI_Selection>& theBaseObjects,
321   const ModelHighAPI_Selection& theAxis,
322   const ModelHighAPI_Double& theSize,
323   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
324 : FeaturesAPI_RevolutionBoolean(theFeature)
325 {
326   if(initialize()) {
327     fillAttribute(theBaseObjects, mybaseObjects);
328     fillAttribute(theAxis, myaxis);
329     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
330     fillAttribute(theSize, mytoAngle);
331     fillAttribute(ModelHighAPI_Double(), myfromAngle);
332     setBooleanObjects(theBooleanObjects);
333   }
334 }
335
336 //==================================================================================================
337 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
338   const std::shared_ptr<ModelAPI_Feature>& theFeature,
339   const std::list<ModelHighAPI_Selection>& theBaseObjects,
340   const ModelHighAPI_Selection& theAxis,
341   const ModelHighAPI_Double& theToAngle,
342   const ModelHighAPI_Double& theFromAngle,
343   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
344 : FeaturesAPI_RevolutionBoolean(theFeature)
345 {
346   if(initialize()) {
347     fillAttribute(theBaseObjects, mybaseObjects);
348     fillAttribute(theAxis, myaxis);
349     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
350     fillAttribute(theToAngle, mytoAngle);
351     fillAttribute(theFromAngle, myfromAngle);
352     setBooleanObjects(theBooleanObjects);
353   }
354 }
355
356 //==================================================================================================
357 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
358   const std::shared_ptr<ModelAPI_Feature>& theFeature,
359   const std::list<ModelHighAPI_Selection>& theBaseObjects,
360   const ModelHighAPI_Selection& theAxis,
361   const ModelHighAPI_Selection& theToObject,
362   const ModelHighAPI_Double& theToOffset,
363   const ModelHighAPI_Selection& theFromObject,
364   const ModelHighAPI_Double& theFromOffset,
365   const std::list<ModelHighAPI_Selection>& theBooleanObjects)
366 : FeaturesAPI_RevolutionBoolean(theFeature)
367 {
368   if(initialize()) {
369     fillAttribute(theBaseObjects, mybaseObjects);
370     fillAttribute(theAxis, myaxis);
371     fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
372     fillAttribute(theToObject, mytoObject);
373     fillAttribute(theToOffset, mytoOffset);
374     fillAttribute(theFromObject, myfromObject);
375     fillAttribute(theFromOffset, myfromOffset);
376     setBooleanObjects(theBooleanObjects);
377   }
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& theSize,
385                                     const std::list<ModelHighAPI_Selection>& theBooleanObjects)
386 {
387   std::shared_ptr<ModelAPI_Feature> aFeature =
388     thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
389   return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature, theBaseObjects,
390                                                           theAxis, theSize, theBooleanObjects));
391 }
392
393 //==================================================================================================
394 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
395                                     const std::list<ModelHighAPI_Selection>& theBaseObjects,
396                                     const ModelHighAPI_Selection& theAxis,
397                                     const ModelHighAPI_Double& theToAngle,
398                                     const ModelHighAPI_Double& theFromAngle,
399                                     const std::list<ModelHighAPI_Selection>& theBooleanObjects)
400 {
401   std::shared_ptr<ModelAPI_Feature> aFeature =
402     thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
403   return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,
404                                                         theBaseObjects,
405                                                         theAxis,
406                                                         theToAngle,
407                                                         theFromAngle,
408                                                         theBooleanObjects));
409 }
410
411 //==================================================================================================
412 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
413                                     const std::list<ModelHighAPI_Selection>& theBaseObjects,
414                                     const ModelHighAPI_Selection& theAxis,
415                                     const ModelHighAPI_Selection& theToObject,
416                                     const ModelHighAPI_Double& theToOffset,
417                                     const ModelHighAPI_Selection& theFromObject,
418                                     const ModelHighAPI_Double& theFromOffset,
419                                     const std::list<ModelHighAPI_Selection>& theBooleanObjects)
420 {
421   std::shared_ptr<ModelAPI_Feature> aFeature =
422     thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
423   return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,
424                                                         theBaseObjects,
425                                                         theAxis,
426                                                         theToObject,
427                                                         theToOffset,
428                                                         theFromObject,
429                                                         theFromOffset,
430                                                         theBooleanObjects));
431 }