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