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