]> SALOME platform Git repositories - modules/shaper.git/blob - src/FeaturesAPI/FeaturesAPI_Extrusion.cpp
Salome HOME
[Code coverage FeaturesAPI]: Improve coverage of Scale, Rotation, Revolution and...
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Extrusion.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "FeaturesAPI_Extrusion.h"
22
23 #include <ModelHighAPI_Double.h>
24 #include <ModelHighAPI_Dumper.h>
25 #include <ModelHighAPI_Reference.h>
26 #include <ModelHighAPI_Tools.h>
27
28 //==================================================================================================
29 FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feature>& theFeature)
30 : ModelHighAPI_Interface(theFeature)
31 {
32   initialize();
33 }
34
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)
40 {
41   if(initialize()) {
42     fillAttribute(theBaseObjects, mybaseObjects);
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_Selection& theDirection,
51                                           const ModelHighAPI_Double& theSize)
52 : ModelHighAPI_Interface(theFeature)
53 {
54   if(initialize()) {
55     fillAttribute(theBaseObjects, mybaseObjects);
56     fillAttribute(theDirection, mydirection);
57     setSizes(theSize, ModelHighAPI_Double());
58   }
59 }
60
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)
67 {
68   if(initialize()) {
69     fillAttribute(theBaseObjects, mybaseObjects);
70     setSizes(theToSize, theFromSize);
71   }
72 }
73
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)
81 {
82   if(initialize()) {
83     fillAttribute(theBaseObjects, mybaseObjects);
84     fillAttribute(theDirection, mydirection);
85     setSizes(theToSize, theFromSize);
86   }
87 }
88
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)
97 {
98   if(initialize()) {
99     fillAttribute(theBaseObjects, mybaseObjects);
100     setPlanesAndOffsets(theToObject, theToOffset, theFromObject, theFromOffset);
101   }
102 }
103
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)
113 {
114   if(initialize()) {
115     fillAttribute(theBaseObjects, mybaseObjects);
116     fillAttribute(theDirection, mydirection);
117     setPlanesAndOffsets(theToObject, theToOffset, theFromObject, theFromOffset);
118   }
119 }
120
121 //==================================================================================================
122 FeaturesAPI_Extrusion::~FeaturesAPI_Extrusion()
123 {
124 }
125
126 //==================================================================================================
127 void FeaturesAPI_Extrusion::setNestedSketch(const ModelHighAPI_Reference& theSketch)
128 {
129   mysketch->setValue(theSketch.feature());
130
131   // To make Sketch feature execute and subfeatures execute.
132   feature()->document()->setCurrentFeature(feature(), false);
133
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);
139   }
140   mybaseObjects->clear();
141   mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
142
143   execIfBaseNotEmpty();
144 }
145
146 //==================================================================================================
147 void FeaturesAPI_Extrusion::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
148 {
149   mysketch->setValue(ObjectPtr());
150   mybaseObjects->clear();
151   fillAttribute(theBaseObjects, mybaseObjects);
152
153   execIfBaseNotEmpty();
154 }
155
156 //==================================================================================================
157 void FeaturesAPI_Extrusion::setDirection(const ModelHighAPI_Selection& theDirection)
158 {
159   fillAttribute(theDirection, mydirection);
160
161   execIfBaseNotEmpty();
162 }
163
164 //==================================================================================================
165 void FeaturesAPI_Extrusion::setSizes(const ModelHighAPI_Double& theToSize,
166                                      const ModelHighAPI_Double& theFromSize)
167 {
168   fillAttribute(FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES(), mycreationMethod);
169   fillAttribute(theToSize, mytoSize);
170   fillAttribute(theFromSize, myfromSize);
171
172   execIfBaseNotEmpty();
173 }
174
175 //==================================================================================================
176 void FeaturesAPI_Extrusion::setSize(const ModelHighAPI_Double& theSize)
177 {
178   setSizes(theSize, ModelHighAPI_Double());
179 }
180
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)
186 {
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);
192
193   execIfBaseNotEmpty();
194 }
195
196 //==================================================================================================
197 void FeaturesAPI_Extrusion::dump(ModelHighAPI_Dumper& theDumper) const
198 {
199   FeaturePtr aBase = feature();
200   const std::string& aDocName = theDumper.name(aBase->document());
201
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());
207
208   theDumper << aBase << " = model.addExtrusion(" << aDocName << ", ";
209   anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
210   theDumper << ", " << anAttrDirection;
211
212   std::string aCreationMethod =
213     aBase->string(FeaturesPlugin_Extrusion::CREATION_METHOD())->value();
214
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());
218
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());
227
228     theDumper << ", " << anAttrToObject << ", " << anAttrToOffset <<
229       ", " << anAttrFromObject << ", " << anAttrFromOffset;
230   }
231
232   theDumper << ")" << std::endl;
233
234   if(anAttrSketch->isInitialized()) {
235     theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
236   }
237 }
238
239 //==================================================================================================
240 void FeaturesAPI_Extrusion::execIfBaseNotEmpty()
241 {
242   if(mybaseObjects->size() > 0) {
243     execute();
244   }
245 }
246
247 //==================================================================================================
248 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
249                           const std::list<ModelHighAPI_Selection>& theBaseObjects,
250                           const ModelHighAPI_Double& theSize)
251 {
252   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
253   return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theSize));
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& theSize)
261 {
262   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
263   return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theDirection, theSize));
264 }
265
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)
271 {
272   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
273   return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature, theBaseObjects, theToSize, theFromSize));
274 }
275
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)
282 {
283   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
284   return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,
285                                                 theBaseObjects,
286                                                 theDirection,
287                                                 theToSize,
288                                                 theFromSize));
289 }
290
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)
298 {
299   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
300   return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,
301                                                 theBaseObjects,
302                                                 theToObject,
303                                                 theToOffset,
304                                                 theFromObject,
305                                                 theFromOffset));
306 }
307
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)
316 {
317   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Extrusion::ID());
318   return ExtrusionPtr(new FeaturesAPI_Extrusion(aFeature,
319                                                 theBaseObjects,
320                                                 theDirection,
321                                                 theToObject,
322                                                 theToOffset,
323                                                 theFromObject,
324                                                 theFromOffset));
325 }