Salome HOME
updated copyright message
[modules/shaper.git] / src / PrimitivesAPI / PrimitivesAPI_Torus.cpp
1 // Copyright (C) 2017-2023  CEA, EDF
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_Torus.cpp
21 // Created:     20 Mar 2017
22 // Author:      Clarisse Genrault
23
24 #include "PrimitivesAPI_Torus.h"
25
26 #include <ModelHighAPI_Dumper.h>
27 #include <ModelHighAPI_Selection.h>
28 #include <ModelHighAPI_Tools.h>
29
30 //==================================================================================================
31 PrimitivesAPI_Torus::PrimitivesAPI_Torus(const std::shared_ptr<ModelAPI_Feature>& theFeature)
32 : ModelHighAPI_Interface(theFeature)
33 {
34   initialize();
35 }
36
37 //==================================================================================================
38 PrimitivesAPI_Torus::PrimitivesAPI_Torus(const std::shared_ptr<ModelAPI_Feature>& theFeature,
39                                        const ModelHighAPI_Selection& theBasePoint,
40                                        const ModelHighAPI_Selection& theAxis,
41                                        const ModelHighAPI_Double& theRadius,
42                                        const ModelHighAPI_Double& theRingRadius)
43 : ModelHighAPI_Interface(theFeature)
44 {
45   if (initialize()) {
46     fillAttribute(theBasePoint, basePoint());
47     fillAttribute(theAxis, axis());
48     setRadius(theRadius, theRingRadius);
49   }
50 }
51
52 //==================================================================================================
53 PrimitivesAPI_Torus::~PrimitivesAPI_Torus()
54 {
55 }
56
57 //==================================================================================================
58 void PrimitivesAPI_Torus::setRadius(const ModelHighAPI_Double& theRadius,
59                                     const ModelHighAPI_Double& theRingRadius)
60 {
61   fillAttribute(theRadius, radius());
62   fillAttribute(theRingRadius, ringRadius());
63   execute();
64 }
65
66 //==================================================================================================
67 void PrimitivesAPI_Torus::dump(ModelHighAPI_Dumper& theDumper) const
68 {
69   FeaturePtr aBase = feature();
70   const std::string& aDocName = theDumper.name(aBase->document());
71
72   theDumper << aBase << " = model.addTorus(" << aDocName;
73
74   AttributeSelectionPtr anAttrBasePoint =
75       aBase->selection(PrimitivesPlugin_Torus::BASE_POINT_ID());
76   AttributeSelectionPtr anAttrAxis =
77       aBase->selection(PrimitivesPlugin_Torus::AXIS_ID());
78   theDumper << ", " << anAttrBasePoint << ", " << anAttrAxis;
79
80   AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Torus::RADIUS_ID());
81   AttributeDoublePtr anAttrRingRadius = aBase->real(PrimitivesPlugin_Torus::RING_RADIUS_ID());
82   theDumper << ", " << anAttrRadius << ", " << anAttrRingRadius;
83
84   theDumper << ")" << std::endl;
85 }
86
87 //==================================================================================================
88 TorusPtr addTorus(const std::shared_ptr<ModelAPI_Document>& thePart,
89                   const ModelHighAPI_Selection& theBasePoint,
90                   const ModelHighAPI_Selection& theAxis,
91                   const ModelHighAPI_Double& theRadius,
92                   const ModelHighAPI_Double& theRingRadius)
93 {
94   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Torus::ID());
95   return TorusPtr(new PrimitivesAPI_Torus(aFeature, theBasePoint, theAxis,
96                                           theRadius, theRingRadius));
97 }
98
99 //==================================================================================================
100 TorusPtr addTorus(const std::shared_ptr<ModelAPI_Document>& thePart,
101                   const ModelHighAPI_Double& theRadius,
102                   const ModelHighAPI_Double& theRingRadius)
103 {
104   ModelHighAPI_Selection aBasePoint("VERTEX", L"PartSet/Origin");
105   ModelHighAPI_Selection anAxis("EDGE", L"PartSet/OZ");
106   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Torus::ID());
107   return TorusPtr(new PrimitivesAPI_Torus(aFeature, aBasePoint, anAxis, theRadius, theRingRadius));
108 }