0025266: Debug statements in the source are getting flushed on to the console
[occt.git] / src / HLRBRep / HLRBRep_InternalAlgo.cxx
1 // Created on: 1997-04-17
2 // Created by: Christophe MARION
3 // Copyright (c) 1997-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 #include <Standard_Stream.hxx>
18 #include <HLRBRep_InternalAlgo.ixx>
19
20 #include <Standard_ErrorHandler.hxx>
21 #include <TColStd_Array1OfReal.hxx>
22 #include <HLRAlgo.hxx>
23 #include <HLRBRep_ShapeToHLR.hxx>
24 #include <HLRBRep_Hider.hxx>
25 #include <stdio.h>
26
27 extern Standard_Integer nbPtIntersection;   // total P.I.
28 extern Standard_Integer nbSegIntersection;  // total S.I
29 extern Standard_Integer nbClassification;   // total classification
30 extern Standard_Integer nbOkIntersection;   // pairs of intersecting edges
31 extern Standard_Integer nbCal1Intersection; // pairs of unrejected edges
32 extern Standard_Integer nbCal2Intersection; // true intersections (not vertex)
33 extern Standard_Integer nbCal3Intersection; // curve-surface intersections
34
35 static Standard_Integer TRACE = Standard_True;
36 static Standard_Integer TRACE10 = Standard_True; 
37
38 #define MinShBI1 MinMaxShBI[ 0]
39 #define MinShBI2 MinMaxShBI[ 1]
40 #define MinShBI3 MinMaxShBI[ 2]
41 #define MinShBI4 MinMaxShBI[ 3]
42 #define MinShBI5 MinMaxShBI[ 4]
43 #define MinShBI6 MinMaxShBI[ 5]
44 #define MinShBI7 MinMaxShBI[ 6]
45 #define MinShBI8 MinMaxShBI[ 7]
46 #define MaxShBI1 MinMaxShBI[ 8]
47 #define MaxShBI2 MinMaxShBI[ 9]
48 #define MaxShBI3 MinMaxShBI[10]
49 #define MaxShBI4 MinMaxShBI[11]
50 #define MaxShBI5 MinMaxShBI[12]
51 #define MaxShBI6 MinMaxShBI[13]
52 #define MaxShBI7 MinMaxShBI[14]
53 #define MaxShBI8 MinMaxShBI[15]
54
55 #define MinShBJ1 MinMaxShBJ[ 0]
56 #define MinShBJ2 MinMaxShBJ[ 1]
57 #define MinShBJ3 MinMaxShBJ[ 2]
58 #define MinShBJ4 MinMaxShBJ[ 3]
59 #define MinShBJ5 MinMaxShBJ[ 4]
60 #define MinShBJ6 MinMaxShBJ[ 5]
61 #define MinShBJ7 MinMaxShBJ[ 6]
62 #define MinShBJ8 MinMaxShBJ[ 7]
63 #define MaxShBJ1 MinMaxShBJ[ 8]
64 #define MaxShBJ2 MinMaxShBJ[ 9]
65 #define MaxShBJ3 MinMaxShBJ[10]
66 #define MaxShBJ4 MinMaxShBJ[11]
67 #define MaxShBJ5 MinMaxShBJ[12]
68 #define MaxShBJ6 MinMaxShBJ[13]
69 #define MaxShBJ7 MinMaxShBJ[14]
70 #define MaxShBJ8 MinMaxShBJ[15]
71
72 //=======================================================================
73 //function : HLRBRep_InternalAlgo
74 //purpose  : 
75 //=======================================================================
76
77 HLRBRep_InternalAlgo::HLRBRep_InternalAlgo () :
78 myDebug       (Standard_False)
79 {
80 }
81
82 //=======================================================================
83 //function : HLRBRep_InternalAlgo
84 //purpose  : 
85 //=======================================================================
86
87 HLRBRep_InternalAlgo::
88 HLRBRep_InternalAlgo (const Handle(HLRBRep_InternalAlgo)& A)
89 {
90   myDS          = A->DataStructure();
91   myProj        = A->Projector();
92   myShapes      = A->SeqOfShapeBounds();
93   myDebug       = A->Debug();
94 }
95
96 //=======================================================================
97 //function : Projector
98 //purpose  : 
99 //=======================================================================
100
101 void HLRBRep_InternalAlgo::Projector (const HLRAlgo_Projector& P)
102 {
103   myProj = P;
104 }
105
106 //=======================================================================
107 //function : Projector
108 //purpose  : 
109 //=======================================================================
110
111 HLRAlgo_Projector & HLRBRep_InternalAlgo::Projector ()
112 { return myProj; }
113
114 //=======================================================================
115 //function : Update
116 //purpose  : 
117 //=======================================================================
118
119 void HLRBRep_InternalAlgo::Update ()
120 {
121   if (!myShapes.IsEmpty()) {
122     Standard_Integer n = myShapes.Length();
123     Handle(HLRBRep_Data) *DS = new Handle(HLRBRep_Data) [n];
124
125     Standard_Integer i,dv,de,df,nv=0,ne=0,nf=0;
126
127     for (i = 1; i <= n; i++) {
128       HLRBRep_ShapeBounds& SB = myShapes(i);
129       try {
130         OCC_CATCH_SIGNALS
131         DS[i-1] = HLRBRep_ShapeToHLR::Load(SB.Shape(),
132                                            myProj,
133                                            myMapOfShapeTool,
134                                            SB.NbOfIso());
135         dv = DS[i-1]->NbVertices();
136         de = DS[i-1]->NbEdges   ();
137         df = DS[i-1]->NbFaces   ();
138       }
139       catch(Standard_Failure) {
140         if (myDebug)
141         {
142           cout << "An exception was catched when preparing the Shape " << i;
143           cout << " and computing its OutLines " << endl;
144           Handle(Standard_Failure) fail = Standard_Failure::Caught();
145           cout << fail << endl;
146         }
147         DS[i-1] = new HLRBRep_Data(0,0,0);
148         dv = 0;
149         de = 0;
150         df = 0;
151       }
152
153       SB = HLRBRep_ShapeBounds
154         (SB.Shape(),SB.ShapeData(),SB.NbOfIso(),1,dv,1,de,1,df);
155       nv += dv;
156       ne += de;
157       nf += df;
158     }
159
160     if (n == 1) myDS = DS[0];
161     else {
162       myDS = new HLRBRep_Data(nv,ne,nf);
163       nv = 0;
164       ne = 0;
165       nf = 0;
166
167       for (i = 1; i <= n; i++) {
168         HLRBRep_ShapeBounds& SB = myShapes(i);
169         SB.Sizes(dv,de,df);
170         SB.Translate(nv,ne,nf);
171         myDS->Write(DS[i-1],nv,ne,nf);
172         nv += dv;
173         ne += de;
174         nf += df;
175       }
176     }
177
178     delete [] DS;
179
180     myDS->Update(myProj);
181
182     Standard_Integer ShapMin[16],ShapMax[16],MinMaxShap[16];
183     Standard_Integer TheMin[16],TheMax[16];
184
185     for (i = 1; i <= n; i++) {
186       Standard_Boolean FirstTime = Standard_True;
187       HLRBRep_ShapeBounds& SB = myShapes(i);
188       Standard_Integer v1,v2,e1,e2,f1,f2;
189       SB.Bounds(v1,v2,e1,e2,f1,f2);
190
191       HLRBRep_EdgeData* ed = &(myDS->EDataArray    (). ChangeValue(e1 - 1));
192       HLRBRep_FaceData* fd = &(myDS->FDataArray    (). ChangeValue(f1 - 1));
193       ed++;
194       fd++;
195
196       for (Standard_Integer e = e1; e <= e2; e++) {
197         HLRAlgo::DecodeMinMax(ed->MinMax(),
198                               (Standard_Address)TheMin,
199                               (Standard_Address)TheMax);
200         if (FirstTime) {
201           FirstTime = Standard_False;
202           HLRAlgo::CopyMinMax((Standard_Address)TheMin,
203                               (Standard_Address)TheMax,
204                               (Standard_Address)ShapMin,
205                               (Standard_Address)ShapMax);
206         }
207         else
208           HLRAlgo::AddMinMax((Standard_Address)TheMin,
209                              (Standard_Address)TheMax,
210                              (Standard_Address)ShapMin,
211                              (Standard_Address)ShapMax);
212         ed++;
213       }
214
215       for (Standard_Integer f = f1; f <= f2; f++) {
216         HLRAlgo::DecodeMinMax(fd->Wires()->MinMax(),
217                               (Standard_Address)TheMin,
218                               (Standard_Address)TheMax);
219         HLRAlgo::AddMinMax((Standard_Address)TheMin,
220                            (Standard_Address)TheMax,
221                            (Standard_Address)ShapMin,
222                            (Standard_Address)ShapMax);
223         fd++;
224       }
225       HLRAlgo::EncodeMinMax((Standard_Address)ShapMin,
226                             (Standard_Address)ShapMax,
227                             (Standard_Address)MinMaxShap);
228       SB.UpdateMinMax((Standard_Address)MinMaxShap);
229     }
230   }
231 }
232
233 //=======================================================================
234 //function : Load
235 //purpose  : 
236 //=======================================================================
237
238 void HLRBRep_InternalAlgo::Load (const Handle(HLRTopoBRep_OutLiner)& S,
239                                  const Handle(MMgt_TShared)& SData, 
240                                  const Standard_Integer nbIso)
241
242   myShapes.Append(HLRBRep_ShapeBounds(S,SData,nbIso,0,0,0,0,0,0));
243   myDS.Nullify();
244 }
245
246 //=======================================================================
247 //function : Load
248 //purpose  : 
249 //=======================================================================
250
251 void HLRBRep_InternalAlgo::Load (const Handle(HLRTopoBRep_OutLiner)& S,
252                                  const Standard_Integer nbIso)
253
254   myShapes.Append(HLRBRep_ShapeBounds(S,nbIso,0,0,0,0,0,0));
255   myDS.Nullify();
256 }
257
258 //=======================================================================
259 //function : Index
260 //purpose  : 
261 //=======================================================================
262
263 Standard_Integer HLRBRep_InternalAlgo::
264 Index (const Handle(HLRTopoBRep_OutLiner)& S) const
265 {
266   Standard_Integer n = myShapes.Length();
267
268   for (Standard_Integer i = 1; i <= n; i++)
269     if (myShapes(i).Shape() == S) return i;
270
271   return 0;
272 }
273
274 //=======================================================================
275 //function : Remove
276 //purpose  : 
277 //=======================================================================
278
279 void HLRBRep_InternalAlgo::Remove (const Standard_Integer I)
280 {
281   Standard_OutOfRange_Raise_if
282     (I == 0 || I > myShapes.Length(),
283      "HLRBRep_InternalAlgo::Remove : unknown Shape");
284   myShapes.Remove(I);
285   
286   myMapOfShapeTool.Clear();
287   myDS.Nullify();
288 }
289
290 //=======================================================================
291 //function : ShapeData
292 //purpose  : 
293 //=======================================================================
294
295 void HLRBRep_InternalAlgo::ShapeData (const Standard_Integer I,
296                                       const Handle(MMgt_TShared)& SData)
297 {
298   Standard_OutOfRange_Raise_if
299     (I == 0 || I > myShapes.Length(),
300      "HLRBRep_InternalAlgo::ShapeData : unknown Shape");
301
302   myShapes(I).ShapeData(SData);
303 }
304
305 //=======================================================================
306 //function : SeqOfShapeBounds
307 //purpose  : 
308 //=======================================================================
309
310 HLRBRep_SeqOfShapeBounds & HLRBRep_InternalAlgo::SeqOfShapeBounds ()
311 {
312   return myShapes;
313 }
314
315 //=======================================================================
316 //function : NbShapes
317 //purpose  : 
318 //=======================================================================
319
320 Standard_Integer HLRBRep_InternalAlgo::NbShapes () const
321 { return myShapes.Length(); }
322
323 //=======================================================================
324 //function : ShapeBounds
325 //purpose  : 
326 //=======================================================================
327
328 HLRBRep_ShapeBounds & HLRBRep_InternalAlgo::
329 ShapeBounds (const Standard_Integer I)
330 {
331   Standard_OutOfRange_Raise_if
332     (I == 0 || I > myShapes.Length(),
333      "HLRBRep_InternalAlgo::ShapeBounds : unknown Shape");
334
335   return myShapes(I);
336 }
337
338 //=======================================================================
339 //function : InitEdgeStatus
340 //purpose  : 
341 //=======================================================================
342
343 void HLRBRep_InternalAlgo::InitEdgeStatus () 
344 {
345   Standard_Boolean visible;
346   HLRBRep_FaceIterator faceIt;
347   
348   HLRBRep_EdgeData* ed = &(myDS->EDataArray().ChangeValue(1));
349   HLRBRep_FaceData* fd = &(myDS->FDataArray().ChangeValue(1));
350   Standard_Integer ne = myDS->NbEdges();
351   Standard_Integer nf = myDS->NbFaces();
352
353   for (Standard_Integer e = 1; e <= ne; e++) {
354     if (ed->Selected()) ed->Status().ShowAll();
355     ed++;
356   }
357 //  for (Standard_Integer f = 1; f <= nf; f++) {
358   Standard_Integer f;
359   for ( f = 1; f <= nf; f++) {
360     if (fd->Selected()) {
361       
362       for (faceIt.InitEdge(*fd);
363            faceIt.MoreEdge();
364            faceIt.NextEdge()) {
365         HLRBRep_EdgeData* edf = &(myDS->EDataArray().ChangeValue(faceIt.Edge()));
366         if (edf->Selected()) edf->Status().HideAll();
367       }
368     }
369     fd++;
370   }
371
372   fd = &(myDS->FDataArray().ChangeValue(1));
373
374   for (f = 1; f <= nf; f++) {
375     visible = Standard_True;
376     if (fd->Selected() && fd->Closed()) {
377       if      ( fd->Side())      visible =  Standard_False;
378       else if ( !fd->WithOutL()) {
379         switch (fd->Orientation()) {
380         case TopAbs_REVERSED : visible =  fd->Back()   ; break;
381         case TopAbs_FORWARD  : visible = !fd->Back()   ; break;
382         case TopAbs_EXTERNAL :
383         case TopAbs_INTERNAL : visible =  Standard_True; break;
384         }
385       }
386     } 
387     if (visible) {
388       
389       for (faceIt.InitEdge(*fd);
390            faceIt.MoreEdge();
391            faceIt.NextEdge()) {
392         Standard_Integer E = faceIt.Edge();
393         HLRBRep_EdgeData* edf = &(myDS->EDataArray().ChangeValue(E));
394         if ( edf->Selected() &&
395             !edf->Vertical())
396           edf->Status().ShowAll();
397       }
398     }
399     fd++;
400   }
401 }
402
403 //=======================================================================
404 //function : Select
405 //purpose  : 
406 //=======================================================================
407
408 void HLRBRep_InternalAlgo::Select ()
409 {
410   if (!myDS.IsNull()) {
411     HLRBRep_EdgeData* ed = &(myDS->EDataArray().ChangeValue(1));
412     HLRBRep_FaceData* fd = &(myDS->FDataArray().ChangeValue(1));
413     Standard_Integer ne = myDS->NbEdges();
414     Standard_Integer nf = myDS->NbFaces();
415     
416     for (Standard_Integer e = 1; e <= ne; e++) {
417       ed->Selected(Standard_True);
418       ed++;
419     }
420     
421     for (Standard_Integer f = 1; f <= nf; f++) {
422       fd->Selected(Standard_True);
423       fd++;
424     }
425   }
426 }
427
428 //=======================================================================
429 //function : Select
430 //purpose  : 
431 //=======================================================================
432
433 void HLRBRep_InternalAlgo::Select (const Standard_Integer I)
434 {
435   if (!myDS.IsNull()) { 
436     Standard_OutOfRange_Raise_if
437       (I == 0 || I > myShapes.Length(),
438        "HLRBRep_InternalAlgo::Select : unknown Shape");
439
440     Standard_Integer v1,v2,e1,e2,f1,f2;
441     myShapes(I).Bounds(v1,v2,e1,e2,f1,f2);
442     
443     HLRBRep_EdgeData* ed = &(myDS->EDataArray().ChangeValue(1));
444     HLRBRep_FaceData* fd = &(myDS->FDataArray().ChangeValue(1));
445     Standard_Integer ne = myDS->NbEdges();
446     Standard_Integer nf = myDS->NbFaces();
447     
448     for (Standard_Integer e = 1; e <= ne; e++) {
449       ed->Selected(e >= e1 && e <= e2);
450       ed++;
451     }
452     
453     for (Standard_Integer f = 1; f <= nf; f++) {
454       fd->Selected(f >= f1 && f <= f2);
455       fd++;
456     }
457   }
458 }
459
460 //=======================================================================
461 //function : SelectEdge
462 //purpose  : 
463 //=======================================================================
464
465 void HLRBRep_InternalAlgo::SelectEdge (const Standard_Integer I)
466 {
467   if (!myDS.IsNull()) {
468     Standard_OutOfRange_Raise_if
469       (I == 0 || I > myShapes.Length(),
470        "HLRBRep_InternalAlgo::SelectEdge : unknown Shape");
471     
472     Standard_Integer v1,v2,e1,e2,f1,f2;
473     myShapes(I).Bounds(v1,v2,e1,e2,f1,f2);
474     
475     HLRBRep_EdgeData* ed = &(myDS->EDataArray().ChangeValue(1));
476     Standard_Integer ne = myDS->NbEdges();
477     
478     for (Standard_Integer e = 1; e <= ne; e++) {
479       ed->Selected(e >= e1 && e <= e2);
480       ed++;
481     }
482   }
483 }
484
485 //=======================================================================
486 //function : SelectFace
487 //purpose  : 
488 //=======================================================================
489
490 void HLRBRep_InternalAlgo::SelectFace (const Standard_Integer I)
491 {
492   if (!myDS.IsNull()) {
493     Standard_OutOfRange_Raise_if
494       (I == 0 || I > myShapes.Length(),
495        "HLRBRep_InternalAlgo::SelectFace : unknown Shape");
496     
497     Standard_Integer v1,v2,e1,e2,f1,f2;
498     myShapes(I).Bounds(v1,v2,e1,e2,f1,f2);
499     
500     HLRBRep_FaceData* fd = &(myDS->FDataArray().ChangeValue(1));
501     Standard_Integer nf = myDS->NbFaces();
502     
503     for (Standard_Integer f = 1; f <= nf; f++) {
504       fd->Selected(f >= f1 && f <= f2);
505       fd++;
506     }
507   }
508 }
509
510 //=======================================================================
511 //function : ShowAll
512 //purpose  : 
513 //=======================================================================
514
515 void HLRBRep_InternalAlgo::ShowAll ()
516 {
517   if (!myDS.IsNull()) {
518     HLRBRep_EdgeData* ed = &(myDS->EDataArray().ChangeValue(1));
519     Standard_Integer ne = myDS->NbEdges();
520
521     for (Standard_Integer ie = 1; ie <= ne; ie++) {
522       ed->Status().ShowAll();
523       ed++;
524     }
525   }
526 }
527
528 //=======================================================================
529 //function : ShowAll
530 //purpose  : 
531 //=======================================================================
532
533 void HLRBRep_InternalAlgo::ShowAll (const Standard_Integer I)
534 {
535   if (!myDS.IsNull()) {
536     Standard_OutOfRange_Raise_if
537       (I == 0 || I > myShapes.Length(),
538        "HLRBRep_InternalAlgo::ShowAll : unknown Shape");
539     
540     Select(I);
541     
542     HLRBRep_EdgeData* ed = &(myDS->EDataArray().ChangeValue(1));
543     Standard_Integer ne = myDS->NbEdges();
544     
545     for (Standard_Integer e = 1; e <= ne; e++) {
546       if (ed->Selected()) ed->Status().ShowAll();
547       ed++;
548     }
549   }
550 }
551
552 //=======================================================================
553 //function : HideAll
554 //purpose  : 
555 //=======================================================================
556
557 void HLRBRep_InternalAlgo::HideAll ()
558 {
559   if (!myDS.IsNull()) {
560     HLRBRep_EdgeData* ed = &(myDS->EDataArray().ChangeValue(1));
561     Standard_Integer ne = myDS->NbEdges();
562     
563     for (Standard_Integer ie = 1; ie <= ne; ie++) {
564       ed->Status().HideAll();
565       ed++;
566     }
567   }
568 }
569
570 //=======================================================================
571 //function : HideAll
572 //purpose  : 
573 //=======================================================================
574
575 void HLRBRep_InternalAlgo::HideAll (const Standard_Integer I)
576 {
577   if (!myDS.IsNull()) {
578     Standard_OutOfRange_Raise_if
579       (I == 0 || I > myShapes.Length(),
580        "HLRBRep_InternalAlgo::HideAll : unknown Shape");
581     
582     Select(I);
583     
584     HLRBRep_EdgeData* ed = &(myDS->EDataArray().ChangeValue(1));
585     Standard_Integer ne = myDS->NbEdges();
586     
587     for (Standard_Integer e = 1; e <= ne; e++) {
588       if (ed->Selected()) ed->Status().HideAll();
589       ed++;
590     }
591   }
592 }
593
594 //=======================================================================
595 //function : PartialHide
596 //purpose  : 
597 //=======================================================================
598
599 void HLRBRep_InternalAlgo::PartialHide ()
600 {
601   if (!myDS.IsNull()) {
602     Standard_Integer i,n = myShapes.Length();
603
604     if (myDebug)
605       cout << " Partial hiding" << endl << endl;
606
607     for (i = 1; i <= n; i++)
608       Hide(i);
609     
610     Select();
611   }
612 }
613
614 //=======================================================================
615 //function : Hide
616 //purpose  : 
617 //=======================================================================
618
619 void HLRBRep_InternalAlgo::Hide ()
620 {
621   if (!myDS.IsNull()) {
622     Standard_Integer i,j,n = myShapes.Length();
623
624     if (myDebug)
625       cout << " Total hiding" << endl;
626
627     for (i = 1; i <= n; i++)
628       Hide(i);
629     
630     for (i = 1; i <= n; i++)
631       for (j = 1; j <= n; j++)
632         if (i != j) Hide(i,j);
633     
634     Select();
635   }
636 }
637
638 //=======================================================================
639 //function : Hide
640 //purpose  : 
641 //=======================================================================
642
643 void HLRBRep_InternalAlgo::Hide (const Standard_Integer I)
644 {
645   if (!myDS.IsNull()) {
646     Standard_OutOfRange_Raise_if
647       (I == 0 || I > myShapes.Length(),
648        "HLRBRep_InternalAlgo::Hide : unknown Shape");
649     
650     if (myDebug)
651       cout << " hiding the shape " << I << " by itself" << endl;
652     
653     Select(I);
654     InitEdgeStatus();
655     HideSelected(I,Standard_True);
656   }
657 }
658
659 //=======================================================================
660 //function : Hide
661 //purpose  : 
662 //=======================================================================
663
664 void HLRBRep_InternalAlgo::Hide (const Standard_Integer I,
665                                  const Standard_Integer J)
666 {
667   if (!myDS.IsNull()) {
668     Standard_OutOfRange_Raise_if
669       (I == 0 || I > myShapes.Length() ||
670        J == 0 || J > myShapes.Length(),
671        "HLRBRep_InternalAlgo::Hide : unknown Shapes");
672
673     if (I == J) Hide(I);
674     else {
675       Standard_Integer* MinMaxShBI =
676         (Standard_Integer*)myShapes(I).MinMax();
677       Standard_Integer* MinMaxShBJ =
678         (Standard_Integer*)myShapes(J).MinMax();
679       if (((MaxShBJ1 - MinShBI1) & 0x80008000) == 0 &&
680           ((MaxShBI1 - MinShBJ1) & 0x80008000) == 0 &&
681           ((MaxShBJ2 - MinShBI2) & 0x80008000) == 0 &&
682           ((MaxShBI2 - MinShBJ2) & 0x80008000) == 0 &&
683           ((MaxShBJ3 - MinShBI3) & 0x80008000) == 0 &&
684           ((MaxShBI3 - MinShBJ3) & 0x80008000) == 0 &&
685           ((MaxShBJ4 - MinShBI4) & 0x80008000) == 0 &&
686           ((MaxShBI4 - MinShBJ4) & 0x80008000) == 0 &&
687           ((MaxShBJ5 - MinShBI5) & 0x80008000) == 0 &&
688           ((MaxShBI5 - MinShBJ5) & 0x80008000) == 0 &&
689           ((MaxShBJ6 - MinShBI6) & 0x80008000) == 0 &&
690           ((MaxShBI6 - MinShBJ6) & 0x80008000) == 0 &&
691           ((MaxShBJ7 - MinShBI7) & 0x80008000) == 0 &&
692           ((MaxShBJ8 - MinShBI8) & 0x80008000) == 0) {
693         if (myDebug) {
694           cout << " hiding the shape " << I;
695           cout << " by the shape : " << J << endl;
696         }
697         SelectEdge(I);
698         SelectFace(J);
699         HideSelected(I,Standard_False);
700       }
701     }
702   }
703 }
704
705 //=======================================================================
706 //function : HideSelected
707 //purpose  : 
708 //=======================================================================
709
710 void HLRBRep_InternalAlgo::HideSelected (const Standard_Integer I,
711                                          const Standard_Boolean SideFace)
712 {
713   Standard_Integer e,f,j,nbVisEdges,nbSelEdges,nbSelFaces,nbCache;
714   Standard_Integer nbFSide,nbFSimp;
715
716 #ifdef DEB
717   if (myDebug) {
718     nbPtIntersection = 0;
719     nbSegIntersection = 0;
720     nbOkIntersection = 0;
721     nbClassification = 0;
722     nbCal1Intersection = 0;
723     nbCal2Intersection = 0;
724     nbCal3Intersection = 0;
725   }
726 #endif
727
728   HLRBRep_ShapeBounds& SB = myShapes(I);
729   Standard_Integer v1,v2,e1,e2,f1,f2;
730   SB.Bounds(v1,v2,e1,e2,f1,f2);
731
732   if (e2 >= e1) {
733     myDS->InitBoundSort(SB.MinMax(),e1,e2);
734     HLRBRep_Hider Cache(myDS);
735     HLRBRep_EdgeData* ed = &(myDS->EDataArray().ChangeValue(1));
736     HLRBRep_FaceData* fd = &(myDS->FDataArray().ChangeValue(1));
737     Standard_Integer ne = myDS->NbEdges();
738     Standard_Integer nf = myDS->NbFaces();
739     
740     if (myDebug) {
741       nbVisEdges = 0;
742       nbSelEdges = 0;
743       nbSelFaces = 0;
744       nbCache = 0;
745       nbFSide = 0;
746       nbFSimp = 0;
747       
748       for (e = 1; e <= ne; e++) {
749         if (ed->Selected()) {
750           nbSelEdges++;
751           if (!ed->Status().AllHidden()) nbVisEdges++;
752         }
753         ed++;
754       }
755       
756       for (f = 1; f <= nf; f++) {
757         if (fd->Selected()) {
758           nbSelFaces++;
759           if (fd->Hiding()) nbCache++;
760           if (fd->Side  ()) nbFSide++;
761           if (fd->Simple()) nbFSimp++;
762         }
763         fd++;
764       }
765       
766       if (myDebug)
767       {
768         cout << endl;
769         cout << "Vertices  : " << setw(5) << myDS->NbVertices() << endl;
770         cout << "Edges     : " << setw(5) << myDS->NbEdges()    << " , ";
771         cout << "Selected  : " << setw(5) << nbSelEdges         << " , ";
772         cout << "Visibles  : " << setw(5) << nbVisEdges         << endl;
773         cout << "Faces     : " << setw(5) << myDS->NbFaces()    << " , ";
774         cout << "Selected  : " << setw(5) << nbSelFaces         << " , ";
775         cout << "Simple    : " << setw(5) << nbFSimp            << endl;
776         if (SideFace)
777           cout << "Side      : " << setw(5) << nbFSide            << " , ";
778         cout << "Cachantes : " << setw(5) << nbCache            << endl << endl;
779       }
780     }
781
782     Standard_Integer QWE=0,QWEQWE;
783     QWEQWE=nf/10;
784
785     if (SideFace) {
786       j = 0;
787       fd = &(myDS->FDataArray().ChangeValue(1));
788       
789       for (f = 1; f <= nf; f++) {
790         if (fd->Selected()) {
791           if (fd->Side()) {
792             if(TRACE10) { 
793               if(++QWE>QWEQWE) { 
794                 QWE=0; 
795                 if (myDebug)
796                   cout<<"*";
797               } 
798             }
799             else {  
800               if (myDebug && TRACE) {
801                 j++;
802                 cout << " OwnHiding " << j << " of face : " << f << endl;
803               }
804             }
805             Cache.OwnHiding(f);
806           }
807         }
808         fd++;
809       }
810     }
811     
812
813 //--
814     TColStd_Array1OfInteger Val(1, nf);
815     TColStd_Array1OfReal    Size(1, nf);
816     TColStd_Array1OfInteger Index(1, nf);
817
818
819     fd = &(myDS->FDataArray().ChangeValue(1));
820     for (f = 1; f <= nf; f++) {
821       if(fd->Plane())          Val(f)=10;
822       else if(fd->Cylinder())  Val(f)=9;
823       else if(fd->Cone())      Val(f)=8;
824       else if(fd->Sphere())    Val(f)=7;
825       else if(fd->Torus())     Val(f)=6;
826       else Val(f)=0;
827       if(fd->Cut())            Val(f)-=10;
828       if(fd->Side())           Val(f)-=100;
829       if(fd->WithOutL())       Val(f)-=20;
830   
831       Size(f)=fd->Size();
832       fd++;
833     }
834
835     for(Standard_Integer tt=1;tt<=nf;tt++) { 
836       Index(tt)=tt;
837     }
838
839     //-- ======================================================================
840 /*    Standard_Boolean TriOk; //-- a refaire
841     do { 
842       Standard_Integer t,tp1;
843       TriOk=Standard_True;
844       for(t=1,tp1=2;t<nf;t++,tp1++) { 
845         if(Val(Index(t))<Val(Index(tp1))) {
846           Standard_Integer q=Index(t); Index(t)=Index(tp1); Index(tp1)=q;
847           TriOk=Standard_False;
848         }
849         else if(Val(Index(t))==Val(Index(tp1))) { 
850           if(Size(Index(t))<Size(Index(tp1))) { 
851             Standard_Integer q=Index(t); Index(t)=Index(tp1); Index(tp1)=q;
852             TriOk=Standard_False;
853           }
854         }
855       }
856     }
857     while(TriOk==Standard_False);
858 */
859     //-- ======================================================================
860     if(nf>2)  {
861       Standard_Integer i,ir,j,l;
862       Standard_Integer rra;
863       l=(nf>>1)+1;
864       ir=nf;
865       for(;;) { 
866         if(l>1) { 
867           rra=Index(--l); 
868         } 
869         else {    
870           rra=Index(ir); 
871           Index(ir)=Index(1);
872           if(--ir == 1) { 
873             Index(1)=rra;
874             break;
875           }
876         }
877         i=l;
878         j=l+l;
879         while(j<=ir) { 
880           if(j<ir) { 
881             if(Val(Index(j)) > Val(Index(j+1)))
882               j++;
883             else if(Val(Index(j)) == Val(Index(j+1))) { 
884               if(Size(Index(j)) > Size(Index(j+1))) 
885                 j++;
886             }
887           }
888           if(Val(rra) > Val(Index(j))) { 
889             Index(i)=Index(j);
890             i=j;
891             j<<=1;
892           }
893           else if((Val(rra) == Val(Index(j))) && (Size(rra) > Size(Index(j)))) { 
894             Index(i)=Index(j);
895             i=j;
896             j<<=1;
897           }
898           else {  
899             j=ir+1;
900           }
901         }
902         Index(i)=rra;
903       }
904     }
905
906     j = 0;
907     HLRBRep_Array1OfFData& FD = myDS->FDataArray();
908     
909     QWE=0;
910     for (f = 1; f <= nf; f++) {
911       Standard_Integer fi = Index(f);
912       fd=&(FD.ChangeValue(fi));
913       if (fd->Selected()) {
914         if (fd->Hiding()) {
915           if(TRACE10 && TRACE==Standard_False) { 
916             if(++QWE>QWEQWE) { 
917               if (myDebug)
918                 cout<<".";
919               QWE=0;
920             }
921           }
922           else if (myDebug && TRACE) {
923             static int rty=0;
924             j++;
925             printf("%6d",fi); fflush(stdout);
926             if(++rty>25) { rty=0; printf("\n"); } 
927           }
928           Cache.Hide(fi,myMapOfShapeTool);
929         }
930       }
931     }
932     
933 #ifdef DEB
934     if (myDebug) {
935       fd = &(myDS->FDataArray().ChangeValue(1));
936       nbFSimp = 0;
937       
938       for (f = 1; f <= nf; f++) {
939         if (fd->Selected() && fd->Simple())
940           nbFSimp++;
941         fd++;
942       }
943
944       cout << "\n";
945       cout << "Simple Faces                  : ";
946       cout << nbFSimp  << "\n";
947       cout << "Intersections calculees       : ";
948       cout << nbCal2Intersection << "\n";
949       cout << "Intersections Ok              : ";
950       cout << nbOkIntersection << "\n";
951       cout << "Points                        : ";
952       cout << nbPtIntersection << "\n";
953       cout << "Segments                      : ";
954       cout << nbSegIntersection << "\n";
955       cout << "Classification                : ";
956       cout << nbClassification << "\n";
957       cout << "Intersections curve-surface   : ";
958       cout << nbCal3Intersection << "\n";
959       cout << endl << endl;
960     }
961 #endif
962   }
963 }
964
965 //=======================================================================
966 //function : Debug
967 //purpose  : 
968 //=======================================================================
969
970 void HLRBRep_InternalAlgo::Debug (const Standard_Boolean deb)
971 { myDebug = deb; }
972
973 //=======================================================================
974 //function : Debug
975 //purpose  : 
976 //=======================================================================
977
978 Standard_Boolean HLRBRep_InternalAlgo::Debug () const
979 { return myDebug; }
980
981 //=======================================================================
982 //function : DataStructure
983 //purpose  : 
984 //=======================================================================
985
986 Handle(HLRBRep_Data) HLRBRep_InternalAlgo::DataStructure () const
987 { return myDS; }