1 // Copyright (C) 2014-2019 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
20 #include "PrimitivesAPI_Cylinder.h"
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Selection.h>
24 #include <ModelHighAPI_Tools.h>
26 //==================================================================================================
27 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature)
28 : ModelHighAPI_Interface(theFeature)
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)
42 fillAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER(), creationMethod());
43 fillAttribute(theBasePoint, basePoint());
44 fillAttribute(theAxis, axis());
45 setSizes(theRadius, theHeight);
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)
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);
67 //==================================================================================================
68 PrimitivesAPI_Cylinder::~PrimitivesAPI_Cylinder()
73 //==================================================================================================
74 void PrimitivesAPI_Cylinder::setSizes(const ModelHighAPI_Double& theRadius,
75 const ModelHighAPI_Double& theHeight)
77 fillAttribute(theRadius, radius());
78 fillAttribute(theHeight, height());
82 //==================================================================================================
83 void PrimitivesAPI_Cylinder::dump(ModelHighAPI_Dumper& theDumper) const
85 FeaturePtr aBase = feature();
86 const std::string& aDocName = theDumper.name(aBase->document());
88 theDumper << aBase << " = model.addCylinder(" << aDocName;
90 AttributeSelectionPtr anAttrBasePoint =
91 aBase->selection(PrimitivesPlugin_Cylinder::BASE_POINT_ID());
92 AttributeSelectionPtr anAttrAxis = aBase->selection(PrimitivesPlugin_Cylinder::AXIS_ID());
93 theDumper << ", " << anAttrBasePoint << ", " << anAttrAxis;
95 AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Cylinder::RADIUS_ID());
96 AttributeDoublePtr anAttrHeight = aBase->real(PrimitivesPlugin_Cylinder::HEIGHT_ID());
97 theDumper << ", " << anAttrRadius << ", " << anAttrHeight;
99 std::string aCreationMethod =
100 aBase->string(PrimitivesPlugin_Cylinder::CREATION_METHOD())->value();
102 if (aCreationMethod == PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION()) {
103 AttributeDoublePtr anAttrAngle = aBase->real(PrimitivesPlugin_Cylinder::ANGLE_ID());
104 theDumper << ", " << anAttrAngle;
107 theDumper << ")" << std::endl;
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)
117 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
118 return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
119 theRadius, theHeight));
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)
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));
135 //==================================================================================================
136 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
137 const ModelHighAPI_Double& theRadius,
138 const ModelHighAPI_Double& theHeight)
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));
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)
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));