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