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 if (theSketch.feature()->firstResult().get())
33 theSketch.feature()->firstResult()->setDisplayed(false);
35 mybaseObjects->clear();
36 mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
41 //==================================================================================================
42 void FeaturesAPI_RevolutionBoolean::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
44 mysketch->setValue(ObjectPtr());
45 mybaseObjects->clear();
46 fillAttribute(theBaseObjects, mybaseObjects);
51 //==================================================================================================
52 void FeaturesAPI_RevolutionBoolean::setAxis(const ModelHighAPI_Selection& theAxis)
54 fillAttribute(theAxis, myaxis);
59 //==================================================================================================
60 void FeaturesAPI_RevolutionBoolean::setAngles(const ModelHighAPI_Double& theToAngle,
61 const ModelHighAPI_Double& theFromAngle)
63 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
64 fillAttribute(theToAngle, mytoAngle);
65 fillAttribute(theFromAngle, myfromAngle);
70 //==================================================================================================
71 void FeaturesAPI_RevolutionBoolean::setAngle(const ModelHighAPI_Double& theAngle)
73 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
74 fillAttribute(theAngle, mytoAngle);
75 fillAttribute(ModelHighAPI_Double(), myfromAngle);
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)
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);
95 //==================================================================================================
96 void FeaturesAPI_RevolutionBoolean::setBooleanObjects(const std::list<ModelHighAPI_Selection>& theBooleanObjects)
98 fillAttribute(theBooleanObjects, mybooleanObjects);
100 execIfBaseNotEmpty();
103 //==================================================================================================
104 void FeaturesAPI_RevolutionBoolean::dump(ModelHighAPI_Dumper& theDumper) const
106 FeaturePtr aBase = feature();
107 const std::string& aDocName = theDumper.name(aBase->document());
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());
113 theDumper << aBase << " = model.addRevolution";
114 if(aBase->getKind() == FeaturesPlugin_RevolutionCut::ID()) {
116 } else if(aBase->getKind() == FeaturesPlugin_RevolutionFuse::ID()) {
119 theDumper << "(" << aDocName << ", ";
120 anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
121 theDumper << ", " << anAttrAxis;
123 std::string aCreationMethod = aBase->string(FeaturesPlugin_Revolution::CREATION_METHOD())->value();
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());
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());
136 theDumper << ", " << anAttrToObject << ", " << anAttrToOffset << ", " << anAttrFromObject << ", " << anAttrFromOffset;
139 AttributeSelectionListPtr anAttrBoolObjects = aBase->selectionList(FeaturesPlugin_CompositeBoolean::OBJECTS_ID());
140 theDumper << ", " << anAttrBoolObjects << ")" << std::endl;
142 if(anAttrSketch->isInitialized()) {
143 theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
147 //==================================================================================================
148 void FeaturesAPI_RevolutionBoolean::execIfBaseNotEmpty()
150 if(mybaseObjects->size() > 0) {
155 //==================================================================================================
156 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(const std::shared_ptr<ModelAPI_Feature>& theFeature)
157 : FeaturesAPI_RevolutionBoolean(theFeature)
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)
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);
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)
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);
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)
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);
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)
229 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
230 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature, theBaseObjects, theAxis, theSize, theBooleanObjects));
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)
241 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
242 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
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)
260 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
261 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
272 //==================================================================================================
273 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(const std::shared_ptr<ModelAPI_Feature>& theFeature)
274 : FeaturesAPI_RevolutionBoolean(theFeature)
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)
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);
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)
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);
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)
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);
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)
346 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
347 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature, theBaseObjects, theAxis, theSize, theBooleanObjects));
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)
358 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
359 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,
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)
377 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
378 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,