Salome HOME
Support of nested option buttons
[modules/shaper.git] / src / SketcherPrs / 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_DefineHandle.hxx>
32 #include <TopoDS.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS_Face.hxx>
35 #include <TopoDS_Vertex.hxx>
36
37 DEFINE_STANDARD_HANDLE (AIS_AngleDimension_, AIS_Dimension)
38
39 //! Angle dimension. Can be constructed:
40 //! - on two intersected edges.
41 //! - on three points or vertices.
42 //! - on conical face.
43 //! - between two intersected faces.
44 //!
45 //! In case of three points or two intersected edges the dimension plane
46 //! (on which dimension presentation is built) can be computed uniquely
47 //! as through three defined points can be built only one plane.
48 //! Therefore, if user-defined plane differs from this one, the dimension can't be built.
49 //!
50 //! In cases of two planes automatic plane by default is built on point of the
51 //! origin of parametric space of the first face (the basis surface) so, that
52 //! the working plane and two faces intersection forms minimal angle between the faces.
53 //! User can define the other point which the dimension plane should pass through
54 //! using the appropriate constructor. This point can lay on the one of the faces or not.
55 //! Also user can define his own plane but it should pass through the three points
56 //! computed on the geometry initialization step (when the constructor or SetMeasuredGeometry() method
57 //! is called). 
58 //!
59 //! In case of the conical face the center point of the angle is the apex of the conical surface.
60 //! The attachment points are points of the first and the last parameter of the basis circle of the cone.
61 //!
62 class AIS_AngleDimension_ : public AIS_Dimension
63 {
64 public:
65
66   //! Constructs minimum angle dimension between two linear edges (where possible).
67   //! These two edges should be intersected by each other. Otherwise the geometry is not valid.
68   //! @param theFirstEdge [in] the first edge.
69   //! @param theSecondEdge [in] the second edge.
70   //! the maximum distanced point of edges from the presentation center
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   //! the maximum distanced point of edges from the presentation center
154   Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Edge& theFirstEdge,
155                                    const TopoDS_Edge& theSecondEdge);
156
157   //! Measures angle defined by three points.
158   //! @param theFirstPoint [in] the first point (point on first angle flyout).
159   //! @param theSecondPoint [in] the center point of angle dimension.
160   //! @param theThirdPoint [in] the second point (point on second angle flyout).
161   Standard_EXPORT void SetMeasuredGeometry (const gp_Pnt& theFirstPoint,
162                                             const gp_Pnt& theSecondPoint,
163                                             const gp_Pnt& theThridPoint);
164
165   //! Measures angle defined by three vertices.
166   //! @param theFirstVertex [in] the first vertex (vertex for first angle flyout).
167   //! @param theSecondVertex [in] the center vertex of angle dimension.
168   //! @param theThirdPoint [in] the second vertex (vertex for second angle flyout).
169   Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Vertex& theFirstVertex,
170                                             const TopoDS_Vertex& theSecondVertex,
171                                             const TopoDS_Vertex& theThirdVertex);
172
173   //! Measures angle of conical face.
174   //! @param theCone [in] the shape to measure.
175   Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theCone);
176
177   //! Measures angle between two planar faces.
178   //! @param theFirstFace [in] the first face.
179   //! @param theSecondFace [in] the second face..
180   Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
181                                             const TopoDS_Face& theSecondFace);
182
183   //! Measures angle between two planar faces.
184   //! @param theFirstFace [in] the first face.
185   //! @param theSecondFace [in] the second face.
186   //! @param thePoint [in] the point which the dimension plane should pass through.
187   //! This point can lay on the one of the faces or not.
188   Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
189                                             const TopoDS_Face& theSecondFace,
190                                             const gp_Pnt& thePoint);
191
192   //! @return the display units string.
193   Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const;
194   
195   //! @return the model units string.
196   Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const;
197
198   Standard_EXPORT virtual void SetDisplayUnits (const TCollection_AsciiString& theUnits);
199
200   Standard_EXPORT virtual void SetModelUnits (const TCollection_AsciiString& theUnits);
201
202   //! Principle of horizontal text alignment settings:
203   //! - divide circle into two halves according to attachment points
204   //! - if aTextPos is between attach points -> Center + positive flyout
205   //! - if aTextPos is not between attach points but in this half -> Left or Right + positive flyout
206   //! - if aTextPos is between reflections of attach points -> Center + negative flyout
207   //! - if aTextPos is not between reflections of attach points -> Left or Right + negative flyout
208   Standard_EXPORT virtual void SetTextPosition (const gp_Pnt& theTextPos);
209
210   Standard_EXPORT virtual const gp_Pnt GetTextPosition () const;
211
212   //! Sets state if the angle arc should be built reversing to the presentation plane.
213   //! Default state is not reversed
214   //! @param theUseReverse [in] the boolean state.
215   void SetAngleReversed(const Standard_Boolean& theUseReverse);
216
217   //! Sets visible state of angle arrows. Default value is true for both
218   //! @param theFirstArrowVisible [in] the visibility of the first arrow.
219   //! @param theSecondArrowVisible [in] the visibility of the second arrow.
220   void SetArrowVisible(const Standard_Boolean& theFirstArrowVisible,
221                        const Standard_Boolean& theSecondArrowVisible);
222
223 public:
224
225   DEFINE_STANDARD_RTTI (AIS_AngleDimension_)
226
227 protected:
228
229   //! Initialization of fields that is common to all constructors. 
230   Standard_EXPORT void Init();
231
232   //! @param theFirstAttach [in] the first attachment point.
233   //! @param theSecondAttach [in] the second attachment point.
234   //! @param theCenter [in] the center point (center point of the angle).  
235   //! @return the center of the dimension arc (the main dimension line in case of angle). 
236   Standard_EXPORT gp_Pnt GetCenterOnArc (const gp_Pnt& theFirstAttach,
237                                          const gp_Pnt& theSecondAttach,
238                                          const gp_Pnt& theCenter) const;
239
240   //! Draws main dimension line (arc).
241   //! @param thePresentation [in] the dimension presentation.
242   //! @param theFirstAttach [in] the first attachment point.
243   //! @param theSecondAttach [in] the second attachment point.
244   //! @param theCenter [in] the center point (center point of the angle).
245   //! @param theRadius [in] the radius of the dimension arc.
246   //! @param theMode [in] the display mode.
247   Standard_EXPORT void DrawArc (const Handle(Prs3d_Presentation)& thePresentation,
248                                 const gp_Pnt& theFirstAttach,
249                                 const gp_Pnt& theSecondAttach,
250                                 const gp_Pnt& theCenter,
251                                 const Standard_Real theRadius,
252                                 const Standard_Integer theMode);
253
254   //! Draws main dimension line (arc) with text.
255   //! @param thePresentation [in] the dimension presentation.
256   //! @param theFirstAttach [in] the first attachment point.
257   //! @param theSecondAttach [in] the second attachment point.
258   //! @param theCenter [in] the center point (center point of the angle).
259   //! @param theText [in] the text label string.
260   //! @param theTextWidth [in] the text label width. 
261   //! @param theMode [in] the display mode.
262   //! @param theLabelPosition [in] the text label vertical and horizontal positioning option
263   //! respectively to the main dimension line. 
264   Standard_EXPORT void DrawArcWithText (const Handle(Prs3d_Presentation)& thePresentation,
265                                         const gp_Pnt& theFirstAttach,
266                                         const gp_Pnt& theSecondAttach,
267                                         const gp_Pnt& theCenter,
268                                         const TCollection_ExtendedString& theText,
269                                         const Standard_Real theTextWidth,
270                                         const Standard_Integer theMode,
271                                         const Standard_Integer theLabelPosition);
272
273   //! Fits text alignment relatively to the dimension line;
274   //! it computes the value of label position and arrow orientation
275   //! according set in the aspect and dimension properties.
276   //! @param theHorizontalTextPos [in] the horizontal alignment for text position.
277   //! @param theLabelPosition [out] the label position, contains bits that defines
278   //! vertical and horizontal alignment. (for internal usage in count text position).
279   //! @param theIsArrowExternal [out] is the arrows external,
280   //! if arrow orientation in the dimension aspect is Prs3d_DAO_Fit, it fits arrow
281   //! orientation automatically.
282   Standard_EXPORT void FitTextAlignment (const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos,
283                                          Standard_Integer& theLabelPosition,
284                                          Standard_Boolean& theIsArrowsExternal) const;
285
286   //! Adjusts aspect parameters according the text position:
287   //! extension size, vertical text alignment and flyout.
288   //! @param theTextPos [in] the user defined 3d point of text position.
289   //! @param theExtensionSize [out] the adjusted extension size.
290   //! @param theAlignment [out] the horizontal label alignment.
291   //! @param theFlyout [out] the adjusted value of flyout.
292   Standard_EXPORT void AdjustParameters (const gp_Pnt& theTextPos,
293                                          Standard_Real& theExtensionSize,
294                                          Prs3d_DimensionTextHorizontalPosition& theAlignment,
295                                          Standard_Real& theFlyout) const;
296
297 protected:
298
299   Standard_EXPORT virtual void ComputePlane();
300
301   //! Checks if the plane includes three angle points to build dimension.
302   Standard_EXPORT virtual Standard_Boolean CheckPlane (const gp_Pln& thePlane) const;
303
304   Standard_EXPORT virtual Standard_Real ComputeValue() const;
305
306   Standard_EXPORT  virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePM,
307                                          const Handle(Prs3d_Presentation)& thePresentation,
308                                          const Standard_Integer theMode = 0);
309
310   Standard_EXPORT virtual void ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
311                                                        const Handle(SelectMgr_EntityOwner)& theOwner);
312
313 protected:
314
315   //! Init angular dimension to measure angle between two linear edges.
316   //! the maximum distanced point of edges from the presentation center
317   //! @return TRUE if the angular dimension can be constructured
318   //!         for the passed edges.
319   Standard_EXPORT Standard_Boolean InitTwoEdgesAngle (gp_Pln& theComputedPlane);
320
321   //! Init angular dimension to measure angle between two planar faces.
322   //! there is no user-defined poisitoning. So attach points are set
323   //! according to faces geometry (in origin of the first face basis surface).
324   //! @return TRUE if the angular dimension can be constructed
325   //!         for the passed faces.
326   Standard_EXPORT Standard_Boolean InitTwoFacesAngle();
327
328   //! Init angular dimension to measure angle between two planar faces.
329   //! @param thePointOnFirstFace [in] the point which the dimension plane should pass through.
330   //! This point can lay on the one of the faces or not.
331   //! It will be projected on the first face and this point will be set
332   //! as the first point attach point.
333   //! It defines some kind of dimension positioning over the faces.
334   //! @return TRUE if the angular dimension can be constructed
335   //!         for the passed faces.
336   Standard_EXPORT Standard_Boolean InitTwoFacesAngle (const gp_Pnt thePointOnFirstFace);
337
338   //! Init angular dimension to measure cone face.
339   //! @return TRUE if the angular dimension can be constructed
340   //!              for the passed cone.
341   Standard_EXPORT Standard_Boolean InitConeAngle();
342
343   //! Check that the points forming angle are valid.
344   //! @return TRUE if the points met the following requirements:
345   //!         The (P1, Center), (P2, Center) can be built.
346   //!         The angle between the vectors > Precision::Angular().
347   Standard_EXPORT Standard_Boolean IsValidPoints (const gp_Pnt& theFirstPoint,
348                                                   const gp_Pnt& theCenterPoint,
349                                                   const gp_Pnt& theSecondPoint) const;
350
351 private:
352   Standard_Boolean myUseReverse;
353
354   Standard_Boolean myFirstArrowVisible;
355   Standard_Boolean mySecondArrowVisible;
356
357   gp_Pnt myFirstPoint;
358   gp_Pnt mySecondPoint;
359   gp_Pnt myCenterPoint;
360   TopoDS_Shape myFirstShape;
361   TopoDS_Shape mySecondShape;
362   TopoDS_Shape myThirdShape;
363 };
364
365 #endif // _AIS_AngleDimension_HeaderFile