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 setSizes(theSize, ModelHighAPI_Double());
181 //==================================================================================================
182 void FeaturesAPI_Extrusion::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
183 const ModelHighAPI_Double& theToOffset,
184 const ModelHighAPI_Selection& theFromObject,
185 const ModelHighAPI_Double& theFromOffset)
187 fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_PLANES(), mycreationMethod);
188 fillAttribute(theToObject, mytoObject);
189 fillAttribute(theToOffset, mytoOffset);
190 fillAttribute(theFromObject, myfromObject);
191 fillAttribute(theFromOffset, myfromOffset);
193 execIfBaseNotEmpty();
196 //==================================================================================================
197 void FeaturesAPI_Extrusion::dump(ModelHighAPI_Dumper& theDumper) const
199 FeaturePtr aBase = feature();
200 const std::string& aDocName = theDumper.name(aBase->document());
202 AttributeReferencePtr anAttrSketch = aBase->reference(FeaturesPlugin_Extrusion::SKETCH_ID());
203 AttributeSelectionListPtr anAttrObjects =
204 aBase->selectionList(FeaturesPlugin_Extrusion::BASE_OBJECTS_ID());
205 AttributeSelectionPtr anAttrDirection =
206 aBase->selection(FeaturesPlugin_Extrusion::DIRECTION_OBJECT_ID());
208 theDumper << aBase << " = model.addExtrusion(" << aDocName << ", ";
209 anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
210 theDumper << ", " << anAttrDirection;
212 std::string aCreationMethod =
213 aBase->string(FeaturesPlugin_Extrusion::CREATION_METHOD())->value();
215 if(aCreationMethod == FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES()) {
216 AttributeDoublePtr anAttrToSize = aBase->real(FeaturesPlugin_Extrusion::TO_SIZE_ID());
217 AttributeDoublePtr anAttrFromSize = aBase->real(FeaturesPlugin_Extrusion::FROM_SIZE_ID());
219 theDumper << ", " << anAttrToSize << ", " << anAttrFromSize;
220 } else if(aCreationMethod == FeaturesPlugin_Extrusion::CREATION_METHOD_BY_PLANES()) {
221 AttributeSelectionPtr anAttrToObject =
222 aBase->selection(FeaturesPlugin_Extrusion::TO_OBJECT_ID());
223 AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Extrusion::TO_OFFSET_ID());
224 AttributeSelectionPtr anAttrFromObject =
225 aBase->selection(FeaturesPlugin_Extrusion::FROM_OBJECT_ID());
226 AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Extrusion::FROM_OFFSET_ID());
228 theDumper << ", " << anAttrToObject << ", " << anAttrToOffset <<
229 ", " << anAttrFromObject << ", " << anAttrFromOffset;
232 theDumper << ")" << std::endl;
234 if(anAttrSketch->isInitialized()) {
235 theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
239 //==================================================================================================
240 void FeaturesAPI_Extrusion::execIfBaseNotEmpty()
242 if(mybaseObjects->size() > 0) {
247 //==================================================================================================
248 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
249 const std::list<ModelHighAPI_Selection>& theBaseObjects,
250 const ModelHighAPI_Double& theSize)
252 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
253 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theSize));
256 //==================================================================================================
257 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
258 const std::list<ModelHighAPI_Selection>& theBaseObjects,
259 const ModelHighAPI_Selection& theDirection,
260 const ModelHighAPI_Double& theSize)
262 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
263 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theDirection, theSize));
266 //==================================================================================================
267 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
268 const std::list<ModelHighAPI_Selection>& theBaseObjects,
269 const ModelHighAPI_Double& theToSize,
270 const ModelHighAPI_Double& theFromSize)
272 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
273 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theToSize, theFromSize));
276 //==================================================================================================
277 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
278 const std::list<ModelHighAPI_Selection>& theBaseObjects,
279 const ModelHighAPI_Selection& theDirection,
280 const ModelHighAPI_Double& theToSize,
281 const ModelHighAPI_Double& theFromSize)
283 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
284 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,
291 //==================================================================================================
292 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
293 const std::list<ModelHighAPI_Selection>& theBaseObjects,
294 const ModelHighAPI_Selection& theToObject,
295 const ModelHighAPI_Double& theToOffset,
296 const ModelHighAPI_Selection& theFromObject,
297 const ModelHighAPI_Double& theFromOffset)
299 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
300 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,
308 //==================================================================================================
309 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
310 const std::list<ModelHighAPI_Selection>& theBaseObjects,
311 const ModelHighAPI_Selection& theDirection,
312 const ModelHighAPI_Selection& theToObject,
313 const ModelHighAPI_Double& theToOffset,
314 const ModelHighAPI_Selection& theFromObject,
315 const ModelHighAPI_Double& theFromOffset)
317 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
318 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,