// File: TopOpeBRepBuild_Builder.cxx // Created: Mon Jun 14 11:48:36 1993 // Author: Jean Yves LEBEY // #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef DEB Standard_IMPORT Standard_Boolean TopOpeBRepBuild_GettraceCU(); Standard_IMPORT Standard_Boolean TopOpeBRepBuild_GettraceCUV(); Standard_IMPORT Standard_Boolean TopOpeBRepBuild_GettraceSPF(); Standard_IMPORT Standard_Boolean TopOpeBRepBuild_GettraceSPS(); Standard_IMPORT Standard_Boolean TopOpeBRepBuild_GetcontextSF2(); Standard_IMPORT Standard_Boolean TopOpeBRepBuild_GettraceSHEX(); Standard_EXPORT void debmarksplit(const Standard_Integer i) {cout<<"++ debmarksplit "< #include #include #include #include Standard_EXPORT TopOpeBRepBuild_Builder* GLOBAL_PBUILDER; //======================================================================= //function : TopOpeBRepBuild_Builder //purpose : //======================================================================= TopOpeBRepBuild_Builder::TopOpeBRepBuild_Builder(const TopOpeBRepDS_BuildTool& BT) : myBuildTool(BT), mySectionDone(Standard_False), myIsKPart(0), myClassifyDef(Standard_False), myClassifyVal(Standard_True), myProcessON(Standard_False) { GLOBAL_PBUILDER = this; InitSection(); } //modified by NIZHNY-MZV Sat May 6 10:04:49 2000 //======================================================================= //function : Destroy //purpose : virtual destructor //======================================================================= void TopOpeBRepBuild_Builder::Destroy() { } //======================================================================= //function : ChangeBuildTool //purpose : //======================================================================= TopOpeBRepDS_BuildTool& TopOpeBRepBuild_Builder::ChangeBuildTool() { return myBuildTool; } //======================================================================= //function : BuildTool //purpose : //======================================================================= const TopOpeBRepDS_BuildTool& TopOpeBRepBuild_Builder::BuildTool() const { return myBuildTool; } //======================================================================= //function : DataStructure //purpose : //======================================================================= Handle(TopOpeBRepDS_HDataStructure) TopOpeBRepBuild_Builder::DataStructure() const { return myDataStructure; } //======================================================================= //function : Perform //purpose : //======================================================================= void TopOpeBRepBuild_Builder::Perform(const Handle(TopOpeBRepDS_HDataStructure)& HDS) { #ifdef DEB GdumpSHASETreset(); #endif Clear(); myDataStructure = HDS; BuildVertices(HDS); SplitEvisoONperiodicF(); BuildEdges(HDS); BuildFaces(HDS); myIsKPart = 0; InitSection(); SplitSectionEdges(); TopOpeBRepDS_Filter F(HDS, &myShapeClassifier); F.ProcessFaceInterferences(mySplitON); TopOpeBRepDS_Reducer R(HDS); R.ProcessFaceInterferences(mySplitON); } // Perform //======================================================================= //function : Perform //purpose : //======================================================================= void TopOpeBRepBuild_Builder::Perform(const Handle(TopOpeBRepDS_HDataStructure)& HDS,const TopoDS_Shape& S1, const TopoDS_Shape& S2) { Perform(HDS); myShape1 = S1; myShape2 = S2; myIsKPart = FindIsKPart(); } // Perform //======================================================================= //function : AddIntersectionEdges //purpose : //======================================================================= void TopOpeBRepBuild_Builder::AddIntersectionEdges (TopoDS_Shape& aFace,const TopAbs_State ToBuild1,const Standard_Boolean RevOri1,TopOpeBRepBuild_ShapeSet& WES) const { TopoDS_Shape anEdge; TopOpeBRepDS_CurveIterator FCurves = myDataStructure->FaceCurves(aFace); for (; FCurves.More(); FCurves.Next()) { Standard_Integer iC = FCurves.Current(); #ifdef DEB Standard_Boolean tCU = TopOpeBRepBuild_GettraceCU(); Standard_Boolean NtCUV = !TopOpeBRepBuild_GettraceCUV(); if(tCU) {cout<Curve(iC).Dump(cout,iC,NtCUV);} #endif const TopTools_ListOfShape& LnewE = NewEdges(iC); for (TopTools_ListIteratorOfListOfShape Iti(LnewE); Iti.More(); Iti.Next()) { anEdge = Iti.Value(); TopAbs_Orientation ori = FCurves.Orientation(ToBuild1); TopAbs_Orientation newori = Orient(ori,RevOri1); if(newori == TopAbs_EXTERNAL) continue; myBuildTool.Orientation(anEdge,newori); const Handle(Geom2d_Curve)& PC = FCurves.PCurve(); myBuildTool.PCurve(aFace,anEdge,PC); WES.AddStartElement(anEdge); } } } //======================================================================= //function : Clear //purpose : //======================================================================= void TopOpeBRepBuild_Builder::Clear() { const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS(); TopOpeBRepDS_DataMapIteratorOfDataMapOfShapeListOfShapeOn1State it; for (it.Initialize(mySplitOUT); it.More(); it.Next()) { const TopoDS_Shape& e = it.Key(); if ( e.ShapeType() == TopAbs_EDGE ) { Standard_Boolean isse = BDS.IsSectionEdge(TopoDS::Edge(e)); if (!isse) mySplitOUT.ChangeFind(e).Clear(); } } for (it.Initialize(mySplitIN); it.More(); it.Next()) { const TopoDS_Shape& e = it.Key(); if ( e.ShapeType() == TopAbs_EDGE ) { Standard_Boolean isse = BDS.IsSectionEdge(TopoDS::Edge(e)); if (!isse) mySplitIN.ChangeFind(e).Clear(); } } for (it.Initialize(mySplitON); it.More(); it.Next()) { const TopoDS_Shape& e = it.Key(); if ( e.ShapeType() == TopAbs_EDGE ) { Standard_Boolean isse = BDS.IsSectionEdge(TopoDS::Edge(e)); if (!isse) mySplitON.ChangeFind(e).Clear(); } } myMergedOUT.Clear(); myMergedIN.Clear(); myMergedON.Clear(); } // Clear //======================================================================= //function : NewFaces //purpose : //======================================================================= const TopTools_ListOfShape& TopOpeBRepBuild_Builder::NewFaces(const Standard_Integer I) const { const TopTools_ListOfShape& L = myNewFaces->Array1().Value(I); return L; } // NewFaces //======================================================================= //function : ChangeNewFaces //purpose : private //======================================================================= TopTools_ListOfShape& TopOpeBRepBuild_Builder::ChangeNewFaces(const Standard_Integer I) { TopTools_ListOfShape& L = myNewFaces->ChangeArray1().ChangeValue(I); return L; } // ChangeNewFaces //======================================================================= //function : NewEdges //purpose : //======================================================================= const TopTools_ListOfShape& TopOpeBRepBuild_Builder::NewEdges(const Standard_Integer I) const { if ( myNewEdges.IsBound(I) ) { return myNewEdges.Find(I); } else { return myEmptyShapeList; } } // NewEdges //======================================================================= //function : ChangeNewEdges //purpose : private //======================================================================= TopTools_ListOfShape& TopOpeBRepBuild_Builder::ChangeNewEdges(const Standard_Integer I) { if ( ! myNewEdges.IsBound(I) ) { TopTools_ListOfShape thelist; myNewEdges.Bind(I, thelist); } TopTools_ListOfShape& L = myNewEdges.ChangeFind(I); return L; } // ChangeNewEdges //======================================================================= //function : NewVertex //purpose : //======================================================================= const TopoDS_Shape& TopOpeBRepBuild_Builder::NewVertex(const Standard_Integer I) const { const TopoDS_Shape& V = myNewVertices->Array1().Value(I); return V; } // NewVertex //======================================================================= //function : ChangeNewVertex //purpose : private //======================================================================= TopoDS_Shape& TopOpeBRepBuild_Builder::ChangeNewVertex(const Standard_Integer I) { TopoDS_Shape& V = myNewVertices->ChangeArray1().ChangeValue(I); return V; } // ChangeNewVertex //======================================================================= //function : ToSplit //purpose : private //======================================================================= Standard_Boolean TopOpeBRepBuild_Builder::ToSplit(const TopoDS_Shape& S,const TopAbs_State ToBuild) const { Standard_Boolean issplit = IsSplit(S,ToBuild); Standard_Boolean hasgeom = myDataStructure->HasGeometry(S); Standard_Boolean hassame = myDataStructure->HasSameDomain(S); Standard_Boolean tosplit = (!issplit) && (hasgeom || hassame); #ifdef DEB Standard_Integer iS; Standard_Boolean tSPS = GtraceSPS(S,iS); if (tSPS) { cout<<"tosplit "< = position of shape / shapes of list // shape S1 is kept // - if LS2 is empty // - if (pos2 == ToBuild1) //======================================================================= Standard_Boolean TopOpeBRepBuild_Builder::KeepShape(const TopoDS_Shape& S1,const TopTools_ListOfShape& LS2,const TopAbs_State ToBuild1) { Standard_Boolean keep = Standard_True; if ( ! LS2.IsEmpty() ) { TopAbs_State pos2 = ShapePosition(S1,LS2); if ( pos2 != ToBuild1 ) keep = Standard_False; } return keep; } //======================================================================= //function : TopType //purpose : return the type of upper subshape found in //======================================================================= TopAbs_ShapeEnum TopOpeBRepBuild_Builder::TopType(const TopoDS_Shape& S) { TopAbs_ShapeEnum t; TopOpeBRepTool_ShapeExplorer e; t = TopAbs_COMPOUND; e.Init(S,t); if (e.More()) return t; t = TopAbs_COMPSOLID; e.Init(S,t); if (e.More()) return t; t = TopAbs_SOLID; e.Init(S,t); if (e.More()) return t; t = TopAbs_SHELL; e.Init(S,t); if (e.More()) return t; t = TopAbs_FACE; e.Init(S,t); if (e.More()) return t; t = TopAbs_WIRE; e.Init(S,t); if (e.More()) return t; t = TopAbs_EDGE; e.Init(S,t); if (e.More()) return t; t = TopAbs_VERTEX; e.Init(S,t); if (e.More()) return t; return TopAbs_SHAPE; } //======================================================================= //function : Reverse //purpose : compute orientation reversibility according to build states //======================================================================= Standard_Boolean TopOpeBRepBuild_Builder::Reverse(const TopAbs_State ToBuild1,const TopAbs_State ToBuild2) { Standard_Boolean rev; if (ToBuild1 == TopAbs_IN && ToBuild2 == TopAbs_IN) rev = Standard_False; else rev = (ToBuild1 == TopAbs_IN); return rev; } //======================================================================= //function : Orient //purpose : reverse the orientation //======================================================================= TopAbs_Orientation TopOpeBRepBuild_Builder::Orient(const TopAbs_Orientation Ori,const Standard_Boolean Reverse) { #ifdef DEB TopAbs_Orientation result; #else TopAbs_Orientation result=TopAbs_FORWARD; #endif switch (Reverse) { case Standard_True : result = TopAbs::Complement(Ori); break; case Standard_False : result = Ori; break; } return result; } //======================================================================= //function : FindSameDomain //purpose : complete the lists L1,L2 with the shapes of the DS // having same domain : // L1 = shapes sharing the same domain of L2 shapes // L2 = shapes sharing the same domain of L1 shapes // (L1 contains a face) //======================================================================= void TopOpeBRepBuild_Builder::FindSameDomain(TopTools_ListOfShape& L1,TopTools_ListOfShape& L2) const { Standard_Integer i; Standard_Integer nl1 = L1.Extent(), nl2 = L2.Extent(); while ( nl1 > 0 || nl2 > 0 ) { TopTools_ListIteratorOfListOfShape it1(L1); for (i=1 ; i<=nl1; i++) { const TopoDS_Shape& S1 = it1.Value(); #ifdef DEB // Standard_Integer iS1 = myDataStructure->Shape(S1); // DEB #endif TopTools_ListIteratorOfListOfShape itsd(myDataStructure->SameDomain(S1)); for (; itsd.More(); itsd.Next() ) { const TopoDS_Shape& S2 = itsd.Value(); #ifdef DEB // Standard_Integer iS2 = myDataStructure->Shape(S2);// DEB #endif Standard_Boolean found = Contains(S2,L2); if ( ! found ) { L2.Prepend(S2); nl2++; } } it1.Next(); } nl1 = 0; TopTools_ListIteratorOfListOfShape it2(L2); for (i=1 ; i<=nl2; i++) { const TopoDS_Shape& S2 = it2.Value(); #ifdef DEB // Standard_Integer iS2 = myDataStructure->Shape(S2);// DEB #endif TopTools_ListIteratorOfListOfShape itsd(myDataStructure->SameDomain(S2)); for (; itsd.More(); itsd.Next() ) { const TopoDS_Shape& S1 = itsd.Value(); #ifdef DEB // Standard_Integer iS1 = myDataStructure->Shape(S1);// DEB #endif Standard_Boolean found = Contains(S1,L1); if ( ! found ) { L1.Prepend(S1); nl1++; } } it2.Next(); } nl2 = 0; } } //======================================================================= //function : FindSameDomainSameOrientation //purpose : //======================================================================= void TopOpeBRepBuild_Builder::FindSameDomainSameOrientation(TopTools_ListOfShape& L1, TopTools_ListOfShape& L2) const { FindSameDomain(L1,L2); TopTools_ListIteratorOfListOfShape it(L1); if ( !it.More() ) return; const TopoDS_Shape& sref = it.Value(); #ifdef DEB // Standard_Integer iref = myDataStructure->SameDomainReference(sref); #endif TopOpeBRepDS_Config oref = myDataStructure->SameDomainOrientation(sref); TopTools_ListOfShape LL1,LL2; for (it.Initialize(L1); it.More(); it.Next() ) { const TopoDS_Shape& s = it.Value(); TopOpeBRepDS_Config o = myDataStructure->SameDomainOrientation(s); if ( o == oref && !Contains(s,LL1) ) LL1.Append(s); else if ( o != oref && !Contains(s,LL2) ) LL2.Append(s); } for (it.Initialize(L2); it.More(); it.Next() ) { const TopoDS_Shape& s = it.Value(); TopOpeBRepDS_Config o = myDataStructure->SameDomainOrientation(s); if ( o == oref && !Contains(s,LL1) ) LL1.Append(s); else if ( o != oref && !Contains(s,LL2) ) LL2.Append(s); } L1 = LL1; L2 = LL2; } //======================================================================= //function : MapShapes //purpose : //======================================================================= void TopOpeBRepBuild_Builder::MapShapes(const TopoDS_Shape& S1,const TopoDS_Shape& S2) { Standard_Boolean S1null = S1.IsNull(); Standard_Boolean S2null = S2.IsNull(); ClearMaps(); if ( ! S1null ) TopExp::MapShapes(S1,myMAP1); if ( ! S2null ) TopExp::MapShapes(S2,myMAP2); } //======================================================================= //function : ClearMaps //purpose : //======================================================================= void TopOpeBRepBuild_Builder::ClearMaps() { myMAP1.Clear(); myMAP2.Clear(); } //======================================================================= //function : FindSameRank //purpose : //======================================================================= void TopOpeBRepBuild_Builder::FindSameRank(const TopTools_ListOfShape& L1,const Standard_Integer rank,TopTools_ListOfShape& L2) const { for ( TopTools_ListIteratorOfListOfShape it1(L1); it1.More(); it1.Next() ) { const TopoDS_Shape& s = it1.Value(); Standard_Integer r = ShapeRank(s); if ( r == rank && !Contains(s,L2) ) { L2.Append(s); } } } //======================================================================= //function : ShapeRank //purpose : //======================================================================= Standard_Integer TopOpeBRepBuild_Builder::ShapeRank(const TopoDS_Shape& s) const { Standard_Boolean isof1 = IsShapeOf(s,1); Standard_Boolean isof2 = IsShapeOf(s,2); Standard_Integer ancetre = (isof1 || isof2) ? ((isof1) ? 1 : 2) : 0; return ancetre; } //======================================================================= //function : IsShapeOf //purpose : //======================================================================= Standard_Boolean TopOpeBRepBuild_Builder::IsShapeOf(const TopoDS_Shape& s,const Standard_Integer i) const { Standard_Boolean b = Standard_False; if (i == 1) b = myMAP1.Contains(s); else if (i == 2) b = myMAP2.Contains(s); return b; } //======================================================================= //function : Contains //purpose : returns True if S is in the list L. //======================================================================= Standard_Boolean TopOpeBRepBuild_Builder::Contains(const TopoDS_Shape& S,const TopTools_ListOfShape& L) { for (TopTools_ListIteratorOfListOfShape it(L); it.More(); it.Next() ) { TopoDS_Shape& SL = it.Value(); Standard_Boolean issame = SL.IsSame(S); if ( issame ) return Standard_True; } return Standard_False; } //======================================================================= //function : Opec12 //purpose : //======================================================================= Standard_Boolean TopOpeBRepBuild_Builder::Opec12() const { Standard_Boolean b = (myState1 == TopAbs_OUT) && (myState2 == TopAbs_IN ); return b; } //======================================================================= //function : Opec21 //purpose : //======================================================================= Standard_Boolean TopOpeBRepBuild_Builder::Opec21() const { Standard_Boolean b = (myState1 == TopAbs_IN ) && (myState2 == TopAbs_OUT); return b; } //======================================================================= //function : Opecom //purpose : //======================================================================= Standard_Boolean TopOpeBRepBuild_Builder::Opecom() const { Standard_Boolean b = (myState1 == TopAbs_IN ) && (myState2 == TopAbs_IN ); return b; } //======================================================================= //function : Opefus //purpose : //======================================================================= Standard_Boolean TopOpeBRepBuild_Builder::Opefus() const { Standard_Boolean b = (myState1 == TopAbs_OUT) && (myState2 == TopAbs_OUT); return b; } //======================================================================= //function : MSplit //purpose : //======================================================================= const TopOpeBRepDS_DataMapOfShapeListOfShapeOn1State& TopOpeBRepBuild_Builder::MSplit(const TopAbs_State s) const { if (s == TopAbs_IN) return mySplitIN; else if (s == TopAbs_OUT) return mySplitOUT; else if (s == TopAbs_ON) return mySplitON; return mySplitIN; } //======================================================================= //function : ChangeMSplit //purpose : //======================================================================= TopOpeBRepDS_DataMapOfShapeListOfShapeOn1State& TopOpeBRepBuild_Builder::ChangeMSplit(const TopAbs_State s) { if (s == TopAbs_IN) return mySplitIN; else if (s == TopAbs_OUT) return mySplitOUT; else if (s == TopAbs_ON) return mySplitON; return mySplitIN; }