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