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