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;
197 //! Set custom direction for dimension. If it is not set, the direction is obtained
198 //! from the measured geometry (e.g. line between points of dimension)
199 //! The direction does not change flyout direction of dimension.
200 //! @param theDirection [in] the dimension direction.
201 //! @param theUseDirection [in] boolean value if custom direction should be used.
202 Standard_EXPORT void SetDirection (const gp_Dir& theDirection, const Standard_Boolean theUseDirection = Standard_True);
206 DEFINE_STANDARD_RTTIEXT(AIS_LengthDimension,AIS_Dimension)
210 //! Checks if the plane includes first and second points to build dimension.
211 Standard_EXPORT virtual Standard_Boolean CheckPlane (const gp_Pln& thePlane) const Standard_OVERRIDE;
213 Standard_EXPORT virtual gp_Pln ComputePlane(const gp_Dir& theAttachDir) const;
215 //! Computes distance between dimension points. If custom direction is defined, the distance
216 //! is a projection value of the distance between points to this direction
217 //! @return dimension value
218 Standard_EXPORT Standard_Real ComputeValue() const Standard_OVERRIDE;
220 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
221 const Handle(Prs3d_Presentation)& thePresentation,
222 const Standard_Integer theMode = 0) Standard_OVERRIDE;
224 //! Computes points bounded the flyout line for linear dimension.
225 //! Direction of flyout line equal to the custom direction of dimension if defined or
226 //! parallel to the main direction line
227 //! @param theFirstPoint [in] the first attach point of linear dimension.
228 //! @param theSecondPoint [in] the second attach point of linear dimension.
229 //! @param theLineBegPoint [out] the first attach point of linear dimension.
230 //! @param theLineEndPoint [out] the second attach point of linear dimension.
231 Standard_EXPORT virtual void ComputeFlyoutLinePoints (const gp_Pnt& theFirstPoint, const gp_Pnt& theSecondPoint,
232 gp_Pnt& theLineBegPoint, gp_Pnt& theLineEndPoint) Standard_OVERRIDE;
234 Standard_EXPORT virtual void ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
235 const Handle(SelectMgr_EntityOwner)& theEntityOwner) Standard_OVERRIDE;
239 //! Checks that distance between two points is valid.
240 //! @param theFirstPoint [in] the first point.
241 //! @param theSecondPoint [in] the second point.
242 Standard_EXPORT Standard_Boolean IsValidPoints (const gp_Pnt& theFirstPoint,
243 const gp_Pnt& theSecondPoint) const;
245 Standard_EXPORT Standard_Boolean InitTwoEdgesLength (const TopoDS_Edge & theFirstEdge,
246 const TopoDS_Edge& theSecondEdge,
249 //! Auxiliary method for InitTwoShapesPoints()
250 //! in case of the distance between edge and vertex.
251 //! Finds the point on the edge that is the closest one to <theVertex>.
252 //! @param theEdgeDir [out] is the direction on the edge to build
253 //! automatical plane.
254 Standard_EXPORT Standard_Boolean InitEdgeVertexLength (const TopoDS_Edge& theEdge,
255 const TopoDS_Vertex& theVertex,
257 Standard_Boolean isInfinite);
259 //! Auxiliary method for InitTwoShapesPoints()
260 //! in case of the distance between face and edge.
261 //! The first attachment point is first parameter point from <theEdge>.
262 //! Find the second attachment point which belongs to <theFace>
263 //! Iterate over the edges of the face and find the closest point according
264 //! to finded point on edge.
265 //! @param theEdgeDir [out] is the direction on the edge to build
266 //! automatical plane.
267 Standard_EXPORT Standard_Boolean InitEdgeFaceLength (const TopoDS_Edge& theEdge,
268 const TopoDS_Face& theFace,
271 //! Initialization of two attach points in case of two owner shapes.
272 Standard_EXPORT Standard_Boolean InitTwoShapesPoints (const TopoDS_Shape& theFirstShape,
273 const TopoDS_Shape& theSecondShape,
274 gp_Pln& theComputedPlane,
275 Standard_Boolean& theIsPlaneComputed);
277 //! Initialization of two attach points in case of one owner shape.
278 Standard_EXPORT Standard_Boolean InitOneShapePoints (const TopoDS_Shape& theShape);
283 gp_Pnt mySecondPoint;
284 TopoDS_Shape myFirstShape;
285 TopoDS_Shape mySecondShape;
287 Standard_Boolean myHasCustomDirection;
290 #endif // _AIS_LengthDimension_HeaderFile