0022312: Translation of french commentaries in OCCT files
[occt.git] / src / BRepOffset / BRepOffset_MakeLoops.cxx
CommitLineData
7fd59977 1// File: BRepOffset_MakeLoops.cxx
2// Created: Thu Sep 5 15:48:34 1996
3// Author: Yves FRICAUD
4// <yfr@claquox.paris1.matra-dtv.fr>
5
6#include <stdio.h>
7
8#include <BRepOffset_MakeLoops.ixx>
9#include <BRepAlgo_Loop.hxx>
10
11
12#include <BRep_Builder.hxx>
13#include <BRep_Tool.hxx>
14#include <TopExp.hxx>
15#include <TopExp_Explorer.hxx>
16#include <TopTools_ListIteratorOfListOfShape.hxx>
17#include <TopoDS.hxx>
18#include <TopoDS_Face.hxx>
19#include <TopoDS_Edge.hxx>
20#include <TopoDS_Vertex.hxx>
21#include <TopTools_MapOfShape.hxx>
22#include <TopoDS_Iterator.hxx>
23#include <BRep_TVertex.hxx>
24
25#ifdef DRAW
26#include <DBRep.hxx>
27#endif
28#ifdef DEB
29Standard_Integer NbF = 1;
30static Standard_Boolean Affich = Standard_False;
31//POP pour NT
32//char name[100];
33#endif
34
35
36BRepOffset_MakeLoops::BRepOffset_MakeLoops()
37{
38}
39
40//=======================================================================
41//function : Build
42//purpose :
43//=======================================================================
44
45void BRepOffset_MakeLoops::Build(const TopTools_ListOfShape& LF,
46 const Handle(BRepAlgo_AsDes)& AsDes,
47 BRepAlgo_Image& Image)
48{
49 TopTools_ListIteratorOfListOfShape it(LF);
50 TopTools_ListIteratorOfListOfShape itl,itLCE;
51 BRepAlgo_Loop Loops;
52 Loops.VerticesForSubstitute( myVerVerMap );
53
54 for (; it.More(); it.Next()) {
55 const TopoDS_Face& F = TopoDS::Face(it.Value());
56 //---------------------------
0d969553 57 // Initialization of Loops.
7fd59977 58 //---------------------------
59 Loops.Init(F);
60 //-----------------------------
0d969553 61 // return edges of F.
7fd59977 62 //-----------------------------
63 const TopTools_ListOfShape& LE = AsDes->Descendant(F);
64 TopTools_ListOfShape AddedEdges;
65
66 for (itl.Initialize(LE); itl.More(); itl.Next()) {
67 TopoDS_Edge E = TopoDS::Edge(itl.Value());
68 if (Image.HasImage(E)) {
69 //-------------------------------------------
0d969553
Y
70 // E was already cut in another face.
71 // Return the cut edges reorientate them as E.
72 // See pb for the edges that have disappeared?
7fd59977 73 //-------------------------------------------
74 const TopTools_ListOfShape& LCE = Image.Image(E);
75 for (itLCE.Initialize(LCE); itLCE.More(); itLCE.Next()) {
76 TopoDS_Shape CE = itLCE.Value().Oriented(E.Orientation());
77 Loops.AddConstEdge(TopoDS::Edge(CE));
78 }
79 }
80 else {
81 Loops .AddEdge(E, AsDes->Descendant(E));
82 AddedEdges.Append (E);
83 }
84 }
85 //------------------------
0d969553 86 // Unwind.
7fd59977 87 //------------------------
88 Loops.Perform();
89 Loops.WiresToFaces();
90 //------------------------
91 // MAJ SD.
92 //------------------------
93 const TopTools_ListOfShape& NF = Loops.NewFaces();
94 //-----------------------
0d969553 95 // F => New faces;
7fd59977 96 //-----------------------
97 Image.Bind(F,NF);
98
99 TopTools_ListIteratorOfListOfShape itAdded;
100 for (itAdded.Initialize(AddedEdges); itAdded.More(); itAdded.Next()) {
101 const TopoDS_Edge& E = TopoDS::Edge(itAdded.Value());
102 //-----------------------
0d969553 103 // E => New edges;
7fd59977 104 //-----------------------
105 const TopTools_ListOfShape& LoopNE = Loops.NewEdges(E);
106 if (Image.HasImage(E)) {
107 Image.Add(E,LoopNE);
108 }
109 else {
110 Image.Bind(E,LoopNE);
111 }
112 }
113 }
114 Loops.GetVerticesForSubstitute( myVerVerMap );
115 if (myVerVerMap.IsEmpty())
116 return;
117 BRep_Builder BB;
118 for (it.Initialize( LF ); it.More(); it.Next())
119 {
120 TopoDS_Shape F = it.Value();
121 TopTools_ListOfShape LIF;
122 Image.LastImage( F, LIF );
123 for (itl.Initialize(LIF); itl.More(); itl.Next())
124 {
125 const TopoDS_Shape& IF = itl.Value();
126 TopExp_Explorer EdExp( IF, TopAbs_EDGE );
127 for (; EdExp.More(); EdExp.Next())
128 {
129 TopoDS_Shape E = EdExp.Current();
130 TopTools_ListOfShape VList;
131 TopoDS_Iterator VerExp( E );
132 for (; VerExp.More(); VerExp.Next())
133 VList.Append( VerExp.Value() );
134 TopTools_ListIteratorOfListOfShape itlv( VList );
135 for (; itlv.More(); itlv.Next())
136 {
137 const TopoDS_Shape& V = itlv.Value();
138 if (myVerVerMap.IsBound( V ))
139 {
140 TopoDS_Shape NewV = myVerVerMap( V );
141 E.Free( Standard_True );
142 NewV.Orientation( V.Orientation() );
143 Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
144 Handle(BRep_TVertex)& NewTV = *((Handle(BRep_TVertex)*) &NewV.TShape());
145 if (TV->Tolerance() > NewTV->Tolerance())
146 NewTV->Tolerance( TV->Tolerance() );
147 NewTV->ChangePoints().Append( TV->ChangePoints() );
148 AsDes->Replace( V, NewV );
149 BB.Remove( E, V );
150 BB.Add( E, NewV );
151 }
152 }
153 }
154 }
155 }
156}
157
158//=======================================================================
159//function : IsBetweenCorks
160//purpose :
161//=======================================================================
162
163static Standard_Boolean IsBetweenCorks(const TopoDS_Shape& E,
164 const Handle(BRepAlgo_AsDes)& AsDes,
165 const TopTools_ListOfShape& LContext)
166{
167 if (!AsDes->HasAscendant(E)) return 1;
168 const TopTools_ListOfShape& LF = AsDes->Ascendant(E);
169 TopTools_ListIteratorOfListOfShape it;
170 for (it.Initialize(LF); it.More(); it.Next()) {
171 const TopoDS_Shape& S = it.Value();
172 Standard_Boolean found = 0;
173 TopTools_ListIteratorOfListOfShape it2;
174 for (it2.Initialize(LContext); it2.More(); it2.Next()) {
175 if(S.IsSame(it2.Value())) {
176 found = 1;
177 break;
178 }
179 }
180 if (!found) return 0;
181 }
182 return 1;
183}
184//=======================================================================
185//function : BuildOnContext
186//purpose :
187//=======================================================================
188
189void BRepOffset_MakeLoops::BuildOnContext(const TopTools_ListOfShape& LContext,
190 const BRepOffset_Analyse& Analyse,
191 const Handle(BRepAlgo_AsDes)& AsDes,
192 BRepAlgo_Image& Image,
193 const Standard_Boolean InSide)
194{
195 //-----------------------------------------
0d969553 196 // unwinding of caps.
7fd59977 197 //-----------------------------------------
198 TopTools_ListIteratorOfListOfShape it(LContext);
199 TopTools_ListIteratorOfListOfShape itl,itLCE;
200 BRepAlgo_Loop Loops;
201 Loops.VerticesForSubstitute( myVerVerMap );
202 TopExp_Explorer exp;
203 TopTools_MapOfShape MapExtent;
204
205 for (; it.More(); it.Next()) {
206 const TopoDS_Face& F = TopoDS::Face(it.Value());
207 TopTools_MapOfShape MBound;
208 //-----------------------------------------------
0d969553
Y
209 // Initialisation of Loops.
210 // F is reversed it will be added in myOffC.
211 // and myOffC will be reversed in the final result.
7fd59977 212 //-----------------------------------------------
213 TopoDS_Shape aLocalShape = F.Reversed();
214 if (InSide) Loops.Init(TopoDS::Face(aLocalShape));
215// if (InSide) Loops.Init(TopoDS::Face(F.Reversed()));
216 else Loops.Init(F);
217 //--------------------------------------------------------
0d969553 218 // return edges of F not modified by definition.
7fd59977 219 //--------------------------------------------------------
220 for (exp.Init(F.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
221 exp.More();
222 exp.Next()) {
223 TopoDS_Edge CE = TopoDS::Edge(exp.Current());
224 MBound.Add(CE);
225 if (Analyse.HasAncestor(CE)) {
0d969553 226 // the stop of cups except for the connectivity stops between caps.
7fd59977 227 // if (!AsDes->HasAscendant(CE)) {
228 aLocalShape = CE.Reversed();
229 if (InSide) Loops.AddConstEdge(CE);
230 else Loops.AddConstEdge(TopoDS::Edge(aLocalShape));
231// else Loops.AddConstEdge(TopoDS::Edge(CE.Reversed()));
232 }
233 }
234 //------------------------------------------------------
0d969553 235 // Trace of offsets + connectivity edge between caps.
7fd59977 236 //------------------------------------------------------
237 const TopTools_ListOfShape& LE = AsDes->Descendant(F);
238 TopTools_ListOfShape AddedEdges;
239
240 for (itl.Initialize(LE); itl.More(); itl.Next()) {
241 TopoDS_Edge E = TopoDS::Edge(itl.Value());
242 if (Image.HasImage(E)) {
243 //-------------------------------------------
0d969553
Y
244 // E was already cut in another face.
245 // Return cut edges and orientate them as E.
246 // See pb for the edges that have disappeared?
7fd59977 247 //-------------------------------------------
248 const TopTools_ListOfShape& LCE = Image.Image(E);
249 for (itLCE.Initialize(LCE); itLCE.More(); itLCE.Next()) {
250 TopoDS_Shape CE = itLCE.Value().Oriented(E.Orientation());
251 if (MapExtent.Contains(E)) {
252 Loops.AddConstEdge(TopoDS::Edge(CE));
253 continue;
254 }
255 if (!MBound.Contains(E)) CE.Reverse();
256 if (InSide) Loops.AddConstEdge(TopoDS::Edge(CE));
257 else
258 {
259 TopoDS_Shape aLocalShape = CE.Reversed();
260 Loops.AddConstEdge(TopoDS::Edge(aLocalShape));
261 }
262// else Loops.AddConstEdge(TopoDS::Edge(CE.Reversed()));
263 }
264 }
265 else {
266 if (IsBetweenCorks(E,AsDes,LContext) && AsDes->HasDescendant(E)) {
0d969553 267 //connection between 2 caps
7fd59977 268 MapExtent.Add(E);
269 TopTools_ListOfShape LV;
270 if (InSide) {
271 for (itLCE.Initialize(AsDes->Descendant(E)); itLCE.More(); itLCE.Next()) {
272 LV.Append(itLCE.Value().Reversed());
273 }
274 Loops.AddEdge(E,LV);
275 }
276 else {
277 Loops.AddEdge(E,AsDes->Descendant(E));
278 }
279 AddedEdges.Append (E);
280 }
281 else if (IsBetweenCorks(E,AsDes,LContext)) {
282 TopoDS_Shape aLocalShape = E.Reversed();
283 if (InSide) Loops.AddConstEdge(E);
284 else Loops.AddConstEdge(TopoDS::Edge(aLocalShape));
285// if (InSide) Loops.AddConstEdge(TopoDS::Edge(E));
286// else Loops.AddConstEdge(TopoDS::Edge(E.Reversed()));
287 }
288 else {
289 TopoDS_Shape aLocalShape = E.Reversed();
290 if (InSide) Loops.AddConstEdge(TopoDS::Edge(aLocalShape));
291 else Loops.AddConstEdge(E);
292// if (InSide) Loops.AddConstEdge(TopoDS::Edge(E.Reversed()));
293// else Loops.AddConstEdge(TopoDS::Edge(E));
294 }
295 }
296 }
297 //------------------------
0d969553 298 // Unwind.
7fd59977 299 //------------------------
300 Loops.Perform();
301 Loops.WiresToFaces();
302 //------------------------
303 // MAJ SD.
304 //------------------------
305 const TopTools_ListOfShape& NF = Loops.NewFaces();
306 //-----------------------
0d969553 307 // F => New faces;
7fd59977 308 //-----------------------
309 Image.Bind(F,NF);
310
311 TopTools_ListIteratorOfListOfShape itAdded;
312 for (itAdded.Initialize(AddedEdges); itAdded.More(); itAdded.Next()) {
313 const TopoDS_Edge& E = TopoDS::Edge(itAdded.Value());
314 //-----------------------
0d969553 315 // E => New edges;
7fd59977 316 //-----------------------
317 if (Image.HasImage(E)) {
318 Image.Add(E,Loops.NewEdges(E));
319 }
320 else {
321 Image.Bind(E,Loops.NewEdges(E));
322 }
323 }
324 }
325 Loops.GetVerticesForSubstitute( myVerVerMap );
326 if (myVerVerMap.IsEmpty())
327 return;
328 BRep_Builder BB;
329 for (it.Initialize( LContext ); it.More(); it.Next())
330 {
331 TopoDS_Shape F = it.Value();
332 TopTools_ListOfShape LIF;
333 Image.LastImage( F, LIF );
334 for (itl.Initialize(LIF); itl.More(); itl.Next())
335 {
336 const TopoDS_Shape& IF = itl.Value();
337 TopExp_Explorer EdExp( IF, TopAbs_EDGE );
338 for (; EdExp.More(); EdExp.Next())
339 {
340 TopoDS_Shape E = EdExp.Current();
341 TopTools_ListOfShape VList;
342 TopoDS_Iterator VerExp( E );
343 for (; VerExp.More(); VerExp.Next())
344 VList.Append( VerExp.Value() );
345 TopTools_ListIteratorOfListOfShape itlv( VList );
346 for (; itlv.More(); itlv.Next())
347 {
348 const TopoDS_Shape& V = itlv.Value();
349 if (myVerVerMap.IsBound( V ))
350 {
351 TopoDS_Shape NewV = myVerVerMap( V );
352 E.Free( Standard_True );
353 NewV.Orientation( V.Orientation() );
354 Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
355 Handle(BRep_TVertex)& NewTV = *((Handle(BRep_TVertex)*) &NewV.TShape());
356 if (TV->Tolerance() > NewTV->Tolerance())
357 NewTV->Tolerance( TV->Tolerance() );
358 NewTV->ChangePoints().Append( TV->ChangePoints() );
359 AsDes->Replace( V, NewV );
360 BB.Remove( E, V );
361 BB.Add( E, NewV );
362 }
363 }
364 }
365 }
366 }
367}
368
369
370//=======================================================================
371//function : BuildFaces
372//purpose :
373//=======================================================================
374
375void BRepOffset_MakeLoops::BuildFaces(const TopTools_ListOfShape& LF,
376 const Handle(BRepAlgo_AsDes)& AsDes,
377 BRepAlgo_Image& Image)
378{
379 TopTools_ListIteratorOfListOfShape itr,itl,itLCE;
380 Standard_Boolean ToRebuild;
381 BRepAlgo_Loop Loops;
382 Loops.VerticesForSubstitute( myVerVerMap );
383 BRep_Builder B;
384
385 //----------------------------------
0d969553 386 // Loop on all faces //.
7fd59977 387 //----------------------------------
388 for (itr.Initialize(LF); itr.More(); itr.Next()) {
389 TopoDS_Face F = TopoDS::Face(itr.Value());
390 Loops.Init(F);
391 ToRebuild = Standard_False;
392 TopTools_ListOfShape AddedEdges;
393
394 if (!Image.HasImage(F)) {
395 //----------------------------------
0d969553 396 // Face F not yet reconstructed.
7fd59977 397 //----------------------------------
398 const TopTools_ListOfShape& LE = AsDes->Descendant(F);
399 //----------------------------------------------------------------
0d969553
Y
400 // first loop to find if the edges of the face were reconstructed.
401 // - maj on map MONV. Some vertices on reconstructed edges
402 // coincide geometrically with old but are not IsSame.
7fd59977 403 //----------------------------------------------------------------
404 TopTools_DataMapOfShapeShape MONV;
405 TopoDS_Vertex OV1,OV2,NV1,NV2;
406
407 for (itl.Initialize(LE); itl.More(); itl.Next()) {
408 TopoDS_Edge E = TopoDS::Edge(itl.Value());
409 if (Image.HasImage(E)) {
410 const TopTools_ListOfShape& LCE = Image.Image(E);
411 if (LCE.Extent() == 1 && LCE.First().IsSame(E)) {
412 TopoDS_Shape aLocalShape = LCE.First().Oriented(E.Orientation());
413 TopoDS_Edge CE = TopoDS::Edge(aLocalShape);
414// TopoDS_Edge CE = TopoDS::Edge(LCE.First().Oriented(E.Orientation()));
415 Loops.AddConstEdge(CE);
416 continue;
417 }
418 //----------------------------------
0d969553 419 // F should be reconstructed.
7fd59977 420 //----------------------------------
421 ToRebuild = Standard_True;
422 for (itLCE.Initialize(LCE); itLCE.More(); itLCE.Next()) {
423 TopoDS_Shape aLocalShape = itLCE.Value().Oriented(E.Orientation());
424 TopoDS_Edge CE = TopoDS::Edge(aLocalShape);
425// TopoDS_Edge CE = TopoDS::Edge(itLCE.Value().Oriented(E.Orientation()));
426 TopExp::Vertices (E ,OV1,OV2);
427 TopExp::Vertices (CE,NV1,NV2);
428 if (!OV1.IsSame(NV1)) MONV.Bind(OV1,NV1);
429 if (!OV2.IsSame(NV2)) MONV.Bind(OV2,NV2);
430 Loops.AddConstEdge(CE);
431 }
432 }
433 }
434 if (ToRebuild) {
435#ifdef DRAW
0d969553 436//POP for NT
7fd59977 437 if ( Affich) {
438 char* name = new char[100];
439 sprintf(name,"CF_%d",NbF++);
440 DBRep::Set(name,F);
441 }
442#endif
443
444 //-----------------------------------------------------------
0d969553
Y
445 // Non-reconstructed edges on other faces are added.
446 // If their vertices were reconstructed they are reconstructed.
7fd59977 447 //-----------------------------------------------------------
448 for (itl.Initialize(LE); itl.More(); itl.Next()) {
449 Standard_Real f,l;
450 TopoDS_Edge E = TopoDS::Edge(itl.Value());
451 BRep_Tool::Range(E,f,l);
452 if (!Image.HasImage(E)) {
453 TopExp::Vertices (E,OV1,OV2);
454 TopTools_ListOfShape LV;
455 if (MONV.IsBound(OV1)) {
456 TopoDS_Vertex VV = TopoDS::Vertex(MONV(OV1));
457 VV.Orientation(TopAbs_FORWARD);
458 LV.Append(VV);
459 TopoDS_Shape aLocalShape = VV.Oriented(TopAbs_INTERNAL);
460 B.UpdateVertex(TopoDS::Vertex(aLocalShape),
461 f,E,BRep_Tool::Tolerance(VV));
462 }
463 if (MONV.IsBound(OV2)) {
464 TopoDS_Vertex VV = TopoDS::Vertex(MONV(OV2));
465 VV.Orientation(TopAbs_REVERSED);
466 LV.Append(VV);
467 TopoDS_Shape aLocalShape = VV.Oriented(TopAbs_INTERNAL);
468 B.UpdateVertex(TopoDS::Vertex(aLocalShape),
469 l,E,BRep_Tool::Tolerance(VV));
470// B.UpdateVertex(TopoDS::Vertex(VV.Oriented(TopAbs_INTERNAL)),
471// l,E,BRep_Tool::Tolerance(VV));
472 }
473 if (LV.IsEmpty()) Loops.AddConstEdge(E);
474 else {
475 Loops.AddEdge (E,LV);
476 AddedEdges.Append(E);
477 }
478 }
479 }
480 }
481 }
482 if (ToRebuild) {
483 //------------------------
484 // Reconstruction.
485 //------------------------
486 Loops.Perform();
487 Loops.WiresToFaces();
488 //------------------------
489 // MAJ SD.
490 //------------------------
491 const TopTools_ListOfShape& NF = Loops.NewFaces();
492 //-----------------------
0d969553 493 // F => New faces;
7fd59977 494 //-----------------------
495 Image.Bind(F,NF);
496
497 TopTools_ListIteratorOfListOfShape itAdded;
498 for (itAdded.Initialize(AddedEdges); itAdded.More(); itAdded.Next()) {
499 const TopoDS_Edge& E = TopoDS::Edge(itAdded.Value());
500 //-----------------------
0d969553 501 // E => New edges;
7fd59977 502 //-----------------------
503 if (Image.HasImage(E)) {
504 Image.Add(E,Loops.NewEdges(E));
505 }
506 else {
507 Image.Bind(E,Loops.NewEdges(E));
508 }
509 }
510 }
511 }
512 Loops.GetVerticesForSubstitute( myVerVerMap );
513 if (myVerVerMap.IsEmpty())
514 return;
515 BRep_Builder BB;
516 for (itr.Initialize( LF ); itr.More(); itr.Next())
517 {
518 TopoDS_Shape F = itr.Value();
519 TopTools_ListOfShape LIF;
520 Image.LastImage( F, LIF );
521 for (itl.Initialize(LIF); itl.More(); itl.Next())
522 {
523 const TopoDS_Shape& IF = itl.Value();
524 TopExp_Explorer EdExp( IF, TopAbs_EDGE );
525 for (; EdExp.More(); EdExp.Next())
526 {
527 TopoDS_Shape E = EdExp.Current();
528 TopTools_ListOfShape VList;
529 TopoDS_Iterator VerExp( E );
530 for (; VerExp.More(); VerExp.Next())
531 VList.Append( VerExp.Value() );
532 TopTools_ListIteratorOfListOfShape itlv( VList );
533 for (; itlv.More(); itlv.Next())
534 {
535 const TopoDS_Shape& V = itlv.Value();
536 if (myVerVerMap.IsBound( V ))
537 {
538 TopoDS_Shape NewV = myVerVerMap( V );
539 E.Free( Standard_True );
540 NewV.Orientation( V.Orientation() );
541 Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
542 Handle(BRep_TVertex)& NewTV = *((Handle(BRep_TVertex)*) &NewV.TShape());
543 if (TV->Tolerance() > NewTV->Tolerance())
544 NewTV->Tolerance( TV->Tolerance() );
545 NewTV->ChangePoints().Append( TV->ChangePoints() );
546 AsDes->Replace( V, NewV );
547 BB.Remove( E, V );
548 BB.Add( E, NewV );
549 }
550 }
551 }
552 }
553 }
554}