0028162: Draw Harness - eliminate usage of deprecated Local Context
[occt.git] / src / QABugs / QABugs_17.cxx
1 // Created on: 2002-03-18
2 // Created by: QA Admin
3 // Copyright (c) 2002-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <stdio.h>
17
18 #include <QABugs.hxx>
19
20 #include <Draw.hxx>
21 #include <Draw_Interpretor.hxx>
22 #include <DBRep.hxx>
23 #include <DrawTrSurf.hxx>
24 #include <AIS_InteractiveContext.hxx>
25 #include <ViewerTest.hxx>
26 #include <ViewerTest_EventManager.hxx>
27 #include <AIS_Shape.hxx>
28 #include <TopoDS_Shape.hxx>
29
30 #include <Geom_Circle.hxx>
31 #include <Geom_Ellipse.hxx>
32 #include <Geom_Plane.hxx>
33 #include <Geom_BSplineSurface.hxx>
34 #include <gp_Pln.hxx>
35 #include <Geom2d_Curve.hxx>
36 #include <GeomAPI.hxx>
37 #include <Geom2dAdaptor_Curve.hxx>
38 #include <Geom2dGcc_QualifiedCurve.hxx>
39 #include <Geom2dGcc_Lin2d2Tan.hxx>
40 #include <Geom2d_Line.hxx>
41 #include <BRepBuilderAPI_MakeEdge.hxx>
42 #include <TopoDS_Edge.hxx>
43 #include <Precision.hxx>
44 #include <Geom2d_Circle.hxx>
45 #include <Geom2dGcc_QCurve.hxx>
46 #include <GccEnt_QualifiedCirc.hxx>
47 #include <Geom2dGcc_Lin2d2TanIter.hxx>
48 #include <BRepBuilderAPI_MakeWire.hxx>
49 #include <TopExp_Explorer.hxx>
50 #include <TopoDS.hxx>
51 #include <TopoDS_Wire.hxx>
52 #include <BRep_Tool.hxx>
53 #include <gp_Circ.hxx>
54 #include <BRepOffsetAPI_MakePipeShell.hxx>
55 #include <AIS_Trihedron.hxx>
56 #include <Geom_Axis2Placement.hxx>
57 #include <V3d_View.hxx>
58 #include <BRepBuilderAPI_MakeVertex.hxx>
59 #include <AIS_LengthDimension.hxx>
60 #include <AIS_RadiusDimension.hxx>
61 #include <BRepPrimAPI_MakeBox.hxx>
62 #include <GeomAdaptor_Surface.hxx>
63 #include <Extrema_ExtPS.hxx>
64 #include <Geom_CartesianPoint.hxx>
65 #include <Geom2d_CartesianPoint.hxx>
66 #include <Geom2dGcc_Circ2d3Tan.hxx>
67 #include <Aspect_Window.hxx>
68
69 #include <TopoDS_Compound.hxx>
70 #include <TopoDS_CompSolid.hxx>
71 #include <StdSelect_ShapeTypeFilter.hxx>
72 #include <Prs3d_Projector.hxx>
73 #include <HLRAlgo_Projector.hxx>
74 #include <Standard_ErrorHandler.hxx>
75 #include <Font_NameOfFont.hxx>
76
77 static Standard_Integer BUC60842 (Draw_Interpretor& di, Standard_Integer /*argc*/,const char ** /*argv*/)
78 {
79   Standard_Character abuf[16];
80   //Standard_Character * abuf = new Standard_Character[16];
81
82   Standard_CString st = abuf;
83
84   Handle(Geom_Circle) cir = new Geom_Circle (gp_Ax2 (gp_Pnt (823.687192, 502.366825, 478.960440), gp_Dir (0.173648, 0.984808, 0.000000), gp_Dir (-0.932169, 0.164367, -0.322560)), 50);
85   Handle(Geom_Ellipse) ell = new Geom_Ellipse (gp_Ax2 (gp_Pnt (1262.224429, 425.040878, 363.609716), gp_Dir (0.173648, 0.984808, 0.000000), gp_Dir (-0.932169, 0.164367, -0.322560)), 150, 100);
86   Handle(Geom_Plane) plne = new Geom_Plane (gp_Ax3 (gp_Ax2 (gp_Pnt (1262.224429, 425.040878, 363.609716), gp_Dir (0.173648, 0.984808, 0.000000), gp_Dir (-0.932169, 0.164367, -0.322560))));
87
88   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
89
90   gp_Pln pln = plne->Pln();
91   Handle(Geom2d_Curve) curve2d = GeomAPI::To2d (ell, pln);
92   Sprintf(abuf,"ell");
93   DrawTrSurf::Set(st,curve2d);
94   if(!aContext.IsNull()) {
95     Handle(AIS_Shape) aisp = 
96       new AIS_Shape (BRepBuilderAPI_MakeEdge(GeomAPI::To3d(curve2d, pln)).Edge());
97     aContext->Display (aisp);
98   }
99
100   Handle(Geom2d_Curve) fromcurve2d = GeomAPI::To2d (cir, pln);
101   Sprintf(abuf,"cil");
102   DrawTrSurf::Set(st,fromcurve2d);
103   if(!aContext.IsNull()) {
104     Handle(AIS_Shape) aisp = 
105       new AIS_Shape (BRepBuilderAPI_MakeEdge(GeomAPI::To3d(fromcurve2d, pln)).Edge());
106     aContext->Display (aisp);
107   }
108
109   Geom2dAdaptor_Curve acur (curve2d), afromcur (fromcurve2d);
110   Geom2dGcc_QualifiedCurve qcur (acur, GccEnt_outside);
111   Geom2dGcc_QualifiedCurve qfromcur (afromcur, GccEnt_outside);
112   Geom2dGcc_Lin2d2Tan lintan (qcur, qfromcur, 0.1, 0.0, 0.0);
113   Standard_Integer i=0;
114   for(i=0;i<lintan.NbSolutions();i++) {
115     Sprintf(abuf,"lintan_%d",i);
116     Handle(Geom2d_Line) glin = new Geom2d_Line(lintan.ThisSolution(i));
117     DrawTrSurf::Set(st,glin);
118     if(!aContext.IsNull()) {
119       Handle(AIS_Shape) aisp = 
120         new AIS_Shape (BRepBuilderAPI_MakeEdge(GeomAPI::To3d(glin, pln)).Edge());      aContext->Display (aisp);
121     }
122   }
123   di << " Is Done = \n" << (Standard_Integer) lintan.IsDone();
124   return 0;
125 }
126
127 static Standard_Integer BUC60843 (Draw_Interpretor& di, Standard_Integer argc,const char ** argv)
128 {
129   if (argc != 4 && argc != 5 && argc != 6 && argc != 7) {
130     di << "Usage : " << argv[0] << "result_shape name_of_circle name_of_curve [ par1 [ tol ] ]\n";
131     return 1;
132   }
133
134   Standard_Real par1 = 0.0, par2 = 0.0;
135   Standard_Real tol  = Precision::Angular();
136   if (argc >= 5)
137     par1 = Draw::Atof(argv[4]);
138   if (argc == 6)
139     par2 = Draw::Atof(argv[5]);
140   if (argc == 7)
141     tol = Draw::Atof(argv[6]);
142   Handle(Geom2d_Curve)  aCur2d1 = DrawTrSurf::GetCurve2d(argv[2]);
143   Handle(Geom2d_Curve)  aCur2d2 = DrawTrSurf::GetCurve2d(argv[3]);
144   if (aCur2d1.IsNull() || aCur2d2.IsNull()) {
145     di << "Faulty : not curves\n";
146     return 1;
147   }
148   Standard_Boolean c1IsCircle = Standard_False;
149   Handle(Geom2d_Circle) aCir2d = Handle(Geom2d_Circle)::DownCast(aCur2d1);
150   if (!aCir2d.IsNull()) {
151     c1IsCircle = Standard_True;
152     if (argc == 6) tol = Draw::Atof(argv[5]);
153   }
154   if(c1IsCircle) {
155     Geom2dAdaptor_Curve acur(aCur2d2);
156     Geom2dGcc_QCurve qcur(acur, GccEnt_unqualified);
157     GccEnt_QualifiedCirc qfromcur(aCir2d->Circ2d(), GccEnt_unqualified);
158     Geom2dGcc_Lin2d2TanIter lintan(qfromcur, qcur , par1, tol); 
159     if (lintan.IsDone()) {
160       gp_Lin2d lin = lintan.ThisSolution(); 
161       Handle(Geom2d_Line) glin = new Geom2d_Line(lin); 
162       DrawTrSurf::Set(argv[1], glin);
163     } else {
164       di << "Faulty : tangent line is not done.\n";
165     }
166   }
167   else {
168     Geom2dAdaptor_Curve acur1(aCur2d1);
169     Geom2dAdaptor_Curve acur2(aCur2d2);
170     Geom2dGcc_QCurve qcur1(acur1, GccEnt_unqualified);
171     Geom2dGcc_QCurve qcur2(acur2, GccEnt_unqualified);
172     Geom2dGcc_Lin2d2TanIter lintan(qcur1, qcur2 , par1, par2, tol); 
173     if (lintan.IsDone()) {
174       gp_Lin2d lin = lintan.ThisSolution(); 
175       Handle(Geom2d_Line) glin = new Geom2d_Line(lin); 
176       DrawTrSurf::Set(argv[1], glin);
177     } else {
178       di << "Faulty : tangent line is not done.\n";
179     }
180   }   
181   return 0;
182 }
183
184 static Standard_Integer BUC60970 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
185 {
186   if(argc!=3)
187   {
188     di << "Usage : " << argv[0] << " shape result\n";
189     return 1;
190   }
191
192   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
193   if(aContext.IsNull()) {
194     di << "use 'vinit' command before " << argv[0] << "\n";
195     return 1;
196   }
197
198   TopoDS_Shape aResult = DBRep::Get(argv[1]);
199
200   BRepBuilderAPI_MakeWire bRepSpineWire; 
201   TopExp_Explorer exp_(aResult, TopAbs_WIRE); 
202
203   Standard_Integer i = 0; 
204   for(;exp_.More();exp_.Next()){     
205     i++; 
206     bRepSpineWire.Add(TopoDS::Wire(exp_.Current())); 
207   } 
208
209   //printf("total no of wires are ............. %d\n", i); 
210   di << "total no of wires are ............. " << i << "\n"; 
211
212   TopoDS_Wire spineWire = bRepSpineWire.Wire(); 
213   aContext->Display(new AIS_Shape(spineWire)); 
214
215   DBRep::Set("slineW",spineWire);
216
217   TopExp_Explorer spineWireExp(spineWire, TopAbs_EDGE); 
218   Standard_Real first, last; 
219   Handle(Geom_Curve) curl_ = BRep_Tool::Curve(TopoDS::Edge(spineWireExp.Current()), first, last); 
220   gp_Pnt firstPnt; 
221   gp_Vec tanVec; 
222   curl_->D1(first, firstPnt, tanVec); 
223   tanVec.Normalize(); 
224   gp_Dir tanDir(tanVec.X(), tanVec.Y(), tanVec.Z()); 
225   gp_Ax2 gpAx2(firstPnt, tanDir); 
226   gp_Circ gpCirc(gpAx2, 2.5); 
227   BRepBuilderAPI_MakeWire aMWire(BRepBuilderAPI_MakeEdge(new Geom_Circle(gpCirc)).Edge());
228   TopoDS_Wire topoWire(aMWire); 
229   aContext->Display(new AIS_Shape(topoWire));
230
231   DBRep::Set("topoW",topoWire);
232
233   BRepOffsetAPI_MakePipeShell bRepPipe(spineWire);
234   bRepPipe.Add(topoWire); 
235   bRepPipe.Build(); 
236
237   aContext->Display(new AIS_Shape(bRepPipe.Shape())); 
238
239   DBRep::Set(argv[2],bRepPipe.Shape());
240
241   return 0;
242 }
243
244 static Standard_Integer  BUC60818(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
245 {
246   if(argc!=1)
247   {
248     di << "Usage : " << argv[0] << "\n";
249     return -1;
250   }
251
252   Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
253   if(myAISContext.IsNull()) 
254   {
255     di << "use 'vinit' command before " << argv[0] << "\n";
256     return -1;
257   }
258
259   // TRIHEDRON
260   Handle(AIS_Trihedron) aTrihedron;
261   Handle(Geom_Axis2Placement) aTrihedronAxis=new Geom_Axis2Placement(gp::XOY());
262   aTrihedron=new AIS_Trihedron(aTrihedronAxis);
263   myAISContext->Display(aTrihedron);
264
265   Standard_DISABLE_DEPRECATION_WARNINGS
266   myAISContext->OpenLocalContext(); 
267   Standard_ENABLE_DEPRECATION_WARNINGS
268   myAISContext->Load(aTrihedron,0); 
269
270   myAISContext->SetAutomaticHilight(  Standard_False );
271
272   Handle(V3d_View) myV3dView = ViewerTest::CurrentView();
273   double Xv,Yv;
274   myV3dView->Project(0,0,0,Xv,Yv);
275
276   Standard_Integer Xp,Yp;
277   myV3dView->Convert(Xv,Yv,Xp,Yp);
278
279   myAISContext->MoveTo( Xp,Yp, myV3dView  );
280   myAISContext->MoveTo( Xp,Yp, myV3dView  );
281
282   if (myAISContext->HasDetected(  )) 
283     di << "has detected shape : OK"   << "\n";
284   else       di << "has detected shape : bugged - Faulty "   << "\n";
285
286   myAISContext->SetAutomaticHilight(  Standard_True );
287
288   return 0;
289 }
290
291 static Standard_Integer BUC60915_1(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
292 {
293   if (argc > 1) {
294     di<<"Function don't has parameters\n";
295     return 1;
296   }
297
298   if(ViewerTest::GetAISContext().IsNull())
299   {
300     di << "View was not created. Use 'vinit' command before "
301        << argv[0] << "\n";
302     return 1;
303   }
304   Handle(AIS_InteractiveContext) context = ViewerTest::GetAISContext();
305
306   //The following dimesion code has problems regarding arrow_size. The desired effect is not produced.
307   /***************************************/
308   //First view
309   /***************************************/
310   gp_Pnt p1 = gp_Pnt(602.51,50.,0.);
311   gp_Pnt p2 = gp_Pnt(602.51,200.,0.);
312   gp_Pnt p3 = gp_Pnt(102.51,200.,0.);
313   gp_Pnt p4 = gp_Pnt(102.51,170.,0.);
314   gp_Pnt p5 = gp_Pnt(502.51,170.,0.);
315   gp_Pnt p6 = gp_Pnt(502.51,80.,0.);
316   gp_Pnt p7 = gp_Pnt(102.51,80.,0.);
317   gp_Pnt p8 = gp_Pnt(102.51,50.,0.);
318   TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(p1);
319   TopoDS_Vertex V2 = BRepBuilderAPI_MakeVertex(p2);
320   TopoDS_Vertex V3 = BRepBuilderAPI_MakeVertex(p3);
321   TopoDS_Vertex V4 = BRepBuilderAPI_MakeVertex(p4);
322   TopoDS_Vertex V5 = BRepBuilderAPI_MakeVertex(p5);
323   TopoDS_Vertex V6 = BRepBuilderAPI_MakeVertex(p6);
324   TopoDS_Vertex V7 = BRepBuilderAPI_MakeVertex(p7);
325   TopoDS_Vertex V8 = BRepBuilderAPI_MakeVertex(p8);
326   gp_Pnt plnpt(0, 0, 0);
327   gp_Dir plndir(0, 0, 1);
328   Handle(Geom_Plane) pln = new Geom_Plane(plnpt,plndir);
329   Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
330   anAspect->MakeArrows3d (Standard_True);
331   anAspect->ArrowAspect()->SetAngle (M_PI/180.0 * 10.0);
332   /***************************************/
333   //dimension "L 502.51"
334   /***************************************/
335   Handle(AIS_LengthDimension) len = new AIS_LengthDimension(V2, V3, pln->Pln());
336   anAspect->ArrowAspect()->SetLength (30.0);
337   len->SetDimensionAspect (anAspect);
338   context->Display(len);
339   /***************************************/
340   //dimension "L 90"
341   /***************************************/
342   Handle(AIS_LengthDimension) len1 = new AIS_LengthDimension(V7, V4, pln->Pln());
343   len1->SetDimensionAspect (anAspect);
344   len1->SetFlyout (30.0);
345   anAspect->ArrowAspect()->SetLength (100.0);
346   context->Display(len1);
347   /***************************************/
348   //dimension "L 150"
349   /***************************************/
350   Handle(AIS_LengthDimension) len2 = new AIS_LengthDimension(V1, V2, pln->Pln());
351   len2->SetDimensionAspect (anAspect);
352   context->Display(len2);
353   /***************************************/
354   //dimension "R 88.58"
355   /***************************************/
356   gp_Circ cir = gp_Circ(gp_Ax2(gp_Pnt(191.09, -88.58, 0), gp_Dir(0, 0, 1)), 88.58);
357   TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(cir,gp_Pnt(191.09,0,0.),gp_Pnt(191.09,-177.16,0.) );
358   Handle(AIS_RadiusDimension) dim1 = new AIS_RadiusDimension(E1);
359   dim1->SetDimensionAspect (anAspect);
360   context->Display(dim1);
361   /***************************************/
362   //dimension "R 43.80"
363   /***************************************/
364   gp_Circ cir1 = gp_Circ(gp_Ax2(gp_Pnt(191.09, -88.58, 0), gp_Dir(0, 0, 1)), 43.80);
365   TopoDS_Edge E_cir1 = BRepBuilderAPI_MakeEdge(cir1);
366   dim1 = new AIS_RadiusDimension(E_cir1);
367   anAspect->ArrowAspect()->SetLength (60.0);
368   dim1->SetDimensionAspect (anAspect);
369   context->Display(dim1);
370   /***************************************/
371   //dimension "R 17.86"
372   /***************************************/
373   gp_Circ cir2 = gp_Circ(gp_Ax2(gp_Pnt(566.11, -88.58, 0), gp_Dir(0, 0, -1)), 17.86);
374   TopoDS_Edge E_cir2 = BRepBuilderAPI_MakeEdge(cir2);
375   dim1 = new AIS_RadiusDimension(E_cir2);
376   anAspect->ArrowAspect()->SetLength (40.0);
377   dim1->SetDimensionAspect (anAspect);
378   context->Display(dim1);
379
380   return 0;
381 }
382
383 static Standard_Integer  OCC138 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv)
384 {
385   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
386   if(aContext.IsNull()) { 
387     di << "use 'vinit' command before " << argv[0] << "\n";
388     return 1;
389   }
390
391   BRepPrimAPI_MakeBox box1(gp_Pnt(0, 0, 0),  gp_Pnt(100, 100, 100));
392   BRepPrimAPI_MakeBox box2(gp_Pnt(120, 120, 120),  gp_Pnt(300, 300,300));
393   BRepPrimAPI_MakeBox box3(gp_Pnt(320, 320, 320),  gp_Pnt(500, 500,500));
394
395   Handle(AIS_InteractiveObject) ais1 = new AIS_Shape(box1.Shape());
396   Handle(AIS_InteractiveObject) ais2 = new AIS_Shape(box2.Shape());
397   Handle(AIS_InteractiveObject) ais3 = new AIS_Shape(box3.Shape());
398
399   aContext->Display(ais1);
400   aContext->Display(ais2);
401   aContext->Display(ais3);
402
403   aContext->AddOrRemoveSelected(ais1);
404   aContext->AddOrRemoveSelected(ais2);
405   aContext->AddOrRemoveSelected(ais3);
406
407   di << "\n No of currents = " << aContext->NbSelected();
408
409   aContext->InitSelected();
410
411   int count = 1;
412   while(aContext->MoreSelected())
413   {
414     di << "\n count is = " << count++;
415     Handle(AIS_InteractiveObject) ais = aContext->SelectedInteractive();
416     aContext->AddOrRemoveSelected(ais);
417     aContext->InitSelected();
418   }
419
420   return 0; 
421 }
422
423 static int geom_get_2Dpt_from_3Dpt(const gp_Pnt& pnt3d, const gp_Pln& pln, gp_Pnt2d& pnt2d)
424
425   int ret = 0; 
426   Handle(Geom_Plane) gpln = new Geom_Plane(pln); 
427   GeomAdaptor_Surface adsur(gpln); 
428   Extrema_ExtPS extps(pnt3d, adsur, 0.001, 0.001); 
429   if( extps.IsDone() ) 
430   { 
431     int index;
432     for(index=1; index<= extps.NbExt(); index++ ) 
433     { 
434       Extrema_POnSurf pons = extps.Point(index); 
435       Standard_Real U, V; 
436       pons.Parameter(U, V); 
437       pnt2d.SetCoord(U, V); 
438       ret = 1; 
439     } 
440   } 
441   return ret;
442
443
444 static Standard_Integer OCC353 (Draw_Interpretor& di, Standard_Integer , const char ** )
445 {
446   gp_Ax2 ax21( gp_Pnt(100,0,0), gp_Dir(0,0,1) );
447   Handle(Geom_Circle) h_cir1 = new Geom_Circle( ax21, 25 );
448
449   gp_Ax2 ax22( gp_Pnt(-100,0,0), gp_Dir(0,0,1) );
450   Handle(Geom_Circle) h_cir2 = new Geom_Circle( ax22, 25 );
451
452   gp_Pln refpln( gp_Pnt(0,0,0), gp_Dir(0,0,1) );
453   Handle(Geom2d_Curve) cir2d1 = GeomAPI::To2d(h_cir1, refpln);
454   Handle(Geom2d_Curve) cir2d2 = GeomAPI::To2d(h_cir2, refpln);
455
456   Geom2dAdaptor_Curve adop1(cir2d1);
457   Geom2dAdaptor_Curve adop2(cir2d2);
458
459   Geom2dGcc_QualifiedCurve qcur1(adop1, GccEnt_enclosing);
460   Geom2dGcc_QualifiedCurve qcur2(adop2, GccEnt_enclosing);
461
462   Handle(Geom_CartesianPoint) h_carpt = new Geom_CartesianPoint(0,175,0);
463
464   gp_Pnt pt3d = h_carpt->Pnt();
465   gp_Pnt2d pt2d;
466   geom_get_2Dpt_from_3Dpt(pt3d, refpln, pt2d);
467
468   Standard_CString st;
469   st = "cir2d1";
470   DrawTrSurf::Set(st,cir2d1);
471   st = "cir2d2";
472   DrawTrSurf::Set(st,cir2d2);
473   st = "pt2d";
474   DrawTrSurf::Set(st,pt2d);
475
476   Handle(Geom2d_CartesianPoint) pt = new Geom2d_CartesianPoint(pt2d);
477   Geom2dGcc_Circ2d3Tan sol( qcur1, qcur2, pt, 0.001, 0.0, 0.0);
478
479   int res = 0;
480   Standard_Character buf[10];
481   buf[0] = '\0';
482
483   if( sol.IsDone() ) {
484     res = sol.NbSolutions();
485     for(Standard_Integer i=1;i<=res;i++) {
486       Handle(Geom2d_Circle) aC = new Geom2d_Circle(sol.ThisSolution(i));
487       Sprintf(buf,"Result_%d",i);
488       st = buf;
489       DrawTrSurf::Set(st,aC);
490     }
491   }
492   else
493     di << "\n Faulty: no solutions found ";
494   //printf("\n Faulty: no solutions found ");
495
496   //printf("\n Num of solutions are %d ", res );
497   di << "\n Num of solutions are " << res << " ";
498
499   return 0;
500 }
501
502 static Standard_Integer OCC280 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
503 {
504   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
505   if(aContext.IsNull()) 
506   { 
507     di << "use 'vinit' command before " << argv[0] << "\n";
508     return -1;
509   }
510   if ( argc != 3) {
511     di << "ERROR : Usage : " << argv[0] << " hlr=0/1 setsurfecedetail=0/1; set perspecrive view\n";
512     return 1;
513   }
514
515   Standard_Integer HLR = Draw::Atoi(argv[1]);
516   if (HLR != 0) {
517     HLR = 1;
518   }
519
520   TCollection_AsciiString anOldName = ViewerTest::GetCurrentViewName();
521   Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
522   aViewer->SetDefaultTypeOfView (V3d_PERSPECTIVE);
523   Handle(Aspect_Window) asp = ViewerTest::CurrentView()->Window();
524   Handle(V3d_View) aNewView = aViewer->CreateView();
525   ViewerTest::CurrentView (aNewView);
526   TCollection_AsciiString aNewName=anOldName + "_new";
527   ViewerTest::InitViewName(aNewName,ViewerTest::CurrentView());
528   aNewView->SetWindow (asp);
529   if (!asp->IsMapped()) asp->Map();
530   aNewView->Redraw();
531   ViewerTest::RemoveView(anOldName,false);
532   ViewerTest::UnsetEventManager();
533   ViewerTest::SetEventManager (new ViewerTest_EventManager (aNewView, ViewerTest::GetAISContext()));
534
535   if (HLR == 1)
536   {
537     di << "HLR\n";
538     ViewerTest::CurrentView()->SetComputedMode (Standard_True);
539   }
540
541   return 0;
542 }
543
544 static Standard_Integer  OCC232 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv)
545 {
546   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
547   if(aContext.IsNull()) { 
548     di << "use 'vinit' command before " << argv[0] << "\n";
549     return 1;
550   }
551
552   BRep_Builder builder;
553   TopoDS_Compound comp;
554   TopoDS_CompSolid cs1, cs2;
555
556   builder.MakeCompound(comp);
557   builder.MakeCompSolid(cs1);
558   builder.MakeCompSolid(cs2);
559
560   TopoDS_Shape sh1 = BRepPrimAPI_MakeBox(gp_Pnt(0, 0, 0), 100, 100, 100).Shape();
561   TopoDS_Shape sh2 = BRepPrimAPI_MakeBox(gp_Pnt(100, 0, 0), 100, 100, 100).Shape();
562   TopoDS_Shape sh3 = BRepPrimAPI_MakeBox(gp_Pnt(200, 0, 0), 100, 100, 100).Shape();
563   builder.Add(cs1, sh1);
564   builder.Add(cs1, sh2);
565   builder.Add(cs1, sh3);
566
567   TopoDS_Shape sh4 = BRepPrimAPI_MakeBox(gp_Pnt(0, 500, 0), 100, 100, 100).Shape();
568   TopoDS_Shape sh5 = BRepPrimAPI_MakeBox(gp_Pnt(100, 500, 0), 100, 100, 100).Shape();
569   TopoDS_Shape sh6 = BRepPrimAPI_MakeBox(gp_Pnt(200, 500, 0), 100, 100, 100).Shape();
570
571   builder.Add(cs2, sh4);
572   builder.Add(cs2, sh5);
573   builder.Add(cs2, sh6);
574
575   builder.Add(comp, cs1);
576   builder.Add(comp, cs2);
577
578   Handle(AIS_Shape) ais = new AIS_Shape(comp);
579   aContext->Display(ais);
580
581   TopExp_Explorer exp(comp,  TopAbs_COMPSOLID);
582   while(exp.More())
583   {
584     //printf("\n TopAbs_COMPSOLID is  there \n");
585     di << "\n TopAbs_COMPSOLID is  there \n";
586     exp.Next();
587   }
588
589   Handle (StdSelect_ShapeTypeFilter) filt = new StdSelect_ShapeTypeFilter(TopAbs_COMPSOLID);
590   aContext->AddFilter(filt);
591   Standard_DISABLE_DEPRECATION_WARNINGS
592   aContext->CloseAllContexts();
593   aContext->OpenLocalContext(); 
594   aContext->ActivateStandardMode(TopAbs_SOLID);
595   Standard_ENABLE_DEPRECATION_WARNINGS
596   return 0; 
597 }
598
599 static Standard_Integer  OCC138LC (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv)
600 {
601   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
602   if(aContext.IsNull()) { 
603     di << "use 'vinit' command before " << argv[0] << "\n";
604     return 1;
605   }
606
607   BRepPrimAPI_MakeBox box1(gp_Pnt(0, 0, 0),  gp_Pnt(100, 100, 100));
608   BRepPrimAPI_MakeBox box2(gp_Pnt(120, 120, 120),  gp_Pnt(300, 300,300));
609   BRepPrimAPI_MakeBox box3(gp_Pnt(320, 320, 320),  gp_Pnt(500, 500,500));
610
611   Handle(AIS_InteractiveObject) ais1 = new AIS_Shape(box1.Shape());
612   Handle(AIS_InteractiveObject) ais2 = new AIS_Shape(box2.Shape());
613   Handle(AIS_InteractiveObject) ais3 = new AIS_Shape(box3.Shape());
614
615   aContext->Display(ais1);
616   aContext->Display(ais2);
617   aContext->Display(ais3);
618
619   aContext->AddOrRemoveSelected(ais1);
620   aContext->AddOrRemoveSelected(ais2);
621   aContext->AddOrRemoveSelected(ais3);
622
623   di << "\n No of selected = " << aContext->NbSelected();
624
625   aContext->InitSelected();
626
627   int count = 1;
628   while(aContext->MoreSelected())
629   {
630     di << "\n count is = %d" << count++;
631     Handle(AIS_InteractiveObject) ais = aContext->SelectedInteractive();
632     aContext->AddOrRemoveSelected(ais);
633     aContext->InitSelected();
634   }
635
636   return 0; 
637 }
638
639 #include <BRepBndLib.hxx>
640 #include <Draw.hxx>
641 //=======================================================================
642 //function : OCC566
643 //purpose  : 
644 //=======================================================================
645 static Standard_Integer OCC566(Draw_Interpretor& di,Standard_Integer n,const char ** a)
646 {
647   if (n < 2) {
648     di<<"Usage: " << a[0] << " shape [ xmin ymin zmin xmax ymax zmax]\n";
649     return 1;
650   }
651   TopoDS_Shape S = DBRep::Get(a[1]);
652   if (S.IsNull()) return 1;
653   Bnd_Box B;
654   BRepBndLib::AddClose(S,B);
655   Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
656   B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
657   di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax;
658   if (n >= 8) {
659     Draw::Set(a[2],axmin) ;
660     Draw::Set(a[3],aymin) ;
661     Draw::Set(a[4],azmin) ;
662     Draw::Set(a[5],axmax) ;
663     Draw::Set(a[6],aymax) ;
664     Draw::Set(a[7],azmax) ;
665   }
666   return 0;
667 }
668
669 #include <BRepFilletAPI_MakeFillet.hxx>
670 //=======================================================================
671 //function : OCC570
672 //purpose  : 
673 //=======================================================================
674 static Standard_Integer OCC570 (Draw_Interpretor& di, Standard_Integer argc,const char ** argv)
675 {
676   if (argc < 2) {
677     di<<"Usage: " << argv[0] << " result\n";
678     return 1;
679   }
680
681   BRepPrimAPI_MakeBox mkBox(100.,100.,100.);
682   TopoDS_Shape aBox = mkBox.Shape();
683
684   TopExp_Explorer aExp;
685   aExp.Init(aBox,TopAbs_WIRE);
686   if (aExp.More())
687   {
688     TopoDS_Shape aWire = aExp.Current();
689
690     aExp.Init(aWire,TopAbs_EDGE);
691     TopoDS_Edge e1 = TopoDS::Edge(aExp.Current()); aExp.Next();
692     TopoDS_Edge e2 = TopoDS::Edge(aExp.Current()); aExp.Next();
693     TopoDS_Edge e3 = TopoDS::Edge(aExp.Current()); aExp.Next();
694     TopoDS_Edge e4 = TopoDS::Edge(aExp.Current());
695
696     try
697     {
698       OCC_CATCH_SIGNALS
699         BRepFilletAPI_MakeFillet mkFillet(aBox);
700       mkFillet.SetContinuity(GeomAbs_C1,.001);
701
702       // Setup variable fillet data
703       TColgp_Array1OfPnt2d t_pnt(1,4);
704       t_pnt.SetValue(1,gp_Pnt2d(0.0,5.0));
705       t_pnt.SetValue(2,gp_Pnt2d(0.3,15.0));
706       t_pnt.SetValue(3,gp_Pnt2d(0.7,15.0));
707       t_pnt.SetValue(4,gp_Pnt2d(1.0,5.0));
708
709       // HERE:
710       // It is impossible to build fillet if at least one edge
711       // with variable radius is added!!! If all are constant, everything is ok.
712       mkFillet.Add(t_pnt,e1);
713       mkFillet.Add(5.0,e2);
714       mkFillet.Add(t_pnt,e3);
715       mkFillet.Add(5.0,e4);
716
717       mkFillet.Build();
718       TopoDS_Shape aFinalShape = mkFillet.Shape();
719
720       DBRep::Set(argv[1],aFinalShape);
721     }
722     catch(Standard_Failure)
723     {
724       di << argv[0] << ": Exception in fillet\n";
725       return 2;
726     }
727   }
728
729   return 0;
730 }
731
732 #include <Law_Interpol.hxx>
733
734 static Standard_Real t3d = 1.e-4;
735 static Standard_Real t2d = 1.e-5;
736 static Standard_Real ta  = 1.e-2;
737 static Standard_Real fl  = 1.e-3;
738 static Standard_Real tapp_angle = 1.e-2;
739 static GeomAbs_Shape blend_cont = GeomAbs_C1;
740
741 static BRepFilletAPI_MakeFillet* Rake = 0;
742 static char name[100];
743
744 static void printtolblend(Draw_Interpretor& di)
745 {
746   di<<"tolerance ang : "<<ta<<"\n";
747   di<<"tolerance 3d  : "<<t3d<<"\n";
748   di<<"tolerance 2d  : "<<t2d<<"\n";
749   di<<"fleche        : "<<fl<<"\n";
750
751   di<<"tolblend "<<ta<<" "<<t3d<<" "<<t2d<<" "<<fl<<"\n";
752 }
753
754 static Standard_Integer MKEVOL(Draw_Interpretor& di, 
755                                Standard_Integer narg, 
756                                const char ** a)
757 {
758   if(Rake != 0) {delete Rake; Rake = 0;}
759   printtolblend(di);
760   if (narg < 3) return 1;
761   TopoDS_Shape V = DBRep::Get(a[2]);
762   Rake = new BRepFilletAPI_MakeFillet(V);
763   Rake->SetParams(ta,t3d,t2d,t3d,t2d,fl);
764   Rake->SetContinuity(blend_cont, tapp_angle);
765   if (narg == 4) {
766     ChFi3d_FilletShape FSh = ChFi3d_Rational;
767     if (!strcasecmp(a[3], "Q")) {
768       FSh = ChFi3d_QuasiAngular;
769     }
770     else if (!strcasecmp(a[3], "P")) {
771       FSh = ChFi3d_Polynomial;
772     }
773     Rake->SetFilletShape(FSh);
774   }
775   strcpy(name, a[1]);
776   return 0;
777 }
778
779 static Standard_Integer UPDATEVOL(Draw_Interpretor& di, 
780                                   Standard_Integer narg, 
781                                   const char ** a)
782 {
783   if(Rake == 0){
784     di << "MakeFillet non initialise\n";
785     return 1 ;
786   }
787   if(narg%2 != 0 || narg < 4) return 1;
788   TColgp_Array1OfPnt2d uandr(1,(narg/2)-1);
789   Standard_Real Rad, Par;
790   TopoDS_Shape aLocalEdge(DBRep::Get(a[1],TopAbs_EDGE));
791   TopoDS_Edge E = TopoDS::Edge(aLocalEdge);
792   for (Standard_Integer ii = 1; ii <= (narg/2)-1; ii++){
793     Par = Draw::Atof(a[2*ii]);
794     Rad = Draw::Atof(a[2*ii + 1]);
795     uandr.ChangeValue(ii).SetCoord(Par,Rad);
796   }
797   //HELPDESK: Add law creation
798   const Standard_Boolean aLawMode = !strcmp(a[0],"OCC570evollaw");
799   if (aLawMode)
800   {
801     di<<"INFO: Using law to define variable fillet\n";
802     Handle(Law_Interpol) law = new Law_Interpol;
803     law->Set(uandr);
804     Rake->Add(law,E);
805   }
806   else
807     Rake->Add(uandr,E);
808
809   return 0;
810 }
811
812 static Standard_Integer BUILDEVOL(Draw_Interpretor& di,
813                                   Standard_Integer, 
814                                   const char **)
815 {
816   if(Rake == 0){
817     di << "MakeFillet non initialise\n";
818     return 1 ;
819   }
820   Rake->Build();
821   if(Rake->IsDone()){
822     TopoDS_Shape result = Rake->Shape();
823     DBRep::Set(name,result);
824     if(Rake != 0) {delete Rake; Rake = 0;}
825     return 0;
826   }
827   if(Rake != 0) {delete Rake; Rake = 0;}
828   return 1;
829 }
830
831 #include <TColGeom_SequenceOfCurve.hxx>
832 #include <Geom_TrimmedCurve.hxx>
833 #include <GeomFill_NSections.hxx>
834 #include <BRepBuilderAPI_MakeFace.hxx>
835 //=======================================================================
836 //function : OCC606
837 //purpose  : 
838 //=======================================================================
839 static Standard_Integer OCC606 ( Draw_Interpretor& di, Standard_Integer n, const char ** a )
840 {
841   if (n != 3 && n != 4)
842   {
843     di << "Usage : " << a[0] << " result shape [-t]\n";
844     return 0;
845   }
846
847   Standard_Boolean TrimMode = (n == 4);
848   if (TrimMode) di<<"INFO: Using trimmed curves...\n";
849   else di<<"INFO: Using non trimmed curves...\n";
850
851   TopoDS_Shape S = DBRep::Get(a[2]);
852
853   TopExp_Explorer t_exp(S,TopAbs_EDGE);
854   TColGeom_SequenceOfCurve n_curves1;
855   TColStd_SequenceOfReal np;
856   Standard_Real param = 5.0;
857
858   for (;t_exp.More();t_exp.Next())
859   {
860     Standard_Real f,l;
861     Handle(Geom_Curve) h_cur = BRep_Tool::Curve(TopoDS::Edge(t_exp.Current()),f,l);
862     if (!h_cur.IsNull())
863     {
864       if (TrimMode) h_cur = new Geom_TrimmedCurve(h_cur,f,l);
865
866       n_curves1.Append(h_cur);
867       np.Append(param);
868       param += 1.0;
869     }
870   }
871
872   if (n_curves1.Length()>1 && !np.IsEmpty())
873   {
874     try
875     {
876       OCC_CATCH_SIGNALS
877         GeomFill_NSections b_surface1(n_curves1, np);
878       b_surface1.ComputeSurface();
879       Handle(Geom_BSplineSurface) result_surf1 = b_surface1.BSplineSurface();
880       if (!result_surf1.IsNull())
881       {
882         BRepBuilderAPI_MakeFace b_face1(result_surf1, Precision::Confusion());
883         TopoDS_Face bsp_face1 = b_face1.Face();
884         DBRep::Set(a[1],bsp_face1);
885       }
886     }
887     catch(Standard_Failure)
888     {
889       di<<"ERROR: Exception in GeomFill_NSections\n";
890     }
891   }
892
893
894   return 0;
895 }
896
897 //=======================================================================
898 //function : OCC813
899 //purpose  : 
900 //=======================================================================
901 static Standard_Integer OCC813 (Draw_Interpretor& di, Standard_Integer argc,const char ** argv)
902 {
903   if (argc < 3)
904   {
905     di << "Usage : " << argv[0] << " U V\n";
906     return 1;
907   }
908
909   Standard_CString str;
910   Standard_Real U = Draw::Atof(argv[1]);
911   Standard_Real V = Draw::Atof(argv[2]);
912
913   //Between ellipse and point:
914
915   Handle(Geom_Ellipse) ell = new Geom_Ellipse(gp_Ax2(gp_Pnt(1262.224429,425.040878,363.609716),
916     gp_Dir(0.173648,0.984808,0.000000),
917     gp_Dir(-0.932169,0.164367,-0.322560)), 150, 100);
918   Handle(Geom_Plane) plne = new Geom_Plane(gp_Ax3(gp_Ax2(gp_Pnt(1262.224429,425.040878,363.609716),
919     gp_Dir(0.173648,0.984808,0.000000),
920     gp_Dir(-0.932169,0.164367,-0.322560))) );
921
922   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
923
924   gp_Pnt2d pt2d(U,V);
925   gp_Pln pln = plne->Pln();
926
927   str = "OCC813_pnt"; DrawTrSurf::Set(str,pt2d);
928
929   Handle(Geom2d_Curve) curve2d = GeomAPI::To2d(ell,pln);
930   Geom2dAdaptor_Curve acur(curve2d);
931   Geom2dGcc_QualifiedCurve qcur(acur, GccEnt_outside);
932
933   str = "OCC813_ell"; DrawTrSurf::Set(str,curve2d);
934   if(!aContext.IsNull()) {
935     Handle(AIS_Shape) aisp = 
936       new AIS_Shape (BRepBuilderAPI_MakeEdge(GeomAPI::To3d(curve2d, pln)).Edge());
937     aContext->Display (aisp);
938   }
939
940   //This does not give any solutions.
941   Geom2dGcc_Lin2d2Tan lintan(qcur, pt2d, 0.1);
942   di<<"OCC813 nb of solutions = "<<lintan.NbSolutions()<<"\n";
943
944   Standard_Character abuf[16];
945   Standard_CString st = abuf;
946
947   Standard_Integer i;
948   for(i=1;i<=lintan.NbSolutions();i++) {
949     Sprintf(abuf,"lintan_%d",i);
950     Handle(Geom2d_Line) glin = new Geom2d_Line(lintan.ThisSolution(i));
951     DrawTrSurf::Set(st,glin);
952     if(!aContext.IsNull()) {
953       Handle(AIS_Shape) aisp = 
954         new AIS_Shape (BRepBuilderAPI_MakeEdge(GeomAPI::To3d(glin, pln)).Edge());      aContext->Display (aisp);
955     }
956   }
957
958   return 0;
959 }
960
961 //=======================================================================
962 //function : OCC814
963 //purpose  : 
964 //=======================================================================
965 static Standard_Integer OCC814 (Draw_Interpretor& di, Standard_Integer argc,const char ** argv)
966 {
967   if (argc > 1)
968   {
969     di << "Usage : " << argv[0] << "\n";
970     return 1;
971   }
972
973   Standard_CString str;
974
975   //Between Ellipse and Circle:
976
977   Handle(Geom_Circle) cir = new Geom_Circle(gp_Ax2(gp_Pnt(823.687192,502.366825,478.960440),
978     gp_Dir(0.173648,0.984808,0.000000),
979     gp_Dir(-0.932169,0.164367,-0.322560)), 50);
980   Handle(Geom_Ellipse) ell = new Geom_Ellipse(gp_Ax2(gp_Pnt(1262.224429,425.040878,363.609716),
981     gp_Dir(0.173648,0.984808,0.000000),
982     gp_Dir(-0.932169,0.164367,-0.322560)), 150, 100);
983   Handle(Geom_Plane) plne = new Geom_Plane(gp_Ax3(gp_Ax2(gp_Pnt(1262.224429,425.040878,363.609716),
984     gp_Dir(0.173648,0.984808,0.000000),
985     gp_Dir(-0.932169,0.164367,-0.322560))) );
986
987   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
988
989   gp_Pln pln = plne->Pln();
990   Handle(Geom2d_Curve) curve2d = GeomAPI::To2d(ell, pln);
991   Handle(Geom2d_Curve) fromcurve2d = GeomAPI::To2d(cir, pln);
992
993   str = "OCC814_cir"; DrawTrSurf::Set(str,curve2d);
994   str = "OCC814_ell"; DrawTrSurf::Set(str,fromcurve2d);
995   if(!aContext.IsNull()) {
996     Handle(AIS_Shape) aisp = 
997       new AIS_Shape (BRepBuilderAPI_MakeEdge(GeomAPI::To3d(curve2d, pln)).Edge());
998     aContext->Display (aisp);
999   }
1000   if(!aContext.IsNull()) {
1001     Handle(AIS_Shape) aisp = 
1002       new AIS_Shape (BRepBuilderAPI_MakeEdge(GeomAPI::To3d(fromcurve2d, pln)).Edge());
1003     aContext->Display (aisp);
1004   }
1005
1006   Geom2dAdaptor_Curve acur(curve2d), afromcur(fromcurve2d);
1007
1008   Geom2dGcc_QualifiedCurve qcur(acur, GccEnt_outside) ;
1009   Geom2dGcc_QualifiedCurve qfromcur(afromcur, GccEnt_outside) ;
1010
1011   //This does not give any solutions.
1012   Geom2dGcc_Lin2d2Tan lintan(qcur, qfromcur, 0.1);
1013   di<<"OCC814 nb of solutions = "<<lintan.NbSolutions()<<"\n";
1014
1015   Standard_Character abuf[16];
1016   Standard_CString st = abuf;
1017
1018   Standard_Integer i;
1019   for(i=1;i<=lintan.NbSolutions();i++) {
1020     Sprintf(abuf,"lintan_%d",i);
1021     Handle(Geom2d_Line) glin = new Geom2d_Line(lintan.ThisSolution(i));
1022     DrawTrSurf::Set(st,glin);
1023     if(!aContext.IsNull()) {
1024       Handle(AIS_Shape) aisp = 
1025         new AIS_Shape (BRepBuilderAPI_MakeEdge(GeomAPI::To3d(glin, pln)).Edge());      aContext->Display (aisp);
1026     }
1027   }
1028
1029   return 0;
1030 }
1031
1032 #include <ShapeAnalysis_Wire.hxx>
1033 #include <IntRes2d_SequenceOfIntersectionPoint.hxx>
1034 #include <TColgp_SequenceOfPnt.hxx>
1035 #include <ShapeFix_Wire.hxx>
1036 //=======================================================================
1037 //function : OCC884
1038 //purpose  : 
1039 //=======================================================================
1040 static Standard_Integer OCC884 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1041 {
1042   if (argc < 3 || argc > 5)
1043   {
1044     di << "Usage : " << argv[0] << " result shape [toler [maxtoler]]\n";
1045     return 1;
1046   }
1047
1048   TopoDS_Shape shape = DBRep::Get(argv[2]); //read the shape
1049
1050   TopExp_Explorer exp(shape, TopAbs_EDGE);
1051   if (!exp.More())
1052   {
1053     di<<"Error: no edge found\n";
1054     return 1;
1055   }
1056
1057   BRep_Builder builder;
1058   TopoDS_Wire wire;
1059   builder.MakeWire(wire);
1060   builder.Add(wire, TopoDS::Edge(exp.Current()));
1061
1062   // HelpDesk: Create planar face if possible
1063   TopoDS_Face face = BRepBuilderAPI_MakeFace(wire,Standard_True);
1064
1065   Handle(ShapeAnalysis_Wire) advWA = new ShapeAnalysis_Wire;
1066   advWA->Load(wire);
1067   advWA->SetFace(face);
1068   advWA->SetPrecision(0.001);
1069
1070   IntRes2d_SequenceOfIntersectionPoint points2d;
1071   TColgp_SequenceOfPnt points3d;
1072
1073   di << "Info: CheckSelfIntersectingEdge = " << (Standard_Integer) advWA->CheckSelfIntersectingEdge(1,points2d,points3d) << "\n";
1074
1075   ShapeExtend_Status status = ShapeExtend_FAIL1;
1076   if (advWA->StatusSelfIntersection(status))
1077     di << "Info: No P Curve found in the edge\n";
1078
1079   status = ShapeExtend_FAIL2; 
1080   if (advWA->StatusSelfIntersection(status))
1081     di << "Info: No Vertices found in the edge\n";
1082
1083   status = ShapeExtend_DONE1; 
1084   if (advWA->StatusSelfIntersection(status))
1085     di << "Info: Self-intersection found in the edge\n";
1086
1087   Standard_Integer i, num = points2d.Length();
1088   di << "Info: No. of self-intersection points : " << num << "\n";
1089
1090   char str[80];
1091   Standard_CString aName = str;
1092   for (i = 1; i <= num; ++i)
1093   { 
1094     gp_Pnt pt = points3d(i); 
1095     di << "Info: Intersecting pt : (" << pt.X() << ", " << pt.Y() << ", " << pt.Z() << ")\n";
1096     Sprintf(str,"p_%d",i);
1097     DrawTrSurf::Set(aName,pt);
1098   }
1099
1100   Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire;
1101   sfw->Load(wire);
1102   sfw->SetFace(face);
1103
1104   if (argc > 3) sfw->SetPrecision(Draw::Atof(argv[3])/*0.1*/);
1105   if (argc > 4) sfw->SetMaxTolerance(Draw::Atof(argv[4]));
1106   di << "Info: Precision is set to " << sfw->Precision() << "\n";
1107   di << "Info: MaxTolerance is set to " << sfw->MaxTolerance() << "\n";
1108
1109   sfw->ModifyTopologyMode() = 1;
1110   sfw->ModifyGeometryMode() = 1; 
1111   sfw->FixSelfIntersectingEdgeMode() = 1;
1112   //printf("Info: FixSelfIntersection = %d\n",sfw->FixSelfIntersection());
1113   di << "Info: FixSelfIntersection = " << (Standard_Integer) sfw->FixSelfIntersection() << "\n";
1114
1115   DBRep::Set(argv[1],sfw->Wire());
1116
1117   status = ShapeExtend_OK;
1118   if (sfw->StatusSelfIntersection(status))
1119     di << "Info: ShapeExtend_OK : No intersection found\n";
1120   //printf("Info: ShapeExtend_OK : No intersection found\n");
1121
1122   status = ShapeExtend_FAIL1;
1123   if (sfw->StatusSelfIntersection(status))
1124     di << "Info: ShapeExtend_FAIL1 : analysis failed (edge has no pcurve, or no vertices etc.)\n";
1125
1126   status = ShapeExtend_FAIL2;
1127   if (sfw->StatusSelfIntersection(status))
1128     di << "Info: ShapeExtend_FAIL2 : self-intersection was found, but not fixed because of limit of increasing tolerance (MaxTolerance)\n";
1129
1130   status = ShapeExtend_FAIL3;
1131   if (sfw->StatusSelfIntersection(status))
1132     di << "Info: ShapeExtend_FAIL3 : intercestion of non adjacent edges found, but not fixed because of limit of increasing tolerance (MaxTolerance)\n";
1133
1134   status = ShapeExtend_DONE1;
1135   if (sfw->StatusSelfIntersection(status))
1136     di << "Info: ShapeExtend_DONE1 : tolerance of vertex was increased to fix self-intersection\n";
1137
1138   status = ShapeExtend_DONE2;
1139   if (sfw->StatusSelfIntersection(status))
1140     di << "Info: ShapeExtend_DONE2 : vertex was moved to fix self-intersection\n";
1141
1142   status = ShapeExtend_DONE3;
1143   if (sfw->StatusSelfIntersection(status))
1144     di << "Info: ShapeExtend_DONE3 : some edges were removed because of intersection\n";
1145
1146   status = ShapeExtend_DONE4;
1147   if (sfw->StatusSelfIntersection(status))
1148     di << "Info: ShapeExtend_DONE4 : pcurve(s) was(were) modified\n";
1149
1150   status = ShapeExtend_DONE5;
1151   if (sfw->StatusSelfIntersection(status))
1152     di << "Info: ShapeExtend_DONE5 : non adjacent intersection fixed by increasing tolerance of vertex(vertices)\n";
1153
1154   status = ShapeExtend_DONE6;
1155   if (sfw->StatusSelfIntersection(status))
1156     di << "Info: ShapeExtend_DONE6 : tolerance of edge was increased to hide intersection\n";
1157
1158   status = ShapeExtend_DONE7;
1159   if (sfw->StatusSelfIntersection(status))
1160     di << "Info: ShapeExtend_DONE7 : range of some edges was decreased to avoid intersection\n";
1161
1162   return 0;
1163 }
1164
1165 #include <Aspect_FillMethod.hxx>
1166 //=======================================================================
1167 //function : OCC1188
1168 //purpose  : 
1169 //=======================================================================
1170 static Standard_Integer OCC1188 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1171 {
1172   if (argc < 2 || argc > 3)
1173   {
1174     di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background\n";
1175     return 1;
1176   }
1177
1178   Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1179   if(AISContext.IsNull()) 
1180   {
1181     di << "use 'vinit' command before " << argv[0] << "\n";
1182     return 1;
1183   }
1184
1185   Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
1186   if (argc == 3)
1187   {
1188     const char* szType = argv[2];
1189     if      (strcmp(szType, "NONE"    ) == 0) aFillType = Aspect_FM_NONE;
1190     else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1191     else if (strcmp(szType, "TILED"   ) == 0) aFillType = Aspect_FM_TILED;
1192     else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1193     else
1194     {
1195       di << "Wrong fill type : " << szType << "\n";
1196       di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
1197       return 1;
1198     }
1199   }
1200
1201   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1202   V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
1203
1204   return 0;
1205 }
1206
1207 #include <Graphic3d_MaterialAspect.hxx>
1208 #include <Prs3d_Drawer.hxx>
1209 #include <Prs3d_ShadingAspect.hxx>
1210 //=======================================================================
1211 //function : OCC1174_1
1212 //purpose  : 
1213 //=======================================================================
1214 static Standard_Integer OCC1174_1 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1215 {
1216   if (argc != 2)
1217   {
1218     di << "Usage : " << argv[0] << " shape\n";
1219     return 1;
1220   }
1221
1222   Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
1223   if(anAISContext.IsNull())
1224   {
1225     di << "use 'vinit' command before " << argv[0] << "\n";
1226     return 1;
1227   }
1228
1229   TopoDS_Shape aShape = DBRep::Get(argv[1]);
1230
1231   Handle(AIS_Shape) anAisIO = new AIS_Shape(aShape);
1232
1233   Quantity_Color aColF(0.0, 0.4, 0.0, Quantity_TOC_RGB);
1234   Quantity_Color aColB(0.0, 0.0, 0.6, Quantity_TOC_RGB);
1235
1236   Handle(Prs3d_Drawer) aDrawer = anAisIO->Attributes();
1237   Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1238
1239   Graphic3d_MaterialAspect aFront = aShadingAspect->Material(Aspect_TOFM_FRONT_SIDE);
1240   aFront.SetAmbientColor(aColF);
1241   aFront.SetDiffuseColor(aColF);
1242   aFront.SetSpecularColor(aColF);
1243   aFront.SetEmissiveColor(aColF);
1244   aFront.SetTransparency(0.0);
1245   aShadingAspect->SetMaterial(aFront,Aspect_TOFM_FRONT_SIDE);
1246
1247   Graphic3d_MaterialAspect aBack = aShadingAspect->Material(Aspect_TOFM_BACK_SIDE);
1248   aBack.SetAmbientColor(aColB);
1249   aBack.SetDiffuseColor(aColB);
1250   aBack.SetSpecularColor(aColB);
1251   aBack.SetEmissiveColor(aColB);
1252   aBack.SetTransparency(0.0);
1253   aShadingAspect->SetMaterial(aBack,Aspect_TOFM_BACK_SIDE);
1254
1255   aDrawer->SetShadingAspect (aShadingAspect);
1256
1257   anAISContext->Display(anAisIO, 1, 0);
1258
1259   Standard_Real r, g, b; 
1260   aShadingAspect->Color(Aspect_TOFM_FRONT_SIDE).Values(r,g,b, Quantity_TOC_RGB);
1261   di << "Info: color on front side (" << r << "," << g << "," << b << ")\n";
1262   aShadingAspect->Color(Aspect_TOFM_BACK_SIDE).Values(r,g,b, Quantity_TOC_RGB);
1263   di << "Info: color on back side (" << r << "," << g << "," << b << ")\n";
1264
1265   return 0;
1266 }
1267
1268 //=======================================================================
1269 //function : OCC1174_2
1270 //purpose  : 
1271 //=======================================================================
1272 static Standard_Integer OCC1174_2 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1273 {
1274   if (argc != 2)
1275   {
1276     di << "Usage : " << argv[0] << " shape\n";
1277     return 1;
1278   }
1279
1280   Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1281   if(AISContext.IsNull()) 
1282   {
1283     di << "use 'vinit' command before " << argv[0] << "\n";
1284     return 1;
1285   }
1286
1287   TopoDS_Shape sh = DBRep::Get(argv[1]);
1288
1289   Handle(AIS_Shape) ais = new AIS_Shape(sh); 
1290   AISContext->Display(ais,1,0); 
1291   AISContext->SetMaterial(ais,Graphic3d_NOM_SHINY_PLASTIC); 
1292
1293   Quantity_Color colf(0.0, 0.4, 0.0, Quantity_TOC_RGB); 
1294   Quantity_Color colb(0.0, 0.0, 0.6, Quantity_TOC_RGB); 
1295   Handle(Prs3d_ShadingAspect) sa = ais->Attributes()->ShadingAspect(); 
1296
1297   Graphic3d_MaterialAspect front = sa->Material(Aspect_TOFM_FRONT_SIDE); 
1298   front.SetAmbientColor(colf); 
1299   front.SetDiffuseColor(colf); 
1300   front.SetSpecularColor(colf); 
1301   front.SetEmissiveColor(colf); 
1302   front.SetTransparency(0.4); 
1303   sa->SetMaterial(front,Aspect_TOFM_FRONT_SIDE); 
1304
1305   Graphic3d_MaterialAspect back = sa->Material(Aspect_TOFM_BACK_SIDE); 
1306   back.SetAmbientColor(colb); 
1307   back.SetDiffuseColor(colb); 
1308   back.SetSpecularColor(colb); 
1309   back.SetEmissiveColor(colb); 
1310   back.SetTransparency(0.2); 
1311   sa->SetMaterial(back,Aspect_TOFM_BACK_SIDE); 
1312
1313   AISContext->Redisplay(ais,1,0);
1314
1315   return 0;
1316 }
1317
1318 #include <TopoDS_Solid.hxx>
1319 #include <BRepFeat_MakeDPrism.hxx>
1320 //=======================================================================
1321 //function : OCCN1
1322 //purpose  : FEATURE OPERATION (BOSS and SLOT)
1323 //=======================================================================
1324 static Standard_Integer OCCN1 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1325 {
1326   if (argc != 4)
1327   {
1328     di << "Usage : " << argv[0] << " angle fuse(1 for boss / 0 for slot) length\n";
1329     return 1;
1330   }
1331
1332   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1333   if(aContext.IsNull()) 
1334   {
1335     di << "use 'vinit' command before " << argv[0] << "\n";
1336     return 1;
1337   }
1338   Standard_Real    angle  = Draw::Atof(argv[1]);
1339   Standard_Integer fuse   = Draw::Atoi(argv[2]);
1340   Standard_Real    length = Draw::Atof(argv[3]);
1341
1342   BRepBuilderAPI_MakeEdge edge1(gp_Pnt(0, 0, 0), gp_Pnt(50, 0, 0));
1343   BRepBuilderAPI_MakeEdge edge2(gp_Pnt(50, 0, 0), gp_Pnt(50, 50, 0));
1344   BRepBuilderAPI_MakeEdge edge3(gp_Pnt(50, 50, 0), gp_Pnt(0, 50, 0));
1345   BRepBuilderAPI_MakeEdge edge4(gp_Pnt(0, 50, 0), gp_Pnt(0, 0, 0));
1346   TopoDS_Edge ted1 = edge1.Edge();
1347   TopoDS_Edge ted2 = edge2.Edge();
1348   TopoDS_Edge ted3 = edge3.Edge();
1349   TopoDS_Edge ted4 = edge4.Edge();
1350
1351   BRepBuilderAPI_MakeWire wire(ted1, ted2, ted3, ted4);
1352   TopoDS_Wire twire = wire.Wire();
1353
1354   BRepBuilderAPI_MakeFace face(twire);
1355   TopoDS_Face tface = face.Face();
1356   ////////Handle(AIS_Shape) face_ais = new AIS_Shape( tface );
1357   ////////aContext->Display(face_ais);
1358
1359   TopoDS_Solid box;
1360   BRepPrimAPI_MakeBox block(gp_Pnt(-50, -50, -150), 150, 150, 100);
1361   box = block.Solid();
1362
1363   TopoDS_Face top_face;
1364   top_face = block.TopFace();
1365
1366   BRepFeat_MakeDPrism slot(box, tface, top_face, angle, fuse,
1367     Standard_True);
1368
1369   slot.Perform(length);
1370   TopoDS_Shape S2 = slot.Shape();
1371
1372   DBRep::Set("OCCN1_tface",tface);
1373   DBRep::Set("OCCN1_slot",S2);
1374
1375   return 0;
1376 }
1377
1378 #include <BRepPrimAPI_MakeCylinder.hxx>
1379 #include <BRepPrimAPI_MakeSphere.hxx>
1380 #include <BRepAlgoAPI_Section.hxx>
1381 #include <BRepAlgo_Section.hxx>
1382 //=======================================================================
1383 //function : OCCN2
1384 //purpose  : BOOLEAN OPERATION
1385 //=======================================================================
1386 static Standard_Integer OCCN2 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1387 {
1388   if (argc > 2) {
1389     di << "Usage : " << argv[0] << " [BRepAlgoAPI/BRepAlgo = 1/0]\n";
1390     return 1;
1391   }
1392   Standard_Boolean IsBRepAlgoAPI = Standard_True;
1393   if (argc == 2) {
1394     Standard_Integer IsB = Draw::Atoi(argv[1]);
1395     if (IsB != 1) {
1396       IsBRepAlgoAPI = Standard_False;
1397 #if ! defined(BRepAlgo_def04)
1398 #endif
1399     }
1400   }
1401
1402   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1403   if(aContext.IsNull()) 
1404   {
1405     di << "use 'vinit' command before " << argv[0] << "\n";
1406     return 1;
1407   }
1408
1409   BRepPrimAPI_MakeCylinder cylinder(50,200);
1410   TopoDS_Shape cylinder_sh = cylinder.Shape();
1411
1412   BRepPrimAPI_MakeSphere sphere(gp_Pnt(60,0,100),50);
1413   TopoDS_Shape sphere_sh = sphere.Shape();
1414
1415   //BRepAlgoAPI_Section section(cylinder_sh, sphere_sh);
1416   //TopoDS_Shape shape = section.Shape();
1417
1418   TopoDS_Shape shape;
1419   if (IsBRepAlgoAPI) {
1420     di << "BRepAlgoAPI_Section section(cylinder_sh, sphere_sh)\n";
1421     BRepAlgoAPI_Section section(cylinder_sh, sphere_sh);
1422     section.Build();
1423     if(!section.IsDone()){
1424       di << "Error performing intersection: not done.\n";
1425     }
1426     shape = section.Shape();
1427   } else {
1428     di << "BRepAlgo_Section section(cylinder_sh, sphere_sh)\n";
1429     BRepAlgo_Section section(cylinder_sh, sphere_sh);
1430     section.Build();
1431     if(!section.IsDone()){
1432       di << "Error performing intersection: not done.\n";
1433     }
1434     shape = section.Shape();
1435   }
1436
1437   DBRep::Set("OCCN2_cylinder",cylinder_sh);
1438   DBRep::Set("OCCN2_sphere",sphere_sh);
1439   DBRep::Set("OCCN2_section",shape);
1440
1441   return 0;
1442 }
1443
1444 #include <TColgp_Array1OfPnt.hxx>
1445 #include <Geom_BezierCurve.hxx>
1446
1447 static Standard_Integer OCC2569 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1448 {
1449   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1450   if(aContext.IsNull()) 
1451   {
1452     di << "use 'vinit' command before " << argv[0] << "\n";
1453     return 1;
1454   }
1455   if(argc != 3) {
1456     di << "Usage : " << argv[0] << " nbpoles result\n";
1457     return 1;
1458   }
1459
1460   int poles=Draw::Atoi(argv[1]); 
1461
1462   TColgp_Array1OfPnt arr(1, poles); 
1463   for(int i=1; i<=poles; i++) 
1464     arr.SetValue(i, gp_Pnt(i+10, i*2+20, i*3+45)); 
1465
1466   Handle(Geom_BezierCurve) bez = new Geom_BezierCurve(arr); 
1467   if(bez.IsNull()) {
1468     di << "\n The curve is not created.\n";
1469   } else {
1470     di << "\n Degree = " << bez->Degree() << "\n";   
1471   }
1472   TopoDS_Edge sh = BRepBuilderAPI_MakeEdge(bez).Edge(); 
1473   Handle(AIS_Shape) ais = new AIS_Shape(sh); 
1474   aContext->Display(ais); 
1475   DrawTrSurf::Set(argv[2],bez);
1476   return 0;
1477 }
1478
1479 #include <TopTools_IndexedMapOfShape.hxx>
1480 #include <TopExp.hxx>
1481
1482 static Standard_Integer OCC1642 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1483 {
1484   if (argc != 10) {
1485     di<<"Usage: " << argv[0] << " FinalWare FinalFace InitWare InitFace shape FixReorder FixDegenerated FixConnected FixSelfIntersection\n";
1486     return 1;
1487   }
1488
1489   TopoDS_Shape shape = DBRep::Get(argv[5]);
1490
1491   TopExp_Explorer exp(shape, TopAbs_WIRE);
1492   TopoDS_Shape wire = exp.Current();
1493
1494   Handle(ShapeAnalysis_Wire) advWA = new ShapeAnalysis_Wire;
1495   advWA->Load(TopoDS::Wire(wire));
1496
1497   DBRep::Set(argv[3],wire);
1498
1499   TopoDS_Face face =
1500     BRepBuilderAPI_MakeFace(TopoDS::Wire(wire),Standard_True);
1501
1502   DBRep::Set(argv[4],face);
1503
1504   advWA->SetFace(face);
1505   Standard_Real precision_to_ana = 0.0001;
1506   advWA->SetPrecision(precision_to_ana);
1507
1508   TopTools_IndexedMapOfShape M;
1509   TopExp::MapShapes(wire, TopAbs_EDGE, M);
1510
1511   int j= 1;
1512   for(j= 1; j<=M.Extent(); ++j) {
1513     Standard_Integer num=1;
1514     IntRes2d_SequenceOfIntersectionPoint points2d;
1515     TColgp_SequenceOfPnt points3d;
1516
1517     cout << "\n j =" << j << ",  CheckSelfIntersectingEdge = " <<
1518       advWA->CheckSelfIntersectingEdge(j, points2d, points3d);
1519
1520
1521     ShapeExtend_Status status = ShapeExtend_FAIL1;
1522     if(advWA->StatusSelfIntersection(status))
1523
1524       status = ShapeExtend_FAIL2;
1525     if(advWA->StatusSelfIntersection(status))
1526       di << "\n No Vertices found in the edge";
1527
1528     status = ShapeExtend_DONE1;
1529     if(advWA->StatusSelfIntersection(status))
1530       di << "\n Self-intersection found in the edge";
1531
1532     num = points2d.Length();
1533     di << "\n No. of self-intersecting edges : " << num;
1534
1535     for(int i=1; i<=num; ++i) {
1536       gp_Pnt pt = points3d(i);
1537       di << "\n Intersecting pt : (" << pt.X() << ", " << pt.Y()<< ", " << pt.Z() << ")";
1538     }
1539
1540   }
1541
1542   Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire;
1543   sfw->Load(TopoDS::Wire(wire));
1544   sfw->SetFace(face);
1545   sfw->SetPrecision(Precision::Confusion());
1546
1547   sfw->FixReorderMode() = 1;
1548   sfw->ClosedWireMode() = 1;
1549   sfw->FixDegeneratedMode() = 1;
1550   sfw->FixConnectedMode() = 1;
1551   sfw->ModifyTopologyMode() = 1;
1552   sfw->ModifyGeometryMode() = 1;
1553   sfw->FixSelfIntersectionMode() = 1;
1554   sfw->FixSelfIntersectingEdgeMode() = 1;
1555   sfw->FixIntersectingEdgesMode() = 1;
1556   sfw->FixNonAdjacentIntersectingEdgesMode() = 1;
1557   sfw->FixEdgeCurvesMode() = 1;
1558
1559   sfw->ModifyRemoveLoopMode() = 1;
1560   sfw->SetMaxTolerance(1.0);
1561
1562   di << "\n FixReorder = " << (Standard_Integer) sfw->FixReorder();
1563   di << "\n FixDegenerated = " << (Standard_Integer) sfw->FixDegenerated();
1564   di << "\n FixConnected = " << (Standard_Integer) sfw->FixConnected();
1565   di << "\n";
1566   di << "\n FixSelfIntersection = " << (Standard_Integer) sfw->FixSelfIntersection();
1567   di << "\n";
1568
1569   Draw::Set(argv[6],sfw->FixReorder()) ;
1570   Draw::Set(argv[7],sfw->FixDegenerated()) ;
1571   Draw::Set(argv[8],sfw->FixConnected()) ;
1572   Draw::Set(argv[9],sfw->FixSelfIntersection()) ;
1573
1574   ShapeExtend_Status status = ShapeExtend_OK;
1575   if(sfw->StatusSelfIntersection(status))
1576     di << "\n ShapeExtend_OK : No intersection found";
1577
1578   status = ShapeExtend_FAIL1;
1579   if(sfw->StatusSelfIntersection(status))
1580     di << "\n ShapeExtend_FAIL1 : analysis failed (edge has no pcurve,or no vertices etc.)";
1581
1582   status = ShapeExtend_FAIL2;
1583   if(sfw->StatusSelfIntersection(status))
1584     di << "\n ShapeExtend_FAIL2 : self-intersection was found, but not fixed because of limit of increasing tolerance (MaxTolerance)";
1585
1586   status = ShapeExtend_FAIL3;
1587   if(sfw->StatusSelfIntersection(status))
1588     di << "\n ShapeExtend_FAIL3 : intercestion of non adjacent edges found, but not fixed because of limit of increasing tolerance (MaxTolerance)";
1589
1590   status = ShapeExtend_DONE1;
1591   if(sfw->StatusSelfIntersection(status))
1592     di << "\n ShapeExtend_DONE1 : tolerance of vertex was increased to fix self-intersection";
1593
1594   status = ShapeExtend_DONE2;
1595   if(sfw->StatusSelfIntersection(status))
1596     di << "\n ShapeExtend_DONE2 : vertex was moved to fix self-intersection";
1597
1598   status = ShapeExtend_DONE3;
1599   if(sfw->StatusSelfIntersection(status))
1600     di << "\n ShapeExtend_DONE3 : some edges were removed because of intersection";
1601
1602   status = ShapeExtend_DONE4;
1603   if(sfw->StatusSelfIntersection(status))
1604     di << "\n ShapeExtend_DONE4 : pcurve(s) was(were) modified";
1605
1606   status = ShapeExtend_DONE5;
1607   if(sfw->StatusSelfIntersection(status))
1608     di << "\n ShapeExtend_DONE5 : non adjacent intersection fixed by increasing tolerance of vertex(vertices)";
1609
1610   status = ShapeExtend_DONE6;
1611   if(sfw->StatusSelfIntersection(status))
1612     di << "\n ShapeExtend_DONE6 : tolerance of edge was increased to hide intersection";
1613
1614   status = ShapeExtend_DONE7;
1615   if(sfw->StatusSelfIntersection(status))
1616     di << "\n ShapeExtend_DONE7 : range of some edges was decreased to avoid intersection";
1617
1618   TopoDS_Wire finalwire = sfw->Wire();
1619
1620   DBRep::Set(argv[1],finalwire);
1621
1622
1623   advWA->Load(TopoDS::Wire(finalwire));
1624
1625   TopoDS_Face fface =
1626     BRepBuilderAPI_MakeFace(TopoDS::Wire(finalwire),Standard_True);
1627
1628   DBRep::Set(argv[2],fface);
1629
1630   advWA->SetFace(fface);
1631
1632   TopTools_IndexedMapOfShape fM;
1633   TopExp::MapShapes(finalwire, TopAbs_EDGE, fM);
1634
1635   for(j= 1; j<=fM.Extent(); ++j) {
1636     Standard_Integer num=1;
1637     IntRes2d_SequenceOfIntersectionPoint points2d;
1638     TColgp_SequenceOfPnt points3d;
1639
1640     di << "\n j =" << j << ",  CheckSelfIntersectingEdge = " <<
1641       (Standard_Integer) advWA->CheckSelfIntersectingEdge(j, points2d, points3d);
1642
1643
1644     status = ShapeExtend_FAIL1;
1645     if(advWA->StatusSelfIntersection(status))
1646
1647       status = ShapeExtend_FAIL2;
1648     if(advWA->StatusSelfIntersection(status))
1649       di << "\n No Vertices found in the edge";
1650
1651     status = ShapeExtend_DONE1;
1652     if(advWA->StatusSelfIntersection(status))
1653       di << "\n Self-intersection found in the edge";
1654
1655     num = points2d.Length();
1656     di << "\n No. of self-intersecting edges : " << num;
1657
1658     for(int i=1; i<=num; ++i) {
1659       gp_Pnt pt = points3d(i);
1660       di << "\n Intersecting pt : (" << pt.X() << ", " << pt.Y() << ", " << pt.Z() << ")";
1661     }
1662
1663   }
1664
1665   di << "\n";
1666
1667   return 0;
1668 }
1669
1670 void QABugs::Commands_17(Draw_Interpretor& theCommands) {
1671   const char *group = "QABugs";
1672
1673   theCommands.Add ("BUC60842", "BUC60842", __FILE__, BUC60842, group);
1674   theCommands.Add ("BUC60843", "BUC60843 result_shape name_of_circle name_of_curve [ par1 [ tol ] ]", __FILE__, BUC60843, group);
1675   theCommands.Add ("BUC60970", "BUC60970 shape result", __FILE__, BUC60970, group);
1676   theCommands.Add ("BUC60818", "BUC60818", __FILE__, BUC60818, group);
1677   theCommands.Add ("BUC60915", "BUC60915", __FILE__, BUC60915_1, group);
1678   theCommands.Add ("OCC138", "OCC138", __FILE__, OCC138, group);
1679   theCommands.Add ("OCC353","OCC353",__FILE__,OCC353,group);
1680   theCommands.Add ("OCC280","OCC280 hlr=0/1 setsurfecedetail=0/1; set perspecrive view",__FILE__,OCC280,group);
1681   theCommands.Add ("OCC232", "OCC232", __FILE__, OCC232 , group);
1682   theCommands.Add ("OCC138LC", "OCC138LC", __FILE__, OCC138LC, group);
1683   theCommands.Add ("OCC566", "OCC566 shape [ xmin ymin zmin xmax ymax zmax] ; print bounding box", __FILE__, OCC566, group);
1684   theCommands.Add ("OCC570", "OCC570 result", __FILE__, OCC570, group);
1685
1686   theCommands.Add("OCC570mkevol",
1687     "OCC570mkevol result object (then use updatevol) [R/Q/P]; mkevol",
1688     __FILE__, MKEVOL,group);
1689   theCommands.Add("OCC570updatevol",
1690     "OCC570updatevol edge u1 rad1 u2 rad2 ...; updatevol",
1691     __FILE__, UPDATEVOL,group);
1692   theCommands.Add("OCC570updatevollaw",
1693     "OCC570updatevollaw edge u1 rad1 u2 rad2 ...; updatevollaw",
1694     __FILE__, UPDATEVOL,group);
1695   theCommands.Add("OCC570buildevol",
1696     "OCC570buildevol; end of the evol fillet computation",
1697     __FILE__, BUILDEVOL,group);
1698
1699   theCommands.Add ("OCC606", "OCC606 result shape [-t]", __FILE__, OCC606, group);
1700
1701   theCommands.Add ("OCC813", "OCC813 U V", __FILE__, OCC813, group);
1702   theCommands.Add ("OCC814", "OCC814", __FILE__, OCC814, group);
1703   theCommands.Add ("OCC884", "OCC884 result shape [toler [maxtoler]]", __FILE__, OCC884, group);
1704   theCommands.Add ("OCC1188", "OCC1188 imagefile [filltype] : Load image as background", __FILE__, OCC1188, group);
1705
1706   theCommands.Add ("OCC1174_1", "OCC1174_1 shape", __FILE__, OCC1174_1, group);
1707   theCommands.Add ("OCC1174_2", "OCC1174_2 shape", __FILE__, OCC1174_2, group);
1708
1709   theCommands.Add ("OCCN1", "OCCN1 angle fuse(1 for boss / 0 for slot) length", __FILE__, OCCN1, group);
1710   theCommands.Add ("OCCN2", "OCCN2", __FILE__, OCCN2, group);
1711
1712   theCommands.Add ("OCC2569", "OCC2569 nbpoles result", __FILE__, OCC2569, group);
1713
1714   theCommands.Add ("OCC1642", "OCC1642 FinalWare FinalFace InitWare InitFace shape FixReorder FixDegenerated FixConnected FixSelfIntersection", __FILE__, OCC1642, group);
1715
1716   return;
1717 }