Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / PrimitivesAPI / PrimitivesAPI_Cylinder.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "PrimitivesAPI_Cylinder.h"
22
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Selection.h>
25 #include <ModelHighAPI_Tools.h>
26
27 //==================================================================================================
28 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature)
29 : ModelHighAPI_Interface(theFeature)
30 {
31   initialize();
32 }
33
34 //==================================================================================================
35 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature,
36                                                const ModelHighAPI_Selection& theBasePoint,
37                                                const ModelHighAPI_Selection& theAxis,
38                                                const ModelHighAPI_Double& theRadius,
39                                                const ModelHighAPI_Double& theHeight)
40 : ModelHighAPI_Interface(theFeature)
41 {
42   if (initialize()) {
43     fillAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER(), creationMethod());
44     fillAttribute(theBasePoint, basePoint());
45     fillAttribute(theAxis, axis());
46     setSizes(theRadius, theHeight);
47   }
48 }
49
50 //==================================================================================================
51 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature,
52                                                const ModelHighAPI_Selection& theBasePoint,
53                                                const ModelHighAPI_Selection& theAxis,
54                                                const ModelHighAPI_Double& theRadius,
55                                                const ModelHighAPI_Double& theHeight,
56                                                const ModelHighAPI_Double& theAngle)
57 : ModelHighAPI_Interface(theFeature)
58 {
59   if (initialize()) {
60     fillAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION(), creationMethod());
61     fillAttribute(theBasePoint, basePoint());
62     fillAttribute(theAxis, axis());
63     fillAttribute(theAngle, angle());
64     setSizes(theRadius, theHeight);
65   }
66 }
67
68 //==================================================================================================
69 PrimitivesAPI_Cylinder::~PrimitivesAPI_Cylinder()
70 {
71
72 }
73
74 //==================================================================================================
75 void PrimitivesAPI_Cylinder::setSizes(const ModelHighAPI_Double& theRadius,
76                                       const ModelHighAPI_Double& theHeight)
77 {
78   fillAttribute(theRadius, radius());
79   fillAttribute(theHeight, height());
80   execute();
81 }
82
83 //==================================================================================================
84 void PrimitivesAPI_Cylinder::dump(ModelHighAPI_Dumper& theDumper) const
85 {
86   FeaturePtr aBase = feature();
87   const std::string& aDocName = theDumper.name(aBase->document());
88
89   theDumper << aBase << " = model.addCylinder(" << aDocName;
90
91   AttributeSelectionPtr anAttrBasePoint =
92     aBase->selection(PrimitivesPlugin_Cylinder::BASE_POINT_ID());
93   AttributeSelectionPtr anAttrAxis = aBase->selection(PrimitivesPlugin_Cylinder::AXIS_ID());
94   theDumper << ", " << anAttrBasePoint << ", " << anAttrAxis;
95
96   AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Cylinder::RADIUS_ID());
97   AttributeDoublePtr anAttrHeight = aBase->real(PrimitivesPlugin_Cylinder::HEIGHT_ID());
98   theDumper << ", " << anAttrRadius << ", " << anAttrHeight;
99
100   std::string aCreationMethod =
101     aBase->string(PrimitivesPlugin_Cylinder::CREATION_METHOD())->value();
102
103   if (aCreationMethod == PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION()) {
104     AttributeDoublePtr anAttrAngle = aBase->real(PrimitivesPlugin_Cylinder::ANGLE_ID());
105     theDumper << ", " << anAttrAngle;
106   }
107
108   theDumper << ")" << std::endl;
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 {
118   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
119   return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
120                                                 theRadius, theHeight));
121 }
122
123 //==================================================================================================
124 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
125                         const ModelHighAPI_Selection& theBasePoint,
126                         const ModelHighAPI_Selection& theAxis,
127                         const ModelHighAPI_Double& theRadius,
128                         const ModelHighAPI_Double& theHeight,
129                         const ModelHighAPI_Double& theAngle)
130 {
131   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
132   return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
133                                                 theRadius, theHeight, theAngle));
134 }
135
136 //==================================================================================================
137 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
138                         const ModelHighAPI_Double& theRadius,
139                         const ModelHighAPI_Double& theHeight)
140 {
141   ModelHighAPI_Selection aBasePoint("VERTEX", "PartSet/Origin");
142   ModelHighAPI_Selection anAxis("EDGE", "PartSet/OZ");
143   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
144   return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, aBasePoint, anAxis,
145                                                 theRadius, theHeight));
146 }
147
148 //==================================================================================================
149 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
150                         const ModelHighAPI_Double& theRadius,
151                         const ModelHighAPI_Double& theHeight,
152                         const ModelHighAPI_Double& theAngle)
153 {
154   ModelHighAPI_Selection aBasePoint("VERTEX", "PartSet/Origin");
155   ModelHighAPI_Selection anAxis("EDGE", "PartSet/OZ");
156   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
157   return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, aBasePoint, anAxis,
158                                                 theRadius, theHeight, theAngle));
159 }