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