Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / PrimitivesAPI / PrimitivesAPI_Torus.cpp
1 // Copyright (C) 2014-201x CEA/DEN, EDF R&D -->
2
3 // File:        PrimitivesAPI_Torus.cpp
4 // Created:     20 Mar 2017
5 // Author:      Clarisse Genrault
6
7 #include "PrimitivesAPI_Torus.h"
8
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Selection.h>
11 #include <ModelHighAPI_Tools.h>
12
13 //==================================================================================================
14 PrimitivesAPI_Torus::PrimitivesAPI_Torus(const std::shared_ptr<ModelAPI_Feature>& theFeature)
15 : ModelHighAPI_Interface(theFeature)
16 {
17   initialize();
18 }
19
20 //==================================================================================================
21 PrimitivesAPI_Torus::PrimitivesAPI_Torus(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& theRingRadius)
26 : ModelHighAPI_Interface(theFeature)
27 {
28   if (initialize()) {
29     fillAttribute(theBasePoint, basePoint());
30     fillAttribute(theAxis, axis());
31     setRadius(theRadius, theRingRadius);
32   }
33 }
34
35 //==================================================================================================
36 PrimitivesAPI_Torus::~PrimitivesAPI_Torus()
37 {
38 }
39
40 //==================================================================================================
41 void PrimitivesAPI_Torus::setRadius(const ModelHighAPI_Double& theRadius,
42                                     const ModelHighAPI_Double& theRingRadius)
43 {
44   fillAttribute(theRadius, radius());
45   fillAttribute(theRingRadius, ringRadius());
46   execute();
47 }
48
49 //==================================================================================================
50 void PrimitivesAPI_Torus::dump(ModelHighAPI_Dumper& theDumper) const
51 {
52   FeaturePtr aBase = feature();
53   const std::string& aDocName = theDumper.name(aBase->document());
54
55   theDumper << aBase << " = model.addTorus(" << aDocName;
56
57   AttributeSelectionPtr anAttrBasePoint =
58       aBase->selection(PrimitivesPlugin_Torus::BASE_POINT_ID());
59   AttributeSelectionPtr anAttrAxis =
60       aBase->selection(PrimitivesPlugin_Torus::AXIS_ID());
61   theDumper << ", " << anAttrBasePoint << ", " << anAttrAxis;
62
63   AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Torus::RADIUS_ID());
64   AttributeDoublePtr anAttrRingRadius = aBase->real(PrimitivesPlugin_Torus::RING_RADIUS_ID());
65   theDumper << ", " << anAttrRadius << ", " << anAttrRingRadius;
66
67   theDumper << ")" << std::endl;
68 }
69
70 //==================================================================================================
71 TorusPtr addTorus(const std::shared_ptr<ModelAPI_Document>& thePart,
72                   const ModelHighAPI_Selection& theBasePoint,
73                   const ModelHighAPI_Selection& theAxis,
74                   const ModelHighAPI_Double& theRadius,
75                   const ModelHighAPI_Double& theRingRadius)
76 {
77   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Torus::ID());
78   return TorusPtr(new PrimitivesAPI_Torus(aFeature, theBasePoint, theAxis,
79                                           theRadius, theRingRadius));
80 }
81
82 //==================================================================================================
83 TorusPtr addTorus(const std::shared_ptr<ModelAPI_Document>& thePart,
84                   const ModelHighAPI_Double& theRadius,
85                   const ModelHighAPI_Double& theRingRadius)
86 {
87   ModelHighAPI_Selection aBasePoint("VERTEX", "PartSet/Origin");
88   ModelHighAPI_Selection anAxis("EDGE", "PartSet/OZ");
89   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Torus::ID());
90   return TorusPtr(new PrimitivesAPI_Torus(aFeature, aBasePoint, anAxis, theRadius, theRingRadius));
91 }