1 // Copyright (C) 2014-2021 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SketchAPI_EllipticArc.h"
21 #include "SketchAPI_Ellipse.h"
23 #include <GeomAPI_Pnt2d.h>
25 #include <ModelHighAPI_Dumper.h>
26 #include <ModelHighAPI_Selection.h>
27 #include <ModelHighAPI_Tools.h>
29 #include <SketchPlugin_ConstraintCoincidenceInternal.h>
30 #include <SketchPlugin_Line.h>
31 #include <SketchPlugin_Point.h>
34 SketchAPI_EllipticArc::SketchAPI_EllipticArc(const std::shared_ptr<ModelAPI_Feature> & theFeature)
35 : SketchAPI_SketchEntity(theFeature)
40 SketchAPI_EllipticArc::SketchAPI_EllipticArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
41 double theCenterX, double theCenterY,
42 double theFocusX, double theFocusY,
43 double theStartX, double theStartY,
44 double theEndX, double theEndY,
46 : SketchAPI_SketchEntity(theFeature)
49 setByCenterFocusAndPoints(theCenterX, theCenterY, theFocusX, theFocusY,
50 theStartX, theStartY, theEndX, theEndY, theInversed);
54 SketchAPI_EllipticArc::SketchAPI_EllipticArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
55 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
56 const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
57 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
58 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
60 : SketchAPI_SketchEntity(theFeature)
63 setByCenterFocusAndPoints(theCenter, theFocus, theStart, theEnd, theInversed);
67 SketchAPI_EllipticArc::SketchAPI_EllipticArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
68 const ModelHighAPI_Selection& theExternal)
69 : SketchAPI_SketchEntity(theFeature)
72 setByExternal(theExternal);
76 SketchAPI_EllipticArc::SketchAPI_EllipticArc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
77 const std::wstring& theExternalName)
78 : SketchAPI_SketchEntity(theFeature)
81 setByExternalName(theExternalName);
85 SketchAPI_EllipticArc::~SketchAPI_EllipticArc()
89 void SketchAPI_EllipticArc::setByCenterFocusAndPoints(double theCenterX, double theCenterY,
90 double theFocusX, double theFocusY,
91 double theStartX, double theStartY,
92 double theEndX, double theEndY,
95 // the order of attribute initialization is reversed to avoid odd recalculation of an elliptic arc
96 fillAttribute(theInversed, reversed());
97 fillAttribute(endPoint(), theEndX, theEndY);
98 fillAttribute(startPoint(), theStartX, theStartY);
99 fillAttribute(firstFocus(), theFocusX, theFocusY);
100 fillAttribute(center(), theCenterX, theCenterY);
105 void SketchAPI_EllipticArc::setByCenterFocusAndPoints(
106 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
107 const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
108 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
109 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
112 // the order of attribute initialization is reversed to avoid odd recalculation of an elliptic arc
113 fillAttribute(theInversed, reversed());
114 fillAttribute(theEnd, endPoint());
115 fillAttribute(theStart, startPoint());
116 fillAttribute(theFocus, firstFocus());
117 fillAttribute(theCenter, center());
122 void SketchAPI_EllipticArc::setByExternal(const ModelHighAPI_Selection & theExternal)
124 fillAttribute(theExternal, external());
128 void SketchAPI_EllipticArc::setByExternalName(const std::wstring & theExternalName)
130 fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
134 void SketchAPI_EllipticArc::setCenter(double theX, double theY)
136 fillAttribute(center(), theX, theY);
140 void SketchAPI_EllipticArc::setCenter(const std::shared_ptr<GeomAPI_Pnt2d> & theCenter)
142 fillAttribute(theCenter, mycenter);
146 void SketchAPI_EllipticArc::setFocus(double theX, double theY)
148 fillAttribute(firstFocus(), theX, theY);
152 void SketchAPI_EllipticArc::setFocus(const std::shared_ptr<GeomAPI_Pnt2d> & theFocus)
154 fillAttribute(theFocus, myfirstFocus);
158 static const std::list<PairOfStrings>& ellipticArcAttrAndDumpNames()
160 static std::list<PairOfStrings> anAttributes;
161 if (anAttributes.empty()) {
162 anAttributes.push_back(
163 PairOfStrings(SketchPlugin_EllipticArc::CENTER_ID(), "center"));
164 anAttributes.push_back(
165 PairOfStrings(SketchPlugin_EllipticArc::FIRST_FOCUS_ID(), "firstFocus"));
166 anAttributes.push_back(
167 PairOfStrings(SketchPlugin_EllipticArc::SECOND_FOCUS_ID(), "secondFocus"));
168 anAttributes.push_back(
169 PairOfStrings(SketchPlugin_EllipticArc::MAJOR_AXIS_START_ID(), "majorAxisStart"));
170 anAttributes.push_back(
171 PairOfStrings(SketchPlugin_EllipticArc::MAJOR_AXIS_END_ID(), "majorAxisEnd"));
172 anAttributes.push_back(
173 PairOfStrings(SketchPlugin_EllipticArc::MINOR_AXIS_START_ID(), "minorAxisStart"));
174 anAttributes.push_back(
175 PairOfStrings(SketchPlugin_EllipticArc::MINOR_AXIS_END_ID(), "minorAxisEnd"));
180 std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_EllipticArc::construction(
181 const std::wstring& center,
182 const std::wstring& firstFocus,
183 const std::wstring& secondFocus,
184 const std::wstring& majorAxisStart,
185 const std::wstring& majorAxisEnd,
186 const std::wstring& minorAxisStart,
187 const std::wstring& minorAxisEnd,
188 const std::wstring& majorAxis,
189 const std::wstring& minorAxis) const
191 FeaturePtr anEllipse = feature();
193 std::list<PairOfStrings> anAttributes = ellipticArcAttrAndDumpNames();
194 // append start and end attributes for axes
195 anAttributes.push_back(PairOfStrings(SketchPlugin_EllipticArc::MAJOR_AXIS_START_ID(),
196 SketchPlugin_EllipticArc::MAJOR_AXIS_END_ID()));
197 anAttributes.push_back(PairOfStrings(SketchPlugin_EllipticArc::MINOR_AXIS_START_ID(),
198 SketchPlugin_EllipticArc::MINOR_AXIS_END_ID()));
200 return SketchAPI_Ellipse::buildConstructionEntities(anEllipse, anAttributes,
201 center, firstFocus, secondFocus,
202 majorAxisStart, majorAxisEnd,
203 minorAxisStart, minorAxisEnd,
204 majorAxis, minorAxis);
207 void SketchAPI_EllipticArc::dump(ModelHighAPI_Dumper& theDumper) const
210 return; // no need to dump copied feature
212 FeaturePtr aBase = feature();
213 const std::string& aSketchName = theDumper.parentName(aBase);
215 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
216 if (anExternal->context()) {
217 // circle is external
218 theDumper << aBase << " = " << aSketchName << ".addEllipticArc("
219 << anExternal << ")" << std::endl;
221 // ellipse given by center, focus and radius
222 theDumper << aBase << " = " << aSketchName << ".addEllipticArc("
223 << center() << ", " << firstFocus() << ", "
224 << startPoint() << ", " << endPoint() << ", "
225 << reversed() << ")" << std::endl;
227 // dump "auxiliary" flag if necessary
228 SketchAPI_SketchEntity::dump(theDumper);
230 // dump auxiliary features produced by elliptic arc
231 std::map<std::string, FeaturePtr> anAuxFeatures;
232 static const std::pair<std::string, std::string> aMajorAxis(
233 SketchPlugin_EllipticArc::MAJOR_AXIS_START_ID(),
234 SketchPlugin_EllipticArc::MAJOR_AXIS_END_ID());
235 static const std::pair<std::string, std::string> aMinorAxis(
236 SketchPlugin_EllipticArc::MINOR_AXIS_START_ID(),
237 SketchPlugin_EllipticArc::MINOR_AXIS_END_ID());
238 SketchAPI_Ellipse::collectAuxiliaryFeatures(aBase, aMajorAxis, aMinorAxis, anAuxFeatures);
240 if (!anAuxFeatures.empty()) {
241 // a list of attributes to write features in special order
242 static std::list<PairOfStrings> anAttributes = ellipticArcAttrAndDumpNames();
243 SketchAPI_Ellipse::dumpConstructionEntities(theDumper, aBase, anAttributes, anAuxFeatures);