1 // Copyright (C) 2017-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: PrimitivesAPI_Torus.cpp
21 // Created: 20 Mar 2017
22 // Author: Clarisse Genrault
24 #include "PrimitivesAPI_Torus.h"
26 #include <ModelHighAPI_Dumper.h>
27 #include <ModelHighAPI_Selection.h>
28 #include <ModelHighAPI_Tools.h>
30 //==================================================================================================
31 PrimitivesAPI_Torus::PrimitivesAPI_Torus(const std::shared_ptr<ModelAPI_Feature>& theFeature)
32 : ModelHighAPI_Interface(theFeature)
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)
46 fillAttribute(theBasePoint, basePoint());
47 fillAttribute(theAxis, axis());
48 setRadius(theRadius, theRingRadius);
52 //==================================================================================================
53 PrimitivesAPI_Torus::~PrimitivesAPI_Torus()
57 //==================================================================================================
58 void PrimitivesAPI_Torus::setRadius(const ModelHighAPI_Double& theRadius,
59 const ModelHighAPI_Double& theRingRadius)
61 fillAttribute(theRadius, radius());
62 fillAttribute(theRingRadius, ringRadius());
66 //==================================================================================================
67 void PrimitivesAPI_Torus::dump(ModelHighAPI_Dumper& theDumper) const
69 FeaturePtr aBase = feature();
70 const std::string& aDocName = theDumper.name(aBase->document());
72 theDumper << aBase << " = model.addTorus(" << aDocName;
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;
80 AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Torus::RADIUS_ID());
81 AttributeDoublePtr anAttrRingRadius = aBase->real(PrimitivesPlugin_Torus::RING_RADIUS_ID());
82 theDumper << ", " << anAttrRadius << ", " << anAttrRingRadius;
84 theDumper << ")" << std::endl;
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)
94 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Torus::ID());
95 return TorusPtr(new PrimitivesAPI_Torus(aFeature, theBasePoint, theAxis,
96 theRadius, theRingRadius));
99 //==================================================================================================
100 TorusPtr addTorus(const std::shared_ptr<ModelAPI_Document>& thePart,
101 const ModelHighAPI_Double& theRadius,
102 const ModelHighAPI_Double& theRingRadius)
104 ModelHighAPI_Selection aBasePoint("VERTEX", "PartSet/Origin");
105 ModelHighAPI_Selection anAxis("EDGE", "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));