Salome HOME
174c523797bf249f171061567ab996eaf7b47f2a
[modules/geom.git] / src / NMTTools / NMTTools_PaveFiller_8.cxx
1 // File:        NMTTools_PaveFiller_8.cxx
2 // Created:     Fri Dec 19 11:15:53 2003
3 // Author:      Peter KURNEV
4 //              <pkv@irinox>
5
6
7 #include <NMTTools_PaveFiller.ixx>
8
9 #include <TColStd_ListOfInteger.hxx>
10 #include <TColStd_ListIteratorOfListOfInteger.hxx>
11
12 #include <BooleanOperations_ShapesDataStructure.hxx>
13 #include <BooleanOperations_OnceExplorer.hxx>
14
15 #include <BOPTools_PaveBlock.hxx>
16 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
17 #include <BOPTools_ListOfPaveBlock.hxx>
18
19 #include <NMTDS_ShapesDataStructure.hxx>
20
21 #include <NMTTools_ListOfCommonBlock.hxx>
22 #include <NMTTools_ListIteratorOfListOfCommonBlock.hxx>
23 #include <NMTTools_CommonBlock.hxx>
24 #include <NMTTools_CommonBlockAPI.hxx>
25
26 //=======================================================================
27 // function: RealPaveBlock
28 // purpose:
29 //=======================================================================
30   const BOPTools_PaveBlock& NMTTools_PaveFiller::RealPaveBlock(const BOPTools_PaveBlock& aPB)
31 {
32   Standard_Integer nE;
33   //
34   nE=aPB.OriginalEdge();
35   const NMTTools_ListOfCommonBlock& aLCBE=myCommonBlockPool(myDS->RefEdge(nE));
36   NMTTools_CommonBlockAPI aCBAPI(aLCBE);
37   if (aCBAPI.IsCommonBlock(aPB)) {
38     NMTTools_CommonBlock& aCB=aCBAPI.CommonBlock(aPB);
39     const BOPTools_PaveBlock& aPBx=aCB.PaveBlock1();
40     return aPBx;
41   }
42   return aPB;
43 }
44 //=======================================================================
45 // function: CommonBlocksFace
46 // purpose:
47 //=======================================================================
48   Standard_Integer NMTTools_PaveFiller::CommonBlocksFace(const Standard_Integer nF,
49                                                          NMTTools_ListOfCommonBlock& aLCB)
50 {
51   Standard_Integer nE;
52   TopAbs_ShapeEnum aT;
53   NMTTools_ListIteratorOfListOfCommonBlock anIt;
54   //
55   aT=myDS->GetShapeType(nF);
56   //
57   if (aT!=TopAbs_FACE) {
58     return 1; // Type mismatch
59   }
60   //
61   BooleanOperations_ShapesDataStructure *pDS=myDS;
62   BooleanOperations_OnceExplorer aExp(*pDS);
63   //
64   aExp.Init(nF, TopAbs_EDGE);
65   for (; aExp.More(); aExp.Next()) {
66     nE=aExp.Current();
67     const NMTTools_ListOfCommonBlock& aLCBE=myCommonBlockPool(myDS->RefEdge(nE));
68     anIt.Initialize(aLCBE);
69     for (; anIt.More(); anIt.Next()) {
70       const NMTTools_CommonBlock& aCBE=anIt.Value();
71       aLCB.Append(aCBE);
72     }
73   }
74   return 0; //Ok
75 }
76 //
77 // 1 RealSplits
78 //
79 //
80 //=======================================================================
81 // function: RealSplitsFace
82 // purpose:
83 //=======================================================================
84   void NMTTools_PaveFiller::RealSplitsFace(const Standard_Integer nF,
85                                            BOPTools_ListOfPaveBlock& aLPB)
86 {
87   Standard_Integer nE;
88   BOPTools_ListIteratorOfListOfPaveBlock anIt;
89   //
90   BooleanOperations_ShapesDataStructure *pDS=myDS;
91   BooleanOperations_OnceExplorer aExp(*pDS);
92   //
93   aExp.Init(nF, TopAbs_EDGE);
94   for (; aExp.More(); aExp.Next()) {
95     nE=aExp.Current();
96     const BOPTools_ListOfPaveBlock& aLPBE=mySplitShapesPool(myDS->RefEdge(nE));
97     anIt.Initialize(aLPBE);
98     for (; anIt.More(); anIt.Next()) {
99       const BOPTools_PaveBlock& aPB=anIt.Value();
100       const BOPTools_PaveBlock& aPBR=RealPaveBlock(aPB);
101       aLPB.Append(aPBR);
102     }
103   }
104 }
105 //=======================================================================
106 // function: HasRealSplitsInOnFace
107 // purpose:
108 //=======================================================================
109   Standard_Boolean NMTTools_PaveFiller::HasRealSplitsInOnFace(const Standard_Integer nF1,
110                                                               const Standard_Integer nF2)
111 {
112   Standard_Boolean bFlag;
113   BOPTools_ListOfPaveBlock aLPB;
114   //
115   RealSplitsInFace(0, nF1, nF2, aLPB);
116   //
117   bFlag=!aLPB.IsEmpty();
118   if (bFlag) {
119     return bFlag;
120   }
121   //
122   RealSplitsInFace(0, nF1, nF2, aLPB);
123   //
124   bFlag=!aLPB.IsEmpty();
125   return bFlag;
126 }
127 //=======================================================================
128 // function: RealSplitsInFace
129 // purpose:
130 //=======================================================================
131   void NMTTools_PaveFiller::RealSplitsInFace(const Standard_Integer ,//for overriding
132                                              const Standard_Integer nF1,
133                                              const Standard_Integer nF2,
134                                              BOPTools_ListOfPaveBlock& aLPB)
135 {
136   Standard_Integer nE1;
137   //
138   BooleanOperations_ShapesDataStructure *pDS=myDS;
139   BooleanOperations_OnceExplorer aExp(*pDS);
140   aExp.Init(nF1, TopAbs_EDGE);
141   for (; aExp.More(); aExp.Next()) {
142     nE1=aExp.Current();
143     RealSplitsInFace (nE1, nF2, aLPB);
144   }
145 }
146 //=======================================================================
147 // function: RealSplitsInFace
148 // purpose:
149 //=======================================================================
150   void NMTTools_PaveFiller::RealSplitsInFace(const Standard_Integer nE1,
151                                              const Standard_Integer nF2,
152                                              BOPTools_ListOfPaveBlock& aLPB)
153 {
154   Standard_Integer nF1;
155   //
156   TColStd_ListIteratorOfListOfInteger anItLFCB;
157   NMTTools_ListIteratorOfListOfCommonBlock anItCB;
158   //
159   const NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(nE1));
160   //
161   anItCB.Initialize(aLCB);
162   for (; anItCB.More(); anItCB.Next()) {
163     NMTTools_CommonBlock& aCB=anItCB.Value();
164     const BOPTools_PaveBlock& aPB1=aCB.PaveBlock1(nE1);
165     const BOPTools_PaveBlock& aPB1R=RealPaveBlock(aPB1);
166
167     const TColStd_ListOfInteger& aLFCB=aCB.Faces();
168     anItLFCB.Initialize(aLFCB);
169     for (; anItLFCB.More(); anItLFCB.Next()) {
170       nF1=anItLFCB.Value();
171       if (nF1==nF2) {
172         aLPB.Append(aPB1R);
173       }
174     }
175   }
176 }
177 //=======================================================================
178 // function: RealSplitsOnEdge
179 // purpose:
180 //=======================================================================
181   void NMTTools_PaveFiller::RealSplitsOnEdge(const Standard_Integer nE1,
182                                              const Standard_Integer nE2,
183                                              BOPTools_ListOfPaveBlock& aLPB)
184 {
185   Standard_Integer nE;
186   //
187   BOPTools_ListIteratorOfListOfPaveBlock anIt;
188   NMTTools_ListIteratorOfListOfCommonBlock anItCB;
189   //
190   const NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(nE1));
191
192   anItCB.Initialize(aLCB);
193   for (; anItCB.More(); anItCB.Next()) {
194     NMTTools_CommonBlock& aCB=anItCB.Value();
195     const BOPTools_PaveBlock& aPB1=aCB.PaveBlock1(nE1);
196     const BOPTools_PaveBlock& aPB1R=RealPaveBlock(aPB1);
197     //
198     const BOPTools_ListOfPaveBlock& aLPBx=aCB.PaveBlocks();
199     anIt.Initialize(aLPBx);
200     for (; anIt.More(); anIt.Next()) {
201       const BOPTools_PaveBlock& aPB2=anIt.Value();
202       nE=aPB2.OriginalEdge();
203       if (nE==nE2) {
204         aLPB.Append(aPB1R);
205       }
206     }
207   }
208 }
209 //=======================================================================
210 // function: RealSplitsOnFace
211 // purpose:
212 //=======================================================================
213   void NMTTools_PaveFiller::RealSplitsOnFace(const Standard_Integer nE1,
214                                              const Standard_Integer nF2,
215                                              BOPTools_ListOfPaveBlock& aLPB)
216 {
217   Standard_Integer nE2;
218   //
219   BooleanOperations_ShapesDataStructure *pDS=myDS;
220   BooleanOperations_OnceExplorer aExp(*pDS);
221   aExp.Init(nF2, TopAbs_EDGE);
222   for (; aExp.More(); aExp.Next()) {
223     nE2=aExp.Current();
224     RealSplitsOnEdge(nE1, nE2, aLPB);
225   }
226 }
227 //=======================================================================
228 // function: RealSplitsOnFace
229 // purpose:
230 //=======================================================================
231   void NMTTools_PaveFiller::RealSplitsOnFace(const Standard_Integer ,//for overriding
232                                              const Standard_Integer nF1,
233                                              const Standard_Integer nF2,
234                                              BOPTools_ListOfPaveBlock& aLPB)
235 {
236   Standard_Integer nE1;
237   //
238   BooleanOperations_ShapesDataStructure *pDS=myDS;
239   BooleanOperations_OnceExplorer aExp(*myDS);
240   aExp.Init(nF1, TopAbs_EDGE);
241   for (; aExp.More(); aExp.Next()) {
242     nE1=aExp.Current();
243     RealSplitsOnFace(nE1, nF2, aLPB);
244   }
245 }
246
247 // 2 SimpleSplits
248 //=======================================================================
249 // function: SplitsFace
250 // purpose:
251 //=======================================================================
252   Standard_Integer NMTTools_PaveFiller::SplitsFace(const Standard_Integer nF,
253                                                    BOPTools_ListOfPaveBlock& aLPB)
254 {
255   Standard_Integer nE;
256   TopAbs_ShapeEnum aT;
257   BOPTools_ListIteratorOfListOfPaveBlock anIt;
258   //
259   aT=myDS->GetShapeType(nF);
260   //
261   if (aT!=TopAbs_FACE) {
262     return 1; // Type mismatch
263   }
264   //
265   BooleanOperations_ShapesDataStructure *pDS=myDS;
266   BooleanOperations_OnceExplorer aExp(*pDS);
267   //
268   aExp.Init(nF, TopAbs_EDGE);
269   for (; aExp.More(); aExp.Next()) {
270     nE=aExp.Current();
271     const BOPTools_ListOfPaveBlock& aLPBE=mySplitShapesPool(myDS->RefEdge(nE));
272     anIt.Initialize(aLPBE);
273     for (; anIt.More(); anIt.Next()) {
274       const BOPTools_PaveBlock& aPBE=anIt.Value();
275       aLPB.Append(aPBE);
276     }
277   }
278   return 0; //Ok
279 }
280
281 //=======================================================================
282 // function: SplitsInFace
283 // purpose: splits of edges from nF1 in nF2
284 //=======================================================================
285   Standard_Integer NMTTools_PaveFiller::SplitsInFace(const Standard_Integer ,//for overriding
286                                                      const Standard_Integer nF1,
287                                                      const Standard_Integer nF2,
288                                                      BOPTools_ListOfPaveBlock& aLPB)
289 {
290   Standard_Integer nE1;
291   TopAbs_ShapeEnum aT1, aT2;
292
293   aT1=myDS->GetShapeType(nF1);
294   aT2=myDS->GetShapeType(nF2);
295
296   if (aT1!=TopAbs_FACE || aT2!=TopAbs_FACE) {
297     return 1; // Type mismatch
298   }
299   BooleanOperations_ShapesDataStructure *pDS=myDS;
300   BooleanOperations_OnceExplorer aExp(*pDS);
301   aExp.Init(nF1, TopAbs_EDGE);
302   for (; aExp.More(); aExp.Next()) {
303     nE1=aExp.Current();
304     SplitsInFace (nE1, nF2, aLPB);
305   }
306   return 0; //Ok
307 }
308 //=======================================================================
309 // function: SplitsInFace
310 // purpose: splits of edge nE1 in aFace2
311 //=======================================================================
312   Standard_Integer NMTTools_PaveFiller::SplitsInFace(const Standard_Integer nE1,
313                                                      const Standard_Integer nF2,
314                                                      BOPTools_ListOfPaveBlock& aLPB)
315 {
316   Standard_Integer nF1;
317   TopAbs_ShapeEnum aT1, aT2;
318
319   aT1=myDS->GetShapeType(nE1);
320   aT2=myDS->GetShapeType(nF2);
321
322   if (aT1!=TopAbs_EDGE || aT2!=TopAbs_FACE) {
323     return 1; // Type mismatch
324   }
325   //
326   TColStd_ListIteratorOfListOfInteger anItLFCB;
327   NMTTools_ListIteratorOfListOfCommonBlock anItCB;
328   //
329   const NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(nE1));
330   //
331   anItCB.Initialize(aLCB);
332   for (; anItCB.More(); anItCB.Next()) {
333     NMTTools_CommonBlock& aCB=anItCB.Value();
334     const BOPTools_PaveBlock& aPB1=aCB.PaveBlock1(nE1);
335
336     const TColStd_ListOfInteger& aLFCB=aCB.Faces();
337     anItLFCB.Initialize(aLFCB);
338     for (; anItLFCB.More(); anItLFCB.Next()) {
339       nF1=anItLFCB.Value();
340       if (nF1==nF2) {
341         aLPB.Append(aPB1);
342       }
343     }
344   }
345   return 0; //Ok
346 }
347 //=======================================================================
348 // function: SplitsOnEdge
349 // purpose:  splits of edge nE1 on nE2
350 //=======================================================================
351   Standard_Integer NMTTools_PaveFiller::SplitsOnEdge(const Standard_Integer nE1,
352                                                      const Standard_Integer nE2,
353                                                      BOPTools_ListOfPaveBlock& aLPB)
354 {
355   Standard_Integer nE;
356   TopAbs_ShapeEnum aT1, aT2;
357
358   aT1=myDS->GetShapeType(nE1);
359   aT2=myDS->GetShapeType(nE2);
360
361   if (aT1!=TopAbs_EDGE || aT2!=TopAbs_EDGE) {
362     return 1; // Type mismatch
363   }
364   //
365   BOPTools_ListIteratorOfListOfPaveBlock anIt;
366   NMTTools_ListIteratorOfListOfCommonBlock anItCB;
367   //
368   const NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(nE1));
369
370   anItCB.Initialize(aLCB);
371   for (; anItCB.More(); anItCB.Next()) {
372     NMTTools_CommonBlock& aCB=anItCB.Value();
373     const BOPTools_PaveBlock& aPB1=aCB.PaveBlock1(nE1);//XXX
374     //
375     const BOPTools_ListOfPaveBlock& aLPBx=aCB.PaveBlocks();
376     anIt.Initialize(aLPBx);
377     for (; anIt.More(); anIt.Next()) {
378       const BOPTools_PaveBlock& aPB2=anIt.Value();
379       nE=aPB2.OriginalEdge();
380       if (nE==nE2) {
381         aLPB.Append(aPB1);
382       }
383     }
384   }
385   return 0; //Ok
386 }
387 //=======================================================================
388 // function: SplitsOnFace
389 // purpose:  splits of edge nE1 on face nF2
390 //=======================================================================
391   Standard_Integer NMTTools_PaveFiller::SplitsOnFace(const Standard_Integer nE1,
392                                                      const Standard_Integer nF2,
393                                                      BOPTools_ListOfPaveBlock& aLPB)
394 {
395   Standard_Integer nE2, ip;
396   TopAbs_ShapeEnum aT1, aT2;
397
398   aT1=myDS->GetShapeType(nE1);
399   aT2=myDS->GetShapeType(nF2);
400
401   if (aT1!=TopAbs_EDGE || aT2!=TopAbs_FACE) {
402     return 1; // Type mismatch
403   }
404   BooleanOperations_ShapesDataStructure *pDS=myDS;
405   BooleanOperations_OnceExplorer aExp(*pDS);
406   aExp.Init(nF2, TopAbs_EDGE);
407   for (; aExp.More(); aExp.Next()) {
408     nE2=aExp.Current();
409     ip=SplitsOnEdge(nE1, nE2, aLPB);
410     if (ip) {
411       return ip;
412     }
413   }
414   return 0; //Ok
415 }
416 //=======================================================================
417 // function: SplitsOnFace
418 // purpose:  splits of edges from face nF1 on face nF2
419 //=======================================================================
420   Standard_Integer NMTTools_PaveFiller::SplitsOnFace(const Standard_Integer ,//for overriding
421                                                      const Standard_Integer nF1,
422                                                      const Standard_Integer nF2,
423                                                      BOPTools_ListOfPaveBlock& aLPB)
424 {
425   Standard_Integer nE1, ip;
426   TopAbs_ShapeEnum aT1, aT2;
427
428   aT1=myDS->GetShapeType(nF1);
429   aT2=myDS->GetShapeType(nF2);
430
431   if (aT1!=TopAbs_FACE || aT2!=TopAbs_FACE) {
432     return 1; // Type mismatch
433   }
434   BooleanOperations_ShapesDataStructure *pDS=myDS;
435   BooleanOperations_OnceExplorer aExp(*myDS);
436   aExp.Init(nF1, TopAbs_EDGE);
437   for (; aExp.More(); aExp.Next()) {
438     nE1=aExp.Current();
439     ip=SplitsOnFace(nE1, nF2, aLPB);
440     if (ip) {
441       return ip;
442     }
443   }
444   return 0; //Ok
445 }
446
447 // 3 Simple Splits indices
448 //=======================================================================
449 // function: SplitsFace
450 // purpose:
451 //=======================================================================
452   Standard_Integer NMTTools_PaveFiller::SplitsFace(const Standard_Integer nF,
453                                                    TColStd_ListOfInteger& aSplits)
454 {
455   Standard_Integer nE, iErr;
456   BOPTools_ListIteratorOfListOfPaveBlock aIt;
457   BOPTools_ListOfPaveBlock aLPB;
458   //
459   iErr=SplitsFace(nF, aLPB);
460    if (iErr) {
461     return iErr;
462   }
463
464   aIt.Initialize(aLPB);
465   for (; aIt.More(); aIt.Next()) {
466     const BOPTools_PaveBlock& aPB=aIt.Value();
467     nE=aPB.Edge();
468     aSplits.Append(nE);
469   }
470   return 0; //Ok
471 }
472
473 //=======================================================================
474 // function: SplitsInFace
475 // purpose: splits of edges from nF1 in nF2
476 //=======================================================================
477   Standard_Integer NMTTools_PaveFiller::SplitsInFace(const Standard_Integer ,//for overriding
478                                                      const Standard_Integer nF1,
479                                                      const Standard_Integer nF2,
480                                                      TColStd_ListOfInteger& aSplits)
481 {
482   Standard_Integer nE, iErr;
483   BOPTools_ListIteratorOfListOfPaveBlock aIt;
484   BOPTools_ListOfPaveBlock aLPB;
485   //
486   iErr=SplitsInFace(0, nF1, nF2, aLPB);
487   if (iErr) {
488     return iErr;
489   }
490   aIt.Initialize(aLPB);
491   for (; aIt.More(); aIt.Next()) {
492     const BOPTools_PaveBlock& aPB=aIt.Value();
493     nE=aPB.Edge();
494     aSplits.Append(nE);
495   }
496   return iErr;
497 }
498 //=======================================================================
499 // function: SplitsInFace
500 // purpose: splits of edge nE1 in aFace2
501 //=======================================================================
502   Standard_Integer NMTTools_PaveFiller::SplitsInFace(const Standard_Integer nE1,
503                                                      const Standard_Integer nF2,
504                                                      TColStd_ListOfInteger& aSplits)
505 {
506   Standard_Integer nE, iErr;
507   BOPTools_ListIteratorOfListOfPaveBlock aIt;
508   BOPTools_ListOfPaveBlock aLPB;
509   //
510   iErr=SplitsInFace(nE1, nF2, aLPB);
511   if (iErr) {
512     return iErr;
513   }
514   aIt.Initialize(aLPB);
515   for (; aIt.More(); aIt.Next()) {
516     const BOPTools_PaveBlock& aPB=aIt.Value();
517     nE=aPB.Edge();
518     aSplits.Append(nE);
519   }
520   return iErr;
521 }
522 //=======================================================================
523 // function: SplitsOnEdge
524 // purpose:  splits of edge nE1 on nE2
525 //=======================================================================
526   Standard_Integer NMTTools_PaveFiller::SplitsOnEdge(const Standard_Integer nE1,
527                                                      const Standard_Integer nE2,
528                                                      TColStd_ListOfInteger& aSplits)
529 {
530   Standard_Integer nE, iErr;
531   BOPTools_ListIteratorOfListOfPaveBlock aIt;
532   BOPTools_ListOfPaveBlock aLPB;
533   //
534   iErr=SplitsOnEdge(nE1, nE2, aLPB);
535   if (iErr) {
536     return iErr;
537   }
538   aIt.Initialize(aLPB);
539   for (; aIt.More(); aIt.Next()) {
540     const BOPTools_PaveBlock& aPB=aIt.Value();
541     nE=aPB.Edge();
542     aSplits.Append(nE);
543   }
544   return iErr;
545 }
546 //=======================================================================
547 // function: SplitsOnFace
548 // purpose:  splits of edge nE1 on face nF2
549 //=======================================================================
550   Standard_Integer NMTTools_PaveFiller::SplitsOnFace(const Standard_Integer nE1,
551                                                      const Standard_Integer nF2,
552                                                      TColStd_ListOfInteger& aSplits)
553 {
554   Standard_Integer nE, iErr;
555   BOPTools_ListIteratorOfListOfPaveBlock aIt;
556   BOPTools_ListOfPaveBlock aLPB;
557   //
558   iErr=SplitsOnEdge(nE1, nF2, aLPB);
559   if (iErr) {
560     return iErr;
561   }
562   aIt.Initialize(aLPB);
563   for (; aIt.More(); aIt.Next()) {
564     const BOPTools_PaveBlock& aPB=aIt.Value();
565     nE=aPB.Edge();
566     aSplits.Append(nE);
567   }
568   return iErr;
569 }
570 //=======================================================================
571 // function: SplitsOnFace
572 // purpose:  splits of edges from face nF1 on face nF2
573 //=======================================================================
574   Standard_Integer NMTTools_PaveFiller::SplitsOnFace(const Standard_Integer ,//for overriding
575                                                      const Standard_Integer nF1,
576                                                      const Standard_Integer nF2,
577                                                      TColStd_ListOfInteger& aSplits)
578 {
579   Standard_Integer nE, iErr;
580   BOPTools_ListIteratorOfListOfPaveBlock aIt;
581   BOPTools_ListOfPaveBlock aLPB;
582   //
583   iErr=SplitsOnFace(0, nF1, nF2, aLPB);
584    if (iErr) {
585     return iErr;
586   }
587
588   aIt.Initialize(aLPB);
589   for (; aIt.More(); aIt.Next()) {
590     const BOPTools_PaveBlock& aPB=aIt.Value();
591     nE=aPB.Edge();
592     aSplits.Append(nE);
593   }
594   return 0; //Ok
595 }