0027818: Visualization - provide an interface to define highlight presentation properties
[occt.git] / src / AIS / AIS_AngleDimension.hxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2013 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #ifndef _AIS_AngleDimension_HeaderFile
16 #define _AIS_AngleDimension_HeaderFile
17
18 #include <AIS_Dimension.hxx>
19 #include <Geom_Plane.hxx>
20 #include <Geom_Line.hxx>
21 #include <Geom_Transformation.hxx>
22 #include <gp.hxx>
23 #include <gp_Ax1.hxx>
24 #include <gp_Dir.hxx>
25 #include <gp_Pnt.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>
32 #include <TopoDS.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS_Face.hxx>
35 #include <TopoDS_Vertex.hxx>
36
37 class AIS_AngleDimension;
38 DEFINE_STANDARD_HANDLE (AIS_AngleDimension, AIS_Dimension)
39
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 //!
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
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.
62 //!
63 class AIS_AngleDimension : public AIS_Dimension
64 {
65 public:
66
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);
73
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);
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).
86   Standard_EXPORT AIS_AngleDimension (const TopoDS_Vertex& theFirstVertex,
87                                       const TopoDS_Vertex& theSecondVertex,
88                                       const TopoDS_Vertex& theThirdVertex);
89
90   //! Constructs angle dimension for the cone face.
91   //! @param theCone [in] the conical face.
92   Standard_EXPORT AIS_AngleDimension (const TopoDS_Face& theCone);
93
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);
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.
105   Standard_EXPORT AIS_AngleDimension (const TopoDS_Face& theFirstFace,
106                                       const TopoDS_Face& theSecondFace,
107                                       const gp_Pnt& thePoint);
108
109 public:
110
111   //! @return first point forming the angle.
112   const gp_Pnt& FirstPoint() const
113   {
114     return myFirstPoint;
115   }
116
117   //! @return second point forming the angle.
118   const gp_Pnt& SecondPoint() const
119   {
120     return mySecondPoint;
121   }
122
123   //! @return center point forming the angle.
124   const gp_Pnt& CenterPoint() const
125   {
126     return myCenterPoint;
127   }
128
129   //! @return first argument shape.
130   const TopoDS_Shape& FirstShape() const
131   {
132     return myFirstShape;
133   }
134
135   //! @return second argument shape.
136   const TopoDS_Shape& SecondShape() const
137   {
138     return mySecondShape;
139   }
140
141   //! @return third argument shape.
142   const TopoDS_Shape& ThirdShape() const
143   {
144     return myThirdShape;
145   }
146
147 public:
148
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);
155
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);
163
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);
171
172   //! Measures angle of conical face.
173   //! @param theCone [in] the shape to measure.
174   Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theCone);
175
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);
181
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);
190
191   //! @return the display units string.
192   Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const Standard_OVERRIDE;
193   
194   //! @return the model units string.
195   Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const Standard_OVERRIDE;
196
197   Standard_EXPORT virtual void SetDisplayUnits (const TCollection_AsciiString& theUnits) Standard_OVERRIDE;
198
199   Standard_EXPORT virtual void SetModelUnits (const TCollection_AsciiString& theUnits) Standard_OVERRIDE;
200
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;
208
209   Standard_EXPORT virtual const gp_Pnt GetTextPosition () const Standard_OVERRIDE;
210
211 public:
212
213   DEFINE_STANDARD_RTTIEXT(AIS_AngleDimension,AIS_Dimension)
214
215 protected:
216
217   //! Initialization of fields that is common to all constructors. 
218   Standard_EXPORT void Init();
219
220   //! Gets plane normal for minimal angle.
221   //! Dimension computation is based on three attach points and plane normal.
222   //! Based on this normal angle arc, arrows and extensions are constructed.
223   gp_Dir GetNormalForMinAngle() const;
224
225   //! @param theFirstAttach [in] the first attachment point.
226   //! @param theSecondAttach [in] the second attachment point.
227   //! @param theCenter [in] the center point (center point of the angle).  
228   //! @return the center of the dimension arc (the main dimension line in case of angle). 
229   Standard_EXPORT gp_Pnt GetCenterOnArc (const gp_Pnt& theFirstAttach,
230                                          const gp_Pnt& theSecondAttach,
231                                          const gp_Pnt& theCenter) const;
232
233   //! Draws main dimension line (arc).
234   //! @param thePresentation [in] the dimension presentation.
235   //! @param theFirstAttach [in] the first attachment point.
236   //! @param theSecondAttach [in] the second attachment point.
237   //! @param theCenter [in] the center point (center point of the angle).
238   //! @param theRadius [in] the radius of the dimension arc.
239   //! @param theMode [in] the display mode.
240   Standard_EXPORT void DrawArc (const Handle(Prs3d_Presentation)& thePresentation,
241                                 const gp_Pnt& theFirstAttach,
242                                 const gp_Pnt& theSecondAttach,
243                                 const gp_Pnt& theCenter,
244                                 const Standard_Real theRadius,
245                                 const Standard_Integer theMode);
246
247   //! Draws main dimension line (arc) with text.
248   //! @param thePresentation [in] the dimension presentation.
249   //! @param theFirstAttach [in] the first attachment point.
250   //! @param theSecondAttach [in] the second attachment point.
251   //! @param theCenter [in] the center point (center point of the angle).
252   //! @param theText [in] the text label string.
253   //! @param theTextWidth [in] the text label width. 
254   //! @param theMode [in] the display mode.
255   //! @param theLabelPosition [in] the text label vertical and horizontal positioning option
256   //! respectively to the main dimension line. 
257   Standard_EXPORT void DrawArcWithText (const Handle(Prs3d_Presentation)& thePresentation,
258                                         const gp_Pnt& theFirstAttach,
259                                         const gp_Pnt& theSecondAttach,
260                                         const gp_Pnt& theCenter,
261                                         const TCollection_ExtendedString& theText,
262                                         const Standard_Real theTextWidth,
263                                         const Standard_Integer theMode,
264                                         const Standard_Integer theLabelPosition);
265
266   //! Fits text alignment relatively to the dimension line;
267   //! it computes the value of label position and arrow orientation
268   //! according set in the aspect and dimension properties.
269   //! @param theHorizontalTextPos [in] the horizontal alignment for text position.
270   //! @param theLabelPosition [out] the label position, contains bits that defines
271   //! vertical and horizontal alignment. (for internal usage in count text position).
272   //! @param theIsArrowExternal [out] is the arrows external,
273   //! if arrow orientation in the dimension aspect is Prs3d_DAO_Fit, it fits arrow
274   //! orientation automatically.
275   Standard_EXPORT void FitTextAlignment (const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos,
276                                          Standard_Integer& theLabelPosition,
277                                          Standard_Boolean& theIsArrowsExternal) const;
278
279   //! Adjusts aspect parameters according the text position:
280   //! extension size, vertical text alignment and flyout.
281   //! @param theTextPos [in] the user defined 3d point of text position.
282   //! @param theExtensionSize [out] the adjusted extension size.
283   //! @param theAlignment [out] the horizontal label alignment.
284   //! @param theFlyout [out] the adjusted value of flyout.
285   Standard_EXPORT void AdjustParameters (const gp_Pnt& theTextPos,
286                                          Standard_Real& theExtensionSize,
287                                          Prs3d_DimensionTextHorizontalPosition& theAlignment,
288                                          Standard_Real& theFlyout) const;
289
290 protected:
291
292   Standard_EXPORT virtual void ComputePlane();
293
294   //! Checks if the plane includes three angle points to build dimension.
295   Standard_EXPORT virtual Standard_Boolean CheckPlane (const gp_Pln& thePlane) const Standard_OVERRIDE;
296
297   Standard_EXPORT virtual Standard_Real ComputeValue() const Standard_OVERRIDE;
298
299   Standard_EXPORT  virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePM,
300                                          const Handle(Prs3d_Presentation)& thePresentation,
301                                          const Standard_Integer theMode = 0) Standard_OVERRIDE;
302
303   Standard_EXPORT virtual void ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
304                                                        const Handle(SelectMgr_EntityOwner)& theOwner) Standard_OVERRIDE;
305
306 protected:
307
308   //! Init angular dimension to measure angle between two linear edges.
309   //! @return TRUE if the angular dimension can be constructured
310   //!         for the passed edges.
311   Standard_EXPORT Standard_Boolean InitTwoEdgesAngle (gp_Pln& theComputedPlane);
312
313   //! Init angular dimension to measure angle between two planar faces.
314   //! there is no user-defined poisitoning. So attach points are set
315   //! according to faces geometry (in origin of the first face basis surface).
316   //! @return TRUE if the angular dimension can be constructed
317   //!         for the passed faces.
318   Standard_EXPORT Standard_Boolean InitTwoFacesAngle();
319
320   //! Init angular dimension to measure angle between two planar faces.
321   //! @param thePointOnFirstFace [in] the point which the dimension plane should pass through.
322   //! This point can lay on the one of the faces or not.
323   //! It will be projected on the first face and this point will be set
324   //! as the first point attach point.
325   //! It defines some kind of dimension positioning over the faces.
326   //! @return TRUE if the angular dimension can be constructed
327   //!         for the passed faces.
328   Standard_EXPORT Standard_Boolean InitTwoFacesAngle (const gp_Pnt thePointOnFirstFace);
329
330   //! Init angular dimension to measure cone face.
331   //! @return TRUE if the angular dimension can be constructed
332   //!              for the passed cone.
333   Standard_EXPORT Standard_Boolean InitConeAngle();
334
335   //! Check that the points forming angle are valid.
336   //! @return TRUE if the points met the following requirements:
337   //!         The (P1, Center), (P2, Center) can be built.
338   //!         The angle between the vectors > Precision::Angular().
339   Standard_EXPORT Standard_Boolean IsValidPoints (const gp_Pnt& theFirstPoint,
340                                                   const gp_Pnt& theCenterPoint,
341                                                   const gp_Pnt& theSecondPoint) const;
342
343 private:
344
345   gp_Pnt myFirstPoint;
346   gp_Pnt mySecondPoint;
347   gp_Pnt myCenterPoint;
348   TopoDS_Shape myFirstShape;
349   TopoDS_Shape mySecondShape;
350   TopoDS_Shape myThirdShape;
351 };
352
353 #endif // _AIS_AngleDimension_HeaderFile