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