Salome HOME
Meet the coding style (line length <= 100)
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Rotation.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        FeaturesAPI_Rotation.cpp
4 // Created:     07 June 2016
5 // Author:      Dmitry Bobylev
6
7 #include "FeaturesAPI_Rotation.h"
8
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Tools.h>
11
12 //==================================================================================================
13 FeaturesAPI_Rotation::FeaturesAPI_Rotation(const std::shared_ptr<ModelAPI_Feature>& theFeature)
14 : ModelHighAPI_Interface(theFeature)
15 {
16   initialize();
17 }
18
19 //==================================================================================================
20 FeaturesAPI_Rotation::FeaturesAPI_Rotation(const std::shared_ptr<ModelAPI_Feature>& theFeature,
21                                            const std::list<ModelHighAPI_Selection>& theMainObjects,
22                                            const ModelHighAPI_Selection& theAxisObject,
23                                            const ModelHighAPI_Double& theAngle)
24 : ModelHighAPI_Interface(theFeature)
25 {
26   if(initialize()) {
27     fillAttribute(theMainObjects, mymainObjects);
28     fillAttribute(theAxisObject, myaxisObject);
29     setAngle(theAngle);
30   }
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& theCenterPoint,
37                                            const ModelHighAPI_Selection& theStartPoint,
38                                            const ModelHighAPI_Selection& theEndPoint)
39 : ModelHighAPI_Interface(theFeature)
40 {
41   if(initialize()) {
42     fillAttribute(theMainObjects, mymainObjects);
43     setPoints(theCenterPoint, theStartPoint, theEndPoint);
44   }
45 }
46
47 //==================================================================================================
48 FeaturesAPI_Rotation::~FeaturesAPI_Rotation()
49 {
50
51 }
52
53 //==================================================================================================
54 void FeaturesAPI_Rotation::setMainObjects(const std::list<ModelHighAPI_Selection>& theMainObjects)
55 {
56   fillAttribute(theMainObjects, mymainObjects);
57
58   execute();
59 }
60
61 //==================================================================================================
62 void FeaturesAPI_Rotation::setAxisObject(const ModelHighAPI_Selection& theAxisObject)
63 {
64   fillAttribute(FeaturesPlugin_Rotation::CREATION_METHOD_BY_ANGLE(), mycreationMethod);
65   fillAttribute(theAxisObject, myaxisObject);
66
67   execute();
68 }
69
70 //==================================================================================================
71 void FeaturesAPI_Rotation::setAngle(const ModelHighAPI_Double& theAngle)
72 {
73   fillAttribute(FeaturesPlugin_Rotation::CREATION_METHOD_BY_ANGLE(), mycreationMethod);
74   fillAttribute(theAngle, myangle);
75
76   execute();
77 }
78
79 //==================================================================================================
80 void FeaturesAPI_Rotation::setPoints(const ModelHighAPI_Selection& theCenterPoint,
81                                      const ModelHighAPI_Selection& theStartPoint,
82                                      const ModelHighAPI_Selection& theEndPoint)
83 {
84   fillAttribute(FeaturesPlugin_Rotation::CREATION_METHOD_BY_THREE_POINTS(), mycreationMethod);
85   fillAttribute(theCenterPoint, centerPoint());
86   fillAttribute(theStartPoint, startPoint());
87   fillAttribute(theEndPoint, endPoint());
88
89   execute();
90 }
91
92 //==================================================================================================
93 void FeaturesAPI_Rotation::dump(ModelHighAPI_Dumper& theDumper) const
94 {
95   FeaturePtr aBase = feature();
96   const std::string& aDocName = theDumper.name(aBase->document());
97
98   AttributeSelectionListPtr anAttrObjects =
99     aBase->selectionList(FeaturesPlugin_Rotation::OBJECTS_LIST_ID());
100
101   theDumper << aBase << " = model.addRotation(" << aDocName << ", " << anAttrObjects;
102
103   std::string aCreationMethod =
104     aBase->string(FeaturesPlugin_Rotation::CREATION_METHOD())->value();
105
106   if (aCreationMethod == FeaturesPlugin_Rotation::CREATION_METHOD_BY_ANGLE()) {
107     AttributeSelectionPtr anAttrAxis = aBase->selection(FeaturesPlugin_Rotation::AXIS_OBJECT_ID());
108     AttributeDoublePtr anAttrAngle = aBase->real(FeaturesPlugin_Rotation::ANGLE_ID());
109     theDumper << ", " << anAttrAxis << ", " << anAttrAngle;
110   } else if (aCreationMethod == FeaturesPlugin_Rotation::CREATION_METHOD_BY_THREE_POINTS()) {
111     AttributeSelectionPtr anAttrCenterPoint =
112       aBase->selection(FeaturesPlugin_Rotation::CENTER_POINT_ID());
113     AttributeSelectionPtr anAttrStartPoint =
114       aBase->selection(FeaturesPlugin_Rotation::START_POINT_ID());
115     AttributeSelectionPtr anAttrEndPoint =
116       aBase->selection(FeaturesPlugin_Rotation::END_POINT_ID());
117     theDumper << ", " << anAttrCenterPoint << ", " << anAttrStartPoint << ", " << anAttrEndPoint;
118   }
119
120   theDumper << ")" << std::endl;
121 }
122
123 //==================================================================================================
124 RotationPtr addRotation(const std::shared_ptr<ModelAPI_Document>& thePart,
125                         const std::list<ModelHighAPI_Selection>& theMainObjects,
126                         const ModelHighAPI_Selection& theAxisObject,
127                         const ModelHighAPI_Double& theAngle)
128 {
129   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Rotation::ID());
130   return RotationPtr(new FeaturesAPI_Rotation(aFeature, theMainObjects, theAxisObject, theAngle));
131 }
132
133 //==================================================================================================
134 RotationPtr addRotation(const std::shared_ptr<ModelAPI_Document>& thePart,
135                         const std::list<ModelHighAPI_Selection>& theMainObjects,
136                         const ModelHighAPI_Selection& theCenterPoint,
137                         const ModelHighAPI_Selection& theStartPoint,
138                         const ModelHighAPI_Selection& theEndPoint)
139 {
140   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Rotation::ID());
141   return RotationPtr(new FeaturesAPI_Rotation(aFeature, theMainObjects, theCenterPoint,
142                                               theStartPoint, theEndPoint));
143 }