Salome HOME
d3333255335118a5b3319982d9b27482f65a3238
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_MacroBSpline.h
1 // Copyright (C) 2019-2020  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 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                                   public ModelAPI_IReentrant
43 {
44 public:
45   /// B-spline macro feature kind
46   inline static const std::string& ID()
47   {
48     static const std::string ID("SketchMacroBSpline");
49     return ID;
50   }
51
52
53   /// list of B-spline poles
54   inline static const std::string& POLES_ID()
55   {
56     static const std::string ID("poles");
57     return ID;
58   }
59
60   /// list of references of B-spline poles
61   inline static const std::string& REF_POLES_ID()
62   {
63     static const std::string ID("poles_ref");
64     return ID;
65   }
66
67   /// list of B-spline weights
68   inline static const std::string& WEIGHTS_ID()
69   {
70     static const std::string ID("weights");
71     return ID;
72   }
73
74   /// flag attribute whether control polygon is need to be created
75   inline static const std::string& CONTROL_POLYGON_ID()
76   {
77     static const std::string ID("need_control_poly");
78     return ID;
79   }
80
81   /// Returns the kind of a feature
82   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
83   {
84     static std::string MY_KIND = SketchPlugin_MacroBSpline::ID();
85     return MY_KIND;
86   }
87
88   /// \brief Request for initialization of data model of the feature: adding all attributes.
89   SKETCHPLUGIN_EXPORT virtual void initAttributes();
90
91   /// Returns the AIS preview
92   virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
93
94   /// Creates a new part document if needed
95   SKETCHPLUGIN_EXPORT virtual void execute();
96
97   /// Reimplemented from ModelAPI_Feature::isMacro().
98   /// \returns true
99   SKETCHPLUGIN_EXPORT virtual bool isMacro() const {return true;};
100
101   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const {return false;};
102
103   /// Apply information of the message to current object. It fills reference object,
104   /// tangent type and tangent point refence in case of tangent arc
105   virtual std::string processEvent(const std::shared_ptr<Events_Message>& theMessage);
106
107   /// Use plugin manager for features creation
108   SketchPlugin_MacroBSpline();
109
110 protected:
111   SketchPlugin_MacroBSpline(bool isPeriodic);
112
113 private:
114   FeaturePtr createBSplineFeature();
115
116   void createControlPolygon(FeaturePtr theBSpline, std::list<FeaturePtr>& thePoles);
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
133 private:
134   std::list<double> myKnots;
135   std::list<int> myMultiplicities;
136   int myDegree;
137   bool myIsPeriodic;
138 };
139
140
141 /**\class SketchPlugin_MacroBSpline
142 * \ingroup Plugins
143 * \brief Feature for creation of the new B-spline in Sketch.
144 */
145 class SketchPlugin_MacroBSplinePeriodic : public SketchPlugin_MacroBSpline
146 {
147 public:
148   /// B-spline macro feature kind
149   inline static const std::string& ID()
150   {
151     static const std::string ID("SketchMacroBSplinePeriodic");
152     return ID;
153   }
154
155   /// Returns the kind of a feature
156   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
157   {
158     return SketchPlugin_MacroBSpline::ID();
159   }
160
161   /// Use plugin manager for features creation
162   SketchPlugin_MacroBSplinePeriodic() : SketchPlugin_MacroBSpline(true) {}
163 };
164
165 #endif