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