1 // Copyright (C) 2014-2017 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<mailto: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 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
92 fillAttribute(theAngle, mytoAngle);
93 fillAttribute(ModelHighAPI_Double(), myfromAngle);
98 //==================================================================================================
99 void FeaturesAPI_RevolutionBoolean::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
100 const ModelHighAPI_Double& theToOffset,
101 const ModelHighAPI_Selection& theFromObject,
102 const ModelHighAPI_Double& theFromOffset)
104 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
105 fillAttribute(theToObject, mytoObject);
106 fillAttribute(theToOffset, mytoOffset);
107 fillAttribute(theFromObject, myfromObject);
108 fillAttribute(theFromOffset, myfromOffset);
110 execIfBaseNotEmpty();
113 //==================================================================================================
114 void FeaturesAPI_RevolutionBoolean::setBooleanObjects(
115 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
117 fillAttribute(theBooleanObjects, mybooleanObjects);
119 execIfBaseNotEmpty();
122 //==================================================================================================
123 void FeaturesAPI_RevolutionBoolean::dump(ModelHighAPI_Dumper& theDumper) const
125 FeaturePtr aBase = feature();
126 const std::string& aDocName = theDumper.name(aBase->document());
128 AttributeReferencePtr anAttrSketch =
129 aBase->reference(FeaturesPlugin_Revolution::SKETCH_ID());
130 AttributeSelectionListPtr anAttrObjects =
131 aBase->selectionList(FeaturesPlugin_Revolution::BASE_OBJECTS_ID());
132 AttributeSelectionPtr anAttrAxis =
133 aBase->selection(FeaturesPlugin_Revolution::AXIS_OBJECT_ID());
135 theDumper << aBase << " = model.addRevolution";
136 if(aBase->getKind() == FeaturesPlugin_RevolutionCut::ID()) {
138 } else if(aBase->getKind() == FeaturesPlugin_RevolutionFuse::ID()) {
141 theDumper << "(" << aDocName << ", ";
142 anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
143 theDumper << ", " << anAttrAxis;
145 std::string aCreationMethod =
146 aBase->string(FeaturesPlugin_Revolution::CREATION_METHOD())->value();
148 if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES()) {
149 AttributeDoublePtr anAttrToAngle = aBase->real(FeaturesPlugin_Revolution::TO_ANGLE_ID());
150 AttributeDoublePtr anAttrFromAngle = aBase->real(FeaturesPlugin_Revolution::FROM_ANGLE_ID());
152 theDumper << ", " << anAttrToAngle << ", " << anAttrFromAngle;
153 } else if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES()) {
154 AttributeSelectionPtr anAttrToObject =
155 aBase->selection(FeaturesPlugin_Revolution::TO_OBJECT_ID());
156 AttributeDoublePtr anAttrToOffset =
157 aBase->real(FeaturesPlugin_Revolution::TO_OFFSET_ID());
158 AttributeSelectionPtr anAttrFromObject =
159 aBase->selection(FeaturesPlugin_Revolution::FROM_OBJECT_ID());
160 AttributeDoublePtr anAttrFromOffset =
161 aBase->real(FeaturesPlugin_Revolution::FROM_OFFSET_ID());
163 theDumper << ", " << anAttrToObject << ", " << anAttrToOffset <<
164 ", " << anAttrFromObject << ", " << anAttrFromOffset;
167 AttributeSelectionListPtr anAttrBoolObjects =
168 aBase->selectionList(FeaturesPlugin_CompositeBoolean::OBJECTS_ID());
169 theDumper << ", " << anAttrBoolObjects << ")" << std::endl;
171 if(anAttrSketch->isInitialized()) {
172 theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
176 //==================================================================================================
177 void FeaturesAPI_RevolutionBoolean::execIfBaseNotEmpty()
179 if(mybaseObjects->size() > 0) {
184 //==================================================================================================
185 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
186 const std::shared_ptr<ModelAPI_Feature>& theFeature)
187 : FeaturesAPI_RevolutionBoolean(theFeature)
192 //==================================================================================================
193 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
194 const std::shared_ptr<ModelAPI_Feature>& theFeature,
195 const std::list<ModelHighAPI_Selection>& theBaseObjects,
196 const ModelHighAPI_Selection& theAxis,
197 const ModelHighAPI_Double& theSize,
198 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
199 : FeaturesAPI_RevolutionBoolean(theFeature)
202 fillAttribute(theBaseObjects, mybaseObjects);
203 fillAttribute(theAxis, myaxis);
204 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
205 fillAttribute(theSize, mytoAngle);
206 fillAttribute(ModelHighAPI_Double(), myfromAngle);
207 setBooleanObjects(theBooleanObjects);
211 //==================================================================================================
212 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
213 const std::shared_ptr<ModelAPI_Feature>& theFeature,
214 const std::list<ModelHighAPI_Selection>& theBaseObjects,
215 const ModelHighAPI_Selection& theAxis,
216 const ModelHighAPI_Double& theToAngle,
217 const ModelHighAPI_Double& theFromAngle,
218 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
219 : FeaturesAPI_RevolutionBoolean(theFeature)
222 fillAttribute(theBaseObjects, mybaseObjects);
223 fillAttribute(theAxis, myaxis);
224 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
225 fillAttribute(theToAngle, mytoAngle);
226 fillAttribute(theFromAngle, myfromAngle);
227 setBooleanObjects(theBooleanObjects);
231 //==================================================================================================
232 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
233 const std::shared_ptr<ModelAPI_Feature>& theFeature,
234 const std::list<ModelHighAPI_Selection>& theBaseObjects,
235 const ModelHighAPI_Selection& theAxis,
236 const ModelHighAPI_Selection& theToObject,
237 const ModelHighAPI_Double& theToOffset,
238 const ModelHighAPI_Selection& theFromObject,
239 const ModelHighAPI_Double& theFromOffset,
240 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
241 : FeaturesAPI_RevolutionBoolean(theFeature)
244 fillAttribute(theBaseObjects, mybaseObjects);
245 fillAttribute(theAxis, myaxis);
246 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
247 fillAttribute(theToObject, mytoObject);
248 fillAttribute(theToOffset, mytoOffset);
249 fillAttribute(theFromObject, myfromObject);
250 fillAttribute(theFromOffset, myfromOffset);
251 setBooleanObjects(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& theSize,
260 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
262 std::shared_ptr<ModelAPI_Feature> aFeature =
263 thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
264 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature, theBaseObjects,
265 theAxis, theSize, theBooleanObjects));
268 //==================================================================================================
269 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
270 const std::list<ModelHighAPI_Selection>& theBaseObjects,
271 const ModelHighAPI_Selection& theAxis,
272 const ModelHighAPI_Double& theToAngle,
273 const ModelHighAPI_Double& theFromAngle,
274 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
276 std::shared_ptr<ModelAPI_Feature> aFeature =
277 thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
278 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
286 //==================================================================================================
287 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
288 const std::list<ModelHighAPI_Selection>& theBaseObjects,
289 const ModelHighAPI_Selection& theAxis,
290 const ModelHighAPI_Selection& theToObject,
291 const ModelHighAPI_Double& theToOffset,
292 const ModelHighAPI_Selection& theFromObject,
293 const ModelHighAPI_Double& theFromOffset,
294 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
296 std::shared_ptr<ModelAPI_Feature> aFeature =
297 thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
298 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
309 //==================================================================================================
310 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
311 const std::shared_ptr<ModelAPI_Feature>& theFeature)
312 : FeaturesAPI_RevolutionBoolean(theFeature)
317 //==================================================================================================
318 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
319 const std::shared_ptr<ModelAPI_Feature>& theFeature,
320 const std::list<ModelHighAPI_Selection>& theBaseObjects,
321 const ModelHighAPI_Selection& theAxis,
322 const ModelHighAPI_Double& theSize,
323 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
324 : FeaturesAPI_RevolutionBoolean(theFeature)
327 fillAttribute(theBaseObjects, mybaseObjects);
328 fillAttribute(theAxis, myaxis);
329 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
330 fillAttribute(theSize, mytoAngle);
331 fillAttribute(ModelHighAPI_Double(), myfromAngle);
332 setBooleanObjects(theBooleanObjects);
336 //==================================================================================================
337 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
338 const std::shared_ptr<ModelAPI_Feature>& theFeature,
339 const std::list<ModelHighAPI_Selection>& theBaseObjects,
340 const ModelHighAPI_Selection& theAxis,
341 const ModelHighAPI_Double& theToAngle,
342 const ModelHighAPI_Double& theFromAngle,
343 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
344 : FeaturesAPI_RevolutionBoolean(theFeature)
347 fillAttribute(theBaseObjects, mybaseObjects);
348 fillAttribute(theAxis, myaxis);
349 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
350 fillAttribute(theToAngle, mytoAngle);
351 fillAttribute(theFromAngle, myfromAngle);
352 setBooleanObjects(theBooleanObjects);
356 //==================================================================================================
357 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
358 const std::shared_ptr<ModelAPI_Feature>& theFeature,
359 const std::list<ModelHighAPI_Selection>& theBaseObjects,
360 const ModelHighAPI_Selection& theAxis,
361 const ModelHighAPI_Selection& theToObject,
362 const ModelHighAPI_Double& theToOffset,
363 const ModelHighAPI_Selection& theFromObject,
364 const ModelHighAPI_Double& theFromOffset,
365 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
366 : FeaturesAPI_RevolutionBoolean(theFeature)
369 fillAttribute(theBaseObjects, mybaseObjects);
370 fillAttribute(theAxis, myaxis);
371 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
372 fillAttribute(theToObject, mytoObject);
373 fillAttribute(theToOffset, mytoOffset);
374 fillAttribute(theFromObject, myfromObject);
375 fillAttribute(theFromOffset, myfromOffset);
376 setBooleanObjects(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& theSize,
385 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
387 std::shared_ptr<ModelAPI_Feature> aFeature =
388 thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
389 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature, theBaseObjects,
390 theAxis, theSize, theBooleanObjects));
393 //==================================================================================================
394 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
395 const std::list<ModelHighAPI_Selection>& theBaseObjects,
396 const ModelHighAPI_Selection& theAxis,
397 const ModelHighAPI_Double& theToAngle,
398 const ModelHighAPI_Double& theFromAngle,
399 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
401 std::shared_ptr<ModelAPI_Feature> aFeature =
402 thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
403 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,
411 //==================================================================================================
412 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
413 const std::list<ModelHighAPI_Selection>& theBaseObjects,
414 const ModelHighAPI_Selection& theAxis,
415 const ModelHighAPI_Selection& theToObject,
416 const ModelHighAPI_Double& theToOffset,
417 const ModelHighAPI_Selection& theFromObject,
418 const ModelHighAPI_Double& theFromOffset,
419 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
421 std::shared_ptr<ModelAPI_Feature> aFeature =
422 thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
423 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,