0031456: Visualization - move out Dimensions and Relations from package AIS to PrsDims
[occt.git] / src / PrsDim / PrsDim_AngleDimension.hxx
CommitLineData
a6eb515f 1// Copyright (c) 1995-1999 Matra Datavision
2// Copyright (c) 1999-2013 OPEN CASCADE SAS
3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
a6eb515f 5//
d5f74e42 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
973c2be1 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.
a6eb515f 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
a6eb515f 14
787ff240 15#ifndef _PrsDim_AngleDimension_HeaderFile
16#define _PrsDim_AngleDimension_HeaderFile
a6eb515f 17
787ff240 18#include <PrsDim_Dimension.hxx>
19#include <PrsDim_TypeOfAngle.hxx>
20#include <PrsDim_TypeOfAngleArrowVisibility.hxx>
ee905e84 21
a6eb515f 22#include <Geom_Plane.hxx>
23#include <Geom_Line.hxx>
a6eb515f 24#include <gp.hxx>
25#include <gp_Ax1.hxx>
26#include <gp_Dir.hxx>
27#include <gp_Pnt.hxx>
28#include <Prs3d_DimensionAspect.hxx>
a6eb515f 29#include <Prs3d_Presentation.hxx>
30#include <Standard.hxx>
31#include <Standard_Macro.hxx>
ec357c5c 32#include <Standard_Type.hxx>
a6eb515f 33#include <TopoDS.hxx>
34#include <TopoDS_Edge.hxx>
35#include <TopoDS_Face.hxx>
60bf98ae 36#include <TopoDS_Vertex.hxx>
a6eb515f 37
787ff240 38DEFINE_STANDARD_HANDLE(PrsDim_AngleDimension, PrsDim_Dimension)
a6eb515f 39
60bf98ae 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.
45//!
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.
50//!
af203d54 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
60bf98ae 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
58//! is called).
59//!
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.
787ff240 62class PrsDim_AngleDimension : public PrsDim_Dimension
a6eb515f 63{
787ff240 64 DEFINE_STANDARD_RTTIEXT(PrsDim_AngleDimension, PrsDim_Dimension)
a6eb515f 65public:
d7bffd44 66
60bf98ae 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.
787ff240 71 Standard_EXPORT PrsDim_AngleDimension (const TopoDS_Edge& theFirstEdge,
72 const TopoDS_Edge& theSecondEdge);
a6eb515f 73
74 //! Constructs the angle display object defined by three points.
60bf98ae 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).
787ff240 78 Standard_EXPORT PrsDim_AngleDimension (const gp_Pnt& theFirstPoint,
79 const gp_Pnt& theSecondPoint,
80 const gp_Pnt& theThirdPoint);
60bf98ae 81
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).
787ff240 86 Standard_EXPORT PrsDim_AngleDimension (const TopoDS_Vertex& theFirstVertex,
87 const TopoDS_Vertex& theSecondVertex,
88 const TopoDS_Vertex& theThirdVertex);
60bf98ae 89
90 //! Constructs angle dimension for the cone face.
91 //! @param theCone [in] the conical face.
787ff240 92 Standard_EXPORT PrsDim_AngleDimension (const TopoDS_Face& theCone);
60bf98ae 93
94 //! Constructs angle dimension between two planar faces.
95 //! @param theFirstFace [in] the first face.
96 //! @param theSecondFace [in] the second face.
787ff240 97 Standard_EXPORT PrsDim_AngleDimension (const TopoDS_Face& theFirstFace,
98 const TopoDS_Face& theSecondFace);
60bf98ae 99
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.
787ff240 105 Standard_EXPORT PrsDim_AngleDimension (const TopoDS_Face& theFirstFace,
106 const TopoDS_Face& theSecondFace,
107 const gp_Pnt& thePoint);
60bf98ae 108
109public:
110
111 //! @return first point forming the angle.
787ff240 112 const gp_Pnt& FirstPoint() const { return myFirstPoint; }
60bf98ae 113
114 //! @return second point forming the angle.
787ff240 115 const gp_Pnt& SecondPoint() const { return mySecondPoint; }
60bf98ae 116
117 //! @return center point forming the angle.
787ff240 118 const gp_Pnt& CenterPoint() const { return myCenterPoint; }
60bf98ae 119
120 //! @return first argument shape.
787ff240 121 const TopoDS_Shape& FirstShape() const { return myFirstShape; }
60bf98ae 122
123 //! @return second argument shape.
787ff240 124 const TopoDS_Shape& SecondShape() const { return mySecondShape; }
60bf98ae 125
126 //! @return third argument shape.
787ff240 127 const TopoDS_Shape& ThirdShape() const { return myThirdShape; }
60bf98ae 128
129public:
130
131 //! Measures minimum angle dimension between two linear edges.
132 //! These two edges should be intersected by each other. Otherwise the geometry is not valid.
133 //! @param theFirstEdge [in] the first edge.
134 //! @param theSecondEdge [in] the second edge.
135 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Edge& theFirstEdge,
136 const TopoDS_Edge& theSecondEdge);
a6eb515f 137
60bf98ae 138 //! Measures angle defined by three points.
139 //! @param theFirstPoint [in] the first point (point on first angle flyout).
140 //! @param theSecondPoint [in] the center point of angle dimension.
141 //! @param theThirdPoint [in] the second point (point on second angle flyout).
142 Standard_EXPORT void SetMeasuredGeometry (const gp_Pnt& theFirstPoint,
143 const gp_Pnt& theSecondPoint,
144 const gp_Pnt& theThridPoint);
a6eb515f 145
60bf98ae 146 //! Measures angle defined by three vertices.
147 //! @param theFirstVertex [in] the first vertex (vertex for first angle flyout).
148 //! @param theSecondVertex [in] the center vertex of angle dimension.
149 //! @param theThirdPoint [in] the second vertex (vertex for second angle flyout).
150 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Vertex& theFirstVertex,
151 const TopoDS_Vertex& theSecondVertex,
152 const TopoDS_Vertex& theThirdVertex);
a6eb515f 153
60bf98ae 154 //! Measures angle of conical face.
155 //! @param theCone [in] the shape to measure.
156 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theCone);
157
158 //! Measures angle between two planar faces.
159 //! @param theFirstFace [in] the first face.
160 //! @param theSecondFace [in] the second face..
161 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
162 const TopoDS_Face& theSecondFace);
163
164 //! Measures angle between two planar faces.
165 //! @param theFirstFace [in] the first face.
166 //! @param theSecondFace [in] the second face.
167 //! @param thePoint [in] the point which the dimension plane should pass through.
168 //! This point can lay on the one of the faces or not.
169 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
170 const TopoDS_Face& theSecondFace,
171 const gp_Pnt& thePoint);
172
173 //! @return the display units string.
79104795 174 Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const Standard_OVERRIDE;
60bf98ae 175
176 //! @return the model units string.
79104795 177 Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const Standard_OVERRIDE;
60bf98ae 178
79104795 179 Standard_EXPORT virtual void SetDisplayUnits (const TCollection_AsciiString& theUnits) Standard_OVERRIDE;
60bf98ae 180
79104795 181 Standard_EXPORT virtual void SetModelUnits (const TCollection_AsciiString& theUnits) Standard_OVERRIDE;
a6eb515f 182
af203d54 183 //! Principle of horizontal text alignment settings:
184 //! - divide circle into two halves according to attachment points
185 //! - if aTextPos is between attach points -> Center + positive flyout
186 //! - if aTextPos is not between attach points but in this half -> Left or Right + positive flyout
187 //! - if aTextPos is between reflections of attach points -> Center + negative flyout
188 //! - if aTextPos is not between reflections of attach points -> Left or Right + negative flyout
79104795 189 Standard_EXPORT virtual void SetTextPosition (const gp_Pnt& theTextPos) Standard_OVERRIDE;
af203d54 190
787ff240 191 Standard_EXPORT virtual gp_Pnt GetTextPosition () const Standard_OVERRIDE;
af203d54 192
ee905e84 193 //! Sets angle type.
194 //! @param theType [in] the type value.
787ff240 195 void SetType (const PrsDim_TypeOfAngle theType) { myType = theType; }
ee905e84 196
197 //! @return the current angle type.
787ff240 198 PrsDim_TypeOfAngle GetType() const { return myType; }
ee905e84 199
200 //! Sets visible arrows type
201 //! @param theType [in] the type of visibility of arrows.
787ff240 202 void SetArrowsVisibility (const PrsDim_TypeOfAngleArrowVisibility& theType) { myArrowsVisibility = theType; }
ee905e84 203
204 //! @return the type of visibility of arrows.
787ff240 205 PrsDim_TypeOfAngleArrowVisibility GetArrowsVisibility() const { return myArrowsVisibility; }
a6eb515f 206
207protected:
208
60bf98ae 209 //! Initialization of fields that is common to all constructors.
210 Standard_EXPORT void Init();
a6eb515f 211
4d147bf2 212 //! Gets plane normal for minimal angle.
213 //! Dimension computation is based on three attach points and plane normal.
214 //! Based on this normal angle arc, arrows and extensions are constructed.
215 gp_Dir GetNormalForMinAngle() const;
216
60bf98ae 217 //! @param theFirstAttach [in] the first attachment point.
218 //! @param theSecondAttach [in] the second attachment point.
219 //! @param theCenter [in] the center point (center point of the angle).
220 //! @return the center of the dimension arc (the main dimension line in case of angle).
221 Standard_EXPORT gp_Pnt GetCenterOnArc (const gp_Pnt& theFirstAttach,
222 const gp_Pnt& theSecondAttach,
af203d54 223 const gp_Pnt& theCenter) const;
a6eb515f 224
60bf98ae 225 //! Draws main dimension line (arc).
226 //! @param thePresentation [in] the dimension presentation.
227 //! @param theFirstAttach [in] the first attachment point.
228 //! @param theSecondAttach [in] the second attachment point.
229 //! @param theCenter [in] the center point (center point of the angle).
230 //! @param theRadius [in] the radius of the dimension arc.
231 //! @param theMode [in] the display mode.
232 Standard_EXPORT void DrawArc (const Handle(Prs3d_Presentation)& thePresentation,
233 const gp_Pnt& theFirstAttach,
234 const gp_Pnt& theSecondAttach,
235 const gp_Pnt& theCenter,
236 const Standard_Real theRadius,
237 const Standard_Integer theMode);
a6eb515f 238
60bf98ae 239 //! Draws main dimension line (arc) with text.
240 //! @param thePresentation [in] the dimension presentation.
241 //! @param theFirstAttach [in] the first attachment point.
242 //! @param theSecondAttach [in] the second attachment point.
243 //! @param theCenter [in] the center point (center point of the angle).
244 //! @param theText [in] the text label string.
245 //! @param theTextWidth [in] the text label width.
246 //! @param theMode [in] the display mode.
247 //! @param theLabelPosition [in] the text label vertical and horizontal positioning option
248 //! respectively to the main dimension line.
249 Standard_EXPORT void DrawArcWithText (const Handle(Prs3d_Presentation)& thePresentation,
250 const gp_Pnt& theFirstAttach,
251 const gp_Pnt& theSecondAttach,
252 const gp_Pnt& theCenter,
253 const TCollection_ExtendedString& theText,
254 const Standard_Real theTextWidth,
255 const Standard_Integer theMode,
256 const Standard_Integer theLabelPosition);
a6eb515f 257
af203d54 258 //! Fits text alignment relatively to the dimension line;
259 //! it computes the value of label position and arrow orientation
260 //! according set in the aspect and dimension properties.
261 //! @param theHorizontalTextPos [in] the horizontal alignment for text position.
262 //! @param theLabelPosition [out] the label position, contains bits that defines
263 //! vertical and horizontal alignment. (for internal usage in count text position).
264 //! @param theIsArrowExternal [out] is the arrows external,
265 //! if arrow orientation in the dimension aspect is Prs3d_DAO_Fit, it fits arrow
266 //! orientation automatically.
267 Standard_EXPORT void FitTextAlignment (const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos,
268 Standard_Integer& theLabelPosition,
269 Standard_Boolean& theIsArrowsExternal) const;
270
271 //! Adjusts aspect parameters according the text position:
272 //! extension size, vertical text alignment and flyout.
af203d54 273 //! @param theTextPos [in] the user defined 3d point of text position.
274 //! @param theExtensionSize [out] the adjusted extension size.
275 //! @param theAlignment [out] the horizontal label alignment.
91b16a64 276 //! @param theFlyout [out] the adjusted value of flyout.
af203d54 277 Standard_EXPORT void AdjustParameters (const gp_Pnt& theTextPos,
278 Standard_Real& theExtensionSize,
91b16a64 279 Prs3d_DimensionTextHorizontalPosition& theAlignment,
280 Standard_Real& theFlyout) const;
af203d54 281
60bf98ae 282protected:
283
201c2208 284 Standard_EXPORT virtual void ComputePlane();
60bf98ae 285
286 //! Checks if the plane includes three angle points to build dimension.
79104795 287 Standard_EXPORT virtual Standard_Boolean CheckPlane (const gp_Pln& thePlane) const Standard_OVERRIDE;
60bf98ae 288
79104795 289 Standard_EXPORT virtual Standard_Real ComputeValue() const Standard_OVERRIDE;
a6eb515f 290
291 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePM,
292 const Handle(Prs3d_Presentation)& thePresentation,
79104795 293 const Standard_Integer theMode = 0) Standard_OVERRIDE;
a6eb515f 294
60bf98ae 295 Standard_EXPORT virtual void ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
79104795 296 const Handle(SelectMgr_EntityOwner)& theOwner) Standard_OVERRIDE;
a6eb515f 297
60bf98ae 298protected:
a6eb515f 299
60bf98ae 300 //! Init angular dimension to measure angle between two linear edges.
301 //! @return TRUE if the angular dimension can be constructured
302 //! for the passed edges.
303 Standard_EXPORT Standard_Boolean InitTwoEdgesAngle (gp_Pln& theComputedPlane);
a6eb515f 304
60bf98ae 305 //! Init angular dimension to measure angle between two planar faces.
306 //! there is no user-defined poisitoning. So attach points are set
307 //! according to faces geometry (in origin of the first face basis surface).
308 //! @return TRUE if the angular dimension can be constructed
309 //! for the passed faces.
310 Standard_EXPORT Standard_Boolean InitTwoFacesAngle();
a6eb515f 311
60bf98ae 312 //! Init angular dimension to measure angle between two planar faces.
313 //! @param thePointOnFirstFace [in] the point which the dimension plane should pass through.
314 //! This point can lay on the one of the faces or not.
315 //! It will be projected on the first face and this point will be set
316 //! as the first point attach point.
317 //! It defines some kind of dimension positioning over the faces.
318 //! @return TRUE if the angular dimension can be constructed
319 //! for the passed faces.
787ff240 320 Standard_EXPORT Standard_Boolean InitTwoFacesAngle (const gp_Pnt& thePointOnFirstFace);
a6eb515f 321
60bf98ae 322 //! Init angular dimension to measure cone face.
323 //! @return TRUE if the angular dimension can be constructed
324 //! for the passed cone.
325 Standard_EXPORT Standard_Boolean InitConeAngle();
326
327 //! Check that the points forming angle are valid.
328 //! @return TRUE if the points met the following requirements:
329 //! The (P1, Center), (P2, Center) can be built.
330 //! The angle between the vectors > Precision::Angular().
331 Standard_EXPORT Standard_Boolean IsValidPoints (const gp_Pnt& theFirstPoint,
332 const gp_Pnt& theCenterPoint,
333 const gp_Pnt& theSecondPoint) const;
a6eb515f 334
ee905e84 335
336 //! Returns true if the arrow should be visible
337 //! @param theArrowType an arrow type
338 //! @return TRUE if the arrow should be visible
787ff240 339 Standard_EXPORT Standard_Boolean isArrowVisible (const PrsDim_TypeOfAngleArrowVisibility theArrowType) const;
ee905e84 340
60bf98ae 341private:
787ff240 342 PrsDim_TypeOfAngle myType; //!< type of angle
343 PrsDim_TypeOfAngleArrowVisibility myArrowsVisibility; //!< type of arrows visibility
a6eb515f 344
60bf98ae 345 gp_Pnt myFirstPoint;
346 gp_Pnt mySecondPoint;
347 gp_Pnt myCenterPoint;
348 TopoDS_Shape myFirstShape;
349 TopoDS_Shape mySecondShape;
350 TopoDS_Shape myThirdShape;
a6eb515f 351};
352
787ff240 353#endif // _PrsDim_AngleDimension_HeaderFile