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