Salome HOME
40c5c4ab31bd1e8e11ef45942d9a9fb873df82f0
[modules/shaper.git] / src / SketchAPI / SketchAPI_Ellipse.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_Ellipse.h"
21
22 #include <GeomAPI_Pnt2d.h>
23
24 #include <ModelHighAPI_Dumper.h>
25 #include <ModelHighAPI_Selection.h>
26 #include <ModelHighAPI_Tools.h>
27
28 SketchAPI_Ellipse::SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature> & theFeature)
29   : SketchAPI_SketchEntity(theFeature)
30 {
31   initialize();
32 }
33
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)
39 {
40   if(initialize()) {
41     setByCenterFocusAndRadius(theCenterX, theCenterY, theFocusX, theFocusY, theMinorRadius);
42   }
43 }
44
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)
50 {
51   if(initialize()) {
52     setByCenterFocusAndRadius(theCenter, theFocus, theMinorRadius);
53   }
54 }
55
56 SketchAPI_Ellipse::SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
57                                      const ModelHighAPI_Selection& theExternal)
58   : SketchAPI_SketchEntity(theFeature)
59 {
60   if (initialize()) {
61     setByExternal(theExternal);
62   }
63 }
64
65 SketchAPI_Ellipse::SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
66                                      const std::string& theExternalName)
67   : SketchAPI_SketchEntity(theFeature)
68 {
69   if (initialize()) {
70     setByExternalName(theExternalName);
71   }
72 }
73
74 SketchAPI_Ellipse::~SketchAPI_Ellipse()
75 {
76 }
77
78 void SketchAPI_Ellipse::setByCenterFocusAndRadius(double theCenterX, double theCenterY,
79                                                   double theFocusX, double theFocusY,
80                                                   double theMinorRadius)
81 {
82   fillAttribute(center(), theCenterX, theCenterY);
83   fillAttribute(firstFocus(), theFocusX, theFocusY);
84   fillAttribute(theMinorRadius, myminorRadius);
85
86   execute();
87 }
88
89 void SketchAPI_Ellipse::setByCenterFocusAndRadius(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
90                                                   const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
91                                                   double theMinorRadius)
92 {
93   fillAttribute(theCenter, mycenter);
94   fillAttribute(theFocus, myfirstFocus);
95   fillAttribute(theMinorRadius, myminorRadius);
96
97   execute();
98 }
99
100 void SketchAPI_Ellipse::setByExternal(const ModelHighAPI_Selection & theExternal)
101 {
102   fillAttribute(theExternal, external());
103   execute();
104 }
105
106 void SketchAPI_Ellipse::setByExternalName(const std::string & theExternalName)
107 {
108   fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
109   execute();
110 }
111
112 void SketchAPI_Ellipse::setCenter(double theX, double theY)
113 {
114   fillAttribute(center(), theX, theY);
115   execute();
116 }
117
118 void SketchAPI_Ellipse::setCenter(const std::shared_ptr<GeomAPI_Pnt2d> & theCenter)
119 {
120   fillAttribute(theCenter, mycenter);
121   execute();
122 }
123
124 void SketchAPI_Ellipse::setFocus(double theX, double theY)
125 {
126   fillAttribute(firstFocus(), theX, theY);
127   execute();
128 }
129
130 void SketchAPI_Ellipse::setFocus(const std::shared_ptr<GeomAPI_Pnt2d> & theFocus)
131 {
132   fillAttribute(theFocus, myfirstFocus);
133   execute();
134 }
135
136 void SketchAPI_Ellipse::setMinorRadius(double theMinorRadius)
137 {
138   fillAttribute(theMinorRadius, myminorRadius);
139   execute();
140 }
141
142 ModelHighAPI_Selection SketchAPI_Ellipse::majorAxis() const
143 {
144 }
145
146 ModelHighAPI_Selection SketchAPI_Ellipse::minorAxis() const
147 {
148 }
149
150 void SketchAPI_Ellipse::dump(ModelHighAPI_Dumper& theDumper) const
151 {
152   if (isCopy())
153     return; // no need to dump copied feature
154
155   FeaturePtr aBase = feature();
156   const std::string& aSketchName = theDumper.parentName(aBase);
157
158   AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
159   if (anExternal->context()) {
160     // circle is external
161     theDumper << aBase << " = " << aSketchName << ".addEllipse(" << anExternal << ")" << std::endl;
162   } else {
163     // ellipse given by center, focus and radius
164     theDumper << aBase << " = " << aSketchName << ".addEllipse("
165               << center() << ", " << firstFocus() << ", " << minorRadius() << ")" << std::endl;
166   }
167   // dump "auxiliary" flag if necessary
168   SketchAPI_SketchEntity::dump(theDumper);
169 }