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