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