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