1 // Copyright (C) 2018-20xx 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef FeaturesPlugin_Measurement_H_
22 #define FeaturesPlugin_Measurement_H_
24 #include "FeaturesPlugin.h"
25 #include <ModelAPI_Feature.h>
27 #include <GeomAPI_IPresentable.h>
28 #include <GeomAPI_IScreenParams.h>
30 /// \class FeaturesPlugin_Measurement
32 /// \brief Feature for calculation metrics.
34 /// Supported following metrics:
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
45 inline static const std::string& ID()
47 static const std::string MY_ID("Measurement");
51 /// \return the kind of a feature.
52 virtual const std::string& getKind()
57 /// Attribute name for measurement method.
58 inline static const std::string& MEASURE_KIND()
60 static const std::string MY_MEASURE_KIND_ID("MeasureKind");
61 return MY_MEASURE_KIND_ID;
64 /// Attribute name for length measure.
65 inline static const std::string& MEASURE_LENGTH()
67 static const std::string MY_MEASURE_ID("Length");
71 /// Attribute name for distance measure.
72 inline static const std::string& MEASURE_DISTANCE()
74 static const std::string MY_MEASURE_ID("Distance");
78 /// Attribute name for radius measure.
79 inline static const std::string& MEASURE_RADIUS()
81 static const std::string MY_MEASURE_ID("Radius");
85 /// Attribute name for angle measure.
86 inline static const std::string& MEASURE_ANGLE()
88 static const std::string MY_MEASURE_ID("Angle");
92 /// Attribute name for angle measurement by 3 points.
93 inline static const std::string& MEASURE_ANGLE_POINTS()
95 static const std::string MY_MEASURE_ID("AngleBy3Points");
100 /// Attribute name of edge selected for length calculation.
101 inline static const std::string& EDGE_FOR_LENGTH_ID()
103 static const std::string MY_EDGE_FOR_LENGTH_ID("edge_for_length");
104 return MY_EDGE_FOR_LENGTH_ID;
107 /// Attribute name of first shape selected for distance calculation.
108 inline static const std::string& DISTANCE_FROM_OBJECT_ID()
110 static const std::string MY_DISTANCE_FROM_OBJECT_ID("distance_from");
111 return MY_DISTANCE_FROM_OBJECT_ID;
114 /// Attribute name of second shape selected for distance calculation.
115 inline static const std::string& DISTANCE_TO_OBJECT_ID()
117 static const std::string MY_DISTANCE_TO_OBJECT_ID("distance_to");
118 return MY_DISTANCE_TO_OBJECT_ID;
121 // Attribute name of edge or face selected to calculate radius.
122 inline static const std::string& CIRCULAR_OBJECT_ID()
124 static const std::string MY_CIRCULAR_OBJECT_ID("circular");
125 return MY_CIRCULAR_OBJECT_ID;
128 /// Attribute name of first edge selected for angle calculation.
129 inline static const std::string& ANGLE_FROM_EDGE_ID()
131 static const std::string MY_ANGLE_FROM_EDGE_ID("angle_from");
132 return MY_ANGLE_FROM_EDGE_ID;
135 /// Attribute name of second shape selected for angle calculation.
136 inline static const std::string& ANGLE_TO_EDGE_ID()
138 static const std::string MY_ANGLE_TO_EDGE_ID("angle_to");
139 return MY_ANGLE_TO_EDGE_ID;
142 /// Attribute name of first point selected for angle calculation.
143 inline static const std::string& ANGLE_POINT1_ID()
145 static const std::string MY_ANGLE_POINT1_ID("angle_point_1");
146 return MY_ANGLE_POINT1_ID;
149 /// Attribute name of second point (apex) selected for angle calculation.
150 inline static const std::string& ANGLE_POINT2_ID()
152 static const std::string MY_ANGLE_POINT2_ID("angle_point_2");
153 return MY_ANGLE_POINT2_ID;
156 /// Attribute name of third point selected for angle calculation.
157 inline static const std::string& ANGLE_POINT3_ID()
159 static const std::string MY_ANGLE_POINT3_ID("angle_point_3");
160 return MY_ANGLE_POINT3_ID;
163 /// Attribute name for result.
164 inline static const std::string& RESULT_ID()
166 static const std::string MY_RESULT_ID("result");
170 /// Attribute name for values of result.
171 inline static const std::string& RESULT_VALUES_ID()
173 static const std::string MY_RESULT_VALUES_ID("result_values");
174 return MY_RESULT_VALUES_ID;
177 /// Creates a new part document if needed
178 FEATURESPLUGIN_EXPORT virtual void execute();
180 /// Request for initialization of data model of the feature: adding all attributes
181 FEATURESPLUGIN_EXPORT virtual void initAttributes();
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);
187 /// Reimplemented from ModelAPI_Feature::isMacro(). Returns true.
188 virtual bool isMacro() const { return true; }
190 /** Returns the AIS preview
191 * \param thePrevious - defines a presentation if it was created previously
193 FEATURESPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
195 /// Set current screen plane
196 /// \param theScreenPlane the screen plane
197 virtual void setScreenPlane(GeomPlanePtr theScreenPlane) {
198 myScreenPlane = theScreenPlane;
201 /// Set current view scale
202 /// \param theScale the view scale
203 virtual void setViewScale(double theScale) {
204 mySceenScale = theScale;
207 /// Use plugin manager for features creation
208 FeaturesPlugin_Measurement();
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
219 /// Compute angle by three points
220 void computeAngleByPoints();
222 /// Create length dimension presentation
223 /// \param thePrevious previous version of presentation
224 AISObjectPtr lengthDimension(AISObjectPtr thePrevious);
226 /// Create distance dimension presentation
227 /// \param thePrevious previous version of presentation
228 AISObjectPtr distanceDimension(AISObjectPtr thePrevious);
230 /// Create radius dimension presentation
231 /// \param thePrevious previous version of presentation
232 AISObjectPtr radiusDimension(AISObjectPtr thePrevious);
234 /// Create angle dimension presentation
235 /// \param thePrevious previous version of presentation
236 AISObjectPtr angleDimension(AISObjectPtr thePrevious);
238 /// Create angle by points dimension presentation
239 /// \param thePrevious previous version of presentation
240 AISObjectPtr angleByPointsDimension(AISObjectPtr thePrevious);
242 /// Set dimension presentation parameters
243 void setupDimension(AISObjectPtr theDim);
245 GeomPlanePtr myScreenPlane; //< a plane of current screen
246 double mySceenScale; //< a scale of current view