Salome HOME
Merge branch 'BR_EDF_2018_Lot1'
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Measurement.h
1 // Copyright (C) 2018-20xx  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 FeaturesPlugin_Measurement_H_
22 #define FeaturesPlugin_Measurement_H_
23
24 #include "FeaturesPlugin.h"
25 #include <ModelAPI_Feature.h>
26
27 /// \class FeaturesPlugin_Measurement
28 /// \ingroup Plugins
29 /// \brief Feature for calculation metrics.
30 ///
31 /// Supported following metrics:
32 /// * length of edge,
33 /// * distance between shapes,
34 /// * radius of arc or cylindrical faces,
35 /// * angle between edges.
36 class FeaturesPlugin_Measurement : public ModelAPI_Feature
37 {
38 public:
39   /// Feature kind.
40   inline static const std::string& ID()
41   {
42     static const std::string MY_ID("Measurement");
43     return MY_ID;
44   }
45
46   /// \return the kind of a feature.
47   virtual const std::string& getKind()
48   {
49     return ID();
50   }
51
52   /// Attribute name for measurement method.
53   inline static const std::string& MEASURE_KIND()
54   {
55     static const std::string MY_MEASURE_KIND_ID("MeasureKind");
56     return MY_MEASURE_KIND_ID;
57   }
58
59   /// Attribute name for length measure.
60   inline static const std::string& MEASURE_LENGTH()
61   {
62     static const std::string MY_MEASURE_ID("Length");
63     return MY_MEASURE_ID;
64   }
65
66   /// Attribute name for distance measure.
67   inline static const std::string& MEASURE_DISTANCE()
68   {
69     static const std::string MY_MEASURE_ID("Distance");
70     return MY_MEASURE_ID;
71   }
72
73   /// Attribute name for radius measure.
74   inline static const std::string& MEASURE_RADIUS()
75   {
76     static const std::string MY_MEASURE_ID("Radius");
77     return MY_MEASURE_ID;
78   }
79
80   /// Attribute name for angle measure.
81   inline static const std::string& MEASURE_ANGLE()
82   {
83     static const std::string MY_MEASURE_ID("Angle");
84     return MY_MEASURE_ID;
85   }
86
87   /// Attribute name for angle measurement by 3 points.
88   inline static const std::string& MEASURE_ANGLE_POINTS()
89   {
90     static const std::string MY_MEASURE_ID("AngleBy3Points");
91     return MY_MEASURE_ID;
92   }
93
94
95   /// Attribute name of edge selected for length calculation.
96   inline static const std::string& EDGE_FOR_LENGTH_ID()
97   {
98     static const std::string MY_EDGE_FOR_LENGTH_ID("edge_for_length");
99     return MY_EDGE_FOR_LENGTH_ID;
100   }
101
102   /// Attribute name of first shape selected for distance calculation.
103   inline static const std::string& DISTANCE_FROM_OBJECT_ID()
104   {
105     static const std::string MY_DISTANCE_FROM_OBJECT_ID("distance_from");
106     return MY_DISTANCE_FROM_OBJECT_ID;
107   }
108
109   /// Attribute name of second shape selected for distance calculation.
110   inline static const std::string& DISTANCE_TO_OBJECT_ID()
111   {
112     static const std::string MY_DISTANCE_TO_OBJECT_ID("distance_to");
113     return MY_DISTANCE_TO_OBJECT_ID;
114   }
115
116   // Attribute name of edge or face selected to calculate radius.
117   inline static const std::string& CIRCULAR_OBJECT_ID()
118   {
119     static const std::string MY_CIRCULAR_OBJECT_ID("circular");
120     return MY_CIRCULAR_OBJECT_ID;
121   }
122
123   /// Attribute name of first edge selected for angle calculation.
124   inline static const std::string& ANGLE_FROM_EDGE_ID()
125   {
126     static const std::string MY_ANGLE_FROM_EDGE_ID("angle_from");
127     return MY_ANGLE_FROM_EDGE_ID;
128   }
129
130   /// Attribute name of second shape selected for angle calculation.
131   inline static const std::string& ANGLE_TO_EDGE_ID()
132   {
133     static const std::string MY_ANGLE_TO_EDGE_ID("angle_to");
134     return MY_ANGLE_TO_EDGE_ID;
135   }
136
137   /// Attribute name of first point selected for angle calculation.
138   inline static const std::string& ANGLE_POINT1_ID()
139   {
140     static const std::string MY_ANGLE_POINT1_ID("angle_point_1");
141     return MY_ANGLE_POINT1_ID;
142   }
143
144   /// Attribute name of second point (apex) selected for angle calculation.
145   inline static const std::string& ANGLE_POINT2_ID()
146   {
147     static const std::string MY_ANGLE_POINT2_ID("angle_point_2");
148     return MY_ANGLE_POINT2_ID;
149   }
150
151   /// Attribute name of third point selected for angle calculation.
152   inline static const std::string& ANGLE_POINT3_ID()
153   {
154     static const std::string MY_ANGLE_POINT3_ID("angle_point_3");
155     return MY_ANGLE_POINT3_ID;
156   }
157
158   /// Attribute name for result.
159   inline static const std::string& RESULT_ID()
160   {
161     static const std::string MY_RESULT_ID("result");
162     return MY_RESULT_ID;
163   }
164
165   /// Attribute name for values of result.
166   inline static const std::string& RESULT_VALUES_ID()
167   {
168     static const std::string MY_RESULT_VALUES_ID("result_values");
169     return MY_RESULT_VALUES_ID;
170   }
171
172   /// Creates a new part document if needed
173   FEATURESPLUGIN_EXPORT virtual void execute();
174
175   /// Request for initialization of data model of the feature: adding all attributes
176   FEATURESPLUGIN_EXPORT virtual void initAttributes();
177
178   /// Called on change of any argument-attribute of this object
179   /// \param theID identifier of changed attribute
180   FEATURESPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
181
182   /// Reimplemented from ModelAPI_Feature::isMacro(). Returns true.
183   virtual bool isMacro() const { return true; }
184
185   /// Use plugin manager for features creation
186   FeaturesPlugin_Measurement();
187
188 private:
189   /// Compute length of the edge
190   void computeLength();
191   /// Compute minimal distance between pair of shapes
192   void computeDistance();
193   /// Compute radius of circular edge or cylindrical face
194   void computeRadius();
195   /// Compute angle(s) between pair of edges if they are intersected
196   void computeAngle();
197   /// Compute angle by three points
198   void computeAngleByPoints();
199 };
200
201 #endif