1 // Copyright (C) 2014-201x CEA/DEN, EDF R&D -->
3 // File: PrimitivesAPI_Cylinder.cpp
4 // Created: 12 Jan 2017
5 // Author: Clarisse Genrault
7 #include "PrimitivesAPI_Cylinder.h"
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Selection.h>
11 #include <ModelHighAPI_Tools.h>
15 //==================================================================================================
16 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature)
17 : ModelHighAPI_Interface(theFeature)
22 //==================================================================================================
23 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature,
24 const ModelHighAPI_Selection& theBasePoint,
25 const ModelHighAPI_Selection& theAxis,
26 const ModelHighAPI_Double& theRadius,
27 const ModelHighAPI_Double& theHeight)
28 : ModelHighAPI_Interface(theFeature)
31 fillAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER(), creationMethod());
32 fillAttribute(theBasePoint, basePoint());
33 fillAttribute(theAxis, axis());
34 setSizes(theRadius, theHeight);
38 //==================================================================================================
39 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature,
40 const ModelHighAPI_Selection& theBasePoint,
41 const ModelHighAPI_Selection& theAxis,
42 const ModelHighAPI_Double& theRadius,
43 const ModelHighAPI_Double& theHeight,
44 const ModelHighAPI_Double& theAngle)
45 : ModelHighAPI_Interface(theFeature)
48 fillAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION(), creationMethod());
49 fillAttribute(theBasePoint, basePoint());
50 fillAttribute(theAxis, axis());
51 fillAttribute(theAngle, angle());
52 setSizes(theRadius, theHeight);
56 //==================================================================================================
57 PrimitivesAPI_Cylinder::~PrimitivesAPI_Cylinder()
62 //==================================================================================================
63 void PrimitivesAPI_Cylinder::setSizes(const ModelHighAPI_Double& theRadius,
64 const ModelHighAPI_Double& theHeight)
66 fillAttribute(theRadius, radius());
67 fillAttribute(theHeight, height());
71 //==================================================================================================
72 void PrimitivesAPI_Cylinder::dump(ModelHighAPI_Dumper& theDumper) const
74 FeaturePtr aBase = feature();
75 const std::string& aDocName = theDumper.name(aBase->document());
77 theDumper << aBase << " = model.addCylinder(" << aDocName;
79 AttributeSelectionPtr anAttrBasePoint =
80 aBase->selection(PrimitivesPlugin_Cylinder::BASE_POINT_ID());
81 AttributeSelectionPtr anAttrAxis = aBase->selection(PrimitivesPlugin_Cylinder::AXIS_ID());
82 theDumper << ", " << anAttrBasePoint << ", " << anAttrAxis;
84 AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Cylinder::RADIUS_ID());
85 AttributeDoublePtr anAttrHeight = aBase->real(PrimitivesPlugin_Cylinder::HEIGHT_ID());
86 theDumper << ", " << anAttrRadius << ", " << anAttrHeight;
88 std::string aCreationMethod =
89 aBase->string(PrimitivesPlugin_Cylinder::CREATION_METHOD())->value();
91 if (aCreationMethod == PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION()) {
92 AttributeDoublePtr anAttrAngle = aBase->real(PrimitivesPlugin_Cylinder::ANGLE_ID());
93 theDumper << ", " << anAttrAngle;
96 theDumper << ")" << std::endl;
99 //==================================================================================================
100 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
101 const ModelHighAPI_Selection& theBasePoint,
102 const ModelHighAPI_Selection& theAxis,
103 const ModelHighAPI_Double& theRadius,
104 const ModelHighAPI_Double& theHeight)
106 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
107 return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
108 theRadius, theHeight));
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,
117 const ModelHighAPI_Double& theAngle)
119 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
120 return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
121 theRadius, theHeight, theAngle));
124 //==================================================================================================
125 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
126 const ModelHighAPI_Double& theRadius,
127 const ModelHighAPI_Double& theHeight)
129 ModelHighAPI_Selection aBasePoint("VERTEX", "PartSet/Origin");
130 ModelHighAPI_Selection anAxis("EDGE", "PartSet/OZ");
131 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
132 return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, aBasePoint, anAxis,
133 theRadius, theHeight));
136 //==================================================================================================
137 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
138 const ModelHighAPI_Double& theRadius,
139 const ModelHighAPI_Double& theHeight,
140 const ModelHighAPI_Double& theAngle)
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, theAngle));