Integration of OCCT 6.5.0 from SVN
[occt.git] / src / TopOpeBRepBuild / TopOpeBRepBuild_SplitSolid.hxx
1  // File:       TopOpeBRepBuild_SplitSolid.hxx
2 // Created:     Tue Sep 12 16:27:50 1995
3 // Author:      Jean Yves LEBEY
4 //              <jyl@meteox>
5
6 #ifndef TopOpeBRepBuild_SplitSolid_INCLUDED
7 #define TopOpeBRepBuild_SplitSolid_INCLUDED
8
9 #include <TopOpeBRepBuild_ShellFaceSet.hxx>
10 #include <TopOpeBRepBuild_SolidBuilder.hxx>
11 #include <TopOpeBRepBuild_define.hxx>
12
13 #ifdef DEB
14 #define DEBSHASET(sarg,meth,shaset,str) TCollection_AsciiString sarg((meth));(sarg)=(sarg)+(shaset).DEBNumber()+(str);
15 Standard_EXPORT Standard_Boolean TopOpeBRepDS_GettraceSTRANGE();
16 Standard_EXPORT void debsplitf(const Standard_Integer i);
17 Standard_EXPORT void debspanc(const Standard_Integer i);
18 //Standard_IMPORT extern Standard_Integer GLOBAL_iexF;
19 Standard_IMPORT Standard_Integer GLOBAL_iexF;
20 #endif
21
22 //=======================================================================
23 //function : SplitSolid
24 //purpose  : 
25 //=======================================================================
26
27 void TopOpeBRepBuild_Builder::SplitSolid(const TopoDS_Shape& S1oriented,
28                                          const TopAbs_State ToBuild1,
29                                          const TopAbs_State ToBuild2)
30 {
31   //modified by IFV for treating shell
32   Standard_Boolean tosplit = Standard_False;
33   Standard_Boolean IsShell = (S1oriented.ShapeType() == TopAbs_SHELL);
34   if(IsShell) {
35     TopExp_Explorer ex;
36     ex.Init(S1oriented, TopAbs_FACE);
37     for (; ex.More(); ex.Next()) {
38       const TopoDS_Shape& sh = ex.Current();
39       tosplit = ToSplit(sh,ToBuild1);
40       if(tosplit) break;
41     }
42   }
43   else tosplit = ToSplit(S1oriented,ToBuild1);
44
45   if ( ! tosplit ) return;
46   // end IFV
47
48   Standard_Boolean RevOri1 = Reverse(ToBuild1,ToBuild2);
49   Standard_Boolean RevOri2 = Reverse(ToBuild2,ToBuild1);
50   Standard_Boolean ConnectTo1 = Standard_True;
51   Standard_Boolean ConnectTo2 = Standard_False;
52
53   // work on a FORWARD solid <S1forward>
54   TopoDS_Shape S1forward = S1oriented; 
55   myBuildTool.Orientation(S1forward,TopAbs_FORWARD);
56   
57   // build the list of solids to split : LS1, LS2
58   TopTools_ListOfShape LS1,LS2;
59   LS1.Append(S1forward);
60   FindSameDomain(LS1,LS2);
61   Standard_Integer n1 = LS1.Extent();
62   Standard_Integer n2 = LS2.Extent();
63   
64   if (!n2) RevOri1 = Standard_False;
65   if (!n1) RevOri2 = Standard_False;
66   
67   // Create a face set <FS> connected by edges
68   // -----------------------------------------
69   TopOpeBRepBuild_ShellFaceSet SFS;
70   
71 #ifdef DEB
72   Standard_Boolean tSPS = TopOpeBRepBuild_GettraceSPS();
73 //  Standard_Integer iSolid = myDataStructure->Shape(S1oriented);
74   if (tSPS) {
75     cout<<endl;
76     GdumpSHASTA(S1oriented,ToBuild1,"___ SplitSolid ");
77     GdumpSAMDOM(LS1, (char *) "1 : "); 
78     GdumpSAMDOM(LS2, (char *) "2 : ");
79   }
80   SFS.DEBNumber(GdumpSHASETindex());
81 #endif
82
83   STATIC_SOLIDINDEX = 1;
84   TopTools_ListIteratorOfListOfShape itLS1;
85   for (itLS1.Initialize(LS1); itLS1.More(); itLS1.Next()) {
86     TopoDS_Shape Scur = itLS1.Value();
87     FillSolid(Scur,ToBuild1,LS2,ToBuild2,SFS,RevOri1);
88   }
89   
90   STATIC_SOLIDINDEX = 2;
91   TopTools_ListIteratorOfListOfShape itLS2;
92   for (itLS2.Initialize(LS2); itLS2.More(); itLS2.Next()) {
93     TopoDS_Shape Scur = itLS2.Value();
94     FillSolid(Scur,ToBuild2,LS1,ToBuild1,SFS,RevOri2);
95   }
96   
97   // Add the intersection surfaces
98   // -----------------------------
99   if (myDataStructure->NbSurfaces() > 0) {
100     TopOpeBRepDS_SurfaceIterator SSurfaces = myDataStructure->SolidSurfaces(S1forward);
101     for (; SSurfaces.More(); SSurfaces.Next()) {
102       Standard_Integer iS = SSurfaces.Current();
103       const TopTools_ListOfShape& LnewF = NewFaces(iS);
104       for (TopTools_ListIteratorOfListOfShape Iti(LnewF); Iti.More(); Iti.Next()) {
105         TopoDS_Shape aFace = Iti.Value();
106         TopAbs_Orientation ori = SSurfaces.Orientation(ToBuild1);
107         myBuildTool.Orientation(aFace,ori);
108         
109 #ifdef DEB
110         if (tSPS){
111           DEBSHASET(ss,"--- SplitSolid ",SFS," AddElement SFS+ face ");  
112           GdumpSHA(aFace,(Standard_Address)ss.ToCString());
113           cout<<" ";TopAbs::Print(ToBuild1,cout)<<" : 1 face ";
114           TopAbs::Print(ori,cout); cout<<endl;
115         }
116 #endif
117         SFS.AddElement(aFace);
118       }
119     }
120   }
121
122   // Create a Solid Builder SOBU
123   // -------------------------
124   TopOpeBRepBuild_SolidBuilder SOBU(SFS);
125
126   // Build the new solids on S1
127   // --------------------------
128   TopTools_ListOfShape& SolidList = ChangeMerged(S1oriented,ToBuild1);
129   if(IsShell)
130     MakeShells(SOBU,SolidList);
131   else
132     MakeSolids(SOBU,SolidList);
133
134   // connect list of new solids <SolidList> as solids built on LS1 solids
135   // --------------------------------------------------------------------
136
137   for (itLS1.Initialize(LS1); itLS1.More(); itLS1.Next()) {
138     TopoDS_Shape Scur = itLS1.Value();
139     MarkSplit(Scur,ToBuild1);
140     TopTools_ListOfShape& SL = ChangeSplit(Scur,ToBuild1);
141     if ( ConnectTo1 ) SL = SolidList;
142
143   }
144   
145   // connect list of new solids <SolidList> as solids built on LS2 solids
146   // --------------------------------------------------------------------
147   for (itLS2.Initialize(LS2); itLS2.More(); itLS2.Next()) {
148     TopoDS_Shape Scur = itLS2.Value();
149     MarkSplit(Scur,ToBuild2);
150     TopTools_ListOfShape& SL = ChangeSplit(Scur,ToBuild2);
151     if ( ConnectTo2 ) SL = SolidList;
152   }
153
154 } // SplitSolid
155
156 //#ifndef TopOpeBRepBuild_SplitSolid_INCLUDED
157 #endif