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(
16 const std::shared_ptr<ModelAPI_Feature>& theFeature)
17 : ModelHighAPI_Interface(theFeature)
21 //==================================================================================================
22 FeaturesAPI_RevolutionBoolean::~FeaturesAPI_RevolutionBoolean()
26 //==================================================================================================
27 void FeaturesAPI_RevolutionBoolean::setNestedSketch(const ModelHighAPI_Reference& theSketch)
29 mysketch->setValue(theSketch.feature());
31 // To make Sketch feature execute and subfeatures execute.
32 feature()->document()->setCurrentFeature(feature(), false);
34 // to inform that the history is updated due to the sketch moved under the composite feature
35 if (theSketch.feature().get()) {
36 theSketch.feature()->document()->updateHistory(ModelAPI_Feature::group());
37 if (theSketch.feature()->firstResult().get())
38 theSketch.feature()->firstResult()->setDisplayed(false);
40 mybaseObjects->clear();
41 mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
46 //==================================================================================================
47 void FeaturesAPI_RevolutionBoolean::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
49 mysketch->setValue(ObjectPtr());
50 mybaseObjects->clear();
51 fillAttribute(theBaseObjects, mybaseObjects);
56 //==================================================================================================
57 void FeaturesAPI_RevolutionBoolean::setAxis(const ModelHighAPI_Selection& theAxis)
59 fillAttribute(theAxis, myaxis);
64 //==================================================================================================
65 void FeaturesAPI_RevolutionBoolean::setAngles(const ModelHighAPI_Double& theToAngle,
66 const ModelHighAPI_Double& theFromAngle)
68 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
69 fillAttribute(theToAngle, mytoAngle);
70 fillAttribute(theFromAngle, myfromAngle);
75 //==================================================================================================
76 void FeaturesAPI_RevolutionBoolean::setAngle(const ModelHighAPI_Double& theAngle)
78 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
79 fillAttribute(theAngle, mytoAngle);
80 fillAttribute(ModelHighAPI_Double(), myfromAngle);
85 //==================================================================================================
86 void FeaturesAPI_RevolutionBoolean::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
87 const ModelHighAPI_Double& theToOffset,
88 const ModelHighAPI_Selection& theFromObject,
89 const ModelHighAPI_Double& theFromOffset)
91 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
92 fillAttribute(theToObject, mytoObject);
93 fillAttribute(theToOffset, mytoOffset);
94 fillAttribute(theFromObject, myfromObject);
95 fillAttribute(theFromOffset, myfromOffset);
100 //==================================================================================================
101 void FeaturesAPI_RevolutionBoolean::setBooleanObjects(
102 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
104 fillAttribute(theBooleanObjects, mybooleanObjects);
106 execIfBaseNotEmpty();
109 //==================================================================================================
110 void FeaturesAPI_RevolutionBoolean::dump(ModelHighAPI_Dumper& theDumper) const
112 FeaturePtr aBase = feature();
113 const std::string& aDocName = theDumper.name(aBase->document());
115 AttributeReferencePtr anAttrSketch =
116 aBase->reference(FeaturesPlugin_Revolution::SKETCH_ID());
117 AttributeSelectionListPtr anAttrObjects =
118 aBase->selectionList(FeaturesPlugin_Revolution::BASE_OBJECTS_ID());
119 AttributeSelectionPtr anAttrAxis =
120 aBase->selection(FeaturesPlugin_Revolution::AXIS_OBJECT_ID());
122 theDumper << aBase << " = model.addRevolution";
123 if(aBase->getKind() == FeaturesPlugin_RevolutionCut::ID()) {
125 } else if(aBase->getKind() == FeaturesPlugin_RevolutionFuse::ID()) {
128 theDumper << "(" << aDocName << ", ";
129 anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
130 theDumper << ", " << anAttrAxis;
132 std::string aCreationMethod =
133 aBase->string(FeaturesPlugin_Revolution::CREATION_METHOD())->value();
135 if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES()) {
136 AttributeDoublePtr anAttrToAngle = aBase->real(FeaturesPlugin_Revolution::TO_ANGLE_ID());
137 AttributeDoublePtr anAttrFromAngle = aBase->real(FeaturesPlugin_Revolution::FROM_ANGLE_ID());
139 theDumper << ", " << anAttrToAngle << ", " << anAttrFromAngle;
140 } else if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES()) {
141 AttributeSelectionPtr anAttrToObject =
142 aBase->selection(FeaturesPlugin_Revolution::TO_OBJECT_ID());
143 AttributeDoublePtr anAttrToOffset =
144 aBase->real(FeaturesPlugin_Revolution::TO_OFFSET_ID());
145 AttributeSelectionPtr anAttrFromObject =
146 aBase->selection(FeaturesPlugin_Revolution::FROM_OBJECT_ID());
147 AttributeDoublePtr anAttrFromOffset =
148 aBase->real(FeaturesPlugin_Revolution::FROM_OFFSET_ID());
150 theDumper << ", " << anAttrToObject << ", " << anAttrToOffset <<
151 ", " << anAttrFromObject << ", " << anAttrFromOffset;
154 AttributeSelectionListPtr anAttrBoolObjects =
155 aBase->selectionList(FeaturesPlugin_CompositeBoolean::OBJECTS_ID());
156 theDumper << ", " << anAttrBoolObjects << ")" << std::endl;
158 if(anAttrSketch->isInitialized()) {
159 theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
163 //==================================================================================================
164 void FeaturesAPI_RevolutionBoolean::execIfBaseNotEmpty()
166 if(mybaseObjects->size() > 0) {
171 //==================================================================================================
172 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
173 const std::shared_ptr<ModelAPI_Feature>& theFeature)
174 : FeaturesAPI_RevolutionBoolean(theFeature)
179 //==================================================================================================
180 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
181 const std::shared_ptr<ModelAPI_Feature>& theFeature,
182 const std::list<ModelHighAPI_Selection>& theBaseObjects,
183 const ModelHighAPI_Selection& theAxis,
184 const ModelHighAPI_Double& theSize,
185 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
186 : FeaturesAPI_RevolutionBoolean(theFeature)
189 fillAttribute(theBaseObjects, mybaseObjects);
190 fillAttribute(theAxis, myaxis);
191 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
192 fillAttribute(theSize, mytoAngle);
193 fillAttribute(ModelHighAPI_Double(), myfromAngle);
194 setBooleanObjects(theBooleanObjects);
198 //==================================================================================================
199 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
200 const std::shared_ptr<ModelAPI_Feature>& theFeature,
201 const std::list<ModelHighAPI_Selection>& theBaseObjects,
202 const ModelHighAPI_Selection& theAxis,
203 const ModelHighAPI_Double& theToAngle,
204 const ModelHighAPI_Double& theFromAngle,
205 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
206 : FeaturesAPI_RevolutionBoolean(theFeature)
209 fillAttribute(theBaseObjects, mybaseObjects);
210 fillAttribute(theAxis, myaxis);
211 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
212 fillAttribute(theToAngle, mytoAngle);
213 fillAttribute(theFromAngle, myfromAngle);
214 setBooleanObjects(theBooleanObjects);
218 //==================================================================================================
219 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
220 const std::shared_ptr<ModelAPI_Feature>& theFeature,
221 const std::list<ModelHighAPI_Selection>& theBaseObjects,
222 const ModelHighAPI_Selection& theAxis,
223 const ModelHighAPI_Selection& theToObject,
224 const ModelHighAPI_Double& theToOffset,
225 const ModelHighAPI_Selection& theFromObject,
226 const ModelHighAPI_Double& theFromOffset,
227 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
228 : FeaturesAPI_RevolutionBoolean(theFeature)
231 fillAttribute(theBaseObjects, mybaseObjects);
232 fillAttribute(theAxis, myaxis);
233 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
234 fillAttribute(theToObject, mytoObject);
235 fillAttribute(theToOffset, mytoOffset);
236 fillAttribute(theFromObject, myfromObject);
237 fillAttribute(theFromOffset, myfromOffset);
238 setBooleanObjects(theBooleanObjects);
242 //==================================================================================================
243 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
244 const std::list<ModelHighAPI_Selection>& theBaseObjects,
245 const ModelHighAPI_Selection& theAxis,
246 const ModelHighAPI_Double& theSize,
247 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
249 std::shared_ptr<ModelAPI_Feature> aFeature =
250 thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
251 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature, theBaseObjects,
252 theAxis, theSize, theBooleanObjects));
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& theToAngle,
260 const ModelHighAPI_Double& theFromAngle,
261 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
263 std::shared_ptr<ModelAPI_Feature> aFeature =
264 thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
265 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
273 //==================================================================================================
274 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
275 const std::list<ModelHighAPI_Selection>& theBaseObjects,
276 const ModelHighAPI_Selection& theAxis,
277 const ModelHighAPI_Selection& theToObject,
278 const ModelHighAPI_Double& theToOffset,
279 const ModelHighAPI_Selection& theFromObject,
280 const ModelHighAPI_Double& theFromOffset,
281 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
283 std::shared_ptr<ModelAPI_Feature> aFeature =
284 thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
285 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
296 //==================================================================================================
297 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
298 const std::shared_ptr<ModelAPI_Feature>& theFeature)
299 : FeaturesAPI_RevolutionBoolean(theFeature)
304 //==================================================================================================
305 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
306 const std::shared_ptr<ModelAPI_Feature>& theFeature,
307 const std::list<ModelHighAPI_Selection>& theBaseObjects,
308 const ModelHighAPI_Selection& theAxis,
309 const ModelHighAPI_Double& theSize,
310 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
311 : FeaturesAPI_RevolutionBoolean(theFeature)
314 fillAttribute(theBaseObjects, mybaseObjects);
315 fillAttribute(theAxis, myaxis);
316 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
317 fillAttribute(theSize, mytoAngle);
318 fillAttribute(ModelHighAPI_Double(), myfromAngle);
319 setBooleanObjects(theBooleanObjects);
323 //==================================================================================================
324 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
325 const std::shared_ptr<ModelAPI_Feature>& theFeature,
326 const std::list<ModelHighAPI_Selection>& theBaseObjects,
327 const ModelHighAPI_Selection& theAxis,
328 const ModelHighAPI_Double& theToAngle,
329 const ModelHighAPI_Double& theFromAngle,
330 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
331 : FeaturesAPI_RevolutionBoolean(theFeature)
334 fillAttribute(theBaseObjects, mybaseObjects);
335 fillAttribute(theAxis, myaxis);
336 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
337 fillAttribute(theToAngle, mytoAngle);
338 fillAttribute(theFromAngle, myfromAngle);
339 setBooleanObjects(theBooleanObjects);
343 //==================================================================================================
344 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
345 const std::shared_ptr<ModelAPI_Feature>& theFeature,
346 const std::list<ModelHighAPI_Selection>& theBaseObjects,
347 const ModelHighAPI_Selection& theAxis,
348 const ModelHighAPI_Selection& theToObject,
349 const ModelHighAPI_Double& theToOffset,
350 const ModelHighAPI_Selection& theFromObject,
351 const ModelHighAPI_Double& theFromOffset,
352 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
353 : FeaturesAPI_RevolutionBoolean(theFeature)
356 fillAttribute(theBaseObjects, mybaseObjects);
357 fillAttribute(theAxis, myaxis);
358 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
359 fillAttribute(theToObject, mytoObject);
360 fillAttribute(theToOffset, mytoOffset);
361 fillAttribute(theFromObject, myfromObject);
362 fillAttribute(theFromOffset, myfromOffset);
363 setBooleanObjects(theBooleanObjects);
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_Double& theSize,
372 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
374 std::shared_ptr<ModelAPI_Feature> aFeature =
375 thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
376 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature, theBaseObjects,
377 theAxis, theSize, theBooleanObjects));
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& theToAngle,
385 const ModelHighAPI_Double& theFromAngle,
386 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
388 std::shared_ptr<ModelAPI_Feature> aFeature =
389 thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
390 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,
398 //==================================================================================================
399 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
400 const std::list<ModelHighAPI_Selection>& theBaseObjects,
401 const ModelHighAPI_Selection& theAxis,
402 const ModelHighAPI_Selection& theToObject,
403 const ModelHighAPI_Double& theToOffset,
404 const ModelHighAPI_Selection& theFromObject,
405 const ModelHighAPI_Double& theFromOffset,
406 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
408 std::shared_ptr<ModelAPI_Feature> aFeature =
409 thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
410 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,