Salome HOME
bd083d6bd23e724474e161700aa0eb9a0ae7c0b2
[modules/shaper.git] / src / BuildPlugin / BuildPlugin_Filling.h
1 // Copyright (C) 2014-2021  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 BuildPlugin_Filling_H_
21 #define BuildPlugin_Filling_H_
22
23 #include "BuildPlugin.h"
24
25 #include <ModelAPI_Feature.h>
26
27 #include <memory>
28 #include <string>
29
30 class GeomAlgoAPI_MakeShape;
31 class GeomAPI_Edge;
32 class GeomAPI_Pnt;
33 class GeomAPI_Shape;
34
35 /// \class BuildPlugin_Filling
36 /// \ingroup Plugins
37 /// \brief Feature for creation of face from list of edges (1D objects).
38 class BuildPlugin_Filling: public ModelAPI_Feature
39 {
40 public:
41   /// Use plugin manager for features creation
42   BuildPlugin_Filling();
43
44   /// Feature kind.
45   inline static const std::string& ID()
46   {
47     static const std::string MY_ID("Filling");
48     return MY_ID;
49   }
50
51   /// \return the kind of a feature.
52   BUILDPLUGIN_EXPORT virtual const std::string& getKind()
53   {
54     static std::string MY_KIND = BuildPlugin_Filling::ID();
55     return MY_KIND;
56   }
57
58   /// Attribute name of base objects.
59   inline static const std::string& BASE_OBJECTS_ID()
60   {
61     static const std::string MY_BASE_OBJECTS_ID("base_objects");
62     return MY_BASE_OBJECTS_ID;
63   }
64
65   /// Attribute name of advanced options.
66   inline static const std::string& ADVANCED_OPTIONS_ID()
67   {
68     static const std::string MY_ADVANCED_OPTIONS_ID("advanced_options");
69     return MY_ADVANCED_OPTIONS_ID;
70   }
71
72   /// Attribute name of method of edge orientation.
73   inline static const std::string& METHOD_ID()
74   {
75     static const std::string MY_METHOD_ID("orientation");
76     return MY_METHOD_ID;
77   }
78
79   /// Supported methods for edge orientation correction
80   struct Method {
81     inline static const std::string& AUTO_CORRECT_ORIENTATION()
82     {
83       static const std::string MY_AUTO_CORRECT_ORIENTATION("auto_correct");
84       return MY_AUTO_CORRECT_ORIENTATION;
85     }
86     inline static const std::string& USE_CURVE_INFORMATION()
87     {
88       static const std::string MY_USE_CURVE_INFORMATION("curve_info");
89       return MY_USE_CURVE_INFORMATION;
90     }
91     inline static const std::string& USE_EDGES_ORIENTATION()
92     {
93       static const std::string MY_USE_EDGES_ORIENTATION("edge_orient");
94       return MY_USE_EDGES_ORIENTATION;
95     }
96   };
97
98   /// Attribute name of minimal degree.
99   inline static const std::string& MINIMAL_DEGREE_ID()
100   {
101     static const std::string MY_MINIMAL_DEGREE_ID("min_degree");
102     return MY_MINIMAL_DEGREE_ID;
103   }
104
105   /// Attribute name of maximal degree.
106   inline static const std::string& MAXIMAL_DEGREE_ID()
107   {
108     static const std::string MY_MAXIMAL_DEGREE_ID("max_degree");
109     return MY_MAXIMAL_DEGREE_ID;
110   }
111
112   /// Attribute name of number of iterations.
113   inline static const std::string& NUMBER_OF_ITERATIONS_ID()
114   {
115     static const std::string MY_NUMBER_OF_ITERATIONS_ID("nb_iter");
116     return MY_NUMBER_OF_ITERATIONS_ID;
117   }
118
119   /// Attribute name of 2D tolerance.
120   inline static const std::string& TOLERANCE_2D_ID()
121   {
122     static const std::string MY_TOLERANCE_2D_ID("tol_2d");
123     return MY_TOLERANCE_2D_ID;
124   }
125
126   /// Attribute name of 3D tolerance.
127   inline static const std::string& TOLERANCE_3D_ID()
128   {
129     static const std::string MY_TOLERANCE_3D_ID("tol_3d");
130     return MY_TOLERANCE_3D_ID;
131   }
132
133   /// Attribute name of approximation.
134   inline static const std::string& APPROXIMATION_ID()
135   {
136     static const std::string MY_APPROXIMATION_ID("approximation");
137     return MY_APPROXIMATION_ID;
138   }
139
140   /// Default value of the orientation
141   inline static const std::string& METHOD_DEFAULT() { return Method::AUTO_CORRECT_ORIENTATION(); }
142   /// Default value of minimal degree
143   inline static int MINIMAL_DEGREE_DEFAULT() { return 2; }
144   /// Default value of maximal degree
145   inline static int MAXIMAL_DEGREE_DEFAULT() { return 5; }
146   /// Default value of number of iterations
147   inline static int NUMBER_OF_ITERATIONS_DEFAULT() { return 0; }
148   /// Default value of 2D tolerance
149   inline static double TOLERANCE_2D_DEFAULT() { return 1.e-4; }
150   /// Default value of 3D tolerance
151   inline static double TOLERANCE_3D_DEFAULT() { return 1.e-4; }
152   /// Default value of the approximation attribute
153   inline static bool APPROXIMATION_DEFAULT() { return false; }
154
155   /// Request for initialization of data model of the feature: adding all attributes.
156   BUILDPLUGIN_EXPORT virtual void initAttributes();
157
158   /// Creates a new part document if needed.
159   BUILDPLUGIN_EXPORT virtual void execute();
160
161   /// Called on change of any argument-attribute of this object.
162   /// \param[in] theID identifier of changed attribute.
163   BUILDPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
164
165 private:
166   /// Convert shape to edge according to construction method
167   std::shared_ptr<GeomAPI_Edge> toEdge(const std::shared_ptr<GeomAPI_Shape>& theShape,
168                                        const std::string& theMethod);
169
170   /// Update values of attributes by their default values
171   void restoreDefaultParameters();
172
173 private:
174   std::shared_ptr<GeomAPI_Edge> myLastEdge;
175 };
176
177 #endif