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