Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchAPI / SketchAPI_MacroArc.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_MacroArc.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 <SketchPlugin_ConstraintCoincidence.h>
30 #include <SketchPlugin_ConstraintTangent.h>
31
32 //================================================================================================
33 SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr<ModelAPI_Feature> & theFeature)
34 : SketchAPI_SketchEntity(theFeature)
35 {
36   initialize();
37 }
38
39 //================================================================================================
40 SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
41                              double theCenterX, double theCenterY,
42                              double theStartX, double theStartY,
43                              double theEndX, double theEndY,
44                              bool theInversed)
45 : SketchAPI_SketchEntity(theFeature)
46 {
47   if(initialize()) {
48     setByCenterStartEnd(theCenterX, theCenterY, theStartX,
49                         theStartY, theEndX, theEndY, theInversed);
50   }
51 }
52
53 //================================================================================================
54 SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
55                              const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
56                              const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
57                              const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
58                              bool theInversed)
59 : SketchAPI_SketchEntity(theFeature)
60 {
61   if(initialize()) {
62     setByCenterStartEnd(theCenter, theStart, theEnd, theInversed);
63   }
64 }
65
66 //================================================================================================
67 SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
68                              double theStartX, double theStartY,
69                              double theEndX, double theEndY,
70                              double thePassedX, double thePassedY)
71 : SketchAPI_SketchEntity(theFeature)
72 {
73   if (initialize()) {
74     setByStartEndPassed(theStartX, theStartY, theEndX, theEndY, thePassedX, thePassedY);
75   }
76 }
77
78 //===============================================================================================
79 SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
80                              const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
81                              const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
82                              const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
83 : SketchAPI_SketchEntity(theFeature)
84 {
85   if (initialize()) {
86     setByStartEndPassed(theStart, theEnd, thePassed);
87   }
88 }
89
90 //================================================================================================
91 SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
92                              const ModelHighAPI_RefAttr& theTangentPoint,
93                              double theEndX, double theEndY,
94                              bool theInversed)
95 : SketchAPI_SketchEntity(theFeature)
96 {
97   if (initialize()) {
98     setByTangent(theTangentPoint, theEndX, theEndY, theInversed);
99   }
100 }
101
102 //================================================================================================
103 SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
104                              const ModelHighAPI_RefAttr& theTangentPoint,
105                              const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
106                              bool theInversed)
107 : SketchAPI_SketchEntity(theFeature)
108 {
109   if (initialize()) {
110     setByTangent(theTangentPoint, theEnd, theInversed);
111   }
112 }
113
114 //================================================================================================
115 SketchAPI_MacroArc::~SketchAPI_MacroArc()
116 {
117
118 }
119
120 //================================================================================================
121 void SketchAPI_MacroArc::setByCenterStartEnd(double theCenterX, double theCenterY,
122                                         double theStartX, double theStartY,
123                                         double theEndX, double theEndY,
124                                         bool theInversed)
125 {
126   fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_CENTER_AND_POINTS(), myarcType);
127   fillAttribute(center(), theCenterX, theCenterY);
128   fillAttribute(startPoint1(), theStartX, theStartY);
129   fillAttribute(endPoint1(), theEndX, theEndY);
130   fillAttribute(theInversed, myreversed);
131
132   execute();
133 }
134
135 //================================================================================================
136 void SketchAPI_MacroArc::setByCenterStartEnd(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
137                                         const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
138                                         const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
139                                         bool theInversed)
140 {
141   fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_CENTER_AND_POINTS(), myarcType);
142   fillAttribute(theCenter, mycenter);
143   fillAttribute(theStart, mystartPoint1);
144   fillAttribute(theEnd, myendPoint1);
145   fillAttribute(theInversed, myreversed);
146
147   execute();
148 }
149
150 //================================================================================================
151 void SketchAPI_MacroArc::setByStartEndPassed(double theStartX, double theStartY,
152                                         double theEndX, double theEndY,
153                                         double thePassedX, double thePassedY)
154 {
155   fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_THREE_POINTS(), myarcType);
156   fillAttribute(startPoint2(), theStartX, theStartY);
157   fillAttribute(endPoint2(), theEndX, theEndY);
158   fillAttribute(passedPoint(), thePassedX, thePassedY);
159
160   execute();
161 }
162
163 //================================================================================================
164 void SketchAPI_MacroArc::setByStartEndPassed(const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
165                                         const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
166                                         const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
167 {
168   fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_THREE_POINTS(), myarcType);
169   fillAttribute(theStart, mystartPoint2);
170   fillAttribute(theEnd, myendPoint2);
171   fillAttribute(thePassed, mypassedPoint);
172
173   execute();
174 }
175
176 //================================================================================================
177 void SketchAPI_MacroArc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint,
178                                  double theEndX, double theEndY,
179                                  bool theInversed)
180 {
181   fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE(), myarcType);
182   fillAttribute(theTangentPoint, mytangentPoint);
183   fillAttribute(endPoint3(), theEndX, theEndY);
184   fillAttribute(theInversed, myreversed);
185
186   execute();
187 }
188
189 //================================================================================================
190 void SketchAPI_MacroArc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint,
191                                  const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
192                                  bool theInversed)
193 {
194   fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE(), myarcType);
195   fillAttribute(theTangentPoint, mytangentPoint);
196   fillAttribute(theEnd, myendPoint3);
197   fillAttribute(theInversed, myreversed);
198
199   execute();
200 }
201
202 //================================================================================================
203 void SketchAPI_MacroArc::setByTransversal(const ModelHighAPI_RefAttr& theTransversalPoint,
204                                           double theEndX, double theEndY,
205                                           bool theInversed)
206 {
207   fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_TRANSVERSAL_LINE(), myarcType);
208   fillAttribute(theTransversalPoint, mytransversalPoint);
209   fillAttribute(endPoint4(), theEndX, theEndY);
210   fillAttribute(theInversed, myreversed);
211
212   execute();
213 }
214
215 //================================================================================================
216 void SketchAPI_MacroArc::setByTransversal(const ModelHighAPI_RefAttr& theTransversalPoint,
217                                           const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
218                                           bool theInversed)
219 {
220   fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_TRANSVERSAL_LINE(), myarcType);
221   fillAttribute(theTransversalPoint, mytransversalPoint);
222   fillAttribute(theEnd, myendPoint4);
223   fillAttribute(theInversed, myreversed);
224
225   execute();
226 }