1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "FeaturesAPI_Rotation.h"
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Tools.h>
26 //==================================================================================================
27 FeaturesAPI_Rotation::FeaturesAPI_Rotation(const std::shared_ptr<ModelAPI_Feature>& theFeature)
28 : ModelHighAPI_Interface(theFeature)
33 //==================================================================================================
34 FeaturesAPI_Rotation::FeaturesAPI_Rotation(const std::shared_ptr<ModelAPI_Feature>& theFeature,
35 const std::list<ModelHighAPI_Selection>& theMainObjects,
36 const ModelHighAPI_Selection& theAxisObject,
37 const ModelHighAPI_Double& theAngle)
38 : ModelHighAPI_Interface(theFeature)
41 fillAttribute(theMainObjects, mymainObjects);
42 fillAttribute(theAxisObject, myaxisObject);
47 //==================================================================================================
48 FeaturesAPI_Rotation::FeaturesAPI_Rotation(const std::shared_ptr<ModelAPI_Feature>& theFeature,
49 const std::list<ModelHighAPI_Selection>& theMainObjects,
50 const ModelHighAPI_Selection& theCenterPoint,
51 const ModelHighAPI_Selection& theStartPoint,
52 const ModelHighAPI_Selection& theEndPoint)
53 : ModelHighAPI_Interface(theFeature)
56 fillAttribute(theMainObjects, mymainObjects);
57 setPoints(theCenterPoint, theStartPoint, theEndPoint);
61 //==================================================================================================
62 FeaturesAPI_Rotation::~FeaturesAPI_Rotation()
67 //==================================================================================================
68 void FeaturesAPI_Rotation::setMainObjects(const std::list<ModelHighAPI_Selection>& theMainObjects)
70 fillAttribute(theMainObjects, mymainObjects);
75 //==================================================================================================
76 void FeaturesAPI_Rotation::setAxisObject(const ModelHighAPI_Selection& theAxisObject)
78 fillAttribute(FeaturesPlugin_Rotation::CREATION_METHOD_BY_ANGLE(), mycreationMethod);
79 fillAttribute(theAxisObject, myaxisObject);
84 //==================================================================================================
85 void FeaturesAPI_Rotation::setAngle(const ModelHighAPI_Double& theAngle)
87 fillAttribute(FeaturesPlugin_Rotation::CREATION_METHOD_BY_ANGLE(), mycreationMethod);
88 fillAttribute(theAngle, myangle);
93 //==================================================================================================
94 void FeaturesAPI_Rotation::setPoints(const ModelHighAPI_Selection& theCenterPoint,
95 const ModelHighAPI_Selection& theStartPoint,
96 const ModelHighAPI_Selection& theEndPoint)
98 fillAttribute(FeaturesPlugin_Rotation::CREATION_METHOD_BY_THREE_POINTS(), mycreationMethod);
99 fillAttribute(theCenterPoint, centerPoint());
100 fillAttribute(theStartPoint, startPoint());
101 fillAttribute(theEndPoint, endPoint());
106 //==================================================================================================
107 void FeaturesAPI_Rotation::dump(ModelHighAPI_Dumper& theDumper) const
109 FeaturePtr aBase = feature();
110 const std::string& aDocName = theDumper.name(aBase->document());
112 AttributeSelectionListPtr anAttrObjects =
113 aBase->selectionList(FeaturesPlugin_Rotation::OBJECTS_LIST_ID());
115 theDumper << aBase << " = model.addRotation(" << aDocName << ", " << anAttrObjects;
117 std::string aCreationMethod =
118 aBase->string(FeaturesPlugin_Rotation::CREATION_METHOD())->value();
120 if (aCreationMethod == FeaturesPlugin_Rotation::CREATION_METHOD_BY_ANGLE()) {
121 AttributeSelectionPtr anAttrAxis = aBase->selection(FeaturesPlugin_Rotation::AXIS_OBJECT_ID());
122 AttributeDoublePtr anAttrAngle = aBase->real(FeaturesPlugin_Rotation::ANGLE_ID());
123 theDumper << ", " << anAttrAxis << ", " << anAttrAngle;
124 } else if (aCreationMethod == FeaturesPlugin_Rotation::CREATION_METHOD_BY_THREE_POINTS()) {
125 AttributeSelectionPtr anAttrCenterPoint =
126 aBase->selection(FeaturesPlugin_Rotation::CENTER_POINT_ID());
127 AttributeSelectionPtr anAttrStartPoint =
128 aBase->selection(FeaturesPlugin_Rotation::START_POINT_ID());
129 AttributeSelectionPtr anAttrEndPoint =
130 aBase->selection(FeaturesPlugin_Rotation::END_POINT_ID());
131 theDumper << ", " << anAttrCenterPoint << ", " << anAttrStartPoint << ", " << anAttrEndPoint;
134 theDumper << ")" << std::endl;
137 //==================================================================================================
138 RotationPtr addRotation(const std::shared_ptr<ModelAPI_Document>& thePart,
139 const std::list<ModelHighAPI_Selection>& theMainObjects,
140 const ModelHighAPI_Selection& theAxisObject,
141 const ModelHighAPI_Double& theAngle)
143 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Rotation::ID());
144 return RotationPtr(new FeaturesAPI_Rotation(aFeature, theMainObjects, theAxisObject, theAngle));
147 //==================================================================================================
148 RotationPtr addRotation(const std::shared_ptr<ModelAPI_Document>& thePart,
149 const std::list<ModelHighAPI_Selection>& theMainObjects,
150 const ModelHighAPI_Selection& theCenterPoint,
151 const ModelHighAPI_Selection& theStartPoint,
152 const ModelHighAPI_Selection& theEndPoint)
154 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Rotation::ID());
155 return RotationPtr(new FeaturesAPI_Rotation(aFeature, theMainObjects, theCenterPoint,
156 theStartPoint, theEndPoint));