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