Salome HOME
bos#35152 [EDF] (2023-T1) Sketch Circle should allow user to position construction...
[modules/shaper.git] / src / SketchAPI / SketchAPI_MacroCircle.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_MacroCircle.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_MacroCircle::SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature)
34 : SketchAPI_SketchEntity(theFeature)
35 {
36   initialize();
37 }
38
39 //==================================================================================================
40 SketchAPI_MacroCircle::SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
41                                              double theCenterX,
42                                              double theCenterY,
43                                              double thePassedX,
44                                              double thePassedY,
45                                              double theAngle)
46 : SketchAPI_SketchEntity(theFeature)
47 {
48   if(initialize()) {
49     setByCenterAndPassedPoints(theCenterX, theCenterY, thePassedX, thePassedY, theAngle);
50   }
51 }
52
53 //==================================================================================================
54 SketchAPI_MacroCircle::SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
55                                              const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
56                                              const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint,
57                                              double theAngle)
58 : SketchAPI_SketchEntity(theFeature)
59 {
60   if(initialize()) {
61     setByCenterAndPassedPoints(theCenterPoint, thePassedPoint, theAngle);
62   }
63 }
64
65 //==================================================================================================
66 SketchAPI_MacroCircle::SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
67                                              double theX1, double theY1,
68                                              double theX2, double theY2,
69                                              double theX3, double theY3,
70                                              double theAngle)
71 : SketchAPI_SketchEntity(theFeature)
72 {
73   if(initialize()) {
74     setByThreePoints(theX1, theY1, theX2, theY2, theX3, theY3, theAngle);
75   }
76 }
77
78 //==================================================================================================
79 SketchAPI_MacroCircle::SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
80                                              const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
81                                              const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
82                                              const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3,
83                                              double theAngle)
84 : SketchAPI_SketchEntity(theFeature)
85 {
86   if(initialize()) {
87     setByThreePoints(thePoint1, thePoint2, thePoint3, theAngle);
88   }
89 }
90
91 //==================================================================================================
92 SketchAPI_MacroCircle::~SketchAPI_MacroCircle()
93 {
94 }
95
96 //==================================================================================================
97 void SketchAPI_MacroCircle::setByCenterAndPassedPoints(double theCenterX,
98                                                        double theCenterY,
99                                                        double thePassedX,
100                                                        double thePassedY,
101                                                        double theAngle)
102 {
103   fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType);
104   fillAttribute(centerPoint(), theCenterX, theCenterY);
105   fillAttribute(passedPoint(), thePassedX, thePassedY);
106
107   bool isNeedPoint =
108     feature()->integer(SketchPlugin_MacroCircle::VERSION_ID())->value() > 0;
109
110   if (isNeedPoint)
111     fillAttribute(theAngle, angle());
112
113   execute();
114 }
115
116 //==================================================================================================
117 void SketchAPI_MacroCircle::setByCenterAndPassedPoints(
118     const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
119     const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint,
120     double theAngle)
121 {
122   fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType);
123   fillAttribute(theCenterPoint, mycenterPoint);
124   fillAttribute(thePassedPoint, mypassedPoint);
125
126   bool isNeedPoint =
127     feature()->integer(SketchPlugin_MacroCircle::VERSION_ID())->value() > 0;
128
129   if (isNeedPoint)
130     fillAttribute(theAngle, angle());
131
132   execute();
133 }
134
135 //==================================================================================================
136 void SketchAPI_MacroCircle::setByThreePoints(double theX1, double theY1,
137                                              double theX2, double theY2,
138                                              double theX3, double theY3,
139                                              double theAngle)
140 {
141   fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
142   fillAttribute(firstPoint(), theX1, theY1);
143   fillAttribute(secondPoint(), theX2, theY2);
144   fillAttribute(thirdPoint(), theX3, theY3);
145
146   bool isNeedPoint =
147     feature()->integer(SketchPlugin_MacroCircle::VERSION_ID())->value() > 0;
148
149   if (isNeedPoint)
150     fillAttribute(theAngle, angle());
151
152   execute();
153 }
154
155 //==================================================================================================
156 void SketchAPI_MacroCircle::setByThreePoints(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
157                                              const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
158                                              const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3,
159                                              double theAngle)
160 {
161   fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
162   fillAttribute(thePoint1, myfirstPoint);
163   fillAttribute(thePoint2, mysecondPoint);
164   fillAttribute(thePoint3, mythirdPoint);
165
166   bool isNeedPoint =
167     feature()->integer(SketchPlugin_MacroCircle::VERSION_ID())->value() > 0;
168
169   if (isNeedPoint)
170     fillAttribute(theAngle, angle());
171
172   execute();
173 }
174
175 // return created point
176 std::shared_ptr<SketchAPI_SketchEntity> SketchAPI_MacroCircle::createdPoint() const
177 {
178   std::shared_ptr<SketchAPI_SketchEntity> anEnt;
179
180   AttributeRefAttrPtr anRef = feature()->refattr(SketchPlugin_MacroCircle::ROTATE_POINT_REF_ID());
181   if (!anRef->isInitialized())
182     return anEnt;
183
184   ObjectPtr aPointObj = anRef->object();
185   FeaturePtr aFeature = ModelAPI_Feature::feature(aPointObj);
186   if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
187   {
188     anEnt = std::shared_ptr < SketchAPI_SketchEntity>(new SketchAPI_Point(aFeature));
189   }
190   return anEnt;
191 }