Salome HOME
#1404 Random crash with Shaper: AIS presentations: operation prs, result sketch prs...
[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   //! @param theUseLongestDistance [in] automatically fills first/second points of presentation by
71   //! the maximum distanced point of edges from the presentation center
72   Standard_EXPORT AIS_AngleDimension (const TopoDS_Edge& theFirstEdge,
73                                       const TopoDS_Edge& theSecondEdge,
74                                       const Standard_Boolean& theUseLongestDistance = Standard_True);
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   //! @param theUseLongestDistance [in] automatically fills first/second points of presentation by
156   //! the maximum distanced point of edges from the presentation center
157   Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Edge& theFirstEdge,
158                                    const TopoDS_Edge& theSecondEdge,
159                                    const Standard_Boolean& theUseLongestDistance = Standard_True);
160
161   //! Measures angle defined by three points.
162   //! @param theFirstPoint [in] the first point (point on first angle flyout).
163   //! @param theSecondPoint [in] the center point of angle dimension.
164   //! @param theThirdPoint [in] the second point (point on second angle flyout).
165   Standard_EXPORT void SetMeasuredGeometry (const gp_Pnt& theFirstPoint,
166                                             const gp_Pnt& theSecondPoint,
167                                             const gp_Pnt& theThridPoint);
168
169   //! Measures angle defined by three vertices.
170   //! @param theFirstVertex [in] the first vertex (vertex for first angle flyout).
171   //! @param theSecondVertex [in] the center vertex of angle dimension.
172   //! @param theThirdPoint [in] the second vertex (vertex for second angle flyout).
173   Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Vertex& theFirstVertex,
174                                             const TopoDS_Vertex& theSecondVertex,
175                                             const TopoDS_Vertex& theThirdVertex);
176
177   //! Measures angle of conical face.
178   //! @param theCone [in] the shape to measure.
179   Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theCone);
180
181   //! Measures angle between two planar faces.
182   //! @param theFirstFace [in] the first face.
183   //! @param theSecondFace [in] the second face..
184   Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
185                                             const TopoDS_Face& theSecondFace);
186
187   //! Measures angle between two planar faces.
188   //! @param theFirstFace [in] the first face.
189   //! @param theSecondFace [in] the second face.
190   //! @param thePoint [in] the point which the dimension plane should pass through.
191   //! This point can lay on the one of the faces or not.
192   Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
193                                             const TopoDS_Face& theSecondFace,
194                                             const gp_Pnt& thePoint);
195
196   //! @return the display units string.
197   Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const;
198   
199   //! @return the model units string.
200   Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const;
201
202   Standard_EXPORT virtual void SetDisplayUnits (const TCollection_AsciiString& theUnits);
203
204   Standard_EXPORT virtual void SetModelUnits (const TCollection_AsciiString& theUnits);
205
206   //! Principle of horizontal text alignment settings:
207   //! - divide circle into two halves according to attachment points
208   //! - if aTextPos is between attach points -> Center + positive flyout
209   //! - if aTextPos is not between attach points but in this half -> Left or Right + positive flyout
210   //! - if aTextPos is between reflections of attach points -> Center + negative flyout
211   //! - if aTextPos is not between reflections of attach points -> Left or Right + negative flyout
212   Standard_EXPORT virtual void SetTextPosition (const gp_Pnt& theTextPos);
213
214   Standard_EXPORT virtual const gp_Pnt GetTextPosition () const;
215
216   //! Sets state if the angle arc should be built reversing to the presentation plane.
217   //! Default state is not reversed
218   //! @param theUseReverse [in] the boolean state.
219   void SetAngleReversed(const Standard_Boolean& theUseReverse);
220
221   //! Sets visible state of angle arrows. Default value is true for both
222   //! @param theFirstArrowVisible [in] the visibility of the first arrow.
223   //! @param theSecondArrowVisible [in] the visibility of the second arrow.
224   void SetArrowVisible(const Standard_Boolean& theFirstArrowVisible,
225                        const Standard_Boolean& theSecondArrowVisible);
226
227 public:
228
229   DEFINE_STANDARD_RTTI (AIS_AngleDimension)
230
231 protected:
232
233   //! Initialization of fields that is common to all constructors. 
234   Standard_EXPORT void Init();
235
236   //! @param theFirstAttach [in] the first attachment point.
237   //! @param theSecondAttach [in] the second attachment point.
238   //! @param theCenter [in] the center point (center point of the angle).  
239   //! @return the center of the dimension arc (the main dimension line in case of angle). 
240   Standard_EXPORT gp_Pnt GetCenterOnArc (const gp_Pnt& theFirstAttach,
241                                          const gp_Pnt& theSecondAttach,
242                                          const gp_Pnt& theCenter) const;
243
244   //! Draws main dimension line (arc).
245   //! @param thePresentation [in] the dimension presentation.
246   //! @param theFirstAttach [in] the first attachment point.
247   //! @param theSecondAttach [in] the second attachment point.
248   //! @param theCenter [in] the center point (center point of the angle).
249   //! @param theRadius [in] the radius of the dimension arc.
250   //! @param theMode [in] the display mode.
251   Standard_EXPORT void DrawArc (const Handle(Prs3d_Presentation)& thePresentation,
252                                 const gp_Pnt& theFirstAttach,
253                                 const gp_Pnt& theSecondAttach,
254                                 const gp_Pnt& theCenter,
255                                 const Standard_Real theRadius,
256                                 const Standard_Integer theMode);
257
258   //! Draws main dimension line (arc) with text.
259   //! @param thePresentation [in] the dimension presentation.
260   //! @param theFirstAttach [in] the first attachment point.
261   //! @param theSecondAttach [in] the second attachment point.
262   //! @param theCenter [in] the center point (center point of the angle).
263   //! @param theText [in] the text label string.
264   //! @param theTextWidth [in] the text label width. 
265   //! @param theMode [in] the display mode.
266   //! @param theLabelPosition [in] the text label vertical and horizontal positioning option
267   //! respectively to the main dimension line. 
268   Standard_EXPORT void DrawArcWithText (const Handle(Prs3d_Presentation)& thePresentation,
269                                         const gp_Pnt& theFirstAttach,
270                                         const gp_Pnt& theSecondAttach,
271                                         const gp_Pnt& theCenter,
272                                         const TCollection_ExtendedString& theText,
273                                         const Standard_Real theTextWidth,
274                                         const Standard_Integer theMode,
275                                         const Standard_Integer theLabelPosition);
276
277   //! Fits text alignment relatively to the dimension line;
278   //! it computes the value of label position and arrow orientation
279   //! according set in the aspect and dimension properties.
280   //! @param theHorizontalTextPos [in] the horizontal alignment for text position.
281   //! @param theLabelPosition [out] the label position, contains bits that defines
282   //! vertical and horizontal alignment. (for internal usage in count text position).
283   //! @param theIsArrowExternal [out] is the arrows external,
284   //! if arrow orientation in the dimension aspect is Prs3d_DAO_Fit, it fits arrow
285   //! orientation automatically.
286   Standard_EXPORT void FitTextAlignment (const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos,
287                                          Standard_Integer& theLabelPosition,
288                                          Standard_Boolean& theIsArrowsExternal) const;
289
290   //! Adjusts aspect parameters according the text position:
291   //! extension size, vertical text alignment and flyout.
292   //! @param theTextPos [in] the user defined 3d point of text position.
293   //! @param theExtensionSize [out] the adjusted extension size.
294   //! @param theAlignment [out] the horizontal label alignment.
295   //! @param theFlyout [out] the adjusted value of flyout.
296   Standard_EXPORT void AdjustParameters (const gp_Pnt& theTextPos,
297                                          Standard_Real& theExtensionSize,
298                                          Prs3d_DimensionTextHorizontalPosition& theAlignment,
299                                          Standard_Real& theFlyout) const;
300
301 protected:
302
303   Standard_EXPORT virtual void ComputePlane();
304
305   //! Checks if the plane includes three angle points to build dimension.
306   Standard_EXPORT virtual Standard_Boolean CheckPlane (const gp_Pln& thePlane) const;
307
308   Standard_EXPORT virtual Standard_Real ComputeValue() const;
309
310   Standard_EXPORT  virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePM,
311                                          const Handle(Prs3d_Presentation)& thePresentation,
312                                          const Standard_Integer theMode = 0);
313
314   Standard_EXPORT virtual void ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
315                                                        const Handle(SelectMgr_EntityOwner)& theOwner);
316
317 protected:
318
319   //! Init angular dimension to measure angle between two linear edges.
320   //! @param theUseLongestDistance [in] automatically fills first/second points of presentation by
321   //! the maximum distanced point of edges from the presentation center
322   //! @return TRUE if the angular dimension can be constructured
323   //!         for the passed edges.
324   Standard_EXPORT Standard_Boolean InitTwoEdgesAngle (gp_Pln& theComputedPlane,
325                                     const Standard_Boolean& theUseLongestDistance = Standard_True);
326
327   //! Init angular dimension to measure angle between two planar faces.
328   //! there is no user-defined poisitoning. So attach points are set
329   //! according to faces geometry (in origin of the first face basis surface).
330   //! @return TRUE if the angular dimension can be constructed
331   //!         for the passed faces.
332   Standard_EXPORT Standard_Boolean InitTwoFacesAngle();
333
334   //! Init angular dimension to measure angle between two planar faces.
335   //! @param thePointOnFirstFace [in] the point which the dimension plane should pass through.
336   //! This point can lay on the one of the faces or not.
337   //! It will be projected on the first face and this point will be set
338   //! as the first point attach point.
339   //! It defines some kind of dimension positioning over the faces.
340   //! @return TRUE if the angular dimension can be constructed
341   //!         for the passed faces.
342   Standard_EXPORT Standard_Boolean InitTwoFacesAngle (const gp_Pnt thePointOnFirstFace);
343
344   //! Init angular dimension to measure cone face.
345   //! @return TRUE if the angular dimension can be constructed
346   //!              for the passed cone.
347   Standard_EXPORT Standard_Boolean InitConeAngle();
348
349   //! Check that the points forming angle are valid.
350   //! @return TRUE if the points met the following requirements:
351   //!         The (P1, Center), (P2, Center) can be built.
352   //!         The angle between the vectors > Precision::Angular().
353   Standard_EXPORT Standard_Boolean IsValidPoints (const gp_Pnt& theFirstPoint,
354                                                   const gp_Pnt& theCenterPoint,
355                                                   const gp_Pnt& theSecondPoint) const;
356
357 private:
358   Standard_Boolean myUseReverse;
359
360   Standard_Boolean myFirstArrowVisible;
361   Standard_Boolean mySecondArrowVisible;
362
363   gp_Pnt myFirstPoint;
364   gp_Pnt mySecondPoint;
365   gp_Pnt myCenterPoint;
366   TopoDS_Shape myFirstShape;
367   TopoDS_Shape mySecondShape;
368   TopoDS_Shape myThirdShape;
369 };
370
371 #endif // _AIS_AngleDimension_HeaderFile