1 // File: TopOpeBRepBuild_HBuilder.cxx
2 // Created: Mon Jun 14 11:48:36 1993
3 // Author: Jean Yves LEBEY
6 #include <TopOpeBRepBuild_HBuilder.ixx>
7 #include <TopOpeBRepDS_ListOfShapeOn1State.hxx>
8 #include <TopOpeBRepDS_DataMapIteratorOfDataMapOfShapeListOfShapeOn1State.hxx>
9 #include <TopOpeBRepDS_CurveIterator.hxx>
10 #include <TopOpeBRepDS_CurveExplorer.hxx>
11 #include <TopOpeBRepDS_Interference.hxx>
12 #include <TopOpeBRepDS_ShapeShapeInterference.hxx>
13 #include <TopTools_ListOfShape.hxx>
14 #include <TopTools_ListIteratorOfListOfShape.hxx>
15 #include <TColStd_ListIteratorOfListOfInteger.hxx>
16 #include <TColStd_MapOfInteger.hxx>
17 #include <TopTools_MapOfShape.hxx>
19 #include <Standard_ProgramError.hxx>
20 #include <TopOpeBRepBuild_define.hxx>
22 //=======================================================================
23 //function : TopOpeBRepBuild_HBuilder
25 //=======================================================================
26 TopOpeBRepBuild_HBuilder::TopOpeBRepBuild_HBuilder
27 (const TopOpeBRepDS_BuildTool& BT)
29 myMakeEdgeAncestorIsDone(Standard_False),
30 myMakeCurveAncestorIsDone(Standard_False),
31 myMakePointAncestorIsDone(Standard_False)
35 //=======================================================================
38 //=======================================================================
39 void TopOpeBRepBuild_HBuilder::Perform
40 (const Handle(TopOpeBRepDS_HDataStructure)& HDS)
42 myBuilder.Perform(HDS);
45 //=======================================================================
48 //=======================================================================
49 void TopOpeBRepBuild_HBuilder::Perform(const Handle(TopOpeBRepDS_HDataStructure)& HDS,const TopoDS_Shape& S1, const TopoDS_Shape& S2)
51 myBuilder.Perform(HDS,S1,S2);
54 //=======================================================================
57 //=======================================================================
58 void TopOpeBRepBuild_HBuilder::Clear()
61 InitExtendedSectionDS();
64 //=======================================================================
65 //function : DataStructure
67 //=======================================================================
68 Handle(TopOpeBRepDS_HDataStructure) TopOpeBRepBuild_HBuilder::DataStructure() const
70 return myBuilder.DataStructure();
73 //=======================================================================
74 //function : ChangeBuildTool
76 //=======================================================================
77 TopOpeBRepDS_BuildTool& TopOpeBRepBuild_HBuilder::ChangeBuildTool()
79 TopOpeBRepDS_BuildTool& BT = myBuilder.ChangeBuildTool();
83 //=======================================================================
84 //function : BuildTool
86 //=======================================================================
87 const TopOpeBRepDS_BuildTool& TopOpeBRepBuild_HBuilder::BuildTool() const
89 return myBuilder.BuildTool();
92 //=======================================================================
93 //function : MergeShapes
95 //=======================================================================
97 void TopOpeBRepBuild_HBuilder::MergeShapes
98 (const TopoDS_Shape& S1, const TopAbs_State ToBuild1,const TopoDS_Shape& S2, const TopAbs_State ToBuild2)
100 myBuilder.MergeShapes(S1,ToBuild1,S2,ToBuild2);
104 //=======================================================================
105 //function : MergeSolids
107 //=======================================================================
109 void TopOpeBRepBuild_HBuilder::MergeSolids
110 (const TopoDS_Shape& S1, const TopAbs_State ToBuild1,const TopoDS_Shape& S2, const TopAbs_State ToBuild2)
112 myBuilder.MergeSolids(S1,ToBuild1,S2,ToBuild2);
116 //=======================================================================
117 //function : MergeSolid
119 //=======================================================================
121 void TopOpeBRepBuild_HBuilder::MergeSolid(const TopoDS_Shape& S, const TopAbs_State ToBuild)
123 myBuilder.MergeSolid(S,ToBuild);
127 //=======================================================================
130 //=======================================================================
131 Standard_Boolean TopOpeBRepBuild_HBuilder::IsSplit(const TopoDS_Shape& S, const TopAbs_State ToBuild) const
133 Standard_Boolean res = myBuilder.IsSplit(S,ToBuild);
138 //=======================================================================
141 //=======================================================================
142 const TopTools_ListOfShape& TopOpeBRepBuild_HBuilder::Splits(const TopoDS_Shape& S, const TopAbs_State ToBuild) const
144 const TopTools_ListOfShape& L = myBuilder.Splits(S,ToBuild);
149 //=======================================================================
150 //function : IsMerged
152 //=======================================================================
154 Standard_Boolean TopOpeBRepBuild_HBuilder::IsMerged(const TopoDS_Shape& S, const TopAbs_State ToBuild) const
156 Standard_Boolean res = myBuilder.IsMerged(S,ToBuild);
161 //=======================================================================
164 //=======================================================================
166 const TopTools_ListOfShape& TopOpeBRepBuild_HBuilder::Merged(const TopoDS_Shape& S, const TopAbs_State ToBuild) const
168 const TopTools_ListOfShape& L = myBuilder.Merged(S,ToBuild);
173 //=======================================================================
174 //function : NewVertex
176 //=======================================================================
177 const TopoDS_Shape& TopOpeBRepBuild_HBuilder::NewVertex(const Standard_Integer I) const
179 const TopoDS_Shape& V = myBuilder.NewVertex(I);
184 //=======================================================================
185 //function : NewEdges
187 //=======================================================================
188 const TopTools_ListOfShape& TopOpeBRepBuild_HBuilder::NewEdges(const Standard_Integer I) const
190 const TopTools_ListOfShape& L = myBuilder.NewEdges(I);
194 //=======================================================================
195 //function : ChangeNewEdges
197 //=======================================================================
198 TopTools_ListOfShape& TopOpeBRepBuild_HBuilder::ChangeNewEdges(const Standard_Integer I)
200 TopTools_ListOfShape& L = myBuilder.ChangeNewEdges(I);
205 //=======================================================================
206 //function : NewFaces
208 //=======================================================================
209 const TopTools_ListOfShape& TopOpeBRepBuild_HBuilder::NewFaces(const Standard_Integer I) const
211 const TopTools_ListOfShape& L = myBuilder.NewFaces(I);
216 //=======================================================================
219 //=======================================================================
221 const TopTools_ListOfShape& TopOpeBRepBuild_HBuilder::Section()
223 const TopTools_ListOfShape& L = myBuilder.Section();
227 static TopTools_ListOfShape* PLE = NULL;
228 static TopTools_ListIteratorOfListOfShape* PITLE = NULL;
229 //=======================================================================
230 //function : InitExtendedSectionDS
232 //=======================================================================
234 void TopOpeBRepBuild_HBuilder::InitExtendedSectionDS(const Standard_Integer k)
237 myMakeCurveAncestorIsDone = Standard_False;
240 myMakeEdgeAncestorIsDone = Standard_False;
243 myMakeEdgeAncestorIsDone = Standard_False;
244 myMakeCurveAncestorIsDone = Standard_False;
249 //=======================================================================
250 //function : InitSection
252 //=======================================================================
254 void TopOpeBRepBuild_HBuilder::InitSection(const Standard_Integer k)
256 if (PLE == NULL) PLE = new TopTools_ListOfShape();
257 if (PITLE == NULL) PITLE = new TopTools_ListIteratorOfListOfShape();
258 PLE->Clear(); PITLE->Initialize(*PLE);
259 InitExtendedSectionDS(k);
260 if (k == 1) myBuilder.SectionCurves(*PLE);
261 else if (k == 2) myBuilder.SectionEdges(*PLE);
262 else if (k == 3) myBuilder.Section(*PLE);
264 PITLE->Initialize(*PLE);
267 //=======================================================================
268 //function : MoreSection
270 //=======================================================================
272 Standard_Boolean TopOpeBRepBuild_HBuilder::MoreSection() const
274 if (PITLE == NULL) return Standard_False;
275 Standard_Boolean b = PITLE->More();
279 //=======================================================================
280 //function : NextSection
282 //=======================================================================
284 void TopOpeBRepBuild_HBuilder::NextSection()
286 if (PITLE == NULL) return;
287 if (PITLE->More()) PITLE->Next();
290 //=======================================================================
291 //function : CurrentSection
293 //=======================================================================
295 const TopoDS_Shape& TopOpeBRepBuild_HBuilder::CurrentSection() const
297 if (PITLE == NULL) Standard_ProgramError::Raise("no more CurrentSection");
298 if (!PITLE->More()) Standard_ProgramError::Raise("no more CurrentSection");
299 return PITLE->Value();
302 //=======================================================================
303 //function : MakeEdgeAncestorMap
305 //=======================================================================
307 void TopOpeBRepBuild_HBuilder::MakeEdgeAncestorMap()
309 if(myMakeEdgeAncestorIsDone)
311 mySectEdgeDSEdges1.Clear();
312 mySectEdgeDSEdges2.Clear();
313 myDSEdgesDSFaces1.Clear();
314 myDSEdgesDSFaces2.Clear();
316 myMakeEdgeAncestorIsDone = Standard_True;
317 TopTools_MapOfShape MF, ME;
319 const TopOpeBRepDS_DataStructure& DS = DataStructure()->DS();
320 // Standard_Integer ns = DS.NbShapes(),is;
321 Standard_Integer ns = DS.NbShapes();
322 // Standard_Integer ei, fi, re, rf ,gi, ise;
323 Standard_Integer ei, fi, re, rf ,gi;
325 TopOpeBRepDS_DataMapIteratorOfDataMapOfShapeListOfShapeOn1State
326 it(myBuilder.mySplitON);
327 TopTools_ListIteratorOfListOfShape its;
328 for(;it.More(); it.Next()) {
329 const TopoDS_Shape& ShaSpl = it.Key();
330 ei = DS.Shape(ShaSpl);
331 re = DS.AncestorRank(ShaSpl);
333 TopOpeBRepDS_ListOfShapeOn1State& losos1s =
334 (*(TopOpeBRepDS_ListOfShapeOn1State*)&it.Value());
335 TopTools_ListOfShape& los = losos1s.ChangeListOnState();
338 for(; its.More(); its.Next()) {
339 TopoDS_Shape& SecEdg = its.Value();
340 if(!mySectEdgeDSEdges1.IsBound(SecEdg))
341 mySectEdgeDSEdges1.Bind(SecEdg, ei);
344 for(; its.More(); its.Next()) {
345 TopoDS_Shape& SecEdg = its.Value();
346 if(!mySectEdgeDSEdges2.IsBound(SecEdg))
347 mySectEdgeDSEdges2.Bind(SecEdg,ei);
351 // Standard_Boolean gb;
352 TopOpeBRepDS_Kind gk;
353 for (fi=1;fi<=ns;fi++) {
354 const TopoDS_Shape& fds = DS.Shape(fi);
357 if (fds.ShapeType() != TopAbs_FACE) continue;
358 TopOpeBRepDS_ListIteratorOfListOfInterference
359 it1(DS.ShapeInterferences(fds));
360 for (;it1.More();it1.Next()) {
361 Handle(TopOpeBRepDS_ShapeShapeInterference) SSI =
362 Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(it1.Value());
363 if (SSI.IsNull()) continue;
364 gk = SSI->GeometryType();
365 gi = SSI->Geometry();
366 if (gk != TopOpeBRepDS_EDGE) continue;
367 rf = DS.AncestorRank(fds);
369 // if (!MF.Contains(fds) ) {
372 if(!myDSEdgesDSFaces1.IsBound(gi)) {
373 TColStd_ListOfInteger thelist;
374 myDSEdgesDSFaces1.Bind(gi,thelist );
376 myDSEdgesDSFaces1.ChangeFind(gi).Append(fi);
379 if(!myDSEdgesDSFaces2.IsBound(gi)){
380 TColStd_ListOfInteger thelist1;
381 myDSEdgesDSFaces2.Bind(gi, thelist1);
383 myDSEdgesDSFaces2.ChangeFind(gi).Append(fi);
390 //=======================================================================
391 //function : GetDSEdgeFromSectEdge
393 //=======================================================================
394 Standard_Integer TopOpeBRepBuild_HBuilder::GetDSEdgeFromSectEdge(const TopoDS_Shape& E,const Standard_Integer rank)
396 if(!myMakeEdgeAncestorIsDone)
397 MakeEdgeAncestorMap();
399 Standard_Integer i = 0;
402 if(mySectEdgeDSEdges1.IsBound(E))
403 i = mySectEdgeDSEdges1.Find(E);
407 if(mySectEdgeDSEdges2.IsBound(E))
408 i = mySectEdgeDSEdges2.Find(E);
413 //=======================================================================
414 //function : GetDSFaceFromDSEdge
416 //=======================================================================
417 TColStd_ListOfInteger& TopOpeBRepBuild_HBuilder::GetDSFaceFromDSEdge
418 (const Standard_Integer indexEdg, const Standard_Integer rank)
420 if(!myMakeEdgeAncestorIsDone)
421 MakeEdgeAncestorMap();
424 if(myDSEdgesDSFaces1.IsBound(indexEdg)) {
425 TColStd_ListOfInteger& loi =
426 myDSEdgesDSFaces1.ChangeFind(indexEdg);
432 if(myDSEdgesDSFaces2.IsBound(indexEdg)) {
433 TColStd_ListOfInteger& loi =
434 myDSEdgesDSFaces2.ChangeFind(indexEdg);
439 return myEmptyIntegerList;
442 //=======================================================================
443 //function : MakeCurveAncestorMap
445 //=======================================================================
447 void TopOpeBRepBuild_HBuilder::MakeCurveAncestorMap()
449 if(myMakeCurveAncestorIsDone)
451 mySectEdgeDSCurve.Clear();
452 myMakeCurveAncestorIsDone = Standard_True;
454 // static const TopOpeBRepDS_DataStructure& DS = DataStructure()->DS();
455 const TopOpeBRepDS_DataStructure& DS = DataStructure()->DS(); // How to do static <--> const
457 const TopOpeBRepDS_DataStructure& DS = DataStructure()->DS();
459 TopTools_ListIteratorOfListOfShape itloe;
460 TopOpeBRepDS_CurveExplorer cex(DS,Standard_True);
461 // Standard_Integer ic, icm;
463 for (; cex.More(); cex.Next()) {
465 const TopTools_ListOfShape& LOS = myBuilder.myNewEdges.Find(ic);
466 itloe.Initialize(LOS);
467 for(;itloe.More();itloe.Next()) {
468 TopoDS_Shape& E = *((TopoDS_Shape*)(&itloe.Value()));
469 if(mySectEdgeDSCurve.IsBound(E)) {
471 cout<<"BRepAlgo_DSAccess::MakeEdgeAncestorFromCurve : program error"<<endl;
474 mySectEdgeDSCurve.Bind(E, ic);
479 //=======================================================================
480 //function : GetDSCurveFromSectEdge
482 //=======================================================================
484 Standard_Integer TopOpeBRepBuild_HBuilder::GetDSCurveFromSectEdge(const TopoDS_Shape& SectEdge)
486 Standard_Integer i = 0;
487 if(!myMakeCurveAncestorIsDone)
488 MakeCurveAncestorMap();
490 if(mySectEdgeDSCurve.IsBound(SectEdge)) {
491 i = mySectEdgeDSCurve.Find(SectEdge);
496 //=======================================================================
497 //function : GetDSFaceFromDSCurve
499 //=======================================================================
501 Standard_Integer TopOpeBRepBuild_HBuilder::GetDSFaceFromDSCurve(const Standard_Integer indexCur,const Standard_Integer rank)
503 Standard_Integer i = 0;
504 if(!myMakeCurveAncestorIsDone)
505 MakeCurveAncestorMap();
507 const TopOpeBRepDS_DataStructure& DS = DataStructure()->DS();
509 const TopOpeBRepDS_Curve& DSC = DS.Curve(indexCur);
510 const TopoDS_Shape& F1 = DSC.Shape1();
515 const TopOpeBRepDS_Curve& DSC = DS.Curve(indexCur);
516 const TopoDS_Shape& F2 = DSC.Shape2();
523 //=======================================================================
524 //function : GetDSPointFromNewVertex
526 //=======================================================================
528 Standard_Integer TopOpeBRepBuild_HBuilder::GetDSPointFromNewVertex(const TopoDS_Shape& NewVert)
530 if(!myMakePointAncestorIsDone) {
531 myMakePointAncestorIsDone = Standard_True;
532 TopOpeBRepDS_DataStructure& DS = DataStructure()->ChangeDS();
533 Standard_Integer i, NbPoint = DS.NbPoints();
534 for(i = 1; i <= NbPoint; i++) {
535 const TopoDS_Shape& Vertex = NewVertex(i);
537 myNewVertexDSPoint.Bind(Vertex, i);
541 Standard_Integer iPnt = 0;
542 if(myNewVertexDSPoint.IsBound(NewVert))
543 iPnt = myNewVertexDSPoint.Find(NewVert);
547 //=======================================================================
548 //function : EdgeCurveAncestors
550 //=======================================================================
552 Standard_Boolean TopOpeBRepBuild_HBuilder::EdgeCurveAncestors(const TopoDS_Shape& E,TopoDS_Shape& F1,TopoDS_Shape& F2,Standard_Integer& IC)
554 F1.Nullify(); F2.Nullify(); IC = 0;
556 const Handle(TopOpeBRepDS_HDataStructure)& HDS = myBuilder.DataStructure();
557 const TopOpeBRepDS_DataStructure& DS = HDS->DS();
559 // TopTools_ListIteratorOfListOfShape itloe;
560 IC = GetDSCurveFromSectEdge(E);
562 return Standard_False;
564 Standard_Integer iF1, iF2;
565 iF1 = GetDSFaceFromDSCurve(IC, 1);
566 iF2 = GetDSFaceFromDSCurve(IC, 2);
570 return Standard_True;
573 //=======================================================================
574 //function : EdgeSectionAncestors
576 //=======================================================================
578 Standard_Boolean TopOpeBRepBuild_HBuilder::EdgeSectionAncestors
579 (const TopoDS_Shape& E, TopTools_ListOfShape& LF1, TopTools_ListOfShape& LF2, TopTools_ListOfShape& LE1, TopTools_ListOfShape& LE2)
581 if (E.ShapeType() != TopAbs_EDGE) return Standard_False;
583 LF1.Clear(); LF2.Clear(); LE1.Clear(); LE2.Clear();
584 TColStd_ListOfInteger f1, f2;
585 f1.Clear(); f2.Clear();
586 Standard_Integer ie1, ie2, curr;
588 ie1 = GetDSEdgeFromSectEdge(E,1);
589 ie2 = GetDSEdgeFromSectEdge(E,2);
590 TColStd_ListIteratorOfListOfInteger it;
593 TColStd_MapOfInteger moi;
595 f1 = GetDSFaceFromDSEdge(ie1,1);
598 for(; it.More(); it.Next()) {
601 it.Initialize(GetDSFaceFromDSEdge(ie2,1));
602 for(; it.More(); it.Next()) {
604 if(!moi.Contains(curr)) {
609 f2 = GetDSFaceFromDSEdge(ie1,2);
612 for(; it.More(); it.Next()) {
615 it.Initialize(GetDSFaceFromDSEdge(ie2,2));
616 for(; it.More(); it.Next()) {
618 if(!moi.Contains(curr)) {
626 f1 = GetDSFaceFromDSEdge(ie1,1);
627 f2 = GetDSFaceFromDSEdge(ie1,2);
630 f1 = GetDSFaceFromDSEdge(ie2,1);
631 f2 = GetDSFaceFromDSEdge(ie2,2);
635 const TopOpeBRepDS_DataStructure& DS = myBuilder.DataStructure()->DS();
638 LE1.Append(DS.Shape(ie1));
640 LE2.Append(DS.Shape(ie2));
642 for(it.Initialize(f1); it.More(); it.Next()) {
644 LF1.Append(DS.Shape(curr));
646 for(it.Initialize(f2); it.More(); it.Next()) {
648 LF2.Append(DS.Shape(curr));
651 Standard_Boolean r = (!LF1.IsEmpty() && !LF2.IsEmpty());
652 r = r && (!LE1.IsEmpty() || !LE2.IsEmpty());
656 //=======================================================================
659 //=======================================================================
661 Standard_Integer TopOpeBRepBuild_HBuilder::IsKPart()
663 Standard_Integer kp = myBuilder.IsKPart();
667 //=======================================================================
668 //function : MergeKPart
670 //=======================================================================
672 void TopOpeBRepBuild_HBuilder::MergeKPart(const TopAbs_State TB1,const TopAbs_State TB2)
674 Standard_Integer kp = IsKPart();
675 if ( kp ) myBuilder.MergeKPart(TB1,TB2);
678 //=======================================================================
679 //function : ChangeBuilder
681 //=======================================================================
683 TopOpeBRepBuild_Builder& TopOpeBRepBuild_HBuilder::ChangeBuilder()