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 mybaseObjects->clear();
30 mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
35 //==================================================================================================
36 void FeaturesAPI_RevolutionBoolean::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
38 mysketch->setValue(ObjectPtr());
39 mybaseObjects->clear();
40 fillAttribute(theBaseObjects, mybaseObjects);
45 //==================================================================================================
46 void FeaturesAPI_RevolutionBoolean::setAxis(const ModelHighAPI_Selection& theAxis)
48 fillAttribute(theAxis, myaxis);
53 //==================================================================================================
54 void FeaturesAPI_RevolutionBoolean::setAngles(const ModelHighAPI_Double& theToAngle,
55 const ModelHighAPI_Double& theFromAngle)
57 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
58 fillAttribute(theToAngle, mytoAngle);
59 fillAttribute(theFromAngle, myfromAngle);
64 //==================================================================================================
65 void FeaturesAPI_RevolutionBoolean::setAngle(const ModelHighAPI_Double& theAngle)
67 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
68 fillAttribute(theAngle, mytoAngle);
69 fillAttribute(ModelHighAPI_Double(), myfromAngle);
74 //==================================================================================================
75 void FeaturesAPI_RevolutionBoolean::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
76 const ModelHighAPI_Double& theToOffset,
77 const ModelHighAPI_Selection& theFromObject,
78 const ModelHighAPI_Double& theFromOffset)
80 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
81 fillAttribute(theToObject, mytoObject);
82 fillAttribute(theToOffset, mytoOffset);
83 fillAttribute(theFromObject, myfromObject);
84 fillAttribute(theFromOffset, myfromOffset);
89 //==================================================================================================
90 void FeaturesAPI_RevolutionBoolean::setBooleanObjects(const std::list<ModelHighAPI_Selection>& theBooleanObjects)
92 fillAttribute(theBooleanObjects, mybooleanObjects);
97 //==================================================================================================
98 void FeaturesAPI_RevolutionBoolean::dump(ModelHighAPI_Dumper& theDumper) const
100 FeaturePtr aBase = feature();
101 const std::string& aDocName = theDumper.name(aBase->document());
103 AttributeReferencePtr anAttrSketch = aBase->reference(FeaturesPlugin_Revolution::SKETCH_ID());
104 AttributeSelectionListPtr anAttrObjects = aBase->selectionList(FeaturesPlugin_Revolution::BASE_OBJECTS_ID());
105 AttributeSelectionPtr anAttrAxis = aBase->selection(FeaturesPlugin_Revolution::AXIS_OBJECT_ID());
107 theDumper << aBase << " = model.addRevolution";
108 if(aBase->getKind() == FeaturesPlugin_RevolutionCut::ID()) {
110 } else if(aBase->getKind() == FeaturesPlugin_RevolutionFuse::ID()) {
113 theDumper << "(" << aDocName << ", ";
114 anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
115 theDumper << ", " << anAttrAxis;
117 std::string aCreationMethod = aBase->string(FeaturesPlugin_Revolution::CREATION_METHOD())->value();
119 if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES()) {
120 AttributeDoublePtr anAttrToAngle = aBase->real(FeaturesPlugin_Revolution::TO_ANGLE_ID());
121 AttributeDoublePtr anAttrFromAngle = aBase->real(FeaturesPlugin_Revolution::FROM_ANGLE_ID());
123 theDumper << ", " << anAttrToAngle << ", " << anAttrFromAngle;
124 } else if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES()) {
125 AttributeSelectionPtr anAttrToObject = aBase->selection(FeaturesPlugin_Revolution::TO_OBJECT_ID());
126 AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Revolution::TO_OFFSET_ID());
127 AttributeSelectionPtr anAttrFromObject = aBase->selection(FeaturesPlugin_Revolution::FROM_OBJECT_ID());
128 AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Revolution::FROM_OFFSET_ID());
130 theDumper << ", " << anAttrToObject << ", " << anAttrToOffset << ", " << anAttrFromObject << ", " << anAttrFromOffset;
133 AttributeSelectionListPtr anAttrBoolObjects = aBase->selectionList(FeaturesPlugin_CompositeBoolean::OBJECTS_ID());
134 theDumper << ", " << anAttrBoolObjects << ")" << std::endl;
136 if(anAttrSketch->isInitialized()) {
137 theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
141 //==================================================================================================
142 void FeaturesAPI_RevolutionBoolean::execIfBaseNotEmpty()
144 if(mybaseObjects->size() > 0) {
149 //==================================================================================================
150 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(const std::shared_ptr<ModelAPI_Feature>& theFeature)
151 : FeaturesAPI_RevolutionBoolean(theFeature)
156 //==================================================================================================
157 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(const std::shared_ptr<ModelAPI_Feature>& theFeature,
158 const std::list<ModelHighAPI_Selection>& theBaseObjects,
159 const ModelHighAPI_Selection& theAxis,
160 const ModelHighAPI_Double& theSize,
161 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
162 : FeaturesAPI_RevolutionBoolean(theFeature)
165 fillAttribute(theBaseObjects, mybaseObjects);
166 fillAttribute(theAxis, myaxis);
167 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
168 fillAttribute(theSize, mytoAngle);
169 fillAttribute(ModelHighAPI_Double(), myfromAngle);
170 setBooleanObjects(theBooleanObjects);
174 //==================================================================================================
175 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(const std::shared_ptr<ModelAPI_Feature>& theFeature,
176 const std::list<ModelHighAPI_Selection>& theBaseObjects,
177 const ModelHighAPI_Selection& theAxis,
178 const ModelHighAPI_Double& theToAngle,
179 const ModelHighAPI_Double& theFromAngle,
180 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
181 : FeaturesAPI_RevolutionBoolean(theFeature)
184 fillAttribute(theBaseObjects, mybaseObjects);
185 fillAttribute(theAxis, myaxis);
186 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
187 fillAttribute(theToAngle, mytoAngle);
188 fillAttribute(theFromAngle, myfromAngle);
189 setBooleanObjects(theBooleanObjects);
193 //==================================================================================================
194 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(const std::shared_ptr<ModelAPI_Feature>& theFeature,
195 const std::list<ModelHighAPI_Selection>& theBaseObjects,
196 const ModelHighAPI_Selection& theAxis,
197 const ModelHighAPI_Selection& theToObject,
198 const ModelHighAPI_Double& theToOffset,
199 const ModelHighAPI_Selection& theFromObject,
200 const ModelHighAPI_Double& theFromOffset,
201 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
202 : FeaturesAPI_RevolutionBoolean(theFeature)
205 fillAttribute(theBaseObjects, mybaseObjects);
206 fillAttribute(theAxis, myaxis);
207 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
208 fillAttribute(theToObject, mytoObject);
209 fillAttribute(theToOffset, mytoOffset);
210 fillAttribute(theFromObject, myfromObject);
211 fillAttribute(theFromOffset, myfromOffset);
212 setBooleanObjects(theBooleanObjects);
216 //==================================================================================================
217 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
218 const std::list<ModelHighAPI_Selection>& theBaseObjects,
219 const ModelHighAPI_Selection& theAxis,
220 const ModelHighAPI_Double& theSize,
221 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
223 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
224 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature, theBaseObjects, theAxis, theSize, theBooleanObjects));
227 //==================================================================================================
228 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
229 const std::list<ModelHighAPI_Selection>& theBaseObjects,
230 const ModelHighAPI_Selection& theAxis,
231 const ModelHighAPI_Double& theToAngle,
232 const ModelHighAPI_Double& theFromAngle,
233 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
235 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
236 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
244 //==================================================================================================
245 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
246 const std::list<ModelHighAPI_Selection>& theBaseObjects,
247 const ModelHighAPI_Selection& theAxis,
248 const ModelHighAPI_Selection& theToObject,
249 const ModelHighAPI_Double& theToOffset,
250 const ModelHighAPI_Selection& theFromObject,
251 const ModelHighAPI_Double& theFromOffset,
252 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
254 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
255 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
266 //==================================================================================================
267 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(const std::shared_ptr<ModelAPI_Feature>& theFeature)
268 : FeaturesAPI_RevolutionBoolean(theFeature)
273 //==================================================================================================
274 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
275 const std::list<ModelHighAPI_Selection>& theBaseObjects,
276 const ModelHighAPI_Selection& theAxis,
277 const ModelHighAPI_Double& theSize,
278 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
279 : FeaturesAPI_RevolutionBoolean(theFeature)
282 fillAttribute(theBaseObjects, mybaseObjects);
283 fillAttribute(theAxis, myaxis);
284 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
285 fillAttribute(theSize, mytoAngle);
286 fillAttribute(ModelHighAPI_Double(), myfromAngle);
287 setBooleanObjects(theBooleanObjects);
291 //==================================================================================================
292 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
293 const std::list<ModelHighAPI_Selection>& theBaseObjects,
294 const ModelHighAPI_Selection& theAxis,
295 const ModelHighAPI_Double& theToAngle,
296 const ModelHighAPI_Double& theFromAngle,
297 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
298 : FeaturesAPI_RevolutionBoolean(theFeature)
301 fillAttribute(theBaseObjects, mybaseObjects);
302 fillAttribute(theAxis, myaxis);
303 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
304 fillAttribute(theToAngle, mytoAngle);
305 fillAttribute(theFromAngle, myfromAngle);
306 setBooleanObjects(theBooleanObjects);
310 //==================================================================================================
311 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
312 const std::list<ModelHighAPI_Selection>& theBaseObjects,
313 const ModelHighAPI_Selection& theAxis,
314 const ModelHighAPI_Selection& theToObject,
315 const ModelHighAPI_Double& theToOffset,
316 const ModelHighAPI_Selection& theFromObject,
317 const ModelHighAPI_Double& theFromOffset,
318 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
319 : FeaturesAPI_RevolutionBoolean(theFeature)
322 fillAttribute(theBaseObjects, mybaseObjects);
323 fillAttribute(theAxis, myaxis);
324 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
325 fillAttribute(theToObject, mytoObject);
326 fillAttribute(theToOffset, mytoOffset);
327 fillAttribute(theFromObject, myfromObject);
328 fillAttribute(theFromOffset, myfromOffset);
329 setBooleanObjects(theBooleanObjects);
333 //==================================================================================================
334 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
335 const std::list<ModelHighAPI_Selection>& theBaseObjects,
336 const ModelHighAPI_Selection& theAxis,
337 const ModelHighAPI_Double& theSize,
338 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
340 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
341 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature, theBaseObjects, theAxis, theSize, theBooleanObjects));
344 //==================================================================================================
345 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
346 const std::list<ModelHighAPI_Selection>& theBaseObjects,
347 const ModelHighAPI_Selection& theAxis,
348 const ModelHighAPI_Double& theToAngle,
349 const ModelHighAPI_Double& theFromAngle,
350 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
352 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
353 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,
361 //==================================================================================================
362 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
363 const std::list<ModelHighAPI_Selection>& theBaseObjects,
364 const ModelHighAPI_Selection& theAxis,
365 const ModelHighAPI_Selection& theToObject,
366 const ModelHighAPI_Double& theToOffset,
367 const ModelHighAPI_Selection& theFromObject,
368 const ModelHighAPI_Double& theFromOffset,
369 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
371 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
372 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,