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(theBasePoint, basePoint());
30 fillAttribute(theAxis, axis());
31 setSizes(theRadius, theHeight);
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 const ModelHighAPI_Double& theAngle)
42 : ModelHighAPI_Interface(theFeature)
45 fillAttribute(theBasePoint, basePoint());
46 fillAttribute(theAxis, axis());
47 fillAttribute(theAngle, angle());
48 setSizes(theRadius, theHeight);
52 //==================================================================================================
53 PrimitivesAPI_Cylinder::~PrimitivesAPI_Cylinder()
58 //==================================================================================================
59 void PrimitivesAPI_Cylinder::setSizes(const ModelHighAPI_Double& theRadius,
60 const ModelHighAPI_Double& theHeight)
62 fillAttribute(theRadius, radius());
63 fillAttribute(theHeight, height());
67 //==================================================================================================
68 void PrimitivesAPI_Cylinder::dump(ModelHighAPI_Dumper& theDumper) const
70 FeaturePtr aBase = feature();
71 const std::string& aDocName = theDumper.name(aBase->document());
73 theDumper << aBase << " = model.addCylinder(" << aDocName;
75 AttributeSelectionPtr anAttrBasePoint =
76 aBase->selection(PrimitivesPlugin_Cylinder::BASE_POINT_ID());
77 AttributeSelectionPtr anAttrAxis = aBase->selection(PrimitivesPlugin_Cylinder::AXIS_ID());
78 theDumper << ", " << anAttrBasePoint << ", " << anAttrAxis;
80 AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Cylinder::RADIUS_ID());
81 AttributeDoublePtr anAttrHeight = aBase->real(PrimitivesPlugin_Cylinder::HEIGHT_ID());
82 theDumper << ", " << anAttrRadius << ", " << anAttrHeight;
84 std::string aCreationMethod =
85 aBase->string(PrimitivesPlugin_Cylinder::CREATION_METHOD())->value();
87 if (aCreationMethod == PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION()) {
88 AttributeDoublePtr anAttrAngle = aBase->real(PrimitivesPlugin_Cylinder::ANGLE_ID());
89 theDumper << ", " << anAttrAngle;
92 theDumper << ")" << std::endl;
95 //==================================================================================================
96 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
97 const ModelHighAPI_Selection& theBasePoint,
98 const ModelHighAPI_Selection& theAxis,
99 const ModelHighAPI_Double& theRadius,
100 const ModelHighAPI_Double& theHeight)
102 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
103 return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
104 theRadius, theHeight));
107 //==================================================================================================
108 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
109 const ModelHighAPI_Selection& theBasePoint,
110 const ModelHighAPI_Selection& theAxis,
111 const ModelHighAPI_Double& theRadius,
112 const ModelHighAPI_Double& theHeight,
113 const ModelHighAPI_Double& theAngle)
115 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
116 return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
117 theRadius, theHeight, theAngle));
120 //==================================================================================================
121 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
122 const ModelHighAPI_Double& theRadius,
123 const ModelHighAPI_Double& theHeight)
125 ModelHighAPI_Selection aBasePoint("VERT", "Origin");
126 ModelHighAPI_Selection anAxis("EDGE", "OZ");
127 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
128 return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, aBasePoint, anAxis,
129 theRadius, theHeight));
132 //==================================================================================================
133 CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
134 const ModelHighAPI_Double& theRadius,
135 const ModelHighAPI_Double& theHeight,
136 const ModelHighAPI_Double& theAngle)
138 ModelHighAPI_Selection aBasePoint("VERT", "Origin");
139 ModelHighAPI_Selection anAxis("EDGE", "OZ");
140 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
141 return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, aBasePoint, anAxis,
142 theRadius, theHeight));