1 // Copyright (C) 2014-2019 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;
163 AttributeSelectionListPtr anAttrBoolObjects =
164 aBase->selectionList(FeaturesPlugin_CompositeBoolean::OBJECTS_ID());
165 theDumper << ", " << anAttrBoolObjects << ")" << std::endl;
167 if(anAttrSketch->isInitialized()) {
168 theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
172 //==================================================================================================
173 void FeaturesAPI_RevolutionBoolean::execIfBaseNotEmpty()
175 if(mybaseObjects->size() > 0) {
180 //==================================================================================================
181 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
182 const std::shared_ptr<ModelAPI_Feature>& theFeature)
183 : FeaturesAPI_RevolutionBoolean(theFeature)
188 //==================================================================================================
189 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
190 const std::shared_ptr<ModelAPI_Feature>& theFeature,
191 const std::list<ModelHighAPI_Selection>& theBaseObjects,
192 const ModelHighAPI_Selection& theAxis,
193 const ModelHighAPI_Double& theSize,
194 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
195 : FeaturesAPI_RevolutionBoolean(theFeature)
198 fillAttribute(theBaseObjects, mybaseObjects);
199 fillAttribute(theAxis, myaxis);
201 setBooleanObjects(theBooleanObjects);
205 //==================================================================================================
206 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
207 const std::shared_ptr<ModelAPI_Feature>& theFeature,
208 const std::list<ModelHighAPI_Selection>& theBaseObjects,
209 const ModelHighAPI_Selection& theAxis,
210 const ModelHighAPI_Double& theToAngle,
211 const ModelHighAPI_Double& theFromAngle,
212 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
213 : FeaturesAPI_RevolutionBoolean(theFeature)
216 fillAttribute(theBaseObjects, mybaseObjects);
217 fillAttribute(theAxis, myaxis);
218 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
219 fillAttribute(theToAngle, mytoAngle);
220 fillAttribute(theFromAngle, myfromAngle);
221 setBooleanObjects(theBooleanObjects);
225 //==================================================================================================
226 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
227 const std::shared_ptr<ModelAPI_Feature>& theFeature,
228 const std::list<ModelHighAPI_Selection>& theBaseObjects,
229 const ModelHighAPI_Selection& theAxis,
230 const ModelHighAPI_Selection& theToObject,
231 const ModelHighAPI_Double& theToOffset,
232 const ModelHighAPI_Selection& theFromObject,
233 const ModelHighAPI_Double& theFromOffset,
234 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
235 : FeaturesAPI_RevolutionBoolean(theFeature)
238 fillAttribute(theBaseObjects, mybaseObjects);
239 fillAttribute(theAxis, myaxis);
240 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
241 fillAttribute(theToObject, mytoObject);
242 fillAttribute(theToOffset, mytoOffset);
243 fillAttribute(theFromObject, myfromObject);
244 fillAttribute(theFromOffset, myfromOffset);
245 setBooleanObjects(theBooleanObjects);
249 //==================================================================================================
250 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
251 const std::list<ModelHighAPI_Selection>& theBaseObjects,
252 const ModelHighAPI_Selection& theAxis,
253 const ModelHighAPI_Double& theSize,
254 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
256 std::shared_ptr<ModelAPI_Feature> aFeature =
257 thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
258 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature, theBaseObjects,
259 theAxis, theSize, theBooleanObjects));
262 //==================================================================================================
263 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
264 const std::list<ModelHighAPI_Selection>& theBaseObjects,
265 const ModelHighAPI_Selection& theAxis,
266 const ModelHighAPI_Double& theToAngle,
267 const ModelHighAPI_Double& theFromAngle,
268 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
270 std::shared_ptr<ModelAPI_Feature> aFeature =
271 thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
272 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
280 //==================================================================================================
281 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
282 const std::list<ModelHighAPI_Selection>& theBaseObjects,
283 const ModelHighAPI_Selection& theAxis,
284 const ModelHighAPI_Selection& theToObject,
285 const ModelHighAPI_Double& theToOffset,
286 const ModelHighAPI_Selection& theFromObject,
287 const ModelHighAPI_Double& theFromOffset,
288 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
290 std::shared_ptr<ModelAPI_Feature> aFeature =
291 thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
292 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
303 //==================================================================================================
304 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
305 const std::shared_ptr<ModelAPI_Feature>& theFeature)
306 : FeaturesAPI_RevolutionBoolean(theFeature)
311 //==================================================================================================
312 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
313 const std::shared_ptr<ModelAPI_Feature>& theFeature,
314 const std::list<ModelHighAPI_Selection>& theBaseObjects,
315 const ModelHighAPI_Selection& theAxis,
316 const ModelHighAPI_Double& theSize,
317 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
318 : FeaturesAPI_RevolutionBoolean(theFeature)
321 fillAttribute(theBaseObjects, mybaseObjects);
322 fillAttribute(theAxis, myaxis);
323 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
324 fillAttribute(theSize, mytoAngle);
325 fillAttribute(ModelHighAPI_Double(), myfromAngle);
326 setBooleanObjects(theBooleanObjects);
330 //==================================================================================================
331 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
332 const std::shared_ptr<ModelAPI_Feature>& theFeature,
333 const std::list<ModelHighAPI_Selection>& theBaseObjects,
334 const ModelHighAPI_Selection& theAxis,
335 const ModelHighAPI_Double& theToAngle,
336 const ModelHighAPI_Double& theFromAngle,
337 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
338 : FeaturesAPI_RevolutionBoolean(theFeature)
341 fillAttribute(theBaseObjects, mybaseObjects);
342 fillAttribute(theAxis, myaxis);
343 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
344 fillAttribute(theToAngle, mytoAngle);
345 fillAttribute(theFromAngle, myfromAngle);
346 setBooleanObjects(theBooleanObjects);
350 //==================================================================================================
351 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
352 const std::shared_ptr<ModelAPI_Feature>& theFeature,
353 const std::list<ModelHighAPI_Selection>& theBaseObjects,
354 const ModelHighAPI_Selection& theAxis,
355 const ModelHighAPI_Selection& theToObject,
356 const ModelHighAPI_Double& theToOffset,
357 const ModelHighAPI_Selection& theFromObject,
358 const ModelHighAPI_Double& theFromOffset,
359 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
360 : FeaturesAPI_RevolutionBoolean(theFeature)
363 fillAttribute(theBaseObjects, mybaseObjects);
364 fillAttribute(theAxis, myaxis);
365 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
366 fillAttribute(theToObject, mytoObject);
367 fillAttribute(theToOffset, mytoOffset);
368 fillAttribute(theFromObject, myfromObject);
369 fillAttribute(theFromOffset, myfromOffset);
370 setBooleanObjects(theBooleanObjects);
374 //==================================================================================================
375 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
376 const std::list<ModelHighAPI_Selection>& theBaseObjects,
377 const ModelHighAPI_Selection& theAxis,
378 const ModelHighAPI_Double& theSize,
379 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
381 std::shared_ptr<ModelAPI_Feature> aFeature =
382 thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
383 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature, theBaseObjects,
384 theAxis, theSize, theBooleanObjects));
387 //==================================================================================================
388 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
389 const std::list<ModelHighAPI_Selection>& theBaseObjects,
390 const ModelHighAPI_Selection& theAxis,
391 const ModelHighAPI_Double& theToAngle,
392 const ModelHighAPI_Double& theFromAngle,
393 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
395 std::shared_ptr<ModelAPI_Feature> aFeature =
396 thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
397 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,
405 //==================================================================================================
406 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
407 const std::list<ModelHighAPI_Selection>& theBaseObjects,
408 const ModelHighAPI_Selection& theAxis,
409 const ModelHighAPI_Selection& theToObject,
410 const ModelHighAPI_Double& theToOffset,
411 const ModelHighAPI_Selection& theFromObject,
412 const ModelHighAPI_Double& theFromOffset,
413 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
415 std::shared_ptr<ModelAPI_Feature> aFeature =
416 thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
417 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,