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());
116 // to inform that the history is updated due to the sketch moved under the composite feature
117 if (theSketch.feature().get())
118 theSketch.feature()->document()->updateHistory(ModelAPI_Feature::group());
119 mybaseObjects->clear();
120 mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
122 execIfBaseNotEmpty();
125 //==================================================================================================
126 void FeaturesAPI_Extrusion::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
128 mysketch->setValue(ObjectPtr());
129 mybaseObjects->clear();
130 fillAttribute(theBaseObjects, mybaseObjects);
132 execIfBaseNotEmpty();
135 //==================================================================================================
136 void FeaturesAPI_Extrusion::setDirection(const ModelHighAPI_Selection& theDirection)
138 fillAttribute(theDirection, mydirection);
140 execIfBaseNotEmpty();
143 //==================================================================================================
144 void FeaturesAPI_Extrusion::setSizes(const ModelHighAPI_Double& theToSize,
145 const ModelHighAPI_Double& theFromSize)
147 fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod);
148 fillAttribute(theToSize, mytoSize);
149 fillAttribute(theFromSize, myfromSize);
151 execIfBaseNotEmpty();
154 //==================================================================================================
155 void FeaturesAPI_Extrusion::setSize(const ModelHighAPI_Double& theSize)
157 fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod);
158 fillAttribute(theSize, mytoSize);
159 fillAttribute(ModelHighAPI_Double(), myfromSize);
161 execIfBaseNotEmpty();
164 //==================================================================================================
165 void FeaturesAPI_Extrusion::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
166 const ModelHighAPI_Double& theToOffset,
167 const ModelHighAPI_Selection& theFromObject,
168 const ModelHighAPI_Double& theFromOffset)
170 fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_PLANES(), mycreationMethod);
171 fillAttribute(theToObject, mytoObject);
172 fillAttribute(theToOffset, mytoOffset);
173 fillAttribute(theFromObject, myfromObject);
174 fillAttribute(theFromOffset, myfromOffset);
176 execIfBaseNotEmpty();
179 //==================================================================================================
180 void FeaturesAPI_Extrusion::dump(ModelHighAPI_Dumper& theDumper) const
182 FeaturePtr aBase = feature();
183 const std::string& aDocName = theDumper.name(aBase->document());
185 AttributeReferencePtr anAttrSketch = aBase->reference(FeaturesPlugin_Extrusion::SKETCH_ID());
186 AttributeSelectionListPtr anAttrObjects = aBase->selectionList(FeaturesPlugin_Extrusion::BASE_OBJECTS_ID());
187 AttributeSelectionPtr anAttrDirection = aBase->selection(FeaturesPlugin_Extrusion::DIRECTION_OBJECT_ID());
189 theDumper << aBase << " = model.addExtrusion(" << aDocName << ", ";
190 anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
191 theDumper << ", " << anAttrDirection;
193 std::string aCreationMethod = aBase->string(FeaturesPlugin_Extrusion::CREATION_METHOD())->value();
195 if(aCreationMethod == FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES()) {
196 AttributeDoublePtr anAttrToSize = aBase->real(FeaturesPlugin_Extrusion::TO_SIZE_ID());
197 AttributeDoublePtr anAttrFromSize = aBase->real(FeaturesPlugin_Extrusion::FROM_SIZE_ID());
199 theDumper << ", " << anAttrToSize << ", " << anAttrFromSize;
200 } else if(aCreationMethod == FeaturesPlugin_Extrusion::CREATION_METHOD_BY_PLANES()) {
201 AttributeSelectionPtr anAttrToObject = aBase->selection(FeaturesPlugin_Extrusion::TO_OBJECT_ID());
202 AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Extrusion::TO_OFFSET_ID());
203 AttributeSelectionPtr anAttrFromObject = aBase->selection(FeaturesPlugin_Extrusion::FROM_OBJECT_ID());
204 AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Extrusion::FROM_OFFSET_ID());
206 theDumper << ", " << anAttrToObject << ", " << anAttrToOffset << ", " << anAttrFromObject << ", " << anAttrFromOffset;
209 theDumper << ")" << std::endl;
211 if(anAttrSketch->isInitialized()) {
212 theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
216 //==================================================================================================
217 void FeaturesAPI_Extrusion::execIfBaseNotEmpty()
219 if(mybaseObjects->size() > 0) {
224 //==================================================================================================
225 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
226 const std::list<ModelHighAPI_Selection>& theBaseObjects,
227 const ModelHighAPI_Double& theSize)
229 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
230 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theSize));
233 //==================================================================================================
234 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
235 const std::list<ModelHighAPI_Selection>& theBaseObjects,
236 const ModelHighAPI_Selection& theDirection,
237 const ModelHighAPI_Double& theSize)
239 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
240 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theDirection, theSize));
243 //==================================================================================================
244 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
245 const std::list<ModelHighAPI_Selection>& theBaseObjects,
246 const ModelHighAPI_Double& theToSize,
247 const ModelHighAPI_Double& theFromSize)
249 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
250 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theToSize, theFromSize));
253 //==================================================================================================
254 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
255 const std::list<ModelHighAPI_Selection>& theBaseObjects,
256 const ModelHighAPI_Selection& theDirection,
257 const ModelHighAPI_Double& theToSize,
258 const ModelHighAPI_Double& theFromSize)
260 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
261 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,
268 //==================================================================================================
269 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
270 const std::list<ModelHighAPI_Selection>& theBaseObjects,
271 const ModelHighAPI_Selection& theToObject,
272 const ModelHighAPI_Double& theToOffset,
273 const ModelHighAPI_Selection& theFromObject,
274 const ModelHighAPI_Double& theFromOffset)
276 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
277 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,
285 //==================================================================================================
286 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
287 const std::list<ModelHighAPI_Selection>& theBaseObjects,
288 const ModelHighAPI_Selection& theDirection,
289 const ModelHighAPI_Selection& theToObject,
290 const ModelHighAPI_Double& theToOffset,
291 const ModelHighAPI_Selection& theFromObject,
292 const ModelHighAPI_Double& theFromOffset)
294 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
295 return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,