Salome HOME
Merge branch 'V9_2_2_BR'
[modules/shaper.git] / src / PrimitivesAPI / PrimitivesAPI_Cone.cpp
1 // Copyright (C) 2017-2019  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File:        PrimitivesAPI_Cone.cpp
21 // Created:     20 Mar 2017
22 // Author:      Clarisse Genrault
23
24 #include "PrimitivesAPI_Cone.h"
25
26 #include <ModelHighAPI_Dumper.h>
27 #include <ModelHighAPI_Selection.h>
28 #include <ModelHighAPI_Tools.h>
29
30 //==================================================================================================
31 PrimitivesAPI_Cone::PrimitivesAPI_Cone(const std::shared_ptr<ModelAPI_Feature>& theFeature)
32 : ModelHighAPI_Interface(theFeature)
33 {
34   initialize();
35 }
36
37 //==================================================================================================
38 PrimitivesAPI_Cone::PrimitivesAPI_Cone(const std::shared_ptr<ModelAPI_Feature>& theFeature,
39                                        const ModelHighAPI_Selection& theBasePoint,
40                                        const ModelHighAPI_Selection& theAxis,
41                                        const ModelHighAPI_Double& theBaseRadius,
42                                        const ModelHighAPI_Double& theTopRadius,
43                                        const ModelHighAPI_Double& theHeight)
44 : ModelHighAPI_Interface(theFeature)
45 {
46   if (initialize()) {
47     fillAttribute(theBasePoint, basePoint());
48     fillAttribute(theAxis, axis());
49     fillAttribute(theBaseRadius, baseRadius());
50     fillAttribute(theTopRadius, topRadius());
51     setHeight(theHeight);
52   }
53 }
54
55 //==================================================================================================
56 PrimitivesAPI_Cone::~PrimitivesAPI_Cone()
57 {
58 }
59
60 //==================================================================================================
61 void PrimitivesAPI_Cone::setRadius(const ModelHighAPI_Double& theBaseRadius,
62                                    const ModelHighAPI_Double& theTopRadius)
63 {
64   fillAttribute(theBaseRadius, baseRadius());
65   fillAttribute(theTopRadius, topRadius());
66   execute();
67 }
68
69 //==================================================================================================
70 void PrimitivesAPI_Cone::setHeight(const ModelHighAPI_Double& theHeight)
71 {
72   fillAttribute(theHeight, height());
73   execute();
74 }
75
76 //==================================================================================================
77 void PrimitivesAPI_Cone::dump(ModelHighAPI_Dumper& theDumper) const
78 {
79   FeaturePtr aBase = feature();
80   const std::string& aDocName = theDumper.name(aBase->document());
81
82   theDumper << aBase << " = model.addCone(" << aDocName;
83
84   AttributeSelectionPtr anAttrBasePoint =
85       aBase->selection(PrimitivesPlugin_Cone::BASE_POINT_ID());
86   AttributeSelectionPtr anAttrAxis =
87       aBase->selection(PrimitivesPlugin_Cone::AXIS_ID());
88   theDumper << ", " << anAttrBasePoint << ", " << anAttrAxis;
89
90   AttributeDoublePtr anAttrBaseRadius = aBase->real(PrimitivesPlugin_Cone::BASE_RADIUS_ID());
91   AttributeDoublePtr anAttrTopRadius = aBase->real(PrimitivesPlugin_Cone::TOP_RADIUS_ID());
92   AttributeDoublePtr anAttrHeight = aBase->real(PrimitivesPlugin_Cone::HEIGHT_ID());
93   theDumper << ", " << anAttrBaseRadius << ", " << anAttrTopRadius << ", " << anAttrHeight;
94
95   theDumper << ")" << std::endl;
96 }
97
98 //==================================================================================================
99 ConePtr addCone(const std::shared_ptr<ModelAPI_Document>& thePart,
100                 const ModelHighAPI_Selection& theBasePoint,
101                 const ModelHighAPI_Selection& theAxis,
102                 const ModelHighAPI_Double& theBaseRadius,
103                 const ModelHighAPI_Double& theTopRadius,
104                 const ModelHighAPI_Double& theHeight)
105 {
106   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cone::ID());
107   return ConePtr(new PrimitivesAPI_Cone(aFeature, theBasePoint, theAxis, theBaseRadius,
108                                         theTopRadius, theHeight));
109 }
110
111 //==================================================================================================
112 ConePtr addCone(const std::shared_ptr<ModelAPI_Document>& thePart,
113                 const ModelHighAPI_Double& theBaseRadius,
114                 const ModelHighAPI_Double& theTopRadius,
115                 const ModelHighAPI_Double& theHeight)
116 {
117   ModelHighAPI_Selection aBasePoint("VERTEX", "PartSet/Origin");
118   ModelHighAPI_Selection anAxis("EDGE", "PartSet/OZ");
119   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cone::ID());
120   return ConePtr(new PrimitivesAPI_Cone(aFeature, aBasePoint, anAxis, theBaseRadius,
121                                         theTopRadius, theHeight));
122 }