Salome HOME
Add "Torus" primitive and "Cone" primitive.
[modules/shaper.git] / src / PrimitivesAPI / PrimitivesAPI_Cone.cpp
1 // Copyright (C) 2014-201x CEA/DEN, EDF R&D -->
2
3 // File:        PrimitivesAPI_Cone.cpp
4 // Created:     20 Mar 2017
5 // Author:      Clarisse Genrault
6
7 #include "PrimitivesAPI_Cone.h"
8
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Selection.h>
11 #include <ModelHighAPI_Tools.h>
12
13 //==================================================================================================
14 PrimitivesAPI_Cone::PrimitivesAPI_Cone(const std::shared_ptr<ModelAPI_Feature>& theFeature)
15 : ModelHighAPI_Interface(theFeature)
16 {
17   initialize();
18 }
19
20 //==================================================================================================
21 PrimitivesAPI_Cone::PrimitivesAPI_Cone(const std::shared_ptr<ModelAPI_Feature>& theFeature,
22                                        const ModelHighAPI_Selection& theBasePoint,
23                                        const ModelHighAPI_Selection& theAxis,
24                                        const ModelHighAPI_Double& theBaseRadius,
25                                        const ModelHighAPI_Double& theTopRadius,
26                                        const ModelHighAPI_Double& theHeight)
27 : ModelHighAPI_Interface(theFeature)
28 {
29   if (initialize()) {
30     fillAttribute(theBasePoint, basePoint());
31     fillAttribute(theAxis, axis());
32     fillAttribute(theBaseRadius, baseRadius());
33     fillAttribute(theTopRadius, topRadius());
34     setHeight(theHeight);
35   }
36 }
37
38 //==================================================================================================
39 PrimitivesAPI_Cone::~PrimitivesAPI_Cone()
40 {
41 }
42
43 //==================================================================================================
44 void PrimitivesAPI_Cone::setRadius(const ModelHighAPI_Double& theBaseRadius,
45                                    const ModelHighAPI_Double& theTopRadius)
46 {
47   fillAttribute(theBaseRadius, baseRadius());
48   fillAttribute(theTopRadius, topRadius());
49   execute();
50 }
51
52 //==================================================================================================
53 void PrimitivesAPI_Cone::setHeight(const ModelHighAPI_Double& theHeight)
54 {
55   fillAttribute(theHeight, height());
56   execute();
57 }
58
59 //==================================================================================================
60 void PrimitivesAPI_Cone::dump(ModelHighAPI_Dumper& theDumper) const
61 {
62   FeaturePtr aBase = feature();
63   const std::string& aDocName = theDumper.name(aBase->document());
64
65   theDumper << aBase << " = model.addCone(" << aDocName;
66
67   AttributeSelectionPtr anAttrBasePoint =
68       aBase->selection(PrimitivesPlugin_Cone::BASE_POINT_ID());
69   AttributeSelectionPtr anAttrAxis =
70       aBase->selection(PrimitivesPlugin_Cone::AXIS_ID());
71   theDumper << ", " << anAttrBasePoint << ", " << anAttrAxis;
72
73   AttributeDoublePtr anAttrBaseRadius = aBase->real(PrimitivesPlugin_Cone::BASE_RADIUS_ID());
74   AttributeDoublePtr anAttrTopRadius = aBase->real(PrimitivesPlugin_Cone::TOP_RADIUS_ID());
75   AttributeDoublePtr anAttrHeight = aBase->real(PrimitivesPlugin_Cone::HEIGHT_ID());
76   theDumper << ", " << anAttrBaseRadius << ", " << anAttrTopRadius << ", " << anAttrHeight;
77
78   theDumper << ")" << std::endl;
79 }
80
81 //==================================================================================================
82 ConePtr addCone(const std::shared_ptr<ModelAPI_Document>& thePart,
83                 const ModelHighAPI_Selection& theBasePoint,
84                 const ModelHighAPI_Selection& theAxis,
85                 const ModelHighAPI_Double& theBaseRadius,
86                 const ModelHighAPI_Double& theTopRadius,
87                 const ModelHighAPI_Double& theHeight)
88 {
89   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cone::ID());
90   return ConePtr(new PrimitivesAPI_Cone(aFeature, theBasePoint, theAxis, theBaseRadius,
91                                         theTopRadius, theHeight));
92 }
93
94 //==================================================================================================
95 ConePtr addCone(const std::shared_ptr<ModelAPI_Document>& thePart,
96                 const ModelHighAPI_Double& theBaseRadius,
97                 const ModelHighAPI_Double& theTopRadius,
98                 const ModelHighAPI_Double& theHeight)
99 {
100   ModelHighAPI_Selection aBasePoint("VERTEX", "PartSet/Origin");
101   ModelHighAPI_Selection anAxis("EDGE", "PartSet/OZ");
102   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cone::ID());
103   return ConePtr(new PrimitivesAPI_Cone(aFeature, aBasePoint, anAxis, theBaseRadius,
104                                         theTopRadius, theHeight));
105 }