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>
13 //==================================================================================================
14 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature)
15 : ModelHighAPI_Interface(theFeature)
20 //==================================================================================================
21 PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature,
22 const ModelHighAPI_Selection& theBasePoint,
23 const ModelHighAPI_Selection& theAxis,
24 const ModelHighAPI_Double& theRadius,
25 const ModelHighAPI_Double& theHeight)
26 : ModelHighAPI_Interface(theFeature)
29 fillAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER(), creationMethod());
30 fillAttribute(theBasePoint, basePoint());
31 fillAttribute(theAxis, axis());
32 setSizes(theRadius, theHeight);
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 const ModelHighAPI_Double& theAngle)
43 : ModelHighAPI_Interface(theFeature)
46 fillAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION(), creationMethod());
47 fillAttribute(theBasePoint, basePoint());
48 fillAttribute(theAxis, axis());
49 fillAttribute(theAngle, angle());
50 setSizes(theRadius, theHeight);
54 //==================================================================================================
55 PrimitivesAPI_Cylinder::~PrimitivesAPI_Cylinder()
60 //==================================================================================================
61 void PrimitivesAPI_Cylinder::setSizes(const ModelHighAPI_Double& theRadius,
62 const ModelHighAPI_Double& theHeight)
64 fillAttribute(theRadius, radius());
65 fillAttribute(theHeight, height());
69 //==================================================================================================
70 void PrimitivesAPI_Cylinder::dump(ModelHighAPI_Dumper& theDumper) const
72 FeaturePtr aBase = feature();
73 const std::string& aDocName = theDumper.name(aBase->document());
75 theDumper << aBase << " = model.addCylinder(" << aDocName;
77 AttributeSelectionPtr anAttrBasePoint =
78 aBase->selection(PrimitivesPlugin_Cylinder::BASE_POINT_ID());
79 AttributeSelectionPtr anAttrAxis = aBase->selection(PrimitivesPlugin_Cylinder::AXIS_ID());
80 theDumper << ", " << anAttrBasePoint << ", " << anAttrAxis;
82 AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Cylinder::RADIUS_ID());
83 AttributeDoublePtr anAttrHeight = aBase->real(PrimitivesPlugin_Cylinder::HEIGHT_ID());
84 theDumper << ", " << anAttrRadius << ", " << anAttrHeight;
86 std::string aCreationMethod =
87 aBase->string(PrimitivesPlugin_Cylinder::CREATION_METHOD())->value();
89 if (aCreationMethod == PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION()) {
90 AttributeDoublePtr anAttrAngle = aBase->real(PrimitivesPlugin_Cylinder::ANGLE_ID());
91 theDumper << ", " << anAttrAngle;
94 theDumper << ")" << std::endl;
97 //==================================================================================================
98 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
99 const ModelHighAPI_Selection& theBasePoint,
100 const ModelHighAPI_Selection& theAxis,
101 const ModelHighAPI_Double& theRadius,
102 const ModelHighAPI_Double& theHeight)
104 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
105 return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
106 theRadius, theHeight));
109 //==================================================================================================
110 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
111 const ModelHighAPI_Selection& theBasePoint,
112 const ModelHighAPI_Selection& theAxis,
113 const ModelHighAPI_Double& theRadius,
114 const ModelHighAPI_Double& theHeight,
115 const ModelHighAPI_Double& theAngle)
117 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
118 return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
119 theRadius, theHeight, theAngle));
122 //==================================================================================================
123 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
124 const ModelHighAPI_Double& theRadius,
125 const ModelHighAPI_Double& theHeight)
127 ModelHighAPI_Selection aBasePoint("VERTEX", "PartSet/Origin");
128 ModelHighAPI_Selection anAxis("EDGE", "PartSet/OZ");
129 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
130 return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, aBasePoint, anAxis,
131 theRadius, theHeight));
134 //==================================================================================================
135 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
136 const ModelHighAPI_Double& theRadius,
137 const ModelHighAPI_Double& theHeight,
138 const ModelHighAPI_Double& theAngle)
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, theAngle));