1 // Copyright (C) 2017-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: FeaturesAPI_MultiRotation.cpp
21 // Created: 04 Apr 2017
22 // Author: Clarisse Genrault (CEA)
24 #include <FeaturesAPI_MultiRotation.h>
26 #include <ModelHighAPI_Double.h>
27 #include <ModelHighAPI_Dumper.h>
28 #include <ModelHighAPI_Tools.h>
30 //==================================================================================================
31 FeaturesAPI_MultiRotation::FeaturesAPI_MultiRotation(
32 const std::shared_ptr<ModelAPI_Feature>& theFeature)
33 : ModelHighAPI_Interface(theFeature)
39 //==================================================================================================
40 FeaturesAPI_MultiRotation::FeaturesAPI_MultiRotation(
41 const std::shared_ptr<ModelAPI_Feature>& theFeature,
42 const std::list<ModelHighAPI_Selection>& theMainObjects,
43 const ModelHighAPI_Selection& theAxis,
44 const ModelHighAPI_Integer& theNumber)
45 : ModelHighAPI_Interface(theFeature)
48 fillAttribute(theMainObjects, mainObjects());
49 fillAttribute(theAxis, axisAngular());
50 fillAttribute("",useStepAngular());
51 setNumberAngular(theNumber);
55 //==================================================================================================
56 FeaturesAPI_MultiRotation::FeaturesAPI_MultiRotation(
57 const std::shared_ptr<ModelAPI_Feature>& theFeature,
58 const std::list<ModelHighAPI_Selection>& theMainObjects,
59 const ModelHighAPI_Selection& theAxis,
60 const ModelHighAPI_Double& theStep,
61 const ModelHighAPI_Integer& theNumber)
62 : ModelHighAPI_Interface(theFeature)
65 fillAttribute(theMainObjects, mainObjects());
66 fillAttribute(theAxis, axisAngular());
67 fillAttribute(FeaturesPlugin_MultiRotation::USE_ANGULAR_STEP_ID(),useStepAngular());
68 fillAttribute(theStep, stepAngular());
69 setNumberAngular(theNumber);
73 //==================================================================================================
74 FeaturesAPI_MultiRotation::~FeaturesAPI_MultiRotation()
78 //==================================================================================================
79 void FeaturesAPI_MultiRotation::setMainObjects(
80 const std::list<ModelHighAPI_Selection>& theMainObjects)
82 fillAttribute(theMainObjects, mainObjects());
87 //==================================================================================================
88 void FeaturesAPI_MultiRotation::setAxisAngular(const ModelHighAPI_Selection& theAxis)
90 fillAttribute(theAxis, axisAngular());
95 //==================================================================================================
96 void FeaturesAPI_MultiRotation::setStepAngular(const ModelHighAPI_Double& theStep)
98 fillAttribute(theStep, stepAngular());
103 //==================================================================================================
104 void FeaturesAPI_MultiRotation::setNumberAngular(const ModelHighAPI_Integer& theNumber)
106 fillAttribute(theNumber, nbAngular());
111 //==================================================================================================
112 void FeaturesAPI_MultiRotation::dump(ModelHighAPI_Dumper& theDumper) const
114 FeaturePtr aBase = feature();
115 const std::string& aDocName = theDumper.name(aBase->document());
117 AttributeSelectionListPtr anAttrObjects =
118 aBase->selectionList(FeaturesPlugin_MultiRotation::OBJECTS_LIST_ID());
119 theDumper << aBase << " = model.addMultiRotation(" << aDocName << ", " << anAttrObjects;
121 AttributeSelectionPtr anAttrAxis =
122 aBase->selection(FeaturesPlugin_MultiRotation::AXIS_ANGULAR_ID());
123 theDumper << ", " << anAttrAxis;
125 if (aBase->string(FeaturesPlugin_MultiRotation::USE_ANGULAR_STEP_ID())->isInitialized()
126 && !aBase->string(FeaturesPlugin_MultiRotation::USE_ANGULAR_STEP_ID())->value().empty()) {
127 AttributeDoublePtr anAttrStepAngular =
128 aBase->real(FeaturesPlugin_MultiRotation::STEP_ANGULAR_ID());
129 theDumper << ", " << anAttrStepAngular;
132 AttributeIntegerPtr anAttrNumberAngular =
133 aBase->integer(FeaturesPlugin_MultiRotation::NB_COPIES_ANGULAR_ID());
134 theDumper << ", " << anAttrNumberAngular;
136 if (!aBase->data()->version().empty())
137 theDumper << ", keepSubResults = True";
139 theDumper << ")" << std::endl;
142 //==================================================================================================
143 MultiRotationPtr addMultiRotation(const std::shared_ptr<ModelAPI_Document>& thePart,
144 const std::list<ModelHighAPI_Selection>& theMainObjects,
145 const ModelHighAPI_Selection& theAxis,
146 const ModelHighAPI_Double& theStep,
147 const ModelHighAPI_Integer& theNumber,
148 const bool keepSubResults)
150 std::shared_ptr<ModelAPI_Feature> aFeature =
151 thePart->addFeature(FeaturesAPI_MultiRotation::ID());
153 aFeature->data()->setVersion("");
155 MultiRotationPtr aResult;
156 if (theNumber.string().empty()) {
157 // rotate for the whole circle
158 double aStepVal = theStep.value();
159 std::string aStepStr = theStep.string();
160 std::ostringstream aStepValAsStr;
161 aStepValAsStr << aStepVal;
163 ModelHighAPI_Integer aNumber = aStepStr == aStepValAsStr.str()
164 ? ModelHighAPI_Integer(aStepVal)
165 : ModelHighAPI_Integer(aStepStr);
166 aResult.reset(new FeaturesAPI_MultiRotation(aFeature, theMainObjects, theAxis, aNumber));
169 aResult.reset(new FeaturesAPI_MultiRotation(aFeature, theMainObjects,
170 theAxis, theStep, theNumber));