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