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>
27 //==================================================================================================
28 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature)
29 : ModelHighAPI_Interface(theFeature)
34 //==================================================================================================
35 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature,
36 const ModelHighAPI_Selection& theBasePoint,
37 const ModelHighAPI_Selection& theAxis,
38 const ModelHighAPI_Double& theRadius,
39 const ModelHighAPI_Double& theHeight)
40 : ModelHighAPI_Interface(theFeature)
43 fillAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER(), creationMethod());
44 fillAttribute(theBasePoint, basePoint());
45 fillAttribute(theAxis, axis());
46 setSizes(theRadius, theHeight);
50 //==================================================================================================
51 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature,
52 const ModelHighAPI_Selection& theBasePoint,
53 const ModelHighAPI_Selection& theAxis,
54 const ModelHighAPI_Double& theRadius,
55 const ModelHighAPI_Double& theHeight,
56 const ModelHighAPI_Double& theAngle)
57 : ModelHighAPI_Interface(theFeature)
60 fillAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION(), creationMethod());
61 fillAttribute(theBasePoint, basePoint());
62 fillAttribute(theAxis, axis());
63 fillAttribute(theAngle, angle());
64 setSizes(theRadius, theHeight);
68 //==================================================================================================
69 PrimitivesAPI_Cylinder::~PrimitivesAPI_Cylinder()
74 //==================================================================================================
75 void PrimitivesAPI_Cylinder::setSizes(const ModelHighAPI_Double& theRadius,
76 const ModelHighAPI_Double& theHeight)
78 fillAttribute(theRadius, radius());
79 fillAttribute(theHeight, height());
83 //==================================================================================================
84 void PrimitivesAPI_Cylinder::dump(ModelHighAPI_Dumper& theDumper) const
86 FeaturePtr aBase = feature();
87 const std::string& aDocName = theDumper.name(aBase->document());
89 theDumper << aBase << " = model.addCylinder(" << aDocName;
91 AttributeSelectionPtr anAttrBasePoint =
92 aBase->selection(PrimitivesPlugin_Cylinder::BASE_POINT_ID());
93 AttributeSelectionPtr anAttrAxis = aBase->selection(PrimitivesPlugin_Cylinder::AXIS_ID());
94 theDumper << ", " << anAttrBasePoint << ", " << anAttrAxis;
96 AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Cylinder::RADIUS_ID());
97 AttributeDoublePtr anAttrHeight = aBase->real(PrimitivesPlugin_Cylinder::HEIGHT_ID());
98 theDumper << ", " << anAttrRadius << ", " << anAttrHeight;
100 std::string aCreationMethod =
101 aBase->string(PrimitivesPlugin_Cylinder::CREATION_METHOD())->value();
103 if (aCreationMethod == PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION()) {
104 AttributeDoublePtr anAttrAngle = aBase->real(PrimitivesPlugin_Cylinder::ANGLE_ID());
105 theDumper << ", " << anAttrAngle;
108 theDumper << ")" << std::endl;
111 //==================================================================================================
112 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
113 const ModelHighAPI_Selection& theBasePoint,
114 const ModelHighAPI_Selection& theAxis,
115 const ModelHighAPI_Double& theRadius,
116 const ModelHighAPI_Double& theHeight)
118 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
119 return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
120 theRadius, theHeight));
123 //==================================================================================================
124 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
125 const ModelHighAPI_Selection& theBasePoint,
126 const ModelHighAPI_Selection& theAxis,
127 const ModelHighAPI_Double& theRadius,
128 const ModelHighAPI_Double& theHeight,
129 const ModelHighAPI_Double& theAngle)
131 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
132 return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
133 theRadius, theHeight, theAngle));
136 //==================================================================================================
137 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
138 const ModelHighAPI_Double& theRadius,
139 const ModelHighAPI_Double& theHeight)
141 ModelHighAPI_Selection aBasePoint("VERTEX", "PartSet/Origin");
142 ModelHighAPI_Selection anAxis("EDGE", "PartSet/OZ");
143 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
144 return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, aBasePoint, anAxis,
145 theRadius, theHeight));
148 //==================================================================================================
149 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
150 const ModelHighAPI_Double& theRadius,
151 const ModelHighAPI_Double& theHeight,
152 const ModelHighAPI_Double& theAngle)
154 ModelHighAPI_Selection aBasePoint("VERTEX", "PartSet/Origin");
155 ModelHighAPI_Selection anAxis("EDGE", "PartSet/OZ");
156 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
157 return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, aBasePoint, anAxis,
158 theRadius, theHeight, theAngle));