Salome HOME
Fix for the issue #2573: Wrong position of created part
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Rotation.cpp
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "FeaturesAPI_Rotation.h"
22
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Tools.h>
25
26 //==================================================================================================
27 FeaturesAPI_Rotation::FeaturesAPI_Rotation(const std::shared_ptr<ModelAPI_Feature>& theFeature)
28 : ModelHighAPI_Interface(theFeature)
29 {
30   initialize();
31 }
32
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)
39 {
40   if(initialize()) {
41     fillAttribute(theMainObjects, mymainObjects);
42     fillAttribute(theAxisObject, myaxisObject);
43     setAngle(theAngle);
44   }
45 }
46
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)
54 {
55   if(initialize()) {
56     fillAttribute(theMainObjects, mymainObjects);
57     setPoints(theCenterPoint, theStartPoint, theEndPoint);
58   }
59 }
60
61 //==================================================================================================
62 FeaturesAPI_Rotation::~FeaturesAPI_Rotation()
63 {
64
65 }
66
67 //==================================================================================================
68 void FeaturesAPI_Rotation::setMainObjects(const std::list<ModelHighAPI_Selection>& theMainObjects)
69 {
70   fillAttribute(theMainObjects, mymainObjects);
71
72   execute();
73 }
74
75 //==================================================================================================
76 void FeaturesAPI_Rotation::setAxisObject(const ModelHighAPI_Selection& theAxisObject)
77 {
78   fillAttribute(FeaturesPlugin_Rotation::CREATION_METHOD_BY_ANGLE(), mycreationMethod);
79   fillAttribute(theAxisObject, myaxisObject);
80
81   execute();
82 }
83
84 //==================================================================================================
85 void FeaturesAPI_Rotation::setAngle(const ModelHighAPI_Double& theAngle)
86 {
87   fillAttribute(FeaturesPlugin_Rotation::CREATION_METHOD_BY_ANGLE(), mycreationMethod);
88   fillAttribute(theAngle, myangle);
89
90   execute();
91 }
92
93 //==================================================================================================
94 void FeaturesAPI_Rotation::setPoints(const ModelHighAPI_Selection& theCenterPoint,
95                                      const ModelHighAPI_Selection& theStartPoint,
96                                      const ModelHighAPI_Selection& theEndPoint)
97 {
98   fillAttribute(FeaturesPlugin_Rotation::CREATION_METHOD_BY_THREE_POINTS(), mycreationMethod);
99   fillAttribute(theCenterPoint, centerPoint());
100   fillAttribute(theStartPoint, startPoint());
101   fillAttribute(theEndPoint, endPoint());
102
103   execute();
104 }
105
106 //==================================================================================================
107 void FeaturesAPI_Rotation::dump(ModelHighAPI_Dumper& theDumper) const
108 {
109   FeaturePtr aBase = feature();
110   const std::string& aDocName = theDumper.name(aBase->document());
111
112   AttributeSelectionListPtr anAttrObjects =
113     aBase->selectionList(FeaturesPlugin_Rotation::OBJECTS_LIST_ID());
114
115   theDumper << aBase << " = model.addRotation(" << aDocName << ", " << anAttrObjects;
116
117   std::string aCreationMethod =
118     aBase->string(FeaturesPlugin_Rotation::CREATION_METHOD())->value();
119
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;
132   }
133
134   theDumper << ")" << std::endl;
135 }
136
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)
142 {
143   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Rotation::ID());
144   return RotationPtr(new FeaturesAPI_Rotation(aFeature, theMainObjects, theAxisObject, theAngle));
145 }
146
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)
153 {
154   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Rotation::ID());
155   return RotationPtr(new FeaturesAPI_Rotation(aFeature, theMainObjects, theCenterPoint,
156                                               theStartPoint, theEndPoint));
157 }