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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "FeaturesAPI_RevolutionBoolean.h"
23 #include <ModelHighAPI_Double.h>
24 #include <ModelHighAPI_Dumper.h>
25 #include <ModelHighAPI_Reference.h>
26 #include <ModelHighAPI_Tools.h>
28 //==================================================================================================
29 FeaturesAPI_RevolutionBoolean::FeaturesAPI_RevolutionBoolean(
30 const std::shared_ptr<ModelAPI_Feature>& theFeature)
31 : ModelHighAPI_Interface(theFeature)
35 //==================================================================================================
36 FeaturesAPI_RevolutionBoolean::~FeaturesAPI_RevolutionBoolean()
40 //==================================================================================================
41 void FeaturesAPI_RevolutionBoolean::setNestedSketch(const ModelHighAPI_Reference& theSketch)
43 mysketch->setValue(theSketch.feature());
45 // To make Sketch feature execute and subfeatures execute.
46 feature()->document()->setCurrentFeature(feature(), false);
48 // to inform that the history is updated due to the sketch moved under the composite feature
49 if (theSketch.feature().get()) {
50 theSketch.feature()->document()->updateHistory(ModelAPI_Feature::group());
51 if (theSketch.feature()->firstResult().get())
52 theSketch.feature()->firstResult()->setDisplayed(false);
54 mybaseObjects->clear();
55 mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
60 //==================================================================================================
61 void FeaturesAPI_RevolutionBoolean::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
63 mysketch->setValue(ObjectPtr());
64 mybaseObjects->clear();
65 fillAttribute(theBaseObjects, mybaseObjects);
70 //==================================================================================================
71 void FeaturesAPI_RevolutionBoolean::setAxis(const ModelHighAPI_Selection& theAxis)
73 fillAttribute(theAxis, myaxis);
78 //==================================================================================================
79 void FeaturesAPI_RevolutionBoolean::setAngles(const ModelHighAPI_Double& theToAngle,
80 const ModelHighAPI_Double& theFromAngle)
82 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
83 fillAttribute(theToAngle, mytoAngle);
84 fillAttribute(theFromAngle, myfromAngle);
89 //==================================================================================================
90 void FeaturesAPI_RevolutionBoolean::setAngle(const ModelHighAPI_Double& theAngle)
92 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
93 fillAttribute(theAngle, mytoAngle);
94 fillAttribute(ModelHighAPI_Double(), myfromAngle);
99 //==================================================================================================
100 void FeaturesAPI_RevolutionBoolean::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
101 const ModelHighAPI_Double& theToOffset,
102 const ModelHighAPI_Selection& theFromObject,
103 const ModelHighAPI_Double& theFromOffset)
105 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
106 fillAttribute(theToObject, mytoObject);
107 fillAttribute(theToOffset, mytoOffset);
108 fillAttribute(theFromObject, myfromObject);
109 fillAttribute(theFromOffset, myfromOffset);
111 execIfBaseNotEmpty();
114 //==================================================================================================
115 void FeaturesAPI_RevolutionBoolean::setBooleanObjects(
116 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
118 fillAttribute(theBooleanObjects, mybooleanObjects);
120 execIfBaseNotEmpty();
123 //==================================================================================================
124 void FeaturesAPI_RevolutionBoolean::dump(ModelHighAPI_Dumper& theDumper) const
126 FeaturePtr aBase = feature();
127 const std::string& aDocName = theDumper.name(aBase->document());
129 AttributeReferencePtr anAttrSketch =
130 aBase->reference(FeaturesPlugin_Revolution::SKETCH_ID());
131 AttributeSelectionListPtr anAttrObjects =
132 aBase->selectionList(FeaturesPlugin_Revolution::BASE_OBJECTS_ID());
133 AttributeSelectionPtr anAttrAxis =
134 aBase->selection(FeaturesPlugin_Revolution::AXIS_OBJECT_ID());
136 theDumper << aBase << " = model.addRevolution";
137 if(aBase->getKind() == FeaturesPlugin_RevolutionCut::ID()) {
139 } else if(aBase->getKind() == FeaturesPlugin_RevolutionFuse::ID()) {
142 theDumper << "(" << aDocName << ", ";
143 anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
144 theDumper << ", " << anAttrAxis;
146 std::string aCreationMethod =
147 aBase->string(FeaturesPlugin_Revolution::CREATION_METHOD())->value();
149 if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES()) {
150 AttributeDoublePtr anAttrToAngle = aBase->real(FeaturesPlugin_Revolution::TO_ANGLE_ID());
151 AttributeDoublePtr anAttrFromAngle = aBase->real(FeaturesPlugin_Revolution::FROM_ANGLE_ID());
153 theDumper << ", " << anAttrToAngle << ", " << anAttrFromAngle;
154 } else if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES()) {
155 AttributeSelectionPtr anAttrToObject =
156 aBase->selection(FeaturesPlugin_Revolution::TO_OBJECT_ID());
157 AttributeDoublePtr anAttrToOffset =
158 aBase->real(FeaturesPlugin_Revolution::TO_OFFSET_ID());
159 AttributeSelectionPtr anAttrFromObject =
160 aBase->selection(FeaturesPlugin_Revolution::FROM_OBJECT_ID());
161 AttributeDoublePtr anAttrFromOffset =
162 aBase->real(FeaturesPlugin_Revolution::FROM_OFFSET_ID());
164 theDumper << ", " << anAttrToObject << ", " << anAttrToOffset <<
165 ", " << anAttrFromObject << ", " << anAttrFromOffset;
168 AttributeSelectionListPtr anAttrBoolObjects =
169 aBase->selectionList(FeaturesPlugin_CompositeBoolean::OBJECTS_ID());
170 theDumper << ", " << anAttrBoolObjects << ")" << std::endl;
172 if(anAttrSketch->isInitialized()) {
173 theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
177 //==================================================================================================
178 void FeaturesAPI_RevolutionBoolean::execIfBaseNotEmpty()
180 if(mybaseObjects->size() > 0) {
185 //==================================================================================================
186 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
187 const std::shared_ptr<ModelAPI_Feature>& theFeature)
188 : FeaturesAPI_RevolutionBoolean(theFeature)
193 //==================================================================================================
194 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
195 const std::shared_ptr<ModelAPI_Feature>& theFeature,
196 const std::list<ModelHighAPI_Selection>& theBaseObjects,
197 const ModelHighAPI_Selection& theAxis,
198 const ModelHighAPI_Double& theSize,
199 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
200 : FeaturesAPI_RevolutionBoolean(theFeature)
203 fillAttribute(theBaseObjects, mybaseObjects);
204 fillAttribute(theAxis, myaxis);
205 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
206 fillAttribute(theSize, mytoAngle);
207 fillAttribute(ModelHighAPI_Double(), myfromAngle);
208 setBooleanObjects(theBooleanObjects);
212 //==================================================================================================
213 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
214 const std::shared_ptr<ModelAPI_Feature>& theFeature,
215 const std::list<ModelHighAPI_Selection>& theBaseObjects,
216 const ModelHighAPI_Selection& theAxis,
217 const ModelHighAPI_Double& theToAngle,
218 const ModelHighAPI_Double& theFromAngle,
219 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
220 : FeaturesAPI_RevolutionBoolean(theFeature)
223 fillAttribute(theBaseObjects, mybaseObjects);
224 fillAttribute(theAxis, myaxis);
225 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
226 fillAttribute(theToAngle, mytoAngle);
227 fillAttribute(theFromAngle, myfromAngle);
228 setBooleanObjects(theBooleanObjects);
232 //==================================================================================================
233 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
234 const std::shared_ptr<ModelAPI_Feature>& theFeature,
235 const std::list<ModelHighAPI_Selection>& theBaseObjects,
236 const ModelHighAPI_Selection& theAxis,
237 const ModelHighAPI_Selection& theToObject,
238 const ModelHighAPI_Double& theToOffset,
239 const ModelHighAPI_Selection& theFromObject,
240 const ModelHighAPI_Double& theFromOffset,
241 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
242 : FeaturesAPI_RevolutionBoolean(theFeature)
245 fillAttribute(theBaseObjects, mybaseObjects);
246 fillAttribute(theAxis, myaxis);
247 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
248 fillAttribute(theToObject, mytoObject);
249 fillAttribute(theToOffset, mytoOffset);
250 fillAttribute(theFromObject, myfromObject);
251 fillAttribute(theFromOffset, myfromOffset);
252 setBooleanObjects(theBooleanObjects);
256 //==================================================================================================
257 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
258 const std::list<ModelHighAPI_Selection>& theBaseObjects,
259 const ModelHighAPI_Selection& theAxis,
260 const ModelHighAPI_Double& theSize,
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, theBaseObjects,
266 theAxis, theSize, theBooleanObjects));
269 //==================================================================================================
270 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
271 const std::list<ModelHighAPI_Selection>& theBaseObjects,
272 const ModelHighAPI_Selection& theAxis,
273 const ModelHighAPI_Double& theToAngle,
274 const ModelHighAPI_Double& theFromAngle,
275 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
277 std::shared_ptr<ModelAPI_Feature> aFeature =
278 thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
279 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
287 //==================================================================================================
288 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
289 const std::list<ModelHighAPI_Selection>& theBaseObjects,
290 const ModelHighAPI_Selection& theAxis,
291 const ModelHighAPI_Selection& theToObject,
292 const ModelHighAPI_Double& theToOffset,
293 const ModelHighAPI_Selection& theFromObject,
294 const ModelHighAPI_Double& theFromOffset,
295 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
297 std::shared_ptr<ModelAPI_Feature> aFeature =
298 thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
299 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
310 //==================================================================================================
311 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
312 const std::shared_ptr<ModelAPI_Feature>& theFeature)
313 : FeaturesAPI_RevolutionBoolean(theFeature)
318 //==================================================================================================
319 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
320 const std::shared_ptr<ModelAPI_Feature>& theFeature,
321 const std::list<ModelHighAPI_Selection>& theBaseObjects,
322 const ModelHighAPI_Selection& theAxis,
323 const ModelHighAPI_Double& theSize,
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_ANGLES(), mycreationMethod);
331 fillAttribute(theSize, mytoAngle);
332 fillAttribute(ModelHighAPI_Double(), myfromAngle);
333 setBooleanObjects(theBooleanObjects);
337 //==================================================================================================
338 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
339 const std::shared_ptr<ModelAPI_Feature>& theFeature,
340 const std::list<ModelHighAPI_Selection>& theBaseObjects,
341 const ModelHighAPI_Selection& theAxis,
342 const ModelHighAPI_Double& theToAngle,
343 const ModelHighAPI_Double& theFromAngle,
344 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
345 : FeaturesAPI_RevolutionBoolean(theFeature)
348 fillAttribute(theBaseObjects, mybaseObjects);
349 fillAttribute(theAxis, myaxis);
350 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
351 fillAttribute(theToAngle, mytoAngle);
352 fillAttribute(theFromAngle, myfromAngle);
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_Selection& theToObject,
363 const ModelHighAPI_Double& theToOffset,
364 const ModelHighAPI_Selection& theFromObject,
365 const ModelHighAPI_Double& theFromOffset,
366 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
367 : FeaturesAPI_RevolutionBoolean(theFeature)
370 fillAttribute(theBaseObjects, mybaseObjects);
371 fillAttribute(theAxis, myaxis);
372 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
373 fillAttribute(theToObject, mytoObject);
374 fillAttribute(theToOffset, mytoOffset);
375 fillAttribute(theFromObject, myfromObject);
376 fillAttribute(theFromOffset, myfromOffset);
377 setBooleanObjects(theBooleanObjects);
381 //==================================================================================================
382 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
383 const std::list<ModelHighAPI_Selection>& theBaseObjects,
384 const ModelHighAPI_Selection& theAxis,
385 const ModelHighAPI_Double& theSize,
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, theBaseObjects,
391 theAxis, theSize, theBooleanObjects));
394 //==================================================================================================
395 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
396 const std::list<ModelHighAPI_Selection>& theBaseObjects,
397 const ModelHighAPI_Selection& theAxis,
398 const ModelHighAPI_Double& theToAngle,
399 const ModelHighAPI_Double& theFromAngle,
400 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
402 std::shared_ptr<ModelAPI_Feature> aFeature =
403 thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
404 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,
412 //==================================================================================================
413 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
414 const std::list<ModelHighAPI_Selection>& theBaseObjects,
415 const ModelHighAPI_Selection& theAxis,
416 const ModelHighAPI_Selection& theToObject,
417 const ModelHighAPI_Double& theToOffset,
418 const ModelHighAPI_Selection& theFromObject,
419 const ModelHighAPI_Double& theFromOffset,
420 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
422 std::shared_ptr<ModelAPI_Feature> aFeature =
423 thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
424 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,