Salome HOME
Copyright update 2022
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Measurement.h
1 // Copyright (C) 2018-2022  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 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 radius measure.
78   inline static const std::string& MEASURE_RADIUS()
79   {
80     static const std::string MY_MEASURE_ID("Radius");
81     return MY_MEASURE_ID;
82   }
83
84   /// Attribute name for angle measure.
85   inline static const std::string& MEASURE_ANGLE()
86   {
87     static const std::string MY_MEASURE_ID("Angle");
88     return MY_MEASURE_ID;
89   }
90
91   /// Attribute name for angle measurement by 3 points.
92   inline static const std::string& MEASURE_ANGLE_POINTS()
93   {
94     static const std::string MY_MEASURE_ID("AngleBy3Points");
95     return MY_MEASURE_ID;
96   }
97
98
99   /// Attribute name of edge selected for length calculation.
100   inline static const std::string& EDGE_FOR_LENGTH_ID()
101   {
102     static const std::string MY_EDGE_FOR_LENGTH_ID("edge_for_length");
103     return MY_EDGE_FOR_LENGTH_ID;
104   }
105
106   /// Attribute name of first shape selected for distance calculation.
107   inline static const std::string& DISTANCE_FROM_OBJECT_ID()
108   {
109     static const std::string MY_DISTANCE_FROM_OBJECT_ID("distance_from");
110     return MY_DISTANCE_FROM_OBJECT_ID;
111   }
112
113   /// Attribute name of second shape selected for distance calculation.
114   inline static const std::string& DISTANCE_TO_OBJECT_ID()
115   {
116     static const std::string MY_DISTANCE_TO_OBJECT_ID("distance_to");
117     return MY_DISTANCE_TO_OBJECT_ID;
118   }
119
120   // Attribute name of edge or face selected to calculate radius.
121   inline static const std::string& CIRCULAR_OBJECT_ID()
122   {
123     static const std::string MY_CIRCULAR_OBJECT_ID("circular");
124     return MY_CIRCULAR_OBJECT_ID;
125   }
126
127   /// Attribute name of first edge selected for angle calculation.
128   inline static const std::string& ANGLE_FROM_EDGE_ID()
129   {
130     static const std::string MY_ANGLE_FROM_EDGE_ID("angle_from");
131     return MY_ANGLE_FROM_EDGE_ID;
132   }
133
134   /// Attribute name of second shape selected for angle calculation.
135   inline static const std::string& ANGLE_TO_EDGE_ID()
136   {
137     static const std::string MY_ANGLE_TO_EDGE_ID("angle_to");
138     return MY_ANGLE_TO_EDGE_ID;
139   }
140
141   /// Attribute name of first point selected for angle calculation.
142   inline static const std::string& ANGLE_POINT1_ID()
143   {
144     static const std::string MY_ANGLE_POINT1_ID("angle_point_1");
145     return MY_ANGLE_POINT1_ID;
146   }
147
148   /// Attribute name of second point (apex) selected for angle calculation.
149   inline static const std::string& ANGLE_POINT2_ID()
150   {
151     static const std::string MY_ANGLE_POINT2_ID("angle_point_2");
152     return MY_ANGLE_POINT2_ID;
153   }
154
155   /// Attribute name of third point selected for angle calculation.
156   inline static const std::string& ANGLE_POINT3_ID()
157   {
158     static const std::string MY_ANGLE_POINT3_ID("angle_point_3");
159     return MY_ANGLE_POINT3_ID;
160   }
161
162   /// Attribute name for result.
163   inline static const std::string& RESULT_ID()
164   {
165     static const std::string MY_RESULT_ID("result");
166     return MY_RESULT_ID;
167   }
168
169   /// Attribute name for values of result.
170   inline static const std::string& RESULT_VALUES_ID()
171   {
172     static const std::string MY_RESULT_VALUES_ID("result_values");
173     return MY_RESULT_VALUES_ID;
174   }
175
176   /// Performs the algorithm and stores results it in the data structure.
177   FEATURESPLUGIN_EXPORT virtual void execute();
178
179   /// Request for initialization of data model of the feature: adding all attributes
180   FEATURESPLUGIN_EXPORT virtual void initAttributes();
181
182   /// Called on change of any argument-attribute of this object
183   /// \param theID identifier of changed attribute
184   FEATURESPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
185
186   /// Reimplemented from ModelAPI_Feature::isMacro(). Returns true.
187   virtual bool isMacro() const { return true; }
188
189   /** Returns the AIS preview
190   *   \param thePrevious - defines a presentation if it was created previously
191   */
192   FEATURESPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
193
194   /// Set current screen plane
195   /// \param theScreenPlane the screen plane
196   virtual void setScreenPlane(GeomPlanePtr theScreenPlane) {
197     myScreenPlane = theScreenPlane;
198   }
199
200   /// Set current view scale
201   /// \param theScale the view scale
202   virtual void setViewScale(double theScale) {
203     mySceenScale = theScale;
204   }
205
206   /// Use plugin manager for features creation
207   FeaturesPlugin_Measurement();
208
209 private:
210   /// Compute length of the edge
211   void computeLength();
212   /// Compute minimal distance between pair of shapes
213   void computeDistance();
214   /// Compute radius of circular edge, cylindrical surface or sphere.
215   void computeRadius();
216   /// Compute angle(s) between pair of edges if they are intersected
217   void computeAngle();
218   /// Compute angle by three points
219   void computeAngleByPoints();
220
221   /// Create length dimension presentation
222   /// \param thePrevious previous version of presentation
223   AISObjectPtr lengthDimension(AISObjectPtr thePrevious);
224
225   /// Create distance dimension presentation
226   /// \param thePrevious previous version of presentation
227   AISObjectPtr distanceDimension(AISObjectPtr thePrevious);
228
229   /// Create radius dimension presentation
230   /// \param thePrevious previous version of presentation
231   AISObjectPtr radiusDimension(AISObjectPtr thePrevious);
232
233   /// Create angle dimension presentation
234   /// \param thePrevious previous version of presentation
235   AISObjectPtr angleDimension(AISObjectPtr thePrevious);
236
237   /// Create angle by points dimension presentation
238   /// \param thePrevious previous version of presentation
239   AISObjectPtr angleByPointsDimension(AISObjectPtr thePrevious);
240
241   /// Set dimension presentation parameters
242   void setupDimension(AISObjectPtr theDim);
243
244   GeomPlanePtr myScreenPlane; //< a plane of current screen
245   double mySceenScale; //< a scale of current view
246 };
247
248 #endif