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());
30 // To make Sketch feature execute and subfeatures execute.
31 feature()->document()->setCurrentFeature(feature(), false);
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);
39 mybaseObjects->clear();
40 mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
45 //==================================================================================================
46 void FeaturesAPI_RevolutionBoolean::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
48 mysketch->setValue(ObjectPtr());
49 mybaseObjects->clear();
50 fillAttribute(theBaseObjects, mybaseObjects);
55 //==================================================================================================
56 void FeaturesAPI_RevolutionBoolean::setAxis(const ModelHighAPI_Selection& theAxis)
58 fillAttribute(theAxis, myaxis);
63 //==================================================================================================
64 void FeaturesAPI_RevolutionBoolean::setAngles(const ModelHighAPI_Double& theToAngle,
65 const ModelHighAPI_Double& theFromAngle)
67 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
68 fillAttribute(theToAngle, mytoAngle);
69 fillAttribute(theFromAngle, myfromAngle);
74 //==================================================================================================
75 void FeaturesAPI_RevolutionBoolean::setAngle(const ModelHighAPI_Double& theAngle)
77 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
78 fillAttribute(theAngle, mytoAngle);
79 fillAttribute(ModelHighAPI_Double(), myfromAngle);
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)
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);
99 //==================================================================================================
100 void FeaturesAPI_RevolutionBoolean::setBooleanObjects(const std::list<ModelHighAPI_Selection>& theBooleanObjects)
102 fillAttribute(theBooleanObjects, mybooleanObjects);
104 execIfBaseNotEmpty();
107 //==================================================================================================
108 void FeaturesAPI_RevolutionBoolean::dump(ModelHighAPI_Dumper& theDumper) const
110 FeaturePtr aBase = feature();
111 const std::string& aDocName = theDumper.name(aBase->document());
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());
117 theDumper << aBase << " = model.addRevolution";
118 if(aBase->getKind() == FeaturesPlugin_RevolutionCut::ID()) {
120 } else if(aBase->getKind() == FeaturesPlugin_RevolutionFuse::ID()) {
123 theDumper << "(" << aDocName << ", ";
124 anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
125 theDumper << ", " << anAttrAxis;
127 std::string aCreationMethod = aBase->string(FeaturesPlugin_Revolution::CREATION_METHOD())->value();
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());
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());
140 theDumper << ", " << anAttrToObject << ", " << anAttrToOffset << ", " << anAttrFromObject << ", " << anAttrFromOffset;
143 AttributeSelectionListPtr anAttrBoolObjects = aBase->selectionList(FeaturesPlugin_CompositeBoolean::OBJECTS_ID());
144 theDumper << ", " << anAttrBoolObjects << ")" << std::endl;
146 if(anAttrSketch->isInitialized()) {
147 theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
151 //==================================================================================================
152 void FeaturesAPI_RevolutionBoolean::execIfBaseNotEmpty()
154 if(mybaseObjects->size() > 0) {
159 //==================================================================================================
160 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(const std::shared_ptr<ModelAPI_Feature>& theFeature)
161 : FeaturesAPI_RevolutionBoolean(theFeature)
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)
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);
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)
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);
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)
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);
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)
233 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
234 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature, theBaseObjects, theAxis, theSize, theBooleanObjects));
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)
245 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
246 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
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)
264 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
265 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
276 //==================================================================================================
277 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(const std::shared_ptr<ModelAPI_Feature>& theFeature)
278 : FeaturesAPI_RevolutionBoolean(theFeature)
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)
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);
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)
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);
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)
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);
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)
350 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
351 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature, theBaseObjects, theAxis, theSize, theBooleanObjects));
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)
362 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
363 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,
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)
381 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
382 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,