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