Salome HOME
Correction following passing of unit tests.
[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 #include <iostream>
14
15 //==================================================================================================
16 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature)
17 : ModelHighAPI_Interface(theFeature)
18 {
19   initialize();
20 }
21
22 //==================================================================================================
23 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature,
24                                      const ModelHighAPI_Selection& theBasePoint,
25                                   const ModelHighAPI_Selection& theAxis,
26                                   const ModelHighAPI_Double& theRadius,
27                                   const ModelHighAPI_Double& theHeight)
28 : ModelHighAPI_Interface(theFeature)
29 {
30   if (initialize()) {
31     fillAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER(), creationMethod());
32     fillAttribute(theBasePoint, basePoint());
33     fillAttribute(theAxis, axis());
34     setSizes(theRadius, theHeight);
35   }
36 }
37
38 //==================================================================================================
39 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature,
40                                      const ModelHighAPI_Selection& theBasePoint,
41                                   const ModelHighAPI_Selection& theAxis,
42                                   const ModelHighAPI_Double& theRadius,
43                                   const ModelHighAPI_Double& theHeight,
44                                   const ModelHighAPI_Double& theAngle)
45 : ModelHighAPI_Interface(theFeature)
46 {
47   if (initialize()) {
48     fillAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION(), creationMethod());
49     fillAttribute(theBasePoint, basePoint());
50     fillAttribute(theAxis, axis());
51     fillAttribute(theAngle, angle());
52     setSizes(theRadius, theHeight);
53   }
54 }
55
56 //==================================================================================================
57 PrimitivesAPI_Cylinder::~PrimitivesAPI_Cylinder()
58 {
59
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   execute();
69 }
70
71 //==================================================================================================
72 void PrimitivesAPI_Cylinder::dump(ModelHighAPI_Dumper& theDumper) const
73 {
74   FeaturePtr aBase = feature();
75   const std::string& aDocName = theDumper.name(aBase->document());
76
77   theDumper << aBase << " = model.addCylinder(" << aDocName;
78
79   AttributeSelectionPtr anAttrBasePoint =
80     aBase->selection(PrimitivesPlugin_Cylinder::BASE_POINT_ID());
81   AttributeSelectionPtr anAttrAxis = aBase->selection(PrimitivesPlugin_Cylinder::AXIS_ID());
82   theDumper << ", " << anAttrBasePoint << ", " << anAttrAxis;
83
84   AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Cylinder::RADIUS_ID());
85   AttributeDoublePtr anAttrHeight = aBase->real(PrimitivesPlugin_Cylinder::HEIGHT_ID());
86   theDumper << ", " << anAttrRadius << ", " << anAttrHeight;
87
88   std::string aCreationMethod =
89     aBase->string(PrimitivesPlugin_Cylinder::CREATION_METHOD())->value();
90
91   if (aCreationMethod == PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION()) {
92     AttributeDoublePtr anAttrAngle = aBase->real(PrimitivesPlugin_Cylinder::ANGLE_ID());
93     theDumper << ", " << anAttrAngle;
94   }
95
96   theDumper << ")" << std::endl;
97 }
98
99 //==================================================================================================
100 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
101                         const ModelHighAPI_Selection& theBasePoint,
102                         const ModelHighAPI_Selection& theAxis,
103                         const ModelHighAPI_Double& theRadius,
104                         const ModelHighAPI_Double& theHeight)
105 {
106   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
107   return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
108                                                 theRadius, theHeight));
109 }
110
111 //==================================================================================================
112 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
113                         const ModelHighAPI_Selection& theBasePoint,
114                         const ModelHighAPI_Selection& theAxis,
115                         const ModelHighAPI_Double& theRadius,
116                         const ModelHighAPI_Double& theHeight,
117                         const ModelHighAPI_Double& theAngle)
118 {
119   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
120   return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
121                                                 theRadius, theHeight, theAngle));
122 }
123
124 //==================================================================================================
125 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
126                         const ModelHighAPI_Double& theRadius,
127                         const ModelHighAPI_Double& theHeight)
128 {
129   ModelHighAPI_Selection aBasePoint("VERTEX", "PartSet/Origin");
130   ModelHighAPI_Selection anAxis("EDGE", "PartSet/OZ");
131   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
132   return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, aBasePoint, anAxis,
133                                                 theRadius, theHeight));
134 }
135
136 //==================================================================================================
137 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
138                         const ModelHighAPI_Double& theRadius,
139                         const ModelHighAPI_Double& theHeight,
140                         const ModelHighAPI_Double& theAngle)
141 {
142   ModelHighAPI_Selection aBasePoint("VERTEX", "PartSet/Origin");
143   ModelHighAPI_Selection anAxis("EDGE", "PartSet/OZ");
144   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
145   return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, aBasePoint, anAxis,
146                                                 theRadius, theHeight, theAngle));
147 }