1 // Created on: 1998-06-03
2 // Created by: data exchange team
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _ShapeAnalysis_WireOrder_HeaderFile
18 #define _ShapeAnalysis_WireOrder_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
24 #include <Standard_Boolean.hxx>
25 #include <TColStd_HArray1OfInteger.hxx>
26 #include <TColgp_HSequenceOfXYZ.hxx>
27 #include <Standard_Real.hxx>
28 #include <Standard_Integer.hxx>
29 class Standard_TypeMismatch;
33 // resolve name collisions with X11 headers
38 //! This class is intended to control and, if possible, redefine
39 //! the order of a list of edges which define a wire
40 //! Edges are not given directly, but as their bounds (start,end)
42 //! This allows to use this tool, either on existing wire, or on
43 //! data just taken from a file (coordinates are easy to get)
45 //! It can work, either in 2D, or in 3D, but not miscible
46 //! Warning about tolerance : according to the mode (2D/3D), it
47 //! must be given as 2D or 3D (i.e. metric) tolerance, uniform
50 //! Two phases : firstly add the couples (start,end)
51 //! secondly perform then get the result
52 class ShapeAnalysis_WireOrder
60 Standard_EXPORT ShapeAnalysis_WireOrder();
62 //! Creates a WireOrder in 3D (if mode3d is True) or 2D (if False)
64 Standard_EXPORT ShapeAnalysis_WireOrder(const Standard_Boolean mode3d, const Standard_Real tol);
66 //! Sets new values. Clears the connexion list
67 //! If <mode3d> changes, also clears the edge list (else, doesnt)
68 Standard_EXPORT void SetMode (const Standard_Boolean mode3d, const Standard_Real tol);
70 //! Returns the working tolerance
71 Standard_EXPORT Standard_Real Tolerance() const;
73 //! Clears the list of edges, but not mode and tol
74 Standard_EXPORT void Clear();
76 //! Adds a couple of points 3D (start,end)
77 Standard_EXPORT void Add (const gp_XYZ& start3d, const gp_XYZ& end3d);
79 //! Adds a couple of points 2D (start,end)
80 Standard_EXPORT void Add (const gp_XY& start2d, const gp_XY& end2d);
82 //! Returns the count of added couples of points (one per edges)
83 Standard_EXPORT Standard_Integer NbEdges() const;
85 //! If this mode is True method perform does not sort edges of
86 //! different loops. The resulting order is first loop, second
88 Standard_EXPORT Standard_Boolean& KeepLoopsMode();
90 //! Computes the better order
91 //! If <closed> is True (D) considers also closure
92 //! Optimised if the couples were already in order
93 //! The criterium is : two couples in order if distance between
94 //! end-prec and start-cur is less then starting tolerance <tol>
95 //! Else, the smallest distance is reached
96 //! Gap corresponds to a smallest distance greater than <tol>
97 Standard_EXPORT void Perform (const Standard_Boolean closed = Standard_True);
99 //! Tells if Perform has been done
100 //! Else, the following methods returns original values
101 Standard_EXPORT Standard_Boolean IsDone() const;
103 //! Returns the status of the order (0 if not done) :
104 //! 0 : all edges are direct and in sequence
105 //! 1 : all edges are direct but some are not in sequence
106 //! 2 : in addition, unresolved gaps remain
107 //! -1 : some edges are reversed, but no gap remain
108 //! -2 : some edges are reversed and some gaps remain
109 //! -10 : COULD NOT BE RESOLVED, Failure on Reorder
110 //! gap : regarding starting <tol>
111 Standard_EXPORT Standard_Integer Status() const;
113 //! Returns the number of original edge which correspond to the
114 //! newly ordered number <n>
115 //! Warning : the returned value is NEGATIVE if edge should be reversed
116 Standard_EXPORT Standard_Integer Ordered (const Standard_Integer n) const;
118 //! Returns the values of the couple <num>, as 3D values
119 Standard_EXPORT void XYZ (const Standard_Integer num, gp_XYZ& start3d, gp_XYZ& end3d) const;
121 //! Returns the values of the couple <num>, as 2D values
122 Standard_EXPORT void XY (const Standard_Integer num, gp_XY& start2d, gp_XY& end2d) const;
124 //! Returns the gap between a couple and its preceeding
125 //! <num> is considered ordered
126 //! If <num> = 0 (D), returns the greatest gap found
127 Standard_EXPORT Standard_Real Gap (const Standard_Integer num = 0) const;
129 //! Determines the chains inside which successive edges have a gap
130 //! less than a given value. Queried by NbChains and Chain
131 Standard_EXPORT void SetChains (const Standard_Real gap);
133 //! Returns the count of computed chains
134 Standard_EXPORT Standard_Integer NbChains() const;
136 //! Returns, for the chain n0 num, starting and ending numbers of
137 //! edges. In the list of ordered edges (see Ordered for originals)
138 Standard_EXPORT void Chain (const Standard_Integer num, Standard_Integer& n1, Standard_Integer& n2) const;
140 //! Determines the couples of edges for which end and start fit
141 //! inside a given gap. Queried by NbCouples and Couple
142 Standard_EXPORT void SetCouples (const Standard_Real gap);
144 //! Returns the count of computed couples
145 Standard_EXPORT Standard_Integer NbCouples() const;
147 //! Returns, for the couple n0 num, the two implied edges
148 //! In the list of ordered edges
149 Standard_EXPORT void Couple (const Standard_Integer num, Standard_Integer& n1, Standard_Integer& n2) const;
164 Standard_Boolean myKeepLoops;
165 Handle(TColStd_HArray1OfInteger) myOrd;
166 Handle(TColStd_HArray1OfInteger) myChains;
167 Handle(TColStd_HArray1OfInteger) myCouples;
168 Handle(TColgp_HSequenceOfXYZ) myXYZ;
171 Standard_Integer myStat;
172 Standard_Boolean myMode;
183 #endif // _ShapeAnalysis_WireOrder_HeaderFile