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