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