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