983cc5a45f57457937b9b17004e199f7dbf165ac
[occt.git] / src / QABugs / QABugs_11.cxx
1 // Created on: 2002-03-20
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 <stdio.h>
17
18 #include <QABugs.hxx>
19
20 #include <Draw.hxx>
21 #include <Draw_Interpretor.hxx>
22 #include <DBRep.hxx>
23 #include <DrawTrSurf.hxx>
24 #include <AIS_InteractiveContext.hxx>
25 #include <ViewerTest.hxx>
26 #include <AIS_Shape.hxx>
27 #include <TopoDS_Shape.hxx>
28
29 #include <Geom_Surface.hxx>
30 #include <Geom_Axis2Placement.hxx>
31 #include <gp.hxx>
32 #include <gp_Trsf.hxx>
33 #include <AIS_Trihedron.hxx>
34 #include <BRepPrimAPI_MakeBox.hxx>
35 #include <Graphic3d_MaterialAspect.hxx>
36 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
37 #include <TopoDS_Solid.hxx>
38 #include <BRepPrimAPI_MakeSphere.hxx>
39 #include <BRepPrimAPI_MakeCone.hxx>
40 #include <BRepPrimAPI_MakeCylinder.hxx>
41 #include <IGESToBRep_Reader.hxx>
42 #include <TopExp_Explorer.hxx>
43 #include <TopoDS.hxx>
44 #include <GCPnts_UniformDeflection.hxx>
45 #include <BRepAdaptor_Curve.hxx>
46 #include <IGESToBRep.hxx>
47 #include <V3d_Viewer.hxx>
48 #include <BRepAdaptor_CompCurve.hxx>
49 #include <GCPnts_AbscissaPoint.hxx>
50 #include <Standard_ErrorHandler.hxx>
51 #include <Standard_Overflow.hxx>
52 #include <Standard_Underflow.hxx>
53 #include <Standard_DivideByZero.hxx>
54 #include <OSD_SIGSEGV.hxx>
55 #include <OSD_Exception_ACCESS_VIOLATION.hxx>
56 #include <OSD_Exception_STACK_OVERFLOW.hxx>
57 #include <OSD.hxx>
58 #include <OSD_ThreadPool.hxx>
59 #include <STEPCAFControl_Writer.hxx>
60 #include <STEPControl_StepModelType.hxx>
61 #include <Interface_Static.hxx>
62 #include <IFSelect_ReturnStatus.hxx>
63 #include <Standard_Failure.hxx>
64 #include <TColgp_HArray1OfPnt2d.hxx>
65 #include <Geom2dAPI_Interpolate.hxx>
66 #include <Geom2d_BSplineCurve.hxx>
67 #include <Geom2dConvert_BSplineCurveToBezierCurve.hxx>
68 #include <Geom2d_BezierCurve.hxx>
69 #include <BRep_Tool.hxx>
70 #include <GeomProjLib.hxx>
71 #include <Geom2dAPI_InterCurveCurve.hxx>
72 #include <IntRes2d_IntersectionSegment.hxx>
73 #include <TDataStd_RealArray.hxx>
74 #include <TDF_CopyLabel.hxx>
75 #include <NCollection_Vector.hxx>
76 #include <TColStd_Array1OfInteger.hxx>
77 #include <Geom_BSplineCurve.hxx>
78 #include <TColgp_Array1OfPnt.hxx>
79 #include <AIS_ColorScale.hxx>
80 #include <AIS_ListOfInteractive.hxx>
81 #include <AIS_ListIteratorOfListOfInteractive.hxx>
82 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
83 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
84 #include <BRepBuilderAPI_MakePolygon.hxx>
85 #include <gp_GTrsf.hxx>
86 #include <Poly_Triangulation.hxx>
87 #include <IGESControl_Reader.hxx>
88 #include <IGESData_IGESModel.hxx>
89 #include <IGESData_IGESEntity.hxx>
90 #include <V3d_View.hxx>
91 #include <BRepFeat_SplitShape.hxx>
92 #include <BRepAlgoAPI_Section.hxx>
93 #include <TColStd_PackedMapOfInteger.hxx>
94
95 #if ! defined(_WIN32)
96 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
97 #else
98 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
99 #endif
100
101 static Standard_Integer  OCC128 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv)
102 {
103   Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
104   if(myAISContext.IsNull()) {
105     di << "use 'vinit' command before " << argv[0] ;
106     return 1;
107   }
108
109   Handle(Geom_Axis2Placement) aTrihedronAxis = new Geom_Axis2Placement(gp::XOY());
110
111   gp_Trsf trsf1;
112   trsf1.SetTranslation(gp_Vec(100, 100, 0));
113   aTrihedronAxis->Transform(trsf1);
114   Handle(AIS_Trihedron) myTrihedron = new AIS_Trihedron(aTrihedronAxis);
115   myTrihedron->SetColor(Quantity_NOC_LIGHTSTEELBLUE4);
116   myTrihedron->SetSize(100);
117   myAISContext->Display(myTrihedron, Standard_True);
118
119 //  TopoDS_Shape shape1 = (TopoDS_Shape) BRepPrimAPI_MakeBox(50,50,50);
120   TopoDS_Shape shape1 = BRepPrimAPI_MakeBox(50,50,50).Shape();
121   Handle(AIS_Shape) AS = new AIS_Shape(shape1);
122   AS->SetDisplayMode(1);
123   Graphic3d_MaterialAspect mat(Graphic3d_NOM_PLASTIC);
124   AS->SetMaterial(mat);
125   AS->SetColor(Quantity_NOC_RED);
126   myAISContext->Display (AS, Standard_False);
127
128   gp_Trsf TouchTrsf;
129   TouchTrsf.SetTranslation(gp_Vec(20, 20, 0));
130
131   myAISContext->ResetLocation(AS);
132   myAISContext->SetLocation(AS , TouchTrsf) ;
133   myAISContext->Redisplay(AS, Standard_True);
134
135  return 0;
136 }
137
138   // Remove as bad version of QAAddOrRemoveSelected from QADraw
139 //static Standard_Integer OCC129 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
140 //{
141 //  if( argc != 3) {
142 //    di<<"Usage : " << argv[0] << " shape islocal\n";
143 //    return 1;
144 //  }
145 //  //get AIS_Shape:
146 //  Handle(AIS_InteractiveContext) anAISCtx = ViewerTest::GetAISContext();
147 //
148 // //   ViewerTest_DoubleMapOfInteractiveAndName& aMap =
149 // //                          ViewerTest::GetDataMapOfAIS ();
150 //  ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
151 //
152 //  TCollection_AsciiString aName(argv[1]);
153 //  Handle(AIS_InteractiveObject) AISObj;
154 //
155 //  if(aMap.IsBound2(aName)) {
156 //    AISObj = aMap.Find2(aName);
157 //    if(AISObj.IsNull()){
158 //      di<<"No interactive object \n";
159 //      return 1;
160 //    }
161 //
162 //    Standard_Integer aNum = -1;
163 //
164 //    if(Draw::Atoi(argv[2])) {
165 //      aNum = anAISCtx->OpenLocalContext();
166 //    }
167 //
168 //    if(anAISCtx->HasOpenedContext()){
169 //      anAISCtx->InitSelected();
170 //      anAISCtx->AddOrRemoveSelected(AISObj);
171 //    }
172 //    else {
173 //      anAISCtx->InitCurrent();
174 //      anAISCtx->AddOrRemoveCurrentObject(AISObj);
175 //    }
176 //
177 //    if(aNum >= 0) {
178 // //      anAISCtx->CloseLocalContext(aNum);
179 //    }
180 //
181 //    return 0;
182 //  }
183 //  //select this shape:
184 //  else {
185 //    di<<"Use 'vdisplay' before";
186 //    return 1;
187 //  }
188 //}
189
190 static Standard_Integer OCC136 (Draw_Interpretor& di, Standard_Integer argc, const char ** /*argv*/)
191 {
192   if(argc > 1){
193     di<<"Usage: OCC136\n";
194     return 1;
195   }
196
197   //create some primitives:
198   // Two basic points:
199   Standard_Real Size=100;
200   gp_Pnt P0(0,0,0), P1(Size,Size,Size);
201   //box
202   TopoDS_Solid aBox = BRepPrimAPI_MakeBox(P0,P1);
203   //sphere
204   TopoDS_Solid aSphere = BRepPrimAPI_MakeSphere (Size*0.5);
205   //cone
206   gp_Ax2 anAx2(P1, gp_Dir(1,1,1));
207   TopoDS_Solid aCone = BRepPrimAPI_MakeCone(anAx2, Size*0.7, Size*0.3, Size);
208   //cylinder
209   anAx2.SetLocation(gp_Pnt(Size,0,0));
210   anAx2.SetDirection(gp_Dir(-1,-1,1));
211   TopoDS_Solid aCyl = BRepPrimAPI_MakeCylinder(anAx2, Size*0.5, Size);
212
213   Handle(AIS_InteractiveContext) anAISCtx = ViewerTest::GetAISContext();
214   if(anAISCtx.IsNull()){
215     di<<"Null interactive context. Use 'vinit' at first.\n";
216     return 1;
217   }
218
219   anAISCtx->EraseAll (Standard_False);
220
221   //load primitives to context
222   Handle(AIS_InteractiveObject) aSh1 = new AIS_Shape(aBox);
223   anAISCtx->Display (aSh1, Standard_False);
224
225   Handle(AIS_InteractiveObject) aSh2 = new AIS_Shape(aSphere);
226   anAISCtx->Display (aSh2, Standard_False);
227
228   Handle(AIS_InteractiveObject) aSh3 = new AIS_Shape(aCone);
229   anAISCtx->Display (aSh3, Standard_False);
230
231   Handle(AIS_InteractiveObject) aSh4 = new AIS_Shape(aCyl);
232   anAISCtx->Display (aSh4, Standard_False);
233
234   //set selected
235   anAISCtx->InitSelected();
236   anAISCtx->AddOrRemoveSelected (aSh1, Standard_False);
237   anAISCtx->AddOrRemoveSelected (aSh2, Standard_False);
238   anAISCtx->AddOrRemoveSelected (aSh3, Standard_False);
239   anAISCtx->AddOrRemoveSelected (aSh4, Standard_False);
240
241   //remove all this objects from context
242   anAISCtx->Remove (aSh1, Standard_False);
243   anAISCtx->Remove (aSh2, Standard_False);
244   anAISCtx->Remove (aSh3, Standard_False);
245   anAISCtx->Remove (aSh4, Standard_False);
246
247   anAISCtx->UpdateCurrentViewer();
248   return 0;
249 }
250
251 static int BUC60610(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) {
252   if(argc < 2){
253     printf("Usage: %s  iges_input [name]\n",argv[0]);
254     return(1);
255   }
256   Standard_Character *Ch = NULL;
257
258   if(argc > 2) {
259     Ch = new Standard_Character[strlen(argv[2])+3];
260   }
261   IGESToBRep_Reader IR;
262   IR.LoadFile (argv[1]);
263   IR.Clear();
264   IR.TransferRoots();
265   TopoDS_Shape aTopShape = IR.OneShape();
266   TopExp_Explorer ex(aTopShape, TopAbs_EDGE);
267   Standard_Integer i=0;
268   for( ; ex.More(); ex.Next()){
269     const TopoDS_Edge &E = TopoDS::Edge(ex.Current());
270     BRepAdaptor_Curve aCurve(E);
271     GCPnts_UniformDeflection plin(aCurve, 0.1);
272     di << "Num points = " << plin.NbPoints() << "\n";
273     if(argc > 2) {
274       i++;
275       Sprintf(Ch,"%s_%i",argv[2],1);
276       DBRep::Set(Ch,E);
277     }
278   }
279   return (1);
280 }
281
282 //====================================================
283 //
284 // Following code is inserted from
285 // /dn03/KAS/dev/QAopt/src/QADraw/QADraw_TOPOLOGY.cxx
286 // ( 75455 Apr 16 18:59)
287 //
288 //====================================================
289
290 //OCC105
291 #include <BRepTools_WireExplorer.hxx>
292 #include <BRep_Tool.hxx>
293 #include <GCPnts_UniformAbscissa.hxx>
294 #include <TopExp.hxx>
295
296 //
297 // usage : OCC105 shape
298 //
299 // comments:
300 //GCPnts_UniformAbscissa returns bad end point foe first edge. Its value is
301
302 //Value Pnt = -338.556216693211 -394.465571897208 0
303 //should be
304 //Value Pnt = -307.47165394 -340.18073533 0
305
306 static int OCC105(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
307 {
308   if (argc != 2){
309     di<<"Usage : OCC105 shape\n";
310     return 1;
311   }
312 //  TopoDS_Wire myTopoDSWire = TopoDS::Wire(DBRep::Get("aa.brep"));
313   TopoDS_Wire myTopoDSWire = TopoDS::Wire(DBRep::Get(argv[1]));
314   Standard_Real l = 0.5; //Draw::Atof(argv[2]);
315   // Find the first vertex of the wire
316   BRepTools_WireExplorer wire_exp(myTopoDSWire);
317   TopoDS_Vertex vlast;
318   {
319     TopoDS_Vertex vw1, vw2;
320     TopExp::Vertices(myTopoDSWire,vw1,vw2);
321     TopoDS_Vertex ve1, ve2;
322     TopoDS_Edge edge = TopoDS::Edge(wire_exp.Current());
323     TopExp::Vertices(edge,ve1,ve2);
324     if (vw1.IsSame(ve1) || vw1.IsSame(ve2))
325       vlast = vw1;
326     else {
327 //      assert(vw2.IsSame(ve1) || vw2.IsSame(ve2));
328       vlast = vw2;
329     }
330   }
331   for ( ; wire_exp.More(); wire_exp.Next())
332     {
333       di << "\n\n New Edge \n"   << "\n";
334       Standard_Real newufirst, newulast;
335       TopoDS_Edge edge = TopoDS::Edge(wire_exp.Current());
336       Standard_Real ufirst, ulast;
337       Handle(Geom_Curve) acurve;
338       TopoDS_Vertex ve1, ve2;
339       TopExp::Vertices(edge,ve1,ve2);
340       if (ve1.IsSame(vlast))
341         {
342           acurve = BRep_Tool::Curve(edge, ufirst, ulast);
343           newufirst = ufirst;
344           newulast  = ulast;
345           vlast = ve2;
346         }
347       else
348         {
349 //          assert(ve2.IsSame(vlast));
350 //          assert ( wire_exp.Orientation( ) == TopAbs_REVERSED );
351           acurve = BRep_Tool::Curve( edge, ufirst, ulast );
352           newufirst = acurve->ReversedParameter( ufirst );
353           newulast  = acurve->ReversedParameter( ulast );
354           acurve = acurve->Reversed( );
355           vlast = ve1;
356         }
357
358       GeomAdaptor_Curve   curve;
359       GCPnts_UniformAbscissa  algo;
360       curve.Load(acurve);
361       algo.Initialize( curve, l, newufirst, newulast );
362       if (!algo.IsDone())
363         di << "Not Done!!!"   << "\n";
364       for (Standard_Integer Index = 1; Index<=algo.NbPoints();Index++) {
365         Standard_Real t = algo.Parameter(Index);
366         gp_Pnt      pt3 = curve.Value(t);
367         di << "Parameter t = " << t   << "\n";
368         di << "Value Pnt = " << pt3.X()<<" " <<pt3.Y()<<" " << pt3.Z()  << "\n";
369       }
370     }
371   return 0;
372
373 }
374
375 #include <TColStd_SequenceOfTransient.hxx>
376 #include <GeomFill_Pipe.hxx>
377 static int pipe_OCC9 (Draw_Interpretor& di,
378                       Standard_Integer n, const char ** a)
379 {
380   if (n < 6) {
381     di << "Usage: " << a[0] << " result path cur1 cur2 radius [tolerance]\n";
382     return 1;
383   }
384
385   TColStd_SequenceOfTransient aCurveSeq;
386   Standard_Integer i;
387   for (i=2 ; i<=4; i++) {
388     Handle(Geom_Curve) aC = Handle(Geom_Curve)::DownCast( DrawTrSurf::Get(a[i]) );
389     if (aC.IsNull()) {
390       di << a[i] << " is not a curve\n";
391       return 1;
392     }
393     aCurveSeq.Append(aC);
394   }
395
396   GeomFill_Pipe aPipe(Handle(Geom_Curve)::DownCast( aCurveSeq(1) ),
397                       Handle(Geom_Curve)::DownCast( aCurveSeq(2) ),
398                       Handle(Geom_Curve)::DownCast( aCurveSeq(3) ),
399                       Draw::Atof (a[5]) );
400
401   if (n == 7) {
402     aPipe.Perform(Draw::Atof (a[6]), Standard_True);
403   } else {
404     aPipe.Perform(Standard_True/*, Standard_True*/);
405   }
406
407   if (!aPipe.IsDone()) {
408     di << "GeomFill_Pipe cannot make a surface\n";
409     return 1;
410   }
411
412   Handle(Geom_Surface) aSurf = aPipe.Surface();
413
414   DrawTrSurf::Set(a[1], aSurf);
415   return 0;
416 }
417
418 //======================================================================
419 // OCC125
420 // usage : OCC125 shell
421 //======================================================================
422 #include <ShapeFix_Shell.hxx>
423
424 Standard_Integer  OCC125(Draw_Interpretor& di ,
425                          Standard_Integer n,
426                          const char ** a)
427 {
428   if (n!=2) {
429     di<<" Use OCC125 shell";
430     return 1;
431   }
432
433   TopoDS_Shape S = DBRep::Get(a[1]);
434
435   if (S.IsNull()) {
436     di<<" Null shape is not allowed";
437     return 1;
438   }
439
440   TopAbs_ShapeEnum aT;
441   aT=S.ShapeType();
442   if (aT!=TopAbs_SHELL) {
443     di<<" Shape Type must be SHELL";
444     return 1;
445   }
446
447   const TopoDS_Shell& aShell = TopoDS::Shell(S);
448   //
449   Standard_Boolean isAccountMultiConex, bNonManifold, bResult;
450
451   isAccountMultiConex=Standard_True;
452   bNonManifold=Standard_False;
453
454   Handle (ShapeFix_Shell) aFix = new ShapeFix_Shell(aShell);
455   bResult=aFix->FixFaceOrientation(aShell, isAccountMultiConex, bNonManifold);
456
457   di<<"bResult="<<(Standard_Integer)bResult;
458
459   TopoDS_Shape aShape;
460   aShape=aFix->Shape();
461
462   TCollection_AsciiString aName(a[1]), aDef("_sh"), aRName;
463   aRName=aName;
464   aRName=aRName+aDef;
465   DBRep::Set (aRName.ToCString(), aShape);
466   di<<aRName.ToCString();
467   //
468   return 0;
469 }
470
471 #include <BRepLib_FindSurface.hxx>
472 #include <BRepBuilderAPI_MakeFace.hxx>
473 Standard_Integer  OCC157(Draw_Interpretor& di,
474                          Standard_Integer n,
475                          const char ** a)
476 //static Standard_Integer findplanarsurface(Draw_Interpretor&, Standard_Integer n, const char ** a)
477 {
478   if (n<3) {
479     di << "bad number of arguments\n";
480     return 1;
481   }
482
483   // try to read a shape:
484   TopoDS_Shape inputShape=DBRep::Get(a[2]);
485   if (inputShape.IsNull() || inputShape.ShapeType() != TopAbs_WIRE) {
486     di << "Invalid input shape\n";
487     return 1;
488   }
489   Standard_Real toler = Draw::Atof(a[3]);
490   TopoDS_Wire aWire = TopoDS::Wire(inputShape);
491   BRepLib_FindSurface FS(aWire, toler, Standard_True);
492   if(FS.Found()) {
493     di<<"OCC157: OK; Planar surface is found\n";
494     Handle(Geom_Surface) aSurf = FS.Surface();
495     BRepBuilderAPI_MakeFace aMakeFace(aSurf,aWire,Standard_True);
496     if(aMakeFace.IsDone()) {
497       TopoDS_Face aFace = aMakeFace.Face();
498       DBRep::Set(a[1],aFace);
499     }
500   }
501   else di<<"OCC157: ERROR; Planar surface is not found with toler = "<<toler <<"\n";
502   return 0;
503
504 }
505
506 // #include <MyCommandsCMD.h>
507 #include <ShapeFix_Shape.hxx>
508 #include <BRepOffset_MakeOffset.hxx>
509 #include <BRepOffsetAPI_MakeOffset.hxx>
510 #include <BRepOffset_Mode.hxx>
511 #include <GeomAbs_JoinType.hxx>
512 #include <AIS_Shape.hxx>
513
514 #include <BRepTools.hxx>
515
516 Standard_Integer  OCC165(Draw_Interpretor& di ,
517                          Standard_Integer n,
518                          const char ** a)
519
520
521 //=======================================================================
522
523 // static int YOffset (Draw_Interpretor& di, Standard_Integer argc, const char ** argv);
524
525 // void MyOffsets_Commands(Draw_Interpretor& theCommands)
526 // {
527 //      theCommands.Add("yoffset" , "yoffset" , __FILE__, YOffset, " Offset on Z Direction");
528 // }
529
530 //=======================================================================
531
532 // static int YOffset (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
533  {
534    if (n > 2)
535      {
536        di <<"Usage : " << a[0] << " [file]\n";
537        return 1;
538      }
539         di.Eval ("axo");
540
541 #define _OFFSET_TELCO_
542 #ifdef _OFFSET_TELCO_
543
544         Standard_CString file = a[1];
545
546         BRep_Builder aBuilder;
547         TopoDS_Shape theShape;
548         //BRepTools::Read(theShape, Standard_CString("/dn02/users_SUN/inv/3/OCC165/2d_tr_line.brep"), aBuilder);
549         BRepTools::Read(theShape, file, aBuilder);
550         DBRep::Set("shape", theShape);
551
552         TopoDS_Wire theWire = TopoDS::Wire(theShape);
553
554         Standard_Real anOffset = 1.5;
555
556 #else
557
558         Standard_Real xA = 0.0, xB = 200.0, xC = 200.0, xD = 0.0,
559                 yA = 0.0, yB = 0.0, yC = 200.0, yD = 200.0,
560                 zA = 0.0, zB = 0.0, zC = 0.0, zD = 0.0;
561
562         BRepBuilderAPI_MakePolygon theSquare;
563         TopoDS_Vertex theA = BRepBuilderAPI_MakeVertex(gp_Pnt(xA, yA, zA));
564         theSquare.Add(theA);
565         TopoDS_Vertex theB = BRepBuilderAPI_MakeVertex(gp_Pnt(xB, yB, zB));
566         theSquare.Add(theB);
567         TopoDS_Vertex theC = BRepBuilderAPI_MakeVertex(gp_Pnt(xC, yC, zC));
568         theSquare.Add(theC);
569         TopoDS_Vertex theD = BRepBuilderAPI_MakeVertex(gp_Pnt(xD, yD, zD));
570         theSquare.Add(theD);
571
572         theSquare.Close();
573         TopoDS_Wire theWire = theSquare.Wire();
574
575         Standard_Real anOffset = 10;
576
577
578 #endif /* _OFFSET_TELCO_ */
579
580
581         TopoDS_Face theFace = BRepBuilderAPI_MakeFace(theWire).Face();
582         DBRep::Set("face", theFace);
583
584
585         Standard_Real anAlt = 0.;
586         GeomAbs_JoinType theJoin = GeomAbs_Intersection;
587 //GeomAbs_Intersection; //GeomAbs_Arc;
588         BRepOffsetAPI_MakeOffset aMakeOffset(theFace, theJoin);
589         aMakeOffset.AddWire(theWire);
590
591         aMakeOffset.Perform(anOffset, anAlt);
592
593         TopoDS_Shape theOffsetShapePos = aMakeOffset.Shape();
594         DBRep::Set("offset", theOffsetShapePos);
595         return 0;
596 //      return TCL_OK;
597 }
598
599 #include<BRepAlgoAPI_Cut.hxx>
600
601 #include<BRepPrimAPI_MakeHalfSpace.hxx>
602 #include<Geom_CartesianPoint.hxx>
603 #include<AIS_Point.hxx>
604
605 #include <BRepBuilderAPI_MakeEdge.hxx>
606 #include <BRepBuilderAPI_MakeWire.hxx>
607 #include <BRepBuilderAPI_MakeFace.hxx>
608
609 static Standard_Integer OCC297 (Draw_Interpretor& di,Standard_Integer /*argc*/, const char ** argv )
610
611 {
612   Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
613   if (myAISContext.IsNull()) {
614     di << "use 'vinit' command before " << argv[0] << "\n";
615     return -1;
616   }
617   
618   gp_Pnt pt1_(250., 250., 0.);
619   gp_Pnt pt2_(-250., 250., 0.);
620   gp_Pnt pt3_(-250., -250., 0.);
621   gp_Pnt pt4_(250., -250., 0.);
622   BRepBuilderAPI_MakeEdge edg1_(pt1_, pt2_);
623   BRepBuilderAPI_MakeEdge edg2_(pt2_, pt3_);
624   BRepBuilderAPI_MakeEdge edg3_(pt3_, pt4_);
625   BRepBuilderAPI_MakeEdge edg4_(pt4_, pt1_);
626
627   BRepBuilderAPI_MakeWire wire_(edg1_, edg2_, edg3_, edg4_);
628   BRepBuilderAPI_MakeFace face_(wire_);
629   TopoDS_Face sh_ = face_.Face();
630
631   int up = 1;
632
633   gp_Pnt g_pnt;
634   if (up)
635     g_pnt = gp_Pnt(0, 0, -100);
636   else
637     g_pnt = gp_Pnt(0, 0, 100);
638
639   myAISContext->EraseAll(Standard_False);
640   Handle(Geom_CartesianPoint) GEOMPoint = new Geom_CartesianPoint(g_pnt);
641   Handle(AIS_Point) AISPoint = new AIS_Point(GEOMPoint);
642   myAISContext->Display(AISPoint, Standard_True);
643
644   BRepPrimAPI_MakeHalfSpace half_(sh_, g_pnt);
645   TopoDS_Solid sol1_ = half_.Solid();
646
647   DBRep::Set("Face", sol1_);
648
649   gp_Ax1 ax1_(gp_Pnt(0., 0., -100.), gp_Dir(0., 0., 1.));
650
651   Standard_Real x = 0., y = 0., z = -80.;
652
653   BRepPrimAPI_MakeBox box(gp_Pnt(x, y, z), gp_Pnt(x + 150, y + 200, z + 200));
654
655   DBRep::Set("Box", box.Shape());
656
657   return 0;
658
659 }
660
661 #include<GProp_GProps.hxx>
662 #include<BRepGProp.hxx>
663
664 static Standard_Integer OCC305 (Draw_Interpretor& di,Standard_Integer argc, const char ** argv )
665
666 {
667   if (argc != 2)
668   {
669     di <<"Usage : " << argv[0] << " file\n";
670     return 1;
671   }
672   Standard_CString file = argv[1];
673
674   Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
675   if(myAISContext.IsNull()) {
676     di << "use 'vinit' command before " << argv[0] << "\n";
677     return -1;
678   }
679
680 TopoDS_Shape sh;
681 BRep_Builder builder;
682 //BRepTools::Read(sh, "/dn02/users_SUN/inv/3/OCC305/testc.brep", builder);
683 BRepTools::Read(sh, file, builder);
684
685 TopoDS_Wire wire;
686 builder.MakeWire(wire);
687 TopoDS_Edge ed;
688 TopoDS_Vertex vt1, vt2;
689 TopExp_Explorer wex(sh, TopAbs_EDGE);
690 for(;wex.More();wex.Next())
691 {
692     ed = TopoDS::Edge(wex.Current());
693     TopExp::Vertices(ed, vt1, vt2);
694     builder.UpdateVertex(vt1, 0.01);
695     builder.UpdateVertex(vt2, 0.01);
696     builder.UpdateEdge(ed, 0.01);
697     builder.Add(wire, ed);
698
699
700     GProp_GProps lprop;
701     BRepGProp::LinearProperties(ed, lprop);
702     printf("\n length = %f", lprop.Mass());
703 }
704  DBRep::Set("Wire",wire);
705 // Handle(AIS_Shape) res = new AIS_Shape( wire );
706 // aContext->SetColor( res, Quantity_NOC_RED );
707 // aContext->Display( res );
708
709 // BRepOffsetAPI_MakeOffset off(wire, GeomAbs_Arc);
710 // off.Perform(0.5, 0);
711
712 // printf("\n IsDone = %d", off.IsDone());
713 // sh = off.Shape();
714 // res = new AIS_Shape( sh );
715 // aContext->SetColor( res, Quantity_NOC_GREEN );
716 // aContext->Display( res );
717
718   return 0;
719
720 }
721
722 static Standard_Integer OCC166 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv)
723 {
724
725   Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
726   if(myAISContext.IsNull()) {
727     di << "use 'vinit' command before " << argv[0];
728     return 1;
729   }
730
731   BRepPrimAPI_MakeBox aBox(gp_Pnt(0, 0, 0), 100, 100, 100);
732   Handle(AIS_Shape) anAISBox = new AIS_Shape(aBox.Shape());
733   myAISContext->SetAutoActivateSelection (Standard_False);
734   myAISContext->Display(anAISBox, 1);
735
736   TColStd_ListOfInteger anActivatedModes;
737   myAISContext->ActivatedModes (anAISBox, anActivatedModes);
738   if(anActivatedModes.Extent() != 1 || anActivatedModes.First() != -1 )
739     return 1;
740
741   return 0;
742 }
743
744 #include <TDocStd_Document.hxx>
745 #include <DDocStd.hxx>
746 #include <PCDM_StoreStatus.hxx>
747 #include <TDocStd_Application.hxx>
748
749 static Standard_Integer OCC381_Save (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
750 {
751   if (nb != 2) {
752     di << "Usage: " << a[0] << " Doc\n";
753     return 1;
754   }
755
756   Handle(TDocStd_Document) D;
757   if (!DDocStd::GetDocument(a[1],D)) return 1;
758
759   Handle(TDocStd_Application) A = DDocStd::GetApplication();
760
761   TCollection_ExtendedString theStatusMessage;
762   if (!D->IsSaved()) {
763     di << "this document has never been saved\n";
764     return 0;
765   }
766   PCDM_StoreStatus theStatus = A->Save(D, theStatusMessage);
767   if (theStatus != PCDM_SS_OK ) {
768     switch ( theStatus ) {
769       case PCDM_SS_DriverFailure: {
770         di << "Error saving document: Could not store , no driver found to make it\n";
771         break ;
772       }
773       case PCDM_SS_WriteFailure: {
774         di << "Error saving document: Write access failure\n";
775         break;
776       }
777       case PCDM_SS_Failure: {
778         di << "Error saving document: Write failure\n" ;
779         break;
780       }
781       case PCDM_SS_Doc_IsNull: {
782         di << "Error saving document: No document to save\n";
783         break ;
784       }
785       case PCDM_SS_No_Obj: {
786         di << "Error saving document: No objects written\n";
787         break;
788       }
789       case PCDM_SS_Info_Section_Error: {
790         di << "Error saving document: Write info section failure\n" ;
791         break;
792       }
793       default:
794           break;
795     }
796     return 1;
797   }
798   return 0;
799 }
800
801 static Standard_Integer OCC381_SaveAs (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
802 {
803   if (nb != 3) {
804     di << "Usage: " << a[0] << " Doc Path\n";
805     return 1;
806   }
807
808   Handle(TDocStd_Document) D;
809   if (!DDocStd::GetDocument(a[1],D)) return 1;
810
811   TCollection_ExtendedString path (a[2]);
812   Handle(TDocStd_Application) A = DDocStd::GetApplication();
813
814   TCollection_ExtendedString theStatusMessage;
815   PCDM_StoreStatus theStatus = A->SaveAs(D,path, theStatusMessage);
816   if (theStatus != PCDM_SS_OK ) {
817     switch ( theStatus ) {
818       case PCDM_SS_DriverFailure: {
819         di << "Error saving document: Could not store , no driver found to make it\n";
820         break ;
821       }
822       case PCDM_SS_WriteFailure: {
823         di << "Error saving document: Write access failure\n";
824         break;
825       }
826       case PCDM_SS_Failure: {
827         di << "Error saving document: Write failure\n" ;
828         break;
829       }
830       case PCDM_SS_Doc_IsNull: {
831         di << "Error saving document: No document to save\n";
832         break ;
833       }
834       case PCDM_SS_No_Obj: {
835         di << "Error saving document: No objects written\n";
836         break;
837       }
838       case PCDM_SS_Info_Section_Error: {
839         di << "Error saving document: Write info section failure\n" ;
840         break;
841       }
842       default:
843           break;
844     }
845     return 1;
846   }
847
848   return 0;
849 }
850
851 #include <BRepClass3d_SolidClassifier.hxx>
852
853 Standard_Integer OCC299bug (Draw_Interpretor& theDi,
854                             Standard_Integer  theArgNb,
855                             const char**      theArgVec)
856 {
857   if (theArgNb < 3)
858   {
859     theDi << "Usage : " << theArgVec[0] << " Solid Point [Tolerance=1.e-7]\n";
860     return -1;
861   }
862
863   TopoDS_Shape aS = DBRep::Get (theArgVec[1]);
864   if (aS.IsNull())
865   {
866     theDi << " Null Shape is not allowed here\n";
867     return 1;
868   }
869   else if (aS.ShapeType() != TopAbs_SOLID)
870   {
871     theDi << " Shape type must be SOLID\n";
872     return 1;
873   }
874
875   gp_Pnt aP (8., 9., 10.);
876   if (!DrawTrSurf::GetPoint (theArgVec[2], aP))
877   {
878     theDi << " Null Point is not allowed here\n";
879     return 1;
880   }
881   const Standard_Real aTol = (theArgNb == 4) ? Draw::Atof (theArgVec[3]) : 1.e-7;
882
883   BRepClass3d_SolidClassifier aSC (aS);
884   aSC.Perform (aP, aTol);
885
886   switch (aSC.State())
887   {
888     case TopAbs_IN:      theDi << "The point is IN shape\n";      return 0;
889     case TopAbs_OUT:     theDi << "The point is OUT of shape\n";  return 0;
890     case TopAbs_ON:      theDi << "The point is ON shape\n";      return 0;
891     case TopAbs_UNKNOWN:
892     default:             theDi << "The point is UNKNOWN shape\n"; return 0;
893   }
894 }
895
896 #include <OSD_Process.hxx>
897 #include <OSD_Path.hxx>
898
899 static Standard_Integer OCC309bug (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
900 {
901   if (nb != 1) {
902     di << "Usage: " << a[0] << "\n";
903     return 1;
904   }
905   OSD_Process p;
906   OSD_Path d = p.CurrentDirectory();
907   TCollection_AsciiString s;
908   d.SystemName(s);
909   di << "*" <<  s.ToCString() << "*\n";
910   d.UpTrek();
911   d.SystemName(s);
912   di <<  "*" <<  s.ToCString() <<  "*\n";
913   return 0;
914 }
915
916 static Standard_Integer OCC310bug (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
917 {
918   if (nb != 1) {
919     di << "Usage: " << a[0] << "\n";
920     return 1;
921   }
922   OSD_Path p("/where/you/want/tmp/qwerty/tmp/");
923   di << p.Trek().ToCString() << "\n";
924   p.UpTrek();
925   di << p.Trek().ToCString() << "\n";
926   return 0;
927 }
928
929 #include <BRepAlgoAPI_Fuse.hxx>
930 #include <BRepAlgoAPI_Common.hxx>
931
932 static Standard_Integer OCC277bug (Draw_Interpretor& di, Standard_Integer nb, const char ** a)
933 {
934   if(nb != 1) {
935     di << "Usage : " << a[0] << "\n";
936     return 1;
937   }
938
939   BRepPrimAPI_MakeBox box1( 100, 100, 100 );
940   BRepPrimAPI_MakeBox box2( gp_Pnt( 50, 50,50 ), 200, 200, 200 );
941
942   TopoDS_Shape shape1 = box1.Shape();
943   TopoDS_Shape shape2 = box2.Shape();
944
945   TopoDS_Shape fuse,comm;
946   di << "fuse = BRepAlgoAPI_Fuse( shape1, shape2 )\n";
947   di << "comm = BRepAlgoAPI_Common( shape1, shape2 )\n";
948   fuse = BRepAlgoAPI_Fuse(shape1, shape2).Shape();
949   comm = BRepAlgoAPI_Common(shape1, shape2).Shape();
950
951   return 0;
952 }
953
954 #include <DDocStd_DrawDocument.hxx>
955 #include <TDataStd_Name.hxx>
956 #include <Draw.hxx>
957 #include <XCAFDoc_ShapeTool.hxx>
958 #include <XCAFDoc_DocumentTool.hxx>
959 #include <TDF_LabelSequence.hxx>
960 #include <TPrsStd_AISPresentation.hxx>
961 #include <TDF_Data.hxx>
962 #include <TDF_Label.hxx>
963 #include <XCAFPrs_Driver.hxx>
964
965 //------------------------------------------------------------------------------------------
966 // name    : OCC363
967 // Purpose :
968 //------------------------------------------------------------------------------------------
969 static Standard_Integer OCC363 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
970 {
971   try
972   {
973     OCC_CATCH_SIGNALS
974     // 1. Verufy amount of arguments
975     if(argc < 3) { di <<"Error OCC363 : Use : OCC363 document filename\n"; return 1; }
976
977     // 2. Retrieve DDocStd application
978     Handle(TDocStd_Application) App = DDocStd::GetApplication();
979
980     // 3. Open document
981     TCollection_ExtendedString name(argv[2]);
982     Handle(TDocStd_Document) Doc;
983     if(App->Open(name, Doc) != PCDM_RS_OK) { di << "Error OCC363 : document was not opened successfully\n"; return 1;}
984     Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(Doc);
985     TDataStd_Name::Set(Doc->GetData()->Root(),argv[1]);
986     Draw::Set(argv[1],DD);
987
988     // 4. Create prsentations
989     Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
990     TDF_LabelSequence seq;
991     shapes->GetFreeShapes ( seq );
992     Handle(TPrsStd_AISPresentation) prs;
993     for ( Standard_Integer i=1; i <= seq.Length(); i++ )
994       if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) )
995         prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
996   }
997   catch(Standard_Failure const&) { di << "FAULTY OCC363 : Exception during reading document.\n";return 0;}
998
999   di << "OCC363 OK\n";
1000   return 0;
1001 }
1002
1003 // Must use OCC299
1004 ////======================================================================================
1005 //// Function : OCC372
1006 //// Purpose  :
1007 ////======================================================================================
1008 //static Standard_Integer OCC372 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1009 //{
1010 //  try
1011 //  {
1012 //    OCC_CATCH_SIGNALS
1013 //    // 1. Verufy amount of arguments
1014 //    if(argc < 2) {di << "OCC372 FAULTY. Use : OCC372 brep-file";return 0;}
1015 //
1016 //    // 2. Read solid
1017 //    BRep_Builder B;
1018 //    TopoDS_Shape Ref;
1019 //    BRepTools::Read(Ref, argv[1], B);
1020 //
1021 //    // 3. Calculate location of aP3d in relation to the solid
1022 //    gp_Pnt aP3d(6311.4862583184, -2841.3092756034, 16.461053497188);
1023 //    BRepClass3d_SolidClassifier SC(Ref);
1024 //    SC.Perform(aP3d, 1e-7);
1025 //
1026 //    // 4. Check returned state. The point must be inside the solid.
1027 //    TopAbs_State aState=SC.State();
1028 //    switch (aState)
1029 //    {
1030 //    case TopAbs_OUT:
1031 //      di<<"OCC372 FAULTY. aState = TopAbs_OUT";
1032 //      return 0;
1033 //    case TopAbs_ON:
1034 //      di<<"OCC372 FAULTY. aState = TopAbs_ON";
1035 //     return 0;
1036 //    case TopAbs_IN:
1037 //      di<<"OCC372 OK. aState = TopAbs_IN" ;
1038 //      return 0;
1039 //    default:
1040 //      di<<"OCC372 FAULTY. aState = UNKNOWN";
1041 //      return 0;
1042 //    }
1043 //  }
1044 //  catch (Standard_Failure) { di<<"OCC372 FAULTY. Exception raised"; }
1045 //
1046 //  return 0;
1047 //}
1048
1049 #include <BRepTopAdaptor_FClass2d.hxx>
1050
1051 //======================================================================================
1052 // Function : OCC377
1053 // Purpose  :
1054 //======================================================================================
1055 static Standard_Integer OCC377 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1056 {
1057   try
1058   {
1059     OCC_CATCH_SIGNALS
1060     // 1. Verify validity of arguments
1061     if ( argc < 1 ) {di << "Error OCC377. Use  OCC377 file x y precuv \n";return 0;}
1062
1063     // 2. Initialize parameters
1064     gp_Pnt2d p2d;
1065     p2d.SetX ( Draw::Atof(argv[2]) );
1066     p2d.SetY ( Draw::Atof(argv[3]) );
1067     Standard_Real precuv = Draw::Atof (argv[4] );
1068
1069     // 3. Read shape
1070     BRep_Builder B;
1071     TopoDS_Shape Shape;
1072     BRepTools::Read ( Shape, argv[1], B );
1073
1074     // 4. Verify whether enrtry point is on wire and reversed ones (indeed results of veridying must be same)
1075     TopExp_Explorer exp;
1076     Standard_Integer i=1;
1077     for (exp.Init(Shape.Oriented(TopAbs_FORWARD),TopAbs_WIRE); exp.More(); exp.Next(), i++)
1078     {
1079       // 4.1. Verify whether enrtry point is on wire
1080       const TopoDS_Wire& wir = TopoDS::Wire(exp.Current());
1081       TopoDS_Face newFace = TopoDS::Face(Shape.EmptyCopied());
1082
1083       TopAbs_Orientation orWire = wir.Orientation();
1084       newFace.Orientation(TopAbs_FORWARD);
1085       B.Add(newFace,wir);
1086
1087       BRepTopAdaptor_FClass2d FClass2d1(newFace,precuv);
1088       TopAbs_State stat1 = FClass2d1.PerformInfinitePoint();
1089       //di << "Wire " << i << ": Infinite point is " <<
1090       //  ( stat1 == TopAbs_IN ? "IN" : stat1 == TopAbs_OUT ? "OUT" : stat1 == TopAbs_ON ? "ON" : "UNKNOWN" ) << "\n";
1091
1092       TCollection_AsciiString TmpString;
1093       stat1 == TopAbs_IN ? TmpString.AssignCat("IN") : stat1 == TopAbs_OUT ? TmpString.AssignCat("OUT") : stat1 == TopAbs_ON ? TmpString.AssignCat("ON") : TmpString.AssignCat("UNKNOWN");
1094       di << "Wire " << i << ": Infinite point is " << TmpString.ToCString() << "\n";
1095
1096       stat1 = FClass2d1.Perform(p2d);
1097       //di << "Wire " << i << ": point ( " << p2d.X() << ", " << p2d.Y() << " ) is " <<
1098       //  ( stat1 == TopAbs_IN ? "IN" : stat1 == TopAbs_OUT ? "OUT" : stat1 == TopAbs_ON ? "ON" : "UNKNOWN" ) << "\n";
1099
1100       TmpString.Clear();
1101       stat1 == TopAbs_IN ? TmpString.AssignCat("IN") : stat1 == TopAbs_OUT ? TmpString.AssignCat("OUT") : stat1 == TopAbs_ON ? TmpString.AssignCat("ON") : TmpString.AssignCat("UNKNOWN");
1102       di << "Wire " << i << ": point ( " << p2d.X() << ", " << p2d.Y() << " ) is " << TmpString.ToCString() << "\n";
1103
1104       // 4.2. Verify whether enrtry point is on reversed wire
1105       newFace = TopoDS::Face(Shape.EmptyCopied());
1106       newFace.Orientation(TopAbs_FORWARD);
1107       orWire = TopAbs::Reverse(orWire);
1108       B.Add(newFace,wir.Oriented(orWire));
1109       BRepTopAdaptor_FClass2d FClass2d2(newFace,precuv);
1110       TopAbs_State stat2 = FClass2d2.PerformInfinitePoint();
1111       //di << "Reversed Wire " << i << ": Infinite point is " <<
1112       //  ( stat2 == TopAbs_IN ? "IN" : stat2 == TopAbs_OUT ? "OUT" : stat2 == TopAbs_ON ? "ON" : "UNKNOWN" ) << "\n";
1113
1114       TmpString.Clear();
1115       stat2 == TopAbs_IN ? TmpString.AssignCat("IN") : stat2 == TopAbs_OUT ? TmpString.AssignCat("OUT") : stat2 == TopAbs_ON ? TmpString.AssignCat("ON") : TmpString.AssignCat("UNKNOWN");
1116       di << "Reversed Wire " << i << ": Infinite point is " << TmpString.ToCString() << "\n";
1117
1118       stat2 = FClass2d2.Perform(p2d);
1119       //di << "Reversed Wire " << i << ": point ( " << p2d.X() << ", " << p2d.Y() << " ) is " <<
1120       //  ( stat2 == TopAbs_IN ? "IN" : stat2 == TopAbs_OUT ? "OUT" : stat2 == TopAbs_ON ? "ON" : "UNKNOWN" ) << "\n";
1121
1122       TmpString.Clear();
1123       stat2 == TopAbs_IN ? TmpString.AssignCat("IN") : stat2 == TopAbs_OUT ? TmpString.AssignCat("OUT") : stat2 == TopAbs_ON ? TmpString.AssignCat("ON") : TmpString.AssignCat("UNKNOWN");
1124       di << "Reversed Wire " << i << ": point ( " << p2d.X() << ", " << p2d.Y() << " ) is " << TmpString.ToCString() << "\n";
1125
1126       // 4.3. Compare results (they must be same)
1127       if(stat1 ==stat2) di << "OCC377 OK\n";
1128       else {di << "OCC377 FAULTY\n"; return 0;}
1129     }
1130   }
1131   catch(Standard_Failure const&)
1132   {
1133     di << "OCC377 Exception";
1134   }
1135
1136   return 0;
1137 }
1138
1139 #include <ShapeUpgrade_ShapeDivideAngle.hxx>
1140 #include <ShapeBuild_ReShape.hxx>
1141
1142 //=======================================================================
1143 //function : OCC22
1144 //purpose  :
1145 //=======================================================================
1146 static Standard_Integer OCC22 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1147 {
1148   try
1149   {
1150     OCC_CATCH_SIGNALS
1151     // 1. Verify arguments of the command
1152     if (argc < 5) { di << "OCC22 FAULTY. Use : OCC22 Result Shape CompoundOfSubshapesToBeDivided ConsiderLocation"; return 0;}
1153
1154     Standard_Boolean aConsiderLocation;
1155     if(strcmp(argv[4], "0")==0) aConsiderLocation = Standard_False;
1156     else aConsiderLocation = Standard_True;
1157
1158     // 2. Iniitialize aShapeUpgrade
1159     ShapeUpgrade_ShapeDivideAngle aShapeUpgrade(M_PI/2.);
1160     // precision
1161     aShapeUpgrade.SetPrecision (Precision::Confusion());
1162     // tolerance
1163     aShapeUpgrade.SetMaxTolerance(0.1);
1164     // subshapes to be divided
1165     TopoDS_Shape aSubShapesToBeDivided = DBRep::Get(argv[3]);
1166     if(aSubShapesToBeDivided.IsNull()) {di << "OCC22 FAULTY. Compound of subshapes to be divided is not exist. Please, verify input values. \n";return 0;}
1167     aShapeUpgrade.Init(aSubShapesToBeDivided);
1168     // context
1169     Handle(ShapeBuild_ReShape) aReshape = new ShapeBuild_ReShape;
1170     aShapeUpgrade.SetContext(aReshape);
1171     if(aConsiderLocation) aReshape->ModeConsiderLocation() = Standard_True;
1172
1173     // 3. Perform splitting
1174     if (aShapeUpgrade.Perform (Standard_False))         di << "Upgrade_SplitRevolution_Done \n";
1175     else if (aShapeUpgrade.Status (ShapeExtend_OK))     di << "Upgrade_SplitRevolution_OK \n";
1176     else if (aShapeUpgrade.Status (ShapeExtend_FAIL)) { di << "OCC22 FAULTY. Operation failed. Angle was not divided\n";return 0;}
1177
1178     // 4. Perform rebuilding shape
1179     // 4.1. Retrieve Shape
1180     TopoDS_Shape anInitShape = DBRep::Get(argv[2]);
1181     if(anInitShape.IsNull()) { di << "OCC22 FAULTY. Initial shape is not exist. Please verify input values \n"; return 0;}
1182     // 4.2 Rebuid retrieved shape
1183     TopoDS_Shape aResultShape = aReshape->Apply(anInitShape);
1184     // 4.3. Create result Draw shape
1185     DBRep::Set(argv[1], aResultShape);
1186   }
1187   catch (Standard_Failure const&) {di << "OCC22 Exception \n" ;return 0;}
1188
1189   return 0;
1190 }
1191
1192
1193 #include <ShapeProcess_OperLibrary.hxx>
1194 #include <ShapeProcess_ShapeContext.hxx>
1195 #include <ShapeProcess.hxx>
1196
1197 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
1198 #include <BRepMesh_IncrementalMesh.hxx>
1199 #include <IMeshTools_Parameters.hxx>
1200
1201 //=======================================================================
1202 //function : OCC24
1203 //purpose  :
1204 //=======================================================================
1205 static Standard_Integer OCC24 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1206 {
1207   try
1208   {
1209     OCC_CATCH_SIGNALS
1210     // 1. Verify amount of arguments of the command
1211     if (argc < 6) { di << "OCC24 FAULTY. Use : OCC22 Result Shape CompoundOfSubshapes ResourceFileName SequenceName"; return 0;}
1212
1213     // 2. Retrieve parameters
1214     // initial shape
1215     TopoDS_Shape anInitShape = DBRep::Get(argv[2]);
1216     if(anInitShape.IsNull()) { di << "OCC24 FAULTY. Initial shape is not exist. Please verify input values \n"; return 0;}
1217     // compound of subshapes
1218     TopoDS_Shape aSubShapes = DBRep::Get(argv[3]);
1219     if(aSubShapes.IsNull()) {di << "OCC24 FAULTY. Compound of subshapes is not exist. Please, verify input values. \n";return 0;}
1220     // name of resource file
1221     const char* aResourceFile = argv[4];
1222     // name of sequence from resource file to be executed
1223     const char* aSequenceName = argv[5];
1224
1225     // 3. Initialize ShapeContext and perform sequence of operation specified with resource file
1226     ShapeProcess_OperLibrary::Init();
1227     Handle(ShapeProcess_ShapeContext) aShapeContext = new ShapeProcess_ShapeContext (aSubShapes, aResourceFile);
1228     aShapeContext->SetDetalisation (TopAbs_EDGE);
1229     ShapeProcess::Perform (aShapeContext, aSequenceName);
1230
1231     // 4. Rebuild initil shape in accordance with performed operation
1232     Handle(ShapeBuild_ReShape) aReshape = new ShapeBuild_ReShape;
1233     TopTools_DataMapIteratorOfDataMapOfShapeShape anIter (aShapeContext->Map());
1234     for (; anIter.More(); anIter.Next())
1235       aReshape->Replace(anIter.Key(), anIter.Value());
1236     TopoDS_Shape aResultShape = aReshape->Apply(anInitShape);
1237
1238     // 5 Create resultant Draw shape
1239     DBRep::Set(argv[1], aResultShape);
1240
1241   }
1242   catch (Standard_Failure const&) {di << "OCC24 Exception \n" ;return 0;}
1243
1244   return 0;
1245 }
1246
1247 //=======================================================================
1248 //function : OCC369
1249 //purpose  : Verify whether exception occurs during building mesh
1250 //=======================================================================
1251 static Standard_Integer OCC369(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1252 {
1253   try
1254   {
1255     OCC_CATCH_SIGNALS
1256     // 1. Verify amount of arguments of the command
1257     if (argc < 2) { di << "OCC369 FAULTY. Use : OCC369 Shape \n"; return 0;}
1258
1259     // 2. Retrieve shape
1260     TopoDS_Shape aShape = DBRep::Get(argv[1]);
1261     if(aShape.IsNull()) {di << "OCC369 FAULTY. Entry shape is NULL \n"; return 0;}
1262
1263     // 3. Build mesh
1264     IMeshTools_Parameters aMeshParams;
1265     aMeshParams.Relative   = Standard_True;
1266     aMeshParams.Deflection = 0.2;
1267     aMeshParams.Angle      = M_PI / 6.0;
1268     BRepMesh_IncrementalMesh aMesh(aShape, aMeshParams);
1269
1270   }
1271   catch (Standard_Failure const&) {di << "OCC369 Exception \n" ;return 0;}
1272
1273   di << "OCC369 OK \n";
1274   return 0;
1275 }
1276
1277 #include <math_Vector.hxx>
1278 #include <math_Matrix.hxx>
1279 static Standard_Integer OCC524 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1280 {
1281   if(argc != 9){
1282     di<<"Usage : " << argv[0] << " LowerVector UpperVector InitialValueVector LowerRowMatrix UpperRowMatrix LowerColMatrix UpperColMatrix InitialValueMatrix\n";
1283     return 1;
1284   }
1285   Standard_Integer LowerVector = Draw::Atoi(argv[1]);
1286   Standard_Integer UpperVector = Draw::Atoi(argv[2]);
1287   Standard_Real InitialValueVector = Draw::Atof(argv[3]);
1288   Standard_Integer LowerRowMatrix = Draw::Atoi(argv[4]);
1289   Standard_Integer UpperRowMatrix = Draw::Atoi(argv[5]);
1290   Standard_Integer LowerColMatrix = Draw::Atoi(argv[6]);
1291   Standard_Integer UpperColMatrix = Draw::Atoi(argv[7]);
1292   Standard_Real InitialValueMatrix = Draw::Atof(argv[8]);
1293
1294   math_Vector Vector1(LowerVector, UpperVector);
1295   math_Vector Vector2(LowerVector, UpperVector);
1296
1297   math_Vector Vector(LowerVector, UpperVector, InitialValueVector);
1298   math_Matrix Matrix(LowerRowMatrix, UpperRowMatrix, LowerColMatrix, UpperColMatrix, InitialValueMatrix);
1299
1300   //Vector.Dump(std::cout);
1301   //std::cout<<std::endl;
1302
1303   //Matrix.Dump(std::cout);
1304   //std::cout<<std::endl;
1305
1306   Vector1.Multiply(Vector, Matrix);
1307
1308   //Vector1.Dump(std::cout);
1309   Standard_SStream aSStream1;
1310   Vector1.Dump(aSStream1);
1311   di << aSStream1;
1312   di<<"\n";
1313
1314   if (Matrix.RowNumber() > 1) {
1315     Matrix(Matrix.LowerRow() + 1, Matrix.LowerCol()) += 1.;
1316   }
1317   Vector2.TMultiply(Vector, Matrix);
1318
1319   //Vector2.Dump(std::cout);
1320   Standard_SStream aSStream2;
1321   Vector2.Dump(aSStream2);
1322   di << aSStream2;
1323   di<<"\n";
1324
1325   return 0;
1326 }
1327
1328 #include <GeomPlate_BuildPlateSurface.hxx>
1329 //=======================================================================
1330 //function : OCC525
1331 //purpose  :
1332 //=======================================================================
1333 static Standard_Integer OCC525(Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/)
1334 {
1335   GeomPlate_BuildPlateSurface aBuilder;
1336   aBuilder.Perform();
1337
1338   if (aBuilder.IsDone())
1339   {
1340     di << "Error in OCC525. Null result is expected.\n";
1341   }
1342   else
1343   {
1344     di << "OCC525 OK \n";
1345   }
1346
1347   return 0;
1348 }
1349
1350 #include <BRepPrimAPI_MakeWedge.hxx>
1351 #include <gce_MakeRotation.hxx>
1352 #include <gce_MakeTranslation.hxx>
1353 #include <BRepBuilderAPI_Transform.hxx>
1354 #include <BRepPrimAPI_MakeWedge.hxx>
1355 //=======================================================================
1356 //function :  OCC578
1357 //purpose  :
1358 //=======================================================================
1359 static Standard_Integer OCC578 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1360 {
1361   if(argc != 4) {
1362     di << "Usage : " << argv[0] << " shape1 shape2 shape3\n";
1363     return 1;
1364   }
1365
1366   gp_Pnt P0(0,0,0.0);
1367   double xperiod = 1.0;
1368   double yperiod = 1.0;
1369   double sub_thick = 0.5;
1370
1371   // mask_substrate
1372   //TopoDS_Shape substrate = BRepPrimAPI_MakeBox( P0, xperiod, yperiod, sub_thick );
1373   TopoDS_Shape substrate = BRepPrimAPI_MakeBox( P0, xperiod, yperiod, sub_thick ).Shape();
1374
1375   // --------------------------------------------------------------------
1376
1377   // wedge
1378   //TopoDS_Shape wedge1 = BRepPrimAPI_MakeWedge(0.5, 0.05, 0.5,
1379         //                                    0.1,  0.1  , 0.4, 0.4 );
1380   TopoDS_Shape wedge1 = BRepPrimAPI_MakeWedge(0.5, 0.05, 0.5,
1381                                               0.1,  0.1  , 0.4, 0.4 ).Shape();
1382
1383   gp_Trsf rotate = gce_MakeRotation ( gp_Pnt(0.0,0.0,0.0),
1384                                      gp_Dir(1.0,0.0,0.0),
1385                                      1.570795 );
1386
1387   gp_Trsf translate = gce_MakeTranslation(gp_Pnt( 0.0, -0.5, 0.0),
1388                                           gp_Pnt( 0.25, 0.25, 0.5)
1389                                           );
1390
1391   rotate.PreMultiply( translate );
1392
1393   TopoDS_Shape wedge1a = BRepBuilderAPI_Transform( wedge1, rotate );
1394
1395   if (wedge1a.IsNull()) {
1396     di<<" Null shape1 is not allowed\n";
1397     return 1;
1398   }
1399   DBRep::Set(argv[1], wedge1a);
1400
1401   // --------------------------------------------------------------------
1402
1403   // wedge top
1404   //TopoDS_Shape wedge2 = BRepPrimAPI_MakeWedge(0.5, 0.3, 0.5,
1405         //                                    0.1,  0.1  , 0.4, 0.4 );
1406   TopoDS_Shape wedge2 = BRepPrimAPI_MakeWedge(0.5, 0.3, 0.5,
1407                                               0.1,  0.1  , 0.4, 0.4 ).Shape();
1408
1409   gp_Trsf rotate2 = gce_MakeRotation ( gp_Pnt(0.0,0.0,0.0),
1410                                       gp_Dir(1.0,0.0,0.0),
1411                                       1.570795 * 3.0 );
1412
1413   gp_Trsf translate2 = gce_MakeTranslation(gp_Pnt( 0.0, 0.0, 0.0),
1414                                            gp_Pnt( 0.25, 0.25, 0.5)
1415                                            );
1416
1417   rotate2.PreMultiply( translate2 );
1418
1419   TopoDS_Shape wedge2a = BRepBuilderAPI_Transform( wedge2, rotate2 );
1420
1421   if (wedge2a.IsNull()) {
1422     di<<" Null shape2 is not allowed\n";
1423     return 1;
1424   }
1425   DBRep::Set(argv[2], wedge2a);
1426
1427
1428   // combine wedges
1429   di << "wedge_common = BRepAlgoAPI_Fuse(wedge1a , wedge2a)\n";
1430   TopoDS_Shape wedge_common = BRepAlgoAPI_Fuse(wedge1a , wedge2a).Shape();
1431
1432   di << "sub_etch1 = BRepAlgoAPI_Cut(substrate, wedge_common)\n";
1433   TopoDS_Shape sub_etch1 = BRepAlgoAPI_Cut(substrate, wedge_common).Shape();
1434  
1435   if (sub_etch1.IsNull()) {
1436     di<<" Null shape3 is not allowed\n";
1437     return 1;
1438   }
1439   DBRep::Set(argv[3], sub_etch1);
1440
1441   return 0;
1442 }
1443
1444 #include <Standard_GUID.hxx>
1445 //=======================================================================
1446 //function :  OCC669
1447 //purpose  :
1448 //=======================================================================
1449 static Standard_Integer OCC669 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1450 {
1451   if(argc != 2){
1452     di<<"Usage : " << argv[0] << " GUID\n";
1453     return -1;
1454   }
1455   Standard_GUID guid(argv[1]);
1456   //guid.ShallowDump(std::cout);
1457   Standard_SStream aSStream;
1458   guid.ShallowDump(aSStream);
1459   di << aSStream;
1460   di<<"\n";
1461   return 0;
1462 }
1463
1464 #include <XCAFDoc.hxx>
1465 //=======================================================================
1466 //function :  OCC738_ShapeRef
1467 //purpose  :
1468 //=======================================================================
1469 static Standard_Integer OCC738_ShapeRef (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1470 {
1471   if(argc != 1){
1472     di<<"Usage : " << argv[0] << "\n";
1473     return -1;
1474   }
1475   const Standard_GUID& guid = XCAFDoc::ShapeRefGUID ();
1476   //guid.ShallowDump(std::cout);
1477   Standard_SStream aSStream;
1478   guid.ShallowDump(aSStream);
1479   di << aSStream;
1480   return 0;
1481 }
1482
1483 //=======================================================================
1484 //function :  OCC738_Assembly
1485 //purpose  : 
1486 //=======================================================================
1487 static Standard_Integer OCC738_Assembly (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1488 {
1489   if(argc != 1){
1490     di<<"Usage : " << argv[0] << "\n";
1491     return -1;
1492   }
1493   const Standard_GUID& guid = XCAFDoc::AssemblyGUID ();
1494   //guid.ShallowDump(std::cout);
1495   Standard_SStream aSStream;
1496   guid.ShallowDump(aSStream);
1497   di << aSStream;
1498   return 0;
1499 }
1500
1501 #if defined(DDataStd_def01)
1502 #include <DDataStd_DrawPresentation.hxx>
1503 //=======================================================================
1504 //function :  OCC739_DrawPresentation
1505 //purpose  : 
1506 //=======================================================================
1507 static Standard_Integer OCC739_DrawPresentation (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1508 {
1509   if(argc != 1){
1510     di<<"Usage : " << argv[0] << "\n";
1511     return -1;
1512   }
1513   const Standard_GUID& guid = DDataStd_DrawPresentation::GetID() ;
1514   //guid.ShallowDump(std::cout);
1515   Standard_SStream aSStream;
1516   guid.ShallowDump(aSStream);
1517   di << aSStream;
1518   return 0;
1519 }
1520 #endif
1521
1522 //=======================================================================
1523 //function :  OCC708
1524 //purpose  : 
1525 //=======================================================================
1526 static Standard_Integer OCC708 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1527 {
1528   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1529   if(aContext.IsNull()) { 
1530     di << argv[0] << "ERROR : use 'vinit' command before \n";
1531     return 1;
1532   }
1533
1534   if ( argc != 2) {
1535     di << "ERROR : Usage : " << argv[0] << " shape ; Deactivate the current transformation\n";
1536     return 1;
1537   }
1538   
1539   Standard_Boolean updateviewer = Standard_True;
1540
1541   ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
1542   
1543   TCollection_AsciiString aName(argv[1]);
1544   Handle(AIS_InteractiveObject) AISObj;
1545
1546   if (!aMap.Find2 (aName, AISObj)
1547     || AISObj.IsNull())
1548   {
1549     di << "Use 'vdisplay' before\n";
1550     return 1;
1551   }
1552
1553   AISObj->ResetTransformation();
1554
1555   aContext->Erase(AISObj, updateviewer);
1556   aContext->UpdateCurrentViewer();
1557   aContext->Display(AISObj, updateviewer);
1558   aContext->UpdateCurrentViewer();
1559   return 0;
1560 }
1561
1562 //=======================================================================
1563 //function :  OCC670
1564 //purpose  :
1565 //=======================================================================
1566 #include <TColStd_Array2OfInteger.hxx>
1567 static Standard_Integer OCC670 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1568 {
1569   if(argc != 1){
1570     di<<"Usage : " << argv[0] << "\n";
1571     return -1;
1572   }
1573
1574   // check that exception initialized without message string can be safely handled and printed
1575   try {
1576     throw Standard_OutOfRange();
1577   }
1578   catch (Standard_Failure const& anException) {
1579     std::cout << "Caught successfully: ";
1580     std::cout << anException << std::endl;
1581   }
1582   return 0;
1583 }
1584
1585 #include <GeomAPI_ProjectPointOnSurf.hxx>
1586 //=======================================================================
1587 //function :  OCC867
1588 //purpose  : 
1589 //=======================================================================
1590 static Standard_Integer OCC867(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1591 {
1592   if (argc!=7)  
1593   {
1594     di<<"Usage : " << argv[0] << " Point Surface Umin Usup Vmin Vsup \n";
1595     return 1;   
1596   }
1597   
1598   gp_Pnt aPoint3d;        
1599   DrawTrSurf::GetPoint(argv[1],aPoint3d);
1600   Handle (Geom_Surface) aSurface=DrawTrSurf::GetSurface(argv[2]);
1601   Standard_Real             Umin=Draw::Atof(argv[3]);
1602   Standard_Real             Usup=Draw::Atof(argv[4]);
1603   Standard_Real             Vmin=Draw::Atof(argv[5]);
1604   Standard_Real             Vsup=Draw::Atof(argv[6]);
1605  
1606   if (aSurface.IsNull()) {
1607     di << argv[2] << " Null surface \n" ;
1608     return 1;
1609   }
1610   
1611   GeomAPI_ProjectPointOnSurf PonSurf;
1612   PonSurf.Init(aSurface, Umin, Usup, Vmin, Vsup);
1613   PonSurf.Perform(aPoint3d);
1614
1615   return 0; 
1616 }
1617
1618 //=======================================================================
1619 //function :  OCC909
1620 //purpose  : 
1621 //=======================================================================
1622 static Standard_Integer OCC909 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1623 {
1624   if (argc!=3)  
1625   {
1626     di<<"Usage : " << argv[0] << " wire face\n";
1627     return 1;   
1628   }
1629   
1630   TopoDS_Wire awire = TopoDS::Wire(DBRep::Get(argv[1])); //read the wire
1631   TopoDS_Face aface = TopoDS::Face(DBRep::Get(argv[2])); //read the face
1632   if (awire.IsNull() || aface.IsNull()) {
1633     di << "Null object\n";
1634     return 1;
1635   }
1636
1637   Standard_Integer count = 0;
1638   TopExp_Explorer TE(awire, TopAbs_VERTEX);
1639   if ( TE.More()) {
1640     BRepTools_WireExplorer WE;
1641     for ( WE.Init(awire,aface); WE.More(); WE.Next()) {
1642       TopoDS_Edge E = WE.Current();
1643       count++;
1644     }
1645   }
1646   di << "Count = " << count << "\n";
1647
1648   return 0; 
1649 }
1650
1651 //=======================================================================
1652 //function :  OCC921
1653 //purpose  : 
1654 //=======================================================================
1655 static Standard_Integer OCC921 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1656 {
1657   if (argc != 2)
1658   {
1659     di <<"Usage : " << argv[0] << " face\n";
1660     return 1;
1661   }
1662   Standard_Real u1, u2, v1, v2;
1663   TopoDS_Face F = TopoDS::Face( DBRep::Get(argv[1]) ); //read the shape
1664   if (F.IsNull())
1665     return 1;
1666   BRepTools::UVBounds(F, u1, u2, v1, v2);
1667   di << "Bounds: " << u1 << "   " << u2 << "   " << v1 << "   " << v2 << "\n";
1668   return 0;
1669 }
1670
1671 #include <Expr_NamedUnknown.hxx>
1672 #include <Expr_GeneralExpression.hxx>
1673 #include <Expr_Exponential.hxx>
1674 //=======================================================================
1675 //function :  OCC902
1676 //purpose  : 
1677 //=======================================================================
1678 static Standard_Integer OCC902(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1679 {
1680   if (argc != 2)
1681   {
1682     di <<"Usage : " << argv[0] << " expression\n";
1683     return 1;
1684   }
1685
1686  TCollection_AsciiString  myStr(argv[1]);
1687
1688  Handle (Expr_NamedUnknown)      myNamed = new Expr_NamedUnknown(myStr);
1689  Handle (Expr_Exponential)       oldExpr = new Expr_Exponential(myNamed); 
1690  Handle (Expr_GeneralExpression) newExpr = oldExpr->Derivative(myNamed);
1691
1692  
1693  TCollection_AsciiString  res        = newExpr->String();
1694  Standard_CString         resStr     = res.ToCString();
1695  TCollection_AsciiString  res_old    = oldExpr->String();
1696  Standard_CString         res_oldStr = res_old.ToCString();
1697  
1698
1699  di << "X = " << argv[1] << "\n";
1700  di << "Y = " << res_oldStr << "\n";
1701  di << "Y' = " << resStr  << "\n";
1702
1703  return 0;
1704 }
1705
1706 #include <DDF.hxx>
1707 #include <TPrsStd_AISViewer.hxx>
1708 #include <TDF_Label.hxx>
1709 #include <TPrsStd_AISPresentation.hxx>
1710 //=======================================================================
1711 //function : OCC1029_AISTransparency 
1712 //purpose  : OCC1029_AISTransparency  (DOC,entry,[real])
1713 //=======================================================================
1714
1715 static Standard_Integer OCC1029_AISTransparency (Draw_Interpretor& di,
1716                                              Standard_Integer nb, 
1717                                              const char ** arg) 
1718 {
1719   if (nb >= 3 ) {     
1720     Handle(TDocStd_Document) D;
1721     if (!DDocStd::GetDocument(arg[1],D)) return 1;  
1722     TDF_Label L;
1723     if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;  
1724
1725     Handle(TPrsStd_AISViewer) viewer;
1726     if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;  
1727
1728     Handle(TPrsStd_AISPresentation) prs;
1729     if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {   
1730       if( nb == 4 ) {
1731         prs->SetTransparency(Draw::Atof(arg[3]));
1732         TPrsStd_AISViewer::Update(L);
1733       }
1734       else {
1735          di << "Transparency = " << prs->Transparency() << "\n";
1736       }
1737       return 0;
1738     }
1739   }
1740   di << arg[0] << " : Error\n";
1741   return 1;
1742 }
1743
1744 //=======================================================================
1745 //function : OCC1030_AISColor 
1746 //purpose  : OCC1030_AISColor (DOC,entry,[color])
1747 //=======================================================================
1748
1749 static Standard_Integer OCC1030_AISColor (Draw_Interpretor& di,
1750                                       Standard_Integer nb, 
1751                                       const char ** arg) 
1752 {
1753   if (nb >= 3) {     
1754     Handle(TDocStd_Document) D;
1755     if (!DDocStd::GetDocument(arg[1],D)) return 1;  
1756     TDF_Label L;
1757     if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;  
1758
1759     Handle(TPrsStd_AISViewer) viewer;
1760     if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;  
1761
1762     Handle(TPrsStd_AISPresentation) prs;
1763     if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {   
1764       if( nb == 4 ) {
1765         prs->SetColor((Quantity_NameOfColor)Draw::Atoi(arg[3]));
1766         TPrsStd_AISViewer::Update(L);
1767       }
1768       else
1769          di << "Color = " << prs->Color() << "\n";
1770       return 0; 
1771     }
1772   }
1773   di << arg[0] << " : Error\n";
1774   return 1;
1775 }
1776
1777 //=======================================================================
1778 //function : OCC1031_AISMaterial
1779 //purpose  : OCC1031_AISMaterial (DOC,entry,[material])
1780 //=======================================================================
1781
1782 static Standard_Integer OCC1031_AISMaterial (Draw_Interpretor& di,
1783                                          Standard_Integer nb,
1784                                          const char ** arg)
1785 {
1786   if (nb >= 3) {     
1787     Handle(TDocStd_Document) D;
1788     if (!DDocStd::GetDocument(arg[1],D)) return 1;  
1789     TDF_Label L;
1790     if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;  
1791
1792     Handle(TPrsStd_AISViewer) viewer;
1793     if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;  
1794
1795     Handle(TPrsStd_AISPresentation) prs;
1796     if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {   
1797       if( nb == 4 ) {
1798         prs->SetMaterial((Graphic3d_NameOfMaterial)Draw::Atoi(arg[3]));
1799         TPrsStd_AISViewer::Update(L);
1800       }
1801       else {
1802          di << "Material = " << prs->Material() << "\n";
1803       }
1804       return 0;
1805     }
1806   }
1807   di << arg[0] << " : Error\n";
1808   return 1;
1809 }
1810
1811 //=======================================================================
1812 //function : OCC1032_AISWidth
1813 //purpose  : OCC1032_AISWidth (DOC,entry,[width])
1814 //=======================================================================
1815
1816 static Standard_Integer OCC1032_AISWidth (Draw_Interpretor& di,
1817                                       Standard_Integer nb, 
1818                                       const char ** arg) 
1819 {
1820   if (nb >= 3) {     
1821     Handle(TDocStd_Document) D;
1822     if (!DDocStd::GetDocument(arg[1],D)) return 1;  
1823     TDF_Label L;
1824     if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;  
1825
1826     Handle(TPrsStd_AISViewer) viewer;
1827     if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;  
1828
1829     Handle(TPrsStd_AISPresentation) prs;
1830     if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {   
1831       if( nb == 4 ) {
1832         prs->SetWidth(Draw::Atof(arg[3]));
1833         TPrsStd_AISViewer::Update(L);
1834       }
1835       else {
1836          di << "Width = " << prs->Width() << "\n";
1837       }
1838       return 0;
1839     }
1840   }
1841   di << arg[0] << " : Error\n";
1842   return 1;
1843 }
1844
1845 //=======================================================================
1846 //function : OCC1033_AISMode
1847 //purpose  : OCC1033_AISMode (DOC,entry,[mode])
1848 //=======================================================================
1849
1850 static Standard_Integer OCC1033_AISMode (Draw_Interpretor& di,
1851                                      Standard_Integer nb, 
1852                                      const char ** arg) 
1853 {
1854   if (nb >= 3) {     
1855     Handle(TDocStd_Document) D;
1856     if (!DDocStd::GetDocument(arg[1],D)) return 1;  
1857     TDF_Label L;
1858     if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;  
1859
1860     Handle(TPrsStd_AISViewer) viewer;
1861     if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;  
1862
1863     Handle(TPrsStd_AISPresentation) prs;
1864     if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {   
1865       if( nb == 4 ) {
1866         prs->SetMode(Draw::Atoi(arg[3]));
1867         TPrsStd_AISViewer::Update(L);
1868       }
1869       else {
1870          di << "Mode = " << prs->Mode() << "\n";
1871       }
1872       return 0;
1873     }
1874   }
1875   di << arg[0] << " : Error\n";
1876   return 1;
1877 }
1878
1879 //=======================================================================
1880 //function : OCC1034_AISSelectionMode
1881 //purpose  : OCC1034_AISSelectionMode (DOC,entry,[selectionmode])
1882 //=======================================================================
1883
1884 static Standard_Integer OCC1034_AISSelectionMode (Draw_Interpretor& di,
1885                                               Standard_Integer nb, 
1886                                               const char ** arg) 
1887 {
1888   if (nb >= 3) {     
1889     Handle(TDocStd_Document) D;
1890     if (!DDocStd::GetDocument(arg[1],D)) return 1;  
1891     TDF_Label L;
1892     if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;  
1893
1894     Handle(TPrsStd_AISViewer) viewer;
1895     if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;  
1896
1897     Handle(TPrsStd_AISPresentation) prs;
1898     if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {   
1899       if( nb == 4 ) {
1900         prs->SetSelectionMode(Draw::Atoi(arg[3]));
1901         TPrsStd_AISViewer::Update(L);
1902       }
1903       else {
1904          di << "SelectionMode = " << prs->SelectionMode() << "\n";
1905       }
1906       return 0;
1907     }
1908   }
1909   di << arg[0] << " : Error\n";
1910   return 1;
1911 }
1912
1913 //=======================================================================
1914 //function :  OCC1487
1915 //purpose  :
1916 //=======================================================================
1917 static Standard_Integer OCC1487 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1918 {
1919   if(argc != 5) {
1920     di << "Usage : " << argv[0] << " CylinderVariant(=1/2) cylinder1 cylinder2 cutshape\n";
1921     return 1;
1922   }
1923
1924   Standard_Integer CaseNumber = Draw::Atoi(argv[1]);
1925
1926   //BRepPrimAPI_MakeCylinder o_mc1 (gp_Ax2 (gp_Pnt(0,-50,140), gp_Dir(1,0,0)), 50,1000);
1927   gp_Dir myDir(1,0,0);
1928   gp_Pnt myPnt(0,-50,140);
1929   gp_Ax2 myAx2(myPnt, myDir);
1930   BRepPrimAPI_MakeCylinder o_mc1 (myAx2, 50,1000);
1931
1932   TopoDS_Shape cyl1 = o_mc1.Shape();
1933
1934   TopoDS_Shape cyl2;
1935   TopoDS_Shape o_cut_shape;
1936   if (CaseNumber == 1) {
1937     //BRepPrimAPI_MakeCylinder o_mc2 (gp_Ax2 (gp_Pnt(21.65064, -50.0, 127.5),gp_Dir(-sin(M_PI/3), 0.0, 0.5)), 5, 150);
1938     gp_Dir myDir_mc2(-sin(M_PI/3), 0.0, 0.5);
1939     gp_Pnt myPnt_mc2(21.65064, -50.0, 127.5);
1940     gp_Ax2 myAx2_mc2(myPnt_mc2, myDir_mc2);
1941     BRepPrimAPI_MakeCylinder o_mc2 (myAx2_mc2, 5, 150);
1942
1943     cyl2 = o_mc2.Shape();
1944     di << "o_cut_shape = BRepAlgoAPI_Cut (o_mc1.Solid (), o_mc2.Solid ())\n";
1945     o_cut_shape = BRepAlgoAPI_Cut (o_mc1.Solid (), o_mc2.Solid ()).Shape();
1946   } else {
1947     //BRepPrimAPI_MakeCylinder o_mc2 (gp_Ax2 (gp_Pnt(978.34936, -50.0, 127.5),gp_Dir(sin(M_PI/3), 0.0, 0.5)), 5, 150);
1948     gp_Dir myDir_mc2(sin(M_PI/3), 0.0, 0.5);
1949     gp_Pnt myPnt_mc2(978.34936, -50.0, 127.5);
1950     gp_Ax2 myAx2_mc2(myPnt_mc2, myDir_mc2);
1951     BRepPrimAPI_MakeCylinder o_mc2 (myAx2_mc2, 5, 150);
1952
1953     cyl2 = o_mc2.Shape();
1954     di << "o_cut_shape = BRepAlgoAPI_Cut (o_mc1.Solid (), o_mc2.Solid ())\n";
1955     o_cut_shape = BRepAlgoAPI_Cut (o_mc1.Solid (), o_mc2.Solid ()).Shape();
1956   }
1957
1958   DBRep::Set(argv[2],cyl1);
1959   DBRep::Set(argv[3],cyl2);
1960   DBRep::Set(argv[4],o_cut_shape);
1961
1962   return 0;
1963 }
1964
1965 #include<TopTools_ListIteratorOfListOfShape.hxx>
1966 #include<BRepFilletAPI_MakeFillet.hxx>
1967 //=======================================================================
1968 //function :  OCC1077
1969 //purpose  :
1970 //=======================================================================
1971 TopoDS_Shape OCC1077_boolbl(BRepAlgoAPI_BooleanOperation& aBoolenaOperation,const Standard_Real aRadius)
1972 {
1973   Standard_Real t3d = 1.e-4;
1974   Standard_Real t2d = 1.e-5;
1975   Standard_Real ta  = 1.e-2;
1976   Standard_Real fl  = 1.e-3;
1977   Standard_Real tapp_angle = 1.e-2;
1978   GeomAbs_Shape blend_cont = GeomAbs_C1;
1979
1980   TopoDS_Shape ShapeCut = aBoolenaOperation.Shape();
1981
1982   TopTools_ListIteratorOfListOfShape its;
1983
1984   TopoDS_Compound result;
1985   BRep_Builder B;
1986   B.MakeCompound(result);
1987
1988   TopExp_Explorer ex;
1989   for (ex.Init(ShapeCut, TopAbs_SOLID); ex.More(); ex.Next())
1990     {
1991       const TopoDS_Shape& cutsol = ex.Current();
1992
1993       BRepFilletAPI_MakeFillet fill(cutsol);
1994       fill.SetParams(ta, t3d, t2d, t3d, t2d, fl);
1995       fill.SetContinuity(blend_cont, tapp_angle);
1996       its = aBoolenaOperation.SectionEdges();
1997       while (its.More())
1998         {
1999           TopoDS_Edge E = TopoDS::Edge(its.Value());
2000           fill.Add(aRadius, E);
2001           its.Next();
2002         }
2003
2004       fill.Build();
2005       if (fill.IsDone())
2006         {
2007           B.Add(result, fill.Shape());
2008         }
2009       else
2010         {
2011           B.Add(result, cutsol);
2012         }
2013     }
2014   return result;
2015 }
2016
2017 TopoDS_Shape OCC1077_cut_blend(const TopoDS_Shape& aShapeToCut, const TopoDS_Shape& aTool, const Standard_Real aRadius)
2018 {
2019   //return OCC1077_boolbl(BRepAlgoAPI_Cut(aShapeToCut, aTool),aRadius);
2020   BRepAlgoAPI_Cut aCut(aShapeToCut, aTool);
2021   return OCC1077_boolbl(aCut,aRadius);
2022 }
2023
2024 //TopoDS_Shape OCC1077_common_blend(const TopoDS_Shape& aShape1, const TopoDS_Shape& aShape2, const Standard_Real aRadius)
2025 //{
2026 //  return OCC1077_boolbl(BRepAlgoAPI_Common(aShape1, aShape2),aRadius);
2027 //}
2028
2029 TopoDS_Shape OCC1077_Bug()
2030 {
2031   TopoDS_Shape theBox = BRepPrimAPI_MakeBox(gp_Pnt(-5, - 5, - 5), 10, 10, 10).Shape();
2032   TopoDS_Shape theSphere = BRepPrimAPI_MakeSphere(7).Shape();
2033
2034   TopoDS_Shape theCommon = BRepAlgoAPI_Common(theBox,theSphere);
2035   TopoDS_Shape theCylinder1 = BRepPrimAPI_MakeCylinder(gp_Ax2(gp_Pnt(0, 0, - 10),
2036                                                               gp_Dir(0, 0, 1)), 3, 20).Shape();
2037   TopoDS_Shape theCylinder2 = BRepPrimAPI_MakeCylinder(gp_Ax2(gp_Pnt(-10, 0, 0),
2038                                                               gp_Dir(1, 0, 0)), 3, 20).Shape();
2039   TopoDS_Shape theCylinder3 = BRepPrimAPI_MakeCylinder(gp_Ax2(gp_Pnt(0, - 10, 0),
2040                                                               gp_Dir(0, 1, 0)), 3, 20).Shape();
2041   TopoDS_Shape theTmp1 = OCC1077_cut_blend(theCommon,theCylinder1,0.7);
2042   Handle(ShapeFix_Shape) fixer = new ShapeFix_Shape(theTmp1);
2043   fixer->Perform();
2044   theTmp1 = fixer->Shape();
2045   TopoDS_Shape theTmp2 = OCC1077_cut_blend(theTmp1,theCylinder2,0.7);
2046   fixer->Init(theTmp2);
2047   fixer->Perform();
2048   theTmp2 = fixer->Shape();
2049   TopoDS_Shape theResult = OCC1077_cut_blend(theTmp2,theCylinder3,0.7);
2050   fixer->Init(theResult);
2051   fixer->Perform();
2052   theResult = fixer->Shape();
2053   return theResult;
2054 }
2055
2056 static Standard_Integer OCC1077 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2057 {
2058   if(argc < 1 || argc > 2) {
2059     di << "Usage : " << argv[0] << " result\n";
2060     return 1;
2061   }
2062
2063   TopoDS_Shape S = OCC1077_Bug();
2064   DBRep::Set(argv[1],S);
2065
2066   return 0;
2067 }
2068
2069 //////////////////////////////////////////////////////////////
2070 /*!
2071  * Compute uniform distribution of points using GCPnts_UniformAbscissa
2072  */
2073 //////////////////////////////////////////////////////////////
2074 static Standard_Integer OCC5739_UniAbs (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2075 {
2076   if (argc < 4)
2077   {
2078     di << "Usage : " << argv[0] << " name shape step\n";
2079     return 1;
2080   }
2081   const char *name = argv[1];
2082   Adaptor3d_Curve *adapCurve=NULL;
2083   Handle(Geom_Curve) curve = DrawTrSurf::GetCurve(argv[2]);
2084   if (!curve.IsNull())
2085     adapCurve = new GeomAdaptor_Curve(curve);
2086   else
2087   {
2088     TopoDS_Shape wire = DBRep::Get(argv[2]);
2089     if (wire.IsNull() || wire.ShapeType() != TopAbs_WIRE)
2090     {
2091       di << argv[0] <<" Faulty : incorrect 1st parameter, curve or wire expected\n";
2092       return 1;
2093     }
2094     adapCurve = new BRepAdaptor_CompCurve(TopoDS::Wire(wire));
2095   }
2096   double step = Draw::Atof(argv[3]);
2097   GCPnts_UniformAbscissa aUni(*adapCurve, step);
2098   int res;
2099   if (!aUni.IsDone())
2100   {
2101     di << argv[0] <<" : fail\n";
2102     res = 1;
2103   }
2104   else
2105   {
2106     int i, np = aUni.NbPoints();
2107     for (i=0; i < np; i++)
2108     {
2109       double par = aUni.Parameter(i+1);
2110       gp_Pnt p = adapCurve->Value(par);
2111       char n[20], *pname=n;
2112       Sprintf(n,"%s_%d",name,i+1);
2113       DrawTrSurf::Set(pname,p);
2114       di<<pname<<" ";
2115     }
2116     res = 0;
2117   }
2118   delete adapCurve;
2119   return res;
2120 }
2121
2122 static Standard_Integer OCC6046 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2123 {
2124   if (argc != 3)
2125   {
2126     di << "Usage : " << argv[0] << " nb_of_vectors size\n";
2127     return 1;
2128   }
2129
2130   Standard_Integer nb = Draw::Atoi(argv[1]);
2131   Standard_Integer sz = Draw::Atoi(argv[2]);
2132   Standard_Real val = 10;
2133   math_Vector **pv = new math_Vector *[nb];
2134
2135   di<<"creating "<<nb<<" vectors "<<sz<<" elements each...\n";
2136   Standard_Integer i;
2137   for (i=0; i < nb; i++) {
2138     pv[i] = new math_Vector (1, sz, val);
2139     if ((i % (nb/10)) == 0) {
2140       di<<" "<<i;
2141       //std::cout.flush();
2142       di<<"\n";
2143     }
2144   }
2145   di<<" done\n";
2146   di<<"deleting them ...\n";
2147   for (i=0; i < nb; i++) {
2148     delete pv[i];
2149     if ((i % (nb/10)) == 0) {
2150       di<<" "<<i;
2151       //std::cout.flush();
2152       di<<"\n";
2153     }
2154   }
2155   di<<" done\n";
2156
2157   delete [] pv;
2158
2159   return 0;
2160 }
2161
2162 static Standard_Integer OCC5698 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2163 {
2164   if (argc != 2)
2165   {
2166     di << "Usage : " << argv[0] << " wire\n";
2167     return 1;
2168   }
2169   TopoDS_Shape shape = DBRep::Get(argv[1],TopAbs_WIRE);
2170   if (shape.IsNull())
2171     return 1;
2172   TopoDS_Wire wire = TopoDS::Wire(shape);
2173   // create curve parameterised by curvilinear distance
2174   BRepAdaptor_CompCurve curve(wire,Standard_True);
2175   Standard_Real length = curve.LastParameter();
2176   Standard_Real need_length = length/2;
2177   gp_Pnt pnt;
2178   curve.D0(need_length,pnt);
2179   // create check_curve parameterised in a general way
2180   BRepAdaptor_CompCurve check_curve(wire);
2181   Standard_Real check_par =
2182     GCPnts_AbscissaPoint(check_curve, need_length, 0).Parameter();
2183   gp_Pnt check_pnt;
2184   check_curve.D0(check_par,check_pnt);
2185   // check that points are coinsiding
2186   Standard_Real error_dist = pnt.Distance(check_pnt);
2187   if (error_dist > Precision::Confusion()) {
2188     //std::cout.precision(3);
2189     di<<"error_dist = "<<error_dist<<
2190       "  ( "<<error_dist/need_length*100<<" %)\n";
2191     return 0;
2192   }
2193   di<<"OK\n";
2194   return 0;
2195 }
2196
2197 // stack overflow can be successfully handled only on 32-bit Windows
2198 #if defined(_WIN32) && !defined(_WIN64)
2199 static int StackOverflow (int i = -1)
2200 {
2201   char arr[2000];
2202   memset (arr, 0, sizeof(arr));
2203   if (i < 0)
2204     StackOverflow(i-1);
2205   return i;
2206 }
2207 #endif
2208
2209 // this code does not work with optimize mode on Windows
2210 #if defined(_MSC_VER)
2211 #pragma optimize( "", off )
2212 #endif
2213 static Standard_Integer OCC6143 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2214 {
2215   if (argc != 1)
2216     {
2217       std::cout << "Usage : " << argv[0] << "\n";
2218       return 1;
2219     }
2220   Standard_Boolean Succes;
2221   
2222   Succes = Standard_True;
2223   //OSD::SetSignal();
2224
2225   {//==== Test Divide ByZero (Integer) ========================================
2226     try{
2227       OCC_CATCH_SIGNALS
2228       std::cout << "(Integer) Divide By Zero..." << std::endl;
2229       di << "(Integer) Divide By Zero...";
2230       //std::cout.flush();
2231       di << "\n";
2232       Standard_Integer res, a =4, b = 0 ;
2233       res = a / b;
2234       di << "Error: 4 / 0 = " << res << " - no exception is raised!\n";
2235       Succes = Standard_False;
2236     }
2237 #if defined(SOLARIS) || defined(_WIN32)
2238     catch(Standard_DivideByZero const&)
2239 #else
2240     catch(Standard_NumericError const&)
2241 #endif
2242     {
2243       di << "Caught, OK\n";
2244     }
2245     catch(Standard_Failure const& anException) {
2246       di << " Caught (";
2247       di << anException.GetMessageString();
2248       di << ")... KO\n";
2249       Succes = Standard_False;
2250     }
2251     // this case tests if (...) supersedes (Standard_*),
2252     // the normal behaviour is not
2253     catch(...) {
2254       di<<" unknown exception... (But) Ok\n";
2255     }
2256   }
2257
2258   {//==== Test Divide ByZero (Real) ===========================================
2259     try{
2260       OCC_CATCH_SIGNALS
2261       std::cout << "(Real) Divide By Zero..." << std::endl;
2262       di << "(Real) Divide By Zero...";
2263       //std::cout.flush();
2264       di << "\n";
2265       Standard_Real res, a= 4.0, b=0.0;
2266       res = a / b;
2267       di << "Error: 4.0 / 0.0 = " << res << " - no exception is raised!\n";
2268       Succes = Standard_False;
2269     }
2270     catch(Standard_DivideByZero const&) // Solaris, Windows w/o SSE2
2271     {
2272       di << "Caught, OK\n";
2273     }
2274     catch(Standard_NumericError const&) // Linux, Windows with SSE2
2275     {
2276       di << "Caught, OK\n";
2277     }
2278     catch(Standard_Failure const& anException) {
2279       //std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
2280       di << " Caught (";
2281       di << anException.GetMessageString();
2282       di << ")... KO\n";
2283       Succes = Standard_False;
2284     }
2285   }
2286
2287   {//==== Test Overflow (Integer) =============================================
2288     try{
2289       OCC_CATCH_SIGNALS
2290       std::cout << "(Integer) Overflow..." << std::endl;
2291       di << "(Integer) Overflow...";
2292       //std::cout.flush();
2293       di << "\n";
2294       Standard_Integer res, i=IntegerLast();
2295       res = i + 1;
2296       //++++ std::cout << " -- "<<res<<"="<<i<<"+1   Does not Caught... KO"<< std::endl;
2297       //++++ Succes = Standard_False;
2298       di << "Not caught: " << i << " + 1 = " << res << ", still OK\n";
2299     }
2300     catch(Standard_Overflow const&) {
2301       di << "Caught, OK\n";
2302     }
2303     catch(Standard_Failure const& anException) {
2304       //std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
2305       di << " Caught (";
2306       di << anException.GetMessageString();
2307       di << ")... KO\n";
2308       Succes = Standard_False;
2309     }
2310   }
2311
2312   {//==== Test Overflow (Real) ================================================ 
2313     try{
2314       OCC_CATCH_SIGNALS
2315       std::cout << "(Real) Overflow..." << std::endl;
2316       di << "(Real) Overflow...";
2317       //std::cout.flush();
2318       di << "\n";
2319       Standard_Real res, r=RealLast();
2320       res = r * r;
2321       
2322       (void)sin(1.); //this function tests FPU flags and raises signal (tested on LINUX).
2323
2324       di << "Error: " << r << "*" << r << " = " << res << " - no exception is raised!\n";
2325       Succes = Standard_False;
2326     }
2327     catch(Standard_Overflow const&) // Solaris, Windows w/o SSE2
2328     {
2329       di << "Caught, OK\n";
2330     }
2331     catch(Standard_NumericError const&) // Linux, Windows with SSE2
2332     {
2333       di << "Caught, OK\n";
2334     }
2335     catch(Standard_Failure const& anException) {
2336       //std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
2337       di << " Caught (";
2338       di << anException.GetMessageString();
2339       di << ")... KO\n";
2340       Succes = Standard_False;
2341     }
2342   }
2343
2344   {//==== Test Underflow (Real) ===============================================
2345     try{
2346       OCC_CATCH_SIGNALS
2347       std::cout << "(Real) Underflow" << std::endl; // to have message in log even if process crashed
2348       di << "(Real) Underflow";
2349       //std::cout.flush();
2350       di << "\n";
2351       Standard_Real res, r = RealSmall();
2352       res = r * r;
2353       //res = res + 1.;
2354       //++++ std::cout<<"-- "<<res<<"="<<r<<"*"<<r<<"   Does not Caught... KO"<<std::endl;
2355       //++++ Succes = Standard_False;
2356       di << "Not caught: " << r << "*" << r << " = " << res << ", still OK\n";
2357     }
2358     catch(Standard_Underflow const&) // could be on Solaris, Windows w/o SSE2
2359     {
2360       di << "Exception caught, KO\n";
2361       Succes = Standard_False;
2362     }
2363     catch(Standard_NumericError const&) // could be on Linux, Windows with SSE2
2364     {
2365       di << "Exception caught, KO\n";
2366       Succes = Standard_False;
2367     }
2368     catch(Standard_Failure const& anException) {
2369       //std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
2370       di << " Caught (";
2371       di << anException.GetMessageString();
2372       di << ")... KO\n";
2373       Succes = Standard_False;
2374     }
2375   }
2376
2377   {//==== Test Invalid Operation (Real) ===============================================
2378     try{
2379       OCC_CATCH_SIGNALS
2380       std::cout << "(Real) Invalid Operation..." << std::endl;
2381       di << "(Real) Invalid Operation...";
2382       //std::cout.flush();
2383       di << "\n";
2384       Standard_Real res, r=-1;
2385       res = sqrt(r);
2386       di << "Error: swrt(-1) = " << res << " - no exception is raised!\n";
2387       Succes = Standard_False;
2388     }
2389     catch(Standard_NumericError const&) {
2390       di << "Caught, OK\n";
2391     }
2392     catch(Standard_Failure const& anException) {
2393       //std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
2394       di << " Caught (";
2395       di << anException.GetMessageString();
2396       di << ")... KO\n";
2397       Succes = Standard_False;
2398     }
2399   }
2400
2401   {//==== Test Access Violation ===============================================
2402     try {
2403       OCC_CATCH_SIGNALS
2404       std::cout << "Segmentation Fault..." << std::endl;
2405       di << "Segmentation Fault...";
2406       //std::cout.flush();
2407       di << "\n";
2408       int* pint=NULL;
2409       *pint = 4;
2410       di << "Error: writing by NULL address - no exception is raised!\n";
2411       Succes = Standard_False;
2412     }
2413 #ifdef _WIN32
2414     catch(OSD_Exception_ACCESS_VIOLATION const&)
2415 #else
2416     catch(OSD_SIGSEGV const&)
2417 #endif
2418     {
2419       di << "Caught, OK\n";
2420     } catch(Standard_Failure const& anException) {
2421       //std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
2422       di << " Caught (";
2423       di << anException.GetMessageString();
2424       di << ")... KO\n";
2425       Succes = Standard_False;
2426     }
2427   }
2428
2429 #if defined(_WIN32) && !defined(_WIN64)
2430   {//==== Test Stack Overflow ===============================================
2431     try {
2432       OCC_CATCH_SIGNALS
2433       std::cout << "Stack Overflow..." << std::endl;
2434       di << "Stack Overflow...";
2435       //std::cout.flush();
2436       di << "\n";
2437       StackOverflow();
2438       di << "Error - no exception is raised!\n";
2439       Succes = Standard_False;
2440     }
2441     catch(OSD_Exception_STACK_OVERFLOW const&) {
2442       di << "Caught, OK\n";
2443     }
2444     catch(Standard_Failure const& anException) {
2445       //std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
2446       di << " Caught (";
2447       di << anException.GetMessageString();
2448       di << ")... KO\n";
2449       Succes = Standard_False;
2450     }
2451   }
2452 #endif
2453
2454  if(Succes) {
2455    di << "TestExcept: Successfull completion\n";
2456  } else {
2457    di << "TestExcept: failure\n";
2458  }
2459
2460   return 0;
2461 }
2462
2463 //! Auxiliary functor.
2464 struct TestParallelFunctor
2465 {
2466   TestParallelFunctor() : myNbNotRaised (0), myNbSigSegv (0), myNbUnknown (0) {}
2467
2468   Standard_Integer NbNotRaised() const { return myNbNotRaised; }
2469   Standard_Integer NbSigSegv()   const { return myNbSigSegv; }
2470   Standard_Integer NbUnknown()   const { return myNbUnknown; }
2471
2472   void operator() (int theThreadId, int theTaskId) const
2473   {
2474     (void )theThreadId;
2475     (void )theTaskId;
2476
2477     // Test Access Violation
2478     {
2479       try {
2480         OCC_CATCH_SIGNALS
2481         int* pint = NULL;
2482         *pint = 4;
2483         Standard_Atomic_Increment (&myNbNotRaised);
2484       }
2485     #ifdef _WIN32
2486       catch (OSD_Exception_ACCESS_VIOLATION const&)
2487     #else
2488       catch (OSD_SIGSEGV const&)
2489     #endif
2490       {
2491         Standard_Atomic_Increment (&myNbSigSegv);
2492       }
2493       catch (Standard_Failure const& )
2494       {
2495         Standard_Atomic_Increment (&myNbUnknown);
2496       }
2497     }
2498   }
2499 private:
2500   mutable volatile Standard_Integer myNbNotRaised;
2501   mutable volatile Standard_Integer myNbSigSegv;
2502   mutable volatile Standard_Integer myNbUnknown;
2503 };
2504
2505 static Standard_Integer OCC30775 (Draw_Interpretor& theDI, Standard_Integer theNbArgs, const char** )
2506 {
2507   if (theNbArgs != 1)
2508   {
2509     std::cout << "Syntax error: wrong number of arguments\n";
2510     return 1;
2511   }
2512
2513   Handle(OSD_ThreadPool) aPool = new OSD_ThreadPool (4);
2514   OSD_ThreadPool::Launcher aLauncher (*aPool, 4);
2515   TestParallelFunctor aFunctor;
2516   aLauncher.Perform (0, 100, aFunctor);
2517   theDI << "NbRaised: "    << (aFunctor.NbSigSegv() + aFunctor.NbUnknown()) << "\n"
2518         << "NbNotRaised: " << aFunctor.NbNotRaised() << "\n"
2519         << "NbSigSeg: "    << aFunctor.NbSigSegv() << "\n"
2520         << "NbUnknown: "   << aFunctor.NbUnknown() << "\n";
2521   return 0;
2522 }
2523
2524 #if defined(_MSC_VER)
2525 #pragma optimize( "", on )
2526 #endif
2527
2528 static TopoDS_Compound AddTestStructure(int nCount_)
2529 {
2530   BRep_Builder B;
2531   int nCount=nCount_;
2532   TopoDS_Compound C;
2533   B.MakeCompound(C);
2534   BRepPrimAPI_MakeBox mkBox(1.0, 2.0, 3.0);
2535   for (int i=0; i<nCount; i++) {
2536     for (int j=0; j<nCount; j++) {
2537       gp_Trsf trsf;
2538       trsf.SetTranslationPart(gp_Vec(5.0*i, 05.0*j, 0.0));
2539       TopLoc_Location topLoc(trsf);
2540       TopoDS_Shape tempShape=mkBox.Shape().Located(topLoc);
2541       B.Add(C, tempShape);
2542     }
2543   }
2544   return C;
2545 }
2546
2547 static Standard_Integer OCC7141 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2548 {
2549   if (argc != 2 && argc != 3)
2550   {
2551     std::cout << "Usage : " << argv[0] << " [nCount] path\n";
2552     return 1;
2553   }
2554
2555   int nCount = (argc > 2 ? Draw::Atoi(argv[1]) : 10);
2556   TCollection_AsciiString aFilePath (argv[argc > 2 ? 2 : 1]);
2557   STEPCAFControl_Writer writer;
2558   Handle(TDocStd_Document) document;
2559   document = new TDocStd_Document("Pace Test-StepExporter-");
2560   Handle(XCAFDoc_ShapeTool) shapeTool;
2561   shapeTool = XCAFDoc_DocumentTool::ShapeTool(document->Main());
2562   shapeTool->AddShape(AddTestStructure(nCount), Standard_True);
2563   STEPControl_StepModelType mode = STEPControl_AsIs;
2564   if (!Interface_Static::SetIVal("write.step.assembly",1)) { //assembly mode
2565     di << "Failed to set assembly mode for step data\n\n";
2566     return 0;
2567   }
2568   try {
2569     OCC_CATCH_SIGNALS
2570     if( writer.Transfer(document, mode)) {
2571         writer.Write(aFilePath.ToCString());
2572     }
2573   }
2574   catch(OSD_Exception_STACK_OVERFLOW const&) {
2575     di << "Failed : STACK OVERFLOW\n\n";
2576   }
2577   catch (Standard_Failure const& anException) {
2578     di << "Failed :\n\n";
2579     //std::cout << Standard_Failure::Caught() << std::endl;
2580     di << anException.GetMessageString();
2581   }
2582   di << argv[0] << " : Finish\n";
2583   
2584   return 0;
2585 }
2586
2587 static Standard_Integer OCC7372 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2588 {
2589   if (argc != 1)
2590     {
2591       di << "Usage : " << argv[0] << "\n";
2592       return 1;
2593     }
2594   
2595   // 1. Create an array of points
2596   Handle(TColgp_HArray1OfPnt2d) ap = new TColgp_HArray1OfPnt2d(1,5);
2597   ap->SetValue(1,gp_Pnt2d(100.0,0.0));
2598   ap->SetValue(2,gp_Pnt2d(100.0,100.0));
2599   ap->SetValue(3,gp_Pnt2d(0.0,100.0));
2600   ap->SetValue(4,gp_Pnt2d(0.0,0.0));
2601   ap->SetValue(5,gp_Pnt2d(50.0,-50.0));
2602
2603   // 2. Create a periodic bspline through these 5 points
2604   Geom2dAPI_Interpolate intp(ap,Standard_True,1e-6);
2605   intp.Perform();
2606   Handle(Geom2d_BSplineCurve) bspline1 = intp.Curve();
2607
2608   // 3. Increase degree of curve from 3 to 8
2609   bspline1->IncreaseDegree(8); // Increase degree to demonstrate the error
2610   Standard_CString CString1 = "BSplineCurve";
2611   DrawTrSurf::Set(CString1,bspline1);
2612
2613   // 4. Convers BSpline curve to Bezier segments
2614   Geom2dConvert_BSplineCurveToBezierCurve bc(bspline1);
2615
2616   // 5. Test the result of conversion
2617   TCollection_AsciiString aRName;
2618   for(Standard_Integer i = 1; i <= bc.NbArcs(); i++) {
2619     Handle(Geom2d_BezierCurve) arc = bc.Arc(i);
2620     aRName="segment_";
2621     aRName=aRName+TCollection_AsciiString(i);
2622     Standard_CString aRNameStr = aRName.ToCString();
2623     DrawTrSurf::Set(aRNameStr,arc);
2624     di << aRNameStr << " ";
2625   }
2626
2627   return 0;
2628 }
2629
2630 static Standard_Integer OCC8169 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2631 {
2632   if (argc != 4)
2633   {
2634     di << "Usage : " << argv[0] << " edge1 edge2 plane\n";
2635     return 1;
2636   }
2637   TopoDS_Edge theEdge1 = TopoDS::Edge(DBRep::Get(argv[1],TopAbs_EDGE));
2638   if (theEdge1.IsNull()) {
2639     di << "Invalid input shape " << argv[1] << "\n";
2640     return 1;
2641   }
2642   TopoDS_Edge theEdge2 = TopoDS::Edge(DBRep::Get(argv[2],TopAbs_EDGE));
2643   if (theEdge2.IsNull()) {
2644     di << "Invalid input shape " << argv[2] << "\n";
2645     return 1;
2646   }
2647   TopoDS_Face theFace = TopoDS::Face(DBRep::Get(argv[3],TopAbs_FACE));
2648   if (theFace.IsNull()) {
2649     di << "Invalid input shape " << argv[3] << "\n";
2650     return 1;
2651   }
2652
2653   Handle(Geom_Surface) thePlane = BRep_Tool::Surface(theFace);
2654
2655   Standard_Real aConfusion = Precision::Confusion();
2656   Standard_Real aP1first, aP1last, aP2first, aP2last;
2657
2658   Handle(Geom_Curve) aCurve1 = BRep_Tool::Curve(theEdge1, aP1first, aP1last);
2659   Handle(Geom_Curve) aCurve2 = BRep_Tool::Curve(theEdge2, aP2first, aP2last);
2660   Handle(Geom2d_Curve) aCurve2d1 = GeomProjLib::Curve2d(aCurve1, aP1first, aP1last, thePlane);
2661   Handle(Geom2d_Curve) aCurve2d2 = GeomProjLib::Curve2d(aCurve2, aP2first, aP2last, thePlane);
2662
2663   Geom2dAPI_InterCurveCurve anInter(aCurve2d1, aCurve2d2, aConfusion);
2664
2665   Standard_Integer NbPoints = anInter.NbPoints();
2666
2667   di << "NbPoints = " << NbPoints << "\n" ;
2668
2669   if (NbPoints > 0) {
2670     Standard_Integer i;
2671     for (i=1; i<=NbPoints; i++) {
2672       gp_Pnt2d aPi = anInter.Point(i);
2673       di << "Point.X(" << i << ") = " << aPi.X() << "   Point.Y(" << i << ") = " << aPi.Y() << "\n" ;
2674     }
2675   }
2676
2677   Standard_Integer NbSegments = anInter.NbSegments();
2678
2679   di << "\nNbSegments = " << NbSegments << "\n" ;
2680
2681   if (NbSegments > 0) {
2682     IntRes2d_IntersectionSegment aSegment = anInter.Intersector().Segment(1);
2683
2684     gp_Pnt2d aP1 = aCurve2d1->Value(aSegment.FirstPoint().ParamOnFirst());
2685     gp_Pnt2d aP2 = aCurve2d2->Value(aSegment.FirstPoint().ParamOnSecond());
2686   
2687     Standard_Real aDist = aP1.Distance(aP2);
2688   
2689     di << "aP1.X() = " << aP1.X() << "   aP1.Y() = " << aP1.Y() << "\n" ;
2690     di << "aP2.X() = " << aP2.X() << "   aP2.Y() = " << aP2.Y() << "\n" ;
2691
2692     di << "Distance = " << aDist << "\n" ;
2693
2694     di << "Confusion = " << aConfusion << "\n" ;
2695
2696     if (aDist > aConfusion) {
2697       di << "\n" << argv[0] << " Faulty\n" ;
2698     } else {
2699       di << "\n" << argv[0] << " OK\n" ;
2700     }
2701   } else {
2702     di << "\n" << argv[0] << " OK\n" ;
2703   }
2704
2705   return 0;
2706 }
2707 static Standard_Integer OCC10138 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2708 {
2709   if (argc != 3)
2710   {
2711     di << "Usage : " << argv[0] << " lower upper\n";
2712     return 1;
2713   }
2714
2715   Standard_Integer LOWER = Draw::Atoi(argv[1]);
2716   Standard_Integer UPPER = Draw::Atoi(argv[2]);
2717
2718   //! 0. Create an empty document with several test labels
2719   Handle(TDocStd_Document) doc = new TDocStd_Document("XmlOcaf");
2720   doc->SetUndoLimit(100);
2721   TDF_Label main_label = doc->Main();
2722   TDF_Label label1 = main_label.FindChild(1, Standard_True);
2723   TDF_Label label2 = main_label.FindChild(2, Standard_True);
2724   
2725   //! 1. Set/Get OCAF attribute
2726   doc->OpenCommand();
2727   TDataStd_RealArray::Set(label1, LOWER, UPPER);
2728   Handle(TDataStd_RealArray) array;
2729   if (label1.FindAttribute(TDataStd_RealArray::GetID(), array) && 
2730       array->Lower() == LOWER && array->Upper() == UPPER)
2731     std::cout<<"1: OK"<<std::endl;
2732   else
2733   {
2734     std::cout<<"1: Failed.."<<std::endl;
2735     return 1;
2736   }
2737   doc->CommitCommand();
2738
2739   //! 2. Set/Get value
2740   doc->OpenCommand();
2741   Standard_Integer i;
2742   for (i = LOWER; i <= UPPER; i++)
2743     array->SetValue(i, i);
2744   for (i = LOWER; i <= UPPER; i++)
2745   {  
2746     if (array->Value(i) != i)
2747     {
2748       std::cout<<"2: Failed.."<<std::endl;
2749       return 2;
2750     }
2751   }
2752   std::cout<<"2: OK"<<std::endl;
2753   doc->CommitCommand();
2754
2755   //! 3. Re-init the array
2756   doc->OpenCommand();
2757   array->Init(LOWER + 2, UPPER + 4);
2758   if (array->Lower() != LOWER + 2 && array->Upper() != UPPER + 4)
2759   {
2760     std::cout<<"3: Failed.."<<std::endl;
2761     return 3;
2762   }
2763   for (i = LOWER + 2; i <= UPPER + 4; i++)
2764     array->SetValue(i, i);
2765   for (i = LOWER + 2; i <= UPPER + 4; i++)
2766   {  
2767     if (array->Value(i) != i)
2768     {
2769       std::cout<<"3: Failed.."<<std::endl;
2770       return 3;
2771     }
2772   }
2773   std::cout<<"3: OK"<<std::endl;
2774   doc->CommitCommand();
2775
2776   //! 4. Change array
2777   doc->OpenCommand();
2778   Handle(TColStd_HArray1OfReal) arr = new TColStd_HArray1OfReal(LOWER + 5, UPPER + 5);
2779   for (i = LOWER + 5; i <= UPPER + 5; i++)
2780     arr->SetValue(i, i);
2781   array->ChangeArray(arr);
2782   for (i = LOWER + 5; i <= UPPER + 5; i++)
2783   {  
2784     if (array->Value(i) != i)
2785     {
2786       std::cout<<"4: Failed.."<<std::endl;
2787       return 4;
2788     }
2789   }
2790   std::cout<<"4: OK"<<std::endl;
2791   doc->CommitCommand();
2792
2793   //! 5. Copy the array
2794   doc->OpenCommand();
2795   TDF_CopyLabel copier(label1, label2);
2796   copier.Perform();
2797   if (!copier.IsDone())
2798   {
2799     std::cout<<"5: Failed.."<<std::endl;
2800     return 5;
2801   }
2802   Handle(TDataStd_RealArray) array2;
2803   if (!label2.FindAttribute(TDataStd_RealArray::GetID(), array2))
2804   {
2805     std::cout<<"5: Failed.."<<std::endl;
2806     return 5;
2807   }
2808   for (i = LOWER + 5; i <= UPPER + 5; i++)
2809   {  
2810     if (array->Value(i) != i)
2811     {
2812       std::cout<<"5: Failed.."<<std::endl;
2813       return 5;
2814     }
2815   }
2816   std::cout<<"5: OK"<<std::endl;
2817   doc->CommitCommand();
2818
2819   //! 6. Undo/Redo
2820   //! 6.a: undoes the 5th action: the copied array should disappear
2821   doc->Undo();
2822   if (!label1.FindAttribute(TDataStd_RealArray::GetID(), array) ||
2823       label2.FindAttribute(TDataStd_RealArray::GetID(), array2))
2824   {
2825     std::cout<<"6.a: Failed.."<<std::endl;
2826     return 6;
2827   }
2828   //! 6.b: undoes the 4th action: the array should be changed to (lower+2,upper+4)
2829   doc->Undo();
2830   if (!label1.FindAttribute(TDataStd_RealArray::GetID(), array) || 
2831       array->Lower() != LOWER + 2 ||
2832       array->Upper() != UPPER + 4)
2833   {
2834     std::cout<<"6.b: Failed.."<<std::endl;
2835     return 6;
2836   }
2837   for (i = LOWER + 2; i <= UPPER + 4; i++)
2838   {
2839     if (array->Value(i) != i)
2840     {
2841       std::cout<<"6.b: Failed.."<<std::endl;
2842       return 6;
2843     }
2844   }
2845   //! 6.c: undoes the 3d action: the array should be changed to (lower,upper)
2846   doc->Undo();
2847   if (!label1.FindAttribute(TDataStd_RealArray::GetID(), array) || 
2848       array->Lower() != LOWER ||
2849       array->Upper() != UPPER)
2850   {
2851     std::cout<<"6.c: Failed.."<<std::endl;
2852     return 6;
2853   }
2854   for (i = LOWER; i <= UPPER; i++)
2855   {
2856     if (array->Value(i) != i)
2857     {
2858       std::cout<<"6.c: Failed.."<<std::endl;
2859       return 6;
2860     }
2861   }
2862   //! 6.d: undoes and redoes the 2nd action: no change is expected.
2863   doc->Undo();
2864   doc->Redo();
2865   if (!label1.FindAttribute(TDataStd_RealArray::GetID(), array) || 
2866       array->Lower() != LOWER ||
2867       array->Upper() != UPPER)
2868   {
2869     std::cout<<"6.d: Failed.."<<std::endl;
2870     return 6;
2871   }
2872   for (i = LOWER; i <= UPPER; i++)
2873   {
2874     if (array->Value(i) != i)
2875     {
2876       std::cout<<"6.d: Failed.."<<std::endl;
2877       return 6;
2878     }
2879   }
2880   std::cout<<"6: OK"<<std::endl;
2881
2882   //! 7. Re-set the array
2883   doc->OpenCommand();
2884   array = TDataStd_RealArray::Set(label1, LOWER + 1, UPPER + 1);
2885   if (array->Lower() != LOWER + 1 && array->Upper() != UPPER + 1)
2886   {
2887     std::cout<<"7: Failed.."<<std::endl;
2888     return 7;
2889   }
2890   for (i = LOWER + 1; i <= UPPER + 1; i++)
2891     array->SetValue(i, i);
2892   for (i = LOWER + 1; i <= UPPER + 1; i++)
2893   {  
2894     if (array->Value(i) != i)
2895     {
2896       std::cout<<"7: Failed.."<<std::endl;
2897       return 7;
2898     }
2899   }
2900   std::cout<<"7: OK"<<std::endl;
2901   doc->CommitCommand();
2902
2903   //! 8.Test of speed: set LOWER and UPPER equal to great integer number and 
2904   //! measure the time spent by this test.
2905   //! Good luck!
2906
2907   return 0;
2908 }
2909
2910 static Standard_Integer OCC7639 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2911 {
2912   Standard_Boolean IsEvenArgc =  Standard_True;
2913   if (argc % 2 == 0) {
2914     IsEvenArgc =  Standard_True;
2915   } else {
2916     IsEvenArgc =  Standard_False;
2917   }
2918
2919   if (argc < 3 || IsEvenArgc)
2920     {
2921       di << "Usage : " << argv[0] << " index1 value1 ... [indexN valueN]\n";
2922       return 1;
2923     }
2924
2925   Standard_Integer i, aValue, aPosition;
2926   NCollection_Vector<int> vec;
2927   for (i = 0; i < argc - 1; i++) {
2928     i++;
2929     aValue = Draw::Atoi(argv[i]);
2930     aPosition = Draw::Atoi(argv[i+1]);
2931     vec.SetValue(aValue, aPosition);
2932   }
2933   NCollection_Vector<int>::Iterator it(vec);
2934   Standard_Integer j;
2935   for (j = 0; it.More(); it.Next(), j++) {
2936     //di << it.Value() << "\n";                                               
2937     di << j << " " << it.Value() << "\n";                                               
2938   }
2939
2940   return 0;
2941 }
2942
2943 static Standard_Integer OCC8797 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2944 {
2945   if (argc != 1) {
2946     di << "Usage : " << argv[0] << "\n";
2947     return 1;
2948   }
2949
2950   gp_Pnt point(0.0,0.0,0.0);
2951
2952   TColgp_Array1OfPnt poles(0,6);
2953   poles(0)=point;
2954
2955   point.SetCoord(1.0,1.0,0.0);
2956   poles(1)=point;
2957
2958   point.SetCoord(2.0,1.0,0.0);
2959   poles(2)=point;
2960
2961   point.SetCoord(3.0,0.0,0.0);
2962   poles(3)=point;
2963
2964   point.SetCoord(4.0,1.0,0.0);
2965   poles(4)=point;
2966
2967   point.SetCoord(5.0,1.0,0.0);
2968   poles(5)=point;
2969
2970   point.SetCoord(6.0,0.0,0.0);
2971   poles(6)=point;
2972
2973   TColStd_Array1OfReal knots(0,2);
2974   knots(0)=0.0;
2975   knots(1)=0.5;
2976   knots(2)=1.0;
2977
2978   TColStd_Array1OfInteger multi(0,2);
2979   multi(0)=4;
2980   multi(1)=3;
2981   multi(2)=4;
2982
2983   Handle(Geom_BSplineCurve) spline = new Geom_BSplineCurve(poles,knots,multi,3);
2984
2985   //length!! 1.
2986   Standard_Real l_abcissa,l_gprop;
2987   GeomAdaptor_Curve adaptor_spline(spline);
2988   GCPnts_AbscissaPoint temp;
2989   l_abcissa=temp.Length(adaptor_spline);
2990   std::cout<<"Length Spline(abcissa_Pnt): "<<l_abcissa<<std::endl;
2991
2992   //length!! 2.
2993   TopoDS_Edge edge = BRepBuilderAPI_MakeEdge (spline);
2994   GProp_GProps prop;
2995   BRepGProp::LinearProperties(edge,prop);
2996   l_gprop=prop.Mass();
2997   std::cout<<"Length Spline(GProp_GProps): "<<l_gprop<<std::endl;
2998
2999   std::cout<<"Difference (abcissa_Pnt<->GProp_GProps): "<<l_gprop-l_abcissa<<std::endl;
3000
3001   return 0;
3002 }
3003
3004 static Standard_Integer OCC7068 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
3005 {
3006   if (argc != 1)
3007   {
3008     di << "Usage : " << argv[0] << "\n";
3009     return 1;
3010   }
3011
3012   Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3013   if(AISContext.IsNull())
3014   {
3015     di << "use 'vinit' command before " << argv[0] << "\n";
3016     return 1;
3017   }
3018
3019   // ObjectsInside
3020   AIS_ListOfInteractive ListOfIO_1;
3021   AISContext->ObjectsInside(ListOfIO_1);
3022   di<< "ObjectsInside = " << ListOfIO_1.Extent() <<"\n";
3023   if (!ListOfIO_1.IsEmpty() ) {
3024     AIS_ListIteratorOfListOfInteractive iter;
3025     for (iter.Initialize(ListOfIO_1); iter.More() ; iter.Next() ) {
3026       Handle(AIS_InteractiveObject) aIO=iter.Value();
3027       di<< GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
3028     }
3029   }
3030
3031   return 0;
3032 }
3033
3034 static Standard_Integer OCC11457 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
3035 {
3036   if ((argc < 9) || (((argc-3) % 3) != 0))
3037   {
3038     di << "Usage : " << argv[0] << "polygon lastedge x1 y1 z1 x2 y2 z2 ...\n";
3039     return 1;
3040   }
3041   Standard_Integer i, j, np = (argc-3) / 3;
3042   BRepBuilderAPI_MakePolygon W;
3043   j = 3;
3044   for (i = 1; i <= np; i ++) {
3045     W.Add(gp_Pnt(Draw::Atof(argv[j]),Draw::Atof(argv[j+1]),Draw::Atof(argv[j+2])));
3046     j += 3;
3047   }
3048   W.Close();
3049   DBRep::Set(argv[1],W.Wire());
3050   DBRep::Set(argv[2],W.Edge());
3051   return 0;
3052 }
3053
3054 static Standard_Integer OCC13963 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
3055 {
3056   if (argc < 5) {
3057     di << "Usage : " << argv[0] << " ratio origin_x origin_y origin_z\n";
3058     return 1;
3059   }
3060   gp_Ax2 aPln (gp_Pnt(0.,0.,0.),
3061                gp_Dir(1., -1., 0.));
3062   gp_GTrsf aTrf;
3063   aTrf.SetAffinity (aPln, Draw::Atof(argv[4]));
3064   gp_XYZ aOrigin (Draw::Atof(argv[1]),Draw::Atof(argv[2]),Draw::Atof(argv[3]));
3065   gp_XYZ aResult (aOrigin);
3066   aTrf.Transforms(aResult);
3067   char sbf[512];
3068   Sprintf(sbf, "( %8.3f %8.3f %8.3f ) => ( %8.3f %8.3f %8.3f )\n",
3069           aOrigin.X(), aOrigin.Y(), aOrigin.Z(),
3070           aResult.X(), aResult.Y(), aResult.Z());
3071   di<<sbf;
3072   return 0;
3073 }
3074
3075 Standard_Integer OCC14376(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
3076 {
3077   if (argc < 2) {
3078     di << "Usage : " << argv[0] << " shape [deflection]\n";
3079     return 1;
3080   }
3081
3082   TopoDS_Shape aShape = DBRep::Get(argv[1]);
3083
3084   if (aShape.IsNull()) {
3085     di<<" Null shape is not allowed";
3086     return 1;
3087   }
3088
3089   Standard_Real aDeflection = 0.45110277533;
3090   if (argc > 2) {
3091     aDeflection = Draw::Atof(argv[2]);
3092   }
3093   di<<"deflection="<< aDeflection << "\n";
3094
3095   BRepMesh_IncrementalMesh aIMesh(aShape, aDeflection, Standard_False, M_PI / 9.);
3096   TopLoc_Location aLocation;
3097   Handle(Poly_Triangulation) aTriang = BRep_Tool::Triangulation(TopoDS::Face(aShape), aLocation);
3098
3099   if(aTriang.IsNull()) {
3100     di << argv[0] << " : Faulty\n" ;
3101   } else {
3102     di << argv[0] << " : OK\n" ;
3103     di<<"NbNodes="<< aTriang->NbNodes()<< "\n";
3104     di<<"NbTriangles="<< aTriang->NbTriangles()<< "\n";
3105   }
3106   return 0;
3107 }
3108
3109 static Standard_Integer OCC15489 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
3110 {
3111   if (argc != 4) {
3112     di << "Usage : " << argv[0] << " A B C\n";
3113     return 1;
3114   }
3115   try
3116     {
3117       gp_Lin2d aLin2d (Draw::Atof(argv[1]),Draw::Atof(argv[2]),Draw::Atof(argv[3]));
3118       gp_Pnt2d anOrigin = aLin2d.Location();
3119       di << "X_0 = " << anOrigin.X() << "   Y_0 = " << anOrigin.Y() << "\n" ;
3120     }
3121   catch(Standard_ConstructionError const&)
3122     {
3123       di << argv[0] << " Exception: Sqrt(A*A + B*B) <= Resolution from gp\n";
3124     }
3125   return 0;
3126 }
3127
3128 static Standard_Integer OCC15755 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
3129 {
3130   if (argc != 3) {
3131     di << "Usage : " << argv[0] << " file shape\n";
3132     return 1;
3133   }
3134
3135   IGESControl_Reader aReader;
3136   aReader.ReadFile(argv[1]);
3137   aReader.SetReadVisible(Standard_True);
3138   aReader.TransferRoots();
3139
3140   Handle(IGESData_IGESModel) model = aReader.IGESModel();
3141   if (model.IsNull()) {
3142     di << "model.IsNull()\n";
3143     return 1;
3144   }
3145   Standard_Integer nb = model->NbEntities();
3146   for (Standard_Integer i = 1; i <= nb; i ++) {
3147     Handle(IGESData_IGESEntity) ent = model->Entity(i);
3148     Handle(TCollection_HAsciiString) name;
3149     name = ent->NameValue();
3150     Standard_CString aStr = name->ToCString();
3151     di << "NameValue = " << aStr << "\n";
3152   }
3153
3154   TopoDS_Shape shape = aReader.OneShape();
3155   DBRep::Set(argv[2],shape);
3156   return 0;
3157 }
3158
3159 // For OCC16782 testing
3160 #include <AppStd_Application.hxx>
3161 #include <TDF_Tool.hxx>
3162 #include <TColStd_HArray1OfInteger.hxx>
3163 // Iterators
3164 #include <TColStd_ListIteratorOfListOfInteger.hxx>
3165 #include <TColStd_ListIteratorOfListOfReal.hxx>
3166 #include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
3167 #include <TDataStd_ListIteratorOfListOfByte.hxx>
3168 #include <TDF_ListIteratorOfLabelList.hxx>
3169 // Attributes
3170 #include <TDataStd_Tick.hxx>
3171 #include <TDataStd_IntegerList.hxx>
3172 #include <TDataStd_RealList.hxx>
3173 #include <TDataStd_ExtStringList.hxx>
3174 #include <TDataStd_BooleanList.hxx>
3175 #include <TDataStd_ReferenceList.hxx>
3176 #include <TDataStd_BooleanArray.hxx>
3177 #include <TDataStd_ReferenceArray.hxx>
3178 #include <TDataStd_ByteArray.hxx>
3179 #include <TDataStd_NamedData.hxx>
3180 #include <TDF_Reference.hxx>
3181 //
3182 Handle(AppStd_Application) app;
3183 int TestSetGet(const Handle(TDocStd_Document)& doc)
3184 {
3185   // TDataStd_Tick:
3186   // Set
3187   TDataStd_Tick::Set(doc->Main());
3188   // Get
3189   Handle(TDataStd_Tick) tick;
3190   if (!doc->Main().FindAttribute(TDataStd_Tick::GetID(), tick))
3191     return 1;
3192   // Forget
3193   doc->Main().ForgetAttribute(TDataStd_Tick::GetID());
3194   if (doc->Main().IsAttribute(TDataStd_Tick::GetID()))
3195     return 2;
3196   doc->Main().ResumeAttribute(tick);
3197   if (!doc->Main().IsAttribute(TDataStd_Tick::GetID()))
3198     return 3;
3199   // Forget
3200   doc->Main().ForgetAttribute(TDataStd_Tick::GetID());
3201   if (doc->Main().IsAttribute(TDataStd_Tick::GetID()))
3202     return 2;
3203
3204   // TDataStd_IntegerList:
3205   // Set
3206   Handle(TDataStd_IntegerList) setintlist = TDataStd_IntegerList::Set(doc->Main());
3207   setintlist->Append(2);
3208   setintlist->Prepend(1);
3209   setintlist->InsertAfter(3, 2);
3210   setintlist->InsertBefore(0, 1);
3211   setintlist->Append(200);
3212   setintlist->Remove(0);
3213   setintlist->Remove(200);
3214   // Get
3215   Handle(TDataStd_IntegerList) getintlist;
3216   if (!doc->Main().FindAttribute(TDataStd_IntegerList::GetID(), getintlist))
3217     return 1;
3218   if (getintlist->First() != 1)
3219     return 2;
3220   if (getintlist->Last() != 3)
3221     return 3;
3222   const TColStd_ListOfInteger& intlist = getintlist->List();
3223   TColStd_ListIteratorOfListOfInteger itr_intlist(intlist);
3224   for (; itr_intlist.More(); itr_intlist.Next())
3225   {
3226     if (itr_intlist.Value() != 1 &&
3227         itr_intlist.Value() != 2 &&
3228         itr_intlist.Value() != 3)
3229     {
3230       return 4;
3231     }
3232   }
3233   getintlist->Clear();
3234
3235   // TDataStd_RealList:
3236   // Set
3237   Handle(TDataStd_RealList) setdbllist = TDataStd_RealList::Set(doc->Main());
3238   setdbllist->Append(2.5);
3239   setdbllist->Prepend(1.5);
3240   setdbllist->InsertAfter(3.5, 2.5);
3241   setdbllist->InsertBefore(0.5, 1.5);
3242   setdbllist->Append(200.5);
3243   setdbllist->Remove(0.5);
3244   setdbllist->Remove(200.5);
3245   // Get
3246   Handle(TDataStd_RealList) getdbllist;
3247   if (!doc->Main().FindAttribute(TDataStd_RealList::GetID(), getdbllist))
3248     return 1;
3249   if (getdbllist->First() != 1.5)
3250     return 2;
3251   if (getdbllist->Last() != 3.5)
3252     return 3;
3253   const TColStd_ListOfReal& dbllist = getdbllist->List();
3254   TColStd_ListIteratorOfListOfReal itr_dbllist(dbllist);
3255   for (; itr_dbllist.More(); itr_dbllist.Next())
3256   {
3257     if (itr_dbllist.Value() != 1.5 &&
3258         itr_dbllist.Value() != 2.5 &&
3259         itr_dbllist.Value() != 3.5)
3260     {
3261       return 4;
3262     }
3263   }
3264   getdbllist->Clear();
3265
3266   // TDataStd_ExtStringList:
3267   // Set
3268   Handle(TDataStd_ExtStringList) setstrlist = TDataStd_ExtStringList::Set(doc->Main());
3269   setstrlist->Append("Hello");
3270   setstrlist->Prepend("Guten Tag");
3271   setstrlist->InsertAfter("Bonjour", "Guten Tag");
3272   setstrlist->InsertBefore("Bonsoir", "Hello");
3273   setstrlist->Append("Good bye");
3274   setstrlist->Remove("Bonsoir");
3275   setstrlist->Remove("Good bye");
3276   // Get
3277   Handle(TDataStd_ExtStringList) getstrlist;
3278   if (!doc->Main().FindAttribute(TDataStd_ExtStringList::GetID(), getstrlist))
3279     return 1;
3280   if (getstrlist->First() != "Guten Tag")
3281     return 2;
3282   if (getstrlist->Last() != "Hello")
3283     return 3;
3284   const TDataStd_ListOfExtendedString& strlist = getstrlist->List();
3285   TDataStd_ListIteratorOfListOfExtendedString itr_strlist(strlist);
3286   for (; itr_strlist.More(); itr_strlist.Next())
3287   {
3288     if (itr_strlist.Value() != "Guten Tag" &&
3289         itr_strlist.Value() != "Bonjour" &&
3290         itr_strlist.Value() != "Hello")
3291     {
3292       return 4;
3293     }
3294   }
3295   getstrlist->Clear();
3296
3297   // TDataStd_BooleanList:
3298   // Set
3299   Handle(TDataStd_BooleanList) setboollist = TDataStd_BooleanList::Set(doc->Main());
3300   setboollist->Append(Standard_True);
3301   setboollist->Prepend(Standard_False);
3302   // Get
3303   Handle(TDataStd_BooleanList) getboollist;
3304   if (!doc->Main().FindAttribute(TDataStd_BooleanList::GetID(), getboollist))
3305     return 1;
3306   if (getboollist->First() != Standard_False)
3307     return 2;
3308   if (getboollist->Last() != Standard_True)
3309     return 3;
3310   const TDataStd_ListOfByte& boollist = getboollist->List();
3311   for (TDataStd_ListIteratorOfListOfByte itr_boollist(boollist); itr_boollist.More(); itr_boollist.Next())
3312   {
3313     if (itr_boollist.Value() != 1
3314      && itr_boollist.Value() != 0)
3315     {
3316       return 4;
3317     }
3318   }
3319   getboollist->Clear();
3320
3321   // TDataStd_ReferenceList:
3322   TDF_Label L1 = doc->Main().FindChild(100);
3323   TDF_Label L2 = doc->Main().FindChild(101);
3324   TDF_Label L3 = doc->Main().FindChild(102);
3325   TDF_Label L4 = doc->Main().FindChild(103);
3326   TDF_Label L5 = doc->Main().FindChild(104);
3327   // Set
3328   Handle(TDataStd_ReferenceList) setreflist = TDataStd_ReferenceList::Set(doc->Main());
3329   setreflist->Append(L1);
3330   setreflist->Prepend(L2);
3331   setreflist->InsertAfter(L3, L2);
3332   setreflist->InsertBefore(L4, L1);
3333   setreflist->Append(L5);
3334   setreflist->Remove(L4);
3335   setreflist->Remove(L5);
3336   // Get
3337   Handle(TDataStd_ReferenceList) getreflist;
3338   if (!doc->Main().FindAttribute(TDataStd_ReferenceList::GetID(), getreflist))
3339     return 1;
3340   if (getreflist->First() != L2)
3341     return 2;
3342   if (getreflist->Last() != L1)
3343     return 3;
3344   const TDF_LabelList& reflist = getreflist->List();
3345   TDF_ListIteratorOfLabelList itr_reflist(reflist);
3346   for (; itr_reflist.More(); itr_reflist.Next())
3347   {
3348     if (itr_reflist.Value() != L1 &&
3349         itr_reflist.Value() != L2 &&
3350         itr_reflist.Value() != L3)
3351     {
3352       return 4;
3353     }
3354   }
3355   getreflist->Clear();
3356
3357   // TDataStd_BooleanArray:
3358   // Set
3359   Handle(TDataStd_BooleanArray) setboolarr = TDataStd_BooleanArray::Set(doc->Main(), 12, 16);
3360   setboolarr->SetValue(12, Standard_True);
3361   setboolarr->SetValue(13, Standard_False);
3362   setboolarr->SetValue(14, Standard_False);
3363   setboolarr->SetValue(15, Standard_False);
3364   setboolarr->SetValue(16, Standard_True);
3365   setboolarr->SetValue(14, Standard_True);
3366   // Get
3367   Handle(TDataStd_BooleanArray) getboolarr;
3368   if (!doc->Main().FindAttribute(TDataStd_BooleanArray::GetID(), getboolarr))
3369     return 1;
3370   if (getboolarr->Value(12) != Standard_True)
3371     return 2;
3372   if (getboolarr->Value(13) != Standard_False)
3373     return 2;
3374   if (getboolarr->Value(14) != Standard_True)
3375     return 2;
3376   if (getboolarr->Value(15) != Standard_False)
3377     return 2;
3378   if (getboolarr->Value(16) != Standard_True)
3379     return 2;
3380
3381   // TDataStd_ReferenceArray:
3382   // Set
3383   Handle(TDataStd_ReferenceArray) setrefarr = TDataStd_ReferenceArray::Set(doc->Main(), 0, 4);
3384   setrefarr->SetValue(0, L1);
3385   setrefarr->SetValue(1, L2);
3386   setrefarr->SetValue(2, L3);
3387   setrefarr->SetValue(3, L4);
3388   setrefarr->SetValue(4, L5);
3389   // Get
3390   Handle(TDataStd_ReferenceArray) getrefarr;
3391   if (!doc->Main().FindAttribute(TDataStd_ReferenceArray::GetID(), getrefarr))
3392     return 1;
3393   if (getrefarr->Value(0) != L1)
3394     return 2;
3395   if (getrefarr->Value(1) != L2)
3396     return 2;
3397   if (getrefarr->Value(2) != L3)
3398     return 2;
3399   if (getrefarr->Value(3) != L4)
3400     return 2;
3401   if (getrefarr->Value(4) != L5)
3402     return 2;
3403
3404   // TDataStd_ByteArray:
3405   // Set
3406   Handle(TDataStd_ByteArray) setbytearr = TDataStd_ByteArray::Set(doc->Main(), 12, 16);
3407   setbytearr->SetValue(12, 0);
3408   setbytearr->SetValue(13, 1);
3409   setbytearr->SetValue(14, 2);
3410   setbytearr->SetValue(15, 3);
3411   setbytearr->SetValue(16, 255);
3412   // Get
3413   Handle(TDataStd_ByteArray) getbytearr;
3414   if (!doc->Main().FindAttribute(TDataStd_ByteArray::GetID(), getbytearr))
3415     return 1;
3416   if (getbytearr->Value(12) != 0)
3417     return 2;
3418   if (getbytearr->Value(13) != 1)
3419     return 2;
3420   if (getbytearr->Value(14) != 2)
3421     return 2;
3422   if (getbytearr->Value(15) != 3)
3423     return 2;
3424   if (getbytearr->Value(16) != 255)
3425     return 2;
3426   
3427   // TDataStd_NamedData:
3428   // Set:
3429   Handle(TDataStd_NamedData) setnd = TDataStd_NamedData::Set(doc->Main());
3430   setnd->SetInteger("Integer1", 1);
3431   setnd->SetInteger("Integer2", 2);
3432   setnd->SetInteger("Integer3", 8);
3433   setnd->SetInteger("Integer3", 3);
3434   // Get:
3435   Handle(TDataStd_NamedData) getnd;
3436   if (!doc->Main().FindAttribute(TDataStd_NamedData::GetID(), getnd))
3437     return 1;
3438   if (!getnd->HasIntegers())
3439     return 2;
3440   if (!getnd->HasInteger("Integer1"))
3441     return 3;
3442   if (getnd->GetInteger("Integer2") != 2)
3443     return 4;
3444   if (getnd->GetInteger("Integer3") != 3)
3445     return 4;
3446
3447   return 0;
3448 }
3449
3450 int TestUndoRedo(const Handle(TDocStd_Document)& doc)
3451 {
3452   // TDataStd_Tick:
3453   doc->OpenCommand();
3454   Handle(TDataStd_Tick) tick = TDataStd_Tick::Set(doc->Main());
3455   doc->CommitCommand();
3456   if (!doc->Main().IsAttribute(TDataStd_Tick::GetID()))
3457     return 1;
3458   doc->Undo();
3459   if (doc->Main().IsAttribute(TDataStd_Tick::GetID()))
3460     return 2;
3461   doc->Redo();
3462   if (!doc->Main().IsAttribute(TDataStd_Tick::GetID()))
3463     return 3;
3464
3465   // TDataStd_IntegerList:
3466   doc->OpenCommand();
3467   Handle(TDataStd_IntegerList) intlist = TDataStd_IntegerList::Set(doc->Main());
3468   intlist->Append(2);
3469   intlist->Prepend(1);
3470   intlist->InsertBefore(0, 1);
3471   intlist->InsertAfter(3, 2);
3472   doc->CommitCommand();
3473   if (!doc->Main().IsAttribute(TDataStd_IntegerList::GetID()))
3474     return 1;
3475   doc->Undo();
3476   if (!intlist->IsEmpty())
3477     return 2;
3478   doc->Redo();
3479   if (!intlist->Extent())
3480     return 3;
3481   if (intlist->First() != 0)
3482     return 4;
3483   if (intlist->Last() != 3)
3484     return 5;
3485   intlist->Clear();
3486
3487   // TDataStd_RealList:
3488   doc->OpenCommand();
3489   Handle(TDataStd_RealList) dbllist = TDataStd_RealList::Set(doc->Main());
3490   dbllist->Append(2.5);
3491   dbllist->Prepend(1.5);
3492   dbllist->InsertBefore(0.5, 1.5);
3493   dbllist->InsertAfter(3.5, 2.5);
3494   doc->CommitCommand();
3495   if (!doc->Main().IsAttribute(TDataStd_RealList::GetID()))
3496     return 1;
3497   doc->Undo();
3498   if (!dbllist->IsEmpty())
3499     return 2;
3500   doc->Redo();
3501   if (!dbllist->Extent())
3502     return 3;
3503   if (dbllist->First() != 0.5)
3504     return 4;
3505   if (dbllist->Last() != 3.5)
3506     return 5;
3507   dbllist->Clear();
3508
3509   // TDataStd_ExtStringList:
3510   doc->OpenCommand();
3511   Handle(TDataStd_ExtStringList) strlist = TDataStd_ExtStringList::Set(doc->Main());
3512   strlist->Append("Hello");
3513   strlist->Prepend("Guten Tag");
3514   strlist->InsertAfter("Bonjour", "Guten Tag");
3515   strlist->InsertBefore("Bonsoir", "Hello");
3516   doc->CommitCommand();
3517   if (!doc->Main().IsAttribute(TDataStd_ExtStringList::GetID()))
3518     return 1;
3519   doc->Undo();
3520   if (!strlist->IsEmpty())
3521     return 2;
3522   doc->Redo();
3523   if (!strlist->Extent())
3524     return 3;
3525   if (strlist->First() != "Guten Tag")
3526     return 4;
3527   if (strlist->Last() != "Hello")
3528     return 5;
3529   strlist->Clear();
3530
3531   // TDataStd_BooleanList:
3532   doc->OpenCommand();
3533   Handle(TDataStd_BooleanList) boollist = TDataStd_BooleanList::Set(doc->Main());
3534   boollist->Append(Standard_True);
3535   boollist->Prepend(Standard_False);
3536   doc->CommitCommand();
3537   if (!doc->Main().IsAttribute(TDataStd_BooleanList::GetID()))
3538     return 1;
3539   doc->Undo();
3540   if (!boollist->IsEmpty())
3541     return 2;
3542   doc->Redo();
3543   if (!boollist->Extent())
3544     return 3;
3545   if (boollist->First() != Standard_False)
3546     return 4;
3547   if (boollist->Last() != Standard_True)
3548     return 5;
3549   boollist->Clear();
3550
3551   // TDataStd_ReferenceList:
3552   TDF_Label L1 = doc->Main().FindChild(100);
3553   TDF_Label L2 = doc->Main().FindChild(101);
3554   TDF_Label L3 = doc->Main().FindChild(102);
3555   TDF_Label L4 = doc->Main().FindChild(103);
3556   doc->OpenCommand();
3557   Handle(TDataStd_ReferenceList) reflist = TDataStd_ReferenceList::Set(doc->Main());
3558   reflist->Append(L1);
3559   reflist->Prepend(L2);
3560   reflist->InsertBefore(L3, L1);
3561   reflist->InsertAfter(L4, L2);
3562   doc->CommitCommand();
3563   if (!doc->Main().IsAttribute(TDataStd_ReferenceList::GetID()))
3564     return 1;
3565   doc->Undo();
3566   if (!reflist->IsEmpty())
3567     return 2;
3568   doc->Redo();
3569   if (!reflist->Extent())
3570     return 3;
3571   if (reflist->First() != L2)
3572     return 4;
3573   if (reflist->Last() != L1)
3574     return 5;
3575   reflist->Clear();
3576
3577   // TDataStd_BooleanArray:
3578   doc->OpenCommand();
3579   Handle(TDataStd_BooleanArray) boolarr = TDataStd_BooleanArray::Set(doc->Main(), 23, 25);
3580   boolarr->SetValue(23, Standard_True);
3581   boolarr->SetValue(25, Standard_True);
3582   doc->CommitCommand();
3583   doc->OpenCommand();
3584   boolarr = TDataStd_BooleanArray::Set(doc->Main(), 230, 250);
3585   boolarr->SetValue(230, Standard_True);
3586   boolarr->SetValue(250, Standard_True);  
3587   doc->CommitCommand();
3588   doc->Undo();
3589   if (boolarr->Value(23) != Standard_True)
3590     return 2;
3591   if (boolarr->Value(24) != Standard_False)
3592     return 2;
3593   if (boolarr->Value(25) != Standard_True)
3594     return 2;
3595   doc->Redo();
3596   if (boolarr->Value(230) != Standard_True)
3597     return 3;
3598   if (boolarr->Value(240) != Standard_False)
3599     return 3;
3600   if (boolarr->Value(250) != Standard_True)
3601     return 3;
3602
3603   // TDataStd_ReferenceArray:
3604   doc->OpenCommand();
3605   Handle(TDataStd_ReferenceArray) refarr = TDataStd_ReferenceArray::Set(doc->Main(), 5, 8);
3606   refarr->SetValue(5, L1);
3607   refarr->SetValue(6, L2);
3608   refarr->SetValue(7, L3);
3609   refarr->SetValue(8, L4);
3610   doc->CommitCommand();
3611   if (!doc->Main().IsAttribute(TDataStd_ReferenceArray::GetID()))
3612     return 1;
3613   doc->Undo();
3614   doc->Redo();
3615   if (refarr->Value(5) != L1)
3616     return 4;
3617   if (refarr->Value(6) != L2)
3618     return 4;
3619   if (refarr->Value(7) != L3)
3620     return 4;
3621   if (refarr->Value(8) != L4)
3622     return 4;
3623
3624   // TDataStd_ByteArray:
3625   doc->OpenCommand();
3626   Handle(TDataStd_ByteArray) bytearr = TDataStd_ByteArray::Set(doc->Main(), 23, 25);
3627   bytearr->SetValue(23, 23);
3628   bytearr->SetValue(25, 25);
3629   doc->CommitCommand();
3630   doc->OpenCommand();
3631   bytearr = TDataStd_ByteArray::Set(doc->Main(), 230, 250);
3632   bytearr->SetValue(230, 230);
3633   bytearr->SetValue(250, 250);  
3634   doc->CommitCommand();
3635   doc->Undo();
3636   if (bytearr->Value(23) != 23)
3637     return 2;
3638   if (bytearr->Value(25) != 25)
3639     return 2;
3640   doc->Redo();
3641   if (bytearr->Value(230) != 230)
3642     return 3;
3643   if (bytearr->Value(250) != 250)
3644     return 3;
3645
3646   // TDataStd_NamedData:
3647   doc->OpenCommand();
3648   Handle(TDataStd_NamedData) nd = TDataStd_NamedData::Set(doc->Main());
3649   nd->SetByte("b14", 12);
3650   nd->SetByte("b17", 18);
3651   nd->SetByte("b14", 14);
3652   nd->SetByte("b17", 17);
3653   doc->CommitCommand();
3654   doc->OpenCommand();
3655   nd = TDataStd_NamedData::Set(doc->Main());
3656   nd->SetReal("r14", 14);
3657   nd->SetReal("r17", 17);
3658   nd->SetReal("r14", 14.4);
3659   nd->SetReal("r17", 17.7);
3660   doc->CommitCommand();
3661   doc->Undo();
3662   if (nd->HasStrings())
3663     return 1;
3664   if (nd->HasReals())
3665     return 1;
3666   if (nd->HasReal("r17"))
3667     return 2;
3668   if (!nd->HasBytes())
3669     return 3;
3670   if (nd->GetByte("b14") != 14)
3671     return 4;
3672   if (nd->GetByte("b17") != 17)
3673     return 4;
3674   if (nd->HasByte("b18"))
3675     return 5;
3676   doc->Redo();
3677   if (!nd->HasBytes())
3678     return 1;
3679   if (!nd->HasReals())
3680     return 1;
3681   if (nd->GetByte("b14") != 14)
3682     return 2;
3683   if (nd->GetReal("r14") != 14.4)
3684     return 2;
3685   if (nd->GetReal("r17") != 17.7)
3686     return 2;
3687
3688   return 0;
3689 }
3690
3691 int TestCopyPaste(const Handle(TDocStd_Document)& doc)
3692 {
3693   TDF_Label L1 = doc->Main().FindChild(1);
3694   TDF_Label L2 = doc->Main().FindChild(2);
3695   TDF_CopyLabel copier(L1, L2);
3696
3697   // TDataStd_Tick:
3698   TDataStd_Tick::Set(L1);
3699   copier.Perform();
3700   if (!copier.IsDone())
3701     return 1;
3702   if (!L2.IsAttribute(TDataStd_Tick::GetID()))
3703     return 2;
3704
3705   // TDataStd_IntegerList:
3706   Handle(TDataStd_IntegerList) intlist = TDataStd_IntegerList::Set(L1);
3707   intlist->Append(1);
3708   intlist->InsertAfter(2, 1);
3709   copier.Perform();
3710   if (!copier.IsDone())
3711     return 1;
3712   intlist->Clear();
3713   intlist.Nullify();
3714   if (!L2.FindAttribute(TDataStd_IntegerList::GetID(), intlist))
3715     return 2;
3716   if (intlist->First() != 1)
3717     return 3;
3718   if (intlist->Last() != 2)
3719     return 4;
3720   intlist->Clear();
3721
3722   // TDataStd_RealList:
3723   Handle(TDataStd_RealList) dbllist = TDataStd_RealList::Set(L1);
3724   dbllist->Append(1.5);
3725   dbllist->InsertAfter(2.5, 1.5);
3726   copier.Perform();
3727   if (!copier.IsDone())
3728     return 1;
3729   dbllist->Clear();
3730   dbllist.Nullify();
3731   if (!L2.FindAttribute(TDataStd_RealList::GetID(), dbllist))
3732     return 2;
3733   if (dbllist->First() != 1.5)
3734     return 3;
3735   if (dbllist->Last() != 2.5)
3736     return 4;
3737   dbllist->Clear();
3738
3739   // TDataStd_ExtStringList:
3740   Handle(TDataStd_ExtStringList) strlist = TDataStd_ExtStringList::Set(L1);
3741   strlist->Append("Open CASCADE");
3742   strlist->InsertAfter(" - is the best set of libraries!", "Open CASCADE");
3743   copier.Perform();
3744   if (!copier.IsDone())
3745     return 1;
3746   strlist->Clear();
3747   strlist.Nullify();
3748   if (!L2.FindAttribute(TDataStd_ExtStringList::GetID(), strlist))
3749     return 2;
3750   if (strlist->First() != "Open CASCADE")
3751     return 3;
3752   if (strlist->Last() != " - is the best set of libraries!")
3753     return 4;
3754   strlist->Clear();
3755
3756   // TDataStd_BooleanList:
3757   Handle(TDataStd_BooleanList) boollist = TDataStd_BooleanList::Set(L1);
3758   boollist->Append(Standard_True);
3759   boollist->Prepend(Standard_False);
3760   copier.Perform();
3761   if (!copier.IsDone())
3762     return 1;
3763   boollist->Clear();
3764   boollist.Nullify();
3765   if (!L2.FindAttribute(TDataStd_BooleanList::GetID(), boollist))
3766     return 2;
3767   if (boollist->First() != Standard_False)
3768     return 3;
3769   if (boollist->Last() != Standard_True)
3770     return 4;
3771   boollist->Clear();
3772
3773   // TDataStd_ReferenceList:
3774   TDF_Label L100 = doc->Main().FindChild(100);
3775   TDF_Label L101 = doc->Main().FindChild(101);
3776   Handle(TDataStd_ReferenceList) reflist = TDataStd_ReferenceList::Set(L1);
3777   reflist->Append(L100);
3778   reflist->InsertAfter(L101, L100);
3779   copier.Perform();
3780   if (!copier.IsDone())
3781     return 1;
3782   reflist->Clear();
3783   reflist.Nullify();
3784   if (!L2.FindAttribute(TDataStd_ReferenceList::GetID(), reflist))
3785     return 2;
3786   if (reflist->First() != L100)
3787     return 3;
3788   if (reflist->Last() != L101)
3789     return 4;
3790   reflist->Clear();
3791
3792   // TDataStd_BooleanArray:
3793   Handle(TDataStd_BooleanArray) boolarr = TDataStd_BooleanArray::Set(L1, 4, 6);
3794   boolarr->SetValue(4, Standard_True);
3795   boolarr->SetValue(6, Standard_True);
3796   copier.Perform();
3797   if (!copier.IsDone())
3798     return 1;
3799   boolarr.Nullify();
3800   if (!L2.FindAttribute(TDataStd_BooleanArray::GetID(), boolarr))
3801     return 2;
3802   if (boolarr->Value(4) != Standard_True)
3803     return 3;
3804   if (boolarr->Value(5) != Standard_False)
3805     return 3;
3806   if (boolarr->Value(6) != Standard_True)
3807     return 3;
3808
3809   // TDataStd_ReferenceArray:
3810   Handle(TDataStd_ReferenceArray) refarr = TDataStd_ReferenceArray::Set(L1, 3, 4);
3811   refarr->SetValue(3, L100);
3812   refarr->SetValue(4, L101);
3813   copier.Perform();
3814   if (!copier.IsDone())
3815     return 1;
3816   refarr.Nullify();
3817   if (!L2.FindAttribute(TDataStd_ReferenceArray::GetID(), refarr))
3818     return 2;
3819   if (refarr->Value(3) != L100)
3820     return 3;
3821   if (refarr->Value(4) != L101)
3822     return 3;
3823
3824   // TDataStd_ByteArray:
3825   Handle(TDataStd_ByteArray) bytearr = TDataStd_ByteArray::Set(L1, 4, 6);
3826   bytearr->SetValue(4, 40);
3827   bytearr->SetValue(6, 60);
3828   copier.Perform();
3829   if (!copier.IsDone())
3830     return 1;
3831   bytearr.Nullify();
3832   if (!L2.FindAttribute(TDataStd_ByteArray::GetID(), bytearr))
3833     return 2;
3834   if (bytearr->Value(4) != 40)
3835     return 3;
3836   if (bytearr->Value(6) != 60)
3837     return 3;
3838
3839   // TDataStd_NamedData:
3840   Handle(TDataStd_NamedData) nd = TDataStd_NamedData::Set(L1);
3841   nd->SetInteger("Integer1", 11);
3842   nd->SetReal("Real1", 11.1);
3843   nd->SetString("String1", "11.11111111");
3844   nd->SetByte("Byte1", 111);
3845   Handle(TColStd_HArray1OfInteger) ints_arr = new TColStd_HArray1OfInteger(4, 5);
3846   ints_arr->SetValue(4, 4);
3847   ints_arr->SetValue(5, 5);
3848   nd->SetArrayOfIntegers("Integers1", ints_arr);
3849   copier.Perform();
3850   if (!copier.IsDone())
3851     return 1;
3852   nd.Nullify();
3853   if (!L2.FindAttribute(TDataStd_NamedData::GetID(), nd))
3854     return 2;
3855   if (!nd->HasIntegers())
3856     return 3;
3857   if (!nd->HasReals())
3858     return 3;
3859   if (!nd->HasStrings())
3860     return 3;
3861   if (!nd->HasBytes())
3862     return 3;
3863   if (!nd->HasArraysOfIntegers())
3864     return 3;
3865   if (nd->HasArraysOfReals())
3866     return 3;
3867   if (!nd->HasInteger("Integer1"))
3868     return 4;
3869   if (nd->GetInteger("Integer1") != 11)
3870     return 4;
3871   if (!nd->HasReal("Real1"))
3872     return 4;
3873   if (nd->GetReal("Real1") != 11.1)
3874     return 4;
3875   if (!nd->HasString("String1"))
3876     return 4;
3877   if (nd->GetString("String1") != "11.11111111")
3878     return 4;
3879   if (!nd->HasByte("Byte1"))
3880     return 4;
3881   if (nd->GetByte("Byte1") != 111)
3882     return 4;
3883   if (!nd->HasArrayOfIntegers("Integers1"))
3884     return 4;
3885   const Handle(TColStd_HArray1OfInteger)& ints_arr_out = nd->GetArrayOfIntegers("Integers1");
3886   if (ints_arr_out.IsNull())
3887     return 4;
3888   if (ints_arr_out->Value(5) != 5)
3889     return 4;
3890
3891   return 0;
3892 }
3893
3894 int TestOpenSave(TCollection_ExtendedString aFile1,
3895                  TCollection_ExtendedString aFile2,
3896                  TCollection_ExtendedString aFile3)
3897 {
3898   // Std
3899   Handle(TDocStd_Document) doc_std, doc_std_open;
3900   app->NewDocument("BinOcaf", doc_std);
3901   // TDataStd_Tick:
3902   TDataStd_Tick::Set(doc_std->Main());
3903   // TDataStd_IntegerList:
3904   Handle(TDataStd_IntegerList) intlist = TDataStd_IntegerList::Set(doc_std->Main());
3905   intlist->Append(1);
3906   intlist->Append(5);
3907   // TDataStd_RealList:
3908   Handle(TDataStd_RealList) dbllist = TDataStd_RealList::Set(doc_std->Main());
3909   dbllist->Append(1.5);
3910   dbllist->Append(5.5);
3911   // TDataStd_ExtStringList:
3912   Handle(TDataStd_ExtStringList) strlist = TDataStd_ExtStringList::Set(doc_std->Main());
3913   strlist->Append("Auf");
3914   strlist->Append("Wiedersehen");
3915   // TDataStd_BooleanList:
3916   Handle(TDataStd_BooleanList) boollist = TDataStd_BooleanList::Set(doc_std->Main());
3917   boollist->Append(Standard_False);
3918   boollist->Append(Standard_True);
3919   // TDataStd_ReferenceList:
3920   TCollection_AsciiString entry1, entry2, entry_first, entry_last;
3921   TDF_Label Lstd1 = doc_std->Main().FindChild(100);
3922   TDF_Tool::Entry(Lstd1, entry1);
3923   TDF_Label Lstd2 = doc_std->Main().FindChild(101);
3924   TDF_Tool::Entry(Lstd2, entry2);
3925   Handle(TDataStd_ReferenceList) reflist = TDataStd_ReferenceList::Set(doc_std->Main());
3926   reflist->Append(Lstd1);
3927   reflist->Append(Lstd2);
3928   // TDataStd_BooleanArray:
3929   Handle(TDataStd_BooleanArray) boolarr = TDataStd_BooleanArray::Set(doc_std->Main(), 15, 18);
3930   boolarr->SetValue(15, Standard_False);
3931   boolarr->SetValue(16, Standard_True);
3932   boolarr->SetValue(17, Standard_True);
3933   boolarr->SetValue(18, Standard_True);
3934   // TDataStd_ReferenceArray:
3935   Handle(TDataStd_ReferenceArray) refarr = TDataStd_ReferenceArray::Set(doc_std->Main(), 45, 46);
3936   refarr->SetValue(45, Lstd1);
3937   refarr->SetValue(46, Lstd2);
3938   // TDataStd_ByteArray:
3939   Handle(TDataStd_ByteArray) bytearr = TDataStd_ByteArray::Set(doc_std->Main(), 15, 18);
3940   bytearr->SetValue(15, 150);
3941   bytearr->SetValue(16, 160);
3942   bytearr->SetValue(17, 170);
3943   bytearr->SetValue(18, 180);
3944   // TDataStd_NamedData:
3945   Handle(TDataStd_NamedData) nameddata = TDataStd_NamedData::Set(doc_std->Main());
3946   // TDF_Reference:
3947   TDF_Label Lstd3 = doc_std->Main().FindChild(103);
3948   Handle(TDF_Reference) ref = TDF_Reference::Set(doc_std->Main(), Lstd3);
3949   // 
3950   // Save
3951   //if (app->SaveAs(doc_std, "W:\\doc.std") != PCDM_SS_OK)
3952   if (app->SaveAs(doc_std, aFile1) != PCDM_SS_OK)
3953     return 1;
3954   intlist.Nullify();
3955   dbllist.Nullify();
3956   strlist.Nullify();
3957   boollist.Nullify();
3958   reflist.Nullify();
3959   boolarr.Nullify();
3960   ref.Nullify();
3961   app->Close(doc_std);
3962   doc_std.Nullify();
3963   //if (app->Open("W:\\doc.std", doc_std_open) != PCDM_RS_OK)
3964   if (app->Open(aFile1, doc_std_open) != PCDM_RS_OK)
3965     return 2;
3966   if (!doc_std_open->Main().IsAttribute(TDataStd_Tick::GetID()))
3967     return 3;
3968   if (!doc_std_open->Main().FindAttribute(TDataStd_IntegerList::GetID(), intlist))
3969     return 4;
3970   if (intlist->First() != 1)
3971     return 5;
3972   if (intlist->Last() != 5)
3973     return 6;
3974   if (!doc_std_open->Main().FindAttribute(TDataStd_RealList::GetID(), dbllist))
3975     return 4;
3976   if (dbllist->First() != 1.5)
3977     return 5;
3978   if (dbllist->Last() != 5.5)
3979     return 6;
3980   if (!doc_std_open->Main().FindAttribute(TDataStd_ExtStringList::GetID(), strlist))
3981     return 4;
3982   if (strlist->First() != "Auf")
3983     return 5;
3984   if (strlist->Last() != "Wiedersehen")
3985     return 6;
3986   if (!doc_std_open->Main().FindAttribute(TDataStd_BooleanList::GetID(), boollist))
3987     return 4;
3988   if (boollist->First() != Standard_False)
3989     return 5;
3990   if (boollist->Last() != Standard_True)
3991     return 6;
3992   if (!doc_std_open->Main().FindAttribute(TDataStd_ReferenceList::GetID(), reflist))
3993     return 4;
3994   TDF_Tool::Entry(reflist->First(), entry_first);
3995   if (entry1 != entry_first)
3996     return 5;
3997   TDF_Tool::Entry(reflist->Last(), entry_last);
3998   if (entry2 != entry_last)
3999     return 6;
4000   if (!doc_std_open->Main().FindAttribute(TDataStd_BooleanArray::GetID(), boolarr))
4001     return 4;
4002   if (boolarr->Value(15) != Standard_False)
4003     return 5;
4004   if (boolarr->Value(16) != Standard_True)
4005     return 5;
4006   if (boolarr->Value(17) != Standard_True)
4007     return 5;
4008   if (boolarr->Value(18) != Standard_True)
4009     return 5;
4010   if (!doc_std_open->Main().FindAttribute(TDataStd_ReferenceArray::GetID(), refarr))
4011     return 4;
4012   TDF_Tool::Entry(refarr->Value(45), entry_first);
4013   if (entry1 != entry_first)
4014     return 5;
4015   TDF_Tool::Entry(refarr->Value(46), entry_last);
4016   if (entry2 != entry_last)
4017     return 6;
4018   if (!doc_std_open->Main().FindAttribute(TDataStd_ByteArray::GetID(), bytearr))
4019     return 4;
4020   if (bytearr->Value(15) != 150)
4021     return 5;
4022   if (bytearr->Value(16) != 160)
4023     return 5;
4024   if (bytearr->Value(17) != 170)
4025     return 5;
4026   if (bytearr->Value(18) != 180)
4027     return 5;
4028   if (!doc_std_open->Main().FindAttribute(TDF_Reference::GetID(), ref))
4029     return 4;
4030   if (ref->Get().IsNull())
4031     return 5;
4032   if (ref->Get().Tag() != 103)
4033       return 5;
4034
4035   // Xml
4036   Handle(TDocStd_Document) doc_xml, doc_xml_open;
4037   app->NewDocument("XmlOcaf", doc_xml);
4038   // TDataStd_Tick:
4039   TDataStd_Tick::Set(doc_xml->Main());
4040   // TDataStd_IntegerList:
4041   intlist = TDataStd_IntegerList::Set(doc_xml->Main());
4042   intlist->Append(1);
4043   intlist->Append(5);
4044   // TDataStd_RealList:
4045   dbllist = TDataStd_RealList::Set(doc_xml->Main());
4046   dbllist->Append(1.5);
4047   dbllist->Append(5.5);
4048   // TDataStd_ExtStringList:
4049   strlist = TDataStd_ExtStringList::Set(doc_xml->Main());
4050   strlist->Append("Guten ");
4051   strlist->Append("Tag");
4052   // TDataStd_BooleanList:
4053   boollist = TDataStd_BooleanList::Set(doc_xml->Main());
4054   boollist->Append(Standard_False);
4055   boollist->Append(Standard_True);
4056   // TDataStd_ReferenceList:
4057   TDF_Label Lxml1 = doc_xml->Main().FindChild(100);
4058   TDF_Tool::Entry(Lxml1, entry1);
4059   TDF_Label Lxml2 = doc_xml->Main().FindChild(101);
4060   TDF_Tool::Entry(Lxml2, entry2);
4061   reflist = TDataStd_ReferenceList::Set(doc_xml->Main());
4062   reflist->Append(Lxml1);
4063   reflist->Append(Lxml2);
4064   // TDataStd_BooleanArray:
4065   boolarr = TDataStd_BooleanArray::Set(doc_xml->Main(), 15, 24);
4066   boolarr->SetValue(15, Standard_False);
4067   boolarr->SetValue(16, Standard_True);
4068   boolarr->SetValue(17, Standard_True);
4069   boolarr->SetValue(18, Standard_True);
4070   boolarr->SetValue(19, Standard_True);
4071   boolarr->SetValue(20, Standard_True);
4072   boolarr->SetValue(21, Standard_False);
4073   boolarr->SetValue(22, Standard_True);
4074   boolarr->SetValue(23, Standard_True);
4075   boolarr->SetValue(24, Standard_True);
4076   // TDataStd_ReferenceArray:
4077   refarr = TDataStd_ReferenceArray::Set(doc_xml->Main(), 444, 445);
4078   refarr->SetValue(444, Lxml1);
4079   refarr->SetValue(445, Lxml2);
4080   // TDataStd_ByteArray:
4081   bytearr = TDataStd_ByteArray::Set(doc_xml->Main(), 15, 24);
4082   bytearr->SetValue(15, 0);
4083   bytearr->SetValue(16, 10);
4084   bytearr->SetValue(17, 100);
4085   bytearr->SetValue(18, 200);
4086   bytearr->SetValue(19, 250);
4087   bytearr->SetValue(20, 251);
4088   bytearr->SetValue(21, 252);
4089   bytearr->SetValue(22, 253);
4090   bytearr->SetValue(23, 254);
4091   bytearr->SetValue(24, 255);
4092   // TDF_Reference:
4093   Lstd3 = doc_xml->Main().FindChild(103);
4094   ref = TDF_Reference::Set(doc_xml->Main(), Lstd3);
4095   // 
4096   // Save
4097   //if (app->SaveAs(doc_xml, "W:\\doc.xml") != PCDM_SS_OK)
4098   if (app->SaveAs(doc_xml, aFile2) != PCDM_SS_OK)
4099     return 1;
4100   intlist.Nullify();
4101   ref.Nullify();
4102   app->Close(doc_xml);
4103   doc_xml.Nullify();
4104   //if (app->Open("W:\\doc.xml", doc_xml_open) != PCDM_RS_OK)
4105   if (app->Open(aFile2, doc_xml_open) != PCDM_RS_OK)
4106     return 2;
4107   if (!doc_xml_open->Main().IsAttribute(TDataStd_Tick::GetID()))
4108     return 3;
4109   if (!doc_xml_open->Main().FindAttribute(TDataStd_IntegerList::GetID(), intlist))
4110     return 4;
4111   if (intlist->First() != 1)
4112     return 5;
4113   if (intlist->Last() != 5)
4114     return 6;
4115   if (!doc_xml_open->Main().FindAttribute(TDataStd_RealList::GetID(), dbllist))
4116     return 4;
4117   if (dbllist->First() != 1.5)
4118     return 5;
4119   if (dbllist->Last() != 5.5)
4120     return 6;
4121   if (!doc_xml_open->Main().FindAttribute(TDataStd_ExtStringList::GetID(), strlist))
4122     return 4;
4123   if (strlist->First() != "Guten ")
4124     return 5;
4125   if (strlist->Last() != "Tag")
4126     return 6;
4127   if (!doc_xml_open->Main().FindAttribute(TDataStd_BooleanList::GetID(), boollist))
4128     return 4;
4129   if (boollist->First() != Standard_False)
4130     return 5;
4131   if (boollist->Last() != Standard_True)
4132     return 6;
4133   if (!doc_xml_open->Main().FindAttribute(TDataStd_ReferenceList::GetID(), reflist))
4134     return 4;
4135   TDF_Tool::Entry(reflist->First(), entry_first);
4136   if (entry1 != entry_first)
4137     return 5;
4138   TDF_Tool::Entry(reflist->Last(), entry_last);
4139   if (entry2 != entry_last)
4140     return 6;
4141   if (!doc_xml_open->Main().FindAttribute(TDataStd_BooleanArray::GetID(), boolarr))
4142     return 4;
4143   if (boolarr->Value(15) != Standard_False)
4144     return 5;
4145   if (boolarr->Value(16) != Standard_True)
4146     return 5;
4147   if (boolarr->Value(17) != Standard_True)
4148     return 5;
4149   if (boolarr->Value(18) != Standard_True)
4150     return 5;
4151   if (boolarr->Value(19) != Standard_True)
4152     return 5;
4153   if (boolarr->Value(20) != Standard_True)
4154     return 5;
4155   if (boolarr->Value(21) != Standard_False)
4156     return 5;
4157   if (boolarr->Value(22) != Standard_True)
4158     return 5;
4159   if (boolarr->Value(23) != Standard_True)
4160     return 5;
4161   if (boolarr->Value(24) != Standard_True)
4162     return 5;
4163   if (!doc_xml_open->Main().FindAttribute(TDataStd_ReferenceArray::GetID(), refarr))
4164     return 4;
4165   TDF_Tool::Entry(refarr->Value(444), entry_first);
4166   if (entry1 != entry_first)
4167     return 5;
4168   TDF_Tool::Entry(refarr->Value(445), entry_last);
4169   if (entry2 != entry_last)
4170     return 6;
4171   if (!doc_xml_open->Main().FindAttribute(TDataStd_ByteArray::GetID(), bytearr))
4172     return 4;
4173   if (bytearr->Value(15) != 0)
4174     return 5;
4175   if (bytearr->Value(16) != 10)
4176     return 5;
4177   if (bytearr->Value(17) != 100)
4178     return 5;
4179   if (bytearr->Value(18) != 200)
4180     return 5;
4181   if (bytearr->Value(19) != 250)
4182     return 5;
4183   if (bytearr->Value(20) != 251)
4184     return 5;
4185   if (bytearr->Value(21) != 252)
4186     return 5;
4187   if (bytearr->Value(22) != 253)
4188     return 5;
4189   if (bytearr->Value(23) != 254)
4190     return 5;
4191   if (bytearr->Value(24) != 255)
4192     return 5;
4193   if (!doc_xml_open->Main().FindAttribute(TDF_Reference::GetID(), ref))
4194     return 4;
4195   if (ref->Get().IsNull())
4196     return 5;
4197   if (ref->Get().Tag() != 103)
4198       return 5;
4199
4200   // Bin
4201   Handle(TDocStd_Document) doc_bin, doc_bin_open;
4202   app->NewDocument("BinOcaf", doc_bin);
4203   // TDataStd_Tick:
4204   TDataStd_Tick::Set(doc_bin->Main());
4205   // TDataStd_IntegerList:
4206   intlist = TDataStd_IntegerList::Set(doc_bin->Main());
4207   intlist->Append(1);
4208   intlist->Append(5);
4209   // TDataStd_RealList:
4210   dbllist = TDataStd_RealList::Set(doc_bin->Main());
4211   dbllist->Append(1.5);
4212   dbllist->Append(5.5);
4213   // TDataStd_ExtStringList:
4214   strlist = TDataStd_ExtStringList::Set(doc_bin->Main());
4215   strlist->Append("Bonjour");
4216   strlist->Append("Bonsoir");
4217   // TDataStd_BooleanList:
4218   boollist = TDataStd_BooleanList::Set(doc_bin->Main());
4219   boollist->Append(Standard_False);
4220   boollist->Append(Standard_True);
4221   // TDataStd_ReferenceList:
4222   TDF_Label Lbin1 = doc_bin->Main().FindChild(100);
4223   TDF_Tool::Entry(Lbin1, entry1);
4224   TDF_Label Lbin2 = doc_bin->Main().FindChild(101);
4225   TDF_Tool::Entry(Lbin2, entry2);
4226   reflist = TDataStd_ReferenceList::Set(doc_bin->Main());
4227   reflist->Append(Lbin1);
4228   reflist->Append(Lbin2);
4229   // TDataStd_BooleanArray:
4230   boolarr = TDataStd_BooleanArray::Set(doc_bin->Main(), 15, 24);
4231   boolarr->SetValue(15, Standard_False);
4232   boolarr->SetValue(16, Standard_True);
4233   boolarr->SetValue(17, Standard_True);
4234   boolarr->SetValue(18, Standard_True);
4235   boolarr->SetValue(19, Standard_True);
4236   boolarr->SetValue(20, Standard_True);
4237   boolarr->SetValue(21, Standard_False);
4238   boolarr->SetValue(22, Standard_True);
4239   boolarr->SetValue(23, Standard_True);
4240   boolarr->SetValue(24, Standard_True);
4241   // TDataStd_ReferenceArray:
4242   refarr = TDataStd_ReferenceArray::Set(doc_bin->Main(), 0, 1);
4243   refarr->SetValue(0, Lbin1);
4244   refarr->SetValue(1, Lbin2);
4245   // TDataStd_ByteArray:
4246   bytearr = TDataStd_ByteArray::Set(doc_bin->Main(), 15, 16);
4247   bytearr->SetValue(15, 0);
4248   bytearr->SetValue(16, 255);
4249   // TDataStd_NamedData:
4250   nameddata = TDataStd_NamedData::Set(doc_bin->Main());
4251   nameddata->SetByte("A", 12);
4252   nameddata->SetByte("B", 234);
4253   // TDF_Reference:
4254   Lstd3 = doc_bin->Main().FindChild(103);
4255   ref = TDF_Reference::Set(doc_bin->Main(), Lstd3);
4256   // 
4257   // Save
4258   //if (app->SaveAs(doc_bin, "W:\\doc.cbf") != PCDM_SS_OK)
4259   if (app->SaveAs(doc_bin, aFile3) != PCDM_SS_OK)
4260     return 1;
4261   intlist.Nullify();
4262   ref.Nullify();
4263   app->Close(doc_bin);
4264   doc_bin.Nullify();
4265   //if (app->Open("W:\\doc.cbf", doc_bin_open) != PCDM_RS_OK)
4266   if (app->Open(aFile3, doc_bin_open) != PCDM_RS_OK)
4267     return 2;
4268   if (!doc_bin_open->Main().IsAttribute(TDataStd_Tick::GetID()))
4269     return 3;
4270   if (!doc_bin_open->Main().FindAttribute(TDataStd_IntegerList::GetID(), intlist))
4271     return 4;
4272   if (intlist->First() != 1)
4273     return 5;
4274   if (intlist->Last() != 5)
4275     return 6;
4276   if (!doc_bin_open->Main().FindAttribute(TDataStd_RealList::GetID(), dbllist))
4277     return 4;
4278   if (dbllist->First() != 1.5)
4279     return 5;
4280   if (dbllist->Last() != 5.5)
4281     return 6;
4282   if (!doc_bin_open->Main().FindAttribute(TDataStd_ExtStringList::GetID(), strlist))
4283     return 4;
4284   if (strlist->First() != "Bonjour")
4285     return 5;
4286   if (strlist->Last() != "Bonsoir")
4287     return 6;
4288   if (!doc_bin_open->Main().FindAttribute(TDataStd_BooleanList::GetID(), boollist))
4289     return 4;
4290   if (boollist->First() != Standard_False)
4291     return 5;
4292   if (boollist->Last() != Standard_True)
4293     return 6;
4294   if (!doc_bin_open->Main().FindAttribute(TDataStd_ReferenceList::GetID(), reflist))
4295     return 4;
4296   TDF_Tool::Entry(reflist->First(), entry_first);
4297   if (entry1 != entry_first)
4298     return 5;
4299   TDF_Tool::Entry(reflist->Last(), entry_last);
4300   if (entry2 != entry_last)
4301     return 6;
4302   if (!doc_bin_open->Main().FindAttribute(TDataStd_BooleanArray::GetID(), boolarr))
4303     return 4;
4304   if (boolarr->Value(15) != Standard_False)
4305     return 5;
4306   if (boolarr->Value(16) != Standard_True)
4307     return 5;
4308   if (boolarr->Value(17) != Standard_True)
4309     return 5;
4310   if (boolarr->Value(18) != Standard_True)
4311     return 5;
4312   if (boolarr->Value(19) != Standard_True)
4313     return 5;
4314   if (boolarr->Value(20) != Standard_True)
4315     return 5;
4316   if (boolarr->Value(21) != Standard_False)
4317     return 5;
4318   if (boolarr->Value(22) != Standard_True)
4319     return 5;
4320   if (boolarr->Value(23) != Standard_True)
4321     return 5;
4322   if (boolarr->Value(24) != Standard_True)
4323     return 5;
4324   if (!doc_bin_open->Main().FindAttribute(TDataStd_ReferenceArray::GetID(), refarr))
4325     return 4;
4326   TDF_Tool::Entry(refarr->Value(0), entry_first);
4327   if (entry1 != entry_first)
4328     return 5;
4329   TDF_Tool::Entry(refarr->Value(1), entry_last);
4330   if (entry2 != entry_last)
4331     return 6;
4332   if (!doc_bin_open->Main().FindAttribute(TDataStd_ByteArray::GetID(), bytearr))
4333     return 4;
4334   if (bytearr->Value(15) != 0)
4335     return 5;
4336   if (bytearr->Value(16) != 255)
4337     return 5;
4338   if (!doc_bin_open->Main().FindAttribute(TDataStd_NamedData::GetID(), nameddata))
4339     return 4;
4340   if (nameddata->GetByte("A") != 12)
4341     return 5;
4342   if (nameddata->GetByte("B") != 234)
4343     return 5;
4344   if (!doc_bin_open->Main().FindAttribute(TDF_Reference::GetID(), ref))
4345     return 4;
4346   if (ref->Get().IsNull())
4347     return 5;
4348   if (ref->Get().Tag() != 103)
4349       return 5;
4350
4351   return 0;
4352 }
4353 // For OCC16782 testing
4354
4355 static Standard_Integer OCC16782 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4356 {
4357   if (argc != 4)
4358   {
4359     di << "Usage : " << argv[0] << " file.std file.xml file.cbf\n";
4360     return 1;
4361   }
4362   TCollection_ExtendedString aFile1(argv[1]);
4363   TCollection_ExtendedString aFile2(argv[2]);
4364   TCollection_ExtendedString aFile3(argv[3]);
4365
4366   if (app.IsNull())
4367     app = new AppStd_Application();
4368
4369   int good = 0;
4370   
4371   Handle(TDocStd_Document) doc;
4372   app->NewDocument("BinOcaf", doc);
4373   doc->SetUndoLimit(10);
4374
4375   di <<"\nTestSetGet start\n";
4376   good += TestSetGet(doc);
4377   di <<"TestSetGet finish\n";
4378   di <<"Status = " << good << "\n";
4379
4380   di <<"\nTestUndoRedo start\n";
4381   good += TestUndoRedo(doc);
4382   di <<"TestUndoRedo finish\n";
4383   di <<"Status = " << good << "\n";
4384
4385   di <<"\nTestCopyPaste start\n";
4386   good += TestCopyPaste(doc);
4387   di <<"TestCopyPaste finish\n";
4388   di <<"Status = " << good << "\n";
4389
4390   di <<"\nTestOpenSave start\n";
4391   good += TestOpenSave(aFile1, aFile2, aFile3);
4392   di <<"TestOpenSave finish\n";
4393   di <<"Status = " << good << "\n";
4394
4395   if (!good)
4396     di <<"\nThe " << argv[0] << " test is passed well, OK\n";
4397   else
4398     di <<"\nThe " << argv[0] << " test failed, Faulty\n";
4399
4400   return 0;
4401 }
4402
4403 static Standard_Integer OCC12584 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4404 {
4405   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4406   if(aContext.IsNull()) { 
4407     di << argv[0] << " ERROR : use 'vinit' command before \n";
4408     return -1;
4409   }
4410
4411   if (argc > 2)
4412   {
4413     di << "Usage : " << argv[0] << " [mode = 0/1/2]\n";
4414     return 1;
4415   }
4416   Standard_Integer mode = 0;
4417   if (argc == 2)
4418   {
4419     mode = Draw::Atoi(argv[1]);
4420   }
4421   if (mode > 2 || mode < 0)
4422   {
4423     di << "Usage : " << argv[0] << " [mode = 0/1/2]\n";
4424     return 1;
4425   }
4426   Handle(V3d_View) V = ViewerTest::CurrentView();
4427   static Handle(AIS_ColorScale) aCS;
4428   if (aCS.IsNull())
4429   {
4430     aCS = new AIS_ColorScale();
4431   }
4432   if (aCS->ZLayer() != Graphic3d_ZLayerId_TopOSD)
4433   {
4434     aCS->SetZLayer (Graphic3d_ZLayerId_TopOSD);
4435   }
4436   if (aCS->TransformPersistence().IsNull()
4437    || aCS->TransformPersistence()->Mode() != Graphic3d_TMF_2d)
4438   {
4439     aContext->SetTransformPersistence (aCS, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
4440   }
4441   Standard_Integer aWinWidth, aWinHeight;
4442   V->Window()->Size (aWinWidth, aWinHeight);
4443   aCS->SetSize (aWinWidth, aWinHeight);
4444   if ( !V.IsNull() ) {
4445     if (mode == 0) {
4446       aContext->Display (aCS, Standard_True);
4447     }
4448     if (mode == 1) {
4449       aContext->Erase (aCS, Standard_False);
4450       V->UpdateLights();
4451       V->Update();
4452     }
4453     if (mode == 2) {
4454       Standard_Boolean IsDisplayed = aContext->IsDisplayed (aCS);
4455       if (IsDisplayed)
4456         di <<"ColorScaleIsDisplayed = 1\n";
4457       else
4458         di <<"ColorScaleIsDisplayed = 0\n";
4459     }
4460   }
4461   return 0;
4462 }
4463
4464 #include <Interface_Macros.hxx>
4465 #include <IGESControl_Controller.hxx>
4466 #include <XSDRAW.hxx>
4467 #include <Draw_ProgressIndicator.hxx>
4468 #include <XSControl_WorkSession.hxx>
4469 #include <Transfer_TransientProcess.hxx>
4470 #include <TColStd_HSequenceOfTransient.hxx>
4471 #include <Message_ProgressSentry.hxx>
4472 #include <XSControl_TransferReader.hxx>
4473
4474 #include <Geom_Plane.hxx>
4475 static Standard_Integer OCC20766 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4476 {
4477   if (argc != 6)
4478   {
4479     di << "Usage : " << argv[0] << " plane a b c d\n";
4480     return 1;
4481   }
4482
4483   Standard_Real A = Draw::Atof(argv[2]);
4484   Standard_Real B = Draw::Atof(argv[3]);
4485   Standard_Real C = Draw::Atof(argv[4]);
4486   Standard_Real D = Draw::Atof(argv[5]);
4487
4488   Handle(Geom_Geometry) result;
4489
4490   Handle(Geom_Plane) aPlane = new Geom_Plane(A, B, C, D);
4491   result = aPlane;
4492
4493   DrawTrSurf::Set(argv[1],result);
4494   return 0;
4495 }
4496
4497 static Standard_Integer OCC20627 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4498 {
4499   if(argc!=2)
4500     {
4501       di << "Usage : " << argv[0] << " MaxNbr\n";
4502       return -1;
4503     }
4504   Standard_Integer aMaxNbr = Draw::Atoi(argv[1]);
4505
4506   for (Standard_Integer i=0;i<aMaxNbr;i++)
4507     {
4508       BRepBuilderAPI_MakePolygon w(gp_Pnt(0,0,0),gp_Pnt(0,100,0),gp_Pnt(20,100,0),gp_Pnt(20,0,0));
4509       w.Close();
4510       TopoDS_Wire wireShape( w.Wire());
4511       BRepBuilderAPI_MakeFace faceBuilder(wireShape);
4512       TopoDS_Face f( faceBuilder.Face());
4513       BRepMesh_IncrementalMesh im(f,1);
4514       BRepTools::Clean(f);
4515     }
4516   return 0;
4517 }
4518
4519 #include <IntCurvesFace_ShapeIntersector.hxx>
4520 #include <gp_Lin.hxx>
4521 Standard_Integer OCC17424 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4522 {
4523   if(argc!=9)
4524     {
4525       di << "Usage : " << argv[0] << " shape X_Pnt Y_Pnt Z_Pnt X_Dir Y_Dir Z_Dir PInf\n";
4526       return -1;
4527     }
4528
4529   TopoDS_Shape shape = DBRep::Get(argv[1]);
4530
4531   if (shape.IsNull()) {
4532     di<<" Null shape is not allowed";
4533     return 1;
4534   }
4535
4536   Standard_Real X_Pnt = Draw::Atof(argv[2]);
4537   Standard_Real Y_Pnt = Draw::Atof(argv[3]);
4538   Standard_Real Z_Pnt = Draw::Atof(argv[4]);
4539
4540   Standard_Real X_Dir = Draw::Atof(argv[5]);
4541   Standard_Real Y_Dir = Draw::Atof(argv[6]);
4542   Standard_Real Z_Dir = Draw::Atof(argv[7]);
4543
4544   Standard_Real PInf  = Draw::Atof(argv[8]);
4545
4546   IntCurvesFace_ShapeIntersector intersector;
4547   intersector.Load(shape, Precision::Intersection());
4548
4549   gp_Pnt origin(X_Pnt, Y_Pnt, Z_Pnt);
4550   gp_Dir dir(X_Dir, Y_Dir, Z_Dir);
4551   gp_Lin ray(origin, dir);
4552
4553   Standard_Real PSup = RealLast();
4554   intersector.PerformNearest(ray, PInf, PSup);
4555   if (intersector.NbPnt() != 0)
4556     {
4557       di << argv[0] << " status = 0 \n";
4558       Standard_Real w = intersector.WParameter(1);
4559       di << "w = " << w << "\n";
4560     } else {
4561       di << argv[0] << " status = -1 \n";
4562     }
4563   return 0;
4564 }
4565
4566 Standard_Integer OCC22301 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4567 {
4568   if (argc != 1) {
4569     di << "Usage : " << argv[0] << "\n";
4570     return 1;
4571   }
4572
4573   // Create mask 1111: extent == 4
4574   TColStd_PackedMapOfInteger aFullMask;
4575   for (Standard_Integer i = 0; i < 4; i++)
4576     aFullMask.Add(i);
4577   
4578   // Create mask 1100: extent == 2
4579   TColStd_PackedMapOfInteger aPartMask;
4580   for (Standard_Integer i = 0; i < 2; i++)
4581     aPartMask.Add(i);
4582   
4583   di << "aFullMask = 1111\n";
4584   di << "aPartMask = 1100\n";
4585   
4586   Standard_Boolean isAffected;
4587   
4588   isAffected = aFullMask.Intersect(aPartMask); // true; extent == 2 (OK)
4589   di << "First time: aFullMask.Intersect(aPartMask), isAffected = " << (Standard_Integer)isAffected << "\n";
4590   isAffected = aFullMask.Intersect(aPartMask); // true; extent == 0 (?)
4591   di << "Second time: aFullMask.Intersect(aPartMask), isAffected = " << (Standard_Integer)isAffected << "\n";
4592   isAffected = aFullMask.Subtract(aPartMask); // false (?)
4593   di << "After two intersections: aFullMask.Subtract(aPartMask), isAffected = " << (Standard_Integer)isAffected << "\n";
4594
4595   return 0;
4596 }
4597
4598 #include <NCollection_DataMap.hxx>
4599 Standard_Integer OCC22744 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4600 {
4601         
4602   if (argc != 1) {
4603     di << "Usage : " << argv[0] << "\n";
4604     return 1;
4605   }
4606   
4607   TCollection_ExtendedString anExtString;
4608   
4609   Standard_ExtCharacter aNonAsciiChar = 0x0f00;
4610   anExtString.Insert(1, aNonAsciiChar);
4611
4612   di << "Is ASCII: " << ( anExtString.IsAscii() ? "true : Error" : "false : OK" ) << "\n";
4613   NCollection_DataMap<TCollection_ExtendedString, Standard_Integer> aMap;
4614   aMap.Bind(anExtString, 0);
4615   
4616   return 0;
4617
4618 }
4619
4620 Standard_Integer OCC22558 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4621 {
4622     if (argc != 10) {
4623         di << "Wrong number of arguments" << argv[0] << "\n";
4624         return 1;
4625     }
4626     
4627     Standard_Real X_vec = Draw::Atof(argv[1]);
4628     Standard_Real Y_vec = Draw::Atof(argv[2]);
4629     Standard_Real Z_vec = Draw::Atof(argv[3]);
4630     
4631     Standard_Real X_dir = Draw::Atof(argv[4]);
4632     Standard_Real Y_dir = Draw::Atof(argv[5]);
4633     Standard_Real Z_dir = Draw::Atof(argv[6]);
4634     
4635     Standard_Real X_pnt = Draw::Atof(argv[7]);
4636     Standard_Real Y_pnt = Draw::Atof(argv[8]);
4637     Standard_Real Z_pnt = Draw::Atof(argv[9]);
4638     
4639     gp_Dir toSym(X_vec, Y_vec, Z_vec);
4640     gp_Dir dir(X_dir, Y_dir, Z_dir);
4641     gp_Pnt loc(X_pnt, Y_pnt, Z_pnt);
4642     gp_Ax2 symObj(loc,dir);
4643     toSym.Mirror(symObj);
4644     
4645     di << "The result " << toSym.X() << " " << toSym.Y() << " " << toSym.Z() << "\n"; 
4646     return 0;
4647 }
4648     
4649
4650 Standard_Integer OCC22736 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4651 {
4652         
4653   if (argc != 9) {
4654     di << "Usage : " << argv[0] << " X_mirrorFirstPoint Y_mirrorFirstPoint X_mirrorSecondPoint Y_mirrorSecondPoint X_p1 Y_p1 X_p2 Y_p2\n";
4655     return 1;
4656   }
4657
4658   Standard_Real X_mirrorFirstPoint = Draw::Atof(argv[1]);
4659   Standard_Real Y_mirrorFirstPoint = Draw::Atof(argv[2]);
4660   Standard_Real X_mirrorSecondPoint = Draw::Atof(argv[3]);
4661   Standard_Real Y_mirrorSecondPoint = Draw::Atof(argv[4]);
4662   Standard_Real X_p1 = Draw::Atof(argv[5]);
4663   Standard_Real Y_p1 = Draw::Atof(argv[6]);
4664   Standard_Real X_p2 = Draw::Atof(argv[7]);
4665   Standard_Real Y_p2 = Draw::Atof(argv[8]);
4666   
4667   gp_Trsf2d identityTransformation;
4668
4669   gp_Pnt2d mirrorFirstPoint(X_mirrorFirstPoint,Y_mirrorFirstPoint);
4670   gp_Pnt2d mirrorSecondPoint(X_mirrorSecondPoint,Y_mirrorSecondPoint);
4671   gp_Ax2d  mirrorAxis(mirrorFirstPoint,gp_Vec2d(mirrorFirstPoint,mirrorSecondPoint));
4672
4673   gp_Pnt2d p1(X_p1,Y_p1);
4674   gp_Pnt2d p2(X_p2,Y_p2);
4675
4676   gp_Trsf2d M1;
4677   M1.SetMirror(mirrorAxis);
4678   gp_Trsf2d M2;
4679   M2.SetMirror(mirrorAxis);
4680   gp_Trsf2d Tcomp;
4681   Tcomp = M2.Multiplied(M1);
4682
4683   Standard_Real aTol = Precision::Confusion();
4684   Standard_Integer aStatus = 0;
4685
4686   //After applying two times the same mirror the point is located on the same location OK
4687   gp_Pnt2d p1MirrorM1   = p1.Transformed(M1);
4688   if ( Abs(p2.X() - p1MirrorM1.X()) > aTol )
4689     aStatus = 2;
4690   if ( Abs(p2.Y() - p1MirrorM1.Y()) > aTol )
4691     aStatus = 3;
4692
4693   gp_Pnt2d p1MirrorM1M2 = p1MirrorM1.Transformed(M2);
4694   if ( Abs(p1.X() - p1MirrorM1M2.X()) > aTol )
4695     aStatus = 4;
4696   if ( Abs(p1.Y() - p1MirrorM1M2.Y()) > aTol )
4697     aStatus = 5;
4698
4699   //If we apply the composed transformation of the same two mirrors to a point the result is //not located on the initial position.-->>ERROR
4700   gp_Pnt2d p1MirrorComp = p1.Transformed(Tcomp);
4701   if ( Abs(p1.X() - p1MirrorComp.X()) > aTol )
4702     aStatus = 6;
4703   if ( Abs(p1.Y() - p1MirrorComp.Y()) > aTol )
4704     aStatus = 7;
4705
4706   di << "Status = " << aStatus << "\n";
4707   return 0;
4708 }
4709
4710 Standard_Integer OCC23429(Draw_Interpretor& /*di*/,
4711                           Standard_Integer narg, const char** a)
4712 {
4713   if (narg < 4) return 1;
4714   
4715   TopoDS_Shape aShape = DBRep::Get(a[2]);
4716   if (aShape.IsNull()) return 1;
4717   
4718   BRepFeat_SplitShape Spls(aShape);
4719   Spls.SetCheckInterior(Standard_False);
4720
4721   TopoDS_Shape aTool = DBRep::Get(a[3]);
4722
4723   BRepAlgoAPI_Section Builder(aShape, aTool, Standard_False);
4724   Builder.ComputePCurveOn1(Standard_True);
4725   if (narg == 5)
4726     Builder.Approximation(Standard_True); 
4727   Builder.Build();
4728   TopoDS_Shape aSection = Builder.Shape();
4729
4730   TopExp_Explorer ExpSec(aSection, TopAbs_EDGE);
4731   for (; ExpSec.More(); ExpSec.Next())
4732   {
4733     TopoDS_Edge anEdge = TopoDS::Edge(ExpSec.Current());
4734     Handle(Geom2d_Curve) thePCurve;
4735     Handle(Geom_Surface) theSurface;
4736     TopLoc_Location theLoc;
4737     Standard_Real fpar, lpar;
4738     BRep_Tool::CurveOnSurface(anEdge, thePCurve, theSurface, theLoc, fpar, lpar);
4739     TopoDS_Face aFace;
4740     TopExp_Explorer ExpShape(aShape, TopAbs_FACE);
4741     for (; ExpShape.More(); ExpShape.Next())
4742     {
4743       aFace = TopoDS::Face(ExpShape.Current());
4744       TopLoc_Location aLoc;
4745       Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace, aLoc);
4746       if (aSurface == theSurface && aLoc == theLoc)
4747         break;
4748     }
4749     Spls.Add(anEdge, aFace);
4750   }
4751
4752   TopoDS_Shape Result = Spls.Shape();
4753   DBRep::Set(a[1], Result);
4754
4755   return 0;
4756 }
4757
4758 #include <ExprIntrp_GenExp.hxx>
4759 Standard_Integer CR23403 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4760 {
4761         
4762   if (argc != 2) {
4763     di << "Usage : " << argv[0] << " string\n";
4764     return 1;
4765   }
4766
4767   Standard_CString aString = argv[1];
4768   Handle(ExprIntrp_GenExp) myExpr = ExprIntrp_GenExp::Create();
4769   try {
4770     OCC_CATCH_SIGNALS
4771     myExpr->Process( aString );
4772   }
4773   catch(Standard_Failure const& anException) {
4774     di << "Exception : " << anException.GetMessageString() << "\n";
4775   }
4776
4777   return 0;
4778 }
4779
4780 Standard_Integer OCC28478 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
4781 {       
4782   Standard_Integer nbOuter = (argc > 1 ? Draw::Atoi(argv[1]) : 3);
4783   Standard_Integer nbInner = (argc > 2 ? Draw::Atoi(argv[2]) : 2);
4784
4785   // test behavior of progress indicator when using nested scopes with names set by Sentry objects
4786   Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di, 1);
4787   aProgress->SetTextMode (Standard_True);
4788
4789   // Outer cycle
4790   Message_ProgressSentry anOuter (aProgress, "Outer", 0, nbOuter, 1);
4791   for (int i = 0; i < nbOuter && anOuter.More(); i++, anOuter.Next())
4792   {
4793     // Inner cycle
4794     Message_ProgressSentry anInner (aProgress, "Inner", 0, nbInner, 1);
4795     for (int j = 0; j < nbInner && anInner.More(); j++, anInner.Next())
4796     {
4797       // Cycle body
4798     }
4799   }
4800
4801   return 0;
4802 }
4803
4804 void QABugs::Commands_11(Draw_Interpretor& theCommands) {
4805   const char *group = "QABugs";
4806
4807   theCommands.Add("OCC128", "OCC128", __FILE__, OCC128, group);
4808
4809   // Remove as bad version of QAAddOrRemoveSelected from QADraw
4810   //theCommands.Add("OCC129", "OCC129 shape islocal", __FILE__, OCC129, group);
4811
4812   theCommands.Add("OCC136", "OCC136", __FILE__, OCC136, group);
4813   theCommands.Add("BUC60610","BUC60610 iges_input [name]",__FILE__,BUC60610,group);
4814
4815 //====================================================
4816 //
4817 // Following commands are inserted from 
4818 // /dn03/KAS/dev/QAopt/src/QADraw/QADraw_TOPOLOGY.cxx
4819 // ( 75455 Apr 16 18:59)
4820 //
4821 //====================================================
4822
4823   theCommands.Add("OCC105","OCC105 shape",__FILE__,OCC105,group); 
4824   theCommands.Add("OCC9"," result path cur1 cur2 radius [tolerance]:\t test GeomFill_Pipe", __FILE__, pipe_OCC9,group);
4825
4826   theCommands.Add("OCC125","OCC125 shell", __FILE__, OCC125,group);
4827
4828   theCommands.Add("OCC157","findplanarsurface Result wire Tol",__FILE__,OCC157,group);
4829   //theCommands.Add("OCC165","OCC165",__FILE__,OCC165,group);
4830   theCommands.Add("OCC165","OCC165 file",__FILE__,OCC165,group);
4831   theCommands.Add("OCC297","OCC297",__FILE__,OCC297,group);
4832   //theCommands.Add("OCC305","OCC305",__FILE__,OCC305,group);
4833   theCommands.Add("OCC305","OCC305 file",__FILE__,OCC305,group);
4834
4835   // New commands:
4836   theCommands.Add("OCC166", "OCC166", __FILE__, OCC166, group);
4837   theCommands.Add("OCC381_Save", "OCC381_Save Doc", __FILE__, OCC381_Save, group);
4838   theCommands.Add("OCC381_SaveAs", "OCC381_SaveAs Doc Path", __FILE__, OCC381_SaveAs, group);
4839
4840   theCommands.Add("OCC299","OCC299 Solid Point [Tolerance=1.e-7]", __FILE__, OCC299bug, group);
4841   theCommands.Add("OCC309","OCC309", __FILE__, OCC309bug, group);
4842   theCommands.Add("OCC310","OCC310", __FILE__, OCC310bug, group);
4843
4844   //theCommands.Add("OCC277","OCC277", __FILE__, OCC277bug, group);
4845   theCommands.Add("OCC277","OCC277", __FILE__, OCC277bug, group);
4846
4847   theCommands.Add("OCC363", "OCC363 document filename ", __FILE__, OCC363, group);
4848   // Must use OCC299
4849   //theCommands.Add("OCC372", "OCC372", __FILE__, OCC372, group);
4850   theCommands.Add("OCC377", "OCC377", __FILE__, OCC377, group);
4851   theCommands.Add("OCC22", "OCC22 Result Shape CompoundOfSubshapesToBeDivided ConsiderLocation", __FILE__, OCC22, group);
4852   theCommands.Add("OCC24", "OCC24 Result Shape CompoundOfSubshapes ResourceFileName", __FILE__, OCC24, group);
4853   theCommands.Add("OCC369", "OCC369 Shape", __FILE__, OCC369, group);
4854   theCommands.Add("OCC524", "OCC524 LowerVector UpperVector InitialValueVector LowerRowMatrix UpperRowMatrix LowerColMatrix UpperColMatrix InitialValueMatrix", __FILE__, OCC524, group);
4855   theCommands.Add("OCC525", "OCC525", __FILE__, OCC525, group);
4856   //theCommands.Add("OCC578", "OCC578 shape1 shape2 shape3", __FILE__, OCC578, group);
4857   theCommands.Add("OCC578", "OCC578 shape1 shape2 shape3", __FILE__, OCC578, group);
4858   theCommands.Add("OCC669", "OCC669 GUID", __FILE__, OCC669, group);
4859   theCommands.Add("OCC738_ShapeRef", "OCC738_ShapeRef", __FILE__, OCC738_ShapeRef, group);
4860   theCommands.Add("OCC738_Assembly", "OCC738_Assembly", __FILE__, OCC738_Assembly, group);
4861   theCommands.Add("OCC708", "OCC708 shape ; Deactivate the current transformation", __FILE__, OCC708, group);
4862   theCommands.Add("OCC670", "OCC670", __FILE__, OCC670, group);
4863   theCommands.Add("OCC867", "OCC867 Point Surface Umin Usup Vmin Vsup", __FILE__, OCC867, group);
4864   theCommands.Add("OCC909", "OCC909 wire face", __FILE__, OCC909, group);
4865   theCommands.Add("OCC921", "OCC921 face", __FILE__, OCC921, group);
4866   theCommands.Add("OCC902", "OCC902 expression", __FILE__, OCC902, group);
4867
4868   theCommands.Add ("OCC1029_AISTransparency","OCC1029_AISTransparency (DOC, entry, [real])",__FILE__, OCC1029_AISTransparency, group);
4869   theCommands.Add ("OCC1030_AISColor", "OCC1030_AISColor (DOC, entry, [color])", __FILE__, OCC1030_AISColor, group);
4870   theCommands.Add ("OCC1031_AISMaterial", "OCC1031_AISMaterial (DOC, entry, [material])", __FILE__, OCC1031_AISMaterial, group); 
4871   theCommands.Add ("OCC1032_AISWidth", "OCC1032_AISWidth (DOC, entry, [width])", __FILE__, OCC1032_AISWidth, group); 
4872   theCommands.Add ("OCC1033_AISMode", "OCC1033_AISMode (DOC, entry, [mode])", __FILE__, OCC1033_AISMode, group); 
4873   theCommands.Add ("OCC1034_AISSelectionMode", "OCC1034_AISSelectionMode (DOC, entry, [selectionmode])", __FILE__, OCC1034_AISSelectionMode, group); 
4874
4875   //theCommands.Add("OCC1487", "OCC1487 CylinderVariant(=1/2) cylinder1 cylinder2 cutshape", __FILE__, OCC1487, group);
4876   theCommands.Add("OCC1487", "OCC1487 CylinderVariant(=1/2) cylinder1 cylinder2 cutshape", __FILE__, OCC1487, group);
4877
4878   theCommands.Add("OCC1077", "OCC1077 result", __FILE__, OCC1077, group);
4879   theCommands.Add("OCC5739", "OCC5739 name shape step", __FILE__, OCC5739_UniAbs, group);
4880   theCommands.Add("OCC6046", "OCC6046 nb_of_vectors size", __FILE__, OCC6046, group);
4881   theCommands.Add("OCC5698", "OCC5698 wire", __FILE__, OCC5698, group);
4882   theCommands.Add("OCC6143", "OCC6143 catching signals", __FILE__, OCC6143, group);
4883   theCommands.Add("OCC30775", "OCC30775 catching signals in threads", __FILE__, OCC30775, group);
4884   theCommands.Add("OCC7141", "OCC7141 [nCount] aPath", __FILE__, OCC7141, group);
4885   theCommands.Add("OCC7372", "OCC7372", __FILE__, OCC7372, group);
4886   theCommands.Add("OCC8169", "OCC8169 edge1 edge2 plane", __FILE__, OCC8169, group);
4887   theCommands.Add("OCC10138", "OCC10138 lower upper", __FILE__, OCC10138, group);
4888   theCommands.Add("OCC7639", "OCC7639 index1 value1 ... [indexN valueN]", __FILE__, OCC7639, group);
4889   theCommands.Add("OCC8797", "OCC8797", __FILE__, OCC8797, group);
4890   theCommands.Add("OCC7068", "OCC7068", __FILE__, OCC7068, group);
4891   theCommands.Add("OCC11457", "OCC11457 polygon lastedge x1 y1 z1 x2 y2 z2 ...", __FILE__, OCC11457, group);
4892   theCommands.Add("OCC13963", "OCC13963 ratio origin_x origin_y origin_z", __FILE__, OCC13963, group);
4893   theCommands.Add("OCC14376", "OCC14376 shape [deflection]", __FILE__, OCC14376, group);
4894   theCommands.Add("OCC15489", "OCC15489 A B C", __FILE__, OCC15489, group);
4895   theCommands.Add("OCC15755", "OCC15755 file shape", __FILE__, OCC15755, group);
4896   theCommands.Add("OCC16782", "OCC16782 file.std file.xml file.cbf", __FILE__, OCC16782, group);
4897   theCommands.Add("OCC12584", "OCC12584 [mode = 0/1/2]", __FILE__, OCC12584, group);
4898   theCommands.Add("OCC20766", "OCC20766 plane a b c d", __FILE__, OCC20766, group);
4899   theCommands.Add("OCC20627", "OCC20627", __FILE__, OCC20627, group);
4900   theCommands.Add("OCC17424", "OCC17424  shape X_Pnt Y_Pnt Z_Pnt X_Dir Y_Dir Z_Dir PInf", __FILE__, OCC17424, group);
4901   theCommands.Add("OCC22301", "OCC22301", __FILE__, OCC22301, group);
4902   theCommands.Add("OCC22736", "OCC22736 X_mirrorFirstPoint Y_mirrorFirstPoint X_mirrorSecondPoint Y_mirrorSecondPoint X_p1 Y_p1 X_p2 Y_p2", __FILE__, OCC22736, group);
4903   theCommands.Add("OCC22744", "OCC22744", __FILE__, OCC22744, group);
4904   theCommands.Add("OCC22558", "OCC22558 x_vec y_vec z_vec x_dir y_dir z_dit x_pnt y_pnt z_pnt", __FILE__, OCC22558, group);
4905   theCommands.Add("CR23403", "CR23403 string", __FILE__, CR23403, group);
4906   theCommands.Add("OCC23429", "OCC23429 res shape tool [appr]", __FILE__, OCC23429, group);
4907   theCommands.Add("OCC28478", "OCC28478 [nb_outer=3 [nb_inner=2]: test progress indicator on nested cycles", __FILE__, OCC28478, group);
4908   return;
4909 }