Salome HOME
Merge remote-tracking branch 'remotes/origin/HigherLevelObjectsHistory'
[modules/shaper.git] / src / SketchAPI / SketchAPI_MacroArc.cpp
1 // Copyright (C) 2014-2019  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 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 /// Obtain constraints prepared by tangent arc
33 static std::list<FeaturePtr> tangentArcConstraints(const FeaturePtr& theArc);
34
35 //================================================================================================
36 SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr<ModelAPI_Feature> & theFeature)
37 : SketchAPI_SketchEntity(theFeature)
38 {
39   initialize();
40 }
41
42 //================================================================================================
43 SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
44                              double theCenterX, double theCenterY,
45                              double theStartX, double theStartY,
46                              double theEndX, double theEndY,
47                              bool theInversed)
48 : SketchAPI_SketchEntity(theFeature)
49 {
50   if(initialize()) {
51     setByCenterStartEnd(theCenterX, theCenterY, theStartX,
52                         theStartY, theEndX, theEndY, theInversed);
53   }
54 }
55
56 //================================================================================================
57 SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
58                              const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
59                              const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
60                              const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
61                              bool theInversed)
62 : SketchAPI_SketchEntity(theFeature)
63 {
64   if(initialize()) {
65     setByCenterStartEnd(theCenter, theStart, theEnd, theInversed);
66   }
67 }
68
69 //================================================================================================
70 SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
71                              double theStartX, double theStartY,
72                              double theEndX, double theEndY,
73                              double thePassedX, double thePassedY)
74 : SketchAPI_SketchEntity(theFeature)
75 {
76   if (initialize()) {
77     setByStartEndPassed(theStartX, theStartY, theEndX, theEndY, thePassedX, thePassedY);
78   }
79 }
80
81 //===============================================================================================
82 SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
83                              const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
84                              const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
85                              const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
86 : SketchAPI_SketchEntity(theFeature)
87 {
88   if (initialize()) {
89     setByStartEndPassed(theStart, theEnd, thePassed);
90   }
91 }
92
93 //================================================================================================
94 SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
95                              const ModelHighAPI_RefAttr& theTangentPoint,
96                              double theEndX, double theEndY,
97                              bool theInversed)
98 : SketchAPI_SketchEntity(theFeature)
99 {
100   if (initialize()) {
101     setByTangent(theTangentPoint, theEndX, theEndY, theInversed);
102   }
103 }
104
105 //================================================================================================
106 SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
107                              const ModelHighAPI_RefAttr& theTangentPoint,
108                              const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
109                              bool theInversed)
110 : SketchAPI_SketchEntity(theFeature)
111 {
112   if (initialize()) {
113     setByTangent(theTangentPoint, theEnd, theInversed);
114   }
115 }
116
117 //================================================================================================
118 SketchAPI_MacroArc::~SketchAPI_MacroArc()
119 {
120
121 }
122
123 //================================================================================================
124 void SketchAPI_MacroArc::setByCenterStartEnd(double theCenterX, double theCenterY,
125                                         double theStartX, double theStartY,
126                                         double theEndX, double theEndY,
127                                         bool theInversed)
128 {
129   fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_CENTER_AND_POINTS(), myarcType);
130   fillAttribute(center(), theCenterX, theCenterY);
131   fillAttribute(startPoint1(), theStartX, theStartY);
132   fillAttribute(endPoint1(), theEndX, theEndY);
133   fillAttribute(theInversed, myreversed);
134
135   execute();
136 }
137
138 //================================================================================================
139 void SketchAPI_MacroArc::setByCenterStartEnd(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
140                                         const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
141                                         const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
142                                         bool theInversed)
143 {
144   fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_CENTER_AND_POINTS(), myarcType);
145   fillAttribute(theCenter, mycenter);
146   fillAttribute(theStart, mystartPoint1);
147   fillAttribute(theEnd, myendPoint1);
148   fillAttribute(theInversed, myreversed);
149
150   execute();
151 }
152
153 //================================================================================================
154 void SketchAPI_MacroArc::setByStartEndPassed(double theStartX, double theStartY,
155                                         double theEndX, double theEndY,
156                                         double thePassedX, double thePassedY)
157 {
158   fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_THREE_POINTS(), myarcType);
159   fillAttribute(startPoint2(), theStartX, theStartY);
160   fillAttribute(endPoint2(), theEndX, theEndY);
161   fillAttribute(passedPoint(), thePassedX, thePassedY);
162
163   execute();
164 }
165
166 //================================================================================================
167 void SketchAPI_MacroArc::setByStartEndPassed(const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
168                                         const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
169                                         const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
170 {
171   fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_THREE_POINTS(), myarcType);
172   fillAttribute(theStart, mystartPoint2);
173   fillAttribute(theEnd, myendPoint2);
174   fillAttribute(thePassed, mypassedPoint);
175
176   execute();
177 }
178
179 //================================================================================================
180 void SketchAPI_MacroArc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint,
181                                  double theEndX, double theEndY,
182                                  bool theInversed)
183 {
184   fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE(), myarcType);
185   fillAttribute(theTangentPoint, mytangentPoint);
186   fillAttribute(endPoint3(), theEndX, theEndY);
187   fillAttribute(theInversed, myreversed);
188
189   execute();
190 }
191
192 //================================================================================================
193 void SketchAPI_MacroArc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint,
194                                  const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
195                                  bool theInversed)
196 {
197   fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE(), myarcType);
198   fillAttribute(theTangentPoint, mytangentPoint);
199   fillAttribute(theEnd, myendPoint3);
200   fillAttribute(theInversed, myreversed);
201
202   execute();
203 }