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_Extrusion.h"
23 #include <ModelHighAPI_Double.h>
24 #include <ModelHighAPI_Dumper.h>
25 #include <ModelHighAPI_Reference.h>
26 #include <ModelHighAPI_Tools.h>
28 //==================================================================================================
29 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature)
30 : ModelHighAPI_Interface(theFeature)
35 //==================================================================================================
36 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
37 const std::list<ModelHighAPI_Selection>& theBaseObjects,
38 const ModelHighAPI_Double& theSize)
39 : ModelHighAPI_Interface(theFeature)
42 fillAttribute(theBaseObjects, mybaseObjects);
43 setSizes(theSize, ModelHighAPI_Double());
47 //==================================================================================================
48 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
49 const std::list<ModelHighAPI_Selection>& theBaseObjects,
50 const ModelHighAPI_Selection& theDirection,
51 const ModelHighAPI_Double& theSize)
52 : ModelHighAPI_Interface(theFeature)
55 fillAttribute(theBaseObjects, mybaseObjects);
56 fillAttribute(theDirection, mydirection);
57 setSizes(theSize, ModelHighAPI_Double());
61 //==================================================================================================
62 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
63 const std::list<ModelHighAPI_Selection>& theBaseObjects,
64 const ModelHighAPI_Double& theToSize,
65 const ModelHighAPI_Double& theFromSize)
66 : ModelHighAPI_Interface(theFeature)
69 fillAttribute(theBaseObjects, mybaseObjects);
70 setSizes(theToSize, theFromSize);
74 //==================================================================================================
75 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
76 const std::list<ModelHighAPI_Selection>& theBaseObjects,
77 const ModelHighAPI_Selection& theDirection,
78 const ModelHighAPI_Double& theToSize,
79 const ModelHighAPI_Double& theFromSize)
80 : ModelHighAPI_Interface(theFeature)
83 fillAttribute(theBaseObjects, mybaseObjects);
84 fillAttribute(theDirection, mydirection);
85 setSizes(theToSize, theFromSize);
89 //==================================================================================================
90 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
91 const std::list<ModelHighAPI_Selection>& theBaseObjects,
92 const ModelHighAPI_Selection& theToObject,
93 const ModelHighAPI_Double& theToOffset,
94 const ModelHighAPI_Selection& theFromObject,
95 const ModelHighAPI_Double& theFromOffset)
96 : ModelHighAPI_Interface(theFeature)
99 fillAttribute(theBaseObjects, mybaseObjects);
100 setPlanesAndOffsets(theToObject, theToOffset, theFromObject, theFromOffset);
104 //==================================================================================================
105 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
106 const std::list<ModelHighAPI_Selection>& theBaseObjects,
107 const ModelHighAPI_Selection& theDirection,
108 const ModelHighAPI_Selection& theToObject,
109 const ModelHighAPI_Double& theToOffset,
110 const ModelHighAPI_Selection& theFromObject,
111 const ModelHighAPI_Double& theFromOffset)
112 : ModelHighAPI_Interface(theFeature)
115 fillAttribute(theBaseObjects, mybaseObjects);
116 fillAttribute(theDirection, mydirection);
117 setPlanesAndOffsets(theToObject, theToOffset, theFromObject, theFromOffset);
121 //==================================================================================================
122 FeaturesAPI_Extrusion::~FeaturesAPI_Extrusion()
126 //==================================================================================================
127 void FeaturesAPI_Extrusion::setNestedSketch(const ModelHighAPI_Reference& theSketch)
129 mysketch->setValue(theSketch.feature());
131 // To make Sketch feature execute and subfeatures execute.
132 feature()->document()->setCurrentFeature(feature(), false);
134 // to inform that the history is updated due to the sketch moved under the composite feature
135 if (theSketch.feature().get()) {
136 theSketch.feature()->document()->updateHistory(ModelAPI_Feature::group());
137 if (theSketch.feature()->firstResult().get())
138 theSketch.feature()->firstResult()->setDisplayed(false);
140 mybaseObjects->clear();
141 mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
143 execIfBaseNotEmpty();
146 //==================================================================================================
147 void FeaturesAPI_Extrusion::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
149 mysketch->setValue(ObjectPtr());
150 mybaseObjects->clear();
151 fillAttribute(theBaseObjects, mybaseObjects);
153 execIfBaseNotEmpty();
156 //==================================================================================================
157 void FeaturesAPI_Extrusion::setDirection(const ModelHighAPI_Selection& theDirection)
159 fillAttribute(theDirection, mydirection);
161 execIfBaseNotEmpty();
164 //==================================================================================================
165 void FeaturesAPI_Extrusion::setSizes(const ModelHighAPI_Double& theToSize,
166 const ModelHighAPI_Double& theFromSize)
168 fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod);
169 fillAttribute(theToSize, mytoSize);
170 fillAttribute(theFromSize, myfromSize);
172 execIfBaseNotEmpty();
175 //==================================================================================================
176 void FeaturesAPI_Extrusion::setSize(const ModelHighAPI_Double& theSize)
178 fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod);
179 fillAttribute(theSize, mytoSize);
180 fillAttribute(ModelHighAPI_Double(), myfromSize);
182 execIfBaseNotEmpty();
185 //==================================================================================================
186 void FeaturesAPI_Extrusion::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
187 const ModelHighAPI_Double& theToOffset,
188 const ModelHighAPI_Selection& theFromObject,
189 const ModelHighAPI_Double& theFromOffset)
191 fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_PLANES(), mycreationMethod);
192 fillAttribute(theToObject, mytoObject);
193 fillAttribute(theToOffset, mytoOffset);
194 fillAttribute(theFromObject, myfromObject);
195 fillAttribute(theFromOffset, myfromOffset);
197 execIfBaseNotEmpty();
200 //==================================================================================================
201 void FeaturesAPI_Extrusion::dump(ModelHighAPI_Dumper& theDumper) const
203 FeaturePtr aBase = feature();
204 const std::string& aDocName = theDumper.name(aBase->document());
206 AttributeReferencePtr anAttrSketch = aBase->reference(FeaturesPlugin_Extrusion::SKETCH_ID());
207 AttributeSelectionListPtr anAttrObjects =
208 aBase->selectionList(FeaturesPlugin_Extrusion::BASE_OBJECTS_ID());
209 AttributeSelectionPtr anAttrDirection =
210 aBase->selection(FeaturesPlugin_Extrusion::DIRECTION_OBJECT_ID());
212 theDumper << aBase << " = model.addExtrusion(" << aDocName << ", ";
213 anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
214 theDumper << ", " << anAttrDirection;
216 std::string aCreationMethod =
217 aBase->string(FeaturesPlugin_Extrusion::CREATION_METHOD())->value();
219 if(aCreationMethod == FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES()) {
220 AttributeDoublePtr anAttrToSize = aBase->real(FeaturesPlugin_Extrusion::TO_SIZE_ID());
221 AttributeDoublePtr anAttrFromSize = aBase->real(FeaturesPlugin_Extrusion::FROM_SIZE_ID());
223 theDumper << ", " << anAttrToSize << ", " << anAttrFromSize;
224 } else if(aCreationMethod == FeaturesPlugin_Extrusion::CREATION_METHOD_BY_PLANES()) {
225 AttributeSelectionPtr anAttrToObject =
226 aBase->selection(FeaturesPlugin_Extrusion::TO_OBJECT_ID());
227 AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Extrusion::TO_OFFSET_ID());
228 AttributeSelectionPtr anAttrFromObject =
229 aBase->selection(FeaturesPlugin_Extrusion::FROM_OBJECT_ID());
230 AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Extrusion::FROM_OFFSET_ID());
232 theDumper << ", " << anAttrToObject << ", " << anAttrToOffset <<
233 ", " << anAttrFromObject << ", " << anAttrFromOffset;
236 theDumper << ")" << std::endl;
238 if(anAttrSketch->isInitialized()) {
239 theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
243 //==================================================================================================
244 void FeaturesAPI_Extrusion::execIfBaseNotEmpty()
246 if(mybaseObjects->size() > 0) {
251 //==================================================================================================
252 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
253 const std::list<ModelHighAPI_Selection>& theBaseObjects,
254 const ModelHighAPI_Double& theSize)
256 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
257 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theSize));
260 //==================================================================================================
261 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
262 const std::list<ModelHighAPI_Selection>& theBaseObjects,
263 const ModelHighAPI_Selection& theDirection,
264 const ModelHighAPI_Double& theSize)
266 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
267 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theDirection, theSize));
270 //==================================================================================================
271 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
272 const std::list<ModelHighAPI_Selection>& theBaseObjects,
273 const ModelHighAPI_Double& theToSize,
274 const ModelHighAPI_Double& theFromSize)
276 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
277 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theToSize, theFromSize));
280 //==================================================================================================
281 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
282 const std::list<ModelHighAPI_Selection>& theBaseObjects,
283 const ModelHighAPI_Selection& theDirection,
284 const ModelHighAPI_Double& theToSize,
285 const ModelHighAPI_Double& theFromSize)
287 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
288 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,
295 //==================================================================================================
296 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
297 const std::list<ModelHighAPI_Selection>& theBaseObjects,
298 const ModelHighAPI_Selection& theToObject,
299 const ModelHighAPI_Double& theToOffset,
300 const ModelHighAPI_Selection& theFromObject,
301 const ModelHighAPI_Double& theFromOffset)
303 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
304 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,
312 //==================================================================================================
313 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
314 const std::list<ModelHighAPI_Selection>& theBaseObjects,
315 const ModelHighAPI_Selection& theDirection,
316 const ModelHighAPI_Selection& theToObject,
317 const ModelHighAPI_Double& theToOffset,
318 const ModelHighAPI_Selection& theFromObject,
319 const ModelHighAPI_Double& theFromOffset)
321 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
322 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,