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