273b1594cc46f24cdb9f4f1c192e29f6f356b32b
[occt.git] / src / QABugs / QABugs_19.cxx
1 // Created on: 2002-05-21
2 // Created by: QA Admin
3 // Copyright (c) 2002-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <QABugs.hxx>
17
18 #include <AIS_InteractiveContext.hxx>
19 #include <AIS_LocalContext.hxx>
20 #include <AIS_Shape.hxx>
21 #include <BRepAlgoAPI_Cut.hxx>
22 #include <BRepOffsetAPI_MakePipe.hxx>
23 #include <BRepPrimAPI_MakeBox.hxx>
24 #include <BRepPrimAPI_MakeSphere.hxx>
25 #include <DBRep.hxx>
26 #include <Draw_Interpretor.hxx>
27 #include <DrawTrSurf.hxx>
28 #include <GCE2d_MakeSegment.hxx>
29 #include <Geom2d_TrimmedCurve.hxx>
30 #include <GeomFill_Trihedron.hxx>
31 #include <Graphic3d_ArrayOfTriangles.hxx>
32 #include <gp_Ax1.hxx>
33 #include <gp_Pnt2d.hxx>
34 #include <gp_Quaternion.hxx>
35 #include <Image_Color.hxx>
36 #include <Image_PixMap.hxx>
37 #include <NCollection_Handle.hxx>
38 #include <NCollection_IncAllocator.hxx>
39 #include <NCollection_Map.hxx>
40 #include <OSD_Parallel.hxx>
41 #include <OSD_PerfMeter.hxx>
42 #include <OSD_Timer.hxx>
43 #include <Precision.hxx>
44 #include <Prs3d_ShadingAspect.hxx>
45 #include <Prs3d_Text.hxx>
46 #include <SelectMgr_Filter.hxx>
47 #include <Standard_Version.hxx>
48 #include <StdSelect_BRepOwner.hxx>
49 #include <TCollection_HAsciiString.hxx>
50 #include <TopExp_Explorer.hxx>
51 #include <TopoDS_Shape.hxx>
52 #include <V3d_View.hxx>
53 #include <ViewerTest.hxx>
54 #include <XmlDrivers_DocumentRetrievalDriver.hxx>
55 #include <XmlDrivers_DocumentStorageDriver.hxx>
56 #include <TDataStd_Real.hxx>
57 #include <Standard_Atomic.hxx>
58
59 #include <cstdio>
60 #include <cmath>
61 #include <iostream>
62
63 #define QCOMPARE(val1, val2) \
64   di << "Checking " #val1 " == " #val2 << \
65         ((val1) == (val2) ? ": OK\n" : ": Error\n")
66
67 static Standard_Integer OCC230 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
68 {
69   if ( argc != 4) {
70     di << "ERROR OCC230: Usage : " << argv[0] << " TrimmedCurve Pnt2d Pnt2d\n";
71     return 1;
72   }
73
74   gp_Pnt2d P1, P2;
75   if ( !DrawTrSurf::GetPoint2d(argv[2],P1)) {
76     di << "ERROR OCC230: " << argv[2] << " is not Pnt2d\n";
77     return 1;
78   }
79   if ( !DrawTrSurf::GetPoint2d(argv[3],P2)) {
80     di << "ERROR OCC230: " << argv[3] << " is not Pnt2d\n";
81     return 1;
82   }
83
84   GCE2d_MakeSegment MakeSegment(P1,P2);
85   Handle(Geom2d_TrimmedCurve) TrimmedCurve = MakeSegment.Value();
86   DrawTrSurf::Set(argv[1], TrimmedCurve);
87   return 0;
88 }
89
90 static Standard_Integer OCC23361 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/)
91 {
92   gp_Pnt p(0, 0, 2);
93   
94   gp_Trsf t1, t2;
95   t1.SetRotation(gp_Ax1(p, gp_Dir(0, 1, 0)), -0.49328285294022267);
96   t2.SetRotation(gp_Ax1(p, gp_Dir(0, 0, 1)), 0.87538474718473880);
97
98   gp_Trsf tComp = t2 * t1;
99
100   gp_Pnt p1(10, 3, 4);
101   gp_Pnt p2 = p1.Transformed(tComp);
102   gp_Pnt p3 = p1.Transformed(t1);
103   p3.Transform(t2);
104
105   // points must be equal
106   if ( ! p2.IsEqual(p3, Precision::Confusion()) )
107     di << "ERROR OCC23361: equivalent transformations does not produce equal points\n";
108   else 
109     di << "OCC23361: OK\n";
110
111   return 0;
112 }
113
114 static Standard_Integer OCC23237 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/)
115 {
116   OSD_PerfMeter aPM("TestMeter",0);
117   OSD_Timer aTM;
118   
119   // run some operation in cycle for about 2 seconds to have good values of times to compare
120   int count = 0;
121   printf("OSD_PerfMeter test.\nRunning Boolean operation on solids in loop.\n");
122   for (; aTM.ElapsedTime() < 2.; count++)
123   {
124     aPM.Start();
125     aTM.Start();
126
127     // do some operation that will take considerable time compared with time of starting / stopping timers
128     BRepPrimAPI_MakeBox aBox (10., 10., 10.);
129     BRepPrimAPI_MakeSphere aSphere (10.);
130     BRepAlgoAPI_Cut aCutter (aBox.Shape(), aSphere.Shape());
131
132     aTM.Stop();
133     aPM.Stop();
134   }
135  
136   int aNbEnters = 0;
137   Standard_Real aPerfMeter_CPUtime = 0., aTimer_CPUTime = 0., aS;
138   Standard_Integer aM, aH;
139   aTM.Show(aS, aM, aH, aTimer_CPUTime);
140
141   perf_get_meter("TestMeter", &aNbEnters, &aPerfMeter_CPUtime);
142   perf_init_meter("TestMeter");
143
144   Standard_Real aTimeDiff = (fabs(aTimer_CPUTime - aPerfMeter_CPUtime) / aTimer_CPUTime);
145
146   printf("\nMeasurement results (%d cycles):\n", count);
147   printf("\nOSD_PerfMeter CPU time: %lf\nOSD_Timer CPU time: %lf\n",
148     aPerfMeter_CPUtime, aTimer_CPUTime);
149   printf("Time delta is: %.3lf %%\n", aTimeDiff * 100);
150
151   if (aTimeDiff > 0.2)
152     di << "OCC23237: Error: too much difference between CPU and elapsed times";
153   else if (aNbEnters != count)
154     di << "OCC23237: Error: counter reported by PerfMeter (" << aNbEnters << ") does not correspond to actual number of cycles";
155   else
156     di << "OCC23237: OK";
157
158   return 0;
159 }
160
161 class IncrementerDecrementer
162 {
163 public:
164     IncrementerDecrementer (Standard_Integer* theVal, Standard_Boolean thePositive) : myVal (theVal), myPositive (thePositive)
165     {}
166     void operator() (const size_t) const
167     {
168       if ( myPositive )
169         Standard_Atomic_Increment(myVal);
170       else
171         Standard_Atomic_Decrement(myVal);
172     }
173 private:
174     Standard_Integer*   myVal;
175     Standard_Boolean    myPositive;
176 };
177
178 static Standard_Integer OCC22980 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/)
179 {
180   int aSum = 0;
181
182   //check returned value
183   QCOMPARE (Standard_Atomic_Decrement (&aSum), -1);
184   QCOMPARE (Standard_Atomic_Increment (&aSum), 0);
185   QCOMPARE (Standard_Atomic_Increment (&aSum), 1);
186   QCOMPARE (Standard_Atomic_Increment (&aSum), 2);
187 //  QCOMPARE (Standard_Atomic_DecrementTest (&aSum), 0);
188 //  QCOMPARE (Standard_Atomic_DecrementTest (&aSum), 1);
189
190   //check atomicity 
191   aSum = 0;
192   const int N = 1 << 24; //big enough to ensure concurrency
193
194   //increment
195   OSD_Parallel::For(0, N, IncrementerDecrementer (&aSum, true));
196   QCOMPARE (aSum, N);
197
198   //decrement
199   OSD_Parallel::For(0, N, IncrementerDecrementer (&aSum, false));
200   QCOMPARE (aSum, 0);
201
202   return 0;
203 }
204
205 #include <TDocStd_Application.hxx>
206 #include <TDocStd_Document.hxx>
207 #include <XCAFDoc_ShapeTool.hxx>
208 #include <XCAFDoc_DocumentTool.hxx>
209 #include <TDF_Label.hxx>
210 #include <TDataStd_Name.hxx>
211 #include <DDocStd.hxx>
212
213 static Standard_Integer OCC23595 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/)
214 {
215   Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
216   Handle(TDocStd_Document) aDoc;
217   anApp->NewDocument ("XmlXCAF", aDoc);
218   QCOMPARE (!aDoc.IsNull(), Standard_True);
219
220   Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
221
222   //check default value
223   Standard_Boolean aValue = XCAFDoc_ShapeTool::AutoNaming();
224   QCOMPARE (aValue, Standard_True);
225
226   //true
227   XCAFDoc_ShapeTool::SetAutoNaming (Standard_True);
228   TopoDS_Shape aShape = BRepPrimAPI_MakeBox (100., 200., 300.).Shape();
229   TDF_Label aLabel = aShTool->AddShape (aShape);
230   Handle(TDataStd_Name) anAttr;
231   QCOMPARE (aLabel.FindAttribute (TDataStd_Name::GetID(), anAttr), Standard_True);
232
233   //false
234   XCAFDoc_ShapeTool::SetAutoNaming (Standard_False);
235   aShape = BRepPrimAPI_MakeBox (300., 200., 100.).Shape();
236   aLabel = aShTool->AddShape (aShape);
237   QCOMPARE (!aLabel.FindAttribute (TDataStd_Name::GetID(), anAttr), Standard_True);
238
239   //restore
240   XCAFDoc_ShapeTool::SetAutoNaming (aValue);
241
242   return 0;
243 }
244
245 #include <ExprIntrp_GenExp.hxx>
246 Standard_Integer OCC22611 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
247 {
248
249   if (argc != 3) {
250     di << "Usage : " << argv[0] << " string nb\n";
251     return 1;
252   }
253
254   TCollection_AsciiString aToken = argv[1];
255   Standard_Integer aNb = atoi(argv[2]);
256
257   Handle(ExprIntrp_GenExp) aGen = ExprIntrp_GenExp::Create();
258   for (Standard_Integer i=0; i < aNb; i++)
259   {
260     aGen->Process(aToken);
261     Handle(Expr_GeneralExpression) aExpr = aGen->Expression();
262   }
263
264   return 0;
265 }
266
267 Standard_Integer OCC22595 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/)
268 {
269   gp_Mat M0;
270   di << "M0 = "
271   << " {" << M0(1,1) << "} {" << M0(1,2) << "} {" << M0(1,3) <<"}"
272   << " {" << M0(2,1) << "} {" << M0(2,2) << "} {" << M0(2,3) <<"}"
273   << " {" << M0(1,1) << "} {" << M0(1,2) << "} {" << M0(1,3) <<"}";
274   return 0;
275 }
276
277 #include <TopoDS_Face.hxx>
278 #include <TopoDS_Face.hxx>
279 #include <TopoDS.hxx>
280 #include <BRepBuilderAPI_Transform.hxx>
281 #include <BRepExtrema_DistShapeShape.hxx>
282 #include <BRepTools.hxx>
283
284 static Standard_Boolean OCC23774Test(const TopoDS_Face& grossPlateFace, const TopoDS_Shape& originalWire, Draw_Interpretor& di)
285 {
286   BRepExtrema_DistShapeShape distShapeShape(grossPlateFace,originalWire,Extrema_ExtFlag_MIN);
287   if(!distShapeShape.IsDone()) {
288     di <<"Distance ShapeShape is Not Done\n";
289     return Standard_False;
290   }
291
292   if(distShapeShape.Value() > 0.01) {
293     di << "Wrong Dist = " <<distShapeShape.Value() << "\n";
294     return Standard_False;
295   } else
296     di << "Dist0 = " <<distShapeShape.Value() <<"\n";
297
298   //////////////////////////////////////////////////////////////////////////
299   /// First Flip Y
300   const gp_Pnt2d axis1P1(1474.8199035519228,1249.9995745636970);
301   const gp_Pnt2d axis1P2(1474.8199035519228,1250.9995745636970);
302
303   gp_Vec2d mirrorVector1(axis1P1,axis1P2);
304
305   gp_Trsf2d mirror1;
306   mirror1.SetMirror(gp_Ax2d(axis1P1,mirrorVector1));
307
308   BRepBuilderAPI_Transform transformer1(mirror1);
309   transformer1.Perform(originalWire);
310   if(!transformer1.IsDone()) {
311     di << "Not Done1 \n";
312     return Standard_False;
313   }
314   TopoDS_Shape step1ModifiedShape = transformer1.ModifiedShape(originalWire);
315   
316   BRepExtrema_DistShapeShape distShapeShape1(grossPlateFace,step1ModifiedShape,Extrema_ExtFlag_MIN);
317   if(!distShapeShape1.IsDone())
318     return Standard_False;
319   if(distShapeShape1.Value() > 0.01) {
320     di << "Dist = " <<distShapeShape1.Value() <<"\n";
321     return Standard_False;
322   } else
323     di << "Dist1 = " <<distShapeShape1.Value() <<"\n";
324
325   //////////////////////////////////////////////////////////////////////////
326   /// Second flip Y
327   transformer1.Perform(step1ModifiedShape);
328   if(!transformer1.IsDone()) {
329     di << "Not Done1 \n";
330     return Standard_False;
331   }
332   TopoDS_Shape step2ModifiedShape = transformer1.ModifiedShape(step1ModifiedShape);
333
334   //This is identity matrix for values but for type is gp_Rotation ?!
335   gp_Trsf2d mirror11 = mirror1;
336   mirror11.PreMultiply(mirror1);
337
338   BRepExtrema_DistShapeShape distShapeShape2(grossPlateFace,step2ModifiedShape);//,Extrema_ExtFlag_MIN);
339   if(!distShapeShape2.IsDone())
340     return Standard_False;
341
342   //This last test case give error (the value is 1008.8822038689706)
343   if(distShapeShape2.Value() > 0.01) {
344     di  << "Wrong Dist2 = " <<distShapeShape2.Value() <<"\n";
345     Standard_Integer N = distShapeShape2.NbSolution();
346     di << "Nb = " <<N <<"\n";
347     for (Standard_Integer i=1;i <= N;i++)
348         di <<"Sol(" <<i<<") = " <<distShapeShape2.PointOnShape1(i).Distance(distShapeShape2.PointOnShape2(i)) <<"\n";
349     return Standard_False;
350   }
351   di << "Distance2 = " <<distShapeShape2.Value() <<"\n";
352  
353   return Standard_True;
354 }
355 static Standard_Integer OCC23774(Draw_Interpretor& di, Standard_Integer n, const char** a)
356
357
358   if (n != 3) {
359         di <<"OCC23774: invalid number of input parameters\n";
360         return 1;
361   }
362
363   const char *ns1 = (a[1]), *ns2 = (a[2]);
364   TopoDS_Shape S1(DBRep::Get(ns1)), S2(DBRep::Get(ns2));
365   if (S1.IsNull() || S2.IsNull()) {
366         di <<"OCC23774: Null input shapes\n";
367         return 1;
368   }
369   const TopoDS_Face& aFace  = TopoDS::Face(S1);
370   if(!OCC23774Test(aFace, S2, di))
371         di << "Something is wrong\n";
372
373  return 0;
374 }
375
376 #include <GeomConvert_ApproxSurface.hxx>
377 #include <Geom_BSplineSurface.hxx>
378 #include <Draw.hxx>
379 #include <OSD_Thread.hxx>
380
381 struct GeomConvertTest_Data
382 {
383   Standard_Integer nbupoles;
384   Handle(Geom_Surface) surf;
385 };
386
387 static Standard_Address GeomConvertTest (Standard_Address data)
388 {
389   GeomConvertTest_Data* info = (GeomConvertTest_Data*)data;
390
391   GeomConvert_ApproxSurface aGAS (info->surf, 1e-4, GeomAbs_C1, GeomAbs_C1, 9, 9, 100, 1);
392   if (!aGAS.IsDone()) {
393     cout << "Error: ApproxSurface is not done!" << endl;
394     return 0;
395   }
396   const Handle(Geom_BSplineSurface)& aBSurf = aGAS.Surface();
397   if (aBSurf.IsNull()) {
398     cout << "Error: BSplineSurface is not created!" << endl;
399     return 0;
400   }
401   cout << "Number of UPoles:" << aBSurf->NbUPoles();
402   if (aBSurf->NbUPoles() == info->nbupoles)
403   {
404     cout << ": OK" << endl;
405     return data; // any non-null pointer
406   }
407   else
408   {
409     cout << ": Error, must be " << info->nbupoles << endl;
410     return 0;
411   }
412 }
413
414 static Standard_Integer OCC23952sweep (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
415 {
416   if (argc != 3) {
417     cout << "Error: invalid number of arguments" << endl;
418     return 1;
419   }
420
421   struct GeomConvertTest_Data aStorage;
422   aStorage.nbupoles = Draw::Atoi(argv[1]); 
423   aStorage.surf = DrawTrSurf::GetSurface(argv[2]);
424   if (aStorage.surf.IsNull())
425   {
426     cout << "Error: " << argv[2] << " is not a DRAW surface!" << endl;
427     return 0;
428   }
429
430   // start conversion in several threads
431   const int NBTHREADS = 100;
432   OSD_Thread aThread[NBTHREADS];
433   for (int i=0; i < NBTHREADS; i++)
434   { 
435     aThread[i].SetFunction (GeomConvertTest);
436     if (!aThread[i].Run(&aStorage))
437       di << "Error: Cannot start thread << " << i << "\n";
438   }
439
440   // check results
441   for (int i=0; i < NBTHREADS; i++)
442   { 
443     Standard_Address aResult = 0;
444     if (!aThread[i].Wait(aResult))
445       di << "Error: Failed waiting for thread << " << i << "\n";
446     if (!aResult) 
447       di << "Error: wrong number of poles in thread " << i << "!\n";
448   }
449
450   return 0;
451 }
452
453 #include <GeomInt_IntSS.hxx>
454
455 struct GeomIntSSTest_Data
456 {
457   Standard_Integer nbsol;
458   Handle(Geom_Surface) surf1, surf2;
459 };
460
461 static Standard_Address GeomIntSSTest (Standard_Address data)
462 {
463   GeomIntSSTest_Data* info = (GeomIntSSTest_Data*)data;
464   GeomInt_IntSS anInter;
465   anInter.Perform (info->surf1, info->surf2, Precision::Confusion(), Standard_True);
466   if (!anInter.IsDone()) {
467     cout << "An intersection is not done!" << endl;
468     return 0;
469   }
470
471   cout << "Number of Lines:" << anInter.NbLines();
472   if (anInter.NbLines() == info->nbsol)
473   {
474     cout << ": OK" << endl;
475     return data; // any non-null pointer
476   }
477   else
478   {
479     cout << ": Error, must be " << info->nbsol << endl;
480     return 0;
481   }
482 }
483
484 static Standard_Integer OCC23952intersect (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
485 {
486   if (argc != 4) {
487     cout << "Error: invalid number of arguments" << endl;
488     return 1;
489   }
490
491   struct GeomIntSSTest_Data aStorage;
492   aStorage.nbsol = Draw::Atoi(argv[1]); 
493   aStorage.surf1 = DrawTrSurf::GetSurface(argv[2]);
494   aStorage.surf2 = DrawTrSurf::GetSurface(argv[3]);
495   if (aStorage.surf1.IsNull() || aStorage.surf2.IsNull())
496   {
497     cout << "Error: Either " << argv[2] << " or " << argv[3] << " is not a DRAW surface!" << endl;
498     return 0;
499   }
500
501   // start conversion in several threads
502   const int NBTHREADS = 100;
503   OSD_Thread aThread[NBTHREADS];
504   for (int i=0; i < NBTHREADS; i++)
505   { 
506     aThread[i].SetFunction (GeomIntSSTest);
507     if (!aThread[i].Run(&aStorage))
508       di << "Error: Cannot start thread << " << i << "\n";
509   }
510
511   // check results
512   for (int i=0; i < NBTHREADS; i++)
513   { 
514     Standard_Address aResult = 0;
515     if (!aThread[i].Wait(aResult))
516       di << "Error: Failed waiting for thread << " << i << "\n";
517     if (!aResult) 
518       di << "Error: wrong number of intersections in thread " << i << "!\n"; 
519   }
520
521   return 0;
522 }
523
524 #include <Geom_SurfaceOfRevolution.hxx> 
525 static Standard_Integer OCC23683 (Draw_Interpretor& di, Standard_Integer argc,const char ** argv)
526 {
527   if (argc < 2) {
528     di<<"Usage: " << argv[0] << " invalid number of arguments\n";
529     return 1;
530   }
531
532   Standard_Integer ucontinuity = 1;
533   Standard_Integer vcontinuity = 1;
534   Standard_Boolean iscnu = false;
535   Standard_Boolean iscnv = false;
536   
537   Handle(Geom_Surface) aSurf = DrawTrSurf::GetSurface(argv[1]);
538
539   QCOMPARE (aSurf->IsCNu (ucontinuity), iscnu);
540   QCOMPARE (aSurf->IsCNv (vcontinuity), iscnv);
541
542   return 0;
543 }
544
545 #include <gp_Ax1.hxx>
546 #include <gp_Ax22d.hxx>
547 #include <Geom_Plane.hxx>
548 #include <Geom2d_Circle.hxx>
549 #include <Geom2d_TrimmedCurve.hxx>
550 #include <BRepBuilderAPI_MakeEdge.hxx>
551 #include <BRepPrimAPI_MakeRevol.hxx>
552 #include <Geom2d_OffsetCurve.hxx>
553
554 static int test_offset(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
555 {
556   // Check the command arguments
557   if ( argc != 1 )
558   {
559     di << "Error: " << argv[0] << " - invalid number of arguments\n";
560     di << "Usage: type help " << argv[0] << "\n";
561     return 1; // TCL_ERROR
562   }
563
564   gp_Ax1 RotoAx( gp::Origin(), gp::DZ() );
565   gp_Ax22d Ax2( gp::Origin2d(), gp::DY2d(), gp::DX2d() );
566   Handle(Geom_Surface) Plane = new Geom_Plane( gp::YOZ() );
567
568   di << "<<<< Preparing sample surface of revolution based on trimmed curve >>>>\n";
569   di << "-----------------------------------------------------------------------\n";
570
571   Handle(Geom2d_Circle) C2d1 = new Geom2d_Circle(Ax2, 1.0);
572   Handle(Geom2d_TrimmedCurve) C2d1Trimmed = new Geom2d_TrimmedCurve(C2d1, 0.0, M_PI/2.0);
573   TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(C2d1Trimmed, Plane);
574
575   DBRep::Set("e1", E1);
576
577   BRepPrimAPI_MakeRevol aRevolBuilder1(E1, RotoAx);
578   TopoDS_Face F1 = TopoDS::Face( aRevolBuilder1.Shape() );
579
580   DBRep::Set("f1", F1);
581
582   di << "Result: f1\n";
583
584   di << "<<<< Preparing sample surface of revolution based on offset curve  >>>>\n";
585   di << "-----------------------------------------------------------------------\n";
586
587   Handle(Geom2d_OffsetCurve) C2d2Offset = new Geom2d_OffsetCurve(C2d1Trimmed, -0.5);
588   TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(C2d2Offset, Plane);
589
590   DBRep::Set("e2", E2);
591
592   BRepPrimAPI_MakeRevol aRevolBuilder2(E2, RotoAx);
593   TopoDS_Face F2 = TopoDS::Face( aRevolBuilder2.Shape() );
594
595   DBRep::Set("f2", F2);
596
597   di << "Result: f2\n";
598
599   return 0;
600 }
601
602 #include <Geom_Curve.hxx>
603 #include <Geom_Surface.hxx>
604 #include <Precision.hxx>
605 #include <ShapeConstruct_ProjectCurveOnSurface.hxx>
606 //=======================================================================
607 //function : OCC24008
608 //purpose  : 
609 //=======================================================================
610 static Standard_Integer OCC24008 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
611 {
612   if (argc != 3) {
613     di << "Usage: " << argv[0] << " invalid number of arguments\n";
614     return 1;
615   }
616   Handle(Geom_Curve) aCurve = DrawTrSurf::GetCurve(argv[1]);
617   Handle(Geom_Surface) aSurf = DrawTrSurf::GetSurface(argv[2]);
618   if (aCurve.IsNull()) {
619     di << "Curve was not read\n";
620         return 1;
621   }
622   if (aSurf.IsNull()) {
623         di << "Surface was not read\n";
624         return 1;
625   }
626   ShapeConstruct_ProjectCurveOnSurface aProj;
627   aProj.Init (aSurf, Precision::Confusion());
628   try {
629     Handle(Geom2d_Curve) aPCurve;
630     aProj.Perform (aCurve, aCurve->FirstParameter(), aCurve->LastParameter(), aPCurve);
631     if (aPCurve.IsNull()) {
632           di << "PCurve was not created\n";
633           return 1;
634     }
635   } catch (...) {
636     di << "Exception was caught\n";
637   }
638   return 0;
639 }
640
641 #include <GeomAdaptor_Surface.hxx>
642 #include <Draw.hxx>
643 //=======================================================================
644 //function : OCC23945
645 //purpose  : 
646 //=======================================================================
647
648 static Standard_Integer OCC23945 (Draw_Interpretor& /*di*/,Standard_Integer n, const char** a)
649 {
650   if (n < 5) return 1;
651
652   Handle(Geom_Surface) aS = DrawTrSurf::GetSurface(a[1]);
653   if (aS.IsNull()) return 1;
654
655   GeomAdaptor_Surface GS(aS);
656
657   Standard_Real U = Draw::Atof(a[2]);
658   Standard_Real V = Draw::Atof(a[3]);
659
660   Standard_Boolean DrawPoint = ( n%3 == 2);
661   if ( DrawPoint) n--;
662
663   gp_Pnt P;
664   if (n >= 13) {
665     gp_Vec DU,DV;
666     if (n >= 22) {
667       gp_Vec D2U,D2V,D2UV;
668       GS.D2(U,V,P,DU,DV,D2U,D2V,D2UV);
669       Draw::Set(a[13],D2U.X());
670       Draw::Set(a[14],D2U.Y());
671       Draw::Set(a[15],D2U.Z());
672       Draw::Set(a[16],D2V.X());
673       Draw::Set(a[17],D2V.Y());
674       Draw::Set(a[18],D2V.Z());
675       Draw::Set(a[19],D2UV.X());
676       Draw::Set(a[20],D2UV.Y());
677       Draw::Set(a[21],D2UV.Z());
678     }
679     else
680       GS.D1(U,V,P,DU,DV);
681
682     Draw::Set(a[7],DU.X());
683     Draw::Set(a[8],DU.Y());
684     Draw::Set(a[9],DU.Z());
685     Draw::Set(a[10],DV.X());
686     Draw::Set(a[11],DV.Y());
687     Draw::Set(a[12],DV.Z());
688   }
689   else 
690     GS.D0(U,V,P);
691
692   if ( n > 6) {
693     Draw::Set(a[4],P.X());
694     Draw::Set(a[5],P.Y());
695     Draw::Set(a[6],P.Z());
696   }
697   if ( DrawPoint) {
698     DrawTrSurf::Set(a[n],P);
699   }
700
701   return 0;
702 }
703
704 //=======================================================================
705 //function : OCC11758
706 //purpose  : 
707 //=======================================================================
708 static Standard_Integer OCC11758 (Draw_Interpretor& di, Standard_Integer n, const char**)
709 {
710   if (n != 1) return 1;
711
712   const char* theStr = "0123456789";
713   Standard_Integer i, j;
714   for ( i = 0; i < 5; ++i ) {
715     // TCollection_AsciiString(const Standard_CString astring)
716     TCollection_AsciiString a(theStr+i);
717     // IsEqual (const Standard_CString other)const
718     //assert( a == theStr+i );
719     QCOMPARE ( a , theStr+i );
720
721     //TCollection_AsciiString(const Standard_CString astring,const Standard_Integer aLen )
722     TCollection_AsciiString b(theStr+i, 3);
723     //assert( b.Length() == 3 );
724     //assert( strncmp( b.ToCString(), theStr+i, 3 ) == 0 );
725     //assert( strlen( b.ToCString() ) == 3 );
726     QCOMPARE ( b.Length() , 3 );
727     QCOMPARE ( strncmp( b.ToCString() , theStr+i, 3 ) , 0 );
728     QCOMPARE ( b.Length() , 3 );
729
730     //TCollection_AsciiString(const Standard_Integer aValue)
731     TCollection_AsciiString c(i);
732     //assert( c.IsIntegerValue() );
733     //assert( c.IntegerValue() == i );
734     QCOMPARE ( c.IsIntegerValue() , Standard_True );
735     QCOMPARE ( c.IntegerValue() , i );
736
737     //TCollection_AsciiString(const Standard_Real aValue)
738     TCollection_AsciiString d( 0.1*i );
739     //assert( d.IsRealValue() );
740     //assert( TCollection_AsciiString(3.3) == "3.3");
741     QCOMPARE ( d.IsRealValue() , Standard_True );
742     QCOMPARE ( TCollection_AsciiString(3.3) , "3.3" );
743
744     //TCollection_AsciiString(const TCollection_AsciiString& astring)
745     TCollection_AsciiString e(d);
746     //assert( e == d );
747     //assert( e.Length() == d.Length() );
748     //assert( strcmp( e.ToCString(), d.ToCString() ) == 0 );
749     QCOMPARE ( e ,d  );
750     QCOMPARE ( e.Length() , d.Length() );
751     QCOMPARE ( strcmp( e.ToCString(), d.ToCString() ) , 0 );
752
753     // TCollection_AsciiString(const TCollection_AsciiString& astring ,
754     //                         const Standard_Character other )
755     TCollection_AsciiString f(e,'\a');
756     //assert( f.Length() == e.Length() + 1 );
757     //assert( strncmp( f.ToCString(), e.ToCString(), e.Length() ) == 0 );
758     //assert( f.Value( f.Length() ) == '\a');
759     QCOMPARE ( f.Length() , e.Length() + 1 );
760     QCOMPARE ( strncmp( f.ToCString(), e.ToCString(), e.Length() ) , 0 );
761     QCOMPARE ( f.Value( f.Length() ) , '\a' );
762
763     // TCollection_AsciiString(const TCollection_AsciiString& astring ,
764     //                         const Standard_CString other )
765     TCollection_AsciiString g(f, theStr);
766     //assert( g.Length() == f.Length() + strlen( theStr ));
767     //assert( strncmp( g.ToCString(), f.ToCString(), f.Length() ) == 0 );
768     //assert( g.Search( theStr ) == f.Length() + 1 );
769     QCOMPARE ( g.Length() , f.Length() + (Standard_Integer)strlen( theStr ) );
770     QCOMPARE ( strncmp( g.ToCString(), f.ToCString(), f.Length() ) , 0 );
771     QCOMPARE ( g.Search( theStr ) , f.Length() + 1 );
772
773     // TCollection_AsciiString(const TCollection_AsciiString& astring ,
774     //                         const TCollection_AsciiString& other )
775     TCollection_AsciiString h(d,a);
776     //assert( h.Length() == d.Length() + a.Length() );
777     //assert( strncmp( h.ToCString(), d.ToCString(), d.Length() ) == 0 );
778     //assert( strncmp( h.ToCString() + d.Length(), a.ToCString(), a.Length() ) == 0 );
779     QCOMPARE ( h.Length() , d.Length() + a.Length() );
780     QCOMPARE ( strncmp( h.ToCString(), d.ToCString(), d.Length() ) , 0 );
781     QCOMPARE ( strncmp( h.ToCString() + d.Length(), a.ToCString(), a.Length() ) , 0 );
782
783     // AssignCat(const Standard_CString other)
784     c.AssignCat( a.ToCString() );
785     //assert( c.Length() == 1 + a.Length() );
786     //assert( c.Search( a ) == 2 );
787     QCOMPARE ( c.Length() , 1 + a.Length() );
788     QCOMPARE ( c.Search( a ) , 2 );
789
790     // AssignCat(const TCollection_AsciiString& other)
791     Standard_Integer dl = d.Length();
792     d.AssignCat( a );
793     //assert( d.Length() == dl + a.Length() );
794     //assert( d.Search( a ) == dl + 1 );
795     QCOMPARE ( d.Length() , dl + a.Length() );
796     QCOMPARE ( d.Search( a ) , dl + 1 );
797
798     // Capitalize()
799     TCollection_AsciiString capitalize("aBC");
800     capitalize.Capitalize();
801     //assert( capitalize == "Abc" );
802     QCOMPARE ( capitalize , "Abc" );
803
804     // Copy(const Standard_CString fromwhere)
805     d = theStr+i;
806     //assert( d == theStr+i );
807     QCOMPARE ( d , theStr+i );
808
809     // Copy(const TCollection_AsciiString& fromwhere)
810     d = h;
811     // IsEqual (const TCollection_AsciiString& other)const
812     //assert( d == h );
813     QCOMPARE ( d , h );
814
815     // Insert(const Standard_Integer where, const Standard_CString what)
816     dl = d.Length();
817     d.Insert( 2, theStr );
818     //assert( d.Length() == dl + strlen( theStr ));
819     //assert( strncmp( d.ToCString() + 1, theStr, strlen( theStr )) == 0 );
820     QCOMPARE ( d.Length() , dl + (Standard_Integer)strlen( theStr ) );
821     QCOMPARE ( strncmp( d.ToCString() + 1, theStr, strlen( theStr )) , 0 );
822
823     //Insert(const Standard_Integer where,const Standard_Character what)
824     d = theStr;
825     d.Insert( i+1, 'i' );
826     //assert( d.Length() == strlen( theStr ) + 1 );
827     //assert( d.Value( i+1 ) == 'i');
828     //assert( strcmp( d.ToCString() + i + 1, theStr+i ) == 0 );
829     QCOMPARE ( d.Length() , (Standard_Integer)strlen( theStr ) + 1 );
830     QCOMPARE ( d.Value( i+1 ) , 'i' );
831     QCOMPARE ( strcmp( d.ToCString() + i + 1, theStr+i ) , 0 );
832
833     //Insert(const Standard_Integer where,const TCollection_AsciiString& what)
834     d = theStr;
835     d.Insert( i+1, TCollection_AsciiString( "i" ));
836     //assert( d.Length() == strlen( theStr ) + 1 );
837     //assert( d.Value( i+1 ) == 'i');
838     //assert( strcmp( d.ToCString() + i + 1, theStr+i ) == 0 );
839     QCOMPARE ( d.Length() , (Standard_Integer)strlen( theStr ) + 1 );
840     QCOMPARE ( d.Value( i+1 ) , 'i' );
841     QCOMPARE ( strcmp( d.ToCString() + i + 1, theStr+i ) , 0 );
842
843     // IsDifferent (const Standard_CString other)const
844     //assert( d.IsDifferent( theStr ));
845     //assert( d.IsDifferent( "theStr" ));
846     //assert( d.IsDifferent( "" ));
847     //assert( !d.IsDifferent( d.ToCString() ));
848     QCOMPARE ( d.IsDifferent( theStr ) , Standard_True );
849     QCOMPARE ( d.IsDifferent( "theStr" ) , Standard_True );
850     QCOMPARE ( d.IsDifferent( "" ) , Standard_True );
851     QCOMPARE ( !d.IsDifferent( d.ToCString() ) , Standard_True );
852
853     // IsDifferent (const TCollection_AsciiString& other)const
854     //assert( d.IsDifferent( TCollection_AsciiString() ));
855     //assert( d.IsDifferent( a ));
856     //assert( d.IsDifferent( h ));
857     //assert( !d.IsDifferent( d ));
858     QCOMPARE ( d.IsDifferent( TCollection_AsciiString() ) , Standard_True );
859     QCOMPARE ( d.IsDifferent( a ) , Standard_True );
860     QCOMPARE ( d.IsDifferent( h ) , Standard_True );
861     QCOMPARE ( !d.IsDifferent( d ) , Standard_True );
862
863     // IsLess (const Standard_CString other)const
864     //assert( TCollection_AsciiString ("0"). IsLess("1"));
865     //assert( TCollection_AsciiString ("0"). IsLess("00"));
866     //assert( TCollection_AsciiString ("").  IsLess("0"));
867     //assert( !TCollection_AsciiString("1"). IsLess("0"));
868     //assert( !TCollection_AsciiString("00").IsLess("0"));
869     //assert( !TCollection_AsciiString("0"). IsLess(""));
870     //assert( TCollection_AsciiString (theStr+i).IsLess(theStr+i+1));
871     QCOMPARE ( TCollection_AsciiString ("0"). IsLess("1") , Standard_True );
872     QCOMPARE ( TCollection_AsciiString ("0"). IsLess("00") , Standard_True );
873     QCOMPARE ( TCollection_AsciiString ("").  IsLess("0") , Standard_True );
874     QCOMPARE ( !TCollection_AsciiString("1"). IsLess("0"), Standard_True );
875     QCOMPARE ( !TCollection_AsciiString("00").IsLess("0") , Standard_True );
876     QCOMPARE ( !TCollection_AsciiString("0"). IsLess("") , Standard_True );
877     QCOMPARE ( TCollection_AsciiString (theStr+i).IsLess(theStr+i+1) , Standard_True );
878
879     // IsLess (const TCollection_AsciiString& other)const
880     //assert( TCollection_AsciiString ("0"). IsLess(TCollection_AsciiString("1" )));
881     //assert( TCollection_AsciiString ("0"). IsLess(TCollection_AsciiString("00")));
882     //assert( TCollection_AsciiString ("").  IsLess(TCollection_AsciiString("0" )));
883     //assert( !TCollection_AsciiString("1"). IsLess(TCollection_AsciiString("0" )));
884     //assert( !TCollection_AsciiString("00").IsLess(TCollection_AsciiString("0" )));
885     //assert( !TCollection_AsciiString("0"). IsLess(TCollection_AsciiString(""  )));
886     //assert( TCollection_AsciiString (theStr+i).IsLess(TCollection_AsciiString(theStr+i+1)));
887     QCOMPARE ( TCollection_AsciiString ("0"). IsLess(TCollection_AsciiString("1" )) , Standard_True );
888     QCOMPARE ( TCollection_AsciiString ("0"). IsLess(TCollection_AsciiString("00")) , Standard_True );
889     QCOMPARE ( TCollection_AsciiString ("").  IsLess(TCollection_AsciiString("0" )) , Standard_True );
890     QCOMPARE ( !TCollection_AsciiString("1"). IsLess(TCollection_AsciiString("0" )) , Standard_True );
891     QCOMPARE ( !TCollection_AsciiString("00").IsLess(TCollection_AsciiString("0" )) , Standard_True );
892     QCOMPARE ( !TCollection_AsciiString("0"). IsLess(TCollection_AsciiString(""  )) , Standard_True );
893     QCOMPARE ( TCollection_AsciiString (theStr+i).IsLess(TCollection_AsciiString(theStr+i+1)) , Standard_True );
894
895     // IsGreater (const Standard_CString other)const
896     //assert( !TCollection_AsciiString("0"). IsGreater("1"));
897     //assert( !TCollection_AsciiString("0"). IsGreater("00"));
898     //assert( !TCollection_AsciiString("").  IsGreater("0"));
899     //assert( TCollection_AsciiString ("1"). IsGreater("0"));
900     //assert( TCollection_AsciiString ("00").IsGreater("0"));
901     //assert( TCollection_AsciiString ("0"). IsGreater(""));
902     //assert( TCollection_AsciiString (theStr+i+1).IsGreater(theStr+i));
903     QCOMPARE ( !TCollection_AsciiString("0"). IsGreater("1") , Standard_True );
904     QCOMPARE ( !TCollection_AsciiString("0"). IsGreater("00") , Standard_True );
905     QCOMPARE ( !TCollection_AsciiString("").  IsGreater("0") , Standard_True );
906     QCOMPARE ( TCollection_AsciiString ("1"). IsGreater("0") , Standard_True );
907     QCOMPARE ( TCollection_AsciiString ("00").IsGreater("0") , Standard_True );
908     QCOMPARE ( TCollection_AsciiString ("0"). IsGreater("") , Standard_True );
909     QCOMPARE ( TCollection_AsciiString (theStr+i+1).IsGreater(theStr+i) , Standard_True );
910
911     // IsGreater (const TCollection_AsciiString& other)const
912     //assert( !TCollection_AsciiString("0"). IsGreater(TCollection_AsciiString("1" )));
913     //assert( !TCollection_AsciiString("0"). IsGreater(TCollection_AsciiString("00")));
914     //assert( !TCollection_AsciiString("").  IsGreater(TCollection_AsciiString("0" )));
915     //assert( TCollection_AsciiString ("1"). IsGreater(TCollection_AsciiString("0" )));
916     //assert( TCollection_AsciiString ("00").IsGreater(TCollection_AsciiString("0" )));
917     //assert( TCollection_AsciiString ("0"). IsGreater(TCollection_AsciiString(""  )));
918     //assert( TCollection_AsciiString (theStr+i+1).IsGreater(TCollection_AsciiString(theStr+i)));
919     QCOMPARE ( !TCollection_AsciiString("0"). IsGreater(TCollection_AsciiString("1" )) , Standard_True );
920     QCOMPARE ( !TCollection_AsciiString("0"). IsGreater(TCollection_AsciiString("00")) , Standard_True );
921     QCOMPARE ( !TCollection_AsciiString("").  IsGreater(TCollection_AsciiString("0" )) , Standard_True );
922     QCOMPARE ( TCollection_AsciiString ("1"). IsGreater(TCollection_AsciiString("0" )) , Standard_True );
923     QCOMPARE ( TCollection_AsciiString ("00").IsGreater(TCollection_AsciiString("0" )) , Standard_True );
924     QCOMPARE ( TCollection_AsciiString ("0"). IsGreater(TCollection_AsciiString(""  )) , Standard_True );
925     QCOMPARE ( TCollection_AsciiString (theStr+i+1).IsGreater(TCollection_AsciiString(theStr+i)) , Standard_True );
926
927     // void Read(Standard_IStream& astream)
928     std::istringstream is( theStr );
929     e.Read( is );
930     //assert( e == theStr );
931     QCOMPARE ( e , theStr );
932
933     // Standard_Integer SearchFromEnd (const Standard_CString what)const
934     //assert( e.SearchFromEnd( theStr + i ) == i + 1 );
935     QCOMPARE ( e.SearchFromEnd( theStr + i ) , i + 1 );
936
937     // SetValue(const Standard_Integer where, const Standard_CString what)
938     e.SetValue( i+1, "what");
939     //assert( e.Search( "what" ) == i+1 );
940     //assert( e.Length() == strlen( theStr ));
941     QCOMPARE ( e.Search( "what" ) , i+1 );
942     QCOMPARE ( e.Length() , (Standard_Integer)strlen( theStr ) );
943
944     // TCollection_AsciiString Split (const Standard_Integer where)
945     e = theStr;
946     d = e.Split( i+1 );
947     //assert( d.Length() + e.Length() == strlen( theStr ));
948     QCOMPARE ( d.Length() + e.Length() , (Standard_Integer)strlen( theStr ) );
949
950     // TCollection_AsciiString SubString (const Standard_Integer FromIndex,
951     //                                    const Standard_Integer ToIndex) const
952     e = theStr;
953     d = e.SubString( (unsigned int)i+1, (unsigned int)i+3 );
954     //assert( d.Length() == 3 );
955     //assert( d.Value(1) == theStr[ i ]);
956     QCOMPARE ( d.Length() , 3 );
957     QCOMPARE ( d.Value(1) , theStr[ i ] );
958
959     // TCollection_AsciiString Token (const Standard_CString separators,
960     //                                const Standard_Integer whichone) const
961     e = " ";
962     for ( j = 0; j < i; ++j ) {
963       e += TCollection_AsciiString( theStr[j] ) + " ";
964       //assert( e.Token(" ", j+1 ) == TCollection_AsciiString( theStr+j, 1 ));
965       QCOMPARE ( e.Token(" ", j+1 ) , TCollection_AsciiString( theStr+j, 1 ) );
966     }
967   }
968   for ( i = 0; i < 5; ++i )
969   {
970     // TCollection_ExtendedString (const Standard_CString astring, 
971     //                             const Standard_Boolean isMultiByte) 
972     const TCollection_ExtendedString a( theStr+i );
973     //assert( TCollection_AsciiString( a ) == theStr+i );
974     QCOMPARE ( TCollection_AsciiString( a ) , theStr+i );
975
976     //TCollection_ExtendedString (const Standard_ExtString astring)
977     const TCollection_ExtendedString b( a.ToExtString() );
978     //assert( a == b );
979     QCOMPARE ( a , b );
980
981     // TCollection_ExtendedString (const Standard_Integer      length,
982     //                             const Standard_ExtCharacter filler )
983     const TCollection_ExtendedString c( i, 1 );
984     //assert( c.Length() == i );
985     QCOMPARE ( c.Length() , i );
986     if ( c.Length() > 0 ) {
987       //assert( c.Value( i ) == 1 );
988       QCOMPARE ( c.Value( i ) , 1 );
989     }
990
991     // TCollection_ExtendedString (const Standard_Integer aValue)
992     TCollection_ExtendedString d( i );
993     const TCollection_AsciiString da( d );
994     //assert( da.IsIntegerValue() );
995     //assert( da.IntegerValue() == i );
996     QCOMPARE ( da.IsIntegerValue() , Standard_True );
997     QCOMPARE (  da.IntegerValue(), i );
998
999     // TCollection_ExtendedString (const Standard_Real aValue)
1000     const TCollection_ExtendedString e( 0.1 * i );
1001     const TCollection_AsciiString ea( e );
1002     //assert( ea.IsRealValue() );
1003     //assert( Abs( ea.RealValue() - 0.1 * i ) < 1e-10 );
1004     QCOMPARE ( ea.IsRealValue() , Standard_True );
1005     QCOMPARE ( Abs( ea.RealValue() - 0.1 * i ) < 1e-10 , Standard_True );
1006
1007     // TCollection_ExtendedString (const TCollection_ExtendedString& astring)
1008     const TCollection_ExtendedString f(e);
1009     //assert( f.Length() == e.Length());
1010     //assert( f == e );
1011     QCOMPARE ( f.Length() , e.Length() );
1012     QCOMPARE ( f , e );
1013
1014     // TCollection_ExtendedString (const TCollection_AsciiString& astring)
1015     const TCollection_ExtendedString g( ea );
1016     //assert( g.Length() == ea.Length() );
1017     //assert( TCollection_AsciiString( g ) == ea );
1018     QCOMPARE ( g.Length() , ea.Length() );
1019     QCOMPARE ( TCollection_AsciiString( g ) , ea );
1020
1021     // AssignCat (const TCollection_ExtendedString& other)
1022     const TCollection_ExtendedString sep(",");
1023     d.AssignCat( sep );
1024     d.AssignCat( g );
1025     //assert( d.Length() == 2 + g.Length() );
1026     //assert( d.Token( sep.ToExtString(), 1 ) == TCollection_ExtendedString( i ));
1027     //assert( d.Token( sep.ToExtString(), 2 ) == g );
1028     QCOMPARE ( d.Length() , 2 + g.Length() );
1029     QCOMPARE ( d.Token( sep.ToExtString(), 1 ) , TCollection_ExtendedString( i ) );
1030     QCOMPARE ( d.Token( sep.ToExtString(), 2 ) , g );
1031
1032     // TCollection_ExtendedString Cat (const TCollection_ExtendedString& other) const
1033     const TCollection_ExtendedString cat = a.Cat( sep );
1034     //assert( cat.Length() == a.Length() + sep.Length() );
1035     //assert( cat.Search( a ) == 1 );
1036     //assert( cat.Search( sep ) == a.Length() + 1 );
1037     QCOMPARE ( cat.Length() , a.Length() + sep.Length() );
1038     QCOMPARE ( cat.Search( a ) , 1 );
1039     QCOMPARE ( cat.Search( sep ) , a.Length() + 1 );
1040
1041     // Copy (const TCollection_ExtendedString& fromwhere)
1042     d = cat;
1043     //assert( d.Length() == cat.Length() );
1044     //assert( d == cat );
1045     QCOMPARE ( d.Length() , cat.Length() );
1046     QCOMPARE ( d , cat );
1047
1048     // IsEqual (const Standard_ExtString other) const
1049     //assert( d.IsEqual( d.ToExtString() ));
1050     QCOMPARE ( d.IsEqual( d.ToExtString() ) , Standard_True );
1051
1052     // IsDifferent (const Standard_ExtString other ) const
1053     //assert( d.IsDifferent( a.ToExtString() ));
1054     QCOMPARE ( d.IsDifferent( a.ToExtString() ) , Standard_True );
1055
1056     // IsDifferent (const TCollection_ExtendedString& other) const
1057     //assert( d.IsDifferent( a ));
1058     QCOMPARE ( d.IsDifferent( a ) , Standard_True );
1059
1060     // IsLess (const Standard_ExtString other) const
1061     const TCollection_ExtendedString l0("0"), l1("1"), l00("00"), l, ls(theStr+i), ls1(theStr+i+1);
1062     //assert( l0. IsLess( l1.ToExtString() ));
1063     //assert( l0. IsLess( l00.ToExtString() ));
1064     //assert( l.  IsLess( l0.ToExtString() ));
1065     //assert( ! l1. IsLess( l0.ToExtString() ));
1066     //assert( ! l00.IsLess( l0.ToExtString() ));
1067     //assert( ! l0. IsLess( l.ToExtString() ));
1068     //assert( ls.IsLess( ls1.ToExtString() ));
1069     QCOMPARE ( l0. IsLess( l1.ToExtString() ) , Standard_True );
1070     QCOMPARE ( l0. IsLess( l00.ToExtString() ) , Standard_True );
1071     QCOMPARE ( l.  IsLess( l0.ToExtString() ) , Standard_True );
1072     QCOMPARE ( ! l1. IsLess( l0.ToExtString() ) , Standard_True );
1073     QCOMPARE ( ! l00.IsLess( l0.ToExtString() ) , Standard_True );
1074     QCOMPARE ( ! l0. IsLess( l.ToExtString() ) , Standard_True );
1075     QCOMPARE ( ls.IsLess( ls1.ToExtString() ) , Standard_True );
1076
1077     // IsLess (const TCollection_ExtendedString& other) const
1078     //assert( l0. IsLess( l1 ));
1079     //assert( l0. IsLess( l00 ));
1080     //assert( l.  IsLess( l0 ));
1081     //assert( ! l1. IsLess( l0 ));
1082     //assert( ! l00.IsLess( l0 ));
1083     //assert( ! l0. IsLess( l ));
1084     //assert( ls.IsLess( ls1 ));
1085     QCOMPARE ( l0. IsLess( l1 ) , Standard_True );
1086     QCOMPARE ( l0. IsLess( l00 ) , Standard_True );
1087     QCOMPARE ( l.  IsLess( l0 ) , Standard_True );
1088     QCOMPARE ( ! l1. IsLess( l0 ) , Standard_True );
1089     QCOMPARE ( ! l00.IsLess( l0 ) , Standard_True );
1090     QCOMPARE ( ! l0. IsLess( l ) , Standard_True );
1091     QCOMPARE ( ls.IsLess( ls1 ) , Standard_True );
1092
1093     // IsGreater (const Standard_ExtString other) const
1094     //assert( ! l0.IsGreater( l1.ToExtString() ));
1095     //assert( ! l0.IsGreater( l00.ToExtString() ));
1096     //assert( ! l. IsGreater( l0.ToExtString() ));
1097     //assert(  l1. IsGreater( l0.ToExtString() ));
1098     //assert(  l00.IsGreater( l0.ToExtString() ));
1099     //assert(  l0. IsGreater( l.ToExtString() ));
1100     //assert(  ls1.IsGreater( ls.ToExtString() ));
1101     QCOMPARE ( ! l0.IsGreater( l1.ToExtString() ) , Standard_True );
1102     QCOMPARE ( ! l0.IsGreater( l00.ToExtString() ) , Standard_True );
1103     QCOMPARE ( ! l. IsGreater( l0.ToExtString() ) , Standard_True );
1104     QCOMPARE ( l1. IsGreater( l0.ToExtString() ) , Standard_True );
1105     QCOMPARE ( l00.IsGreater( l0.ToExtString() ) , Standard_True );
1106     QCOMPARE ( l0. IsGreater( l.ToExtString() ) , Standard_True );
1107     QCOMPARE ( ls1.IsGreater( ls.ToExtString() ) ,Standard_True  );
1108
1109     // IsGreater (const TCollection_ExtendedString& other) const
1110     //assert( ! l0.IsGreater( l1));
1111     //assert( ! l0.IsGreater( l00));
1112     //assert( ! l. IsGreater( l0));
1113     //assert(  l1. IsGreater( l0));
1114     //assert(  l00.IsGreater( l0));
1115     //assert(  l0. IsGreater( l));
1116     //assert(  ls1.IsGreater( ls));
1117     QCOMPARE ( ! l0.IsGreater( l1) , Standard_True );
1118     QCOMPARE ( ! l0.IsGreater( l00) , Standard_True );
1119     QCOMPARE ( ! l. IsGreater( l0) , Standard_True );
1120     QCOMPARE ( l1. IsGreater( l0) , Standard_True );
1121     QCOMPARE ( l00.IsGreater( l0) , Standard_True );
1122     QCOMPARE ( l0. IsGreater( l) , Standard_True );
1123     QCOMPARE ( ls1.IsGreater( ls) , Standard_True );
1124
1125     // ==========================
1126     //TCollection_HAsciiString::
1127     // ==========================
1128
1129     // IsDifferent(const Handle(TCollection_HAsciiString)& S)
1130     Handle(TCollection_HAsciiString) ha1 = new TCollection_HAsciiString( theStr+i );
1131     Handle(TCollection_HAsciiString) ha2 = new TCollection_HAsciiString( theStr+i+1 );
1132     //assert( ha1->IsDifferent( ha2 ));
1133     //assert( !ha1->IsDifferent( ha1 ));
1134     QCOMPARE ( ha1->IsDifferent( ha2 ) , Standard_True );
1135     QCOMPARE ( !ha1->IsDifferent( ha1 ) , Standard_True );
1136
1137     // IsSameString (const Handle(TCollection_HAsciiString)& S)
1138     //assert( !ha1->IsSameString( ha2 ));
1139     //assert( ha1->IsSameString( ha1 ));
1140     QCOMPARE ( !ha1->IsSameString( ha2 ) , Standard_True );
1141     QCOMPARE ( ha1->IsSameString( ha1 ) , Standard_True );
1142
1143     // IsSameState (const Handle(TCollection_HAsciiString)& other) const
1144     //assert( !ha1->IsSameState( ha2 ));
1145     //assert( ha1->IsSameState( ha1 ));
1146     QCOMPARE ( !ha1->IsSameState( ha2 ) , Standard_True );
1147     QCOMPARE ( ha1->IsSameState( ha1 ) , Standard_True );
1148
1149     // IsSameString (const Handle(TCollection_HAsciiString)& S ,
1150     //               const Standard_Boolean CaseSensitive) const
1151     //assert( !ha1->IsSameString( ha2, true ));
1152     //assert( ha1->IsSameString( ha1, true ));
1153     //assert( !ha1->IsSameString( ha2, false ));
1154     //assert( ha1->IsSameString( ha1, false ));
1155     QCOMPARE ( !ha1->IsSameString( ha2, Standard_True ) , Standard_True );
1156     QCOMPARE ( ha1->IsSameString( ha1, Standard_True ) , Standard_True );
1157     QCOMPARE ( !ha1->IsSameString( ha2, Standard_False ) , Standard_True );
1158     QCOMPARE ( ha1->IsSameString( ha1, Standard_False ) , Standard_True );
1159
1160     ha1->SetValue( 1, "AbC0000000");
1161     ha2->SetValue( 1, "aBc0000000");
1162     //assert( !ha1->IsSameString( ha2, true ));
1163     //assert( ha1->IsSameString( ha2, false ));
1164     QCOMPARE ( !ha1->IsSameString( ha2, Standard_True ) , Standard_True );
1165     QCOMPARE (  ha1->IsSameString( ha2, Standard_False ), Standard_True );
1166   }
1167   return 0;
1168 }
1169
1170 #include <Geom_CylindricalSurface.hxx>
1171 #include <IntTools_FaceFace.hxx>
1172 #include <IntTools_Curve.hxx>
1173 #include <IntTools_PntOn2Faces.hxx>
1174
1175 static Standard_Integer OCC24005 (Draw_Interpretor& theDI, Standard_Integer theNArg, const char** theArgv) 
1176 {
1177   if(theNArg < 2)
1178   {
1179     theDI << "Wrong a number of arguments!\n";
1180     return 1;
1181   }
1182
1183   Handle(Geom_Plane) plane(new Geom_Plane(
1184                                   gp_Ax3( gp_Pnt(-72.948737453424499, 754.30437716359393, 259.52151854671678),
1185                                   gp_Dir(6.2471473085930200e-007, -0.99999999999980493, 0.00000000000000000),
1186                                   gp_Dir(0.99999999999980493, 6.2471473085930200e-007, 0.00000000000000000))));
1187   Handle(Geom_CylindricalSurface) cylinder(
1188                   new Geom_CylindricalSurface(
1189                                   gp_Ax3(gp_Pnt(-6.4812490053250649, 753.39408794522092, 279.16400974257465),
1190                                   gp_Dir(1.0000000000000000, 0.0, 0.00000000000000000),
1191                                   gp_Dir(0.0, 1.0000000000000000, 0.00000000000000000)),
1192                                                                                           19.712534607908712));
1193
1194   DrawTrSurf::Set("pln", plane);
1195   theDI << "pln\n";
1196   DrawTrSurf::Set("cyl", cylinder);
1197   theDI << "cyl\n";
1198
1199   BRep_Builder builder;
1200   TopoDS_Face face1, face2;
1201   builder.MakeFace(face1, plane, Precision::Confusion());
1202   builder.MakeFace(face2, cylinder, Precision::Confusion());
1203   IntTools_FaceFace anInters;
1204   anInters.SetParameters(false, true, true, Precision::Confusion());
1205   anInters.Perform(face1, face2);
1206
1207   if (!anInters.IsDone())
1208   {
1209     theDI<<"No intersections found!\n";
1210
1211     return 1;
1212   }
1213
1214   //Handle(Geom_Curve) aResult;
1215   //gp_Pnt             aPoint;
1216
1217   const IntTools_SequenceOfCurves& aCvsX=anInters.Lines();
1218   const IntTools_SequenceOfPntOn2Faces& aPntsX=anInters.Points();
1219
1220   char buf[1024];  
1221   Standard_Integer aNbCurves, aNbPoints;
1222
1223   aNbCurves=aCvsX.Length();
1224   aNbPoints=aPntsX.Length();
1225
1226   if (aNbCurves >= 2)
1227   {
1228     for (Standard_Integer i=1; i<=aNbCurves; ++i)
1229     {
1230       Sprintf(buf, "%s_%d",theArgv[1],i);
1231       theDI << buf << " ";
1232       
1233       const IntTools_Curve& aIC = aCvsX(i);
1234       const Handle(Geom_Curve)& aC3D= aIC.Curve();
1235       DrawTrSurf::Set(buf,aC3D);
1236     }
1237   }
1238   else if (aNbCurves == 1)
1239   {
1240     const IntTools_Curve& aIC = aCvsX(1);
1241     const Handle(Geom_Curve)& aC3D= aIC.Curve();
1242     Sprintf(buf, "%s",theArgv[1]);
1243     theDI << buf << " ";
1244     DrawTrSurf::Set(buf,aC3D);
1245   }
1246
1247   for (Standard_Integer i = 1; i<=aNbPoints; ++i)
1248   {
1249     const IntTools_PntOn2Faces& aPi=aPntsX(i);
1250     const gp_Pnt& aP=aPi.P1().Pnt();
1251     
1252     Sprintf(buf,"%s_p_%d",theArgv[1],i);
1253     theDI << buf << " ";
1254     DrawTrSurf::Set(buf, aP);
1255   }
1256
1257   return 0;
1258 }
1259
1260 #include <BRepAlgo_NormalProjection.hxx>
1261 static Standard_Integer OCC24012 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) 
1262 {
1263         if (argc != 3) {
1264                 di << "Usage : " << argv[0] << " should be 2 arguments (face and edge)";
1265                 return 1;
1266         }
1267         
1268         Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
1269         if(myAISContext.IsNull()) {
1270                 di << "use 'vinit' command before " << argv[0] << "\n";
1271                 return 1;
1272         }
1273
1274         TopoDS_Face m_Face1 = TopoDS::Face(DBRep::Get(argv[1]));
1275         TopoDS_Edge m_Edge = TopoDS::Edge(DBRep::Get(argv[2]));
1276         
1277         BRepAlgo_NormalProjection anormpro(m_Face1);
1278     anormpro.Add(m_Edge);
1279     anormpro.SetDefaultParams();
1280
1281     //anormpro.Compute3d();
1282     //anormpro.SetLimit();
1283
1284     anormpro.Build();
1285
1286     if (anormpro.IsDone())
1287     {
1288         TopoDS_Shape rshape = anormpro.Projection();
1289                 Handle(AIS_InteractiveObject) myShape = new AIS_Shape (rshape);
1290                 myAISContext->SetColor (myShape, Quantity_Color(Quantity_NOC_YELLOW), Standard_False);
1291                 myAISContext->Display (myShape, Standard_True);
1292     }
1293
1294         return 0;
1295 }
1296
1297 #include <BRepFeat_SplitShape.hxx>
1298 #include <ShapeAnalysis_ShapeContents.hxx>
1299 #include <BRepAlgo.hxx>
1300 static Standard_Integer OCC24086 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) 
1301 {
1302         if (argc != 3) {
1303                 di << "Usage : " << argv[0] << " should be 2 arguments (face and wire)";
1304                 return 1;
1305         }
1306         
1307         Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
1308         if(myAISContext.IsNull()) {
1309                 di << "use 'vinit' command before " << argv[0] << "\n";
1310                 return 1;
1311         }
1312         
1313         TopoDS_Shape result;
1314         TopoDS_Face face = TopoDS::Face(DBRep::Get(argv[1]));
1315         TopoDS_Wire wire = TopoDS::Wire(DBRep::Get(argv[2]));
1316     
1317         BRepFeat_SplitShape asplit(face);
1318         asplit.Add(wire, face);
1319         asplit.Build();
1320     result = asplit.Shape();
1321     ShapeAnalysis_ShapeContents ana;
1322     ana.Perform(result);
1323     ana.NbFaces();
1324
1325         if (!(BRepAlgo::IsValid(result))) {
1326                 di << "Result was checked and it is INVALID\n";
1327         } else {
1328                 di << "Result was checked and it is VALID\n";
1329         }
1330         
1331         Handle(AIS_InteractiveObject) myShape = new AIS_Shape (result);
1332         myAISContext->Display(myShape, Standard_True);
1333
1334         return 0;
1335 }
1336
1337 #include <Geom_Circle.hxx>
1338 #include <GeomAdaptor_Curve.hxx>
1339 #include <Extrema_ExtPC.hxx>
1340 #include <gp_Cylinder.hxx>
1341 #include <ElSLib.hxx>
1342 static Standard_Integer OCC24945 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1343 {
1344   if (argc != 1) {
1345     di << "Usage: " << argv[0] << " invalid number of arguments\n";
1346     return 1;
1347   }
1348
1349   gp_Pnt aP3D( -1725.97, 843.257, -4.22741e-013 );
1350   gp_Ax2 aAxis( gp_Pnt( 0, 843.257, 0 ), gp_Dir( 0, -1, 0 ), gp::DX() );
1351   Handle(Geom_Circle) aCircle = new Geom_Circle( aAxis, 1725.9708621929999 );
1352   GeomAdaptor_Curve aC3D( aCircle );
1353
1354   Extrema_ExtPC aExtPC( aP3D, aC3D );
1355   //Standard_Real aParam = (aExtPC.Point(1)).Parameter();
1356   gp_Pnt aProj = (aExtPC.Point(1)).Value();
1357   di << "Projected point: X = " << aProj.X() << "; Y = " << aProj.Y() << "; Z = " << aProj.Z() << "\n";
1358
1359   // Result of deviation
1360   gp_Ax2 aCylAxis( gp_Pnt( 0, 2103.87, 0 ), -gp::DY(), -gp::DX() );
1361   gp_Cylinder aCylinder( aCylAxis, 1890. );
1362
1363   Standard_Real aU = 0., aV = 0.;
1364   ElSLib::Parameters( aCylinder, aProj, aU, aV );
1365   di << "Parameters on cylinder: U = " << aU << "; V = " << aV << "\n";
1366   
1367   return 0;
1368 }
1369
1370 #include <Extrema_FuncPSNorm.hxx>
1371 #include <math_FunctionSetRoot.hxx>
1372 #include <math_Vector.hxx>
1373 #include <BRepBuilderAPI_MakeVertex.hxx>
1374 static Standard_Integer OCC24137 (Draw_Interpretor& theDI, Standard_Integer theNArg, const char** theArgv) 
1375 {
1376   Standard_Integer anArgIter = 1;
1377   if (theNArg < 5)
1378     {
1379       theDI <<"Usage: " << theArgv[0] << " face vertex U V [N]\n";
1380       return 1;
1381     }
1382
1383   // get target shape
1384   Standard_CString aFaceName = theArgv[anArgIter++];
1385   Standard_CString aVertName = theArgv[anArgIter++];
1386   const TopoDS_Shape aShapeF = DBRep::Get (aFaceName);
1387   const TopoDS_Shape aShapeV = DBRep::Get (aVertName);
1388   const Standard_Real aUFrom = Atof (theArgv[anArgIter++]);
1389   const Standard_Real aVFrom = Atof (theArgv[anArgIter++]);
1390   const Standard_Integer aNbIts = (anArgIter < theNArg) ? atol (theArgv[anArgIter++]) : 100;
1391   if (aShapeF.IsNull() || aShapeF.ShapeType() != TopAbs_FACE)
1392     {
1393       std::cout << "Error: " << aFaceName << " shape is null / not a face" << std::endl;
1394       return 1;
1395     }
1396   if (aShapeV.IsNull() || aShapeV.ShapeType() != TopAbs_VERTEX)
1397     {
1398       std::cout << "Error: " << aVertName << " shape is null / not a vertex" << std::endl;
1399       return 1;
1400     }
1401   const TopoDS_Face   aFace = TopoDS::Face   (aShapeF);
1402   const TopoDS_Vertex aVert = TopoDS::Vertex (aShapeV);
1403   GeomAdaptor_Surface aSurf (BRep_Tool::Surface (aFace));
1404
1405   gp_Pnt aPnt = BRep_Tool::Pnt (aVert), aRes;
1406
1407   Extrema_FuncPSNorm    anExtFunc;
1408   math_FunctionSetRoot aRoot (anExtFunc, aNbIts);
1409
1410   math_Vector aTolUV (1, 2), aUVinf  (1, 2), aUVsup  (1, 2), aFromUV (1, 2);
1411   aTolUV (1) =  Precision::Confusion(); aTolUV (2) =  Precision::Confusion();
1412   aUVinf (1) = -Precision::Infinite();  aUVinf (2) = -Precision::Infinite();
1413   aUVsup (1) =  Precision::Infinite();  aUVsup (2) =  Precision::Infinite();
1414   aFromUV(1) =  aUFrom; aFromUV(2) = aVFrom;
1415
1416   anExtFunc.Initialize (aSurf);
1417   anExtFunc.SetPoint (aPnt);
1418   aRoot.SetTolerance (aTolUV);
1419   aRoot.Perform (anExtFunc, aFromUV, aUVinf, aUVsup);
1420   if (!aRoot.IsDone())
1421     {
1422       std::cerr << "No results!\n";
1423       return 1;
1424     }
1425
1426   theDI << aRoot.Root()(1) << " " << aRoot.Root()(2) << "\n";
1427   
1428   aSurf.D0 (aRoot.Root()(1), aRoot.Root()(2), aRes);
1429   DBRep::Set ("result", BRepBuilderAPI_MakeVertex (aRes));
1430   return 0;
1431 }
1432
1433 //! Check boolean operations on NCollection_Map
1434 static Standard_Integer OCC24271 (Draw_Interpretor& di,
1435                                   Standard_Integer  /*theArgNb*/,
1436                                   const char**      /*theArgVec*/)
1437 {
1438   // input data
1439   const Standard_Integer aLeftLower  = 1;
1440   const Standard_Integer aLeftUpper  = 10;
1441   const Standard_Integer aRightLower = 5;
1442   const Standard_Integer aRightUpper = 15;
1443
1444   // define arguments
1445   NCollection_Map<Standard_Integer> aMapLeft;
1446   for (Standard_Integer aKeyIter = aLeftLower; aKeyIter <= aLeftUpper; ++aKeyIter)
1447   {
1448     aMapLeft.Add (aKeyIter);
1449   }
1450
1451   NCollection_Map<Standard_Integer> aMapRight;
1452   for (Standard_Integer aKeyIter = aRightLower; aKeyIter <= aRightUpper; ++aKeyIter)
1453   {
1454     aMapRight.Add (aKeyIter);
1455   }
1456
1457   QCOMPARE (aMapLeft .Contains (aMapRight), Standard_False);
1458   QCOMPARE (aMapRight.Contains (aMapLeft),  Standard_False);
1459
1460   // validate Union operation
1461   NCollection_Map<Standard_Integer> aMapUnion;
1462   aMapUnion.Union (aMapLeft, aMapRight);
1463   QCOMPARE (aMapUnion.Extent(), aRightUpper - aLeftLower + 1);
1464   for (Standard_Integer aKeyIter = aLeftLower; aKeyIter <= aRightUpper; ++aKeyIter)
1465   {
1466     QCOMPARE (aMapUnion.Contains (aKeyIter), Standard_True);
1467   }
1468
1469   // validate Intersection operation
1470   NCollection_Map<Standard_Integer> aMapSect;
1471   aMapSect.Intersection (aMapLeft, aMapRight);
1472   QCOMPARE (aMapSect.Extent(), aLeftUpper - aRightLower + 1);
1473   for (Standard_Integer aKeyIter = aRightLower; aKeyIter <= aLeftUpper; ++aKeyIter)
1474   {
1475     QCOMPARE (aMapSect.Contains (aKeyIter), Standard_True);
1476   }
1477   QCOMPARE (aMapLeft .Contains (aMapSect), Standard_True);
1478   QCOMPARE (aMapRight.Contains (aMapSect), Standard_True);
1479
1480   // validate Substruction operation
1481   NCollection_Map<Standard_Integer> aMapSubsLR;
1482   aMapSubsLR.Subtraction (aMapLeft, aMapRight);
1483   QCOMPARE (aMapSubsLR.Extent(), aRightLower - aLeftLower);
1484   for (Standard_Integer aKeyIter = aLeftLower; aKeyIter < aRightLower; ++aKeyIter)
1485   {
1486     QCOMPARE (aMapSubsLR.Contains (aKeyIter), Standard_True);
1487   }
1488
1489   NCollection_Map<Standard_Integer> aMapSubsRL;
1490   aMapSubsRL.Subtraction (aMapRight, aMapLeft);
1491   QCOMPARE (aMapSubsRL.Extent(), aRightUpper - aLeftUpper);
1492   for (Standard_Integer aKeyIter = aLeftUpper + 1; aKeyIter < aRightUpper; ++aKeyIter)
1493   {
1494     QCOMPARE (aMapSubsRL.Contains (aKeyIter), Standard_True);
1495   }
1496
1497   // validate Difference operation
1498   NCollection_Map<Standard_Integer> aMapDiff;
1499   aMapDiff.Difference (aMapLeft, aMapRight);
1500   QCOMPARE (aMapDiff.Extent(), aRightLower - aLeftLower + aRightUpper - aLeftUpper);
1501   for (Standard_Integer aKeyIter = aLeftLower; aKeyIter < aRightLower; ++aKeyIter)
1502   {
1503     QCOMPARE (aMapDiff.Contains (aKeyIter), Standard_True);
1504   }
1505   for (Standard_Integer aKeyIter = aLeftUpper + 1; aKeyIter < aRightUpper; ++aKeyIter)
1506   {
1507     QCOMPARE (aMapDiff.Contains (aKeyIter), Standard_True);
1508   }
1509
1510   // validate Exchange operation
1511   NCollection_Map<Standard_Integer> aMapSwap;
1512   aMapSwap.Exchange (aMapSect);
1513   for (Standard_Integer aKeyIter = aRightLower; aKeyIter <= aLeftUpper; ++aKeyIter)
1514   {
1515     QCOMPARE (aMapSwap.Contains (aKeyIter), Standard_True);
1516   }
1517   QCOMPARE (aMapSect.IsEmpty(), Standard_True);
1518   aMapSwap.Add (34);
1519   aMapSect.Add (43);
1520
1521   NCollection_Map<Standard_Integer> aMapCopy (aMapSwap);
1522   QCOMPARE (aMapCopy.IsEqual (aMapSwap), Standard_True);
1523   aMapCopy.Remove (34);
1524   aMapCopy.Add    (43);
1525   QCOMPARE (aMapCopy.IsEqual (aMapSwap), Standard_False);
1526
1527   return 0;
1528 }
1529
1530 #define QVERIFY(val1) \
1531   di << "Checking " #val1 " == Standard_True" << \
1532         ((val1) == Standard_True ? ": OK\n" : ": Error\n")
1533
1534 #include <GeomInt_IntSS.hxx>
1535 #include <Geom_ConicalSurface.hxx>
1536 #include <Standard_ErrorHandler.hxx>
1537 //=======================================================================
1538 //function : OCC23972
1539 //purpose  : 
1540 //=======================================================================
1541 static void DoGeomIntSSTest (const Handle(Geom_Surface)& theSurf1,
1542                              const Handle(Geom_Surface)& theSurf2,
1543                              const Standard_Integer theNbSol,
1544                              Draw_Interpretor& di)
1545 {
1546   try {
1547     OCC_CATCH_SIGNALS
1548          GeomInt_IntSS anInter;
1549          anInter.Perform (theSurf1, theSurf2, Precision::Confusion(), Standard_True);
1550          QVERIFY (anInter.IsDone());
1551          QCOMPARE (anInter.NbLines(), theNbSol);
1552   } catch (...) {
1553     QVERIFY (Standard_False);
1554   }
1555 }
1556
1557 namespace {
1558   static Handle(Geom_ConicalSurface) CreateCone (const gp_Pnt& theLoc,
1559                                                  const gp_Dir& theDir,
1560                                                  const gp_Dir& theXDir,
1561                                                  const Standard_Real theRad,
1562                                                  const Standard_Real theSin,
1563                                                  const Standard_Real theCos)
1564   {
1565     const Standard_Real anA = atan (theSin / theCos);
1566     gp_Ax3 anAxis (theLoc, theDir, theXDir);
1567     Handle(Geom_ConicalSurface) aSurf = new Geom_ConicalSurface (anAxis, anA, theRad);
1568     return aSurf;
1569   }
1570 }
1571
1572 static Standard_Integer OCC23972 (Draw_Interpretor& di,Standard_Integer n, const char**)
1573 {
1574   if (n != 1) return 1;
1575
1576   //process specific cones, cannot read them from files because due to rounding the original error
1577   //in math_FunctionRoots gets hidden
1578   Handle(Geom_Surface) aS1 = CreateCone (
1579                                          gp_Pnt (123.694345356663, 789.9, 68.15),
1580                                          gp_Dir (-1, 3.48029791472957e-016, -8.41302743359754e-017),
1581                                          gp_Dir (-3.48029791472957e-016, -1, -3.17572289932207e-016),
1582                                          3.28206830417112,
1583                                          0.780868809443031,
1584                                          0.624695047554424);
1585   Handle(Geom_Surface) aS2 = CreateCone (
1586                                          gp_Pnt (123.694345356663, 784.9, 68.15),
1587                                          gp_Dir (-1, -2.5209507537117e-016, -1.49772808948866e-016),
1588                                          gp_Dir (1.49772808948866e-016, 3.17572289932207e-016, -1),
1589                                          3.28206830417112,
1590                                          0.780868809443031,
1591                                          0.624695047554424);
1592   
1593   DoGeomIntSSTest (aS1, aS2, 2, di);
1594
1595   return 0;
1596 }
1597
1598 #include <ShapeFix_EdgeProjAux.hxx>
1599 static Standard_Integer OCC24370 (Draw_Interpretor& di, Standard_Integer argc,const char ** argv)
1600 {
1601   if (argc < 5) {
1602     di<<"Usage: " << argv[0] << " invalid number of arguments\n";
1603     return 1;
1604   }
1605
1606   TopoDS_Shape aSh = DBRep::Get(argv[1]);
1607   if (aSh.IsNull()) {
1608     di << argv[0] << " Error: Null input edge\n";
1609     return 1;
1610   }
1611   const TopoDS_Edge& anEdge = TopoDS::Edge (aSh);
1612
1613   Handle(Geom2d_Curve) aC = DrawTrSurf::GetCurve2d(argv[2]);
1614   if (aC.IsNull()) {
1615     di << argv[0] << " Error: Null input curve\n";
1616     return 1;
1617   }
1618
1619   Handle(Geom_Surface) aS = DrawTrSurf::GetSurface(argv[3]);
1620   if (aS.IsNull()) {
1621     di << argv[0] << " Error: Null input surface\n";
1622     return 1;
1623   }
1624
1625   Standard_Real prec = Draw::Atof(argv[4]);
1626   
1627   //prepare data
1628   TopoDS_Face aFace;
1629   BRep_Builder aB;
1630   aB.MakeFace (aFace, aS, Precision::Confusion());
1631   aB.UpdateEdge (anEdge, aC, aFace, Precision::Confusion());
1632   aB.Range (anEdge, aFace, aC->FirstParameter(), aC->LastParameter());
1633
1634   //call algorithm
1635   ShapeFix_EdgeProjAux aProj (aFace, anEdge);
1636   aProj.Compute (prec);
1637   
1638   Standard_Boolean isfirstdone = aProj.IsFirstDone();
1639   Standard_Boolean islastdone = aProj.IsLastDone();
1640
1641   Standard_Real first = 0.;
1642   Standard_Real last = 0.;
1643   Standard_Integer isfirstdoneInteger = 0;
1644   Standard_Integer islastdoneInteger = 0;
1645
1646
1647   if (isfirstdone) {
1648     first = aProj.FirstParam();
1649     isfirstdoneInteger = 1;
1650   }
1651  
1652   if (islastdone) {
1653     last= aProj.LastParam();
1654     islastdoneInteger = 1;
1655   }
1656
1657   di << isfirstdoneInteger << " "<< islastdoneInteger << " "<< first << " "<< last << " \n";
1658
1659   return 0;
1660 }
1661
1662 template<typename T, typename HT>
1663 static void DoIsNull(Draw_Interpretor& di)
1664 {
1665   HT aHandle;
1666   //    QVERIFY (aHandle.IsNull());
1667   QCOMPARE (aHandle.IsNull(), Standard_True);
1668   const T* p = aHandle.get();
1669 #if OCC_VERSION_HEX > 0x060700
1670   //QVERIFY (!p);
1671   //QVERIFY (p == 0);
1672   QCOMPARE (!p, Standard_True);
1673   QCOMPARE (p == 0, Standard_True);
1674 #endif
1675
1676   aHandle = new T;
1677   //QVERIFY (!aHandle.IsNull());
1678   QCOMPARE (!aHandle.IsNull(), Standard_True);
1679   p = aHandle.get();
1680   //QVERIFY (p);
1681   //QVERIFY (p != 0);
1682   QCOMPARE (p != NULL, Standard_True);
1683   QCOMPARE (p != 0, Standard_True);
1684 }
1685
1686 //=======================================================================
1687 //function : OCC24533
1688 //purpose  : 
1689 //=======================================================================
1690 static Standard_Integer OCC24533 (Draw_Interpretor& di, Standard_Integer n, const char**)
1691 {
1692   if (n != 1) return 1;
1693
1694   DoIsNull<Standard_Transient, Handle(Standard_Transient)>(di);
1695
1696   return 0;
1697 }
1698
1699 // Dummy class to test interface for compilation issues
1700 class QABugs_HandleClass : public Standard_Transient
1701 {
1702 public:
1703   Standard_Integer HandleProc (Draw_Interpretor& , Standard_Integer  , const char** theArgVec)
1704   {
1705     std::cerr << "QABugs_HandleClass[" << this << "] " << theArgVec[0] << "\n";
1706     return 0;
1707   }
1708   DEFINE_STANDARD_RTTI_INLINE(QABugs_HandleClass,Standard_Transient) // Type definition
1709 };
1710 DEFINE_STANDARD_HANDLE    (QABugs_HandleClass, Standard_Transient)
1711
1712
1713 // Dummy class to test interface for compilation issues
1714 struct QABugs_NHandleClass
1715 {
1716   Standard_Integer NHandleProc (Draw_Interpretor& , Standard_Integer  , const char** theArgVec)
1717   {
1718     std::cerr << "QABugs_NHandleClass[" << this << "] " << theArgVec[0] << "\n";
1719     return 0;
1720   }
1721 };
1722
1723 #include <XCAFDoc_ColorTool.hxx>
1724 #include <STEPControl_StepModelType.hxx>
1725 #include <STEPCAFControl_Writer.hxx>
1726 static Standard_Integer OCC23951 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1727 {
1728   if (argc != 2) {
1729     di << "Usage: " << argv[0] << " invalid number of arguments\n";
1730     return 1;
1731   }
1732   Handle(TDocStd_Document) aDoc = new TDocStd_Document("dummy");;
1733   TopoDS_Shape s1 = BRepPrimAPI_MakeBox(1,1,1).Shape();
1734   TDF_Label lab1 = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main ())->NewShape();
1735   XCAFDoc_DocumentTool::ShapeTool (aDoc->Main ())->SetShape(lab1, s1);
1736   TDataStd_Name::Set(lab1, "Box1");
1737         
1738   Quantity_Color yellow(1,1,0, Quantity_TOC_RGB);
1739   XCAFDoc_DocumentTool::ColorTool (aDoc->Main())->SetColor(lab1, yellow, XCAFDoc_ColorGen);
1740   XCAFDoc_DocumentTool::ColorTool(aDoc->Main())->SetVisibility(lab1, 0);
1741
1742   STEPControl_StepModelType mode = STEPControl_AsIs;
1743   STEPCAFControl_Writer writer;
1744   if ( ! writer.Transfer (aDoc, mode ) )
1745   {
1746     di << "The document cannot be translated or gives no result"  <<  "\n";
1747     return 1;
1748   }
1749
1750   writer.Write(argv[1]);
1751   return 0;
1752 }
1753
1754
1755 //=======================================================================
1756 //function : OCC23950
1757 //purpose  :
1758 //=======================================================================
1759 static Standard_Integer OCC23950 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1760 {
1761   if (argc != 2) {
1762     di << "Usage : " << argv[0] << " step_file\n";
1763     return 1;
1764   }
1765
1766   Handle(TDocStd_Document) aDoc = new TDocStd_Document ("dummy");
1767   TopoDS_Shape s6 = BRepBuilderAPI_MakeVertex (gp_Pnt (75, 0, 0));
1768   gp_Trsf t0;
1769   TopLoc_Location location0 (t0);
1770
1771   TDF_Label lab1 = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main ())->NewShape ();
1772   XCAFDoc_DocumentTool::ShapeTool (aDoc->Main ())->SetShape (lab1, s6);
1773   TDataStd_Name::Set(lab1, "Point1");
1774
1775   TDF_Label labelA0 = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main ())->NewShape ();
1776   TDataStd_Name::Set(labelA0, "ASSEMBLY");
1777
1778   TDF_Label component01 = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main ())->AddComponent (labelA0, lab1, location0);
1779   XCAFDoc_DocumentTool::ShapeTool (aDoc->Main ())->UpdateAssemblies();
1780
1781   Quantity_Color yellow(1,1,0, Quantity_TOC_RGB);
1782   XCAFDoc_DocumentTool::ColorTool (labelA0)->SetColor (component01, yellow, XCAFDoc_ColorGen);
1783   XCAFDoc_DocumentTool::ColorTool (labelA0)->SetVisibility (component01, 0);
1784
1785   STEPControl_StepModelType mode = STEPControl_AsIs;
1786   STEPCAFControl_Writer writer;
1787   if (! writer.Transfer (aDoc, mode))
1788   {
1789     di << "The document cannot be translated or gives no result\n";
1790     return 1;
1791   }
1792
1793   writer.Write (argv[1]);
1794   return 0;
1795 }
1796
1797 //=======================================================================
1798 //function : OCC24667
1799 //purpose  : 
1800 //=======================================================================
1801 static Standard_Integer OCC24667 (Draw_Interpretor& di, Standard_Integer n, const char** a)
1802 {
1803   if (n == 1)
1804   {
1805     di << "OCC24667 result Wire_spine Profile [Mode [Approx]]\n";
1806     di << "Mode = 0 - CorrectedFrenet,\n";
1807     di << "     = 1 - Frenet,\n";
1808     di << "     = 2 - DiscreteTrihedron\n";
1809     di << "Approx - force C1-approximation if result is C0\n";
1810     return 0;
1811   }
1812
1813   if (n > 1 && n < 4) return 1;
1814
1815   TopoDS_Shape Spine = DBRep::Get(a[2],TopAbs_WIRE);
1816   if ( Spine.IsNull()) return 1;
1817
1818   TopoDS_Shape Profile = DBRep::Get(a[3]);
1819   if ( Profile.IsNull()) return 1;
1820
1821   GeomFill_Trihedron Mode = GeomFill_IsCorrectedFrenet;
1822   if (n >= 5)
1823   {
1824     Standard_Integer iMode = atoi(a[4]);
1825     if (iMode == 1)
1826       Mode = GeomFill_IsFrenet;
1827     else if (iMode == 2)
1828       Mode = GeomFill_IsDiscreteTrihedron;
1829   }
1830
1831   Standard_Boolean ForceApproxC1 = Standard_False;
1832   if (n >= 6)
1833     ForceApproxC1 = Standard_True;
1834
1835   BRepOffsetAPI_MakePipe aPipe(TopoDS::Wire(Spine),
1836                                           Profile,
1837                                           Mode,
1838                                           ForceApproxC1);
1839
1840   TopoDS_Shape S = aPipe.Shape();
1841   TopoDS_Shape aSF = aPipe.FirstShape();
1842   TopoDS_Shape aSL = aPipe.LastShape();
1843
1844   DBRep::Set(a[1],S);
1845
1846   TCollection_AsciiString aStrF(a[1], "_f");
1847   TCollection_AsciiString aStrL(a[1], "_l");
1848
1849   DBRep::Set(aStrF.ToCString(), aSF);
1850   DBRep::Set(aStrL.ToCString(), aSL);
1851
1852   return 0;
1853 }
1854
1855 #include <BRepPrimAPI_MakeCylinder.hxx>
1856 #include <BRepBuilderAPI_Copy.hxx>
1857 #include <BRepTools_NurbsConvertModification.hxx>
1858 static TopoDS_Shape CreateTestShape (int& theShapeNb)
1859 {
1860   TopoDS_Compound aComp;
1861   BRep_Builder aBuilder;
1862   aBuilder.MakeCompound (aComp);
1863   //NURBS modifier is used to increase footprint of each shape
1864   Handle(BRepTools_NurbsConvertModification) aNurbsModif = new BRepTools_NurbsConvertModification;
1865   TopoDS_Shape aRefShape = BRepPrimAPI_MakeCylinder (50., 100.).Solid();
1866   BRepTools_Modifier aModifier (aRefShape, aNurbsModif);
1867   if (aModifier.IsDone()) {
1868     aRefShape = aModifier.ModifiedShape (aRefShape);
1869   }
1870   int aSiblingNb = 0;
1871   for (; theShapeNb > 0; --theShapeNb) {
1872     TopoDS_Shape aShape;
1873     if (++aSiblingNb <= 100) { //number of siblings is limited to avoid long lists
1874                 aShape = BRepBuilderAPI_Copy (aRefShape, Standard_True /*CopyGeom*/).Shape();
1875     } else {
1876       aShape = CreateTestShape (theShapeNb);
1877     }
1878     aBuilder.Add (aComp, aShape);
1879   }
1880   return aComp;
1881 }
1882
1883 #include <TDataStd_Integer.hxx>
1884 #include <TNaming_Builder.hxx>
1885 static Standard_Integer OCC24931 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1886 {
1887   if (argc != 2) {
1888     di << "Usage: " << argv[0] << " invalid number of arguments\n";
1889     return 1;
1890   }
1891   TCollection_ExtendedString aFileName (argv[1]);
1892   PCDM_StoreStatus aSStatus  = PCDM_SS_Failure;
1893
1894   Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
1895   {
1896     Handle(TDocStd_Document) aDoc;
1897     anApp->NewDocument ("XmlOcaf", aDoc);
1898     TDF_Label aLab = aDoc->Main();
1899     TDataStd_Integer::Set (aLab, 0);
1900     int n = 10000; //must be big enough
1901     TopoDS_Shape aShape = CreateTestShape (n);
1902     TNaming_Builder aBuilder (aLab);
1903     aBuilder.Generated (aShape);
1904
1905     aSStatus = anApp->SaveAs (aDoc, aFileName);
1906     anApp->Close (aDoc);
1907   }
1908   QCOMPARE (aSStatus, PCDM_SS_OK);
1909   return 0;
1910 }
1911
1912 #include <TDF_AttributeIterator.hxx>
1913 //=======================================================================
1914 //function : OCC24755
1915 //purpose  : 
1916 //=======================================================================
1917 static Standard_Integer OCC24755 (Draw_Interpretor& di, Standard_Integer n, const char** a)
1918 {
1919   if (n != 1)
1920   {
1921     std::cout << "Usage : " << a[0] << "\n";
1922     return 1;
1923   }
1924
1925   Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
1926   Handle(TDocStd_Document) aDoc;
1927   anApp->NewDocument ("BinOcaf", aDoc);
1928   TDF_Label aLab = aDoc->Main();
1929   // Prepend an int value.
1930   TDataStd_Integer::Set (aLab, 0);
1931   // Prepend a name.
1932   TDataStd_Name::Set (aLab, "test");
1933   // Append a double value.
1934   aLab.AddAttribute(new TDataStd_Real(), true/*append*/);
1935
1936   TDF_AttributeIterator i (aLab);
1937   Handle(TDF_Attribute) anAttr = i.Value();
1938   QCOMPARE (anAttr->IsKind (STANDARD_TYPE (TDataStd_Integer)), Standard_True);
1939   i.Next();
1940   anAttr = i.Value();
1941   QCOMPARE (anAttr->IsKind (STANDARD_TYPE (TDataStd_Name)), Standard_True);
1942   i.Next();
1943   anAttr = i.Value();
1944   QCOMPARE (anAttr->IsKind (STANDARD_TYPE (TDataStd_Real)), Standard_True);
1945
1946   return 0;
1947 }
1948
1949 struct MyStubObject
1950 {
1951   MyStubObject() : ptr(0L) {}
1952   MyStubObject(void* thePtr) : ptr(thePtr) {}
1953   char overhead[40];
1954   void* ptr;
1955 };
1956
1957 //=======================================================================
1958 //function : OCC24834
1959 //purpose  : 
1960 //=======================================================================
1961 static Standard_Integer OCC24834 (Draw_Interpretor& di, Standard_Integer n, const char** a)
1962 {
1963   if (n != 1)
1964   {
1965     std::cout << "Usage : " << a[0] << "\n";
1966     return 1;
1967   }
1968
1969   int i = sizeof (char*);  
1970   if (i > 4) {
1971     std::cout << "64-bit architecture is not supported.\n";
1972     return 0;
1973   }
1974
1975   NCollection_List<MyStubObject> aList;
1976   const Standard_Integer aSmallBlockSize = 40;
1977   const Standard_Integer aLargeBlockSize = 1500000;
1978
1979   // quick populate memory with large blocks
1980   try
1981   {
1982     for (;;)
1983     {
1984       aList.Append(MyStubObject(Standard::Allocate(aLargeBlockSize)));
1985     }
1986   }
1987   catch (Standard_Failure)
1988   {
1989     di << "caught out of memory for large blocks: OK\n";
1990   }
1991   catch (...)
1992   {
1993     di << "skept out of memory for large blocks: Error\n";
1994   }
1995
1996   // allocate small blocks
1997   try
1998   {
1999     for (;;)
2000     {
2001       aList.Append(MyStubObject(Standard::Allocate(aSmallBlockSize)));
2002     }
2003   }
2004   catch (Standard_Failure)
2005   {
2006     di << "caught out of memory for small blocks: OK\n";
2007   }
2008   catch (...)
2009   {
2010     di << "skept out of memory for small blocks: Error\n";
2011   }
2012
2013   // release all allocated blocks
2014   for (NCollection_List<MyStubObject>::Iterator it(aList); it.More(); it.Next())
2015   {
2016     Standard::Free(it.Value().ptr);
2017   }
2018   return 0;
2019 }
2020
2021
2022 #include <Geom2dAPI_InterCurveCurve.hxx>
2023 #include <IntRes2d_IntersectionPoint.hxx>
2024 //=======================================================================
2025 //function : OCC24889
2026 //purpose  : 
2027 //=======================================================================
2028 static Standard_Integer OCC24889 (Draw_Interpretor& theDI,
2029                                   Standard_Integer /*theNArg*/,
2030                                   const char** /*theArgs*/)
2031 {
2032  // Curves
2033   Handle( Geom2d_Circle ) aCircle1 = new Geom2d_Circle(
2034     gp_Ax22d( gp_Pnt2d( 25, -25 ), gp_Dir2d( 1, 0 ), gp_Dir2d( -0, 1 ) ), 155 );
2035
2036   Handle( Geom2d_Circle ) aCircle2 = new Geom2d_Circle(
2037     gp_Ax22d( gp_Pnt2d( 25, 25 ), gp_Dir2d( 1, 0 ), gp_Dir2d( -0, 1 ) ), 155 );
2038
2039   Handle( Geom2d_TrimmedCurve ) aTrim[2] = {
2040     new Geom2d_TrimmedCurve( aCircle1, 1.57079632679490, 2.97959469729228 ),
2041     new Geom2d_TrimmedCurve( aCircle2, 3.30359060633978, 4.71238898038469 )
2042   };
2043
2044   DrawTrSurf::Set("c_1", aTrim[0]);
2045   DrawTrSurf::Set("c_2", aTrim[1]);
2046
2047   // Intersection
2048   const Standard_Real aTol = Precision::Confusion();
2049   Geom2dAPI_InterCurveCurve aIntTool( aTrim[0], aTrim[1], aTol );
2050
2051   const IntRes2d_IntersectionPoint& aIntPnt =
2052     aIntTool.Intersector().Point( 1 );
2053
2054   gp_Pnt2d aIntRes = aIntTool.Point( 1 );
2055   Standard_Real aPar[2] = {
2056     aIntPnt.ParamOnFirst(),
2057     aIntPnt.ParamOnSecond()
2058   };
2059
2060   //theDI.precision( 5 );
2061   theDI << "Int point: X = " << aIntRes.X() << "; Y = " << aIntRes.Y() << "\n";
2062   for (int i = 0; i < 2; ++i)
2063   {
2064     theDI << "Curve " << i << ": FirstParam = " << aTrim[i]->FirstParameter() <<
2065       "; LastParam = " << aTrim[i]->LastParameter() <<
2066       "; IntParameter = " << aPar[i] << "\n";
2067   }
2068
2069   return 0;
2070 }
2071
2072 #include <math_GlobOptMin.hxx>
2073 #include <math_MultipleVarFunctionWithHessian.hxx>
2074 //=======================================================================
2075 //function : OCC25004
2076 //purpose  : Check extremaCC on Branin function.
2077 //=======================================================================
2078 // Function is:
2079 // f(u,v) = a*(v - b*u^2 + c*u-r)^2+s(1-t)*cos(u)+s
2080 // Standard borders are:
2081 // -5 <= u <= 10
2082 //  0 <= v <= 15
2083 class BraninFunction : public math_MultipleVarFunctionWithHessian
2084 {
2085 public:
2086   BraninFunction()
2087   {
2088     a = 1.0;
2089     b = 5.1 / (4.0 * M_PI * M_PI);
2090     c = 5.0 / M_PI;
2091     r = 6.0;
2092     s = 10.0;
2093     t = 1.0 / (8.0 *  M_PI);
2094   }
2095   virtual Standard_Integer NbVariables() const
2096   {
2097     return 2;
2098   }
2099   virtual Standard_Boolean Value(const math_Vector& X,Standard_Real& F)
2100   {
2101     Standard_Real u = X(1);
2102     Standard_Real v = X(2);
2103
2104     Standard_Real aSqPt = (v - b * u * u + c * u - r); // Square Part of function.
2105     Standard_Real aLnPt = s * (1 - t) * cos(u); // Linear part of funcrtion.
2106     F = a * aSqPt * aSqPt + aLnPt + s;
2107     return Standard_True;
2108   }
2109   virtual Standard_Boolean Gradient(const math_Vector& X,math_Vector& G)
2110   {
2111     Standard_Real u = X(1);
2112     Standard_Real v = X(2);
2113
2114     Standard_Real aSqPt = (v - b * u * u + c * u - r); // Square Part of function.
2115     G(1) = 2 * a * aSqPt * (c - 2 * b * u) - s * (1 - t) * sin(u);
2116     G(2) = 2 * a * aSqPt;
2117
2118     return Standard_True;
2119   }
2120   virtual Standard_Boolean Values(const math_Vector& X,Standard_Real& F,math_Vector& G)
2121   {
2122     Value(X,F);
2123     Gradient(X,G);
2124
2125     return Standard_True;
2126   }
2127   virtual Standard_Boolean Values(const math_Vector& X,Standard_Real& F,math_Vector& G,math_Matrix& H)
2128   {
2129     Value(X,F);
2130     Gradient(X,G);
2131
2132     Standard_Real u = X(1);
2133     Standard_Real v = X(2);
2134
2135     Standard_Real aSqPt = (v - b * u * u + c * u - r); // Square Part of function.
2136     Standard_Real aTmpPt = c - 2 * b *u; // Tmp part.
2137     H(1,1) = 2 * a * aTmpPt * aTmpPt - 4 * a * b * aSqPt - s * (1 - t) * cos(u);
2138     H(1,2) = 2 * a * aTmpPt;
2139     H(2,1) = H(1,2);
2140     H(2,2) = 2 * a;
2141
2142     return Standard_True;
2143   }
2144
2145 private:
2146   // Standard parameters.
2147   Standard_Real a, b, c, r, s, t;
2148 };
2149
2150 static Standard_Integer OCC25004 (Draw_Interpretor& theDI,
2151                                   Standard_Integer /*theNArg*/,
2152                                   const char** /*theArgs*/)
2153 {
2154   BraninFunction aFunc;
2155
2156   math_Vector aLower(1,2), aUpper(1,2);
2157   aLower(1) = -5;
2158   aLower(2) =  0;
2159   aUpper(1) = 10;
2160   aUpper(2) = 15;
2161
2162   Standard_Integer aGridOrder = 16;
2163   math_Vector aFuncValues(1, aGridOrder * aGridOrder);
2164
2165   Standard_Real aLipConst = 0;
2166   math_Vector aCurrPnt1(1, 2), aCurrPnt2(1, 2);
2167
2168   // Get Lipshitz constant estimation on regular grid.
2169   Standard_Integer i, j, idx = 1;
2170   for(i = 1; i <= aGridOrder; i++)
2171   {
2172     for(j = 1; j <= aGridOrder; j++)
2173     {
2174       aCurrPnt1(1) = aLower(1) + (aUpper(1) - aLower(1)) * (i - 1) / (aGridOrder - 1.0);
2175       aCurrPnt1(2) = aLower(2) + (aUpper(2) - aLower(2)) * (j - 1) / (aGridOrder - 1.0);
2176
2177       aFunc.Value(aCurrPnt1, aFuncValues(idx));
2178       idx++;
2179     }
2180   }
2181
2182   Standard_Integer k, l;
2183   Standard_Integer idx1, idx2;
2184   for(i = 1; i <= aGridOrder; i++)
2185   for(j = 1; j <= aGridOrder; j++)
2186   for(k = 1; k <= aGridOrder; k++)
2187   for(l = 1; l <= aGridOrder; l++)
2188     {
2189       if (i == k && j == l) 
2190         continue;
2191
2192       aCurrPnt1(1) = aLower(1) + (aUpper(1) - aLower(1)) * (i - 1) / (aGridOrder - 1.0);
2193       aCurrPnt1(2) = aLower(2) + (aUpper(2) - aLower(2)) * (j - 1) / (aGridOrder - 1.0);
2194       idx1 = (i - 1) * aGridOrder + j;
2195
2196       aCurrPnt2(1) = aLower(1) + (aUpper(1) - aLower(1)) * (k - 1) / (aGridOrder - 1.0);
2197       aCurrPnt2(2) = aLower(2) + (aUpper(2) - aLower(2)) * (l - 1) / (aGridOrder - 1.0);
2198       idx2 = (k - 1) * aGridOrder + l;
2199
2200       aCurrPnt1.Add(-aCurrPnt2);
2201       Standard_Real dist = aCurrPnt1.Norm();
2202
2203       Standard_Real C = Abs(aFuncValues(idx1) - aFuncValues(idx2)) / dist;
2204       if (C > aLipConst)
2205         aLipConst = C;
2206     }
2207
2208   math_GlobOptMin aFinder(&aFunc, aLower, aUpper, aLipConst);
2209   aFinder.Perform();
2210   //(-pi , 12.275), (pi , 2.275), (9.42478, 2.475)
2211
2212   Standard_Real anExtValue = aFinder.GetF();
2213   theDI << "F = " << anExtValue << "\n";
2214
2215   Standard_Integer aNbExt = aFinder.NbExtrema();
2216   theDI << "NbExtrema = " << aNbExt << "\n";
2217
2218   return 0;
2219 }
2220
2221 #include <OSD_Environment.hxx>
2222 #include <Plugin.hxx>
2223 #include <Plugin_Macro.hxx>
2224 #include <Resource_Manager.hxx>
2225
2226 #define THE_QATEST_DOC_FORMAT       "My Proprietary Format"
2227
2228 #define QA_CHECK(theDesc, theExpr, theValue) \
2229 {\
2230   const bool isTrue = !!(theExpr); \
2231   std::cout << theDesc << (isTrue ? " TRUE  " : " FALSE ") << (isTrue == theValue ? " is OK\n" : " is FAIL\n"); \
2232 }
2233
2234 class Test_TDocStd_Application : public TDocStd_Application
2235 {
2236 public:
2237
2238   Test_TDocStd_Application ()
2239   {
2240     // explicitly initialize resource manager
2241     myResources = new Resource_Manager ("");
2242     myResources->SetResource ("xml.FileFormat", THE_QATEST_DOC_FORMAT);
2243     myResources->SetResource (THE_QATEST_DOC_FORMAT ".Description",     "Test XML Document");
2244     myResources->SetResource (THE_QATEST_DOC_FORMAT ".FileExtension",   "xml");
2245   }
2246
2247   virtual Handle(PCDM_Reader) ReaderFromFormat (const TCollection_ExtendedString&) Standard_OVERRIDE
2248   {
2249     return new XmlDrivers_DocumentRetrievalDriver ();
2250   }
2251   virtual Handle(PCDM_StorageDriver) WriterFromFormat (const TCollection_ExtendedString&) Standard_OVERRIDE
2252   {
2253     return new XmlDrivers_DocumentStorageDriver ("Test");
2254   }
2255   virtual Standard_CString ResourcesName() Standard_OVERRIDE { return ""; }
2256 };
2257
2258 //=======================================================================
2259 //function : OCC24925
2260 //purpose  :
2261 //=======================================================================
2262 static Standard_Integer OCC24925 (Draw_Interpretor& theDI,
2263                                   Standard_Integer  theArgNb,
2264                                   const char**      theArgVec)
2265 {
2266   if (theArgNb != 2
2267    && theArgNb != 5)
2268   {
2269     std::cout << "Error: wrong syntax! See usage:\n";
2270     theDI.PrintHelp (theArgVec[0]);
2271     return 1;
2272   }
2273
2274   Standard_Integer anArgIter = 1;
2275   TCollection_ExtendedString aFileName = theArgVec[anArgIter++];
2276   TCollection_AsciiString    aPlugin   = "TKXml";
2277   TCollection_AsciiString    aSaver    = "03a56820-8269-11d5-aab2-0050044b1af1"; // XmlStorageDriver   in XmlDrivers.cxx
2278   TCollection_AsciiString    aLoader   = "03a56822-8269-11d5-aab2-0050044b1af1"; // XmlRetrievalDriver in XmlDrivers.cxx
2279   if (anArgIter < theArgNb)
2280   {
2281     aPlugin = theArgVec[anArgIter++];
2282     aSaver  = theArgVec[anArgIter++];
2283     aLoader = theArgVec[anArgIter++];
2284   }
2285
2286   PCDM_StoreStatus  aSStatus = PCDM_SS_Failure;
2287   PCDM_ReaderStatus aRStatus = PCDM_RS_OpenError;
2288
2289   Handle(TDocStd_Application) anApp = new Test_TDocStd_Application ();
2290   {
2291     Handle(TDocStd_Document) aDoc;
2292     anApp->NewDocument (THE_QATEST_DOC_FORMAT, aDoc);
2293     TDF_Label aLab = aDoc->Main();
2294     TDataStd_Integer::Set (aLab, 0);
2295     TDataStd_Name::Set (aLab, "QABugs_19.cxx");
2296
2297     aSStatus = anApp->SaveAs (aDoc, aFileName);
2298     anApp->Close (aDoc);
2299   }
2300   QA_CHECK ("SaveAs()", aSStatus == PCDM_SS_OK, true);
2301
2302   {
2303     Handle(TDocStd_Document) aDoc;
2304     aRStatus = anApp->Open (aFileName, aDoc);
2305     anApp->Close (aDoc);
2306   }
2307   QA_CHECK ("Open()  ", aRStatus == PCDM_RS_OK, true);
2308   return 0;
2309 }
2310
2311 //=======================================================================
2312 //function : OCC25043
2313 //purpose  :
2314 //=======================================================================
2315 #include <BRepAlgoAPI_Check.hxx>
2316 static Standard_Integer OCC25043 (Draw_Interpretor& theDI,
2317                                   Standard_Integer  theArgNb,
2318                                   const char**      theArgVec)
2319 {
2320   if (theArgNb != 2) {
2321     theDI << "Usage: " << theArgVec[0] << " shape\n";
2322     return 1;
2323   }
2324   
2325   TopoDS_Shape aShape = DBRep::Get(theArgVec[1]);
2326   if (aShape.IsNull()) 
2327   {
2328     theDI << theArgVec[1] << " shape is NULL\n";
2329     return 1;
2330   }
2331   
2332   BRepAlgoAPI_Check  anAlgoApiCheck(aShape, Standard_True, Standard_True);
2333
2334   if (!anAlgoApiCheck.IsValid())
2335   {
2336     BOPAlgo_ListIteratorOfListOfCheckResult anCheckIter(anAlgoApiCheck.Result());
2337     for (; anCheckIter.More(); anCheckIter.Next())
2338     {
2339       const BOPAlgo_CheckResult& aCurCheckRes = anCheckIter.Value();
2340       const TopTools_ListOfShape& aCurFaultyShapes = aCurCheckRes.GetFaultyShapes1();
2341       TopTools_ListIteratorOfListOfShape aFaultyIter(aCurFaultyShapes);
2342       for (; aFaultyIter.More(); aFaultyIter.Next())
2343       {
2344         const TopoDS_Shape& aFaultyShape = aFaultyIter.Value();
2345         
2346         Standard_Boolean anIsFaultyShapeFound = Standard_False;
2347         TopExp_Explorer anExp(aShape, aFaultyShape.ShapeType());
2348         for (; anExp.More() && !anIsFaultyShapeFound; anExp.Next())
2349         {
2350           if (anExp.Current().IsEqual(aFaultyShape))
2351             anIsFaultyShapeFound = Standard_True;
2352         }
2353         
2354         if (!anIsFaultyShapeFound)
2355         {
2356           theDI << "Error. Faulty Shape is NOT found in source shape.\n";
2357           return 0;
2358         }
2359         else 
2360         {
2361           theDI << "Info. Faulty shape is found in source shape\n";
2362         }
2363       }
2364     }
2365   }
2366   else 
2367   {
2368     theDI << "Problems are not detected. Test is not performed.";
2369   }
2370
2371   return 0;
2372 }
2373
2374 //=======================================================================
2375 //function : OCC24606
2376 //purpose  :
2377 //=======================================================================
2378 static Standard_Integer OCC24606 (Draw_Interpretor& theDI,
2379                                   Standard_Integer  theArgNb,
2380                                   const char**      theArgVec)
2381 {
2382   if (theArgNb > 1)
2383   {
2384     std::cerr << "Error: incorrect number of arguments.\n";
2385     theDI << "Usage : " << theArgVec[0] << "\n";
2386     return 1;
2387   }
2388
2389   Handle(V3d_View) aView = ViewerTest::CurrentView();
2390   if (aView.IsNull())
2391   {
2392     std::cerr << "Errro: no active view, please call 'vinit'.\n";
2393     return 1;
2394   }
2395
2396   aView->DepthFitAll();
2397   aView->FitAll();
2398
2399   return 0;
2400 }
2401
2402 //=======================================================================
2403 //function : OCC25202
2404 //purpose  :
2405 //=======================================================================
2406 #include <ShapeBuild_ReShape.hxx>
2407 static Standard_Integer OCC25202 ( Draw_Interpretor& theDI,
2408                                    Standard_Integer theArgN,
2409                                    const char** theArgVal)
2410 {
2411   //  0      1    2     3     4     5     6 
2412   //reshape res shape numF1 face1 numF2 face2
2413   if(theArgN < 7)
2414     {
2415       theDI << "Use: reshape res shape numF1 face1 numF2 face2\n";
2416       return 1;
2417     }
2418
2419   TopoDS_Shape aShape = DBRep::Get(theArgVal[2]);
2420   const Standard_Integer  aNumOfRE1 = Draw::Atoi(theArgVal[3]),
2421                           aNumOfRE2 = Draw::Atoi(theArgVal[5]);
2422   TopoDS_Face aShapeForRepl1 = TopoDS::Face(DBRep::Get(theArgVal[4])),
2423               aShapeForRepl2 = TopoDS::Face(DBRep::Get(theArgVal[6]));
2424
2425   if(aShape.IsNull())
2426   {
2427     theDI << theArgVal[2] << " is null shape\n";
2428     return 1;
2429   }
2430
2431   if(aShapeForRepl1.IsNull())
2432   {
2433     theDI << theArgVal[4] << " is not a replaced type\n";
2434     return 1;
2435   }
2436
2437   if(aShapeForRepl2.IsNull())
2438   {
2439     theDI << theArgVal[6] << " is not a replaced type\n";
2440     return 1;
2441   }
2442
2443
2444   TopoDS_Shape aReplacedShape;
2445   ShapeBuild_ReShape aReshape;
2446
2447   //////////////////// explode (begin)
2448   TopTools_MapOfShape M;
2449   M.Add(aShape);
2450   Standard_Integer aNbShapes = 0;
2451   for (TopExp_Explorer ex(aShape,TopAbs_FACE); ex.More(); ex.Next())
2452     {
2453       const TopoDS_Shape& Sx = ex.Current();
2454       Standard_Boolean added = M.Add(Sx);
2455       if (added)
2456         {
2457           aNbShapes++;
2458           if(aNbShapes == aNumOfRE1)
2459             {
2460               aReplacedShape = Sx;
2461
2462               aReshape.Replace(aReplacedShape, aShapeForRepl1);
2463             }
2464
2465           if(aNbShapes == aNumOfRE2)
2466             {
2467               aReplacedShape = Sx;
2468
2469               aReshape.Replace(aReplacedShape, aShapeForRepl2);
2470             }
2471         }
2472     }
2473   //////////////////// explode (end)
2474
2475   if(aReplacedShape.IsNull())
2476     {
2477       theDI << "There is not any shape for replacing.\n";
2478     }
2479
2480   DBRep::Set (theArgVal[1],aReshape.Apply (aShape,TopAbs_WIRE,2));
2481
2482   return 0;
2483 }
2484
2485 #include <ShapeFix_Wireframe.hxx>
2486 //=======================================================================
2487 //function : OCC7570
2488 //purpose  : 
2489 //=======================================================================
2490 static Standard_Integer OCC7570 (Draw_Interpretor& di, Standard_Integer n, const char** a)
2491 {
2492   if (n != 2) {
2493     di<<"Usage: "<<a[0]<<" invalid number of arguments\n";
2494     return 1;
2495   }
2496   TopoDS_Shape in_shape (DBRep::Get (a[1]));
2497   ShapeFix_Wireframe fix_tool (in_shape);
2498   fix_tool.ModeDropSmallEdges () = Standard_True;
2499   fix_tool.SetPrecision (1.e+6);
2500   fix_tool.SetLimitAngle (0.01);
2501   fix_tool.FixSmallEdges ();
2502   TopoDS_Shape new_shape = fix_tool.Shape ();
2503   return 0;
2504 }
2505
2506 #include <AIS_TypeFilter.hxx>
2507 //=======================================================================
2508 //function : OCC25340
2509 //purpose  : 
2510 //=======================================================================
2511 static Standard_Integer OCC25340 (Draw_Interpretor& /*theDI*/,
2512                                  Standard_Integer  /*theArgNb*/,
2513                                  const char** /*theArgVec*/)
2514 {
2515   Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2516   if (aCtx.IsNull())
2517   {
2518     std::cerr << "Error: No opened viewer!\n";
2519     return 1;
2520   }
2521   Handle(AIS_TypeFilter) aFilter = new AIS_TypeFilter (AIS_KOI_Shape);
2522   aCtx->AddFilter (aFilter);
2523   return 0;
2524 }
2525
2526 //=======================================================================
2527 //function : OCC24826
2528 //purpose  :
2529 //=======================================================================
2530 class ParallelTest_Saxpy
2531 {
2532 public:
2533   typedef NCollection_Array1<Standard_Real> Vector;
2534
2535   //! Constructor
2536   ParallelTest_Saxpy(const Vector& theX, Vector& theY, Standard_Real theScalar)
2537   : myX(theX),
2538     myY(theY),
2539     myScalar(theScalar)
2540   {
2541   }
2542
2543   //! Dummy calculation
2544   void operator() (const Standard_Integer theIndex) const
2545   {
2546     myY(theIndex) = myScalar * myX(theIndex) + myY(theIndex);
2547   }
2548
2549 private:
2550   ParallelTest_Saxpy( const ParallelTest_Saxpy& );
2551   ParallelTest_Saxpy& operator =( ParallelTest_Saxpy& );
2552
2553 private:
2554   const Vector&       myX;
2555   Vector&             myY;
2556   const Standard_Real myScalar;
2557 };
2558
2559 //---------------------------------------------------------------------
2560 static Standard_Integer OCC24826(Draw_Interpretor& theDI,
2561                                  Standard_Integer  trheArgc,
2562                                  const char**      theArgv)
2563 {
2564   if ( trheArgc != 2 )
2565   {
2566     theDI << "Usage: "
2567           << theArgv[0]
2568           << " vec_length\n";
2569     return 1;
2570   }
2571
2572   // Generate data;
2573   Standard_Integer aLength = Draw::Atoi(theArgv[1]);
2574
2575   NCollection_Array1<Standard_Real> aX (0, aLength - 1);
2576   NCollection_Array1<Standard_Real> anY(0, aLength - 1);
2577
2578   for ( Standard_Integer i = 0; i < aLength; ++i )
2579   {
2580     aX(i) = anY(i) = (Standard_Real) i;
2581   }
2582
2583   OSD_Timer aTimer;
2584
2585   aTimer.Start();
2586
2587   //! Serial proccesing
2588   for ( Standard_Integer i = 0; i < aLength; ++i )
2589   {
2590     anY(i) = 1e-6 * aX(i) + anY(i);
2591   }
2592
2593   aTimer.Stop();
2594   cout << "Processing time (sequential mode):\n";
2595   aTimer.Show();
2596
2597   const ParallelTest_Saxpy aFunctor(aX, anY, 1e-6);
2598
2599   aTimer.Reset();
2600   aTimer.Start();
2601
2602   // Parallel processing
2603   OSD_Parallel::For(0, aLength, aFunctor);
2604
2605   aTimer.Stop();
2606   cout << "Processing time (parallel mode):\n";
2607   aTimer.Show();
2608
2609   return 0;
2610 }
2611
2612 /*****************************************************************************/
2613
2614 #include <GeomAPI_IntSS.hxx>
2615 //=======================================================================
2616 //function : OCC25100
2617 //purpose  :
2618 //=======================================================================
2619 static Standard_Integer OCC25100 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2620 {
2621   if (argc < 2)
2622   {
2623     di << "the method requires a shape name\n";
2624     return 1;
2625   }
2626
2627   TopoDS_Shape S = DBRep::Get(argv[1]);
2628   if ( S.IsNull() )
2629   {
2630     di << "Shape is empty\n";
2631     return 1;
2632   }
2633   
2634   TopExp_Explorer aFaceExp(S, TopAbs_FACE);
2635   const Handle(Geom_Surface)& aSurf = BRep_Tool::Surface(TopoDS::Face(aFaceExp.Current()));
2636
2637   GeomAPI_IntSS anIntersector(aSurf, aSurf, Precision::Confusion());
2638
2639   if (!anIntersector.IsDone())
2640   {
2641     di << "Error. Intersection is not done\n";
2642     return 1;
2643   }
2644
2645   di << "Test complete\n";
2646
2647   return 0;
2648 }
2649
2650 //=======================================================================
2651 //function : OCC25348
2652 //purpose  : 
2653 //=======================================================================
2654 static Standard_Integer OCC25348 (Draw_Interpretor& theDI,
2655                                  Standard_Integer  /*theArgNb*/,
2656                                  const char** /*theArgVec*/)
2657 {
2658   Handle(NCollection_IncAllocator) anAlloc1;
2659   NCollection_List<int> aList1(anAlloc1);
2660   for (int i=0; i < 10; i++)
2661   {
2662     Handle(NCollection_IncAllocator) anAlloc2;
2663     NCollection_List<int> aList2(anAlloc2);
2664     aList2.Append(i);
2665     aList1.Assign(aList2);
2666   }
2667   theDI << "Test complete\n";
2668   return 0;
2669 }
2670
2671 #include <IntCurvesFace_ShapeIntersector.hxx>
2672 #include <BRepBndLib.hxx>
2673 //=======================================================================
2674 //function : OCC25413
2675 //purpose  : 
2676 //=======================================================================
2677 static Standard_Integer OCC25413 (Draw_Interpretor& di, Standard_Integer narg , const char** a)
2678 {
2679   if (narg != 2) {
2680     di << "Usage: " << a[0] << " invalid number of arguments\n";
2681     return 1;
2682   }
2683   TopoDS_Shape aShape = DBRep::Get (a[1]);
2684
2685   IntCurvesFace_ShapeIntersector Inter;
2686   Inter.Load(aShape, Precision::Confusion());
2687
2688   Bnd_Box aBndBox;
2689   BRepBndLib::Add(aShape, aBndBox);
2690
2691   gp_Dir aDir(0., 1., 0.);
2692   const int N = 250;
2693   Standard_Real xMin = aBndBox.CornerMin().X();
2694   Standard_Real zMin = aBndBox.CornerMin().Z();
2695   Standard_Real xMax = aBndBox.CornerMax().X();
2696   Standard_Real zMax = aBndBox.CornerMax().Z();
2697   Standard_Real xStep = (xMax - xMin) / N;
2698   Standard_Real zStep = (zMax - zMin) / N;
2699
2700   for (Standard_Real x = xMin; x <= xMax; x += xStep)
2701     for (Standard_Real z = zMin; z <= zMax; z += zStep)
2702     {
2703       gp_Pnt aPoint(x, 0.0, z);
2704       gp_Lin aLine(aPoint, aDir);
2705       Inter.PerformNearest(aLine, -100., 100.);
2706     }
2707   return 0;
2708 }
2709
2710
2711 #include <BOPAlgo_PaveFiller.hxx>
2712 //
2713 #include <BRepAlgoAPI_BooleanOperation.hxx>
2714 #include <BRepAlgoAPI_Common.hxx>
2715 #include <BRepAlgoAPI_Fuse.hxx>
2716 #include <BRepAlgoAPI_Cut.hxx>
2717 #include <BRepAlgoAPI_Section.hxx>
2718 //
2719 #include <TopExp.hxx>
2720 #include <TopTools_MapOfShape.hxx>
2721 //=======================================================================
2722 //function : OCC25446
2723 //purpose  :
2724 //=======================================================================
2725 static Standard_Integer OCC25446 (Draw_Interpretor& theDI, 
2726                                   Standard_Integer argc, 
2727                                   const char ** argv)
2728 {
2729   if (argc != 5) {
2730     theDI << "Usage: OCC25446 res b1 b2 op\n";
2731     return 1;
2732   }
2733   //
2734   TopoDS_Shape aS1 = DBRep::Get(argv[2]);
2735   if (aS1.IsNull()) {
2736     theDI << argv[2] << " shape is NULL\n";
2737     return 1;
2738   }
2739   //
2740   TopoDS_Shape aS2 = DBRep::Get(argv[3]);
2741   if (aS2.IsNull()) {
2742     theDI << argv[3] << " shape is NULL\n";
2743     return 1;
2744   }
2745   //
2746   Standard_Integer iOp;
2747   BOPAlgo_Operation aOp;
2748   //
2749   iOp = Draw::Atoi(argv[4]);
2750   if (iOp < 0 || iOp > 4) {
2751     theDI << "Invalid operation type\n";
2752     return 1;
2753   }
2754   aOp = (BOPAlgo_Operation)iOp;
2755   //
2756   Standard_Integer iErr;
2757   TopTools_ListOfShape aLS;
2758   BOPAlgo_PaveFiller aPF;
2759   //
2760   aLS.Append(aS1);
2761   aLS.Append(aS2);
2762   aPF.SetArguments(aLS);
2763   //
2764   aPF.Perform();
2765   iErr = aPF.HasErrors();
2766   if (iErr) {
2767     theDI << "Intersection failed with error status: " << iErr << "\n";
2768     return 1;
2769   }
2770   //
2771   BRepAlgoAPI_BooleanOperation* pBuilder = NULL;
2772   // 
2773   switch (aOp) {
2774   case BOPAlgo_COMMON:
2775     pBuilder = new BRepAlgoAPI_Common(aS1, aS2, aPF);
2776     break;
2777   case BOPAlgo_FUSE:
2778     pBuilder = new BRepAlgoAPI_Fuse(aS1, aS2, aPF);
2779     break;
2780   case BOPAlgo_CUT:
2781     pBuilder = new BRepAlgoAPI_Cut (aS1, aS2, aPF);
2782     break;
2783   case BOPAlgo_CUT21:
2784     pBuilder = new BRepAlgoAPI_Cut(aS1, aS2, aPF, Standard_False);
2785     break;
2786   case BOPAlgo_SECTION:
2787     pBuilder = new BRepAlgoAPI_Section(aS1, aS2, aPF);
2788     break;
2789   default:
2790     break;
2791   }
2792   //
2793   iErr = pBuilder->HasErrors();
2794   if (!pBuilder->IsDone()) {
2795     theDI << "BOP failed with error status: " << iErr << "\n";
2796     return 1;
2797   }
2798   //
2799   const TopoDS_Shape& aRes = pBuilder->Shape();
2800   DBRep::Set(argv[1], aRes);
2801   //
2802   TopTools_MapOfShape aMapArgs, aMapShape;
2803   TopTools_MapIteratorOfMapOfShape aIt;
2804   Standard_Boolean bIsDeletedHist, bIsDeletedMap;
2805   TopAbs_ShapeEnum aType;
2806   //
2807   TopExp::MapShapes(aS1, aMapArgs);
2808   TopExp::MapShapes(aS2, aMapArgs);
2809   TopExp::MapShapes(aRes, aMapShape);
2810   //
2811   aIt.Initialize(aMapArgs);
2812   for (; aIt.More(); aIt.Next()) {
2813     const TopoDS_Shape& aS = aIt.Value();
2814     aType = aS.ShapeType();
2815     if (!(aType==TopAbs_EDGE || aType==TopAbs_FACE || 
2816           aType==TopAbs_VERTEX || aType==TopAbs_SOLID)) {
2817       continue;
2818     }
2819     //
2820     bIsDeletedHist = pBuilder->IsDeleted(aS);
2821     bIsDeletedMap = !aMapShape.Contains(aS) &&
2822       (pBuilder->Modified(aS).Extent() == 0);
2823     //
2824     if (bIsDeletedHist != bIsDeletedMap) {
2825       theDI << "Error. Wrong value of IsDeleted flag.\n";
2826       return 1;
2827     }
2828   }
2829   //
2830   theDI << "Test complete\n";
2831   return 0;
2832 }
2833
2834 //====================================================
2835 // Auxiliary functor class for the command OCC25545;
2836 // it gets access to a vertex with the given index and
2837 // checks that X coordinate of the point is equal to index;
2838 // if it is not so then a data race is reported.
2839 //====================================================
2840 struct OCC25545_Functor
2841 {
2842   OCC25545_Functor(const std::vector<TopoDS_Shape>& theShapeVec)
2843     : myShapeVec(&theShapeVec),
2844       myIsRaceDetected(0)
2845   {}
2846
2847   void operator()(size_t i) const
2848   {
2849     if (!myIsRaceDetected) {
2850       const TopoDS_Vertex& aV = TopoDS::Vertex (myShapeVec->at(i));
2851       gp_Pnt aP = BRep_Tool::Pnt (aV);
2852       if (aP.X () != static_cast<double> (i)) {
2853         Standard_Atomic_Increment(&myIsRaceDetected);
2854       }
2855     }
2856   }
2857
2858   const std::vector<TopoDS_Shape>* myShapeVec;
2859   mutable volatile int myIsRaceDetected;
2860 };
2861
2862 //=======================================================================
2863 //function : OCC25545
2864 //purpose  : Tests data race when concurrently accessing TopLoc_Location::Transformation()
2865 //=======================================================================
2866
2867 static Standard_Integer OCC25545 (Draw_Interpretor& di, 
2868                                   Standard_Integer, 
2869                                   const char **)
2870 {
2871   // Place vertices in a vector, giving the i-th vertex the
2872   // transformation that translates it on the vector (i,0,0) from the origin.
2873   Standard_Integer n = 1000;
2874   std::vector<TopoDS_Shape> aShapeVec (n);
2875   std::vector<TopLoc_Location> aLocVec (n);
2876   TopoDS_Shape aShape = BRepBuilderAPI_MakeVertex (gp::Origin ());
2877   aShapeVec[0] = aShape;
2878   for (Standard_Integer i = 1; i < n; ++i) {
2879     gp_Trsf aT;
2880     aT.SetTranslation (gp_Vec (1, 0, 0));
2881     aLocVec[i] = aLocVec[i - 1] * aT;
2882     aShapeVec[i] = aShape.Moved (aLocVec[i]);
2883   }
2884
2885   // Evaluator function will access vertices geometry
2886   // concurrently
2887   OCC25545_Functor aFunc(aShapeVec);
2888
2889   // concurrently process
2890   OSD_Parallel::For (0, n, aFunc);
2891
2892   QVERIFY (!aFunc.myIsRaceDetected);
2893   return 0;
2894 }
2895
2896 //=======================================================================
2897 //function : OCC25547
2898 //purpose  :
2899 //=======================================================================
2900 #include <BRepMesh_GeomTool.hxx>
2901 #include <BRepAdaptor_Curve.hxx>
2902 #include <Geom_TrimmedCurve.hxx>
2903 #include <BRepBuilderAPI_MakeFace.hxx>
2904 #include <BRepAdaptor_HSurface.hxx>
2905 #include <BRepAdaptor_Surface.hxx>
2906 static Standard_Integer OCC25547(
2907   Draw_Interpretor& theDI, 
2908   Standard_Integer  /*argc*/, 
2909   const char **     /*argv*/)
2910 {
2911   // The general aim of this test is to prevent linkage errors due to missed
2912   // Standard_EXPORT attribute for static methods.
2913
2914   // However, start checking the main functionality at first.
2915   const Standard_Real aFirstP = 0., aLastP = M_PI;
2916   Handle(Geom_Circle) aCircle = new Geom_Circle(gp_Ax2(gp::Origin(), gp::DZ()), 10);
2917   Handle(Geom_TrimmedCurve) aHalf = new Geom_TrimmedCurve(aCircle, aFirstP, aLastP);
2918   TopoDS_Edge aEdge = BRepBuilderAPI_MakeEdge(aHalf);
2919   BRepAdaptor_Curve aAdaptor(aEdge);
2920   BRepMesh_GeomTool aGeomTool(aAdaptor, aFirstP, aLastP, 0.1, 0.5);
2921
2922   if (aGeomTool.NbPoints() == 0)
2923   {
2924     theDI << "Error. BRepMesh_GeomTool failed to discretize an arc.\n";
2925     return 1;
2926   }
2927
2928   // Test static methods.
2929   TopoDS_Face aFace = BRepBuilderAPI_MakeFace(gp_Pln(gp::Origin(), gp::DZ()));
2930   BRepAdaptor_Surface aSurf(aFace);
2931   Handle(BRepAdaptor_HSurface) aHSurf = new BRepAdaptor_HSurface(aSurf);
2932
2933   gp_Pnt aPnt;
2934   gp_Dir aNormal;
2935   if (!BRepMesh_GeomTool::Normal(aHSurf, 10., 10., aPnt, aNormal))
2936   {
2937     theDI << "Error. BRepMesh_GeomTool failed to take a normal of surface.\n";
2938     return 1;
2939   }
2940
2941   gp_XY aRefPnts[4] = {
2942     gp_XY(-10., -10.), gp_XY(10., 10.), 
2943     gp_XY(-10., 10.), gp_XY(10., -10.)
2944   };
2945
2946   gp_Pnt2d aIntPnt;
2947   Standard_Real aParams[2];
2948   BRepMesh_GeomTool::IntFlag aIntFlag = BRepMesh_GeomTool::IntLinLin(
2949     aRefPnts[0], aRefPnts[1], aRefPnts[2], aRefPnts[3], 
2950     aIntPnt.ChangeCoord(), aParams);
2951
2952   Standard_Real aDiff = aIntPnt.Distance(gp::Origin2d());
2953   if (aIntFlag != BRepMesh_GeomTool::Cross || aDiff > Precision::PConfusion())
2954   {
2955     theDI << "Error. BRepMesh_GeomTool failed to intersect two lines.\n";
2956     return 1;
2957   }
2958
2959   aIntFlag = BRepMesh_GeomTool::IntSegSeg(
2960     aRefPnts[0], aRefPnts[1], aRefPnts[2], aRefPnts[3], 
2961     Standard_False, Standard_False, aIntPnt);
2962
2963   aDiff = aIntPnt.Distance(gp::Origin2d());
2964   if (aIntFlag != BRepMesh_GeomTool::Cross || aDiff > Precision::PConfusion())
2965   {
2966     theDI << "Error. BRepMesh_GeomTool failed to intersect two segments.\n";
2967     return 1;
2968   }
2969
2970
2971   theDI << "Test complete\n";
2972   return 0;
2973 }
2974
2975 static Standard_Integer OCC26139 (Draw_Interpretor& theDI,
2976                                   Standard_Integer  argc,
2977                                   const char **     argv)
2978 {
2979
2980   Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2981   if (aCtx.IsNull())
2982   {
2983     theDI << "Use 'vinit' command before " << argv[0] << "\n";
2984     return 1;
2985   }
2986
2987   Standard_Integer aBoxGridSize = 100;
2988   Standard_Integer aCompGridSize = 3;
2989   Standard_Real aBoxSize = 5.0;
2990
2991   if (argc > 1)
2992   {
2993     for (Standard_Integer anArgIdx = 1; anArgIdx < argc; ++anArgIdx)
2994     {
2995       TCollection_AsciiString anArg (argv[anArgIdx]);
2996       anArg.LowerCase();
2997       if (anArg == "-boxgrid")
2998       {
2999         aBoxGridSize = Draw::Atoi (argv[++anArgIdx]);
3000       }
3001       else if (anArg == "-compgrid")
3002       {
3003         aCompGridSize = Draw::Atoi (argv[++anArgIdx]);
3004       }
3005       else if (anArg == "-boxsize")
3006       {
3007         aBoxSize = Draw::Atof (argv[++anArgIdx]);
3008       }
3009     }
3010   }
3011
3012   NCollection_List<Handle(AIS_Shape)> aCompounds;
3013   for (Standard_Integer aCompGridX = 0; aCompGridX < aCompGridSize; ++aCompGridX)
3014   {
3015     for (Standard_Integer aCompGridY = 0; aCompGridY < aCompGridSize; ++aCompGridY)
3016     {
3017       BRep_Builder aBuilder;
3018       TopoDS_Compound aComp;
3019       aBuilder.MakeCompound (aComp);
3020       for (Standard_Integer aBoxGridX = 0; aBoxGridX < aBoxGridSize; ++aBoxGridX)
3021       {
3022         for (Standard_Integer aBoxGridY = 0; aBoxGridY < aBoxGridSize; ++aBoxGridY)
3023         {
3024           BRepPrimAPI_MakeBox aBox (gp_Pnt (aBoxGridX * aBoxSize, aBoxGridY * aBoxSize, 0.0),
3025                                     aBoxSize, aBoxSize, aBoxSize);
3026           aBuilder.Add (aComp, aBox.Shape());
3027         }
3028       }
3029       gp_Trsf aTrsf;
3030       aTrsf.SetTranslation (gp_Vec (aBoxGridSize * aBoxSize * aCompGridX,
3031                                     aBoxGridSize * aBoxSize * aCompGridY,
3032                                     0.0));
3033       TopLoc_Location aLoc (aTrsf);
3034       aComp.Located (aLoc);
3035       aCompounds.Append (new AIS_Shape (aComp));
3036     }
3037   }
3038
3039   OSD_Timer aTimer;
3040   for (NCollection_List<Handle(AIS_Shape)>::Iterator aCompIter (aCompounds); aCompIter.More(); aCompIter.Next())
3041   {
3042     aTimer.Start();
3043     aCtx->Display (aCompIter.Value(), Standard_False);
3044     aTimer.Stop();
3045     theDI << "Display time: " << aTimer.ElapsedTime() << "\n";
3046     aTimer.Reset();
3047   }
3048
3049   aTimer.Reset();
3050   aTimer.Start();
3051   for (NCollection_List<Handle(AIS_Shape)>::Iterator aCompIter (aCompounds); aCompIter.More(); aCompIter.Next())
3052   {
3053     aCtx->Remove (aCompIter.Value(), Standard_False);
3054   }
3055   aTimer.Stop();
3056   theDI << "Remove time: " << aTimer.ElapsedTime() << "\n";
3057
3058   return 0;
3059 }
3060
3061 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
3062 #include <TColStd_DataMapOfIntegerInteger.hxx>
3063 #include <OSD.hxx>
3064 #include <ShapeFix_Wire.hxx>
3065 #include <ShapeExtend_Status.hxx>
3066 #ifdef _WIN32
3067 #define EXCEPTION ...
3068 #else
3069 #define EXCEPTION Standard_Failure
3070 #endif
3071
3072 static ShapeExtend_Status getStatusGap(const Handle(ShapeFix_Wire)&   theFix,
3073                                        const Standard_Boolean theIs3d)
3074 {
3075         for (Standard_Integer i=ShapeExtend_OK; i<=ShapeExtend_FAIL; i++)
3076         {
3077                 Standard_Boolean isFound;
3078                 if (theIs3d)
3079                         isFound = theFix->StatusGaps3d( (ShapeExtend_Status) i );
3080                 else
3081                         isFound = theFix->StatusGaps2d( (ShapeExtend_Status) i );
3082                 if (isFound) return ShapeExtend_Status(i);
3083         }
3084         return ShapeExtend_OK;
3085 }
3086
3087 //===================
3088 //function : OCC24881
3089 //purpose  : 
3090 //===================
3091 static Standard_Integer OCC24881 (Draw_Interpretor& di, Standard_Integer narg , const char** a)
3092 {
3093   if (narg < 2) {
3094     di<<"Usage: "<<a[0]<<" invalid number of arguments\n";
3095     return 1;
3096   }
3097 //    cout <<"FileName1: " << argv[1] <<endl;
3098
3099   TopoDS_Shape aShape = DBRep::Get (a[1]);
3100
3101     OSD::SetSignal();
3102     Handle(ShapeFix_Wire) aWireFix = new ShapeFix_Wire;
3103
3104     // map FixStatus - NbSuchStatuses
3105     TColStd_DataMapOfIntegerInteger aStatusNbDMap;
3106     Standard_Integer nbFixed=0, nbOk=0;
3107
3108 //Begin: STEP 7
3109     ShapeExtend_Status aStatus=ShapeExtend_OK;
3110     try {
3111         TopExp_Explorer aFaceExplorer(aShape, TopAbs_FACE);
3112         for (; aFaceExplorer.More(); aFaceExplorer.Next())
3113         {
3114                 TopoDS_Shape aFace = aFaceExplorer.Current();
3115                 // loop on wires
3116                 TopoDS_Iterator aWireItr(aFace);
3117                 for (; aWireItr.More(); aWireItr.Next() )
3118                 {
3119                         Standard_Boolean wasOk = Standard_False;
3120                         TopoDS_Wire aSrcWire = TopoDS::Wire(aWireItr.Value());
3121
3122                         aWireFix->Load (aSrcWire);
3123                         aWireFix->SetFace (TopoDS::Face(aFace));
3124                         aWireFix->FixReorder(); //correct order is a prerequisite
3125                         // fix 3d
3126                         if (!aWireFix->FixGaps3d())
3127                         {
3128                                 // not fixed, why?
3129                                 aStatus = getStatusGap(aWireFix, Standard_True);
3130                                 if (aStatus == ShapeExtend_OK)
3131                                         wasOk = Standard_True;
3132                                 else
3133                                 {
3134                                         // keep 3d fail status
3135                                         if (aStatusNbDMap.IsBound (aStatus))
3136                                                 aStatusNbDMap(aStatus)++;
3137                                         else
3138                                                 aStatusNbDMap.Bind(aStatus,1);
3139                                         continue;
3140                                 }
3141                         }
3142
3143                         // fix 2d
3144                         if (aWireFix->FixGaps2d())
3145                                 nbFixed++;
3146                         else
3147                         {
3148                                 aStatus = getStatusGap(aWireFix, Standard_False);
3149                                 if (aStatus == ShapeExtend_OK)
3150                                 {
3151                                         if (wasOk)
3152                                         {
3153                                                 nbOk++;
3154                                                 continue;
3155                                         }
3156                                         else
3157                                                 nbFixed++;
3158                                 }
3159                                 else
3160                                 {
3161                                         // keep 2d fail status
3162                                         Standard_Integer aStatus2d = aStatus + ShapeExtend_FAIL;
3163                                         if (aStatusNbDMap.IsBound (aStatus2d))
3164                                                 aStatusNbDMap(aStatus2d)++;
3165                                         else
3166                                                 aStatusNbDMap.Bind(aStatus2d,1);
3167                                         continue;
3168                                 }
3169                         }
3170                 }
3171         }
3172 //End: STEP 7
3173      } catch (EXCEPTION) {
3174        di << "Exception is raised = " <<aStatus << "\n";
3175        return 1;
3176
3177      }
3178 // report what is done
3179
3180         if (nbFixed)
3181         {
3182                 di <<"Fix_FillGaps_Fixed: nbFixed = "<<nbFixed <<"\n";
3183
3184         }    
3185         if (nbOk)
3186         {
3187                 di << "Fix_FillGaps_NothingToDo\n";
3188
3189         }
3190         TColStd_DataMapIteratorOfDataMapOfIntegerInteger aStatusItr(aStatusNbDMap);
3191         for (; aStatusItr.More(); aStatusItr.Next()) 
3192         {
3193                 switch ((ShapeExtend_Status) aStatusItr.Key()) 
3194                 {
3195                         // treat 3d status
3196                         case ShapeExtend_FAIL1:
3197                         di <<"Fix_FillGaps_3dNoCurveFail, nb failed = ";
3198                         break;
3199                         case ShapeExtend_FAIL2:
3200                         di <<"Fix_FillGaps_3dSomeGapsFail, nb failed = ";
3201                         break;
3202                         default:
3203                         // treat 2d status
3204                         switch ((ShapeExtend_Status) (aStatusItr.Key() - ShapeExtend_FAIL)) 
3205                         {
3206                                 case ShapeExtend_FAIL1:
3207                                 di <<"Fix_FillGaps_2dNoPCurveFail, nb failed = ";
3208                                 break;
3209                                 case ShapeExtend_FAIL2:
3210                                 di <<"Fix_FillGaps_2dSomeGapsFail, nb failed = ";
3211                                 break;
3212                                 default:
3213                                 break;
3214                         }
3215                 }
3216                 di <<aStatusItr.Value()<< "\n";
3217         }
3218         di << ("__________________________________") <<"\n";
3219
3220   return 0;
3221 }
3222
3223 //=======================================================================
3224 //function : OCC26172
3225 //purpose  :
3226 //=======================================================================
3227 static Standard_Integer OCC26172 (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3228 {
3229   if (theArgNb != 1)
3230   {
3231     std::cerr << "Error: wrong number of arguments! See usage:\n";
3232     theDI.PrintHelp (theArgVec[0]);
3233     return 1;
3234   }
3235
3236   Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3237   if(anAISContext.IsNull())
3238   {
3239     std::cerr << "Error: no active view. Please call vinit.\n";
3240     return 1;
3241   }
3242
3243   gp_Pnt aStart (100, 100, 100);
3244   gp_Pnt anEnd (300, 400, 600);
3245   BRepBuilderAPI_MakeEdge anEdgeBuilder (aStart, anEnd);
3246   TopoDS_Edge anEdge = anEdgeBuilder.Edge();
3247   Handle(AIS_Shape) aTestAISShape = new AIS_Shape (anEdge);
3248   anAISContext->Display (aTestAISShape, Standard_True);
3249
3250   // 2. activate it in selection modes
3251   TColStd_SequenceOfInteger aModes;
3252   aModes.Append (AIS_Shape::SelectionMode ((TopAbs_ShapeEnum) TopAbs_VERTEX));
3253   aModes.Append (AIS_Shape::SelectionMode ((TopAbs_ShapeEnum) TopAbs_EDGE));
3254
3255   Standard_DISABLE_DEPRECATION_WARNINGS
3256   anAISContext->OpenLocalContext();
3257   Standard_ENABLE_DEPRECATION_WARNINGS
3258   anAISContext->Deactivate (aTestAISShape);
3259   anAISContext->Load (aTestAISShape, -1, true);
3260   for (Standard_Integer anIt = 1; anIt <= aModes.Length(); ++anIt)
3261   {
3262     anAISContext->Activate (aTestAISShape, aModes (anIt));
3263   }
3264
3265   // select entities in vertex selection mode
3266   Handle(SelectMgr_Selection) aSelection = aTestAISShape->Selection (aModes (1));
3267   Standard_DISABLE_DEPRECATION_WARNINGS
3268   for (aSelection->Init(); aSelection->More(); aSelection->Next())
3269   {
3270     Handle(SelectBasics_SensitiveEntity) anEntity = aSelection->Sensitive()->BaseSensitive();
3271     if (anEntity.IsNull())
3272     {
3273       continue;
3274     }
3275
3276     Handle(SelectMgr_EntityOwner) anOwner =
3277       Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
3278
3279     if (anOwner.IsNull())
3280     {
3281       continue;
3282     }
3283
3284     anAISContext->LocalContext()->AddOrRemoveSelected (anOwner);
3285   }
3286   Standard_ENABLE_DEPRECATION_WARNINGS
3287
3288   // select entities in edge selection mode
3289   aSelection = aTestAISShape->Selection (aModes (2));
3290   Standard_DISABLE_DEPRECATION_WARNINGS
3291   for (aSelection->Init(); aSelection->More(); aSelection->Next())
3292   {
3293     Handle(SelectBasics_SensitiveEntity) anEntity = aSelection->Sensitive()->BaseSensitive();
3294     if (anEntity.IsNull())
3295     {
3296       continue;
3297     }
3298
3299     Handle(SelectMgr_EntityOwner) anOwner =
3300       Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
3301
3302     if (anOwner.IsNull())
3303     {
3304       continue;
3305     }
3306
3307     anAISContext->LocalContext()->AddOrRemoveSelected (anOwner);
3308   }
3309   Standard_ENABLE_DEPRECATION_WARNINGS
3310
3311   // deactivate vertex mode and check clearing of outdated selection
3312   anAISContext->Deactivate (aTestAISShape, aModes (1));
3313   Standard_DISABLE_DEPRECATION_WARNINGS
3314   anAISContext->LocalContext()->ClearOutdatedSelection (aTestAISShape, true);
3315   Standard_ENABLE_DEPRECATION_WARNINGS
3316
3317   return 0;
3318 }
3319
3320 //=======================================================================
3321 //function : OCC26284
3322 //purpose  :
3323 //=======================================================================
3324 static Standard_Integer OCC26284 (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3325 {
3326   if (theArgNb != 1)
3327   {
3328     std::cerr << "Error: wrong number of arguments! See usage:\n";
3329     theDI.PrintHelp (theArgVec[0]);
3330     return 1;
3331   }
3332
3333   Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3334   if (anAISContext.IsNull())
3335   {
3336     std::cerr << "Error: no active view. Please call vinit.\n";
3337     return 1;
3338   }
3339
3340   BRepPrimAPI_MakeSphere aSphereBuilder (gp_Pnt (0.0, 0.0, 0.0), 1.0);
3341   Handle(AIS_Shape) aSphere = new AIS_Shape (aSphereBuilder.Shape());
3342   anAISContext->Display (aSphere, Standard_False);
3343   for (Standard_Integer aChildIdx = 0; aChildIdx < 5; ++aChildIdx)
3344   {
3345     BRepPrimAPI_MakeSphere aBuilder (gp_Pnt (1.0 + aChildIdx, 1.0 + aChildIdx, 1.0 + aChildIdx), 1.0);
3346     Handle(AIS_Shape) aChild = new AIS_Shape (aBuilder.Shape());
3347     aSphere->AddChild (aChild);
3348     anAISContext->Display (aChild, Standard_False);
3349   }
3350
3351   anAISContext->RecomputeSelectionOnly (aSphere);
3352   anAISContext->UpdateCurrentViewer();
3353
3354   return 0;
3355 }
3356
3357 #include <IntTools_Context.hxx>
3358 #include <GeomAPI_ProjectPointOnSurf.hxx>
3359
3360 //=======================================================================
3361 //function : xprojponf
3362 //purpose  : 
3363 //=======================================================================
3364 Standard_Integer xprojponf (Draw_Interpretor& di, 
3365                             Standard_Integer n, 
3366                             const char** a)
3367 {
3368   if (n!=3) {
3369     di<<" use xprojponf p f \n";
3370     return 0;
3371   }
3372   // 
3373   gp_Pnt aP, aPS;
3374   TopoDS_Shape aS;
3375   TopoDS_Face aF;
3376   Handle(IntTools_Context) aCtx;
3377   //
3378   DrawTrSurf::GetPoint(a[1], aP);
3379   aS=DBRep::Get(a[2]);
3380   //
3381   if (aS.IsNull()) {
3382     di<<" null shape is not allowed\n";
3383     return 0;
3384   }
3385   //
3386   if (aS.ShapeType()!=TopAbs_FACE) {
3387     di << a[2] << " not a face\n";
3388     return 0;
3389   }
3390   //
3391   aCtx=new IntTools_Context;
3392   //
3393   aF=TopoDS::Face(aS);
3394   GeomAPI_ProjectPointOnSurf& aPPS=aCtx->ProjPS(aF);
3395   //
3396   aPPS.Perform(aP);
3397   if (!aPPS.IsDone()) {
3398     di<<" projection failed\n";
3399     return 0;
3400   }
3401   //
3402   aPS=aPPS.NearestPoint();
3403   di<< " point px " << aPS.X() << " " << aPS.Y() << " " <<  aPS.Z() << "\n";
3404   //
3405   return 0;
3406 }
3407
3408 //=======================================================================
3409 //function : OCC25547
3410 //purpose  :
3411 //=======================================================================
3412 #include <BRepMesh_CircleTool.hxx>
3413 #include <SelectMgr_EntityOwner.hxx>
3414
3415 static Standard_Boolean inspect_point(const gp_XY&        thePoint,
3416                                       const gp_XY&        theCenter,
3417                                       const Standard_Real theRadius)
3418 {
3419   static Standard_Real aPrecision   = Precision::PConfusion();
3420   static Standard_Real aSqPrecision = aPrecision * aPrecision;
3421   const gp_XY aDistVec = thePoint - theCenter;
3422   if (aDistVec.SquareModulus() - (theRadius * theRadius) < aSqPrecision)
3423     return Standard_True;
3424   else
3425     return Standard_False;
3426 }
3427
3428 static Standard_Integer OCC24923(
3429   Draw_Interpretor& theDI, 
3430   Standard_Integer  argc, 
3431   const char **     argv)
3432 {
3433   srand(static_cast<unsigned int>(time(NULL)));
3434
3435   const Standard_Real    aMaxDeviation = (argc > 1) ? Draw::Atof(argv[1]) : 0.01;
3436   const Standard_Integer aPointsNb     = 10000000;
3437   const Standard_Real    aMinAngle     = 5 * M_PI / 180.;
3438   static Standard_Real   aSqPrecision  = Precision::PConfusion() * Precision::PConfusion();
3439
3440   Standard_Integer aFailedNb = 0;
3441   for (Standard_Integer i = 0; i < aPointsNb; ++i)
3442   {
3443     gp_XY p[3];
3444     for (Standard_Integer j = 0; j < 3; ++j)
3445       p[j].SetCoord(((Standard_Real)rand())/RAND_MAX, ((Standard_Real)rand())/RAND_MAX);
3446
3447     // Check that points do not compose degenerated triangle.
3448     gp_XY aVec1 = p[1] - p[0];
3449     gp_XY aVec2 = p[2] - p[0];
3450     if (aVec1.SquareModulus() > aSqPrecision && 
3451         aVec2.SquareModulus() > aSqPrecision &&
3452         (aVec1 ^ aVec2) > aMinAngle)
3453     {
3454       gp_XY aCenter;
3455       Standard_Real aRadius;
3456       if (BRepMesh_CircleTool::MakeCircle(p[0], p[1], p[2], aCenter, aRadius))
3457       {
3458         if (!inspect_point(p[0], aCenter, aRadius) || 
3459             !inspect_point(p[1], aCenter, aRadius) || 
3460             !inspect_point(p[2], aCenter, aRadius))
3461         {
3462          /* theDI << "Missed: " <<
3463             "p1=(" << p1.X() << ", " << p1.Y() << "), " <<
3464             "p2=(" << p2.X() << ", " << p2.Y() << "), " <<
3465             "p3=(" << p3.X() << ", " << p3.Y() << "), " <<
3466             "c=(" << aCenter.X() << ", " << aCenter.Y() << "), " <<
3467             "r=" << aRadius << "\n";*/
3468             
3469           ++aFailedNb;
3470         }
3471
3472         continue;
3473       }
3474     }
3475
3476     // Ensure that aPointsNb suitable for tests are generated
3477     --i;
3478   }
3479
3480   const Standard_Real aDeviation = 
3481     1. - (Standard_Real)(aPointsNb - aFailedNb) / (Standard_Real)aPointsNb;
3482
3483   theDI << "Number of incorrect cases: " << aFailedNb << " (Total " << aPointsNb << ")\n";
3484   if (aDeviation > aMaxDeviation)
3485   {
3486     theDI << "Failed. Number of incorrect results is too huge: " << 
3487       aDeviation * 100 << "% (Max " << aMaxDeviation * 100 << "%)\n";
3488     return 1;
3489   }
3490
3491   theDI << "Deviation of incorrect results is: " <<
3492     aDeviation * 100 << "% (Max " << aMaxDeviation * 100 << "%)\n";
3493   theDI << "Test completed\n";
3494   return 0;
3495 }
3496
3497 //=======================================================================
3498 //function : OCC25574
3499 //purpose  : check implementation of Euler angles in gp_Quaternion
3500 //=======================================================================
3501
3502 static Standard_Integer OCC25574 (Draw_Interpretor& theDI, Standard_Integer /*argc*/, const char** /*argv*/)
3503 {
3504   Standard_Boolean isTestOk = Standard_True;
3505
3506   // Check consistency of Get and Set operations for Euler angles
3507   gp_Quaternion aQuat;
3508   aQuat.Set(0.06766916507860499, 0.21848101129786085, 0.11994599260380681,0.9660744746954637);
3509   Standard_Real alpha,beta,gamma;
3510   gp_Mat aRinv = aQuat.GetMatrix().Inverted();
3511   gp_Mat aI;
3512   aI.SetIdentity();
3513   const char* names[] = { "Extrinsic_XYZ", "Extrinsic_XZY", "Extrinsic_YZX", "Extrinsic_YXZ", "Extrinsic_ZXY", "Extrinsic_ZYX", 
3514                           "Intrinsic_XYZ", "Intrinsic_XZY", "Intrinsic_YZX", "Intrinsic_YXZ", "Intrinsic_ZXY", "Intrinsic_ZYX", 
3515                           "Extrinsic_XYX", "Extrinsic_XZX", "Extrinsic_YZY", "Extrinsic_YXY", "Extrinsic_ZYZ", "Extrinsic_ZXZ",
3516                           "Intrinsic_XYX", "Intrinsic_XZX", "Intrinsic_YZY", "Intrinsic_YXY", "Intrinsic_ZXZ", "Intrinsic_ZYZ" };
3517   for (int i = gp_Extrinsic_XYZ; i <= gp_Intrinsic_ZYZ; i++)
3518   {
3519     aQuat.GetEulerAngles (gp_EulerSequence(i), alpha, beta, gamma);
3520
3521     gp_Quaternion aQuat2;
3522     aQuat2.SetEulerAngles (gp_EulerSequence(i), alpha, beta, gamma);
3523
3524     gp_Mat aR = aQuat2.GetMatrix();
3525     gp_Mat aDiff = aR * aRinv - aI;
3526     if (aDiff.Determinant() > 1e-5)
3527     {
3528       theDI << "Error: Euler angles conversion incorrect for sequence " << names[i - gp_Extrinsic_XYZ] << "\n";
3529       isTestOk = Standard_False;
3530     }
3531   }
3532
3533   // Check conversion between intrinsic and extrinsic rotations
3534   // Any extrinsic rotation is equivalent to an intrinsic rotation
3535   // by the same angles but with inverted order of elemental rotations, and vice versa
3536   // For instance:
3537   //    Extrinsic_XZY = Incrinsic_XZY
3538   //    R = X(A)Z(B)Y(G) --> R = Y(G)Z(B)X(A)
3539   alpha = 0.1517461713131;
3540   beta = 1.5162198410141;
3541   gamma = 1.9313156236541;
3542   Standard_Real alpha2, beta2, gamma2;
3543   gp_EulerSequence pairs[][2] = { {gp_Extrinsic_XYZ, gp_Intrinsic_ZYX},
3544                                   {gp_Extrinsic_XZY, gp_Intrinsic_YZX},
3545                                   {gp_Extrinsic_YZX, gp_Intrinsic_XZY},
3546                                   {gp_Extrinsic_YXZ, gp_Intrinsic_ZXY},
3547                                   {gp_Extrinsic_ZXY, gp_Intrinsic_YXZ},
3548                                   {gp_Extrinsic_ZYX, gp_Intrinsic_XYZ} };
3549   for (int i = 0; i < 6; i++)
3550   {
3551     aQuat.SetEulerAngles(pairs[i][0],  alpha,  beta,  gamma);
3552     aQuat.GetEulerAngles(pairs[i][1], gamma2, beta2, alpha2);
3553
3554     if (Abs(alpha - alpha2) > 1e-5 || Abs(beta - beta2) > 1e-5 || Abs(gamma - gamma2) > 1e-5)
3555     {
3556       theDI << "Error: intrinsic and extrinsic conversion incorrect for sequence " << names[i] << "\n";
3557       isTestOk = Standard_False;
3558     }
3559   }
3560
3561   // Check correspondence of enumeration and actual rotation it defines, 
3562   // by rotation by one axis and checking that it does not change a point on that axis
3563   for (int i = gp_Extrinsic_XYZ; i <= gp_Intrinsic_ZYZ; i++)
3564   {
3565     // Iterate over rotations R(A)R(B)R(G) for each Euler angle Alpha, Beta, Gamma
3566     // There are three ordered axes corresponding to three rotations.
3567     // Each rotation applyed with current angle around current axis.
3568     for (int j=0; j < 3; j++)
3569     {
3570       // note that current axis index is obtained by parsing of enumeration name!
3571       int anAxis = names[i - gp_Extrinsic_XYZ][10 + j] - 'X';
3572       Standard_ASSERT_RETURN (anAxis >=0 && anAxis <= 2, "Incorrect parsing of enumeration name", 1);
3573
3574       // Set 90 degrees to current Euler angle
3575       double anAngles[3] = {0., 0., 0.};
3576       anAngles[j] = 0.5 * M_PI;
3577
3578       gp_Quaternion q2;
3579       q2.SetEulerAngles (gp_EulerSequence(i), anAngles[0], anAngles[1], anAngles[2]);
3580
3581       // Set point on axis corresponding to current rotation
3582       // We will apply rotation around this axis
3583       gp_XYZ v (0., 0., 0.);
3584       v.SetCoord (anAxis + 1, 1.);
3585
3586       // Apply rotation to point
3587       gp_Trsf aT;
3588       aT.SetRotation (q2);
3589       gp_XYZ v2 = v;
3590       aT.Transforms (v2);
3591
3592       // Check that point is still on origin position
3593       if ((v - v2).SquareModulus() > Precision::SquareConfusion())
3594       {
3595         // avoid reporting small coordinates
3596         for (int k=1; k <= 3; k++) 
3597           if (Abs (v2.Coord(k)) < Precision::Confusion())
3598             v2.SetCoord (k, 0.);
3599
3600         isTestOk = Standard_False;
3601         theDI << "Error: Euler sequence " << names[i - gp_Extrinsic_XYZ] << " is incorrect:\n";
3602         theDI << "rotating by angle 90 deg around " << (anAxis == 0 ? "X" : anAxis == 1 ? "Y" : "Z") <<
3603                       " converts vector (" << v.X() << ", " << v.Y() << ", " << v.Z() << ") to ("
3604                         << v2.X() << ", " << v2.Y() << ", " << v2.Z() << ")\n";
3605       }
3606     }
3607   }
3608
3609   // Check correspondence of enumeration and actual rotation it defines, 
3610   // by comparing cumulative rotation matrix with sequence of rotations by axes
3611   const Standard_Real anAngle[3] = { 0.1, 0.2, 0.3 };
3612   for (int i = gp_Extrinsic_XYZ; i <= gp_Intrinsic_ZYZ; i++)
3613   {
3614     // Sequence of rotations
3615     gp_Mat aR[3];
3616     for (int j=0; j < 3; j++)
3617     {
3618       // note that current axis index is obtained by parsing of enumeration name!
3619       int anAxis = names[i - gp_Extrinsic_XYZ][10 + j] - 'X';
3620       Standard_ASSERT_RETURN (anAxis >=0 && anAxis <= 2, "Incorrect parsing of enumeration name", 1);
3621
3622       // Set point on axis corresponding to current rotation
3623       // We will apply rotation around this axis
3624       gp_XYZ v (0., 0., 0.);
3625       v.SetCoord (anAxis + 1, 1.);
3626       aR[j].SetRotation (v, anAngle[j]);
3627     }
3628
3629     // construct cumulative transformation (differently for extrinsic and intrinsic rotations);
3630     // note that we parse first symbol of the enum name to identify its type
3631     gp_Mat aRot;
3632     if (names[i - gp_Extrinsic_XYZ][0] == 'E') // extrinsic
3633     {
3634       aRot = aR[2] * aR[1] * aR[0];
3635     }
3636     else // intrinsic
3637     {
3638       aRot = aR[0] * aR[1] * aR[2];
3639     }
3640
3641     // set the same angles in quaternion
3642     aQuat.SetEulerAngles (gp_EulerSequence(i), anAngle[0], anAngle[1], anAngle[2]);
3643
3644     gp_Mat aRQ = aQuat.GetMatrix();
3645     gp_Mat aDiff = aRQ * aRot.Inverted() - aI;
3646     if (aDiff.Determinant() > 1e-5)
3647     {
3648       theDI << "Error: Euler angles conversion does not correspond to sequential rotations for " << names[i - gp_Extrinsic_XYZ] << "\n";
3649       isTestOk = Standard_False;
3650     }
3651   }
3652
3653   // similar checkfor YawPitchRoll sequence as defined in description of #25574
3654   {
3655     // Start with world coordinate system
3656     gp_Ax2 world;
3657
3658     // Perform three rotations using the yaw-pitch-roll convention.
3659     // This means: rotate around the original z axis with angle alpha,
3660     // then rotate around the new y axis with angle beta,
3661     // then rotate around the new x axis with angle gamma.
3662     alpha = 0.0 / 180.0 * M_PI;
3663     beta = -35.0 / 180.0 * M_PI;
3664     gamma = 90.0 / 180.0 * M_PI;
3665
3666     const gp_Quaternion rotationZ(world.Direction(), alpha);
3667     const gp_Vec rotY = rotationZ.Multiply(world.YDirection());
3668     const gp_Vec rotX = rotationZ.Multiply(world.XDirection());
3669
3670     const gp_Quaternion rotationY(rotY, beta);
3671     const gp_Vec rotZ = rotationY.Multiply(world.Direction());
3672     const gp_Vec rotRotX = rotationY.Multiply(rotX);
3673
3674     const gp_Quaternion rotationX(rotRotX, gamma);
3675     const gp_Vec rotRotZ = rotationX.Multiply(rotZ);
3676
3677     gp_Ax2 result(gp_Pnt(0.0, 0.0, 0.0), rotRotZ, rotRotX);
3678
3679     // Now compute the Euler angles
3680     gp_Trsf transformation;
3681     transformation.SetDisplacement(gp_Ax2(), result);
3682
3683     Standard_Real computedAlpha;
3684     Standard_Real computedBeta;
3685     Standard_Real computedGamma;
3686
3687     transformation.GetRotation().GetEulerAngles(gp_YawPitchRoll, computedAlpha, computedBeta, computedGamma);
3688
3689     // We expect now to get the same angles as we have used for our rotations
3690     if (Abs(alpha - computedAlpha) > 1e-5 || Abs(beta - computedBeta) > 1e-5 || Abs(gamma - computedGamma) > 1e-5)
3691     {
3692       theDI << "Error: unexpected values of Euler angles for YawPitchRoll sequence:\n";
3693       theDI << "alpha: " << alpha / M_PI * 180.0 << " and computed alpha: "
3694             << computedAlpha / M_PI * 180.0 << "\n";
3695       theDI << "beta: " << beta / M_PI * 180.0 << " and computed beta: "
3696             << computedBeta / M_PI * 180.0 << "\n";
3697       theDI << "gamma: " << gamma / M_PI * 180.0 << " and computed gamma: "
3698             << computedGamma / M_PI * 180.0 << "\n";
3699       isTestOk = Standard_False;
3700     }
3701   }
3702
3703   // test from #25946
3704   {
3705     gp_Quaternion q;
3706     q.Set(0.06766916507860499, 0.21848101129786085, 0.11994599260380681,0.9660744746954637);
3707
3708     q.GetEulerAngles(gp_Intrinsic_ZYX, alpha,beta, gamma);
3709     q.GetEulerAngles(gp_Extrinsic_XYZ, alpha2,beta2,gamma2);
3710
3711     // gp_Intrinsic_ZYX and gp_Extrinsic_XYZ should produce the same values of angles but in opposite order
3712     if (Abs(alpha - gamma2) > 1e-5 || Abs(beta - beta2) > 1e-5 || Abs(gamma - alpha2) > 1e-5)
3713     {
3714       theDI << "Error: Euler angles computed for gp_Intrinsic_ZYX and gp_Extrinsic_XYZ do not match:\n";
3715       theDI << "alpha: " << alpha / M_PI * 180.0 << " and " << alpha2 / M_PI * 180.0 << "\n";
3716       theDI << "beta: " << beta / M_PI * 180.0 << " and " << beta2 / M_PI * 180.0 << "\n";
3717       theDI << "gamma: " << gamma / M_PI * 180.0 << " and " << gamma2 / M_PI * 180.0 << "\n";
3718       isTestOk = Standard_False;
3719     }
3720   }
3721
3722   theDI << (isTestOk ? "Test completed" : "Test failed") << "\n";
3723   return 0;
3724 }
3725
3726 #include <TColGeom_Array1OfBSplineCurve.hxx>
3727 #include <TColStd_Array1OfReal.hxx>
3728 #include <TColGeom_HArray1OfBSplineCurve.hxx>
3729 #include <GeomConvert.hxx>
3730
3731 //=======================================================================
3732 //function : OCC26446
3733 //purpose  : 
3734 //=======================================================================
3735 Standard_Integer OCC26446 (Draw_Interpretor& di, 
3736                            Standard_Integer n, 
3737                            const char** a)
3738 {
3739   if (n != 4) {
3740     di << "Usage: OCC26446 r c1 c2\n";
3741     return 1;
3742   }
3743
3744   Handle(Geom_BSplineCurve) aCurve1 =
3745     Handle(Geom_BSplineCurve)::DownCast(DrawTrSurf::GetCurve(a[2]));
3746   Handle(Geom_BSplineCurve) aCurve2 = 
3747     Handle(Geom_BSplineCurve)::DownCast(DrawTrSurf::GetCurve(a[3]));
3748
3749   if (aCurve1.IsNull()) {
3750     di << a[2] << " is not a BSpline curve\n";
3751         return 1;
3752   }
3753
3754   if (aCurve2.IsNull()) {
3755     di << a[3] << " is not a BSpline curve\n";
3756         return 1;
3757   }
3758
3759   TColGeom_Array1OfBSplineCurve          aCurves     (0, 1);
3760   TColStd_Array1OfReal                   aTolerances (0, 0);
3761   Standard_Real                          aTolConf    = 1.e-3;
3762   Standard_Real                          aTolClosure = Precision::Confusion();
3763   Handle(TColGeom_HArray1OfBSplineCurve) aConcatCurves;
3764   Handle(TColStd_HArray1OfInteger)       anIndices;
3765
3766   aCurves.SetValue(0, aCurve1);
3767   aCurves.SetValue(1, aCurve2);
3768   aTolerances.SetValue(0, aTolConf);
3769
3770   GeomConvert::ConcatC1(aCurves,
3771                         aTolerances,
3772                         anIndices,
3773                         aConcatCurves,
3774                         Standard_False,
3775                         aTolClosure);
3776
3777   Handle(Geom_BSplineCurve) aResult =
3778     aConcatCurves->Value(aConcatCurves->Lower());
3779
3780   DrawTrSurf::Set(a[1], aResult);
3781   return 0;
3782 }
3783
3784 static Standard_Integer OCC26448 (Draw_Interpretor& theDI, Standard_Integer, const char **)
3785 {
3786   TColStd_SequenceOfReal aSeq1, aSeq2;
3787   aSeq1.Append(11.);
3788   aSeq1.Prepend (aSeq2);
3789   theDI << "TCollection: 11 -> " << aSeq1.First() << "\n";
3790
3791   NCollection_Sequence<Standard_Real> nSeq1, nSeq2;
3792   nSeq1.Append(11.);
3793   nSeq1.Prepend (nSeq2);
3794   theDI << "NCollection: 11 -> " << nSeq1.First() << "\n";
3795
3796   theDI << "OK";
3797   return 0;
3798 }
3799
3800 //=======================================================================
3801 //function : OCC26407
3802 //purpose  :
3803 //=======================================================================
3804 #include <BRepBuilderAPI_MakeWire.hxx>
3805 #include <BRepBuilderAPI_MakeEdge.hxx>
3806 #include <BRepMesh_IncrementalMesh.hxx>
3807 #include <TCollection_AsciiString.hxx>
3808 static Standard_Integer OCC26407 (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3809 {
3810   if (theArgNb != 2)
3811   {
3812     std::cerr << "Error: wrong number of arguments! See usage:\n";
3813     theDI.PrintHelp (theArgVec[0]);
3814     return 1;
3815   }
3816
3817   // Construct vertices.
3818   std::vector<TopoDS_Vertex> wire_vertices;
3819   wire_vertices.push_back(BRepBuilderAPI_MakeVertex(gp_Pnt(587.90000000000009094947, 40.6758179230516248026106, 88.5)));
3820   wire_vertices.push_back(BRepBuilderAPI_MakeVertex(gp_Pnt(807.824182076948432040808, 260.599999999999965893949, 88.5)));
3821   wire_vertices.push_back(BRepBuilderAPI_MakeVertex(gp_Pnt(644.174182076948454778176, 424.249999999999943156581, 88.5000000000000142108547)));
3822   wire_vertices.push_back(BRepBuilderAPI_MakeVertex(gp_Pnt(629.978025792618950617907, 424.25, 88.5)));
3823   wire_vertices.push_back(BRepBuilderAPI_MakeVertex(gp_Pnt(793.628025792618700506864, 260.599999999999852207111, 88.5)));
3824   wire_vertices.push_back(BRepBuilderAPI_MakeVertex(gp_Pnt(587.900000000000204636308, 54.8719742073813492311274, 88.5)));
3825   wire_vertices.push_back(BRepBuilderAPI_MakeVertex(gp_Pnt(218.521974207381418864315, 424.250000000000056843419, 88.5)));
3826   wire_vertices.push_back(BRepBuilderAPI_MakeVertex(gp_Pnt(204.325817923051886282337, 424.249999999999943156581, 88.5)));
3827
3828   // Construct wire.
3829   BRepBuilderAPI_MakeWire wire_builder;
3830   for (size_t i = 0; i < wire_vertices.size(); i++)
3831   {
3832     const TopoDS_Vertex &v = wire_vertices[i];
3833     const TopoDS_Vertex &w = wire_vertices[(i+1) % wire_vertices.size()];
3834
3835     wire_builder.Add(BRepBuilderAPI_MakeEdge(v, w));
3836   }
3837
3838   // Create face and triangulate it.
3839   // Construct face.
3840   gp_Pnt v0 = BRep_Tool::Pnt(wire_vertices[0]);
3841   gp_Pnt v1 = BRep_Tool::Pnt(wire_vertices[1]);
3842   gp_Pnt v2 = BRep_Tool::Pnt(wire_vertices[wire_vertices.size() - 1]);
3843
3844   gp_Vec face_normal = gp_Vec(v0, v1).Crossed(gp_Vec(v0, v2));
3845
3846   TopoDS_Face face = BRepBuilderAPI_MakeFace(gp_Pln(v0, face_normal), wire_builder);
3847   BRepMesh_IncrementalMesh m(face, 1e-7);
3848
3849   if (m.GetStatusFlags() != 0)
3850   {
3851     theDI << "Failed. Status for face constructed from vertices: " << m.GetStatusFlags() << "\n";
3852     return 1;
3853   }
3854   DBRep::Set(theArgVec[1], face);
3855   char buf[256];
3856   sprintf(buf, "isos %s 0", theArgVec[1]);
3857   theDI.Eval(buf);
3858
3859   sprintf(buf, "triangles %s", theArgVec[1]);
3860   theDI.Eval(buf);
3861
3862   theDI.Eval("smallview; fit");
3863
3864   theDI << "Test completed\n";
3865   return 0;
3866 }
3867
3868 //=======================================================================
3869 //function : OCC26485
3870 //purpose  :
3871 //=======================================================================
3872 #include <Poly.hxx>
3873 static Standard_Integer OCC26485 (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3874 {
3875   if (theArgNb != 2)
3876   {
3877     std::cerr << "Error: wrong number of arguments! See usage:\n";
3878     theDI.PrintHelp (theArgVec[0]);
3879     return 1;
3880   }
3881
3882   TopoDS_Shape aShape = DBRep::Get(theArgVec[1]);
3883   if (aShape.IsNull())
3884   {
3885     theDI << "Failed. Null shape\n";
3886     return 1;
3887   }
3888
3889   Standard_Boolean isFailed = Standard_False;
3890   TopExp_Explorer aExplorer(aShape, TopAbs_FACE);
3891   for (; aExplorer.More(); aExplorer.Next())
3892   {
3893     const TopoDS_Face& aFace = TopoDS::Face( aExplorer.Current() );
3894     TopLoc_Location L = TopLoc_Location();
3895     const Handle(Poly_Triangulation)& aT = BRep_Tool::Triangulation( aFace , L );
3896
3897     if(aT.IsNull())
3898       continue;
3899
3900     Poly::ComputeNormals(aT);
3901     const TColgp_Array1OfPnt&       aVertices = aT->Nodes();
3902     const TShort_Array1OfShortReal& aNormals  = aT->Normals();
3903
3904     // Number of nodes in the triangulation
3905     int aVertexNb = aT->Nodes().Length();
3906     if (aVertexNb*3 != aNormals.Length())
3907     {
3908       theDI << "Failed. Different number of normals vs. vertices\n";
3909       return 1;
3910     }
3911
3912     // Get each vertex index, checking common vertexes between shapes
3913     for( int i=0; i < aVertexNb; i++ )
3914     {
3915       gp_Pnt aPoint = aVertices.Value( i+1 );
3916       gp_Vec aNormal = gp_Vec(
3917         aNormals.Value( i*3 + 1 ),
3918         aNormals.Value( i*3 + 2 ),
3919         aNormals.Value( i*3 + 3 ) );
3920
3921       if (aNormal.X() == 0 && aNormal.Y() == 0 && aNormal.Z() == 1)
3922       {
3923         char buf[256];
3924         sprintf(buf, "fail_%d", i+1);
3925         theDI << "Failed. Point " << buf << ": "
3926               << aPoint.X() << " "
3927               << aPoint.Y() << " "
3928               << aPoint.Z() << "\n";
3929
3930         DrawTrSurf::Set (buf, aPoint);
3931       }
3932     }
3933   }
3934
3935   theDI << (isFailed ? "Test failed" : "Test completed") << "\n";
3936   return 0;
3937 }
3938
3939 //=======================================================================
3940 //function : OCC26553
3941 //purpose  :
3942 //=======================================================================
3943 #include <BRepBuilderAPI_MakeWire.hxx>
3944
3945 static Standard_Integer OCC26553 (Draw_Interpretor& theDI, Standard_Integer theArgc, const char** theArgv)
3946 {
3947   if (theArgc < 2)
3948   {
3949     theDI << "Error: path to file with shell is missing\n";
3950     return 1;
3951   }
3952
3953   BRep_Builder aBuilder;
3954   TopoDS_Shape aShell;
3955   BRepTools::Read(aShell, theArgv[1], aBuilder);
3956
3957   if (aShell.IsNull())
3958   {
3959     theDI << "Error: shell not loaded\n";
3960     return 1;
3961   }
3962
3963   TopoDS_Edge aPipeEdge = BRepBuilderAPI_MakeEdge (gp_Pnt (0, 0, 0), gp_Pnt (0, 0, 10));
3964   TopoDS_Wire aPipeWire = BRepBuilderAPI_MakeWire(aPipeEdge).Wire();
3965
3966   BRepOffsetAPI_MakePipe aPipeBuilder(aPipeWire, aShell);
3967   if (!aPipeBuilder.IsDone())
3968   {
3969     theDI << "Error: failed to create pipe\n";
3970     return 1;
3971   }
3972
3973   for (TopExp_Explorer aShapeExplorer(aShell, TopAbs_EDGE); aShapeExplorer.More(); aShapeExplorer.Next ()) {
3974     const TopoDS_Shape& aGeneratedShape = aPipeBuilder.Generated(aPipeEdge, aShapeExplorer.Current());
3975     if (aGeneratedShape.IsNull())
3976     {
3977       theDI << "Error: null shape\n";
3978       return 1;
3979     }
3980   }
3981
3982   theDI << "History returned successfully\n";
3983   return 0;
3984 }
3985
3986 //=======================================================================
3987 //function : OCC26195
3988 //purpose  :
3989 //=======================================================================
3990 #include <SelectMgr_SelectingVolumeManager.hxx>
3991 #include <BRepBuilderAPI_MakePolygon.hxx>
3992 #include <Geom_CartesianPoint.hxx>
3993 #include <AIS_Line.hxx>
3994 #include <Aspect_Window.hxx>
3995 static Standard_Integer OCC26195 (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3996 {
3997   if (theArgNb < 3)
3998   {
3999     std::cerr << "Error: wrong number of arguments! See usage:\n";
4000     theDI.PrintHelp (theArgVec[0]);
4001     return 1;
4002   }
4003
4004   if (ViewerTest::GetAISContext().IsNull())
4005   {
4006     std::cerr << "Error: No opened context!\n";
4007     return 1;
4008   }
4009
4010   gp_Pnt2d aPxPnt1, aPxPnt2;
4011   aPxPnt1.SetX (Draw::Atof (theArgVec[1]));
4012   aPxPnt1.SetY (Draw::Atof (theArgVec[2]));
4013   if (theArgNb > 4)
4014   {
4015     aPxPnt2.SetX (Draw::Atof (theArgVec[3]));
4016     aPxPnt2.SetY (Draw::Atof (theArgVec[4]));
4017   }
4018   Standard_Boolean toPrint = Standard_False;
4019   if (theArgNb % 2 == 0)
4020   {
4021     toPrint = Draw::Atoi (theArgVec[theArgNb - 1]) != 0;
4022   }
4023
4024   SelectMgr_SelectingVolumeManager* aMgr = new SelectMgr_SelectingVolumeManager();
4025   aMgr->SetActiveSelectionType (theArgNb > 4 ?
4026     SelectMgr_SelectingVolumeManager::Box : SelectMgr_SelectingVolumeManager::Point);
4027   aMgr->SetCamera (ViewerTest::CurrentView()->Camera());
4028   aMgr->SetPixelTolerance (ViewerTest::GetAISContext()->PixelTolerance());
4029   Standard_Integer aWidth, aHeight;
4030   ViewerTest::CurrentView()->View()->Window()->Size (aWidth, aHeight);
4031   aMgr->SetWindowSize (aWidth, aHeight);
4032   if (theArgNb > 4)
4033   {
4034     aMgr->BuildSelectingVolume (aPxPnt1, aPxPnt2);
4035   }
4036   else
4037   {
4038     aMgr->BuildSelectingVolume (aPxPnt1);
4039   }
4040   const gp_Pnt* aVerts = aMgr->GetVertices();
4041   gp_Pnt aNearPnt = aMgr->GetNearPickedPnt();
4042   gp_Pnt aFarPnt  = aMgr->GetFarPickedPnt();
4043   BRepBuilderAPI_MakePolygon aWireBldrs[4];
4044
4045   aWireBldrs[0].Add (gp_Pnt (aVerts[0].X(), aVerts[0].Y(), aVerts[0].Z()));
4046   aWireBldrs[0].Add (gp_Pnt (aVerts[4].X(), aVerts[4].Y(), aVerts[4].Z()));
4047   aWireBldrs[0].Add (gp_Pnt (aVerts[6].X(), aVerts[6].Y(), aVerts[6].Z()));
4048   aWireBldrs[0].Add (gp_Pnt (aVerts[2].X(), aVerts[2].Y(), aVerts[2].Z()));
4049   aWireBldrs[0].Add (gp_Pnt (aVerts[0].X(), aVerts[0].Y(), aVerts[0].Z()));
4050
4051   aWireBldrs[1].Add (gp_Pnt (aVerts[4].X(), aVerts[4].Y(), aVerts[4].Z()));
4052   aWireBldrs[1].Add (gp_Pnt (aVerts[5].X(), aVerts[5].Y(), aVerts[5].Z()));
4053   aWireBldrs[1].Add (gp_Pnt (aVerts[7].X(), aVerts[7].Y(), aVerts[7].Z()));
4054   aWireBldrs[1].Add (gp_Pnt (aVerts[6].X(), aVerts[6].Y(), aVerts[6].Z()));
4055   aWireBldrs[1].Add (gp_Pnt (aVerts[4].X(), aVerts[4].Y(), aVerts[4].Z()));
4056
4057   aWireBldrs[2].Add (gp_Pnt (aVerts[1].X(), aVerts[1].Y(), aVerts[1].Z()));
4058   aWireBldrs[2].Add (gp_Pnt (aVerts[5].X(), aVerts[5].Y(), aVerts[5].Z()));
4059   aWireBldrs[2].Add (gp_Pnt (aVerts[7].X(), aVerts[7].Y(), aVerts[7].Z()));
4060   aWireBldrs[2].Add (gp_Pnt (aVerts[3].X(), aVerts[3].Y(), aVerts[3].Z()));
4061   aWireBldrs[2].Add (gp_Pnt (aVerts[1].X(), aVerts[1].Y(), aVerts[1].Z()));
4062
4063   aWireBldrs[3].Add (gp_Pnt (aVerts[0].X(), aVerts[0].Y(), aVerts[0].Z()));
4064   aWireBldrs[3].Add (gp_Pnt (aVerts[1].X(), aVerts[1].Y(), aVerts[1].Z()));
4065   aWireBldrs[3].Add (gp_Pnt (aVerts[3].X(), aVerts[3].Y(), aVerts[3].Z()));
4066   aWireBldrs[3].Add (gp_Pnt (aVerts[2].X(), aVerts[2].Y(), aVerts[2].Z()));
4067   aWireBldrs[3].Add (gp_Pnt (aVerts[0].X(), aVerts[0].Y(), aVerts[0].Z()));
4068
4069   TopoDS_Compound aComp;
4070   BRep_Builder    aCompBuilder;
4071   aCompBuilder.MakeCompound (aComp);
4072   for (Standard_Integer aWireIdx = 0; aWireIdx < 4; ++aWireIdx)
4073   {
4074     aCompBuilder.Add (aComp, aWireBldrs[aWireIdx].Shape());
4075   }
4076   DBRep::Set ("c", aComp);
4077
4078   Handle(AIS_InteractiveObject) aCmp = new AIS_Shape (aComp);
4079   aCmp->SetColor (Quantity_NOC_GREEN);
4080   ViewerTest::Display ("c", aCmp, Standard_True, Standard_True);
4081
4082   Handle(Geom_CartesianPoint) aPnt1 = new Geom_CartesianPoint (aNearPnt);
4083   Handle(Geom_CartesianPoint) aPnt2 = new Geom_CartesianPoint (aFarPnt);
4084
4085   Handle(AIS_Line) aLine = new AIS_Line (aPnt1, aPnt2);
4086   ViewerTest::Display ("l", aLine, Standard_True, Standard_True);
4087
4088   if (toPrint)
4089   {
4090     theDI << "Near: " << aNearPnt.X() << " " << aNearPnt.Y() << " " << aNearPnt.Z() << "\n";
4091     theDI << "Far: " << aFarPnt.X() << " " << aFarPnt.Y() << " " << aFarPnt.Z() << "\n";
4092   }
4093
4094   return 0;
4095 }
4096
4097 //=======================================================================
4098 //function : OCC26462
4099 //purpose  :
4100 //=======================================================================
4101 static Standard_Integer OCC26462 (Draw_Interpretor& theDI, Standard_Integer /*theArgNb*/, const char** /*theArgVec*/)
4102 {
4103   if (ViewerTest::GetAISContext().IsNull())
4104   {
4105     std::cerr << "Error: No opened context!\n";
4106     return 1;
4107   }
4108
4109   BRepPrimAPI_MakeBox aBuilder1 (gp_Pnt (10.0, 10.0, 0.0), 10.0, 10.0, 10.0);
4110   BRepPrimAPI_MakeBox aBuilder2 (10.0, 10.0, 10.0);
4111   Handle(AIS_InteractiveObject) aBox1 = new AIS_Shape (aBuilder1.Shape());
4112   Handle(AIS_InteractiveObject) aBox2 = new AIS_Shape (aBuilder2.Shape());
4113
4114   const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4115   aCtx->Display (aBox1, 0, 2, Standard_False);
4116   aCtx->Display (aBox2, 0, 2, Standard_False);
4117   ViewerTest::CurrentView()->FitAll();
4118   aCtx->SetWidth (aBox1, 3, Standard_False);
4119   aCtx->SetWidth (aBox2, 3, Standard_False);
4120
4121   aCtx->MoveTo (305, 322, ViewerTest::CurrentView(), Standard_False);
4122   aCtx->ShiftSelect (Standard_False);
4123   aCtx->MoveTo (103, 322, ViewerTest::CurrentView(), Standard_False);
4124   aCtx->ShiftSelect (Standard_False);
4125   if (aCtx->NbSelected() != 0)
4126   {
4127     theDI << "ERROR: no boxes must be selected!\n";
4128     return 1;
4129   }
4130
4131   aCtx->SetSelectionSensitivity (aBox1, 2, 5);
4132
4133   aCtx->MoveTo (305, 322, ViewerTest::CurrentView(), Standard_False);
4134   aCtx->ShiftSelect (Standard_False);
4135   if (aCtx->NbSelected() != 1)
4136   {
4137     theDI << "ERROR: b1 was not selected\n";
4138     return 1;
4139   }
4140   aCtx->MoveTo (103, 322, ViewerTest::CurrentView(), Standard_False);
4141   aCtx->ShiftSelect (Standard_True);
4142   if (aCtx->NbSelected() != 1)
4143   {
4144     theDI << "ERROR: b2 is selected after b1's tolerance increased\n";
4145     return 1;
4146   }
4147
4148   return 0;
4149 }
4150
4151
4152 #include <BRepBuilderAPI_GTransform.hxx>
4153 static Standard_Integer OCC26313(Draw_Interpretor& di,Standard_Integer n,const char** a)
4154 {
4155   if (n <= 1) return 1;
4156   
4157   gp_Trsf T;
4158   gp_GTrsf GT(T);
4159   
4160   gp_Mat rot( 1.0, 0.0, 0.0,
4161               0.0, 2.0, 0.0,
4162               0.0, 0.0, 3.0);
4163   
4164   GT.SetVectorialPart(rot);
4165   BRepBuilderAPI_GTransform gtrf(GT);
4166
4167   TopoDS_Shape aSrcShape = DBRep::Get(a[2]);
4168   if (aSrcShape.IsNull()) {
4169     di << a[2] << " is not a valid shape\n";
4170     return 1;
4171   }
4172
4173   
4174   gtrf.Perform(aSrcShape);
4175   if (gtrf.IsDone())
4176   {
4177     try
4178     {
4179       DBRep::Set(a[1], gtrf.ModifiedShape(aSrcShape));
4180     }
4181     catch(Standard_Failure)
4182     {
4183       di << "Error: Exception is thrown\n";
4184     }
4185   }
4186   else
4187   {
4188     di << "Error: Result is not done\n";
4189     return 1;
4190   }
4191   
4192   return 0;
4193 }
4194
4195 //=======================================================================
4196 //function : OCC26525
4197 //purpose  : check number of intersection points
4198 //=======================================================================
4199 #include <BRepAdaptor_Curve.hxx>
4200 #include <BRepAdaptor_Surface.hxx>
4201 #include <BRepAdaptor_HCurve.hxx>
4202 #include <BRepAdaptor_HSurface.hxx>
4203 #include <IntCurveSurface_HInter.hxx>
4204 Standard_Integer OCC26525 (Draw_Interpretor& di, 
4205                            Standard_Integer n, 
4206                            const char** a)
4207 {
4208   TopoDS_Shape aS1, aS2;
4209   TopoDS_Edge aE; 
4210   TopoDS_Face aF;
4211
4212   if (n<4)
4213   {
4214     di << " use OCC26525 r edge face \n";
4215     return 1;
4216   }
4217
4218   aS1 = DBRep::Get(a[2]);
4219   aS2 = DBRep::Get(a[3]);
4220
4221   if (aS1.IsNull() || aS2.IsNull())
4222   {
4223     di << " Null shapes are not allowed \n";
4224     return 0;
4225   }
4226   if (aS1.ShapeType()!=TopAbs_EDGE)
4227   {
4228     di << " Shape" << a[2] << " should be of type EDGE\n";
4229     return 0;
4230   }
4231   if (aS2.ShapeType()!=TopAbs_FACE)
4232   {
4233     di << " Shape" << a[3] << " should be of type FACE\n";
4234     return 0;
4235   }
4236
4237   aE=TopoDS::Edge(aS1);
4238   aF=TopoDS::Face(aS2);
4239
4240   char buf[128];
4241   Standard_Boolean bIsDone;
4242   Standard_Integer i, aNbPoints;
4243   Standard_Real aU, aV, aT;
4244   gp_Pnt aP;
4245   BRepAdaptor_Curve aBAC;
4246   BRepAdaptor_Surface aBAS;
4247   IntCurveSurface_TransitionOnCurve aTC;
4248   IntCurveSurface_HInter aHInter;
4249
4250   aBAC.Initialize(aE);
4251   aBAS.Initialize(aF);
4252
4253   Handle(BRepAdaptor_HCurve) aHBAC=new BRepAdaptor_HCurve(aBAC);
4254   Handle(BRepAdaptor_HSurface) aHBAS = new BRepAdaptor_HSurface(aBAS);
4255
4256   aHInter.Perform(aHBAC, aHBAS);
4257   bIsDone=aHInter.IsDone();
4258   if (!bIsDone)
4259   {
4260     di << " intersection is not done\n";
4261     return 0;
4262   }
4263
4264   aNbPoints=aHInter.NbPoints();
4265   sprintf (buf, " Number of intersection points found: %d", aNbPoints);
4266   di <<  buf << "\n";
4267   for (i=1; i<=aNbPoints; ++i)
4268   {
4269     const IntCurveSurface_IntersectionPoint& aIP=aHInter.Point(i);
4270     aIP.Values(aP, aU, aV, aT, aTC);
4271     //
4272     sprintf (buf, "point %s_%d %lg %lg %lg  ", a[1], i, aP.X(), aP.Y(), aP.Z());
4273     di << buf << "\n";
4274   }
4275
4276   return 0;
4277 }
4278
4279 //=======================================================================
4280 //function : OCC24537
4281 //purpose  : Puts inverted numbers (in the sense of little/big endian inversion)
4282 //           from predefined arrays.
4283 //=======================================================================
4284 #include <FSD_BinaryFile.hxx>
4285
4286 template<int size>
4287 inline const unsigned char* SizeRef ();
4288
4289 template<>
4290 inline const unsigned char* SizeRef <8> ()
4291 {
4292   static const unsigned char aSizeRef[] = {
4293     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
4294     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,
4295     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
4296     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,
4297     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,
4298     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,
4299     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,
4300     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,
4301     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09,
4302     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
4303   return aSizeRef;
4304 }
4305
4306 template<>
4307 inline const unsigned char* SizeRef <4> ()
4308 {
4309   static const unsigned char aSizeRef[] = {
4310     0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x02,
4311     0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x04,
4312     0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x06,
4313     0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x08,
4314     0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x00};
4315   return aSizeRef;
4316 }
4317
4318 static Standard_Integer OCC24537(
4319   Draw_Interpretor& theDI, 
4320   Standard_Integer  argc, 
4321   const char **     argv)
4322 {
4323   std::ofstream aF;
4324   if (argc > 1)
4325   {
4326     aF.open(argv[1]);
4327     if (!aF.is_open())
4328     {
4329       cout << "cannot create file " << argv[1] << endl;
4330       return 1;
4331     }
4332   }
4333   Standard_Boolean isErr = Standard_False;
4334   // 1. InverseInt
4335   const unsigned char anIntRef[] = {
4336     0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x02,
4337     0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x04,
4338     0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x06,
4339     0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x08,
4340     0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x00};
4341   Standard_Integer anIntArr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
4342   if (aF.is_open())
4343   {
4344     for(int i = 0; i < 10; ++i)
4345     {
4346       Standard_Integer anInv = FSD_BinaryFile::InverseInt(anIntArr[i]);
4347       aF.write(reinterpret_cast<char*>(&anInv), sizeof(anInv));
4348     }
4349   }
4350   else
4351   {
4352     Standard_Integer anInv[10];
4353     for(int i = 0; i < 10; ++i)
4354       anInv[i] = FSD_BinaryFile::InverseInt(anIntArr[i]);
4355     if (memcmp(anInv, anIntRef, sizeof(anIntRef)) != 0)
4356     {
4357       theDI << "Error: incorrect conversion of an integer value\n";
4358       isErr = Standard_True;
4359     }
4360   }
4361   
4362   // 1a. Random InverseInt
4363   const unsigned char aRndIntRef[] = {
4364     0xFF,0xC2,0xF7,0x00,0xFF,0xFF,0xFB,0x2E,
4365     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
4366     0x00,0x00,0x04,0xD2,0x00,0x00,0x04,0xD3,
4367     0xFF,0xFF,0xFD,0x1E,0xFF,0xFF,0xFF,0xFB,
4368     0x00,0x00,0x03,0x8D,0x00,0x3D,0x09,0x00};
4369   Standard_Integer aRndIntArr[] = {-4000000, -1234, 0, 1, 1234, 1235, -738, -5, 909, 4000000};
4370   if (aF.is_open())
4371   {
4372     for(int i = 0; i < 10; ++i)
4373     {
4374       Standard_Integer anInv = FSD_BinaryFile::InverseInt(aRndIntArr[i]);
4375       aF.write(reinterpret_cast<char*>(&anInv), sizeof(anInv));
4376     }
4377   }
4378   else
4379   {
4380     Standard_Integer anInv[10];
4381     for(int i = 0; i < 10; ++i)
4382       anInv[i] = FSD_BinaryFile::InverseInt(aRndIntArr[i]);
4383     if (memcmp(anInv, aRndIntRef, sizeof(aRndIntRef)) != 0)
4384     {
4385       theDI << "Error: incorrect conversion of a dispersed integer value\n";
4386       isErr = Standard_True;
4387     }
4388   }
4389   
4390   // 2. InverseReal
4391   const unsigned char aRealRef[] = {
4392     0x3F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
4393     0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
4394     0x40,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
4395     0x40,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
4396     0x40,0x14,0x00,0x00,0x00,0x00,0x00,0x00,
4397     0x40,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
4398     0x40,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,
4399     0x40,0x20,0x00,0x00,0x00,0x00,0x00,0x00,
4400     0x40,0x22,0x00,0x00,0x00,0x00,0x00,0x00,
4401     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
4402   const Standard_Real aRealArr[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 0.0};
4403   if (aF.is_open())
4404   {
4405     for(int i = 0; i < 10; ++i)
4406     {
4407       Standard_Real anInv = FSD_BinaryFile::InverseReal(aRealArr[i]);
4408       aF.write(reinterpret_cast<char*>(&anInv), sizeof(anInv));
4409     }
4410   }
4411   else
4412   {
4413     Standard_Real anInv[10];
4414     for(int i = 0; i < 10; ++i)
4415       anInv[i] = FSD_BinaryFile::InverseReal(aRealArr[i]);
4416     if (memcmp(anInv, aRealRef, sizeof(aRealRef)) != 0)
4417     {
4418       theDI << "Error: incorrect conversion of a real value\n";
4419       isErr = Standard_True;
4420     }
4421   }
4422
4423   // 2a. Random InverseReal
4424   const unsigned char aRndRealRef[] = {
4425     0xFE,0x37,0xE4,0x3C,0x88,0x00,0x75,0x9C,
4426     0xBE,0x11,0x2E,0x0B,0xE8,0x26,0xD6,0x95,
4427     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
4428     0x3E,0x11,0x2E,0x0B,0xE8,0x26,0xD6,0x95,
4429     0x3F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
4430     0x40,0x09,0x21,0xDA,0x45,0x5B,0x53,0xE4,
4431     0x54,0xB2,0x49,0xAD,0x25,0x94,0xC3,0x7D,
4432     0x40,0x20,0x00,0x00,0x00,0x00,0x00,0x00,
4433     0xC0,0x23,0xCC,0xCC,0xCC,0xCC,0xCC,0xCD,
4434     0x40,0x23,0xCC,0xCC,0xCC,0xCC,0xCC,0xCD};
4435   const Standard_Real aRndRealArr[] = {-1e300, -1.e-9, 0., 1.e-9, 1., 3.1415296, 1.e100, 8.0, -9.9, 9.9};
4436   if (aF.is_open())
4437   {
4438     for(int i = 0; i < 10; ++i)
4439     {
4440       Standard_Real anInv = FSD_BinaryFile::InverseReal(aRndRealArr[i]);
4441       aF.write(reinterpret_cast<char*>(&anInv), sizeof(anInv));
4442     }
4443   }
4444   else
4445   {
4446     Standard_Real anInv[10];
4447     for(int i = 0; i < 10; ++i)
4448       anInv[i] = FSD_BinaryFile::InverseReal(aRndRealArr[i]);
4449     if (memcmp(anInv, aRndRealRef, sizeof(aRndRealRef)) != 0)
4450     {
4451       theDI << "Error: incorrect conversion of a dispersed real value\n";
4452       isErr = Standard_True;
4453     }
4454   }
4455
4456   // 3. InverseShortReal
4457   const unsigned char aShortRealRef[] = {
4458     0x3F,0x80,0x00,0x00,0x40,0x00,0x00,0x00,
4459     0x40,0x40,0x00,0x00,0x40,0x80,0x00,0x00,
4460     0x40,0xA0,0x00,0x00,0x40,0xC0,0x00,0x00,
4461     0x40,0xE0,0x00,0x00,0x41,0x00,0x00,0x00,
4462     0x41,0x10,0x00,0x00,0x00,0x00,0x00,0x00};
4463   const Standard_ShortReal aShortRealArr[] = {
4464     1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 0.0f};
4465   if (aF.is_open())
4466   {
4467     for(int i = 0; i < 10; ++i)
4468     {
4469       Standard_ShortReal anInv = FSD_BinaryFile::InverseShortReal(aShortRealArr[i]);
4470       aF.write(reinterpret_cast<char*>(&anInv), sizeof(anInv));
4471     }
4472   }
4473   else
4474   {
4475     Standard_ShortReal anInv[10];
4476     for(int i = 0; i < 10; ++i)
4477       anInv[i] = FSD_BinaryFile::InverseShortReal(aShortRealArr[i]);
4478     if (memcmp(anInv, aShortRealRef, sizeof(aShortRealRef)) != 0)
4479     {
4480       theDI << "Error: incorrect conversion of a short real value\n";
4481       isErr = Standard_True;
4482     }
4483   }
4484
4485   // 3a. Random InverseShortReal
4486   const unsigned char aRndShortRealRef[] = {
4487     0xB0,0x89,0x70,0x5F,0x00,0x00,0x00,0x00,
4488     0x30,0x89,0x70,0x5F,0x3F,0x80,0x00,0x00,
4489     0x40,0x49,0x0E,0x56,0xC0,0xD6,0x66,0x66,
4490     0x40,0xD6,0x66,0x66,0x42,0xC5,0xCC,0xCD,
4491     0xC2,0xC7,0xCC,0xCD,0x42,0xC7,0xCC,0xCD};
4492   const Standard_ShortReal aRndShortRealArr[] = {
4493     -1.e-9f, 0.f, 1.e-9f, 1.f, 3.1415f, -6.7f, 6.7f, 98.9f, -99.9f, 99.9f};
4494   if (aF.is_open())
4495   {
4496     for(int i = 0; i < 10; ++i)
4497     {
4498       Standard_ShortReal anInv = FSD_BinaryFile::InverseShortReal(aRndShortRealArr[i]);
4499       aF.write(reinterpret_cast<char*>(&anInv), sizeof(anInv));
4500     }
4501   }
4502   else
4503   {
4504     Standard_ShortReal anInv[10];
4505     for(int i = 0; i < 10; ++i)
4506       anInv[i] = FSD_BinaryFile::InverseShortReal(aRndShortRealArr[i]);
4507     if (memcmp(anInv, aRndShortRealRef, sizeof(aRndShortRealRef)) != 0)
4508     {
4509       theDI << "Error: incorrect conversion of a dispersed short real value\n";
4510       isErr = Standard_True;
4511     }
4512   }
4513
4514   // 4. InverseSize
4515   const Standard_Size aSizeArr[] = {1ul, 2ul, 3ul, 4ul, 5ul, 6ul, 7ul, 8ul, 9ul, 0ul};
4516   if (aF.is_open())
4517   {
4518     for(int i = 0; i < 10; ++i)
4519     {
4520       Standard_Size anInv = FSD_BinaryFile::InverseSize(aSizeArr[i]);
4521       aF.write(reinterpret_cast<char*>(&anInv), sizeof(anInv));
4522     }
4523   }
4524   else
4525   {
4526     Standard_Size anInv[10];
4527     const unsigned char* aSizeRef = SizeRef<sizeof(Standard_Size)>();
4528     for(int i = 0; i < 10; ++i)
4529       anInv[i] = FSD_BinaryFile::InverseSize(aSizeArr[i]);
4530     if (memcmp(anInv, aSizeRef, sizeof(Standard_Size)*10) != 0)
4531     {
4532       theDI << "Error: incorrect conversion of a size value\n";
4533       isErr = Standard_True;
4534     }
4535   }
4536
4537   if (!aF.is_open() && !isErr)
4538     theDI << "Conversion was done OK";
4539   if (aF.is_open())
4540   {
4541     cout << "the file " << argv[1] << " has been created" << endl;
4542     aF.close();
4543   }
4544   return 0;
4545 }
4546
4547
4548 #include <TopExp.hxx>
4549 #include <BRepOffsetAPI_DraftAngle.hxx>
4550 #include <vector>
4551 static TopoDS_Shape taper(const TopoDS_Shape &shape, const TopoDS_Face &face_a, const TopoDS_Face &face_b, Standard_Real angle)
4552 {
4553   // Use maximum face-to-taper z-offset.
4554   const gp_Pln neutral_plane(gp_Ax3(gp_Pnt(0.0, 0.0, 140.0), gp_Dir(0.0, 0.0, 1.0)));
4555
4556   // Draft angle needs to be in radians, and flipped to adhere to our own (arbitrary) draft
4557   // angle definition.
4558   const Standard_Real draft_angle = -(angle / 180.0) * M_PI;
4559
4560   // Add face to draft. The first argument indicates that all material added/removed during
4561   // drafting is located below the neutral plane
4562   BRepOffsetAPI_DraftAngle drafter(shape);
4563   drafter.Add(face_a, gp_Dir(0.0, 0.0, -1.0), draft_angle, neutral_plane);
4564   drafter.Add(face_b, gp_Dir(0.0, 0.0, -1.0), draft_angle, neutral_plane);
4565   drafter.Build();
4566
4567   return drafter.Shape();
4568 }
4569
4570 static void dumpShapeVertices(const TopoDS_Shape &shape, std::vector<Standard_Real>& coords)
4571 {
4572   TopTools_IndexedMapOfShape shape_vertices;
4573   TopExp::MapShapes(shape, TopAbs_VERTEX, shape_vertices);
4574
4575   for (Standard_Integer i = 1; i <= shape_vertices.Extent(); i++)
4576   {
4577     gp_Pnt p = BRep_Tool::Pnt(TopoDS::Vertex(shape_vertices(i)));
4578     coords.push_back(p.X());
4579     coords.push_back(p.Y());
4580     coords.push_back(p.Z());
4581   }
4582 }
4583
4584 static void GetCoords(const Standard_CString& path_to_file, std::vector<Standard_Real>& coords)
4585 {
4586   TopoDS_Shape shape;
4587   BRep_Builder builder;
4588   BRepTools::Read(shape, path_to_file, builder);
4589   TopTools_IndexedMapOfShape shape_faces;
4590   TopExp::MapShapes(shape, TopAbs_FACE, shape_faces);
4591   TopoDS_Face face_a = TopoDS::Face(shape_faces(1));
4592   TopoDS_Face face_b = TopoDS::Face(shape_faces(5));
4593   dumpShapeVertices(taper(shape, face_a, face_b, 5.0), coords);
4594 }
4595
4596 static Standard_Integer OCC26396 (Draw_Interpretor& theDI, Standard_Integer theArgc, const char** theArgv)
4597 {
4598   if (theArgc < 2)
4599   {
4600     theDI << "Error: path to file is missing\n";
4601     return 1;
4602   }
4603
4604   const int maxInd = 50;
4605
4606   std::vector<Standard_Real> ref_coords;
4607   ref_coords.reserve(100);
4608   Standard_Boolean Stat = Standard_True;
4609
4610   GetCoords(theArgv[1], ref_coords);
4611
4612   std::vector<Standard_Real> coords;
4613   coords.reserve(100);
4614   for (int i = 1; i < maxInd; i++)
4615   {
4616     GetCoords(theArgv[1], coords);
4617     if (coords.size() != ref_coords.size())
4618     {
4619       Stat = Standard_False;
4620       break;
4621     }
4622     for (size_t j = 0; j < coords.size(); j++)
4623       if (Abs(ref_coords[j] - coords[j]) > RealEpsilon())
4624       {
4625         Stat = Standard_False;
4626         break;
4627       }
4628     coords.clear();
4629   }
4630   if (!Stat)
4631     theDI << "Error: unstable results";
4632   else
4633     theDI << "test OK";
4634
4635   return 0;
4636 }
4637
4638 //=======================================================================
4639 //function : OCC26750 
4640 //purpose  : 
4641 //=======================================================================
4642 static Standard_Integer OCC26750( Draw_Interpretor& theDI,
4643                                   Standard_Integer  /*theNArg*/,
4644                                   const char ** /*theArgVal*/)
4645 {
4646   const gp_Vec2d aVec1(1.0, 0.0);
4647   const gp_Vec2d aVec2(0.0, -1.0);
4648
4649   if(aVec1.IsNormal(aVec2, Precision::Angular()))
4650   {
4651     theDI << "gp_Vec2d OK. Vectors are normal.\n";
4652   }
4653   else
4654   {
4655     theDI << "Error in gp_Vec2d. Vectors should be normal.\n";
4656   }
4657
4658   const gp_Dir2d aD1(1.0, 0.0);
4659   const gp_Dir2d aD2(0.0, -1.0);
4660
4661   if(aD1.IsNormal(aD2, Precision::Angular()))
4662   {
4663     theDI << "gp_Dir2d OK. Vectors are normal.\n";
4664   }
4665   else
4666   {
4667     theDI << "Error in gp_Dir2d. Vectors should be normal.\n";
4668   }
4669   
4670   return 0;
4671 }
4672
4673 //=======================================================================
4674 //function : OCC26746 
4675 //purpose  : Checks if coefficients of the torus are computed properly.
4676 //=======================================================================
4677 #include <Geom_ToroidalSurface.hxx>
4678 #include <Geom_BSplineCurve.hxx>
4679 static Standard_Integer OCC26746(
4680   Draw_Interpretor& theDI, 
4681   Standard_Integer  theNArg, 
4682   const char **     theArgVal)
4683 {
4684   if(theNArg < 2)
4685   {
4686     theDI << "Use: OCC26746 torus [toler NbCheckedPoints]\n";
4687     return 1;
4688   }
4689
4690   const Handle(Geom_ToroidalSurface) aGtor = 
4691     Handle(Geom_ToroidalSurface)::DownCast(DrawTrSurf::GetSurface(theArgVal[1]));
4692
4693   const Standard_Real aToler = (theNArg >= 3)? Draw::Atof(theArgVal[2]) : 1.0e-7;
4694   const Standard_Integer aNbPntsMax = (theNArg >= 4)? Draw::Atoi(theArgVal[3]) : 5;
4695
4696   const Standard_Integer aLowIndex = 5;
4697   const Standard_Real aStep = 2.0*M_PI/aNbPntsMax;
4698
4699   TColStd_Array1OfReal anArrCoeffs(aLowIndex, aLowIndex+34);
4700   aGtor->Torus().Coefficients(anArrCoeffs);
4701
4702   Standard_Real aUpar = 0.0, aVpar = 0.0;
4703   for(Standard_Integer aUind = 0; aUind <= aNbPntsMax; aUind++)
4704   {
4705     for(Standard_Integer aVind = 0; aVind <= aNbPntsMax; aVind++)
4706     {
4707       const gp_Pnt aPt(aGtor->Value(aUpar, aVpar));
4708       const Standard_Real aX1 = aPt.X();
4709       const Standard_Real aX2 = aX1*aX1;
4710       const Standard_Real aX3 = aX2*aX1;
4711       const Standard_Real aX4 = aX2*aX2;
4712       const Standard_Real aY1 = aPt.Y();
4713       const Standard_Real aY2 = aY1*aY1;
4714       const Standard_Real aY3 = aY2*aY1;
4715       const Standard_Real aY4 = aY2*aY2;
4716       const Standard_Real aZ1 = aPt.Z();
4717       const Standard_Real aZ2 = aZ1*aZ1;
4718       const Standard_Real aZ3 = aZ2*aZ1;
4719       const Standard_Real aZ4 = aZ2*aZ2;
4720
4721       Standard_Integer i = aLowIndex;
4722
4723       Standard_Real aDelta =  anArrCoeffs(i++) * aX4;  //1
4724       aDelta+= anArrCoeffs(i++) * aY4;                 //2
4725       aDelta+= anArrCoeffs(i++) * aZ4;                 //3
4726       aDelta+= anArrCoeffs(i++) * aX3 * aY1;           //4
4727       aDelta+= anArrCoeffs(i++) * aX3 * aZ1;           //5
4728       aDelta+= anArrCoeffs(i++) * aY3 * aX1;           //6
4729       aDelta+= anArrCoeffs(i++) * aY3 * aZ1;           //7
4730       aDelta+= anArrCoeffs(i++) * aZ3 * aX1;           //8
4731       aDelta+= anArrCoeffs(i++) * aZ3 * aY1;           //9
4732       aDelta+= anArrCoeffs(i++) * aX2 * aY2;           //10
4733       aDelta+= anArrCoeffs(i++) * aX2 * aZ2;           //11
4734       aDelta+= anArrCoeffs(i++) * aY2 * aZ2;           //12
4735       aDelta+= anArrCoeffs(i++) * aX2 * aY1 * aZ1;     //13
4736       aDelta+= anArrCoeffs(i++) * aX1 * aY2 * aZ1;     //14
4737       aDelta+= anArrCoeffs(i++) * aX1 * aY1 * aZ2;     //15
4738       aDelta+= anArrCoeffs(i++) * aX3;                 //16
4739       aDelta+= anArrCoeffs(i++) * aY3;                 //17
4740       aDelta+= anArrCoeffs(i++) * aZ3;                 //18
4741       aDelta+= anArrCoeffs(i++) * aX2 * aY1;           //19
4742       aDelta+= anArrCoeffs(i++) * aX2 * aZ1;           //20
4743       aDelta+= anArrCoeffs(i++) * aY2 * aX1;           //21
4744       aDelta+= anArrCoeffs(i++) * aY2 * aZ1;           //22
4745       aDelta+= anArrCoeffs(i++) * aZ2 * aX1;           //23
4746       aDelta+= anArrCoeffs(i++) * aZ2 * aY1;           //24
4747       aDelta+= anArrCoeffs(i++) * aX1 * aY1 * aZ1;     //25
4748       aDelta+= anArrCoeffs(i++) * aX2;                 //26
4749       aDelta+= anArrCoeffs(i++) * aY2;                 //27
4750       aDelta+= anArrCoeffs(i++) * aZ2;                 //28
4751       aDelta+= anArrCoeffs(i++) * aX1 * aY1;           //29
4752       aDelta+= anArrCoeffs(i++) * aX1 * aZ1;           //30
4753       aDelta+= anArrCoeffs(i++) * aY1 * aZ1;           //31
4754       aDelta+= anArrCoeffs(i++) * aX1;                 //32
4755       aDelta+= anArrCoeffs(i++) * aY1;                 //33
4756       aDelta+= anArrCoeffs(i++) * aZ1;                 //34
4757       aDelta+= anArrCoeffs(i++);                       //35
4758
4759       if(Abs(aDelta) > aToler)
4760       {
4761         theDI << "(" << aUpar << ", " << aVpar << "): Error in torus coefficients computation (Delta = " << aDelta << ").\n";
4762       }
4763       else
4764       {
4765         theDI << "(" << aUpar << ", " << aVpar << "): OK (Delta = " << aDelta << ").\n";
4766       }
4767
4768       aVpar = (aVind == aNbPntsMax)? 2.0*M_PI : aVpar + aStep;
4769     }
4770
4771     aVpar = 0.0;
4772     aUpar = (aUind == aNbPntsMax)? 2.0*M_PI : aUpar + aStep;
4773   }
4774
4775   return 0;     
4776 }
4777
4778 DEFINE_STANDARD_HANDLE(QABugs_VertexFilter, SelectMgr_Filter)
4779 class QABugs_VertexFilter: public SelectMgr_Filter
4780 {
4781 public:
4782   Standard_EXPORT QABugs_VertexFilter() : SelectMgr_Filter() {}
4783
4784   Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)&) const
4785   {
4786     return Standard_False;
4787   }
4788 };
4789
4790 //=======================================================================
4791 //function : BUC26658 
4792 //purpose  : Checks selection in the context after using a selection filter
4793 //=======================================================================
4794 static Standard_Integer BUC26658 (Draw_Interpretor& theDI,
4795                                   Standard_Integer  /*theNArg*/,
4796                                   const char ** theArgVal)
4797 {
4798   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4799   if(aContext.IsNull()) {
4800     theDI << "use 'vinit' command before " << theArgVal[0] << "\n";
4801     return 1;
4802   }
4803
4804   TopoDS_Shape aBoxShape = BRepPrimAPI_MakeBox(20,20,20).Shape();
4805   Handle(AIS_Shape) anAISIO = new AIS_Shape(aBoxShape);
4806
4807   // visualization of the box in the local mode with possibility to
4808   // select box vertices
4809   Standard_DISABLE_DEPRECATION_WARNINGS
4810   aContext->OpenLocalContext();
4811   Standard_ENABLE_DEPRECATION_WARNINGS
4812
4813   int aDispMode = 0;// wireframe
4814   anAISIO->SetDisplayMode(aDispMode);
4815   aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed); 
4816   theDI.Eval(" vfit");
4817
4818   aContext->Load(anAISIO, -1, true); /// load allowing decomposition
4819   aContext->Deactivate(anAISIO);
4820   aContext->Activate(anAISIO, AIS_Shape::SelectionMode(TopAbs_VERTEX), false);
4821   aContext->UpdateCurrentViewer();
4822
4823   // select a point on the box
4824   Handle(V3d_View) myV3dView = ViewerTest::CurrentView();
4825   double Xv,Yv;
4826   myV3dView->Project(20,20,0,Xv,Yv);
4827   Standard_Integer Xp,Yp;
4828   myV3dView->Convert(Xv,Yv,Xp,Yp);
4829
4830   aContext->MoveTo (Xp, Yp, myV3dView, Standard_False);
4831   aContext->Select (Standard_False);
4832   bool aHasSelected = false;
4833   for (aContext->InitSelected(); aContext->MoreSelected() && !aHasSelected; aContext->NextSelected()) {
4834     Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
4835     if (!anIO.IsNull()) {
4836       const TopoDS_Shape aShape = aContext->SelectedShape();
4837       if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX)
4838         aHasSelected = true;
4839     }
4840   }
4841   if (aHasSelected)
4842      cout << "has selected vertex : OK"   << endl;
4843   else {
4844     theDI << "has selected vertex : bugged - Faulty\n";
4845     return 1;
4846   }
4847   // filter to deny any selection in the viewer
4848   Handle(QABugs_VertexFilter) aFilter = new QABugs_VertexFilter();
4849   aContext->AddFilter(aFilter);
4850
4851   // update previous selection by hand
4852   Standard_DISABLE_DEPRECATION_WARNINGS
4853   aContext->LocalContext()->ClearOutdatedSelection(anAISIO, true);
4854   Standard_ENABLE_DEPRECATION_WARNINGS
4855
4856   // check that there are no selected vertices
4857   aContext->Select (Standard_True);
4858   aHasSelected = false;
4859   for (aContext->InitSelected(); aContext->MoreSelected() && !aHasSelected; aContext->NextSelected()) {
4860     Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
4861     if (!anIO.IsNull()) {
4862       const TopoDS_Shape aShape = aContext->SelectedShape();
4863       if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX)
4864         aHasSelected = true;
4865     }
4866   }
4867   if (!aHasSelected) cout << "has no selected vertex after filter : OK"   << endl;
4868   else {
4869     theDI << "has no selected vertex after filter : bugged - Faulty\n";
4870     return 1;
4871   }
4872
4873   return 0;
4874 }
4875
4876 //=======================================================================
4877 //function : OCC26945_open
4878 //purpose  : Opens local context and activates given standard selection mode
4879 //=======================================================================
4880 static Standard_Integer OCC26945_open (Draw_Interpretor& theDI, Standard_Integer theArgc, const char** theArgv)
4881 {
4882   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4883   if (aCtx.IsNull())
4884   {
4885     std::cout << "No interactive context. Use 'vinit' command before " << theArgv[0] << "\n";
4886     return 1;
4887   }
4888
4889   if (theArgc < 2)
4890   {
4891     std::cout << "Not enough arguments. See usage:\n";
4892     theDI.PrintHelp (theArgv[0]);
4893     return 1;
4894   }
4895
4896   const TopAbs_ShapeEnum aSelType = AIS_Shape::SelectionType (Draw::Atoi (theArgv[1]));
4897   Standard_DISABLE_DEPRECATION_WARNINGS
4898   Standard_Integer aLocalCtxIdx = aCtx->OpenLocalContext();
4899   aCtx->ActivateStandardMode (aSelType);
4900   Standard_ENABLE_DEPRECATION_WARNINGS
4901   theDI << aLocalCtxIdx;
4902
4903   return 0;
4904 }
4905
4906 //=======================================================================
4907 //function : OCC26945_close
4908 //purpose  : Closes local context with the id given
4909 //=======================================================================
4910 static Standard_Integer OCC26945_close (Draw_Interpretor& theDI, Standard_Integer theArgc, const char** theArgv)
4911 {
4912   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4913   if (aCtx.IsNull())
4914   {
4915     std::cout << "No interactive context. Use 'vinit' command before " << theArgv[0] << "\n";
4916     return 1;
4917   }
4918
4919   if (theArgc < 2)
4920   {
4921     std::cout << "Not enough arguments. See usage:\n";
4922     theDI.PrintHelp (theArgv[0]);
4923     return 1;
4924   }
4925
4926   const Standard_Integer aCtxToClose = Draw::Atoi (theArgv[1]);
4927   Standard_DISABLE_DEPRECATION_WARNINGS
4928   aCtx->CloseLocalContext (aCtxToClose);
4929   Standard_ENABLE_DEPRECATION_WARNINGS
4930
4931   return 0;
4932 }
4933
4934 //=======================================================================
4935 //function : OCC27048
4936 //purpose  : Calculate value of B-spline surface N times
4937 //=======================================================================
4938 static Standard_Integer OCC27048(Draw_Interpretor& theDI, Standard_Integer theArgc, const char** theArgv)
4939 {
4940   if (theArgc != 5)
4941   {
4942     std::cout << "Incorrect number of arguments. See usage:" << std::endl;
4943     theDI.PrintHelp(theArgv[0]);
4944     return 1;
4945   }
4946
4947   Handle(Geom_Surface) aSurf = DrawTrSurf::GetSurface(theArgv[1]);
4948   GeomAdaptor_Surface anAdaptor(aSurf);
4949
4950   Standard_Real aU = Draw::Atof(theArgv[2]);
4951   Standard_Real aV = Draw::Atof(theArgv[3]);
4952   Standard_Integer aN = Draw::Atoi(theArgv[4]);
4953
4954   for (; aN > 0; --aN)
4955     anAdaptor.Value(aU, aV);
4956
4957   return 0;
4958 }
4959
4960 //========================================================================
4961 //function : OCC27065
4962 //purpose  : Tests overloaded method "Generated" of BRepOffsetAPI_MakePipe
4963 //========================================================================
4964 static Standard_Integer OCC27065(Draw_Interpretor& di,
4965                                  Standard_Integer n, const char** a)
4966 {
4967   if (n < 3) return 1;
4968   BRep_Builder BB;
4969
4970   TopoDS_Shape SpineShape = DBRep::Get(a[1],TopAbs_WIRE);
4971   if ( SpineShape.IsNull()) return 1;
4972   TopoDS_Wire Spine = TopoDS::Wire(SpineShape);
4973
4974   TopoDS_Shape Profile = DBRep::Get(a[2]);
4975   if ( Profile.IsNull()) return 1;
4976
4977   BRepOffsetAPI_MakePipe aPipeBuilder(Spine, Profile);
4978   if (!aPipeBuilder.IsDone())
4979   {
4980     di << "Error: failed to create pipe\n";
4981     return 1;
4982   }
4983
4984   TopExp_Explorer Explo(Profile, TopAbs_SHELL);
4985   TopoDS_Shape aShape;
4986   TopTools_ListIteratorOfListOfShape itl;
4987   if (Explo.More())
4988   {
4989     aShape = Explo.Current();
4990     TopoDS_Compound res1;
4991     BB.MakeCompound(res1);
4992     itl.Initialize(aPipeBuilder.Generated(aShape));
4993     for (; itl.More(); itl.Next())
4994       BB.Add(res1, itl.Value());
4995     DBRep::Set("res_shell", res1);
4996   }
4997
4998   Explo.Init(Profile, TopAbs_FACE);
4999   if (Explo.More())
5000   {
5001     aShape = Explo.Current();
5002     TopoDS_Compound res2;
5003     BB.MakeCompound(res2);
5004     itl.Initialize(aPipeBuilder.Generated(aShape));
5005     for (; itl.More(); itl.Next())
5006       BB.Add(res2, itl.Value());
5007     DBRep::Set("res_face", res2);
5008   }
5009   
5010   Explo.Init(Profile, TopAbs_WIRE);
5011   if (Explo.More())
5012   {
5013     aShape = Explo.Current();
5014     TopoDS_Compound res3;
5015     BB.MakeCompound(res3);
5016     itl.Initialize(aPipeBuilder.Generated(aShape));
5017     for (; itl.More(); itl.Next())
5018       BB.Add(res3, itl.Value());
5019     DBRep::Set("res_wire", res3);
5020   }
5021   
5022   Explo.Init(Profile, TopAbs_EDGE);
5023   if (Explo.More())
5024   {
5025     aShape = Explo.Current();
5026     TopoDS_Compound res4;
5027     BB.MakeCompound(res4);
5028     itl.Initialize(aPipeBuilder.Generated(aShape));
5029     for (; itl.More(); itl.Next())
5030       BB.Add(res4, itl.Value());
5031     DBRep::Set("res_edge", res4);
5032   }
5033   
5034   Explo.Init(Profile, TopAbs_VERTEX);
5035   if (Explo.More())
5036   {
5037     aShape = Explo.Current();
5038     TopoDS_Compound res5;
5039     BB.MakeCompound(res5);
5040     itl.Initialize(aPipeBuilder.Generated(aShape));
5041     for (; itl.More(); itl.Next())
5042       BB.Add(res5, itl.Value());
5043     DBRep::Set("res_vertex", res5);
5044   }
5045   
5046   return 0;
5047 }
5048
5049 //========================================================================
5050 //function : OCC27318
5051 //purpose  : Creates a box that is not listed in map of AIS objects of ViewerTest
5052 //========================================================================
5053 static Standard_Integer OCC27318 (Draw_Interpretor& /*theDI*/, Standard_Integer /*theArgc*/, const char** theArgv)
5054 {
5055   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
5056   if (aCtx.IsNull())
5057   {
5058     std::cout << "No interactive context. Use 'vinit' command before " << theArgv[0] << "\n";
5059     return 1;
5060   }
5061
5062   TopoDS_Shape aBox = BRepPrimAPI_MakeBox (20, 20, 20).Shape();
5063   Handle(AIS_Shape) aBoxObj = new AIS_Shape (aBox);
5064   aCtx->Display (aBoxObj, Standard_True);
5065
5066   return 0;
5067 }
5068
5069 //========================================================================
5070 //function : OCC27523
5071 //purpose  : Checks recomputation of deactivated selection mode after object's redisplaying
5072 //========================================================================
5073 static Standard_Integer OCC27523 (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
5074 {
5075   if (theArgNb != 1)
5076   {
5077     std::cerr << "Error: wrong number of arguments! See usage:\n";
5078     theDI.PrintHelp (theArgVec[0]);
5079     return 1;
5080   }
5081
5082   Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
5083   if(anAISContext.IsNull())
5084   {
5085     std::cerr << "Error: no active view. Please call vinit.\n";
5086     return 1;
5087   }
5088
5089   gp_Pnt aStart (100, 100, 100);
5090   gp_Pnt anEnd (300, 400, 600);
5091   BRepBuilderAPI_MakeEdge anEdgeBuilder (aStart, anEnd);
5092   TopoDS_Edge anEdge = anEdgeBuilder.Edge();
5093   Handle(AIS_InteractiveObject) aTestAISShape = new AIS_Shape (anEdge);
5094   anAISContext->Display (aTestAISShape, Standard_False);
5095
5096   // activate it in selection modes
5097   TColStd_SequenceOfInteger aModes;
5098   aModes.Append (AIS_Shape::SelectionMode ((TopAbs_ShapeEnum) TopAbs_VERTEX));
5099
5100   anAISContext->Deactivate (aTestAISShape);
5101   anAISContext->Load (aTestAISShape, -1, true);
5102   anAISContext->Activate (aTestAISShape, 0);
5103   anAISContext->Deactivate (aTestAISShape, 0);
5104
5105   // activate in vertices mode
5106   for (Standard_Integer anIt = 1; anIt <= aModes.Length(); ++anIt)
5107   {
5108     anAISContext->Activate (aTestAISShape, aModes (anIt));
5109   }
5110
5111   TopoDS_Shape aVertexShape = BRepBuilderAPI_MakeVertex (gp_Pnt (75, 0, 0));
5112   TopAbs_ShapeEnum aVertexShapeType = aVertexShape.ShapeType();
5113   Handle(AIS_Shape)::DownCast (aTestAISShape)->Set (aVertexShape);
5114   aTestAISShape->Redisplay();
5115
5116   anAISContext->AddOrRemoveSelected (aTestAISShape, Standard_True);
5117
5118   bool aValidShapeType = false;
5119   for (anAISContext->InitSelected(); anAISContext->MoreSelected(); anAISContext->NextSelected())
5120   {
5121     Handle(SelectMgr_EntityOwner) anOwner = anAISContext->SelectedOwner();
5122     Handle(StdSelect_BRepOwner) aBRO = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
5123     if (!aBRO.IsNull() && aBRO->HasShape())
5124     {
5125       TopoDS_Shape aShape = aBRO->Shape();
5126
5127       aValidShapeType = aShape.ShapeType() == aVertexShapeType;
5128     }
5129   }
5130
5131   if (!aValidShapeType)
5132   {
5133     std::cerr << "Error: shape type is invalid.\n";
5134     return 1;
5135   }
5136
5137   return 0;
5138 }
5139
5140 //========================================================================
5141 //function : OCC27700
5142 //purpose  : glPolygonMode() used for frame drawing affects label text shading
5143 //========================================================================
5144
5145 class OCC27700_Text : public AIS_InteractiveObject
5146 {
5147 public:
5148
5149   DEFINE_STANDARD_RTTI_INLINE (OCC27700_Text, AIS_InteractiveObject)
5150
5151   virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
5152                         const Handle(Prs3d_Presentation)& thePresentation,
5153                         const Standard_Integer /*theMode*/) Standard_OVERRIDE
5154   {
5155     Handle(Graphic3d_ArrayOfTriangles) aFrame = new Graphic3d_ArrayOfTriangles (6, 6);
5156     aFrame->AddVertex (gp_Pnt (-1, 0, 0));
5157     aFrame->AddVertex (gp_Pnt (-1, 1, 0));
5158     aFrame->AddVertex (gp_Pnt ( 3, 1, 0));
5159     aFrame->AddVertex (gp_Pnt ( 3, 0, 0));
5160
5161     aFrame->AddEdge (1);
5162     aFrame->AddEdge (2);
5163     aFrame->AddEdge (3);
5164
5165     aFrame->AddEdge (2);
5166     aFrame->AddEdge (3);
5167     aFrame->AddEdge (4);
5168
5169     Handle(Graphic3d_AspectFillArea3d) aFillAspect =
5170       new Graphic3d_AspectFillArea3d (*myDrawer->ShadingAspect()->Aspect().get());
5171     aFillAspect->SetInteriorStyle (Aspect_IS_POINT);
5172
5173     // create separate group for frame elements
5174     Handle(Graphic3d_Group) aFrameGroup = Prs3d_Root::NewGroup (thePresentation);
5175     aFrameGroup->AddPrimitiveArray (aFrame);
5176     aFrameGroup->SetGroupPrimitivesAspect (aFillAspect);
5177
5178     // create separate group for text elements
5179     Handle(Graphic3d_Group) aTextGroup = Prs3d_Root::NewGroup (thePresentation);
5180     TCollection_ExtendedString aString ("YOU SHOULD SEE THIS TEXT", Standard_True);
5181     Prs3d_Text::Draw (Prs3d_Root::CurrentGroup (thePresentation), myDrawer->TextAspect(), aString, gp_Ax2 (gp::Origin(), gp::DZ()));
5182   }
5183
5184   virtual void ComputeSelection (const Handle(SelectMgr_Selection)& /*theSelection*/,
5185                                  const Standard_Integer /*theMode*/) Standard_OVERRIDE {}
5186 };
5187
5188 static Standard_Integer OCC27700 (Draw_Interpretor& /*theDI*/, Standard_Integer /*theArgNb*/, const char** /*theArgVec*/)
5189 {
5190   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5191   if (aContext.IsNull())
5192   {
5193     std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5194     return 1;
5195   }
5196   Handle(OCC27700_Text) aPresentation = new OCC27700_Text();
5197   aContext->Display (aPresentation, Standard_True);
5198   return 0;
5199 }
5200
5201 //========================================================================
5202 //function : OCC27757
5203 //purpose  : Creates a box that has a sphere as child object and displays it
5204 //========================================================================
5205 static Standard_Integer OCC27757 (Draw_Interpretor& /*theDI*/, Standard_Integer /*theArgc*/, const char** theArgv)
5206 {
5207   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
5208   if (aCtx.IsNull())
5209   {
5210     std::cout << "No interactive context. Use 'vinit' command before " << theArgv[0] << "\n";
5211     return 1;
5212   }
5213
5214   TopoDS_Shape aBox = BRepPrimAPI_MakeBox (20.0, 20.0, 20.0).Shape();
5215   TopoDS_Shape aSphere = BRepPrimAPI_MakeSphere (10.0).Shape();
5216   gp_Trsf aTrsf;
5217   aTrsf.SetTranslationPart (gp_Vec (20.0, 20.0, 0.0));
5218   aSphere.Located (TopLoc_Location (aTrsf));
5219
5220
5221   Handle(AIS_Shape) aBoxObj = new AIS_Shape (aBox);
5222   Handle(AIS_Shape) aSphereObj = new AIS_Shape (aSphere);
5223   aBoxObj->AddChild (aSphereObj);
5224   aCtx->Display (aBoxObj, 1, 0, Standard_False);
5225   aCtx->UpdateCurrentViewer();
5226
5227   return 0;
5228 }
5229
5230 //========================================================================
5231 //function : OCC27818
5232 //purpose  : Creates three boxes and highlights one of them with own style
5233 //========================================================================
5234 static Standard_Integer OCC27818 (Draw_Interpretor& /*theDI*/, Standard_Integer /*theArgc*/, const char** theArgv)
5235 {
5236   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
5237   if (aCtx.IsNull())
5238   {
5239     std::cout << "No interactive context. Use 'vinit' command before " << theArgv[0] << "\n";
5240     return 1;
5241   }
5242
5243   Handle(AIS_Shape) aBoxObjs[3];
5244   for (Standard_Integer aBoxIdx = 0; aBoxIdx < 3; ++aBoxIdx)
5245   {
5246     TopoDS_Shape aBox = BRepPrimAPI_MakeBox (20.0, 20.0, 20.0).Shape();
5247     aBoxObjs[aBoxIdx] = new AIS_Shape (aBox);
5248     gp_Trsf aTrsf;
5249     aTrsf.SetTranslationPart (gp_Vec (30.0 * aBoxIdx, 30.0 * aBoxIdx, 0.0));
5250     aBoxObjs[aBoxIdx]->SetLocalTransformation (aTrsf);
5251     aBoxObjs[aBoxIdx]->SetHilightMode (AIS_Shaded);
5252   }
5253
5254   {
5255     Handle(Prs3d_Drawer) aHiStyle = new Prs3d_Drawer();
5256     aBoxObjs[1]->SetDynamicHilightAttributes (aHiStyle);
5257     aHiStyle->SetDisplayMode (AIS_Shaded);
5258     aHiStyle->SetColor (Quantity_NOC_RED);
5259     aHiStyle->SetTransparency (0.8f);
5260   }
5261   {
5262     Handle(Prs3d_Drawer) aSelStyle = new Prs3d_Drawer();
5263     aBoxObjs[2]->SetHilightAttributes (aSelStyle);
5264     aSelStyle->SetDisplayMode (AIS_Shaded);
5265     aSelStyle->SetColor (Quantity_NOC_RED);
5266     aSelStyle->SetTransparency (0.0f);
5267     aSelStyle->SetZLayer (Graphic3d_ZLayerId_Topmost);
5268   }
5269
5270   for (Standard_Integer aBoxIdx = 0; aBoxIdx < 3; ++aBoxIdx)
5271   {
5272     aCtx->Display (aBoxObjs[aBoxIdx], AIS_Shaded, 0, Standard_False);
5273   }
5274
5275   aCtx->UpdateCurrentViewer();
5276
5277   return 0;
5278 }
5279
5280 //========================================================================
5281 //function : OCC27893
5282 //purpose  : Creates a box and selects it via AIS_InteractiveContext API
5283 //========================================================================
5284 static Standard_Integer OCC27893 (Draw_Interpretor& /*theDI*/, Standard_Integer /*theArgc*/, const char** theArgv)
5285 {
5286   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
5287   if (aCtx.IsNull())
5288   {
5289     std::cout << "No interactive context. Use 'vinit' command before " << theArgv[0] << "\n";
5290     return 1;
5291   }
5292
5293   TopoDS_Shape aBox = BRepPrimAPI_MakeBox (10.0, 10.0, 10.0).Shape();
5294   Handle(AIS_InteractiveObject) aBoxObj = new AIS_Shape (aBox);
5295   aCtx->Display (aBoxObj, AIS_Shaded, 0, Standard_False);
5296   aCtx->SetSelected (aBoxObj, Standard_True);
5297
5298   return 0;
5299 }
5300
5301 //========================================================================
5302 //function : OCC28310
5303 //purpose  : Tests validness of iterator in AIS_InteractiveContext after
5304 // an removing object from it
5305 //========================================================================
5306 static Standard_Integer OCC28310 (Draw_Interpretor& /*theDI*/, Standard_Integer /*theArgc*/, const char** theArgv)
5307 {
5308   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
5309   if (aCtx.IsNull())
5310   {
5311     std::cout << "No interactive context. Use 'vinit' command before " << theArgv[0] << "\n";
5312     return 1;
5313   }
5314
5315   TopoDS_Shape aBox = BRepPrimAPI_MakeBox (10.0, 10.0, 10.0).Shape();
5316   Handle(AIS_InteractiveObject) aBoxObj = new AIS_Shape (aBox);
5317   aCtx->Display (aBoxObj, AIS_Shaded, 0, Standard_False);
5318   ViewerTest::CurrentView()->FitAll();
5319   aCtx->MoveTo (200, 200, ViewerTest::CurrentView(), Standard_True);
5320   aCtx->Select(Standard_True);
5321
5322   aCtx->Remove (aBoxObj, Standard_True);
5323   // nullify the object explicitly to simulate situation in project,
5324   // when ::Remove is called from another method and the object is destroyed
5325   // before ::DetectedInteractive is called
5326   aBoxObj.Nullify();
5327
5328   for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
5329   {
5330     Handle(AIS_InteractiveObject) anObj = aCtx->DetectedInteractive();
5331   }
5332
5333   return 0;
5334 }
5335
5336 // repetitive display and removal of multiple small objects in the viewer for 
5337 // test of memory leak in visualization (OCCT 6.9.0 - 7.0.0)
5338 static Standard_Integer OCC29412 (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
5339 {
5340   Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5341   if (aCtx.IsNull())
5342   {
5343     std::cout << "Error: no active view.\n";
5344     return 1;
5345   }
5346
5347   const int aNbIters = (theArgNb <= 1 ? 10000 : Draw::Atoi (theArgVec[1]));
5348   int aProgressPrev = -1;
5349   for (int m_loopIndex = 0; m_loopIndex < aNbIters; m_loopIndex++)
5350   {
5351     gp_Pnt pos;
5352     gp_Vec dir(0, 0,1);
5353
5354     gp_Ax2 center (pos, dir);
5355     gp_Circ circle (center, 1);
5356     Handle(AIS_Shape) feature;
5357
5358     BRepBuilderAPI_MakeEdge builder( circle );
5359
5360     if( builder.Error() == BRepBuilderAPI_EdgeDone )
5361     {
5362       TopoDS_Edge E1 = builder.Edge();
5363       TopoDS_Shape W2 = BRepBuilderAPI_MakeWire(E1).Wire();
5364       feature = new AIS_Shape(W2);
5365       aCtx->Display (feature, true);
5366     }
5367
5368     aCtx->CurrentViewer()->Update();
5369     ViewerTest::CurrentView()->FitAll();
5370     aCtx->Remove (feature, true);
5371
5372     const int aProgress = (m_loopIndex * 100) / aNbIters;
5373     if (aProgress != aProgressPrev)
5374     {
5375       std::cerr << aProgress << "%\r";
5376       aProgressPrev = aProgress;
5377     }
5378   }
5379   return 0;
5380 }
5381
5382 //========================================================================
5383 //function : Commands_19
5384 //purpose  :
5385 //========================================================================
5386
5387 void QABugs::Commands_19(Draw_Interpretor& theCommands) {
5388   const char *group = "QABugs";
5389
5390   Handle(QABugs_HandleClass) aClassPtr = new QABugs_HandleClass();
5391   theCommands.Add ("OCC24202_1", "Test Handle-based procedure",
5392                    __FILE__, aClassPtr, &QABugs_HandleClass::HandleProc, group);
5393   NCollection_Handle<QABugs_NHandleClass> aNClassPtr = new QABugs_NHandleClass();
5394   theCommands.Add ("OCC24202_2", "Test NCollection_Handle-based procedure",
5395                    __FILE__, aNClassPtr, &QABugs_NHandleClass::NHandleProc, group);
5396
5397   theCommands.Add ("OCC230", "OCC230 TrimmedCurve Pnt2d Pnt2d", __FILE__, OCC230, group);
5398   theCommands.Add ("OCC23361", "OCC23361", __FILE__, OCC23361, group);
5399   theCommands.Add ("OCC23237", "OCC23237", __FILE__, OCC23237, group); 
5400   theCommands.Add ("OCC22980", "OCC22980", __FILE__, OCC22980, group);
5401   theCommands.Add ("OCC23595", "OCC23595", __FILE__, OCC23595, group);
5402   theCommands.Add ("OCC22611", "OCC22611 string nb", __FILE__, OCC22611, group);
5403   theCommands.Add ("OCC22595", "OCC22595", __FILE__, OCC22595, group);
5404   theCommands.Add ("OCC23774", "OCC23774 shape1 shape2", __FILE__, OCC23774, group);
5405   theCommands.Add ("OCC23683", "OCC23683 shape", __FILE__, OCC23683, group);
5406   theCommands.Add ("OCC23952sweep", "OCC23952sweep nbupoles shape", __FILE__, OCC23952sweep, group);
5407   theCommands.Add ("OCC23952intersect", "OCC23952intersect nbsol shape1 shape2", __FILE__, OCC23952intersect, group);
5408   theCommands.Add ("test_offset", "test_offset", __FILE__, test_offset, group);
5409   theCommands.Add ("OCC23945", "OCC23945 surfname U V X Y Z [DUX DUY DUZ DVX DVY DVZ [D2UX D2UY D2UZ D2VX D2VY D2VZ D2UVX D2UVY D2UVZ]]", __FILE__, OCC23945,group);
5410   theCommands.Add ("OCC24008", "OCC24008 curve surface", __FILE__, OCC24008, group);
5411   theCommands.Add ("OCC11758", "OCC11758", __FILE__, OCC11758, group);
5412   theCommands.Add ("OCC24005", "OCC24005 result", __FILE__, OCC24005, group);
5413   theCommands.Add ("OCC24137", "OCC24137 face vertex U V [N]", __FILE__, OCC24137, group);
5414   theCommands.Add ("OCC24271", "Boolean operations on NCollection_Map", __FILE__, OCC24271, group);
5415   theCommands.Add ("OCC23972", "OCC23972", __FILE__, OCC23972, group);
5416   theCommands.Add ("OCC24370", "OCC24370 edge pcurve surface prec", __FILE__, OCC24370, group);
5417   theCommands.Add ("OCC24533", "OCC24533", __FILE__, OCC24533, group);
5418   theCommands.Add ("OCC24012", "OCC24012 face edge", __FILE__, OCC24012, group);
5419   theCommands.Add ("OCC24086", "OCC24086 face wire", __FILE__, OCC24086, group);
5420   theCommands.Add ("OCC24667", "OCC24667 result Wire_spine Profile [Mode [Approx]], no args to get help", __FILE__, OCC24667, group);
5421   theCommands.Add ("OCC24755", "OCC24755", __FILE__, OCC24755, group);
5422   theCommands.Add ("OCC24834", "OCC24834", __FILE__, OCC24834, group);
5423   theCommands.Add ("OCC24889", "OCC24889", __FILE__, OCC24889, group);
5424   theCommands.Add ("OCC23951", "OCC23951 path to saved step file", __FILE__, OCC23951, group);
5425   theCommands.Add ("OCC24931", "OCC24931 path to saved xml file", __FILE__, OCC24931, group);
5426   theCommands.Add ("OCC24945", "OCC24945", __FILE__, OCC24945, group);
5427   theCommands.Add ("OCC23950", "OCC23950 step_file", __FILE__, OCC23950, group);
5428   theCommands.Add ("OCC25004", "OCC25004", __FILE__, OCC25004, group);
5429   theCommands.Add ("OCC24925",
5430                    "OCC24925 filename [pluginLib=TKXml storageGuid retrievalGuid]"
5431                    "\nOCAF persistence without setting environment variables",
5432                    __FILE__, OCC24925, group);
5433   theCommands.Add ("OCC25043", "OCC25043 shape", __FILE__, OCC25043, group);
5434   theCommands.Add ("OCC24826,", "This test performs simple saxpy test.\n Usage: OCC24826 length", __FILE__, OCC24826, group);
5435   theCommands.Add ("OCC24606", "OCC24606 : Tests ::FitAll for V3d view ('vfit' is for NIS view)", __FILE__, OCC24606, group);
5436   theCommands.Add ("OCC25202", "OCC25202 res shape numF1 face1 numF2 face2", __FILE__, OCC25202, group);
5437   theCommands.Add ("OCC7570", "OCC7570 shape", __FILE__, OCC7570, group);
5438   theCommands.Add ("OCC25100", "OCC25100 shape", __FILE__, OCC25100, group);
5439   theCommands.Add ("OCC25340", "OCC25340", __FILE__, OCC25340, group);
5440   theCommands.Add ("OCC25348", "OCC25348", __FILE__, OCC25348, group);
5441   theCommands.Add ("OCC25413", "OCC25413 shape", __FILE__, OCC25413, group);
5442   theCommands.Add ("OCC25446", "OCC25446 res b1 b2 op", __FILE__, OCC25446, group);
5443   theCommands.Add ("OCC25545", 
5444                    "no args; tests data race when concurrently accessing \n"
5445                    "\t\tTopLoc_Location::Transformation()",
5446                    __FILE__, OCC25545, group);
5447   theCommands.Add ("OCC25547", "OCC25547", __FILE__, OCC25547, group);
5448   theCommands.Add ("OCC24881", "OCC24881 shape", __FILE__, OCC24881, group);
5449   theCommands.Add ("OCC26172", "OCC26172", __FILE__, OCC26172, group);
5450   theCommands.Add ("xprojponf", "xprojponf p f", __FILE__, xprojponf, group);
5451   theCommands.Add ("OCC24923", "OCC24923", __FILE__, OCC24923, group);
5452   theCommands.Add ("OCC26139", "OCC26139 [-boxsize value] [-boxgrid value] [-compgrid value]", __FILE__, OCC26139, group);
5453   theCommands.Add ("OCC26284", "OCC26284", __FILE__, OCC26284, group);
5454   theCommands.Add ("OCC26446", "OCC26446 r c1 c2", __FILE__, OCC26446, group);
5455   theCommands.Add ("OCC26448", "OCC26448: check method Prepend() of sequence", __FILE__, OCC26448, group);
5456   theCommands.Add ("OCC26407", "OCC26407 result_name", __FILE__, OCC26407, group);
5457   theCommands.Add ("OCC26485", "OCC26485 shape", __FILE__, OCC26485, group);
5458   theCommands.Add ("OCC26553", "OCC26553 file_path", __FILE__, OCC26553, group);
5459   theCommands.Add ("OCC26195",
5460                    "OCC26195: x1_pix y1_pix [x2_pix y2_pix] [toPrintPixelCoord 0|1]"
5461                    "\n\t\t: Draws rectangular selecting frustum defined by point selection in pixel coordinates"
5462                    "\n\t\t: [x1_pix, y1_pix] or rectangular selection in pixel coordinates [x1_pix, y1_pix,"
5463                    "\n\t\t: x2_pix, y2_pix]."
5464                    "\n\t\t: [toPrintPixelCoord 0|1] - prints 3d projection of pixel coordinate or center of"
5465                    "\n\t\t: selecting rectangle onto near and far view frustum planes",
5466                    __FILE__, OCC26195, group);
5467   theCommands.Add ("OCC26462",
5468                    "OCC26462: Checks the ability to manage sensitivity of a particular selection mode in local context",
5469                    __FILE__, OCC26462, group);
5470
5471   theCommands.Add ("OCC26313", "OCC26313 result shape", __FILE__, OCC26313, group);
5472   theCommands.Add ("OCC26396", "OCC26396 shape_file_path", __FILE__, OCC26396, group);
5473   theCommands.Add ("OCC26525", "OCC26525 result edge face ", __FILE__, OCC26525, group);
5474
5475   theCommands.Add ("OCC24537", "OCC24537 [file]", __FILE__, OCC24537, group);
5476   theCommands.Add ("OCC26750", "OCC26750", __FILE__, OCC26750, group);
5477   theCommands.Add ("OCC25574", "OCC25574", __FILE__, OCC25574, group);
5478   theCommands.Add ("OCC26746", "OCC26746 torus [toler NbCheckedPoints] ", __FILE__, OCC26746, group);
5479
5480   theCommands.Add ("BUC26658", "BUC26658 unexpected selection in the context using a selection filter", __FILE__, BUC26658, group);
5481   theCommands.Add ("OCC26945_open",
5482                    "OCC26945 selectionModeToActivate"
5483                    "\n\t\t: Opens a new local context with selectionModeToActivate activated."
5484                    "\n\t\t: Prints the ID of newely opened local context in case of success.",
5485                    __FILE__, OCC26945_open, group);
5486   theCommands.Add ("OCC26945_close",
5487                    "OCC26945 localCtxToClose"
5488                    "\n\t\t: Closes local context with the ID localCtxToClose",
5489                    __FILE__, OCC26945_close, group);
5490
5491   theCommands.Add ("OCC27048",
5492                    "OCC27048 surf U V N\nCalculate value of surface N times in the point (U, V)",
5493                    __FILE__, OCC27048, group);
5494   
5495   theCommands.Add ("OCC27065",
5496                    "OCC27065 spine profile",
5497                    __FILE__, OCC27065, group);
5498
5499   theCommands.Add ("OCC27318",
5500                    "OCC27318: Creates a box that is not listed in map of AIS objects of ViewerTest",
5501                    __FILE__, OCC27318, group);
5502   theCommands.Add ("OCC27523",
5503                    "OCC27523: Checks recomputation of deactivated selection mode after object's redisplaying",
5504                    __FILE__, OCC27523, group);
5505   theCommands.Add ("OCC27700",
5506                    "OCC27700: Checks drawing text after setting interior style",
5507                    __FILE__, OCC27700, group);
5508   theCommands.Add ("OCC27757",
5509                    "OCC27757: Creates a box that has a sphere as child object and displays it",
5510                    __FILE__, OCC27757, group);
5511   theCommands.Add ("OCC27818",
5512                    "OCC27818: Creates three boxes and highlights one of them with own style",
5513                    __FILE__, OCC27818, group);
5514   theCommands.Add ("OCC27893",
5515                    "OCC27893: Creates a box and selects it via AIS_InteractiveContext API",
5516                    __FILE__, OCC27893, group);
5517   theCommands.Add("OCC28310",
5518                   "OCC28310: Tests validness of iterator in AIS_InteractiveContext after an removing object from it",
5519                   __FILE__, OCC28310, group);
5520   theCommands.Add("OCC29412", "OCC29412 [nb cycles]: test display / remove of many small objects", __FILE__, OCC29412, group);
5521   return;
5522 }