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