1 // Copyright (C) 2018-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef FeaturesPlugin_Measurement_H_
21 #define FeaturesPlugin_Measurement_H_
23 #include "FeaturesPlugin.h"
24 #include <ModelAPI_Feature.h>
26 #include <GeomAPI_IPresentable.h>
27 #include <GeomAPI_IScreenParams.h>
29 /// \class FeaturesPlugin_Measurement
31 /// \brief Feature for calculation metrics.
33 /// Supported following metrics:
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
44 inline static const std::string& ID()
46 static const std::string MY_ID("Measurement");
50 /// \return the kind of a feature.
51 virtual const std::string& getKind()
56 /// Attribute name for measurement method.
57 inline static const std::string& MEASURE_KIND()
59 static const std::string MY_MEASURE_KIND_ID("MeasureKind");
60 return MY_MEASURE_KIND_ID;
63 /// Attribute name for length measure.
64 inline static const std::string& MEASURE_LENGTH()
66 static const std::string MY_MEASURE_ID("Length");
70 /// Attribute name for distance measure.
71 inline static const std::string& MEASURE_DISTANCE()
73 static const std::string MY_MEASURE_ID("Distance");
77 /// Attribute name for radius measure.
78 inline static const std::string& MEASURE_RADIUS()
80 static const std::string MY_MEASURE_ID("Radius");
84 /// Attribute name for angle measure.
85 inline static const std::string& MEASURE_ANGLE()
87 static const std::string MY_MEASURE_ID("Angle");
91 /// Attribute name for angle measurement by 3 points.
92 inline static const std::string& MEASURE_ANGLE_POINTS()
94 static const std::string MY_MEASURE_ID("AngleBy3Points");
99 /// Attribute name of edge selected for length calculation.
100 inline static const std::string& EDGE_FOR_LENGTH_ID()
102 static const std::string MY_EDGE_FOR_LENGTH_ID("edge_for_length");
103 return MY_EDGE_FOR_LENGTH_ID;
106 /// Attribute name of first shape selected for distance calculation.
107 inline static const std::string& DISTANCE_FROM_OBJECT_ID()
109 static const std::string MY_DISTANCE_FROM_OBJECT_ID("distance_from");
110 return MY_DISTANCE_FROM_OBJECT_ID;
113 /// Attribute name of second shape selected for distance calculation.
114 inline static const std::string& DISTANCE_TO_OBJECT_ID()
116 static const std::string MY_DISTANCE_TO_OBJECT_ID("distance_to");
117 return MY_DISTANCE_TO_OBJECT_ID;
120 // Attribute name of edge or face selected to calculate radius.
121 inline static const std::string& CIRCULAR_OBJECT_ID()
123 static const std::string MY_CIRCULAR_OBJECT_ID("circular");
124 return MY_CIRCULAR_OBJECT_ID;
127 /// Attribute name of first edge selected for angle calculation.
128 inline static const std::string& ANGLE_FROM_EDGE_ID()
130 static const std::string MY_ANGLE_FROM_EDGE_ID("angle_from");
131 return MY_ANGLE_FROM_EDGE_ID;
134 /// Attribute name of second shape selected for angle calculation.
135 inline static const std::string& ANGLE_TO_EDGE_ID()
137 static const std::string MY_ANGLE_TO_EDGE_ID("angle_to");
138 return MY_ANGLE_TO_EDGE_ID;
141 /// Attribute name of first point selected for angle calculation.
142 inline static const std::string& ANGLE_POINT1_ID()
144 static const std::string MY_ANGLE_POINT1_ID("angle_point_1");
145 return MY_ANGLE_POINT1_ID;
148 /// Attribute name of second point (apex) selected for angle calculation.
149 inline static const std::string& ANGLE_POINT2_ID()
151 static const std::string MY_ANGLE_POINT2_ID("angle_point_2");
152 return MY_ANGLE_POINT2_ID;
155 /// Attribute name of third point selected for angle calculation.
156 inline static const std::string& ANGLE_POINT3_ID()
158 static const std::string MY_ANGLE_POINT3_ID("angle_point_3");
159 return MY_ANGLE_POINT3_ID;
162 /// Attribute name for result.
163 inline static const std::string& RESULT_ID()
165 static const std::string MY_RESULT_ID("result");
169 /// Attribute name for values of result.
170 inline static const std::string& RESULT_VALUES_ID()
172 static const std::string MY_RESULT_VALUES_ID("result_values");
173 return MY_RESULT_VALUES_ID;
176 /// Performs the algorithm and stores results it in the data structure.
177 FEATURESPLUGIN_EXPORT virtual void execute();
179 /// Request for initialization of data model of the feature: adding all attributes
180 FEATURESPLUGIN_EXPORT virtual void initAttributes();
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);
186 /// Reimplemented from ModelAPI_Feature::isMacro(). Returns true.
187 virtual bool isMacro() const { return true; }
189 /** Returns the AIS preview
190 * \param thePrevious - defines a presentation if it was created previously
192 FEATURESPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
194 /// Set current screen plane
195 /// \param theScreenPlane the screen plane
196 virtual void setScreenPlane(GeomPlanePtr theScreenPlane) {
197 myScreenPlane = theScreenPlane;
200 /// Set current view scale
201 /// \param theScale the view scale
202 virtual void setViewScale(double theScale) {
203 mySceenScale = theScale;
206 /// Use plugin manager for features creation
207 FeaturesPlugin_Measurement();
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
218 /// Compute angle by three points
219 void computeAngleByPoints();
221 /// Create length dimension presentation
222 /// \param thePrevious previous version of presentation
223 AISObjectPtr lengthDimension(AISObjectPtr thePrevious);
225 /// Create distance dimension presentation
226 /// \param thePrevious previous version of presentation
227 AISObjectPtr distanceDimension(AISObjectPtr thePrevious);
229 /// Create radius dimension presentation
230 /// \param thePrevious previous version of presentation
231 AISObjectPtr radiusDimension(AISObjectPtr thePrevious);
233 /// Create angle dimension presentation
234 /// \param thePrevious previous version of presentation
235 AISObjectPtr angleDimension(AISObjectPtr thePrevious);
237 /// Create angle by points dimension presentation
238 /// \param thePrevious previous version of presentation
239 AISObjectPtr angleByPointsDimension(AISObjectPtr thePrevious);
241 /// Set dimension presentation parameters
242 void setupDimension(AISObjectPtr theDim);
244 GeomPlanePtr myScreenPlane; //< a plane of current screen
245 double mySceenScale; //< a scale of current view