0024870: Provide OCCT RTTI test cases
[occt.git] / src / BRepBuilderAPI / BRepBuilderAPI_Sewing.hxx
1 // Created on: 1995-03-23
2 // Created by: Jing Cheng MEI
3 // Copyright (c) 1995-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 _BRepBuilderAPI_Sewing_HeaderFile
18 #define _BRepBuilderAPI_Sewing_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
22
23 #include <Standard_Real.hxx>
24 #include <Standard_Boolean.hxx>
25 #include <TopTools_IndexedDataMapOfShapeShape.hxx>
26 #include <TopoDS_Shape.hxx>
27 #include <TopTools_IndexedMapOfShape.hxx>
28 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
29 #include <TopTools_DataMapOfShapeShape.hxx>
30 #include <Standard_Integer.hxx>
31 #include <TopTools_DataMapOfShapeListOfShape.hxx>
32 #include <TopTools_MapOfShape.hxx>
33 #include <MMgt_TShared.hxx>
34 #include <TopTools_ListOfShape.hxx>
35 #include <TopTools_SequenceOfShape.hxx>
36 #include <TColStd_IndexedMapOfInteger.hxx>
37 #include <TColStd_SequenceOfInteger.hxx>
38 #include <TColStd_Array1OfBoolean.hxx>
39 #include <TColStd_Array1OfReal.hxx>
40 #include <TColgp_Array1OfPnt.hxx>
41 #include <TColStd_SequenceOfReal.hxx>
42
43 #include <Message_ProgressIndicator.hxx>
44
45 class BRepTools_ReShape;
46 class Standard_OutOfRange;
47 class Standard_NoSuchObject;
48 class TopoDS_Shape;
49 class Message_ProgressIndicator;
50 class TopoDS_Edge;
51 class TopoDS_Face;
52 class Geom_Surface;
53 class TopLoc_Location;
54 class Geom2d_Curve;
55 class Geom_Curve;
56
57
58 class BRepBuilderAPI_Sewing;
59 DEFINE_STANDARD_HANDLE(BRepBuilderAPI_Sewing, MMgt_TShared)
60
61 //! Provides methods to
62 //!
63 //! - identify possible contigous boundaries (for control
64 //! afterwards (of continuity: C0, C1, ...))
65 //!
66 //! - assemble contigous shapes into one shape.
67 //! Only manifold shapes will be found. Sewing will not
68 //! be done in case of multiple edges.
69 //!
70 //! For sewing, use this function as following:
71 //! - create an empty object
72 //! - default tolerance 1.E-06
73 //! - with face analysis on
74 //! - with sewing operation on
75 //! - set the cutting option as you need (default True)
76 //! - define a tolerance
77 //! - add shapes to be sewed -> Add
78 //! - compute -> Perfom
79 //! - output the resulted shapes
80 //! - output free edges if necessary
81 //! - output multiple edges if necessary
82 //! - output the problems if any
83 class BRepBuilderAPI_Sewing : public MMgt_TShared
84 {
85
86 public:
87
88   
89   //! Creates an object with
90   //! tolerance of connexity
91   //! option for sewing (if false only control)
92   //! option for analysis of degenerated shapes
93   //! option for cutting of free edges.
94   //! option for non manifold processing
95   Standard_EXPORT BRepBuilderAPI_Sewing(const Standard_Real tolerance = 1.0e-06, const Standard_Boolean option1 = Standard_True, const Standard_Boolean option2 = Standard_True, const Standard_Boolean option3 = Standard_True, const Standard_Boolean option4 = Standard_False);
96   
97   //! initialize the parameters if necessary
98   Standard_EXPORT void Init (const Standard_Real tolerance = 1.0e-06, const Standard_Boolean option1 = Standard_True, const Standard_Boolean option2 = Standard_True, const Standard_Boolean option3 = Standard_True, const Standard_Boolean option4 = Standard_False);
99   
100   //! Loades the context shape.
101   Standard_EXPORT void Load (const TopoDS_Shape& shape);
102   
103   //! Defines the shapes to be sewed or controlled
104   Standard_EXPORT void Add (const TopoDS_Shape& shape);
105   
106   //! Computing
107   //! thePI - progress indicator of algorithm
108   Standard_EXPORT void Perform (const Handle(Message_ProgressIndicator)& thePI = 0);
109   
110   //! Gives the sewed shape
111   //! a null shape if nothing constructed
112   //! may be a face, a shell, a solid or a compound
113   Standard_EXPORT const TopoDS_Shape& SewedShape() const;
114   
115   //! set context
116   Standard_EXPORT void SetContext (const Handle(BRepTools_ReShape)& theContext);
117   
118   //! return context
119   Standard_EXPORT const Handle(BRepTools_ReShape)& GetContext() const;
120   
121   //! Gives the number of free edges (edge shared by one face)
122   Standard_EXPORT Standard_Integer NbFreeEdges() const;
123   
124   //! Gives each free edge
125   Standard_EXPORT const TopoDS_Edge& FreeEdge (const Standard_Integer index) const;
126   
127   //! Gives the number of multiple edges
128   //! (edge shared by more than two faces)
129   Standard_EXPORT Standard_Integer NbMultipleEdges() const;
130   
131   //! Gives each multiple edge
132   Standard_EXPORT const TopoDS_Edge& MultipleEdge (const Standard_Integer index) const;
133   
134   //! Gives the number of contigous edges (edge shared by two faces)
135   Standard_EXPORT Standard_Integer NbContigousEdges() const;
136   
137   //! Gives each contigous edge
138   Standard_EXPORT const TopoDS_Edge& ContigousEdge (const Standard_Integer index) const;
139   
140   //! Gives the sections (edge) belonging to a contigous edge
141   Standard_EXPORT const TopTools_ListOfShape& ContigousEdgeCouple (const Standard_Integer index) const;
142   
143   //! Indicates if a section is bound (before use SectionToBoundary)
144   Standard_EXPORT Standard_Boolean IsSectionBound (const TopoDS_Edge& section) const;
145   
146   //! Gives the original edge (free boundary) which becomes the
147   //! the section. Remember that sections constitute  common edges.
148   //! This imformation is important for control because with
149   //! original edge we can find the surface to which the section
150   //! is attached.
151   Standard_EXPORT const TopoDS_Edge& SectionToBoundary (const TopoDS_Edge& section) const;
152   
153   //! Gives the number of degenerated shapes
154   Standard_EXPORT Standard_Integer NbDegeneratedShapes() const;
155   
156   //! Gives each degenerated shape
157   Standard_EXPORT const TopoDS_Shape& DegeneratedShape (const Standard_Integer index) const;
158   
159   //! Indicates if a input shape is degenerated
160   Standard_EXPORT Standard_Boolean IsDegenerated (const TopoDS_Shape& shape) const;
161   
162   //! Indicates if a input shape has been modified
163   Standard_EXPORT Standard_Boolean IsModified (const TopoDS_Shape& shape) const;
164   
165   //! Gives a modifieded shape
166   Standard_EXPORT const TopoDS_Shape& Modified (const TopoDS_Shape& shape) const;
167   
168   //! Indicates if a input subshape has been modified
169   Standard_EXPORT Standard_Boolean IsModifiedSubShape (const TopoDS_Shape& shape) const;
170   
171   //! Gives a modifieded subshape
172   Standard_EXPORT TopoDS_Shape ModifiedSubShape (const TopoDS_Shape& shape) const;
173   
174   //! print the informations
175   Standard_EXPORT void Dump() const;
176   
177   //! Gives the number of deleted faces (faces smallest than tolerance)
178   Standard_EXPORT Standard_Integer NbDeletedFaces() const;
179   
180   //! Gives each deleted face
181   Standard_EXPORT const TopoDS_Face& DeletedFace (const Standard_Integer index) const;
182   
183   //! Gives a modified shape
184   Standard_EXPORT TopoDS_Face WhichFace (const TopoDS_Edge& theEdg, const Standard_Integer index = 1) const;
185   
186   //! Gets same parameter mode.
187     Standard_Boolean SameParameterMode() const;
188   
189   //! Sets same parameter mode.
190     void SetSameParameterMode (const Standard_Boolean SameParameterMode);
191   
192   //! Gives set tolerance.
193     Standard_Real Tolerance() const;
194   
195   //! Sets tolerance
196     void SetTolerance (const Standard_Real theToler);
197   
198   //! Gives set min tolerance.
199     Standard_Real MinTolerance() const;
200   
201   //! Sets min tolerance
202     void SetMinTolerance (const Standard_Real theMinToler);
203   
204   //! Gives set max tolerance
205     Standard_Real MaxTolerance() const;
206   
207   //! Sets max tolerance.
208     void SetMaxTolerance (const Standard_Real theMaxToler);
209   
210   //! Returns mode for sewing faces By default - true.
211     Standard_Boolean FaceMode() const;
212   
213   //! Sets mode for sewing faces By default - true.
214     void SetFaceMode (const Standard_Boolean theFaceMode);
215   
216   //! Returns mode for sewing floating edges By default - false.
217     Standard_Boolean FloatingEdgesMode() const;
218   
219   //! Sets mode for sewing floating edges By default - false.
220   //! Returns mode for cutting floating edges By default - false.
221   //! Sets mode for cutting floating edges By default - false.
222     void SetFloatingEdgesMode (const Standard_Boolean theFloatingEdgesMode);
223   
224   //! Returns mode for accounting of local tolerances
225   //! of edges and vertices during of merging.
226     Standard_Boolean LocalTolerancesMode() const;
227   
228   //! Sets mode for accounting of local tolerances
229   //! of edges and vertices during of merging
230   //! in this case WorkTolerance = myTolerance + tolEdge1+ tolEdg2;
231     void SetLocalTolerancesMode (const Standard_Boolean theLocalTolerancesMode);
232   
233   //! Sets mode for non-manifold sewing.
234     void SetNonManifoldMode (const Standard_Boolean theNonManifoldMode);
235   
236   //! Gets mode for non-manifold sewing.
237   //!
238   //! INTERNAL FUCTIONS ---
239     Standard_Boolean NonManifoldMode() const;
240
241
242
243
244   DEFINE_STANDARD_RTTI(BRepBuilderAPI_Sewing,MMgt_TShared)
245
246 protected:
247
248   
249   //! Performs cutting of sections
250   //! thePI - progress indicator of processing
251   Standard_EXPORT void Cutting (const Handle(Message_ProgressIndicator)& thePI = 0);
252   
253   Standard_EXPORT void Merging (const Standard_Boolean passage, const Handle(Message_ProgressIndicator)& thePI = 0);
254   
255   Standard_EXPORT Standard_Boolean IsMergedClosed (const TopoDS_Edge& Edge1, const TopoDS_Edge& Edge2, const TopoDS_Face& fase) const;
256   
257   Standard_EXPORT Standard_Boolean FindCandidates (TopTools_SequenceOfShape& seqSections, TColStd_IndexedMapOfInteger& mapReference, TColStd_SequenceOfInteger& seqCandidates, TColStd_SequenceOfInteger& seqOrientations);
258   
259   Standard_EXPORT void AnalysisNearestEdges (const TopTools_SequenceOfShape& sequenceSec, TColStd_SequenceOfInteger& seqIndCandidate, TColStd_SequenceOfInteger& seqOrientations, const Standard_Boolean evalDist = Standard_True);
260   
261   //! Merged nearest edges.
262   Standard_EXPORT Standard_Boolean MergedNearestEdges (const TopoDS_Shape& edge, TopTools_SequenceOfShape& SeqMergedEdge, TColStd_SequenceOfInteger& SeqMergedOri);
263   
264   Standard_EXPORT void EdgeProcessing (const Handle(Message_ProgressIndicator)& thePI = 0);
265   
266   Standard_EXPORT void CreateOutputInformations();
267   
268   //! Defines if surface is U closed.
269   Standard_EXPORT virtual Standard_Boolean IsUClosedSurface (const Handle(Geom_Surface)& surf, const TopoDS_Shape& theEdge, const TopLoc_Location& theloc) const;
270   
271   //! Defines if surface is V closed.
272   Standard_EXPORT virtual Standard_Boolean IsVClosedSurface (const Handle(Geom_Surface)& surf, const TopoDS_Shape& theEdge, const TopLoc_Location& theloc) const;
273   
274
275   //! This method is called from Perform only
276   //! thePI - progress indicator of processing
277   Standard_EXPORT virtual void FaceAnalysis (const Handle(Message_ProgressIndicator)& thePI = 0);
278   
279
280   //! This method is called from Perform only
281   Standard_EXPORT virtual void FindFreeBoundaries();
282   
283
284   //! This method is called from Perform only
285   //! thePI - progress indicator of processing
286   Standard_EXPORT virtual void VerticesAssembling (const Handle(Message_ProgressIndicator)& thePI = 0);
287   
288
289   //! This method is called from Perform only
290   Standard_EXPORT virtual void CreateSewedShape();
291   
292   //! Get wire from free edges.
293   //! This method is called from EdgeProcessing only
294   Standard_EXPORT virtual void GetFreeWires (TopTools_MapOfShape& MapFreeEdges, TopTools_SequenceOfShape& seqWires);
295   
296
297   //! This method is called from MergingOfSections only
298   Standard_EXPORT virtual void EvaluateAngulars (TopTools_SequenceOfShape& sequenceSec, TColStd_Array1OfBoolean& secForward, TColStd_Array1OfReal& tabAng, const Standard_Integer indRef) const;
299   
300
301   //! This method is called from MergingOfSections only
302   Standard_EXPORT virtual void EvaluateDistances (TopTools_SequenceOfShape& sequenceSec, TColStd_Array1OfBoolean& secForward, TColStd_Array1OfReal& tabAng, TColStd_Array1OfReal& arrLen, TColStd_Array1OfReal& tabMinDist, const Standard_Integer indRef) const;
303   
304
305   //! This method is called from SameParameterEdge only
306   Standard_EXPORT virtual Handle(Geom2d_Curve) SameRange (const Handle(Geom2d_Curve)& CurvePtr, const Standard_Real FirstOnCurve, const Standard_Real LastOnCurve, const Standard_Real RequestedFirst, const Standard_Real RequestedLast) const;
307   
308
309   //! This method is called from SameParameterEdge only
310   Standard_EXPORT virtual void SameParameter (const TopoDS_Edge& edge) const;
311   
312
313   //! This method is called from Merging only
314   Standard_EXPORT virtual TopoDS_Edge SameParameterEdge (const TopoDS_Shape& edge, const TopTools_SequenceOfShape& seqEdges, const TColStd_SequenceOfInteger& seqForward, TopTools_MapOfShape& mapMerged, const Handle(BRepTools_ReShape)& locReShape);
315   
316
317   //! This method is called from Merging only
318   Standard_EXPORT virtual TopoDS_Edge SameParameterEdge (const TopoDS_Edge& edge1, const TopoDS_Edge& edge2, const TopTools_ListOfShape& listFaces1, const TopTools_ListOfShape& listFaces2, const Standard_Boolean secForward, Standard_Integer& whichSec, const Standard_Boolean firstCall = Standard_True);
319   
320   //! Projects points on curve
321   //! This method is called from Cutting only
322   Standard_EXPORT void ProjectPointsOnCurve (const TColgp_Array1OfPnt& arrPnt, const Handle(Geom_Curve)& Crv, const Standard_Real first, const Standard_Real last, TColStd_Array1OfReal& arrDist, TColStd_Array1OfReal& arrPara, TColgp_Array1OfPnt& arrProj, const Standard_Boolean isConsiderEnds) const;
323   
324   //! Creates cutting vertices on projections
325   //! This method is called from Cutting only
326   Standard_EXPORT virtual void CreateCuttingNodes (const TopTools_IndexedMapOfShape& MapVert, const TopoDS_Shape& bound, const TopoDS_Shape& vfirst, const TopoDS_Shape& vlast, const TColStd_Array1OfReal& arrDist, const TColStd_Array1OfReal& arrPara, const TColgp_Array1OfPnt& arrPnt, TopTools_SequenceOfShape& seqNode, TColStd_SequenceOfReal& seqPara);
327   
328   //! Performs cutting of bound
329   //! This method is called from Cutting only
330   Standard_EXPORT virtual void CreateSections (const TopoDS_Shape& bound, const TopTools_SequenceOfShape& seqNode, const TColStd_SequenceOfReal& seqPara, TopTools_ListOfShape& listEdge);
331   
332   //! Makes all edges from shape same parameter
333   //! if SameParameterMode is equal to Standard_True
334   //! This method is called from Perform only
335   Standard_EXPORT virtual void SameParameterShape();
336
337   Standard_Real myTolerance;
338   Standard_Boolean mySewing;
339   Standard_Boolean myAnalysis;
340   Standard_Boolean myCutting;
341   Standard_Boolean myNonmanifold;
342   TopTools_IndexedDataMapOfShapeShape myOldShapes;
343   TopoDS_Shape mySewedShape;
344   TopTools_IndexedMapOfShape myDegenerated;
345   TopTools_IndexedMapOfShape myFreeEdges;
346   TopTools_IndexedMapOfShape myMultipleEdges;
347   TopTools_IndexedDataMapOfShapeListOfShape myContigousEdges;
348   TopTools_DataMapOfShapeShape myContigSecBound;
349   Standard_Integer myNbShapes;
350   Standard_Integer myNbVertices;
351   Standard_Integer myNbEdges;
352   TopTools_IndexedDataMapOfShapeListOfShape myBoundFaces;
353   TopTools_DataMapOfShapeListOfShape myBoundSections;
354   TopTools_DataMapOfShapeShape mySectionBound;
355   TopTools_IndexedDataMapOfShapeShape myVertexNode;
356   TopTools_IndexedDataMapOfShapeShape myVertexNodeFree;
357   TopTools_DataMapOfShapeListOfShape myNodeSections;
358   TopTools_DataMapOfShapeListOfShape myCuttingNode;
359   TopTools_IndexedMapOfShape myLittleFace;
360   TopoDS_Shape myShape;
361   Handle(BRepTools_ReShape) myReShape;
362
363
364 private:
365
366
367   Standard_Boolean myFaceMode;
368   Standard_Boolean myFloatingEdgesMode;
369   Standard_Boolean mySameParameterMode;
370   Standard_Boolean myLocalToleranceMode;
371   Standard_Real myMinTolerance;
372   Standard_Real myMaxTolerance;
373   TopTools_MapOfShape myMergedEdges;
374
375
376 };
377
378
379 #include <BRepBuilderAPI_Sewing.lxx>
380
381
382
383
384
385 #endif // _BRepBuilderAPI_Sewing_HeaderFile