0030726: Visualization - change Selected state of owner in AIS_Selection
[occt.git] / src / AIS / AIS_DiameterDimension.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
16 #ifndef _AIS_DiameterDimension_HeaderFile
17 #define _AIS_DiameterDimension_HeaderFile
18
19 #include <AIS.hxx>
20 #include <AIS_Dimension.hxx>
21 #include <gp_Pnt.hxx>
22 #include <gp_Circ.hxx>
23 #include <Standard.hxx>
24 #include <Standard_Macro.hxx>
25 #include <Standard_Type.hxx>
26
27 class AIS_DiameterDimension;
28 DEFINE_STANDARD_HANDLE (AIS_DiameterDimension, AIS_Dimension)
29
30 //! Diameter dimension. Can be constructued:
31 //! - On generic circle.
32 //! - On generic circle with user-defined anchor point on that circle
33 //!   (dimension plane is oriented to follow the anchor point).
34 //! - On generic circle in the specified plane.
35 //! - On generic shape containing geometry that can be measured
36 //!   by diameter dimension: circle wire, circular face, etc.
37 //! The anchor point is the location of the left attachement point of
38 //! dimension on the circle.
39 //! The anchor point computation is processed after dimension plane setting
40 //! so that positive flyout direction stands with normal of the circle and
41 //! the normal of the plane.
42 //! If the plane is user-defined the anchor point was computed as intersection
43 //! of the plane and the basis circle. Among two intersection points
44 //! the one is selected so that positive flyout direction vector and
45 //! the circle normal on the one side form the circle plane.
46 //! (corner between positive flyout directio nand the circle normal is acute.)
47 //! If the plane is computed automatically (by default it is the circle plane),
48 //! the anchor point is the zero parameter point of the circle.
49 //!
50 //! The dimension is considered as invalid if the user-defined plane
51 //! does not include th enachor point and th ecircle center,
52 //! if the diameter of the circle is less than Precision::Confusion().
53 //! In case if the dimension is built on the arbitrary shape, it can be considered
54 //! as invalid if the shape does not contain circle geometry.
55 //!
56 class AIS_DiameterDimension : public AIS_Dimension
57 {
58 public:
59
60   //! Construct diameter dimension for the circle.
61   //! @param theCircle [in] the circle to measure.
62   Standard_EXPORT AIS_DiameterDimension (const gp_Circ& theCircle);
63
64   //! Construct diameter dimension for the circle and orient it correspondingly
65   //! to the passed plane.
66   //! @param theCircle [in] the circle to measure.
67   //! @param thePlane [in] the plane defining preferred orientation
68   //!        for dimension.
69   Standard_EXPORT AIS_DiameterDimension (const gp_Circ& theCircle,
70                                          const gp_Pln& thePlane);
71
72   //! Construct diameter on the passed shape, if applicable.
73   //! @param theShape [in] the shape to measure.
74   Standard_EXPORT AIS_DiameterDimension (const TopoDS_Shape& theShape);
75
76   //! Construct diameter on the passed shape, if applicable - and
77   //! define the preferred plane to orient the dimension.
78   //! @param theShape [in] the shape to measure.
79   //! @param thePlane [in] the plane defining preferred orientation
80   //!        for dimension.
81   Standard_EXPORT AIS_DiameterDimension (const TopoDS_Shape& theShape,
82                                          const gp_Pln& thePlane);
83
84 public:
85
86   //! @return measured geometry circle.
87   const gp_Circ& Circle() const
88   {
89     return myCircle;
90   }
91
92   //! @return anchor point on circle for diameter dimension.
93   Standard_EXPORT gp_Pnt AnchorPoint();
94
95   //! @return the measured shape.
96   const TopoDS_Shape& Shape() const
97   {
98     return myShape;
99   }
100
101 public:
102
103   //! Measure diameter of the circle.
104   //! The actual dimension plane is used for determining anchor points
105   //! on the circle to attach the dimension lines to.
106   //! The dimension will become invalid if the diameter of the circle
107   //! is less than Precision::Confusion().
108   //! @param theCircle [in] the circle to measure.
109   Standard_EXPORT void SetMeasuredGeometry (const gp_Circ& theCircle);
110
111   //! Measure diameter on the passed shape, if applicable.
112   //! The dimension will become invalid if the passed shape is not
113   //! measurable or if measured diameter value is less than Precision::Confusion().
114   //! @param theShape [in] the shape to measure.
115   Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Shape& theShape);
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_DiameterDimension,AIS_Dimension)
134
135 protected:
136
137   //! Override this method to change logic of anchor point computation.
138   //! Computes anchor point. Its computation is based on the current
139   //! dimension plane. Therfore, anchor point is an intersection of plane
140   //! and circle.
141   //! ATTENTION!
142   //! 1) The plane should be set or computed before.
143   //! 2) The plane should inclide th ecircle center to be valid.
144   Standard_EXPORT virtual void ComputeAnchorPoint();
145
146   Standard_EXPORT virtual void ComputePlane();
147
148   //! Checks if the center of the circle is on the plane.
149   Standard_EXPORT virtual Standard_Boolean CheckPlane (const gp_Pln& thePlane) const Standard_OVERRIDE;
150
151   Standard_EXPORT virtual Standard_Real ComputeValue() const Standard_OVERRIDE;
152
153   Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
154                                         const Handle(Prs3d_Presentation)& thePresentation,
155                                         const Standard_Integer theMode = 0) Standard_OVERRIDE;
156
157   Standard_EXPORT virtual void ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
158                                                        const Handle(SelectMgr_EntityOwner)& theEntityOwner) Standard_OVERRIDE;
159
160 protected:
161
162   //! Compute points on the circle sides for the dimension plane.
163   //! Program error exception is raised if the dimension plane "x" direction 
164   //! is orthogonal to plane (the "impossible" case). The passed dimension plane
165   //! is the one specially computed to locate dimension presentation in circle.
166   //! @param theCircle [in] the circle.
167   //! @param theFirstPnt [out] the first point.
168   //! @param theSecondPnt [out] the second point.
169   Standard_EXPORT void ComputeSidePoints (const gp_Circ& theCircle,
170                                           gp_Pnt& theFirstPnt,
171                                           gp_Pnt& theSecondPnt);
172
173   Standard_EXPORT Standard_Boolean IsValidCircle (const gp_Circ& theCircle) const;
174
175   Standard_EXPORT Standard_Boolean IsValidAnchor (const gp_Circ& theCircle,
176                                                   const gp_Pnt& thePnt) const;
177
178 private:
179
180   gp_Circ          myCircle;
181   gp_Pnt           myAnchorPoint;
182   TopoDS_Shape     myShape;
183 };
184
185 #endif // _AIS_DiameterDimension_HeaderFile