0026570: Crash on attempt to rotate a shape.
[occt.git] / src / ShapeAnalysis / ShapeAnalysis_Edge.hxx
1 // Created on: 1998-06-08
2 // Created by: data exchange team
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _ShapeAnalysis_Edge_HeaderFile
18 #define _ShapeAnalysis_Edge_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23
24 #include <Standard_Integer.hxx>
25 #include <Standard_Boolean.hxx>
26 #include <Standard_Real.hxx>
27 #include <ShapeExtend_Status.hxx>
28 class TopoDS_Edge;
29 class Geom_Curve;
30 class TopoDS_Face;
31 class Geom_Surface;
32 class TopLoc_Location;
33 class Geom2d_Curve;
34 class gp_Pnt2d;
35 class TopoDS_Vertex;
36 class gp_Vec2d;
37 class gp_Pnt;
38 class Adaptor3d_Curve;
39
40 // resolve name collisions with X11 headers
41 #ifdef Status
42   #undef Status
43 #endif
44
45 //! Tool for analyzing the edge.
46 //! Queries geometrical representations of the edge (3d curve, pcurve
47 //! on the given face or surface) and topological sub-shapes (bounding
48 //! vertices).
49 //! Provides methods for analyzing geometry and topology consistency
50 //! (3d and pcurve(s) consistency, their adjacency to the vertices).
51 class ShapeAnalysis_Edge 
52 {
53 public:
54
55   DEFINE_STANDARD_ALLOC
56
57   
58   //! Empty constructor; initialises Status to OK
59   Standard_EXPORT ShapeAnalysis_Edge();
60   
61   //! Tells if the edge has a 3d curve
62   Standard_EXPORT Standard_Boolean HasCurve3d (const TopoDS_Edge& edge) const;
63   
64   //! Returns the 3d curve and bounding parameteres for the edge
65   //! Returns False if no 3d curve.
66   //! If <orient> is True (default), takes orientation into account:
67   //! if the edge is reversed, cf and cl are toggled
68   Standard_EXPORT Standard_Boolean Curve3d (const TopoDS_Edge& edge, Handle(Geom_Curve)& C3d, Standard_Real& cf, Standard_Real& cl, const Standard_Boolean orient = Standard_True) const;
69   
70   //! Gives True if the edge has a 3d curve, this curve is closed,
71   //! and the edge has the same vertex at start and end
72   Standard_EXPORT Standard_Boolean IsClosed3d (const TopoDS_Edge& edge) const;
73   
74   //! Tells if the Edge has a pcurve on the face.
75   Standard_EXPORT Standard_Boolean HasPCurve (const TopoDS_Edge& edge, const TopoDS_Face& face) const;
76   
77   //! Tells if the edge has a pcurve on the surface (with location).
78   Standard_EXPORT Standard_Boolean HasPCurve (const TopoDS_Edge& edge, const Handle(Geom_Surface)& surface, const TopLoc_Location& location) const;
79   
80   Standard_EXPORT Standard_Boolean PCurve (const TopoDS_Edge& edge, const TopoDS_Face& face, Handle(Geom2d_Curve)& C2d, Standard_Real& cf, Standard_Real& cl, const Standard_Boolean orient = Standard_True) const;
81   
82   //! Returns the pcurve and bounding parameteres for the edge
83   //! lying on the surface.
84   //! Returns False if the edge has no pcurve on this surface.
85   //! If <orient> is True (default), takes orientation into account:
86   //! if the edge is reversed, cf and cl are toggled
87   Standard_EXPORT Standard_Boolean PCurve (const TopoDS_Edge& edge, const Handle(Geom_Surface)& surface, const TopLoc_Location& location, Handle(Geom2d_Curve)& C2d, Standard_Real& cf, Standard_Real& cl, const Standard_Boolean orient = Standard_True) const;
88   
89   Standard_EXPORT Standard_Boolean BoundUV (const TopoDS_Edge& edge, const TopoDS_Face& face, gp_Pnt2d& first, gp_Pnt2d& last) const;
90   
91   //! Returns the ends of pcurve
92   //! Calls method PCurve with <orient> equal to True
93   Standard_EXPORT Standard_Boolean BoundUV (const TopoDS_Edge& edge, const Handle(Geom_Surface)& surface, const TopLoc_Location& location, gp_Pnt2d& first, gp_Pnt2d& last) const;
94   
95   Standard_EXPORT Standard_Boolean IsSeam (const TopoDS_Edge& edge, const TopoDS_Face& face) const;
96   
97   //! Returns True if the edge has two pcurves on one surface
98   Standard_EXPORT Standard_Boolean IsSeam (const TopoDS_Edge& edge, const Handle(Geom_Surface)& surface, const TopLoc_Location& location) const;
99   
100   //! Returns start vertex of the edge (taking edge orientation
101   //! into account).
102   Standard_EXPORT TopoDS_Vertex FirstVertex (const TopoDS_Edge& edge) const;
103   
104   //! Returns end vertex of the edge (taking edge orientation
105   //! into account).
106   Standard_EXPORT TopoDS_Vertex LastVertex (const TopoDS_Edge& edge) const;
107   
108   Standard_EXPORT Standard_Boolean GetEndTangent2d (const TopoDS_Edge& edge, const TopoDS_Face& face, const Standard_Boolean atEnd, gp_Pnt2d& pos, gp_Vec2d& tang, const Standard_Real dparam = 0.0) const;
109   
110   //! Returns tangent of the edge pcurve at its start (if atEnd is
111   //! False) or end (if True), regarding the orientation of edge.
112   //! If edge is REVERSED, tangent is reversed before return.
113   //! Returns True if pcurve is available and tangent is computed
114   //! and is not null, else False.
115   Standard_EXPORT Standard_Boolean GetEndTangent2d (const TopoDS_Edge& edge, const Handle(Geom_Surface)& surface, const TopLoc_Location& location, const Standard_Boolean atEnd, gp_Pnt2d& pos, gp_Vec2d& tang, const Standard_Real dparam = 0.0) const;
116   
117   //! Checks the start and/or end vertex of the edge for matching
118   //! with 3d curve with the given precision.
119   //! <vtx> = 1 : start vertex only
120   //! <vtx> = 2 : end vertex only
121   //! <vtx> = 0 : both (default)
122   //! If preci < 0 the vertices are considered with their own
123   //! tolerances, else with the given <preci>.
124   Standard_EXPORT Standard_Boolean CheckVerticesWithCurve3d (const TopoDS_Edge& edge, const Standard_Real preci = -1, const Standard_Integer vtx = 0);
125   
126   Standard_EXPORT Standard_Boolean CheckVerticesWithPCurve (const TopoDS_Edge& edge, const TopoDS_Face& face, const Standard_Real preci = -1, const Standard_Integer vtx = 0);
127   
128   //! Checks the start and/or end vertex of the edge for matching
129   //! with pcurve with the given precision.
130   //! <vtx> = 1 : start vertex
131   //! <vtx> = 2 : end vertex
132   //! <vtx> = 0 : both
133   //! If preci < 0 the vertices are considered with their own
134   //! tolerances, else with the given <preci>.
135   Standard_EXPORT Standard_Boolean CheckVerticesWithPCurve (const TopoDS_Edge& edge, const Handle(Geom_Surface)& surface, const TopLoc_Location& location, const Standard_Real preci = -1, const Standard_Integer vtx = 0);
136   
137   Standard_EXPORT Standard_Boolean CheckVertexTolerance (const TopoDS_Edge& edge, const TopoDS_Face& face, Standard_Real& toler1, Standard_Real& toler2);
138   
139   //! Checks if it is necessary to increase tolerances of the edge
140   //! vertices to comprise the ends of 3d curve and pcurve on
141   //! the given face (first method) or all pcurves stored in an edge
142   //! (second one)
143   //! toler1 returns necessary tolerance for first vertex,
144   //! toler2 returns necessary tolerance for last vertex.
145   Standard_EXPORT Standard_Boolean CheckVertexTolerance (const TopoDS_Edge& edge, Standard_Real& toler1, Standard_Real& toler2);
146   
147   Standard_EXPORT Standard_Boolean CheckCurve3dWithPCurve (const TopoDS_Edge& edge, const TopoDS_Face& face);
148   
149   //! Checks mutual orientation of 3d curve and pcurve on the
150   //! analysis of curves bounding points
151   Standard_EXPORT Standard_Boolean CheckCurve3dWithPCurve (const TopoDS_Edge& edge, const Handle(Geom_Surface)& surface, const TopLoc_Location& location);
152   
153   //! Returns the status (in the form of True/False) of last Check
154   Standard_EXPORT Standard_Boolean Status (const ShapeExtend_Status status) const;
155   
156   //! Checks the edge to be SameParameter.
157   //! Calculates the maximal deviation between 3d curve and each
158   //! pcurve of the edge on <NbControl> equidistant points (the same
159   //! algorithm as in BRepCheck; default value is 23 as in BRepCheck).
160   //! This deviation is returned in <maxdev> parameter.
161   //! If deviation is greater than tolerance of the edge (i.e.
162   //! incorrect flag) returns False, else returns True.
163   Standard_EXPORT Standard_Boolean CheckSameParameter (const TopoDS_Edge& edge, Standard_Real& maxdev, const Standard_Integer NbControl = 23);
164
165   //! Checks the edge to be SameParameter.
166   //! Calculates the maximal deviation between 3d curve and each
167   //! pcurve of the edge on <NbControl> equidistant points (the same
168   //! algorithm as in BRepCheck; default value is 23 as in BRepCheck).
169   //! This deviation is returned in <maxdev> parameter.
170   //! If deviation is greater than tolerance of the edge (i.e.
171   //! incorrect flag) returns False, else returns True.
172   Standard_EXPORT Standard_Boolean CheckSameParameter (const TopoDS_Edge& theEdge, const TopoDS_Face& theFace, Standard_Real& theMaxdev, const Standard_Integer theNbControl = 23);
173
174   //! Checks possibility for pcurve thePC to have range [theFirst, theLast] (edge range)
175   //! having respect to real first, last parameters of thePC 
176   Standard_EXPORT Standard_Boolean CheckPCurveRange (const Standard_Real theFirst, const Standard_Real theLast,
177                                                      const Handle(Geom2d_Curve)& thePC);
178
179   //! Computes the maximal deviation between the two curve
180   //! representations.
181   //! dev is an input/output parameter and contains the computed
182   //! deviation (should be initialized with 0. for the first call).
183   //! Used by CheckSameParameter().
184   Standard_EXPORT static Standard_Boolean ComputeDeviation (const Adaptor3d_Curve& CRef, const Adaptor3d_Curve& Other, const Standard_Boolean SameParameter, Standard_Real& dev, const Standard_Integer NCONTROL);
185   
186   //! Checks the first edge is overlapped with second edge.
187   //! If distance between two edges is less then theTolOverlap
188   //! edges is overlapped.
189   //! theDomainDis - length of part of edges on wich edges is overlapped.
190   Standard_EXPORT Standard_Boolean CheckOverlapping (const TopoDS_Edge& theEdge1, const TopoDS_Edge& theEdge2, Standard_Real& theTolOverlap, const Standard_Real theDomainDist = 0.0);
191
192
193
194
195 protected:
196
197
198
199   Standard_Integer myStatus;
200
201
202 private:
203
204   
205   //! Check points by pairs (A and A, B and B) with precisions
206   //! (preci1 and preci2).
207   //! P1 are the points either from 3d curve or from vertices,
208   //! P2 are the points from pcurve
209   Standard_EXPORT Standard_Boolean CheckPoints (const gp_Pnt& P1A, const gp_Pnt& P1B, const gp_Pnt& P2A, const gp_Pnt& P2B, const Standard_Real preci1, const Standard_Real preci2);
210
211
212
213
214 };
215
216
217
218
219
220
221
222 #endif // _ShapeAnalysis_Edge_HeaderFile