1 // Copyright (C) 2014-2021 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "FeaturesAPI_RevolutionBoolean.h"
22 #include <ModelHighAPI_Double.h>
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Reference.h>
25 #include <ModelHighAPI_Tools.h>
27 //==================================================================================================
28 FeaturesAPI_RevolutionBoolean::FeaturesAPI_RevolutionBoolean(
29 const std::shared_ptr<ModelAPI_Feature>& theFeature)
30 : ModelHighAPI_Interface(theFeature)
34 //==================================================================================================
35 FeaturesAPI_RevolutionBoolean::~FeaturesAPI_RevolutionBoolean()
39 //==================================================================================================
40 void FeaturesAPI_RevolutionBoolean::setNestedSketch(const ModelHighAPI_Reference& theSketch)
42 mysketch->setValue(theSketch.feature());
44 // To make Sketch feature execute and subfeatures execute.
45 feature()->document()->setCurrentFeature(feature(), false);
47 // to inform that the history is updated due to the sketch moved under the composite feature
48 if (theSketch.feature().get()) {
49 theSketch.feature()->document()->updateHistory(ModelAPI_Feature::group());
50 if (theSketch.feature()->firstResult().get())
51 theSketch.feature()->firstResult()->setDisplayed(false);
53 mybaseObjects->clear();
54 mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
59 //==================================================================================================
60 void FeaturesAPI_RevolutionBoolean::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
62 mysketch->setValue(ObjectPtr());
63 mybaseObjects->clear();
64 fillAttribute(theBaseObjects, mybaseObjects);
69 //==================================================================================================
70 void FeaturesAPI_RevolutionBoolean::setAxis(const ModelHighAPI_Selection& theAxis)
72 fillAttribute(theAxis, myaxis);
77 //==================================================================================================
78 void FeaturesAPI_RevolutionBoolean::setAngles(const ModelHighAPI_Double& theToAngle,
79 const ModelHighAPI_Double& theFromAngle)
81 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
82 fillAttribute(theToAngle, mytoAngle);
83 fillAttribute(theFromAngle, myfromAngle);
88 //==================================================================================================
89 void FeaturesAPI_RevolutionBoolean::setAngle(const ModelHighAPI_Double& theAngle)
91 setAngles(theAngle, ModelHighAPI_Double());
94 //==================================================================================================
95 void FeaturesAPI_RevolutionBoolean::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
96 const ModelHighAPI_Double& theToOffset,
97 const ModelHighAPI_Selection& theFromObject,
98 const ModelHighAPI_Double& theFromOffset)
100 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
101 fillAttribute(theToObject, mytoObject);
102 fillAttribute(theToOffset, mytoOffset);
103 fillAttribute(theFromObject, myfromObject);
104 fillAttribute(theFromOffset, myfromOffset);
106 execIfBaseNotEmpty();
109 //==================================================================================================
110 void FeaturesAPI_RevolutionBoolean::setBooleanObjects(
111 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
113 fillAttribute(theBooleanObjects, mybooleanObjects);
115 execIfBaseNotEmpty();
118 //==================================================================================================
119 void FeaturesAPI_RevolutionBoolean::dump(ModelHighAPI_Dumper& theDumper) const
121 FeaturePtr aBase = feature();
122 const std::string& aDocName = theDumper.name(aBase->document());
124 AttributeReferencePtr anAttrSketch =
125 aBase->reference(FeaturesPlugin_Revolution::SKETCH_ID());
126 AttributeSelectionListPtr anAttrObjects =
127 aBase->selectionList(FeaturesPlugin_Revolution::BASE_OBJECTS_ID());
128 AttributeSelectionPtr anAttrAxis =
129 aBase->selection(FeaturesPlugin_Revolution::AXIS_OBJECT_ID());
131 theDumper << aBase << " = model.addRevolution";
132 if(aBase->getKind() == FeaturesPlugin_RevolutionCut::ID()) {
134 } else if(aBase->getKind() == FeaturesPlugin_RevolutionFuse::ID()) {
137 theDumper << "(" << aDocName << ", ";
138 anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
139 theDumper << ", " << anAttrAxis;
141 std::string aCreationMethod =
142 aBase->string(FeaturesPlugin_Revolution::CREATION_METHOD())->value();
144 if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES()) {
145 AttributeDoublePtr anAttrToAngle = aBase->real(FeaturesPlugin_Revolution::TO_ANGLE_ID());
146 AttributeDoublePtr anAttrFromAngle = aBase->real(FeaturesPlugin_Revolution::FROM_ANGLE_ID());
148 theDumper << ", " << anAttrToAngle << ", " << anAttrFromAngle;
149 } else if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES()) {
150 AttributeSelectionPtr anAttrToObject =
151 aBase->selection(FeaturesPlugin_Revolution::TO_OBJECT_ID());
152 AttributeDoublePtr anAttrToOffset =
153 aBase->real(FeaturesPlugin_Revolution::TO_OFFSET_ID());
154 AttributeSelectionPtr anAttrFromObject =
155 aBase->selection(FeaturesPlugin_Revolution::FROM_OBJECT_ID());
156 AttributeDoublePtr anAttrFromOffset =
157 aBase->real(FeaturesPlugin_Revolution::FROM_OFFSET_ID());
159 theDumper << ", " << anAttrToObject << ", " << anAttrToOffset <<
160 ", " << anAttrFromObject << ", " << anAttrFromOffset;
165 AttributeSelectionListPtr anAttrBoolObjects =
166 aBase->selectionList(FeaturesPlugin_CompositeBoolean::OBJECTS_ID());
167 theDumper << ", " << anAttrBoolObjects << ")" << std::endl;
169 if(anAttrSketch->isInitialized()) {
170 theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
174 //==================================================================================================
175 void FeaturesAPI_RevolutionBoolean::execIfBaseNotEmpty()
177 if(mybaseObjects->size() > 0) {
182 //==================================================================================================
183 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
184 const std::shared_ptr<ModelAPI_Feature>& theFeature)
185 : FeaturesAPI_RevolutionBoolean(theFeature)
190 //==================================================================================================
191 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
192 const std::shared_ptr<ModelAPI_Feature>& theFeature,
193 const std::list<ModelHighAPI_Selection>& theBaseObjects,
194 const ModelHighAPI_Selection& theAxis,
195 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
196 : FeaturesAPI_RevolutionBoolean(theFeature)
199 fillAttribute(theBaseObjects, mybaseObjects);
200 fillAttribute(theAxis, myaxis);
201 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_THROUGH_ALL(), mycreationMethod);
202 setBooleanObjects(theBooleanObjects);
206 //==================================================================================================
207 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
208 const std::shared_ptr<ModelAPI_Feature>& theFeature,
209 const std::list<ModelHighAPI_Selection>& theBaseObjects,
210 const ModelHighAPI_Selection& theAxis,
211 const ModelHighAPI_Double& theSize,
212 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
213 : FeaturesAPI_RevolutionBoolean(theFeature)
216 fillAttribute(theBaseObjects, mybaseObjects);
217 fillAttribute(theAxis, myaxis);
219 setBooleanObjects(theBooleanObjects);
223 //==================================================================================================
224 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
225 const std::shared_ptr<ModelAPI_Feature>& theFeature,
226 const std::list<ModelHighAPI_Selection>& theBaseObjects,
227 const ModelHighAPI_Selection& theAxis,
228 const ModelHighAPI_Double& theToAngle,
229 const ModelHighAPI_Double& theFromAngle,
230 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
231 : FeaturesAPI_RevolutionBoolean(theFeature)
234 fillAttribute(theBaseObjects, mybaseObjects);
235 fillAttribute(theAxis, myaxis);
236 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
237 fillAttribute(theToAngle, mytoAngle);
238 fillAttribute(theFromAngle, myfromAngle);
239 setBooleanObjects(theBooleanObjects);
243 //==================================================================================================
244 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
245 const std::shared_ptr<ModelAPI_Feature>& theFeature,
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)
253 : FeaturesAPI_RevolutionBoolean(theFeature)
256 fillAttribute(theBaseObjects, mybaseObjects);
257 fillAttribute(theAxis, myaxis);
258 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
259 fillAttribute(theToObject, mytoObject);
260 fillAttribute(theToOffset, mytoOffset);
261 fillAttribute(theFromObject, myfromObject);
262 fillAttribute(theFromOffset, myfromOffset);
263 setBooleanObjects(theBooleanObjects);
267 //==================================================================================================
268 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
269 const std::list<ModelHighAPI_Selection>& theBaseObjects,
270 const ModelHighAPI_Selection& theAxis,
271 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
273 std::shared_ptr<ModelAPI_Feature> aFeature =
274 thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
275 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature, theBaseObjects,
276 theAxis, theBooleanObjects));
279 //==================================================================================================
280 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
281 const std::list<ModelHighAPI_Selection>& theBaseObjects,
282 const ModelHighAPI_Selection& theAxis,
283 const ModelHighAPI_Double& theSize,
284 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
286 std::shared_ptr<ModelAPI_Feature> aFeature =
287 thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
288 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature, theBaseObjects,
289 theAxis, theSize, theBooleanObjects));
292 //==================================================================================================
293 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
294 const std::list<ModelHighAPI_Selection>& theBaseObjects,
295 const ModelHighAPI_Selection& theAxis,
296 const ModelHighAPI_Double& theToAngle,
297 const ModelHighAPI_Double& theFromAngle,
298 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
300 std::shared_ptr<ModelAPI_Feature> aFeature =
301 thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
302 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
310 //==================================================================================================
311 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
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)
320 std::shared_ptr<ModelAPI_Feature> aFeature =
321 thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
322 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
333 //==================================================================================================
334 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
335 const std::shared_ptr<ModelAPI_Feature>& theFeature)
336 : FeaturesAPI_RevolutionBoolean(theFeature)
341 //==================================================================================================
342 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
343 const std::shared_ptr<ModelAPI_Feature>& theFeature,
344 const std::list<ModelHighAPI_Selection>& theBaseObjects,
345 const ModelHighAPI_Selection& theAxis,
346 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
347 : FeaturesAPI_RevolutionBoolean(theFeature)
350 fillAttribute(theBaseObjects, mybaseObjects);
351 fillAttribute(theAxis, myaxis);
352 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_THROUGH_ALL(), mycreationMethod);
353 setBooleanObjects(theBooleanObjects);
357 //==================================================================================================
358 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
359 const std::shared_ptr<ModelAPI_Feature>& theFeature,
360 const std::list<ModelHighAPI_Selection>& theBaseObjects,
361 const ModelHighAPI_Selection& theAxis,
362 const ModelHighAPI_Double& theSize,
363 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
364 : FeaturesAPI_RevolutionBoolean(theFeature)
367 fillAttribute(theBaseObjects, mybaseObjects);
368 fillAttribute(theAxis, myaxis);
369 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
370 fillAttribute(theSize, mytoAngle);
371 fillAttribute(ModelHighAPI_Double(), myfromAngle);
372 setBooleanObjects(theBooleanObjects);
376 //==================================================================================================
377 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
378 const std::shared_ptr<ModelAPI_Feature>& theFeature,
379 const std::list<ModelHighAPI_Selection>& theBaseObjects,
380 const ModelHighAPI_Selection& theAxis,
381 const ModelHighAPI_Double& theToAngle,
382 const ModelHighAPI_Double& theFromAngle,
383 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
384 : FeaturesAPI_RevolutionBoolean(theFeature)
387 fillAttribute(theBaseObjects, mybaseObjects);
388 fillAttribute(theAxis, myaxis);
389 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
390 fillAttribute(theToAngle, mytoAngle);
391 fillAttribute(theFromAngle, myfromAngle);
392 setBooleanObjects(theBooleanObjects);
396 //==================================================================================================
397 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
398 const std::shared_ptr<ModelAPI_Feature>& theFeature,
399 const std::list<ModelHighAPI_Selection>& theBaseObjects,
400 const ModelHighAPI_Selection& theAxis,
401 const ModelHighAPI_Selection& theToObject,
402 const ModelHighAPI_Double& theToOffset,
403 const ModelHighAPI_Selection& theFromObject,
404 const ModelHighAPI_Double& theFromOffset,
405 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
406 : FeaturesAPI_RevolutionBoolean(theFeature)
409 fillAttribute(theBaseObjects, mybaseObjects);
410 fillAttribute(theAxis, myaxis);
411 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
412 fillAttribute(theToObject, mytoObject);
413 fillAttribute(theToOffset, mytoOffset);
414 fillAttribute(theFromObject, myfromObject);
415 fillAttribute(theFromOffset, myfromOffset);
416 setBooleanObjects(theBooleanObjects);
420 //==================================================================================================
421 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
422 const std::list<ModelHighAPI_Selection>& theBaseObjects,
423 const ModelHighAPI_Selection& theAxis,
424 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
426 std::shared_ptr<ModelAPI_Feature> aFeature =
427 thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
428 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature, theBaseObjects,
429 theAxis, theBooleanObjects));
432 //==================================================================================================
433 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
434 const std::list<ModelHighAPI_Selection>& theBaseObjects,
435 const ModelHighAPI_Selection& theAxis,
436 const ModelHighAPI_Double& theSize,
437 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
439 std::shared_ptr<ModelAPI_Feature> aFeature =
440 thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
441 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature, theBaseObjects,
442 theAxis, theSize, theBooleanObjects));
445 //==================================================================================================
446 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
447 const std::list<ModelHighAPI_Selection>& theBaseObjects,
448 const ModelHighAPI_Selection& theAxis,
449 const ModelHighAPI_Double& theToAngle,
450 const ModelHighAPI_Double& theFromAngle,
451 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
453 std::shared_ptr<ModelAPI_Feature> aFeature =
454 thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
455 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,
463 //==================================================================================================
464 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
465 const std::list<ModelHighAPI_Selection>& theBaseObjects,
466 const ModelHighAPI_Selection& theAxis,
467 const ModelHighAPI_Selection& theToObject,
468 const ModelHighAPI_Double& theToOffset,
469 const ModelHighAPI_Selection& theFromObject,
470 const ModelHighAPI_Double& theFromOffset,
471 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
473 std::shared_ptr<ModelAPI_Feature> aFeature =
474 thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
475 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,