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