0022980: Fixed Standard_Atomic.hxx
[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 #if defined(WOKC40)
22 #define V2D
23 #define Viewer2dTest QAViewer2dTest
24 #endif
25
26 #include <stdio.h>
27
28 #include <QABugs.hxx>
29
30 #include <Draw_Interpretor.hxx>
31 #include <DBRep.hxx>
32 #include <DrawTrSurf.hxx>
33 #include <AIS_InteractiveContext.hxx>
34 #include <ViewerTest.hxx>
35 #include <ViewerTest_EventManager.hxx>
36 #include <AIS_Shape.hxx>
37 #include <TopoDS_Shape.hxx>
38
39 #include <Geom_Circle.hxx>
40 #include <Geom_Ellipse.hxx>
41 #include <Geom_Plane.hxx>
42 #include <gp_Pln.hxx>
43 #include <Geom2d_Curve.hxx>
44 #include <GeomAPI.hxx>
45 #include <Geom2dAdaptor_Curve.hxx>
46 #include <Geom2dGcc_QualifiedCurve.hxx>
47 #include <Geom2dGcc_Lin2d2Tan.hxx>
48 #include <Geom2d_Line.hxx>
49 #include <BRepBuilderAPI_MakeEdge.hxx>
50 #include <TopoDS_Edge.hxx>
51 #include <Precision.hxx>
52 #include <Geom2d_Circle.hxx>
53 #include <Geom2dGcc_MyQCurve.hxx>
54 #include <GccEnt_QualifiedCirc.hxx>
55 #include <Geom2dGcc_MyL2d2Tan.hxx>
56 #include <BRepBuilderAPI_MakeWire.hxx>
57 #include <TopExp_Explorer.hxx>
58 #include <TopoDS.hxx>
59 #include <TopoDS_Wire.hxx>
60 #include <BRep_Tool.hxx>
61 #include <gp_Circ.hxx>
62 #include <BRepOffsetAPI_MakePipeShell.hxx>
63 #include <AIS_Trihedron.hxx>
64 #include <Geom_Axis2Placement.hxx>
65 #include <V3d_View.hxx>
66 #include <ViewerTest_Tool.hxx>
67 #include <BRepBuilderAPI_MakeVertex.hxx>
68 #include <AIS_LengthDimension.hxx>
69 #include <AIS_RadiusDimension.hxx>
70 #include <BRepPrimAPI_MakeBox.hxx>
71 #include <GeomAdaptor_Surface.hxx>
72 #include <Extrema_ExtPS.hxx>
73 #include <Geom_CartesianPoint.hxx>
74 #include <Geom2d_CartesianPoint.hxx>
75 #include <Geom2dGcc_Circ2d3Tan.hxx>
76 #include <Aspect_Window.hxx>
77
78 #include <TopoDS_Compound.hxx>
79 #include <TopoDS_CompSolid.hxx>
80 #include <StdSelect_ShapeTypeFilter.hxx>
81
82 #include <QABugs_MyText.hxx>
83
84 #if defined(WOKC40)
85 #include <QAViewer2dTest.hxx>
86 #include <QAViewer2dTest_DoubleMapOfInteractiveAndName.hxx>
87 #else
88 #include <Viewer2dTest.hxx>
89 #include <Viewer2dTest_DoubleMapOfInteractiveAndName.hxx>
90 #endif
91
92 #include <Prs3d_Projector.hxx>
93 #include <HLRAlgo_Projector.hxx>
94 #include <AIS2D_ProjShape.hxx>
95 #include <AIS2D_InteractiveContext.hxx>
96 #include <Standard_ErrorHandler.hxx>
97
98 #if ! defined(WNT)
99 #if defined(WOKC40)
100 extern QAViewer2dTest_DoubleMapOfInteractiveAndName& GetMapOfAIS2D();
101 #else
102 extern Viewer2dTest_DoubleMapOfInteractiveAndName& GetMapOfAIS2D();
103 #endif
104 #else
105 Standard_EXPORT Viewer2dTest_DoubleMapOfInteractiveAndName& GetMapOfAIS2D();
106 #endif
107
108 #include <GGraphic2d_SetOfCurves.hxx>
109 #include <Graphic2d_SetOfSegments.hxx>
110
111 #include <Font_NameOfFont.hxx>
112
113 static Standard_Integer BUC60842 (Draw_Interpretor& di, Standard_Integer /*argc*/,const char ** /*argv*/)
114 {
115   Standard_Character abuf[16];
116   //Standard_Character * abuf = new Standard_Character[16];
117
118   Standard_CString st = abuf;
119
120   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);
121   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);
122   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))));
123
124   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
125
126   gp_Pln pln = plne->Pln();
127   Handle(Geom2d_Curve) curve2d = GeomAPI::To2d (ell, pln);
128   sprintf(abuf,"ell");
129   DrawTrSurf::Set(st,curve2d);
130   if(!aContext.IsNull()) {
131     Handle(AIS_Shape) aisp = 
132       new AIS_Shape (BRepBuilderAPI_MakeEdge(GeomAPI::To3d(curve2d, pln)).Edge());
133     aContext->Display (aisp);
134   }
135
136   Handle(Geom2d_Curve) fromcurve2d = GeomAPI::To2d (cir, pln);
137   sprintf(abuf,"cil");
138   DrawTrSurf::Set(st,fromcurve2d);
139   if(!aContext.IsNull()) {
140     Handle(AIS_Shape) aisp = 
141       new AIS_Shape (BRepBuilderAPI_MakeEdge(GeomAPI::To3d(fromcurve2d, pln)).Edge());
142     aContext->Display (aisp);
143   }
144
145   Geom2dAdaptor_Curve acur (curve2d), afromcur (fromcurve2d);
146   Geom2dGcc_QualifiedCurve qcur (acur, GccEnt_outside);
147   Geom2dGcc_QualifiedCurve qfromcur (afromcur, GccEnt_outside);
148   Geom2dGcc_Lin2d2Tan lintan (qcur, qfromcur, 0.1, 0.0, 0.0);
149   Standard_Integer i=0;
150   for(i=0;i<lintan.NbSolutions();i++) {
151     sprintf(abuf,"lintan_%d",i);
152     Handle(Geom2d_Line) glin = new Geom2d_Line(lintan.ThisSolution(i));
153     DrawTrSurf::Set(st,glin);
154     if(!aContext.IsNull()) {
155       Handle(AIS_Shape) aisp = 
156         new AIS_Shape (BRepBuilderAPI_MakeEdge(GeomAPI::To3d(glin, pln)).Edge());      aContext->Display (aisp);
157     }
158   }
159   di << " Is Done = \n" << (Standard_Integer) lintan.IsDone();
160   return 0;
161 }
162
163 static Standard_Integer BUC60843 (Draw_Interpretor& di, Standard_Integer argc,const char ** argv)
164 {
165   if (argc != 4 && argc != 5 && argc != 6 && argc != 7) {
166     di << "Usage : " << argv[0] << "result_shape name_of_circle name_of_curve [ par1 [ tol ] ]" << "\n";
167     return 1;
168   }
169
170   Standard_Real par1 = 0.0, par2 = 0.0;
171   Standard_Real tol  = Precision::Angular();
172   if (argc >= 5)
173     par1 = atof(argv[4]);
174   if (argc == 6)
175     par2 = atof(argv[5]);
176   if (argc == 7)
177     tol = atof(argv[6]);
178   Handle(Geom2d_Curve)  aCur2d1 = DrawTrSurf::GetCurve2d(argv[2]);
179   Handle(Geom2d_Curve)  aCur2d2 = DrawTrSurf::GetCurve2d(argv[3]);
180   if (aCur2d1.IsNull() || aCur2d2.IsNull()) {
181     di << "Faulty : not curves" << "\n";
182     return 1;
183   }
184   Standard_Boolean c1IsCircle = Standard_False;
185   Handle(Geom2d_Circle) aCir2d = Handle(Geom2d_Circle)::DownCast(aCur2d1);
186   if (!aCir2d.IsNull()) {
187     c1IsCircle = Standard_True;
188     if (argc == 6) tol = atof(argv[5]);
189   }
190   if(c1IsCircle) {
191     Geom2dAdaptor_Curve acur(aCur2d2);
192     Geom2dGcc_MyQCurve qcur(acur, GccEnt_unqualified);
193     GccEnt_QualifiedCirc qfromcur(aCir2d->Circ2d(), GccEnt_unqualified);
194     Geom2dGcc_MyL2d2Tan lintan(qfromcur, qcur , par1, tol); 
195     if (lintan.IsDone()) {
196       gp_Lin2d lin = lintan.ThisSolution(); 
197       Handle(Geom2d_Line) glin = new Geom2d_Line(lin); 
198       DrawTrSurf::Set(argv[1], glin);
199     } else {
200       di << "Faulty : tangent line is not done." << "\n";
201     }
202   }
203   else {
204     Geom2dAdaptor_Curve acur1(aCur2d1);
205     Geom2dAdaptor_Curve acur2(aCur2d2);
206     Geom2dGcc_MyQCurve qcur1(acur1, GccEnt_unqualified);
207     Geom2dGcc_MyQCurve qcur2(acur2, GccEnt_unqualified);
208     Geom2dGcc_MyL2d2Tan lintan(qcur1, qcur2 , par1, par2, tol); 
209     if (lintan.IsDone()) {
210       gp_Lin2d lin = lintan.ThisSolution(); 
211       Handle(Geom2d_Line) glin = new Geom2d_Line(lin); 
212       DrawTrSurf::Set(argv[1], glin);
213     } else {
214       di << "Faulty : tangent line is not done." << "\n";
215     }
216   }   
217   return 0;
218 }
219
220 static Standard_Integer BUC60970 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
221 {
222   if(argc!=3)
223   {
224     di << "Usage : " << argv[0] << " shape result" <<"\n";
225     return 1;
226   }
227
228   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
229   if(aContext.IsNull()) {
230     di << "use 'vinit' command before " << argv[0] << "\n";
231     return 1;
232   }
233
234   TopoDS_Shape aResult = DBRep::Get(argv[1]);
235
236   BRepBuilderAPI_MakeWire bRepSpineWire; 
237   TopExp_Explorer exp_(aResult, TopAbs_WIRE); 
238
239   Standard_Integer i = 0; 
240   for(;exp_.More();exp_.Next()){     
241     i++; 
242     bRepSpineWire.Add(TopoDS::Wire(exp_.Current())); 
243   } 
244
245   //printf("total no of wires are ............. %d\n", i); 
246   di << "total no of wires are ............. " << i << "\n"; 
247
248   TopoDS_Wire spineWire = bRepSpineWire.Wire(); 
249   aContext->Display(new AIS_Shape(spineWire)); 
250
251   DBRep::Set("slineW",spineWire);
252
253   TopExp_Explorer spineWireExp(spineWire, TopAbs_EDGE); 
254   Standard_Real first, last; 
255   Handle_Geom_Curve curl_ = BRep_Tool::Curve(TopoDS::Edge(spineWireExp.Current()), first, last); 
256   gp_Pnt firstPnt; 
257   gp_Vec tanVec; 
258   curl_->D1(first, firstPnt, tanVec); 
259   tanVec.Normalize(); 
260   gp_Dir tanDir(tanVec.X(), tanVec.Y(), tanVec.Z()); 
261   gp_Ax2 gpAx2(firstPnt, tanDir); 
262   gp_Circ gpCirc(gpAx2, 2.5); 
263   BRepBuilderAPI_MakeWire aMWire(BRepBuilderAPI_MakeEdge(new Geom_Circle(gpCirc)).Edge());
264   TopoDS_Wire topoWire(aMWire); 
265   aContext->Display(new AIS_Shape(topoWire));
266
267   DBRep::Set("topoW",topoWire);
268
269   BRepOffsetAPI_MakePipeShell bRepPipe(spineWire);
270   bRepPipe.Add(topoWire); 
271   bRepPipe.Build(); 
272
273   aContext->Display(new AIS_Shape(bRepPipe.Shape())); 
274
275   DBRep::Set(argv[2],bRepPipe.Shape());
276
277   return 0;
278 }
279
280 static Standard_Integer  BUC60818(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
281 {
282   if(argc!=1)
283   {
284     di << "Usage : " << argv[0] << "\n";
285     return -1;
286   }
287
288   Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
289   if(myAISContext.IsNull()) 
290   {
291     di << "use 'vinit' command before " << argv[0] << "\n";
292     return -1;
293   }
294
295   // TRIHEDRON
296   Handle(AIS_Trihedron) aTrihedron;
297   Handle(Geom_Axis2Placement) aTrihedronAxis=new Geom_Axis2Placement(gp::XOY());
298   aTrihedron=new AIS_Trihedron(aTrihedronAxis);
299   myAISContext->Display(aTrihedron);
300
301   myAISContext->OpenLocalContext(); 
302   myAISContext->Load(aTrihedron,0); 
303
304   myAISContext->SetAutomaticHilight(  Standard_False );
305
306   Handle(V3d_View) myV3dView = ViewerTest::CurrentView();
307   double Xv,Yv;
308   myV3dView->Project(0,0,0,Xv,Yv);
309
310   Standard_Integer Xp,Yp;
311   myV3dView->Convert(Xv,Yv,Xp,Yp);
312
313   myAISContext->MoveTo( Xp,Yp, myV3dView  );
314   myAISContext->MoveTo( Xp,Yp, myV3dView  );
315
316   if (myAISContext->HasDetected(  )) 
317     di << "has detected shape : OK"   << "\n";
318   else       di << "has detected shape : bugged - Faulty "   << "\n";
319
320   myAISContext->SetAutomaticHilight(  Standard_True );
321
322   return 0;
323 }
324
325 static Standard_Integer BUC60915_1(Draw_Interpretor& di, Standard_Integer argc, const char ** /*argv*/)
326 {
327   if (argc > 1) {
328     di<<"Function don't has parameters"<<"\n";
329     return 1;
330   }
331
332   Handle(AIS_InteractiveContext)   context= ViewerTest_Tool::MakeContext ("buc60915");
333   ViewerTest_Tool::InitViewerTest (context);
334
335   //The following dimesion code has problems regarding arrow_size. The desired effect is not produced.
336   /***************************************/
337   //First view
338   /***************************************/
339   gp_Pnt p1 = gp_Pnt(602.51,50.,0.);
340   gp_Pnt p2 = gp_Pnt(602.51,200.,0.);
341   gp_Pnt p3 = gp_Pnt(102.51,200.,0.);
342   gp_Pnt p4 = gp_Pnt(102.51,170.,0.);
343   gp_Pnt p5 = gp_Pnt(502.51,170.,0.);
344   gp_Pnt p6 = gp_Pnt(502.51,80.,0.);
345   gp_Pnt p7 = gp_Pnt(102.51,80.,0.);
346   gp_Pnt p8 = gp_Pnt(102.51,50.,0.);
347   TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(p1);
348   TopoDS_Vertex V2 = BRepBuilderAPI_MakeVertex(p2);
349   TopoDS_Vertex V3 = BRepBuilderAPI_MakeVertex(p3);
350   TopoDS_Vertex V4 = BRepBuilderAPI_MakeVertex(p4);
351   TopoDS_Vertex V5 = BRepBuilderAPI_MakeVertex(p5);
352   TopoDS_Vertex V6 = BRepBuilderAPI_MakeVertex(p6);
353   TopoDS_Vertex V7 = BRepBuilderAPI_MakeVertex(p7);
354   TopoDS_Vertex V8 = BRepBuilderAPI_MakeVertex(p8);
355   gp_Pnt plnpt(0, 0, 0);
356   gp_Dir plndir(0, 0, 1);
357   Handle(Geom_Plane) pln = new Geom_Plane(plnpt,plndir);
358   /***************************************/
359   //dimension "L 502.51"
360   /***************************************/
361   Handle(AIS_LengthDimension) len = new AIS_LengthDimension(V2, V3, pln, 502.51, "502.51");
362   len->SetPosition(gp_Pnt(350, 250, 0));
363   len->SetTypeOfDist(AIS_TOD_Horizontal);
364   len->SetArrowSize(30.0);
365   context->Display(len);
366   /***************************************/
367   //dimension "L 90"
368   /***************************************/
369   Handle(AIS_LengthDimension) len1 = new AIS_LengthDimension(V4, V7, pln, 90, "90");
370   len1->SetPosition(gp_Pnt(70, 120, 0));
371   len1->SetTypeOfDist(AIS_TOD_Vertical);
372   len1->SetArrowSize(100.0);
373   context->Display(len1);
374   /***************************************/
375   //dimension "L 150"
376   /***************************************/
377   Handle(AIS_LengthDimension) len2 = new AIS_LengthDimension(V1, V2, pln, 150, "150",gp_Pnt(650, 120, 0),DsgPrs_AS_BOTHAR,
378     AIS_TOD_Vertical, 100.0 );
379   //len2->SetPosition(gp_Pnt(650, 120, 0));
380   //len2->SetTypeOfDist(AIS_TOD_Vertical);
381   //len1->SetArrowSize(100.0);
382   context->Display(len2);
383   /***************************************/
384   //dimension "R 88.58"
385   /***************************************/
386   gp_Circ cir = gp_Circ(gp_Ax2(gp_Pnt(191.09, -88.58, 0), gp_Dir(0, 0, 1)), 88.58);
387   TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(cir,gp_Pnt(191.09,0,0.),gp_Pnt(191.09,-177.16,0.) );
388   Handle(AIS_RadiusDimension) dim1 = new AIS_RadiusDimension(E1,88.58, "R 88.58",gp_Pnt(-30.0, -80.0, 0.0),DsgPrs_AS_BOTHAR,
389     100.0 );
390   context->Display(dim1);
391   /***************************************/
392   //dimension "R 43.80"
393   /***************************************/
394   gp_Circ cir1 = gp_Circ(gp_Ax2(gp_Pnt(191.09, -88.58, 0), gp_Dir(0, 0, 1)), 43.80);
395   TopoDS_Edge E_cir1 = BRepBuilderAPI_MakeEdge(cir1);
396   dim1 = new AIS_RadiusDimension(E_cir1,43.80, "R 43.80",gp_Pnt(0.0, -50.0, 0.0),DsgPrs_AS_LASTAR, 60.0 );
397   context->Display(dim1);
398   /***************************************/
399   //dimension "R 17.86"
400   /***************************************/
401   gp_Circ cir2 = gp_Circ(gp_Ax2(gp_Pnt(566.11, -88.58, 0), gp_Dir(0, 0, -1)), 17.86);
402   TopoDS_Edge E_cir2 = BRepBuilderAPI_MakeEdge(cir2);
403   dim1 = new AIS_RadiusDimension(E_cir2,17.86, "R 17.86",gp_Pnt(600.0, -50.0, 0.0),DsgPrs_AS_LASTAR, 40.0 );
404   context->Display(dim1);
405
406   return 0;
407 }
408
409 static Standard_Integer  OCC138 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv)
410 {
411   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
412   if(aContext.IsNull()) { 
413     di << "use 'vinit' command before " << argv[0] << "\n";
414     return 1;
415   }
416
417   BRepPrimAPI_MakeBox box1(gp_Pnt(0, 0, 0),  gp_Pnt(100, 100, 100));
418   BRepPrimAPI_MakeBox box2(gp_Pnt(120, 120, 120),  gp_Pnt(300, 300,300));
419   BRepPrimAPI_MakeBox box3(gp_Pnt(320, 320, 320),  gp_Pnt(500, 500,500));
420
421   Handle_AIS_Shape ais1 = new AIS_Shape(box1.Shape());
422   Handle_AIS_Shape ais2 = new AIS_Shape(box2.Shape());
423   Handle_AIS_Shape ais3 = new AIS_Shape(box3.Shape());
424
425   aContext->Display(ais1);
426   aContext->Display(ais2);
427   aContext->Display(ais3);
428
429   aContext->AddOrRemoveCurrentObject(ais1);
430   aContext->AddOrRemoveCurrentObject(ais2);
431   aContext->AddOrRemoveCurrentObject(ais3);
432
433   di << "\n No of currents = " << aContext->NbCurrents();
434
435   aContext->InitCurrent();
436
437   int count = 1;
438   while(aContext->MoreCurrent())
439   {
440     di << "\n count is = " << count++;
441     Handle_AIS_InteractiveObject ais = aContext->Current();
442     aContext->AddOrRemoveCurrentObject(ais);
443     aContext->InitCurrent();
444   }
445
446   return 0; 
447 }
448
449 static Standard_Integer BUC60821(Draw_Interpretor& di, Standard_Integer argc,const char ** argv )   
450 {
451
452   if(argc < 3){
453     di << "Usage: " << argv[0] << " TextHight1 TextHight2 TextHight2";
454     return(-1);
455   }
456
457   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
458
459   if(aContext.IsNull()) 
460   { 
461     di << "use 'vinit' command before " << argv[0] << "\n";
462     return -1;
463   }
464
465   Handle(QABugs_MyText) txt1 = new QABugs_MyText("Gosha1",gp_Pnt(0,0,0),Font_NOF_ASCII_SIMPLEX,Quantity_NOC_RED,atoi(argv[1]));
466   aContext->Display(txt1);
467
468   Handle(QABugs_MyText) txt2 = new QABugs_MyText("Gosha2",gp_Pnt(0,0,100),Font_NOF_ASCII_SIMPLEX,Quantity_NOC_YELLOW,atoi(argv[2]));
469   aContext->Display(txt2);
470
471   Handle(QABugs_MyText) txt3 = new QABugs_MyText("Gosha3",gp_Pnt(0,100,100),Font_NOF_ASCII_SIMPLEX,Quantity_NOC_SKYBLUE,atoi(argv[3]));
472   aContext->Display(txt3);
473
474   return 0;
475 }
476
477 static int geom_get_2Dpt_from_3Dpt(const gp_Pnt& pnt3d, const gp_Pln& pln, gp_Pnt2d& pnt2d)
478
479   int ret = 0; 
480   Handle_Geom_Plane gpln = new Geom_Plane(pln); 
481   GeomAdaptor_Surface adsur(gpln); 
482   Extrema_ExtPS extps(pnt3d, adsur, 0.001, 0.001); 
483   if( extps.IsDone() ) 
484   { 
485     int index;
486     for(index=1; index<= extps.NbExt(); index++ ) 
487     { 
488       Extrema_POnSurf pons = extps.Point(index); 
489       Standard_Real U, V; 
490       pons.Parameter(U, V); 
491       pnt2d.SetCoord(U, V); 
492       ret = 1; 
493     } 
494   } 
495   return ret;
496
497
498 static Standard_Integer OCC353 (Draw_Interpretor& di, Standard_Integer , const char ** )
499 {
500   gp_Ax2 ax21( gp_Pnt(100,0,0), gp_Dir(0,0,1) );
501   Handle_Geom_Circle h_cir1 = new Geom_Circle( ax21, 25 );
502
503   gp_Ax2 ax22( gp_Pnt(-100,0,0), gp_Dir(0,0,1) );
504   Handle_Geom_Circle h_cir2 = new Geom_Circle( ax22, 25 );
505
506   gp_Pln refpln( gp_Pnt(0,0,0), gp_Dir(0,0,1) );
507   Handle_Geom2d_Curve cir2d1 = GeomAPI::To2d(h_cir1, refpln);
508   Handle_Geom2d_Curve cir2d2 = GeomAPI::To2d(h_cir2, refpln);
509
510   Geom2dAdaptor_Curve adop1(cir2d1);
511   Geom2dAdaptor_Curve adop2(cir2d2);
512
513   Geom2dGcc_QualifiedCurve qcur1(adop1, GccEnt_enclosing);
514   Geom2dGcc_QualifiedCurve qcur2(adop2, GccEnt_enclosing);
515
516   Handle_Geom_CartesianPoint h_carpt = new Geom_CartesianPoint(0,175,0);
517
518   gp_Pnt pt3d = h_carpt->Pnt();
519   gp_Pnt2d pt2d;
520   geom_get_2Dpt_from_3Dpt(pt3d, refpln, pt2d);
521
522   Standard_CString st;
523   st = "cir2d1";
524   DrawTrSurf::Set(st,cir2d1);
525   st = "cir2d2";
526   DrawTrSurf::Set(st,cir2d2);
527   st = "pt2d";
528   DrawTrSurf::Set(st,pt2d);
529
530   Handle_Geom2d_CartesianPoint pt = new Geom2d_CartesianPoint(pt2d);
531   Geom2dGcc_Circ2d3Tan sol( qcur1, qcur2, pt, 0.001, 0.0, 0.0);
532
533   int res = 0;
534   Standard_Character buf[10];
535   buf[0] = '\0';
536
537   if( sol.IsDone() ) {
538     res = sol.NbSolutions();
539     for(Standard_Integer i=1;i<=res;i++) {
540       Handle(Geom2d_Circle) aC = new Geom2d_Circle(sol.ThisSolution(i));
541       sprintf(buf,"Result_%d",i);
542       st = buf;
543       DrawTrSurf::Set(st,aC);
544     }
545   }
546   else
547     di << "\n Faulty: no solutions found ";
548   //printf("\n Faulty: no solutions found ");
549
550   //printf("\n Num of solutions are %d ", res );
551   di << "\n Num of solutions are " << res << " ";
552
553   return 0;
554 }
555
556 static Standard_Integer OCC280 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
557 {
558   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
559   if(aContext.IsNull()) 
560   { 
561     di << "use 'vinit' command before " << argv[0] << "\n";
562     return -1;
563   }
564   if ( argc != 3) {
565     di << "ERROR : Usage : " << argv[0] << " hlr=0/1 setsurfecedetail=0/1; set perspecrive view" << "\n";
566     return 1;
567   }
568
569   Standard_Integer HLR = atoi(argv[1]);
570   if (HLR != 0) {
571     HLR = 1;
572   }
573
574   Handle(V3d_View) anOldView = ViewerTest::CurrentView();
575   Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
576   if (atoi (argv[2]))
577   {
578     aViewer->SetDefaultSurfaceDetail (V3d_TEX_ALL);
579   }
580   aViewer->SetDefaultTypeOfView (V3d_PERSPECTIVE);
581
582   Handle(Aspect_Window) asp = anOldView->Window();
583   aViewer->SetViewOff (anOldView);
584
585   Handle(V3d_View) aNewView = aViewer->CreateView();
586   ViewerTest::CurrentView (aNewView);
587
588   aNewView->SetWindow (asp);
589   if (!asp->IsMapped()) asp->Map();
590
591   anOldView->Remove();
592   anOldView.Nullify();
593
594   aNewView->Update();
595
596   // replace view in event manager
597   ViewerTest::UnsetEventManager();
598   ViewerTest::SetEventManager (new ViewerTest_EventManager (aNewView, ViewerTest::GetAISContext()));
599
600   if (HLR == 1) {
601     di << "HLR" << "\n";
602     aNewView->SetDegenerateModeOff();
603   }
604
605   return 0;
606 }
607
608 static Standard_Integer  OCC232 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
609 {
610   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
611   if(aContext.IsNull()) { 
612     di << "use 'vinit' command before " << argv[0] << "\n";
613     return 1;
614   }
615
616   BRep_Builder builder;
617   TopoDS_Compound comp;
618   TopoDS_CompSolid cs1, cs2;
619
620   builder.MakeCompound(comp);
621   builder.MakeCompSolid(cs1);
622   builder.MakeCompSolid(cs2);
623
624   TopoDS_Shape sh1 = BRepPrimAPI_MakeBox(gp_Pnt(0, 0, 0), 100, 100, 100).Shape();
625   TopoDS_Shape sh2 = BRepPrimAPI_MakeBox(gp_Pnt(100, 0, 0), 100, 100, 100).Shape();
626   TopoDS_Shape sh3 = BRepPrimAPI_MakeBox(gp_Pnt(200, 0, 0), 100, 100, 100).Shape();
627   builder.Add(cs1, sh1);
628   builder.Add(cs1, sh2);
629   builder.Add(cs1, sh3);
630
631   TopoDS_Shape sh4 = BRepPrimAPI_MakeBox(gp_Pnt(0, 500, 0), 100, 100, 100).Shape();
632   TopoDS_Shape sh5 = BRepPrimAPI_MakeBox(gp_Pnt(100, 500, 0), 100, 100, 100).Shape();
633   TopoDS_Shape sh6 = BRepPrimAPI_MakeBox(gp_Pnt(200, 500, 0), 100, 100, 100).Shape();
634
635   builder.Add(cs2, sh4);
636   builder.Add(cs2, sh5);
637   builder.Add(cs2, sh6);
638
639   builder.Add(comp, cs1);
640   builder.Add(comp, cs2);
641
642   Handle_AIS_Shape ais = new AIS_Shape(comp);
643   aContext->Display(ais);
644
645   TopExp_Explorer exp(comp,  TopAbs_COMPSOLID);
646   while(exp.More())
647   {
648     //printf("\n TopAbs_COMPSOLID is  there \n");
649     di << "\n TopAbs_COMPSOLID is  there \n";
650     exp.Next();
651   }
652
653   Handle (StdSelect_ShapeTypeFilter) filt = new StdSelect_ShapeTypeFilter(TopAbs_COMPSOLID);
654   aContext->AddFilter(filt);
655   aContext->CloseAllContexts();
656   aContext->OpenLocalContext(); 
657   aContext->ActivateStandardMode(TopAbs_SOLID);
658
659   return 0; 
660 }
661
662 static Standard_Integer  OCC138LC (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv)
663 {
664   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
665   if(aContext.IsNull()) { 
666     di << "use 'vinit' command before " << argv[0] << "\n";
667     return 1;
668   }
669
670   BRepPrimAPI_MakeBox box1(gp_Pnt(0, 0, 0),  gp_Pnt(100, 100, 100));
671   BRepPrimAPI_MakeBox box2(gp_Pnt(120, 120, 120),  gp_Pnt(300, 300,300));
672   BRepPrimAPI_MakeBox box3(gp_Pnt(320, 320, 320),  gp_Pnt(500, 500,500));
673
674   Handle_AIS_Shape ais1 = new AIS_Shape(box1.Shape());
675   Handle_AIS_Shape ais2 = new AIS_Shape(box2.Shape());
676   Handle_AIS_Shape ais3 = new AIS_Shape(box3.Shape());
677
678   aContext->Display(ais1);
679   aContext->Display(ais2);
680   aContext->Display(ais3);
681
682   aContext->AddOrRemoveSelected(ais1);
683   aContext->AddOrRemoveSelected(ais2);
684   aContext->AddOrRemoveSelected(ais3);
685
686   di << "\n No of selected = " << aContext->NbSelected();
687
688   aContext->InitSelected();
689
690   int count = 1;
691   while(aContext->MoreSelected())
692   {
693     di << "\n count is = %d" << count++;
694     Handle_AIS_InteractiveObject ais = aContext->SelectedInteractive();
695     aContext->AddOrRemoveSelected(ais);
696     aContext->InitSelected();
697   }
698
699   return 0; 
700 }
701
702 static Standard_Integer  OCC189 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv)
703 {
704   Handle(AIS_InteractiveContext) aContext1 = ViewerTest::GetAISContext();
705   if(aContext1.IsNull()) { 
706     di << "use 'vinit' command before " << argv[0] << "\n";
707     return 1;
708   }
709   Handle(AIS_InteractiveContext) aContext2 = ViewerTest::GetAISContext();
710   if(aContext2.IsNull()) { 
711     di << "use 'vinit' command before " << argv[0] << "\n";
712     return 1;
713   }
714
715   BRepPrimAPI_MakeBox box1(gp_Pnt(0, 0, 0),  gp_Pnt(100, 100, 100));
716   BRepPrimAPI_MakeBox box2(gp_Pnt(120, 120, 120),  gp_Pnt(300, 300, 300));
717   BRepPrimAPI_MakeBox box3(gp_Pnt(320, 320, 320),  gp_Pnt(500, 500, 500));
718
719   Handle_AIS_Shape ais1 = new AIS_Shape(box1.Shape());
720   Handle_AIS_Shape ais2 = new AIS_Shape(box2.Shape());
721   Handle_AIS_Shape ais3 = new AIS_Shape(box3.Shape());
722
723   aContext1->Display(ais1);
724   aContext1->Display(ais2);
725   aContext1->Display(ais3);
726
727   aContext2->Display(ais1);
728   aContext2->Display(ais2);
729   aContext2->Display(ais3);
730
731   aContext1->AddOrRemoveCurrentObject(ais1);
732   aContext1->AddOrRemoveCurrentObject(ais2);
733   aContext1->AddOrRemoveCurrentObject(ais3);
734
735   di << "\n Stage : 1";
736   di << "\n \t No of currents on aContext1 = " << aContext1->NbCurrents();
737   di << "\n \t No of currents on aContext2 = " << aContext2->NbCurrents() << "\n\n";
738
739   di << "\n aContext1->IsCurrent = " << (Standard_Integer) aContext1->IsCurrent(ais1) << ", aContext2->IsCurrent = " << (Standard_Integer) aContext2->IsCurrent(ais1) << " ";
740
741   aContext2->AddOrRemoveCurrentObject(ais1);
742   aContext2->AddOrRemoveCurrentObject(ais2);
743   aContext2->AddOrRemoveCurrentObject(ais3);
744
745   di << "\n Stage : 2";
746   di << "\n \t No of currents on aContext1 = " << aContext1->NbCurrents();
747   di << "\n \t No of currents on aContext2 = " << aContext2->NbCurrents() << "\n\n";
748
749   aContext1->InitCurrent();
750   int count1 = 1;
751   while(aContext1->MoreCurrent())
752   {
753     di << "\n count1 is = " << count1++;
754     Handle_AIS_InteractiveObject ais = aContext1->Current();
755     aContext1->AddOrRemoveCurrentObject(ais);
756     aContext1->InitCurrent();
757   }
758
759   di << "\n Stage : 3";
760   di << "\n \t No of currents on aContext1 = " << aContext1->NbCurrents();
761   di << "\n \t No of currents on aContext2 = " << aContext2->NbCurrents() << "\n\n";
762
763   aContext2->InitCurrent();
764   int count2 = 1;
765   while(aContext2->MoreCurrent())
766   {
767     di << "\n count2 is = " << count2++;
768     Handle_AIS_InteractiveObject ais = aContext2->Current();
769     aContext2->AddOrRemoveCurrentObject(ais);
770     aContext2->InitCurrent();
771   }
772
773   di << "\n\n Stage : 4";
774   di << "\n \t No of currents on aContext1 = " << aContext1->NbCurrents();
775   di << "\n \t No of currents on aContext2 = " << aContext2->NbCurrents();
776
777   return 0; 
778 }
779
780 static Standard_Integer  OCC389 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
781 {
782   if (argc < 3)
783   {
784     di<<"Usage: " << argv[0] << " name shape1 [shape2] ..."<<"\n";
785     return 1;
786   }
787
788   //if (Viewer2dTest::CurrentView().IsNull())
789   //{ 
790   //  cout << "2D AIS Viewer Initialization ..." << endl;
791   //  Viewer2dTest::ViewerInit(); 
792   //  cout << "Done" << endl;
793   //}
794
795   di<<"Begin!"<<"\n";
796   Handle(AIS2D_InteractiveContext) aContext = Viewer2dTest::GetAIS2DContext();
797   di<<"Check InteractiveContext"<<"\n";
798
799   if(aContext.IsNull()) {
800     di << "use 'v2dinit' command before " << argv[0] << "\n";
801     return 1;
802   }
803
804   di<<"CloseLocalContext"<<"\n";
805   aContext->CloseLocalContext();
806
807   di<<"OpenLocalContext"<<"\n";
808   aContext->OpenLocalContext();
809
810   TCollection_AsciiString name(argv[1]);
811
812   di<<"Found name"<<"\n";
813   Standard_Boolean IsBound = GetMapOfAIS2D().IsBound2(name);
814   if (IsBound)
815   {
816     di<<"Already displayed"<<"\n";
817   }
818   else // Create the AIS2D_ProjShape from a name
819   {
820     di<<"Create the AIS2D_ProjShape from a name; (1)"<<"\n";
821     Prs3d_Projector aPrs3dProjector(Standard_False, 1, -1.0,0.2,0.3, 0.0, 0.0, 0.0, -0.0,0.0,1.0);
822     di<<"Create the AIS2D_ProjShape from a name; (2)"<<"\n";
823     HLRAlgo_Projector aProjector = aPrs3dProjector.Projector();
824     di<<"Create the AIS2D_ProjShape from a name; (3)"<<"\n";
825     Handle(AIS2D_ProjShape) shp_2d =
826       new AIS2D_ProjShape(aProjector, 0, Standard_False, Standard_True);
827     di<<"Create the AIS2D_ProjShape from a name; (4)"<<"\n";
828
829     Standard_Integer i;
830     Standard_Boolean isValid = Standard_False;
831     for (i = 2; i < argc; i++)
832     {
833       di<<"i="<< i-1 <<"\n";
834       TopoDS_Shape aShape = DBRep::Get(argv[i]);
835       if (!aShape.IsNull())
836       {
837         shp_2d->Add( aShape );
838         di<<"Added shape: "<<argv[i]<<"\n";
839         isValid = Standard_True;
840       }
841     }
842
843     if (isValid)
844     {
845       di<<"Now start displaying..."<<"\n";
846       aContext->Display(shp_2d, 1, 1, Standard_True);
847
848       GetMapOfAIS2D().Bind(shp_2d, name);
849     }
850   }
851
852   aContext->UpdateCurrentViewer();
853   return 0; 
854 }
855
856 #include <BRepBndLib.hxx>
857 #include <Draw.hxx>
858 //=======================================================================
859 //function : OCC566
860 //purpose  : 
861 //=======================================================================
862 static Standard_Integer OCC566(Draw_Interpretor& di,Standard_Integer n,const char ** a)
863 {
864   if (n < 2) {
865     di<<"Usage: " << a[0] << " shape [ xmin ymin zmin xmax ymax zmax]"<<"\n";
866     return 1;
867   }
868   TopoDS_Shape S = DBRep::Get(a[1]);
869   if (S.IsNull()) return 1;
870   Bnd_Box B;
871   BRepBndLib::AddClose(S,B);
872   Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
873   B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
874   di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax;
875   if (n >= 8) {
876     Draw::Set(a[2],axmin) ;
877     Draw::Set(a[3],aymin) ;
878     Draw::Set(a[4],azmin) ;
879     Draw::Set(a[5],axmax) ;
880     Draw::Set(a[6],aymax) ;
881     Draw::Set(a[7],azmax) ;
882   }
883   return 0;
884 }
885
886 #include <BRepFilletAPI_MakeFillet.hxx>
887 //=======================================================================
888 //function : OCC570
889 //purpose  : 
890 //=======================================================================
891 static Standard_Integer OCC570 (Draw_Interpretor& di, Standard_Integer argc,const char ** argv)
892 {
893   if (argc < 2) {
894     di<<"Usage: " << argv[0] << " result"<<"\n";
895     return 1;
896   }
897
898   BRepPrimAPI_MakeBox mkBox(100.,100.,100.);
899   TopoDS_Shape aBox = mkBox.Shape();
900
901   TopExp_Explorer aExp;
902   aExp.Init(aBox,TopAbs_WIRE);
903   if (aExp.More())
904   {
905     TopoDS_Shape aWire = aExp.Current();
906
907     aExp.Init(aWire,TopAbs_EDGE);
908     TopoDS_Edge e1 = TopoDS::Edge(aExp.Current()); aExp.Next();
909     TopoDS_Edge e2 = TopoDS::Edge(aExp.Current()); aExp.Next();
910     TopoDS_Edge e3 = TopoDS::Edge(aExp.Current()); aExp.Next();
911     TopoDS_Edge e4 = TopoDS::Edge(aExp.Current());
912
913     try
914     {
915       OCC_CATCH_SIGNALS
916         BRepFilletAPI_MakeFillet mkFillet(aBox);
917       mkFillet.SetContinuity(GeomAbs_C1,.001);
918
919       // Setup variable fillet data
920       TColgp_Array1OfPnt2d t_pnt(1,4);
921       t_pnt.SetValue(1,gp_Pnt2d(0.0,5.0));
922       t_pnt.SetValue(2,gp_Pnt2d(0.3,15.0));
923       t_pnt.SetValue(3,gp_Pnt2d(0.7,15.0));
924       t_pnt.SetValue(4,gp_Pnt2d(1.0,5.0));
925
926       // HERE:
927       // It is impossible to build fillet if at least one edge
928       // with variable radius is added!!! If all are constant, everything is ok.
929       mkFillet.Add(t_pnt,e1);
930       mkFillet.Add(5.0,e2);
931       mkFillet.Add(t_pnt,e3);
932       mkFillet.Add(5.0,e4);
933
934       mkFillet.Build();
935       TopoDS_Shape aFinalShape = mkFillet.Shape();
936
937       DBRep::Set(argv[1],aFinalShape);
938     }
939     catch(Standard_Failure)
940     {
941       di << argv[0] << ": Exception in fillet"<<"\n";
942       return 2;
943     }
944   }
945
946   return 0;
947 }
948
949 #include <Law_Interpol.hxx>
950
951 static Standard_Real t3d = 1.e-4;
952 static Standard_Real t2d = 1.e-5;
953 static Standard_Real ta  = 1.e-2;
954 static Standard_Real fl  = 1.e-3;
955 static Standard_Real tapp_angle = 1.e-2;
956 static GeomAbs_Shape blend_cont = GeomAbs_C1;
957
958 static BRepFilletAPI_MakeFillet* Rakk = 0;
959 static BRepFilletAPI_MakeFillet* Rake = 0;
960 static char name[100];
961
962 static void printtolblend(Draw_Interpretor& di)
963 {
964   di<<"tolerance ang : "<<ta<<"\n";
965   di<<"tolerance 3d  : "<<t3d<<"\n";
966   di<<"tolerance 2d  : "<<t2d<<"\n";
967   di<<"fleche        : "<<fl<<"\n";
968
969   di<<"tolblend "<<ta<<" "<<t3d<<" "<<t2d<<" "<<fl<<"\n";
970 }
971
972 static Standard_Integer MKEVOL(Draw_Interpretor& di, 
973                                Standard_Integer narg, 
974                                const char ** a)
975 {
976   if(Rake != 0) {delete Rake; Rake = 0;}
977   printtolblend(di);
978   if (narg < 3) return 1;
979   TopoDS_Shape V = DBRep::Get(a[2]);
980   Rake = new BRepFilletAPI_MakeFillet(V);
981   Rake->SetParams(ta,t3d,t2d,t3d,t2d,fl);
982   Rake->SetContinuity(blend_cont, tapp_angle);
983   if (narg == 4) {
984     ChFi3d_FilletShape FSh = ChFi3d_Rational;
985     if (!strcasecmp(a[3], "Q")) {
986       FSh = ChFi3d_QuasiAngular;
987     }
988     else if (!strcasecmp(a[3], "P")) {
989       FSh = ChFi3d_Polynomial;
990     }
991     Rake->SetFilletShape(FSh);
992   }
993   strcpy(name, a[1]);
994   return 0;
995 }
996
997 static Standard_Integer UPDATEVOL(Draw_Interpretor& di, 
998                                   Standard_Integer narg, 
999                                   const char ** a)
1000 {
1001   if(Rake == 0){
1002     di << "MakeFillet non initialise"<<"\n";
1003     return 1 ;
1004   }
1005   if(narg%2 != 0 || narg < 4) return 1;
1006   TColgp_Array1OfPnt2d uandr(1,(narg/2)-1);
1007   Standard_Real Rad, Par;
1008   TopoDS_Shape aLocalEdge(DBRep::Get(a[1],TopAbs_EDGE));
1009   TopoDS_Edge E = TopoDS::Edge(aLocalEdge);
1010   for (Standard_Integer ii = 1; ii <= (narg/2)-1; ii++){
1011     Par = atof(a[2*ii]);
1012     Rad = atof(a[2*ii + 1]);
1013     uandr.ChangeValue(ii).SetCoord(Par,Rad);
1014   }
1015   //HELPDESK: Add law creation
1016   const Standard_Boolean aLawMode = !strcmp(a[0],"OCC570evollaw");
1017   if (aLawMode)
1018   {
1019     di<<"INFO: Using law to define variable fillet"<<"\n";
1020     Handle(Law_Interpol) law = new Law_Interpol;
1021     law->Set(uandr);
1022     Rake->Add(law,E);
1023   }
1024   else
1025     Rake->Add(uandr,E);
1026
1027   return 0;
1028 }
1029
1030 static Standard_Integer BUILDEVOL(Draw_Interpretor& di,
1031                                   Standard_Integer, 
1032                                   const char **)
1033 {
1034   if(Rake == 0){
1035     di << "MakeFillet non initialise"<<"\n";
1036     return 1 ;
1037   }
1038   Rake->Build();
1039   if(Rake->IsDone()){
1040     TopoDS_Shape result = Rake->Shape();
1041     DBRep::Set(name,result);
1042     if(Rake != 0) {delete Rake; Rake = 0;}
1043     return 0;
1044   }
1045   if(Rake != 0) {delete Rake; Rake = 0;}
1046   return 1;
1047 }
1048
1049 #include <TColGeom_SequenceOfCurve.hxx>
1050 #include <Geom_TrimmedCurve.hxx>
1051 #include <GeomFill_NSections.hxx>
1052 #include <BRepBuilderAPI_MakeFace.hxx>
1053 //=======================================================================
1054 //function : OCC606
1055 //purpose  : 
1056 //=======================================================================
1057 static Standard_Integer OCC606 ( Draw_Interpretor& di, Standard_Integer n, const char ** a )
1058 {
1059   if (n != 3 && n != 4)
1060   {
1061     di << "Usage : " << a[0] << " result shape [-t]" << "\n";
1062     return 0;
1063   }
1064
1065   Standard_Boolean TrimMode = (n == 4);
1066   if (TrimMode) di<<"INFO: Using trimmed curves..."<<"\n";
1067   else di<<"INFO: Using non trimmed curves..."<<"\n";
1068
1069   TopoDS_Shape S = DBRep::Get(a[2]);
1070
1071   TopExp_Explorer t_exp(S,TopAbs_EDGE);
1072   TColGeom_SequenceOfCurve n_curves1;
1073   TColStd_SequenceOfReal np;
1074   Standard_Real param = 5.0;
1075
1076   for (;t_exp.More();t_exp.Next())
1077   {
1078     Standard_Real f,l;
1079     Handle(Geom_Curve) h_cur = BRep_Tool::Curve(TopoDS::Edge(t_exp.Current()),f,l);
1080     if (!h_cur.IsNull())
1081     {
1082       if (TrimMode) h_cur = new Geom_TrimmedCurve(h_cur,f,l);
1083
1084       n_curves1.Append(h_cur);
1085       np.Append(param);
1086       param += 1.0;
1087     }
1088   }
1089
1090   if (n_curves1.Length()>1 && !np.IsEmpty())
1091   {
1092     try
1093     {
1094       OCC_CATCH_SIGNALS
1095         GeomFill_NSections b_surface1(n_curves1, np);
1096       b_surface1.ComputeSurface();
1097       Handle(Geom_BSplineSurface) result_surf1 = b_surface1.BSplineSurface();
1098       if (!result_surf1.IsNull())
1099       {
1100         BRepBuilderAPI_MakeFace b_face1(result_surf1, Precision::Confusion());
1101         TopoDS_Face bsp_face1 = b_face1.Face();
1102         DBRep::Set(a[1],bsp_face1);
1103       }
1104     }
1105     catch(Standard_Failure)
1106     {
1107       di<<"ERROR: Exception in GeomFill_NSections"<<"\n";
1108     }
1109   }
1110
1111
1112   return 0;
1113 }
1114
1115 //=======================================================================
1116 //function : OCC813
1117 //purpose  : 
1118 //=======================================================================
1119 static Standard_Integer OCC813 (Draw_Interpretor& di, Standard_Integer argc,const char ** argv)
1120 {
1121   if (argc < 3)
1122   {
1123     di << "Usage : " << argv[0] << " U V" << "\n";
1124     return 1;
1125   }
1126
1127   Standard_CString str;
1128   Standard_Real U = atof(argv[1]);
1129   Standard_Real V = atof(argv[2]);
1130
1131   //Between ellipse and point:
1132
1133   Handle(Geom_Ellipse) ell = new Geom_Ellipse(gp_Ax2(gp_Pnt(1262.224429,425.040878,363.609716),
1134     gp_Dir(0.173648,0.984808,0.000000),
1135     gp_Dir(-0.932169,0.164367,-0.322560)), 150, 100);
1136   Handle(Geom_Plane) plne = new Geom_Plane(gp_Ax3(gp_Ax2(gp_Pnt(1262.224429,425.040878,363.609716),
1137     gp_Dir(0.173648,0.984808,0.000000),
1138     gp_Dir(-0.932169,0.164367,-0.322560))) );
1139
1140   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1141
1142   gp_Pnt2d pt2d(U,V);
1143   gp_Pln pln = plne->Pln();
1144
1145   str = "OCC813_pnt"; DrawTrSurf::Set(str,pt2d);
1146
1147   Handle(Geom2d_Curve) curve2d = GeomAPI::To2d(ell,pln);
1148   Geom2dAdaptor_Curve acur(curve2d);
1149   Geom2dGcc_QualifiedCurve qcur(acur, GccEnt_outside);
1150
1151   str = "OCC813_ell"; DrawTrSurf::Set(str,curve2d);
1152   if(!aContext.IsNull()) {
1153     Handle(AIS_Shape) aisp = 
1154       new AIS_Shape (BRepBuilderAPI_MakeEdge(GeomAPI::To3d(curve2d, pln)).Edge());
1155     aContext->Display (aisp);
1156   }
1157
1158   //This does not give any solutions.
1159   Geom2dGcc_Lin2d2Tan lintan(qcur, pt2d, 0.1);
1160   di<<"OCC813 nb of solutions = "<<lintan.NbSolutions()<<"\n";
1161
1162   Standard_Character abuf[16];
1163   Standard_CString st = abuf;
1164
1165   Standard_Integer i;
1166   for(i=1;i<=lintan.NbSolutions();i++) {
1167     sprintf(abuf,"lintan_%d",i);
1168     Handle(Geom2d_Line) glin = new Geom2d_Line(lintan.ThisSolution(i));
1169     DrawTrSurf::Set(st,glin);
1170     if(!aContext.IsNull()) {
1171       Handle(AIS_Shape) aisp = 
1172         new AIS_Shape (BRepBuilderAPI_MakeEdge(GeomAPI::To3d(glin, pln)).Edge());      aContext->Display (aisp);
1173     }
1174   }
1175
1176   return 0;
1177 }
1178
1179 //=======================================================================
1180 //function : OCC814
1181 //purpose  : 
1182 //=======================================================================
1183 static Standard_Integer OCC814 (Draw_Interpretor& di, Standard_Integer argc,const char ** argv)
1184 {
1185   if (argc > 1)
1186   {
1187     di << "Usage : " << argv[0] << "\n";
1188     return 1;
1189   }
1190
1191   Standard_CString str;
1192
1193   //Between Ellipse and Circle:
1194
1195   Handle(Geom_Circle) cir = new Geom_Circle(gp_Ax2(gp_Pnt(823.687192,502.366825,478.960440),
1196     gp_Dir(0.173648,0.984808,0.000000),
1197     gp_Dir(-0.932169,0.164367,-0.322560)), 50);
1198   Handle(Geom_Ellipse) ell = new Geom_Ellipse(gp_Ax2(gp_Pnt(1262.224429,425.040878,363.609716),
1199     gp_Dir(0.173648,0.984808,0.000000),
1200     gp_Dir(-0.932169,0.164367,-0.322560)), 150, 100);
1201   Handle(Geom_Plane) plne = new Geom_Plane(gp_Ax3(gp_Ax2(gp_Pnt(1262.224429,425.040878,363.609716),
1202     gp_Dir(0.173648,0.984808,0.000000),
1203     gp_Dir(-0.932169,0.164367,-0.322560))) );
1204
1205   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1206
1207   gp_Pln pln = plne->Pln();
1208   Handle(Geom2d_Curve) curve2d = GeomAPI::To2d(ell, pln);
1209   Handle(Geom2d_Curve) fromcurve2d = GeomAPI::To2d(cir, pln);
1210
1211   str = "OCC814_cir"; DrawTrSurf::Set(str,curve2d);
1212   str = "OCC814_ell"; DrawTrSurf::Set(str,fromcurve2d);
1213   if(!aContext.IsNull()) {
1214     Handle(AIS_Shape) aisp = 
1215       new AIS_Shape (BRepBuilderAPI_MakeEdge(GeomAPI::To3d(curve2d, pln)).Edge());
1216     aContext->Display (aisp);
1217   }
1218   if(!aContext.IsNull()) {
1219     Handle(AIS_Shape) aisp = 
1220       new AIS_Shape (BRepBuilderAPI_MakeEdge(GeomAPI::To3d(fromcurve2d, pln)).Edge());
1221     aContext->Display (aisp);
1222   }
1223
1224   Geom2dAdaptor_Curve acur(curve2d), afromcur(fromcurve2d);
1225
1226   Geom2dGcc_QualifiedCurve qcur(acur, GccEnt_outside) ;
1227   Geom2dGcc_QualifiedCurve qfromcur(afromcur, GccEnt_outside) ;
1228
1229   //This does not give any solutions.
1230   Geom2dGcc_Lin2d2Tan lintan(qcur, qfromcur, 0.1);
1231   di<<"OCC814 nb of solutions = "<<lintan.NbSolutions()<<"\n";
1232
1233   Standard_Character abuf[16];
1234   Standard_CString st = abuf;
1235
1236   Standard_Integer i;
1237   for(i=1;i<=lintan.NbSolutions();i++) {
1238     sprintf(abuf,"lintan_%d",i);
1239     Handle(Geom2d_Line) glin = new Geom2d_Line(lintan.ThisSolution(i));
1240     DrawTrSurf::Set(st,glin);
1241     if(!aContext.IsNull()) {
1242       Handle(AIS_Shape) aisp = 
1243         new AIS_Shape (BRepBuilderAPI_MakeEdge(GeomAPI::To3d(glin, pln)).Edge());      aContext->Display (aisp);
1244     }
1245   }
1246
1247   return 0;
1248 }
1249
1250 #include <ShapeAnalysis_Wire.hxx>
1251 #include <IntRes2d_SequenceOfIntersectionPoint.hxx>
1252 #include <TColgp_SequenceOfPnt.hxx>
1253 #include <ShapeFix_Wire.hxx>
1254 //=======================================================================
1255 //function : OCC884
1256 //purpose  : 
1257 //=======================================================================
1258 static Standard_Integer OCC884 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1259 {
1260   if (argc < 3 || argc > 5)
1261   {
1262     di << "Usage : " << argv[0] << " result shape [toler [maxtoler]]" << "\n";
1263     return 1;
1264   }
1265
1266   TopoDS_Shape shape = DBRep::Get(argv[2]); //read the shape
1267
1268   TopExp_Explorer exp(shape, TopAbs_EDGE);
1269   if (!exp.More())
1270   {
1271     di<<"Error: no edge found"<<"\n";
1272     return 1;
1273   }
1274
1275   BRep_Builder builder;
1276   TopoDS_Wire wire;
1277   builder.MakeWire(wire);
1278   builder.Add(wire, TopoDS::Edge(exp.Current()));
1279
1280   // HelpDesk: Create planar face if possible
1281   TopoDS_Face face = BRepBuilderAPI_MakeFace(wire,Standard_True);
1282
1283   Handle(ShapeAnalysis_Wire) advWA = new ShapeAnalysis_Wire;
1284   advWA->Load(wire);
1285   advWA->SetFace(face);
1286   advWA->SetPrecision(0.001);
1287
1288   IntRes2d_SequenceOfIntersectionPoint points2d;
1289   TColgp_SequenceOfPnt points3d;
1290
1291   di << "Info: CheckSelfIntersectingEdge = " << (Standard_Integer) advWA->CheckSelfIntersectingEdge(1,points2d,points3d) << "\n";
1292
1293   ShapeExtend_Status status = ShapeExtend_FAIL1;
1294   if (advWA->StatusSelfIntersection(status))
1295     di << "Info: No P Curve found in the edge\n";
1296
1297   status = ShapeExtend_FAIL2; 
1298   if (advWA->StatusSelfIntersection(status))
1299     di << "Info: No Vertices found in the edge\n";
1300
1301   status = ShapeExtend_DONE1; 
1302   if (advWA->StatusSelfIntersection(status))
1303     di << "Info: Self-intersection found in the edge\n";
1304
1305   Standard_Integer i, num = points2d.Length();
1306   di << "Info: No. of self-intersection points : " << num << "\n";
1307
1308   char str[80];
1309   Standard_CString name = str;
1310   for (i = 1; i <= num; ++i)
1311   { 
1312     gp_Pnt pt = points3d(i); 
1313     di << "Info: Intersecting pt : (" << pt.X() << ", " << pt.Y() << ", " << pt.Z() << ")\n";
1314     sprintf(str,"p_%d",i);
1315     DrawTrSurf::Set(name,pt);
1316   }
1317
1318   Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire;
1319   sfw->Load(wire);
1320   sfw->SetFace(face);
1321
1322   if (argc > 3) sfw->SetPrecision(atof(argv[3])/*0.1*/);
1323   if (argc > 4) sfw->SetMaxTolerance(atof(argv[4]));
1324   di << "Info: Precision is set to " << sfw->Precision() << "\n";
1325   di << "Info: MaxTolerance is set to " << sfw->MaxTolerance() << "\n";
1326
1327   sfw->ModifyTopologyMode() = 1;
1328   sfw->ModifyGeometryMode() = 1; 
1329   sfw->FixSelfIntersectingEdgeMode() = 1;
1330   //printf("Info: FixSelfIntersection = %d\n",sfw->FixSelfIntersection());
1331   di << "Info: FixSelfIntersection = " << (Standard_Integer) sfw->FixSelfIntersection() << "\n";
1332
1333   DBRep::Set(argv[1],sfw->Wire());
1334
1335   status = ShapeExtend_OK;
1336   if (sfw->StatusSelfIntersection(status))
1337     di << "Info: ShapeExtend_OK : No intersection found\n";
1338   //printf("Info: ShapeExtend_OK : No intersection found\n");
1339
1340   status = ShapeExtend_FAIL1;
1341   if (sfw->StatusSelfIntersection(status))
1342     di << "Info: ShapeExtend_FAIL1 : analysis failed (edge has no pcurve, or no vertices etc.)\n";
1343
1344   status = ShapeExtend_FAIL2;
1345   if (sfw->StatusSelfIntersection(status))
1346     di << "Info: ShapeExtend_FAIL2 : self-intersection was found, but not fixed because of limit of increasing tolerance (MaxTolerance)\n";
1347
1348   status = ShapeExtend_FAIL3;
1349   if (sfw->StatusSelfIntersection(status))
1350     di << "Info: ShapeExtend_FAIL3 : intercestion of non adjacent edges found, but not fixed because of limit of increasing tolerance (MaxTolerance)\n";
1351
1352   status = ShapeExtend_DONE1;
1353   if (sfw->StatusSelfIntersection(status))
1354     di << "Info: ShapeExtend_DONE1 : tolerance of vertex was increased to fix self-intersection\n";
1355
1356   status = ShapeExtend_DONE2;
1357   if (sfw->StatusSelfIntersection(status))
1358     di << "Info: ShapeExtend_DONE2 : vertex was moved to fix self-intersection\n";
1359
1360   status = ShapeExtend_DONE3;
1361   if (sfw->StatusSelfIntersection(status))
1362     di << "Info: ShapeExtend_DONE3 : some edges were removed because of intersection\n";
1363
1364   status = ShapeExtend_DONE4;
1365   if (sfw->StatusSelfIntersection(status))
1366     di << "Info: ShapeExtend_DONE4 : pcurve(s) was(were) modified\n";
1367
1368   status = ShapeExtend_DONE5;
1369   if (sfw->StatusSelfIntersection(status))
1370     di << "Info: ShapeExtend_DONE5 : non adjacent intersection fixed by increasing tolerance of vertex(vertices)\n";
1371
1372   status = ShapeExtend_DONE6;
1373   if (sfw->StatusSelfIntersection(status))
1374     di << "Info: ShapeExtend_DONE6 : tolerance of edge was increased to hide intersection\n";
1375
1376   status = ShapeExtend_DONE7;
1377   if (sfw->StatusSelfIntersection(status))
1378     di << "Info: ShapeExtend_DONE7 : range of some edges was decreased to avoid intersection\n";
1379
1380   return 0;
1381 }
1382
1383 #include <Aspect_FillMethod.hxx>
1384 //=======================================================================
1385 //function : OCC1188
1386 //purpose  : 
1387 //=======================================================================
1388 static Standard_Integer OCC1188 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1389 {
1390   if (argc < 2 || argc > 3)
1391   {
1392     di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
1393     return 1;
1394   }
1395
1396   Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1397   if(AISContext.IsNull()) 
1398   {
1399     di << "use 'vinit' command before " << argv[0] << "\n";
1400     return 1;
1401   }
1402
1403   Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
1404   if (argc == 3)
1405   {
1406     const char* szType = argv[2];
1407     if      (strcmp(szType, "NONE"    ) == 0) aFillType = Aspect_FM_NONE;
1408     else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1409     else if (strcmp(szType, "TILED"   ) == 0) aFillType = Aspect_FM_TILED;
1410     else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1411     else
1412     {
1413       di << "Wrong fill type : " << szType << "\n";
1414       di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1415       return 1;
1416     }
1417   }
1418
1419   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1420   V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
1421
1422   return 0;
1423 }
1424
1425 #include <AIS_Drawer.hxx>
1426 #include <Graphic3d_MaterialAspect.hxx>
1427 #include <Prs3d_ShadingAspect.hxx>
1428 //=======================================================================
1429 //function : OCC1174_1
1430 //purpose  : 
1431 //=======================================================================
1432 static Standard_Integer OCC1174_1 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1433 {
1434   if (argc != 2)
1435   {
1436     di << "Usage : " << argv[0] << " shape" << "\n";
1437     return 1;
1438   }
1439
1440   Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1441   if(AISContext.IsNull()) 
1442   {
1443     di << "use 'vinit' command before " << argv[0] << "\n";
1444     return 1;
1445   }
1446
1447   TopoDS_Shape sh = DBRep::Get(argv[1]);
1448
1449   Handle(AIS_Shape) ais = new AIS_Shape(sh);
1450
1451   Quantity_Color colf(0.0, 0.4, 0.0, Quantity_TOC_RGB);
1452   Quantity_Color colb(0.0, 0.0, 0.6, Quantity_TOC_RGB);
1453
1454   Handle(Prs3d_ShadingAspect) sa = ais->Attributes()->ShadingAspect();
1455
1456   Graphic3d_MaterialAspect front = sa->Material(Aspect_TOFM_FRONT_SIDE);
1457   front.SetAmbientColor(colf);
1458   front.SetDiffuseColor(colf);
1459   front.SetSpecularColor(colf);
1460   front.SetEmissiveColor(colf);
1461   front.SetTransparency(0.0);
1462   sa->SetMaterial(front,Aspect_TOFM_FRONT_SIDE);
1463
1464   Graphic3d_MaterialAspect back = sa->Material(Aspect_TOFM_BACK_SIDE);
1465   back.SetAmbientColor(colb);
1466   back.SetDiffuseColor(colb);
1467   back.SetSpecularColor(colb);
1468   back.SetEmissiveColor(colb);
1469   back.SetTransparency(0.0);
1470   sa->SetMaterial(back,Aspect_TOFM_BACK_SIDE);
1471
1472   AISContext->Display(ais,1,0);
1473
1474   Standard_Real r, g, b; 
1475   sa->Color(Aspect_TOFM_FRONT_SIDE).Values(r,g,b, Quantity_TOC_RGB);
1476   di << "Info: color on front side (" << r << "," << g << "," << b << ")\n";
1477   sa->Color(Aspect_TOFM_BACK_SIDE).Values(r,g,b, Quantity_TOC_RGB);
1478   di << "Info: color on back side (" << r << "," << g << "," << b << ")\n";
1479
1480   return 0;
1481 }
1482
1483 //=======================================================================
1484 //function : OCC1174_2
1485 //purpose  : 
1486 //=======================================================================
1487 static Standard_Integer OCC1174_2 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1488 {
1489   if (argc != 2)
1490   {
1491     di << "Usage : " << argv[0] << " shape" << "\n";
1492     return 1;
1493   }
1494
1495   Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1496   if(AISContext.IsNull()) 
1497   {
1498     di << "use 'vinit' command before " << argv[0] << "\n";
1499     return 1;
1500   }
1501
1502   TopoDS_Shape sh = DBRep::Get(argv[1]);
1503
1504   Handle(AIS_Shape) ais = new AIS_Shape(sh); 
1505   AISContext->Display(ais,1,0); 
1506   AISContext->SetMaterial(ais,Graphic3d_NOM_SHINY_PLASTIC); 
1507
1508   Quantity_Color colf(0.0, 0.4, 0.0, Quantity_TOC_RGB); 
1509   Quantity_Color colb(0.0, 0.0, 0.6, Quantity_TOC_RGB); 
1510   Handle(Prs3d_ShadingAspect) sa = ais->Attributes()->ShadingAspect(); 
1511
1512   Graphic3d_MaterialAspect front = sa->Material(Aspect_TOFM_FRONT_SIDE); 
1513   front.SetAmbientColor(colf); 
1514   front.SetDiffuseColor(colf); 
1515   front.SetSpecularColor(colf); 
1516   front.SetEmissiveColor(colf); 
1517   front.SetTransparency(0.4); 
1518   sa->SetMaterial(front,Aspect_TOFM_FRONT_SIDE); 
1519
1520   Graphic3d_MaterialAspect back = sa->Material(Aspect_TOFM_BACK_SIDE); 
1521   back.SetAmbientColor(colb); 
1522   back.SetDiffuseColor(colb); 
1523   back.SetSpecularColor(colb); 
1524   back.SetEmissiveColor(colb); 
1525   back.SetTransparency(0.2); 
1526   sa->SetMaterial(back,Aspect_TOFM_BACK_SIDE); 
1527
1528   AISContext->Redisplay(ais,1,0);
1529
1530   return 0;
1531 }
1532
1533 #include <Graphic2d_Segment.hxx>
1534 #include <Prs2d_Length.hxx>
1535 #include <Prs2d_AspectLine.hxx>
1536 #include <AIS2D_InteractiveObject.hxx>
1537 //=======================================================================
1538 //  OCC672:
1539 //         OCC672_Length
1540 //         OCC672_Angle
1541 //         OCC672_Diameter
1542 //         OCC672_ShortLength 
1543 //=======================================================================
1544
1545 static Standard_Integer OCC672_Length (Draw_Interpretor& di, Standard_Integer n,const char ** argv)
1546 {
1547   if (n != 17) {
1548     di << " wrong parameters !\n";
1549     di << "must be : OCC672_Length x1 y1 x2 y2 str scale_text length_dist angle_arrow length_arrow x3 y3 x4 y4 TxtAngle TxtPosH TxtPosV\n";
1550     return 1;
1551   }
1552
1553   Standard_Real x1=atof(argv[1]);
1554   Standard_Real y1=atof(argv[2]);
1555   Standard_Real x2=atof(argv[3]);
1556   Standard_Real y2=atof(argv[4]);
1557   Standard_Real x3=atof(argv[10]);
1558   Standard_Real y3=atof(argv[11]);
1559   Standard_Real x4=atof(argv[12]);
1560   Standard_Real y4=atof(argv[13]);
1561   Standard_Real txtAngle=atof(argv[14]);
1562   Standard_Real txtPosH=atof(argv[15]);
1563   Standard_Real txtPosV=atof(argv[16]);
1564
1565   di<<"Begin!\n";
1566   Handle(AIS2D_InteractiveContext) aContext = Viewer2dTest::GetAIS2DContext();
1567   di<<"Check InteractiveContext\n";
1568
1569   if(aContext.IsNull()) {
1570     di << "use 'v2dinit' command before " << argv[0] << "\n";
1571     return 1;
1572   }
1573
1574   di<<"CloseLocalContext\n";
1575   aContext->CloseLocalContext();
1576
1577   di<<"OpenLocalContext\n";
1578   aContext->OpenLocalContext();
1579   //step0 end  
1580   Handle(AIS2D_InteractiveObject) aIO10 = new AIS2D_InteractiveObject();
1581   Handle(Graphic2d_Segment) theSegmA, theSegmB, theSegmC, theSegmD;
1582
1583   theSegmA = new Graphic2d_Segment( aIO10, x1, y1, x2, y2 );
1584   theSegmB = new Graphic2d_Segment( aIO10, x2, y2, x3, y3 );
1585   theSegmC = new Graphic2d_Segment( aIO10, x3, y3, x4, y4 );
1586   theSegmD = new Graphic2d_Segment( aIO10, x4, y4, x1, y1 );
1587
1588   aContext->Display( aIO10, Standard_True ); 
1589
1590   Handle(Prs2d_Length) length = new Prs2d_Length(aIO10, gp_Pnt2d(x1, y1), gp_Pnt2d(x2, y2), argv[5],
1591     atof(argv[6]), atof(argv[7]), Prs2d_TOD_AUTOMATIC, 
1592     atof(argv[8]), atof(argv[9]), Prs2d_TOA_FILLED,
1593     Prs2d_AS_BOTHAR);
1594
1595   length->SetTextRelPos(txtPosH,txtPosV);
1596   length->SetTextRelAngle(txtAngle);
1597
1598   Handle(Prs2d_AspectLine) theAspect = new Prs2d_AspectLine(Quantity_NOC_WHITE,
1599     Aspect_TOL_SOLID, Aspect_WOL_THIN);
1600   aIO10->SetAspect( theAspect,  length);
1601   aContext->Display( aIO10, Standard_True );
1602
1603   Handle(Prs2d_Length) lengthB = new Prs2d_Length(aIO10, gp_Pnt2d(x2, y2), gp_Pnt2d(x3, y3), argv[5],
1604     atof(argv[6]), atof(argv[7]), Prs2d_TOD_AUTOMATIC, 
1605     atof(argv[8]), atof(argv[9]), Prs2d_TOA_FILLED,
1606     Prs2d_AS_BOTHAR);
1607
1608   lengthB->SetTextRelPos(txtPosH,txtPosV);
1609   lengthB->SetTextRelAngle(txtAngle);
1610
1611   aIO10->SetAspect( theAspect,  lengthB);
1612   aContext->Display( aIO10, Standard_True );
1613
1614   Handle(Prs2d_Length) lengthC = new Prs2d_Length(aIO10, gp_Pnt2d(x3, y3), gp_Pnt2d(x4, y4), argv[5],
1615     atof(argv[6]), atof(argv[7]), Prs2d_TOD_AUTOMATIC, 
1616     atof(argv[8]), atof(argv[9]), Prs2d_TOA_FILLED,
1617     Prs2d_AS_BOTHAR);
1618
1619   lengthC->SetTextRelPos(txtPosH,txtPosV);
1620   lengthC->SetTextRelAngle(txtAngle);
1621
1622   aIO10->SetAspect( theAspect,  lengthC);
1623   aContext->Display( aIO10, Standard_True );
1624
1625   Handle(Prs2d_Length) lengthD = new Prs2d_Length(aIO10, gp_Pnt2d(x4, y4), gp_Pnt2d(x1, y1), argv[5],
1626     atof(argv[6]), atof(argv[7]), Prs2d_TOD_AUTOMATIC, 
1627     atof(argv[8]), atof(argv[9]), Prs2d_TOA_FILLED,
1628     Prs2d_AS_BOTHAR);
1629
1630   lengthD->SetTextRelPos(txtPosH,txtPosV);
1631   lengthD->SetTextRelAngle(txtAngle);
1632
1633   aIO10->SetAspect( theAspect,  lengthD);
1634   aContext->Display( aIO10, Standard_True );
1635   return 0;
1636 }
1637
1638 #include <Prs2d_Angle.hxx>
1639 static Standard_Integer OCC672_Angle (Draw_Interpretor& di, Standard_Integer n,const char ** argv)
1640 {
1641   if (n != 15) {
1642     di << "Wrong parameters !\n";
1643     di << "must be : OCC672_Angle x1 y1 x2 y2 x3 y3 aRadius aText aTxtScale anArrAngle anArrLength txtAngle txtPosH txtPosV  \n";
1644     return 1;
1645   }
1646
1647   Standard_Real x1=atof(argv[1]);
1648   Standard_Real y1=atof(argv[2]);
1649   Standard_Real x2=atof(argv[3]);
1650   Standard_Real y2=atof(argv[4]);
1651   Standard_Real x3=atof(argv[5]);
1652   Standard_Real y3=atof(argv[6]);
1653   Standard_Real aRadius=atof(argv[7]);
1654   Standard_Real aTxtScale=atof(argv[9]);
1655   Standard_Real anArrAngle=atof(argv[10]);
1656   Standard_Real anArrLength=atof(argv[11]);
1657   Standard_Real txtAngle=atof(argv[12]);
1658   Standard_Real txtPosH=atof(argv[13]);
1659   Standard_Real txtPosV=atof(argv[14]);
1660
1661   di<<"Begin!\n";
1662   Handle(AIS2D_InteractiveContext) aContext = Viewer2dTest::GetAIS2DContext();
1663   di<<"Check InteractiveContext\n";
1664
1665   if(aContext.IsNull()) {
1666     di << "use 'v2dinit' command before " << argv[0] << "\n";
1667     return 1;
1668   }
1669
1670   di<<"CloseLocalContext\n";
1671   aContext->CloseLocalContext();
1672
1673   di<<"OpenLocalContext\n";
1674   aContext->OpenLocalContext();
1675
1676   Handle(AIS2D_InteractiveObject) aIO10 = new AIS2D_InteractiveObject();
1677   Handle(Graphic2d_Segment) theSegmA, theSegmB;
1678   theSegmA = new Graphic2d_Segment( aIO10, x1, y1, x2, y2 );
1679   theSegmB = new Graphic2d_Segment( aIO10, x1, y1, x3, y3 );
1680   aContext->Display( aIO10, Standard_True ); 
1681
1682   Handle(Prs2d_Angle) angle = new Prs2d_Angle(aIO10, gp_Pnt2d(x1, y1), gp_Pnt2d(x2, y2),gp_Pnt2d(x3,y3),
1683     aRadius,argv[8],aTxtScale,anArrAngle,anArrLength,Prs2d_TOA_FILLED,
1684     Prs2d_AS_BOTHAR);
1685
1686   angle->SetTextRelPos(txtPosH,txtPosV);
1687   angle->SetTextAbsAngle(txtAngle);
1688
1689   aContext->Display( aIO10, Standard_True );
1690   return 0; 
1691 }
1692
1693 #include <Prs2d_Diameter.hxx>
1694 #include <gp_Circ2d.hxx>
1695 #include <Graphic2d_Circle.hxx>
1696 #include <Prs2d_AspectText.hxx>
1697 static Standard_Integer OCC672_Diameter (Draw_Interpretor& di, Standard_Integer n,const char ** argv)
1698 {
1699   if (n != 13) {
1700     di << "Wrong parameters !\n";
1701     di << "must be : OCC672_Diameter x1 y1 cx cy radius aText aTxtScale anArrAngle anArrLength txtAngle txtPosH txtPosV\n";
1702     return 1;
1703   }
1704
1705   Standard_Real x1=atof(argv[1]);
1706   Standard_Real y1=atof(argv[2]);
1707   Standard_Real cx=atof(argv[3]);    //coordinats for circle 
1708   Standard_Real cy=atof(argv[4]);    //
1709   Standard_Real radius=atof(argv[5]);//radius for circle 
1710   Standard_Real aTxtScale=atof(argv[7]);
1711   Standard_Real anArrAngle=atof(argv[8]);
1712   Standard_Real anArrLength=atof(argv[9]);
1713
1714   Standard_Real txtAngle=atof(argv[10]);
1715   Standard_Real txtPosH=atof(argv[11]);
1716   Standard_Real txtPosV=atof(argv[12]);
1717
1718
1719   di<<"Begin!\n";
1720   Handle(AIS2D_InteractiveContext) aContext = Viewer2dTest::GetAIS2DContext();
1721   di<<"Check InteractiveContext\n";
1722
1723   if(aContext.IsNull()) {
1724     di << "use 'v2dinit' command before " << argv[0] << "\n";
1725     return 1;
1726   }
1727
1728   di<<"CloseLocalContext\n";
1729   aContext->CloseLocalContext();
1730
1731   di<<"OpenLocalContext\n";
1732   aContext->OpenLocalContext();
1733   Handle(AIS2D_InteractiveObject) aIO10 = new AIS2D_InteractiveObject(); 
1734
1735   Handle (Graphic2d_Circle) HCirc;
1736   HCirc= new Graphic2d_Circle(aIO10,cx,cy,radius);
1737
1738   gp_Dir2d myDir2d(1,0);
1739   gp_Pnt2d myPnt2d(cx,cy);
1740   gp_Ax2d myAx2d(myPnt2d,myDir2d);
1741   gp_Circ2d myCirc(myAx2d,radius);
1742
1743   Handle(Prs2d_Diameter) diameter = new Prs2d_Diameter(aIO10, gp_Pnt2d(x1, y1),myCirc,
1744     argv[6],aTxtScale,anArrAngle,anArrLength,
1745     Prs2d_TOA_FILLED,
1746     Prs2d_AS_BOTHAR,Standard_True);
1747
1748   diameter->SetTextRelPos(txtPosH,txtPosV);
1749
1750   diameter->SetTextAbsAngle(txtAngle);
1751
1752   aContext->Display( aIO10, Standard_True );
1753
1754   return 0;
1755 }
1756
1757 #include <gp_Lin2d.hxx>
1758 static Standard_Integer OCC672_ShortLength (Draw_Interpretor& di, Standard_Integer n,const char ** argv)
1759 {
1760   if (n != 17) {
1761     di << " wrong parameters !\n";
1762     di << "must be : OCC672_ShortLength x1 y1 x2 y2 str scale_text length_dist angle_arrow length_arrow x3 y3 x4 y4 TxtAngle TxtPosH TxtPosV\n";
1763     return 1;
1764   }
1765
1766   Standard_Real x1=atof(argv[1]);
1767   Standard_Real y1=atof(argv[2]);
1768   Standard_Real x2=atof(argv[3]);
1769   Standard_Real y2=atof(argv[4]);
1770   Standard_Real x3=atof(argv[10]);
1771   Standard_Real y3=atof(argv[11]);
1772   Standard_Real x4=atof(argv[12]);
1773   Standard_Real y4=atof(argv[13]);
1774   Standard_Real txtAngle=atof(argv[14]);
1775   Standard_Real txtPosH=atof(argv[15]);
1776   Standard_Real txtPosV=atof(argv[16]);
1777
1778
1779   di<<"Begin!\n";
1780   Handle(AIS2D_InteractiveContext) aContext = Viewer2dTest::GetAIS2DContext();
1781   di<<"Check InteractiveContext\n";
1782
1783   if(aContext.IsNull()) {
1784     di << "use 'v2dinit' command before " << argv[0] << "\n";
1785     return 1;
1786   }
1787
1788   di<<"CloseLocalContext\n";
1789   aContext->CloseLocalContext();
1790
1791   di<<"OpenLocalContext\n";
1792   aContext->OpenLocalContext();
1793
1794   Handle(AIS2D_InteractiveObject) aIO10 = new AIS2D_InteractiveObject();
1795   Handle(Graphic2d_Segment) theSegmA, theSegmB, theSegmC, theSegmD;
1796   theSegmB = new Graphic2d_Segment( aIO10, x2, y2, x3, y3 );
1797   theSegmD = new Graphic2d_Segment( aIO10, x4, y4, x1, y1 );
1798
1799   aContext->Display( aIO10, Standard_True ); 
1800
1801   gp_Pnt2d p3(x3,y3),p2(x2,y2),p1(x1,y1);
1802   gp_Vec2d theVec(p3,p2);
1803   gp_Dir2d theDir(theVec);
1804   gp_Lin2d theLin1(p1,theDir);
1805   gp_Lin2d theLin2(p3,theDir);
1806
1807   Handle(Prs2d_Length) length = new Prs2d_Length(aIO10, p1, theLin2, argv[5],
1808     atof(argv[6]), 5.0, 20.0, 5.,
1809     Prs2d_TOA_CLOSED,Prs2d_AS_BOTHAR,
1810     Standard_True);
1811
1812
1813   Handle(Prs2d_AspectLine) theAspect = new Prs2d_AspectLine(Quantity_NOC_WHITE,
1814     Aspect_TOL_SOLID, Aspect_WOL_THIN);
1815   length->SetTextRelPos(txtPosH,txtPosV);
1816   length->SetTextRelAngle(txtAngle);
1817
1818   aIO10->SetAspect( theAspect,  length);
1819   aContext->Display( aIO10, Standard_True );
1820
1821   return 0;
1822 }
1823
1824 #include <TopoDS_Solid.hxx>
1825 #include <BRepFeat_MakeDPrism.hxx>
1826 //=======================================================================
1827 //function : OCCN1
1828 //purpose  : FEATURE OPERATION (BOSS and SLOT)
1829 //=======================================================================
1830 static Standard_Integer OCCN1 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1831 {
1832   if (argc != 4)
1833   {
1834     di << "Usage : " << argv[0] << " angle fuse(1 for boss / 0 for slot) length" << "\n";
1835     return 1;
1836   }
1837
1838   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1839   if(aContext.IsNull()) 
1840   {
1841     di << "use 'vinit' command before " << argv[0] << "\n";
1842     return 1;
1843   }
1844   Standard_Real    angle  = atof(argv[1]);
1845   Standard_Integer fuse   = atoi(argv[2]);
1846   Standard_Real    length = atof(argv[3]);
1847
1848   BRepBuilderAPI_MakeEdge edge1(gp_Pnt(0, 0, 0), gp_Pnt(50, 0, 0));
1849   BRepBuilderAPI_MakeEdge edge2(gp_Pnt(50, 0, 0), gp_Pnt(50, 50, 0));
1850   BRepBuilderAPI_MakeEdge edge3(gp_Pnt(50, 50, 0), gp_Pnt(0, 50, 0));
1851   BRepBuilderAPI_MakeEdge edge4(gp_Pnt(0, 50, 0), gp_Pnt(0, 0, 0));
1852   TopoDS_Edge ted1 = edge1.Edge();
1853   TopoDS_Edge ted2 = edge2.Edge();
1854   TopoDS_Edge ted3 = edge3.Edge();
1855   TopoDS_Edge ted4 = edge4.Edge();
1856
1857   BRepBuilderAPI_MakeWire wire(ted1, ted2, ted3, ted4);
1858   TopoDS_Wire twire = wire.Wire();
1859
1860   BRepBuilderAPI_MakeFace face(twire);
1861   TopoDS_Face tface = face.Face();
1862   ////////Handle_AIS_Shape face_ais = new AIS_Shape( tface );
1863   ////////aContext->Display(face_ais);
1864
1865   TopoDS_Solid box;
1866   BRepPrimAPI_MakeBox block(gp_Pnt(-50, -50, -150), 150, 150, 100);
1867   box = block.Solid();
1868
1869   TopoDS_Face top_face;
1870   top_face = block.TopFace();
1871
1872   BRepFeat_MakeDPrism slot(box, tface, top_face, angle, fuse,
1873     Standard_True);
1874
1875   slot.Perform(length);
1876   TopoDS_Shape S2 = slot.Shape();
1877
1878   DBRep::Set("OCCN1_tface",tface);
1879   DBRep::Set("OCCN1_slot",S2);
1880
1881   return 0;
1882 }
1883
1884 #include <BRepPrimAPI_MakeCylinder.hxx>
1885 #include <BRepPrimAPI_MakeSphere.hxx>
1886 #include <BRepAlgoAPI_Section.hxx>
1887 #include <BRepAlgo_Section.hxx>
1888 //=======================================================================
1889 //function : OCCN2
1890 //purpose  : BOOLEAN OPERATION
1891 //=======================================================================
1892 static Standard_Integer OCCN2 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1893 {
1894   if (argc > 2) {
1895     di << "Usage : " << argv[0] << " [BRepAlgoAPI/BRepAlgo = 1/0]" << "\n";
1896     return 1;
1897   }
1898   Standard_Boolean IsBRepAlgoAPI = Standard_True;
1899   if (argc == 2) {
1900     Standard_Integer IsB = atoi(argv[1]);
1901     if (IsB != 1) {
1902       IsBRepAlgoAPI = Standard_False;
1903 #if ! defined(BRepAlgo_def04)
1904 #endif
1905     }
1906   }
1907
1908   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1909   if(aContext.IsNull()) 
1910   {
1911     di << "use 'vinit' command before " << argv[0] << "\n";
1912     return 1;
1913   }
1914
1915   BRepPrimAPI_MakeCylinder cylinder(50,200);
1916   TopoDS_Shape cylinder_sh = cylinder.Shape();
1917
1918   BRepPrimAPI_MakeSphere sphere(gp_Pnt(60,0,100),50);
1919   TopoDS_Shape sphere_sh = sphere.Shape();
1920
1921   //BRepAlgoAPI_Section section(cylinder_sh, sphere_sh);
1922   //TopoDS_Shape shape = section.Shape();
1923
1924   TopoDS_Shape shape;
1925   if (IsBRepAlgoAPI) {
1926     di << "BRepAlgoAPI_Section section(cylinder_sh, sphere_sh)" <<"\n";
1927     BRepAlgoAPI_Section section(cylinder_sh, sphere_sh);
1928     section.Build();
1929     if(!section.IsDone()){
1930       di << "Error performing intersection: not done." << "\n";
1931     }
1932     shape = section.Shape();
1933   } else {
1934     di << "BRepAlgo_Section section(cylinder_sh, sphere_sh)" <<"\n";
1935     BRepAlgo_Section section(cylinder_sh, sphere_sh);
1936     section.Build();
1937     if(!section.IsDone()){
1938       di << "Error performing intersection: not done." << "\n";
1939     }
1940     shape = section.Shape();
1941   }
1942
1943   DBRep::Set("OCCN2_cylinder",cylinder_sh);
1944   DBRep::Set("OCCN2_sphere",sphere_sh);
1945   DBRep::Set("OCCN2_section",shape);
1946
1947   return 0;
1948 }
1949
1950 #include <TColgp_Array1OfPnt.hxx>
1951 #include <Geom_BezierCurve.hxx>
1952
1953 static Standard_Integer OCC2569 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1954 {
1955   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1956   if(aContext.IsNull()) 
1957   {
1958     di << "use 'vinit' command before " << argv[0] << "\n";
1959     return 1;
1960   }
1961   if(argc != 3) {
1962     di << "Usage : " << argv[0] << " nbpoles result" << "\n";
1963     return 1;
1964   }
1965
1966   int poles=atoi(argv[1]); 
1967
1968   TColgp_Array1OfPnt arr(1, poles); 
1969   for(int i=1; i<=poles; i++) 
1970     arr.SetValue(i, gp_Pnt(i+10, i*2+20, i*3+45)); 
1971
1972   Handle_Geom_BezierCurve bez = new Geom_BezierCurve(arr); 
1973   if(bez.IsNull()) {
1974     di << "\n The curve is not created.\n";
1975   } else {
1976     di << "\n Degree = " << bez->Degree() << "\n";   
1977   }
1978   TopoDS_Edge sh = BRepBuilderAPI_MakeEdge(bez).Edge(); 
1979   Handle_AIS_Shape ais = new AIS_Shape(sh); 
1980   aContext->Display(ais); 
1981   DrawTrSurf::Set(argv[2],bez);
1982   return 0;
1983 }
1984
1985 #include <TopTools_IndexedMapOfShape.hxx>
1986 #include <TopExp.hxx>
1987
1988 static Standard_Integer OCC1642 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1989 {
1990   if (argc != 10) {
1991     di<<"Usage: " << argv[0] << " FinalWare FinalFace InitWare InitFace shape FixReorder FixDegenerated FixConnected FixSelfIntersection"<<"\n";
1992     return 1;
1993   }
1994
1995   TopoDS_Shape shape = DBRep::Get(argv[5]);
1996
1997   TopExp_Explorer exp(shape, TopAbs_WIRE);
1998   TopoDS_Shape wire = exp.Current();
1999
2000   Handle(ShapeAnalysis_Wire) advWA = new ShapeAnalysis_Wire;
2001   advWA->Load(TopoDS::Wire(wire));
2002
2003   DBRep::Set(argv[3],wire);
2004
2005   TopoDS_Face face =
2006     BRepBuilderAPI_MakeFace(TopoDS::Wire(wire),Standard_True);
2007
2008   DBRep::Set(argv[4],face);
2009
2010   advWA->SetFace(face);
2011   Standard_Real precision_to_ana = 0.0001;
2012   advWA->SetPrecision(precision_to_ana);
2013
2014   TopTools_IndexedMapOfShape M;
2015   TopExp::MapShapes(wire, TopAbs_EDGE, M);
2016
2017   int j= 1;
2018   for(j= 1; j<=M.Extent(); ++j) {
2019     Standard_Integer num=1;
2020     IntRes2d_SequenceOfIntersectionPoint points2d;
2021     TColgp_SequenceOfPnt points3d;
2022
2023     cout << "\n j =" << j << ",  CheckSelfIntersectingEdge = " <<
2024       advWA->CheckSelfIntersectingEdge(j, points2d, points3d);
2025
2026
2027     ShapeExtend_Status status = ShapeExtend_FAIL1;
2028     if(advWA->StatusSelfIntersection(status))
2029
2030       status = ShapeExtend_FAIL2;
2031     if(advWA->StatusSelfIntersection(status))
2032       di << "\n No Vertices found in the edge";
2033
2034     status = ShapeExtend_DONE1;
2035     if(advWA->StatusSelfIntersection(status))
2036       di << "\n Self-intersection found in the edge";
2037
2038     num = points2d.Length();
2039     di << "\n No. of self-intersecting edges : " << num;
2040
2041     for(int i=1; i<=num; ++i) {
2042       gp_Pnt pt = points3d(i);
2043       di << "\n Intersecting pt : (" << pt.X() << ", " << pt.Y()<< ", " << pt.Z() << ")";
2044     }
2045
2046   }
2047
2048   Handle_ShapeFix_Wire sfw = new ShapeFix_Wire;
2049   sfw->Load(TopoDS::Wire(wire));
2050   sfw->SetFace(face);
2051   sfw->SetPrecision(Precision::Confusion());
2052
2053   sfw->FixReorderMode() = 1;
2054   sfw->ClosedWireMode() = 1;
2055   sfw->FixDegeneratedMode() = 1;
2056   sfw->FixConnectedMode() = 1;
2057   sfw->ModifyTopologyMode() = 1;
2058   sfw->ModifyGeometryMode() = 1;
2059   sfw->FixSelfIntersectionMode() = 1;
2060   sfw->FixSelfIntersectingEdgeMode() = 1;
2061   sfw->FixIntersectingEdgesMode() = 1;
2062   sfw->FixNonAdjacentIntersectingEdgesMode() = 1;
2063   sfw->FixEdgeCurvesMode() = 1;
2064
2065   sfw->ModifyRemoveLoopMode() = 1;
2066   sfw->SetMaxTolerance(1.0);
2067
2068   di << "\n FixReorder = " << (Standard_Integer) sfw->FixReorder();
2069   di << "\n FixDegenerated = " << (Standard_Integer) sfw->FixDegenerated();
2070   di << "\n FixConnected = " << (Standard_Integer) sfw->FixConnected();
2071   di << "\n";
2072   di << "\n FixSelfIntersection = " << (Standard_Integer) sfw->FixSelfIntersection();
2073   di << "\n";
2074
2075   Draw::Set(argv[6],sfw->FixReorder()) ;
2076   Draw::Set(argv[7],sfw->FixDegenerated()) ;
2077   Draw::Set(argv[8],sfw->FixConnected()) ;
2078   Draw::Set(argv[9],sfw->FixSelfIntersection()) ;
2079
2080   ShapeExtend_Status status = ShapeExtend_OK;
2081   if(sfw->StatusSelfIntersection(status))
2082     di << "\n ShapeExtend_OK : No intersection found";
2083
2084   status = ShapeExtend_FAIL1;
2085   if(sfw->StatusSelfIntersection(status))
2086     di << "\n ShapeExtend_FAIL1 : analysis failed (edge has no pcurve,or no vertices etc.)";
2087
2088   status = ShapeExtend_FAIL2;
2089   if(sfw->StatusSelfIntersection(status))
2090     di << "\n ShapeExtend_FAIL2 : self-intersection was found, but not fixed because of limit of increasing tolerance (MaxTolerance)";
2091
2092   status = ShapeExtend_FAIL3;
2093   if(sfw->StatusSelfIntersection(status))
2094     di << "\n ShapeExtend_FAIL3 : intercestion of non adjacent edges found, but not fixed because of limit of increasing tolerance (MaxTolerance)";
2095
2096   status = ShapeExtend_DONE1;
2097   if(sfw->StatusSelfIntersection(status))
2098     di << "\n ShapeExtend_DONE1 : tolerance of vertex was increased to fix self-intersection";
2099
2100   status = ShapeExtend_DONE2;
2101   if(sfw->StatusSelfIntersection(status))
2102     di << "\n ShapeExtend_DONE2 : vertex was moved to fix self-intersection";
2103
2104   status = ShapeExtend_DONE3;
2105   if(sfw->StatusSelfIntersection(status))
2106     di << "\n ShapeExtend_DONE3 : some edges were removed because of intersection";
2107
2108   status = ShapeExtend_DONE4;
2109   if(sfw->StatusSelfIntersection(status))
2110     di << "\n ShapeExtend_DONE4 : pcurve(s) was(were) modified";
2111
2112   status = ShapeExtend_DONE5;
2113   if(sfw->StatusSelfIntersection(status))
2114     di << "\n ShapeExtend_DONE5 : non adjacent intersection fixed by increasing tolerance of vertex(vertices)";
2115
2116   status = ShapeExtend_DONE6;
2117   if(sfw->StatusSelfIntersection(status))
2118     di << "\n ShapeExtend_DONE6 : tolerance of edge was increased to hide intersection";
2119
2120   status = ShapeExtend_DONE7;
2121   if(sfw->StatusSelfIntersection(status))
2122     di << "\n ShapeExtend_DONE7 : range of some edges was decreased to avoid intersection";
2123
2124   TopoDS_Wire finalwire = sfw->Wire();
2125
2126   DBRep::Set(argv[1],finalwire);
2127
2128
2129   advWA->Load(TopoDS::Wire(finalwire));
2130
2131   TopoDS_Face fface =
2132     BRepBuilderAPI_MakeFace(TopoDS::Wire(finalwire),Standard_True);
2133
2134   DBRep::Set(argv[2],fface);
2135
2136   advWA->SetFace(fface);
2137
2138   TopTools_IndexedMapOfShape fM;
2139   TopExp::MapShapes(finalwire, TopAbs_EDGE, fM);
2140
2141   for(j= 1; j<=fM.Extent(); ++j) {
2142     Standard_Integer num=1;
2143     IntRes2d_SequenceOfIntersectionPoint points2d;
2144     TColgp_SequenceOfPnt points3d;
2145
2146     di << "\n j =" << j << ",  CheckSelfIntersectingEdge = " <<
2147       (Standard_Integer) advWA->CheckSelfIntersectingEdge(j, points2d, points3d);
2148
2149
2150     ShapeExtend_Status status = ShapeExtend_FAIL1;
2151     if(advWA->StatusSelfIntersection(status))
2152
2153       status = ShapeExtend_FAIL2;
2154     if(advWA->StatusSelfIntersection(status))
2155       di << "\n No Vertices found in the edge";
2156
2157     status = ShapeExtend_DONE1;
2158     if(advWA->StatusSelfIntersection(status))
2159       di << "\n Self-intersection found in the edge";
2160
2161     num = points2d.Length();
2162     di << "\n No. of self-intersecting edges : " << num;
2163
2164     for(int i=1; i<=num; ++i) {
2165       gp_Pnt pt = points3d(i);
2166       di << "\n Intersecting pt : (" << pt.X() << ", " << pt.Y() << ", " << pt.Z() << ")";
2167     }
2168
2169   }
2170
2171   di << "\n";
2172
2173   return 0;
2174 }
2175
2176 Standard_Integer OCC17480(Draw_Interpretor& di,   Standard_Integer n,   const char ** a)
2177 {
2178   if ( n < 2 ) {
2179     cout << "Usage: OCC17480 basic_shape <mode[0:1]>" <<endl;
2180     return 0;    
2181   }
2182
2183   TopoDS_Shape brep_pipe =  DBRep::Get(a[1]);
2184
2185   Standard_Boolean mode = Standard_False;
2186   if(n == 3 && atoi(a[2]) == 1)
2187     mode = Standard_True;
2188
2189   Handle_AIS_Shape ais_pipe = new AIS_Shape( brep_pipe );
2190   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2191   Handle(AIS2D_InteractiveContext) aContext_2d = Viewer2dTest::GetAIS2DContext();
2192
2193   if(!aContext.IsNull())
2194     aContext->Display(ais_pipe);      
2195
2196   if(!aContext_2d.IsNull())
2197     aContext_2d->EraseAll(Standard_True);
2198
2199   gp_Ax3 ax3(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1), gp_Dir(0, 1, 0));
2200   gp_Pln plane(ax3);
2201   gp_Ax2 ax2 = ax3.Ax2();
2202
2203   HLRAlgo_Projector aProjector = HLRAlgo_Projector(ax2);
2204   Handle_AIS2D_ProjShape myDisplayableShape = 
2205     new AIS2D_ProjShape(aProjector, 0, mode, Standard_True);
2206
2207   myDisplayableShape->Add( brep_pipe );
2208
2209   di << "\n Total number of primitives : " << myDisplayableShape->Length();
2210
2211   Handle(Graphic2d_Line) mySectProjLines = myDisplayableShape->GetPrimitives();
2212   Handle(Graphic2d_Line) mySectProjLinesHLR = myDisplayableShape->GetHLPrimitives();
2213
2214   Handle_Standard_Type sty = mySectProjLines->DynamicType();
2215   Handle_Standard_Type sty1 = mySectProjLinesHLR->DynamicType();
2216
2217   di << "\n Class Name = " << (char*)sty->Name();
2218   di << "\n HLR Class Name = " << (char*)sty1->Name();
2219   di << "\n mySectProjLines.IsNull = " << (Standard_Integer) mySectProjLines.IsNull();
2220   di << "\n mySectProjLinesHLR.IsNull = " << (Standard_Integer) mySectProjLinesHLR.IsNull();
2221
2222   Handle(GGraphic2d_SetOfCurves) setCurves;
2223   Handle(Graphic2d_SetOfSegments) setSegments;
2224
2225   if(mySectProjLines->IsKind(STANDARD_TYPE(GGraphic2d_SetOfCurves)))
2226   {
2227     setCurves = Handle(GGraphic2d_SetOfCurves)::DownCast(mySectProjLines);
2228     di << "\n Number of Curves in set = " << setCurves->Length();
2229   }
2230   if(mySectProjLines->IsKind(STANDARD_TYPE(Graphic2d_SetOfSegments)))    
2231   {
2232     setSegments = Handle(Graphic2d_SetOfSegments)::DownCast(mySectProjLines);
2233     di << "\n Number of Curves in set = " << setSegments->Length();
2234   }
2235
2236   Handle(GGraphic2d_SetOfCurves) setCurvesHLR;
2237   Handle(Graphic2d_SetOfSegments) setSegmentsHLR;
2238
2239   if(mySectProjLinesHLR->IsKind(STANDARD_TYPE(GGraphic2d_SetOfCurves)))
2240   {
2241     setCurvesHLR = Handle(GGraphic2d_SetOfCurves)::DownCast(mySectProjLinesHLR);
2242     di << "\n HLR Number of Curves in set = " << setCurvesHLR->Length();
2243   }
2244   if(mySectProjLinesHLR->IsKind(STANDARD_TYPE(Graphic2d_SetOfSegments)))
2245   {
2246     setSegmentsHLR = Handle(Graphic2d_SetOfSegments)::DownCast(mySectProjLinesHLR);
2247     di << "\n HLR Number of Curves in set = " << setSegmentsHLR->Length();
2248   }
2249
2250   aContext_2d->Display( myDisplayableShape,Standard_True );
2251   return 0;
2252 }
2253
2254 void QABugs::Commands_17(Draw_Interpretor& theCommands) {
2255   const char *group = "QABugs";
2256
2257   theCommands.Add ("BUC60842", "BUC60842", __FILE__, BUC60842, group);
2258   theCommands.Add ("BUC60843", "BUC60843 result_shape name_of_circle name_of_curve [ par1 [ tol ] ]", __FILE__, BUC60843, group);
2259   theCommands.Add ("BUC60970", "BUC60970 shape result", __FILE__, BUC60970, group);
2260   theCommands.Add ("BUC60818", "BUC60818", __FILE__, BUC60818, group);
2261   theCommands.Add ("BUC60915", "BUC60915", __FILE__, BUC60915_1, group);
2262   theCommands.Add ("OCC138", "OCC138", __FILE__, OCC138, group);
2263   theCommands.Add ("BUC60821","BUC60821",__FILE__,BUC60821,group);
2264   theCommands.Add ("OCC353","OCC353",__FILE__,OCC353,group);
2265   theCommands.Add ("OCC280","OCC280 hlr=0/1 setsurfecedetail=0/1; set perspecrive view",__FILE__,OCC280,group);
2266   theCommands.Add ("OCC232", "OCC232", __FILE__, OCC232 , group);
2267   theCommands.Add ("OCC138LC", "OCC138LC", __FILE__, OCC138LC, group);
2268   theCommands.Add ("OCC189", "OCC189", __FILE__, OCC189, group);
2269   theCommands.Add ("OCC389", "OCC389 name shape1 [shape2] ...", __FILE__, OCC389, group);
2270
2271   theCommands.Add ("OCC566", "OCC566 shape [ xmin ymin zmin xmax ymax zmax] ; print bounding box", __FILE__, OCC566, group);
2272   theCommands.Add ("OCC570", "OCC570 result", __FILE__, OCC570, group);
2273
2274   theCommands.Add("OCC570mkevol",
2275     "OCC570mkevol result object (then use updatevol) [R/Q/P]; mkevol",
2276     __FILE__, MKEVOL,group);
2277   theCommands.Add("OCC570updatevol",
2278     "OCC570updatevol edge u1 rad1 u2 rad2 ...; updatevol",
2279     __FILE__, UPDATEVOL,group);
2280   theCommands.Add("OCC570updatevollaw",
2281     "OCC570updatevollaw edge u1 rad1 u2 rad2 ...; updatevollaw",
2282     __FILE__, UPDATEVOL,group);
2283   theCommands.Add("OCC570buildevol",
2284     "OCC570buildevol; end of the evol fillet computation",
2285     __FILE__, BUILDEVOL,group);
2286
2287   theCommands.Add ("OCC606", "OCC606 result shape [-t]", __FILE__, OCC606, group);
2288
2289   theCommands.Add ("OCC813", "OCC813 U V", __FILE__, OCC813, group);
2290   theCommands.Add ("OCC814", "OCC814", __FILE__, OCC814, group);
2291   theCommands.Add ("OCC884", "OCC884 result shape [toler [maxtoler]]", __FILE__, OCC884, group);
2292   theCommands.Add ("OCC1188", "OCC1188 imagefile [filltype] : Load image as background", __FILE__, OCC1188, group);
2293
2294   theCommands.Add ("OCC1174_1", "OCC1174_1 shape", __FILE__, OCC1174_1, group);
2295   theCommands.Add ("OCC1174_2", "OCC1174_2 shape", __FILE__, OCC1174_2, group);
2296
2297   theCommands.Add("OCC672_Length"," OCC672_Length x1 y1 x2 y2 str scale_text length_dist angle_arrow length_arrow x3 y3 x4 y4 textAngle textPosH textPosV",__FILE__,OCC672_Length,group);
2298   theCommands.Add("OCC672_Angle","OCC672_Angle x1 y1 x2 y2 x3 y3 aRadius aText aTxtScale anArrAngle anArrLength txtAngle txtPosH txtPosV",__FILE__,OCC672_Angle,group);
2299   theCommands.Add("OCC672_Diameter","OCC672_Diameter x1 y1 cx cy radius aText aTxtScale anArrAngle anArrLength txtAngle txtPosH txtPosV",__FILE__,OCC672_Diameter,group);
2300   theCommands.Add("OCC672_ShortLength","",__FILE__,OCC672_ShortLength,group);
2301
2302   theCommands.Add ("OCCN1", "OCCN1 angle fuse(1 for boss / 0 for slot) length", __FILE__, OCCN1, group);
2303   theCommands.Add ("OCCN2", "OCCN2", __FILE__, OCCN2, group);
2304
2305   theCommands.Add ("OCC2569", "OCC2569 nbpoles result", __FILE__, OCC2569, group);
2306
2307   theCommands.Add ("OCC1642", "OCC1642 FinalWare FinalFace InitWare InitFace shape FixReorder FixDegenerated FixConnected FixSelfIntersection", __FILE__, OCC1642, group);
2308
2309   theCommands.Add ("OCC17480", "OCC17480 Shape", __FILE__, OCC17480, group);
2310
2311   return;
2312 }