1 // Created on: 1996-03-07
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <gp_Pnt.hxx>
19 #include <Standard_NoSuchObject.hxx>
20 #include <TCollection_AsciiString.hxx>
21 #include <TopoDS.hxx>
22 #include <TopoDS_Edge.hxx>
23 #include <TopoDS_Face.hxx>
24 #include <TopoDS_Shape.hxx>
25 #include <TopoDS_Vertex.hxx>
26 #include <TopOpeBRepBuild_Builder.hxx>
27 #include <TopOpeBRepBuild_define.hxx>
28 #include <TopOpeBRepBuild_EdgeBuilder.hxx>
29 #include <TopOpeBRepBuild_FaceBuilder.hxx>
30 #include <TopOpeBRepBuild_GTopo.hxx>
31 #include <TopOpeBRepBuild_HBuilder.hxx>
32 #include <TopOpeBRepBuild_PaveSet.hxx>
33 #include <TopOpeBRepBuild_ShapeSet.hxx>
34 #include <TopOpeBRepBuild_ShellFaceSet.hxx>
35 #include <TopOpeBRepBuild_SolidBuilder.hxx>
36 #include <TopOpeBRepBuild_WireEdgeSet.hxx>
37 #include <TopOpeBRepDS.hxx>
38 #include <TopOpeBRepDS_BuildTool.hxx>
39 #include <TopOpeBRepDS_CurveIterator.hxx>
40 #include <TopOpeBRepDS_EXPORT.hxx>
41 #include <TopOpeBRepDS_HDataStructure.hxx>
42 #include <TopOpeBRepDS_PointIterator.hxx>
43 #include <TopOpeBRepDS_SurfaceIterator.hxx>
44 #include <TopOpeBRepTool_2d.hxx>
45 #include <TopOpeBRepTool_EXPORT.hxx>
46 #include <TopOpeBRepTool_ShapeExplorer.hxx>
47
48 #ifdef OCCT_DEBUG
49 Standard_EXPORT void debfctwesmess(const Standard_Integer i,const TCollection_AsciiString& s = "");
50 Standard_EXPORT void debffwesON(const Standard_Integer i);
debffwesk(const Standard_Integer i)51 Standard_EXPORT void debffwesk(const Standard_Integer i) {std::cout<<"++ debffwesk "<<i<<std::endl;}
52 #endif
53
54 Standard_Boolean TopOpeBRepBuild_FUN_aresamegeom(const TopoDS_Shape& S1,const TopoDS_Shape& S2);
55
56 #define M_IN(st ) (st == TopAbs_IN)
57 #define M_OUT(st) (st == TopAbs_OUT)
58 #define M_FORWARD(st ) (st == TopAbs_FORWARD)
59 #define M_REVERSED(st) (st == TopAbs_REVERSED)
60 #define M_INTERNAL(st) (st == TopAbs_INTERNAL)
61 #define M_EXTERNAL(st) (st == TopAbs_EXTERNAL)
62
63 //=======================================================================
64 //function : GFillFacesWESK
65 //purpose :
66 //=======================================================================
GFillFacesWESK(const TopTools_ListOfShape & LS1,const TopTools_ListOfShape & LS2,const TopOpeBRepBuild_GTopo & G1,TopOpeBRepBuild_WireEdgeSet & WES,const Standard_Integer Kfill)67 void TopOpeBRepBuild_Builder::GFillFacesWESK(const TopTools_ListOfShape& LS1,const TopTools_ListOfShape& LS2,const TopOpeBRepBuild_GTopo& G1,TopOpeBRepBuild_WireEdgeSet& WES,const Standard_Integer Kfill)
68 {
69 if ( LS1.IsEmpty() ) return;
70 TopAbs_State TB1,TB2; G1.StatesON(TB1,TB2);
71
72 const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
73
74 const TopoDS_Shape& F1 = LS1.First();
75 myFaceReference = TopoDS::Face(F1);
76 #ifdef OCCT_DEBUG
77 Standard_Integer iF1 =
78 #endif
79 BDS.Shape(F1);
80 Standard_Integer iref = BDS.SameDomainRef(F1);
81 TopAbs_Orientation oref = BDS.Shape(iref).Orientation();
82
83 #ifdef OCCT_DEBUG
84 Standard_Boolean tSPS = GtraceSPS(F1,iF1);
85 if(tSPS) std::cout<<"\n%%%%%%%%%%%%% K = "<<Kfill<<" %%%%%%%%%%%%% ";
86 if(tSPS) GdumpSHASTA(iF1,TB1,WES,"GFillFacesWESK","myFaceReference");
87 if(tSPS) debffwesk(iF1);
88 #endif
89
90 TopAbs_State TB;
91 TopOpeBRepBuild_GTopo G;
92 TopTools_ListIteratorOfListOfShape it;
93 Standard_Boolean gistoreverse1;
94
95 G = G1;
96 gistoreverse1 = G.IsToReverse1();
97 TB = TB1;
98 it.Initialize(LS1);
99
100 #ifdef OCCT_DEBUG
101 if(tSPS){
102 std::cout<<"\n^^^^^^^^ GFillFacesWESK : traitement de 1/2";
103 TopAbs_State TB11,TB21; G.StatesON(TB11,TB21);
104 std::cout<<" TB = ";TopAbs::Print(TB,std::cout); std::cout<<" ";
105 std::cout<<"(TB1 = ";TopAbs::Print(TB11,std::cout);std::cout<<",";
106 std::cout<<" TB2 = ";TopAbs::Print(TB21,std::cout);std::cout<<")\n\n";
107 }
108 #endif
109
110 for(; it.More(); it.Next()) {
111 const TopoDS_Shape& S = it.Value(); Standard_Integer iS = myDataStructure->Shape(S);
112 Standard_Boolean tomerge = !IsMerged(S,TB);
113 if (!tomerge) continue;
114
115 // lors de l'insertion des composantes (edges splitees) de S dans le WES :
116 // - faces de meme orientation geometrique :
117 // la grille indique l'orientation des composantes
118 // - faces d'orientation geometrique != :
119 // les aretes de S sont exprimees dans une surface
120 // d'orientation opposee a la surface de la face de reference.
121 // Leur orientation dans la face resultat (reference) est le contraire
122 // de la grille.
123 // Modified by Sergey KHROMOV - Sat Apr 27 14:40:35 2002 Begin
124 // const TopoDS_Shape& Fref = WES.Face();
125 // const TopoDS_Shape& F = S;
126 // Standard_Boolean samegeom = ::TopOpeBRepBuild_FUN_aresamegeom(Fref,F);
127 // Standard_Boolean r = gistoreverse1;
128 // if ( !samegeom ) { r = !r; G.SetReverse(r); }
129
130 // Standard_Boolean rev = Standard_False;
131 // Modified by Sergey KHROMOV - Sat Apr 27 14:40:36 2002 End
132 TopAbs_Orientation oS = BDS.Shape(iS).Orientation();
133 TopOpeBRepDS_Config conf = BDS.SameDomainOri(S);
134 Standard_Boolean b1 = (conf == TopOpeBRepDS_DIFFORIENTED && (oS == oref));
135 Standard_Boolean b2 = (conf == TopOpeBRepDS_SAMEORIENTED && (oS != oref));
136 Standard_Boolean b = b1 || b2;
137 // Modified by Sergey KHROMOV - Sat Apr 27 14:40:01 2002 Begin
138 // if (b) {
139 // rev = Standard_True;
140 // G.SetReverse(rev);
141 // }
142 if (b)
143 G.SetReverse(!gistoreverse1);
144 // Modified by Sergey KHROMOV - Sat Apr 27 14:40:03 2002 End
145
146 if (Kfill == 1) {
147 GFillFaceWES(S,LS2,G,WES);
148 }
149 else if (Kfill == 2) {
150 #ifdef OCCT_DEBUG
151 if (tSPS) debfctwesmess(iF1);
152 #endif
153 GFillCurveTopologyWES(S,G,WES);
154 }
155 else if (Kfill == 3) {
156 #ifdef OCCT_DEBUG
157 if (tSPS) debffwesON(iF1);
158 #endif
159 GFillONPartsWES(S,G,LS2,WES);
160 }
161 else {
162 // error
163 }
164 } // it(LS1)
165
166
167 G = G1.CopyPermuted();
168 gistoreverse1 = G.IsToReverse1();
169 TB = TB2;
170 it.Initialize(LS2);
171
172 #ifdef OCCT_DEBUG
173 if(tSPS){
174 std::cout<<"\n^^^^^^^^ GFillFacesWESK : traitement de 2/1";
175 TopAbs_State TB12,TB22; G.StatesON(TB12,TB22);
176 std::cout<<" TB = ";TopAbs::Print(TB,std::cout); std::cout<<" ";
177 std::cout<<"(TB1 = ";TopAbs::Print(TB12,std::cout);std::cout<<",";
178 std::cout<<" TB2 = ";TopAbs::Print(TB22,std::cout);std::cout<<")\n\n";
179 }
180 #endif
181
182 for (; it.More(); it.Next()) {
183 const TopoDS_Shape& S = it.Value(); Standard_Integer iS = myDataStructure->Shape(S);
184 Standard_Boolean tomerge = !IsMerged(S,TB);
185 if (!tomerge) continue;
186
187 // Modified by Sergey KHROMOV - Sat Apr 27 14:38:33 2002 Begin
188 // const TopoDS_Shape& Fref = WES.Face();
189 // const TopoDS_Shape& F = S;
190 // Standard_Boolean samegeom = ::TopOpeBRepBuild_FUN_aresamegeom(Fref,F);
191 // Standard_Boolean r = gistoreverse1;
192 // if ( !samegeom ) { r = !r; G.SetReverse(r); }
193
194 // Standard_Boolean rev = Standard_False;
195 // Modified by Sergey KHROMOV - Sat Apr 27 14:38:30 2002 End
196 TopAbs_Orientation oS = BDS.Shape(iS).Orientation();
197 TopOpeBRepDS_Config conf = BDS.SameDomainOri(S);
198 Standard_Boolean b1 = (conf == TopOpeBRepDS_DIFFORIENTED && (oS == oref));
199 Standard_Boolean b2 = (conf == TopOpeBRepDS_SAMEORIENTED && (oS != oref));
200 Standard_Boolean b = b1 || b2;
201 // Modified by Sergey KHROMOV - Sat Apr 27 14:39:04 2002 Begin
202 // if (b) {
203 // rev = Standard_True;
204 // G.SetReverse(rev);
205 // }
206 if (b)
207 G.SetReverse(!gistoreverse1);
208 // Modified by Sergey KHROMOV - Sat Apr 27 14:39:08 2002 End
209
210 if (Kfill == 1) {
211 GFillFaceWES(S,LS1,G,WES);
212 }
213 else if (Kfill == 2) {
214 GFillCurveTopologyWES(S,G,WES);
215 }
216 else if (Kfill == 3) {
217 #ifdef OCCT_DEBUG
218 if(tSPS) debffwesON(iF1);
219 #endif
220 GFillONPartsWES(S,G,LS1,WES);
221 }
222 else {
223 }
224
225 } // it(LS2)
226
227 } // GFillFacesWESK
228