0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / BRepAlgo / BRepAlgo_DSAccess.cxx
CommitLineData
b311480e 1// Created on: 1997-08-13
2// Created by: Prestataire Mary FABIEN
3// Copyright (c) 1997-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
7fd59977 17
42cf5bc1 18#include <BRepAlgo_BooleanOperations.hxx>
19#include <BRepAlgo_DSAccess.hxx>
20#include <BRepAlgo_EdgeConnector.hxx>
7fd59977 21#include <TColStd_IndexedMapOfInteger.hxx>
42cf5bc1 22#include <TColStd_ListIteratorOfListOfInteger.hxx>
23#include <TColStd_ListOfInteger.hxx>
7fd59977 24#include <TColStd_MapIteratorOfMapOfInteger.hxx>
54f7544d 25#include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
42cf5bc1 26#include <TColStd_MapOfInteger.hxx>
7fd59977 27#include <TopoDS.hxx>
28#include <TopoDS_Compound.hxx>
42cf5bc1 29#include <TopoDS_Shape.hxx>
30#include <TopoDS_Vertex.hxx>
7fd59977 31#include <TopoDS_Wire.hxx>
42cf5bc1 32#include <TopOpeBRep_DSFiller.hxx>
33#include <TopOpeBRepBuild_FaceBuilder.hxx>
34#include <TopOpeBRepBuild_HBuilder.hxx>
35#include <TopOpeBRepBuild_WireEdgeSet.hxx>
7fd59977 36#include <TopOpeBRepDS_BuildTool.hxx>
7fd59977 37#include <TopOpeBRepDS_Check.hxx>
42cf5bc1 38#include <TopOpeBRepDS_CheckStatus.hxx>
7fd59977 39#include <TopOpeBRepDS_CurveExplorer.hxx>
40#include <TopOpeBRepDS_CurveIterator.hxx>
41#include <TopOpeBRepDS_Filter.hxx>
42cf5bc1 42#include <TopOpeBRepDS_HDataStructure.hxx>
43#include <TopOpeBRepDS_Interference.hxx>
44#include <TopOpeBRepDS_InterferenceIterator.hxx>
45#include <TopOpeBRepDS_ListIteratorOfListOfInterference.hxx>
46#include <TopOpeBRepDS_ListOfInterference.hxx>
47#include <TopOpeBRepDS_PointIterator.hxx>
7fd59977 48#include <TopOpeBRepDS_Reducer.hxx>
42cf5bc1 49#include <TopOpeBRepDS_ShapeShapeInterference.hxx>
7fd59977 50#include <TopOpeBRepTool_GeomTool.hxx>
42cf5bc1 51#include <TopTools_ListIteratorOfListOfShape.hxx>
52#include <TopTools_ListOfShape.hxx>
53#include <TopTools_MapOfShape.hxx>
7fd59977 54
55#ifdef DRAW
56//#include <TestTopOpe.hxx>
57#endif
58
59//=======================================================================
60//function : Create
61//purpose :
62//=======================================================================
63
64BRepAlgo_DSAccess::BRepAlgo_DSAccess() {
65 Init();
66}
67
68//=======================================================================
69//function : Init
70//purpose :
71//=======================================================================
72
73void BRepAlgo_DSAccess::Init()
74{
75 if(myHDS.IsNull())
76 myHDS = new TopOpeBRepDS_HDataStructure();
77 else
78 myHDS->ChangeDS().Init();
79 myRecomputeBuilderIsDone = Standard_False;
80 myGetSectionIsDone = Standard_False;
81 myListOfCompoundOfEdgeConnected.Clear();
82 myEC = new BRepAlgo_EdgeConnector();
83 myHB.Nullify();
84
85 // init of the builder
86 Standard_Real tol3dAPPROX = 1e-7;
87 Standard_Real tol2dAPPROX = 1e-7;
88 // set tolerance values used by the APPROX process
89 TopOpeBRepTool_GeomTool GT;
90 GT.Define(TopOpeBRepTool_APPROX);
91 GT.SetTolerances(tol3dAPPROX,tol2dAPPROX);
92 TopOpeBRepDS_BuildTool BT(GT);
93 myHB = new TopOpeBRepBuild_HBuilder(BT);
94 myHB->ChangeBuilder().ChangeClassify(Standard_False);
95
96 myState1 = TopAbs_UNKNOWN;
97 myState2 = TopAbs_UNKNOWN;
98
99}
100
101
102// Filling of the DS
103
104//=======================================================================
105//function : Load
106//purpose :
107//=======================================================================
108
109void BRepAlgo_DSAccess::Load(const TopoDS_Shape& S)
110{
111 TopOpeBRepDS_DataStructure& DS = myHDS->ChangeDS();
112 myS1 = S;
113 DS.AddShape(S, 1);
114}
115
116//=======================================================================
117//function : Load
118//purpose :
119//=======================================================================
120
121void BRepAlgo_DSAccess::Load(TopoDS_Shape& S1,
122 TopoDS_Shape& S2)
123{
124 TopOpeBRepDS_DataStructure& DS = myHDS->ChangeDS();
125
126 if ( S1.Orientation() == TopAbs_REVERSED ) {
127 S1.Orientation(TopAbs_FORWARD);
128 }
129 if ( S2.Orientation() == TopAbs_REVERSED ) {
130 S2.Orientation(TopAbs_FORWARD);
131 }
132
133 DS.AddShape(S1,1);
134 DS.AddShape(S2,2);
135
136 TopOpeBRepTool_ShapeExplorer ex1,ex2;
137 for (ex1.Init(S1,TopAbs_SOLID); ex1.More(); ex1.Next()) {
138 const TopoDS_Shape& so1 = ex1.Current();
139 for (ex2.Init(S2,TopAbs_SOLID); ex2.More(); ex2.Next()) {
140 const TopoDS_Shape& so2 = ex2.Current();
141 DS.FillShapesSameDomain(so1,so2);
142 }
143 }
144
145 myS1 = S1;
146 myS2 = S2;
147
148#ifdef DRAW
149// TestTopOpe::CurrentDS(myHDS);
150// TestTopOpe::Shapes(myS1,myS2);
151#endif
152}
153
154//=======================================================================
155//function : Intersect
156//purpose :
157//=======================================================================
158
159void BRepAlgo_DSAccess::Intersect()
160{
161 myRecomputeBuilderIsDone = Standard_False;
162
163 if(!myS1.IsNull() && !myS2.IsNull())
164 myDSFiller.Insert(myS1, myS2, myHDS);
165}
166
167//=======================================================================
168//function : Intersect
169//purpose :
170//=======================================================================
171
172void BRepAlgo_DSAccess::Intersect
173(const TopoDS_Shape& S1,
174 const TopoDS_Shape& S2)
175{
176 myRecomputeBuilderIsDone = Standard_False;
177
178 if(S1.IsNull() || S2.IsNull()) {
179 return;
180 }
181
182 Standard_Boolean orientFORWARD = Standard_False;
183 TopExp_Explorer exp;
184 if(S1.ShapeType() != TopAbs_FACE) {
185 exp.Init(S1, TopAbs_FACE);
186 if(!exp.More())
187 return;
188 }
189 if(S2.ShapeType() != TopAbs_FACE) {
190 exp.Init(S2, TopAbs_FACE);
191 if(!exp.More())
192 return;
193 }
194 myDSFiller.Insert(S1, S2, myHDS, orientFORWARD);
195}
196
197//=======================================================================
198//function : SameDomain
199//purpose :
200//=======================================================================
201
202void BRepAlgo_DSAccess::SameDomain
203(const TopoDS_Shape& S1,
204 const TopoDS_Shape& S2)
205{
206 myRecomputeBuilderIsDone = Standard_False;
207
208 if(S1.IsNull() || S2.IsNull())
209 return;
210
211 TopExp_Explorer exp1, exp2;
212 exp1.Init(S1, TopAbs_FACE);
213 if(!exp1.More())
214 return;
215 exp2.Init(S2, TopAbs_FACE);
216 if(!exp2.More())
217 return;
218
219 myDSFiller.Insert2d(S1, S2, myHDS);
220}
221
222
223// Construction of Sections
224
225#define FindKeep Standard_False
226
227//=======================================================================
228//function : GetSectionEdgeSet
229//purpose :
230//=======================================================================
231
232const TopTools_ListOfShape& BRepAlgo_DSAccess::GetSectionEdgeSet
233(const TopoDS_Shape& S1,
234 const TopoDS_Shape& S2)
235{
236 GetSectionEdgeSet();
237
238 // Check if S1 and S2 contain faces
239 TopExp_Explorer exp1, exp2;
240 exp1.Init(S1, TopAbs_FACE);
241 if(!exp1.More())
242 return myEmptyListOfShape;
243 exp2.Init(S2, TopAbs_FACE);
244 if(!exp2.More())
245 return myEmptyListOfShape;
246
247 for(exp1.Init(S1, TopAbs_FACE); exp1.More(); exp1.Next()) {
248 if(!myHDS->HasShape(exp1.Current(), FindKeep))
249 return myEmptyListOfShape;
250 }
251 for(exp2.Init(S2, TopAbs_FACE); exp2.More(); exp2.Next())
252 if(!myHDS->HasShape(exp2.Current(), FindKeep))
253 return myEmptyListOfShape;
254
255 TopOpeBRepDS_DataStructure& DS = myHDS->ChangeDS();
256 TopOpeBRepBuild_Builder& Builder = myHB->ChangeBuilder();
257
258 // The purpose is to find interferences associated with faces,
259 // edges that come from their Geometry (= Edge || Curve)
260 TopTools_ListOfShape LE;
261 LE.Clear();
262 TopExp_Explorer exp;
263 for(exp1.Init(S1, TopAbs_FACE); exp1.More(); exp1.Next()) {
264 const TopoDS_Shape& F1 = exp1.Current();
265
266 TopOpeBRepDS_ListOfInterference& lof = DS.ChangeShapeInterferences(F1);
267 TopOpeBRepDS_InterferenceIterator li(lof);
268 li.SupportKind(TopOpeBRepDS_FACE);
269 for(exp2.Init(S2, TopAbs_FACE); exp2.More(); exp2.Next()) {
270 const TopoDS_Shape& F2 = exp2.Current();
271 Standard_Integer si = DS.Shape(F2, FindKeep);
272 li.Support(si);
273
274 for(; li.More(); li.Next()) {
275 const TopOpeBRepDS_Interference& CurrInt = li.Value();
276 TopOpeBRepDS_Kind gk = CurrInt.GeometryType();
277 Standard_Integer gi = CurrInt.Geometry();
278 const TopoDS_Shape& geosha = DS.Shape(gi, FindKeep);
279 if(gk == TopOpeBRepDS_CURVE) {
280 const TopTools_ListOfShape& lEdge = myHB->NewEdges(gi);
281 LE.Append(lEdge.First());
282 } else {
283 const TopTools_ListOfShape& lEdge = Builder.Splits(geosha, TopAbs_ON);
284 TopTools_ListIteratorOfListOfShape it(lEdge);
285 for(; it.More(); it.Next()) {
286 const TopoDS_Shape& CurrEdge = it.Value();
287 Standard_Integer ipv1, ipv2;
288 TopOpeBRepDS_Kind pvk1, pvk2;
289 PntVtxOnSectEdge(CurrEdge, ipv1, pvk1, ipv2, pvk2);
290 if(pvk1 != TopOpeBRepDS_VERTEX) {
291 ipv1 = 0;
292 if(pvk2 != TopOpeBRepDS_VERTEX) continue;
293 } else {
294 if(pvk2 != TopOpeBRepDS_VERTEX)
295 ipv2 = 0;
296 }
297 for(exp.Init(F1, TopAbs_VERTEX); exp.More(); exp.Next()) {
298 Standard_Integer iVert = DS.Shape(exp.Current());
299 if(iVert) {
300 if((iVert == ipv1) || (iVert == ipv2)) {
301 LE.Append(CurrEdge);
302 break;
303 }
304 }
305 }
306 }
307 }
308 }
309 }
310 }
311
312 // find all groups of connected Edges associated to LE
313 TopTools_ListIteratorOfListOfShape ILE;
314 myCurrentList.Clear();
315 TopTools_MapOfShape ME;
316 ME.Clear();
317 TopTools_ListIteratorOfListOfShape ILC;
318 TopExp_Explorer ECE;
319 ILE.Initialize(LE);
320 for(;ILE.More();ILE.Next()) {
321 const TopoDS_Shape& E = ILE.Value();
322 ILC.Initialize(myListOfCompoundOfEdgeConnected);
323 for(;ILC.More();ILC.Next()) {
324 const TopoDS_Shape& Com = ILC.Value();
325 ECE.Init(Com, TopAbs_EDGE);
326 for(;ECE.More();ECE.Next()) {
327 if(ECE.Current().IsSame(E)) {
328 if(!ME.Contains(Com)) {
329 myCurrentList.Append(Com);
330 ME.Add(Com);
331 break;
332 }
333 }
334 }
335 }
336 }
337
338 return myCurrentList;
339}
340
341//=======================================================================
342//function : GetSectionEdgeSet
343//purpose :
344//=======================================================================
345
346const TopTools_ListOfShape& BRepAlgo_DSAccess::GetSectionEdgeSet()
347{
348 if(!myRecomputeBuilderIsDone) {
349 // it is possible to call the method many times consecutively
350 myHDS->AddAncestors(myS1);
351 // start of lpa modification
352 if (!myS1.IsSame(myS2) && !myS2.IsNull()) {
353 myHDS->AddAncestors(myS2);
354 myHB->Perform(myHDS,myS1,myS2);
355 }
356 else {
357 myHB->Perform(myHDS);
358 }
359 // end of modif lpa
360 myRecomputeBuilderIsDone = Standard_True;
361 myGetSectionIsDone = Standard_False;
362 }
363 if(myGetSectionIsDone)
364 return myListOfCompoundOfEdgeConnected;
365 myGetSectionIsDone = Standard_True;
366
367 myListOfCompoundOfEdgeConnected.Clear();
368
369 // EdgeConnector
370 Handle(BRepAlgo_EdgeConnector) EC = myEC;
371 EC->ClearStartElement();
372 TopTools_MapOfShape ME;
373 ME.Clear();
374 myHB->InitSection();
375 for(; myHB->MoreSection(); myHB->NextSection()) {
376 const TopoDS_Edge& ES = TopoDS::Edge(myHB->CurrentSection());
377 if(ME.Contains(ES)) continue;
378 ME.Add(ES);
379 EC->AddStart(ES);
380 }
381 TopTools_ListOfShape& LW = EC->MakeBlock();
382
383 // the wires are tranformed into compounds.
384 myCompoundWireMap.Clear();
385 BRep_Builder BB;
386 TopTools_ListIteratorOfListOfShape ILW(LW);
387 TopExp_Explorer Explor;
388 for(;ILW.More();ILW.Next()) {
389 TopoDS_Compound Compound;
390//POP
391 BB.MakeCompound(Compound);
392// BB.MakeCompound(TopoDS::Compound(Compound));
393 Explor.Init(ILW.Value(), TopAbs_EDGE);
394 for(;Explor.More(); Explor.Next()) {
395 BB.Add(Compound, Explor.Current());
396 }
397 myListOfCompoundOfEdgeConnected.Append(Compound);
398 myCompoundWireMap.Bind(Compound,ILW.Value());
399 }
400 return myListOfCompoundOfEdgeConnected;
401}
402
403//=======================================================================
404//function : IsWire
405//purpose :
406//=======================================================================
407
408Standard_Boolean BRepAlgo_DSAccess::IsWire(const TopoDS_Shape& S)
409{
410 Standard_Boolean b = Standard_False;
411 if(myEC->IsDone()) {
412 if (myCompoundWireMap.IsBound(S))
413 b = myEC->IsWire(myCompoundWireMap(S));
414 }
415 return b;
416}
417
418//=======================================================================
419//function : Wire
420//purpose :
421//=======================================================================
422
423const TopoDS_Shape& BRepAlgo_DSAccess::Wire(const TopoDS_Shape& S)
424{
425 if(!IsWire(S)) {
426 myWire.Nullify();
427 }
428 else {
429 BRep_Builder BB;
430 BB.MakeWire(myWire);
431 TopExp_Explorer Explor(S, TopAbs_EDGE);
432 for(;Explor.More(); Explor.Next()) BB.Add(myWire, Explor.Current());
433 }
434 return myWire;
435}
436
437//=======================================================================
438//function : SectionVertex
439//purpose :
440//=======================================================================
441
442const TopTools_ListOfShape& BRepAlgo_DSAccess::SectionVertex
443(const TopoDS_Shape& F,
444 const TopoDS_Shape& E)
445{
446 TopTools_ListOfShape Result;
447 Result.Clear();
448 if(F.ShapeType() != TopAbs_FACE) return myEmptyListOfShape;
449 if(E.ShapeType() != TopAbs_EDGE) return myEmptyListOfShape;
450 Standard_Integer iF = myHDS->Shape(F), iE = myHDS->Shape(E);
451 if((iF == 0) || (iE == 0)) return myEmptyListOfShape;
452
453 const TopOpeBRepDS_DataStructure& DS = myHDS->DS();
454 const TopOpeBRepDS_ListOfInterference& LI =
455 DS.ShapeInterferences(E, Standard_False);
456 TopOpeBRepDS_InterferenceIterator II(LI);
457 Standard_Integer goodIndex = 0;
458 TopOpeBRepDS_Kind goodKind;
459 for(;II.More();II.Next()) {
b7c077b9 460 const Handle(TopOpeBRepDS_Interference)& I = II.Value();
7fd59977 461 const TopOpeBRepDS_Transition& T = I->Transition();
462 if((T.ONAfter() == TopAbs_FACE) &&
463 (T.IndexAfter() == iF)) {
464 goodKind = I->GeometryType();
465 goodIndex = I->Geometry();
466 if(goodKind == TopOpeBRepDS_VERTEX)
467 Result.Append(myHDS->Shape(goodIndex));
468 else
469 if (goodKind == TopOpeBRepDS_POINT)
470 Result.Append(myHB->NewVertex(goodIndex));
471 }
472 }
473 myListOfVertex = Result;
474 return myListOfVertex;
475}
476
477
478// Editing of the DS
479
480//=======================================================================
481//function : SuppressEdgeSet
482//purpose :
483//=======================================================================
484
485void BRepAlgo_DSAccess::SuppressEdgeSet
486(const TopoDS_Shape& C)
487{
488 // It is checked if C really is a Coumpound of connected Edges
489
490 myHB->InitExtendedSectionDS();
491// myGetSectionIsDone = Standard_False;
492
493 TopTools_ListIteratorOfListOfShape LLS(myListOfCompoundOfEdgeConnected);
494 for(;LLS.More(); LLS.Next())
495 if(C == LLS.Value())
496 break;
497 if(!LLS.More())
498 return;
499
500 // Cleaning
501 TopoDS_Shape Empty;
502 Empty.Nullify();
503 Suppress(C, Empty);
504 myListOfCompoundOfEdgeConnected.Remove(LLS);
505}
506
507//=======================================================================
508//function : ChangeEdgeSet
509//purpose :
510//=======================================================================
511
512void BRepAlgo_DSAccess::ChangeEdgeSet
513(const TopoDS_Shape& Old, const TopoDS_Shape& New)
514{
515 // It is checked if Old is a Coumpound of connected Edges
516
517 myHB->InitExtendedSectionDS();
518
519 TopTools_ListIteratorOfListOfShape LLS(myListOfCompoundOfEdgeConnected);
520 for(;LLS.More(); LLS.Next())
521 if(Old == LLS.Value())
522 break;
523 if(!LLS.More())
524 return;
525
526 // The compound of Edges to be rotated is constructed
527 BRep_Builder B;
528 Standard_Boolean Trouve;
529 Standard_Integer iC;
530 TopoDS_Compound C;
531 TopoDS_Edge E;
532 B.MakeCompound(C);
54f7544d 533 TColStd_PackedMapOfInteger RPoint; //The points to be controlled
7fd59977 534
535 TopOpeBRepDS_ListIteratorOfListOfInterference iter;
536 TopExp_Explorer exp(Old, TopAbs_EDGE);
537 TopExp_Explorer exp2;
538 for(; exp.More(); exp.Next()) {
539 const TopoDS_Shape& Edge = exp.Current();
540 for(exp2.Init(New, TopAbs_EDGE), Trouve=Standard_False;
541 exp2.More() && (!Trouve); exp2.Next()) {
542 E = TopoDS::Edge(exp2.Current());
543 Trouve = E.IsSame(Edge);
544 }
545
546 if (!Trouve) B.Add(C, Edge); // Edge to be removed
547 else if (!E.IsEqual(Edge)) {
548 // It is necessary to change Interferences => take the complement
549 iC = myHB->GetDSCurveFromSectEdge(Edge);
550 if (!iC) {
0797d9d3 551#ifdef OCCT_DEBUG
0d969553 552 cout << "Warning DSAccess: Modifications of Edge are not implemented" << endl;
7fd59977 553#endif
554 }
555 else {
0d969553 556 // Complete the interferences Curve/Face
7fd59977 557 Standard_Integer iF;
558 Handle(TopOpeBRepDS_Interference) interf;
559
560 iF = myHB->GetDSFaceFromDSCurve(iC, 1);
561 TopOpeBRepDS_ListOfInterference& list1 =
562 myHDS->ChangeDS().ChangeShapeInterferences(iF);
563 for(iter.Initialize(list1); iter.More(); iter.Next()) {
564 interf = iter.Value();
565 if (interf->Geometry() == iC)
566 interf->Transition(interf->Transition().Complement());
567 }
568 iF = myHB->GetDSFaceFromDSCurve(iC, 2);
569 TopOpeBRepDS_ListOfInterference& list2 =
570 myHDS->ChangeDS().ChangeShapeInterferences(iF);
571 for(iter.Initialize(list2); iter.More(); iter.Next()) {
572 interf = iter.Value();
573 if (interf->Geometry() == iC)
574 interf->Transition(interf->Transition().Complement());
575 }
576 // The associated points are recorded
577 Standard_Integer ipv1, ipv2;
578 //Standard_Boolean bid; // skl
579 TopOpeBRepDS_Kind k1, k2;
580 PntVtxOnCurve(iC, ipv1, k1, ipv2, k2);
581 if (ipv1 != 0) /*bid = */RPoint.Add(ipv1); // skl
582 if (ipv2 != 0) /*bid = */RPoint.Add(ipv2); // skl
583 }
584 }
585 }
586
587
0d969553 588 // Cleaning
7fd59977 589 Suppress(C, New);
590
591 // Is it necessary to invert the Interferences "Edge on Fa"
592 if (!RPoint.IsEmpty()) {
593 const TopOpeBRepDS_DataStructure & DS = myHDS->DS();
594 Standard_Integer iP,iE, nbShape = DS.NbShapes();
595 Handle(TopOpeBRepDS_Interference) interf;
596 for (iE=1; iE<=nbShape; iE++) {
597 if (DS.Shape(iE,0).ShapeType() == TopAbs_EDGE) {
598 const TopOpeBRepDS_ListOfInterference& List =
599 myHDS->DS().ShapeInterferences(iE);
600 for(iter.Initialize(List); iter.More(); iter.Next()) {
601 interf = iter.Value();
602 if (interf->GeometryType() == TopOpeBRepDS_POINT) {
603 iP = interf->Geometry();
604 if (RPoint.Contains(iP))
605 interf->Transition(interf->Transition().Complement());
606 }
607 }
608 }
609 }
610 }
611
612 // The old is replaced by new
613 LLS.Value() = New;
614}
615
616
617//=======================================================================
618//function : Remove
619//purpose :
620//=======================================================================
621
622void BRepAlgo_DSAccess::Suppress(const TopoDS_Shape& C,
623 const TopoDS_Shape& Keep)
624{
625 TopOpeBRepDS_DataStructure& DS = myHDS->ChangeDS();
626 TopOpeBRepBuild_Builder& Builder = myHB->ChangeBuilder();
627 Standard_Integer i, iC = 0, iF1, iF2,iE1, iE2;
628// TopOpeBRepDS_ListIteratorOfListOfInterference;
629 TColStd_ListIteratorOfListOfInteger it1, it2;
630
631 //A group of points to be kept is constructed
632 mySetOfKeepPoint.Clear();
633 if (!Keep.IsNull()) {
634 //Standard_Boolean B; // skl
635 Standard_Integer ipv1, ipv2;
636 TopOpeBRepDS_Kind k1, k2;
637 TopExp_Explorer exp(Keep, TopAbs_EDGE);
638 for(; exp.More(); exp.Next()) {
639 const TopoDS_Shape& SectEdge = exp.Current();
640 iC = myHB->GetDSCurveFromSectEdge(SectEdge);
641 if(!iC)
642 PntVtxOnSectEdge(SectEdge, ipv1, k1, ipv2, k2);
643 else
644 PntVtxOnCurve(iC, ipv1, k1, ipv2, k2);
645 if (ipv1 != 0) /*B = */mySetOfKeepPoint.Add(ipv1); // skl
646 if (ipv2 != 0) /*B = */mySetOfKeepPoint.Add(ipv2); // skl
647 }
648 }
649
650 // The curves, which generated the the Edges, are found
651 // during the parsing the Edges which come from Edge are found
652 // (= MapOfInteger : ESE)
653
0d969553 654 // First, the interferences of support 1d.
7fd59977 655 TopExp_Explorer exp(C, TopAbs_EDGE);
656 for(; exp.More(); exp.Next()) {
657 const TopoDS_Shape& SectEdge = exp.Current();
658 iC = myHB->GetDSCurveFromSectEdge(SectEdge);
659 if(!iC) {
660 // the Edges that come from Edge are processed
661 // the interferences connected with Edges are processed :
662 iE1 = myHB->GetDSEdgeFromSectEdge(SectEdge, 1);
663 iE2 = myHB->GetDSEdgeFromSectEdge(SectEdge, 2);
664
665 RemoveEdgeInterferences(iE1,iE2,SectEdge);
666
667 TColStd_ListOfInteger& loi11 = myHB->GetDSFaceFromDSEdge(iE1, 1);
668 TColStd_ListOfInteger& loi12 = myHB->GetDSFaceFromDSEdge(iE1, 2);
669 for(it1.Initialize(loi11); it1.More(); it1.Next()) {
670 iF1 = it1.Value();
671 for(it2.Initialize(loi12); it2.More(); it2.Next()) {
672 iF2 = it2.Value();
673 // similar to the case of SectEdges coming from curve.
674 RemoveEdgeInterferences(iF1,iF2,SectEdge);
675 }
676 }
677 TColStd_ListOfInteger& loi21 = myHB->GetDSFaceFromDSEdge(iE2, 1);
678 TColStd_ListOfInteger& loi22 = myHB->GetDSFaceFromDSEdge(iE2, 2);
679 for(it1.Initialize(loi21); it1.More(); it1.Next()) {
680 iF1 = it1.Value();
681 for(it2.Initialize(loi22); it2.More(); it2.Next()) {
682 iF2 = it2.Value();
683 // similar to the case of SectEdges coming from curve.
684 RemoveEdgeInterferences(iF1,iF2,SectEdge);
685 }
686 }
687 continue;
688 }
689 // The Edges that come from Curve are processed
690 iF1 = myHB->GetDSFaceFromDSCurve(iC, 1);
691 iF2 = myHB->GetDSFaceFromDSCurve(iC, 2);
692
693 RemoveEdgeInterferences(iF1, iF2, iC);
694 DS.ChangeKeepCurve(iC, FindKeep);
695 }
696
697 // Secondly, the interferences of 2D support.
698 exp.Init(C, TopAbs_EDGE);
699 for(; exp.More(); exp.Next()) {
700 const TopoDS_Shape& SectEdge = exp.Current();
701 iC = myHB->GetDSCurveFromSectEdge(SectEdge);
702 if(!iC) {
703 iE1 = myHB->GetDSEdgeFromSectEdge(SectEdge, 1);
704 iE2 = myHB->GetDSEdgeFromSectEdge(SectEdge, 2);
705 TColStd_ListOfInteger& loi11 = myHB->GetDSFaceFromDSEdge(iE1, 1);
706 TColStd_ListOfInteger& loi12 = myHB->GetDSFaceFromDSEdge(iE1, 2);
707 for(it1.Initialize(loi11); it1.More(); it1.Next()) {
708 iF1 = it1.Value();
709 for(it2.Initialize(loi12); it2.More(); it2.Next()) {
710 iF2 = it2.Value();
711 if(iF1 == iF2)
712 continue;
713 RemoveFaceInterferences(iF1, iF2, iE1, iE2);
714 }
715 }
716 TColStd_ListOfInteger& loi21 = myHB->GetDSFaceFromDSEdge(iE2, 1);
717 TColStd_ListOfInteger& loi22 = myHB->GetDSFaceFromDSEdge(iE2, 2);
718 for(it1.Initialize(loi21); it1.More(); it1.Next()) {
719 iF1 = it1.Value();
720 for(it2.Initialize(loi22); it2.More(); it2.Next()) {
721 iF2 = it2.Value();
722 if(iF1 == iF2)
723 continue;
724 RemoveFaceInterferences(iF1, iF2, iE1, iE2);
725 }
726 }
727 }
728 else {
729 iF1 = myHB->GetDSFaceFromDSCurve(iC, 1);
730 iF2 = myHB->GetDSFaceFromDSCurve(iC, 2);
731
732 RemoveFaceInterferences(iF1, iF2, iC);
733 }
734 }
735
736 // Thirdly, RemoveSameDomain is done for the faces that contain all Edges of C,
737 // and are SameDomain and without Geometry.
738
739 RemoveFaceSameDomain(C);
740
741 // Fourthly, the faces, that were not concerned, are removed
742 Standard_Integer NbSh = DS.NbShapes();
743 for(i = 1; i <= NbSh; i++) {
744 const TopoDS_Shape& Face = DS.Shape(i);
745 if(Face.IsNull())
746 continue;
747 if((Face.ShapeType() != TopAbs_FACE) || DS.HasGeometry(Face) ||
748 (myHDS->HasSameDomain(Face)))
749 continue;
750 for(exp.Init(Face, TopAbs_EDGE); exp.More(); exp.Next()){
751 const TopoDS_Shape& Edge = exp.Current();
752 if(DS.HasShape(Edge))
753 break;
754 }
755 if(exp.More())
756 continue;
757 DS.ChangeKeepShape(Face, Standard_False);
758 }
759
760 // Builder.myKPMAPf1f2 is reconstructed
761 Builder.FindIsKPart();
762
763 // The Edges of section are removed from Builder.mySplitON
764 exp.Init(C, TopAbs_EDGE);
765 for(; exp.More(); exp.Next()) {
766 const TopoDS_Shape& SectE= exp.Current();
767 TopTools_ListOfShape& losob = Builder.ChangeSplit(SectE, TopAbs_ON);
768 losob.Clear();
769 }
770}
771
772//=======================================================================
773//function : SuppressSectionVertex
774//purpose :
775//=======================================================================
776
777void BRepAlgo_DSAccess::SuppressSectionVertex
778(const TopoDS_Vertex& /*V*/)
779{
780 if(!myRecomputeBuilderIsDone)
781 return;
782}
783
784
785// Reconstruction of Shapes
786
787//=======================================================================
788//function : Merge
789//purpose :
790//=======================================================================
791
792const TopoDS_Shape& BRepAlgo_DSAccess::Merge
793(const TopAbs_State state1,
794 const TopAbs_State state2)
795{
796 if((state1 != TopAbs_IN) &&
797 (state1 != TopAbs_OUT))
798 return myEmptyShape;
799 if((state2 != TopAbs_IN) &&
800 (state2 != TopAbs_OUT))
801 return myEmptyShape;
802 // if GetSectionEdgeSet has already been called, nothing is done
803 // in GetSectionEdgeSet.
804 if(myState1 != TopAbs_UNKNOWN)
805 if(myState1 != state1 || myState2 != state2)
806 myGetSectionIsDone = Standard_False;
807 myState1 = state1;
808 myState2 = state2;
809 GetSectionEdgeSet();
810
811 myHB->Clear();
812 myHB->MergeShapes(myS1,state1,myS2,state2);
813 const TopTools_ListOfShape& L1 = myHB->Merged(myS1,state1);
814
815 BRep_Builder BB;
816 myResultShape.Nullify();
817 BB.MakeCompound(TopoDS::Compound(myResultShape));
818 TopTools_ListIteratorOfListOfShape it(L1);
819 for(;it.More(); it.Next()) {
820 BB.Add(myResultShape, it.Value());
821 }
822 return myResultShape;
823}
824
825//=======================================================================
826//function : Merge
827//purpose :
828//=======================================================================
829
830const TopoDS_Shape& BRepAlgo_DSAccess::Merge
831(const TopAbs_State state1)
832{
833 if((state1 != TopAbs_IN) &&
834 (state1 != TopAbs_OUT))
835 return myEmptyShape;
836 GetSectionEdgeSet();
837
838 myHB->Clear();
839 myHB->MergeSolid(myS1,state1);
840 const TopTools_ListOfShape& L1 = myHB->Merged(myS1,state1);
841
842 BRep_Builder BB;
843 myResultShape.Nullify();
844 BB.MakeCompound(TopoDS::Compound(myResultShape));
845 TopTools_ListIteratorOfListOfShape it(L1);
846 for(;it.More(); it.Next()) {
847 BB.Add(myResultShape, it.Value());
848 }
849 return myResultShape;
850}
851
852//=======================================================================
853//function : Propagate
854//purpose :
855//=======================================================================
856
857const TopoDS_Shape& BRepAlgo_DSAccess::Propagate
858(const TopAbs_State what,
859 const TopoDS_Shape& /*fromShape*/,
860 const TopoDS_Shape& /*LoadShape*/)
861{
862 if((what != TopAbs_IN) &&
863 (what != TopAbs_OUT))
864 return myEmptyShape;
865 if(!myRecomputeBuilderIsDone)
866 return myEmptyShape;
867
868// myHB->MergeShapes(myS1,t1,myS2,t2);
869
0d969553 870 //POP for NT;
7fd59977 871 static TopoDS_Shape bid;
872 return bid;
873}
874
875//=======================================================================
876//function : PropagateFromSection
877//purpose :
878//=======================================================================
879
880const TopoDS_Shape& BRepAlgo_DSAccess::PropagateFromSection
881(const TopoDS_Shape& SectionShape)
882{
883 GetSectionEdgeSet();
884 TopTools_ListIteratorOfListOfShape ils(myListOfCompoundOfEdgeConnected);
885 TopExp_Explorer exp;
886 for(; ils.More(); ils.Next()) {
887 const TopoDS_Shape& SetEdgSet = ils.Value();
888 exp.Init(SetEdgSet, TopAbs_EDGE);
889 for(; exp.More(); exp.Next()) {
890 if(SectionShape.IsSame(exp.Current()))
891 return SetEdgSet;
892 }
893 }
894 return myEmptyShape;
895}
896
897//=======================================================================
898//function : Modified
899//purpose :
900//=======================================================================
901
902const TopTools_ListOfShape& BRepAlgo_DSAccess::Modified (const TopoDS_Shape& Shape)
903{
904 myModified.Clear() ;
905
906// Handle(TopOpeBRepBuild_HBuilder)& HBuilder = myDSA.myHB ;
907 TopTools_ListIteratorOfListOfShape Iterator ;
908
909 if (myHB->IsSplit (Shape, TopAbs_OUT)) {
910 for (Iterator.Initialize (myHB->Splits (Shape, TopAbs_OUT)) ;
911 Iterator.More() ;
912 Iterator.Next()) {
913 myModified.Append (Iterator.Value()) ;
914 }
915 }
916 if (myHB->IsSplit (Shape, TopAbs_IN)) {
917 for (Iterator.Initialize (myHB->Splits (Shape, TopAbs_IN)) ;
918 Iterator.More() ;
919 Iterator.Next()) {
920 myModified.Append (Iterator.Value()) ;
921 }
922 }
923 if (myHB->IsSplit (Shape, TopAbs_ON)) {
924 for (Iterator.Initialize (myHB->Splits (Shape, TopAbs_ON)) ;
925 Iterator.More() ;
926 Iterator.Next()) {
927 myModified.Append (Iterator.Value()) ;
928 }
929 }
930
931 if (myHB->IsMerged (Shape, TopAbs_OUT)) {
932 for (Iterator.Initialize (myHB->Merged (Shape, TopAbs_OUT)) ;
933 Iterator.More() ;
934 Iterator.Next()) {
935 myModified.Append (Iterator.Value()) ;
936 }
937 }
938 if (myHB->IsMerged(Shape, TopAbs_IN)) {
939 for (Iterator.Initialize (myHB->Merged (Shape, TopAbs_IN)) ;
940 Iterator.More() ;
941 Iterator.Next()) {
942 myModified.Append (Iterator.Value()) ;
943 }
944 }
945 if (myHB->IsMerged(Shape, TopAbs_ON)) {
946 for (Iterator.Initialize (myHB->Merged (Shape, TopAbs_ON)) ;
947 Iterator.More() ;
948 Iterator.Next()) {
949 myModified.Append (Iterator.Value()) ;
950 }
951 }
952
953 return myModified ;
954}
955
956
957
958//=======================================================================
959//function : Check
960//purpose :
961//=======================================================================
962
963BRepAlgo_CheckStatus BRepAlgo_DSAccess::Check()
964{
965// TopOpeBRepDS_Check Ck(HDS);
0d969553
Y
966// to be precised : in Ck, there is a possibility to know
967// exactly the n*n of shapes/points/curves/surfaces,
968// which are not correct in the DS.
7fd59977 969// Standard_Boolean IsOK = Ck.ChkIntgSamDom() ;
970// IsOK = IsOK && Ck.OneVertexOnPnt();
971// IsOK = IsOK && Ck.ChkIntg();
972// if(IsOK)
973// return TopOpeBRepDS_OK;
974 return BRepAlgo_NOK;
975}
976
977//=======================================================================
978//function : RemoveEdgeInterferences
979//purpose : case of SectEdge coming from Edge(s)
980//
981// if iE1 and iE2 are Edges :
982// Remove interferences of DSEdge(= iE1 or iE2) of
983// geometry a vertex of SectEdge, and if there is nothing else,
984// make unkeep on DSEdge
985// if iE1 or iE2 == 0, no interference on Edges in the DS
986// NYI : management of SameDomain
987//
988// if iE1 and iE2 are Faces :
989// for each of faces F1 and F2, explode into Edges
0d969553 990// for each Edge :
7fd59977 991// remove the interferences of a SectEdge vertex
992// on geometry. If there is no other interferences attached to
993// these Edges, and if these Edges are not SameDomain,
994// make unKeepShape.
995//=======================================================================
996
997void BRepAlgo_DSAccess::RemoveEdgeInterferences
998(const Standard_Integer iE1,
999 const Standard_Integer iE2,
1000 const TopoDS_Shape& SectEdge)
1001{
1002 if(!iE1 || !iE2)
1003 return;
1004
1005 TopOpeBRepDS_DataStructure& DS = myHDS->ChangeDS();
1006 TopOpeBRepDS_Kind kind1, kind2;
1007 TopExp_Explorer exp(SectEdge, TopAbs_VERTEX);
1008 Standard_Integer i = 1, ipv1, ipv2;
1009
1010 // the Vertex/Points of SectEdge are retrieved
1011 PntVtxOnSectEdge(SectEdge, ipv1, kind1, ipv2, kind2);
1012
1013 const TopoDS_Shape& Shape = DS.Shape(iE1, FindKeep);
1014 if(Shape.IsNull())
1015 return;
1016 if(Shape.ShapeType() == TopAbs_FACE) {
1017 Standard_Integer iF1 = iE1, iF2 = iE2;
1018 RemoveEdgeInterferencesFromFace(iF1, iF2, ipv1, kind1, ipv2, kind2);
1019 return;
1020 }
1021 else if(Shape.ShapeType() != TopAbs_EDGE)
1022 return;
1023
1024 // the interferences are taken from the DS
1025 TopOpeBRepDS_ListIteratorOfListOfInterference lioloi;
1026 TopOpeBRepDS_Kind gk;
1027 Standard_Integer iCurrE1, iCurrE2, gi;
1028// Standard_Boolean RemInterf;
1029
1030 for(i = 1; i <= 2; i++) {
1031 iCurrE1 = ((i == 1) ? iE1 : iE2);
1032 iCurrE2 = ((i == 1) ? iE2 : iE1);
1033 const TopoDS_Shape& DSEdge = DS.Shape(iCurrE1, FindKeep);
1034 if(DSEdge.IsNull())
1035 continue;
1036 TopOpeBRepDS_ListOfInterference& loi =
1037 DS.ChangeShapeInterferences(DSEdge);
1038 // RemInterf = Standard_True;
1039 for(lioloi.Initialize(loi); lioloi.More(); lioloi.Next()) {
1040 Handle(TopOpeBRepDS_Interference) I = lioloi.Value();
1041 if (I.IsNull()) continue;
1042 if((I->SupportType() != TopOpeBRepDS_EDGE) ||
1043 (I->Support() != iCurrE2)) {
1044 // RemInterf = Standard_False;//debug ...
1045 continue;
1046 }
1047 gk = I->GeometryType();
1048 gi = I->Geometry();
1049 if(gk == kind1) {
1050 if(gi == ipv1) {
1051 DS.RemoveShapeInterference(DSEdge, I);
1052 if(!DS.HasGeometry(DSEdge)) {
1053 // if(RemInterf || (!lioloi.More())) {
1054 RemoveEdgeSameDomain(iCurrE1, iCurrE2); // NYI : SameDomain
1055 DS.ChangeKeepShape(iCurrE1, FindKeep);
1056 // }
1057 }
1058 }
1059 }
1060 else if(gk == kind2) {
1061 if(gi == ipv2) {
1062 DS.RemoveShapeInterference(DSEdge, I);
1063 if(!DS.HasGeometry(DSEdge)) {
1064 // if(RemInterf || (!lioloi.More())) {//debug
1065 RemoveEdgeSameDomain(iCurrE1, iCurrE2); // NYI : SameDomain
1066 DS.ChangeKeepShape(iCurrE1, FindKeep);
1067 // }
1068 }
1069 }
1070 }
1071 }
1072 }
1073}
1074
1075//=======================================================================
1076//function : RemoveEdgeInterferences
1077//purpose : case of SectEdge coming from Curve
0d969553
Y
1078// for each of faces F1 and F2, explode into Edges
1079// for each Edge :
7fd59977 1080// remove the interferences that have a vertex of SectEdge
1081// as a geometry. If no other interferences are attached to
1082// these Edges, and if the Edges are not SameDomain,
1083// make unKeepShape.
1084//=======================================================================
1085
1086void BRepAlgo_DSAccess::RemoveEdgeInterferences
1087(const Standard_Integer iF1,
1088 const Standard_Integer iF2,
1089 const Standard_Integer iCurve)
1090{
1091 TopOpeBRepDS_Kind gk1, gk2;
1092 Standard_Integer gi1, gi2;
1093
1094 PntVtxOnCurve(iCurve, gi1, gk1, gi2, gk2);
1095
1096 if (!mySetOfKeepPoint.IsEmpty()) {
1097 if (mySetOfKeepPoint.Contains(gi1)) gi1 = 0;
1098 if (mySetOfKeepPoint.Contains(gi2)) gi2 = 0;
1099 }
1100
1101 if (gi1 || gi2)
1102 RemoveEdgeInterferencesFromFace(iF1, iF2, gi1, gk1, gi2, gk2);
1103}
1104
1105//=======================================================================
1106//function : RemoveFaceInterferences
1107//purpose : case of SectEdge coming from Edge(s)
1108// Remove interferences between F1 and F2 concerning
1109// DSEdge (= E1 or E2) :
1110// a) if DSEdge is not SameDomain -> the edge is Removed
1111// b) if among other interferences of DSEdge of
0d969553
Y
1112// GeomtryType == VERTEX, there is none
1113// with Edge of DSFace(= F1 or F2)
7fd59977 1114// if DSFace has no more interferences and is not SameDomain,
1115// make unkeep DSFace.
1116//=======================================================================
1117
1118void BRepAlgo_DSAccess::RemoveFaceInterferences
1119(const Standard_Integer iF1,
1120 const Standard_Integer iF2,
1121 const Standard_Integer iE1,
1122 const Standard_Integer iE2)
1123{
1124 if(!iF1 || !iF2)
1125 return;
1126 TopOpeBRepDS_DataStructure& DS = myHDS->ChangeDS();
1127 TopOpeBRepDS_ListIteratorOfListOfInterference lioloi;//, lioloei, liolofi;
1128 TopTools_ListIteratorOfListOfShape liolos;
1129 TopOpeBRepDS_Kind gk;
1130 TopExp_Explorer exp;
1131 Standard_Integer i, iCurrF1, iCurrF2, j, iCurrE1, /*iCurrE2,*/ gi; // skl
1132 Standard_Boolean RemInterf;
1133
1134 for(i = 1; i <= 2; i++) {
1135 iCurrF1 = ((i == 1) ? iF1 : iF2);
1136 iCurrF2 = ((i == 1) ? iF2 : iF1);
1137 const TopoDS_Shape& DSFace = DS.Shape(iCurrF1);
1138 if(DSFace.IsNull())
1139 continue;
1140 const TopOpeBRepDS_ListOfInterference& loi = DS.ShapeInterferences(DSFace);
1141 for(lioloi.Initialize(loi); lioloi.More(); lioloi.Next()) {
1142 Handle(TopOpeBRepDS_Interference) I = lioloi.Value();
1143 if (I.IsNull()) continue;
1144 if((I->SupportType() != TopOpeBRepDS_FACE) ||
1145 (I->Support() != iCurrF2)) {
1146 continue;
1147 }
1148 gk = I->GeometryType();
1149 gi = I->Geometry();
1150 if(gk != TopOpeBRepDS_EDGE) continue;
1151 for(j = 1; j <= 2; j++) {
1152 iCurrE1 = ((j == 1) ? iE1 : iE2);
1153 //iCurrE2 = ((j == 1) ? iE2 : iE1); // skl
1154 if(gi != iCurrE1) continue;
1155 // a) if DSEdge is not SameDomain -> the interference is Removed
1156 // et DSEdge
1157 const TopoDS_Shape& DSEdge = DS.Shape(iCurrE1, FindKeep);
1158 if(DSEdge.IsNull())
1159 continue;
1160 if(!myHDS->HasSameDomain(DSEdge)) {
1161 if(!DS.HasGeometry(DSEdge)) {
1162 DS.RemoveShapeInterference(DSFace, I);
1163 DS.ChangeKeepShape(DSEdge, FindKeep);
1164 } else {
1165 // NYI : manage the case when the geometry of DSEdge
1166 // NYI : is not connected anyhow with two faces
1167 }
1168 if(!DS.HasGeometry(DSFace)) {
1169 DS.ChangeKeepShape(DSFace, FindKeep);
1170 }
1171 continue;
1172 }
1173 // b) if no Edges of SameDomain(DSEdge),
1174 // belong to DSFace(= F1 or F2)
1175 // -> the interference is removed
1176 const TopoDS_Shape& Edge = DS.Shape(iCurrE1, FindKeep);
1177 if(Edge.IsNull())
1178 continue;
1179 const TopTools_ListOfShape& loe = DS.ShapeSameDomain(Edge);
1180 RemInterf = Standard_True;
1181 for(liolos.Initialize(loe); liolos.More(); liolos.Next()) {
1182 const TopoDS_Shape& ESD = liolos.Value();
1183 for(exp.Init(DSFace, TopAbs_EDGE); exp.More(); exp.Next()) {
1184 if(ESD.IsSame(exp.Current())) {
1185 RemInterf = Standard_False;
1186 break;
1187 }
1188 }
1189 if(!RemInterf) break;
1190 }
1191 if(RemInterf) {
1192 // RemoveSameDomain(iCurrF1, iCurrF2);
1193
1194 if(!DS.HasGeometry(DSFace)) {
1195 if(!myHDS->HasSameDomain(DSFace))
1196 DS.ChangeKeepShape(DSFace, FindKeep);
1197 }
1198 }
1199 if(!DS.HasGeometry(DSFace) && !myHDS->HasSameDomain(DSFace))
1200 DS.ChangeKeepShape(DSFace, FindKeep);
1201 }
1202 }
1203 }
1204}
1205
1206//=======================================================================
1207//function : RemoveFaceInterferences
1208//purpose : case of SectEdge from Curve
1209// remove interferences of Geometry iCurve between F1 and F2.
1210// if Face(= F1 or F2) has noother interference, and if Face
1211// is not SameDomain, make unKeepShape Face.
1212//=======================================================================
1213
1214void BRepAlgo_DSAccess::RemoveFaceInterferences
1215(const Standard_Integer iF1,
1216 const Standard_Integer iF2,
1217 const Standard_Integer iCurve)
1218{
1219 TopOpeBRepDS_DataStructure& DS = myHDS->ChangeDS();
1220 TopOpeBRepDS_ListIteratorOfListOfInterference lioloi;
1221 TopOpeBRepDS_Kind gk;
1222 Standard_Integer i, iCurrF1, iCurrF2, gi;
1223
1224 for(i = 1; i <= 2; i++) {
1225 iCurrF1 = ((i == 1) ? iF1 : iF2);
1226 iCurrF2 = ((i == 1) ? iF2 : iF1);
1227 const TopoDS_Shape& DSFace = DS.Shape(iCurrF1);
1228 const TopOpeBRepDS_ListOfInterference& loi = DS.ShapeInterferences(DSFace);
1229 for(lioloi.Initialize(loi); lioloi.More(); lioloi.Next()) {
1230 Handle(TopOpeBRepDS_Interference) I = lioloi.Value();
1231 if (I.IsNull()) continue;
1232 if((I->SupportType() != TopOpeBRepDS_FACE) ||
1233 (I->Support() != iCurrF2)) {
1234 break;;
1235 }
1236 }
1237 for(lioloi.Initialize(loi); lioloi.More(); lioloi.Next()) {
1238 Handle(TopOpeBRepDS_Interference) I = lioloi.Value();
1239 if (I.IsNull()) continue;
1240 if((I->SupportType() != TopOpeBRepDS_FACE) ||
1241 (I->Support() != iCurrF2)) {
1242 continue;
1243 }
1244 gk = I->GeometryType();
1245 gi = I->Geometry();
1246 if(gk != TopOpeBRepDS_CURVE) continue;
1247 if(gi != iCurve) continue;
1248 DS.RemoveShapeInterference(DSFace, I);
1249// const TopoDS_Shape& interferenceface = DS.Shape(iCurrF2);
1250// DS.RemoveShapeInterference(interferenceface, I);
1251 if(!DS.HasGeometry(DSFace)) {
1252 const TopTools_ListOfShape& los = DS.ShapeSameDomain(DSFace);
1253 if(los.IsEmpty())
1254 DS.ChangeKeepShape(DSFace, FindKeep);
1255 }
1256// if(!DS.HasGeometry(interferenceface)) {
1257// const TopTools_ListOfShape& los = DS.ShapeSameDomain(interferenceface);
1258// if(los.IsEmpty())
1259// DS.ChangeKeepShape(interferenceface, FindKeep);
1260// }
1261 }
1262 }
1263}
1264
1265//=======================================================================
1266//function : RemoveEdgeInterferencesFromFace
1267//purpose : Remove interferences of Edges from iF1 or iF2
1268// that have GeometryType kind1/kind2 and
1269// Geometry ipv1/ipv2.
1270// if kind1/kind2 == TopAbs_VERTEX -> RemoveEdgeFromFace
1271//=======================================================================
1272
1273void BRepAlgo_DSAccess::RemoveEdgeInterferencesFromFace
1274(const Standard_Integer iF1,
1275 const Standard_Integer iF2,
1276 const Standard_Integer ipv1,
1277 const TopOpeBRepDS_Kind kind1,
1278 const Standard_Integer ipv2,
1279 const TopOpeBRepDS_Kind kind2)
1280{
1281 TopOpeBRepDS_DataStructure& DS = myHDS->ChangeDS();
1282 TopOpeBRepDS_ListIteratorOfListOfInterference lioloi;
1283 TopExp_Explorer exp, exp2;
1284 TopOpeBRepDS_Kind sk, gk;
1285 Standard_Integer i, iCurrF1, iCurrF2, iE = 0, si, gi;
1286
1287 for(i = 1; i <= 2; i++) {
1288 iCurrF1 = ((i == 1) ? iF1 : iF2);
1289 iCurrF2 = ((i == 1) ? iF2 : iF1);
1290 const TopoDS_Shape& DSFace = DS.Shape(iCurrF1, FindKeep);
1291 if(DSFace.IsNull())
1292 continue;
1293 exp.Init(DSFace, TopAbs_EDGE);
1294 for(; exp.More(); exp.Next()) {
1295 const TopoDS_Shape& DSEdge = exp.Current();
1296 iE = DS.Shape(DSEdge, FindKeep);
1297 if(!iE) continue;
1298 const TopOpeBRepDS_ListOfInterference& loi =
1299 DS.ShapeInterferences(DSEdge);
1300 for(lioloi.Initialize(loi); lioloi.More(); lioloi.Next()) {
1301 Handle(TopOpeBRepDS_Interference) I = lioloi.Value();
1302 if (I.IsNull()) continue;
1303 sk = I->SupportType();
1304 si = I->Support();
1305 if((sk != TopOpeBRepDS_FACE) || (si != iCurrF2)) {
1306 if(sk != TopOpeBRepDS_EDGE)
1307 continue;
1308 const TopoDS_Shape& DSFace2 = DS.Shape(iCurrF2, FindKeep);
1309 exp2.Init(DSFace2, TopAbs_EDGE);
1310 for(; exp2.More(); exp2.Next()) {
1311 if(si == DS.Shape(exp2.Current(), FindKeep))
1312 break;
1313 }
1314 if(!exp2.More())
1315 continue;
1316 }
1317 gk = I->GeometryType();
1318 gi = I->Geometry();
1319 if(gk == kind1) {
1320 if(gi == ipv1) {
1321 DS.RemoveShapeInterference(DSEdge, I);
1322// if(!DS.HasGeometry(DSEdge)) {
1323// const TopTools_ListOfShape& los = DS.ShapeSameDomain(DSEdge);
1324// if(los.IsEmpty()) {
1325// DS.ChangeKeepShape(iE, FindKeep);
1326// }
1327// }
1328 }
1329 else if(gk == kind2) {
1330 if(gi == ipv2) {
1331 DS.RemoveShapeInterference(DSEdge, I);
1332// if(!DS.HasGeometry(DSEdge)) {
1333// const TopTools_ListOfShape& los = DS.ShapeSameDomain(DSEdge);
1334// if(los.IsEmpty()) {
1335// DS.ChangeKeepShape(iE, FindKeep);
1336// }
1337// }
1338 }
1339 }
1340 else continue;
1341 }
1342 }
1343 }
1344 if(kind1 == TopOpeBRepDS_VERTEX)
1345 RemoveEdgeFromFace(iCurrF1,ipv1);
1346 if(kind2 == TopOpeBRepDS_VERTEX)
1347 RemoveEdgeFromFace(iCurrF1,ipv2);
1348 }
1349}
1350
1351//=======================================================================
1352//function : RemoveEdgeFromFace
1353//purpose : Remove from DS the Edges, which belong to iF
1354// and have iV as vertex if they do not have Geometry and
1355// are not SameDomain.
1356//=======================================================================
1357
1358void BRepAlgo_DSAccess::RemoveEdgeFromFace
1359(const Standard_Integer iF,
1360 const Standard_Integer iV)
1361{
1362 if(!iF || !iV)
1363 return;
1364 TopOpeBRepDS_DataStructure& DS = myHDS->ChangeDS();
1365 const TopoDS_Shape& DSFace = DS.Shape(iF, FindKeep);
1366 const TopoDS_Shape& Vertex = DS.Shape(iV, FindKeep);
1367 if(DSFace.IsNull() || Vertex.IsNull())
1368 return;
1369 TopExp_Explorer exp(DSFace, TopAbs_EDGE), exp2;
1370 for(; exp.More(); exp.Next()) {
1371 const TopoDS_Shape& Edge = exp.Current();
0797d9d3 1372#ifdef OCCT_DEBUG
7fd59977 1373// Standard_Integer iEdge2 = DS.Shape(Edge, FindKeep);
1374// Standard_Integer iEdge3 = DS.Shape(Edge);
1375#endif
1376
1377 if(!DS.HasShape(Edge))
1378 continue;
1379 exp2.Init(Edge, TopAbs_VERTEX);
1380 for(; exp2.More(); exp2.Next()) {
0797d9d3 1381#ifdef OCCT_DEBUG
7fd59977 1382// Standard_Integer iEdge5 = DS.Shape(Vertex, FindKeep);
1383// Standard_Integer iEdge4 = DS.Shape(Vertex);
1384// Standard_Integer iEdge6 = DS.Shape(exp2.Current(), FindKeep);
1385// Standard_Integer iEdge7 = DS.Shape(exp2.Current());
1386#endif
1387
1388 if(Vertex.IsSame(exp2.Current())) {
1389 if(!DS.HasGeometry(Edge)) {
1390 const TopTools_ListOfShape& los = DS.ShapeSameDomain(Edge);
1391 if(los.IsEmpty()) {
0797d9d3 1392#ifdef OCCT_DEBUG
7fd59977 1393// Standard_Integer iEdge = DS.Shape(Edge);
1394#endif
1395 DS.ChangeKeepShape(Edge, FindKeep);
1396 }
1397 }
1398 }
1399 }
1400 }
1401}
1402
1403//=======================================================================
1404//function : PntVtxOnCurve
1405//purpose : To find the points/vertices on curves
1406//=======================================================================
1407
1408void BRepAlgo_DSAccess::PntVtxOnCurve
1409(const Standard_Integer iCurve,
1410 Standard_Integer& ipv1,
1411 TopOpeBRepDS_Kind& pvk1,
1412 Standard_Integer& ipv2,
1413 TopOpeBRepDS_Kind& pvk2)
1414{
1415 TopOpeBRepDS_DataStructure& DS = myHDS->ChangeDS();
1416
1417 const TopOpeBRepDS_Curve& C = DS.Curve(iCurve);
1418 TopOpeBRepDS_Kind pvk;
1419 Standard_Integer ipv, iMother = C.Mother(), igoodC = iCurve, comp = 0;
1420 if(iMother) igoodC = iMother;
0797d9d3 1421//#ifndef OCCT_DEBUG
7fd59977 1422 TopOpeBRepDS_PointIterator PII = myHDS->CurvePoints(igoodC);
c6541a0c 1423 TopOpeBRepDS_PointIterator& PIt = PII; // skl : I change "M_PI" to "PIt"
7fd59977 1424//#else
1425// TopOpeBRepDS_PointIterator& PIt = myHDS->CurvePoints(igoodC);
1426//#endif
1427 for(;PIt.More(); PIt.Next()) {
1428 comp++;
1429 if(comp > 2)
1430 // Standard_Error ...
1431 return;
1432 ipv = PIt.Current();
1433 // a point or a vertex is removed from the DS
1434 if(PIt.IsPoint()) {
1435 pvk = TopOpeBRepDS_POINT;
1436 DS.ChangeKeepPoint(ipv, FindKeep);
1437 }
1438 else if(PIt.IsVertex()) {
1439 pvk = TopOpeBRepDS_VERTEX;
1440 DS.ChangeKeepShape(ipv, FindKeep);
1441 }
1442 else continue;
1443 ((comp == 1) ? ipv1 : ipv2) = ipv;
1444 ((comp == 1) ? pvk1 : pvk2) = pvk;
1445 }
1446}
1447
1448//=======================================================================
1449//function : PntVtxOnSectEdge
1450//purpose : Points/Vertexes on SectEdge are found
1451//=======================================================================
1452
1453void BRepAlgo_DSAccess::PntVtxOnSectEdge
1454(const TopoDS_Shape& SectEdge,
1455 Standard_Integer& ipv1,
1456 TopOpeBRepDS_Kind& pvk1,
1457 Standard_Integer& ipv2,
1458 TopOpeBRepDS_Kind& pvk2)
1459{
1460// myHB->ChangeBuilder();
1461 TopOpeBRepDS_DataStructure& DS = myHDS->ChangeDS();
1462 TopOpeBRepDS_Kind kind = TopOpeBRepDS_POINT;
1463 TopExp_Explorer exp(SectEdge, TopAbs_VERTEX);
1464 Standard_Integer i = 1, ipv;
1465
1466 for(; exp.More(); exp.Next(), i++) {
1467 const TopoDS_Shape& DSVertex = exp.Current();
1468 ipv = myHB->GetDSPointFromNewVertex(DSVertex);
1469 if(!ipv) {
1470 ipv = DS.Shape(DSVertex, FindKeep);
1471 kind = TopOpeBRepDS_VERTEX;
1472 if(!ipv)
1473 // Standard_Error ...
1474 return;
1475 }
1476
1477 if(i == 1) {
1478 ipv1 = ipv;
1479 pvk1 = kind;
1480 }
1481 else if(i == 2) {
1482 ipv2 = ipv;
1483 pvk2 = kind;
1484 }
1485 else
1486 // Standard_Error ...
1487 return;
1488 }
1489}
1490
1491//=======================================================================
1492//function : RemoveEdgeSameDomain
1493//purpose :
1494//=======================================================================
1495
1496void BRepAlgo_DSAccess::RemoveEdgeSameDomain
1497(const Standard_Integer /*iE1*/,
1498 const Standard_Integer /*iE2*/)
1499{
1500 return;
1501/* TopOpeBRepDS_DataStructure& DS = myHDS->ChangeDS();
1502 const TopoDS_Shape& E1 = DS.Shape(iE1);
1503 const TopoDS_Shape& E2 = DS.Shape(iE2);
1504 TopAbs_ShapeEnum ts1, ts2;
1505 ts1 = E1.ShapeType();
1506 ts2 = E2.ShapeType();
1507 if((ts1 != TopAbs_EDGE) ||
1508 (ts2 != TopAbs_EDGE))
1509 return;
1510 TopTools_ListOfShape& lossd = DS.ChangeShapeSameDomain(E1);
1511 if(lossd.IsEmpty())
1512 return;
1513 Standard_Integer exte = lossd.Extent();
1514 if(exte == 1) {
1515 if(lossd.First().IsSame(E2))
1516 DS.UnfillShapesSameDomain(E1,E2);
1517 return;
1518 }*/
1519}
1520
1521//=======================================================================
1522//function : RemoveFaceSameDomain
1523//purpose : remove SameDomain information of glued faces
1524//=======================================================================
1525
1526void BRepAlgo_DSAccess::RemoveFaceSameDomain
1527(const TopoDS_Shape& C)
1528{
1529// myHB->ChangeBuilder();
1530 TopOpeBRepDS_DataStructure& DS = myHDS->ChangeDS();
1531
1532//TColStd_ListIteratorOfListOfInteger it;
1533 TopExp_Explorer exp(C, TopAbs_EDGE);
1534 Standard_Integer iE1, iE2, iE, /*NbF,*/ iF1, iF2, iCurrF1, iCurrF2, iC =0; // skl
1535 iF1 = iF2 = iCurrF1 = iCurrF2 = 0;
1536 Standard_Boolean b;
1537 const TopoDS_Shape& SectEdge = exp.Current();
1538
1539 for(; exp.More(); exp.Next()) {
1540 iC = myHB->GetDSCurveFromSectEdge(SectEdge);
1541 if(!iC && !SectEdge.IsNull())
1542 break;
1543// const TopoDS_Shape& SectEdge = exp.Current();
1544 }
1545 if(!iC && !SectEdge.IsNull()) {
1546 iE1 = myHB->GetDSEdgeFromSectEdge(SectEdge, 1);
1547 iE2 = myHB->GetDSEdgeFromSectEdge(SectEdge, 2);
1548 if(iE1 && iE2) return;
1549 iE = (iE1 ? iE1 : iE2);
1550 if(!iE) return;
1551
1552 TColStd_ListOfInteger& loi = FindGoodFace(iE, iF1, b);
1553 if(!b) return;
1554 if(exp.More())
1555 exp.Next();
1556 //NbF = loi.Extent(); // skl
1557 for(; exp.More(); exp.Next()) {
1558 // skl : I change "SectEdge" to "SectEdg"
1559 const TopoDS_Shape& SectEdg = exp.Current();
1560 iC = myHB->GetDSCurveFromSectEdge(SectEdg);
1561 if(!iC) {
1562 iE1 = myHB->GetDSEdgeFromSectEdge(SectEdg, 1);
1563 iE2 = myHB->GetDSEdgeFromSectEdge(SectEdg, 2);
1564 if(iE1 && iE2) return;
1565 iE = (iE1 ? iE1 : iE2);
1566 if(!iE) return;
1567
1568 TColStd_ListOfInteger& loi2 = FindGoodFace(iE, iCurrF1, b);
1569 if(!b) return;
1570 if(!iCurrF1 || !iF1) return;
1571 if(iCurrF1 != iF1) {
1572 if(loi2.Extent() == 1) iCurrF2 = loi2.First();
1573 if(iCurrF2 == iF1) continue;
1574 if(loi.Extent() == 1) iF2 = loi.First();
1575
1576 if(!iCurrF2 || !iF2) return;
1577 if((iCurrF1 == iF2) ||
1578 (iCurrF2 == iF2)) {
1579 iF1 = iF2;
1580 continue;
1581 }
1582 return;
1583 }
1584 }
1585 }
1586
1587 const TopoDS_Shape& FSD = DS.Shape(iF1);
1588 if(FSD.IsNull())
1589 return;
1590 TopTools_ListOfShape& ssd = DS.ChangeShapeSameDomain(FSD);
1591 TopTools_ListIteratorOfListOfShape itssd(ssd);
1592 TopExp_Explorer exp2;
1593 for(; itssd.More(); itssd.Next()) {
1594 exp2.Init(itssd.Value(), TopAbs_VERTEX);
1595 for(; exp2.More(); exp2.Next()) {
1596 const TopoDS_Shape& exp2Curr = exp2.Current();
1597 exp.Init(C, TopAbs_VERTEX);
1598 for(; exp.More(); exp.Next()) {
1599 if(exp2Curr.IsSame(exp.Current()))
1600 break;
1601 }
1602 if(exp.More())
1603 break;
1604 }
1605 if(exp2.More())
1606 break;
1607 }
1608
1609 if(exp2.More()) {
1610 const TopoDS_Shape& FSD2 = itssd.Value();
1611 Standard_Integer iFSD = DS.Shape(FSD), iFSD2 = DS.Shape(FSD2);
1612 RemoveFaceSameDomain(iFSD, iFSD2);
1613// DS.UnfillShapesSameDomain(FSD, FSD2);
1614 }
1615 }
1616}
1617
1618//=======================================================================
1619//function : FindGoodFace
1620//purpose :
1621//=======================================================================
1622
1623TColStd_ListOfInteger& BRepAlgo_DSAccess::FindGoodFace
1624(const Standard_Integer iE,
1625 Standard_Integer& iF1,
1626 Standard_Boolean& b)
1627{
1628// myHB->ChangeBuilder();
1629 b = Standard_False;
1630 TColStd_ListOfInteger& loi = myHB->GetDSFaceFromDSEdge(iE, 1);
1631 if(loi.Extent() == 1) {
1632 iF1 = loi.First();
1633 b = Standard_True;
1634 TColStd_ListOfInteger& loi2 = myHB->GetDSFaceFromDSEdge(iE, 2);
1635 return loi2;
1636 }
1637 else {
1638 TColStd_ListOfInteger& loi2 = myHB->GetDSFaceFromDSEdge(iE, 2);
1639 if(loi2.Extent() == 1) {
1640 b = Standard_True;
1641 iF1 = loi2.First();
1642 return loi;
1643 }
1644 }
1645 b = Standard_False;
1646 return myEmptyListOfInteger;
1647}
1648
1649//=======================================================================
1650//function : RemoveFaceSameDomain
1651//purpose :
1652//=======================================================================
1653
1654void BRepAlgo_DSAccess::RemoveFaceSameDomain
1655(const Standard_Integer iF1,
1656 const Standard_Integer iF2)
1657{
1658 TopOpeBRepDS_DataStructure& DS = myHDS->ChangeDS();
1659 const TopoDS_Shape& F1 = DS.Shape(iF1, FindKeep);
1660 const TopoDS_Shape& F2 = DS.Shape(iF2, FindKeep);
1661 if(F1.IsNull() || F2.IsNull())
1662 return;
1663
1664
1665 Standard_Integer iref1 = DS.SameDomainRef(F1),
1666 iref2 = DS.SameDomainRef(F2), istart, iend;
1667 if(iref1 == iF1)
1668 DS.SameDomainRef(F2,iF2);
1669 if(iref2 == iF1)
1670 DS.SameDomainRef(F1,iF1);
1671 DS.UnfillShapesSameDomain(F1,F2);
1672
1673 if(iref1 != iref2)
1674 return;
1675 Standard_Boolean iF1iF2IsConnected = Standard_False;
1676 TColStd_IndexedMapOfInteger moi;
1677 moi.Clear();
1678 if(iref2 == iF2) {
1679 istart = iF2;
1680 iend = iF1;
1681 }
1682 else {
1683 istart = iF1;
1684 iend = iF2;
1685 }
1686 moi.Add(istart);
1687 Standard_Integer NbConnect = 0, icurr;
1688 while(moi.Extent() > NbConnect) {
1689 NbConnect++;
1690 icurr = moi.FindKey(NbConnect);
1691 DS.SameDomainRef(icurr, istart);
1692 const TopTools_ListOfShape& los = DS.ShapeSameDomain(icurr);
1693 if(los.IsEmpty()) {
1694 const TopoDS_Shape& SNSD = DS.Shape(icurr);
1695 DS.SameDomainRef(SNSD, 0);
1696 }
1697 TopTools_ListIteratorOfListOfShape li(los);
1698 for(; li.More(); li.Next()) {
1699 Standard_Integer iCurrShap = DS.Shape(li.Value(), FindKeep);
1700 if(!iCurrShap)
1701 return;
1702 if(iCurrShap == iend)
1703 iF1iF2IsConnected = Standard_True;
1704 moi.Add(iCurrShap);
1705 }
1706 }
1707 if(!iF1iF2IsConnected) {
1708 moi.Clear();
1709 moi.Add(iend);
1710 NbConnect = 0;
1711 while(moi.Extent() > NbConnect) {
1712 NbConnect++;
1713 icurr = moi.FindKey(NbConnect);
1714 DS.SameDomainRef(icurr, iend);
1715 const TopTools_ListOfShape& los = DS.ShapeSameDomain(icurr);
1716 if(los.IsEmpty()) {
1717 const TopoDS_Shape& SNSD = DS.Shape(icurr);
1718 DS.SameDomainRef(SNSD, 0);
1719 }
1720 TopTools_ListIteratorOfListOfShape li(los);
1721 for(; li.More(); li.Next()) {
1722 Standard_Integer iCurrShap = DS.Shape(li.Value(), FindKeep);
1723 if(!iCurrShap)
1724 return;
1725 moi.Add(iCurrShap);
1726 }
1727 }
1728 }
1729}
1730
1731//=======================================================================
1732//function : DS
1733//purpose :
1734//=======================================================================
1735
1736const Handle(TopOpeBRepDS_HDataStructure)&
1737BRepAlgo_DSAccess::DS() const
1738{
1739 return myHDS;
1740}
1741
1742//=======================================================================
1743//function : changeDS
1744//purpose :
1745//=======================================================================
1746Handle(TopOpeBRepDS_HDataStructure)&
1747BRepAlgo_DSAccess::ChangeDS()
1748{
1749 return myHDS;
1750}
1751
1752//=======================================================================
1753//function : Builder
1754//purpose :
1755//=======================================================================
1756
1757const Handle(TopOpeBRepBuild_HBuilder)&
1758BRepAlgo_DSAccess::Builder() const
1759{
1760 return myHB;
1761}
1762
1763//=======================================================================
1764//function : ChangeBuilder
1765//purpose :
1766//=======================================================================
1767
1768Handle(TopOpeBRepBuild_HBuilder)&
1769BRepAlgo_DSAccess::ChangeBuilder()
1770{
1771 return myHB;
1772}