]> SALOME platform Git repositories - modules/shaper.git/blob - src/FeaturesAPI/FeaturesAPI_Revolution.cpp
Salome HOME
d54b660fb9d4c9c8b460410b0a0c788c376f8077
[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_Tools.h>
12
13 //==================================================================================================
14 FeaturesAPI_Revolution::FeaturesAPI_Revolution(const std::shared_ptr<ModelAPI_Feature>& theFeature)
15 : ModelHighAPI_Interface(theFeature)
16 {
17   initialize();
18 }
19
20 //==================================================================================================
21 FeaturesAPI_Revolution::FeaturesAPI_Revolution(const std::shared_ptr<ModelAPI_Feature>& theFeature,
22                                                const std::list<ModelHighAPI_Selection>& theBaseObjects,
23                                                const ModelHighAPI_Selection& theAxis,
24                                                const ModelHighAPI_Double& theAngle)
25 : ModelHighAPI_Interface(theFeature)
26 {
27   if(initialize()) {
28     fillAttribute(theBaseObjects, mybaseObjects);
29     fillAttribute(theAxis, myaxis);
30     setAngles(theAngle, ModelHighAPI_Double());
31   }
32 }
33
34 //==================================================================================================
35 FeaturesAPI_Revolution::FeaturesAPI_Revolution(const std::shared_ptr<ModelAPI_Feature>& theFeature,
36                                                const std::list<ModelHighAPI_Selection>& theBaseObjects,
37                                                const ModelHighAPI_Selection& theAxis,
38                                                const ModelHighAPI_Double& theToAngle,
39                                                const ModelHighAPI_Double& theFromAngle)
40 : ModelHighAPI_Interface(theFeature)
41 {
42   if(initialize()) {
43     fillAttribute(theBaseObjects, mybaseObjects);
44     fillAttribute(theAxis, myaxis);
45     setAngles(theToAngle, theFromAngle);
46   }
47 }
48
49 //==================================================================================================
50 FeaturesAPI_Revolution::FeaturesAPI_Revolution(const std::shared_ptr<ModelAPI_Feature>& theFeature,
51                                                const std::list<ModelHighAPI_Selection>& theBaseObjects,
52                                                const ModelHighAPI_Selection& theAxis,
53                                                const ModelHighAPI_Selection& theToObject,
54                                                const ModelHighAPI_Double& theToOffset,
55                                                const ModelHighAPI_Selection& theFromObject,
56                                                const ModelHighAPI_Double& theFromOffset)
57 : ModelHighAPI_Interface(theFeature)
58 {
59   if(initialize()) {
60     fillAttribute(theBaseObjects, mybaseObjects);
61     fillAttribute(theAxis, myaxis);
62     setPlanesAndOffsets(theToObject, theToOffset, theFromObject, theFromOffset);
63   }
64 }
65
66 //==================================================================================================
67 FeaturesAPI_Revolution::~FeaturesAPI_Revolution()
68 {
69
70 }
71
72 //==================================================================================================
73 void FeaturesAPI_Revolution::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
74 {
75   fillAttribute(theBaseObjects, mybaseObjects);
76
77   execute();
78 }
79
80 //==================================================================================================
81 void FeaturesAPI_Revolution::setAxis(const ModelHighAPI_Selection& theAxis)
82 {
83   fillAttribute(theAxis, myaxis);
84
85   execute();
86 }
87
88 //==================================================================================================
89 void FeaturesAPI_Revolution::setAngles(const ModelHighAPI_Double& theToAngle,
90                                        const ModelHighAPI_Double& theFromAngle)
91 {
92   fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
93   fillAttribute(theToAngle, mytoAngle);
94   fillAttribute(theFromAngle, myfromAngle);
95
96   execute();
97 }
98
99 //==================================================================================================
100 void FeaturesAPI_Revolution::setAngle(const ModelHighAPI_Double& theAngle)
101 {
102   fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
103   fillAttribute(theAngle, mytoAngle);
104   fillAttribute(ModelHighAPI_Double(), myfromAngle);
105
106   execute();
107 }
108
109 //==================================================================================================
110 void FeaturesAPI_Revolution::setPlanesAndOffsets(const ModelHighAPI_Selection& theToObject,
111                                                 const ModelHighAPI_Double& theToOffset,
112                                                 const ModelHighAPI_Selection& theFromObject,
113                                                 const ModelHighAPI_Double& theFromOffset)
114 {
115   fillAttribute("ByPlanesAndOffsets", mycreationMethod);
116   fillAttribute(theToObject, mytoObject);
117   fillAttribute(theToOffset, mytoOffset);
118   fillAttribute(theFromObject, myfromObject);
119   fillAttribute(theFromOffset, myfromOffset);
120
121   execute();
122 }
123
124 //==================================================================================================
125 void FeaturesAPI_Revolution::dump(ModelHighAPI_Dumper& theDumper) const
126 {
127   FeaturePtr aBase = feature();
128   const std::string& aDocName = theDumper.name(aBase->document());
129
130   AttributeSelectionListPtr anObjects = aBase->selectionList(FeaturesPlugin_Revolution::BASE_OBJECTS_ID());
131   AttributeSelectionPtr anAxis = aBase->selection(FeaturesPlugin_Revolution::AXIS_OBJECT_ID());
132
133   theDumper << aBase << " = model.addRevolution(" << aDocName << ", " << anObjects << ", " << anAxis;
134
135   std::string aCreationMethod = aBase->string(FeaturesPlugin_Revolution::CREATION_METHOD())->value();
136
137   if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES()) {
138     AttributeDoublePtr anAttrToAngle = aBase->real(FeaturesPlugin_Revolution::TO_ANGLE_ID());
139     AttributeDoublePtr anAttrFromAngle = aBase->real(FeaturesPlugin_Revolution::FROM_ANGLE_ID());
140
141     theDumper << ", " << anAttrToAngle << ", " << anAttrFromAngle;
142   } else if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES()) {
143     AttributeSelectionPtr anAttrToObject = aBase->selection(FeaturesPlugin_Revolution::TO_OBJECT_ID());
144     AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Revolution::TO_OFFSET_ID());
145     AttributeSelectionPtr anAttrFromObject = aBase->selection(FeaturesPlugin_Revolution::FROM_OBJECT_ID());
146     AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Revolution::FROM_OFFSET_ID());
147
148     theDumper << ", " << anAttrToObject << ", " << anAttrToOffset << ", " << anAttrFromObject << ", " << anAttrFromOffset;
149   }
150
151   theDumper << ")" << std::endl;
152 }
153
154 //==================================================================================================
155 RevolutionPtr addRevolution(const std::shared_ptr<ModelAPI_Document>& thePart,
156                             const std::list<ModelHighAPI_Selection>& theBaseObjects,
157                             const ModelHighAPI_Selection& theAxis,
158                             const ModelHighAPI_Double& theAngle)
159 {
160   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID());
161   return RevolutionPtr(new FeaturesAPI_Revolution(aFeature, theBaseObjects, theAxis, theAngle));
162 }
163
164 //==================================================================================================
165 RevolutionPtr addRevolution(const std::shared_ptr<ModelAPI_Document>& thePart,
166                             const std::list<ModelHighAPI_Selection>& theBaseObjects,
167                             const ModelHighAPI_Selection& theAxis,
168                             const ModelHighAPI_Double& theToAngle,
169                             const ModelHighAPI_Double& theFromAngle)
170 {
171   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID());
172   return RevolutionPtr(new FeaturesAPI_Revolution(aFeature,
173                                                 theBaseObjects,
174                                                 theAxis,
175                                                 theToAngle,
176                                                 theFromAngle));
177 }
178
179 //==================================================================================================
180 RevolutionPtr addRevolution(const std::shared_ptr<ModelAPI_Document>& thePart,
181                             const std::list<ModelHighAPI_Selection>& theBaseObjects,
182                             const ModelHighAPI_Selection& theAxis,
183                             const ModelHighAPI_Selection& theToObject,
184                             const ModelHighAPI_Double& theToOffset,
185                             const ModelHighAPI_Selection& theFromObject,
186                             const ModelHighAPI_Double& theFromOffset)
187 {
188   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Revolution::ID());
189   return RevolutionPtr(new FeaturesAPI_Revolution(aFeature,
190                                                 theBaseObjects,
191                                                 theAxis,
192                                                 theToObject,
193                                                 theToOffset,
194                                                 theFromObject,
195                                                 theFromOffset));
196 }