1 // Copyright (C) 2014-2020 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 << ", axis = " << anAttrAxis << ", angle = " << 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 << ", center = " << anAttrCenterPoint
131 << ", start = " << anAttrStartPoint
132 << ", end = " << anAttrEndPoint;
135 if (!aBase->data()->version().empty())
136 theDumper << ", keepSubResults = True";
138 theDumper << ")" << std::endl;
141 //==================================================================================================
142 RotationPtr addRotation(const std::shared_ptr<ModelAPI_Document>& part,
143 const std::list<ModelHighAPI_Selection>& objects,
144 const ModelHighAPI_Selection& axis,
145 const std::pair<ModelHighAPI_Selection, ModelHighAPI_Double>& angle,
146 const ModelHighAPI_Selection& center,
147 const ModelHighAPI_Selection& start,
148 const ModelHighAPI_Selection& end,
149 const bool keepSubResults)
151 std::shared_ptr<ModelAPI_Feature> aFeature = part->addFeature(FeaturesAPI_Rotation::ID());
153 aFeature->data()->setVersion("");
156 bool byPoints = false;
157 ModelHighAPI_Selection aPoints[3];
158 if (angle.first.variantType() == ModelHighAPI_Selection::VT_Empty) {
159 if (axis.variantType() == ModelHighAPI_Selection::VT_Empty) {
171 aPoints[1] = angle.first;
176 RotationPtr aRotation;
178 aRotation.reset(new FeaturesAPI_Rotation(aFeature, objects, axis, angle.second));
180 aRotation.reset(new FeaturesAPI_Rotation(aFeature, objects,
181 aPoints[0], aPoints[1], aPoints[2]));