0028573: Get rid of the old Boolean Operations in QA commands
[occt.git] / src / QABugs / QABugs_3.cxx
1 // Created on: 2002-06-17
2 // Created by: QA Admin
3 // Copyright (c) 2002-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <QABugs.hxx>
17 #include <Draw.hxx>
18 #include <Draw_Interpretor.hxx>
19 #include <TopLoc_Location.hxx>
20 #include <TopoDS_Face.hxx>
21 #include <TopoDS.hxx>
22 #include <DBRep.hxx>
23 #include <Geom_Surface.hxx>
24 #include <BRep_Tool.hxx>
25 #include <GeomInt_IntSS.hxx>
26 #include <BRepBuilderAPI_MakeEdge.hxx>
27 #include <Standard_ErrorHandler.hxx>
28 #include <Graphic3d_ClipPlane.hxx>
29
30 #include <fstream>
31
32 static int BUC60623(Draw_Interpretor& di, Standard_Integer argc, const char ** a)
33 {
34   if(argc!=4)
35   {
36     di << "Usage : " << a[0] << " result Shape1 Shape2\n";
37     return -1;
38   }
39
40   TopLoc_Location L1;
41   TopLoc_Location L2;
42   TopoDS_Face F1 = TopoDS::Face(DBRep::Get(a[2],TopAbs_FACE));
43   TopoDS_Face F2 = TopoDS::Face(DBRep::Get(a[3],TopAbs_FACE));
44   Handle(Geom_Surface) GSF1 = BRep_Tool::Surface(F1, L1);
45   Handle(Geom_Surface) GSF2 = BRep_Tool::Surface(F2, L2);
46   GeomInt_IntSS Inter;
47   Inter.Perform(GSF1,GSF2, BRep_Tool::Tolerance(F1));
48   if (!Inter.IsDone()) {
49     di << "Intersection not done\n";
50     return 1;
51   }
52   Standard_Integer nbsol = Inter.NbLines();
53   if(!nbsol) {
54     di << "The number of solutions is zero!"   << "\n";
55     return 0;
56   }
57   Handle(Geom_Curve) Sol = Inter.Line(1);
58   if(!Sol.IsNull()) {
59     DBRep::Set(a[1], BRepBuilderAPI_MakeEdge(Sol));
60       return 0;
61     } else di << "The first solution is Null!"   << "\n";
62
63   di << "fini\n";
64   return 0;
65 }
66
67 #include<ViewerTest.hxx>
68 #include<AIS_InteractiveContext.hxx>
69 #include<AIS_Shape.hxx>
70   
71 static int BUC60569(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
72 {
73   if(argc!=2)
74   {
75     di << "Usage : " << argv[0] << " shape\n";
76     return -1;
77   }
78
79   Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
80   if(myAISContext.IsNull()) {
81     di << "use 'vinit' command before " << argv[0] << "\n";
82     return -1;
83   }
84
85   TopoDS_Shape theShape =  DBRep::Get(argv[1]);
86
87   Handle(AIS_Shape) anAISShape = new AIS_Shape( theShape ); 
88   myAISContext->Display( anAISShape, Standard_True );
89
90   Standard_DISABLE_DEPRECATION_WARNINGS
91   myAISContext->OpenLocalContext(); 
92   myAISContext->ActivateStandardMode(TopAbs_FACE);
93   Standard_ENABLE_DEPRECATION_WARNINGS
94
95   return 0;
96 }
97
98 static int BUC60614(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
99 {
100   if(argc!=2)
101   {
102     di << "Usage : "<< argv[0] << " shape\n";
103     return -1;
104   }
105
106   //  di.Eval("vinit");
107
108   TopoDS_Shape theShape =  DBRep::Get(argv[1]);
109
110 //  ViewerTest::GetAISContext(); 
111   Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
112   if(myAISContext.IsNull()) {
113     di << "use 'vinit' command before " << argv[0] << "\n";
114     return -1;    
115   }
116   Handle(AIS_Shape) anAISShape = new AIS_Shape( theShape ); 
117   myAISContext->Display( anAISShape, Standard_True );
118
119   Standard_DISABLE_DEPRECATION_WARNINGS
120   myAISContext->OpenLocalContext(); 
121   myAISContext->ActivateStandardMode(TopAbs_COMPOUND);
122   Standard_ENABLE_DEPRECATION_WARNINGS
123 //  myAISContext->ActivateStandardMode(TopAbs_SOLID);
124 //  di.Eval("vfit");
125 //  cout << "vfini" << endl;
126   return 0;
127 }
128
129 #include<BRep_Builder.hxx>
130 #include<BRepTools_ShapeSet.hxx>
131 #include<BRepTools.hxx>
132 #include<BRepAdaptor_HSurface.hxx>
133 #include<TopOpeBRep_PointClassifier.hxx>
134 #include<Precision.hxx>
135 #ifdef _MSC_VER
136 #include<stdio.h>
137 #endif
138
139 static int BUC60609(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) {
140   gp_Pnt2d uvSurf;
141   TopAbs_State state;
142   
143   if (argc == 3) {
144     // BUC60609 shape name
145   } else if ( argc == 5 ) {
146     // BUC60609 shape name U V
147   } else {
148     di << "Usage : "<< argv[0] << " shape name [U V]\n";
149     return(-1);
150   }
151   
152   TCollection_AsciiString  aFilePath(argv[1]); 
153   
154   filebuf fic;
155   istream in(&fic);
156   if (!fic.open(aFilePath.ToCString(),ios::in)) {
157     di << "Cannot open file for reading : " << aFilePath << "\n";
158     return(-1);
159   }
160
161   TopoDS_Shape theShape;
162   char typ[255];
163   in >> typ;
164   if (!in.fail()) {
165     if( !strcmp(typ, "DBRep_DrawableShape") ){
166       BRep_Builder B;
167       BRepTools_ShapeSet S(B);
168       S.Read(in);
169       S.Read(theShape,in);
170     }else{
171       di << "Wrong entity type in " << aFilePath << "\n";
172       return(-1);
173     }
174   }
175
176   const TopoDS_Face &face = TopoDS::Face (theShape);
177
178   if(argc > 2){
179     DBRep::Set(argv[2],face);
180   }
181
182   Standard_Real faceUMin,faceUMax,faceVMin,faceVMax;
183   
184   BRepTools::UVBounds (face, faceUMin,faceUMax,faceVMin,faceVMax);
185
186   di << "The bounds of the trimmed face:\n";
187   di << faceUMin << " <= U <= " << faceUMax << "\n";
188   di << faceVMin << " <= V <= " << faceVMax << "\n";
189   
190   Handle(BRepAdaptor_HSurface) hsurfa = new BRepAdaptor_HSurface(face);
191   
192   TopOpeBRep_PointClassifier PClass;
193
194   di << "Now test the point classifier by inputting U,V values\n";
195   di << "inside or outside the bounds displayed above\n";
196   di << "Type stop to exit\n";
197   
198   // Please register this:
199   // ***********************************************
200   // Note also that for periodic surfaces such as nimpod_1.topo,
201   // the U/V values may be +- 2pi compared to the actual face bounds
202   // (because U,V is probably coming from a Geom package routine).
203   // Hence IT WOULD BE USEFUL IF TopOpeBRep_PointClassifier COULD
204   // COPE WITH PERIODIC SURFACES, i.e. U,V +-Period giving same result.
205   // *************************************************
206
207   if (argc == 3) {
208     uvSurf = gp_Pnt2d(0.14,5.1);
209     state = PClass.Classify(face,uvSurf,Precision::PConfusion());
210     if(state == TopAbs_IN || state == TopAbs_ON){
211       di << "U=" << 0.14 << " V=" << 5.1 << "  classified INSIDE\n";
212     }else{
213       di << "U=" << 0.14 << " V=" << 5.1 << "  classified OUTSIDE\n";
214     }
215
216     uvSurf = gp_Pnt2d(1.28,5.1);
217     state = PClass.Classify(face,uvSurf,Precision::PConfusion());
218     if(state == TopAbs_IN || state == TopAbs_ON){
219       di << "U=" << 1.28 << " V=" << 5.1 << "  classified INSIDE\n";
220     }else{
221       di << "U=" << 1.28 << " V=" << 5.1 << "  classified OUTSIDE\n";
222     }
223   } else {
224     uvSurf = gp_Pnt2d(Draw::Atof(argv[3]),Draw::Atof(argv[4]));
225     state = PClass.Classify(face,uvSurf,Precision::PConfusion());
226     if(state == TopAbs_IN || state == TopAbs_ON){
227       di << "U=" << Draw::Atof(argv[3]) << " V=" << Draw::Atof(argv[4]) << "  classified INSIDE\n";
228     }else{
229       di << "U=" << Draw::Atof(argv[3]) << " V=" << Draw::Atof(argv[4]) << "  classified OUTSIDE\n";
230     }
231   }
232   return 0;
233 }
234
235 #include<BRepBuilderAPI_MakeVertex.hxx>
236 #include<TCollection_ExtendedString.hxx>
237 #include<AIS_LengthDimension.hxx>
238
239 static Standard_Integer BUC60632(Draw_Interpretor& di, Standard_Integer /*n*/, const char ** a)
240 {
241   
242   Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
243   if(myAIScontext.IsNull()) {
244     di << "use 'vinit' command before " << a[0] << "\n";
245     return -1;
246   }
247   myAIScontext->EraseAll (Standard_False);
248   
249   TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(0,0,0)); 
250   TopoDS_Vertex V2 = BRepBuilderAPI_MakeVertex(gp_Pnt(10,10,0)); 
251   
252   Handle(AIS_Shape) Ve1 = new AIS_Shape(V1);
253   Handle(AIS_Shape) Ve2 = new AIS_Shape(V2);
254   
255   myAIScontext->Display (Ve1, Standard_False);
256   myAIScontext->Display (Ve2, Standard_False);
257   
258   Handle(Geom_Plane) Plane1 = new Geom_Plane(gp_Pnt(0,0,0),gp_Dir(0,0,1)); 
259   TCollection_ExtendedString Ext1("Dim1"); 
260   Handle(AIS_LengthDimension) Dim1 = new AIS_LengthDimension(V1,V2,Plane1->Pln()); 
261   Dim1->SetCustomValue (Draw::Atof(a[2]));
262
263   Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
264   anAspect->MakeArrows3d (Standard_False);
265   anAspect->MakeText3d (Standard_True);
266   anAspect->MakeTextShaded (Standard_True);
267   anAspect->TextAspect()->SetHeight (2.5);
268   anAspect->ArrowAspect()->SetLength (1.0);
269   Dim1->SetDimensionAspect (anAspect);
270
271   myAIScontext->SetDisplayMode (Dim1, Draw::Atoi(a[1]), Standard_False);
272   myAIScontext->Display (Dim1, Standard_True);
273   return 0;
274 }
275
276 #include<TopoDS_Wire.hxx>
277
278 static Standard_Integer BUC60652(Draw_Interpretor& di, Standard_Integer argc, const char ** argv )
279 {
280   if(argc!=2) {
281     di << "Usage : BUC60652 fase"   << "\n";
282     return 1;
283   }
284   TopoDS_Shape shape = DBRep::Get( argv[1] ); 
285   TopoDS_Face face = TopoDS::Face( shape ); 
286   TopoDS_Wire ow = BRepTools::OuterWire( face ); 
287   DBRep::Set( "w", ow ); 
288   return 0; 
289 }
290
291 #include <Geom_Axis2Placement.hxx>
292 #include <AIS_Trihedron.hxx>
293
294 static Standard_Integer BUC60574(Draw_Interpretor& di, Standard_Integer /*n*/, const char ** a)
295 {
296   
297   Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
298   if(myAISContext.IsNull()) {
299     di << "use 'vinit' command before " << a[0] << "\n";
300     return -1;
301   }
302   
303   Handle(Geom_Axis2Placement) atrihedronAxis = new Geom_Axis2Placement(gp::XOY()); 
304   Handle(AIS_Trihedron) atri = new AIS_Trihedron(atrihedronAxis); 
305   gp_Trsf aTrsf; 
306   gp_Vec trans(5,5,5); 
307   aTrsf.SetTranslation(trans); 
308   TopLoc_Location aLoc(aTrsf); 
309   myAISContext->SetLocation(atri,aLoc); 
310   myAISContext->Display(atri,0,-1,Standard_True, Standard_True);
311
312   Standard_DISABLE_DEPRECATION_WARNINGS
313   myAISContext->OpenLocalContext(Standard_False, Standard_True, Standard_False, Standard_False);
314   Standard_ENABLE_DEPRECATION_WARNINGS
315
316   myAISContext->Load(atri,3,Standard_True);
317
318   return 0;
319 }
320
321 #include <TopoDS_Solid.hxx>
322 #include <BRepPrimAPI_MakeBox.hxx>
323 #include <BRepPrimAPI_MakeSphere.hxx>
324
325 #include <BRepAlgoAPI_Fuse.hxx>
326
327 #include <V3d_View.hxx>
328 #include <gce_MakePln.hxx>
329
330 #define DEFAULT_COLOR    Quantity_NOC_GOLDENROD
331
332 //=======================================================================
333 //function : GetColorFromName
334 //purpose  : get the Quantity_NameOfColor from a string
335 //=======================================================================
336
337 static Quantity_NameOfColor GetColorFromName( const char *name ) 
338
339   Quantity_NameOfColor ret = DEFAULT_COLOR;
340   
341   Standard_Boolean Found = Standard_False;
342   Standard_CString colstring;
343   for(Standard_Integer i=0;i<=514 && !Found;i++)
344     {
345       colstring = Quantity_Color::StringName(Quantity_NameOfColor(i));
346       if (!strcasecmp(name,colstring)) {
347         ret = (Quantity_NameOfColor)i;
348         Found = Standard_True;
349       }
350     }
351   
352   return ret;
353 }
354    
355 static Standard_Integer setcolor (Draw_Interpretor& di,Standard_Integer argc, const char ** argv )
356 {
357
358 Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
359 if(myAISContext.IsNull()) { 
360     di << "use 'vinit' command before " << argv[0] << "\n";
361     return -1;
362   }
363
364 Handle(V3d_View) myV3dView = ViewerTest::CurrentView();
365
366 switch (argc){
367
368  case 2:
369    {
370      di <<"case 2 : This command will change the background color to " << argv[1]<< "\n";
371 //   setcolor <name> 
372 //   Change the background color of the view with a predefined name Graphic3d_NOC_<name>  
373
374      myV3dView -> SetBackgroundColor(GetColorFromName(argv[1]));
375      myV3dView -> Redraw();
376    break;
377    }
378
379  case 3:
380    {
381      di <<"case 3 : This command will change the color of the objects to "<< argv[2]<< "\n";
382 //   setcolor <object> <name> 
383 //   Change the object color with a predefined name 
384
385      TopoDS_Shape aShape = DBRep::Get(argv[1]);
386      Handle(AIS_InteractiveObject) myShape = new AIS_Shape (aShape);
387      myAISContext->SetColor(myShape,GetColorFromName(argv[2]),Standard_True);
388      myAISContext->Display(myShape,Standard_True);
389      myAISContext->UpdateCurrentViewer();
390 //     return 0;
391    break;
392    }
393  case 4:
394    {
395      di <<"case 4 : This command will change the background color to <r> <g> <b> :"<< argv[1] << argv[2] << argv[3] << "\n";
396
397 //   setcolor <r> <g> <b> 
398 //   Change the background color of the view with the color values <r>,<g>,<b> 
399 //   A color value must be defined in the space [0.,1.] 
400
401      Standard_Real QuantityOfRed   = Draw::Atoi(argv[1]);
402      Standard_Real QuantityOfGreen = Draw::Atoi(argv[2]);
403      Standard_Real QuantityOfBlue  = Draw::Atoi(argv[3]);
404      myV3dView->SetBackgroundColor(Quantity_TOC_RGB,QuantityOfRed,QuantityOfGreen,QuantityOfBlue);
405      myV3dView->Redraw();
406    break;
407    }
408
409  case 5:
410    {
411     di <<"case 5 : This command will change the color of the objects to <r> <g> <b> : "<<argv[2]<< argv[3]<< argv[4]<< "\n";
412
413 //  setcolor <object> <r> <g> <b> 
414 //  change the object color with RGB values. 
415
416
417     Standard_Real QuantityOfRed   = Draw::Atof(argv[2]);
418     Standard_Real QuantityOfGreen = Draw::Atof(argv[3]);
419     Standard_Real QuantityOfBlue  = Draw::Atof(argv[4]);
420
421     TopoDS_Shape aShape = DBRep::Get(argv[1]);
422     Handle(AIS_InteractiveObject) myShape =  new AIS_Shape (aShape);
423     myAISContext->SetColor(myShape,Quantity_Color(QuantityOfRed,QuantityOfGreen,QuantityOfBlue,Quantity_TOC_RGB),Standard_True);
424     myAISContext->Display(myShape,Standard_True);
425     myAISContext->UpdateCurrentViewer();
426 //  myShape->SetColor(Quantity_Color(QuantityOfRed,QuantityOfGreen,QuantityOfBlue,Quantity_TOC_RGB));
427 //  myShape->Redisplay();
428    break;
429    }
430  }
431 return 0;
432 }
433
434 #include <Bnd_BoundSortBox.hxx>
435 #include <BRepBndLib.hxx>
436 #include <Bnd_HArray1OfBox.hxx>
437   
438 static Standard_Integer BUC60729 (Draw_Interpretor& /*di*/,Standard_Integer /*argc*/, const char ** /*argv*/ )
439 {
440   Bnd_Box aMainBox;
441   TopoDS_Shape aShape = BRepPrimAPI_MakeBox(1,1,1).Solid();
442
443   BRepBndLib::Add(aShape , aMainBox );
444
445   Standard_Integer siMaxNbrBox = 6;
446   Bnd_BoundSortBox m_BoundSortBox;
447   m_BoundSortBox.Initialize( aMainBox, siMaxNbrBox );
448   TopExp_Explorer aExplorer(aShape,TopAbs_FACE);
449   Standard_Integer i;
450
451
452 //  Bnd_Box __emptyBox; // Box is void !
453 //  Handle(Bnd_HArray1OfBox) __aSetOfBox = new Bnd_HArray1OfBox( 1, siMaxNbrBox, __emptyBox ); 
454
455   for (i=1,aExplorer.ReInit(); aExplorer.More(); aExplorer.Next(),i++ ) 
456     { 
457       const TopoDS_Shape& aFace = aExplorer.Current();
458       Bnd_Box aBox;
459       BRepBndLib::Add( aFace, aBox );
460       m_BoundSortBox.Add( aBox, i );
461 //      __aSetOfBox->SetValue( i, aBox ); 
462     } 
463 //  m_BoundSortBox.Initialize( aMainBox, siMaxNbrBox );
464   
465   return 0;
466 }
467
468 static Standard_Integer BUC60724(Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/ )
469 {
470   TCollection_AsciiString as1("");
471   TCollection_AsciiString as2('\0');
472   if(as1.ToCString() == NULL || as1.Length() != 0 || as1.ToCString()[0] != '\0')
473     di << "Error : the first string is not zero string : " << as1.ToCString() << "\n";
474
475   if(as2.ToCString() == NULL || as2.Length() != 0 || as2.ToCString()[0] != '\0')
476     di << "Error : the second string is not zero string : " << as2.ToCString() << "\n";
477   
478   return 0;
479 }
480
481 #include <UnitsAPI.hxx>
482
483 static Standard_Integer BUC60727(Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/ )
484 {
485 di <<"Program Test\n";
486 UnitsAPI::SetLocalSystem(UnitsAPI_MDTV); //length is mm 
487 di <<"AnyToLS (3,mm) = " << UnitsAPI::AnyToLS(3.,"mm") << "\n"; // result was WRONG. 
488
489    return 0;
490 }
491
492 #include <gp_Circ.hxx>
493 #include <Geom_Circle.hxx>
494 #include <GeomAPI.hxx>
495 #include <Geom2d_CartesianPoint.hxx>
496 #include <Geom2dGcc_QualifiedCurve.hxx>
497 #include <Geom2dGcc_Circ2d2TanRad.hxx>
498 #include <Geom2d_Circle.hxx>
499 #include <ProjLib.hxx>
500
501 static Standard_Integer BUC60792(Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv )
502 {
503   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
504   if(aContext.IsNull()) { 
505     di << "use 'vinit' command before " << argv[0] << "\n";
506     return -1;
507   }
508
509   gp_Pnt pt3d(0, 20, 150);
510   gp_Ax2 anAx2(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0), gp_Dir(0, 0, 1));
511   gp_Circ circ(anAx2, 50.0); 
512   Handle(Geom_Circle) gcir = new Geom_Circle(circ); 
513   Handle(Geom_Plane) pln = new Geom_Plane(gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0))); 
514   Handle(Geom2d_Curve) gcir1 = GeomAPI::To2d(gcir, pln->Pln()); 
515   TopoDS_Shape sh1 = BRepBuilderAPI_MakeEdge(gcir1, pln).Shape(); 
516   Handle(AIS_Shape) ais1 = new AIS_Shape(sh1); 
517   aContext->SetColor (ais1, Quantity_NOC_INDIANRED, Standard_False);
518   aContext->Display (ais1, Standard_False);
519   DBRep::Set("sh0",sh1);
520   gp_Pnt2d thepoint; 
521 //  local_get_2Dpointfrom3Dpoint(pt3d, pln->Pln(), thepoint); 
522   thepoint = ProjLib::Project(pln->Pln(),pt3d);
523   Handle(Geom2d_CartesianPoint) ThePoint = new Geom2d_CartesianPoint(thepoint); 
524   Geom2dAdaptor_Curve acur1(gcir1) ; 
525   Geom2dGcc_QualifiedCurve qcur1(acur1, GccEnt_outside) ; 
526   Geom2dGcc_Circ2d2TanRad cirtanrad(qcur1, ThePoint, 200.0, 0.0001); 
527   printf("\n No. of solutions = %d\n", cirtanrad.NbSolutions()); 
528   Handle(Geom2d_Circle) gccc; 
529   if( cirtanrad.NbSolutions() ) { 
530     for( int i = 1; i<=cirtanrad.NbSolutions(); i++) { 
531       gp_Circ2d ccc = cirtanrad.ThisSolution(i); 
532       gccc = new Geom2d_Circle(ccc); 
533       TopoDS_Shape sh = BRepBuilderAPI_MakeEdge(gccc, pln).Shape();
534       Standard_Character aStr[5];
535       Sprintf(aStr,"sh%d",i);
536       DBRep::Set(aStr,sh);
537       Handle(AIS_Shape) ais = new AIS_Shape(sh); 
538       if( i ==1 ) 
539         aContext->SetColor (ais, Quantity_NOC_GREEN, Standard_False);
540       if( i == 2) 
541         aContext->SetColor (ais, Quantity_NOC_HOTPINK, Standard_False);
542       aContext->Display (ais, Standard_False);
543       Standard_Real ParSol1, ParSol2, ParArg1, ParArg2; 
544       gp_Pnt2d PntSol1, PntSol2; 
545       cirtanrad.Tangency1(i, ParSol1, ParArg1, PntSol1);
546       printf("%f\t%f\t\t%f\t%f\n",ParSol1, ParArg1,PntSol1.X(),PntSol1.Y());
547       cirtanrad.Tangency2(i, ParSol2, ParArg2, PntSol2); 
548       printf("%f\t%f\t\t%f\t%f\n",ParSol2, ParArg2,PntSol2.X(),PntSol2.Y());
549     }
550   }
551   aContext->UpdateCurrentViewer();
552   return 0;
553 }
554
555 #include <TColgp_Array2OfPnt.hxx>
556 #include <Geom_BezierSurface.hxx>
557 #include <BRepBuilderAPI_MakeFace.hxx>
558 #include <BRepBuilderAPI_MakeWire.hxx>
559 #include <Geom_OffsetSurface.hxx>
560 #include <BRepFilletAPI_MakeFillet2d.hxx>
561 #include <GeomProjLib.hxx>
562 #include <Geom_TrimmedCurve.hxx>
563
564 static Standard_Integer BUC60811(Draw_Interpretor& di, Standard_Integer argc, const char ** argv )
565 {
566   if(argc == 4) {
567     TopLoc_Location L1;
568     TopoDS_Edge aEdge = TopoDS::Edge(DBRep::Get(argv[2],TopAbs_EDGE));
569     TopoDS_Face aFace = TopoDS::Face(DBRep::Get(argv[3],TopAbs_FACE));
570     Standard_Real f = 0.0, l = 0.0; 
571     Handle(Geom_Curve) GC = BRep_Tool::Curve(aEdge,f,l);
572     Handle(Geom_Surface) GS = BRep_Tool::Surface(aFace, L1);
573     GC = new Geom_TrimmedCurve(GC, f, l); 
574     Handle(Geom_Curve) projCurve = GeomProjLib::Project(GC,GS); 
575     BRepBuilderAPI_MakeWire *myWire; 
576     myWire = new BRepBuilderAPI_MakeWire(); 
577     myWire->Add((BRepBuilderAPI_MakeEdge(projCurve)).Edge());
578     DBRep::Set(argv[1],myWire->Wire());
579     return  0;
580   }
581   
582   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
583   if(aContext.IsNull()) { 
584     di << "use 'vinit' command before " << argv[0] << "\n";
585     return -1;
586   }
587   
588 //step 1. creating a Bezier Surface and a patch 
589   TopoDS_Face FP; 
590   TopoDS_Shape FP1; 
591   TopoDS_Solid solid; 
592   Handle(AIS_Shape) ais1; 
593   Handle(AIS_Shape) ais2; 
594   Handle(Geom_BezierSurface) BZ1;
595   TColgp_Array2OfPnt array1(1,3,1,3);
596   array1.SetValue(1,1,gp_Pnt(0,100,0));
597   array1.SetValue(1,2,gp_Pnt(200,100,0));
598   array1.SetValue(1,3,gp_Pnt(400,100,0)); 
599   array1.SetValue(2,1,gp_Pnt(0,200,100)); 
600   array1.SetValue(2,2,gp_Pnt(200,200,100)); 
601   array1.SetValue(2,3,gp_Pnt(400,200,100)); 
602   array1.SetValue(3,1,gp_Pnt(0,300,0)); 
603   array1.SetValue(3,2,gp_Pnt(200,300,0)); 
604   array1.SetValue(3,3,gp_Pnt(400,300,0)); 
605   BZ1 = new Geom_BezierSurface(array1);
606   BRepBuilderAPI_MakeFace bzf1( BZ1, Precision::Confusion() );
607   TopoDS_Face F1= bzf1.Face();
608   ais1 = new AIS_Shape(F1);
609   DBRep::Set("F1",F1);
610   aContext->SetMaterial(ais1,Graphic3d_NOM_ALUMINIUM,Standard_False);
611   aContext->Display (ais1, Standard_False);
612   BRep_Builder B;
613   TopoDS_Shell shell;
614   B.MakeShell(shell);
615   B.Add(shell, bzf1); 
616   shell.Closed (BRep_Tool::IsClosed (shell));
617   B.MakeSolid(solid);
618   B.Add(solid,shell); 
619   gp_Dir D(0, 0, 1.0f); 
620   BRepBuilderAPI_MakeWire mkw; 
621   gp_Pnt p1 = gp_Pnt(150., 150.0, 260.);
622   gp_Pnt p2 = gp_Pnt(350., 150., 260.); 
623   BRepBuilderAPI_MakeEdge* E1 = new BRepBuilderAPI_MakeEdge(p1,p2); 
624   mkw.Add(*E1); 
625   p1 = gp_Pnt(350., 150., 260.); 
626   p2 = gp_Pnt(350., 250., 260.); 
627   BRepBuilderAPI_MakeEdge* E2 = new BRepBuilderAPI_MakeEdge(p1,p2); 
628   mkw.Add(*E2); 
629   p1 = gp_Pnt(350., 250., 260.); 
630   p2 = gp_Pnt(300., 250.0, 260.); 
631   BRepBuilderAPI_MakeEdge* E3 = new BRepBuilderAPI_MakeEdge(p1,p2);
632   mkw.Add(*E3); 
633   p1 = gp_Pnt(300., 250.0, 260.); 
634   p2 = gp_Pnt(200., 200.0, 260.); 
635   BRepBuilderAPI_MakeEdge* E4 = new BRepBuilderAPI_MakeEdge(p1,p2); 
636   mkw.Add(*E4); 
637   p1 = gp_Pnt(200., 200.0, 260.); 
638   p2 = gp_Pnt(150., 200.0, 260.); 
639   BRepBuilderAPI_MakeEdge* E5 = new BRepBuilderAPI_MakeEdge(p1,p2);
640   mkw.Add(*E5); 
641   p1 = gp_Pnt(150., 200.0, 260.); 
642   p2 = gp_Pnt(150., 150.0, 260.); 
643   BRepBuilderAPI_MakeEdge* E6 = new BRepBuilderAPI_MakeEdge(p1,p2);
644   mkw.Add(*E6); 
645   FP = BRepBuilderAPI_MakeFace(mkw.Wire()); 
646   ais2 = new AIS_Shape( FP ); 
647   aContext->SetMaterial(ais2,Graphic3d_NOM_ALUMINIUM,Standard_False); 
648   aContext->Display (ais2, Standard_False);
649
650   DBRep::Set("FP",FP);
651   
652 //step 2. offseting the surface. 
653   Handle(Geom_OffsetSurface) offsurf; 
654   offsurf = new Geom_OffsetSurface(BZ1, -100); 
655   BRepBuilderAPI_MakeFace bzf2( offsurf, Precision::Confusion() ); 
656   TopoDS_Face F2= bzf2.Face(); 
657   Handle(AIS_Shape) ais22 = new AIS_Shape(F2); 
658   aContext->Display (ais22, Standard_False);
659   DBRep::Set("F2",F2);
660   
661 //step 3. filleting the patch. 
662 //( I want to project wire of this patch on offseted surface above) 
663   BRepFilletAPI_MakeFillet2d fillet( FP ); 
664   TopExp_Explorer Ex; 
665   Ex.Init(FP, TopAbs_VERTEX); 
666   TopoDS_Vertex v1 = TopoDS::Vertex(Ex.Current()); 
667   fillet.AddFillet(v1, 20); 
668   di << "\nError is " << fillet.Status() << "\n";
669 //  printf("\nError is %d ", fillet.Status()); 
670   Ex.Next(); 
671   TopoDS_Vertex V2 = TopoDS::Vertex(Ex.Current()); 
672   fillet.AddFillet(V2, 20); 
673   di << "\nError is " << fillet.Status() << "\n";
674 //  printf("\nError is %d ", fillet.Status());
675   fillet.Build(); 
676   FP1 = fillet.Shape(); 
677   ais2 = new AIS_Shape( FP1 ); 
678   aContext->SetMaterial(ais2,Graphic3d_NOM_ALUMINIUM,Standard_False); 
679   aContext->Display (ais2, Standard_False);
680
681   DBRep::Set("FP1",FP1);
682   
683 //step 4. Projecting the wire of this patch on offsetted surface. 
684 //  TopExp_Explorer Ex; 
685   BRepBuilderAPI_MakeWire *myWire; 
686   myWire = new BRepBuilderAPI_MakeWire(); 
687   for (Ex.Init( FP1, TopAbs_EDGE); Ex.More(); Ex.Next()) 
688     { 
689       TopoDS_Edge e1 = TopoDS::Edge(Ex.Current()); 
690       Standard_Real f = 0.0, l = 0.0; 
691       Handle(Geom_Curve) newBSplin = BRep_Tool::Curve(e1, f, l);
692       newBSplin = new Geom_TrimmedCurve(newBSplin, f, l); 
693       Handle(Geom_Curve) projCurve = GeomProjLib::Project(newBSplin,offsurf); 
694       myWire->Add((BRepBuilderAPI_MakeEdge(projCurve)).Edge()); 
695     } 
696   Handle(AIS_Shape) ais33 = new AIS_Shape( myWire->Wire() ); 
697   aContext->Display (ais33, Standard_True);
698
699   DBRep::Set("Wire",myWire->Wire());
700   
701   return 0;
702 }
703
704 #include<GeomAPI_ExtremaCurveCurve.hxx>
705
706 static int BUC60825(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
707
708 {
709   if(argc < 3){
710     printf("Usage: %s edge1 edge2",argv[0]);
711     return(-1);
712   }
713  
714         TopoDS_Edge E1 = TopoDS::Edge(DBRep::Get(argv[1])),
715         E2 = TopoDS::Edge(DBRep::Get(argv[2]));
716
717         Standard_Real fp , lp;
718
719         Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1 , fp , lp),
720         C2 = BRep_Tool::Curve(E2 , fp , lp);
721
722         GeomAPI_ExtremaCurveCurve aExt(C1 , C2);
723
724         di << "NB RESULTS : " << aExt.NbExtrema() << "\n";
725
726         return 0;
727 }
728
729 #include <BRepBuilderAPI_MakePolygon.hxx>
730 #include <BRepOffsetAPI_ThruSections.hxx>
731
732 static int OCC10006(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
733 {
734   if(argc != 1) {
735     di << "Usage : " << argv[0] << "\n";
736     return 1;
737   }
738
739   double bottompoints1[12] = { 10, -10, 0, 100, -10, 0, 100, -100, 0, 10, -100, 0};
740   double toppoints1[12] = { 0, 0, 10, 100, 0, 10, 100, -100, 10, 0, -100, 10};
741   double bottompoints2[12] = { 0, 0, 10.00, 100, 0, 10.00, 100, -100, 10.00, 0, -100, 10.00};
742   double toppoints2[12] = { 0, 0, 250, 100, 0, 250, 100, -100, 250, 0, -100, 250};
743   BRepBuilderAPI_MakePolygon bottompolygon1, toppolygon1, bottompolygon2, toppolygon2;
744   gp_Pnt tmppnt;
745   for (int i=0;i<4;i++) {
746     tmppnt.SetCoord(bottompoints1[3*i], bottompoints1[3*i+1], bottompoints1[3*i+2]);
747     bottompolygon1.Add(tmppnt);
748     tmppnt.SetCoord(toppoints1[3*i], toppoints1[3*i+1], toppoints1[3*i+2]);
749     toppolygon1.Add(tmppnt);
750     tmppnt.SetCoord(bottompoints2[3*i], bottompoints2[3*i+1], bottompoints2[3*i+2]);
751     bottompolygon2.Add(tmppnt);
752     tmppnt.SetCoord(toppoints2[3*i], toppoints2[3*i+1], toppoints2[3*i+2]);
753     toppolygon2.Add(tmppnt);
754   }
755   bottompolygon1.Close();
756   DBRep::Set("B1",bottompolygon1.Shape());
757   toppolygon1.Close();
758   DBRep::Set("T1",toppolygon1.Shape());
759   bottompolygon2.Close();
760   DBRep::Set("B2",bottompolygon2.Shape());
761   toppolygon2.Close();
762   DBRep::Set("T2",toppolygon2.Shape());
763   BRepOffsetAPI_ThruSections loft1(Standard_True, Standard_True);
764   loft1.AddWire(bottompolygon1.Wire());
765   loft1.AddWire(toppolygon1.Wire());
766   loft1.Build();
767   BRepOffsetAPI_ThruSections loft2(Standard_True, Standard_True);
768   loft2.AddWire(bottompolygon2.Wire());
769   loft2.AddWire(toppolygon2.Wire());
770   loft2.Build();
771   if (loft1.Shape().IsNull() || loft2.Shape().IsNull())
772     return 1;
773   DBRep::Set("TS1",loft1.Shape());
774   DBRep::Set("TS2",loft2.Shape());
775
776   di << "BRepAlgoAPI_Fuse result(loft1.Shape(), loft2.Shape())\n";
777   BRepAlgoAPI_Fuse result(loft1.Shape(), loft2.Shape());
778   DBRep::Set("F", result.Shape());
779
780   return 0;
781 }
782
783 #include <Geom_RectangularTrimmedSurface.hxx>
784 #include <GC_MakeTrimmedCone.hxx>
785
786 static Standard_Integer BUC60856(Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv )
787 {
788   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
789   if(aContext.IsNull()) { 
790     di << "use 'vinit' command before " << argv[0] << "\n";
791     return -1;
792   }
793
794   gp_Ax2  Cone_Ax;                                                                
795   double R1=8, R2=16;
796   gp_Pnt P0(0,0,0),                                                              
797   P1(0,0,20), P2(0,0,45);                                                        
798   Handle(Geom_RectangularTrimmedSurface) S = GC_MakeTrimmedCone (P1, P2, R1, R2).Value();
799   TopoDS_Shape myshape = BRepBuilderAPI_MakeFace(S, Precision::Confusion()).Shape();
800   Handle(AIS_Shape) ais1 = new AIS_Shape(myshape);
801   aContext->Display (ais1, Standard_False);
802   aContext->SetColor (ais1, Quantity_NOC_BLUE1, Standard_False);
803   
804   Handle(Geom_RectangularTrimmedSurface) S2 = GC_MakeTrimmedCone (P1, P2,R1, 0).Value();
805   TopoDS_Shape myshape2 = BRepBuilderAPI_MakeFace(S2, Precision::Confusion()).Shape();
806   Handle(AIS_Shape) ais2 = new AIS_Shape(myshape2);
807   aContext->Display (ais2, Standard_False);
808   aContext->SetColor (ais2, Quantity_NOC_RED, Standard_False);
809   return 0;
810 }
811
812 //==========================================================================
813 //function : CoordLoad
814 //           chargement d une face dans l explorer.
815 //==========================================================================
816 static Standard_Integer coordload (Draw_Interpretor& theDi,
817                                    Standard_Integer  theArgsNb,
818                                    const char**      theArgVec)
819
820   if (theArgsNb < 3)
821   {
822     return 1;
823   }
824
825   std::ifstream aFile (theArgVec[2], ios::in);
826   if (!aFile)
827   {
828     theDi << "unable to open " << theArgVec[2] << " for input\n";
829     return 2;
830   }
831
832   char aLine[80];
833   memset (aLine, 0, 40);
834   aFile.getline (aLine, 80);
835
836   gp_Pnt aPnt (0.0, 0.0, 0.0);
837   aLine[40] = '\0';
838   aPnt.SetY (Draw::Atof (&aLine[20]));
839   aLine[20] = '\0';
840   aPnt.SetX (Draw::Atof (aLine));
841   TopoDS_Vertex aVert1 = BRepBuilderAPI_MakeVertex (aPnt);
842   BRepBuilderAPI_MakeWire aMakeWire;
843   for (;;)
844   {
845     memset (aLine, 0, 40);
846     aFile.getline (aLine, 80);
847     if (!aFile)
848     {
849       break;
850     }
851
852     aLine[40] = '\0';
853     aPnt.SetY (Draw::Atof (&aLine[20]));
854     aLine[20] = '\0';
855     aPnt.SetX (Draw::Atof (aLine));
856     TopoDS_Vertex aVert2 = BRepBuilderAPI_MakeVertex (aPnt);
857     aMakeWire.Add (BRepBuilderAPI_MakeEdge (aVert1, aVert2));
858     aVert1 = aVert2;
859   }
860   aFile.close();
861
862   if (!aMakeWire.IsDone())
863   {
864     DBRep::Set (theArgVec[1], TopoDS_Face());
865     return 0;
866   }
867
868   BRepBuilderAPI_MakeFace aMakeFace (aMakeWire.Wire());
869   DBRep::Set (theArgVec[1], aMakeFace.IsDone() ? aMakeFace.Face() : TopoDS_Face());
870   return 0;
871 }
872
873 static Standard_Integer TestMem (Draw_Interpretor& /*di*/,
874                                  Standard_Integer /*nb*/, 
875                                  const char ** /*arg*/) 
876 {
877   TCollection_ExtendedString aString(1024*1024, 'A');
878   return 0;
879 }
880
881 static Standard_Integer BUC60876_ (Draw_Interpretor& di,
882                                  Standard_Integer argc, 
883                                  const char ** argv) 
884 {
885   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
886   if(aContext.IsNull()) { 
887     di << "use 'vinit' command before " << argv[0] << "\n";
888     return -1;
889   }     
890   if((argc != 2) && (argc != 3)) {
891     di<< "usage : " << argv[0] << " shape [mode==1]\n";
892     return -1;
893   }
894   TopoDS_Shape aShape = DBRep::Get(argv[1]);
895   Handle(AIS_InteractiveObject) anIO = new AIS_Shape(aShape);
896 //  Handle(AIS_InteractiveObject) anIOa = ViewerTest::GetAISShapeFromName(argv[1]);
897   anIO->SetHilightMode((argc == 3) ? Draw::Atoi(argv[2]) : 1);
898   aContext->Display (anIO, Standard_True);
899   return 0;
900 }
901
902 //=======================================================================
903 //function : buc60773
904 //purpose  : 
905 //=======================================================================
906
907 #include<TCollection_HAsciiString.hxx>
908
909 static Standard_Integer BUC60773 (Draw_Interpretor& /*di*/, Standard_Integer /*n*/, const char ** /*a*/)
910 {
911   Handle(TCollection_HAsciiString) hAscii = new TCollection_HAsciiString();
912   Standard_CString aStr = hAscii->ToCString();
913   TCollection_AsciiString aAscii(aStr);  
914   
915   return 0;
916 }
917
918 #include<BRepPrimAPI_MakeCylinder.hxx>
919 #include<BRepPrimAPI_MakeCone.hxx>
920
921 static int TestCMD(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
922
923 {
924   if(argc != 1) {
925     di << "Usage : " << argv[0] << "\n";
926     return 1;
927   }
928
929   //Cylindre 36.085182 20.0 8.431413 88.04671 20.0 38.931416 10.0
930
931   Standard_Real x11 = 36.085182;
932   Standard_Real y11 = 20.0;
933   Standard_Real z11 = 8.431413;
934   Standard_Real x12 = 88.04671;
935   Standard_Real y12 = 20.0;
936   Standard_Real z12 = 38.931416;
937   Standard_Real radius = 10.0;
938
939   gp_Pnt base1(x11, y11, z11);
940   gp_Dir vect1(x12-x11, y12-y11, z12-z11);
941   gp_Ax2 axis1(base1, vect1);
942   Standard_Real height1 = sqrt( ((x12-x11)*(x12-x11)) + ((y12-y11)*(y12-y11)) + ((z12-z11)*(z12-z11)) );
943   BRepPrimAPI_MakeCylinder cylinder(axis1, radius, height1);
944
945   TopoDS_Shape SCyl = cylinder.Shape();
946   DBRep::Set("cyl", SCyl);
947
948    
949   //Cone 70.7262 20.0 28.431412 105.36722 20.0 48.431416 6.0 3.0
950   Standard_Real x21 = 70.7262;
951   Standard_Real y21 = 20.0;
952   Standard_Real z21 = 28.431412;
953   Standard_Real x22 = 105.36722;
954   Standard_Real y22 = 20.0;
955   Standard_Real z22 = 48.431416;
956   Standard_Real radius1 = 6.0;
957   Standard_Real radius2 = 3.0;
958
959   gp_Pnt base2(x21, y21, z21);
960   gp_Dir vect2(x22-x21, y22-y21, z22-z21);
961   gp_Ax2 axis2(base2, vect2);
962   Standard_Real height2 = sqrt( ((x22-x21)*(x22-x21)) + ((y22-y21)*(y22-y21)) + ((z22-z21)*(z22-z21)) );
963   BRepPrimAPI_MakeCone cone(axis2, radius1, radius2, height2);
964
965   TopoDS_Shape SCon = cone.Shape();
966   DBRep::Set("con", SCon);
967
968   di << "BRepAlgoAPI_Fuse SFuse(SCyl, SCon)\n";
969   BRepAlgoAPI_Fuse SFuse(SCyl, SCon);
970   if (!SFuse.IsDone()) {
971     di << "Error: Boolean fuse operation failed !\n";
972   }
973   else {
974     const TopoDS_Shape& fuse = SFuse.Shape();
975     DBRep::Set("fus", fuse);
976   }
977   return 0;
978 }
979
980 #include <NCollection_DataMap.hxx>
981 #include <TColStd_HSequenceOfAsciiString.hxx>
982 #include <TopExp.hxx>
983 #include <TopoDS_Iterator.hxx>
984
985 //---------------------------------------------------------------------------------------
986
987 static Standard_Integer statface (Draw_Interpretor& di,Standard_Integer /*argc*/, const char ** argv )
988
989 {  
990   TopoDS_Shape aShape = DBRep::Get(argv[1]);
991   if(aShape.IsNull())
992   {
993     di<<"Invalid input shape\n";
994     return 1;
995   }
996   NCollection_DataMap<TCollection_AsciiString, Standard_Integer> aMap;
997   Handle(TColStd_HSequenceOfAsciiString) aSequence = new TColStd_HSequenceOfAsciiString;
998   Standard_CString aString;
999   Standard_Integer l=0;
1000   TopExp_Explorer expl;
1001   Standard_Real f3d,l3d;
1002   for(expl.Init(aShape,TopAbs_FACE);expl.More();expl.Next())
1003   {
1004     // SURFACES
1005     TopoDS_Face aFace = TopoDS::Face (expl.Current());
1006     Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace);
1007     aString = aSurface->DynamicType()->Name();
1008
1009     if (aMap.IsBound(aString))
1010       aMap.ChangeFind(aString)++;
1011     else {
1012       aMap.Bind(aString, 1);
1013       aSequence->Append(aString);
1014     }
1015   }
1016   // PCURVES
1017   for(expl.Init(aShape,TopAbs_FACE);expl.More();expl.Next())
1018   {
1019     TopoDS_Face aFace = TopoDS::Face (expl.Current());
1020     TopoDS_Iterator anIt(aFace);
1021     TopoDS_Wire aWire = TopoDS::Wire (anIt.Value());
1022     TopoDS_Iterator it (aWire); 
1023     for (; it.More(); it.Next()) {
1024       TopoDS_Edge Edge = TopoDS::Edge (it.Value());
1025       Handle(Geom2d_Curve) aCurve2d = BRep_Tool::CurveOnSurface(Edge,aFace,f3d,l3d);
1026       aString = aCurve2d->DynamicType()->Name();
1027       if(aMap.IsBound(aString))
1028         aMap.ChangeFind(aString)++;
1029       else  {
1030         aMap.Bind(aString, 1);
1031         aSequence->Append(aString);
1032       }
1033     }
1034   }
1035   // 3d CURVES
1036   TopExp_Explorer exp;
1037   for (exp.Init(aShape,TopAbs_EDGE); exp.More(); exp.Next()) 
1038   {
1039     TopoDS_Edge Edge = TopoDS::Edge (exp.Current());
1040     Handle(Geom_Curve) aCurve3d = BRep_Tool::Curve (Edge,f3d,l3d);
1041     if(aCurve3d.IsNull())
1042     {
1043       l++;
1044     } else {
1045       aString = aCurve3d->DynamicType()->Name();
1046       if (aMap.IsBound(aString))
1047       {
1048         aMap.ChangeFind(aString)++;
1049       } else {
1050         aMap.Bind(aString, 1);
1051         aSequence->Append(aString);
1052       }
1053     }
1054   }
1055   // Output 
1056   di<<"\n";
1057
1058   for (Standard_Integer i = 1; i <= aSequence->Length(); i++) {
1059     di << aMap.Find(aSequence->Value(i)) << "   --   " << aSequence->Value(i).ToCString() << "\n";
1060   }
1061
1062   di<<"\n";
1063   di<<"Degenerated edges :\n";
1064   di<<l<<"   --    Degenerated edges \n";
1065
1066   return 0;
1067
1068 }
1069
1070 #include <BRepBuilderAPI_Transform.hxx>
1071
1072 static Standard_Integer BUC60841(Draw_Interpretor& di, Standard_Integer argc, const char ** argv )
1073 {
1074   if(argc != 1) {
1075     di << "Usage : " << argv[0] << "\n";
1076     return 1;
1077   }
1078
1079   gp_Ax2 Ax2 = gp_Ax2(gp_Pnt(0, 621, 78), gp_Dir(0, 1,0));
1080   BRepPrimAPI_MakeCylinder cyl(Ax2, 260, 150);
1081   //BRepPrimAPI_MakeCylinder cyl(gp_Ax2(gp_Pnt(0, 621, 78), gp_Dir(0, 1,0)), 260, 150);
1082
1083   TopoDS_Shape sh1 = cyl.Shape();
1084   DBRep::Set("sh1",sh1);
1085   gp_Trsf trsf1, trsf2;
1086   trsf1.SetTranslation(gp_Pnt(0.000000,700.000000,-170.000000),
1087                        gp_Pnt(0.000000,700.000000,-95.000000));
1088   trsf2.SetRotation(gp_Ax1(gp_Pnt(0.000000,700.000000,-170.000000),
1089                            gp_Dir(0.000000,0.000000,1.000000)), 0.436111);
1090   BRepBuilderAPI_Transform trans1(sh1, trsf1);
1091   TopoDS_Shape sh2 = trans1.Shape();
1092   DBRep::Set("sh2",sh2);
1093
1094   di << "BRepAlgoAPI_Fuse fuse1(sh1, sh2)\n";
1095   BRepAlgoAPI_Fuse fuse1(sh1, sh2);
1096   TopoDS_Shape fsh1 = fuse1.Shape();
1097   DBRep::Set("fsh1",fsh1);
1098
1099   BRepBuilderAPI_Transform trans2(fsh1, trsf2);
1100   TopoDS_Shape sh3 = trans2.Shape();
1101   DBRep::Set("sh3",sh3);
1102
1103   di << "BRepAlgoAPI_Fuse fuse2(fsh1,sh3)\n";
1104   BRepAlgoAPI_Fuse fuse2(fsh1, sh3);
1105   const TopoDS_Shape& fsh2 = fuse2.Shape();
1106   DBRep::Set("fsh2",fsh2);
1107
1108   Handle(AIS_Shape) aisp1 = new AIS_Shape(fsh2);
1109   return 0;
1110 }
1111
1112 #include <ShapeBuild_Edge.hxx>
1113
1114 static Standard_Integer BUC60874(Draw_Interpretor& /*di*/, Standard_Integer /*argc*/, const char ** argv )
1115 {
1116   TopoDS_Edge e = TopoDS::Edge(DBRep::Get(argv[1],TopAbs_EDGE));
1117   ShapeBuild_Edge().BuildCurve3d(e);
1118   DBRep::Set("ED",e);
1119   return 0;
1120 }
1121
1122
1123 #include<TDF_Label.hxx>
1124 #include<TDataStd_TreeNode.hxx>
1125
1126 #include<DDocStd.hxx>
1127
1128 #include<DDF.hxx>
1129
1130 #include<TDocStd_Modified.hxx>
1131 #include<TDF_ListIteratorOfDeltaList.hxx>
1132 #include<TDocStd_Document.hxx>
1133 #include<TDocStd_Application.hxx>
1134 #include<TDF_Delta.hxx>
1135 #include<TDataXtd_Constraint.hxx>
1136 #include<TPrsStd_AISPresentation.hxx>
1137 #include<TPrsStd_AISViewer.hxx>
1138 #include<TNaming_Builder.hxx>
1139 #include<TNaming_Naming.hxx>
1140 #include<TNaming_NamedShape.hxx>
1141   
1142 static int BUC60817(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) {
1143   if(argc!=2) {
1144     di << "Usage : " << argv[0] << " D\n";
1145     di<<1;
1146     return 0;
1147   }
1148
1149   Handle(TDF_Data) DF;
1150   if (!DDF::GetDF(argv[1],DF)) {di<<2;return 0;}
1151   
1152   TDF_Label L1,L2;
1153   Handle(TDataStd_TreeNode) TN1,TN2;
1154
1155   DDF::AddLabel(DF,"0:2",L1);
1156   TN1 = TDataStd_TreeNode::Set(L1);
1157
1158   DDF::AddLabel(DF,"0:3",L2);
1159   TN2 = TDataStd_TreeNode::Set(L2);
1160
1161   TN1->Append(TN2);
1162   if(!(TN2->IsDescendant(TN1))) {di<<3;return 0;}
1163   if((TN1->IsDescendant(TN2))) {di<<4;return 0;}
1164
1165   di<<0;
1166   return 0;
1167 }
1168
1169 static int BUC60831_1(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) {
1170   if(argc!=2) {
1171     di << "Usage : " << argv[0] << " D\n";
1172     di<<-1;
1173     return 0;
1174   }
1175
1176   Handle(TDF_Data) DF;
1177   if (!DDF::GetDF(argv[1],DF)) {di<<-2;return 0;}
1178   
1179   TDF_Label L;
1180   DDF::FindLabel(DF,"0:1",L,Standard_False);
1181   Handle(TDocStd_Modified) MDF;
1182   if (!L.Root().FindAttribute (TDocStd_Modified::GetID(), MDF)) {
1183     MDF = new TDocStd_Modified();
1184     L.Root().AddAttribute(MDF);
1185   }
1186
1187   di<<!MDF->IsEmpty();
1188   return 0;
1189 }
1190
1191 static int BUC60831_2(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) {
1192   if(argc!=3) {
1193     di << "Usage : " << argv[0] << " D Label\n";
1194     di<<1;
1195     return 0;
1196   }
1197
1198   Handle(TDF_Data) DF;
1199   if (!DDF::GetDF(argv[1],DF)) {di<<2;return 0;}
1200   
1201   TDF_Label L;
1202   DDF::FindLabel(DF,argv[2],L,Standard_False);
1203
1204   TDocStd_Modified::Add(L);
1205   
1206   di<<0;
1207   return 0;
1208 }
1209
1210 static int BUC60836(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) {
1211   if(argc!=2) {
1212     di << "Usage : " << argv[0] << " D\n";
1213     di<<1;
1214     return 0;
1215   }
1216
1217
1218   Handle(TDF_Data) aDF;
1219   if (!DDF::GetDF(argv[1],aDF)) {di<<2;return 0;}
1220
1221   Handle(TDocStd_Document) aDocument;
1222   if (!DDocStd::GetDocument(argv[1], aDocument)) {di<<3;return 0;}
1223    
1224   TDF_Label L;
1225   Handle(TDataStd_TreeNode) TN;
1226
1227   aDocument->NewCommand();
1228   DDF::AddLabel(aDF,"0:2",L);
1229   TN = TDataStd_TreeNode::Set(L);
1230
1231   aDocument->NewCommand();
1232   DDF::AddLabel(aDF,"0:3",L);
1233   TN = TDataStd_TreeNode::Set(L);
1234
1235   aDocument->NewCommand();
1236   DDF::AddLabel(aDF,"0:4",L);
1237   TN = TDataStd_TreeNode::Set(L);
1238   aDocument->NewCommand();
1239
1240   TDF_DeltaList Us,Rs;
1241   Us = aDocument->GetUndos();
1242   Rs = aDocument->GetUndos();
1243
1244   Standard_Integer i;
1245   char Names[10][5]={"n1","n2","n3","n4","n5","n6","n7","n8","n9","n10"};  
1246
1247   TDF_ListIteratorOfDeltaList IDL;
1248   for(IDL.Initialize(Us),i=1;IDL.More();IDL.Next(),i++){
1249     Handle(TDF_Delta) D = IDL.Value();
1250     TCollection_ExtendedString S(Names[i-1]);
1251     D->SetName(S);
1252 //    cout<<" U"<<i<<"="<<D->Name()<<endl;
1253   }
1254   
1255   aDocument->Undo();
1256   aDocument->Undo();
1257   
1258   Us = aDocument->GetUndos();
1259   Rs = aDocument->GetRedos();
1260
1261   for(IDL.Initialize(Us),i=1;IDL.More();IDL.Next(),i++){
1262     Handle(TDF_Delta) D = IDL.Value();
1263 //    cout<<" U"<<i<<"="<<D->Name()<<endl;
1264   }
1265
1266   TCollection_ExtendedString n2name ("n2");
1267   for(IDL.Initialize(Rs),i=1;IDL.More();IDL.Next(),i++){
1268     Handle(TDF_Delta) D = IDL.Value();
1269     if ( i == 1 && ! D->Name().IsEqual (n2name) ) 
1270     {
1271       di << 4;
1272       return 0;
1273    }
1274   }
1275
1276   di<<0;
1277   return 0;
1278 }
1279
1280 static int BUC60847(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) {
1281   if(argc!=3) {
1282     di << "Usage : " << argv[0] << " D Shape\n";
1283     di<<1;
1284     return 0;
1285   }
1286
1287   Handle(TDF_Data) aDF;
1288   if (!DDF::GetDF(argv[1],aDF)) {di<<2;return 0;}
1289   
1290   TopoDS_Shape s = DBRep::Get(argv[2]);
1291   if (s.IsNull()) { di <<"shape not found\n"; di<<3;return 0;}
1292   TDF_Label L;
1293   DDF::AddLabel(aDF, "0:2", L);
1294   TNaming_Builder SI (L);
1295   SI.Generated(s);
1296
1297   Handle(TNaming_NamedShape) NS = new TNaming_NamedShape;
1298
1299   TNaming_Naming aNN;
1300   NS=aNN.Name(L,s,s);
1301 //  if (!NS->IsEmpty()) {di<<3;return 0;}
1302   if (NS->IsEmpty()) {di<<4;return 0;}
1303   di<<0;
1304   return 0;
1305 }
1306
1307 static int BUC60862(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) {
1308   if(argc!=3) {
1309     di << "Usage : " << argv[0] << " D Shape\n";
1310     di<<1;
1311     return 0;
1312   }
1313
1314   Handle(TDF_Data) aDF;
1315   if (!DDF::GetDF(argv[1],aDF)) {di<<2;return 0;}
1316   
1317   TopoDS_Shape s = DBRep::Get(argv[2]);
1318   if (s.IsNull()) { di <<"shape not found\n"; di<<3;return 0;}
1319   TDF_Label L;
1320   DDF::AddLabel(aDF, "0:2", L);
1321   TNaming_Builder SI (L);
1322   SI.Generated(s);
1323
1324   Handle(TNaming_NamedShape) NS = new TNaming_NamedShape;
1325
1326   TNaming_Naming aNN;
1327   NS=aNN.Name(L,s,s);
1328   if (NS->IsEmpty()) {di<<4;return 0;}
1329   di<<0;
1330   return 0;
1331 }
1332
1333 static int BUC60867(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) {
1334   if (argc == 2) {
1335     TCollection_ExtendedString path (argv[1]); 
1336     Handle(TDocStd_Application) A = DDocStd::GetApplication();
1337     Handle(TDocStd_Document) D;
1338     Standard_Integer insession = A->IsInSession(path);
1339     if (insession > 0) {  
1340       di <<"document " << insession << "  is already in session\n";
1341       di<<2;
1342       return 0;
1343     }
1344     PCDM_ReaderStatus Result = A->Open(path,D);
1345     if(Result==PCDM_RS_OK){
1346       di<<0;
1347       return 0; 
1348     }
1349   }
1350   di<<3;
1351   return 0;
1352 }
1353
1354 static int BUC60910(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) {
1355   if(argc!=2) {
1356     di << "Usage : " << argv[0] << " D\n";
1357     di<<1;
1358     return 0;
1359   }
1360
1361   Handle(TDF_Data) aDF;
1362   if (!DDF::GetDF(argv[1],aDF)) {di<<2;return 0;}
1363   
1364   TDF_Label L;
1365   DDF::AddLabel(aDF, "0:2", L);
1366  
1367   Handle(TPrsStd_AISPresentation) AISP = 
1368     TPrsStd_AISPresentation::Set(L,TDataXtd_Constraint::GetID());
1369
1370   if (AISP->HasOwnMode()) {di<<3;return 0;}
1371   AISP->SetMode(3);
1372   Standard_Integer Mode = AISP->Mode();
1373   if (Mode!=3) {di<<4;return 0;}
1374   if (!AISP->HasOwnMode()) {di<<5;return 0;}
1375   AISP->UnsetMode();
1376   if (AISP->HasOwnMode()) {di<<6;return 0;}
1377   di<<0;
1378   return 0;
1379 }
1380
1381 static int BUC60925(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) {
1382   if(argc!=2) {
1383     di << "Usage : " << argv[0] << " D\n";
1384     di<<1;
1385     return 0;
1386   }
1387
1388   Handle(TDF_Data) aDF;
1389   if (!DDF::GetDF(argv[1],aDF)) {di<<2;return 0;}
1390   
1391   TDF_Label L;
1392   DDF::AddLabel(aDF, "0:2", L);
1393   TDF_LabelMap LM;
1394   LM.Add(L);
1395   
1396   Handle(TNaming_NamedShape) NS = new TNaming_NamedShape;
1397 //  Handle(TNaming_Name) NN = new TNaming_Name;
1398   TNaming_Name NN;
1399
1400   NN.Type(TNaming_IDENTITY);
1401   NN.Append(NS);
1402   Standard_Boolean Res = NN.Solve(L,LM);
1403   
1404   if (Res!=Standard_False) {di<<3;return 0;}
1405   di<<0;
1406   return 0;
1407 }
1408
1409 static int BUC60932(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) {
1410   if(argc!=2) {
1411     di << "Usage : " << argv[0] << " D\n";
1412     di<<1;
1413     return 0;
1414   }
1415
1416
1417   Handle(TDocStd_Document) aDocument;
1418   if (!DDocStd::GetDocument(argv[1], aDocument)) {di<<2;return 0;}
1419    
1420   if(!aDocument->InitDeltaCompaction()) {di<<3;return 0;}
1421   if(!aDocument->PerformDeltaCompaction()) {di<<4;return 0;}
1422
1423   di<<0;
1424   return 0;
1425 }
1426
1427 //=======================================================================
1428 //function : AISWidth
1429 //purpose  : AISWidth (DOC,entry,[width])
1430 // abv: testing command for checking bug BUC60917 in TPrsStd_AISPresentation
1431 //=======================================================================
1432
1433 static int AISWidth(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) {
1434
1435   if (argc >= 3) {     
1436     Handle(TDocStd_Document) D;
1437     if (!DDocStd::GetDocument(argv[1],D)) {di<<(-1);return 0;}
1438     TDF_Label L;
1439     if (!DDF::FindLabel(D->GetData(),argv[2],L)) {di<<(-2);return 0;}
1440
1441     Handle(TPrsStd_AISViewer) viewer;
1442     if( !TPrsStd_AISViewer::Find(L, viewer) ) {di<<(-3);return 0;}
1443
1444     Handle(TPrsStd_AISPresentation) prs;
1445     if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {   
1446       if( argc == 4 ) {
1447         prs->SetWidth(Draw::Atof(argv[3]));
1448         TPrsStd_AISViewer::Update(L);
1449       }
1450       else {
1451        if (prs->HasOwnWidth()){ 
1452 //         cout << "Width = " << prs->Width() << endl;
1453          di<<prs->Width();
1454        }
1455        else{
1456          di << "AISWidth: Warning : Width wasn't set\n";
1457          di<<(-4);
1458        }
1459       }
1460       return 0;
1461     }
1462   }
1463   di << "AISWidth : Error"   << "\n";
1464   di<<(-5);
1465   return 0;
1466 }
1467
1468 //=======================================================================
1469 //function : BUC60921 ( & BUC60954 )
1470 //purpose  : Test memory allocation of OCAF in Undo/Redo operations
1471 //=======================================================================
1472
1473 static Standard_Integer BUC60921 (Draw_Interpretor& di,
1474                                   Standard_Integer nb, 
1475                                   const char ** arg) 
1476 {
1477   if (nb >= 4) {     
1478     Handle(TDocStd_Document) D;
1479     if (!DDocStd::GetDocument(arg[1],D)) {di<<1;return 0;}
1480     TDF_Label L;
1481     DDF::AddLabel(D->GetData(),arg[2],L);
1482
1483     BRep_Builder B;
1484     TopoDS_Shape S;
1485     BRepTools::Read ( S, arg[3], B );
1486     
1487     TNaming_Builder tnBuild(L);
1488     tnBuild.Generated(S);
1489 //    di << "File " << arg[3] << " added";
1490     di<<0;
1491     return 0;
1492   }
1493   di << "BUC60921 Doc label brep_file: directly read brep file and put shape to the label"   << "\n";
1494   di<<2;
1495   return 0;
1496 }
1497
1498 #include<IGESControl_Reader.hxx>
1499 #include<BRepPrimAPI_MakeHalfSpace.hxx>
1500
1501 static Standard_Integer BUC60951_(Draw_Interpretor& di, Standard_Integer argc, const char ** a)
1502 {
1503   if (argc != 2) {
1504     di << "Usage : " << a[0] << " file.igs\n";
1505     return 1;
1506   }
1507
1508   Handle(AIS_InteractiveContext) myContext = ViewerTest::GetAISContext(); 
1509
1510   if(myContext.IsNull()) {
1511     di << "use 'vinit' command before " << a[0] << "\n";
1512     return -1;
1513   }
1514
1515 //  IGESControlStd_Reader reader;
1516   IGESControl_Reader reader;
1517   reader.ReadFile(a[1]);
1518   reader.TransferRoots();
1519   TopoDS_Shape shape = reader.OneShape();
1520   printf("\n iges1 shape type = %d", shape.ShapeType() );
1521   TopTools_IndexedMapOfShape list;
1522   TopExp::MapShapes(shape, TopAbs_FACE, list);
1523   printf("\n No. of faces = %d", list.Extent());
1524
1525   TopoDS_Shell shell;
1526   BRep_Builder builder;
1527   builder.MakeShell(shell);
1528   for(int i=1;i<=list.Extent(); i++) { 
1529     TopoDS_Face face = TopoDS::Face(list.FindKey(i));
1530     builder.Add(shell, face);
1531   }
1532   shell.Closed (BRep_Tool::IsClosed (shell));
1533
1534   BRepPrimAPI_MakeHalfSpace half(shell, gp_Pnt(0, 0, 20));
1535   TopoDS_Solid sol = half.Solid();
1536   gp_Ax2 anAx2(gp_Pnt(-800.0, 0.0, 0), gp_Dir(0, 0, -1));
1537   BRepPrimAPI_MakeCylinder cyl(anAx2, 50, 300);
1538   TopoDS_Shape sh = cyl.Shape();
1539
1540   di << "BRepAlgoAPI_Fuse fuse(sol, sh)\n";
1541   BRepAlgoAPI_Fuse fuse(sol, sh);
1542   sh = fuse.Shape();
1543
1544   Handle(AIS_Shape) res = new AIS_Shape(sh);
1545   myContext->Display (res, Standard_True);
1546   return 0;
1547 }
1548
1549 void QABugs::Commands_3(Draw_Interpretor& theCommands) {
1550   const char *group = "QABugs";
1551
1552   theCommands.Add("BUC60623","BUC60623 result Shape1 Shape2",__FILE__,BUC60623,group);
1553   theCommands.Add("BUC60569","BUC60569 shape",__FILE__,BUC60569,group);
1554   theCommands.Add("BUC60614","BUC60614 shape",__FILE__,BUC60614,group);
1555   theCommands.Add("BUC60609","BUC60609 shape name [U V]",__FILE__,BUC60609,group);
1556   theCommands.Add("BUC60632","BUC60632 mode length",__FILE__,BUC60632,group);
1557   theCommands.Add("BUC60652","BUC60652 face",__FILE__,BUC60652,group);
1558   theCommands.Add("BUC60574","BUC60574 ",__FILE__,BUC60574,group);
1559
1560   theCommands.Add("GER61351","GER61351 name/object name/r g b/object r g b",__FILE__,setcolor,group);
1561   theCommands.Add("setcolor","setcolor name/object name/r g b/object r g b",__FILE__,setcolor,group);
1562
1563   theCommands.Add("BUC60729","BUC60729",__FILE__,BUC60729,group);
1564   theCommands.Add("BUC60724","BUC60724",__FILE__,BUC60724,group);
1565   theCommands.Add("BUC60727","BUC60727",__FILE__,BUC60727,group);
1566   theCommands.Add("BUC60792","BUC60792",__FILE__,BUC60792,group);
1567   theCommands.Add("BUC60811","BUC60811",__FILE__,BUC60811,group);
1568
1569   theCommands.Add("BUC60825","BUC60825",__FILE__,BUC60825,group);
1570
1571   theCommands.Add("OCC10006","OCC10006",__FILE__,OCC10006,group);
1572
1573   theCommands.Add("BUC60856","BUC60856",__FILE__,BUC60856,group);
1574
1575   theCommands.Add("coordload","load coord from file",__FILE__,coordload);
1576
1577   theCommands.Add("TestMem","TestMem",__FILE__,TestMem,group);
1578   theCommands.Add("BUC60945","BUC60945",__FILE__,TestMem,group);
1579   theCommands.Add("BUC60876","BUC60876 shape",__FILE__,BUC60876_,group); 
1580   theCommands.Add("BUC60773","BUC60773",__FILE__,BUC60773,group); 
1581
1582   theCommands.Add("TestCMD","TestCMD",__FILE__,TestCMD,group);
1583
1584   theCommands.Add("statface","statface face",__FILE__,statface,group);
1585
1586   theCommands.Add("BUC60841","BUC60841",__FILE__,BUC60841,group);
1587
1588   theCommands.Add("BUC60874","BUC60874",__FILE__,BUC60874,group);
1589
1590   theCommands.Add("BUC60817","BUC60817 D",__FILE__,BUC60817,group);
1591   theCommands.Add("BUC60831_1","BUC60831_1 D",__FILE__,BUC60831_1,group);
1592   theCommands.Add("BUC60831_2","BUC60831_2 D Label",__FILE__,BUC60831_2,group);
1593   theCommands.Add("BUC60836","BUC60836 D",__FILE__,BUC60836,group);
1594   theCommands.Add("BUC60847","BUC60847 D Shape",__FILE__,BUC60847,group);
1595   theCommands.Add("BUC60862","BUC60862 D Shape",__FILE__,BUC60862,group);
1596   theCommands.Add("BUC60867","BUC60867",__FILE__,BUC60867,group);
1597   theCommands.Add("BUC60910","BUC60910 D",__FILE__,BUC60910,group);
1598   theCommands.Add("BUC60925","BUC60925 D",__FILE__,BUC60925,group);
1599   theCommands.Add("BUC60932","BUC60932 D",__FILE__,BUC60932,group);
1600   theCommands.Add("AISWidth","AISWidth (DOC,entry,[width])",__FILE__,AISWidth,group);
1601   theCommands.Add("BUC60921","BUC60921 Doc label brep_file",__FILE__,BUC60921,group);
1602
1603   theCommands.Add("BUC60951","BUC60951 file.igs",__FILE__,BUC60951_, group );
1604
1605 }