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_Extrusion.h"
22 #include <ModelHighAPI_Double.h>
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Reference.h>
25 #include <ModelHighAPI_Tools.h>
27 //==================================================================================================
28 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature)
29 : ModelHighAPI_Interface(theFeature)
34 //==================================================================================================
35 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
36 const std::list<ModelHighAPI_Selection>& theBaseObjects,
37 const ModelHighAPI_Double& theSize)
38 : ModelHighAPI_Interface(theFeature)
41 fillAttribute(theBaseObjects, mybaseObjects);
42 setSizes(theSize, ModelHighAPI_Double());
46 //==================================================================================================
47 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
48 const std::list<ModelHighAPI_Selection>& theBaseObjects,
49 const ModelHighAPI_Selection& theDirection,
50 const ModelHighAPI_Double& theSize)
51 : ModelHighAPI_Interface(theFeature)
54 fillAttribute(theBaseObjects, mybaseObjects);
55 fillAttribute(theDirection, mydirection);
56 setSizes(theSize, ModelHighAPI_Double());
60 //==================================================================================================
61 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
62 const std::list<ModelHighAPI_Selection>& theBaseObjects,
63 const ModelHighAPI_Double& theToSize,
64 const ModelHighAPI_Double& theFromSize)
65 : ModelHighAPI_Interface(theFeature)
68 fillAttribute(theBaseObjects, mybaseObjects);
69 setSizes(theToSize, theFromSize);
73 //==================================================================================================
74 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
75 const std::list<ModelHighAPI_Selection>& theBaseObjects,
76 const ModelHighAPI_Selection& theDirection,
77 const ModelHighAPI_Double& theToSize,
78 const ModelHighAPI_Double& theFromSize)
79 : ModelHighAPI_Interface(theFeature)
82 fillAttribute(theBaseObjects, mybaseObjects);
83 fillAttribute(theDirection, mydirection);
84 setSizes(theToSize, theFromSize);
88 //==================================================================================================
89 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
90 const std::list<ModelHighAPI_Selection>& theBaseObjects,
91 const ModelHighAPI_Selection& theToObject,
92 const ModelHighAPI_Double& theToOffset,
93 const ModelHighAPI_Selection& theFromObject,
94 const ModelHighAPI_Double& theFromOffset)
95 : ModelHighAPI_Interface(theFeature)
98 fillAttribute(theBaseObjects, mybaseObjects);
99 setPlanesAndOffsets(theToObject, theToOffset, theFromObject, theFromOffset);
103 //==================================================================================================
104 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
105 const std::list<ModelHighAPI_Selection>& theBaseObjects,
106 const ModelHighAPI_Selection& theDirection,
107 const ModelHighAPI_Selection& theToObject,
108 const ModelHighAPI_Double& theToOffset,
109 const ModelHighAPI_Selection& theFromObject,
110 const ModelHighAPI_Double& theFromOffset)
111 : ModelHighAPI_Interface(theFeature)
114 fillAttribute(theBaseObjects, mybaseObjects);
115 fillAttribute(theDirection, mydirection);
116 setPlanesAndOffsets(theToObject, theToOffset, theFromObject, theFromOffset);
120 //==================================================================================================
121 FeaturesAPI_Extrusion::~FeaturesAPI_Extrusion()
125 //==================================================================================================
126 void FeaturesAPI_Extrusion::setNestedSketch(const ModelHighAPI_Reference& theSketch)
128 mysketch->setValue(theSketch.feature());
130 // To make Sketch feature execute and subfeatures execute.
131 feature()->document()->setCurrentFeature(feature(), false);
133 // to inform that the history is updated due to the sketch moved under the composite feature
134 if (theSketch.feature().get()) {
135 theSketch.feature()->document()->updateHistory(ModelAPI_Feature::group());
136 if (theSketch.feature()->firstResult().get())
137 theSketch.feature()->firstResult()->setDisplayed(false);
139 mybaseObjects->clear();
140 mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
142 execIfBaseNotEmpty();
145 //==================================================================================================
146 void FeaturesAPI_Extrusion::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
148 mysketch->setValue(ObjectPtr());
149 mybaseObjects->clear();
150 fillAttribute(theBaseObjects, mybaseObjects);
152 execIfBaseNotEmpty();
155 //==================================================================================================
156 void FeaturesAPI_Extrusion::setDirection(const ModelHighAPI_Selection& theDirection)
158 fillAttribute(theDirection, mydirection);
160 execIfBaseNotEmpty();
163 //==================================================================================================
164 void FeaturesAPI_Extrusion::setSizes(const ModelHighAPI_Double& theToSize,
165 const ModelHighAPI_Double& theFromSize)
167 fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod);
168 fillAttribute(theToSize, mytoSize);
169 fillAttribute(theFromSize, myfromSize);
171 execIfBaseNotEmpty();
174 //==================================================================================================
175 void FeaturesAPI_Extrusion::setSize(const ModelHighAPI_Double& theSize)
177 setSizes(theSize, ModelHighAPI_Double());
180 //==================================================================================================
181 void FeaturesAPI_Extrusion::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
182 const ModelHighAPI_Double& theToOffset,
183 const ModelHighAPI_Selection& theFromObject,
184 const ModelHighAPI_Double& theFromOffset)
186 fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_PLANES(), mycreationMethod);
187 fillAttribute(theToObject, mytoObject);
188 fillAttribute(theToOffset, mytoOffset);
189 fillAttribute(theFromObject, myfromObject);
190 fillAttribute(theFromOffset, myfromOffset);
192 execIfBaseNotEmpty();
195 //==================================================================================================
196 void FeaturesAPI_Extrusion::dump(ModelHighAPI_Dumper& theDumper) const
198 FeaturePtr aBase = feature();
199 const std::string& aDocName = theDumper.name(aBase->document());
201 AttributeReferencePtr anAttrSketch = aBase->reference(FeaturesPlugin_Extrusion::SKETCH_ID());
202 AttributeSelectionListPtr anAttrObjects =
203 aBase->selectionList(FeaturesPlugin_Extrusion::BASE_OBJECTS_ID());
204 AttributeSelectionPtr anAttrDirection =
205 aBase->selection(FeaturesPlugin_Extrusion::DIRECTION_OBJECT_ID());
207 theDumper << aBase << " = model.addExtrusion(" << aDocName << ", ";
208 anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
209 theDumper << ", " << anAttrDirection;
211 std::string aCreationMethod =
212 aBase->string(FeaturesPlugin_Extrusion::CREATION_METHOD())->value();
214 if(aCreationMethod == FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES()) {
215 AttributeDoublePtr anAttrToSize = aBase->real(FeaturesPlugin_Extrusion::TO_SIZE_ID());
216 AttributeDoublePtr anAttrFromSize = aBase->real(FeaturesPlugin_Extrusion::FROM_SIZE_ID());
218 theDumper << ", " << anAttrToSize << ", " << anAttrFromSize;
219 } else if(aCreationMethod == FeaturesPlugin_Extrusion::CREATION_METHOD_BY_PLANES()) {
220 AttributeSelectionPtr anAttrToObject =
221 aBase->selection(FeaturesPlugin_Extrusion::TO_OBJECT_ID());
222 AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Extrusion::TO_OFFSET_ID());
223 AttributeSelectionPtr anAttrFromObject =
224 aBase->selection(FeaturesPlugin_Extrusion::FROM_OBJECT_ID());
225 AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Extrusion::FROM_OFFSET_ID());
227 theDumper << ", " << anAttrToObject << ", " << anAttrToOffset <<
228 ", " << anAttrFromObject << ", " << anAttrFromOffset;
231 theDumper << ")" << std::endl;
233 if(anAttrSketch->isInitialized()) {
234 theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
238 //==================================================================================================
239 void FeaturesAPI_Extrusion::execIfBaseNotEmpty()
241 if(mybaseObjects->size() > 0) {
246 //==================================================================================================
247 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
248 const std::list<ModelHighAPI_Selection>& theBaseObjects,
249 const ModelHighAPI_Double& theSize)
251 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
252 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theSize));
255 //==================================================================================================
256 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
257 const std::list<ModelHighAPI_Selection>& theBaseObjects,
258 const ModelHighAPI_Selection& theDirection,
259 const ModelHighAPI_Double& theSize)
261 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
262 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theDirection, theSize));
265 //==================================================================================================
266 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
267 const std::list<ModelHighAPI_Selection>& theBaseObjects,
268 const ModelHighAPI_Double& theToSize,
269 const ModelHighAPI_Double& theFromSize)
271 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
272 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theToSize, theFromSize));
275 //==================================================================================================
276 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
277 const std::list<ModelHighAPI_Selection>& theBaseObjects,
278 const ModelHighAPI_Selection& theDirection,
279 const ModelHighAPI_Double& theToSize,
280 const ModelHighAPI_Double& theFromSize)
282 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
283 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,
290 //==================================================================================================
291 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
292 const std::list<ModelHighAPI_Selection>& theBaseObjects,
293 const ModelHighAPI_Selection& theToObject,
294 const ModelHighAPI_Double& theToOffset,
295 const ModelHighAPI_Selection& theFromObject,
296 const ModelHighAPI_Double& theFromOffset)
298 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
299 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,
307 //==================================================================================================
308 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
309 const std::list<ModelHighAPI_Selection>& theBaseObjects,
310 const ModelHighAPI_Selection& theDirection,
311 const ModelHighAPI_Selection& theToObject,
312 const ModelHighAPI_Double& theToOffset,
313 const ModelHighAPI_Selection& theFromObject,
314 const ModelHighAPI_Double& theFromOffset)
316 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
317 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,