1 // Copyright (C) 2019-2023 CEA, EDF
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 SketchPlugin_MacroBSpline_H_
21 #define SketchPlugin_MacroBSpline_H_
23 #include <ModelAPI_IReentrant.h>
25 #include "SketchPlugin.h"
27 #include "SketchPlugin_SketchEntity.h"
29 #include <GeomAPI_IPresentable.h>
34 class GeomDataAPI_Point2DArray;
36 /**\class SketchPlugin_MacroBSpline
38 * \brief Feature for creation of the new B-spline in Sketch.
40 class SketchPlugin_MacroBSpline : public SketchPlugin_SketchEntity,
41 public GeomAPI_IPresentable
44 /// B-spline macro feature kind
45 inline static const std::string& ID()
47 static const std::string ID("SketchMacroBSpline");
52 /// list of B-spline poles
53 inline static const std::string& POLES_ID()
55 static const std::string ID("poles");
59 /// list of references of B-spline poles
60 inline static const std::string& REF_POLES_ID()
62 static const std::string ID("poles_ref");
66 /// list of B-spline weights
67 inline static const std::string& WEIGHTS_ID()
69 static const std::string ID("weights");
73 /// flag attribute whether control polygon is need to be created
74 inline static const std::string& CONTROL_POLYGON_ID()
76 static const std::string ID("need_control_poly");
80 /// Returns the kind of a feature
81 SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
83 static std::string MY_KIND = SketchPlugin_MacroBSpline::ID();
87 /// \brief Request for initialization of data model of the feature: adding all attributes.
88 SKETCHPLUGIN_EXPORT virtual void initAttributes();
90 /// Returns the AIS preview
91 virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
93 /// Creates a new part document if needed
94 SKETCHPLUGIN_EXPORT virtual void execute();
96 /// Reimplemented from ModelAPI_Feature::isMacro().
98 SKETCHPLUGIN_EXPORT virtual bool isMacro() const {return true;};
100 SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const {return false;};
102 /// Use plugin manager for features creation
103 SketchPlugin_MacroBSpline();
106 SketchPlugin_MacroBSpline(bool isPeriodic);
109 FeaturePtr createBSplineFeature();
111 /// Create control polygon for the B-spline and returns the list of its poles
112 static void createControlPolygon(FeaturePtr theBSpline,
114 std::list<FeaturePtr>& thePoles);
116 /// Create additional coincidences if other features were selected while creating the B-spline
117 void constraintsForPoles(const std::list<FeaturePtr>& thePoles);
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 friend class SketchPlugin_CurveFitting;
135 std::list<double> myKnots;
136 std::list<int> myMultiplicities;
142 /**\class SketchPlugin_MacroBSplinePeriodic
144 * \brief Feature for creation of the new periodic B-spline in Sketch.
146 class SketchPlugin_MacroBSplinePeriodic : public SketchPlugin_MacroBSpline
149 /// B-spline macro feature kind
150 inline static const std::string& ID()
152 static const std::string ID("SketchMacroBSplinePeriodic");
156 /// Returns the kind of a feature
157 SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
159 return SketchPlugin_MacroBSplinePeriodic::ID();
162 /// Use plugin manager for features creation
163 SketchPlugin_MacroBSplinePeriodic() : SketchPlugin_MacroBSpline(true) {}