0024023: Revamp the OCCT Handle -- automatic
[occt.git] / src / AIS / AIS_LengthDimension.hxx
CommitLineData
a6eb515f 1// Copyright (c) 1999-2013 OPEN CASCADE SAS
2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
a6eb515f 4//
d5f74e42 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
973c2be1 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.
a6eb515f 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
a6eb515f 13
14#ifndef _AIS_LengthDimension_HeaderFile
15#define _AIS_LengthDimension_HeaderFile
16
17#include <AIS.hxx>
18#include <AIS_Dimension.hxx>
a6eb515f 19#include <AIS_KindOfDimension.hxx>
20#include <Geom_Plane.hxx>
21#include <Geom_Transformation.hxx>
22#include <gp_Pnt.hxx>
23#include <gp_Dir.hxx>
24#include <Prs3d_DimensionAspect.hxx>
6262338c 25#include <Prs3d_Drawer.hxx>
a6eb515f 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>
ec357c5c 32#include <Standard_Type.hxx>
a6eb515f 33#include <TopoDS.hxx>
34#include <TopoDS_Vertex.hxx>
35#include <TCollection_ExtendedString.hxx>
36
37class TopoDS_Face;
38class TCollection_ExtendedString;
39class gp_Pnt;
40class TopoDS_Edge;
41class TopoDS_Shape;
42class Geom_Plane;
a6eb515f 43class Prs3d_Presentation;
44class Prs3d_Projector;
45class Geom_Transformation;
46class SelectMgr_Selection;
a6eb515f 47class Bnd_Box;
48class gp_Dir;
49class TopoDS_Vertex;
50class Standard_Transient;
a6eb515f 51class AIS_LengthDimension;
52
60bf98ae 53DEFINE_STANDARD_HANDLE (AIS_LengthDimension, AIS_Dimension)
a6eb515f 54
60bf98ae 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.
61//!
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.
64//!
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.
68//!
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.
a6eb515f 73class AIS_LengthDimension : public AIS_Dimension
74{
75public:
76
60bf98ae 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);
a6eb515f 83
60bf98ae 84public:
85
86 //! Construct length dimension between two faces.
87 //! @param theFirstFace [in] the first face (first shape).
88 //! @param theSecondFace [in] the second face (second shape).
89 Standard_EXPORT AIS_LengthDimension (const TopoDS_Face& theFirstFace,
90 const TopoDS_Face& theSecondFace);
91
92 //! Construct length dimension between two points in
93 //! the specified plane.
94 //! @param theFirstPoint [in] the first point.
95 //! @param theSecondPoint [in] the second point.
96 //! @param thePlane [in] the plane to orient dimension.
97 Standard_EXPORT AIS_LengthDimension (const gp_Pnt& theFirstPoint,
98 const gp_Pnt& theSecondPoint,
99 const gp_Pln& thePlane);
100
101 //! Construct length dimension between two arbitrary shapes in
102 //! the specified plane.
103 //! @param theFirstShape [in] the first shape.
104 //! @param theSecondShape [in] the second shape.
105 //! @param thePlane [in] the plane to orient dimension.
a6eb515f 106 Standard_EXPORT AIS_LengthDimension (const TopoDS_Shape& theFirstShape,
107 const TopoDS_Shape& theSecondShape,
60bf98ae 108 const gp_Pln& thePlane);
a6eb515f 109
60bf98ae 110 //! Construct length dimension of linear edge.
111 //! @param theEdge [in] the edge to measure.
112 //! @param thePlane [in] the plane to orient dimension.
113 Standard_EXPORT AIS_LengthDimension (const TopoDS_Edge& theEdge,
114 const gp_Pln& thePlane);
a6eb515f 115
60bf98ae 116public:
a6eb515f 117
60bf98ae 118 //! @return first attachement point.
119 const gp_Pnt& FirstPoint() const
120 {
121 return myFirstPoint;
122 }
123
124 //! @return second attachement point.
125 const gp_Pnt& SecondPoint() const
126 {
127 return mySecondPoint;
128 }
129
130 //! @return first attachement shape.
131 const TopoDS_Shape& FirstShape() const
132 {
133 return myFirstShape;
134 }
135
136 //! @return second attachement shape.
137 const TopoDS_Shape& SecondShape() const
138 {
139 return mySecondShape;
140 }
141
142public:
143
144 //! Measure distance between two points.
145 //! The dimension will become invalid if the new distance between
146 //! attachement points is less than Precision::Confusion().
147 //! @param theFirstPoint [in] the first point.
148 //! @param theSecondPoint [in] the second point.
149 //! @param thePlane [in] the user-defined plane
150 Standard_EXPORT void SetMeasuredGeometry (const gp_Pnt& theFirstPoint,
151 const gp_Pnt& theSecondPoint,
152 const gp_Pln& thePlane);
153
154 //! Measure length of edge.
155 //! The dimension will become invalid if the new length of edge
156 //! is less than Precision::Confusion().
157 //! @param theEdge [in] the edge to measure.
158 //! @param thePlane [in] the user-defined plane
159 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Edge& theEdge,
160 const gp_Pln& thePlane);
161
162 //! Measure distance between two faces.
163 //! The dimension will become invalid if the distance can not
164 //! be measured or it is less than Precision::Confusion().
165 //! @param theFirstFace [in] the first face (first shape).
166 //! @param theSecondFace [in] the second face (second shape).
167 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
168 const TopoDS_Face& theSecondFace);
169
170 //! Measure distance between face and edge.
171 //! The dimension will become invalid if the distance can not
172 //! be measured or it is less than Precision::Confusion().
173 //! @param theFace [in] the face (first shape).
174 //! @param theEdge [in] the edge (second shape).
175 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFace,
176 const TopoDS_Edge& theEdge);
177
178 //! Measure distance between generic pair of shapes (edges, vertices, length),
179 //! where measuring is applicable.
180 //! @param theFirstShape [in] the first shape.
181 //! @param theSecondShape [in] the second shape.
182 Standard_EXPORT void SetMeasuredShapes (const TopoDS_Shape& theFirstShape,
183 const TopoDS_Shape& theSecondShape);
184
185 //! @return the display units string.
af203d54 186 Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const;
187
60bf98ae 188 //! @return the model units string.
af203d54 189 Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const;
60bf98ae 190
191 Standard_EXPORT virtual void SetDisplayUnits (const TCollection_AsciiString& theUnits);
192
193 Standard_EXPORT virtual void SetModelUnits (const TCollection_AsciiString& theUnits);
a6eb515f 194
af203d54 195 Standard_EXPORT virtual void SetTextPosition (const gp_Pnt& theTextPos);
196
197 Standard_EXPORT virtual const gp_Pnt GetTextPosition() const;
198
d7bffd44 199public:
200
ec357c5c 201 DEFINE_STANDARD_RTTI(AIS_LengthDimension, AIS_Dimension)
d7bffd44 202
60bf98ae 203protected:
d7bffd44 204
60bf98ae 205 //! Checks if the plane includes first and second points to build dimension.
206 Standard_EXPORT virtual Standard_Boolean CheckPlane (const gp_Pln& thePlane) const;
d7bffd44 207
60bf98ae 208 Standard_EXPORT virtual gp_Pln ComputePlane(const gp_Dir& theAttachDir) const;
d7bffd44 209
60bf98ae 210 Standard_EXPORT Standard_Real ComputeValue() const;
d7bffd44 211
60bf98ae 212 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
213 const Handle(Prs3d_Presentation)& thePresentation,
214 const Standard_Integer theMode = 0);
d7bffd44 215
60bf98ae 216 Standard_EXPORT virtual void ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
217 const Handle(SelectMgr_EntityOwner)& theEntityOwner);
a6eb515f 218
60bf98ae 219protected:
220
221 //! Checks that distance between two points is valid.
222 //! @param theFirstPoint [in] the first point.
223 //! @param theSecondPoint [in] the second point.
224 Standard_EXPORT Standard_Boolean IsValidPoints (const gp_Pnt& theFirstPoint,
225 const gp_Pnt& theSecondPoint) const;
226
227 Standard_EXPORT Standard_Boolean InitTwoEdgesLength (const TopoDS_Edge & theFirstEdge,
228 const TopoDS_Edge& theSecondEdge,
229 gp_Dir& theEdgeDir);
230
231 //! Auxiliary method for InitTwoShapesPoints()
232 //! in case of the distance between edge and vertex.
233 //! Finds the point on the edge that is the closest one to <theVertex>.
234 //! @param theEdgeDir [out] is the direction on the edge to build
235 //! automatical plane.
236 Standard_EXPORT Standard_Boolean InitEdgeVertexLength (const TopoDS_Edge& theEdge,
237 const TopoDS_Vertex& theVertex,
238 gp_Dir& theEdgeDir,
239 Standard_Boolean isInfinite);
240
241 //! Auxiliary method for InitTwoShapesPoints()
242 //! in case of the distance between face and edge.
243 //! The first attachment point is first parameter point from <theEdge>.
244 //! Find the second attachment point which belongs to <theFace>
245 //! Iterate over the edges of the face and find the closest point according
246 //! to finded point on edge.
247 //! @param theEdgeDir [out] is the direction on the edge to build
248 //! automatical plane.
249 Standard_EXPORT Standard_Boolean InitEdgeFaceLength (const TopoDS_Edge& theEdge,
250 const TopoDS_Face& theFace,
251 gp_Dir& theEdgeDir);
252
253 //! Initialization of two attach points in case of two owner shapes.
254 Standard_EXPORT Standard_Boolean InitTwoShapesPoints (const TopoDS_Shape& theFirstShape,
255 const TopoDS_Shape& theSecondShape,
256 gp_Pln& theComputedPlane,
257 Standard_Boolean& theIsPlaneComputed);
258
259 //! Initialization of two attach points in case of one owner shape.
260 Standard_EXPORT Standard_Boolean InitOneShapePoints (const TopoDS_Shape& theShape);
261
262private:
a6eb515f 263
60bf98ae 264 gp_Pnt myFirstPoint;
265 gp_Pnt mySecondPoint;
266 TopoDS_Shape myFirstShape;
267 TopoDS_Shape mySecondShape;
a6eb515f 268};
269
60bf98ae 270#endif // _AIS_LengthDimension_HeaderFile