Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[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 #include <iostream>
28
29 //==================================================================================================
30 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature)
31 : ModelHighAPI_Interface(theFeature)
32 {
33   initialize();
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 : ModelHighAPI_Interface(theFeature)
43 {
44   if (initialize()) {
45     fillAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER(), creationMethod());
46     fillAttribute(theBasePoint, basePoint());
47     fillAttribute(theAxis, axis());
48     setSizes(theRadius, theHeight);
49   }
50 }
51
52 //==================================================================================================
53 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature,
54                                      const ModelHighAPI_Selection& theBasePoint,
55                                   const ModelHighAPI_Selection& theAxis,
56                                   const ModelHighAPI_Double& theRadius,
57                                   const ModelHighAPI_Double& theHeight,
58                                   const ModelHighAPI_Double& theAngle)
59 : ModelHighAPI_Interface(theFeature)
60 {
61   if (initialize()) {
62     fillAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION(), creationMethod());
63     fillAttribute(theBasePoint, basePoint());
64     fillAttribute(theAxis, axis());
65     fillAttribute(theAngle, angle());
66     setSizes(theRadius, theHeight);
67   }
68 }
69
70 //==================================================================================================
71 PrimitivesAPI_Cylinder::~PrimitivesAPI_Cylinder()
72 {
73
74 }
75
76 //==================================================================================================
77 void PrimitivesAPI_Cylinder::setSizes(const ModelHighAPI_Double& theRadius,
78                                       const ModelHighAPI_Double& theHeight)
79 {
80   fillAttribute(theRadius, radius());
81   fillAttribute(theHeight, height());
82   execute();
83 }
84
85 //==================================================================================================
86 void PrimitivesAPI_Cylinder::dump(ModelHighAPI_Dumper& theDumper) const
87 {
88   FeaturePtr aBase = feature();
89   const std::string& aDocName = theDumper.name(aBase->document());
90
91   theDumper << aBase << " = model.addCylinder(" << aDocName;
92
93   AttributeSelectionPtr anAttrBasePoint =
94     aBase->selection(PrimitivesPlugin_Cylinder::BASE_POINT_ID());
95   AttributeSelectionPtr anAttrAxis = aBase->selection(PrimitivesPlugin_Cylinder::AXIS_ID());
96   theDumper << ", " << anAttrBasePoint << ", " << anAttrAxis;
97
98   AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Cylinder::RADIUS_ID());
99   AttributeDoublePtr anAttrHeight = aBase->real(PrimitivesPlugin_Cylinder::HEIGHT_ID());
100   theDumper << ", " << anAttrRadius << ", " << anAttrHeight;
101
102   std::string aCreationMethod =
103     aBase->string(PrimitivesPlugin_Cylinder::CREATION_METHOD())->value();
104
105   if (aCreationMethod == PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION()) {
106     AttributeDoublePtr anAttrAngle = aBase->real(PrimitivesPlugin_Cylinder::ANGLE_ID());
107     theDumper << ", " << anAttrAngle;
108   }
109
110   theDumper << ")" << std::endl;
111 }
112
113 //==================================================================================================
114 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
115                         const ModelHighAPI_Selection& theBasePoint,
116                         const ModelHighAPI_Selection& theAxis,
117                         const ModelHighAPI_Double& theRadius,
118                         const ModelHighAPI_Double& theHeight)
119 {
120   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
121   return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
122                                                 theRadius, theHeight));
123 }
124
125 //==================================================================================================
126 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
127                         const ModelHighAPI_Selection& theBasePoint,
128                         const ModelHighAPI_Selection& theAxis,
129                         const ModelHighAPI_Double& theRadius,
130                         const ModelHighAPI_Double& theHeight,
131                         const ModelHighAPI_Double& theAngle)
132 {
133   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
134   return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
135                                                 theRadius, theHeight, theAngle));
136 }
137
138 //==================================================================================================
139 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
140                         const ModelHighAPI_Double& theRadius,
141                         const ModelHighAPI_Double& theHeight)
142 {
143   ModelHighAPI_Selection aBasePoint("VERTEX", "PartSet/Origin");
144   ModelHighAPI_Selection anAxis("EDGE", "PartSet/OZ");
145   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
146   return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, aBasePoint, anAxis,
147                                                 theRadius, theHeight));
148 }
149
150 //==================================================================================================
151 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
152                         const ModelHighAPI_Double& theRadius,
153                         const ModelHighAPI_Double& theHeight,
154                         const ModelHighAPI_Double& theAngle)
155 {
156   ModelHighAPI_Selection aBasePoint("VERTEX", "PartSet/Origin");
157   ModelHighAPI_Selection anAxis("EDGE", "PartSet/OZ");
158   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
159   return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, aBasePoint, anAxis,
160                                                 theRadius, theHeight, theAngle));
161 }