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