1 // Copyright (C) 2014-2019 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_Ellipse.h"
22 #include <GeomAPI_Pnt2d.h>
24 #include <ModelHighAPI_Dumper.h>
25 #include <ModelHighAPI_Selection.h>
26 #include <ModelHighAPI_Tools.h>
28 SketchAPI_Ellipse::SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature> & theFeature)
29 : SketchAPI_SketchEntity(theFeature)
34 SketchAPI_Ellipse::SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
35 double theCenterX, double theCenterY,
36 double theFocusX, double theFocusY,
37 double theMinorRadius)
38 : SketchAPI_SketchEntity(theFeature)
41 setByCenterFocusAndRadius(theCenterX, theCenterY, theFocusX, theFocusY, theMinorRadius);
45 SketchAPI_Ellipse::SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
46 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
47 const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
48 double theMinorRadius)
49 : SketchAPI_SketchEntity(theFeature)
52 setByCenterFocusAndRadius(theCenter, theFocus, theMinorRadius);
56 SketchAPI_Ellipse::SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
57 const ModelHighAPI_Selection& theExternal)
58 : SketchAPI_SketchEntity(theFeature)
61 setByExternal(theExternal);
65 SketchAPI_Ellipse::SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
66 const std::string& theExternalName)
67 : SketchAPI_SketchEntity(theFeature)
70 setByExternalName(theExternalName);
74 SketchAPI_Ellipse::~SketchAPI_Ellipse()
78 void SketchAPI_Ellipse::setByCenterFocusAndRadius(double theCenterX, double theCenterY,
79 double theFocusX, double theFocusY,
80 double theMinorRadius)
82 fillAttribute(center(), theCenterX, theCenterY);
83 fillAttribute(firstFocus(), theFocusX, theFocusY);
84 fillAttribute(theMinorRadius, myminorRadius);
89 void SketchAPI_Ellipse::setByCenterFocusAndRadius(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
90 const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
91 double theMinorRadius)
93 fillAttribute(theCenter, mycenter);
94 fillAttribute(theFocus, myfirstFocus);
95 fillAttribute(theMinorRadius, myminorRadius);
100 void SketchAPI_Ellipse::setByExternal(const ModelHighAPI_Selection & theExternal)
102 fillAttribute(theExternal, external());
106 void SketchAPI_Ellipse::setByExternalName(const std::string & theExternalName)
108 fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
112 void SketchAPI_Ellipse::setCenter(double theX, double theY)
114 fillAttribute(center(), theX, theY);
118 void SketchAPI_Ellipse::setCenter(const std::shared_ptr<GeomAPI_Pnt2d> & theCenter)
120 fillAttribute(theCenter, mycenter);
124 void SketchAPI_Ellipse::setFocus(double theX, double theY)
126 fillAttribute(firstFocus(), theX, theY);
130 void SketchAPI_Ellipse::setFocus(const std::shared_ptr<GeomAPI_Pnt2d> & theFocus)
132 fillAttribute(theFocus, myfirstFocus);
136 void SketchAPI_Ellipse::setMinorRadius(double theMinorRadius)
138 fillAttribute(theMinorRadius, myminorRadius);
142 ModelHighAPI_Selection SketchAPI_Ellipse::majorAxis() const
144 return ModelHighAPI_Selection();
147 ModelHighAPI_Selection SketchAPI_Ellipse::minorAxis() const
149 return ModelHighAPI_Selection();
152 void SketchAPI_Ellipse::dump(ModelHighAPI_Dumper& theDumper) const
155 return; // no need to dump copied feature
157 FeaturePtr aBase = feature();
158 const std::string& aSketchName = theDumper.parentName(aBase);
160 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
161 if (anExternal->context()) {
162 // circle is external
163 theDumper << aBase << " = " << aSketchName << ".addEllipse(" << anExternal << ")" << std::endl;
165 // ellipse given by center, focus and radius
166 theDumper << aBase << " = " << aSketchName << ".addEllipse("
167 << center() << ", " << firstFocus() << ", " << minorRadius() << ")" << std::endl;
169 // dump "auxiliary" flag if necessary
170 SketchAPI_SketchEntity::dump(theDumper);