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