]> SALOME platform Git repositories - modules/shaper.git/blob - src/FeaturesAPI/FeaturesAPI_Extrusion.cpp
Salome HOME
Make nested sketch not displayed after dump in the neutral point.
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Extrusion.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        FeaturesAPI_Extrusion.cpp
4 // Created:     09 June 2016
5 // Author:      Dmitry Bobylev
6
7 #include "FeaturesAPI_Extrusion.h"
8
9 #include <ModelHighAPI_Double.h>
10 #include <ModelHighAPI_Dumper.h>
11 #include <ModelHighAPI_Reference.h>
12 #include <ModelHighAPI_Tools.h>
13
14 //==================================================================================================
15 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature)
16 : ModelHighAPI_Interface(theFeature)
17 {
18   initialize();
19 }
20
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)
26 {
27   if(initialize()) {
28     fillAttribute(theBaseObjects, mybaseObjects);
29     setSizes(theSize, ModelHighAPI_Double());
30   }
31 }
32
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)
39 {
40   if(initialize()) {
41     fillAttribute(theBaseObjects, mybaseObjects);
42     fillAttribute(theDirection, mydirection);
43     setSizes(theSize, ModelHighAPI_Double());
44   }
45 }
46
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)
53 {
54   if(initialize()) {
55     fillAttribute(theBaseObjects, mybaseObjects);
56     setSizes(theToSize, theFromSize);
57   }
58 }
59
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)
67 {
68   if(initialize()) {
69     fillAttribute(theBaseObjects, mybaseObjects);
70     fillAttribute(theDirection, mydirection);
71     setSizes(theToSize, theFromSize);
72   }
73 }
74
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)
83 {
84   if(initialize()) {
85     fillAttribute(theBaseObjects, mybaseObjects);
86     setPlanesAndOffsets(theToObject, theToOffset, theFromObject, theFromOffset);
87   }
88 }
89
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)
99 {
100   if(initialize()) {
101     fillAttribute(theBaseObjects, mybaseObjects);
102     fillAttribute(theDirection, mydirection);
103     setPlanesAndOffsets(theToObject, theToOffset, theFromObject, theFromOffset);
104   }
105 }
106
107 //==================================================================================================
108 FeaturesAPI_Extrusion::~FeaturesAPI_Extrusion()
109 {
110 }
111
112 //==================================================================================================
113 void FeaturesAPI_Extrusion::setNestedSketch(const ModelHighAPI_Reference& theSketch)
114 {
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     if (theSketch.feature()->firstResult().get())
120       theSketch.feature()->firstResult()->setDisplayed(false);
121   }
122   mybaseObjects->clear();
123   mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
124
125   execIfBaseNotEmpty();
126 }
127
128 //==================================================================================================
129 void FeaturesAPI_Extrusion::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
130 {
131   mysketch->setValue(ObjectPtr());
132   mybaseObjects->clear();
133   fillAttribute(theBaseObjects, mybaseObjects);
134
135   execIfBaseNotEmpty();
136 }
137
138 //==================================================================================================
139 void FeaturesAPI_Extrusion::setDirection(const ModelHighAPI_Selection& theDirection)
140 {
141   fillAttribute(theDirection, mydirection);
142
143   execIfBaseNotEmpty();
144 }
145
146 //==================================================================================================
147 void FeaturesAPI_Extrusion::setSizes(const ModelHighAPI_Double& theToSize,
148                                      const ModelHighAPI_Double& theFromSize)
149 {
150   fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod);
151   fillAttribute(theToSize, mytoSize);
152   fillAttribute(theFromSize, myfromSize);
153
154   execIfBaseNotEmpty();
155 }
156
157 //==================================================================================================
158 void FeaturesAPI_Extrusion::setSize(const ModelHighAPI_Double& theSize)
159 {
160   fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod);
161   fillAttribute(theSize, mytoSize);
162   fillAttribute(ModelHighAPI_Double(), myfromSize);
163
164   execIfBaseNotEmpty();
165 }
166
167 //==================================================================================================
168 void FeaturesAPI_Extrusion::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
169                                                 const ModelHighAPI_Double& theToOffset,
170                                                 const ModelHighAPI_Selection& theFromObject,
171                                                 const ModelHighAPI_Double& theFromOffset)
172 {
173   fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_PLANES(), mycreationMethod);
174   fillAttribute(theToObject, mytoObject);
175   fillAttribute(theToOffset, mytoOffset);
176   fillAttribute(theFromObject, myfromObject);
177   fillAttribute(theFromOffset, myfromOffset);
178
179   execIfBaseNotEmpty();
180 }
181
182 //==================================================================================================
183 void FeaturesAPI_Extrusion::dump(ModelHighAPI_Dumper& theDumper) const
184 {
185   FeaturePtr aBase = feature();
186   const std::string& aDocName = theDumper.name(aBase->document());
187
188   AttributeReferencePtr anAttrSketch = aBase->reference(FeaturesPlugin_Extrusion::SKETCH_ID());
189   AttributeSelectionListPtr anAttrObjects = aBase->selectionList(FeaturesPlugin_Extrusion::BASE_OBJECTS_ID());
190   AttributeSelectionPtr anAttrDirection = aBase->selection(FeaturesPlugin_Extrusion::DIRECTION_OBJECT_ID());
191
192   theDumper << aBase << " = model.addExtrusion(" << aDocName << ", ";
193   anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
194   theDumper << ", " << anAttrDirection;
195
196   std::string aCreationMethod = aBase->string(FeaturesPlugin_Extrusion::CREATION_METHOD())->value();
197
198   if(aCreationMethod == FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES()) {
199     AttributeDoublePtr anAttrToSize = aBase->real(FeaturesPlugin_Extrusion::TO_SIZE_ID());
200     AttributeDoublePtr anAttrFromSize = aBase->real(FeaturesPlugin_Extrusion::FROM_SIZE_ID());
201
202     theDumper << ", " << anAttrToSize << ", " << anAttrFromSize;
203   } else if(aCreationMethod == FeaturesPlugin_Extrusion::CREATION_METHOD_BY_PLANES()) {
204     AttributeSelectionPtr anAttrToObject = aBase->selection(FeaturesPlugin_Extrusion::TO_OBJECT_ID());
205     AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Extrusion::TO_OFFSET_ID());
206     AttributeSelectionPtr anAttrFromObject = aBase->selection(FeaturesPlugin_Extrusion::FROM_OBJECT_ID());
207     AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Extrusion::FROM_OFFSET_ID());
208
209     theDumper << ", " << anAttrToObject << ", " << anAttrToOffset << ", " << anAttrFromObject << ", " << anAttrFromOffset;
210   }
211
212   theDumper << ")" << std::endl;
213
214   if(anAttrSketch->isInitialized()) {
215     theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
216   }
217 }
218
219 //==================================================================================================
220 void FeaturesAPI_Extrusion::execIfBaseNotEmpty()
221 {
222   if(mybaseObjects->size() > 0) {
223     execute();
224   }
225 }
226
227 //==================================================================================================
228 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
229                           const std::list<ModelHighAPI_Selection>& theBaseObjects,
230                           const ModelHighAPI_Double& theSize)
231 {
232   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
233   return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theSize));
234 }
235
236 //==================================================================================================
237 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
238                           const std::list<ModelHighAPI_Selection>& theBaseObjects,
239                           const ModelHighAPI_Selection& theDirection,
240                           const ModelHighAPI_Double& theSize)
241 {
242   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
243   return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theDirection, theSize));
244 }
245
246 //==================================================================================================
247 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
248                           const std::list<ModelHighAPI_Selection>& theBaseObjects,
249                           const ModelHighAPI_Double& theToSize,
250                           const ModelHighAPI_Double& theFromSize)
251 {
252   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
253   return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theToSize, theFromSize));
254 }
255
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& theToSize,
261                           const ModelHighAPI_Double& theFromSize)
262 {
263   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
264   return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,
265                                                 theBaseObjects,
266                                                 theDirection,
267                                                 theToSize,
268                                                 theFromSize));
269 }
270
271 //==================================================================================================
272 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
273                           const std::list<ModelHighAPI_Selection>& theBaseObjects,
274                           const ModelHighAPI_Selection& theToObject,
275                           const ModelHighAPI_Double& theToOffset,
276                           const ModelHighAPI_Selection& theFromObject,
277                           const ModelHighAPI_Double& theFromOffset)
278 {
279   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
280   return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,
281                                                 theBaseObjects,
282                                                 theToObject,
283                                                 theToOffset,
284                                                 theFromObject,
285                                                 theFromOffset));
286 }
287
288 //==================================================================================================
289 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
290                           const std::list<ModelHighAPI_Selection>& theBaseObjects,
291                           const ModelHighAPI_Selection& theDirection,
292                           const ModelHighAPI_Selection& theToObject,
293                           const ModelHighAPI_Double& theToOffset,
294                           const ModelHighAPI_Selection& theFromObject,
295                           const ModelHighAPI_Double& theFromOffset)
296 {
297   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
298   return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,
299                                                 theBaseObjects,
300                                                 theDirection,
301                                                 theToObject,
302                                                 theToOffset,
303                                                 theFromObject,
304                                                 theFromOffset));
305 }