Salome HOME
cdb7d8bca283ded3b370bece0c5a6416471ae5ee
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_MacroBSpline.h
1 // Copyright (C) 2019-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_MacroBSpline_H_
21 #define SketchPlugin_MacroBSpline_H_
22
23 #include <ModelAPI_IReentrant.h>
24
25 #include "SketchPlugin.h"
26
27 #include "SketchPlugin_SketchEntity.h"
28
29 #include <GeomAPI_IPresentable.h>
30
31 class GeomAPI_Circ2d;
32 class GeomAPI_Pnt2d;
33
34 class GeomDataAPI_Point2DArray;
35
36 /**\class SketchPlugin_MacroBSpline
37  * \ingroup Plugins
38  * \brief Feature for creation of the new B-spline in Sketch.
39  */
40 class SketchPlugin_MacroBSpline : public SketchPlugin_SketchEntity,
41                                   public GeomAPI_IPresentable
42 {
43 public:
44   /// B-spline macro feature kind
45   inline static const std::string& ID()
46   {
47     static const std::string ID("SketchMacroBSpline");
48     return ID;
49   }
50
51
52   /// list of B-spline poles
53   inline static const std::string& POLES_ID()
54   {
55     static const std::string ID("poles");
56     return ID;
57   }
58
59   /// list of references of B-spline poles
60   inline static const std::string& REF_POLES_ID()
61   {
62     static const std::string ID("poles_ref");
63     return ID;
64   }
65
66   /// list of B-spline weights
67   inline static const std::string& WEIGHTS_ID()
68   {
69     static const std::string ID("weights");
70     return ID;
71   }
72
73   /// flag attribute whether control polygon is need to be created
74   inline static const std::string& CONTROL_POLYGON_ID()
75   {
76     static const std::string ID("need_control_poly");
77     return ID;
78   }
79
80   /// Returns the kind of a feature
81   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
82   {
83     static std::string MY_KIND = SketchPlugin_MacroBSpline::ID();
84     return MY_KIND;
85   }
86
87   /// \brief Request for initialization of data model of the feature: adding all attributes.
88   SKETCHPLUGIN_EXPORT virtual void initAttributes();
89
90   /// Returns the AIS preview
91   virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
92
93   /// Creates a new part document if needed
94   SKETCHPLUGIN_EXPORT virtual void execute();
95
96   /// Reimplemented from ModelAPI_Feature::isMacro().
97   /// \returns true
98   SKETCHPLUGIN_EXPORT virtual bool isMacro() const {return true;};
99
100   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const {return false;};
101
102   /// Use plugin manager for features creation
103   SketchPlugin_MacroBSpline();
104
105 protected:
106   SketchPlugin_MacroBSpline(bool isPeriodic);
107
108 private:
109   FeaturePtr createBSplineFeature();
110
111   /// Create control polygon for the B-spline and returns the list of its poles
112   static void createControlPolygon(FeaturePtr theBSpline,
113                                    bool thePeriodic,
114                                    std::list<FeaturePtr>& thePoles);
115
116   /// Create additional coincidences if other features were selected while creating the B-spline
117   void constraintsForPoles(const std::list<FeaturePtr>& thePoles);
118
119   /// Create Point feature coincident with the B-spline pole
120   static FeaturePtr createAuxiliaryPole(std::shared_ptr<GeomDataAPI_Point2DArray> theBSplinePoles,
121                                         const int thePoleIndex);
122   /// Create segment between consequtive B-spline poles
123   static void createAuxiliarySegment(std::shared_ptr<GeomDataAPI_Point2DArray> theBSplinePoles,
124                                      const int thePoleIndex1,
125                                      const int thePoleIndex2);
126   /// Set name of auxiliary feature representing the control polygon
127   static void assignDefaultNameForAux(FeaturePtr theAuxFeature,
128                                       std::shared_ptr<GeomDataAPI_Point2DArray> theBSplinePoles,
129                                       const int thePoleIndex1,
130                                       const int thePoleIndex2 = -1);
131   friend class SketchPlugin_BSplineBase;
132   friend class SketchPlugin_CurveFitting;
133
134 private:
135   std::list<double> myKnots;
136   std::list<int> myMultiplicities;
137   int myDegree;
138   bool myIsPeriodic;
139 };
140
141
142 /**\class SketchPlugin_MacroBSplinePeriodic
143 * \ingroup Plugins
144 * \brief Feature for creation of the new periodic B-spline in Sketch.
145 */
146 class SketchPlugin_MacroBSplinePeriodic : public SketchPlugin_MacroBSpline
147 {
148 public:
149   /// B-spline macro feature kind
150   inline static const std::string& ID()
151   {
152     static const std::string ID("SketchMacroBSplinePeriodic");
153     return ID;
154   }
155
156   /// Returns the kind of a feature
157   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
158   {
159     return SketchPlugin_MacroBSplinePeriodic::ID();
160   }
161
162   /// Use plugin manager for features creation
163   SketchPlugin_MacroBSplinePeriodic() : SketchPlugin_MacroBSpline(true) {}
164 };
165
166 #endif