Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / PrimitivesAPI / PrimitivesAPI_Cylinder.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        PrimitivesAPI_Cylinder.h
4 // Created:     12 Jan 2017
5 // Author:      Clarisse Genrault (CEA)
6
7 #include "PrimitivesAPI_Cylinder.h"
8
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Selection.h>
11 #include <ModelHighAPI_Tools.h>
12
13 //==================================================================================================
14 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature)
15 : ModelHighAPI_Interface(theFeature)
16 {
17   initialize();
18 }
19
20 //==================================================================================================
21 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature,
22                                                const ModelHighAPI_Selection& theBasePoint,
23                                                const ModelHighAPI_Selection& theAxis,
24                                                const ModelHighAPI_Double& theRadius,
25                                                const ModelHighAPI_Double& theHeight)
26 : ModelHighAPI_Interface(theFeature)
27 {
28   if (initialize()) {
29     fillAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER(), creationMethod());
30     setObjects(theBasePoint, theAxis);
31     setSizes(theRadius, theHeight);
32   }
33 }
34
35 //==================================================================================================
36 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature,
37                                                const ModelHighAPI_Selection& theBasePoint,
38                                                const ModelHighAPI_Selection& theAxis,
39                                                const ModelHighAPI_Double& theRadius,
40                                                const ModelHighAPI_Double& theHeight,
41                                                const ModelHighAPI_Double& theAngle)
42 : ModelHighAPI_Interface(theFeature)
43 {
44   if (initialize()) {
45     fillAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION(), creationMethod());
46     setObjects(theBasePoint, theAxis);
47     setSizes(theRadius, theHeight);
48     setAngle(theAngle);
49   }
50 }
51
52 //==================================================================================================
53 void PrimitivesAPI_Cylinder::setObjects(const ModelHighAPI_Selection& theBasePoint,
54                                         const ModelHighAPI_Selection& theAxis)
55 {
56   fillAttribute(theBasePoint, basePoint());
57   fillAttribute(theAxis, axis());
58
59   execute();
60 }
61
62 //==================================================================================================
63 void PrimitivesAPI_Cylinder::setSizes(const ModelHighAPI_Double& theRadius,
64                                       const ModelHighAPI_Double& theHeight)
65 {
66   fillAttribute(theRadius, radius());
67   fillAttribute(theHeight, height());
68
69   execute();
70 }
71
72 //==================================================================================================
73 void PrimitivesAPI_Cylinder::setAngle(const ModelHighAPI_Double& theAngle)
74 {
75   fillAttribute(theAngle, angle());
76
77   execute();
78 }
79
80 //==================================================================================================
81 void PrimitivesAPI_Cylinder::dump(ModelHighAPI_Dumper& theDumper) const
82 {
83   FeaturePtr aBase = feature();
84   const std::string& aDocName = theDumper.name(aBase->document());
85
86   theDumper << aBase << " = model.addCylinder(" << aDocName;
87
88   std::string aCreationMethod = aBase->string(PrimitivesPlugin_Cylinder::CREATION_METHOD())->value();
89   
90   AttributeSelectionPtr anAttrBasePoint =
91     aBase->selection(PrimitivesPlugin_Cylinder::BASE_POINT_ID());
92   AttributeSelectionPtr anAttrAxis = aBase->selection(PrimitivesPlugin_Cylinder::AXIS_ID());
93   AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Cylinder::RADIUS_ID());
94   AttributeDoublePtr anAttrHeight = aBase->real(PrimitivesPlugin_Cylinder::HEIGHT_ID());
95   
96   theDumper << ", " << anAttrBasePoint << ", " << anAttrAxis;
97   theDumper << ", " << anAttrRadius << ", " << anAttrHeight;
98   
99   if (aCreationMethod == PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION()) {
100     AttributeDoublePtr anAttrAngle = aBase->real(PrimitivesPlugin_Cylinder::ANGLE_ID());
101     theDumper << ", " << anAttrAngle;
102   }
103
104   theDumper << ")" << std::endl;
105 }
106
107 //==================================================================================================
108 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
109                         const ModelHighAPI_Selection& theBasePoint,
110                         const ModelHighAPI_Selection& theAxis,
111                         const ModelHighAPI_Double& theRadius,
112                         const ModelHighAPI_Double& theHeight,
113                         const ModelHighAPI_Double& theAngle)
114 {
115   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
116   return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
117                                                 theRadius, theHeight, theAngle));
118 }
119
120 //==================================================================================================
121 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
122                         const ModelHighAPI_Selection& theBasePoint,
123                         const ModelHighAPI_Selection& theAxis,
124                         const ModelHighAPI_Double& theRadius,
125                         const ModelHighAPI_Double& theHeight)
126 {
127   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
128   return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
129                                                 theRadius, theHeight));
130 }
131
132 //==================================================================================================
133 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
134                         const ModelHighAPI_Double& theRadius,
135                         const ModelHighAPI_Double& theHeight,
136                         const ModelHighAPI_Double& theAngle)
137 {
138   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
139   ModelHighAPI_Selection aBasePoint("VERT", "Origin");
140   ModelHighAPI_Selection anAxis("EDGE", "OZ");
141   return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, aBasePoint, anAxis,
142                                                 theRadius, theHeight, theAngle));
143 }
144
145 //==================================================================================================
146 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
147                         const ModelHighAPI_Double& theRadius,
148                         const ModelHighAPI_Double& theHeight)
149 {
150   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
151   ModelHighAPI_Selection aBasePoint("VERT", "Origin");
152   ModelHighAPI_Selection anAxis("EDGE", "OZ");
153   return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, aBasePoint, anAxis,
154                                                 theRadius, theHeight));
155 }