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_KindOfDimension.hxx>
20 #include <Geom_Plane.hxx>
21 #include <Geom_Transformation.hxx>
24 #include <Prs3d_DimensionAspect.hxx>
25 #include <Prs3d_Drawer.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_Type.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;
50 class Standard_Transient;
51 class AIS_LengthDimension;
53 DEFINE_STANDARD_HANDLE (AIS_LengthDimension, AIS_Dimension)
55 //! Length dimension. Can be constructued:
56 //! - Between two generic points.
57 //! - Between two vertices.
58 //! - Between two faces.
59 //! - Between two parallel edges.
60 //! - Between face and edge.
62 //! In case of two points (vertices) or one linear edge the user-defined plane
63 //! that includes this geometry is necessary to be set.
65 //! In case of face-edge, edge-vertex or face-face lengthes the automatic plane
66 //! computing is allowed. For this plane the third point is found on the
67 //! edge or on the face.
69 //! Please note that if the inappropriate geometry is defined
70 //! or the distance between measured points is less than
71 //! Precision::Confusion(), the dimension is invalid and its
72 //! presentation can not be computed.
73 class AIS_LengthDimension : public AIS_Dimension
77 //! Construct length dimension between face and edge.
78 //! Here dimension can be built without user-defined plane.
79 //! @param theFace [in] the face (first shape).
80 //! @param theEdge [in] the edge (second shape).
81 Standard_EXPORT AIS_LengthDimension (const TopoDS_Face& theFace,
82 const TopoDS_Edge& theEdge);
84 //! Construct length dimension between two faces.
85 //! @param theFirstFace [in] the first face (first shape).
86 //! @param theSecondFace [in] the second face (second shape).
87 Standard_EXPORT AIS_LengthDimension (const TopoDS_Face& theFirstFace,
88 const TopoDS_Face& theSecondFace);
90 //! Construct length dimension between two points in
91 //! the specified plane.
92 //! @param theFirstPoint [in] the first point.
93 //! @param theSecondPoint [in] the second point.
94 //! @param thePlane [in] the plane to orient dimension.
95 Standard_EXPORT AIS_LengthDimension (const gp_Pnt& theFirstPoint,
96 const gp_Pnt& theSecondPoint,
97 const gp_Pln& thePlane);
99 //! Construct length dimension between two arbitrary shapes in
100 //! the specified plane.
101 //! @param theFirstShape [in] the first shape.
102 //! @param theSecondShape [in] the second shape.
103 //! @param thePlane [in] the plane to orient dimension.
104 Standard_EXPORT AIS_LengthDimension (const TopoDS_Shape& theFirstShape,
105 const TopoDS_Shape& theSecondShape,
106 const gp_Pln& thePlane);
108 //! Construct length dimension of linear edge.
109 //! @param theEdge [in] the edge to measure.
110 //! @param thePlane [in] the plane to orient dimension.
111 Standard_EXPORT AIS_LengthDimension (const TopoDS_Edge& theEdge,
112 const gp_Pln& thePlane);
116 //! @return first attachement point.
117 const gp_Pnt& FirstPoint() const
122 //! @return second attachement point.
123 const gp_Pnt& SecondPoint() const
125 return mySecondPoint;
128 //! @return first attachement shape.
129 const TopoDS_Shape& FirstShape() const
134 //! @return second attachement shape.
135 const TopoDS_Shape& SecondShape() const
137 return mySecondShape;
142 //! Measure distance between two points.
143 //! The dimension will become invalid if the new distance between
144 //! attachement points is less than Precision::Confusion().
145 //! @param theFirstPoint [in] the first point.
146 //! @param theSecondPoint [in] the second point.
147 //! @param thePlane [in] the user-defined plane
148 Standard_EXPORT void SetMeasuredGeometry (const gp_Pnt& theFirstPoint,
149 const gp_Pnt& theSecondPoint,
150 const gp_Pln& thePlane);
152 //! Measure length of edge.
153 //! The dimension will become invalid if the new length of edge
154 //! is less than Precision::Confusion().
155 //! @param theEdge [in] the edge to measure.
156 //! @param thePlane [in] the user-defined plane
157 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Edge& theEdge,
158 const gp_Pln& thePlane);
160 //! Measure distance between two faces.
161 //! The dimension will become invalid if the distance can not
162 //! be measured or it is less than Precision::Confusion().
163 //! @param theFirstFace [in] the first face (first shape).
164 //! @param theSecondFace [in] the second face (second shape).
165 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
166 const TopoDS_Face& theSecondFace);
168 //! Measure distance between face and edge.
169 //! The dimension will become invalid if the distance can not
170 //! be measured or it is less than Precision::Confusion().
171 //! @param theFace [in] the face (first shape).
172 //! @param theEdge [in] the edge (second shape).
173 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFace,
174 const TopoDS_Edge& theEdge);
176 //! Measure distance between generic pair of shapes (edges, vertices, length),
177 //! where measuring is applicable.
178 //! @param theFirstShape [in] the first shape.
179 //! @param theSecondShape [in] the second shape.
180 Standard_EXPORT void SetMeasuredShapes (const TopoDS_Shape& theFirstShape,
181 const TopoDS_Shape& theSecondShape);
183 //! @return the display units string.
184 Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const Standard_OVERRIDE;
186 //! @return the model units string.
187 Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const Standard_OVERRIDE;
189 Standard_EXPORT virtual void SetDisplayUnits (const TCollection_AsciiString& theUnits) Standard_OVERRIDE;
191 Standard_EXPORT virtual void SetModelUnits (const TCollection_AsciiString& theUnits) Standard_OVERRIDE;
193 Standard_EXPORT virtual void SetTextPosition (const gp_Pnt& theTextPos) Standard_OVERRIDE;
195 Standard_EXPORT virtual const gp_Pnt GetTextPosition() const Standard_OVERRIDE;
199 DEFINE_STANDARD_RTTIEXT(AIS_LengthDimension,AIS_Dimension)
203 //! Checks if the plane includes first and second points to build dimension.
204 Standard_EXPORT virtual Standard_Boolean CheckPlane (const gp_Pln& thePlane) const Standard_OVERRIDE;
206 Standard_EXPORT virtual gp_Pln ComputePlane(const gp_Dir& theAttachDir) const;
208 Standard_EXPORT Standard_Real ComputeValue() const Standard_OVERRIDE;
210 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
211 const Handle(Prs3d_Presentation)& thePresentation,
212 const Standard_Integer theMode = 0) Standard_OVERRIDE;
214 Standard_EXPORT virtual void ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
215 const Handle(SelectMgr_EntityOwner)& theEntityOwner) Standard_OVERRIDE;
219 //! Checks that distance between two points is valid.
220 //! @param theFirstPoint [in] the first point.
221 //! @param theSecondPoint [in] the second point.
222 Standard_EXPORT Standard_Boolean IsValidPoints (const gp_Pnt& theFirstPoint,
223 const gp_Pnt& theSecondPoint) const;
225 Standard_EXPORT Standard_Boolean InitTwoEdgesLength (const TopoDS_Edge & theFirstEdge,
226 const TopoDS_Edge& theSecondEdge,
229 //! Auxiliary method for InitTwoShapesPoints()
230 //! in case of the distance between edge and vertex.
231 //! Finds the point on the edge that is the closest one to <theVertex>.
232 //! @param theEdgeDir [out] is the direction on the edge to build
233 //! automatical plane.
234 Standard_EXPORT Standard_Boolean InitEdgeVertexLength (const TopoDS_Edge& theEdge,
235 const TopoDS_Vertex& theVertex,
237 Standard_Boolean isInfinite);
239 //! Auxiliary method for InitTwoShapesPoints()
240 //! in case of the distance between face and edge.
241 //! The first attachment point is first parameter point from <theEdge>.
242 //! Find the second attachment point which belongs to <theFace>
243 //! Iterate over the edges of the face and find the closest point according
244 //! to finded point on edge.
245 //! @param theEdgeDir [out] is the direction on the edge to build
246 //! automatical plane.
247 Standard_EXPORT Standard_Boolean InitEdgeFaceLength (const TopoDS_Edge& theEdge,
248 const TopoDS_Face& theFace,
251 //! Initialization of two attach points in case of two owner shapes.
252 Standard_EXPORT Standard_Boolean InitTwoShapesPoints (const TopoDS_Shape& theFirstShape,
253 const TopoDS_Shape& theSecondShape,
254 gp_Pln& theComputedPlane,
255 Standard_Boolean& theIsPlaneComputed);
257 //! Initialization of two attach points in case of one owner shape.
258 Standard_EXPORT Standard_Boolean InitOneShapePoints (const TopoDS_Shape& theShape);
263 gp_Pnt mySecondPoint;
264 TopoDS_Shape myFirstShape;
265 TopoDS_Shape mySecondShape;
268 #endif // _AIS_LengthDimension_HeaderFile