1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "PrimitivesAPI_Cylinder.h"
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Selection.h>
25 #include <ModelHighAPI_Tools.h>
29 //==================================================================================================
30 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature)
31 : ModelHighAPI_Interface(theFeature)
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)
45 fillAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER(), creationMethod());
46 fillAttribute(theBasePoint, basePoint());
47 fillAttribute(theAxis, axis());
48 setSizes(theRadius, theHeight);
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)
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);
70 //==================================================================================================
71 PrimitivesAPI_Cylinder::~PrimitivesAPI_Cylinder()
76 //==================================================================================================
77 void PrimitivesAPI_Cylinder::setSizes(const ModelHighAPI_Double& theRadius,
78 const ModelHighAPI_Double& theHeight)
80 fillAttribute(theRadius, radius());
81 fillAttribute(theHeight, height());
85 //==================================================================================================
86 void PrimitivesAPI_Cylinder::dump(ModelHighAPI_Dumper& theDumper) const
88 FeaturePtr aBase = feature();
89 const std::string& aDocName = theDumper.name(aBase->document());
91 theDumper << aBase << " = model.addCylinder(" << aDocName;
93 AttributeSelectionPtr anAttrBasePoint =
94 aBase->selection(PrimitivesPlugin_Cylinder::BASE_POINT_ID());
95 AttributeSelectionPtr anAttrAxis = aBase->selection(PrimitivesPlugin_Cylinder::AXIS_ID());
96 theDumper << ", " << anAttrBasePoint << ", " << anAttrAxis;
98 AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Cylinder::RADIUS_ID());
99 AttributeDoublePtr anAttrHeight = aBase->real(PrimitivesPlugin_Cylinder::HEIGHT_ID());
100 theDumper << ", " << anAttrRadius << ", " << anAttrHeight;
102 std::string aCreationMethod =
103 aBase->string(PrimitivesPlugin_Cylinder::CREATION_METHOD())->value();
105 if (aCreationMethod == PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION()) {
106 AttributeDoublePtr anAttrAngle = aBase->real(PrimitivesPlugin_Cylinder::ANGLE_ID());
107 theDumper << ", " << anAttrAngle;
110 theDumper << ")" << std::endl;
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)
120 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
121 return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
122 theRadius, theHeight));
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)
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));
138 //==================================================================================================
139 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
140 const ModelHighAPI_Double& theRadius,
141 const ModelHighAPI_Double& theHeight)
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));
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)
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));