]> SALOME platform Git repositories - modules/shaper.git/blob - src/FeaturesAPI/FeaturesAPI_Revolution.cpp
Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Revolution.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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
18 //
19
20 #include "FeaturesAPI_Revolution.h"
21
22 #include <ModelHighAPI_Double.h>
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Reference.h>
25 #include <ModelHighAPI_Tools.h>
26
27 //==================================================================================================
28 FeaturesAPI_Revolution::FeaturesAPI_Revolution(const std::shared_ptr<ModelAPI_Feature>& theFeature)
29 : ModelHighAPI_Interface(theFeature)
30 {
31   initialize();
32 }
33
34 //==================================================================================================
35 FeaturesAPI_Revolution::FeaturesAPI_Revolution(
36   const std::shared_ptr<ModelAPI_Feature>& theFeature,
37   const std::list<ModelHighAPI_Selection>& theBaseObjects,
38   const ModelHighAPI_Selection& theAxis,
39   const ModelHighAPI_Double& theAngle)
40 : ModelHighAPI_Interface(theFeature)
41 {
42   if(initialize()) {
43     fillAttribute(theBaseObjects, mybaseObjects);
44     fillAttribute(theAxis, myaxis);
45     setAngles(theAngle, ModelHighAPI_Double());
46   }
47 }
48
49 //==================================================================================================
50 FeaturesAPI_Revolution::FeaturesAPI_Revolution(
51   const std::shared_ptr<ModelAPI_Feature>& theFeature,
52   const std::list<ModelHighAPI_Selection>& theBaseObjects,
53   const ModelHighAPI_Selection& theAxis,
54   const ModelHighAPI_Double& theToAngle,
55   const ModelHighAPI_Double& theFromAngle)
56 : ModelHighAPI_Interface(theFeature)
57 {
58   if(initialize()) {
59     fillAttribute(theBaseObjects, mybaseObjects);
60     fillAttribute(theAxis, myaxis);
61     setAngles(theToAngle, theFromAngle);
62   }
63 }
64
65 //==================================================================================================
66 FeaturesAPI_Revolution::FeaturesAPI_Revolution(
67   const std::shared_ptr<ModelAPI_Feature>& theFeature,
68   const std::list<ModelHighAPI_Selection>& theBaseObjects,
69   const ModelHighAPI_Selection& theAxis,
70   const ModelHighAPI_Selection& theToObject,
71   const ModelHighAPI_Double& theToOffset,
72   const ModelHighAPI_Selection& theFromObject,
73   const ModelHighAPI_Double& theFromOffset)
74 : ModelHighAPI_Interface(theFeature)
75 {
76   if(initialize()) {
77     fillAttribute(theBaseObjects, mybaseObjects);
78     fillAttribute(theAxis, myaxis);
79     setPlanesAndOffsets(theToObject, theToOffset, theFromObject, theFromOffset);
80   }
81 }
82
83 //==================================================================================================
84 FeaturesAPI_Revolution::~FeaturesAPI_Revolution()
85 {
86
87 }
88
89 //==================================================================================================
90 void FeaturesAPI_Revolution::setNestedSketch(const ModelHighAPI_Reference& theSketch)
91 {
92   mysketch->setValue(theSketch.feature());
93
94   // To make Sketch feature execute and subfeatures execute.
95   feature()->document()->setCurrentFeature(feature(), false);
96
97   // to inform that the history is updated due to the sketch moved under the composite feature
98   if (theSketch.feature().get()) {
99     theSketch.feature()->document()->updateHistory(ModelAPI_Feature::group());
100     if (theSketch.feature()->firstResult().get())
101       theSketch.feature()->firstResult()->setDisplayed(false);
102   }
103   mybaseObjects->clear();
104   mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
105
106   execIfBaseNotEmpty();
107 }
108
109 //==================================================================================================
110 void FeaturesAPI_Revolution::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
111 {
112   mysketch->setValue(ObjectPtr());
113   mybaseObjects->clear();
114   fillAttribute(theBaseObjects, mybaseObjects);
115
116   execIfBaseNotEmpty();
117 }
118
119 //==================================================================================================
120 void FeaturesAPI_Revolution::setAxis(const ModelHighAPI_Selection& theAxis)
121 {
122   fillAttribute(theAxis, myaxis);
123
124   execIfBaseNotEmpty();
125 }
126
127 //==================================================================================================
128 void FeaturesAPI_Revolution::setAngles(const ModelHighAPI_Double& theToAngle,
129                                        const ModelHighAPI_Double& theFromAngle)
130 {
131   fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
132   fillAttribute(theToAngle, mytoAngle);
133   fillAttribute(theFromAngle, myfromAngle);
134
135   execIfBaseNotEmpty();
136 }
137
138 //==================================================================================================
139 void FeaturesAPI_Revolution::setAngle(const ModelHighAPI_Double& theAngle)
140 {
141   fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
142   fillAttribute(theAngle, mytoAngle);
143   fillAttribute(ModelHighAPI_Double(), myfromAngle);
144
145   execIfBaseNotEmpty();
146 }
147
148 //==================================================================================================
149 void FeaturesAPI_Revolution::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
150                                                 const ModelHighAPI_Double& theToOffset,
151                                                 const ModelHighAPI_Selection& theFromObject,
152                                                 const ModelHighAPI_Double& theFromOffset)
153 {
154   fillAttribute("ByPlanesAndOffsets", mycreationMethod);
155   fillAttribute(theToObject, mytoObject);
156   fillAttribute(theToOffset, mytoOffset);
157   fillAttribute(theFromObject, myfromObject);
158   fillAttribute(theFromOffset, myfromOffset);
159
160   execIfBaseNotEmpty();
161 }
162
163 //==================================================================================================
164 void FeaturesAPI_Revolution::dump(ModelHighAPI_Dumper& theDumper) const
165 {
166   FeaturePtr aBase = feature();
167   const std::string& aDocName = theDumper.name(aBase->document());
168
169   AttributeReferencePtr anAttrSketch = aBase->reference(FeaturesPlugin_Revolution::SKETCH_ID());
170   AttributeSelectionListPtr anAttrObjects =
171     aBase->selectionList(FeaturesPlugin_Revolution::BASE_OBJECTS_ID());
172   AttributeSelectionPtr anAttrAxis = aBase->selection(FeaturesPlugin_Revolution::AXIS_OBJECT_ID());
173
174   theDumper << aBase << " = model.addRevolution(" << aDocName << ", ";
175   anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
176   theDumper << ", " << anAttrAxis;
177
178   std::string aCreationMethod =
179     aBase->string(FeaturesPlugin_Revolution::CREATION_METHOD())->value();
180
181   if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES()) {
182     AttributeDoublePtr anAttrToAngle = aBase->real(FeaturesPlugin_Revolution::TO_ANGLE_ID());
183     AttributeDoublePtr anAttrFromAngle = aBase->real(FeaturesPlugin_Revolution::FROM_ANGLE_ID());
184
185     theDumper << ", " << anAttrToAngle << ", " << anAttrFromAngle;
186   } else if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES()) {
187     AttributeSelectionPtr anAttrToObject =
188       aBase->selection(FeaturesPlugin_Revolution::TO_OBJECT_ID());
189     AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Revolution::TO_OFFSET_ID());
190     AttributeSelectionPtr anAttrFromObject =
191       aBase->selection(FeaturesPlugin_Revolution::FROM_OBJECT_ID());
192     AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Revolution::FROM_OFFSET_ID());
193
194     theDumper << ", " << anAttrToObject << ", " << anAttrToOffset <<
195       ", " << anAttrFromObject << ", " << anAttrFromOffset;
196   }
197
198   theDumper << ")" << std::endl;
199
200   if(anAttrSketch->isInitialized()) {
201     theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
202   }
203 }
204
205 //==================================================================================================
206 void FeaturesAPI_Revolution::execIfBaseNotEmpty()
207 {
208   if(mybaseObjects->size() > 0) {
209     execute();
210   }
211 }
212
213 //==================================================================================================
214 RevolutionPtr addRevolution(const std::shared_ptr<ModelAPI_Document>& thePart,
215                             const std::list<ModelHighAPI_Selection>& theBaseObjects,
216                             const ModelHighAPI_Selection& theAxis,
217                             const ModelHighAPI_Double& theAngle)
218 {
219   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID());
220   return RevolutionPtr(new FeaturesAPI_Revolution(aFeature, theBaseObjects, theAxis, theAngle));
221 }
222
223 //==================================================================================================
224 RevolutionPtr addRevolution(const std::shared_ptr<ModelAPI_Document>& thePart,
225                             const std::list<ModelHighAPI_Selection>& theBaseObjects,
226                             const ModelHighAPI_Selection& theAxis,
227                             const ModelHighAPI_Double& theToAngle,
228                             const ModelHighAPI_Double& theFromAngle)
229 {
230   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID());
231   return RevolutionPtr(new FeaturesAPI_Revolution(aFeature,
232                                                 theBaseObjects,
233                                                 theAxis,
234                                                 theToAngle,
235                                                 theFromAngle));
236 }
237
238 //==================================================================================================
239 RevolutionPtr addRevolution(const std::shared_ptr<ModelAPI_Document>& thePart,
240                             const std::list<ModelHighAPI_Selection>& theBaseObjects,
241                             const ModelHighAPI_Selection& theAxis,
242                             const ModelHighAPI_Selection& theToObject,
243                             const ModelHighAPI_Double& theToOffset,
244                             const ModelHighAPI_Selection& theFromObject,
245                             const ModelHighAPI_Double& theFromOffset)
246 {
247   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID());
248   return RevolutionPtr(new FeaturesAPI_Revolution(aFeature,
249                                                 theBaseObjects,
250                                                 theAxis,
251                                                 theToObject,
252                                                 theToOffset,
253                                                 theFromObject,
254                                                 theFromOffset));
255 }