0030523: Visualization - Highlighting does not work anymore
[occt.git] / src / AIS / AIS_RadiusDimension.hxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 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_RadiusDimension_HeaderFile
16 #define _AIS_RadiusDimension_HeaderFile
17
18 #include <AIS.hxx>
19 #include <AIS_Dimension.hxx>
20 #include <gp_Pnt.hxx>
21 #include <gp_Circ.hxx>
22 #include <Standard.hxx>
23 #include <Standard_Macro.hxx>
24
25 class AIS_RadiusDimension;
26 DEFINE_STANDARD_HANDLE (AIS_RadiusDimension,AIS_Dimension)
27
28 //! Radius dimension. Can be constructued:
29 //! - On generic circle.
30 //! - On generic circle with user-defined anchor point on that circle.
31 //! - On generic shape containing geometry that can be measured
32 //!   by diameter dimension: circle wire, arc, circular face, etc.
33 //! The anchor point is the location of left attachement point of
34 //! dimension on the circle. It can be user-specified, or computed as
35 //! middle point on the arc. The radius dimension always lies in the
36 //! plane of the measured circle. The dimension is considered as
37 //! invalid if the user-specified anchor point is not lying on the circle,
38 //! if the radius of the circle is less than Precision::Confusion().
39 //! In case if the dimension is built on the arbitrary shape,
40 //! it can be considered as invalid if the shape does not contain
41 //! circle geometry.
42 class AIS_RadiusDimension : public AIS_Dimension
43 {
44 public:
45
46   //! Create radius dimension for the circle geometry.
47   //! @param theCircle [in] the circle to measure.
48   Standard_EXPORT AIS_RadiusDimension (const gp_Circ& theCircle);
49
50   //! Create radius dimension for the circle geometry and define its
51   //! orientation by location of the first point on that circle.
52   //! @param theCircle [in] the circle to measure.
53   //! @param theAnchorPoint [in] the point to define the position
54   //!        of the dimension attachment on the circle.
55   Standard_EXPORT AIS_RadiusDimension (const gp_Circ& theCircle,
56                                        const gp_Pnt& theAnchorPoint);
57
58   //! Create radius dimension for the arbitrary shape (if possible).
59   //! @param theShape [in] the shape to measure.
60   Standard_EXPORT AIS_RadiusDimension (const TopoDS_Shape& theShape);
61
62 public:
63
64   //! @return measured geometry circle.
65   const gp_Circ& Circle() const
66   {
67     return myCircle;
68   }
69
70   //! @return anchor point on circle for radius dimension.
71   const gp_Pnt& AnchorPoint() const
72   {
73     return myAnchorPoint;
74   }
75
76   //! @return the measured shape.
77   const TopoDS_Shape& Shape() const
78   {
79     return myShape;
80   }
81
82 public:
83
84   //! Measure radius of the circle.
85   //! The dimension will become invalid if the radius of the circle
86   //! is less than Precision::Confusion().
87   //! @param theCircle [in] the circle to measure.
88   void SetMeasuredGeometry (const gp_Circ& theCircle) { SetMeasuredGeometry (theCircle, gp_Pnt(), Standard_False); }
89
90   //! Measure radius of the circle and orient the dimension so
91   //! the dimension lines attaches to anchor point on the circle.
92   //! The dimension will become invalid if the radius of the circle
93   //! is less than Precision::Confusion().
94   //! @param theCircle [in] the circle to measure.
95   //! @param theAnchorPoint [in] the point to attach the dimension lines, should be on the circle
96   //! @param theHasAnchor   [in] should be set TRUE if theAnchorPoint should be used
97   Standard_EXPORT void SetMeasuredGeometry (const gp_Circ& theCircle,
98                                             const gp_Pnt& theAnchorPoint,
99                                             const Standard_Boolean theHasAnchor = Standard_True);
100
101   //! Measure radius on the passed shape, if applicable.
102   //! The dimension will become invalid if the passed shape is not
103   //! measurable or if measured diameter value is less than Precision::Confusion().
104   //! @param theShape [in] the shape to measure.
105   void SetMeasuredGeometry (const TopoDS_Shape& theShape) { SetMeasuredGeometry (theShape, gp_Pnt(), Standard_False); }
106
107   //! Measure radius on the passed shape, if applicable.
108   //! The dimension will become invalid if the passed shape is not
109   //! measurable or if measured diameter value is less than Precision::Confusion().
110   //! @param theShape [in] the shape to measure.
111   //! @param theAnchorPoint [in] the point to attach the dimension lines, should be on the circle
112   //! @param theHasAnchor   [in] should be set TRUE if theAnchorPoint should be used
113   Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Shape& theShape,
114                                             const gp_Pnt& theAnchorPoint,
115                                             const Standard_Boolean theHasAnchor = Standard_True);
116
117   //! @return the display units string.
118   Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const Standard_OVERRIDE;
119   
120   //! @return the model units string.
121   Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const Standard_OVERRIDE;
122
123   Standard_EXPORT virtual void SetDisplayUnits (const TCollection_AsciiString& theUnits) Standard_OVERRIDE;
124
125   Standard_EXPORT virtual void SetModelUnits (const TCollection_AsciiString& theUnits) Standard_OVERRIDE;
126
127   Standard_EXPORT virtual void SetTextPosition (const gp_Pnt& theTextPos) Standard_OVERRIDE;
128
129   Standard_EXPORT virtual const gp_Pnt GetTextPosition() const Standard_OVERRIDE;
130
131 public:
132
133   DEFINE_STANDARD_RTTIEXT(AIS_RadiusDimension,AIS_Dimension)
134
135 protected:
136
137   Standard_EXPORT virtual void ComputePlane();
138
139   //! Checks if anchor point and the center of the circle are on the plane.
140   Standard_EXPORT virtual Standard_Boolean CheckPlane (const gp_Pln& thePlane) const Standard_OVERRIDE;
141
142   Standard_EXPORT virtual Standard_Real ComputeValue() const Standard_OVERRIDE;
143
144   Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
145                                         const Handle(Prs3d_Presentation)& thePresentation,
146                                         const Standard_Integer theMode = 0) Standard_OVERRIDE;
147
148 protected:
149
150   Standard_EXPORT Standard_Boolean IsValidCircle (const gp_Circ& theCircle) const;
151
152   Standard_EXPORT Standard_Boolean IsValidAnchor (const gp_Circ& theCircle,
153                                                   const gp_Pnt& thePnt) const;
154
155 private:
156
157   gp_Circ      myCircle;
158   gp_Pnt       myAnchorPoint;
159   TopoDS_Shape myShape;
160 };
161
162 #endif // _AIS_RadiusDimension_HeaderFile