Salome HOME
ac88a4522dfa794599d77f3fa04a4937e691ed64
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_CurveFitting.h
1 // Copyright (C) 2020-2023  CEA, EDF
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 SketchPlugin_CurveFitting_H_
21 #define SketchPlugin_CurveFitting_H_
22
23 #include <SketchPlugin.h>
24 #include <SketchPlugin_SketchEntity.h>
25
26 #include <GeomAPI_IPresentable.h>
27
28 class GeomAPI_Edge;
29
30 /**\class SketchPlugin_CurveFitting
31  * \ingroup Plugins
32  * \brief Feature for creation of the new B-spline curve in sketch
33  *        as an interpolation or an approximation of a list of points.
34  */
35 class SketchPlugin_CurveFitting : public SketchPlugin_SketchEntity,
36                                   public GeomAPI_IPresentable
37 {
38 public:
39   /// Interpolation macro feature kind
40   inline static const std::string& ID()
41   {
42     static const std::string ID("SketchCurveFitting");
43     return ID;
44   }
45
46   /// list of selected points
47   inline static const std::string& POINTS_ID()
48   {
49     static const std::string ID("points");
50     return ID;
51   }
52
53   /// attribute for the periodic flag
54   inline static const std::string& PERIODIC_ID()
55   {
56     static const std::string ID("periodic");
57     return ID;
58   }
59
60   /// attribute for the closed flag
61   inline static const std::string& CLOSED_ID()
62   {
63     static const std::string ID("closed");
64     return ID;
65   }
66
67   /// attribute for the flag of creation a control polygon
68   inline static const std::string& NEED_CONTROL_POLYGON_ID()
69   {
70     static const std::string ID("need_control_poly");
71     return ID;
72   }
73
74   /// attribute for the type of the operation
75   inline static const std::string& TYPE_ID()
76   {
77     static const std::string ID("type");
78     return ID;
79   }
80
81   /// value for the type of operation
82   inline static const std::string& TYPE_INTERPOLATION_ID()
83   {
84     static const std::string ID("interpolation_type");
85     return ID;
86   }
87
88   /// value for the type of operation
89   inline static const std::string& TYPE_APPROXIMATION_ID()
90   {
91     static const std::string ID("approximation_type");
92     return ID;
93   }
94
95   /// attribute for the precision of the approximation
96   inline static const std::string& PRECISION_ID()
97   {
98     static const std::string ID("precision");
99     return ID;
100   }
101
102   /// attribute for the closed flag
103   inline static const std::string& REORDER_POINTS_ACTION_ID()
104   {
105     static const std::string ID("reorder_points");
106     return ID;
107   }
108
109   /// Returns the kind of a feature
110   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
111   {
112     static std::string MY_KIND = SketchPlugin_CurveFitting::ID();
113     return MY_KIND;
114   }
115
116   /// Returns the AIS preview
117   virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
118
119   /// Creates a new part document if needed
120   SKETCHPLUGIN_EXPORT virtual void execute();
121
122   /// Reimplemented from ModelAPI_Feature::isMacro().
123   /// \returns true
124   SKETCHPLUGIN_EXPORT virtual bool isMacro() const {return true;};
125
126   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const {return false;};
127
128   /// Performs some functionality by action id.
129   /// \param[in] theAttributeId action key id.
130   /// \return false in case if action not performed.
131   SKETCHPLUGIN_EXPORT virtual bool customAction(const std::string& theActionId);
132
133   /// Use plugin manager for features creation
134   SketchPlugin_CurveFitting();
135
136 protected:
137   /// \brief Initializes attributes of derived class.
138   virtual void initDerivedClassAttributes();
139
140 private:
141   /// \brief Create a feature, which passes through the selected points
142   FeaturePtr createBSplineFeature();
143
144   /// \brief Create coincidence constraints between selected points and the produced curve.
145   void createConstraints(FeaturePtr theProducedFeature);
146
147   /// \brief Reorder point to compose the polyline of the minimal length
148   void reorderPoints();
149
150 private:
151   std::shared_ptr<GeomAPI_Edge> myTransientResult; ///< Interpolation curve
152 };
153
154 #endif