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