0028838: Configuration - undefine macros coming from X11 headers in place of collision
[occt.git] / src / TopOpeBRepBuild / TopOpeBRepBuild_Builder.cxx
1 // Created on: 1993-06-14
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1993-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
18 #include <BRep_Builder.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepClass3d_SolidClassifier.hxx>
21 #include <Geom2d_Curve.hxx>
22 #include <Geom_Curve.hxx>
23 #include <gp_Pnt.hxx>
24 #include <Precision.hxx>
25 #include <Standard_NoSuchObject.hxx>
26 #include <TCollection_AsciiString.hxx>
27 #include <TopExp.hxx>
28 #include <TopoDS.hxx>
29 #include <TopoDS_Compound.hxx>
30 #include <TopoDS_Edge.hxx>
31 #include <TopoDS_Face.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Shell.hxx>
34 #include <TopoDS_Vertex.hxx>
35 #include <TopoDS_Wire.hxx>
36 #include <TopOpeBRepBuild_Builder.hxx>
37 #include <TopOpeBRepBuild_define.hxx>
38 #include <TopOpeBRepBuild_EdgeBuilder.hxx>
39 #include <TopOpeBRepBuild_FaceBuilder.hxx>
40 #include <TopOpeBRepBuild_GTool.hxx>
41 #include <TopOpeBRepBuild_GTopo.hxx>
42 #include <TopOpeBRepBuild_HBuilder.hxx>
43 #include <TopOpeBRepBuild_PaveSet.hxx>
44 #include <TopOpeBRepBuild_ShapeSet.hxx>
45 #include <TopOpeBRepBuild_ShellFaceSet.hxx>
46 #include <TopOpeBRepBuild_SolidBuilder.hxx>
47 #include <TopOpeBRepBuild_WireEdgeSet.hxx>
48 #include <TopOpeBRepDS_BuildTool.hxx>
49 #include <TopOpeBRepDS_Config.hxx>
50 #include <TopOpeBRepDS_Curve.hxx>
51 #include <TopOpeBRepDS_CurveExplorer.hxx>
52 #include <TopOpeBRepDS_CurveIterator.hxx>
53 #include <TopOpeBRepDS_DataMapIteratorOfDataMapOfShapeListOfShapeOn1State.hxx>
54 #include <TopOpeBRepDS_Filter.hxx>
55 #include <TopOpeBRepDS_HDataStructure.hxx>
56 #include <TopOpeBRepDS_ListOfShapeOn1State.hxx>
57 #include <TopOpeBRepDS_Point.hxx>
58 #include <TopOpeBRepDS_PointIterator.hxx>
59 #include <TopOpeBRepDS_Reducer.hxx>
60 #include <TopOpeBRepDS_Surface.hxx>
61 #include <TopOpeBRepDS_SurfaceIterator.hxx>
62 #include <TopOpeBRepTool_ShapeExplorer.hxx>
63
64 #ifdef OCCT_DEBUG
65 extern Standard_Boolean TopOpeBRepBuild_GettraceCU();
66 extern Standard_Boolean TopOpeBRepBuild_GettraceCUV();
67 extern Standard_Boolean TopOpeBRepBuild_GettraceSPF();
68 extern Standard_Boolean TopOpeBRepBuild_GettraceSPS();
69 extern Standard_Boolean TopOpeBRepBuild_GetcontextSF2();
70 extern Standard_Boolean TopOpeBRepBuild_GettraceSHEX();
71 Standard_EXPORT void debmarksplit(const Standard_Integer i) {cout<<"++ debmarksplit "<<i<<endl;}
72 Standard_EXPORT void debchangesplit(const Standard_Integer i) {cout<<"++ debchangesplit "<<i<<endl;}
73 #endif
74
75 static  Standard_Integer STATIC_SOLIDINDEX = 0;
76 #include <TopOpeBRepBuild_SplitEdge.hxx>
77 #include <TopOpeBRepBuild_SplitFace.hxx>
78 #include "TopOpeBRepBuild_SplitSolid.pxx"
79 #include <TopOpeBRepBuild_SplitShapes.hxx>
80 #include "TopOpeBRepBuild_Fill.pxx"
81
82 Standard_EXPORT TopOpeBRepBuild_Builder* GLOBAL_PBUILDER;
83
84 //=======================================================================
85 //function : TopOpeBRepBuild_Builder
86 //purpose  : 
87 //=======================================================================
88 TopOpeBRepBuild_Builder::TopOpeBRepBuild_Builder(const TopOpeBRepDS_BuildTool& BT) 
89 : myBuildTool(BT),
90   mySectionDone(Standard_False),
91   myIsKPart(0),
92   myClassifyDef(Standard_False),
93   myClassifyVal(Standard_True),
94   myProcessON(Standard_False)
95 {
96   GLOBAL_PBUILDER = this;
97   InitSection();
98 }
99
100 //modified by NIZHNY-MZV  Sat May  6 10:04:49 2000
101 //=======================================================================
102 //function : ~TopOpeBRepBuild_Builder
103 //purpose  : virtual destructor
104 //=======================================================================
105 TopOpeBRepBuild_Builder::~TopOpeBRepBuild_Builder()
106 {
107
108
109 //=======================================================================
110 //function : ChangeBuildTool
111 //purpose  : 
112 //=======================================================================
113 TopOpeBRepDS_BuildTool& TopOpeBRepBuild_Builder::ChangeBuildTool() 
114 {
115   return myBuildTool;
116 }
117
118 //=======================================================================
119 //function : BuildTool
120 //purpose  : 
121 //=======================================================================
122 const TopOpeBRepDS_BuildTool& TopOpeBRepBuild_Builder::BuildTool() const
123 {
124   return myBuildTool;
125 }
126
127 //=======================================================================
128 //function : DataStructure
129 //purpose  : 
130 //=======================================================================
131 Handle(TopOpeBRepDS_HDataStructure) TopOpeBRepBuild_Builder::DataStructure() const
132 {
133   return myDataStructure;
134 }
135
136 //=======================================================================
137 //function : Perform
138 //purpose  : 
139 //=======================================================================
140 void TopOpeBRepBuild_Builder::Perform(const Handle(TopOpeBRepDS_HDataStructure)& HDS)
141 {
142 #ifdef OCCT_DEBUG
143   GdumpSHASETreset();
144 #endif
145   Clear();
146   myDataStructure = HDS;
147   BuildVertices(HDS); 
148   SplitEvisoONperiodicF();
149   BuildEdges(HDS); 
150   BuildFaces(HDS);
151   myIsKPart = 0;
152   InitSection();
153   SplitSectionEdges();
154   TopOpeBRepDS_Filter F(HDS, &myShapeClassifier);
155   F.ProcessFaceInterferences(mySplitON);
156   TopOpeBRepDS_Reducer R(HDS);
157   R.ProcessFaceInterferences(mySplitON);
158 } // Perform
159
160 //=======================================================================
161 //function : Perform
162 //purpose  : 
163 //=======================================================================
164 void TopOpeBRepBuild_Builder::Perform(const Handle(TopOpeBRepDS_HDataStructure)& HDS,const TopoDS_Shape& S1, const TopoDS_Shape& S2)
165 {
166   Perform(HDS);
167   myShape1 = S1; myShape2 = S2;
168   myIsKPart = FindIsKPart();
169 } // Perform
170
171 //=======================================================================
172 //function : AddIntersectionEdges
173 //purpose  : 
174 //=======================================================================
175 void TopOpeBRepBuild_Builder::AddIntersectionEdges
176 (TopoDS_Shape& aFace,const TopAbs_State ToBuild1,const Standard_Boolean RevOri1,TopOpeBRepBuild_ShapeSet& WES) const
177 {
178   TopoDS_Shape anEdge;
179   TopOpeBRepDS_CurveIterator FCurves = myDataStructure->FaceCurves(aFace);
180   for (; FCurves.More(); FCurves.Next()) {
181     Standard_Integer iC = FCurves.Current();
182     const TopTools_ListOfShape& LnewE = NewEdges(iC);
183     for (TopTools_ListIteratorOfListOfShape Iti(LnewE); Iti.More(); Iti.Next()) {
184       anEdge = Iti.Value();
185       TopAbs_Orientation ori = FCurves.Orientation(ToBuild1);
186       TopAbs_Orientation newori = Orient(ori,RevOri1);
187
188       if(newori == TopAbs_EXTERNAL) continue;
189
190       myBuildTool.Orientation(anEdge,newori);
191       const Handle(Geom2d_Curve)& PC = FCurves.PCurve();
192       myBuildTool.PCurve(aFace,anEdge,PC);
193       WES.AddStartElement(anEdge);
194     }
195   }
196 }
197
198 //=======================================================================
199 //function : Clear
200 //purpose  : 
201 //=======================================================================
202 void TopOpeBRepBuild_Builder::Clear()
203 {
204   const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
205   TopOpeBRepDS_DataMapIteratorOfDataMapOfShapeListOfShapeOn1State it;
206   for (it.Initialize(mySplitOUT); it.More(); it.Next()) {
207     const TopoDS_Shape& e = it.Key();
208     if ( e.ShapeType() == TopAbs_EDGE ) {
209       Standard_Boolean isse =  BDS.IsSectionEdge(TopoDS::Edge(e));
210       if (!isse) mySplitOUT.ChangeFind(e).Clear();
211     }
212   }
213   for (it.Initialize(mySplitIN); it.More(); it.Next()) {
214     const TopoDS_Shape& e = it.Key();
215     if ( e.ShapeType() == TopAbs_EDGE ) {
216       Standard_Boolean isse =  BDS.IsSectionEdge(TopoDS::Edge(e));
217       if (!isse) mySplitIN.ChangeFind(e).Clear();
218     }
219   }
220   for (it.Initialize(mySplitON); it.More(); it.Next()) {
221     const TopoDS_Shape& e = it.Key();
222     if ( e.ShapeType() == TopAbs_EDGE ) {
223       Standard_Boolean isse =  BDS.IsSectionEdge(TopoDS::Edge(e));
224       if (!isse) mySplitON.ChangeFind(e).Clear();
225     }
226   }
227   myMergedOUT.Clear();
228   myMergedIN.Clear();
229   myMergedON.Clear();
230 } // Clear
231
232 //=======================================================================
233 //function : NewFaces
234 //purpose  : 
235 //=======================================================================
236 const TopTools_ListOfShape& TopOpeBRepBuild_Builder::NewFaces(const Standard_Integer I) const
237 {
238   const TopTools_ListOfShape& L = myNewFaces->Array1().Value(I);
239   return L;
240 } // NewFaces
241
242 //=======================================================================
243 //function : ChangeNewFaces
244 //purpose  : private
245 //=======================================================================
246 TopTools_ListOfShape& TopOpeBRepBuild_Builder::ChangeNewFaces(const Standard_Integer I)
247 {
248   TopTools_ListOfShape& L = myNewFaces->ChangeArray1().ChangeValue(I);
249   return L;
250 } // ChangeNewFaces
251
252 //=======================================================================
253 //function : NewEdges
254 //purpose  : 
255 //=======================================================================
256 const TopTools_ListOfShape& TopOpeBRepBuild_Builder::NewEdges(const Standard_Integer I) const
257 {
258   if ( myNewEdges.IsBound(I) ) {
259     return myNewEdges.Find(I);
260   }
261   else {
262     return myEmptyShapeList;
263   }
264 } // NewEdges
265
266 //=======================================================================
267 //function : ChangeNewEdges
268 //purpose  : private
269 //=======================================================================
270 TopTools_ListOfShape& TopOpeBRepBuild_Builder::ChangeNewEdges(const Standard_Integer I)
271 {
272   if ( ! myNewEdges.IsBound(I) ) {
273     TopTools_ListOfShape thelist;
274     myNewEdges.Bind(I, thelist);
275   }
276   TopTools_ListOfShape& L = myNewEdges.ChangeFind(I);
277   return L;
278 } // ChangeNewEdges
279
280 //=======================================================================
281 //function : NewVertex
282 //purpose  : 
283 //=======================================================================
284 const TopoDS_Shape& TopOpeBRepBuild_Builder::NewVertex(const Standard_Integer I) const
285 {
286   const TopoDS_Shape& V = myNewVertices->Array1().Value(I);
287   return V;
288 } // NewVertex
289
290 //=======================================================================
291 //function : ChangeNewVertex
292 //purpose  : private
293 //=======================================================================
294 TopoDS_Shape& TopOpeBRepBuild_Builder::ChangeNewVertex(const Standard_Integer I)
295 {
296   TopoDS_Shape& V = myNewVertices->ChangeArray1().ChangeValue(I);
297   return V;
298 } // ChangeNewVertex
299
300 //=======================================================================
301 //function : ToSplit
302 //purpose  : private
303 //=======================================================================
304 Standard_Boolean TopOpeBRepBuild_Builder::ToSplit(const TopoDS_Shape& S,const TopAbs_State ToBuild) const
305 {
306   Standard_Boolean issplit = IsSplit(S,ToBuild);
307   Standard_Boolean hasgeom = myDataStructure->HasGeometry(S);
308   Standard_Boolean hassame = myDataStructure->HasSameDomain(S);
309   Standard_Boolean tosplit = (!issplit) && (hasgeom || hassame);
310
311 #ifdef OCCT_DEBUG
312   Standard_Integer iS; Standard_Boolean tSPS = GtraceSPS(S,iS);
313   if (tSPS) { 
314     cout<<"tosplit "<<tosplit<<" : !issplit "<<(!issplit);
315     cout<<" && (hasgeom || hassame) ("<<hasgeom<<" || "<<hassame<<")"<<endl;
316   }
317 #endif
318
319   return tosplit;
320 } // ToSplit
321
322 //=======================================================================
323 //function : MarkSplit
324 //purpose  : private
325 //=======================================================================
326 void TopOpeBRepBuild_Builder::MarkSplit(const TopoDS_Shape& S,const TopAbs_State ToBuild,const Standard_Boolean Bval) 
327 {
328   TopOpeBRepDS_DataMapOfShapeListOfShapeOn1State* p = NULL;
329   if      ( ToBuild == TopAbs_OUT ) p = &mySplitOUT;
330   else if ( ToBuild == TopAbs_IN  ) p = &mySplitIN;
331   else if ( ToBuild == TopAbs_ON  ) p = &mySplitON;
332   if ( p == NULL ) return;
333
334   TopOpeBRepDS_ListOfShapeOn1State thelist;
335   if (!(*p).IsBound(S)) (*p).Bind(S, thelist);
336   TopOpeBRepDS_ListOfShapeOn1State& losos = (*p).ChangeFind(S);
337   losos.Split(Bval);
338   
339 #ifdef OCCT_DEBUG
340   Standard_Integer iS; Standard_Boolean tSPS = GtraceSPS(S,iS);
341   if(tSPS){
342     GdumpSHA(S, (char *) "MarkSplit ");
343     cout<<" ";TopAbs::Print(ToBuild,cout);cout<<" "<<Bval<<endl;
344     debmarksplit(iS);
345   }
346 #endif
347   
348 } // MarkSplit
349
350 //=======================================================================
351 //function : IsSplit
352 //purpose  : 
353 //=======================================================================
354 Standard_Boolean TopOpeBRepBuild_Builder::IsSplit(const TopoDS_Shape& S,const TopAbs_State ToBuild) const
355 {
356   Standard_Boolean res = Standard_False;  
357   const TopOpeBRepDS_DataMapOfShapeListOfShapeOn1State* p = NULL;
358   if      ( ToBuild == TopAbs_OUT ) p = &mySplitOUT;
359   else if ( ToBuild == TopAbs_IN  ) p = &mySplitIN;
360   else if ( ToBuild == TopAbs_ON  ) p = &mySplitON;
361   if ( p == NULL ) return res;
362
363   if ((*p).IsBound(S)) {
364     const TopOpeBRepDS_ListOfShapeOn1State& losos = (*p).Find(S);
365     res = losos.IsSplit();
366 #ifdef OCCT_DEBUG
367 //    Standard_Integer n = losos.ListOnState().Extent();
368 #endif
369   }
370   return res;
371 } // IsSplit
372
373 //=======================================================================
374 //function : Splits
375 //purpose  : 
376 //=======================================================================
377 const TopTools_ListOfShape& TopOpeBRepBuild_Builder::Splits(const TopoDS_Shape& S, const TopAbs_State ToBuild) const
378 {
379   const TopOpeBRepDS_DataMapOfShapeListOfShapeOn1State* p = NULL;
380   if      ( ToBuild == TopAbs_OUT ) p = &mySplitOUT;
381   else if ( ToBuild == TopAbs_IN  ) p = &mySplitIN;
382   else if ( ToBuild == TopAbs_ON  ) p = &mySplitON;
383   if ( p == NULL ) return myEmptyShapeList;
384
385   if ((*p).IsBound(S)) {
386     const TopOpeBRepDS_ListOfShapeOn1State& losos = (*p).Find(S);
387     const TopTools_ListOfShape& L = losos.ListOnState();
388     return L;
389   }
390   return myEmptyShapeList;
391 } // Splits
392
393 //=======================================================================
394 //function : ChangeSplit
395 //purpose  : private
396 //=======================================================================
397 TopTools_ListOfShape& TopOpeBRepBuild_Builder::ChangeSplit(const TopoDS_Shape& S,const TopAbs_State ToBuild)
398 {
399 #ifdef OCCT_DEBUG
400   Standard_Integer iS; Standard_Boolean tSPS = GtraceSPS(S,iS);
401   if(tSPS){
402     GdumpSHA(S, (char *) "ChangeSplit ");
403     cout<<" ";TopAbs::Print(ToBuild,cout);cout<<endl;
404     debchangesplit(iS);
405   }
406 #endif
407
408   TopOpeBRepDS_DataMapOfShapeListOfShapeOn1State* p = NULL;
409   if      ( ToBuild == TopAbs_OUT ) p = &mySplitOUT;
410   else if ( ToBuild == TopAbs_IN  ) p = &mySplitIN;
411   else if ( ToBuild == TopAbs_ON  ) p = &mySplitON;
412   if ( p == NULL ) return myEmptyShapeList;
413   TopOpeBRepDS_ListOfShapeOn1State thelist1;
414   if (!(*p).IsBound(S)) (*p).Bind(S, thelist1);
415   TopOpeBRepDS_ListOfShapeOn1State& losos = (*p).ChangeFind(S);
416   TopTools_ListOfShape& L = losos.ChangeListOnState();
417   return L;
418 } // ChangeSplit
419
420 //=======================================================================
421 //function : ShapePosition
422 //purpose  : compute position of shape S compared with the shapes of list LS
423 //           if S is found IN any shape of LS, return IN
424 //           else return OUT
425 //=======================================================================
426 TopAbs_State TopOpeBRepBuild_Builder::ShapePosition(const TopoDS_Shape& S, const TopTools_ListOfShape& LS)
427
428   TopAbs_State state = TopAbs_UNKNOWN;
429
430   // take the edges of myEdgeAvoid as shape to avoid
431   // during face classification
432   const TopTools_ListOfShape* PLOS = &myEmptyShapeList;
433   TopAbs_ShapeEnum tS = S.ShapeType();
434   if (tS == TopAbs_FACE) PLOS = &myEdgeAvoid;
435   // NYI : idem with myFaceAvoid if (tS == TopAbs_SOLID)
436
437   for (TopTools_ListIteratorOfListOfShape Iti(LS); Iti.More(); Iti.Next()) {
438     const TopoDS_Shape& SLS = Iti.Value();
439 #ifdef OCCT_DEBUG
440 //    TopAbs_ShapeEnum tSLS = SLS.ShapeType();
441 #endif
442     state = myShapeClassifier.StateShapeShape(S,(*PLOS),SLS);
443     if (state != TopAbs_OUT && state != TopAbs_UNKNOWN) return state;
444   }
445   if (state == TopAbs_UNKNOWN) return state;
446   return TopAbs_OUT;
447 }
448
449 //=======================================================================
450 //function : KeepShape
451 //purpose  : compute <pos2> = position of shape <S1> / shapes of list <LS2>
452 //           shape S1 is kept
453 //           - if LS2 is empty
454 //           - if (pos2 == ToBuild1)
455 //=======================================================================
456 Standard_Boolean TopOpeBRepBuild_Builder::KeepShape(const TopoDS_Shape& S1,const TopTools_ListOfShape& LS2,const TopAbs_State ToBuild1)
457
458   Standard_Boolean keep = Standard_True;
459   if ( ! LS2.IsEmpty() ) {
460     TopAbs_State pos2 = ShapePosition(S1,LS2);
461     if ( pos2 != ToBuild1 ) keep = Standard_False;
462   }
463   return keep;
464 }
465
466 //=======================================================================
467 //function : TopType
468 //purpose  : return the type of upper subshape found in <S>
469 //=======================================================================
470 TopAbs_ShapeEnum TopOpeBRepBuild_Builder::TopType(const TopoDS_Shape& S)
471 {
472   TopAbs_ShapeEnum t;
473   TopOpeBRepTool_ShapeExplorer e;
474
475   t = TopAbs_COMPOUND;   e.Init(S,t); if (e.More()) return t;
476   t = TopAbs_COMPSOLID;  e.Init(S,t); if (e.More()) return t;
477   t = TopAbs_SOLID;      e.Init(S,t); if (e.More()) return t;
478   t = TopAbs_SHELL;      e.Init(S,t); if (e.More()) return t;
479   t = TopAbs_FACE;       e.Init(S,t); if (e.More()) return t;
480   t = TopAbs_WIRE;       e.Init(S,t); if (e.More()) return t;
481   t = TopAbs_EDGE;       e.Init(S,t); if (e.More()) return t;
482   t = TopAbs_VERTEX;     e.Init(S,t); if (e.More()) return t;
483
484   return TopAbs_SHAPE;
485 }
486
487 //=======================================================================
488 //function : Reverse
489 //purpose  : compute orientation reversibility according to build states
490 //=======================================================================
491 Standard_Boolean TopOpeBRepBuild_Builder::Reverse(const TopAbs_State ToBuild1,const TopAbs_State ToBuild2)
492 {
493   Standard_Boolean rev;
494   if (ToBuild1 == TopAbs_IN && ToBuild2 == TopAbs_IN) rev = Standard_False;
495   else rev = (ToBuild1 == TopAbs_IN);
496   return rev;
497 }
498
499 //=======================================================================
500 //function : Orient
501 //purpose  : reverse the orientation
502 //=======================================================================
503 TopAbs_Orientation TopOpeBRepBuild_Builder::Orient(const TopAbs_Orientation Ori,const Standard_Boolean Reverse)
504 {
505   return !Reverse
506        ? Ori
507        : TopAbs::Complement(Ori);
508 }
509
510 //=======================================================================
511 //function : FindSameDomain
512 //purpose  : complete the lists L1,L2 with the shapes of the DS
513 //           having same domain :
514 //           L1 = shapes sharing the same domain of L2 shapes
515 //           L2 = shapes sharing the same domain of L1 shapes
516 // (L1 contains a face)
517 //=======================================================================
518 void TopOpeBRepBuild_Builder::FindSameDomain(TopTools_ListOfShape& L1,TopTools_ListOfShape& L2) const 
519 {
520   Standard_Integer i;
521   Standard_Integer nl1 = L1.Extent(), nl2 = L2.Extent();
522
523   while ( nl1 > 0 || nl2 > 0 )  {
524
525     TopTools_ListIteratorOfListOfShape it1(L1);
526     for (i=1 ; i<=nl1; i++) {
527       const TopoDS_Shape& S1 = it1.Value();
528 #ifdef OCCT_DEBUG
529 //      Standard_Integer iS1 = myDataStructure->Shape(S1);  // DEB
530 #endif
531       TopTools_ListIteratorOfListOfShape itsd(myDataStructure->SameDomain(S1));
532       for (; itsd.More(); itsd.Next() ) {
533         const TopoDS_Shape& S2 = itsd.Value();
534 #ifdef OCCT_DEBUG
535 //      Standard_Integer iS2 = myDataStructure->Shape(S2);// DEB
536 #endif
537         Standard_Boolean found = Contains(S2,L2);
538         if ( ! found ) {
539           L2.Prepend(S2);
540           nl2++;
541         }
542       }
543       it1.Next();
544     }
545     nl1 = 0;
546
547     TopTools_ListIteratorOfListOfShape it2(L2);
548     for (i=1 ; i<=nl2; i++) {
549       const TopoDS_Shape& S2 = it2.Value();
550 #ifdef OCCT_DEBUG
551 //      Standard_Integer iS2 = myDataStructure->Shape(S2);// DEB
552 #endif
553       TopTools_ListIteratorOfListOfShape itsd(myDataStructure->SameDomain(S2));
554       for (; itsd.More(); itsd.Next() ) {
555         const TopoDS_Shape& S1 = itsd.Value();
556 #ifdef OCCT_DEBUG
557 //      Standard_Integer iS1 = myDataStructure->Shape(S1);// DEB
558 #endif
559         Standard_Boolean found = Contains(S1,L1);
560         if ( ! found ) {
561           L1.Prepend(S1);
562           nl1++;
563         }
564       }
565       it2.Next();
566     }
567     nl2 = 0;
568
569   }
570
571 }
572
573
574 //=======================================================================
575 //function : FindSameDomainSameOrientation
576 //purpose  : 
577 //=======================================================================
578 void TopOpeBRepBuild_Builder::FindSameDomainSameOrientation(TopTools_ListOfShape& L1, TopTools_ListOfShape& L2) const 
579 {
580   FindSameDomain(L1,L2);
581   TopTools_ListIteratorOfListOfShape it(L1);
582   if ( !it.More() ) return;
583
584   const TopoDS_Shape& sref = it.Value();
585 #ifdef OCCT_DEBUG
586 //  Standard_Integer  iref = myDataStructure->SameDomainReference(sref);
587 #endif
588   TopOpeBRepDS_Config oref = myDataStructure->SameDomainOrientation(sref);
589
590   TopTools_ListOfShape LL1,LL2;
591
592   for (it.Initialize(L1); it.More(); it.Next() ) {
593     const TopoDS_Shape& s = it.Value();
594     TopOpeBRepDS_Config o = myDataStructure->SameDomainOrientation(s);
595     if      ( o == oref && !Contains(s,LL1) ) LL1.Append(s);
596     else if ( o != oref && !Contains(s,LL2) ) LL2.Append(s);
597   }
598
599   for (it.Initialize(L2); it.More(); it.Next() ) {
600     const TopoDS_Shape& s = it.Value();
601     TopOpeBRepDS_Config o = myDataStructure->SameDomainOrientation(s);
602     if      ( o == oref && !Contains(s,LL1) ) LL1.Append(s);
603     else if ( o != oref && !Contains(s,LL2) ) LL2.Append(s);
604   }
605
606   L1 = LL1;
607   L2 = LL2;
608
609 }
610
611 //=======================================================================
612 //function : MapShapes
613 //purpose  : 
614 //=======================================================================
615 void TopOpeBRepBuild_Builder::MapShapes(const TopoDS_Shape& S1,const TopoDS_Shape& S2)
616 {
617   Standard_Boolean S1null = S1.IsNull();
618   Standard_Boolean S2null = S2.IsNull();
619   ClearMaps();
620   if ( ! S1null ) TopExp::MapShapes(S1,myMAP1);
621   if ( ! S2null ) TopExp::MapShapes(S2,myMAP2);
622 }
623
624 //=======================================================================
625 //function : ClearMaps
626 //purpose  : 
627 //=======================================================================
628 void TopOpeBRepBuild_Builder::ClearMaps()
629 {
630   myMAP1.Clear(); 
631   myMAP2.Clear(); 
632 }
633
634 //=======================================================================
635 //function : FindSameRank
636 //purpose  : 
637 //=======================================================================
638 void TopOpeBRepBuild_Builder::FindSameRank(const TopTools_ListOfShape& L1,const Standard_Integer rank,TopTools_ListOfShape& L2) const
639 {
640   for (  TopTools_ListIteratorOfListOfShape it1(L1); it1.More(); it1.Next() ) {
641     const TopoDS_Shape& s = it1.Value();
642     Standard_Integer r = ShapeRank(s);
643     if ( r == rank && !Contains(s,L2) ) {
644       L2.Append(s);
645     }
646   }
647 }
648
649 //=======================================================================
650 //function : ShapeRank
651 //purpose  : 
652 //=======================================================================
653 Standard_Integer TopOpeBRepBuild_Builder::ShapeRank(const TopoDS_Shape& s) const 
654 {
655   Standard_Boolean isof1 = IsShapeOf(s,1);
656   Standard_Boolean isof2 = IsShapeOf(s,2);
657   Standard_Integer ancetre = (isof1 || isof2) ? ((isof1) ? 1 : 2) : 0;
658   return ancetre;
659 }
660
661 //=======================================================================
662 //function : IsShapeOf
663 //purpose  : 
664 //=======================================================================
665 Standard_Boolean TopOpeBRepBuild_Builder::IsShapeOf(const TopoDS_Shape& s,const Standard_Integer i) const 
666 {
667   Standard_Boolean b = Standard_False;
668   if      (i == 1) b = myMAP1.Contains(s);
669   else if (i == 2) b = myMAP2.Contains(s);
670   return b;
671 }
672
673 //=======================================================================
674 //function : Contains
675 //purpose  : returns True if S is in the list L.
676 //=======================================================================
677 Standard_Boolean TopOpeBRepBuild_Builder::Contains(const TopoDS_Shape& S,const TopTools_ListOfShape& L) 
678 {
679   for (TopTools_ListIteratorOfListOfShape it(L); it.More(); it.Next() ) {
680     TopoDS_Shape& SL = it.Value();
681     Standard_Boolean issame = SL.IsSame(S);
682     if ( issame ) return Standard_True;
683   }
684   return Standard_False;
685 }
686
687 //=======================================================================
688 //function : Opec12
689 //purpose  : 
690 //=======================================================================
691 Standard_Boolean TopOpeBRepBuild_Builder::Opec12() const 
692 {
693   Standard_Boolean b = (myState1 == TopAbs_OUT) && (myState2 == TopAbs_IN );
694   return b;
695 }
696
697 //=======================================================================
698 //function : Opec21
699 //purpose  : 
700 //=======================================================================
701 Standard_Boolean TopOpeBRepBuild_Builder::Opec21() const 
702 {
703   Standard_Boolean b = (myState1 == TopAbs_IN ) && (myState2 == TopAbs_OUT);
704   return b;
705 }
706
707 //=======================================================================
708 //function : Opecom
709 //purpose  : 
710 //=======================================================================
711 Standard_Boolean TopOpeBRepBuild_Builder::Opecom() const 
712 {
713   Standard_Boolean b = (myState1 == TopAbs_IN ) && (myState2 == TopAbs_IN );
714   return b;
715 }
716
717 //=======================================================================
718 //function : Opefus
719 //purpose  : 
720 //=======================================================================
721 Standard_Boolean TopOpeBRepBuild_Builder::Opefus() const 
722 {
723   Standard_Boolean b = (myState1 == TopAbs_OUT) && (myState2 == TopAbs_OUT);
724   return b;
725 }
726
727 //=======================================================================
728 //function : MSplit
729 //purpose  : 
730 //=======================================================================
731 const TopOpeBRepDS_DataMapOfShapeListOfShapeOn1State& TopOpeBRepBuild_Builder::MSplit(const TopAbs_State s) const
732 {
733   if      (s == TopAbs_IN)  return mySplitIN;
734   else if (s == TopAbs_OUT) return mySplitOUT;
735   else if (s == TopAbs_ON)  return mySplitON;
736   return mySplitIN;
737 }
738
739 //=======================================================================
740 //function : ChangeMSplit
741 //purpose  : 
742 //=======================================================================
743 TopOpeBRepDS_DataMapOfShapeListOfShapeOn1State& TopOpeBRepBuild_Builder::ChangeMSplit(const TopAbs_State s)
744 {
745   if      (s == TopAbs_IN)  return mySplitIN;
746   else if (s == TopAbs_OUT) return mySplitOUT;
747   else if (s == TopAbs_ON)  return mySplitON;
748   return mySplitIN;
749 }