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
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Standard_NoSuchObject.hxx>
19 #include <Standard_ProgramError.hxx>
20 #include <Standard_Type.hxx>
21 #include <TColStd_ListIteratorOfListOfInteger.hxx>
22 #include <TColStd_MapOfInteger.hxx>
24 #include <TopoDS_Shape.hxx>
25 #include <TopOpeBRepBuild_Builder.hxx>
26 #include <TopOpeBRepBuild_define.hxx>
27 #include <TopOpeBRepBuild_HBuilder.hxx>
28 #include <TopOpeBRepDS_BuildTool.hxx>
29 #include <TopOpeBRepDS_CurveExplorer.hxx>
30 #include <TopOpeBRepDS_CurveIterator.hxx>
31 #include <TopOpeBRepDS_DataMapIteratorOfDataMapOfShapeListOfShapeOn1State.hxx>
32 #include <TopOpeBRepDS_HDataStructure.hxx>
33 #include <TopOpeBRepDS_Interference.hxx>
34 #include <TopOpeBRepDS_ListOfShapeOn1State.hxx>
35 #include <TopOpeBRepDS_ShapeShapeInterference.hxx>
36 #include <TopTools_ListIteratorOfListOfShape.hxx>
37 #include <TopTools_ListOfShape.hxx>
38 #include <TopTools_MapOfShape.hxx>
40 IMPLEMENT_STANDARD_RTTIEXT(TopOpeBRepBuild_HBuilder,MMgt_TShared)
42 //=======================================================================
43 //function : TopOpeBRepBuild_HBuilder
45 //=======================================================================
46 TopOpeBRepBuild_HBuilder::TopOpeBRepBuild_HBuilder
47 (const TopOpeBRepDS_BuildTool& BT)
49 myMakeEdgeAncestorIsDone(Standard_False),
50 myMakeCurveAncestorIsDone(Standard_False),
51 myMakePointAncestorIsDone(Standard_False)
55 //=======================================================================
58 //=======================================================================
59 void TopOpeBRepBuild_HBuilder::Perform
60 (const Handle(TopOpeBRepDS_HDataStructure)& HDS)
62 myBuilder.Perform(HDS);
65 //=======================================================================
68 //=======================================================================
69 void TopOpeBRepBuild_HBuilder::Perform(const Handle(TopOpeBRepDS_HDataStructure)& HDS,const TopoDS_Shape& S1, const TopoDS_Shape& S2)
71 myBuilder.Perform(HDS,S1,S2);
74 //=======================================================================
77 //=======================================================================
78 void TopOpeBRepBuild_HBuilder::Clear()
81 InitExtendedSectionDS();
84 //=======================================================================
85 //function : DataStructure
87 //=======================================================================
88 Handle(TopOpeBRepDS_HDataStructure) TopOpeBRepBuild_HBuilder::DataStructure() const
90 return myBuilder.DataStructure();
93 //=======================================================================
94 //function : ChangeBuildTool
96 //=======================================================================
97 TopOpeBRepDS_BuildTool& TopOpeBRepBuild_HBuilder::ChangeBuildTool()
99 TopOpeBRepDS_BuildTool& BT = myBuilder.ChangeBuildTool();
103 //=======================================================================
104 //function : BuildTool
106 //=======================================================================
107 const TopOpeBRepDS_BuildTool& TopOpeBRepBuild_HBuilder::BuildTool() const
109 return myBuilder.BuildTool();
112 //=======================================================================
113 //function : MergeShapes
115 //=======================================================================
117 void TopOpeBRepBuild_HBuilder::MergeShapes
118 (const TopoDS_Shape& S1, const TopAbs_State ToBuild1,const TopoDS_Shape& S2, const TopAbs_State ToBuild2)
120 myBuilder.MergeShapes(S1,ToBuild1,S2,ToBuild2);
124 //=======================================================================
125 //function : MergeSolids
127 //=======================================================================
129 void TopOpeBRepBuild_HBuilder::MergeSolids
130 (const TopoDS_Shape& S1, const TopAbs_State ToBuild1,const TopoDS_Shape& S2, const TopAbs_State ToBuild2)
132 myBuilder.MergeSolids(S1,ToBuild1,S2,ToBuild2);
136 //=======================================================================
137 //function : MergeSolid
139 //=======================================================================
141 void TopOpeBRepBuild_HBuilder::MergeSolid(const TopoDS_Shape& S, const TopAbs_State ToBuild)
143 myBuilder.MergeSolid(S,ToBuild);
147 //=======================================================================
150 //=======================================================================
151 Standard_Boolean TopOpeBRepBuild_HBuilder::IsSplit(const TopoDS_Shape& S, const TopAbs_State ToBuild) const
153 Standard_Boolean res = myBuilder.IsSplit(S,ToBuild);
158 //=======================================================================
161 //=======================================================================
162 const TopTools_ListOfShape& TopOpeBRepBuild_HBuilder::Splits(const TopoDS_Shape& S, const TopAbs_State ToBuild) const
164 const TopTools_ListOfShape& L = myBuilder.Splits(S,ToBuild);
169 //=======================================================================
170 //function : IsMerged
172 //=======================================================================
174 Standard_Boolean TopOpeBRepBuild_HBuilder::IsMerged(const TopoDS_Shape& S, const TopAbs_State ToBuild) const
176 Standard_Boolean res = myBuilder.IsMerged(S,ToBuild);
181 //=======================================================================
184 //=======================================================================
186 const TopTools_ListOfShape& TopOpeBRepBuild_HBuilder::Merged(const TopoDS_Shape& S, const TopAbs_State ToBuild) const
188 const TopTools_ListOfShape& L = myBuilder.Merged(S,ToBuild);
193 //=======================================================================
194 //function : NewVertex
196 //=======================================================================
197 const TopoDS_Shape& TopOpeBRepBuild_HBuilder::NewVertex(const Standard_Integer I) const
199 const TopoDS_Shape& V = myBuilder.NewVertex(I);
204 //=======================================================================
205 //function : NewEdges
207 //=======================================================================
208 const TopTools_ListOfShape& TopOpeBRepBuild_HBuilder::NewEdges(const Standard_Integer I) const
210 const TopTools_ListOfShape& L = myBuilder.NewEdges(I);
214 //=======================================================================
215 //function : ChangeNewEdges
217 //=======================================================================
218 TopTools_ListOfShape& TopOpeBRepBuild_HBuilder::ChangeNewEdges(const Standard_Integer I)
220 TopTools_ListOfShape& L = myBuilder.ChangeNewEdges(I);
225 //=======================================================================
226 //function : NewFaces
228 //=======================================================================
229 const TopTools_ListOfShape& TopOpeBRepBuild_HBuilder::NewFaces(const Standard_Integer I) const
231 const TopTools_ListOfShape& L = myBuilder.NewFaces(I);
236 //=======================================================================
239 //=======================================================================
241 const TopTools_ListOfShape& TopOpeBRepBuild_HBuilder::Section()
243 const TopTools_ListOfShape& L = myBuilder.Section();
247 static TopTools_ListOfShape* PLE = NULL;
248 static TopTools_ListIteratorOfListOfShape* PITLE = NULL;
249 //=======================================================================
250 //function : InitExtendedSectionDS
252 //=======================================================================
254 void TopOpeBRepBuild_HBuilder::InitExtendedSectionDS(const Standard_Integer k)
257 myMakeCurveAncestorIsDone = Standard_False;
260 myMakeEdgeAncestorIsDone = Standard_False;
263 myMakeEdgeAncestorIsDone = Standard_False;
264 myMakeCurveAncestorIsDone = Standard_False;
269 //=======================================================================
270 //function : InitSection
272 //=======================================================================
274 void TopOpeBRepBuild_HBuilder::InitSection(const Standard_Integer k)
276 if (PLE == NULL) PLE = new TopTools_ListOfShape();
277 if (PITLE == NULL) PITLE = new TopTools_ListIteratorOfListOfShape();
278 PLE->Clear(); PITLE->Initialize(*PLE);
279 InitExtendedSectionDS(k);
280 if (k == 1) myBuilder.SectionCurves(*PLE);
281 else if (k == 2) myBuilder.SectionEdges(*PLE);
282 else if (k == 3) myBuilder.Section(*PLE);
284 PITLE->Initialize(*PLE);
287 //=======================================================================
288 //function : MoreSection
290 //=======================================================================
292 Standard_Boolean TopOpeBRepBuild_HBuilder::MoreSection() const
294 if (PITLE == NULL) return Standard_False;
295 Standard_Boolean b = PITLE->More();
299 //=======================================================================
300 //function : NextSection
302 //=======================================================================
304 void TopOpeBRepBuild_HBuilder::NextSection()
306 if (PITLE == NULL) return;
307 if (PITLE->More()) PITLE->Next();
310 //=======================================================================
311 //function : CurrentSection
313 //=======================================================================
315 const TopoDS_Shape& TopOpeBRepBuild_HBuilder::CurrentSection() const
317 if (PITLE == NULL) Standard_ProgramError::Raise("no more CurrentSection");
318 if (!PITLE->More()) Standard_ProgramError::Raise("no more CurrentSection");
319 return PITLE->Value();
322 //=======================================================================
323 //function : MakeEdgeAncestorMap
325 //=======================================================================
327 void TopOpeBRepBuild_HBuilder::MakeEdgeAncestorMap()
329 if(myMakeEdgeAncestorIsDone)
331 mySectEdgeDSEdges1.Clear();
332 mySectEdgeDSEdges2.Clear();
333 myDSEdgesDSFaces1.Clear();
334 myDSEdgesDSFaces2.Clear();
336 myMakeEdgeAncestorIsDone = Standard_True;
337 TopTools_MapOfShape MF, ME;
339 const TopOpeBRepDS_DataStructure& DS = DataStructure()->DS();
340 // Standard_Integer ns = DS.NbShapes(),is;
341 Standard_Integer ns = DS.NbShapes();
342 // Standard_Integer ei, fi, re, rf ,gi, ise;
343 Standard_Integer ei, fi, re, rf ,gi;
345 TopOpeBRepDS_DataMapIteratorOfDataMapOfShapeListOfShapeOn1State
346 it(myBuilder.mySplitON);
347 TopTools_ListIteratorOfListOfShape its;
348 for(;it.More(); it.Next()) {
349 const TopoDS_Shape& ShaSpl = it.Key();
350 ei = DS.Shape(ShaSpl);
351 re = DS.AncestorRank(ShaSpl);
353 TopOpeBRepDS_ListOfShapeOn1State& losos1s =
354 (*(TopOpeBRepDS_ListOfShapeOn1State*)&it.Value());
355 TopTools_ListOfShape& los = losos1s.ChangeListOnState();
358 for(; its.More(); its.Next()) {
359 TopoDS_Shape& SecEdg = its.Value();
360 if(!mySectEdgeDSEdges1.IsBound(SecEdg))
361 mySectEdgeDSEdges1.Bind(SecEdg, ei);
364 for(; its.More(); its.Next()) {
365 TopoDS_Shape& SecEdg = its.Value();
366 if(!mySectEdgeDSEdges2.IsBound(SecEdg))
367 mySectEdgeDSEdges2.Bind(SecEdg,ei);
371 // Standard_Boolean gb;
372 TopOpeBRepDS_Kind gk;
373 for (fi=1;fi<=ns;fi++) {
374 const TopoDS_Shape& fds = DS.Shape(fi);
377 if (fds.ShapeType() != TopAbs_FACE) continue;
378 TopOpeBRepDS_ListIteratorOfListOfInterference
379 it1(DS.ShapeInterferences(fds));
380 for (;it1.More();it1.Next()) {
381 Handle(TopOpeBRepDS_ShapeShapeInterference) SSI =
382 Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(it1.Value());
383 if (SSI.IsNull()) continue;
384 gk = SSI->GeometryType();
385 gi = SSI->Geometry();
386 if (gk != TopOpeBRepDS_EDGE) continue;
387 rf = DS.AncestorRank(fds);
389 // if (!MF.Contains(fds) ) {
392 if(!myDSEdgesDSFaces1.IsBound(gi)) {
393 TColStd_ListOfInteger thelist;
394 myDSEdgesDSFaces1.Bind(gi,thelist );
396 myDSEdgesDSFaces1.ChangeFind(gi).Append(fi);
399 if(!myDSEdgesDSFaces2.IsBound(gi)){
400 TColStd_ListOfInteger thelist1;
401 myDSEdgesDSFaces2.Bind(gi, thelist1);
403 myDSEdgesDSFaces2.ChangeFind(gi).Append(fi);
410 //=======================================================================
411 //function : GetDSEdgeFromSectEdge
413 //=======================================================================
414 Standard_Integer TopOpeBRepBuild_HBuilder::GetDSEdgeFromSectEdge(const TopoDS_Shape& E,const Standard_Integer rank)
416 if(!myMakeEdgeAncestorIsDone)
417 MakeEdgeAncestorMap();
419 Standard_Integer i = 0;
422 if(mySectEdgeDSEdges1.IsBound(E))
423 i = mySectEdgeDSEdges1.Find(E);
427 if(mySectEdgeDSEdges2.IsBound(E))
428 i = mySectEdgeDSEdges2.Find(E);
433 //=======================================================================
434 //function : GetDSFaceFromDSEdge
436 //=======================================================================
437 TColStd_ListOfInteger& TopOpeBRepBuild_HBuilder::GetDSFaceFromDSEdge
438 (const Standard_Integer indexEdg, const Standard_Integer rank)
440 if(!myMakeEdgeAncestorIsDone)
441 MakeEdgeAncestorMap();
444 if(myDSEdgesDSFaces1.IsBound(indexEdg)) {
445 TColStd_ListOfInteger& loi =
446 myDSEdgesDSFaces1.ChangeFind(indexEdg);
452 if(myDSEdgesDSFaces2.IsBound(indexEdg)) {
453 TColStd_ListOfInteger& loi =
454 myDSEdgesDSFaces2.ChangeFind(indexEdg);
459 return myEmptyIntegerList;
462 //=======================================================================
463 //function : MakeCurveAncestorMap
465 //=======================================================================
467 void TopOpeBRepBuild_HBuilder::MakeCurveAncestorMap()
469 if(myMakeCurveAncestorIsDone)
471 mySectEdgeDSCurve.Clear();
472 myMakeCurveAncestorIsDone = Standard_True;
473 const TopOpeBRepDS_DataStructure& DS = DataStructure()->DS();
474 TopTools_ListIteratorOfListOfShape itloe;
475 TopOpeBRepDS_CurveExplorer cex(DS,Standard_True);
476 // Standard_Integer ic, icm;
478 for (; cex.More(); cex.Next()) {
480 const TopTools_ListOfShape& LOS = myBuilder.myNewEdges.Find(ic);
481 itloe.Initialize(LOS);
482 for(;itloe.More();itloe.Next()) {
483 TopoDS_Shape& E = *((TopoDS_Shape*)(&itloe.Value()));
484 if(mySectEdgeDSCurve.IsBound(E)) {
486 cout<<"BRepAlgo_DSAccess::MakeEdgeAncestorFromCurve : program error"<<endl;
489 mySectEdgeDSCurve.Bind(E, ic);
494 //=======================================================================
495 //function : GetDSCurveFromSectEdge
497 //=======================================================================
499 Standard_Integer TopOpeBRepBuild_HBuilder::GetDSCurveFromSectEdge(const TopoDS_Shape& SectEdge)
501 Standard_Integer i = 0;
502 if(!myMakeCurveAncestorIsDone)
503 MakeCurveAncestorMap();
505 if(mySectEdgeDSCurve.IsBound(SectEdge)) {
506 i = mySectEdgeDSCurve.Find(SectEdge);
511 //=======================================================================
512 //function : GetDSFaceFromDSCurve
514 //=======================================================================
516 Standard_Integer TopOpeBRepBuild_HBuilder::GetDSFaceFromDSCurve(const Standard_Integer indexCur,const Standard_Integer rank)
518 Standard_Integer i = 0;
519 if(!myMakeCurveAncestorIsDone)
520 MakeCurveAncestorMap();
522 const TopOpeBRepDS_DataStructure& DS = DataStructure()->DS();
524 const TopOpeBRepDS_Curve& DSC = DS.Curve(indexCur);
525 const TopoDS_Shape& F1 = DSC.Shape1();
530 const TopOpeBRepDS_Curve& DSC = DS.Curve(indexCur);
531 const TopoDS_Shape& F2 = DSC.Shape2();
538 //=======================================================================
539 //function : GetDSPointFromNewVertex
541 //=======================================================================
543 Standard_Integer TopOpeBRepBuild_HBuilder::GetDSPointFromNewVertex(const TopoDS_Shape& NewVert)
545 if(!myMakePointAncestorIsDone) {
546 myMakePointAncestorIsDone = Standard_True;
547 TopOpeBRepDS_DataStructure& DS = DataStructure()->ChangeDS();
548 Standard_Integer i, NbPoint = DS.NbPoints();
549 for(i = 1; i <= NbPoint; i++) {
550 const TopoDS_Shape& Vertex = NewVertex(i);
552 myNewVertexDSPoint.Bind(Vertex, i);
556 Standard_Integer iPnt = 0;
557 if(myNewVertexDSPoint.IsBound(NewVert))
558 iPnt = myNewVertexDSPoint.Find(NewVert);
562 //=======================================================================
563 //function : EdgeCurveAncestors
565 //=======================================================================
567 Standard_Boolean TopOpeBRepBuild_HBuilder::EdgeCurveAncestors(const TopoDS_Shape& E,TopoDS_Shape& F1,TopoDS_Shape& F2,Standard_Integer& IC)
569 F1.Nullify(); F2.Nullify(); IC = 0;
571 const Handle(TopOpeBRepDS_HDataStructure)& HDS = myBuilder.DataStructure();
572 const TopOpeBRepDS_DataStructure& DS = HDS->DS();
574 // TopTools_ListIteratorOfListOfShape itloe;
575 IC = GetDSCurveFromSectEdge(E);
577 return Standard_False;
579 Standard_Integer iF1, iF2;
580 iF1 = GetDSFaceFromDSCurve(IC, 1);
581 iF2 = GetDSFaceFromDSCurve(IC, 2);
585 return Standard_True;
588 //=======================================================================
589 //function : EdgeSectionAncestors
591 //=======================================================================
593 Standard_Boolean TopOpeBRepBuild_HBuilder::EdgeSectionAncestors
594 (const TopoDS_Shape& E, TopTools_ListOfShape& LF1, TopTools_ListOfShape& LF2, TopTools_ListOfShape& LE1, TopTools_ListOfShape& LE2)
596 if (E.ShapeType() != TopAbs_EDGE) return Standard_False;
598 LF1.Clear(); LF2.Clear(); LE1.Clear(); LE2.Clear();
599 TColStd_ListOfInteger f1, f2;
600 f1.Clear(); f2.Clear();
601 Standard_Integer ie1, ie2, curr;
603 ie1 = GetDSEdgeFromSectEdge(E,1);
604 ie2 = GetDSEdgeFromSectEdge(E,2);
605 TColStd_ListIteratorOfListOfInteger it;
608 TColStd_MapOfInteger moi;
610 f1 = GetDSFaceFromDSEdge(ie1,1);
613 for(; it.More(); it.Next()) {
616 it.Initialize(GetDSFaceFromDSEdge(ie2,1));
617 for(; it.More(); it.Next()) {
619 if(!moi.Contains(curr)) {
624 f2 = GetDSFaceFromDSEdge(ie1,2);
627 for(; it.More(); it.Next()) {
630 it.Initialize(GetDSFaceFromDSEdge(ie2,2));
631 for(; it.More(); it.Next()) {
633 if(!moi.Contains(curr)) {
641 f1 = GetDSFaceFromDSEdge(ie1,1);
642 f2 = GetDSFaceFromDSEdge(ie1,2);
645 f1 = GetDSFaceFromDSEdge(ie2,1);
646 f2 = GetDSFaceFromDSEdge(ie2,2);
650 const TopOpeBRepDS_DataStructure& DS = myBuilder.DataStructure()->DS();
653 LE1.Append(DS.Shape(ie1));
655 LE2.Append(DS.Shape(ie2));
657 for(it.Initialize(f1); it.More(); it.Next()) {
659 LF1.Append(DS.Shape(curr));
661 for(it.Initialize(f2); it.More(); it.Next()) {
663 LF2.Append(DS.Shape(curr));
666 Standard_Boolean r = (!LF1.IsEmpty() && !LF2.IsEmpty());
667 r = r && (!LE1.IsEmpty() || !LE2.IsEmpty());
671 //=======================================================================
674 //=======================================================================
676 Standard_Integer TopOpeBRepBuild_HBuilder::IsKPart()
678 Standard_Integer kp = myBuilder.IsKPart();
682 //=======================================================================
683 //function : MergeKPart
685 //=======================================================================
687 void TopOpeBRepBuild_HBuilder::MergeKPart(const TopAbs_State TB1,const TopAbs_State TB2)
689 Standard_Integer kp = IsKPart();
690 if ( kp ) myBuilder.MergeKPart(TB1,TB2);
693 //=======================================================================
694 //function : ChangeBuilder
696 //=======================================================================
698 TopOpeBRepBuild_Builder& TopOpeBRepBuild_HBuilder::ChangeBuilder()