1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: FeaturesAPI_Extrusion.cpp
4 // Created: 09 June 2016
5 // Author: Dmitry Bobylev
7 #include "FeaturesAPI_Extrusion.h"
9 #include <ModelHighAPI_Double.h>
10 #include <ModelHighAPI_Dumper.h>
11 #include <ModelHighAPI_Reference.h>
12 #include <ModelHighAPI_Tools.h>
14 //==================================================================================================
15 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature)
16 : ModelHighAPI_Interface(theFeature)
21 //==================================================================================================
22 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
23 const std::list<ModelHighAPI_Selection>& theBaseObjects,
24 const ModelHighAPI_Double& theSize)
25 : ModelHighAPI_Interface(theFeature)
28 fillAttribute(theBaseObjects, mybaseObjects);
29 setSizes(theSize, ModelHighAPI_Double());
33 //==================================================================================================
34 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
35 const std::list<ModelHighAPI_Selection>& theBaseObjects,
36 const ModelHighAPI_Selection& theDirection,
37 const ModelHighAPI_Double& theSize)
38 : ModelHighAPI_Interface(theFeature)
41 fillAttribute(theBaseObjects, mybaseObjects);
42 fillAttribute(theDirection, mydirection);
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_Double& theToSize,
51 const ModelHighAPI_Double& theFromSize)
52 : ModelHighAPI_Interface(theFeature)
55 fillAttribute(theBaseObjects, mybaseObjects);
56 setSizes(theToSize, theFromSize);
60 //==================================================================================================
61 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
62 const std::list<ModelHighAPI_Selection>& theBaseObjects,
63 const ModelHighAPI_Selection& theDirection,
64 const ModelHighAPI_Double& theToSize,
65 const ModelHighAPI_Double& theFromSize)
66 : ModelHighAPI_Interface(theFeature)
69 fillAttribute(theBaseObjects, mybaseObjects);
70 fillAttribute(theDirection, mydirection);
71 setSizes(theToSize, theFromSize);
75 //==================================================================================================
76 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
77 const std::list<ModelHighAPI_Selection>& theBaseObjects,
78 const ModelHighAPI_Selection& theToObject,
79 const ModelHighAPI_Double& theToOffset,
80 const ModelHighAPI_Selection& theFromObject,
81 const ModelHighAPI_Double& theFromOffset)
82 : ModelHighAPI_Interface(theFeature)
85 fillAttribute(theBaseObjects, mybaseObjects);
86 setPlanesAndOffsets(theToObject, theToOffset, theFromObject, theFromOffset);
90 //==================================================================================================
91 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature,
92 const std::list<ModelHighAPI_Selection>& theBaseObjects,
93 const ModelHighAPI_Selection& theDirection,
94 const ModelHighAPI_Selection& theToObject,
95 const ModelHighAPI_Double& theToOffset,
96 const ModelHighAPI_Selection& theFromObject,
97 const ModelHighAPI_Double& theFromOffset)
98 : ModelHighAPI_Interface(theFeature)
101 fillAttribute(theBaseObjects, mybaseObjects);
102 fillAttribute(theDirection, mydirection);
103 setPlanesAndOffsets(theToObject, theToOffset, theFromObject, theFromOffset);
107 //==================================================================================================
108 FeaturesAPI_Extrusion::~FeaturesAPI_Extrusion()
112 //==================================================================================================
113 void FeaturesAPI_Extrusion::setNestedSketch(const ModelHighAPI_Reference& theSketch)
115 mysketch->setValue(theSketch.feature());
117 // To make Sketch feature execute and subfeatures execute.
118 feature()->document()->setCurrentFeature(feature(), false);
120 // to inform that the history is updated due to the sketch moved under the composite feature
121 if (theSketch.feature().get()) {
122 theSketch.feature()->document()->updateHistory(ModelAPI_Feature::group());
123 if (theSketch.feature()->firstResult().get())
124 theSketch.feature()->firstResult()->setDisplayed(false);
126 mybaseObjects->clear();
127 mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
129 execIfBaseNotEmpty();
132 //==================================================================================================
133 void FeaturesAPI_Extrusion::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
135 mysketch->setValue(ObjectPtr());
136 mybaseObjects->clear();
137 fillAttribute(theBaseObjects, mybaseObjects);
139 execIfBaseNotEmpty();
142 //==================================================================================================
143 void FeaturesAPI_Extrusion::setDirection(const ModelHighAPI_Selection& theDirection)
145 fillAttribute(theDirection, mydirection);
147 execIfBaseNotEmpty();
150 //==================================================================================================
151 void FeaturesAPI_Extrusion::setSizes(const ModelHighAPI_Double& theToSize,
152 const ModelHighAPI_Double& theFromSize)
154 fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod);
155 fillAttribute(theToSize, mytoSize);
156 fillAttribute(theFromSize, myfromSize);
158 execIfBaseNotEmpty();
161 //==================================================================================================
162 void FeaturesAPI_Extrusion::setSize(const ModelHighAPI_Double& theSize)
164 fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod);
165 fillAttribute(theSize, mytoSize);
166 fillAttribute(ModelHighAPI_Double(), myfromSize);
168 execIfBaseNotEmpty();
171 //==================================================================================================
172 void FeaturesAPI_Extrusion::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
173 const ModelHighAPI_Double& theToOffset,
174 const ModelHighAPI_Selection& theFromObject,
175 const ModelHighAPI_Double& theFromOffset)
177 fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_PLANES(), mycreationMethod);
178 fillAttribute(theToObject, mytoObject);
179 fillAttribute(theToOffset, mytoOffset);
180 fillAttribute(theFromObject, myfromObject);
181 fillAttribute(theFromOffset, myfromOffset);
183 execIfBaseNotEmpty();
186 //==================================================================================================
187 void FeaturesAPI_Extrusion::dump(ModelHighAPI_Dumper& theDumper) const
189 FeaturePtr aBase = feature();
190 const std::string& aDocName = theDumper.name(aBase->document());
192 AttributeReferencePtr anAttrSketch = aBase->reference(FeaturesPlugin_Extrusion::SKETCH_ID());
193 AttributeSelectionListPtr anAttrObjects =
194 aBase->selectionList(FeaturesPlugin_Extrusion::BASE_OBJECTS_ID());
195 AttributeSelectionPtr anAttrDirection =
196 aBase->selection(FeaturesPlugin_Extrusion::DIRECTION_OBJECT_ID());
198 theDumper << aBase << " = model.addExtrusion(" << aDocName << ", ";
199 anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
200 theDumper << ", " << anAttrDirection;
202 std::string aCreationMethod =
203 aBase->string(FeaturesPlugin_Extrusion::CREATION_METHOD())->value();
205 if(aCreationMethod == FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES()) {
206 AttributeDoublePtr anAttrToSize = aBase->real(FeaturesPlugin_Extrusion::TO_SIZE_ID());
207 AttributeDoublePtr anAttrFromSize = aBase->real(FeaturesPlugin_Extrusion::FROM_SIZE_ID());
209 theDumper << ", " << anAttrToSize << ", " << anAttrFromSize;
210 } else if(aCreationMethod == FeaturesPlugin_Extrusion::CREATION_METHOD_BY_PLANES()) {
211 AttributeSelectionPtr anAttrToObject =
212 aBase->selection(FeaturesPlugin_Extrusion::TO_OBJECT_ID());
213 AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Extrusion::TO_OFFSET_ID());
214 AttributeSelectionPtr anAttrFromObject =
215 aBase->selection(FeaturesPlugin_Extrusion::FROM_OBJECT_ID());
216 AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Extrusion::FROM_OFFSET_ID());
218 theDumper << ", " << anAttrToObject << ", " << anAttrToOffset <<
219 ", " << anAttrFromObject << ", " << anAttrFromOffset;
222 theDumper << ")" << std::endl;
224 if(anAttrSketch->isInitialized()) {
225 theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
229 //==================================================================================================
230 void FeaturesAPI_Extrusion::execIfBaseNotEmpty()
232 if(mybaseObjects->size() > 0) {
237 //==================================================================================================
238 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
239 const std::list<ModelHighAPI_Selection>& theBaseObjects,
240 const ModelHighAPI_Double& theSize)
242 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
243 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theSize));
246 //==================================================================================================
247 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
248 const std::list<ModelHighAPI_Selection>& theBaseObjects,
249 const ModelHighAPI_Selection& theDirection,
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, theDirection, theSize));
256 //==================================================================================================
257 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
258 const std::list<ModelHighAPI_Selection>& theBaseObjects,
259 const ModelHighAPI_Double& theToSize,
260 const ModelHighAPI_Double& theFromSize)
262 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
263 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theToSize, theFromSize));
266 //==================================================================================================
267 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
268 const std::list<ModelHighAPI_Selection>& theBaseObjects,
269 const ModelHighAPI_Selection& theDirection,
270 const ModelHighAPI_Double& theToSize,
271 const ModelHighAPI_Double& theFromSize)
273 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
274 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,
281 //==================================================================================================
282 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
283 const std::list<ModelHighAPI_Selection>& theBaseObjects,
284 const ModelHighAPI_Selection& theToObject,
285 const ModelHighAPI_Double& theToOffset,
286 const ModelHighAPI_Selection& theFromObject,
287 const ModelHighAPI_Double& theFromOffset)
289 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
290 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,
298 //==================================================================================================
299 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
300 const std::list<ModelHighAPI_Selection>& theBaseObjects,
301 const ModelHighAPI_Selection& theDirection,
302 const ModelHighAPI_Selection& theToObject,
303 const ModelHighAPI_Double& theToOffset,
304 const ModelHighAPI_Selection& theFromObject,
305 const ModelHighAPI_Double& theFromOffset)
307 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
308 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,