1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _PrsDim_DiameterDimension_HeaderFile
16 #define _PrsDim_DiameterDimension_HeaderFile
18 #include <PrsDim_Dimension.hxx>
20 #include <gp_Circ.hxx>
21 #include <Standard.hxx>
22 #include <Standard_Macro.hxx>
23 #include <Standard_Type.hxx>
25 DEFINE_STANDARD_HANDLE(PrsDim_DiameterDimension, PrsDim_Dimension)
27 //! Diameter dimension. Can be constructued:
28 //! - On generic circle.
29 //! - On generic circle with user-defined anchor point on that circle
30 //! (dimension plane is oriented to follow the anchor point).
31 //! - On generic circle in the specified plane.
32 //! - On generic shape containing geometry that can be measured
33 //! by diameter dimension: circle wire, circular face, etc.
34 //! The anchor point is the location of the left attachement point of
35 //! dimension on the circle.
36 //! The anchor point computation is processed after dimension plane setting
37 //! so that positive flyout direction stands with normal of the circle and
38 //! the normal of the plane.
39 //! If the plane is user-defined the anchor point was computed as intersection
40 //! of the plane and the basis circle. Among two intersection points
41 //! the one is selected so that positive flyout direction vector and
42 //! the circle normal on the one side form the circle plane.
43 //! (corner between positive flyout directio nand the circle normal is acute.)
44 //! If the plane is computed automatically (by default it is the circle plane),
45 //! the anchor point is the zero parameter point of the circle.
47 //! The dimension is considered as invalid if the user-defined plane
48 //! does not include th enachor point and th ecircle center,
49 //! if the diameter of the circle is less than Precision::Confusion().
50 //! In case if the dimension is built on the arbitrary shape, it can be considered
51 //! as invalid if the shape does not contain circle geometry.
52 class PrsDim_DiameterDimension : public PrsDim_Dimension
54 DEFINE_STANDARD_RTTIEXT(PrsDim_DiameterDimension, PrsDim_Dimension)
57 //! Construct diameter dimension for the circle.
58 //! @param theCircle [in] the circle to measure.
59 Standard_EXPORT PrsDim_DiameterDimension (const gp_Circ& theCircle);
61 //! Construct diameter dimension for the circle and orient it correspondingly
62 //! to the passed plane.
63 //! @param theCircle [in] the circle to measure.
64 //! @param thePlane [in] the plane defining preferred orientation
66 Standard_EXPORT PrsDim_DiameterDimension (const gp_Circ& theCircle,
67 const gp_Pln& thePlane);
69 //! Construct diameter on the passed shape, if applicable.
70 //! @param theShape [in] the shape to measure.
71 Standard_EXPORT PrsDim_DiameterDimension (const TopoDS_Shape& theShape);
73 //! Construct diameter on the passed shape, if applicable - and
74 //! define the preferred plane to orient the dimension.
75 //! @param theShape [in] the shape to measure.
76 //! @param thePlane [in] the plane defining preferred orientation
78 Standard_EXPORT PrsDim_DiameterDimension (const TopoDS_Shape& theShape,
79 const gp_Pln& thePlane);
83 //! @return measured geometry circle.
84 const gp_Circ& Circle() const { return myCircle; }
86 //! @return anchor point on circle for diameter dimension.
87 Standard_EXPORT gp_Pnt AnchorPoint();
89 //! @return the measured shape.
90 const TopoDS_Shape& Shape() const { return myShape; }
94 //! Measure diameter of the circle.
95 //! The actual dimension plane is used for determining anchor points
96 //! on the circle to attach the dimension lines to.
97 //! The dimension will become invalid if the diameter of the circle
98 //! is less than Precision::Confusion().
99 //! @param theCircle [in] the circle to measure.
100 Standard_EXPORT void SetMeasuredGeometry (const gp_Circ& theCircle);
102 //! Measure diameter on the passed shape, if applicable.
103 //! The dimension will become invalid if the passed shape is not
104 //! measurable or if measured diameter value is less than Precision::Confusion().
105 //! @param theShape [in] the shape to measure.
106 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Shape& theShape);
108 //! @return the display units string.
109 Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const Standard_OVERRIDE;
111 //! @return the model units string.
112 Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const Standard_OVERRIDE;
114 Standard_EXPORT virtual void SetDisplayUnits (const TCollection_AsciiString& theUnits) Standard_OVERRIDE;
116 Standard_EXPORT virtual void SetModelUnits (const TCollection_AsciiString& theUnits) Standard_OVERRIDE;
118 Standard_EXPORT virtual void SetTextPosition (const gp_Pnt& theTextPos) Standard_OVERRIDE;
120 Standard_EXPORT virtual gp_Pnt GetTextPosition() const Standard_OVERRIDE;
124 //! Override this method to change logic of anchor point computation.
125 //! Computes anchor point. Its computation is based on the current
126 //! dimension plane. Therfore, anchor point is an intersection of plane
129 //! 1) The plane should be set or computed before.
130 //! 2) The plane should inclide th ecircle center to be valid.
131 Standard_EXPORT virtual void ComputeAnchorPoint();
133 Standard_EXPORT virtual void ComputePlane();
135 //! Checks if the center of the circle is on the plane.
136 Standard_EXPORT virtual Standard_Boolean CheckPlane (const gp_Pln& thePlane) const Standard_OVERRIDE;
138 Standard_EXPORT virtual Standard_Real ComputeValue() const Standard_OVERRIDE;
140 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
141 const Handle(Prs3d_Presentation)& thePresentation,
142 const Standard_Integer theMode = 0) Standard_OVERRIDE;
144 Standard_EXPORT virtual void ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
145 const Handle(SelectMgr_EntityOwner)& theEntityOwner) Standard_OVERRIDE;
149 //! Compute points on the circle sides for the dimension plane.
150 //! Program error exception is raised if the dimension plane "x" direction
151 //! is orthogonal to plane (the "impossible" case). The passed dimension plane
152 //! is the one specially computed to locate dimension presentation in circle.
153 //! @param theCircle [in] the circle.
154 //! @param theFirstPnt [out] the first point.
155 //! @param theSecondPnt [out] the second point.
156 Standard_EXPORT void ComputeSidePoints (const gp_Circ& theCircle,
158 gp_Pnt& theSecondPnt);
160 Standard_EXPORT Standard_Boolean IsValidCircle (const gp_Circ& theCircle) const;
162 Standard_EXPORT Standard_Boolean IsValidAnchor (const gp_Circ& theCircle,
163 const gp_Pnt& thePnt) const;
168 gp_Pnt myAnchorPoint;
169 TopoDS_Shape myShape;
172 #endif // _PrsDim_DiameterDimension_HeaderFile