Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchAPI / SketchAPI_BSpline.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 SketchAPI_BSpline_H_
21 #define SketchAPI_BSpline_H_
22
23 #include "SketchAPI.h"
24 #include "SketchAPI_SketchEntity.h"
25
26 #include <GeomDataAPI_Point2DArray.h>
27
28 #include <ModelAPI_AttributeDoubleArray.h>
29
30 #include <SketchPlugin_BSpline.h>
31 #include <SketchPlugin_BSplinePeriodic.h>
32
33 #include <ModelHighAPI_Double.h>
34 #include <ModelHighAPI_Integer.h>
35
36 class ModelHighAPI_Selection;
37
38 /// \class SketchAPI_BSpline
39 /// \ingroup CPPHighAPI
40 /// \brief Interface for BSpline feature.
41 class SketchAPI_BSpline : public SketchAPI_SketchEntity
42 {
43 public:
44   /// Constructor without values.
45   SKETCHAPI_EXPORT
46   explicit SketchAPI_BSpline(const std::shared_ptr<ModelAPI_Feature>& theFeature);
47
48   /// Destructor.
49   SKETCHAPI_EXPORT
50   virtual ~SketchAPI_BSpline();
51
52   INTERFACE_8(SketchPlugin_BSpline::ID(),
53               poles, SketchPlugin_BSplineBase::POLES_ID(),
54               GeomDataAPI_Point2DArray, /** B-spline poles */,
55               weights, SketchPlugin_BSplineBase::WEIGHTS_ID(),
56               ModelAPI_AttributeDoubleArray, /** B-spline weights */,
57               knots, SketchPlugin_BSplineBase::KNOTS_ID(),
58               ModelAPI_AttributeDoubleArray, /** B-spline knots */,
59               multiplicities, SketchPlugin_BSplineBase::MULTS_ID(),
60               ModelAPI_AttributeIntArray, /** Knots multiplicities */,
61               degree, SketchPlugin_BSplineBase::DEGREE_ID(),
62               ModelAPI_AttributeInteger, /** B-spline degree */,
63               startPoint, SketchPlugin_BSpline::START_ID(),
64               GeomDataAPI_Point2D, /** First pole of B-spline */,
65               endPoint, SketchPlugin_BSpline::END_ID(),
66               GeomDataAPI_Point2D, /** Last pole of B-spline */,
67               external, SketchPlugin_BSplineBase::EXTERNAL_ID(),
68               ModelAPI_AttributeSelection, /** External */)
69
70   /// Set by poles and weights.
71   SKETCHAPI_EXPORT
72   void setByDegreePolesAndWeights(const ModelHighAPI_Integer& theDegree,
73                                   const std::list<std::shared_ptr<GeomAPI_Pnt2d> >& thePoles,
74                                   const std::list<ModelHighAPI_Double>& theWeights);
75
76   /// Initialize by full set of B-spline parameters.
77   SKETCHAPI_EXPORT
78   void setByParameters(const ModelHighAPI_Integer& theDegree,
79                        const std::list<std::shared_ptr<GeomAPI_Pnt2d> >& thePoles,
80                        const std::list<ModelHighAPI_Double>& theWeights,
81                        const std::list<ModelHighAPI_Double>& theKnots,
82                        const std::list<ModelHighAPI_Integer>& theMults);
83
84   /// Set by external.
85   SKETCHAPI_EXPORT
86   void setByExternal(const ModelHighAPI_Selection& theExternal);
87
88   /// Generate list of construction points coincident with B-spline poles
89   SKETCHAPI_EXPORT
90   std::list<std::shared_ptr<SketchAPI_SketchEntity> > controlPoles(
91       const std::list<int>& regular   = std::list<int>(),
92       const std::list<int>& auxiliary = std::list<int>()) const;
93
94   /// Generate control polygon for B-spline curve
95   SKETCHAPI_EXPORT
96   std::list<std::shared_ptr<SketchAPI_SketchEntity> > controlPolygon(
97       const std::list<int>& regular   = std::list<int>(),
98       const std::list<int>& auxiliary = std::list<int>()) const;
99
100   /// Insert new pole after the pole with the given index
101   SKETCHAPI_EXPORT
102   bool insertPole(const int theIndex,
103                   const std::shared_ptr<GeomAPI_Pnt2d>& theCoordinates,
104                   const ModelHighAPI_Double& theWeight = ModelHighAPI_Double(1.0));
105
106   /// Dump wrapped feature
107   SKETCHAPI_EXPORT
108   virtual void dump(ModelHighAPI_Dumper& theDumper) const;
109
110 protected:
111   SketchAPI_BSpline(const std::shared_ptr<ModelAPI_Feature>& theFeature, bool theInitialize);
112
113 private:
114   /// Initialize start and end points of B-spline and apply internal coincidence
115   /// constraint to keep them on the corresponding pole.
116   void setStartAndEndPoints();
117
118   /// Compute default B-spline parameters (degree, knots and multiplicities)
119   /// basing on hte given poles and weights
120   void getDefaultParameters(const std::list<std::shared_ptr<GeomAPI_Pnt2d> >& thePoles,
121                             const std::list<ModelHighAPI_Double>& theWeights,
122                             ModelHighAPI_Integer& theDegree,
123                             std::list<ModelHighAPI_Double>& theKnots,
124                             std::list<ModelHighAPI_Integer>& theMults) const;
125
126   /// Check what parameters of B-spline are default
127   void checkDefaultParameters(bool& isDefaultDegree,
128                               bool& isDefaultWeights,
129                               bool& isDefaultKnotsMults) const;
130
131   void dumpControlPolygon(ModelHighAPI_Dumper& theDumper,
132                           const FeaturePtr& theBSpline,
133                           const std::string& theMethod,
134                           const std::map<int, FeaturePtr>& theAuxFeatures) const;
135 };
136
137 /// Pointer on B-spline object.
138 typedef std::shared_ptr<SketchAPI_BSpline> BSplinePtr;
139
140
141
142 /// \class SketchAPI_BSplinePeriodic
143 /// \ingroup CPPHighAPI
144 /// \brief Interface for BSplinePeriodic feature.
145 class SketchAPI_BSplinePeriodic : public SketchAPI_BSpline
146 {
147 public:
148   /// Constructor without values.
149   SKETCHAPI_EXPORT
150   explicit SketchAPI_BSplinePeriodic(const std::shared_ptr<ModelAPI_Feature>& theFeature);
151
152   /// Destructor.
153   SKETCHAPI_EXPORT
154   virtual ~SketchAPI_BSplinePeriodic() {}
155
156   static std::string ID() { return SketchPlugin_BSplinePeriodic::ID(); }
157   virtual std::string getID() { return SketchPlugin_BSplinePeriodic::ID(); }
158 };
159
160 #endif // SketchAPI_BSpline_H_