Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / SketchAPI / SketchAPI_Circle.cpp
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "SketchAPI_Circle.h"
22
23 #include <GeomAPI_Pnt2d.h>
24
25 #include <ModelHighAPI_Double.h>
26 #include <ModelHighAPI_Dumper.h>
27 #include <ModelHighAPI_Selection.h>
28 #include <ModelHighAPI_Tools.h>
29
30 //==================================================================================================
31 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature> & theFeature)
32 : SketchAPI_SketchEntity(theFeature)
33 {
34   initialize();
35 }
36
37 //==================================================================================================
38 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
39                                    double theCenterX,
40                                    double theCenterY,
41                                    double theRadius)
42 : SketchAPI_SketchEntity(theFeature)
43 {
44   if(initialize()) {
45     setByCenterAndRadius(theCenterX, theCenterY, theRadius);
46   }
47 }
48
49 //==================================================================================================
50 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
51                                    const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
52                                    double theRadius)
53 : SketchAPI_SketchEntity(theFeature)
54 {
55   if(initialize()) {
56     setByCenterAndRadius(theCenter, theRadius);
57   }
58 }
59
60 //==================================================================================================
61 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
62                                    const ModelHighAPI_Selection& theExternal)
63 : SketchAPI_SketchEntity(theFeature)
64 {
65   if (initialize()) {
66     setByExternal(theExternal);
67   }
68 }
69
70 //==================================================================================================
71 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
72                                    const std::string& theExternalName)
73 : SketchAPI_SketchEntity(theFeature)
74 {
75   if (initialize()) {
76     setByExternalName(theExternalName);
77   }
78 }
79
80 //==================================================================================================
81 SketchAPI_Circle::~SketchAPI_Circle()
82 {
83
84 }
85
86 //==================================================================================================
87 void SketchAPI_Circle::setByCenterAndRadius(double theCenterX, double theCenterY, double theRadius)
88 {
89   fillAttribute(center(), theCenterX, theCenterY);
90   fillAttribute(theRadius, myradius);
91
92   execute();
93 }
94
95 //==================================================================================================
96 void SketchAPI_Circle::setByCenterAndRadius(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
97                                             double theRadius)
98 {
99   fillAttribute(theCenter, mycenter);
100   fillAttribute(theRadius, myradius);
101
102   execute();
103 }
104
105 //==================================================================================================
106 void SketchAPI_Circle::setByExternal(const ModelHighAPI_Selection & theExternal)
107 {
108   fillAttribute(theExternal, external());
109
110   execute();
111 }
112
113 //==================================================================================================
114 void SketchAPI_Circle::setByExternalName(const std::string & theExternalName)
115 {
116   fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
117
118   execute();
119 }
120
121 //==================================================================================================
122 void SketchAPI_Circle::setCenter(double theX, double theY)
123 {
124   fillAttribute(center(), theX, theY);
125
126   execute();
127 }
128
129 //==================================================================================================
130 void SketchAPI_Circle::setCenter(const std::shared_ptr<GeomAPI_Pnt2d> & theCenter)
131 {
132   fillAttribute(theCenter, mycenter);
133
134   execute();
135 }
136
137 //==================================================================================================
138 void SketchAPI_Circle::setRadius(double theRadius)
139 {
140   fillAttribute(ModelHighAPI_Double(theRadius), myradius);
141
142   execute();
143 }
144
145 //==================================================================================================
146 void SketchAPI_Circle::dump(ModelHighAPI_Dumper& theDumper) const
147 {
148   if (isCopy())
149     return; // no need to dump copied feature
150
151   FeaturePtr aBase = feature();
152   const std::string& aSketchName = theDumper.parentName(aBase);
153
154   AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
155   if (anExternal->context()) {
156     // circle is external
157     theDumper << aBase << " = " << aSketchName << ".addCircle(" << anExternal << ")" << std::endl;
158   } else {
159     // circle given by center and radius
160     theDumper << aBase << " = " << aSketchName << ".addCircle("
161               << center() << ", " << radius() << ")" << std::endl;
162   }
163   // dump "auxiliary" flag if necessary
164   SketchAPI_SketchEntity::dump(theDumper);
165 }