Salome HOME
Updated copyright comment
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Measurement.h
1 // Copyright (C) 2018-2024  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 FeaturesPlugin_Measurement_H_
21 #define FeaturesPlugin_Measurement_H_
22
23 #include "FeaturesPlugin.h"
24 #include <ModelAPI_Feature.h>
25
26 #include <GeomAPI_IPresentable.h>
27 #include <GeomAPI_IScreenParams.h>
28
29 /// \class FeaturesPlugin_Measurement
30 /// \ingroup Plugins
31 /// \brief Feature for calculation metrics.
32 ///
33 /// Supported following metrics:
34 /// * length of edge,
35 /// * distance between shapes,
36 /// * radius of arc or cylindrical faces,
37 /// * angle between edges.
38 class FeaturesPlugin_Measurement : public ModelAPI_Feature,
39   public GeomAPI_IPresentable,
40   public GeomAPI_IScreenParams
41 {
42 public:
43   /// Feature kind.
44   inline static const std::string& ID()
45   {
46     static const std::string MY_ID("Measurement");
47     return MY_ID;
48   }
49
50   /// \return the kind of a feature.
51   virtual const std::string& getKind()
52   {
53     return ID();
54   }
55
56   /// Attribute name for measurement method.
57   inline static const std::string& MEASURE_KIND()
58   {
59     static const std::string MY_MEASURE_KIND_ID("MeasureKind");
60     return MY_MEASURE_KIND_ID;
61   }
62
63   /// Attribute name for length measure.
64   inline static const std::string& MEASURE_LENGTH()
65   {
66     static const std::string MY_MEASURE_ID("Length");
67     return MY_MEASURE_ID;
68   }
69
70   /// Attribute name for distance measure.
71   inline static const std::string& MEASURE_DISTANCE()
72   {
73     static const std::string MY_MEASURE_ID("Distance");
74     return MY_MEASURE_ID;
75   }
76
77   /// Attribute name for distance measure.
78   inline static const std::string& MEASURE_PROXIMITY()
79   {
80     static const std::string MY_MEASURE_ID("Proximity");
81     return MY_MEASURE_ID;
82   }
83
84   /// Attribute name for radius measure.
85   inline static const std::string& MEASURE_RADIUS()
86   {
87     static const std::string MY_MEASURE_ID("Radius");
88     return MY_MEASURE_ID;
89   }
90
91   /// Attribute name for angle measure.
92   inline static const std::string& MEASURE_ANGLE()
93   {
94     static const std::string MY_MEASURE_ID("Angle");
95     return MY_MEASURE_ID;
96   }
97
98   /// Attribute name for angle measurement by 3 points.
99   inline static const std::string& MEASURE_ANGLE_POINTS()
100   {
101     static const std::string MY_MEASURE_ID("AngleBy3Points");
102     return MY_MEASURE_ID;
103   }
104
105
106   /// Attribute name of edge selected for length calculation.
107   inline static const std::string& EDGE_FOR_LENGTH_ID()
108   {
109     static const std::string MY_EDGE_FOR_LENGTH_ID("edge_for_length");
110     return MY_EDGE_FOR_LENGTH_ID;
111   }
112
113   /// Attribute name of first shape selected for distance calculation.
114   inline static const std::string& DISTANCE_FROM_OBJECT_ID()
115   {
116     static const std::string MY_DISTANCE_FROM_OBJECT_ID("distance_from");
117     return MY_DISTANCE_FROM_OBJECT_ID;
118   }
119
120   /// Attribute name of second shape selected for distance calculation.
121   inline static const std::string& DISTANCE_TO_OBJECT_ID()
122   {
123     static const std::string MY_DISTANCE_TO_OBJECT_ID("distance_to");
124     return MY_DISTANCE_TO_OBJECT_ID;
125   }
126
127   // Attribute name of edge or face selected to calculate radius.
128   inline static const std::string& CIRCULAR_OBJECT_ID()
129   {
130     static const std::string MY_CIRCULAR_OBJECT_ID("circular");
131     return MY_CIRCULAR_OBJECT_ID;
132   }
133
134   /// Attribute name of first edge selected for angle calculation.
135   inline static const std::string& ANGLE_FROM_EDGE_ID()
136   {
137     static const std::string MY_ANGLE_FROM_EDGE_ID("angle_from");
138     return MY_ANGLE_FROM_EDGE_ID;
139   }
140
141   /// Attribute name of second shape selected for angle calculation.
142   inline static const std::string& ANGLE_TO_EDGE_ID()
143   {
144     static const std::string MY_ANGLE_TO_EDGE_ID("angle_to");
145     return MY_ANGLE_TO_EDGE_ID;
146   }
147
148   /// Attribute name of first point selected for angle calculation.
149   inline static const std::string& ANGLE_POINT1_ID()
150   {
151     static const std::string MY_ANGLE_POINT1_ID("angle_point_1");
152     return MY_ANGLE_POINT1_ID;
153   }
154
155   /// Attribute name of second point (apex) selected for angle calculation.
156   inline static const std::string& ANGLE_POINT2_ID()
157   {
158     static const std::string MY_ANGLE_POINT2_ID("angle_point_2");
159     return MY_ANGLE_POINT2_ID;
160   }
161
162   /// Attribute name of third point selected for angle calculation.
163   inline static const std::string& ANGLE_POINT3_ID()
164   {
165     static const std::string MY_ANGLE_POINT3_ID("angle_point_3");
166     return MY_ANGLE_POINT3_ID;
167   }
168
169   /// Attribute name for result.
170   inline static const std::string& RESULT_ID()
171   {
172     static const std::string MY_RESULT_ID("result");
173     return MY_RESULT_ID;
174   }
175
176   /// Attribute name for values of result.
177   inline static const std::string& RESULT_VALUES_ID()
178   {
179     static const std::string MY_RESULT_VALUES_ID("result_values");
180     return MY_RESULT_VALUES_ID;
181   }
182
183   /// Performs the algorithm and stores results it in the data structure.
184   FEATURESPLUGIN_EXPORT virtual void execute();
185
186   /// Request for initialization of data model of the feature: adding all attributes
187   FEATURESPLUGIN_EXPORT virtual void initAttributes();
188
189   /// Called on change of any argument-attribute of this object
190   /// \param theID identifier of changed attribute
191   FEATURESPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
192
193   /// Reimplemented from ModelAPI_Feature::isMacro(). Returns true.
194   virtual bool isMacro() const { return true; }
195
196   /** Returns the AIS preview
197   *   \param thePrevious - defines a presentation if it was created previously
198   */
199   FEATURESPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
200
201   /// Set current screen plane
202   /// \param theScreenPlane the screen plane
203   virtual void setScreenPlane(GeomPlanePtr theScreenPlane) {
204     myScreenPlane = theScreenPlane;
205   }
206
207   /// Set current view scale
208   /// \param theScale the view scale
209   virtual void setViewScale(double theScale) {
210     mySceenScale = theScale;
211   }
212
213   /// Use plugin manager for features creation
214   FeaturesPlugin_Measurement();
215
216 private:
217   /// Compute length of the edge
218   void computeLength();
219   /// Compute minimal distance between pair of shapes
220   void computeDistance();
221   /// Compute proximity (maximum of all minimal distances between pair of shapes)
222   void computeProximity();
223   /// Compute radius of circular edge, cylindrical surface or sphere.
224   void computeRadius();
225   /// Compute angle(s) between pair of edges if they are intersected
226   void computeAngle();
227   /// Compute angle by three points
228   void computeAngleByPoints();
229
230   /// Create length dimension presentation
231   /// \param thePrevious previous version of presentation
232   AISObjectPtr lengthDimension(AISObjectPtr thePrevious);
233
234   /// Create distance dimension presentation
235   /// \param thePrevious previous version of presentation
236   AISObjectPtr distanceDimension(AISObjectPtr thePrevious);
237
238   /// Create radius dimension presentation
239   /// \param thePrevious previous version of presentation
240   AISObjectPtr radiusDimension(AISObjectPtr thePrevious);
241
242   /// Create angle dimension presentation
243   /// \param thePrevious previous version of presentation
244   AISObjectPtr angleDimension(AISObjectPtr thePrevious);
245
246   /// Create angle by points dimension presentation
247   /// \param thePrevious previous version of presentation
248   AISObjectPtr angleByPointsDimension(AISObjectPtr thePrevious);
249
250   /// Set dimension presentation parameters
251   void setupDimension(AISObjectPtr theDim);
252
253   GeomPlanePtr myScreenPlane; //< a plane of current screen
254   double mySceenScale; //< a scale of current view
255 };
256
257 #endif