Salome HOME
f0847f729d50799fca3c3545ccf9bf5f4dc571b7
[modules/shaper.git] / src / SketchAPI / SketchAPI_Ellipse.h
1 // Copyright (C) 2014-2021  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 #ifndef SketchAPI_Ellipse_H_
21 #define SketchAPI_Ellipse_H_
22
23 #include "SketchAPI.h"
24 #include "SketchAPI_SketchEntity.h"
25
26 #include <SketchPlugin_Ellipse.h>
27
28 class ModelHighAPI_Selection;
29
30 typedef std::pair<std::string, std::string> PairOfStrings;
31
32 /// \class SketchAPI_Ellipse
33 /// \ingroup CPPHighAPI
34 /// \brief Interface for Ellipse feature.
35 class SketchAPI_Ellipse : public SketchAPI_SketchEntity
36 {
37 public:
38   /// Constructor without values.
39   SKETCHAPI_EXPORT
40   explicit SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature>& theFeature);
41
42   /// Constructor with values.
43   SKETCHAPI_EXPORT
44   SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
45                     double theCenterX, double theCenterY,
46                     double theFocusX, double theFocusY,
47                     double theMinorRadius);
48
49   /// Constructor with values.
50   SKETCHAPI_EXPORT
51   SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
52                     const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
53                     const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
54                     double theMinorRadius);
55
56   /// Constructor with external.
57   SKETCHAPI_EXPORT
58   SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
59                     const ModelHighAPI_Selection& theExternal);
60
61   /// Constructor with external.
62   SKETCHAPI_EXPORT
63   SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
64                     const std::wstring& theExternalName);
65
66   /// Destructor.
67   SKETCHAPI_EXPORT
68   virtual ~SketchAPI_Ellipse();
69
70   INTERFACE_10(SketchPlugin_Ellipse::ID(),
71                center, SketchPlugin_Ellipse::CENTER_ID(),
72                GeomDataAPI_Point2D, /** Center point */,
73                firstFocus, SketchPlugin_Ellipse::FIRST_FOCUS_ID(),
74                GeomDataAPI_Point2D, /** Focus in positive direction of a major axis */,
75                secondFocus, SketchPlugin_Ellipse::SECOND_FOCUS_ID(),
76                GeomDataAPI_Point2D, /** Focus in negative direction of a major axis */,
77                majorAxisNegative, SketchPlugin_Ellipse::MAJOR_AXIS_START_ID(),
78                GeomDataAPI_Point2D, /** Start point of major axis */,
79                majorAxisPositive, SketchPlugin_Ellipse::MAJOR_AXIS_END_ID(),
80                GeomDataAPI_Point2D, /** End point of major axis */,
81                minorAxisNegative, SketchPlugin_Ellipse::MINOR_AXIS_START_ID(),
82                GeomDataAPI_Point2D, /** Start point of minor axis */,
83                minorAxisPositive, SketchPlugin_Ellipse::MINOR_AXIS_END_ID(),
84                GeomDataAPI_Point2D, /** End point of minor axis */,
85                majorRadius, SketchPlugin_Ellipse::MAJOR_RADIUS_ID(),
86                ModelAPI_AttributeDouble, /** Major radius */,
87                minorRadius, SketchPlugin_Ellipse::MINOR_RADIUS_ID(),
88                ModelAPI_AttributeDouble, /** Minor radius */,
89                external, SketchPlugin_Ellipse::EXTERNAL_ID(),
90                ModelAPI_AttributeSelection, /** External */)
91
92   /// Set by center, focus and radius.
93   SKETCHAPI_EXPORT
94   void setByCenterFocusAndRadius(double theCenterX, double theCenterY,
95                                  double theFocusX, double theFocusY,
96                                  double theMinorRadius);
97
98   /// Set by center, focus and radius.
99   SKETCHAPI_EXPORT
100   void setByCenterFocusAndRadius(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
101                                  const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
102                                  double theMinorRadius);
103
104   /// Set by external.
105   SKETCHAPI_EXPORT
106   void setByExternal(const ModelHighAPI_Selection& theExternal);
107
108   /// Set by external name.
109   SKETCHAPI_EXPORT
110   void setByExternalName(const std::wstring& theExternalName);
111
112   /// Set center.
113   SKETCHAPI_EXPORT
114   void setCenter(double theX, double theY);
115
116   /// Set center.
117   SKETCHAPI_EXPORT
118   void setCenter(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter);
119
120   /// Set focus.
121   SKETCHAPI_EXPORT
122   void setFocus(double theX, double theY);
123
124   /// Set focus.
125   SKETCHAPI_EXPORT
126   void setFocus(const std::shared_ptr<GeomAPI_Pnt2d>& theFocus);
127
128   /// Set radius.
129   SKETCHAPI_EXPORT
130   void setMinorRadius(double theRadius);
131
132   /// Create construction elements (focuses, axes etc.).
133   /// Empty value for each parameter shows that the corresponding feature has been removed.
134   /// Value "aux" marks this feature as auxiliary.
135   /// And the name of the feature shows that it is a regular feature.
136   SKETCHAPI_EXPORT
137   std::list<std::shared_ptr<SketchAPI_SketchEntity> > construction(
138       const std::wstring& center = std::wstring(),
139       const std::wstring& firstFocus = std::wstring(),
140       const std::wstring& secondFocus = std::wstring(),
141       const std::wstring& majorAxisStart = std::wstring(),
142       const std::wstring& majorAxisEnd = std::wstring(),
143       const std::wstring& minorAxisStart = std::wstring(),
144       const std::wstring& minorAxisEnd = std::wstring(),
145       const std::wstring& majorAxis = std::wstring(),
146       const std::wstring& minorAxis = std::wstring()) const;
147
148   /// Dump wrapped feature
149   SKETCHAPI_EXPORT
150   virtual void dump(ModelHighAPI_Dumper& theDumper) const;
151
152 private:
153   /// Find all features connected with theEllipse by the internal coincidence.
154   /// \param[in]  theEllipse        ellipse or elliptic arc
155   /// \param[in]  theMajorAxis      names of attributes composing a major axis of ellipse
156   /// \param[in]  theMinorAxis      names of attributes composing a minor axis of ellipse
157   /// \param[out] theAttrToFeature  map attribute of ellipse and coincident auxiliary feature
158   static void collectAuxiliaryFeatures(FeaturePtr theEllipse,
159                                        const PairOfStrings& theMajorAxis,
160                                        const PairOfStrings& theMinorAxis,
161                                        std::map<std::string, FeaturePtr>& theAttrToFeature);
162
163   /// \brief Dump the construction features (points, axes) for the ellipse.
164   /// \param[in] theDumper      dumper instance
165   /// \param[in] theAttributes  list of attributes the construction points are
166   ///                           connected with, and their dump names
167   /// \param[in] theAuxFeatures list of construction features
168   static void dumpConstructionEntities(ModelHighAPI_Dumper& theDumper,
169                                        const FeaturePtr& theEllipse,
170                                        const std::list<PairOfStrings>& theAttributes,
171                                        const std::map<std::string, FeaturePtr>& theAuxFeatures);
172
173   /// \brief Create construction features for the ellipse connected
174   ///        with corresponding attribute of ellipse.
175   static std::list<std::shared_ptr<SketchAPI_SketchEntity> > buildConstructionEntities(
176       const FeaturePtr& theEllipse,
177       const std::list<PairOfStrings>& theAttributes,
178       const std::wstring& theCenter,
179       const std::wstring& theFirstFocus,
180       const std::wstring& theSecondFocus,
181       const std::wstring& theMajorAxisStart,
182       const std::wstring& theMajorAxisEnd,
183       const std::wstring& theMinorAxisStart,
184       const std::wstring& theMinorAxisEnd,
185       const std::wstring& theMajorAxis,
186       const std::wstring& theMinorAxis);
187
188   friend class SketchAPI_EllipticArc;
189 };
190
191 /// Pointer on Ellipse object.
192 typedef std::shared_ptr<SketchAPI_Ellipse> EllipsePtr;
193
194 #endif // SketchPlugin_Ellipse_H_