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