1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2013 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _AIS_AngleDimension_HeaderFile
16 #define _AIS_AngleDimension_HeaderFile
18 #include <AIS_Dimension.hxx>
19 #include <Geom_Plane.hxx>
20 #include <Geom_Line.hxx>
21 #include <Geom_Transformation.hxx>
26 #include <Prs3d_DimensionAspect.hxx>
27 #include <Prs3d_Projector.hxx>
28 #include <Prs3d_Presentation.hxx>
29 #include <Standard.hxx>
30 #include <Standard_Macro.hxx>
31 #include <Standard_Type.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS_Face.hxx>
35 #include <TopoDS_Vertex.hxx>
37 class AIS_AngleDimension;
38 DEFINE_STANDARD_HANDLE (AIS_AngleDimension, AIS_Dimension)
40 //! Angle dimension. Can be constructed:
41 //! - on two intersected edges.
42 //! - on three points or vertices.
43 //! - on conical face.
44 //! - between two intersected faces.
46 //! In case of three points or two intersected edges the dimension plane
47 //! (on which dimension presentation is built) can be computed uniquely
48 //! as through three defined points can be built only one plane.
49 //! Therefore, if user-defined plane differs from this one, the dimension can't be built.
51 //! In cases of two planes automatic plane by default is built on point of the
52 //! origin of parametric space of the first face (the basis surface) so, that
53 //! the working plane and two faces intersection forms minimal angle between the faces.
54 //! User can define the other point which the dimension plane should pass through
55 //! using the appropriate constructor. This point can lay on the one of the faces or not.
56 //! Also user can define his own plane but it should pass through the three points
57 //! computed on the geometry initialization step (when the constructor or SetMeasuredGeometry() method
60 //! In case of the conical face the center point of the angle is the apex of the conical surface.
61 //! The attachment points are points of the first and the last parameter of the basis circle of the cone.
63 class AIS_AngleDimension : public AIS_Dimension
67 //! Constructs minimum angle dimension between two linear edges (where possible).
68 //! These two edges should be intersected by each other. Otherwise the geometry is not valid.
69 //! @param theFirstEdge [in] the first edge.
70 //! @param theSecondEdge [in] the second edge.
71 Standard_EXPORT AIS_AngleDimension (const TopoDS_Edge& theFirstEdge,
72 const TopoDS_Edge& theSecondEdge);
74 //! Constructs the angle display object defined by three points.
75 //! @param theFirstPoint [in] the first point (point on first angle flyout).
76 //! @param theSecondPoint [in] the center point of angle dimension.
77 //! @param theThirdPoint [in] the second point (point on second angle flyout).
78 Standard_EXPORT AIS_AngleDimension (const gp_Pnt& theFirstPoint,
79 const gp_Pnt& theSecondPoint,
80 const gp_Pnt& theThirdPoint);
82 //! Constructs the angle display object defined by three vertices.
83 //! @param theFirstVertex [in] the first vertex (vertex for first angle flyout).
84 //! @param theSecondVertex [in] the center vertex of angle dimension.
85 //! @param theThirdPoint [in] the second vertex (vertex for second angle flyout).
86 Standard_EXPORT AIS_AngleDimension (const TopoDS_Vertex& theFirstVertex,
87 const TopoDS_Vertex& theSecondVertex,
88 const TopoDS_Vertex& theThirdVertex);
90 //! Constructs angle dimension for the cone face.
91 //! @param theCone [in] the conical face.
92 Standard_EXPORT AIS_AngleDimension (const TopoDS_Face& theCone);
94 //! Constructs angle dimension between two planar faces.
95 //! @param theFirstFace [in] the first face.
96 //! @param theSecondFace [in] the second face.
97 Standard_EXPORT AIS_AngleDimension (const TopoDS_Face& theFirstFace,
98 const TopoDS_Face& theSecondFace);
100 //! Constructs angle dimension between two planar faces.
101 //! @param theFirstFace [in] the first face.
102 //! @param theSecondFace [in] the second face.
103 //! @param thePoint [in] the point which the dimension plane should pass through.
104 //! This point can lay on the one of the faces or not.
105 Standard_EXPORT AIS_AngleDimension (const TopoDS_Face& theFirstFace,
106 const TopoDS_Face& theSecondFace,
107 const gp_Pnt& thePoint);
111 //! @return first point forming the angle.
112 const gp_Pnt& FirstPoint() const
117 //! @return second point forming the angle.
118 const gp_Pnt& SecondPoint() const
120 return mySecondPoint;
123 //! @return center point forming the angle.
124 const gp_Pnt& CenterPoint() const
126 return myCenterPoint;
129 //! @return first argument shape.
130 const TopoDS_Shape& FirstShape() const
135 //! @return second argument shape.
136 const TopoDS_Shape& SecondShape() const
138 return mySecondShape;
141 //! @return third argument shape.
142 const TopoDS_Shape& ThirdShape() const
149 //! Measures minimum angle dimension between two linear edges.
150 //! These two edges should be intersected by each other. Otherwise the geometry is not valid.
151 //! @param theFirstEdge [in] the first edge.
152 //! @param theSecondEdge [in] the second edge.
153 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Edge& theFirstEdge,
154 const TopoDS_Edge& theSecondEdge);
156 //! Measures angle defined by three points.
157 //! @param theFirstPoint [in] the first point (point on first angle flyout).
158 //! @param theSecondPoint [in] the center point of angle dimension.
159 //! @param theThirdPoint [in] the second point (point on second angle flyout).
160 Standard_EXPORT void SetMeasuredGeometry (const gp_Pnt& theFirstPoint,
161 const gp_Pnt& theSecondPoint,
162 const gp_Pnt& theThridPoint);
164 //! Measures angle defined by three vertices.
165 //! @param theFirstVertex [in] the first vertex (vertex for first angle flyout).
166 //! @param theSecondVertex [in] the center vertex of angle dimension.
167 //! @param theThirdPoint [in] the second vertex (vertex for second angle flyout).
168 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Vertex& theFirstVertex,
169 const TopoDS_Vertex& theSecondVertex,
170 const TopoDS_Vertex& theThirdVertex);
172 //! Measures angle of conical face.
173 //! @param theCone [in] the shape to measure.
174 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theCone);
176 //! Measures angle between two planar faces.
177 //! @param theFirstFace [in] the first face.
178 //! @param theSecondFace [in] the second face..
179 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
180 const TopoDS_Face& theSecondFace);
182 //! Measures angle between two planar faces.
183 //! @param theFirstFace [in] the first face.
184 //! @param theSecondFace [in] the second face.
185 //! @param thePoint [in] the point which the dimension plane should pass through.
186 //! This point can lay on the one of the faces or not.
187 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
188 const TopoDS_Face& theSecondFace,
189 const gp_Pnt& thePoint);
191 //! @return the display units string.
192 Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const Standard_OVERRIDE;
194 //! @return the model units string.
195 Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const Standard_OVERRIDE;
197 Standard_EXPORT virtual void SetDisplayUnits (const TCollection_AsciiString& theUnits) Standard_OVERRIDE;
199 Standard_EXPORT virtual void SetModelUnits (const TCollection_AsciiString& theUnits) Standard_OVERRIDE;
201 //! Principle of horizontal text alignment settings:
202 //! - divide circle into two halves according to attachment points
203 //! - if aTextPos is between attach points -> Center + positive flyout
204 //! - if aTextPos is not between attach points but in this half -> Left or Right + positive flyout
205 //! - if aTextPos is between reflections of attach points -> Center + negative flyout
206 //! - if aTextPos is not between reflections of attach points -> Left or Right + negative flyout
207 Standard_EXPORT virtual void SetTextPosition (const gp_Pnt& theTextPos) Standard_OVERRIDE;
209 Standard_EXPORT virtual const gp_Pnt GetTextPosition () const Standard_OVERRIDE;
213 DEFINE_STANDARD_RTTI (AIS_AngleDimension, AIS_Dimension)
217 //! Initialization of fields that is common to all constructors.
218 Standard_EXPORT void Init();
220 //! @param theFirstAttach [in] the first attachment point.
221 //! @param theSecondAttach [in] the second attachment point.
222 //! @param theCenter [in] the center point (center point of the angle).
223 //! @return the center of the dimension arc (the main dimension line in case of angle).
224 Standard_EXPORT gp_Pnt GetCenterOnArc (const gp_Pnt& theFirstAttach,
225 const gp_Pnt& theSecondAttach,
226 const gp_Pnt& theCenter) const;
228 //! Draws main dimension line (arc).
229 //! @param thePresentation [in] the dimension presentation.
230 //! @param theFirstAttach [in] the first attachment point.
231 //! @param theSecondAttach [in] the second attachment point.
232 //! @param theCenter [in] the center point (center point of the angle).
233 //! @param theRadius [in] the radius of the dimension arc.
234 //! @param theMode [in] the display mode.
235 Standard_EXPORT void DrawArc (const Handle(Prs3d_Presentation)& thePresentation,
236 const gp_Pnt& theFirstAttach,
237 const gp_Pnt& theSecondAttach,
238 const gp_Pnt& theCenter,
239 const Standard_Real theRadius,
240 const Standard_Integer theMode);
242 //! Draws main dimension line (arc) with text.
243 //! @param thePresentation [in] the dimension presentation.
244 //! @param theFirstAttach [in] the first attachment point.
245 //! @param theSecondAttach [in] the second attachment point.
246 //! @param theCenter [in] the center point (center point of the angle).
247 //! @param theText [in] the text label string.
248 //! @param theTextWidth [in] the text label width.
249 //! @param theMode [in] the display mode.
250 //! @param theLabelPosition [in] the text label vertical and horizontal positioning option
251 //! respectively to the main dimension line.
252 Standard_EXPORT void DrawArcWithText (const Handle(Prs3d_Presentation)& thePresentation,
253 const gp_Pnt& theFirstAttach,
254 const gp_Pnt& theSecondAttach,
255 const gp_Pnt& theCenter,
256 const TCollection_ExtendedString& theText,
257 const Standard_Real theTextWidth,
258 const Standard_Integer theMode,
259 const Standard_Integer theLabelPosition);
261 //! Fits text alignment relatively to the dimension line;
262 //! it computes the value of label position and arrow orientation
263 //! according set in the aspect and dimension properties.
264 //! @param theHorizontalTextPos [in] the horizontal alignment for text position.
265 //! @param theLabelPosition [out] the label position, contains bits that defines
266 //! vertical and horizontal alignment. (for internal usage in count text position).
267 //! @param theIsArrowExternal [out] is the arrows external,
268 //! if arrow orientation in the dimension aspect is Prs3d_DAO_Fit, it fits arrow
269 //! orientation automatically.
270 Standard_EXPORT void FitTextAlignment (const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos,
271 Standard_Integer& theLabelPosition,
272 Standard_Boolean& theIsArrowsExternal) const;
274 //! Adjusts aspect parameters according the text position:
275 //! extension size, vertical text alignment and flyout.
276 //! @param theTextPos [in] the user defined 3d point of text position.
277 //! @param theExtensionSize [out] the adjusted extension size.
278 //! @param theAlignment [out] the horizontal label alignment.
279 //! @param theFlyout [out] the adjusted value of flyout.
280 Standard_EXPORT void AdjustParameters (const gp_Pnt& theTextPos,
281 Standard_Real& theExtensionSize,
282 Prs3d_DimensionTextHorizontalPosition& theAlignment,
283 Standard_Real& theFlyout) const;
287 Standard_EXPORT virtual void ComputePlane() Standard_OVERRIDE;
289 //! Checks if the plane includes three angle points to build dimension.
290 Standard_EXPORT virtual Standard_Boolean CheckPlane (const gp_Pln& thePlane) const Standard_OVERRIDE;
292 Standard_EXPORT virtual Standard_Real ComputeValue() const Standard_OVERRIDE;
294 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePM,
295 const Handle(Prs3d_Presentation)& thePresentation,
296 const Standard_Integer theMode = 0) Standard_OVERRIDE;
298 Standard_EXPORT virtual void ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
299 const Handle(SelectMgr_EntityOwner)& theOwner) Standard_OVERRIDE;
303 //! Init angular dimension to measure angle between two linear edges.
304 //! @return TRUE if the angular dimension can be constructured
305 //! for the passed edges.
306 Standard_EXPORT Standard_Boolean InitTwoEdgesAngle (gp_Pln& theComputedPlane);
308 //! Init angular dimension to measure angle between two planar faces.
309 //! there is no user-defined poisitoning. So attach points are set
310 //! according to faces geometry (in origin of the first face basis surface).
311 //! @return TRUE if the angular dimension can be constructed
312 //! for the passed faces.
313 Standard_EXPORT Standard_Boolean InitTwoFacesAngle();
315 //! Init angular dimension to measure angle between two planar faces.
316 //! @param thePointOnFirstFace [in] the point which the dimension plane should pass through.
317 //! This point can lay on the one of the faces or not.
318 //! It will be projected on the first face and this point will be set
319 //! as the first point attach point.
320 //! It defines some kind of dimension positioning over the faces.
321 //! @return TRUE if the angular dimension can be constructed
322 //! for the passed faces.
323 Standard_EXPORT Standard_Boolean InitTwoFacesAngle (const gp_Pnt thePointOnFirstFace);
325 //! Init angular dimension to measure cone face.
326 //! @return TRUE if the angular dimension can be constructed
327 //! for the passed cone.
328 Standard_EXPORT Standard_Boolean InitConeAngle();
330 //! Check that the points forming angle are valid.
331 //! @return TRUE if the points met the following requirements:
332 //! The (P1, Center), (P2, Center) can be built.
333 //! The angle between the vectors > Precision::Angular().
334 Standard_EXPORT Standard_Boolean IsValidPoints (const gp_Pnt& theFirstPoint,
335 const gp_Pnt& theCenterPoint,
336 const gp_Pnt& theSecondPoint) const;
341 gp_Pnt mySecondPoint;
342 gp_Pnt myCenterPoint;
343 TopoDS_Shape myFirstShape;
344 TopoDS_Shape mySecondShape;
345 TopoDS_Shape myThirdShape;
348 #endif // _AIS_AngleDimension_HeaderFile