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