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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "PrimitivesAPI_Cylinder.h"
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Selection.h>
24 #include <ModelHighAPI_Tools.h>
28 //==================================================================================================
29 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature)
30 : ModelHighAPI_Interface(theFeature)
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)
44 fillAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER(), creationMethod());
45 fillAttribute(theBasePoint, basePoint());
46 fillAttribute(theAxis, axis());
47 setSizes(theRadius, theHeight);
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)
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);
69 //==================================================================================================
70 PrimitivesAPI_Cylinder::~PrimitivesAPI_Cylinder()
75 //==================================================================================================
76 void PrimitivesAPI_Cylinder::setSizes(const ModelHighAPI_Double& theRadius,
77 const ModelHighAPI_Double& theHeight)
79 fillAttribute(theRadius, radius());
80 fillAttribute(theHeight, height());
84 //==================================================================================================
85 void PrimitivesAPI_Cylinder::dump(ModelHighAPI_Dumper& theDumper) const
87 FeaturePtr aBase = feature();
88 const std::string& aDocName = theDumper.name(aBase->document());
90 theDumper << aBase << " = model.addCylinder(" << aDocName;
92 AttributeSelectionPtr anAttrBasePoint =
93 aBase->selection(PrimitivesPlugin_Cylinder::BASE_POINT_ID());
94 AttributeSelectionPtr anAttrAxis = aBase->selection(PrimitivesPlugin_Cylinder::AXIS_ID());
95 theDumper << ", " << anAttrBasePoint << ", " << anAttrAxis;
97 AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Cylinder::RADIUS_ID());
98 AttributeDoublePtr anAttrHeight = aBase->real(PrimitivesPlugin_Cylinder::HEIGHT_ID());
99 theDumper << ", " << anAttrRadius << ", " << anAttrHeight;
101 std::string aCreationMethod =
102 aBase->string(PrimitivesPlugin_Cylinder::CREATION_METHOD())->value();
104 if (aCreationMethod == PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION()) {
105 AttributeDoublePtr anAttrAngle = aBase->real(PrimitivesPlugin_Cylinder::ANGLE_ID());
106 theDumper << ", " << anAttrAngle;
109 theDumper << ")" << std::endl;
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)
119 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
120 return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
121 theRadius, theHeight));
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)
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));
137 //==================================================================================================
138 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
139 const ModelHighAPI_Double& theRadius,
140 const ModelHighAPI_Double& theHeight)
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));
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)
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));