c68194bf96c99cceaf40d904546785c4eb29c62f
[occt.git] / src / BOPTest / BOPTest_LowCommands.cxx
1 // File:        BOPTest_LowCommands.cxx
2 // Created:     Wed Mar 28 16:46:22 2001
3 // Author:      Peter KURNEV
4 //              <pkv@irinox>
5
6 #include <BOPTest.ixx>
7
8 #include <stdio.h>
9
10 #include <gp_Vec2d.hxx>
11 #include <gp_Pnt2d.hxx>
12 #include <gp_Pnt.hxx>
13
14 #include <Geom2d_Curve.hxx>
15 #include <Geom_Surface.hxx>
16
17 #include <BRep_Tool.hxx>
18 #include <BRep_Builder.hxx>
19 #include <BRep_GCurve.hxx>
20 #include <BRep_TEdge.hxx>
21 #include <BRep_CurveRepresentation.hxx>
22 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
23
24 #include <BRepClass3d_SolidClassifier.hxx>
25 #include <BRepClass_FaceClassifier.hxx>
26
27 #include <TopoDS.hxx>
28 #include <TopoDS_Edge.hxx>
29 #include <TopoDS_Face.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <TopoDS_Vertex.hxx>
32 #include <TopoDS_Iterator.hxx>
33
34 #include <TopTools_MapOfShape.hxx>
35
36 #include <TopLoc_Location.hxx>
37
38 #include <TopExp_Explorer.hxx>
39
40 #include <TopAbs.hxx>
41 #include <TopAbs_State.hxx>
42
43 #include <DBRep.hxx>
44
45 #include <DrawTrSurf.hxx>
46
47 #include <BOPTools_Tools2D.hxx>
48 #include <BOPTools_Tools3D.hxx>
49
50 #include <IntTools_Tools.hxx>
51
52 #include <BOP_Refiner.hxx>
53
54 #include <TCollection_AsciiString.hxx>
55 #include <IntTools_Context.hxx>
56 #include <IntTools_FClass2d.hxx>
57 #include <gp_Pnt2d.hxx>
58 #include <Standard_Static.hxx>
59 #include <OSD_Chronometer.hxx>
60
61 #include <BRepTools.hxx>
62
63 static
64   Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E, 
65                                       const TopoDS_Face& F,
66                                       Standard_Real& First,
67                                       Standard_Real& Last);
68 static
69   Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E, 
70                                       const Handle(Geom_Surface)& S,
71                                       const TopLoc_Location& L,
72                                       Standard_Real& First,
73                                       Standard_Real& Last);
74 static
75   void PrintState (Draw_Interpretor& aDI,
76                    const TopAbs_State& aState);
77
78 static  Standard_Integer bhaspc      (Draw_Interpretor& , Standard_Integer , const char** );
79 static  Standard_Integer baddve      (Draw_Interpretor& , Standard_Integer , const char** );
80 static  Standard_Integer bisclosed   (Draw_Interpretor& , Standard_Integer , const char** );
81 static  Standard_Integer bexplode    (Draw_Interpretor& , Standard_Integer , const char** );
82 static  Standard_Integer bupdateedge (Draw_Interpretor& , Standard_Integer , const char**);
83 static  Standard_Integer bremovesim  (Draw_Interpretor& , Standard_Integer , const char** );
84 static  Standard_Integer bopsetdisp  (Draw_Interpretor& , Standard_Integer , const char** );
85 static  Standard_Integer bfaceprepare(Draw_Interpretor& , Standard_Integer , const char** );
86 static  Standard_Integer brefine     (Draw_Interpretor& , Standard_Integer , const char** );
87 static  Standard_Integer bclassify   (Draw_Interpretor& , Standard_Integer , const char** );
88 static  Standard_Integer b2dclassify (Draw_Interpretor& , Standard_Integer , const char** );
89
90 //modified by NIZNHY-PKV Mon May 29 11:44:24 2006f
91 static  Standard_Integer bhole       (Draw_Interpretor& , Standard_Integer , const char** );
92 static  Standard_Integer bxhole      (Draw_Interpretor& , Standard_Integer , const char** );
93 //modified by NIZNHY-PKV Mon May 29 11:44:28 2006t
94
95 //=======================================================================
96 //function : LowCommands
97 //purpose  : 
98 //=======================================================================
99   void  BOPTest::LowCommands(Draw_Interpretor& theCommands)
100 {
101   static Standard_Boolean done = Standard_False;
102   if (done) return;
103   done = Standard_True;
104   // Chapter's name
105   const char* g = "CCR commands";
106   //
107   // Whether Edge has PCurve on Face
108   theCommands.Add("bhaspc"       , "Use >bhaspc Edge Face"    , __FILE__, bhaspc      , g);
109   theCommands.Add("baddve"       , "Use >addve  E V1 V2 p1 p2", __FILE__, baddve      , g);
110   theCommands.Add("bisclosed"    , "Use >bisclosed Edge Face" , __FILE__, bisclosed   , g);
111   theCommands.Add("bexplode"     , ""                         , __FILE__, bexplode    , g);
112   theCommands.Add("bupdateedge"  , "Use bupdateedge Edge Face", __FILE__, bupdateedge , g);
113   theCommands.Add("bremovesim"   , "Use bremovesim Face"      , __FILE__, bremovesim  , g);
114   theCommands.Add("bopsetdisp"   , "Use bopsetdisp"           , __FILE__, bopsetdisp  , g);
115   
116
117   theCommands.Add("bfaceprepare" , "Use bfaceprepare F1 "     , __FILE__, bfaceprepare, g);
118
119   theCommands.Add("brefine"      , "Use brefine Shape "       , __FILE__, brefine     , g);
120   theCommands.Add("bclassify"    , "Use >bclassify Solid Point [Tolerance=1.e-7]",
121                                                                 __FILE__, bclassify   , g);
122   theCommands.Add("b2dclassify"  , "Use >bclassify Face Point2d [Tol2D=Tol(Face)] ",
123                                                                 __FILE__, b2dclassify , g);
124   //modified by NIZNHY-PKV Mon May 29 11:45:33 2006f
125   theCommands.Add("bhole"   , "Use bhole"                     , __FILE__, bhole       , g);
126   theCommands.Add("bxhole"  , "Use bxhole"                    , __FILE__, bxhole      , g);
127   //modified by NIZNHY-PKV Mon May 29 11:45:37 2006t
128 }
129
130 //=======================================================================
131 //function : brefine
132 //purpose  : 
133 //=======================================================================
134 Standard_Integer  brefine (Draw_Interpretor& di,
135                            Standard_Integer n, 
136                            const char** a)
137 {
138   if (n<2) {
139     di << " Use >brefine Shape1\n";
140     return 1;
141   }
142
143   TopoDS_Shape aS = DBRep::Get(a[1]);
144  
145   
146   if (aS.IsNull()) {
147     di << " Null shape is not allowed \n";
148     return 1;
149   }
150
151   Standard_Boolean bIsDone;
152   BOP_Refiner aRefiner;
153   aRefiner.SetShape(aS);
154
155   aRefiner.Do();
156
157   bIsDone=aRefiner.IsDone();
158   
159   if (bIsDone) {
160     Standard_Integer aNbRemovedVertices, aNbRemovedEdges, iFlag=0;
161     aNbRemovedVertices=aRefiner.NbRemovedVertices();
162     aNbRemovedEdges=aRefiner.NbRemovedEdges();
163
164     if (aNbRemovedVertices) {
165       di << " Vertices removed=" << aNbRemovedVertices << "%d\n";
166       iFlag++;
167     }
168
169     if (aNbRemovedEdges) {
170       di << " Edges    removed=" << aNbRemovedEdges << "\n";
171       iFlag++;
172     }
173
174     // REFRESH
175     if (iFlag) {
176       TCollection_AsciiString aNm(a[1]);
177       Standard_CString pstr;
178       
179       pstr=aNm.ToCString();
180       DBRep::Set(pstr, aS);
181     }
182   }
183
184   else {
185     di << "Not Done, err=" << aRefiner.ErrorStatus() << "\n";
186   }
187   return 0;
188 }
189 //=======================================================================
190 //function : bfaceprepare
191 //purpose  : 
192 //=======================================================================
193 Standard_Integer  bfaceprepare(Draw_Interpretor& di, Standard_Integer n, const char** a)
194 {
195   if (n<2) {
196     di << " Use bfaceprepare> F1\n";
197     return 1;
198   }
199
200   TopoDS_Shape S1 = DBRep::Get(a[1]);
201  
202   
203   if (S1.IsNull()) {
204     di << " Null shape is not allowed \n";
205     return 1;
206   }
207   if (S1.ShapeType()!=TopAbs_FACE) {
208     di << " Type mismatch\n";
209     return 1;
210   }
211
212   const TopoDS_Face& aF1=TopoDS::Face(S1);
213
214   TopAbs_Orientation anOr;
215   anOr=aF1.Orientation();
216   if (anOr==TopAbs_FORWARD) {
217     return 0;
218   }
219   //
220   Standard_Real aTol;
221   TopoDS_Face newFace;
222   BRep_Builder aBB;
223   
224   Handle(Geom_Surface) aS1=BRep_Tool::Surface(aF1);
225   Handle(Geom_Surface) aS=Handle(Geom_Surface)::DownCast(aS1->Copy());
226   aS->VReverse();
227
228   aTol=BRep_Tool::Tolerance(aF1);
229
230   aBB.MakeFace (newFace, aS, aTol);
231
232   TopExp_Explorer anExp(aF1, TopAbs_WIRE);
233   for (; anExp.More(); anExp.Next()) {
234     const TopoDS_Shape& newWire=anExp.Current();
235     aBB.Add(newFace, newWire);
236   }
237
238   TCollection_AsciiString aNm(a[1]), aNmNew("_r");
239   aNm=aNm+aNmNew;
240   Standard_CString an=aNm.ToCString();
241   di << an << "\n";
242   DBRep::Set(an, newFace); 
243   return 0;
244 }
245 //=======================================================================
246 //function : bopsetdisp
247 //purpose  : 
248 //=======================================================================
249 Standard_Integer bopsetdisp (Draw_Interpretor& di, Standard_Integer , const char** )
250 {
251   Standard_Integer aFlag;
252   
253   char* xr=getenv("MDISP");
254   if (xr==NULL) {
255     aFlag=putenv((char*)"MDISP=yes");
256     di << " MDISP=yes. Return code=" << aFlag << "\n";
257   }
258   else if (!strcmp (xr, "yes")) {
259     aFlag=putenv((char*)"MDISP=no");
260     di << " MDISP=no. Return code=" << aFlag << "\n";
261   }
262   else {
263     aFlag=putenv((char*)"MDISP=yes");
264     di << " MDISP=yes. Return code=" << aFlag << "\n";
265   }
266   
267
268   return 0;
269 }
270 //=======================================================================
271 //function : bremovesim
272 //purpose  : 
273 //=======================================================================
274 Standard_Integer bremovesim (Draw_Interpretor& di, Standard_Integer n, const char** a)
275 {
276   if (n<2) {
277     di << " Use bremovesim> Face\n";
278     return 1;
279   }
280
281   TopoDS_Shape S1 = DBRep::Get(a[1]);
282  
283   
284   if (S1.IsNull()) {
285     di << " Null shapes are not allowed \n";
286     return 1;
287   }
288   if (S1.ShapeType()!=TopAbs_FACE) {
289     di << " Type mismatch\n";
290     return 1;
291   }
292   
293
294   const TopoDS_Face& aF=TopoDS::Face(S1);
295   //
296   IntTools_Context aCtx;
297   BOPTools_Tools3D::RemoveSims (aF, aCtx);
298   //
299   di << " Ok\n";
300   return 0;
301 }
302 //=======================================================================
303 //function : bupdateedge
304 //purpose  : 
305 //=======================================================================
306 Standard_Integer bupdateedge (Draw_Interpretor& di, Standard_Integer n, const char** a)
307 {
308   if (n<3) {
309     di << " Use bupdateedge> Edge Face\n";
310     return 1;
311   }
312
313   TopoDS_Shape S1 = DBRep::Get(a[1]);
314   TopoDS_Shape S2 = DBRep::Get(a[2]);
315   
316   if (S1.IsNull() || S2.IsNull()) {
317     di << " Null shapes are not allowed \n";
318     return 1;
319   }
320   if (S1.ShapeType()!=TopAbs_EDGE || S2.ShapeType()!=TopAbs_FACE) {
321     di << " Type mismatch\n";
322     return 1;
323   }
324   
325   const TopoDS_Edge& aE=TopoDS::Edge(S1);
326   const TopoDS_Face& aF=TopoDS::Face(S2);
327   Handle(Geom2d_Curve) aC2D;
328
329   Standard_Real aTol;
330   aTol=BRep_Tool::Tolerance(aE);
331   BRep_Builder BB;
332   BB.UpdateEdge(aE, aC2D, aF, aTol);
333   di << " Ok\n";
334   return 0;
335 }
336
337 //=======================================================================
338 //function : bisclosed
339 //purpose  : 
340 //=======================================================================
341 Standard_Integer bisclosed (Draw_Interpretor& di, Standard_Integer n, const char** a)
342 {
343   if (n<3) {
344     di << " Use bisclosed> Edge Face\n";
345     return 1;
346   }
347
348   TopoDS_Shape S1 = DBRep::Get(a[1]);
349   TopoDS_Shape S2 = DBRep::Get(a[2]);
350   
351   if (S1.IsNull() || S2.IsNull()) {
352     di << " Null shapes are not allowed \n";
353     return 1;
354   }
355   if (S1.ShapeType()!=TopAbs_EDGE || S2.ShapeType()!=TopAbs_FACE) {
356     di << " Type mismatch\n";
357     return 1;
358   }
359   
360   const TopoDS_Edge& aE=TopoDS::Edge(S1);
361   const TopoDS_Face& aF=TopoDS::Face(S2);
362
363   Standard_Boolean anIsClosed;
364   anIsClosed=BRep_Tool::IsClosed(aE, aF); 
365
366   if (!anIsClosed) {
367     di << " Edge is not closed on this face\n";
368   }
369   else {
370     di << " Edge is closed on this face\n";
371   }
372   return 0;
373 }
374
375 //=======================================================================
376 //function : bhaspc
377 //purpose  : 
378 //=======================================================================
379 Standard_Integer bhaspc (Draw_Interpretor& di, Standard_Integer n, const char** a)
380 {
381   if (n<3) {
382     di << " Use bhaspc> Edge Face [do]\n";
383     return 1;
384   }
385
386   TopoDS_Shape S1 = DBRep::Get(a[1]);
387   TopoDS_Shape S2 = DBRep::Get(a[2]);
388   
389   if (S1.IsNull() || S2.IsNull()) {
390     di << " Null shapes are not allowed \n";
391     return 1;
392   }
393   if (S1.ShapeType()!=TopAbs_EDGE || S2.ShapeType()!=TopAbs_FACE) {
394     di << " Type mismatch\n";
395     return 1;
396   }
397
398   const TopoDS_Edge& aE=TopoDS::Edge(S1);
399   const TopoDS_Face& aF=TopoDS::Face(S2);
400   Standard_Real f2D, l2D; 
401
402   Handle(Geom2d_Curve) C2D=CurveOnSurface(aE, aF, f2D, l2D);
403   
404   if (C2D.IsNull()) {
405     di << " No 2D Curves detected\n";
406   }
407   else {
408     di << " Ok Edge has P-Curve on this Face\n";
409   }
410   
411   if (n==4) {
412     if (!strcmp(a[3], "do")) {
413       BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF);  
414     }
415   }
416
417   return 0;
418 }
419   
420 //=======================================================================
421 //function : baddve
422 //purpose  : 
423 //=======================================================================
424 Standard_Integer baddve (Draw_Interpretor& di, Standard_Integer n, const char** a)
425 {
426   if (n<6) {
427     di << " Use baddve> E V1 V2 p1 p2\n";
428     return 1;
429   }
430
431   TopoDS_Shape S1 = DBRep::Get(a[1]);
432   TopoDS_Shape S2 = DBRep::Get(a[2]);
433   TopoDS_Shape S3 = DBRep::Get(a[3]);
434   if (S1.IsNull() || S2.IsNull() || S3.IsNull()) {
435     di << " Null shapes are not allowed \n";
436     return 1;
437   }
438
439   if (S1.ShapeType()!=TopAbs_EDGE || 
440       S2.ShapeType()!=TopAbs_VERTEX ||
441       S3.ShapeType()!=TopAbs_VERTEX ) {
442     di << " Type mismatch\n";
443     return 1;
444   }
445   const TopoDS_Edge& aE=TopoDS::Edge(S1);
446   const TopoDS_Vertex& aV1=TopoDS::Vertex(S2);
447   const TopoDS_Vertex& aV2=TopoDS::Vertex(S3);
448
449
450   Standard_Real p1, p2;
451   p1=atof(a[4]);
452   p2=atof(a[5]);
453   
454   TopoDS_Edge E=aE;
455   E.EmptyCopy();
456
457   BRep_Builder BB;
458   BB.Add  (E, aV1);
459   BB.Add  (E, aV2);
460   BB.Range(E, p1, p2);
461
462   DBRep::Set("ne", E);
463   return 0;
464 }
465
466 static Handle(Geom2d_Curve) nullPCurve;
467 //=======================================================================
468 //function : CurveOnSurface
469 //purpose  : 
470 //=======================================================================
471 Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E, 
472                                     const TopoDS_Face& F,
473                                     Standard_Real& First,
474                                     Standard_Real& Last)
475 {
476   TopLoc_Location l;
477   const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
478   TopoDS_Edge aLocalEdge = E;
479   if (F.Orientation() == TopAbs_REVERSED) {
480     aLocalEdge.Reverse();
481   }
482   return CurveOnSurface(aLocalEdge,S,l,First,Last);
483 }
484
485 //=======================================================================
486 //function : CurveOnSurface
487 //purpose  : 
488 //=======================================================================
489 Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E, 
490                                     const Handle(Geom_Surface)& S,
491                                     const TopLoc_Location& L,
492                                     Standard_Real& First,
493                                     Standard_Real& Last)
494 {
495   TopLoc_Location l = L.Predivided(E.Location());
496   Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
497
498   // find the representation
499   BRep_ListIteratorOfListOfCurveRepresentation itcr
500     ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
501
502   while (itcr.More()) {
503     const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
504     if (cr->IsCurveOnSurface(S,l)) {
505       const Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr);
506       GC->Range(First,Last);
507       if (GC->IsCurveOnClosedSurface() && Eisreversed)
508         return GC->PCurve2();
509       else
510         return GC->PCurve();
511     }
512     itcr.Next();
513   }
514   return nullPCurve;
515 }
516
517 //=======================================================================
518 //function : bexplode
519 //purpose  : 
520 //=======================================================================
521 static Standard_Integer bexplode(Draw_Interpretor& di,
522                                  Standard_Integer n, 
523                                  const char** a)
524 {
525   if (n <= 1) return 1;
526   TopoDS_Shape S = DBRep::Get(a[1]);
527   if (S.IsNull()) return 0;
528   char newname[1024];
529   strcpy(newname,a[1]);
530   char* p = newname;
531   while (*p != '\0') p++;
532   *p = '_';
533   p++;
534   Standard_Integer i = 0;
535   if (n == 2) {
536     TopoDS_Iterator itr(S);
537     while (itr.More()) {
538       i++;
539       sprintf(p,"%d",i);
540       DBRep::Set(newname,itr.Value());
541       di.AppendElement(newname);
542       itr.Next();
543     }
544   }
545   else {
546     // explode a type
547     TopAbs_ShapeEnum typ;
548     switch (a[2][0]) {
549       
550     case 'C' :
551     case 'c' :
552       if ((a[2][1] == 'd')||(a[2][1] == 'D')) 
553         typ = TopAbs_COMPOUND;
554       else
555         typ = TopAbs_COMPSOLID;
556       break;
557       
558     case 'S' :
559     case 's' :
560       if ((a[2][1] == 'O')||(a[2][1] == 'o')) 
561         typ = TopAbs_SOLID;
562       else if ((a[2][1] == 'H')||(a[2][1] == 'h')) 
563         typ = TopAbs_SHELL;
564       else
565         return 1;
566       break;
567       
568     case 'F' :
569     case 'f' :
570       typ = TopAbs_FACE;
571       break;
572       
573     case 'W' :
574     case 'w' :
575       typ = TopAbs_WIRE;
576       break;
577       
578     case 'E' :
579     case 'e' :
580       typ = TopAbs_EDGE;
581       break;
582       
583     case 'V' :
584     case 'v' :
585       typ = TopAbs_VERTEX;
586       break;
587       
588       default :
589         return 1;
590     }
591     
592     
593     TopExp_Explorer ex(S,typ);
594     for (; ex.More(); ex.Next()) {
595       const TopoDS_Shape& aS = ex.Current();
596       i++;
597       sprintf(p,"%d",i);
598       DBRep::Set(newname,aS);
599       di.AppendElement(newname);
600     }
601   }
602   return 0;
603 }
604
605 //=======================================================================
606 //function : bclassify
607 //purpose  : 
608 //=======================================================================
609 Standard_Integer bclassify (Draw_Interpretor& aDI,
610                             Standard_Integer n, 
611                             const char** a)
612 {
613   char sbf[512];        
614   
615   if (n < 3) {
616     sprintf(sbf, " Use >bclassify Solid Point [Tolerance=1.e-7]\n");
617     aDI<<sbf;
618     return 1;
619   }
620   
621   TopoDS_Shape aS = DBRep::Get(a[1]);
622   if (aS.IsNull()) {
623     sprintf(sbf, " Null Shape is not allowed here\n");
624     aDI<<sbf;
625     return 1;
626   }
627   
628   if (aS.ShapeType()!=TopAbs_SOLID) {
629     sprintf(sbf, " Shape type must be SOLID\n");
630     aDI<<sbf;
631     return 1;
632   }
633   //
634   Standard_Real aTol=1.e-7;
635   TopAbs_State aState = TopAbs_UNKNOWN;
636   gp_Pnt aP(8., 9., 10.);
637   
638   DrawTrSurf::GetPoint(a[2], aP);
639   
640   aTol=1.e-7; 
641   if (n==4) {
642     aTol=atof(a[3]);
643   }
644   //
645   BRepClass3d_SolidClassifier aSC(aS);
646   aSC.Perform(aP,aTol);
647   //
648   aState = aSC.State();
649   //
650   PrintState (aDI, aState);
651   //
652   return 0;
653 }
654 //
655 //=======================================================================
656 //function : b2dclassify
657 //purpose  : 
658 //=======================================================================
659 Standard_Integer b2dclassify (Draw_Interpretor& aDI,
660                               Standard_Integer n, 
661                               const char** a)
662 {
663   char sbf[512];        
664   
665   if (n < 3) {
666     sprintf(sbf, " Use >bclassify Face Point2d [Tol2D=Tol(Face)]\n");
667     aDI<<sbf;
668     return 1;
669   }
670   
671   TopoDS_Shape aS = DBRep::Get(a[1]);
672   if (aS.IsNull()) {
673     sprintf(sbf, " Null Shape is not allowed here\n");
674     aDI<<sbf;
675     return 1;
676   }
677   
678   if (aS.ShapeType()!=TopAbs_FACE) {
679     sprintf(sbf, " Shape type must be FACE\n");
680     aDI<<sbf;
681     return 1;
682   }
683   //
684   Standard_Real aTol;
685   TopAbs_State aState = TopAbs_UNKNOWN;
686   gp_Pnt2d aP(8., 9.);
687   
688   DrawTrSurf::GetPoint2d(a[2], aP);
689   
690   const TopoDS_Face& aF=TopoDS::Face(aS);
691   aTol=BRep_Tool::Tolerance(aF); 
692   if (n==4) {
693     aTol=atof(a[3]);
694   }
695   //
696   BRepClass_FaceClassifier aClassifier;
697   aClassifier.Perform(aF, aP, aTol);
698   //
699   aState = aClassifier.State();
700   //
701   PrintState (aDI, aState);
702   //
703   return 0;
704 }
705 //=======================================================================
706 //function : PrintState
707 //purpose  : 
708 //=======================================================================
709 void PrintState (Draw_Interpretor& aDI,
710                  const TopAbs_State& aState)
711 {
712   char sbf[512];        
713   TCollection_AsciiString sIN("IN"), sOUT("OUT of"), sON("ON"), sUNKNOWN("UNKNOWN"); 
714   //
715   sprintf(sbf, "The point is "); aDI<<sbf;
716   //
717   switch (aState) {
718   case TopAbs_IN:               
719     sprintf(sbf, sIN.ToCString());
720     break;
721   case TopAbs_OUT:              
722     sprintf(sbf, sOUT.ToCString());
723     break;
724   case TopAbs_ON:               
725     sprintf(sbf, sON.ToCString());
726     break;
727   case TopAbs_UNKNOWN:          
728     sprintf(sbf, sUNKNOWN.ToCString());
729     break;
730   default:
731     sprintf(sbf, sUNKNOWN.ToCString()); 
732     break;
733   }
734   aDI<<sbf; 
735         //
736   sprintf(sbf, " shape\n");
737   aDI<<sbf;
738   
739 }
740 //
741 //modified by NIZNHY-PKV Mon May 29 11:40:29 2006f
742 //=======================================================================
743 //function : bhole
744 //purpose  : 
745 //=======================================================================
746 Standard_Integer bhole (Draw_Interpretor& aDI,
747                         Standard_Integer n, 
748                         const char** a)
749 {
750   char sbf[512];        
751   
752   if (n!=2) {
753     sprintf(sbf, " Use bhole Face\n");
754     aDI<<sbf;
755     return 1;
756   }
757   
758   TopoDS_Shape aS = DBRep::Get(a[1]);
759   if (aS.IsNull()) {
760     sprintf(sbf, " Null Shape is not allowed here\n");
761     aDI<<sbf;
762     return 1;
763   }
764   
765   if (aS.ShapeType()!=TopAbs_FACE) {
766     sprintf(sbf, " Shape type must be FACE\n");
767     aDI<<sbf;
768     return 1;
769   }
770   //
771   Standard_Boolean bIsHole;
772   Standard_Real aTol=1.e-7;
773   IntTools_FClass2d aFClass2d;
774   //
775   const TopoDS_Face& aF=TopoDS::Face(aS);
776   aTol=BRep_Tool::Tolerance(aF); 
777   //
778   aFClass2d.Init(aF, aTol);
779   //
780   bIsHole=aFClass2d.IsHole();
781   printf(" bIsHole=%d\n", bIsHole);
782   //
783   return 0;
784 }
785 //
786
787
788 //
789 //=======================================================================
790 //class : X_Chr
791 //purpose  : 
792 //=======================================================================
793 class X_Chr {
794  public:
795 //  X_Chr::X_Chr() {
796   X_Chr() {
797     Reset();
798   }
799   void Reset() {
800     myTime=0.;
801     myCnt=0;
802   }
803   void Start() {
804     myChronometer.Reset();
805     myChronometer.Start();
806   }
807   void Stop() {
808     Standard_Real aTime;
809     //
810     myChronometer.Stop();
811     myChronometer.Show(aTime);
812     myTime=myTime+aTime;
813     ++myCnt;
814   }
815   void Show(const char *pComment) {
816     printf("  Tps: %7.2lf\tCnt: %d\tfor %s\n", myTime, myCnt, pComment);
817   }
818   
819  protected:
820   Standard_Real myTime;
821   Standard_Integer myCnt;
822   OSD_Chronometer myChronometer;
823   
824 };
825
826 //
827 //=======================================================================
828 //function : bxhole
829 //purpose  : 
830 //=======================================================================
831 Standard_Integer bxhole (Draw_Interpretor& aDI,
832                          Standard_Integer n, 
833                          const char** a)
834 {
835   char sbf[512];        
836   Standard_Integer aNbIter;
837   //
838   if (n!=3) {
839     sprintf(sbf, " Use bxhole Face NbIter\n");
840     aDI<<sbf;
841     return 1;
842   }
843   
844   TopoDS_Shape aS = DBRep::Get(a[1]);
845   if (aS.IsNull()) {
846     sprintf(sbf, " Null Shape is not allowed here\n");
847     aDI<<sbf;
848     return 1;
849   }
850   if (aS.ShapeType()!=TopAbs_FACE) {
851     sprintf(sbf, " Shape type must be FACE\n");
852     aDI<<sbf;
853     return 1;
854   }
855   //
856   aNbIter=atoi(a[2]);
857   if (aNbIter<1) {
858     aNbIter=1;
859   }
860   //
861   Standard_Integer i;
862   Standard_Boolean bIsHole;
863   Standard_Real aTol, aUMin, aUMax, aVMin, aVMax;
864   gp_Pnt2d aP2DInf;
865   TopAbs_State aState;
866   X_Chr aChr;
867   //
868   aTol=1.e-7;
869   const TopoDS_Face& aF=TopoDS::Face(aS);
870   aTol=BRep_Tool::Tolerance(aF); 
871   //
872   BRepTools::UVBounds(aF, aUMin, aUMax, aVMin, aVMax);
873   aP2DInf.SetCoord(aUMin, aVMin);
874   //
875   // 1. New
876   aChr.Reset();
877   aChr.Start();
878   for (i=1; i<=aNbIter; ++i) {
879     IntTools_FClass2d aFClass2d;
880     //
881     aFClass2d.Init(aF, aTol);
882     //
883     bIsHole=aFClass2d.IsHole();
884   }
885   aChr.Stop();
886   aChr.Show(" new");
887   printf(" new bIsHole=%d\n", bIsHole);
888   //``````````````````````````````````````````
889   aChr.Reset();
890   aChr.Start();
891   for (i=1; i<=aNbIter; ++i) {
892     IntTools_FClass2d aFClass2d;
893     //
894     aFClass2d.Init(aF, aTol);
895     //
896     aState=aFClass2d.Perform(aP2DInf);
897     bIsHole=(aState==TopAbs_IN);
898   }
899   aChr.Stop();
900   aChr.Show(" was");
901   printf(" was bIsHole=%d\n", bIsHole);
902   //
903   return 0;
904 }
905 //modified by NIZNHY-PKV Mon May 29 11:40:31 2006t