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