0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / TopOpeBRepBuild / TopOpeBRepBuild_SplitFace.hxx
CommitLineData
b311480e 1// Created on: 1995-09-12
2// Created by: Jean Yves LEBEY
3// Copyright (c) 1995-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22#ifndef _TopOpeBRepBuild_SplitFace_HeaderFile
23#define _TopOpeBRepBuild_SplitFace_HeaderFile
24
25#include <TopOpeBRepBuild_WireEdgeSet.hxx>
26#include <TopOpeBRepBuild_FaceBuilder.hxx>
27
28#ifdef DEB
29Standard_EXPORT void debspf(const Standard_Integer i) {cout<<"++ debspf"<<i<<endl;}
30#endif
31
32//=======================================================================
33//function : SplitFace
34//purpose :
35//=======================================================================
36
37void TopOpeBRepBuild_Builder::SplitFace(const TopoDS_Shape& Foriented,
38 const TopAbs_State ToBuild1,
39 const TopAbs_State ToBuild2)
40{
41#ifdef DEB
42 if(TopOpeBRepBuild_GetcontextSF2()){
43 SplitFace2(Foriented,ToBuild1,ToBuild2);
44 return;
45 }
46#endif
47 SplitFace1(Foriented,ToBuild1,ToBuild2);
48 return;
49}
50
51//=======================================================================
52//function : SplitFace1
53//purpose : tout dans le meme edge set
54//=======================================================================
55
56void TopOpeBRepBuild_Builder::SplitFace1(const TopoDS_Shape& Foriented,
57 const TopAbs_State ToBuild1,
58 const TopAbs_State ToBuild2)
59{
60 // process connect connect
61 // operation tobuild1 tobuild2 face F to 1 to 2
62 // --------- -------- -------- ------- ------- -------
63 // common IN IN yes yes yes
64 // fuse OUT OUT yes yes yes
65 // cut 1-2 OUT IN yes yes no
66 // cut 2-1 IN OUT yes yes no
67 //
68 Standard_Boolean tosplit = ToSplit(Foriented,ToBuild1);
69 if ( ! tosplit ) return;
70
71 Standard_Boolean RevOri1 = Reverse(ToBuild1,ToBuild2);
72 Standard_Boolean RevOri2 = Reverse(ToBuild2,ToBuild1);
73 Standard_Boolean ConnectTo1 = Standard_True;
74 Standard_Boolean ConnectTo2 = Standard_False;
75
76 // work on a FORWARD face <Fforward>
77 TopoDS_Shape Fforward = Foriented;
78 myBuildTool.Orientation(Fforward,TopAbs_FORWARD);
79
80 // build the list of faces to split : LF1, LF2
81 TopTools_ListOfShape LF1,LF2;
82 LF1.Append(Fforward);
83 FindSameDomain(LF1,LF2);
84 Standard_Integer n1 = LF1.Extent();
85 Standard_Integer n2 = LF2.Extent();
86
87 // SplitFace on a face having other same domained faces on the
88 // other shape : do not reverse orientation of faces in FillFace
89 if (!n2) RevOri1 = Standard_False;
90 if (!n1) RevOri2 = Standard_False;
91
92 // Create an edge set <WES> connected by vertices
93 // ----------------------------------------------
94 TopOpeBRepBuild_WireEdgeSet WES(Fforward,this);
95
96#ifdef DEB
97 Standard_Boolean tSPF=TopOpeBRepBuild_GettraceSPF();
98 Standard_Integer iFace=myDataStructure->Shape(Foriented);
99 if(tSPF){cout<<endl;GdumpSHASTA(Foriented,ToBuild1,"=== SplitFace ");}
100 if(tSPF){GdumpSAMDOM(LF1, (char *) "1 : ");GdumpSAMDOM(LF2, (char *) "2 : ");}
101 if(tSPF) debspf(iFace);
102#endif
103
104 TopTools_ListIteratorOfListOfShape itLF1,itLF2;
105
106 for (itLF1.Initialize(LF1); itLF1.More(); itLF1.Next()) {
107 const TopoDS_Shape& Fcur = itLF1.Value();
108// myDataStructure->Shape(Fcur);//DEB
109 FillFace(Fcur,ToBuild1,LF2,ToBuild2,WES,RevOri1);
110 }
111
112 for (itLF2.Initialize(LF2); itLF2.More(); itLF2.Next()) {
113 const TopoDS_Shape& Fcur = itLF2.Value();
114// myDataStructure->Shape(Fcur);//DEB
115 FillFace(Fcur,ToBuild2,LF1,ToBuild1,WES,RevOri2);
116 }
117
118 // Add the intersection edges to edge set WES
119 // -----------------------------------------
120 AddIntersectionEdges(Fforward,ToBuild1,RevOri1,WES);
121
122#ifdef DEB
123 Standard_Integer iF; Standard_Boolean tSPS = GtraceSPS(Fforward,iF);
124 if(tSPS) WES.DumpSS();
125#endif
126
127 // Create a Face Builder FBU
128 // ------------------------
129 TopOpeBRepBuild_FaceBuilder FBU;
130 FBU.InitFaceBuilder(WES,Fforward,Standard_False); //forceclass = False
131
132 // Build the new faces
133 // -------------------
134 TopTools_ListOfShape& FaceList = ChangeMerged(Fforward,ToBuild1);
135 MakeFaces(Fforward,FBU,FaceList);
136
137 // connect new faces as faces built <ToBuild1> on LF1 faces
138 // --------------------------------------------------------
139 for (itLF1.Initialize(LF1); itLF1.More(); itLF1.Next()) {
140 TopoDS_Shape Fcur = itLF1.Value();
141 MarkSplit(Fcur,ToBuild1);
142 TopTools_ListOfShape& FL = ChangeSplit(Fcur,ToBuild1);
143 if ( ConnectTo1 ) FL = FaceList;
144 }
145
146 // connect new faces as faces built <ToBuild2> on LF2 faces
147 // --------------------------------------------------------
148 for (itLF2.Initialize(LF2); itLF2.More(); itLF2.Next()) {
149 TopoDS_Shape Fcur = itLF2.Value();
150 MarkSplit(Fcur,ToBuild2);
151 TopTools_ListOfShape& FL = ChangeSplit(Fcur,ToBuild2);
152 if ( ConnectTo2 ) FL = FaceList;
153 }
154
155} // SplitFace1
156
157//=======================================================================
158//function : SplitFace2
159//purpose :
160//=======================================================================
161
162void TopOpeBRepBuild_Builder::SplitFace2(const TopoDS_Shape& Foriented,
163 const TopAbs_State ToBuild1,
164 const TopAbs_State ToBuild2)
165{
166 // process connect connect
167 // operation tobuild1 tobuild2 face F to 1 to 2
168 // --------- -------- -------- ------- ------- -------
169 // common IN IN yes yes yes
170 // fuse OUT OUT yes yes yes
171 // cut 1-2 OUT IN yes yes no
172 // cut 2-1 IN OUT yes yes no
173 //
174 Standard_Boolean tosplit = ToSplit(Foriented,ToBuild1);
175 if ( ! tosplit ) return;
176
177 Standard_Boolean RevOri1 = Reverse(ToBuild1,ToBuild2);
178 Standard_Boolean RevOri2 = Reverse(ToBuild2,ToBuild1);
179 Standard_Boolean ConnectTo1 = Standard_True;
180 Standard_Boolean ConnectTo2 = Standard_False;
181
182 // work on a FORWARD face <Fforward>
183 TopoDS_Shape Fforward = Foriented;
184 myBuildTool.Orientation(Fforward,TopAbs_FORWARD);
185
186 TopTools_ListOfShape LF1 ; //liste des faces de 1 samedomain
187 TopTools_ListOfShape LF2 ; //liste des faces de 2 samedomain
188 LF1.Append(Fforward);
189 FindSameDomain(LF1,LF2);
190 Standard_Integer n1 = LF1.Extent();
191 Standard_Integer n2 = LF2.Extent();
192
193#ifdef DEB
194 Standard_Boolean tSPF = TopOpeBRepBuild_GettraceSPF();
195// Standard_Integer iFace = myDataStructure->Shape(Foriented);
196 if (tSPF) {
197 cout<<endl;
198 GdumpSHASTA(Foriented,ToBuild1,"=== SplitFace ");
199 GdumpSAMDOM(LF1, (char *) "samedomain 1 : ");
200 GdumpSAMDOM(LF2, (char *) "samedomain 2 : ");
201 }
202#endif
203
204 // SplitFace on a face having other same domained faces on the
205 // other shape : do not reverse orientation of faces in FillFace
206 if (!n2) RevOri1 = Standard_False;
207 if (!n1) RevOri2 = Standard_False;
208
209 TopTools_ListOfShape LFSO; //liste des faces de 1,2 samedomainsameorientation
210 TopTools_ListOfShape LFOO; //liste des faces de 1,2 samedomainoppositeorient
211
212 // LFSO : faces des shapes 1 ou 2, de meme orientation que Fforward.
213 // LFOO : faces des shapes 1 ou 2, d'orientation contraire que Fforward.
214 LFSO.Append(Fforward);
215 FindSameDomainSameOrientation(LFSO,LFOO);
216
217 TopTools_ListOfShape LFSO1,LFOO1; // same domain, same orientation, et du shape de F
218 TopTools_ListOfShape LFSO2,LFOO2; // "" "",du shape autre que celui de F
219
220 // on construit les parties ToBuild1 de F
221 Standard_Integer rankF = ShapeRank(Foriented);
222 Standard_Integer rankX = (rankF) ? ((rankF == 1) ? 2 : 1) : 0;
223
224 FindSameRank(LFSO,rankF,LFSO1);
225 FindSameRank(LFOO,rankF,LFOO1);
226 FindSameRank(LFSO,rankX,LFSO2);
227 FindSameRank(LFOO,rankX,LFOO2);
228
229#ifdef DEB
230 if ( tSPF ) {
231 GdumpSAMDOM(LFSO1, (char *) "LFSO1 : ");
232 GdumpSAMDOM(LFOO1, (char *) "LFOO1 : ");
233 GdumpSAMDOM(LFSO2, (char *) "LFSO2 : ");
234 GdumpSAMDOM(LFOO2, (char *) "LFOO2 : ");
235 }
236#endif
237
238 TopAbs_State tob1 = ToBuild1;
239 TopAbs_State tob2 = ToBuild2;
240 TopAbs_State tob1comp = (ToBuild1 == TopAbs_IN) ? TopAbs_OUT : TopAbs_IN;
241 TopAbs_State tob2comp = (ToBuild2 == TopAbs_IN) ? TopAbs_OUT : TopAbs_IN;
242 TopTools_ListIteratorOfListOfShape itLF ;
243
244 // --------------------------------------------------------------------
245 // traitement des faces de meme orientation que Fforward dans WireEdgeSet WES1
246 // --------------------------------------------------------------------
247 TopOpeBRepBuild_WireEdgeSet WES1(Fforward,this);
248
249 // traitement des faces de 1 same domain, same orientation que F : LFSO1
250 for (itLF.Initialize(LFSO1); itLF.More(); itLF.Next()) {
251 const TopoDS_Shape& Fcur = itLF.Value();
252// myDataStructure->Shape(Fcur);//DEB
253 // les wires de Fcur sont a comparer avec les faces de 2
254 FillFace(Fcur,tob1,LF2,tob2,WES1,RevOri1);
255 }
256
257 // traitement des faces de 2 same domain, same orientation que F : LFSO2
258 for (itLF.Initialize(LFSO2); itLF.More(); itLF.Next()) {
259 const TopoDS_Shape& Fcur = itLF.Value();
260// myDataStructure->Shape(Fcur);//DEB
261 // les wires de Fcur sont a comparer avec les faces de 1
262 FillFace(Fcur,tob2,LF1,tob1,WES1,RevOri2);
263 }
264
265 // traitement des faces de 1 same domain, oppo orientation que F : LFOO1
266 for (itLF.Initialize(LFOO1); itLF.More(); itLF.Next()) {
267 const TopoDS_Shape& Fcur = itLF.Value();
268// myDataStructure->Shape(Fcur);//DEB
269 // les wires de Fcur sont a comparer avec les faces de 2
270 FillFace(Fcur,tob1comp,LF2,ToBuild2,WES1,!RevOri1);
271 }
272
273 // traitement des faces de 2 same domain, oppo orientation que F : LFOO2
274 for (itLF.Initialize(LFOO2); itLF.More(); itLF.Next()) {
275 const TopoDS_Shape& Fcur = itLF.Value();
276// myDataStructure->Shape(Fcur);//DEB
277 // les wires de Fcur sont a comparer avec les faces de 1
278 FillFace(Fcur,tob2comp,LF1,ToBuild1,WES1,!RevOri2);
279 }
280
281 // Add the intersection edges to edge set WES1
282 // ------------------------------------------
283 AddIntersectionEdges(Fforward,ToBuild1,RevOri1,WES1);
284
285 // Create a Face Builder FBU1
286 // ------------------------
287 TopOpeBRepBuild_FaceBuilder FBU1(WES1,Fforward);
288
289 // Build the new faces
290 // -------------------
291 TopTools_ListOfShape& FaceList1 = ChangeMerged(Fforward,ToBuild1);
292 MakeFaces(Fforward,FBU1,FaceList1);
293
294 // connect new faces as faces built <ToBuild1> on LF1 faces
295 // --------------------------------------------------------
296 for (itLF.Initialize(LF1); itLF.More(); itLF.Next()) {
297 TopoDS_Shape Fcur = itLF.Value();
298 MarkSplit(Fcur,ToBuild1);
299 TopTools_ListOfShape& FL = ChangeSplit(Fcur,ToBuild1);
300 if ( ConnectTo1 ) FL = FaceList1;
301 }
302
303 // --------------------------------------------------------------------
304 // traitement des faces de meme orientation que Fforward dans WireEdgeSet WES2
305 // --------------------------------------------------------------------
306 TopOpeBRepBuild_WireEdgeSet WES2(Fforward,this);
307
308 // traitement des faces de 1 same domain, same orientation que F : LFSO1
309 for (itLF.Initialize(LFSO1); itLF.More(); itLF.Next()) {
310 const TopoDS_Shape& Fcur = itLF.Value();
311// myDataStructure->Shape(Fcur);//DEB
312 // les wires de Fcur sont a comparer avec les faces de 2
313 FillFace(Fcur,tob1comp,LF2,tob2,WES2,!RevOri1);
314 }
315
316 // traitement des faces de 2 same domain, same orientation que F : LFSO2
317 for (itLF.Initialize(LFSO2); itLF.More(); itLF.Next()) {
318 const TopoDS_Shape& Fcur = itLF.Value();
319// myDataStructure->Shape(Fcur);//DEB
320 // les wires de Fcur sont a comparer avec les faces de 1
321 FillFace(Fcur,tob2comp,LF1,tob1,WES2,!RevOri2);
322 }
323
324 // traitement des faces de 1 same domain, oppo orientation que F : LFOO1
325 for (itLF.Initialize(LFOO1); itLF.More(); itLF.Next()) {
326 const TopoDS_Shape& Fcur = itLF.Value();
327// myDataStructure->Shape(Fcur);//DEB
328 // les wires de Fcur sont a comparer avec les faces de 2
329 FillFace(Fcur,tob1,LF2,ToBuild2,WES2,RevOri1);
330 }
331
332 // traitement des faces de 2 same domain, oppo orientation que F : LFOO2
333 for (itLF.Initialize(LFOO2); itLF.More(); itLF.Next()) {
334 const TopoDS_Shape& Fcur = itLF.Value();
335// myDataStructure->Shape(Fcur);//DEB
336 // les wires de Fcur sont a comparer avec les faces de 1
337 FillFace(Fcur,tob2,LF1,ToBuild1,WES2,RevOri2);
338 }
339
340 // Add the intersection edges to edge set WES2
341 // ------------------------------------------
342 AddIntersectionEdges(Fforward,ToBuild2,RevOri2,WES2);
343
344 // Create a Face Builder FBU2
345 // -------------------------
346 TopOpeBRepBuild_FaceBuilder FBU2(WES2,Fforward);
347
348 // Build the new faces
349 // -------------------
350 TopTools_ListOfShape& FaceList2 = ChangeMerged(Fforward,ToBuild2);
351 MakeFaces(Fforward,FBU2,FaceList2);
352
353 // connect new faces as faces built <ToBuild2> on LF2 faces
354 // --------------------------------------------------------
355 for (itLF.Initialize(LF2); itLF.More(); itLF.Next()) {
356 TopoDS_Shape Fcur = itLF.Value();
357 MarkSplit(Fcur,ToBuild2);
358 TopTools_ListOfShape& FL = ChangeSplit(Fcur,ToBuild2);
359 if ( ConnectTo2 ) FL = FaceList2;
360 }
361
362} // SplitFace2
363
364
365#if 0
366//=======================================================================
367//function : SplitFaceOK
368//purpose : tout dans le meme edge set
369//=======================================================================
370
371void TopOpeBRepBuild_Builder::SplitFaceOK(const TopoDS_Shape& Foriented,
372 const TopAbs_State ToBuild1,
373 const TopAbs_State ToBuild2)
374{
375 // process connect connect
376 // operation tobuild1 tobuild2 face F to 1 to 2
377 // --------- -------- -------- ------- ------- -------
378 // common IN IN yes yes yes
379 // fuse OUT OUT yes yes yes
380 // cut 1-2 OUT IN yes yes no
381 // cut 2-1 IN OUT yes yes no
382 //
383 Standard_Boolean tosplit = ToSplit(Foriented,ToBuild1);
384 if ( ! tosplit ) return;
385
386 Standard_Boolean RevOri1 = Reverse(ToBuild1,ToBuild2);
387 Standard_Boolean RevOri2 = Reverse(ToBuild2,ToBuild1);
388 Standard_Boolean ConnectTo1 = Standard_True;
389 Standard_Boolean ConnectTo2 = Standard_False;
390
391 // work on a FORWARD face <Fforward>
392 TopoDS_Shape Fforward = Foriented;
393 myBuildTool.Orientation(Fforward,TopAbs_FORWARD);
394
395 // build the list of faces to split : LF1, LF2
396 TopTools_ListOfShape LF1,LF2;
397 LF1.Append(Fforward);
398 FindSameDomain(LF1,LF2);
399 Standard_Integer n1 = LF1.Extent();
400 Standard_Integer n2 = LF2.Extent();
401
402 // SplitFace on a face having other same domained faces on the
403 // other shape : do not reverse orientation of faces in FillFace
404 if (!n2) RevOri1 = Standard_False;
405 if (!n1) RevOri2 = Standard_False;
406
407 // Create an edge set <WES> connected by vertices
408 // ---------------------------------------------
409 TopOpeBRepBuild_WireEdgeSet WES(Fforward,this);
410
411#ifdef DEB
412 Standard_Boolean tSPF = TopOpeBRepBuild_GettraceSPF();
413 Standard_Integer iFace = myDataStructure->Shape(Foriented);
414 if(tSPF){cout<<endl;GdumpSHASTA(Foriented,ToBuild1,"=== SplitFaceOK ");}
415 if(tSPF){GdumpSAMDOM(LF1,"1 : ");GdumpSAMDOM(LF2,"2 : ");}
416#endif
417
418 TopTools_ListIteratorOfListOfShape itLF1,itLF2;
419
420 for (itLF1.Initialize(LF1); itLF1.More(); itLF1.Next()) {
421 const TopoDS_Shape& Fcur = itLF1.Value();
422 Standard_Integer icur = myDataStructure->Shape(Fcur);//DEB
423 FillFace(Fcur,ToBuild1,LF2,ToBuild2,WES,RevOri1);
424 }
425
426 for (itLF2.Initialize(LF2); itLF2.More(); itLF2.Next()) {
427 const TopoDS_Shape& Fcur = itLF2.Value();
428 Standard_Integer icur = myDataStructure->Shape(Fcur);//DEB
429 FillFace(Fcur,ToBuild2,LF1,ToBuild1,WES,RevOri2);
430 }
431
432 // Add the intersection edges to edge set WES
433 // -----------------------------------------
434 AddIntersectionEdges(Fforward,ToBuild1,RevOri1,WES);
435
436 // Create a Face Builder FBU
437 // ------------------------
438 TopOpeBRepBuild_FaceBuilder FBU(WES,Fforward);
439
440 // Build the new faces
441 // -------------------
442 TopTools_ListOfShape& FaceList = ChangeMerged(Fforward,ToBuild1);
443 MakeFaces(Fforward,FBU,FaceList);
444
445 // connect new faces as faces built <ToBuild1> on LF1 faces
446 // --------------------------------------------------------
447 for (itLF1.Initialize(LF1); itLF1.More(); itLF1.Next()) {
448 TopoDS_Shape Fcur = itLF1.Value();
449 MarkSplit(Fcur,ToBuild1);
450 TopTools_ListOfShape& FL = ChangeSplit(Fcur,ToBuild1);
451 if ( ConnectTo1 ) FL = FaceList;
452 }
453
454 // connect new faces as faces built <ToBuild2> on LF2 faces
455 // --------------------------------------------------------
456 for (itLF2.Initialize(LF2); itLF2.More(); itLF2.Next()) {
457 TopoDS_Shape Fcur = itLF2.Value();
458 MarkSplit(Fcur,ToBuild2);
459 TopTools_ListOfShape& FL = ChangeSplit(Fcur,ToBuild2);
460 if ( ConnectTo2 ) FL = FaceList;
461 }
462
463} // SplitFaceOK
464
465// #if 0
466#endif
467
468//#ifndef _TopOpeBRepBuild_SplitFace_HeaderFile
469#endif