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