Salome HOME
Adding the "Cylinder" primitive (the following).
[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(theBasePoint, basePoint());
30     fillAttribute(theAxis, axis());
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(theBasePoint, basePoint());
46     fillAttribute(theAxis, axis());
47     fillAttribute(theAngle, angle());
48     setSizes(theRadius, theHeight);
49   }
50 }
51
52 //==================================================================================================
53 PrimitivesAPI_Cylinder::~PrimitivesAPI_Cylinder()
54 {
55
56 }
57
58 //==================================================================================================
59 void PrimitivesAPI_Cylinder::setSizes(const ModelHighAPI_Double& theRadius,
60                                       const ModelHighAPI_Double& theHeight)
61 {
62   fillAttribute(theRadius, radius());
63   fillAttribute(theHeight, height());
64   execute();
65 }
66
67 //==================================================================================================
68 void PrimitivesAPI_Cylinder::dump(ModelHighAPI_Dumper& theDumper) const
69 {
70   FeaturePtr aBase = feature();
71   const std::string& aDocName = theDumper.name(aBase->document());
72
73   theDumper << aBase << " = model.addCylinder(" << aDocName;
74
75   AttributeSelectionPtr anAttrBasePoint =
76     aBase->selection(PrimitivesPlugin_Cylinder::BASE_POINT_ID());
77   AttributeSelectionPtr anAttrAxis = aBase->selection(PrimitivesPlugin_Cylinder::AXIS_ID());
78   theDumper << ", " << anAttrBasePoint << ", " << anAttrAxis;
79
80   AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Cylinder::RADIUS_ID());
81   AttributeDoublePtr anAttrHeight = aBase->real(PrimitivesPlugin_Cylinder::HEIGHT_ID());
82   theDumper << ", " << anAttrRadius << ", " << anAttrHeight;
83
84   std::string aCreationMethod =
85     aBase->string(PrimitivesPlugin_Cylinder::CREATION_METHOD())->value();
86
87   if (aCreationMethod == PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION()) {
88     AttributeDoublePtr anAttrAngle = aBase->real(PrimitivesPlugin_Cylinder::ANGLE_ID());
89     theDumper << ", " << anAttrAngle;
90   }
91
92   theDumper << ")" << std::endl;
93 }
94
95 //==================================================================================================
96 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
97                         const ModelHighAPI_Selection& theBasePoint,
98                         const ModelHighAPI_Selection& theAxis,
99                         const ModelHighAPI_Double& theRadius,
100                         const ModelHighAPI_Double& theHeight)
101 {
102   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
103   return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
104                                                 theRadius, theHeight));
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_Double& theRadius,
123                         const ModelHighAPI_Double& theHeight)
124 {
125   ModelHighAPI_Selection aBasePoint("VERT", "Origin");
126   ModelHighAPI_Selection anAxis("EDGE", "OZ");
127   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
128   return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, aBasePoint, anAxis,
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   ModelHighAPI_Selection aBasePoint("VERT", "Origin");
139   ModelHighAPI_Selection anAxis("EDGE", "OZ");
140   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
141   return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, aBasePoint, anAxis,
142                                                 theRadius, theHeight));
143 }