1 // Copyright (C) 2014-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 #include "FeaturesAPI_Rotation.h"
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Tools.h>
25 //==================================================================================================
26 FeaturesAPI_Rotation::FeaturesAPI_Rotation(const std::shared_ptr<ModelAPI_Feature>& theFeature)
27 : ModelHighAPI_Interface(theFeature)
32 //==================================================================================================
33 FeaturesAPI_Rotation::FeaturesAPI_Rotation(const std::shared_ptr<ModelAPI_Feature>& theFeature,
34 const std::list<ModelHighAPI_Selection>& theMainObjects,
35 const ModelHighAPI_Selection& theAxisObject,
36 const ModelHighAPI_Double& theAngle)
37 : ModelHighAPI_Interface(theFeature)
40 fillAttribute(theMainObjects, mymainObjects);
41 fillAttribute(theAxisObject, myaxisObject);
46 //==================================================================================================
47 FeaturesAPI_Rotation::FeaturesAPI_Rotation(const std::shared_ptr<ModelAPI_Feature>& theFeature,
48 const std::list<ModelHighAPI_Selection>& theMainObjects,
49 const ModelHighAPI_Selection& theCenterPoint,
50 const ModelHighAPI_Selection& theStartPoint,
51 const ModelHighAPI_Selection& theEndPoint)
52 : ModelHighAPI_Interface(theFeature)
55 fillAttribute(theMainObjects, mymainObjects);
56 setPoints(theCenterPoint, theStartPoint, theEndPoint);
60 //==================================================================================================
61 FeaturesAPI_Rotation::~FeaturesAPI_Rotation()
66 //==================================================================================================
67 void FeaturesAPI_Rotation::setMainObjects(const std::list<ModelHighAPI_Selection>& theMainObjects)
69 fillAttribute(theMainObjects, mymainObjects);
74 //==================================================================================================
75 void FeaturesAPI_Rotation::setAxisObject(const ModelHighAPI_Selection& theAxisObject)
77 fillAttribute(FeaturesPlugin_Rotation::CREATION_METHOD_BY_ANGLE(), mycreationMethod);
78 fillAttribute(theAxisObject, myaxisObject);
83 //==================================================================================================
84 void FeaturesAPI_Rotation::setAngle(const ModelHighAPI_Double& theAngle)
86 fillAttribute(FeaturesPlugin_Rotation::CREATION_METHOD_BY_ANGLE(), mycreationMethod);
87 fillAttribute(theAngle, myangle);
92 //==================================================================================================
93 void FeaturesAPI_Rotation::setPoints(const ModelHighAPI_Selection& theCenterPoint,
94 const ModelHighAPI_Selection& theStartPoint,
95 const ModelHighAPI_Selection& theEndPoint)
97 fillAttribute(FeaturesPlugin_Rotation::CREATION_METHOD_BY_THREE_POINTS(), mycreationMethod);
98 fillAttribute(theCenterPoint, centerPoint());
99 fillAttribute(theStartPoint, startPoint());
100 fillAttribute(theEndPoint, endPoint());
105 //==================================================================================================
106 void FeaturesAPI_Rotation::dump(ModelHighAPI_Dumper& theDumper) const
108 FeaturePtr aBase = feature();
109 const std::string& aDocName = theDumper.name(aBase->document());
111 AttributeSelectionListPtr anAttrObjects =
112 aBase->selectionList(FeaturesPlugin_Rotation::OBJECTS_LIST_ID());
114 theDumper << aBase << " = model.addRotation(" << aDocName << ", " << anAttrObjects;
116 std::string aCreationMethod =
117 aBase->string(FeaturesPlugin_Rotation::CREATION_METHOD())->value();
119 if (aCreationMethod == FeaturesPlugin_Rotation::CREATION_METHOD_BY_ANGLE()) {
120 AttributeSelectionPtr anAttrAxis = aBase->selection(FeaturesPlugin_Rotation::AXIS_OBJECT_ID());
121 AttributeDoublePtr anAttrAngle = aBase->real(FeaturesPlugin_Rotation::ANGLE_ID());
122 theDumper << ", " << anAttrAxis << ", " << anAttrAngle;
123 } else if (aCreationMethod == FeaturesPlugin_Rotation::CREATION_METHOD_BY_THREE_POINTS()) {
124 AttributeSelectionPtr anAttrCenterPoint =
125 aBase->selection(FeaturesPlugin_Rotation::CENTER_POINT_ID());
126 AttributeSelectionPtr anAttrStartPoint =
127 aBase->selection(FeaturesPlugin_Rotation::START_POINT_ID());
128 AttributeSelectionPtr anAttrEndPoint =
129 aBase->selection(FeaturesPlugin_Rotation::END_POINT_ID());
130 theDumper << ", " << anAttrCenterPoint << ", " << anAttrStartPoint << ", " << anAttrEndPoint;
133 theDumper << ")" << std::endl;
136 //==================================================================================================
137 RotationPtr addRotation(const std::shared_ptr<ModelAPI_Document>& thePart,
138 const std::list<ModelHighAPI_Selection>& theMainObjects,
139 const ModelHighAPI_Selection& theAxisObject,
140 const ModelHighAPI_Double& theAngle)
142 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Rotation::ID());
143 return RotationPtr(new FeaturesAPI_Rotation(aFeature, theMainObjects, theAxisObject, theAngle));
146 //==================================================================================================
147 RotationPtr addRotation(const std::shared_ptr<ModelAPI_Document>& thePart,
148 const std::list<ModelHighAPI_Selection>& theMainObjects,
149 const ModelHighAPI_Selection& theCenterPoint,
150 const ModelHighAPI_Selection& theStartPoint,
151 const ModelHighAPI_Selection& theEndPoint)
153 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Rotation::ID());
154 return RotationPtr(new FeaturesAPI_Rotation(aFeature, theMainObjects, theCenterPoint,
155 theStartPoint, theEndPoint));