1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: FeaturesAPI_RevolutionBoolean.cpp
4 // Created: 09 June 2016
5 // Author: Dmitry Bobylev
7 #include "FeaturesAPI_RevolutionBoolean.h"
9 #include <ModelHighAPI_Double.h>
10 #include <ModelHighAPI_Dumper.h>
11 #include <ModelHighAPI_Reference.h>
12 #include <ModelHighAPI_Tools.h>
14 //==================================================================================================
15 FeaturesAPI_RevolutionBoolean::FeaturesAPI_RevolutionBoolean(const std::shared_ptr<ModelAPI_Feature>& theFeature)
16 : ModelHighAPI_Interface(theFeature)
20 //==================================================================================================
21 FeaturesAPI_RevolutionBoolean::~FeaturesAPI_RevolutionBoolean()
25 //==================================================================================================
26 void FeaturesAPI_RevolutionBoolean::setNestedSketch(const ModelHighAPI_Reference& theSketch)
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 mybaseObjects->clear();
33 mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
38 //==================================================================================================
39 void FeaturesAPI_RevolutionBoolean::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
41 mysketch->setValue(ObjectPtr());
42 mybaseObjects->clear();
43 fillAttribute(theBaseObjects, mybaseObjects);
48 //==================================================================================================
49 void FeaturesAPI_RevolutionBoolean::setAxis(const ModelHighAPI_Selection& theAxis)
51 fillAttribute(theAxis, myaxis);
56 //==================================================================================================
57 void FeaturesAPI_RevolutionBoolean::setAngles(const ModelHighAPI_Double& theToAngle,
58 const ModelHighAPI_Double& theFromAngle)
60 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
61 fillAttribute(theToAngle, mytoAngle);
62 fillAttribute(theFromAngle, myfromAngle);
67 //==================================================================================================
68 void FeaturesAPI_RevolutionBoolean::setAngle(const ModelHighAPI_Double& theAngle)
70 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
71 fillAttribute(theAngle, mytoAngle);
72 fillAttribute(ModelHighAPI_Double(), myfromAngle);
77 //==================================================================================================
78 void FeaturesAPI_RevolutionBoolean::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
79 const ModelHighAPI_Double& theToOffset,
80 const ModelHighAPI_Selection& theFromObject,
81 const ModelHighAPI_Double& theFromOffset)
83 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
84 fillAttribute(theToObject, mytoObject);
85 fillAttribute(theToOffset, mytoOffset);
86 fillAttribute(theFromObject, myfromObject);
87 fillAttribute(theFromOffset, myfromOffset);
92 //==================================================================================================
93 void FeaturesAPI_RevolutionBoolean::setBooleanObjects(const std::list<ModelHighAPI_Selection>& theBooleanObjects)
95 fillAttribute(theBooleanObjects, mybooleanObjects);
100 //==================================================================================================
101 void FeaturesAPI_RevolutionBoolean::dump(ModelHighAPI_Dumper& theDumper) const
103 FeaturePtr aBase = feature();
104 const std::string& aDocName = theDumper.name(aBase->document());
106 AttributeReferencePtr anAttrSketch = aBase->reference(FeaturesPlugin_Revolution::SKETCH_ID());
107 AttributeSelectionListPtr anAttrObjects = aBase->selectionList(FeaturesPlugin_Revolution::BASE_OBJECTS_ID());
108 AttributeSelectionPtr anAttrAxis = aBase->selection(FeaturesPlugin_Revolution::AXIS_OBJECT_ID());
110 theDumper << aBase << " = model.addRevolution";
111 if(aBase->getKind() == FeaturesPlugin_RevolutionCut::ID()) {
113 } else if(aBase->getKind() == FeaturesPlugin_RevolutionFuse::ID()) {
116 theDumper << "(" << aDocName << ", ";
117 anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
118 theDumper << ", " << anAttrAxis;
120 std::string aCreationMethod = aBase->string(FeaturesPlugin_Revolution::CREATION_METHOD())->value();
122 if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES()) {
123 AttributeDoublePtr anAttrToAngle = aBase->real(FeaturesPlugin_Revolution::TO_ANGLE_ID());
124 AttributeDoublePtr anAttrFromAngle = aBase->real(FeaturesPlugin_Revolution::FROM_ANGLE_ID());
126 theDumper << ", " << anAttrToAngle << ", " << anAttrFromAngle;
127 } else if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES()) {
128 AttributeSelectionPtr anAttrToObject = aBase->selection(FeaturesPlugin_Revolution::TO_OBJECT_ID());
129 AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Revolution::TO_OFFSET_ID());
130 AttributeSelectionPtr anAttrFromObject = aBase->selection(FeaturesPlugin_Revolution::FROM_OBJECT_ID());
131 AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Revolution::FROM_OFFSET_ID());
133 theDumper << ", " << anAttrToObject << ", " << anAttrToOffset << ", " << anAttrFromObject << ", " << anAttrFromOffset;
136 AttributeSelectionListPtr anAttrBoolObjects = aBase->selectionList(FeaturesPlugin_CompositeBoolean::OBJECTS_ID());
137 theDumper << ", " << anAttrBoolObjects << ")" << std::endl;
139 if(anAttrSketch->isInitialized()) {
140 theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
144 //==================================================================================================
145 void FeaturesAPI_RevolutionBoolean::execIfBaseNotEmpty()
147 if(mybaseObjects->size() > 0) {
152 //==================================================================================================
153 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(const std::shared_ptr<ModelAPI_Feature>& theFeature)
154 : FeaturesAPI_RevolutionBoolean(theFeature)
159 //==================================================================================================
160 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(const std::shared_ptr<ModelAPI_Feature>& theFeature,
161 const std::list<ModelHighAPI_Selection>& theBaseObjects,
162 const ModelHighAPI_Selection& theAxis,
163 const ModelHighAPI_Double& theSize,
164 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
165 : FeaturesAPI_RevolutionBoolean(theFeature)
168 fillAttribute(theBaseObjects, mybaseObjects);
169 fillAttribute(theAxis, myaxis);
170 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
171 fillAttribute(theSize, mytoAngle);
172 fillAttribute(ModelHighAPI_Double(), myfromAngle);
173 setBooleanObjects(theBooleanObjects);
177 //==================================================================================================
178 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(const std::shared_ptr<ModelAPI_Feature>& theFeature,
179 const std::list<ModelHighAPI_Selection>& theBaseObjects,
180 const ModelHighAPI_Selection& theAxis,
181 const ModelHighAPI_Double& theToAngle,
182 const ModelHighAPI_Double& theFromAngle,
183 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
184 : FeaturesAPI_RevolutionBoolean(theFeature)
187 fillAttribute(theBaseObjects, mybaseObjects);
188 fillAttribute(theAxis, myaxis);
189 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
190 fillAttribute(theToAngle, mytoAngle);
191 fillAttribute(theFromAngle, myfromAngle);
192 setBooleanObjects(theBooleanObjects);
196 //==================================================================================================
197 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(const std::shared_ptr<ModelAPI_Feature>& theFeature,
198 const std::list<ModelHighAPI_Selection>& theBaseObjects,
199 const ModelHighAPI_Selection& theAxis,
200 const ModelHighAPI_Selection& theToObject,
201 const ModelHighAPI_Double& theToOffset,
202 const ModelHighAPI_Selection& theFromObject,
203 const ModelHighAPI_Double& theFromOffset,
204 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
205 : FeaturesAPI_RevolutionBoolean(theFeature)
208 fillAttribute(theBaseObjects, mybaseObjects);
209 fillAttribute(theAxis, myaxis);
210 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
211 fillAttribute(theToObject, mytoObject);
212 fillAttribute(theToOffset, mytoOffset);
213 fillAttribute(theFromObject, myfromObject);
214 fillAttribute(theFromOffset, myfromOffset);
215 setBooleanObjects(theBooleanObjects);
219 //==================================================================================================
220 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
221 const std::list<ModelHighAPI_Selection>& theBaseObjects,
222 const ModelHighAPI_Selection& theAxis,
223 const ModelHighAPI_Double& theSize,
224 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
226 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
227 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature, theBaseObjects, theAxis, theSize, theBooleanObjects));
230 //==================================================================================================
231 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
232 const std::list<ModelHighAPI_Selection>& theBaseObjects,
233 const ModelHighAPI_Selection& theAxis,
234 const ModelHighAPI_Double& theToAngle,
235 const ModelHighAPI_Double& theFromAngle,
236 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
238 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
239 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
247 //==================================================================================================
248 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
249 const std::list<ModelHighAPI_Selection>& theBaseObjects,
250 const ModelHighAPI_Selection& theAxis,
251 const ModelHighAPI_Selection& theToObject,
252 const ModelHighAPI_Double& theToOffset,
253 const ModelHighAPI_Selection& theFromObject,
254 const ModelHighAPI_Double& theFromOffset,
255 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
257 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
258 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
269 //==================================================================================================
270 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(const std::shared_ptr<ModelAPI_Feature>& theFeature)
271 : FeaturesAPI_RevolutionBoolean(theFeature)
276 //==================================================================================================
277 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
278 const std::list<ModelHighAPI_Selection>& theBaseObjects,
279 const ModelHighAPI_Selection& theAxis,
280 const ModelHighAPI_Double& theSize,
281 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
282 : FeaturesAPI_RevolutionBoolean(theFeature)
285 fillAttribute(theBaseObjects, mybaseObjects);
286 fillAttribute(theAxis, myaxis);
287 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
288 fillAttribute(theSize, mytoAngle);
289 fillAttribute(ModelHighAPI_Double(), myfromAngle);
290 setBooleanObjects(theBooleanObjects);
294 //==================================================================================================
295 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
296 const std::list<ModelHighAPI_Selection>& theBaseObjects,
297 const ModelHighAPI_Selection& theAxis,
298 const ModelHighAPI_Double& theToAngle,
299 const ModelHighAPI_Double& theFromAngle,
300 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
301 : FeaturesAPI_RevolutionBoolean(theFeature)
304 fillAttribute(theBaseObjects, mybaseObjects);
305 fillAttribute(theAxis, myaxis);
306 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
307 fillAttribute(theToAngle, mytoAngle);
308 fillAttribute(theFromAngle, myfromAngle);
309 setBooleanObjects(theBooleanObjects);
313 //==================================================================================================
314 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
315 const std::list<ModelHighAPI_Selection>& theBaseObjects,
316 const ModelHighAPI_Selection& theAxis,
317 const ModelHighAPI_Selection& theToObject,
318 const ModelHighAPI_Double& theToOffset,
319 const ModelHighAPI_Selection& theFromObject,
320 const ModelHighAPI_Double& theFromOffset,
321 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
322 : FeaturesAPI_RevolutionBoolean(theFeature)
325 fillAttribute(theBaseObjects, mybaseObjects);
326 fillAttribute(theAxis, myaxis);
327 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
328 fillAttribute(theToObject, mytoObject);
329 fillAttribute(theToOffset, mytoOffset);
330 fillAttribute(theFromObject, myfromObject);
331 fillAttribute(theFromOffset, myfromOffset);
332 setBooleanObjects(theBooleanObjects);
336 //==================================================================================================
337 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
338 const std::list<ModelHighAPI_Selection>& theBaseObjects,
339 const ModelHighAPI_Selection& theAxis,
340 const ModelHighAPI_Double& theSize,
341 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
343 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
344 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature, theBaseObjects, theAxis, theSize, theBooleanObjects));
347 //==================================================================================================
348 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
349 const std::list<ModelHighAPI_Selection>& theBaseObjects,
350 const ModelHighAPI_Selection& theAxis,
351 const ModelHighAPI_Double& theToAngle,
352 const ModelHighAPI_Double& theFromAngle,
353 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
355 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
356 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,
364 //==================================================================================================
365 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
366 const std::list<ModelHighAPI_Selection>& theBaseObjects,
367 const ModelHighAPI_Selection& theAxis,
368 const ModelHighAPI_Selection& theToObject,
369 const ModelHighAPI_Double& theToOffset,
370 const ModelHighAPI_Selection& theFromObject,
371 const ModelHighAPI_Double& theFromOffset,
372 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
374 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
375 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,