1 -- Created on: 1995-03-23
2 -- Created by: Jing Cheng MEI
3 -- Copyright (c) 1995-1999 Matra Datavision
4 -- Copyright (c) 1999-2012 OPEN CASCADE SAS
6 -- The content of this file is subject to the Open CASCADE Technology Public
7 -- License Version 6.5 (the "License"). You may not use the content of this file
8 -- except in compliance with the License. Please obtain a copy of the License
9 -- at http://www.opencascade.org and read it completely before using this file.
11 -- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 -- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 -- The Original Code and all software distributed under the License is
15 -- distributed on an "AS IS" basis, without warranty of any kind, and the
16 -- Initial Developer hereby disclaims all such warranties, including without
17 -- limitation, any warranties of merchantability, fitness for a particular
18 -- purpose or non-infringement. Please see the License for the specific terms
19 -- and conditions governing the rights and limitations under the License.
22 -- Modified Thu May 7 15:20:25 1998 by David Carbonel (dcl)
23 -- Little faces management.
24 -- Add of Cutting option.
25 -- Optimisation of cutting fonction
26 -- Modified Thu Jan 21 13:00:58 MET 1999 by Jing Cheng MEI
27 -- Nonmanifold processing
29 class Sewing from BRepBuilderAPI inherits TShared from MMgt
31 ---Purpose: Provides methods to
33 -- - identify possible contigous boundaries (for control
36 -- - assemble contigous shapes into one shape.
37 -- Only manifold shapes will be found. Sewing will not
38 -- be done in case of multiple edges.
40 -- For sewing, use this function as following:
41 -- - create an empty object
42 -- - default tolerance 1.E-06
43 -- - with face analysis on
44 -- - with sewing operation on
45 -- - set the cutting option as you need (default True)
46 -- - define a tolerance
47 -- - add shapes to be sewed -> Add
48 -- - compute -> Perfom
49 -- - output the resulted shapes
50 -- - output free edges if necessary
51 -- - output multiple edges if necessary
52 -- - output the problems if any
54 -- For control, use this function as following:
55 -- - create an empty object
56 -- - default tolerance 1.E-06
57 -- - with face analysis on
58 -- - with sewing operation on
59 -- - set the cutting option as you need (default True)
60 -- - define a tolerance to capture contigous boundaries
61 -- - set if necessary face analysis off
62 -- - set sewing operation off
63 -- - add shapes to be controlled -> Add
64 -- - compute -> Perfom
65 -- - output couples of connected edges (contigous) and
66 -- their original boundary for control
67 -- - output the problems if any
74 ListOfShape from TopTools,
75 MapOfShape from TopTools,
76 DataMapOfShapeShape from TopTools,
77 DataMapOfShapeListOfShape from TopTools,
78 IndexedMapOfShape from TopTools,
79 IndexedDataMapOfShapeShape from TopTools,
80 IndexedDataMapOfShapeListOfShape from TopTools,
81 SequenceOfShape from TopTools,
82 Array1OfShape from TopTools,
84 Array1OfInteger from TColStd,
85 Array1OfPnt from TColgp,
86 Array2OfPnt2d from TColgp,
87 Array1OfBoolean from TColStd,
88 Array1OfReal from TColStd,
89 IndexedMapOfInteger from TColStd,
96 ReShape from BRepTools,
97 SequenceOfInteger from TColStd,
98 SequenceOfReal from TColStd,
99 SequenceOfPnt from TColgp,
100 ProgressIndicator from Message
104 OutOfRange from Standard,
105 NoSuchObject from Standard
109 Create(tolerance: Real = 1.0e-06; -- tolerance of connexity
110 option1 : Boolean = Standard_True; -- option for sewing
111 option2 : Boolean = Standard_True; -- option for analysis of degenerated shapes
112 option3 : Boolean = Standard_True; -- option for cutting of free edges.
113 option4 : Boolean = Standard_False) -- option for non manifold processing
114 returns Sewing from BRepBuilderAPI;
115 ---Purpose: Creates an object with
116 -- tolerance of connexity
117 -- option for sewing (if false only control)
118 -- option for analysis of degenerated shapes
119 -- option for cutting of free edges.
120 -- option for non manifold processing
122 Init(me : mutable; tolerance: Real = 1.0e-06; -- tolerance of connexity
123 option1: Boolean = Standard_True; -- option for sewing
124 option2: Boolean = Standard_True; -- option for analysis of degenerated shapes
125 option3: Boolean = Standard_True; -- option for cutting free edge after first merging
126 -- This option can be set to False if no edge need to be cut.
127 option4: Boolean = Standard_False);-- option for non manifold processing
128 ---Purpose: initialize the parameters if necessary
130 Load(me : mutable; shape : Shape from TopoDS);
131 ---Purpose: Loades the context shape.
133 Add(me : mutable; shape : Shape from TopoDS);
134 ---Purpose: Defines the shapes to be sewed or controlled
136 Perform(me : mutable;
137 thePI : ProgressIndicator from Message = 0);
138 ---Purpose: Computing
139 -- thePI - progress indicator of algorithm
141 SewedShape(me) returns Shape from TopoDS;
142 ---C++: return const &
143 ---Purpose: Gives the sewed shape
144 -- a null shape if nothing constructed
145 -- may be a face, a shell, a solid or a compound
147 NbFreeEdges(me) returns Integer;
148 ---Purpose: Gives the number of free edges (edge shared by one face)
150 FreeEdge(me; index: Integer) returns Edge from TopoDS
151 raises OutOfRange from Standard; -- raised if index < 1 or > NbFreeEdges
152 ---C++: return const &
153 ---Purpose: Gives each free edge
155 NbMultipleEdges(me) returns Integer;
156 ---Purpose: Gives the number of multiple edges
157 -- (edge shared by more than two faces)
159 MultipleEdge(me; index: Integer) returns Edge from TopoDS
160 raises OutOfRange from Standard; -- raised if index < 1 or > NbMultipleEdges
161 ---C++: return const &
162 ---Purpose: Gives each multiple edge
164 NbContigousEdges(me) returns Integer;
165 ---Purpose: Gives the number of contigous edges (edge shared by two faces)
167 ContigousEdge(me; index: Integer) returns Edge from TopoDS
168 raises OutOfRange from Standard; -- raised if index < 1 or > NbContigousEdges
169 ---C++: return const &
170 ---Purpose: Gives each contigous edge
172 ContigousEdgeCouple(me; index: Integer) returns ListOfShape from TopTools
173 raises OutOfRange from Standard; -- raised if index < 1 or > NbContigousEdges
174 ---C++: return const &
175 ---Purpose: Gives the sections (edge) belonging to a contigous edge
177 IsSectionBound(me; section: Edge from TopoDS) returns Boolean;
178 ---Purpose: Indicates if a section is bound (before use SectionToBoundary)
180 SectionToBoundary(me; section: Edge from TopoDS) returns Edge from TopoDS
181 raises NoSuchObject from Standard; -- raised if section has not been bound
182 ---C++: return const &
183 ---Purpose: Gives the original edge (free boundary) which becomes the
184 -- the section. Remember that sections constitute common edges.
185 -- This imformation is important for control because with
186 -- original edge we can find the surface to which the section
189 NbDegeneratedShapes(me) returns Integer;
190 ---Purpose: Gives the number of degenerated shapes
192 DegeneratedShape(me; index: Integer) returns Shape from TopoDS
193 raises OutOfRange from Standard; -- raised if index < 1 or > NbDegeneratedShapes
194 ---C++: return const &
195 ---Purpose: Gives each degenerated shape
197 IsDegenerated(me; shape: Shape from TopoDS) returns Boolean;
198 ---Purpose: Indicates if a input shape is degenerated
200 IsModified(me; shape: Shape from TopoDS) returns Boolean;
201 ---Purpose: Indicates if a input shape has been modified
203 Modified(me ; shape: Shape from TopoDS) returns Shape from TopoDS
204 raises NoSuchObject from Standard; -- raised if shape has not been modified
205 ---C++: return const &
206 ---Purpose: Gives a modifieded shape
208 IsModifiedSubShape(me; shape: Shape from TopoDS) returns Boolean;
209 ---Purpose: Indicates if a input subshape has been modified
211 ModifiedSubShape(me ; shape: Shape from TopoDS) returns Shape from TopoDS
212 raises NoSuchObject from Standard; -- raised if shape has not been modified
213 ---Purpose: Gives a modifieded subshape
216 ---Purpose: print the informations
218 NbDeletedFaces(me) returns Integer;
219 ---Purpose: Gives the number of deleted faces (faces smallest than tolerance)
221 DeletedFace(me; index: Integer) returns Face from TopoDS
222 raises OutOfRange from Standard; -- raised if index < 1 or > NbDeletedFaces
223 ---C++: return const &
224 ---Purpose: Gives each deleted face
226 WhichFace(me; theEdg: Edge from TopoDS; index: Integer = 1) returns Face from TopoDS;
227 ---Purpose: Gives a modified shape
229 SameParameterMode(me) returns Boolean;
231 ---Purpose: Gets same parameter mode.
233 SetSameParameterMode(me: in mutable; SameParameterMode : Boolean);
235 ---Purpose: Sets same parameter mode.
237 Tolerance(me) returns Real;
239 ---Purpose: Gives set tolerance.
241 SetTolerance(me: mutable; theToler : Real);
243 ---Purpose: Sets tolerance
244 MinTolerance(me) returns Real;
246 ---Purpose: Gives set min tolerance.
248 SetMinTolerance(me: mutable; theMinToler : Real);
250 ---Purpose: Sets min tolerance
252 MaxTolerance(me) returns Real;
254 ---Purpose: Gives set max tolerance
256 SetMaxTolerance(me:mutable; theMaxToler : Real);
258 ---Purpose: Sets max tolerance.
260 FaceMode(me) returns Boolean;
262 ---Purpose: Returns mode for sewing faces By default - true.
264 SetFaceMode(me: mutable; theFaceMode : Boolean);
266 ---Purpose: Sets mode for sewing faces By default - true.
268 FloatingEdgesMode(me) returns Boolean;
270 ---Purpose: Returns mode for sewing floating edges By default - false.
272 SetFloatingEdgesMode(me: mutable; theFloatingEdgesMode : Boolean);
274 ---Purpose: Sets mode for sewing floating edges By default - false.
276 -- CuttingFloatingEdgesMode(me) returns Boolean;
278 ---Purpose: Returns mode for cutting floating edges By default - false.
280 -- SetCuttingFloatingEdgesMode(me: mutable; theCuttingFloatingEdgesMode : Boolean);
282 ---Purpose: Sets mode for cutting floating edges By default - false.
284 LocalTolerancesMode(me) returns Boolean;
286 ---Purpose: Returns mode for accounting of local tolerances
287 -- of edges and vertices during of merging.
289 SetLocalTolerancesMode(me: mutable; theLocalTolerancesMode : Boolean);
291 ---Purpose: Sets mode for accounting of local tolerances
292 -- of edges and vertices during of merging
293 -- in this case WorkTolerance = myTolerance + tolEdge1+ tolEdg2;
295 SetNonManifoldMode(me: mutable; theNonManifoldMode : Boolean);
297 ---Purpose: Sets mode for non-manifold sewing.
299 NonManifoldMode(me) returns Boolean;
301 ---Purpose: Gets mode for non-manifold sewing.
302 -------------------------
303 --- INTERNAL FUCTIONS ---
304 -------------------------
306 Cutting(me : mutable;
307 thePI : ProgressIndicator from Message = 0) is protected;
308 ---Purpose: Performs cutting of sections
309 -- thePI - progress indicator of processing
311 Merging(me : mutable; passage : Boolean;
312 thePI : ProgressIndicator from Message = 0) is protected;
315 Edge1 : Edge from TopoDS;
316 Edge2 : Edge from TopoDS;
317 fase : Face from TopoDS)
318 returns Boolean is protected;
320 FindCandidates(me : mutable;
321 seqSections : in out SequenceOfShape from TopTools;
322 mapReference : in out IndexedMapOfInteger from TColStd;
323 seqCandidates : in out SequenceOfInteger from TColStd;
324 seqOrientations : in out SequenceOfInteger from TColStd)
325 returns Boolean is protected;
327 AnalysisNearestEdges(me : mutable;
328 sequenceSec : SequenceOfShape from TopTools;
329 seqIndCandidate : in out SequenceOfInteger from TColStd;
330 seqOrientations : in out SequenceOfInteger from TColStd;
331 evalDist : Boolean = Standard_True) is protected;
335 MergedNearestEdges(me : mutable;
336 edge : Shape from TopoDS;
337 SeqMergedEdge : in out SequenceOfShape from TopTools;
338 SeqMergedOri : in out SequenceOfInteger from TColStd)
339 returns Boolean is protected;
340 ---Purpose: Merged nearest edges.
342 EdgeProcessing(me : mutable;
343 thePI : ProgressIndicator from Message = 0) is protected;
345 CreateOutputInformations(me : mutable) is protected;
347 ---------------------------------
348 --- VIRTUAL INTERNAL FUCTIONS ---
349 ---------------------------------
351 IsUClosedSurface(me; surf : Surface from Geom; theEdge : Shape from TopoDS;
352 theloc : Location from TopLoc)
353 returns Boolean is virtual protected;
354 ---Purpose: Defines if surface is U closed.
356 IsVClosedSurface(me; surf : Surface from Geom; theEdge : Shape from TopoDS;
357 theloc : Location from TopLoc)
358 returns Boolean is virtual protected;
359 ---Purpose:Defines if surface is V closed.
361 FaceAnalysis(me : mutable;
362 thePI : ProgressIndicator from Message = 0) is virtual protected;
364 -- This method is called from Perform only
365 -- thePI - progress indicator of processing
367 FindFreeBoundaries(me : mutable) is virtual protected;
369 -- This method is called from Perform only
371 VerticesAssembling(me : mutable;
372 thePI : ProgressIndicator from Message = 0) is virtual protected;
374 -- This method is called from Perform only
375 -- thePI - progress indicator of processing
377 CreateSewedShape(me : mutable) is virtual protected;
379 -- This method is called from Perform only
381 GetFreeWires(me : mutable;
382 MapFreeEdges : in out MapOfShape from TopTools;
383 seqWires : in out SequenceOfShape from TopTools) is virtual protected;
384 ---Purpose: Get wire from free edges.
385 -- This method is called from EdgeProcessing only
388 sequenceSec : in out SequenceOfShape from TopTools;
389 secForward : in out Array1OfBoolean from TColStd;
390 tabAng : in out Array1OfReal from TColStd;
391 indRef : in Integer) is virtual protected;
393 -- This method is called from MergingOfSections only
395 EvaluateDistances(me;
396 sequenceSec : in out SequenceOfShape from TopTools;
397 secForward : in out Array1OfBoolean from TColStd;
398 tabAng : in out Array1OfReal from TColStd;
399 arrLen : in out Array1OfReal from TColStd;
400 tabMinDist : in out Array1OfReal from TColStd;
401 indRef : in Integer) is virtual protected;
403 -- This method is called from MergingOfSections only
406 CurvePtr : Curve from Geom2d;
407 FirstOnCurve : Real from Standard;
408 LastOnCurve : Real from Standard;
409 RequestedFirst : Real from Standard;
410 RequestedLast : Real from Standard)
411 returns Curve from Geom2d is virtual protected;
413 -- This method is called from SameParameterEdge only
415 SameParameter(me; edge : Edge from TopoDS) is virtual protected;
417 -- This method is called from SameParameterEdge only
419 SameParameterEdge(me : mutable;
420 edge : Shape from TopoDS;
421 seqEdges : SequenceOfShape from TopTools;
422 seqForward : SequenceOfInteger from TColStd;
423 mapMerged : in out MapOfShape from TopTools;
424 locReShape : ReShape from BRepTools)
425 returns Edge from TopoDS is virtual protected;
427 -- This method is called from Merging only
429 SameParameterEdge(me : mutable;
430 edge1 : Edge from TopoDS;
431 edge2 : Edge from TopoDS;
432 listFaces1 : ListOfShape from TopTools;
433 listFaces2 : ListOfShape from TopTools;
434 secForward : Boolean ;
435 whichSec : in out Integer;
436 firstCall : Boolean = Standard_True)
437 returns Edge from TopoDS is virtual protected;
439 -- This method is called from Merging only
441 ProjectPointsOnCurve(me;
442 arrPnt : Array1OfPnt from TColgp;
443 Crv : Curve from Geom;
444 first : Real from Standard;
445 last : Real from Standard;
446 arrDist : in out Array1OfReal from TColStd;
447 arrPara : in out Array1OfReal from TColStd;
448 arrProj : in out Array1OfPnt from TColgp;
449 isConsiderEnds : in Boolean from Standard) is protected;
450 ---Purpose: Projects points on curve
451 -- This method is called from Cutting only
453 CreateCuttingNodes(me : mutable;
454 MapVert : IndexedMapOfShape from TopTools;
455 bound : Shape from TopoDS;
456 vfirst : Shape from TopoDS;
457 vlast : Shape from TopoDS;
458 arrDist : Array1OfReal from TColStd;
459 arrPara : Array1OfReal from TColStd;
460 arrPnt : Array1OfPnt from TColgp;
461 seqNode : in out SequenceOfShape from TopTools;
462 seqPara : in out SequenceOfReal from TColStd) is virtual protected;
463 ---Purpose: Creates cutting vertices on projections
464 -- This method is called from Cutting only
466 CreateSections(me : mutable;
467 bound : Shape from TopoDS;
468 seqNode : SequenceOfShape from TopTools;
469 seqPara : SequenceOfReal from TColStd;
470 listEdge : in out ListOfShape from TopTools) is virtual protected;
471 ---Purpose: Performs cutting of bound
472 -- This method is called from Cutting only
474 SameParameterShape(me : mutable) is virtual protected;
475 ---Purpose: Makes all edges from shape same parameter
476 -- if SameParameterMode is equal to Standard_True
477 -- This method is called from Perform only
482 myTolerance : Real is protected;
483 mySewing : Boolean is protected;
484 myAnalysis : Boolean is protected;
485 myCutting : Boolean is protected;
486 -- Indicates if the cutting will be done or not.
487 -- Default value is true.
488 myNonmanifold : Boolean is protected;
489 myFaceMode : Boolean; -- Mode for sewing faces by default true
490 myFloatingEdgesMode : Boolean; -- Mode for sewing floating edges by default - false
491 -- myCuttingFloatingEdgesMode : Boolean; -- Mode for cutting of floating edges by default - false
492 mySameParameterMode : Boolean;
493 myLocalToleranceMode : Boolean;
495 myOldShapes : IndexedDataMapOfShapeShape from TopTools is protected;
496 -- input shape -> input shape after analysis
497 mySewedShape : Shape from TopoDS is protected;
498 -- contains the sewed shape
499 myDegenerated : IndexedMapOfShape from TopTools is protected;
500 -- contains all degenerated shapes
501 myFreeEdges : IndexedMapOfShape from TopTools is protected;
502 -- contains all free edges
503 -- (edge shared by only one face)
504 myMultipleEdges : IndexedMapOfShape from TopTools is protected;
505 -- contains all multiple edges
506 -- (edge shared by more than two faces)
507 myContigousEdges : IndexedDataMapOfShapeListOfShape from TopTools is protected;
508 -- contains all contigous edges
509 -- (edge shared by two faces) and a list of sections
510 -- (two edges) which constitute each contigous edge
511 myContigSecBound : DataMapOfShapeShape is protected;
512 -- for each section belong to a contigous edge
513 -- indicates its the original free boundary
516 -- OldShape : input shapes
517 -- Shape : input shapes after analysis
518 -- Bound : free boundaries
519 -- Section : free boundaries after cutting
520 -- Edge : connected sections become edge
521 -- - Free edge : edge shared by one face
522 -- - Contigous edge : edge shared by two faces
523 -- - Multiple edge : edge shared by more than two faces
524 -- Vertex : vertices on free boundaries
525 -- Node : assembled vertices become node
527 myNbShapes : Integer is protected; -- number of input shapes after analysis
528 myNbVertices : Integer is protected; -- number of nodes after assembling
529 myNbEdges : Integer is protected; -- number of edges after merging
531 myBoundFaces : IndexedDataMapOfShapeListOfShape from TopTools is protected;
532 -- for EACH bound contains a list of faces (REFERENCE map)
533 myBoundSections : DataMapOfShapeListOfShape from TopTools is protected;
534 -- for bound contains a list of cutting sections if any
535 --mySectionEdge : DataMapOfShapeShape from TopTools is protected;
536 -- for section contains a merged edge for this section
537 mySectionBound : DataMapOfShapeShape from TopTools is protected;
538 -- for EACH section contains its bound
539 myVertexNode : IndexedDataMapOfShapeShape from TopTools is protected;
540 -- for EACH original vertex contains a node
541 myVertexNodeFree : IndexedDataMapOfShapeShape from TopTools is protected;
542 -- for EACH floating vertex contains a node
543 myNodeSections : DataMapOfShapeListOfShape from TopTools is protected;
544 -- for EACH node contains a list of sections
545 myCuttingNode : DataMapOfShapeListOfShape from TopTools is protected;
546 -- nodes cutting edges
547 myLittleFace : IndexedMapOfShape from TopTools is protected;
548 -- Faces to be suppress because they are too little
549 myMinTolerance : Real;
551 myMaxTolerance : Real;
553 myShape : Shape from TopoDS is protected;
555 myReShape : ReShape from BRepTools is protected;
556 myMergedEdges : MapOfShape from TopTools;