]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchAPI/SketchAPI_Circle.cpp
Salome HOME
[GITHUB #2] problem in export dialog - difference in STEP vs BREP
[modules/shaper.git] / src / SketchAPI / SketchAPI_Circle.cpp
1 // Copyright (C) 2014-2024  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 #include <SketchAPI_Point.h>
30 #include <SketchPlugin_ConstraintCoincidenceInternal.h>
31
32 //==================================================================================================
33 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature> & theFeature)
34 : SketchAPI_SketchEntity(theFeature)
35 {
36   initialize();
37 }
38
39 //==================================================================================================
40 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
41                                    double theCenterX,
42                                    double theCenterY,
43                                    double theRadius,
44                                    bool theIsAddPoint,
45                                    double theAngle)
46 : SketchAPI_SketchEntity(theFeature)
47 {
48   if(initialize()) {
49     setByCenterAndRadius(theCenterX, theCenterY, theRadius, theIsAddPoint, theAngle);
50   }
51 }
52
53 //==================================================================================================
54 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
55                                    const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
56                                    double theRadius,
57                                    bool theIsAddPoint,
58                                    double theAngle)
59 : SketchAPI_SketchEntity(theFeature)
60 {
61   if(initialize()) {
62     setByCenterAndRadius(theCenter, theRadius, theAngle);
63   }
64 }
65
66 //==================================================================================================
67 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
68                                    const ModelHighAPI_Selection& theExternal)
69 : SketchAPI_SketchEntity(theFeature)
70 {
71   if (initialize()) {
72     setByExternal(theExternal);
73   }
74 }
75
76 //==================================================================================================
77 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
78                                    const std::wstring& theExternalName)
79 : SketchAPI_SketchEntity(theFeature)
80 {
81   if (initialize()) {
82     setByExternalName(theExternalName);
83   }
84 }
85
86 //==================================================================================================
87 SketchAPI_Circle::~SketchAPI_Circle()
88 {
89
90 }
91
92 //==================================================================================================
93 void SketchAPI_Circle::setByCenterAndRadius(double theCenterX, double theCenterY,
94                                             double theRadius, bool theIsAddPoint,
95                                             double theAngle)
96 {
97   fillAttribute(center(), theCenterX, theCenterY);
98   fillAttribute(theRadius, myradius);
99   fillAttribute(theIsAddPoint, myaddpoint);
100   fillAttribute(theAngle, myangle);
101
102   execute();
103   //createPoint();
104 }
105
106 //==================================================================================================
107 void SketchAPI_Circle::setByCenterAndRadius(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
108                                             double theRadius, bool theIsAddPoint,
109                                             double theAngle)
110 {
111   fillAttribute(theCenter, mycenter);
112   fillAttribute(theRadius, myradius);
113   fillAttribute(theIsAddPoint, myaddpoint);
114   fillAttribute(theAngle, myangle);
115
116   execute();
117   //createPoint();
118 }
119
120 //==================================================================================================
121 void SketchAPI_Circle::setByExternal(const ModelHighAPI_Selection & theExternal)
122 {
123   fillAttribute(theExternal, external());
124
125   execute();
126 }
127
128 //==================================================================================================
129 void SketchAPI_Circle::setByExternalName(const std::wstring & theExternalName)
130 {
131   fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
132
133   execute();
134 }
135
136 //==================================================================================================
137 void SketchAPI_Circle::setCenter(double theX, double theY)
138 {
139   fillAttribute(center(), theX, theY);
140
141   execute();
142 }
143
144 //==================================================================================================
145 void SketchAPI_Circle::setCenter(const std::shared_ptr<GeomAPI_Pnt2d> & theCenter)
146 {
147   fillAttribute(theCenter, mycenter);
148
149   execute();
150 }
151
152 //==================================================================================================
153 void SketchAPI_Circle::setRadius(double theRadius)
154 {
155   fillAttribute(ModelHighAPI_Double(theRadius), myradius);
156
157   execute();
158 }
159
160 //==================================================================================================
161 void SketchAPI_Circle::setIsToAddPoint(bool theIsToAddPoint)
162 {
163   fillAttribute(theIsToAddPoint, myaddpoint);
164
165   execute();
166 }
167
168 //==================================================================================================
169 void SketchAPI_Circle::setAngle(double theAngle)
170 {
171   fillAttribute(ModelHighAPI_Double(theAngle), myangle);
172
173   execute();
174 }
175
176 //==================================================================================================
177 // Return created point
178 std::shared_ptr<SketchAPI_SketchEntity> SketchAPI_Circle::createdPoint() const
179 {
180   AttributeReferencePtr anRef = feature()->reference(SketchPlugin_Circle::CONSTRUCTION_POINT_REF_ID());
181   if (!anRef->isInitialized())
182     return {};
183
184   FeaturePtr aFeature = ModelAPI_Feature::feature(anRef->value());
185   if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
186   {
187     return std::shared_ptr < SketchAPI_SketchEntity>(new SketchAPI_Point(aFeature));
188   }
189   return {};
190 }
191
192 //==================================================================================================
193 void SketchAPI_Circle::dump(ModelHighAPI_Dumper& theDumper) const
194 {
195   if (isCopy())
196     return; // no need to dump copied feature
197
198   FeaturePtr aBase = feature();
199   const std::string& aSketchName = theDumper.parentName(aBase);
200
201   const bool isToAddPoint = addpoint()->value();
202
203   AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
204   if (anExternal->context()) {
205     // circle is external
206     if(isToAddPoint)
207     {
208       theDumper << aBase << " = " << aSketchName << ".addCircleWithPoint(" << anExternal << ")" << std::endl;
209     }
210     else
211     {
212       theDumper << aBase << " = " << aSketchName << ".addCircle(" << anExternal << ")" << std::endl;
213     }
214   }
215   else {
216     // circle given by center and radius
217     if(isToAddPoint)
218     {
219       theDumper << aBase << " = " << aSketchName << ".addCircleWithPoint(" << center() << ", " << radius();
220       theDumper << ", " << angle() << ")" << std::endl;
221       std::shared_ptr<SketchAPI_SketchEntity> aPoint = createdPoint();
222       if (aPoint)
223         theDumper << aPoint->feature() << " = " << theDumper.name(aBase) << ".createdPoint()" << std::endl;
224     }
225     else
226     {
227       theDumper << aBase << " = " << aSketchName << ".addCircle("
228               << center() << ", " << radius() << ")" << std::endl;
229     }
230   }
231   // dump "auxiliary" flag if necessary
232   SketchAPI_SketchEntity::dump(theDumper);
233 }