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