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