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