Salome HOME
Task 2.12. New entities: ellipses and arcs of ellipses (issue #3003)
[modules/shaper.git] / src / SketchAPI / SketchAPI_MacroEllipse.h
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 #ifndef SketchAPI_MacroEllipse_H_
21 #define SketchAPI_MacroEllipse_H_
22
23 #include "SketchAPI.h"
24 #include "SketchAPI_SketchEntity.h"
25
26 #include <SketchPlugin_MacroEllipse.h>
27
28 class ModelHighAPI_RefAttr;
29 class SketchAPI_Point;
30 class SketchAPI_Line;
31
32 /// \class SketchAPI_MacroEllipse
33 /// \ingroup CPPHighAPI
34 /// \brief Interface for Ellipse feature.
35 class SketchAPI_MacroEllipse: public SketchAPI_SketchEntity
36 {
37 public:
38   /// Constructor without values.
39   SKETCHAPI_EXPORT
40   explicit SketchAPI_MacroEllipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
41                                   bool callInitialize = true);
42
43   /// Constructor with values.
44   SKETCHAPI_EXPORT
45   SketchAPI_MacroEllipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
46                          double theX1, double theY1,
47                          double theX2, double theY2,
48                          double theX3, double theY3,
49                          bool byCenter = true);
50
51   /// Constructor with values.
52   SKETCHAPI_EXPORT
53   SketchAPI_MacroEllipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
54                          const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
55                          const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
56                          const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3,
57                          bool byCenter = true);
58
59   /// Constructor with values and/or references.
60   SKETCHAPI_EXPORT
61   SketchAPI_MacroEllipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
62                          const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
63                          const ModelHighAPI_RefAttr&           thePoint1Ref,
64                          const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
65                          const ModelHighAPI_RefAttr&           thePoint2Ref,
66                          const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3,
67                          const ModelHighAPI_RefAttr&           thePoint3Ref,
68                          bool byCenter = true);
69
70   /// Destructor.
71   SKETCHAPI_EXPORT
72   virtual ~SketchAPI_MacroEllipse();
73
74   INTERFACE_1(SketchPlugin_MacroEllipse::ID(),
75               ellipseType, SketchPlugin_MacroEllipse::ELLIPSE_TYPE(),
76               ModelAPI_AttributeString, /** Ellipse type */)
77
78   /// Return created auxiliary center point
79   SKETCHAPI_EXPORT std::shared_ptr<SketchAPI_Point> center();
80   /// Return created auxiliary focus in the positive direction of major axis
81   SKETCHAPI_EXPORT std::shared_ptr<SketchAPI_Point> focus1();
82   /// Return created auxiliary focus in the negative direction of major axis
83   SKETCHAPI_EXPORT std::shared_ptr<SketchAPI_Point> focus2();
84   /// Return created auxiliary point - start of major axis
85   SKETCHAPI_EXPORT std::shared_ptr<SketchAPI_Point> majorAxisStart();
86   /// Return created auxiliary point - end of major axis
87   SKETCHAPI_EXPORT std::shared_ptr<SketchAPI_Point> majorAxisEnd();
88   /// Return created auxiliary point - start of minor axis
89   SKETCHAPI_EXPORT std::shared_ptr<SketchAPI_Point> minorAxisStart();
90   /// Return created auxiliary point - end of minor axis
91   SKETCHAPI_EXPORT std::shared_ptr<SketchAPI_Point> minorAxisEnd();
92   /// Return created auxiliary major axis
93   SKETCHAPI_EXPORT std::shared_ptr<SketchAPI_Line> majorAxis();
94   /// Return created auxiliary minor axis
95   SKETCHAPI_EXPORT std::shared_ptr<SketchAPI_Line> minorAxis();
96
97 protected:
98   // find a parent sketch
99   void storeSketch(const std::shared_ptr<ModelAPI_Feature>& theFeature);
100
101 private:
102   /// Set flag of creation by center, major semi-axis and passed point.
103   void setByCenterAndPassedPoints();
104   /// Set flag of creation by major axis and passed point.
105   void setByMajorAxisAndPassedPoint();
106
107   /// Set points of ellipse.
108   void initializePoints(double theMajorAxisX1, double theMajorAxisY1,
109                         double theMajorAxisX2, double theMajorAxisY2,
110                         double thePassedX, double thePassedY);
111
112   /// Set points of ellipse.
113   void initializePoints(const std::shared_ptr<GeomAPI_Pnt2d>& theMajorAxisPoint1,
114                         const std::shared_ptr<GeomAPI_Pnt2d>& theMajorAxisPoint2,
115                         const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
116
117   /// Set points of ellipse.
118   void initializePoints(const std::shared_ptr<GeomAPI_Pnt2d>& theMajorAxisPoint1,
119                         const ModelHighAPI_RefAttr&           theMajorAxisPoint1Ref,
120                         const std::shared_ptr<GeomAPI_Pnt2d>& theMajorAxisPoint2,
121                         const ModelHighAPI_RefAttr&           theMajorAxisPoint2Ref,
122                         const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint,
123                         const ModelHighAPI_RefAttr&           thePassedPointRef);
124
125   /// Collect auxiliary features
126   void collectAuxiliary();
127
128 private:
129   CompositeFeaturePtr mySketch;
130   std::shared_ptr<SketchAPI_Point> myCenter;
131   std::shared_ptr<SketchAPI_Point> myFocus1;
132   std::shared_ptr<SketchAPI_Point> myFocus2;
133   std::shared_ptr<SketchAPI_Point> myMajorAxisStart;
134   std::shared_ptr<SketchAPI_Point> myMajorAxisEnd;
135   std::shared_ptr<SketchAPI_Point> myMinorAxisStart;
136   std::shared_ptr<SketchAPI_Point> myMinorAxisEnd;
137   std::shared_ptr<SketchAPI_Line>  myMajorAxis;
138   std::shared_ptr<SketchAPI_Line>  myMinorAxis;
139 };
140
141 /// Pointer on Circle object.
142 typedef std::shared_ptr<SketchAPI_MacroEllipse> MacroEllipsePtr;
143
144 #endif // SketchAPI_MacroEllipse_H_