1 // Copyright (C) 2019-2020 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef SketchAPI_BSpline_H_
21 #define SketchAPI_BSpline_H_
23 #include "SketchAPI.h"
24 #include "SketchAPI_SketchEntity.h"
26 #include <GeomDataAPI_Point2DArray.h>
28 #include <ModelAPI_AttributeDoubleArray.h>
30 #include <SketchPlugin_BSpline.h>
31 #include <SketchPlugin_BSplinePeriodic.h>
33 #include <ModelHighAPI_Double.h>
34 #include <ModelHighAPI_Integer.h>
36 class ModelHighAPI_Selection;
38 /// \class SketchAPI_BSpline
39 /// \ingroup CPPHighAPI
40 /// \brief Interface for BSpline feature.
41 class SketchAPI_BSpline : public SketchAPI_SketchEntity
44 /// Constructor without values.
46 explicit SketchAPI_BSpline(const std::shared_ptr<ModelAPI_Feature>& theFeature);
50 virtual ~SketchAPI_BSpline();
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 */)
70 /// Set by poles and weights.
72 void setByDegreePolesAndWeights(const ModelHighAPI_Integer& theDegree,
73 const std::list<std::shared_ptr<GeomAPI_Pnt2d> >& thePoles,
74 const std::list<ModelHighAPI_Double>& theWeights);
76 /// Initialize by full set of B-spline parameters.
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);
86 void setByExternal(const ModelHighAPI_Selection& theExternal);
88 /// Generate list of construction points coincident with B-spline poles
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;
94 /// Generate control polygon for B-spline curve
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;
100 /// Insert new pole after the pole with the given index
102 bool insertPole(const int theIndex,
103 const std::shared_ptr<GeomAPI_Pnt2d>& theCoordinates,
104 const ModelHighAPI_Double& theWeight = ModelHighAPI_Double(1.0));
106 /// Dump wrapped feature
108 virtual void dump(ModelHighAPI_Dumper& theDumper) const;
111 SketchAPI_BSpline(const std::shared_ptr<ModelAPI_Feature>& theFeature, bool theInitialize);
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();
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;
126 /// Check what parameters of B-spline are default
127 void checkDefaultParameters(bool& isDefaultDegree,
128 bool& isDefaultWeights,
129 bool& isDefaultKnotsMults) const;
131 void dumpControlPolygon(ModelHighAPI_Dumper& theDumper,
132 const FeaturePtr& theBSpline,
133 const std::string& theMethod,
134 const std::map<int, FeaturePtr>& theAuxFeatures) const;
137 /// Pointer on B-spline object.
138 typedef std::shared_ptr<SketchAPI_BSpline> BSplinePtr;
142 /// \class SketchAPI_BSplinePeriodic
143 /// \ingroup CPPHighAPI
144 /// \brief Interface for BSplinePeriodic feature.
145 class SketchAPI_BSplinePeriodic : public SketchAPI_BSpline
148 /// Constructor without values.
150 explicit SketchAPI_BSplinePeriodic(const std::shared_ptr<ModelAPI_Feature>& theFeature);
154 virtual ~SketchAPI_BSplinePeriodic() {}
156 static std::string ID() { return SketchPlugin_BSplinePeriodic::ID(); }
157 virtual std::string getID() { return SketchPlugin_BSplinePeriodic::ID(); }
160 #endif // SketchAPI_BSpline_H_