0031456: Visualization - move out Dimensions and Relations from package AIS to PrsDims
[occt.git] / src / PrsDim / PrsDim_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
787ff240 14#ifndef _PrsDim_LengthDimension_HeaderFile
15#define _PrsDim_LengthDimension_HeaderFile
a6eb515f 16
787ff240 17#include <PrsDim_Dimension.hxx>
18#include <PrsDim_KindOfDimension.hxx>
a6eb515f 19#include <Geom_Plane.hxx>
a6eb515f 20#include <gp_Pnt.hxx>
21#include <gp_Dir.hxx>
22#include <Prs3d_DimensionAspect.hxx>
6262338c 23#include <Prs3d_Drawer.hxx>
a6eb515f 24#include <TopoDS.hxx>
25#include <TopoDS_Vertex.hxx>
a6eb515f 26
787ff240 27DEFINE_STANDARD_HANDLE (PrsDim_LengthDimension, PrsDim_Dimension)
a6eb515f 28
60bf98ae 29//! Length dimension. Can be constructued:
30//! - Between two generic points.
31//! - Between two vertices.
32//! - Between two faces.
33//! - Between two parallel edges.
34//! - Between face and edge.
35//!
36//! In case of two points (vertices) or one linear edge the user-defined plane
37//! that includes this geometry is necessary to be set.
38//!
39//! In case of face-edge, edge-vertex or face-face lengthes the automatic plane
40//! computing is allowed. For this plane the third point is found on the
41//! edge or on the face.
1c078d3b 42//!
60bf98ae 43//! Please note that if the inappropriate geometry is defined
44//! or the distance between measured points is less than
45//! Precision::Confusion(), the dimension is invalid and its
46//! presentation can not be computed.
787ff240 47class PrsDim_LengthDimension : public PrsDim_Dimension
a6eb515f 48{
787ff240 49 DEFINE_STANDARD_RTTIEXT(PrsDim_LengthDimension, PrsDim_Dimension)
a6eb515f 50public:
51
60bf98ae 52 //! Construct length dimension between face and edge.
53 //! Here dimension can be built without user-defined plane.
54 //! @param theFace [in] the face (first shape).
55 //! @param theEdge [in] the edge (second shape).
787ff240 56 Standard_EXPORT PrsDim_LengthDimension (const TopoDS_Face& theFace,
57 const TopoDS_Edge& theEdge);
a6eb515f 58
60bf98ae 59 //! Construct length dimension between two faces.
60 //! @param theFirstFace [in] the first face (first shape).
61 //! @param theSecondFace [in] the second face (second shape).
787ff240 62 Standard_EXPORT PrsDim_LengthDimension (const TopoDS_Face& theFirstFace,
63 const TopoDS_Face& theSecondFace);
60bf98ae 64
65 //! Construct length dimension between two points in
66 //! the specified plane.
67 //! @param theFirstPoint [in] the first point.
68 //! @param theSecondPoint [in] the second point.
69 //! @param thePlane [in] the plane to orient dimension.
787ff240 70 Standard_EXPORT PrsDim_LengthDimension (const gp_Pnt& theFirstPoint,
71 const gp_Pnt& theSecondPoint,
72 const gp_Pln& thePlane);
60bf98ae 73
74 //! Construct length dimension between two arbitrary shapes in
75 //! the specified plane.
76 //! @param theFirstShape [in] the first shape.
77 //! @param theSecondShape [in] the second shape.
78 //! @param thePlane [in] the plane to orient dimension.
787ff240 79 Standard_EXPORT PrsDim_LengthDimension (const TopoDS_Shape& theFirstShape,
80 const TopoDS_Shape& theSecondShape,
81 const gp_Pln& thePlane);
a6eb515f 82
60bf98ae 83 //! Construct length dimension of linear edge.
84 //! @param theEdge [in] the edge to measure.
85 //! @param thePlane [in] the plane to orient dimension.
787ff240 86 Standard_EXPORT PrsDim_LengthDimension (const TopoDS_Edge& theEdge,
87 const gp_Pln& thePlane);
a6eb515f 88
60bf98ae 89public:
a6eb515f 90
60bf98ae 91 //! @return first attachement point.
787ff240 92 const gp_Pnt& FirstPoint() const { return myFirstPoint; }
60bf98ae 93
94 //! @return second attachement point.
787ff240 95 const gp_Pnt& SecondPoint() const { return mySecondPoint; }
60bf98ae 96
97 //! @return first attachement shape.
787ff240 98 const TopoDS_Shape& FirstShape() const { return myFirstShape; }
60bf98ae 99
100 //! @return second attachement shape.
787ff240 101 const TopoDS_Shape& SecondShape() const { return mySecondShape; }
60bf98ae 102
103public:
104
105 //! Measure distance between two points.
106 //! The dimension will become invalid if the new distance between
107 //! attachement points is less than Precision::Confusion().
108 //! @param theFirstPoint [in] the first point.
109 //! @param theSecondPoint [in] the second point.
110 //! @param thePlane [in] the user-defined plane
111 Standard_EXPORT void SetMeasuredGeometry (const gp_Pnt& theFirstPoint,
112 const gp_Pnt& theSecondPoint,
113 const gp_Pln& thePlane);
114
115 //! Measure length of edge.
116 //! The dimension will become invalid if the new length of edge
117 //! is less than Precision::Confusion().
118 //! @param theEdge [in] the edge to measure.
119 //! @param thePlane [in] the user-defined plane
120 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Edge& theEdge,
121 const gp_Pln& thePlane);
122
123 //! Measure distance between two faces.
124 //! The dimension will become invalid if the distance can not
125 //! be measured or it is less than Precision::Confusion().
126 //! @param theFirstFace [in] the first face (first shape).
127 //! @param theSecondFace [in] the second face (second shape).
128 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
129 const TopoDS_Face& theSecondFace);
130
131 //! Measure distance between face and edge.
132 //! The dimension will become invalid if the distance can not
133 //! be measured or it is less than Precision::Confusion().
134 //! @param theFace [in] the face (first shape).
135 //! @param theEdge [in] the edge (second shape).
136 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFace,
137 const TopoDS_Edge& theEdge);
138
139 //! Measure distance between generic pair of shapes (edges, vertices, length),
140 //! where measuring is applicable.
141 //! @param theFirstShape [in] the first shape.
142 //! @param theSecondShape [in] the second shape.
143 Standard_EXPORT void SetMeasuredShapes (const TopoDS_Shape& theFirstShape,
144 const TopoDS_Shape& theSecondShape);
145
146 //! @return the display units string.
79104795 147 Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const Standard_OVERRIDE;
af203d54 148
60bf98ae 149 //! @return the model units string.
79104795 150 Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const Standard_OVERRIDE;
60bf98ae 151
79104795 152 Standard_EXPORT virtual void SetDisplayUnits (const TCollection_AsciiString& theUnits) Standard_OVERRIDE;
60bf98ae 153
79104795 154 Standard_EXPORT virtual void SetModelUnits (const TCollection_AsciiString& theUnits) Standard_OVERRIDE;
a6eb515f 155
79104795 156 Standard_EXPORT virtual void SetTextPosition (const gp_Pnt& theTextPos) Standard_OVERRIDE;
af203d54 157
787ff240 158 Standard_EXPORT virtual gp_Pnt GetTextPosition() const Standard_OVERRIDE;
af203d54 159
948c552a 160 //! Set custom direction for dimension. If it is not set, the direction is obtained
161 //! from the measured geometry (e.g. line between points of dimension)
162 //! The direction does not change flyout direction of dimension.
163 //! @param theDirection [in] the dimension direction.
164 //! @param theUseDirection [in] boolean value if custom direction should be used.
165 Standard_EXPORT void SetDirection (const gp_Dir& theDirection, const Standard_Boolean theUseDirection = Standard_True);
166
60bf98ae 167protected:
d7bffd44 168
60bf98ae 169 //! Checks if the plane includes first and second points to build dimension.
79104795 170 Standard_EXPORT virtual Standard_Boolean CheckPlane (const gp_Pln& thePlane) const Standard_OVERRIDE;
d7bffd44 171
60bf98ae 172 Standard_EXPORT virtual gp_Pln ComputePlane(const gp_Dir& theAttachDir) const;
d7bffd44 173
948c552a 174 //! Computes distance between dimension points. If custom direction is defined, the distance
175 //! is a projection value of the distance between points to this direction
176 //! @return dimension value
79104795 177 Standard_EXPORT Standard_Real ComputeValue() const Standard_OVERRIDE;
d7bffd44 178
60bf98ae 179 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
180 const Handle(Prs3d_Presentation)& thePresentation,
79104795 181 const Standard_Integer theMode = 0) Standard_OVERRIDE;
d7bffd44 182
948c552a 183 //! Computes points bounded the flyout line for linear dimension.
184 //! Direction of flyout line equal to the custom direction of dimension if defined or
185 //! parallel to the main direction line
186 //! @param theFirstPoint [in] the first attach point of linear dimension.
187 //! @param theSecondPoint [in] the second attach point of linear dimension.
188 //! @param theLineBegPoint [out] the first attach point of linear dimension.
189 //! @param theLineEndPoint [out] the second attach point of linear dimension.
190 Standard_EXPORT virtual void ComputeFlyoutLinePoints (const gp_Pnt& theFirstPoint, const gp_Pnt& theSecondPoint,
191 gp_Pnt& theLineBegPoint, gp_Pnt& theLineEndPoint) Standard_OVERRIDE;
192
60bf98ae 193 Standard_EXPORT virtual void ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
79104795 194 const Handle(SelectMgr_EntityOwner)& theEntityOwner) Standard_OVERRIDE;
a6eb515f 195
60bf98ae 196protected:
197
198 //! Checks that distance between two points is valid.
199 //! @param theFirstPoint [in] the first point.
200 //! @param theSecondPoint [in] the second point.
201 Standard_EXPORT Standard_Boolean IsValidPoints (const gp_Pnt& theFirstPoint,
202 const gp_Pnt& theSecondPoint) const;
203
204 Standard_EXPORT Standard_Boolean InitTwoEdgesLength (const TopoDS_Edge & theFirstEdge,
205 const TopoDS_Edge& theSecondEdge,
206 gp_Dir& theEdgeDir);
207
208 //! Auxiliary method for InitTwoShapesPoints()
209 //! in case of the distance between edge and vertex.
210 //! Finds the point on the edge that is the closest one to <theVertex>.
211 //! @param theEdgeDir [out] is the direction on the edge to build
212 //! automatical plane.
213 Standard_EXPORT Standard_Boolean InitEdgeVertexLength (const TopoDS_Edge& theEdge,
214 const TopoDS_Vertex& theVertex,
215 gp_Dir& theEdgeDir,
216 Standard_Boolean isInfinite);
217
218 //! Auxiliary method for InitTwoShapesPoints()
219 //! in case of the distance between face and edge.
220 //! The first attachment point is first parameter point from <theEdge>.
221 //! Find the second attachment point which belongs to <theFace>
222 //! Iterate over the edges of the face and find the closest point according
223 //! to finded point on edge.
224 //! @param theEdgeDir [out] is the direction on the edge to build
225 //! automatical plane.
226 Standard_EXPORT Standard_Boolean InitEdgeFaceLength (const TopoDS_Edge& theEdge,
227 const TopoDS_Face& theFace,
228 gp_Dir& theEdgeDir);
229
230 //! Initialization of two attach points in case of two owner shapes.
231 Standard_EXPORT Standard_Boolean InitTwoShapesPoints (const TopoDS_Shape& theFirstShape,
232 const TopoDS_Shape& theSecondShape,
233 gp_Pln& theComputedPlane,
234 Standard_Boolean& theIsPlaneComputed);
235
236 //! Initialization of two attach points in case of one owner shape.
237 Standard_EXPORT Standard_Boolean InitOneShapePoints (const TopoDS_Shape& theShape);
238
239private:
a6eb515f 240
60bf98ae 241 gp_Pnt myFirstPoint;
242 gp_Pnt mySecondPoint;
243 TopoDS_Shape myFirstShape;
244 TopoDS_Shape mySecondShape;
948c552a 245 gp_Dir myDirection;
246 Standard_Boolean myHasCustomDirection;
a6eb515f 247};
248
787ff240 249#endif // _PrsDim_LengthDimension_HeaderFile