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