0024425: Improve usage ergonomics of new dimension presentations
[occt.git] / src / AIS / AIS_DiameterDimension.hxx
CommitLineData
a6eb515f 1// Copyright (c) 1995-1999 Matra Datavision
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
60bf98ae 18
a6eb515f 19#ifndef _AIS_DiameterDimension_HeaderFile
20#define _AIS_DiameterDimension_HeaderFile
21
22#include <AIS.hxx>
23#include <AIS_Dimension.hxx>
24#include <gp_Pnt.hxx>
25#include <gp_Circ.hxx>
26#include <Standard.hxx>
27#include <Standard_Macro.hxx>
28#include <Standard_DefineHandle.hxx>
29
60bf98ae 30DEFINE_STANDARD_HANDLE (AIS_DiameterDimension, AIS_Dimension)
a6eb515f 31
60bf98ae 32//! Diameter dimension. Can be constructued:
33//! - On generic circle.
34//! - On generic circle with user-defined anchor point on that circle
35//! (dimension plane is oriented to follow the anchor point).
36//! - On generic circle in the specified plane.
37//! - On generic shape containing geometry that can be measured
38//! by diameter dimension: circle wire, circular face, etc.
39//! The anchor point is the location of the left attachement point of
40//! dimension on the circle.
41//! The anchor point computation is processed after dimension plane setting
42//! so that positive flyout direction stands with normal of the circle and
43//! the normal of the plane.
44//! If the plane is user-defined the anchor point was computed as intersection
45//! of the plane and the basis circle. Among two intersection points
46//! the one is selected so that positive flyout direction vector and
47//! the circle normal on the one side form the circle plane.
48//! (corner between positive flyout directio nand the circle normal is acute.)
49//! If the plane is computed automatically (by default it is the circle plane),
50//! the anchor point is the zero parameter point of the circle.
51//!
52//! The dimension is considered as invalid if the user-defined plane
53//! does not include th enachor point and th ecircle center,
54//! if the diameter of the circle is less than Precision::Confusion().
55//! In case if the dimension is built on the arbitrary shape, it can be considered
56//! as invalid if the shape does not contain circle geometry.
57//!
a6eb515f 58class AIS_DiameterDimension : public AIS_Dimension
59{
60public:
fe83e1ea 61
60bf98ae 62 //! Construct diameter dimension for the circle.
63 //! @param theCircle [in] the circle to measure.
64 Standard_EXPORT AIS_DiameterDimension (const gp_Circ& theCircle);
65
66 //! Construct diameter dimension for the circle and orient it correspondingly
67 //! to the passed plane.
68 //! @param theCircle [in] the circle to measure.
69 //! @param thePlane [in] the plane defining preferred orientation
70 //! for dimension.
71 Standard_EXPORT AIS_DiameterDimension (const gp_Circ& theCircle,
72 const gp_Pln& thePlane);
73
74 //! Construct diameter on the passed shape, if applicable.
75 //! @param theShape [in] the shape to measure.
76 Standard_EXPORT AIS_DiameterDimension (const TopoDS_Shape& theShape);
77
78 //! Construct diameter on the passed shape, if applicable - and
79 //! define the preferred plane to orient the dimension.
80 //! @param theShape [in] the shape to measure.
81 //! @param thePlane [in] the plane defining preferred orientation
82 //! for dimension.
83 Standard_EXPORT AIS_DiameterDimension (const TopoDS_Shape& theShape,
84 const gp_Pln& thePlane);
85
86public:
87
88 //! @return measured geometry circle.
89 const gp_Circ& Circle() const
90 {
91 return myCircle;
92 }
93
94 //! @return anchor point on circle for diameter dimension.
95 Standard_EXPORT gp_Pnt AnchorPoint();
96
97 //! @return the measured shape.
98 const TopoDS_Shape& Shape() const
99 {
100 return myShape;
101 }
102
103public:
104
105 //! Measure diameter of the circle.
106 //! The actual dimension plane is used for determining anchor points
107 //! on the circle to attach the dimension lines to.
108 //! The dimension will become invalid if the diameter of the circle
109 //! is less than Precision::Confusion().
110 //! @param theCircle [in] the circle to measure.
111 Standard_EXPORT void SetMeasuredGeometry (const gp_Circ& theCircle);
112
113 //! Measure diameter on the passed shape, if applicable.
114 //! The dimension will become invalid if the passed shape is not
115 //! measurable or if measured diameter value is less than Precision::Confusion().
116 //! @param theShape [in] the shape to measure.
117 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Shape& theShape);
a6eb515f 118
60bf98ae 119 //! @return the display units string.
120 Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits () const;
121
122 //! @return the model units string.
123 Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits () const;
124
125 Standard_EXPORT virtual void SetDisplayUnits (const TCollection_AsciiString& theUnits);
126
127 Standard_EXPORT virtual void SetModelUnits (const TCollection_AsciiString& theUnits);
128
129public:
a6eb515f 130
a6eb515f 131 DEFINE_STANDARD_RTTI(AIS_DiameterDimension)
132
133protected:
134
60bf98ae 135 //! Override this method to change logic of anchor point computation.
136 //! Computes anchor point. Its computation is based on the current
137 //! dimension plane. Therfore, anchor point is an intersection of plane
138 //! and circle.
139 //! ATTENTION!
140 //! 1) The plane should be set or computed before.
141 //! 2) The plane should inclide th ecircle center to be valid.
142 Standard_EXPORT virtual void ComputeAnchorPoint();
143
144 Standard_EXPORT virtual void ComputePlane();
145
146 //! Checks if the center of the circle is on the plane.
147 Standard_EXPORT virtual Standard_Boolean CheckPlane (const gp_Pln& thePlane) const;
d7bffd44 148
60bf98ae 149 Standard_EXPORT virtual Standard_Real ComputeValue() const;
a6eb515f 150
60bf98ae 151 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
152 const Handle(Prs3d_Presentation)& thePresentation,
153 const Standard_Integer theMode = 0);
a6eb515f 154
60bf98ae 155 Standard_EXPORT virtual void ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
156 const Handle(SelectMgr_EntityOwner)& theEntityOwner);
157
158protected:
159
160 //! Compute points on the circle sides for the specified dimension plane.
161 //! Program error exception is raised if the dimension plane "x" direction
162 //! is orthogonal to plane (the "impossible" case). The passed dimension plane
163 //! is the one specially computed to locate dimension presentation in circle.
164 //! @param theCircle [in] the circle.
165 //! @param thePlane [in] the dimension presentation plane computed.
166 //! @param theFirstPnt [out] the first point.
167 //! @param theSecondPnt [out] the second point.
168 Standard_EXPORT void ComputeSidePoints (const gp_Circ& theCircle,
169 const gp_Pln& thePlane,
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;
a6eb515f 177
d7bffd44 178private:
a6eb515f 179
60bf98ae 180 gp_Circ myCircle;
181 gp_Pnt myAnchorPoint;
182 TopoDS_Shape myShape;
a6eb515f 183};
60bf98ae 184
185#endif // _AIS_DiameterDimension_HeaderFile