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 setAngles(theAngle, ModelHighAPI_Double());
95 //==================================================================================================
96 void FeaturesAPI_RevolutionBoolean::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
97 const ModelHighAPI_Double& theToOffset,
98 const ModelHighAPI_Selection& theFromObject,
99 const ModelHighAPI_Double& theFromOffset)
101 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
102 fillAttribute(theToObject, mytoObject);
103 fillAttribute(theToOffset, mytoOffset);
104 fillAttribute(theFromObject, myfromObject);
105 fillAttribute(theFromOffset, myfromOffset);
107 execIfBaseNotEmpty();
110 //==================================================================================================
111 void FeaturesAPI_RevolutionBoolean::setBooleanObjects(
112 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
114 fillAttribute(theBooleanObjects, mybooleanObjects);
116 execIfBaseNotEmpty();
119 //==================================================================================================
120 void FeaturesAPI_RevolutionBoolean::dump(ModelHighAPI_Dumper& theDumper) const
122 FeaturePtr aBase = feature();
123 const std::string& aDocName = theDumper.name(aBase->document());
125 AttributeReferencePtr anAttrSketch =
126 aBase->reference(FeaturesPlugin_Revolution::SKETCH_ID());
127 AttributeSelectionListPtr anAttrObjects =
128 aBase->selectionList(FeaturesPlugin_Revolution::BASE_OBJECTS_ID());
129 AttributeSelectionPtr anAttrAxis =
130 aBase->selection(FeaturesPlugin_Revolution::AXIS_OBJECT_ID());
132 theDumper << aBase << " = model.addRevolution";
133 if(aBase->getKind() == FeaturesPlugin_RevolutionCut::ID()) {
135 } else if(aBase->getKind() == FeaturesPlugin_RevolutionFuse::ID()) {
138 theDumper << "(" << aDocName << ", ";
139 anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
140 theDumper << ", " << anAttrAxis;
142 std::string aCreationMethod =
143 aBase->string(FeaturesPlugin_Revolution::CREATION_METHOD())->value();
145 if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES()) {
146 AttributeDoublePtr anAttrToAngle = aBase->real(FeaturesPlugin_Revolution::TO_ANGLE_ID());
147 AttributeDoublePtr anAttrFromAngle = aBase->real(FeaturesPlugin_Revolution::FROM_ANGLE_ID());
149 theDumper << ", " << anAttrToAngle << ", " << anAttrFromAngle;
150 } else if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES()) {
151 AttributeSelectionPtr anAttrToObject =
152 aBase->selection(FeaturesPlugin_Revolution::TO_OBJECT_ID());
153 AttributeDoublePtr anAttrToOffset =
154 aBase->real(FeaturesPlugin_Revolution::TO_OFFSET_ID());
155 AttributeSelectionPtr anAttrFromObject =
156 aBase->selection(FeaturesPlugin_Revolution::FROM_OBJECT_ID());
157 AttributeDoublePtr anAttrFromOffset =
158 aBase->real(FeaturesPlugin_Revolution::FROM_OFFSET_ID());
160 theDumper << ", " << anAttrToObject << ", " << anAttrToOffset <<
161 ", " << anAttrFromObject << ", " << anAttrFromOffset;
164 AttributeSelectionListPtr anAttrBoolObjects =
165 aBase->selectionList(FeaturesPlugin_CompositeBoolean::OBJECTS_ID());
166 theDumper << ", " << anAttrBoolObjects << ")" << std::endl;
168 if(anAttrSketch->isInitialized()) {
169 theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
173 //==================================================================================================
174 void FeaturesAPI_RevolutionBoolean::execIfBaseNotEmpty()
176 if(mybaseObjects->size() > 0) {
181 //==================================================================================================
182 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
183 const std::shared_ptr<ModelAPI_Feature>& theFeature)
184 : FeaturesAPI_RevolutionBoolean(theFeature)
189 //==================================================================================================
190 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
191 const std::shared_ptr<ModelAPI_Feature>& theFeature,
192 const std::list<ModelHighAPI_Selection>& theBaseObjects,
193 const ModelHighAPI_Selection& theAxis,
194 const ModelHighAPI_Double& theSize,
195 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
196 : FeaturesAPI_RevolutionBoolean(theFeature)
199 fillAttribute(theBaseObjects, mybaseObjects);
200 fillAttribute(theAxis, myaxis);
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& theToAngle,
212 const ModelHighAPI_Double& theFromAngle,
213 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
214 : FeaturesAPI_RevolutionBoolean(theFeature)
217 fillAttribute(theBaseObjects, mybaseObjects);
218 fillAttribute(theAxis, myaxis);
219 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
220 fillAttribute(theToAngle, mytoAngle);
221 fillAttribute(theFromAngle, myfromAngle);
222 setBooleanObjects(theBooleanObjects);
226 //==================================================================================================
227 FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(
228 const std::shared_ptr<ModelAPI_Feature>& theFeature,
229 const std::list<ModelHighAPI_Selection>& theBaseObjects,
230 const ModelHighAPI_Selection& theAxis,
231 const ModelHighAPI_Selection& theToObject,
232 const ModelHighAPI_Double& theToOffset,
233 const ModelHighAPI_Selection& theFromObject,
234 const ModelHighAPI_Double& theFromOffset,
235 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
236 : FeaturesAPI_RevolutionBoolean(theFeature)
239 fillAttribute(theBaseObjects, mybaseObjects);
240 fillAttribute(theAxis, myaxis);
241 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
242 fillAttribute(theToObject, mytoObject);
243 fillAttribute(theToOffset, mytoOffset);
244 fillAttribute(theFromObject, myfromObject);
245 fillAttribute(theFromOffset, myfromOffset);
246 setBooleanObjects(theBooleanObjects);
250 //==================================================================================================
251 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
252 const std::list<ModelHighAPI_Selection>& theBaseObjects,
253 const ModelHighAPI_Selection& theAxis,
254 const ModelHighAPI_Double& theSize,
255 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
257 std::shared_ptr<ModelAPI_Feature> aFeature =
258 thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
259 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature, theBaseObjects,
260 theAxis, theSize, theBooleanObjects));
263 //==================================================================================================
264 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
265 const std::list<ModelHighAPI_Selection>& theBaseObjects,
266 const ModelHighAPI_Selection& theAxis,
267 const ModelHighAPI_Double& theToAngle,
268 const ModelHighAPI_Double& theFromAngle,
269 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
271 std::shared_ptr<ModelAPI_Feature> aFeature =
272 thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
273 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
281 //==================================================================================================
282 RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& thePart,
283 const std::list<ModelHighAPI_Selection>& theBaseObjects,
284 const ModelHighAPI_Selection& theAxis,
285 const ModelHighAPI_Selection& theToObject,
286 const ModelHighAPI_Double& theToOffset,
287 const ModelHighAPI_Selection& theFromObject,
288 const ModelHighAPI_Double& theFromOffset,
289 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
291 std::shared_ptr<ModelAPI_Feature> aFeature =
292 thePart->addFeature(FeaturesPlugin_RevolutionCut::ID());
293 return RevolutionCutPtr(new FeaturesAPI_RevolutionCut(aFeature,
304 //==================================================================================================
305 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
306 const std::shared_ptr<ModelAPI_Feature>& theFeature)
307 : FeaturesAPI_RevolutionBoolean(theFeature)
312 //==================================================================================================
313 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
314 const std::shared_ptr<ModelAPI_Feature>& theFeature,
315 const std::list<ModelHighAPI_Selection>& theBaseObjects,
316 const ModelHighAPI_Selection& theAxis,
317 const ModelHighAPI_Double& theSize,
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_ANGLES(), mycreationMethod);
325 fillAttribute(theSize, mytoAngle);
326 fillAttribute(ModelHighAPI_Double(), myfromAngle);
327 setBooleanObjects(theBooleanObjects);
331 //==================================================================================================
332 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
333 const std::shared_ptr<ModelAPI_Feature>& theFeature,
334 const std::list<ModelHighAPI_Selection>& theBaseObjects,
335 const ModelHighAPI_Selection& theAxis,
336 const ModelHighAPI_Double& theToAngle,
337 const ModelHighAPI_Double& theFromAngle,
338 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
339 : FeaturesAPI_RevolutionBoolean(theFeature)
342 fillAttribute(theBaseObjects, mybaseObjects);
343 fillAttribute(theAxis, myaxis);
344 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
345 fillAttribute(theToAngle, mytoAngle);
346 fillAttribute(theFromAngle, myfromAngle);
347 setBooleanObjects(theBooleanObjects);
351 //==================================================================================================
352 FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(
353 const std::shared_ptr<ModelAPI_Feature>& theFeature,
354 const std::list<ModelHighAPI_Selection>& theBaseObjects,
355 const ModelHighAPI_Selection& theAxis,
356 const ModelHighAPI_Selection& theToObject,
357 const ModelHighAPI_Double& theToOffset,
358 const ModelHighAPI_Selection& theFromObject,
359 const ModelHighAPI_Double& theFromOffset,
360 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
361 : FeaturesAPI_RevolutionBoolean(theFeature)
364 fillAttribute(theBaseObjects, mybaseObjects);
365 fillAttribute(theAxis, myaxis);
366 fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
367 fillAttribute(theToObject, mytoObject);
368 fillAttribute(theToOffset, mytoOffset);
369 fillAttribute(theFromObject, myfromObject);
370 fillAttribute(theFromOffset, myfromOffset);
371 setBooleanObjects(theBooleanObjects);
375 //==================================================================================================
376 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
377 const std::list<ModelHighAPI_Selection>& theBaseObjects,
378 const ModelHighAPI_Selection& theAxis,
379 const ModelHighAPI_Double& theSize,
380 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
382 std::shared_ptr<ModelAPI_Feature> aFeature =
383 thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
384 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature, theBaseObjects,
385 theAxis, theSize, theBooleanObjects));
388 //==================================================================================================
389 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
390 const std::list<ModelHighAPI_Selection>& theBaseObjects,
391 const ModelHighAPI_Selection& theAxis,
392 const ModelHighAPI_Double& theToAngle,
393 const ModelHighAPI_Double& theFromAngle,
394 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
396 std::shared_ptr<ModelAPI_Feature> aFeature =
397 thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
398 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,
406 //==================================================================================================
407 RevolutionFusePtr addRevolutionFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
408 const std::list<ModelHighAPI_Selection>& theBaseObjects,
409 const ModelHighAPI_Selection& theAxis,
410 const ModelHighAPI_Selection& theToObject,
411 const ModelHighAPI_Double& theToOffset,
412 const ModelHighAPI_Selection& theFromObject,
413 const ModelHighAPI_Double& theFromOffset,
414 const std::list<ModelHighAPI_Selection>& theBooleanObjects)
416 std::shared_ptr<ModelAPI_Feature> aFeature =
417 thePart->addFeature(FeaturesPlugin_RevolutionFuse::ID());
418 return RevolutionFusePtr(new FeaturesAPI_RevolutionFuse(aFeature,