1 // Copyright (c) 1999-2013 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _AIS_LengthDimension_HeaderFile
15 #define _AIS_LengthDimension_HeaderFile
18 #include <AIS_Dimension.hxx>
19 #include <AIS_Drawer.hxx>
20 #include <AIS_KindOfDimension.hxx>
21 #include <Geom_Plane.hxx>
22 #include <Geom_Transformation.hxx>
25 #include <Prs3d_DimensionAspect.hxx>
26 #include <Prs3d_Presentation.hxx>
27 #include <Prs3d_Projector.hxx>
28 #include <PrsMgr_PresentationManager3d.hxx>
29 #include <SelectMgr_Selection.hxx>
30 #include <Standard.hxx>
31 #include <Standard_Macro.hxx>
32 #include <Standard_DefineHandle.hxx>
34 #include <TopoDS_Vertex.hxx>
35 #include <TCollection_ExtendedString.hxx>
38 class TCollection_ExtendedString;
43 class Prs3d_Presentation;
44 class Prs3d_Projector;
45 class Geom_Transformation;
46 class SelectMgr_Selection;
51 class Standard_Transient;
52 class Handle(Standard_Type);
53 class Handle(AIS_Relation);
54 class AIS_LengthDimension;
56 DEFINE_STANDARD_HANDLE (AIS_LengthDimension, AIS_Dimension)
58 //! Length dimension. Can be constructued:
59 //! - Between two generic points.
60 //! - Between two vertices.
61 //! - Between two faces.
62 //! - Between two parallel edges.
63 //! - Between face and edge.
65 //! In case of two points (vertices) or one linear edge the user-defined plane
66 //! that includes this geometry is necessary to be set.
68 //! In case of face-edge, edge-vertex or face-face lengthes the automatic plane
69 //! computing is allowed. For this plane the third point is found on the
70 //! edge or on the face.
72 //! Please note that if the inappropriate geometry is defined
73 //! or the distance between measured points is less than
74 //! Precision::Confusion(), the dimension is invalid and its
75 //! presentation can not be computed.
76 class AIS_LengthDimension : public AIS_Dimension
80 //! Construct length dimension between face and edge.
81 //! Here dimension can be built without user-defined plane.
82 //! @param theFace [in] the face (first shape).
83 //! @param theEdge [in] the edge (second shape).
84 Standard_EXPORT AIS_LengthDimension (const TopoDS_Face& theFace,
85 const TopoDS_Edge& theEdge);
89 //! Construct length dimension between two faces.
90 //! @param theFirstFace [in] the first face (first shape).
91 //! @param theSecondFace [in] the second face (second shape).
92 Standard_EXPORT AIS_LengthDimension (const TopoDS_Face& theFirstFace,
93 const TopoDS_Face& theSecondFace);
95 //! Construct length dimension between two points in
96 //! the specified plane.
97 //! @param theFirstPoint [in] the first point.
98 //! @param theSecondPoint [in] the second point.
99 //! @param thePlane [in] the plane to orient dimension.
100 Standard_EXPORT AIS_LengthDimension (const gp_Pnt& theFirstPoint,
101 const gp_Pnt& theSecondPoint,
102 const gp_Pln& thePlane);
104 //! Construct length dimension between two arbitrary shapes in
105 //! the specified plane.
106 //! @param theFirstShape [in] the first shape.
107 //! @param theSecondShape [in] the second shape.
108 //! @param thePlane [in] the plane to orient dimension.
109 Standard_EXPORT AIS_LengthDimension (const TopoDS_Shape& theFirstShape,
110 const TopoDS_Shape& theSecondShape,
111 const gp_Pln& thePlane);
113 //! Construct length dimension of linear edge.
114 //! @param theEdge [in] the edge to measure.
115 //! @param thePlane [in] the plane to orient dimension.
116 Standard_EXPORT AIS_LengthDimension (const TopoDS_Edge& theEdge,
117 const gp_Pln& thePlane);
121 //! @return first attachement point.
122 const gp_Pnt& FirstPoint() const
127 //! @return second attachement point.
128 const gp_Pnt& SecondPoint() const
130 return mySecondPoint;
133 //! @return first attachement shape.
134 const TopoDS_Shape& FirstShape() const
139 //! @return second attachement shape.
140 const TopoDS_Shape& SecondShape() const
142 return mySecondShape;
147 //! Measure distance between two points.
148 //! The dimension will become invalid if the new distance between
149 //! attachement points is less than Precision::Confusion().
150 //! @param theFirstPoint [in] the first point.
151 //! @param theSecondPoint [in] the second point.
152 //! @param thePlane [in] the user-defined plane
153 Standard_EXPORT void SetMeasuredGeometry (const gp_Pnt& theFirstPoint,
154 const gp_Pnt& theSecondPoint,
155 const gp_Pln& thePlane);
157 //! Measure length of edge.
158 //! The dimension will become invalid if the new length of edge
159 //! is less than Precision::Confusion().
160 //! @param theEdge [in] the edge to measure.
161 //! @param thePlane [in] the user-defined plane
162 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Edge& theEdge,
163 const gp_Pln& thePlane);
165 //! Measure distance between two faces.
166 //! The dimension will become invalid if the distance can not
167 //! be measured or it is less than Precision::Confusion().
168 //! @param theFirstFace [in] the first face (first shape).
169 //! @param theSecondFace [in] the second face (second shape).
170 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
171 const TopoDS_Face& theSecondFace);
173 //! Measure distance between face and edge.
174 //! The dimension will become invalid if the distance can not
175 //! be measured or it is less than Precision::Confusion().
176 //! @param theFace [in] the face (first shape).
177 //! @param theEdge [in] the edge (second shape).
178 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFace,
179 const TopoDS_Edge& theEdge);
181 //! Measure distance between generic pair of shapes (edges, vertices, length),
182 //! where measuring is applicable.
183 //! @param theFirstShape [in] the first shape.
184 //! @param theSecondShape [in] the second shape.
185 Standard_EXPORT void SetMeasuredShapes (const TopoDS_Shape& theFirstShape,
186 const TopoDS_Shape& theSecondShape);
188 //! @return the display units string.
189 Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const;
191 //! @return the model units string.
192 Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const;
194 Standard_EXPORT virtual void SetDisplayUnits (const TCollection_AsciiString& theUnits);
196 Standard_EXPORT virtual void SetModelUnits (const TCollection_AsciiString& theUnits);
198 Standard_EXPORT virtual void SetTextPosition (const gp_Pnt& theTextPos);
200 Standard_EXPORT virtual const gp_Pnt GetTextPosition() const;
204 DEFINE_STANDARD_RTTI(AIS_LengthDimension)
208 //! Checks if the plane includes first and second points to build dimension.
209 Standard_EXPORT virtual Standard_Boolean CheckPlane (const gp_Pln& thePlane) const;
211 Standard_EXPORT virtual gp_Pln ComputePlane(const gp_Dir& theAttachDir) const;
213 Standard_EXPORT Standard_Real ComputeValue() const;
215 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
216 const Handle(Prs3d_Presentation)& thePresentation,
217 const Standard_Integer theMode = 0);
219 Standard_EXPORT virtual void ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
220 const Handle(SelectMgr_EntityOwner)& theEntityOwner);
224 //! Checks that distance between two points is valid.
225 //! @param theFirstPoint [in] the first point.
226 //! @param theSecondPoint [in] the second point.
227 Standard_EXPORT Standard_Boolean IsValidPoints (const gp_Pnt& theFirstPoint,
228 const gp_Pnt& theSecondPoint) const;
230 Standard_EXPORT Standard_Boolean InitTwoEdgesLength (const TopoDS_Edge & theFirstEdge,
231 const TopoDS_Edge& theSecondEdge,
234 //! Auxiliary method for InitTwoShapesPoints()
235 //! in case of the distance between edge and vertex.
236 //! Finds the point on the edge that is the closest one to <theVertex>.
237 //! @param theEdgeDir [out] is the direction on the edge to build
238 //! automatical plane.
239 Standard_EXPORT Standard_Boolean InitEdgeVertexLength (const TopoDS_Edge& theEdge,
240 const TopoDS_Vertex& theVertex,
242 Standard_Boolean isInfinite);
244 //! Auxiliary method for InitTwoShapesPoints()
245 //! in case of the distance between face and edge.
246 //! The first attachment point is first parameter point from <theEdge>.
247 //! Find the second attachment point which belongs to <theFace>
248 //! Iterate over the edges of the face and find the closest point according
249 //! to finded point on edge.
250 //! @param theEdgeDir [out] is the direction on the edge to build
251 //! automatical plane.
252 Standard_EXPORT Standard_Boolean InitEdgeFaceLength (const TopoDS_Edge& theEdge,
253 const TopoDS_Face& theFace,
256 //! Initialization of two attach points in case of two owner shapes.
257 Standard_EXPORT Standard_Boolean InitTwoShapesPoints (const TopoDS_Shape& theFirstShape,
258 const TopoDS_Shape& theSecondShape,
259 gp_Pln& theComputedPlane,
260 Standard_Boolean& theIsPlaneComputed);
262 //! Initialization of two attach points in case of one owner shape.
263 Standard_EXPORT Standard_Boolean InitOneShapePoints (const TopoDS_Shape& theShape);
268 gp_Pnt mySecondPoint;
269 TopoDS_Shape myFirstShape;
270 TopoDS_Shape mySecondShape;
273 #endif // _AIS_LengthDimension_HeaderFile