Salome HOME
Update copyrights
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_MultiRotation.cpp
1 // Copyright (C) 2017-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File:        FeaturesAPI_MultiRotation.cpp
21 // Created:     04 Apr 2017
22 // Author:      Clarisse Genrault (CEA)
23
24 #include <FeaturesAPI_MultiRotation.h>
25
26 #include <ModelHighAPI_Dumper.h>
27 #include <ModelHighAPI_Tools.h>
28
29 //==================================================================================================
30 FeaturesAPI_MultiRotation::FeaturesAPI_MultiRotation(
31   const std::shared_ptr<ModelAPI_Feature>& theFeature)
32 : ModelHighAPI_Interface(theFeature)
33 {
34   initialize();
35 }
36
37
38 //==================================================================================================
39 FeaturesAPI_MultiRotation::FeaturesAPI_MultiRotation(
40   const std::shared_ptr<ModelAPI_Feature>& theFeature,
41   const std::list<ModelHighAPI_Selection>& theMainObjects,
42   const ModelHighAPI_Selection& theAxis,
43   const ModelHighAPI_Integer& theNumber)
44 : ModelHighAPI_Interface(theFeature)
45 {
46   if(initialize()) {
47     fillAttribute(theMainObjects, mainObjects());
48     fillAttribute(theAxis, axisAngular());
49     fillAttribute("",useStepAngular());
50     setNumberAngular(theNumber);
51   }
52 }
53
54 //==================================================================================================
55 FeaturesAPI_MultiRotation::FeaturesAPI_MultiRotation(
56   const std::shared_ptr<ModelAPI_Feature>& theFeature,
57   const std::list<ModelHighAPI_Selection>& theMainObjects,
58   const ModelHighAPI_Selection& theAxis,
59   const ModelHighAPI_Double& theStep,
60   const ModelHighAPI_Integer& theNumber)
61 : ModelHighAPI_Interface(theFeature)
62 {
63   if(initialize()) {
64     fillAttribute(theMainObjects, mainObjects());
65     fillAttribute(theAxis, axisAngular());
66     fillAttribute(FeaturesPlugin_MultiRotation::USE_ANGULAR_STEP_ID(),useStepAngular());
67     fillAttribute(theStep, stepAngular());
68     setNumberAngular(theNumber);
69   }
70 }
71
72 //==================================================================================================
73 FeaturesAPI_MultiRotation::~FeaturesAPI_MultiRotation()
74 {
75 }
76
77 //==================================================================================================
78 void FeaturesAPI_MultiRotation::setMainObjects(
79   const std::list<ModelHighAPI_Selection>& theMainObjects)
80 {
81   fillAttribute(theMainObjects, mainObjects());
82
83   execute();
84 }
85
86 //==================================================================================================
87 void FeaturesAPI_MultiRotation::setAxisAngular(const ModelHighAPI_Selection& theAxis)
88 {
89   fillAttribute(theAxis, axisAngular());
90
91   execute();
92 }
93
94 //==================================================================================================
95 void FeaturesAPI_MultiRotation::setStepAngular(const ModelHighAPI_Double& theStep)
96 {
97   fillAttribute(theStep, stepAngular());
98
99   execute();
100 }
101
102 //==================================================================================================
103 void FeaturesAPI_MultiRotation::setNumberAngular(const ModelHighAPI_Integer& theNumber)
104 {
105   fillAttribute(theNumber, nbAngular());
106
107   execute();
108 }
109
110 //==================================================================================================
111 void FeaturesAPI_MultiRotation::dump(ModelHighAPI_Dumper& theDumper) const
112 {
113   FeaturePtr aBase = feature();
114   const std::string& aDocName = theDumper.name(aBase->document());
115
116   AttributeSelectionListPtr anAttrObjects =
117     aBase->selectionList(FeaturesPlugin_MultiRotation::OBJECTS_LIST_ID());
118   theDumper << aBase << " = model.addMultiRotation(" << aDocName << ", " << anAttrObjects;
119
120   AttributeSelectionPtr anAttrAxis =
121     aBase->selection(FeaturesPlugin_MultiRotation::AXIS_ANGULAR_ID());
122   theDumper << ", " << anAttrAxis;
123
124   if (aBase->string(FeaturesPlugin_MultiRotation::USE_ANGULAR_STEP_ID())->isInitialized()
125       && !aBase->string(FeaturesPlugin_MultiRotation::USE_ANGULAR_STEP_ID())->value().empty()) {
126     AttributeDoublePtr anAttrStepAngular =
127       aBase->real(FeaturesPlugin_MultiRotation::STEP_ANGULAR_ID());
128       theDumper << ", " << anAttrStepAngular;
129   }
130
131   AttributeIntegerPtr anAttrNumberAngular =
132     aBase->integer(FeaturesPlugin_MultiRotation::NB_COPIES_ANGULAR_ID());
133   theDumper << ", " << anAttrNumberAngular;
134
135   theDumper << ")" << std::endl;
136 }
137
138 //==================================================================================================
139 MultiRotationPtr addMultiRotation(const std::shared_ptr<ModelAPI_Document>& thePart,
140                                   const std::list<ModelHighAPI_Selection>& theMainObjects,
141                                   const ModelHighAPI_Selection& theAxis,
142                                   const ModelHighAPI_Integer& theNumber)
143 {
144   std::shared_ptr<ModelAPI_Feature> aFeature =
145     thePart->addFeature(FeaturesAPI_MultiRotation::ID());
146   return MultiRotationPtr(new FeaturesAPI_MultiRotation(aFeature, theMainObjects,
147                                                         theAxis, theNumber));
148 }
149
150 //==================================================================================================
151 MultiRotationPtr addMultiRotation(const std::shared_ptr<ModelAPI_Document>& thePart,
152                                   const std::list<ModelHighAPI_Selection>& theMainObjects,
153                                   const ModelHighAPI_Selection& theAxis,
154                                   const ModelHighAPI_Double& theStep,
155                                   const ModelHighAPI_Integer& theNumber)
156 {
157   std::shared_ptr<ModelAPI_Feature> aFeature =
158     thePart->addFeature(FeaturesAPI_MultiRotation::ID());
159   return MultiRotationPtr(new FeaturesAPI_MultiRotation(aFeature, theMainObjects,
160                                                         theAxis, theStep, theNumber));
161 }