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