Salome HOME
6c09db9f22251506fb1162c51f481479d92639f1
[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   mybaseObjects->clear();
78   mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
79
80   execIfBaseNotEmpty();
81 }
82
83 //==================================================================================================
84 void FeaturesAPI_Revolution::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
85 {
86   mysketch->setValue(ObjectPtr());
87   mybaseObjects->clear();
88   fillAttribute(theBaseObjects, mybaseObjects);
89
90   execIfBaseNotEmpty();
91 }
92
93 //==================================================================================================
94 void FeaturesAPI_Revolution::setAxis(const ModelHighAPI_Selection& theAxis)
95 {
96   fillAttribute(theAxis, myaxis);
97
98   execIfBaseNotEmpty();
99 }
100
101 //==================================================================================================
102 void FeaturesAPI_Revolution::setAngles(const ModelHighAPI_Double& theToAngle,
103                                        const ModelHighAPI_Double& theFromAngle)
104 {
105   fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
106   fillAttribute(theToAngle, mytoAngle);
107   fillAttribute(theFromAngle, myfromAngle);
108
109   execIfBaseNotEmpty();
110 }
111
112 //==================================================================================================
113 void FeaturesAPI_Revolution::setAngle(const ModelHighAPI_Double& theAngle)
114 {
115   fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
116   fillAttribute(theAngle, mytoAngle);
117   fillAttribute(ModelHighAPI_Double(), myfromAngle);
118
119   execIfBaseNotEmpty();
120 }
121
122 //==================================================================================================
123 void FeaturesAPI_Revolution::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
124                                                 const ModelHighAPI_Double& theToOffset,
125                                                 const ModelHighAPI_Selection& theFromObject,
126                                                 const ModelHighAPI_Double& theFromOffset)
127 {
128   fillAttribute("ByPlanesAndOffsets", mycreationMethod);
129   fillAttribute(theToObject, mytoObject);
130   fillAttribute(theToOffset, mytoOffset);
131   fillAttribute(theFromObject, myfromObject);
132   fillAttribute(theFromOffset, myfromOffset);
133
134   execIfBaseNotEmpty();
135 }
136
137 //==================================================================================================
138 void FeaturesAPI_Revolution::dump(ModelHighAPI_Dumper& theDumper) const
139 {
140   FeaturePtr aBase = feature();
141   const std::string& aDocName = theDumper.name(aBase->document());
142
143   AttributeReferencePtr anAttrSketch = aBase->reference(FeaturesPlugin_Revolution::SKETCH_ID());
144   AttributeSelectionListPtr anAttrObjects = aBase->selectionList(FeaturesPlugin_Revolution::BASE_OBJECTS_ID());
145   AttributeSelectionPtr anAttrAxis = aBase->selection(FeaturesPlugin_Revolution::AXIS_OBJECT_ID());
146
147   theDumper << aBase << " = model.addRevolution(" << aDocName << ", ";
148   anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
149   theDumper << ", " << anAttrAxis;
150
151   std::string aCreationMethod = aBase->string(FeaturesPlugin_Revolution::CREATION_METHOD())->value();
152
153   if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES()) {
154     AttributeDoublePtr anAttrToAngle = aBase->real(FeaturesPlugin_Revolution::TO_ANGLE_ID());
155     AttributeDoublePtr anAttrFromAngle = aBase->real(FeaturesPlugin_Revolution::FROM_ANGLE_ID());
156
157     theDumper << ", " << anAttrToAngle << ", " << anAttrFromAngle;
158   } else if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES()) {
159     AttributeSelectionPtr anAttrToObject = aBase->selection(FeaturesPlugin_Revolution::TO_OBJECT_ID());
160     AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Revolution::TO_OFFSET_ID());
161     AttributeSelectionPtr anAttrFromObject = aBase->selection(FeaturesPlugin_Revolution::FROM_OBJECT_ID());
162     AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Revolution::FROM_OFFSET_ID());
163
164     theDumper << ", " << anAttrToObject << ", " << anAttrToOffset << ", " << anAttrFromObject << ", " << anAttrFromOffset;
165   }
166
167   theDumper << ")" << std::endl;
168
169   if(anAttrSketch->isInitialized()) {
170     theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
171   }
172 }
173
174 //==================================================================================================
175 void FeaturesAPI_Revolution::execIfBaseNotEmpty()
176 {
177   if(mybaseObjects->size() > 0) {
178     execute();
179   }
180 }
181
182 //==================================================================================================
183 RevolutionPtr addRevolution(const std::shared_ptr<ModelAPI_Document>& thePart,
184                             const std::list<ModelHighAPI_Selection>& theBaseObjects,
185                             const ModelHighAPI_Selection& theAxis,
186                             const ModelHighAPI_Double& theAngle)
187 {
188   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID());
189   return RevolutionPtr(new FeaturesAPI_Revolution(aFeature, theBaseObjects, theAxis, theAngle));
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& theToAngle,
197                             const ModelHighAPI_Double& theFromAngle)
198 {
199   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID());
200   return RevolutionPtr(new FeaturesAPI_Revolution(aFeature,
201                                                 theBaseObjects,
202                                                 theAxis,
203                                                 theToAngle,
204                                                 theFromAngle));
205 }
206
207 //==================================================================================================
208 RevolutionPtr addRevolution(const std::shared_ptr<ModelAPI_Document>& thePart,
209                             const std::list<ModelHighAPI_Selection>& theBaseObjects,
210                             const ModelHighAPI_Selection& theAxis,
211                             const ModelHighAPI_Selection& theToObject,
212                             const ModelHighAPI_Double& theToOffset,
213                             const ModelHighAPI_Selection& theFromObject,
214                             const ModelHighAPI_Double& theFromOffset)
215 {
216   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID());
217   return RevolutionPtr(new FeaturesAPI_Revolution(aFeature,
218                                                 theBaseObjects,
219                                                 theAxis,
220                                                 theToObject,
221                                                 theToOffset,
222                                                 theFromObject,
223                                                 theFromOffset));
224 }