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 <AIS_TypeOfAngle.hxx>
20 #include <AIS_TypeOfAngleArrowVisibility.hxx>
22 #include <Geom_Plane.hxx>
23 #include <Geom_Line.hxx>
24 #include <Geom_Transformation.hxx>
29 #include <Prs3d_DimensionAspect.hxx>
30 #include <Prs3d_Projector.hxx>
31 #include <Prs3d_Presentation.hxx>
32 #include <Standard.hxx>
33 #include <Standard_Macro.hxx>
34 #include <Standard_Type.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <TopoDS_Face.hxx>
38 #include <TopoDS_Vertex.hxx>
40 class AIS_AngleDimension;
41 DEFINE_STANDARD_HANDLE (AIS_AngleDimension, AIS_Dimension)
43 //! Angle dimension. Can be constructed:
44 //! - on two intersected edges.
45 //! - on three points or vertices.
46 //! - on conical face.
47 //! - between two intersected faces.
49 //! In case of three points or two intersected edges the dimension plane
50 //! (on which dimension presentation is built) can be computed uniquely
51 //! as through three defined points can be built only one plane.
52 //! Therefore, if user-defined plane differs from this one, the dimension can't be built.
54 //! In cases of two planes automatic plane by default is built on point of the
55 //! origin of parametric space of the first face (the basis surface) so, that
56 //! the working plane and two faces intersection forms minimal angle between the faces.
57 //! User can define the other point which the dimension plane should pass through
58 //! using the appropriate constructor. This point can lay on the one of the faces or not.
59 //! Also user can define his own plane but it should pass through the three points
60 //! computed on the geometry initialization step (when the constructor or SetMeasuredGeometry() method
63 //! In case of the conical face the center point of the angle is the apex of the conical surface.
64 //! The attachment points are points of the first and the last parameter of the basis circle of the cone.
66 class AIS_AngleDimension : public AIS_Dimension
70 //! Constructs minimum angle dimension between two linear edges (where possible).
71 //! These two edges should be intersected by each other. Otherwise the geometry is not valid.
72 //! @param theFirstEdge [in] the first edge.
73 //! @param theSecondEdge [in] the second edge.
74 Standard_EXPORT AIS_AngleDimension (const TopoDS_Edge& theFirstEdge,
75 const TopoDS_Edge& theSecondEdge);
77 //! Constructs the angle display object defined by three points.
78 //! @param theFirstPoint [in] the first point (point on first angle flyout).
79 //! @param theSecondPoint [in] the center point of angle dimension.
80 //! @param theThirdPoint [in] the second point (point on second angle flyout).
81 Standard_EXPORT AIS_AngleDimension (const gp_Pnt& theFirstPoint,
82 const gp_Pnt& theSecondPoint,
83 const gp_Pnt& theThirdPoint);
85 //! Constructs the angle display object defined by three vertices.
86 //! @param theFirstVertex [in] the first vertex (vertex for first angle flyout).
87 //! @param theSecondVertex [in] the center vertex of angle dimension.
88 //! @param theThirdPoint [in] the second vertex (vertex for second angle flyout).
89 Standard_EXPORT AIS_AngleDimension (const TopoDS_Vertex& theFirstVertex,
90 const TopoDS_Vertex& theSecondVertex,
91 const TopoDS_Vertex& theThirdVertex);
93 //! Constructs angle dimension for the cone face.
94 //! @param theCone [in] the conical face.
95 Standard_EXPORT AIS_AngleDimension (const TopoDS_Face& theCone);
97 //! Constructs angle dimension between two planar faces.
98 //! @param theFirstFace [in] the first face.
99 //! @param theSecondFace [in] the second face.
100 Standard_EXPORT AIS_AngleDimension (const TopoDS_Face& theFirstFace,
101 const TopoDS_Face& theSecondFace);
103 //! Constructs angle dimension between two planar faces.
104 //! @param theFirstFace [in] the first face.
105 //! @param theSecondFace [in] the second face.
106 //! @param thePoint [in] the point which the dimension plane should pass through.
107 //! This point can lay on the one of the faces or not.
108 Standard_EXPORT AIS_AngleDimension (const TopoDS_Face& theFirstFace,
109 const TopoDS_Face& theSecondFace,
110 const gp_Pnt& thePoint);
114 //! @return first point forming the angle.
115 const gp_Pnt& FirstPoint() const
120 //! @return second point forming the angle.
121 const gp_Pnt& SecondPoint() const
123 return mySecondPoint;
126 //! @return center point forming the angle.
127 const gp_Pnt& CenterPoint() const
129 return myCenterPoint;
132 //! @return first argument shape.
133 const TopoDS_Shape& FirstShape() const
138 //! @return second argument shape.
139 const TopoDS_Shape& SecondShape() const
141 return mySecondShape;
144 //! @return third argument shape.
145 const TopoDS_Shape& ThirdShape() const
152 //! Measures minimum angle dimension between two linear edges.
153 //! These two edges should be intersected by each other. Otherwise the geometry is not valid.
154 //! @param theFirstEdge [in] the first edge.
155 //! @param theSecondEdge [in] the second edge.
156 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Edge& theFirstEdge,
157 const TopoDS_Edge& theSecondEdge);
159 //! Measures angle defined by three points.
160 //! @param theFirstPoint [in] the first point (point on first angle flyout).
161 //! @param theSecondPoint [in] the center point of angle dimension.
162 //! @param theThirdPoint [in] the second point (point on second angle flyout).
163 Standard_EXPORT void SetMeasuredGeometry (const gp_Pnt& theFirstPoint,
164 const gp_Pnt& theSecondPoint,
165 const gp_Pnt& theThridPoint);
167 //! Measures angle defined by three vertices.
168 //! @param theFirstVertex [in] the first vertex (vertex for first angle flyout).
169 //! @param theSecondVertex [in] the center vertex of angle dimension.
170 //! @param theThirdPoint [in] the second vertex (vertex for second angle flyout).
171 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Vertex& theFirstVertex,
172 const TopoDS_Vertex& theSecondVertex,
173 const TopoDS_Vertex& theThirdVertex);
175 //! Measures angle of conical face.
176 //! @param theCone [in] the shape to measure.
177 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theCone);
179 //! Measures angle between two planar faces.
180 //! @param theFirstFace [in] the first face.
181 //! @param theSecondFace [in] the second face..
182 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
183 const TopoDS_Face& theSecondFace);
185 //! Measures angle between two planar faces.
186 //! @param theFirstFace [in] the first face.
187 //! @param theSecondFace [in] the second face.
188 //! @param thePoint [in] the point which the dimension plane should pass through.
189 //! This point can lay on the one of the faces or not.
190 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
191 const TopoDS_Face& theSecondFace,
192 const gp_Pnt& thePoint);
194 //! @return the display units string.
195 Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const Standard_OVERRIDE;
197 //! @return the model units string.
198 Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const Standard_OVERRIDE;
200 Standard_EXPORT virtual void SetDisplayUnits (const TCollection_AsciiString& theUnits) Standard_OVERRIDE;
202 Standard_EXPORT virtual void SetModelUnits (const TCollection_AsciiString& theUnits) Standard_OVERRIDE;
204 //! Principle of horizontal text alignment settings:
205 //! - divide circle into two halves according to attachment points
206 //! - if aTextPos is between attach points -> Center + positive flyout
207 //! - if aTextPos is not between attach points but in this half -> Left or Right + positive flyout
208 //! - if aTextPos is between reflections of attach points -> Center + negative flyout
209 //! - if aTextPos is not between reflections of attach points -> Left or Right + negative flyout
210 Standard_EXPORT virtual void SetTextPosition (const gp_Pnt& theTextPos) Standard_OVERRIDE;
212 Standard_EXPORT virtual const gp_Pnt GetTextPosition () const Standard_OVERRIDE;
215 //! @param theType [in] the type value.
216 void SetType(const AIS_TypeOfAngle theType)
221 //! @return the current angle type.
222 AIS_TypeOfAngle GetType() const
227 //! Sets visible arrows type
228 //! @param theType [in] the type of visibility of arrows.
229 void SetArrowsVisibility(const AIS_TypeOfAngleArrowVisibility& theType)
231 myArrowsVisibility = theType;
234 //! @return the type of visibility of arrows.
235 AIS_TypeOfAngleArrowVisibility GetArrowsVisibility() const
237 return myArrowsVisibility;
242 DEFINE_STANDARD_RTTIEXT(AIS_AngleDimension,AIS_Dimension)
246 //! Initialization of fields that is common to all constructors.
247 Standard_EXPORT void Init();
249 //! Gets plane normal for minimal angle.
250 //! Dimension computation is based on three attach points and plane normal.
251 //! Based on this normal angle arc, arrows and extensions are constructed.
252 gp_Dir GetNormalForMinAngle() const;
254 //! @param theFirstAttach [in] the first attachment point.
255 //! @param theSecondAttach [in] the second attachment point.
256 //! @param theCenter [in] the center point (center point of the angle).
257 //! @return the center of the dimension arc (the main dimension line in case of angle).
258 Standard_EXPORT gp_Pnt GetCenterOnArc (const gp_Pnt& theFirstAttach,
259 const gp_Pnt& theSecondAttach,
260 const gp_Pnt& theCenter) const;
262 //! Draws main dimension line (arc).
263 //! @param thePresentation [in] the dimension presentation.
264 //! @param theFirstAttach [in] the first attachment point.
265 //! @param theSecondAttach [in] the second attachment point.
266 //! @param theCenter [in] the center point (center point of the angle).
267 //! @param theRadius [in] the radius of the dimension arc.
268 //! @param theMode [in] the display mode.
269 Standard_EXPORT void DrawArc (const Handle(Prs3d_Presentation)& thePresentation,
270 const gp_Pnt& theFirstAttach,
271 const gp_Pnt& theSecondAttach,
272 const gp_Pnt& theCenter,
273 const Standard_Real theRadius,
274 const Standard_Integer theMode);
276 //! Draws main dimension line (arc) with text.
277 //! @param thePresentation [in] the dimension presentation.
278 //! @param theFirstAttach [in] the first attachment point.
279 //! @param theSecondAttach [in] the second attachment point.
280 //! @param theCenter [in] the center point (center point of the angle).
281 //! @param theText [in] the text label string.
282 //! @param theTextWidth [in] the text label width.
283 //! @param theMode [in] the display mode.
284 //! @param theLabelPosition [in] the text label vertical and horizontal positioning option
285 //! respectively to the main dimension line.
286 Standard_EXPORT void DrawArcWithText (const Handle(Prs3d_Presentation)& thePresentation,
287 const gp_Pnt& theFirstAttach,
288 const gp_Pnt& theSecondAttach,
289 const gp_Pnt& theCenter,
290 const TCollection_ExtendedString& theText,
291 const Standard_Real theTextWidth,
292 const Standard_Integer theMode,
293 const Standard_Integer theLabelPosition);
295 //! Fits text alignment relatively to the dimension line;
296 //! it computes the value of label position and arrow orientation
297 //! according set in the aspect and dimension properties.
298 //! @param theHorizontalTextPos [in] the horizontal alignment for text position.
299 //! @param theLabelPosition [out] the label position, contains bits that defines
300 //! vertical and horizontal alignment. (for internal usage in count text position).
301 //! @param theIsArrowExternal [out] is the arrows external,
302 //! if arrow orientation in the dimension aspect is Prs3d_DAO_Fit, it fits arrow
303 //! orientation automatically.
304 Standard_EXPORT void FitTextAlignment (const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos,
305 Standard_Integer& theLabelPosition,
306 Standard_Boolean& theIsArrowsExternal) const;
308 //! Adjusts aspect parameters according the text position:
309 //! extension size, vertical text alignment and flyout.
310 //! @param theTextPos [in] the user defined 3d point of text position.
311 //! @param theExtensionSize [out] the adjusted extension size.
312 //! @param theAlignment [out] the horizontal label alignment.
313 //! @param theFlyout [out] the adjusted value of flyout.
314 Standard_EXPORT void AdjustParameters (const gp_Pnt& theTextPos,
315 Standard_Real& theExtensionSize,
316 Prs3d_DimensionTextHorizontalPosition& theAlignment,
317 Standard_Real& theFlyout) const;
321 Standard_EXPORT virtual void ComputePlane();
323 //! Checks if the plane includes three angle points to build dimension.
324 Standard_EXPORT virtual Standard_Boolean CheckPlane (const gp_Pln& thePlane) const Standard_OVERRIDE;
326 Standard_EXPORT virtual Standard_Real ComputeValue() const Standard_OVERRIDE;
328 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePM,
329 const Handle(Prs3d_Presentation)& thePresentation,
330 const Standard_Integer theMode = 0) Standard_OVERRIDE;
332 Standard_EXPORT virtual void ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
333 const Handle(SelectMgr_EntityOwner)& theOwner) Standard_OVERRIDE;
337 //! Init angular dimension to measure angle between two linear edges.
338 //! @return TRUE if the angular dimension can be constructured
339 //! for the passed edges.
340 Standard_EXPORT Standard_Boolean InitTwoEdgesAngle (gp_Pln& theComputedPlane);
342 //! Init angular dimension to measure angle between two planar faces.
343 //! there is no user-defined poisitoning. So attach points are set
344 //! according to faces geometry (in origin of the first face basis surface).
345 //! @return TRUE if the angular dimension can be constructed
346 //! for the passed faces.
347 Standard_EXPORT Standard_Boolean InitTwoFacesAngle();
349 //! Init angular dimension to measure angle between two planar faces.
350 //! @param thePointOnFirstFace [in] the point which the dimension plane should pass through.
351 //! This point can lay on the one of the faces or not.
352 //! It will be projected on the first face and this point will be set
353 //! as the first point attach point.
354 //! It defines some kind of dimension positioning over the faces.
355 //! @return TRUE if the angular dimension can be constructed
356 //! for the passed faces.
357 Standard_EXPORT Standard_Boolean InitTwoFacesAngle (const gp_Pnt thePointOnFirstFace);
359 //! Init angular dimension to measure cone face.
360 //! @return TRUE if the angular dimension can be constructed
361 //! for the passed cone.
362 Standard_EXPORT Standard_Boolean InitConeAngle();
364 //! Check that the points forming angle are valid.
365 //! @return TRUE if the points met the following requirements:
366 //! The (P1, Center), (P2, Center) can be built.
367 //! The angle between the vectors > Precision::Angular().
368 Standard_EXPORT Standard_Boolean IsValidPoints (const gp_Pnt& theFirstPoint,
369 const gp_Pnt& theCenterPoint,
370 const gp_Pnt& theSecondPoint) const;
373 //! Returns true if the arrow should be visible
374 //! @param theArrowType an arrow type
375 //! @return TRUE if the arrow should be visible
376 Standard_EXPORT Standard_Boolean isArrowVisible(const AIS_TypeOfAngleArrowVisibility& theArrowType) const;
379 AIS_TypeOfAngle myType; //!< type of angle
380 AIS_TypeOfAngleArrowVisibility myArrowsVisibility; //!< type of arrows visibility
383 gp_Pnt mySecondPoint;
384 gp_Pnt myCenterPoint;
385 TopoDS_Shape myFirstShape;
386 TopoDS_Shape mySecondShape;
387 TopoDS_Shape myThirdShape;
390 #endif // _AIS_AngleDimension_HeaderFile