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