Salome HOME
16b38caa3be45777bccb8aba716494e82d0f2c92
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Fillet.h
1 // Copyright (C) 2014-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 SketchPlugin_Fillet_H_
21 #define SketchPlugin_Fillet_H_
22
23 #include "SketchPlugin.h"
24
25 #include "SketchPlugin_SketchEntity.h"
26
27 #include <GeomAPI_IPresentable.h>
28 #include <GeomDataAPI_Point2D.h>
29
30 class GeomAPI_XY;
31
32 /// \class SketchPlugin_Fillet
33 /// \ingroup Plugins
34 /// \brief Feature for creation of a new arc filleting two objects which have
35 /// coincident point.
36 class SketchPlugin_Fillet: public SketchPlugin_SketchEntity, public GeomAPI_IPresentable
37 {
38  public:
39   /// Feature kind.
40   inline static const std::string& ID()
41   {
42     static const std::string MY_FEATURE_ID("SketchFillet");
43     return MY_FEATURE_ID;
44   }
45
46   /// Attribute name of fillet point.
47   inline static const std::string& FILLET_POINT_ID()
48   {
49     static const std::string ID("fillet_point");
50     return ID;
51   }
52
53   /// \return the kind of a feature.
54   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
55   {
56     static std::string MY_KIND = SketchPlugin_Fillet::ID();
57     return MY_KIND;
58   }
59
60   /// \brief Creates a new part document if needed.
61   SKETCHPLUGIN_EXPORT virtual void execute();
62
63   /// \brief Request for initialization of data model of the feature: adding all attributes.
64   SKETCHPLUGIN_EXPORT virtual void initAttributes();
65
66   /// Returns the AIS preview
67   SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
68
69   /// Reimplemented from ModelAPI_Feature::isMacro().
70   /// \returns true
71   SKETCHPLUGIN_EXPORT virtual bool isMacro() const {return true;}
72
73   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const {return false;}
74
75   /// Reimplemented from SketchPlugin_Feature::move().
76   /// Do nothing.
77   SKETCHPLUGIN_EXPORT virtual void move(const double, const double) {}
78
79   /// \brief Use plugin manager for features creation
80   SketchPlugin_Fillet();
81
82 private:
83   bool calculateFilletParameters();
84
85   /// Create new feature presenting a fillet arc and initialize its parameters
86   FeaturePtr createFilletArc();
87
88   /// Create point representing fillet apex and additional coincidences with fillet features
89   FeaturePtr createFilletApex(const std::shared_ptr<GeomAPI_Pnt2d>& theCoordinates);
90
91   /// Remove references to a feature participating in fillet,
92   /// but transfer "distance" constraints to features after fillet
93   /// \param[in, out] theFeaturesToRemove  features referred to fillet edges
94   ///                 (all distances will be processed and removed from this list)
95   /// \param[in]      theFilletPoints      fillet points from participating features
96   void  removeReferencesButKeepDistances(std::set<FeaturePtr>& theFeaturesToRemove,
97                                          const AttributePoint2DPtr theFilletPoints[2]);
98
99   bool findFeaturesContainingFilletPoint(std::shared_ptr<GeomDataAPI_Point2D> theFilletPoint);
100
101 private:
102     FeaturePtr myBaseFeatures[2];
103     std::string myFeatAttributes[4]; // attributes of features
104     bool myIsReversed;
105     bool myIsNotInversed[2]; // indicates which point the features share
106     bool myFilletCreated;
107     std::shared_ptr<GeomAPI_XY> myCenterXY;
108     std::shared_ptr<GeomAPI_XY> myTangentXY1;
109     std::shared_ptr<GeomAPI_XY> myTangentXY2;
110 };
111
112 #endif