Salome HOME
Merge remote-tracking branch 'remotes/origin/occ/bsplines'
[modules/shaper.git] / src / SketchAPI / SketchAPI_BSpline.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 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   /// Dump wrapped feature
101   SKETCHAPI_EXPORT
102   virtual void dump(ModelHighAPI_Dumper& theDumper) const;
103
104 protected:
105   SketchAPI_BSpline(const std::shared_ptr<ModelAPI_Feature>& theFeature, bool theInitialize);
106
107 private:
108   /// Initialize start and end points of B-spline and apply internal coincidence
109   /// constraint to keep them on the corresponding pole.
110   void setStartAndEndPoints();
111
112   /// Compute default B-spline parameters (degree, knots and multiplicities)
113   /// basing on hte given poles and weights
114   void getDefaultParameters(const std::list<std::shared_ptr<GeomAPI_Pnt2d> >& thePoles,
115                             const std::list<ModelHighAPI_Double>& theWeights,
116                             ModelHighAPI_Integer& theDegree,
117                             std::list<ModelHighAPI_Double>& theKnots,
118                             std::list<ModelHighAPI_Integer>& theMults) const;
119
120   /// Check what parameters of B-spline are default
121   void checkDefaultParameters(bool& isDefaultDegree,
122                               bool& isDefaultWeights,
123                               bool& isDefaultKnotsMults) const;
124
125   void dumpControlPolygon(ModelHighAPI_Dumper& theDumper,
126                           const FeaturePtr& theBSpline,
127                           const std::string& theMethod,
128                           const std::map<int, FeaturePtr>& theAuxFeatures) const;
129 };
130
131 /// Pointer on B-spline object.
132 typedef std::shared_ptr<SketchAPI_BSpline> BSplinePtr;
133
134
135
136 /// \class SketchAPI_BSplinePeriodic
137 /// \ingroup CPPHighAPI
138 /// \brief Interface for BSplinePeriodic feature.
139 class SketchAPI_BSplinePeriodic : public SketchAPI_BSpline
140 {
141 public:
142   /// Constructor without values.
143   SKETCHAPI_EXPORT
144   explicit SketchAPI_BSplinePeriodic(const std::shared_ptr<ModelAPI_Feature>& theFeature);
145
146   /// Destructor.
147   SKETCHAPI_EXPORT
148   virtual ~SketchAPI_BSplinePeriodic() {}
149
150   static std::string ID() { return SketchPlugin_BSplinePeriodic::ID(); }
151   virtual std::string getID() { return SketchPlugin_BSplinePeriodic::ID(); }
152 };
153
154 #endif // SketchAPI_BSpline_H_