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