0028908: Improvement on attachment of attributes to the label
[occt.git] / src / QABugs / QABugs_19.cxx
1 // Created on: 2002-05-21
2 // Created by: QA Admin
3 // Copyright (c) 2002-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <QABugs.hxx>
17
18 #include <AIS_InteractiveContext.hxx>
19 #include <AIS_LocalContext.hxx>
20 #include <AIS_Shape.hxx>
21 #include <BRepAlgoAPI_Cut.hxx>
22 #include <BRepOffsetAPI_MakePipe.hxx>
23 #include <BRepPrimAPI_MakeBox.hxx>
24 #include <BRepPrimAPI_MakeSphere.hxx>
25 #include <DBRep.hxx>
26 #include <Draw_Interpretor.hxx>
27 #include <DrawTrSurf.hxx>
28 #include <GCE2d_MakeSegment.hxx>
29 #include <Geom2d_TrimmedCurve.hxx>
30 #include <GeomFill_Trihedron.hxx>
31 #include <Graphic3d_ArrayOfTriangles.hxx>
32 #include <gp_Ax1.hxx>
33 #include <gp_Pnt2d.hxx>
34 #include <gp_Quaternion.hxx>
35 #include <Image_Color.hxx>
36 #include <Image_PixMap.hxx>
37 #include <NCollection_Handle.hxx>
38 #include <NCollection_IncAllocator.hxx>
39 #include <NCollection_Map.hxx>
40 #include <OSD_Parallel.hxx>
41 #include <OSD_PerfMeter.hxx>
42 #include <OSD_Timer.hxx>
43 #include <Precision.hxx>
44 #include <Prs3d_ShadingAspect.hxx>
45 #include <Prs3d_Text.hxx>
46 #include <SelectMgr_Filter.hxx>
47 #include <Standard_Version.hxx>
48 #include <StdSelect_BRepOwner.hxx>
49 #include <TCollection_HAsciiString.hxx>
50 #include <TopExp_Explorer.hxx>
51 #include <TopoDS_Shape.hxx>
52 #include <V3d_View.hxx>
53 #include <ViewerTest.hxx>
54 #include <XmlDrivers_DocumentRetrievalDriver.hxx>
55 #include <XmlDrivers_DocumentStorageDriver.hxx>
56 #include <TDataStd_Real.hxx>
57
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 //function : OCC23972
1538 //purpose  : 
1539 //=======================================================================
1540 static void DoGeomIntSSTest (const Handle(Geom_Surface)& theSurf1,
1541                              const Handle(Geom_Surface)& theSurf2,
1542                              const Standard_Integer theNbSol,
1543                              Draw_Interpretor& di)
1544 {
1545   try {
1546     OCC_CATCH_SIGNALS
1547          GeomInt_IntSS anInter;
1548          anInter.Perform (theSurf1, theSurf2, Precision::Confusion(), Standard_True);
1549          QVERIFY (anInter.IsDone());
1550          QCOMPARE (anInter.NbLines(), theNbSol);
1551   } catch (...) {
1552     QVERIFY (Standard_False);
1553   }
1554 }
1555
1556 namespace {
1557   static Handle(Geom_ConicalSurface) CreateCone (const gp_Pnt& theLoc,
1558                                                  const gp_Dir& theDir,
1559                                                  const gp_Dir& theXDir,
1560                                                  const Standard_Real theRad,
1561                                                  const Standard_Real theSin,
1562                                                  const Standard_Real theCos)
1563   {
1564     const Standard_Real anA = atan (theSin / theCos);
1565     gp_Ax3 anAxis (theLoc, theDir, theXDir);
1566     Handle(Geom_ConicalSurface) aSurf = new Geom_ConicalSurface (anAxis, anA, theRad);
1567     return aSurf;
1568   }
1569 }
1570
1571 static Standard_Integer OCC23972 (Draw_Interpretor& di,Standard_Integer n, const char**)
1572 {
1573   if (n != 1) return 1;
1574
1575   //process specific cones, cannot read them from files because due to rounding the original error
1576   //in math_FunctionRoots gets hidden
1577   Handle(Geom_Surface) aS1 = CreateCone (
1578                                          gp_Pnt (123.694345356663, 789.9, 68.15),
1579                                          gp_Dir (-1, 3.48029791472957e-016, -8.41302743359754e-017),
1580                                          gp_Dir (-3.48029791472957e-016, -1, -3.17572289932207e-016),
1581                                          3.28206830417112,
1582                                          0.780868809443031,
1583                                          0.624695047554424);
1584   Handle(Geom_Surface) aS2 = CreateCone (
1585                                          gp_Pnt (123.694345356663, 784.9, 68.15),
1586                                          gp_Dir (-1, -2.5209507537117e-016, -1.49772808948866e-016),
1587                                          gp_Dir (1.49772808948866e-016, 3.17572289932207e-016, -1),
1588                                          3.28206830417112,
1589                                          0.780868809443031,
1590                                          0.624695047554424);
1591   
1592   DoGeomIntSSTest (aS1, aS2, 2, di);
1593
1594   return 0;
1595 }
1596
1597 #include <ShapeFix_EdgeProjAux.hxx>
1598 static Standard_Integer OCC24370 (Draw_Interpretor& di, Standard_Integer argc,const char ** argv)
1599 {
1600   if (argc < 5) {
1601     di<<"Usage: " << argv[0] << " invalid number of arguments\n";
1602     return 1;
1603   }
1604
1605   TopoDS_Shape aSh = DBRep::Get(argv[1]);
1606   if (aSh.IsNull()) {
1607     di << argv[0] << " Error: Null input edge\n";
1608     return 1;
1609   }
1610   const TopoDS_Edge& anEdge = TopoDS::Edge (aSh);
1611
1612   Handle(Geom2d_Curve) aC = DrawTrSurf::GetCurve2d(argv[2]);
1613   if (aC.IsNull()) {
1614     di << argv[0] << " Error: Null input curve\n";
1615     return 1;
1616   }
1617
1618   Handle(Geom_Surface) aS = DrawTrSurf::GetSurface(argv[3]);
1619   if (aS.IsNull()) {
1620     di << argv[0] << " Error: Null input surface\n";
1621     return 1;
1622   }
1623
1624   Standard_Real prec = Draw::Atof(argv[4]);
1625   
1626   //prepare data
1627   TopoDS_Face aFace;
1628   BRep_Builder aB;
1629   aB.MakeFace (aFace, aS, Precision::Confusion());
1630   aB.UpdateEdge (anEdge, aC, aFace, Precision::Confusion());
1631   aB.Range (anEdge, aFace, aC->FirstParameter(), aC->LastParameter());
1632
1633   //call algorithm
1634   ShapeFix_EdgeProjAux aProj (aFace, anEdge);
1635   aProj.Compute (prec);
1636   
1637   Standard_Boolean isfirstdone = aProj.IsFirstDone();
1638   Standard_Boolean islastdone = aProj.IsLastDone();
1639
1640   Standard_Real first = 0.;
1641   Standard_Real last = 0.;
1642   Standard_Integer isfirstdoneInteger = 0;
1643   Standard_Integer islastdoneInteger = 0;
1644
1645
1646   if (isfirstdone) {
1647     first = aProj.FirstParam();
1648     isfirstdoneInteger = 1;
1649   }
1650  
1651   if (islastdone) {
1652     last= aProj.LastParam();
1653     islastdoneInteger = 1;
1654   }
1655
1656   di << isfirstdoneInteger << " "<< islastdoneInteger << " "<< first << " "<< last << " \n";
1657
1658   return 0;
1659 }
1660
1661 template<typename T, typename HT>
1662 static void DoIsNull(Draw_Interpretor& di)
1663 {
1664   HT aHandle;
1665   //    QVERIFY (aHandle.IsNull());
1666   QCOMPARE (aHandle.IsNull(), Standard_True);
1667   const T* p = aHandle.get();
1668 #if OCC_VERSION_HEX > 0x060700
1669   //QVERIFY (!p);
1670   //QVERIFY (p == 0);
1671   QCOMPARE (!p, Standard_True);
1672   QCOMPARE (p == 0, Standard_True);
1673 #endif
1674
1675   aHandle = new T;
1676   //QVERIFY (!aHandle.IsNull());
1677   QCOMPARE (!aHandle.IsNull(), Standard_True);
1678   p = aHandle.get();
1679   //QVERIFY (p);
1680   //QVERIFY (p != 0);
1681   QCOMPARE (p != NULL, Standard_True);
1682   QCOMPARE (p != 0, Standard_True);
1683 }
1684
1685 //=======================================================================
1686 //function : OCC24533
1687 //purpose  : 
1688 //=======================================================================
1689 static Standard_Integer OCC24533 (Draw_Interpretor& di, Standard_Integer n, const char**)
1690 {
1691   if (n != 1) return 1;
1692
1693   DoIsNull<Standard_Transient, Handle(Standard_Transient)>(di);
1694
1695   return 0;
1696 }
1697
1698 // Dummy class to test interface for compilation issues
1699 class QABugs_HandleClass : public Standard_Transient
1700 {
1701 public:
1702   Standard_Integer HandleProc (Draw_Interpretor& , Standard_Integer  , const char** theArgVec)
1703   {
1704     std::cerr << "QABugs_HandleClass[" << this << "] " << theArgVec[0] << "\n";
1705     return 0;
1706   }
1707   DEFINE_STANDARD_RTTI_INLINE(QABugs_HandleClass,Standard_Transient) // Type definition
1708 };
1709 DEFINE_STANDARD_HANDLE    (QABugs_HandleClass, Standard_Transient)
1710
1711
1712 // Dummy class to test interface for compilation issues
1713 struct QABugs_NHandleClass
1714 {
1715   Standard_Integer NHandleProc (Draw_Interpretor& , Standard_Integer  , const char** theArgVec)
1716   {
1717     std::cerr << "QABugs_NHandleClass[" << this << "] " << theArgVec[0] << "\n";
1718     return 0;
1719   }
1720 };
1721
1722 #include <XCAFDoc_ColorTool.hxx>
1723 #include <STEPControl_StepModelType.hxx>
1724 #include <STEPCAFControl_Writer.hxx>
1725 static Standard_Integer OCC23951 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1726 {
1727   if (argc != 2) {
1728     di << "Usage: " << argv[0] << " invalid number of arguments\n";
1729     return 1;
1730   }
1731   Handle(TDocStd_Document) aDoc = new TDocStd_Document("dummy");;
1732   TopoDS_Shape s1 = BRepPrimAPI_MakeBox(1,1,1).Shape();
1733   TDF_Label lab1 = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main ())->NewShape();
1734   XCAFDoc_DocumentTool::ShapeTool (aDoc->Main ())->SetShape(lab1, s1);
1735   TDataStd_Name::Set(lab1, "Box1");
1736         
1737   Quantity_Color yellow(1,1,0, Quantity_TOC_RGB);
1738   XCAFDoc_DocumentTool::ColorTool (aDoc->Main())->SetColor(lab1, yellow, XCAFDoc_ColorGen);
1739   XCAFDoc_DocumentTool::ColorTool(aDoc->Main())->SetVisibility(lab1, 0);
1740
1741   STEPControl_StepModelType mode = STEPControl_AsIs;
1742   STEPCAFControl_Writer writer;
1743   if ( ! writer.Transfer (aDoc, mode ) )
1744   {
1745     di << "The document cannot be translated or gives no result"  <<  "\n";
1746     return 1;
1747   }
1748
1749   writer.Write(argv[1]);
1750   return 0;
1751 }
1752
1753
1754 //=======================================================================
1755 //function : OCC23950
1756 //purpose  :
1757 //=======================================================================
1758 static Standard_Integer OCC23950 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1759 {
1760   if (argc != 2) {
1761     di << "Usage : " << argv[0] << " step_file\n";
1762     return 1;
1763   }
1764
1765   Handle(TDocStd_Document) aDoc = new TDocStd_Document ("dummy");
1766   TopoDS_Shape s6 = BRepBuilderAPI_MakeVertex (gp_Pnt (75, 0, 0));
1767   gp_Trsf t0;
1768   TopLoc_Location location0 (t0);
1769
1770   TDF_Label lab1 = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main ())->NewShape ();
1771   XCAFDoc_DocumentTool::ShapeTool (aDoc->Main ())->SetShape (lab1, s6);
1772   TDataStd_Name::Set(lab1, "Point1");
1773
1774   TDF_Label labelA0 = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main ())->NewShape ();
1775   TDataStd_Name::Set(labelA0, "ASSEMBLY");
1776
1777   TDF_Label component01 = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main ())->AddComponent (labelA0, lab1, location0);
1778   XCAFDoc_DocumentTool::ShapeTool (aDoc->Main ())->UpdateAssemblies();
1779
1780   Quantity_Color yellow(1,1,0, Quantity_TOC_RGB);
1781   XCAFDoc_DocumentTool::ColorTool (labelA0)->SetColor (component01, yellow, XCAFDoc_ColorGen);
1782   XCAFDoc_DocumentTool::ColorTool (labelA0)->SetVisibility (component01, 0);
1783
1784   STEPControl_StepModelType mode = STEPControl_AsIs;
1785   STEPCAFControl_Writer writer;
1786   if (! writer.Transfer (aDoc, mode))
1787   {
1788     di << "The document cannot be translated or gives no result\n";
1789     return 1;
1790   }
1791
1792   writer.Write (argv[1]);
1793   return 0;
1794 }
1795
1796 //=======================================================================
1797 //function : OCC24667
1798 //purpose  : 
1799 //=======================================================================
1800 static Standard_Integer OCC24667 (Draw_Interpretor& di, Standard_Integer n, const char** a)
1801 {
1802   if (n == 1)
1803   {
1804     di << "OCC24667 result Wire_spine Profile [Mode [Approx]]\n";
1805     di << "Mode = 0 - CorrectedFrenet,\n";
1806     di << "     = 1 - Frenet,\n";
1807     di << "     = 2 - DiscreteTrihedron\n";
1808     di << "Approx - force C1-approximation if result is C0\n";
1809     return 0;
1810   }
1811
1812   if (n > 1 && n < 4) return 1;
1813
1814   TopoDS_Shape Spine = DBRep::Get(a[2],TopAbs_WIRE);
1815   if ( Spine.IsNull()) return 1;
1816
1817   TopoDS_Shape Profile = DBRep::Get(a[3]);
1818   if ( Profile.IsNull()) return 1;
1819
1820   GeomFill_Trihedron Mode = GeomFill_IsCorrectedFrenet;
1821   if (n >= 5)
1822   {
1823     Standard_Integer iMode = atoi(a[4]);
1824     if (iMode == 1)
1825       Mode = GeomFill_IsFrenet;
1826     else if (iMode == 2)
1827       Mode = GeomFill_IsDiscreteTrihedron;
1828   }
1829
1830   Standard_Boolean ForceApproxC1 = Standard_False;
1831   if (n >= 6)
1832     ForceApproxC1 = Standard_True;
1833
1834   BRepOffsetAPI_MakePipe aPipe(TopoDS::Wire(Spine),
1835                                           Profile,
1836                                           Mode,
1837                                           ForceApproxC1);
1838
1839   TopoDS_Shape S = aPipe.Shape();
1840   TopoDS_Shape aSF = aPipe.FirstShape();
1841   TopoDS_Shape aSL = aPipe.LastShape();
1842
1843   DBRep::Set(a[1],S);
1844
1845   TCollection_AsciiString aStrF(a[1], "_f");
1846   TCollection_AsciiString aStrL(a[1], "_l");
1847
1848   DBRep::Set(aStrF.ToCString(), aSF);
1849   DBRep::Set(aStrL.ToCString(), aSL);
1850
1851   return 0;
1852 }
1853
1854 #include <BRepPrimAPI_MakeCylinder.hxx>
1855 #include <BRepBuilderAPI_Copy.hxx>
1856 #include <BRepTools_NurbsConvertModification.hxx>
1857 static TopoDS_Shape CreateTestShape (int& theShapeNb)
1858 {
1859   TopoDS_Compound aComp;
1860   BRep_Builder aBuilder;
1861   aBuilder.MakeCompound (aComp);
1862   //NURBS modifier is used to increase footprint of each shape
1863   Handle(BRepTools_NurbsConvertModification) aNurbsModif = new BRepTools_NurbsConvertModification;
1864   TopoDS_Shape aRefShape = BRepPrimAPI_MakeCylinder (50., 100.).Solid();
1865   BRepTools_Modifier aModifier (aRefShape, aNurbsModif);
1866   if (aModifier.IsDone()) {
1867     aRefShape = aModifier.ModifiedShape (aRefShape);
1868   }
1869   int aSiblingNb = 0;
1870   for (; theShapeNb > 0; --theShapeNb) {
1871     TopoDS_Shape aShape;
1872     if (++aSiblingNb <= 100) { //number of siblings is limited to avoid long lists
1873                 aShape = BRepBuilderAPI_Copy (aRefShape, Standard_True /*CopyGeom*/).Shape();
1874     } else {
1875       aShape = CreateTestShape (theShapeNb);
1876     }
1877     aBuilder.Add (aComp, aShape);
1878   }
1879   return aComp;
1880 }
1881
1882 #include <TDataStd_Integer.hxx>
1883 #include <TNaming_Builder.hxx>
1884 static Standard_Integer OCC24931 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1885 {
1886   if (argc != 2) {
1887     di << "Usage: " << argv[0] << " invalid number of arguments\n";
1888     return 1;
1889   }
1890   TCollection_ExtendedString aFileName (argv[1]);
1891   PCDM_StoreStatus aSStatus  = PCDM_SS_Failure;
1892
1893   Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
1894   {
1895     Handle(TDocStd_Document) aDoc;
1896     anApp->NewDocument ("XmlOcaf", aDoc);
1897     TDF_Label aLab = aDoc->Main();
1898     TDataStd_Integer::Set (aLab, 0);
1899     int n = 10000; //must be big enough
1900     TopoDS_Shape aShape = CreateTestShape (n);
1901     TNaming_Builder aBuilder (aLab);
1902     aBuilder.Generated (aShape);
1903
1904     aSStatus = anApp->SaveAs (aDoc, aFileName);
1905     anApp->Close (aDoc);
1906   }
1907   QCOMPARE (aSStatus, PCDM_SS_OK);
1908   return 0;
1909 }
1910
1911 #include <TDF_AttributeIterator.hxx>
1912 //=======================================================================
1913 //function : OCC24755
1914 //purpose  : 
1915 //=======================================================================
1916 static Standard_Integer OCC24755 (Draw_Interpretor& di, Standard_Integer n, const char** a)
1917 {
1918   if (n != 1)
1919   {
1920     std::cout << "Usage : " << a[0] << "\n";
1921     return 1;
1922   }
1923
1924   Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
1925   Handle(TDocStd_Document) aDoc;
1926   anApp->NewDocument ("BinOcaf", aDoc);
1927   TDF_Label aLab = aDoc->Main();
1928   // Prepend an int value.
1929   TDataStd_Integer::Set (aLab, 0);
1930   // Prepend a name.
1931   TDataStd_Name::Set (aLab, "test");
1932   // Append a double value.
1933   aLab.AddAttribute(new TDataStd_Real(), true/*append*/);
1934
1935   TDF_AttributeIterator i (aLab);
1936   Handle(TDF_Attribute) anAttr = i.Value();
1937   QCOMPARE (anAttr->IsKind (STANDARD_TYPE (TDataStd_Name)), Standard_True);
1938   i.Next();
1939   anAttr = i.Value();
1940   QCOMPARE (anAttr->IsKind (STANDARD_TYPE (TDataStd_Integer)), Standard_True);
1941   i.Next();
1942   anAttr = i.Value();
1943   QCOMPARE (anAttr->IsKind (STANDARD_TYPE (TDataStd_Real)), Standard_True);
1944
1945   return 0;
1946 }
1947
1948 struct MyStubObject
1949 {
1950   MyStubObject() : ptr(0L) {}
1951   MyStubObject(void* thePtr) : ptr(thePtr) {}
1952   char overhead[40];
1953   void* ptr;
1954 };
1955
1956 //=======================================================================
1957 //function : OCC24834
1958 //purpose  : 
1959 //=======================================================================
1960 static Standard_Integer OCC24834 (Draw_Interpretor& di, Standard_Integer n, const char** a)
1961 {
1962   if (n != 1)
1963   {
1964     std::cout << "Usage : " << a[0] << "\n";
1965     return 1;
1966   }
1967
1968   int i = sizeof (char*);  
1969   if (i > 4) {
1970     std::cout << "64-bit architecture is not supported.\n";
1971     return 0;
1972   }
1973
1974   NCollection_List<MyStubObject> aList;
1975   const Standard_Integer aSmallBlockSize = 40;
1976   const Standard_Integer aLargeBlockSize = 1500000;
1977
1978   // quick populate memory with large blocks
1979   try
1980   {
1981     for (;;)
1982     {
1983       aList.Append(MyStubObject(Standard::Allocate(aLargeBlockSize)));
1984     }
1985   }
1986   catch (Standard_Failure)
1987   {
1988     di << "caught out of memory for large blocks: OK\n";
1989   }
1990   catch (...)
1991   {
1992     di << "skept out of memory for large blocks: Error\n";
1993   }
1994
1995   // allocate small blocks
1996   try
1997   {
1998     for (;;)
1999     {
2000       aList.Append(MyStubObject(Standard::Allocate(aSmallBlockSize)));
2001     }
2002   }
2003   catch (Standard_Failure)
2004   {
2005     di << "caught out of memory for small blocks: OK\n";
2006   }
2007   catch (...)
2008   {
2009     di << "skept out of memory for small blocks: Error\n";
2010   }
2011
2012   // release all allocated blocks
2013   for (NCollection_List<MyStubObject>::Iterator it(aList); it.More(); it.Next())
2014   {
2015     Standard::Free(it.Value().ptr);
2016   }
2017   return 0;
2018 }
2019
2020
2021 #include <Geom2dAPI_InterCurveCurve.hxx>
2022 #include <IntRes2d_IntersectionPoint.hxx>
2023 //=======================================================================
2024 //function : OCC24889
2025 //purpose  : 
2026 //=======================================================================
2027 static Standard_Integer OCC24889 (Draw_Interpretor& theDI,
2028                                   Standard_Integer /*theNArg*/,
2029                                   const char** /*theArgs*/)
2030 {
2031  // Curves
2032   Handle( Geom2d_Circle ) aCircle1 = new Geom2d_Circle(
2033     gp_Ax22d( gp_Pnt2d( 25, -25 ), gp_Dir2d( 1, 0 ), gp_Dir2d( -0, 1 ) ), 155 );
2034
2035   Handle( Geom2d_Circle ) aCircle2 = new Geom2d_Circle(
2036     gp_Ax22d( gp_Pnt2d( 25, 25 ), gp_Dir2d( 1, 0 ), gp_Dir2d( -0, 1 ) ), 155 );
2037
2038   Handle( Geom2d_TrimmedCurve ) aTrim[2] = {
2039     new Geom2d_TrimmedCurve( aCircle1, 1.57079632679490, 2.97959469729228 ),
2040     new Geom2d_TrimmedCurve( aCircle2, 3.30359060633978, 4.71238898038469 )
2041   };
2042
2043   DrawTrSurf::Set("c_1", aTrim[0]);
2044   DrawTrSurf::Set("c_2", aTrim[1]);
2045
2046   // Intersection
2047   const Standard_Real aTol = Precision::Confusion();
2048   Geom2dAPI_InterCurveCurve aIntTool( aTrim[0], aTrim[1], aTol );
2049
2050   const IntRes2d_IntersectionPoint& aIntPnt =
2051     aIntTool.Intersector().Point( 1 );
2052
2053   gp_Pnt2d aIntRes = aIntTool.Point( 1 );
2054   Standard_Real aPar[2] = {
2055     aIntPnt.ParamOnFirst(),
2056     aIntPnt.ParamOnSecond()
2057   };
2058
2059   //theDI.precision( 5 );
2060   theDI << "Int point: X = " << aIntRes.X() << "; Y = " << aIntRes.Y() << "\n";
2061   for (int i = 0; i < 2; ++i)
2062   {
2063     theDI << "Curve " << i << ": FirstParam = " << aTrim[i]->FirstParameter() <<
2064       "; LastParam = " << aTrim[i]->LastParameter() <<
2065       "; IntParameter = " << aPar[i] << "\n";
2066   }
2067
2068   return 0;
2069 }
2070
2071 #include <math_GlobOptMin.hxx>
2072 #include <math_MultipleVarFunctionWithHessian.hxx>
2073 //=======================================================================
2074 //function : OCC25004
2075 //purpose  : Check extremaCC on Branin function.
2076 //=======================================================================
2077 // Function is:
2078 // f(u,v) = a*(v - b*u^2 + c*u-r)^2+s(1-t)*cos(u)+s
2079 // Standard borders are:
2080 // -5 <= u <= 10
2081 //  0 <= v <= 15
2082 class BraninFunction : public math_MultipleVarFunctionWithHessian
2083 {
2084 public:
2085   BraninFunction()
2086   {
2087     a = 1.0;
2088     b = 5.1 / (4.0 * M_PI * M_PI);
2089     c = 5.0 / M_PI;
2090     r = 6.0;
2091     s = 10.0;
2092     t = 1.0 / (8.0 *  M_PI);
2093   }
2094   virtual Standard_Integer NbVariables() const
2095   {
2096     return 2;
2097   }
2098   virtual Standard_Boolean Value(const math_Vector& X,Standard_Real& F)
2099   {
2100     Standard_Real u = X(1);
2101     Standard_Real v = X(2);
2102
2103     Standard_Real aSqPt = (v - b * u * u + c * u - r); // Square Part of function.
2104     Standard_Real aLnPt = s * (1 - t) * cos(u); // Linear part of funcrtion.
2105     F = a * aSqPt * aSqPt + aLnPt + s;
2106     return Standard_True;
2107   }
2108   virtual Standard_Boolean Gradient(const math_Vector& X,math_Vector& G)
2109   {
2110     Standard_Real u = X(1);
2111     Standard_Real v = X(2);
2112
2113     Standard_Real aSqPt = (v - b * u * u + c * u - r); // Square Part of function.
2114     G(1) = 2 * a * aSqPt * (c - 2 * b * u) - s * (1 - t) * sin(u);
2115     G(2) = 2 * a * aSqPt;
2116
2117     return Standard_True;
2118   }
2119   virtual Standard_Boolean Values(const math_Vector& X,Standard_Real& F,math_Vector& G)
2120   {
2121     Value(X,F);
2122     Gradient(X,G);
2123
2124     return Standard_True;
2125   }
2126   virtual Standard_Boolean Values(const math_Vector& X,Standard_Real& F,math_Vector& G,math_Matrix& H)
2127   {
2128     Value(X,F);
2129     Gradient(X,G);
2130
2131     Standard_Real u = X(1);
2132     Standard_Real v = X(2);
2133
2134     Standard_Real aSqPt = (v - b * u * u + c * u - r); // Square Part of function.
2135     Standard_Real aTmpPt = c - 2 * b *u; // Tmp part.
2136     H(1,1) = 2 * a * aTmpPt * aTmpPt - 4 * a * b * aSqPt - s * (1 - t) * cos(u);
2137     H(1,2) = 2 * a * aTmpPt;
2138     H(2,1) = H(1,2);
2139     H(2,2) = 2 * a;
2140
2141     return Standard_True;
2142   }
2143
2144 private:
2145   // Standard parameters.
2146   Standard_Real a, b, c, r, s, t;
2147 };
2148
2149 static Standard_Integer OCC25004 (Draw_Interpretor& theDI,
2150                                   Standard_Integer /*theNArg*/,
2151                                   const char** /*theArgs*/)
2152 {
2153   BraninFunction aFunc;
2154
2155   math_Vector aLower(1,2), aUpper(1,2);
2156   aLower(1) = -5;
2157   aLower(2) =  0;
2158   aUpper(1) = 10;
2159   aUpper(2) = 15;
2160
2161   Standard_Integer aGridOrder = 16;
2162   math_Vector aFuncValues(1, aGridOrder * aGridOrder);
2163
2164   Standard_Real aLipConst = 0;
2165   math_Vector aCurrPnt1(1, 2), aCurrPnt2(1, 2);
2166
2167   // Get Lipshitz constant estimation on regular grid.
2168   Standard_Integer i, j, idx = 1;
2169   for(i = 1; i <= aGridOrder; i++)
2170   {
2171     for(j = 1; j <= aGridOrder; j++)
2172     {
2173       aCurrPnt1(1) = aLower(1) + (aUpper(1) - aLower(1)) * (i - 1) / (aGridOrder - 1.0);
2174       aCurrPnt1(2) = aLower(2) + (aUpper(2) - aLower(2)) * (j - 1) / (aGridOrder - 1.0);
2175
2176       aFunc.Value(aCurrPnt1, aFuncValues(idx));
2177       idx++;
2178     }
2179   }
2180
2181   Standard_Integer k, l;
2182   Standard_Integer idx1, idx2;
2183   for(i = 1; i <= aGridOrder; i++)
2184   for(j = 1; j <= aGridOrder; j++)
2185   for(k = 1; k <= aGridOrder; k++)
2186   for(l = 1; l <= aGridOrder; l++)
2187     {
2188       if (i == k && j == l) 
2189         continue;
2190
2191       aCurrPnt1(1) = aLower(1) + (aUpper(1) - aLower(1)) * (i - 1) / (aGridOrder - 1.0);
2192       aCurrPnt1(2) = aLower(2) + (aUpper(2) - aLower(2)) * (j - 1) / (aGridOrder - 1.0);
2193       idx1 = (i - 1) * aGridOrder + j;
2194
2195       aCurrPnt2(1) = aLower(1) + (aUpper(1) - aLower(1)) * (k - 1) / (aGridOrder - 1.0);
2196       aCurrPnt2(2) = aLower(2) + (aUpper(2) - aLower(2)) * (l - 1) / (aGridOrder - 1.0);
2197       idx2 = (k - 1) * aGridOrder + l;
2198
2199       aCurrPnt1.Add(-aCurrPnt2);
2200       Standard_Real dist = aCurrPnt1.Norm();
2201
2202       Standard_Real C = Abs(aFuncValues(idx1) - aFuncValues(idx2)) / dist;
2203       if (C > aLipConst)
2204         aLipConst = C;
2205     }
2206
2207   math_GlobOptMin aFinder(&aFunc, aLower, aUpper, aLipConst);
2208   aFinder.Perform();
2209   //(-pi , 12.275), (pi , 2.275), (9.42478, 2.475)
2210
2211   Standard_Real anExtValue = aFinder.GetF();
2212   theDI << "F = " << anExtValue << "\n";
2213
2214   Standard_Integer aNbExt = aFinder.NbExtrema();
2215   theDI << "NbExtrema = " << aNbExt << "\n";
2216
2217   return 0;
2218 }
2219
2220 #include <OSD_Environment.hxx>
2221 #include <Plugin.hxx>
2222 #include <Plugin_Macro.hxx>
2223 #include <Resource_Manager.hxx>
2224
2225 #define THE_QATEST_DOC_FORMAT       "My Proprietary Format"
2226
2227 #define QA_CHECK(theDesc, theExpr, theValue) \
2228 {\
2229   const bool isTrue = !!(theExpr); \
2230   std::cout << theDesc << (isTrue ? " TRUE  " : " FALSE ") << (isTrue == theValue ? " is OK\n" : " is FAIL\n"); \
2231 }
2232
2233 class Test_TDocStd_Application : public TDocStd_Application
2234 {
2235 public:
2236
2237   Test_TDocStd_Application ()
2238   {
2239     // explicitly initialize resource manager
2240     myResources = new Resource_Manager ("");
2241     myResources->SetResource ("xml.FileFormat", THE_QATEST_DOC_FORMAT);
2242     myResources->SetResource (THE_QATEST_DOC_FORMAT ".Description",     "Test XML Document");
2243     myResources->SetResource (THE_QATEST_DOC_FORMAT ".FileExtension",   "xml");
2244   }
2245
2246   virtual Handle(PCDM_Reader) ReaderFromFormat (const TCollection_ExtendedString&) Standard_OVERRIDE
2247   {
2248     return new XmlDrivers_DocumentRetrievalDriver ();
2249   }
2250   virtual Handle(PCDM_StorageDriver) WriterFromFormat (const TCollection_ExtendedString&) Standard_OVERRIDE
2251   {
2252     return new XmlDrivers_DocumentStorageDriver ("Test");
2253   }
2254   virtual Standard_CString ResourcesName() Standard_OVERRIDE { return ""; }
2255 };
2256
2257 //=======================================================================
2258 //function : OCC24925
2259 //purpose  :
2260 //=======================================================================
2261 static Standard_Integer OCC24925 (Draw_Interpretor& theDI,
2262                                   Standard_Integer  theArgNb,
2263                                   const char**      theArgVec)
2264 {
2265   if (theArgNb != 2
2266    && theArgNb != 5)
2267   {
2268     std::cout << "Error: wrong syntax! See usage:\n";
2269     theDI.PrintHelp (theArgVec[0]);
2270     return 1;
2271   }
2272
2273   Standard_Integer anArgIter = 1;
2274   TCollection_ExtendedString aFileName = theArgVec[anArgIter++];
2275   TCollection_AsciiString    aPlugin   = "TKXml";
2276   TCollection_AsciiString    aSaver    = "03a56820-8269-11d5-aab2-0050044b1af1"; // XmlStorageDriver   in XmlDrivers.cxx
2277   TCollection_AsciiString    aLoader   = "03a56822-8269-11d5-aab2-0050044b1af1"; // XmlRetrievalDriver in XmlDrivers.cxx
2278   if (anArgIter < theArgNb)
2279   {
2280     aPlugin = theArgVec[anArgIter++];
2281     aSaver  = theArgVec[anArgIter++];
2282     aLoader = theArgVec[anArgIter++];
2283   }
2284
2285   PCDM_StoreStatus  aSStatus = PCDM_SS_Failure;
2286   PCDM_ReaderStatus aRStatus = PCDM_RS_OpenError;
2287
2288   Handle(TDocStd_Application) anApp = new Test_TDocStd_Application ();
2289   {
2290     Handle(TDocStd_Document) aDoc;
2291     anApp->NewDocument (THE_QATEST_DOC_FORMAT, aDoc);
2292     TDF_Label aLab = aDoc->Main();
2293     TDataStd_Integer::Set (aLab, 0);
2294     TDataStd_Name::Set (aLab, "QABugs_19.cxx");
2295
2296     aSStatus = anApp->SaveAs (aDoc, aFileName);
2297     anApp->Close (aDoc);
2298   }
2299   QA_CHECK ("SaveAs()", aSStatus == PCDM_SS_OK, true);
2300
2301   {
2302     Handle(TDocStd_Document) aDoc;
2303     aRStatus = anApp->Open (aFileName, aDoc);
2304     anApp->Close (aDoc);
2305   }
2306   QA_CHECK ("Open()  ", aRStatus == PCDM_RS_OK, true);
2307   return 0;
2308 }
2309
2310 //=======================================================================
2311 //function : OCC25043
2312 //purpose  :
2313 //=======================================================================
2314 #include <BRepAlgoAPI_Check.hxx>
2315 static Standard_Integer OCC25043 (Draw_Interpretor& theDI,
2316                                   Standard_Integer  theArgNb,
2317                                   const char**      theArgVec)
2318 {
2319   if (theArgNb != 2) {
2320     theDI << "Usage: " << theArgVec[0] << " shape\n";
2321     return 1;
2322   }
2323   
2324   TopoDS_Shape aShape = DBRep::Get(theArgVec[1]);
2325   if (aShape.IsNull()) 
2326   {
2327     theDI << theArgVec[1] << " shape is NULL\n";
2328     return 1;
2329   }
2330   
2331   BRepAlgoAPI_Check  anAlgoApiCheck(aShape, Standard_True, Standard_True);
2332
2333   if (!anAlgoApiCheck.IsValid())
2334   {
2335     BOPAlgo_ListIteratorOfListOfCheckResult anCheckIter(anAlgoApiCheck.Result());
2336     for (; anCheckIter.More(); anCheckIter.Next())
2337     {
2338       const BOPAlgo_CheckResult& aCurCheckRes = anCheckIter.Value();
2339       const BOPCol_ListOfShape& aCurFaultyShapes = aCurCheckRes.GetFaultyShapes1();
2340       BOPCol_ListIteratorOfListOfShape aFaultyIter(aCurFaultyShapes);
2341       for (; aFaultyIter.More(); aFaultyIter.Next())
2342       {
2343         const TopoDS_Shape& aFaultyShape = aFaultyIter.Value();
2344         
2345         Standard_Boolean anIsFaultyShapeFound = Standard_False;
2346         TopExp_Explorer anExp(aShape, aFaultyShape.ShapeType());
2347         for (; anExp.More() && !anIsFaultyShapeFound; anExp.Next())
2348         {
2349           if (anExp.Current().IsEqual(aFaultyShape))
2350             anIsFaultyShapeFound = Standard_True;
2351         }
2352         
2353         if (!anIsFaultyShapeFound)
2354         {
2355           theDI << "Error. Faulty Shape is NOT found in source shape.\n";
2356           return 0;
2357         }
2358         else 
2359         {
2360           theDI << "Info. Faulty shape is found in source shape\n";
2361         }
2362       }
2363     }
2364   }
2365   else 
2366   {
2367     theDI << "Problems are not detected. Test is not performed.";
2368   }
2369
2370   return 0;
2371 }
2372
2373 //=======================================================================
2374 //function : OCC24606
2375 //purpose  :
2376 //=======================================================================
2377 static Standard_Integer OCC24606 (Draw_Interpretor& theDI,
2378                                   Standard_Integer  theArgNb,
2379                                   const char**      theArgVec)
2380 {
2381   if (theArgNb > 1)
2382   {
2383     std::cerr << "Error: incorrect number of arguments.\n";
2384     theDI << "Usage : " << theArgVec[0] << "\n";
2385     return 1;
2386   }
2387
2388   Handle(V3d_View) aView = ViewerTest::CurrentView();
2389   if (aView.IsNull())
2390   {
2391     std::cerr << "Errro: no active view, please call 'vinit'.\n";
2392     return 1;
2393   }
2394
2395   aView->DepthFitAll();
2396   aView->FitAll();
2397
2398   return 0;
2399 }
2400
2401 //=======================================================================
2402 //function : OCC25202
2403 //purpose  :
2404 //=======================================================================
2405 #include <ShapeBuild_ReShape.hxx>
2406 static Standard_Integer OCC25202 ( Draw_Interpretor& theDI,
2407                                    Standard_Integer theArgN,
2408                                    const char** theArgVal)
2409 {
2410   //  0      1    2     3     4     5     6 
2411   //reshape res shape numF1 face1 numF2 face2
2412   if(theArgN < 7)
2413     {
2414       theDI << "Use: reshape res shape numF1 face1 numF2 face2\n";
2415       return 1;
2416     }
2417
2418   TopoDS_Shape aShape = DBRep::Get(theArgVal[2]);
2419   const Standard_Integer  aNumOfRE1 = Draw::Atoi(theArgVal[3]),
2420                           aNumOfRE2 = Draw::Atoi(theArgVal[5]);
2421   TopoDS_Face aShapeForRepl1 = TopoDS::Face(DBRep::Get(theArgVal[4])),
2422               aShapeForRepl2 = TopoDS::Face(DBRep::Get(theArgVal[6]));
2423
2424   if(aShape.IsNull())
2425   {
2426     theDI << theArgVal[2] << " is null shape\n";
2427     return 1;
2428   }
2429
2430   if(aShapeForRepl1.IsNull())
2431   {
2432     theDI << theArgVal[4] << " is not a replaced type\n";
2433     return 1;
2434   }
2435
2436   if(aShapeForRepl2.IsNull())
2437   {
2438     theDI << theArgVal[6] << " is not a replaced type\n";
2439     return 1;
2440   }
2441
2442
2443   TopoDS_Shape aReplacedShape;
2444   ShapeBuild_ReShape aReshape;
2445
2446   //////////////////// explode (begin)
2447   TopTools_MapOfShape M;
2448   M.Add(aShape);
2449   Standard_Integer aNbShapes = 0;
2450   for (TopExp_Explorer ex(aShape,TopAbs_FACE); ex.More(); ex.Next())
2451     {
2452       const TopoDS_Shape& Sx = ex.Current();
2453       Standard_Boolean added = M.Add(Sx);
2454       if (added)
2455         {
2456           aNbShapes++;
2457           if(aNbShapes == aNumOfRE1)
2458             {
2459               aReplacedShape = Sx;
2460
2461               aReshape.Replace(aReplacedShape, aShapeForRepl1);
2462             }
2463
2464           if(aNbShapes == aNumOfRE2)
2465             {
2466               aReplacedShape = Sx;
2467
2468               aReshape.Replace(aReplacedShape, aShapeForRepl2);
2469             }
2470         }
2471     }
2472   //////////////////// explode (end)
2473
2474   if(aReplacedShape.IsNull())
2475     {
2476       theDI << "There is not any shape for replacing.\n";
2477     }
2478
2479   DBRep::Set (theArgVal[1],aReshape.Apply (aShape,TopAbs_WIRE,2));
2480
2481   return 0;
2482 }
2483
2484 #include <ShapeFix_Wireframe.hxx>
2485 //=======================================================================
2486 //function : OCC7570
2487 //purpose  : 
2488 //=======================================================================
2489 static Standard_Integer OCC7570 (Draw_Interpretor& di, Standard_Integer n, const char** a)
2490 {
2491   if (n != 2) {
2492     di<<"Usage: "<<a[0]<<" invalid number of arguments\n";
2493     return 1;
2494   }
2495   TopoDS_Shape in_shape (DBRep::Get (a[1]));
2496   ShapeFix_Wireframe fix_tool (in_shape);
2497   fix_tool.ModeDropSmallEdges () = Standard_True;
2498   fix_tool.SetPrecision (1.e+6);
2499   fix_tool.SetLimitAngle (0.01);
2500   fix_tool.FixSmallEdges ();
2501   TopoDS_Shape new_shape = fix_tool.Shape ();
2502   return 0;
2503 }
2504
2505 #include <AIS_TypeFilter.hxx>
2506 //=======================================================================
2507 //function : OCC25340
2508 //purpose  : 
2509 //=======================================================================
2510 static Standard_Integer OCC25340 (Draw_Interpretor& /*theDI*/,
2511                                  Standard_Integer  /*theArgNb*/,
2512                                  const char** /*theArgVec*/)
2513 {
2514   Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2515   if (aCtx.IsNull())
2516   {
2517     std::cerr << "Error: No opened viewer!\n";
2518     return 1;
2519   }
2520   Handle(AIS_TypeFilter) aFilter = new AIS_TypeFilter (AIS_KOI_Shape);
2521   aCtx->AddFilter (aFilter);
2522   return 0;
2523 }
2524
2525 //=======================================================================
2526 //function : OCC24826
2527 //purpose  :
2528 //=======================================================================
2529 class ParallelTest_Saxpy
2530 {
2531 public:
2532   typedef NCollection_Array1<Standard_Real> Vector;
2533
2534   //! Constructor
2535   ParallelTest_Saxpy(const Vector& theX, Vector& theY, Standard_Real theScalar)
2536   : myX(theX),
2537     myY(theY),
2538     myScalar(theScalar)
2539   {
2540   }
2541
2542   //! Dummy calculation
2543   void operator() (const Standard_Integer theIndex) const
2544   {
2545     myY(theIndex) = myScalar * myX(theIndex) + myY(theIndex);
2546   }
2547
2548 private:
2549   ParallelTest_Saxpy( const ParallelTest_Saxpy& );
2550   ParallelTest_Saxpy& operator =( ParallelTest_Saxpy& );
2551
2552 private:
2553   const Vector&       myX;
2554   Vector&             myY;
2555   const Standard_Real myScalar;
2556 };
2557
2558 //---------------------------------------------------------------------
2559 static Standard_Integer OCC24826(Draw_Interpretor& theDI,
2560                                  Standard_Integer  trheArgc,
2561                                  const char**      theArgv)
2562 {
2563   if ( trheArgc != 2 )
2564   {
2565     theDI << "Usage: "
2566           << theArgv[0]
2567           << " vec_length\n";
2568     return 1;
2569   }
2570
2571   // Generate data;
2572   Standard_Integer aLength = Draw::Atoi(theArgv[1]);
2573
2574   NCollection_Array1<Standard_Real> aX (0, aLength - 1);
2575   NCollection_Array1<Standard_Real> anY(0, aLength - 1);
2576
2577   for ( Standard_Integer i = 0; i < aLength; ++i )
2578   {
2579     aX(i) = anY(i) = (Standard_Real) i;
2580   }
2581
2582   OSD_Timer aTimer;
2583
2584   aTimer.Start();
2585
2586   //! Serial proccesing
2587   for ( Standard_Integer i = 0; i < aLength; ++i )
2588   {
2589     anY(i) = 1e-6 * aX(i) + anY(i);
2590   }
2591
2592   aTimer.Stop();
2593   cout << "Processing time (sequential mode):\n";
2594   aTimer.Show();
2595
2596   const ParallelTest_Saxpy aFunctor(aX, anY, 1e-6);
2597
2598   aTimer.Reset();
2599   aTimer.Start();
2600
2601   // Parallel processing
2602   OSD_Parallel::For(0, aLength, aFunctor);
2603
2604   aTimer.Stop();
2605   cout << "Processing time (parallel mode):\n";
2606   aTimer.Show();
2607
2608   return 0;
2609 }
2610
2611 /*****************************************************************************/
2612
2613 #include <GeomAPI_IntSS.hxx>
2614 //=======================================================================
2615 //function : OCC25100
2616 //purpose  :
2617 //=======================================================================
2618 static Standard_Integer OCC25100 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2619 {
2620   if (argc < 2)
2621   {
2622     di << "the method requires a shape name\n";
2623     return 1;
2624   }
2625
2626   TopoDS_Shape S = DBRep::Get(argv[1]);
2627   if ( S.IsNull() )
2628   {
2629     di << "Shape is empty\n";
2630     return 1;
2631   }
2632   
2633   TopExp_Explorer aFaceExp(S, TopAbs_FACE);
2634   const Handle(Geom_Surface)& aSurf = BRep_Tool::Surface(TopoDS::Face(aFaceExp.Current()));
2635
2636   GeomAPI_IntSS anIntersector(aSurf, aSurf, Precision::Confusion());
2637
2638   if (!anIntersector.IsDone())
2639   {
2640     di << "Error. Intersection is not done\n";
2641     return 1;
2642   }
2643
2644   di << "Test complete\n";
2645
2646   return 0;
2647 }
2648
2649 //=======================================================================
2650 //function : OCC25348
2651 //purpose  : 
2652 //=======================================================================
2653 static Standard_Integer OCC25348 (Draw_Interpretor& theDI,
2654                                  Standard_Integer  /*theArgNb*/,
2655                                  const char** /*theArgVec*/)
2656 {
2657   Handle(NCollection_IncAllocator) anAlloc1;
2658   NCollection_List<int> aList1(anAlloc1);
2659   for (int i=0; i < 10; i++)
2660   {
2661     Handle(NCollection_IncAllocator) anAlloc2;
2662     NCollection_List<int> aList2(anAlloc2);
2663     aList2.Append(i);
2664     aList1.Assign(aList2);
2665   }
2666   theDI << "Test complete\n";
2667   return 0;
2668 }
2669
2670 #include <IntCurvesFace_ShapeIntersector.hxx>
2671 #include <BRepBndLib.hxx>
2672 //=======================================================================
2673 //function : OCC25413
2674 //purpose  : 
2675 //=======================================================================
2676 static Standard_Integer OCC25413 (Draw_Interpretor& di, Standard_Integer narg , const char** a)
2677 {
2678   if (narg != 2) {
2679     di << "Usage: " << a[0] << " invalid number of arguments\n";
2680     return 1;
2681   }
2682   TopoDS_Shape aShape = DBRep::Get (a[1]);
2683
2684   IntCurvesFace_ShapeIntersector Inter;
2685   Inter.Load(aShape, Precision::Confusion());
2686
2687   Bnd_Box aBndBox;
2688   BRepBndLib::Add(aShape, aBndBox);
2689
2690   gp_Dir aDir(0., 1., 0.);
2691   const int N = 250;
2692   Standard_Real xMin = aBndBox.CornerMin().X();
2693   Standard_Real zMin = aBndBox.CornerMin().Z();
2694   Standard_Real xMax = aBndBox.CornerMax().X();
2695   Standard_Real zMax = aBndBox.CornerMax().Z();
2696   Standard_Real xStep = (xMax - xMin) / N;
2697   Standard_Real zStep = (zMax - zMin) / N;
2698
2699   for (Standard_Real x = xMin; x <= xMax; x += xStep)
2700     for (Standard_Real z = zMin; z <= zMax; z += zStep)
2701     {
2702       gp_Pnt aPoint(x, 0.0, z);
2703       gp_Lin aLine(aPoint, aDir);
2704       Inter.PerformNearest(aLine, -100., 100.);
2705     }
2706   return 0;
2707 }
2708
2709
2710 #include <BOPAlgo_PaveFiller.hxx>
2711 //
2712 #include <BRepAlgoAPI_BooleanOperation.hxx>
2713 #include <BRepAlgoAPI_Common.hxx>
2714 #include <BRepAlgoAPI_Fuse.hxx>
2715 #include <BRepAlgoAPI_Cut.hxx>
2716 #include <BRepAlgoAPI_Section.hxx>
2717 //
2718 #include <BOPTools.hxx>
2719 //
2720 #include <BOPCol_MapOfShape.hxx>
2721 #include <BOPCol_ListOfShape.hxx>
2722 //=======================================================================
2723 //function : OCC25446
2724 //purpose  :
2725 //=======================================================================
2726 static Standard_Integer OCC25446 (Draw_Interpretor& theDI, 
2727                                   Standard_Integer argc, 
2728                                   const char ** argv)
2729 {
2730   if (argc != 5) {
2731     theDI << "Usage: OCC25446 res b1 b2 op\n";
2732     return 1;
2733   }
2734   //
2735   TopoDS_Shape aS1 = DBRep::Get(argv[2]);
2736   if (aS1.IsNull()) {
2737     theDI << argv[2] << " shape is NULL\n";
2738     return 1;
2739   }
2740   //
2741   TopoDS_Shape aS2 = DBRep::Get(argv[3]);
2742   if (aS2.IsNull()) {
2743     theDI << argv[3] << " shape is NULL\n";
2744     return 1;
2745   }
2746   //
2747   Standard_Integer iOp;
2748   BOPAlgo_Operation aOp;
2749   //
2750   iOp = Draw::Atoi(argv[4]);
2751   if (iOp < 0 || iOp > 4) {
2752     theDI << "Invalid operation type\n";
2753     return 1;
2754   }
2755   aOp = (BOPAlgo_Operation)iOp;
2756   //
2757   Standard_Integer iErr;
2758   BOPCol_ListOfShape aLS;
2759   BOPAlgo_PaveFiller aPF;
2760   //
2761   aLS.Append(aS1);
2762   aLS.Append(aS2);
2763   aPF.SetArguments(aLS);
2764   //
2765   aPF.Perform();
2766   iErr = aPF.HasErrors();
2767   if (iErr) {
2768     theDI << "Intersection failed with error status: " << iErr << "\n";
2769     return 1;
2770   }
2771   //
2772   BRepAlgoAPI_BooleanOperation* pBuilder = NULL;
2773   // 
2774   switch (aOp) {
2775   case BOPAlgo_COMMON:
2776     pBuilder = new BRepAlgoAPI_Common(aS1, aS2, aPF);
2777     break;
2778   case BOPAlgo_FUSE:
2779     pBuilder = new BRepAlgoAPI_Fuse(aS1, aS2, aPF);
2780     break;
2781   case BOPAlgo_CUT:
2782     pBuilder = new BRepAlgoAPI_Cut (aS1, aS2, aPF);
2783     break;
2784   case BOPAlgo_CUT21:
2785     pBuilder = new BRepAlgoAPI_Cut(aS1, aS2, aPF, Standard_False);
2786     break;
2787   case BOPAlgo_SECTION:
2788     pBuilder = new BRepAlgoAPI_Section(aS1, aS2, aPF);
2789     break;
2790   default:
2791     break;
2792   }
2793   //
2794   iErr = pBuilder->HasErrors();
2795   if (!pBuilder->IsDone()) {
2796     theDI << "BOP failed with error status: " << iErr << "\n";
2797     return 1;
2798   }
2799   //
2800   const TopoDS_Shape& aRes = pBuilder->Shape();
2801   DBRep::Set(argv[1], aRes);
2802   //
2803   BOPCol_MapOfShape aMapArgs, aMapShape;
2804   BOPCol_MapIteratorOfMapOfShape aIt;
2805   Standard_Boolean bIsDeletedHist, bIsDeletedMap;
2806   TopAbs_ShapeEnum aType;
2807   //
2808   BOPTools::MapShapes(aS1, aMapArgs);
2809   BOPTools::MapShapes(aS2, aMapArgs);
2810   BOPTools::MapShapes(aRes, aMapShape);
2811   //
2812   aIt.Initialize(aMapArgs);
2813   for (; aIt.More(); aIt.Next()) {
2814     const TopoDS_Shape& aS = aIt.Value();
2815     aType = aS.ShapeType();
2816     if (!(aType==TopAbs_EDGE || aType==TopAbs_FACE || 
2817           aType==TopAbs_VERTEX || aType==TopAbs_SOLID)) {
2818       continue;
2819     }
2820     //
2821     bIsDeletedHist = pBuilder->IsDeleted(aS);
2822     bIsDeletedMap = !aMapShape.Contains(aS) &&
2823       (pBuilder->Modified(aS).Extent() == 0);
2824     //
2825     if (bIsDeletedHist != bIsDeletedMap) {
2826       theDI << "Error. Wrong value of IsDeleted flag.\n";
2827       return 1;
2828     }
2829   }
2830   //
2831   theDI << "Test complete\n";
2832   return 0;
2833 }
2834
2835 //====================================================
2836 // Auxiliary functor class for the command OCC25545;
2837 // it gets access to a vertex with the given index and
2838 // checks that X coordinate of the point is equal to index;
2839 // if it is not so then a data race is reported.
2840 //====================================================
2841 struct OCC25545_Functor
2842 {
2843   OCC25545_Functor(const std::vector<TopoDS_Shape>& theShapeVec)
2844     : myShapeVec(&theShapeVec),
2845       myIsRaceDetected(0)
2846   {}
2847
2848   void operator()(size_t i) const
2849   {
2850     if (!myIsRaceDetected) {
2851       const TopoDS_Vertex& aV = TopoDS::Vertex (myShapeVec->at(i));
2852       gp_Pnt aP = BRep_Tool::Pnt (aV);
2853       if (aP.X () != static_cast<double> (i)) {
2854         Standard_Atomic_Increment(&myIsRaceDetected);
2855       }
2856     }
2857   }
2858
2859   const std::vector<TopoDS_Shape>* myShapeVec;
2860   mutable volatile int myIsRaceDetected;
2861 };
2862
2863 //=======================================================================
2864 //function : OCC25545
2865 //purpose  : Tests data race when concurrently accessing TopLoc_Location::Transformation()
2866 //=======================================================================
2867 #ifdef HAVE_TBB
2868 static Standard_Integer OCC25545 (Draw_Interpretor& di, 
2869                                   Standard_Integer, 
2870                                   const char **)
2871 {
2872   // Place vertices in a vector, giving the i-th vertex the
2873   // transformation that translates it on the vector (i,0,0) from the origin.
2874   size_t n = 1000;
2875   std::vector<TopoDS_Shape> aShapeVec (n);
2876   std::vector<TopLoc_Location> aLocVec (n);
2877   TopoDS_Shape aShape = BRepBuilderAPI_MakeVertex (gp::Origin ());
2878   aShapeVec[0] = aShape;
2879   for (size_t i = 1; i < n; ++i) {
2880     gp_Trsf aT;
2881     aT.SetTranslation (gp_Vec (1, 0, 0));
2882     aLocVec[i] = aLocVec[i - 1] * aT;
2883     aShapeVec[i] = aShape.Moved (aLocVec[i]);
2884   }
2885
2886   // Evaluator function will access vertices geometry
2887   // concurrently
2888   OCC25545_Functor aFunc(aShapeVec);
2889
2890   //concurrently process
2891   tbb::parallel_for (size_t (0), n, aFunc, tbb::simple_partitioner ());
2892   QVERIFY (!aFunc.myIsRaceDetected);
2893   return 0;
2894 }
2895 #else
2896 static Standard_Integer OCC25545 (Draw_Interpretor&, 
2897                                   Standard_Integer, 
2898                                   const char **argv)
2899 {
2900   cout << "Test skipped: command " << argv[0] << " requires TBB library" << endl;
2901   return 0;
2902 }
2903 #endif
2904
2905 //=======================================================================
2906 //function : OCC25547
2907 //purpose  :
2908 //=======================================================================
2909 #include <BRepMesh_GeomTool.hxx>
2910 #include <BRepAdaptor_Curve.hxx>
2911 #include <Geom_TrimmedCurve.hxx>
2912 #include <BRepBuilderAPI_MakeFace.hxx>
2913 #include <BRepAdaptor_HSurface.hxx>
2914 #include <BRepAdaptor_Surface.hxx>
2915 static Standard_Integer OCC25547(
2916   Draw_Interpretor& theDI, 
2917   Standard_Integer  /*argc*/, 
2918   const char **     /*argv*/)
2919 {
2920   // The general aim of this test is to prevent linkage errors due to missed
2921   // Standard_EXPORT attribute for static methods.
2922
2923   // However, start checking the main functionality at first.
2924   const Standard_Real aFirstP = 0., aLastP = M_PI;
2925   Handle(Geom_Circle) aCircle = new Geom_Circle(gp_Ax2(gp::Origin(), gp::DZ()), 10);
2926   Handle(Geom_TrimmedCurve) aHalf = new Geom_TrimmedCurve(aCircle, aFirstP, aLastP);
2927   TopoDS_Edge aEdge = BRepBuilderAPI_MakeEdge(aHalf);
2928   BRepAdaptor_Curve aAdaptor(aEdge);
2929   BRepMesh_GeomTool aGeomTool(aAdaptor, aFirstP, aLastP, 0.1, 0.5);
2930
2931   if (aGeomTool.NbPoints() == 0)
2932   {
2933     theDI << "Error. BRepMesh_GeomTool failed to discretize an arc.\n";
2934     return 1;
2935   }
2936
2937   // Test static methods.
2938   TopoDS_Face aFace = BRepBuilderAPI_MakeFace(gp_Pln(gp::Origin(), gp::DZ()));
2939   BRepAdaptor_Surface aSurf(aFace);
2940   Handle(BRepAdaptor_HSurface) aHSurf = new BRepAdaptor_HSurface(aSurf);
2941
2942   gp_Pnt aPnt;
2943   gp_Dir aNormal;
2944   if (!BRepMesh_GeomTool::Normal(aHSurf, 10., 10., aPnt, aNormal))
2945   {
2946     theDI << "Error. BRepMesh_GeomTool failed to take a normal of surface.\n";
2947     return 1;
2948   }
2949
2950   gp_XY aRefPnts[4] = {
2951     gp_XY(-10., -10.), gp_XY(10., 10.), 
2952     gp_XY(-10., 10.), gp_XY(10., -10.)
2953   };
2954
2955   gp_Pnt2d aIntPnt;
2956   Standard_Real aParams[2];
2957   BRepMesh_GeomTool::IntFlag aIntFlag = BRepMesh_GeomTool::IntLinLin(
2958     aRefPnts[0], aRefPnts[1], aRefPnts[2], aRefPnts[3], 
2959     aIntPnt.ChangeCoord(), aParams);
2960
2961   Standard_Real aDiff = aIntPnt.Distance(gp::Origin2d());
2962   if (aIntFlag != BRepMesh_GeomTool::Cross || aDiff > Precision::PConfusion())
2963   {
2964     theDI << "Error. BRepMesh_GeomTool failed to intersect two lines.\n";
2965     return 1;
2966   }
2967
2968   aIntFlag = BRepMesh_GeomTool::IntSegSeg(
2969     aRefPnts[0], aRefPnts[1], aRefPnts[2], aRefPnts[3], 
2970     Standard_False, Standard_False, aIntPnt);
2971
2972   aDiff = aIntPnt.Distance(gp::Origin2d());
2973   if (aIntFlag != BRepMesh_GeomTool::Cross || aDiff > Precision::PConfusion())
2974   {
2975     theDI << "Error. BRepMesh_GeomTool failed to intersect two segments.\n";
2976     return 1;
2977   }
2978
2979
2980   theDI << "Test complete\n";
2981   return 0;
2982 }
2983
2984 static Standard_Integer OCC26139 (Draw_Interpretor& theDI,
2985                                   Standard_Integer  argc,
2986                                   const char **     argv)
2987 {
2988
2989   Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
2990   if (aCtx.IsNull())
2991   {
2992     theDI << "Use 'vinit' command before " << argv[0] << "\n";
2993     return 1;
2994   }
2995
2996   Standard_Integer aBoxGridSize = 100;
2997   Standard_Integer aCompGridSize = 3;
2998   Standard_Real aBoxSize = 5.0;
2999
3000   if (argc > 1)
3001   {
3002     for (Standard_Integer anArgIdx = 1; anArgIdx < argc; ++anArgIdx)
3003     {
3004       TCollection_AsciiString anArg (argv[anArgIdx]);
3005       anArg.LowerCase();
3006       if (anArg == "-boxgrid")
3007       {
3008         aBoxGridSize = Draw::Atoi (argv[++anArgIdx]);
3009       }
3010       else if (anArg == "-compgrid")
3011       {
3012         aCompGridSize = Draw::Atoi (argv[++anArgIdx]);
3013       }
3014       else if (anArg == "-boxsize")
3015       {
3016         aBoxSize = Draw::Atof (argv[++anArgIdx]);
3017       }
3018     }
3019   }
3020
3021   NCollection_List<Handle(AIS_Shape)> aCompounds;
3022   for (Standard_Integer aCompGridX = 0; aCompGridX < aCompGridSize; ++aCompGridX)
3023   {
3024     for (Standard_Integer aCompGridY = 0; aCompGridY < aCompGridSize; ++aCompGridY)
3025     {
3026       BRep_Builder aBuilder;
3027       TopoDS_Compound aComp;
3028       aBuilder.MakeCompound (aComp);
3029       for (Standard_Integer aBoxGridX = 0; aBoxGridX < aBoxGridSize; ++aBoxGridX)
3030       {
3031         for (Standard_Integer aBoxGridY = 0; aBoxGridY < aBoxGridSize; ++aBoxGridY)
3032         {
3033           BRepPrimAPI_MakeBox aBox (gp_Pnt (aBoxGridX * aBoxSize, aBoxGridY * aBoxSize, 0.0),
3034                                     aBoxSize, aBoxSize, aBoxSize);
3035           aBuilder.Add (aComp, aBox.Shape());
3036         }
3037       }
3038       gp_Trsf aTrsf;
3039       aTrsf.SetTranslation (gp_Vec (aBoxGridSize * aBoxSize * aCompGridX,
3040                                     aBoxGridSize * aBoxSize * aCompGridY,
3041                                     0.0));
3042       TopLoc_Location aLoc (aTrsf);
3043       aComp.Located (aLoc);
3044       aCompounds.Append (new AIS_Shape (aComp));
3045     }
3046   }
3047
3048   OSD_Timer aTimer;
3049   for (NCollection_List<Handle(AIS_Shape)>::Iterator aCompIter (aCompounds); aCompIter.More(); aCompIter.Next())
3050   {
3051     aTimer.Start();
3052     aCtx->Display (aCompIter.Value(), Standard_False);
3053     aTimer.Stop();
3054     theDI << "Display time: " << aTimer.ElapsedTime() << "\n";
3055     aTimer.Reset();
3056   }
3057
3058   aTimer.Reset();
3059   aTimer.Start();
3060   for (NCollection_List<Handle(AIS_Shape)>::Iterator aCompIter (aCompounds); aCompIter.More(); aCompIter.Next())
3061   {
3062     aCtx->Remove (aCompIter.Value(), Standard_False);
3063   }
3064   aTimer.Stop();
3065   theDI << "Remove time: " << aTimer.ElapsedTime() << "\n";
3066
3067   return 0;
3068 }
3069
3070 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
3071 #include <TColStd_DataMapOfIntegerInteger.hxx>
3072 #include <OSD.hxx>
3073 #include <ShapeFix_Wire.hxx>
3074 #include <ShapeExtend_Status.hxx>
3075 #ifdef _WIN32
3076 #define EXCEPTION ...
3077 #else
3078 #define EXCEPTION Standard_Failure
3079 #endif
3080
3081 static ShapeExtend_Status getStatusGap(const Handle(ShapeFix_Wire)&   theFix,
3082                                        const Standard_Boolean theIs3d)
3083 {
3084         for (Standard_Integer i=ShapeExtend_OK; i<=ShapeExtend_FAIL; i++)
3085         {
3086                 Standard_Boolean isFound;
3087                 if (theIs3d)
3088                         isFound = theFix->StatusGaps3d( (ShapeExtend_Status) i );
3089                 else
3090                         isFound = theFix->StatusGaps2d( (ShapeExtend_Status) i );
3091                 if (isFound) return ShapeExtend_Status(i);
3092         }
3093         return ShapeExtend_OK;
3094 }
3095
3096 //===================
3097 //function : OCC24881
3098 //purpose  : 
3099 //===================
3100 static Standard_Integer OCC24881 (Draw_Interpretor& di, Standard_Integer narg , const char** a)
3101 {
3102   if (narg < 2) {
3103     di<<"Usage: "<<a[0]<<" invalid number of arguments\n";
3104     return 1;
3105   }
3106 //    cout <<"FileName1: " << argv[1] <<endl;
3107
3108   TopoDS_Shape aShape = DBRep::Get (a[1]);
3109
3110     OSD::SetSignal();
3111     Handle(ShapeFix_Wire) aWireFix = new ShapeFix_Wire;
3112
3113     // map FixStatus - NbSuchStatuses
3114     TColStd_DataMapOfIntegerInteger aStatusNbDMap;
3115     Standard_Integer nbFixed=0, nbOk=0;
3116
3117 //Begin: STEP 7
3118     ShapeExtend_Status aStatus=ShapeExtend_OK;
3119     try {
3120         TopExp_Explorer aFaceExplorer(aShape, TopAbs_FACE);
3121         for (; aFaceExplorer.More(); aFaceExplorer.Next())
3122         {
3123                 TopoDS_Shape aFace = aFaceExplorer.Current();
3124                 // loop on wires
3125                 TopoDS_Iterator aWireItr(aFace);
3126                 for (; aWireItr.More(); aWireItr.Next() )
3127                 {
3128                         Standard_Boolean wasOk = Standard_False;
3129                         TopoDS_Wire aSrcWire = TopoDS::Wire(aWireItr.Value());
3130
3131                         aWireFix->Load (aSrcWire);
3132                         aWireFix->SetFace (TopoDS::Face(aFace));
3133                         aWireFix->FixReorder(); //correct order is a prerequisite
3134                         // fix 3d
3135                         if (!aWireFix->FixGaps3d())
3136                         {
3137                                 // not fixed, why?
3138                                 aStatus = getStatusGap(aWireFix, Standard_True);
3139                                 if (aStatus == ShapeExtend_OK)
3140                                         wasOk = Standard_True;
3141                                 else
3142                                 {
3143                                         // keep 3d fail status
3144                                         if (aStatusNbDMap.IsBound (aStatus))
3145                                                 aStatusNbDMap(aStatus)++;
3146                                         else
3147                                                 aStatusNbDMap.Bind(aStatus,1);
3148                                         continue;
3149                                 }
3150                         }
3151
3152                         // fix 2d
3153                         if (aWireFix->FixGaps2d())
3154                                 nbFixed++;
3155                         else
3156                         {
3157                                 aStatus = getStatusGap(aWireFix, Standard_False);
3158                                 if (aStatus == ShapeExtend_OK)
3159                                 {
3160                                         if (wasOk)
3161                                         {
3162                                                 nbOk++;
3163                                                 continue;
3164                                         }
3165                                         else
3166                                                 nbFixed++;
3167                                 }
3168                                 else
3169                                 {
3170                                         // keep 2d fail status
3171                                         Standard_Integer aStatus2d = aStatus + ShapeExtend_FAIL;
3172                                         if (aStatusNbDMap.IsBound (aStatus2d))
3173                                                 aStatusNbDMap(aStatus2d)++;
3174                                         else
3175                                                 aStatusNbDMap.Bind(aStatus2d,1);
3176                                         continue;
3177                                 }
3178                         }
3179                 }
3180         }
3181 //End: STEP 7
3182      } catch (EXCEPTION) {
3183        di << "Exception is raised = " <<aStatus << "\n";
3184        return 1;
3185
3186      }
3187 // report what is done
3188
3189         if (nbFixed)
3190         {
3191                 di <<"Fix_FillGaps_Fixed: nbFixed = "<<nbFixed <<"\n";
3192
3193         }    
3194         if (nbOk)
3195         {
3196                 di << "Fix_FillGaps_NothingToDo\n";
3197
3198         }
3199         TColStd_DataMapIteratorOfDataMapOfIntegerInteger aStatusItr(aStatusNbDMap);
3200         for (; aStatusItr.More(); aStatusItr.Next()) 
3201         {
3202                 switch ((ShapeExtend_Status) aStatusItr.Key()) 
3203                 {
3204                         // treat 3d status
3205                         case ShapeExtend_FAIL1:
3206                         di <<"Fix_FillGaps_3dNoCurveFail, nb failed = ";
3207                         break;
3208                         case ShapeExtend_FAIL2:
3209                         di <<"Fix_FillGaps_3dSomeGapsFail, nb failed = ";
3210                         break;
3211                         default:
3212                         // treat 2d status
3213                         switch ((ShapeExtend_Status) (aStatusItr.Key() - ShapeExtend_FAIL)) 
3214                         {
3215                                 case ShapeExtend_FAIL1:
3216                                 di <<"Fix_FillGaps_2dNoPCurveFail, nb failed = ";
3217                                 break;
3218                                 case ShapeExtend_FAIL2:
3219                                 di <<"Fix_FillGaps_2dSomeGapsFail, nb failed = ";
3220                                 break;
3221                                 default:
3222                                 break;
3223                         }
3224                 }
3225                 di <<aStatusItr.Value()<< "\n";
3226         }
3227         di << ("__________________________________") <<"\n";
3228
3229   return 0;
3230 }
3231
3232 //=======================================================================
3233 //function : OCC26172
3234 //purpose  :
3235 //=======================================================================
3236 static Standard_Integer OCC26172 (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3237 {
3238   if (theArgNb != 1)
3239   {
3240     std::cerr << "Error: wrong number of arguments! See usage:\n";
3241     theDI.PrintHelp (theArgVec[0]);
3242     return 1;
3243   }
3244
3245   Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3246   if(anAISContext.IsNull())
3247   {
3248     std::cerr << "Error: no active view. Please call vinit.\n";
3249     return 1;
3250   }
3251
3252   gp_Pnt aStart (100, 100, 100);
3253   gp_Pnt anEnd (300, 400, 600);
3254   BRepBuilderAPI_MakeEdge anEdgeBuilder (aStart, anEnd);
3255   TopoDS_Edge anEdge = anEdgeBuilder.Edge();
3256   Handle(AIS_Shape) aTestAISShape = new AIS_Shape (anEdge);
3257   anAISContext->Display (aTestAISShape, Standard_True);
3258
3259   // 2. activate it in selection modes
3260   TColStd_SequenceOfInteger aModes;
3261   aModes.Append (AIS_Shape::SelectionMode ((TopAbs_ShapeEnum) TopAbs_VERTEX));
3262   aModes.Append (AIS_Shape::SelectionMode ((TopAbs_ShapeEnum) TopAbs_EDGE));
3263
3264   Standard_DISABLE_DEPRECATION_WARNINGS
3265   anAISContext->OpenLocalContext();
3266   Standard_ENABLE_DEPRECATION_WARNINGS
3267   anAISContext->Deactivate (aTestAISShape);
3268   anAISContext->Load (aTestAISShape, -1, true);
3269   for (Standard_Integer anIt = 1; anIt <= aModes.Length(); ++anIt)
3270   {
3271     anAISContext->Activate (aTestAISShape, aModes (anIt));
3272   }
3273
3274   // select entities in vertex selection mode
3275   Handle(SelectMgr_Selection) aSelection = aTestAISShape->Selection (aModes (1));
3276   Standard_DISABLE_DEPRECATION_WARNINGS
3277   for (aSelection->Init(); aSelection->More(); aSelection->Next())
3278   {
3279     Handle(SelectBasics_SensitiveEntity) anEntity = aSelection->Sensitive()->BaseSensitive();
3280     if (anEntity.IsNull())
3281     {
3282       continue;
3283     }
3284
3285     Handle(SelectMgr_EntityOwner) anOwner =
3286       Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
3287
3288     if (anOwner.IsNull())
3289     {
3290       continue;
3291     }
3292
3293     anAISContext->LocalContext()->AddOrRemoveSelected (anOwner);
3294   }
3295   Standard_ENABLE_DEPRECATION_WARNINGS
3296
3297   // select entities in edge selection mode
3298   aSelection = aTestAISShape->Selection (aModes (2));
3299   Standard_DISABLE_DEPRECATION_WARNINGS
3300   for (aSelection->Init(); aSelection->More(); aSelection->Next())
3301   {
3302     Handle(SelectBasics_SensitiveEntity) anEntity = aSelection->Sensitive()->BaseSensitive();
3303     if (anEntity.IsNull())
3304     {
3305       continue;
3306     }
3307
3308     Handle(SelectMgr_EntityOwner) anOwner =
3309       Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
3310
3311     if (anOwner.IsNull())
3312     {
3313       continue;
3314     }
3315
3316     anAISContext->LocalContext()->AddOrRemoveSelected (anOwner);
3317   }
3318   Standard_ENABLE_DEPRECATION_WARNINGS
3319
3320   // deactivate vertex mode and check clearing of outdated selection
3321   anAISContext->Deactivate (aTestAISShape, aModes (1));
3322   Standard_DISABLE_DEPRECATION_WARNINGS
3323   anAISContext->LocalContext()->ClearOutdatedSelection (aTestAISShape, true);
3324   Standard_ENABLE_DEPRECATION_WARNINGS
3325
3326   return 0;
3327 }
3328
3329 //=======================================================================
3330 //function : OCC26284
3331 //purpose  :
3332 //=======================================================================
3333 static Standard_Integer OCC26284 (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3334 {
3335   if (theArgNb != 1)
3336   {
3337     std::cerr << "Error: wrong number of arguments! See usage:\n";
3338     theDI.PrintHelp (theArgVec[0]);
3339     return 1;
3340   }
3341
3342   Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3343   if (anAISContext.IsNull())
3344   {
3345     std::cerr << "Error: no active view. Please call vinit.\n";
3346     return 1;
3347   }
3348
3349   BRepPrimAPI_MakeSphere aSphereBuilder (gp_Pnt (0.0, 0.0, 0.0), 1.0);
3350   Handle(AIS_Shape) aSphere = new AIS_Shape (aSphereBuilder.Shape());
3351   anAISContext->Display (aSphere, Standard_False);
3352   for (Standard_Integer aChildIdx = 0; aChildIdx < 5; ++aChildIdx)
3353   {
3354     BRepPrimAPI_MakeSphere aBuilder (gp_Pnt (1.0 + aChildIdx, 1.0 + aChildIdx, 1.0 + aChildIdx), 1.0);
3355     Handle(AIS_Shape) aChild = new AIS_Shape (aBuilder.Shape());
3356     aSphere->AddChild (aChild);
3357     anAISContext->Display (aChild, Standard_False);
3358   }
3359
3360   anAISContext->RecomputeSelectionOnly (aSphere);
3361   anAISContext->UpdateCurrentViewer();
3362
3363   return 0;
3364 }
3365
3366 #include <IntTools_Context.hxx>
3367 #include <GeomAPI_ProjectPointOnSurf.hxx>
3368
3369 //=======================================================================
3370 //function : xprojponf
3371 //purpose  : 
3372 //=======================================================================
3373 Standard_Integer xprojponf (Draw_Interpretor& di, 
3374                             Standard_Integer n, 
3375                             const char** a)
3376 {
3377   if (n!=3) {
3378     di<<" use xprojponf p f \n";
3379     return 0;
3380   }
3381   // 
3382   gp_Pnt aP, aPS;
3383   TopoDS_Shape aS;
3384   TopoDS_Face aF;
3385   Handle(IntTools_Context) aCtx;
3386   //
3387   DrawTrSurf::GetPoint(a[1], aP);
3388   aS=DBRep::Get(a[2]);
3389   //
3390   if (aS.IsNull()) {
3391     di<<" null shape is not allowed\n";
3392     return 0;
3393   }
3394   //
3395   if (aS.ShapeType()!=TopAbs_FACE) {
3396     di << a[2] << " not a face\n";
3397     return 0;
3398   }
3399   //
3400   aCtx=new IntTools_Context;
3401   //
3402   aF=TopoDS::Face(aS);
3403   GeomAPI_ProjectPointOnSurf& aPPS=aCtx->ProjPS(aF);
3404   //
3405   aPPS.Perform(aP);
3406   if (!aPPS.IsDone()) {
3407     di<<" projection failed\n";
3408     return 0;
3409   }
3410   //
3411   aPS=aPPS.NearestPoint();
3412   di<< " point px " << aPS.X() << " " << aPS.Y() << " " <<  aPS.Z() << "\n";
3413   //
3414   return 0;
3415 }
3416
3417 //=======================================================================
3418 //function : OCC25547
3419 //purpose  :
3420 //=======================================================================
3421 #include <BRepMesh_CircleTool.hxx>
3422 #include <SelectMgr_EntityOwner.hxx>
3423
3424 static Standard_Boolean inspect_point(const gp_XY&        thePoint,
3425                                       const gp_XY&        theCenter,
3426                                       const Standard_Real theRadius)
3427 {
3428   static Standard_Real aPrecision   = Precision::PConfusion();
3429   static Standard_Real aSqPrecision = aPrecision * aPrecision;
3430   const gp_XY aDistVec = thePoint - theCenter;
3431   if (aDistVec.SquareModulus() - (theRadius * theRadius) < aSqPrecision)
3432     return Standard_True;
3433   else
3434     return Standard_False;
3435 }
3436
3437 static Standard_Integer OCC24923(
3438   Draw_Interpretor& theDI, 
3439   Standard_Integer  argc, 
3440   const char **     argv)
3441 {
3442   srand(static_cast<unsigned int>(time(NULL)));
3443
3444   const Standard_Real    aMaxDeviation = (argc > 1) ? Draw::Atof(argv[1]) : 0.01;
3445   const Standard_Integer aPointsNb     = 10000000;
3446   const Standard_Real    aMinAngle     = 5 * M_PI / 180.;
3447   static Standard_Real   aSqPrecision  = Precision::PConfusion() * Precision::PConfusion();
3448
3449   Standard_Integer aFailedNb = 0;
3450   for (Standard_Integer i = 0; i < aPointsNb; ++i)
3451   {
3452     gp_XY p[3];
3453     for (Standard_Integer j = 0; j < 3; ++j)
3454       p[j].SetCoord(((Standard_Real)rand())/RAND_MAX, ((Standard_Real)rand())/RAND_MAX);
3455
3456     // Check that points do not compose degenerated triangle.
3457     gp_XY aVec1 = p[1] - p[0];
3458     gp_XY aVec2 = p[2] - p[0];
3459     if (aVec1.SquareModulus() > aSqPrecision && 
3460         aVec2.SquareModulus() > aSqPrecision &&
3461         (aVec1 ^ aVec2) > aMinAngle)
3462     {
3463       gp_XY aCenter;
3464       Standard_Real aRadius;
3465       if (BRepMesh_CircleTool::MakeCircle(p[0], p[1], p[2], aCenter, aRadius))
3466       {
3467         if (!inspect_point(p[0], aCenter, aRadius) || 
3468             !inspect_point(p[1], aCenter, aRadius) || 
3469             !inspect_point(p[2], aCenter, aRadius))
3470         {
3471          /* theDI << "Missed: " <<
3472             "p1=(" << p1.X() << ", " << p1.Y() << "), " <<
3473             "p2=(" << p2.X() << ", " << p2.Y() << "), " <<
3474             "p3=(" << p3.X() << ", " << p3.Y() << "), " <<
3475             "c=(" << aCenter.X() << ", " << aCenter.Y() << "), " <<
3476             "r=" << aRadius << "\n";*/
3477             
3478           ++aFailedNb;
3479         }
3480
3481         continue;
3482       }
3483     }
3484
3485     // Ensure that aPointsNb suitable for tests are generated
3486     --i;
3487   }
3488
3489   const Standard_Real aDeviation = 
3490     1. - (Standard_Real)(aPointsNb - aFailedNb) / (Standard_Real)aPointsNb;
3491
3492   theDI << "Number of failed cases: " << aFailedNb << " (Total " << aPointsNb << ")\n";
3493   if (aDeviation > aMaxDeviation)
3494   {
3495     theDI << "Failed. Number of incorrect results is too huge: " << 
3496       aDeviation * 100 << "% (Max " << aMaxDeviation * 100 << "%)\n";
3497     return 1;
3498   }
3499
3500   theDI << "Deviation of incorrect results is: " <<
3501     aDeviation * 100 << "% (Max " << aMaxDeviation * 100 << "%)\n";
3502   theDI << "Test completed\n";
3503   return 0;
3504 }
3505
3506 //=======================================================================
3507 //function : OCC25574
3508 //purpose  : check implementation of Euler angles in gp_Quaternion
3509 //=======================================================================
3510
3511 static Standard_Integer OCC25574 (Draw_Interpretor& theDI, Standard_Integer /*argc*/, const char** /*argv*/)
3512 {
3513   Standard_Boolean isTestOk = Standard_True;
3514
3515   // Check consistency of Get and Set operations for Euler angles
3516   gp_Quaternion aQuat;
3517   aQuat.Set(0.06766916507860499, 0.21848101129786085, 0.11994599260380681,0.9660744746954637);
3518   Standard_Real alpha,beta,gamma;
3519   gp_Mat aRinv = aQuat.GetMatrix().Inverted();
3520   gp_Mat aI;
3521   aI.SetIdentity();
3522   const char* names[] = { "Extrinsic_XYZ", "Extrinsic_XZY", "Extrinsic_YZX", "Extrinsic_YXZ", "Extrinsic_ZXY", "Extrinsic_ZYX", 
3523                           "Intrinsic_XYZ", "Intrinsic_XZY", "Intrinsic_YZX", "Intrinsic_YXZ", "Intrinsic_ZXY", "Intrinsic_ZYX", 
3524                           "Extrinsic_XYX", "Extrinsic_XZX", "Extrinsic_YZY", "Extrinsic_YXY", "Extrinsic_ZYZ", "Extrinsic_ZXZ",
3525                           "Intrinsic_XYX", "Intrinsic_XZX", "Intrinsic_YZY", "Intrinsic_YXY", "Intrinsic_ZXZ", "Intrinsic_ZYZ" };
3526   for (int i = gp_Extrinsic_XYZ; i <= gp_Intrinsic_ZYZ; i++)
3527   {
3528     aQuat.GetEulerAngles (gp_EulerSequence(i), alpha, beta, gamma);
3529
3530     gp_Quaternion aQuat2;
3531     aQuat2.SetEulerAngles (gp_EulerSequence(i), alpha, beta, gamma);
3532
3533     gp_Mat aR = aQuat2.GetMatrix();
3534     gp_Mat aDiff = aR * aRinv - aI;
3535     if (aDiff.Determinant() > 1e-5)
3536     {
3537       theDI << "Error: Euler angles conversion incorrect for sequence " << names[i - gp_Extrinsic_XYZ] << "\n";
3538       isTestOk = Standard_False;
3539     }
3540   }
3541
3542   // Check conversion between intrinsic and extrinsic rotations
3543   // Any extrinsic rotation is equivalent to an intrinsic rotation
3544   // by the same angles but with inverted order of elemental rotations, and vice versa
3545   // For instance:
3546   //    Extrinsic_XZY = Incrinsic_XZY
3547   //    R = X(A)Z(B)Y(G) --> R = Y(G)Z(B)X(A)
3548   alpha = 0.1517461713131;
3549   beta = 1.5162198410141;
3550   gamma = 1.9313156236541;
3551   Standard_Real alpha2, beta2, gamma2;
3552   gp_EulerSequence pairs[][2] = { {gp_Extrinsic_XYZ, gp_Intrinsic_ZYX},
3553                                   {gp_Extrinsic_XZY, gp_Intrinsic_YZX},
3554                                   {gp_Extrinsic_YZX, gp_Intrinsic_XZY},
3555                                   {gp_Extrinsic_YXZ, gp_Intrinsic_ZXY},
3556                                   {gp_Extrinsic_ZXY, gp_Intrinsic_YXZ},
3557                                   {gp_Extrinsic_ZYX, gp_Intrinsic_XYZ} };
3558   for (int i = 0; i < 6; i++)
3559   {
3560     aQuat.SetEulerAngles(pairs[i][0],  alpha,  beta,  gamma);
3561     aQuat.GetEulerAngles(pairs[i][1], gamma2, beta2, alpha2);
3562
3563     if (Abs(alpha - alpha2) > 1e-5 || Abs(beta - beta2) > 1e-5 || Abs(gamma - gamma2) > 1e-5)
3564     {
3565       theDI << "Error: intrinsic and extrinsic conversion incorrect for sequence " << names[i] << "\n";
3566       isTestOk = Standard_False;
3567     }
3568   }
3569
3570   // Check correspondence of enumeration and actual rotation it defines, 
3571   // by rotation by one axis and checking that it does not change a point on that axis
3572   for (int i = gp_Extrinsic_XYZ; i <= gp_Intrinsic_ZYZ; i++)
3573   {
3574     // Iterate over rotations R(A)R(B)R(G) for each Euler angle Alpha, Beta, Gamma
3575     // There are three ordered axes corresponding to three rotations.
3576     // Each rotation applyed with current angle around current axis.
3577     for (int j=0; j < 3; j++)
3578     {
3579       // note that current axis index is obtained by parsing of enumeration name!
3580       int anAxis = names[i - gp_Extrinsic_XYZ][10 + j] - 'X';
3581       Standard_ASSERT_RETURN (anAxis >=0 && anAxis <= 2, "Incorrect parsing of enumeration name", 1);
3582
3583       // Set 90 degrees to current Euler angle
3584       double anAngles[3] = {0., 0., 0.};
3585       anAngles[j] = 0.5 * M_PI;
3586
3587       gp_Quaternion q2;
3588       q2.SetEulerAngles (gp_EulerSequence(i), anAngles[0], anAngles[1], anAngles[2]);
3589
3590       // Set point on axis corresponding to current rotation
3591       // We will apply rotation around this axis
3592       gp_XYZ v (0., 0., 0.);
3593       v.SetCoord (anAxis + 1, 1.);
3594
3595       // Apply rotation to point
3596       gp_Trsf aT;
3597       aT.SetRotation (q2);
3598       gp_XYZ v2 = v;
3599       aT.Transforms (v2);
3600
3601       // Check that point is still on origin position
3602       if ((v - v2).SquareModulus() > Precision::SquareConfusion())
3603       {
3604         // avoid reporting small coordinates
3605         for (int k=1; k <= 3; k++) 
3606           if (Abs (v2.Coord(k)) < Precision::Confusion())
3607             v2.SetCoord (k, 0.);
3608
3609         isTestOk = Standard_False;
3610         theDI << "Error: Euler sequence " << names[i - gp_Extrinsic_XYZ] << " is incorrect:\n";
3611         theDI << "rotating by angle 90 deg around " << (anAxis == 0 ? "X" : anAxis == 1 ? "Y" : "Z") <<
3612                       " converts vector (" << v.X() << ", " << v.Y() << ", " << v.Z() << ") to ("
3613                         << v2.X() << ", " << v2.Y() << ", " << v2.Z() << ")\n";
3614       }
3615     }
3616   }
3617
3618   // Check correspondence of enumeration and actual rotation it defines, 
3619   // by comparing cumulative rotation matrix with sequence of rotations by axes
3620   const Standard_Real anAngle[3] = { 0.1, 0.2, 0.3 };
3621   for (int i = gp_Extrinsic_XYZ; i <= gp_Intrinsic_ZYZ; i++)
3622   {
3623     // Sequence of rotations
3624     gp_Mat aR[3];
3625     for (int j=0; j < 3; j++)
3626     {
3627       // note that current axis index is obtained by parsing of enumeration name!
3628       int anAxis = names[i - gp_Extrinsic_XYZ][10 + j] - 'X';
3629       Standard_ASSERT_RETURN (anAxis >=0 && anAxis <= 2, "Incorrect parsing of enumeration name", 1);
3630
3631       // Set point on axis corresponding to current rotation
3632       // We will apply rotation around this axis
3633       gp_XYZ v (0., 0., 0.);
3634       v.SetCoord (anAxis + 1, 1.);
3635       aR[j].SetRotation (v, anAngle[j]);
3636     }
3637
3638     // construct cumulative transformation (differently for extrinsic and intrinsic rotations);
3639     // note that we parse first symbol of the enum name to identify its type
3640     gp_Mat aRot;
3641     if (names[i - gp_Extrinsic_XYZ][0] == 'E') // extrinsic
3642     {
3643       aRot = aR[2] * aR[1] * aR[0];
3644     }
3645     else // intrinsic
3646     {
3647       aRot = aR[0] * aR[1] * aR[2];
3648     }
3649
3650     // set the same angles in quaternion
3651     aQuat.SetEulerAngles (gp_EulerSequence(i), anAngle[0], anAngle[1], anAngle[2]);
3652
3653     gp_Mat aRQ = aQuat.GetMatrix();
3654     gp_Mat aDiff = aRQ * aRot.Inverted() - aI;
3655     if (aDiff.Determinant() > 1e-5)
3656     {
3657       theDI << "Error: Euler angles conversion does not correspond to sequential rotations for " << names[i - gp_Extrinsic_XYZ] << "\n";
3658       isTestOk = Standard_False;
3659     }
3660   }
3661
3662   // similar checkfor YawPitchRoll sequence as defined in description of #25574
3663   {
3664     // Start with world coordinate system
3665     gp_Ax2 world;
3666
3667     // Perform three rotations using the yaw-pitch-roll convention.
3668     // This means: rotate around the original z axis with angle alpha,
3669     // then rotate around the new y axis with angle beta,
3670     // then rotate around the new x axis with angle gamma.
3671     alpha = 0.0 / 180.0 * M_PI;
3672     beta = -35.0 / 180.0 * M_PI;
3673     gamma = 90.0 / 180.0 * M_PI;
3674
3675     const gp_Quaternion rotationZ(world.Direction(), alpha);
3676     const gp_Vec rotY = rotationZ.Multiply(world.YDirection());
3677     const gp_Vec rotX = rotationZ.Multiply(world.XDirection());
3678
3679     const gp_Quaternion rotationY(rotY, beta);
3680     const gp_Vec rotZ = rotationY.Multiply(world.Direction());
3681     const gp_Vec rotRotX = rotationY.Multiply(rotX);
3682
3683     const gp_Quaternion rotationX(rotRotX, gamma);
3684     const gp_Vec rotRotZ = rotationX.Multiply(rotZ);
3685
3686     gp_Ax2 result(gp_Pnt(0.0, 0.0, 0.0), rotRotZ, rotRotX);
3687
3688     // Now compute the Euler angles
3689     gp_Trsf transformation;
3690     transformation.SetDisplacement(gp_Ax2(), result);
3691
3692     Standard_Real computedAlpha;
3693     Standard_Real computedBeta;
3694     Standard_Real computedGamma;
3695
3696     transformation.GetRotation().GetEulerAngles(gp_YawPitchRoll, computedAlpha, computedBeta, computedGamma);
3697
3698     // We expect now to get the same angles as we have used for our rotations
3699     if (Abs(alpha - computedAlpha) > 1e-5 || Abs(beta - computedBeta) > 1e-5 || Abs(gamma - computedGamma) > 1e-5)
3700     {
3701       theDI << "Error: unexpected values of Euler angles for YawPitchRoll sequence:\n";
3702       theDI << "alpha: " << alpha / M_PI * 180.0 << " and computed alpha: "
3703             << computedAlpha / M_PI * 180.0 << "\n";
3704       theDI << "beta: " << beta / M_PI * 180.0 << " and computed beta: "
3705             << computedBeta / M_PI * 180.0 << "\n";
3706       theDI << "gamma: " << gamma / M_PI * 180.0 << " and computed gamma: "
3707             << computedGamma / M_PI * 180.0 << "\n";
3708       isTestOk = Standard_False;
3709     }
3710   }
3711
3712   // test from #25946
3713   {
3714     gp_Quaternion q;
3715     q.Set(0.06766916507860499, 0.21848101129786085, 0.11994599260380681,0.9660744746954637);
3716
3717     q.GetEulerAngles(gp_Intrinsic_ZYX, alpha,beta, gamma);
3718     q.GetEulerAngles(gp_Extrinsic_XYZ, alpha2,beta2,gamma2);
3719
3720     // gp_Intrinsic_ZYX and gp_Extrinsic_XYZ should produce the same values of angles but in opposite order
3721     if (Abs(alpha - gamma2) > 1e-5 || Abs(beta - beta2) > 1e-5 || Abs(gamma - alpha2) > 1e-5)
3722     {
3723       theDI << "Error: Euler angles computed for gp_Intrinsic_ZYX and gp_Extrinsic_XYZ do not match:\n";
3724       theDI << "alpha: " << alpha / M_PI * 180.0 << " and " << alpha2 / M_PI * 180.0 << "\n";
3725       theDI << "beta: " << beta / M_PI * 180.0 << " and " << beta2 / M_PI * 180.0 << "\n";
3726       theDI << "gamma: " << gamma / M_PI * 180.0 << " and " << gamma2 / M_PI * 180.0 << "\n";
3727       isTestOk = Standard_False;
3728     }
3729   }
3730
3731   theDI << (isTestOk ? "Test completed" : "Test failed") << "\n";
3732   return 0;
3733 }
3734
3735 #include <TColGeom_Array1OfBSplineCurve.hxx>
3736 #include <TColStd_Array1OfReal.hxx>
3737 #include <TColGeom_HArray1OfBSplineCurve.hxx>
3738 #include <GeomConvert.hxx>
3739
3740 //=======================================================================
3741 //function : OCC26446
3742 //purpose  : 
3743 //=======================================================================
3744 Standard_Integer OCC26446 (Draw_Interpretor& di, 
3745                            Standard_Integer n, 
3746                            const char** a)
3747 {
3748   if (n != 4) {
3749     di << "Usage: OCC26446 r c1 c2\n";
3750     return 1;
3751   }
3752
3753   Handle(Geom_BSplineCurve) aCurve1 =
3754     Handle(Geom_BSplineCurve)::DownCast(DrawTrSurf::GetCurve(a[2]));
3755   Handle(Geom_BSplineCurve) aCurve2 = 
3756     Handle(Geom_BSplineCurve)::DownCast(DrawTrSurf::GetCurve(a[3]));
3757
3758   if (aCurve1.IsNull()) {
3759     di << a[2] << " is not a BSpline curve\n";
3760         return 1;
3761   }
3762
3763   if (aCurve2.IsNull()) {
3764     di << a[3] << " is not a BSpline curve\n";
3765         return 1;
3766   }
3767
3768   TColGeom_Array1OfBSplineCurve          aCurves     (0, 1);
3769   TColStd_Array1OfReal                   aTolerances (0, 0);
3770   Standard_Real                          aTolConf    = 1.e-3;
3771   Standard_Real                          aTolClosure = Precision::Confusion();
3772   Handle(TColGeom_HArray1OfBSplineCurve) aConcatCurves;
3773   Handle(TColStd_HArray1OfInteger)       anIndices;
3774
3775   aCurves.SetValue(0, aCurve1);
3776   aCurves.SetValue(1, aCurve2);
3777   aTolerances.SetValue(0, aTolConf);
3778
3779   GeomConvert::ConcatC1(aCurves,
3780                         aTolerances,
3781                         anIndices,
3782                         aConcatCurves,
3783                         Standard_False,
3784                         aTolClosure);
3785
3786   Handle(Geom_BSplineCurve) aResult =
3787     aConcatCurves->Value(aConcatCurves->Lower());
3788
3789   DrawTrSurf::Set(a[1], aResult);
3790   return 0;
3791 }
3792
3793 static Standard_Integer OCC26448 (Draw_Interpretor& theDI, Standard_Integer, const char **)
3794 {
3795   TColStd_SequenceOfReal aSeq1, aSeq2;
3796   aSeq1.Append(11.);
3797   aSeq1.Prepend (aSeq2);
3798   theDI << "TCollection: 11 -> " << aSeq1.First() << "\n";
3799
3800   NCollection_Sequence<Standard_Real> nSeq1, nSeq2;
3801   nSeq1.Append(11.);
3802   nSeq1.Prepend (nSeq2);
3803   theDI << "NCollection: 11 -> " << nSeq1.First() << "\n";
3804
3805   theDI << "OK";
3806   return 0;
3807 }
3808
3809 //=======================================================================
3810 //function : OCC26407
3811 //purpose  :
3812 //=======================================================================
3813 #include <BRepBuilderAPI_MakeWire.hxx>
3814 #include <BRepBuilderAPI_MakeEdge.hxx>
3815 #include <BRepMesh_IncrementalMesh.hxx>
3816 #include <TCollection_AsciiString.hxx>
3817 static Standard_Integer OCC26407 (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3818 {
3819   if (theArgNb != 2)
3820   {
3821     std::cerr << "Error: wrong number of arguments! See usage:\n";
3822     theDI.PrintHelp (theArgVec[0]);
3823     return 1;
3824   }
3825
3826   // Construct vertices.
3827   std::vector<TopoDS_Vertex> wire_vertices;
3828   wire_vertices.push_back(BRepBuilderAPI_MakeVertex(gp_Pnt(587.90000000000009094947, 40.6758179230516248026106, 88.5)));
3829   wire_vertices.push_back(BRepBuilderAPI_MakeVertex(gp_Pnt(807.824182076948432040808, 260.599999999999965893949, 88.5)));
3830   wire_vertices.push_back(BRepBuilderAPI_MakeVertex(gp_Pnt(644.174182076948454778176, 424.249999999999943156581, 88.5000000000000142108547)));
3831   wire_vertices.push_back(BRepBuilderAPI_MakeVertex(gp_Pnt(629.978025792618950617907, 424.25, 88.5)));
3832   wire_vertices.push_back(BRepBuilderAPI_MakeVertex(gp_Pnt(793.628025792618700506864, 260.599999999999852207111, 88.5)));
3833   wire_vertices.push_back(BRepBuilderAPI_MakeVertex(gp_Pnt(587.900000000000204636308, 54.8719742073813492311274, 88.5)));
3834   wire_vertices.push_back(BRepBuilderAPI_MakeVertex(gp_Pnt(218.521974207381418864315, 424.250000000000056843419, 88.5)));
3835   wire_vertices.push_back(BRepBuilderAPI_MakeVertex(gp_Pnt(204.325817923051886282337, 424.249999999999943156581, 88.5)));
3836
3837   // Construct wire.
3838   BRepBuilderAPI_MakeWire wire_builder;
3839   for (size_t i = 0; i < wire_vertices.size(); i++)
3840   {
3841     const TopoDS_Vertex &v = wire_vertices[i];
3842     const TopoDS_Vertex &w = wire_vertices[(i+1) % wire_vertices.size()];
3843
3844     wire_builder.Add(BRepBuilderAPI_MakeEdge(v, w));
3845   }
3846
3847   // Create face and triangulate it.
3848   // Construct face.
3849   gp_Pnt v0 = BRep_Tool::Pnt(wire_vertices[0]);
3850   gp_Pnt v1 = BRep_Tool::Pnt(wire_vertices[1]);
3851   gp_Pnt v2 = BRep_Tool::Pnt(wire_vertices[wire_vertices.size() - 1]);
3852
3853   gp_Vec face_normal = gp_Vec(v0, v1).Crossed(gp_Vec(v0, v2));
3854
3855   TopoDS_Face face = BRepBuilderAPI_MakeFace(gp_Pln(v0, face_normal), wire_builder);
3856   BRepMesh_IncrementalMesh m(face, 1e-7);
3857
3858   if (m.GetStatusFlags() != 0)
3859   {
3860     theDI << "Failed. Status for face constructed from vertices: " << m.GetStatusFlags() << "\n";
3861     return 1;
3862   }
3863   DBRep::Set(theArgVec[1], face);
3864   char buf[256];
3865   sprintf(buf, "isos %s 0", theArgVec[1]);
3866   theDI.Eval(buf);
3867
3868   sprintf(buf, "triangles %s", theArgVec[1]);
3869   theDI.Eval(buf);
3870
3871   theDI.Eval("smallview; fit");
3872
3873   theDI << "Test completed\n";
3874   return 0;
3875 }
3876
3877 //=======================================================================
3878 //function : OCC26485
3879 //purpose  :
3880 //=======================================================================
3881 #include <Poly.hxx>
3882 static Standard_Integer OCC26485 (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3883 {
3884   if (theArgNb != 2)
3885   {
3886     std::cerr << "Error: wrong number of arguments! See usage:\n";
3887     theDI.PrintHelp (theArgVec[0]);
3888     return 1;
3889   }
3890
3891   TopoDS_Shape aShape = DBRep::Get(theArgVec[1]);
3892   if (aShape.IsNull())
3893   {
3894     theDI << "Failed. Null shape\n";
3895     return 1;
3896   }
3897
3898   Standard_Boolean isFailed = Standard_False;
3899   TopExp_Explorer aExplorer(aShape, TopAbs_FACE);
3900   for (; aExplorer.More(); aExplorer.Next())
3901   {
3902     const TopoDS_Face& aFace = TopoDS::Face( aExplorer.Current() );
3903     TopLoc_Location L = TopLoc_Location();
3904     const Handle(Poly_Triangulation)& aT = BRep_Tool::Triangulation( aFace , L );
3905
3906     if(aT.IsNull())
3907       continue;
3908
3909     Poly::ComputeNormals(aT);
3910     const TColgp_Array1OfPnt&       aVertices = aT->Nodes();
3911     const TShort_Array1OfShortReal& aNormals  = aT->Normals();
3912
3913     // Number of nodes in the triangulation
3914     int aVertexNb = aT->Nodes().Length();
3915     if (aVertexNb*3 != aNormals.Length())
3916     {
3917       theDI << "Failed. Different number of normals vs. vertices\n";
3918       return 1;
3919     }
3920
3921     // Get each vertex index, checking common vertexes between shapes
3922     for( int i=0; i < aVertexNb; i++ )
3923     {
3924       gp_Pnt aPoint = aVertices.Value( i+1 );
3925       gp_Vec aNormal = gp_Vec(
3926         aNormals.Value( i*3 + 1 ),
3927         aNormals.Value( i*3 + 2 ),
3928         aNormals.Value( i*3 + 3 ) );
3929
3930       if (aNormal.X() == 0 && aNormal.Y() == 0 && aNormal.Z() == 1)
3931       {
3932         char buf[256];
3933         sprintf(buf, "fail_%d", i+1);
3934         theDI << "Failed. Point " << buf << ": "
3935               << aPoint.X() << " "
3936               << aPoint.Y() << " "
3937               << aPoint.Z() << "\n";
3938
3939         DrawTrSurf::Set (buf, aPoint);
3940       }
3941     }
3942   }
3943
3944   theDI << (isFailed ? "Test failed" : "Test completed") << "\n";
3945   return 0;
3946 }
3947
3948 //=======================================================================
3949 //function : OCC26553
3950 //purpose  :
3951 //=======================================================================
3952 #include <BRepBuilderAPI_MakeWire.hxx>
3953
3954 static Standard_Integer OCC26553 (Draw_Interpretor& theDI, Standard_Integer theArgc, const char** theArgv)
3955 {
3956   if (theArgc < 2)
3957   {
3958     theDI << "Error: path to file with shell is missing\n";
3959     return 1;
3960   }
3961
3962   BRep_Builder aBuilder;
3963   TopoDS_Shape aShell;
3964   BRepTools::Read(aShell, theArgv[1], aBuilder);
3965
3966   if (aShell.IsNull())
3967   {
3968     theDI << "Error: shell not loaded\n";
3969     return 1;
3970   }
3971
3972   TopoDS_Edge aPipeEdge = BRepBuilderAPI_MakeEdge (gp_Pnt (0, 0, 0), gp_Pnt (0, 0, 10));
3973   TopoDS_Wire aPipeWire = BRepBuilderAPI_MakeWire(aPipeEdge).Wire();
3974
3975   BRepOffsetAPI_MakePipe aPipeBuilder(aPipeWire, aShell);
3976   if (!aPipeBuilder.IsDone())
3977   {
3978     theDI << "Error: failed to create pipe\n";
3979     return 1;
3980   }
3981
3982   for (TopExp_Explorer aShapeExplorer(aShell, TopAbs_EDGE); aShapeExplorer.More(); aShapeExplorer.Next ()) {
3983     const TopoDS_Shape& aGeneratedShape = aPipeBuilder.Generated(aPipeEdge, aShapeExplorer.Current());
3984     if (aGeneratedShape.IsNull())
3985     {
3986       theDI << "Error: null shape\n";
3987       return 1;
3988     }
3989   }
3990
3991   theDI << "History returned successfully\n";
3992   return 0;
3993 }
3994
3995 //=======================================================================
3996 //function : OCC26195
3997 //purpose  :
3998 //=======================================================================
3999 #include <SelectMgr_SelectingVolumeManager.hxx>
4000 #include <BRepBuilderAPI_MakePolygon.hxx>
4001 #include <Geom_CartesianPoint.hxx>
4002 #include <AIS_Line.hxx>
4003 #include <Aspect_Window.hxx>
4004 static Standard_Integer OCC26195 (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
4005 {
4006   if (theArgNb < 3)
4007   {
4008     std::cerr << "Error: wrong number of arguments! See usage:\n";
4009     theDI.PrintHelp (theArgVec[0]);
4010     return 1;
4011   }
4012
4013   if (ViewerTest::GetAISContext().IsNull())
4014   {
4015     std::cerr << "Error: No opened context!\n";
4016     return 1;
4017   }
4018
4019   gp_Pnt2d aPxPnt1, aPxPnt2;
4020   aPxPnt1.SetX (Draw::Atof (theArgVec[1]));
4021   aPxPnt1.SetY (Draw::Atof (theArgVec[2]));
4022   if (theArgNb > 4)
4023   {
4024     aPxPnt2.SetX (Draw::Atof (theArgVec[3]));
4025     aPxPnt2.SetY (Draw::Atof (theArgVec[4]));
4026   }
4027   Standard_Boolean toPrint = Standard_False;
4028   if (theArgNb % 2 == 0)
4029   {
4030     toPrint = Draw::Atoi (theArgVec[theArgNb - 1]) != 0;
4031   }
4032
4033   SelectMgr_SelectingVolumeManager* aMgr = new SelectMgr_SelectingVolumeManager();
4034   aMgr->SetActiveSelectionType (theArgNb > 4 ?
4035     SelectMgr_SelectingVolumeManager::Box : SelectMgr_SelectingVolumeManager::Point);
4036   aMgr->SetCamera (ViewerTest::CurrentView()->Camera());
4037   aMgr->SetPixelTolerance (ViewerTest::GetAISContext()->PixelTolerance());
4038   Standard_Integer aWidth, aHeight;
4039   ViewerTest::CurrentView()->View()->Window()->Size (aWidth, aHeight);
4040   aMgr->SetWindowSize (aWidth, aHeight);
4041   if (theArgNb > 4)
4042   {
4043     aMgr->BuildSelectingVolume (aPxPnt1, aPxPnt2);
4044   }
4045   else
4046   {
4047     aMgr->BuildSelectingVolume (aPxPnt1);
4048   }
4049   const gp_Pnt* aVerts = aMgr->GetVertices();
4050   gp_Pnt aNearPnt = aMgr->GetNearPickedPnt();
4051   gp_Pnt aFarPnt  = aMgr->GetFarPickedPnt();
4052   BRepBuilderAPI_MakePolygon aWireBldrs[4];
4053
4054   aWireBldrs[0].Add (gp_Pnt (aVerts[0].X(), aVerts[0].Y(), aVerts[0].Z()));
4055   aWireBldrs[0].Add (gp_Pnt (aVerts[4].X(), aVerts[4].Y(), aVerts[4].Z()));
4056   aWireBldrs[0].Add (gp_Pnt (aVerts[6].X(), aVerts[6].Y(), aVerts[6].Z()));
4057   aWireBldrs[0].Add (gp_Pnt (aVerts[2].X(), aVerts[2].Y(), aVerts[2].Z()));
4058   aWireBldrs[0].Add (gp_Pnt (aVerts[0].X(), aVerts[0].Y(), aVerts[0].Z()));
4059
4060   aWireBldrs[1].Add (gp_Pnt (aVerts[4].X(), aVerts[4].Y(), aVerts[4].Z()));
4061   aWireBldrs[1].Add (gp_Pnt (aVerts[5].X(), aVerts[5].Y(), aVerts[5].Z()));
4062   aWireBldrs[1].Add (gp_Pnt (aVerts[7].X(), aVerts[7].Y(), aVerts[7].Z()));
4063   aWireBldrs[1].Add (gp_Pnt (aVerts[6].X(), aVerts[6].Y(), aVerts[6].Z()));
4064   aWireBldrs[1].Add (gp_Pnt (aVerts[4].X(), aVerts[4].Y(), aVerts[4].Z()));
4065
4066   aWireBldrs[2].Add (gp_Pnt (aVerts[1].X(), aVerts[1].Y(), aVerts[1].Z()));
4067   aWireBldrs[2].Add (gp_Pnt (aVerts[5].X(), aVerts[5].Y(), aVerts[5].Z()));
4068   aWireBldrs[2].Add (gp_Pnt (aVerts[7].X(), aVerts[7].Y(), aVerts[7].Z()));
4069   aWireBldrs[2].Add (gp_Pnt (aVerts[3].X(), aVerts[3].Y(), aVerts[3].Z()));
4070   aWireBldrs[2].Add (gp_Pnt (aVerts[1].X(), aVerts[1].Y(), aVerts[1].Z()));
4071
4072   aWireBldrs[3].Add (gp_Pnt (aVerts[0].X(), aVerts[0].Y(), aVerts[0].Z()));
4073   aWireBldrs[3].Add (gp_Pnt (aVerts[1].X(), aVerts[1].Y(), aVerts[1].Z()));
4074   aWireBldrs[3].Add (gp_Pnt (aVerts[3].X(), aVerts[3].Y(), aVerts[3].Z()));
4075   aWireBldrs[3].Add (gp_Pnt (aVerts[2].X(), aVerts[2].Y(), aVerts[2].Z()));
4076   aWireBldrs[3].Add (gp_Pnt (aVerts[0].X(), aVerts[0].Y(), aVerts[0].Z()));
4077
4078   TopoDS_Compound aComp;
4079   BRep_Builder    aCompBuilder;
4080   aCompBuilder.MakeCompound (aComp);
4081   for (Standard_Integer aWireIdx = 0; aWireIdx < 4; ++aWireIdx)
4082   {
4083     aCompBuilder.Add (aComp, aWireBldrs[aWireIdx].Shape());
4084   }
4085   DBRep::Set ("c", aComp);
4086
4087   Handle(AIS_InteractiveObject) aCmp = new AIS_Shape (aComp);
4088   aCmp->SetColor (Quantity_NOC_GREEN);
4089   ViewerTest::Display ("c", aCmp, Standard_True, Standard_True);
4090
4091   Handle(Geom_CartesianPoint) aPnt1 = new Geom_CartesianPoint (aNearPnt);
4092   Handle(Geom_CartesianPoint) aPnt2 = new Geom_CartesianPoint (aFarPnt);
4093
4094   Handle(AIS_Line) aLine = new AIS_Line (aPnt1, aPnt2);
4095   ViewerTest::Display ("l", aLine, Standard_True, Standard_True);
4096
4097   if (toPrint)
4098   {
4099     theDI << "Near: " << aNearPnt.X() << " " << aNearPnt.Y() << " " << aNearPnt.Z() << "\n";
4100     theDI << "Far: " << aFarPnt.X() << " " << aFarPnt.Y() << " " << aFarPnt.Z() << "\n";
4101   }
4102
4103   return 0;
4104 }
4105
4106 //=======================================================================
4107 //function : OCC26462
4108 //purpose  :
4109 //=======================================================================
4110 static Standard_Integer OCC26462 (Draw_Interpretor& theDI, Standard_Integer /*theArgNb*/, const char** /*theArgVec*/)
4111 {
4112   if (ViewerTest::GetAISContext().IsNull())
4113   {
4114     std::cerr << "Error: No opened context!\n";
4115     return 1;
4116   }
4117
4118   BRepPrimAPI_MakeBox aBuilder1 (gp_Pnt (10.0, 10.0, 0.0), 10.0, 10.0, 10.0);
4119   BRepPrimAPI_MakeBox aBuilder2 (10.0, 10.0, 10.0);
4120   Handle(AIS_InteractiveObject) aBox1 = new AIS_Shape (aBuilder1.Shape());
4121   Handle(AIS_InteractiveObject) aBox2 = new AIS_Shape (aBuilder2.Shape());
4122
4123   const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4124   aCtx->Display (aBox1, 0, 2, Standard_False);
4125   aCtx->Display (aBox2, 0, 2, Standard_False);
4126   ViewerTest::CurrentView()->FitAll();
4127   aCtx->SetWidth (aBox1, 3, Standard_False);
4128   aCtx->SetWidth (aBox2, 3, Standard_False);
4129
4130   aCtx->MoveTo (305, 322, ViewerTest::CurrentView(), Standard_False);
4131   aCtx->ShiftSelect (Standard_False);
4132   aCtx->MoveTo (103, 322, ViewerTest::CurrentView(), Standard_False);
4133   aCtx->ShiftSelect (Standard_False);
4134   if (aCtx->NbSelected() != 0)
4135   {
4136     theDI << "ERROR: no boxes must be selected!\n";
4137     return 1;
4138   }
4139
4140   aCtx->SetSelectionSensitivity (aBox1, 2, 5);
4141
4142   aCtx->MoveTo (305, 322, ViewerTest::CurrentView(), Standard_False);
4143   aCtx->ShiftSelect (Standard_False);
4144   if (aCtx->NbSelected() != 1)
4145   {
4146     theDI << "ERROR: b1 was not selected\n";
4147     return 1;
4148   }
4149   aCtx->MoveTo (103, 322, ViewerTest::CurrentView(), Standard_False);
4150   aCtx->ShiftSelect (Standard_True);
4151   if (aCtx->NbSelected() != 1)
4152   {
4153     theDI << "ERROR: b2 is selected after b1's tolerance increased\n";
4154     return 1;
4155   }
4156
4157   return 0;
4158 }
4159
4160
4161 #include <BRepBuilderAPI_GTransform.hxx>
4162 static Standard_Integer OCC26313(Draw_Interpretor& di,Standard_Integer n,const char** a)
4163 {
4164   if (n <= 1) return 1;
4165   
4166   gp_Trsf T;
4167   gp_GTrsf GT(T);
4168   
4169   gp_Mat rot( 1.0, 0.0, 0.0,
4170               0.0, 2.0, 0.0,
4171               0.0, 0.0, 3.0);
4172   
4173   GT.SetVectorialPart(rot);
4174   BRepBuilderAPI_GTransform gtrf(GT);
4175
4176   TopoDS_Shape aSrcShape = DBRep::Get(a[2]);
4177   if (aSrcShape.IsNull()) {
4178     di << a[2] << " is not a valid shape\n";
4179     return 1;
4180   }
4181
4182   
4183   gtrf.Perform(aSrcShape);
4184   if (gtrf.IsDone())
4185   {
4186     try
4187     {
4188       DBRep::Set(a[1], gtrf.ModifiedShape(aSrcShape));
4189     }
4190     catch(Standard_Failure)
4191     {
4192       di << "Error: Exception is thrown\n";
4193     }
4194   }
4195   else
4196   {
4197     di << "Error: Result is not done\n";
4198     return 1;
4199   }
4200   
4201   return 0;
4202 }
4203
4204 //=======================================================================
4205 //function : OCC26525
4206 //purpose  : check number of intersection points
4207 //=======================================================================
4208 #include <BRepAdaptor_Curve.hxx>
4209 #include <BRepAdaptor_Surface.hxx>
4210 #include <BRepAdaptor_HCurve.hxx>
4211 #include <BRepAdaptor_HSurface.hxx>
4212 #include <IntCurveSurface_HInter.hxx>
4213 Standard_Integer OCC26525 (Draw_Interpretor& di, 
4214                            Standard_Integer n, 
4215                            const char** a)
4216 {
4217   TopoDS_Shape aS1, aS2;
4218   TopoDS_Edge aE; 
4219   TopoDS_Face aF;
4220
4221   if (n<4)
4222   {
4223     di << " use OCC26525 r edge face \n";
4224     return 1;
4225   }
4226
4227   aS1 = DBRep::Get(a[2]);
4228   aS2 = DBRep::Get(a[3]);
4229
4230   if (aS1.IsNull() || aS2.IsNull())
4231   {
4232     di << " Null shapes are not allowed \n";
4233     return 0;
4234   }
4235   if (aS1.ShapeType()!=TopAbs_EDGE)
4236   {
4237     di << " Shape" << a[2] << " should be of type EDGE\n";
4238     return 0;
4239   }
4240   if (aS2.ShapeType()!=TopAbs_FACE)
4241   {
4242     di << " Shape" << a[3] << " should be of type FACE\n";
4243     return 0;
4244   }
4245
4246   aE=TopoDS::Edge(aS1);
4247   aF=TopoDS::Face(aS2);
4248
4249   char buf[128];
4250   Standard_Boolean bIsDone;
4251   Standard_Integer i, aNbPoints;
4252   Standard_Real aU, aV, aT;
4253   gp_Pnt aP;
4254   BRepAdaptor_Curve aBAC;
4255   BRepAdaptor_Surface aBAS;
4256   IntCurveSurface_TransitionOnCurve aTC;
4257   IntCurveSurface_HInter aHInter;
4258
4259   aBAC.Initialize(aE);
4260   aBAS.Initialize(aF);
4261
4262   Handle(BRepAdaptor_HCurve) aHBAC=new BRepAdaptor_HCurve(aBAC);
4263   Handle(BRepAdaptor_HSurface) aHBAS = new BRepAdaptor_HSurface(aBAS);
4264
4265   aHInter.Perform(aHBAC, aHBAS);
4266   bIsDone=aHInter.IsDone();
4267   if (!bIsDone)
4268   {
4269     di << " intersection is not done\n";
4270     return 0;
4271   }
4272
4273   aNbPoints=aHInter.NbPoints();
4274   sprintf (buf, " Number of intersection points found: %d", aNbPoints);
4275   di <<  buf << "\n";
4276   for (i=1; i<=aNbPoints; ++i)
4277   {
4278     const IntCurveSurface_IntersectionPoint& aIP=aHInter.Point(i);
4279     aIP.Values(aP, aU, aV, aT, aTC);
4280     //
4281     sprintf (buf, "point %s_%d %lg %lg %lg  ", a[1], i, aP.X(), aP.Y(), aP.Z());
4282     di << buf << "\n";
4283   }
4284
4285   return 0;
4286 }
4287
4288 //=======================================================================
4289 //function : OCC24537
4290 //purpose  : Puts inverted numbers (in the sense of little/big endian inversion)
4291 //           from predefined arrays.
4292 //=======================================================================
4293 #include <FSD_BinaryFile.hxx>
4294
4295 template<int size>
4296 inline const unsigned char* SizeRef ();
4297
4298 template<>
4299 inline const unsigned char* SizeRef <8> ()
4300 {
4301   static const unsigned char aSizeRef[] = {
4302     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
4303     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,
4304     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
4305     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,
4306     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,
4307     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,
4308     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,
4309     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,
4310     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09,
4311     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
4312   return aSizeRef;
4313 }
4314
4315 template<>
4316 inline const unsigned char* SizeRef <4> ()
4317 {
4318   static const unsigned char aSizeRef[] = {
4319     0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x02,
4320     0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x04,
4321     0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x06,
4322     0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x08,
4323     0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x00};
4324   return aSizeRef;
4325 }
4326
4327 static Standard_Integer OCC24537(
4328   Draw_Interpretor& theDI, 
4329   Standard_Integer  argc, 
4330   const char **     argv)
4331 {
4332   std::ofstream aF;
4333   if (argc > 1)
4334   {
4335     aF.open(argv[1]);
4336     if (!aF.is_open())
4337     {
4338       cout << "cannot create file " << argv[1] << endl;
4339       return 1;
4340     }
4341   }
4342   Standard_Boolean isErr = Standard_False;
4343   // 1. InverseInt
4344   const unsigned char anIntRef[] = {
4345     0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x02,
4346     0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x04,
4347     0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x06,
4348     0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x08,
4349     0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x00};
4350   Standard_Integer anIntArr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
4351   if (aF.is_open())
4352   {
4353     for(int i = 0; i < 10; ++i)
4354     {
4355       Standard_Integer anInv = FSD_BinaryFile::InverseInt(anIntArr[i]);
4356       aF.write(reinterpret_cast<char*>(&anInv), sizeof(anInv));
4357     }
4358   }
4359   else
4360   {
4361     Standard_Integer anInv[10];
4362     for(int i = 0; i < 10; ++i)
4363       anInv[i] = FSD_BinaryFile::InverseInt(anIntArr[i]);
4364     if (memcmp(anInv, anIntRef, sizeof(anIntRef)) != 0)
4365     {
4366       theDI << "Error: incorrect conversion of an integer value\n";
4367       isErr = Standard_True;
4368     }
4369   }
4370   
4371   // 1a. Random InverseInt
4372   const unsigned char aRndIntRef[] = {
4373     0xFF,0xC2,0xF7,0x00,0xFF,0xFF,0xFB,0x2E,
4374     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
4375     0x00,0x00,0x04,0xD2,0x00,0x00,0x04,0xD3,
4376     0xFF,0xFF,0xFD,0x1E,0xFF,0xFF,0xFF,0xFB,
4377     0x00,0x00,0x03,0x8D,0x00,0x3D,0x09,0x00};
4378   Standard_Integer aRndIntArr[] = {-4000000, -1234, 0, 1, 1234, 1235, -738, -5, 909, 4000000};
4379   if (aF.is_open())
4380   {
4381     for(int i = 0; i < 10; ++i)
4382     {
4383       Standard_Integer anInv = FSD_BinaryFile::InverseInt(aRndIntArr[i]);
4384       aF.write(reinterpret_cast<char*>(&anInv), sizeof(anInv));
4385     }
4386   }
4387   else
4388   {
4389     Standard_Integer anInv[10];
4390     for(int i = 0; i < 10; ++i)
4391       anInv[i] = FSD_BinaryFile::InverseInt(aRndIntArr[i]);
4392     if (memcmp(anInv, aRndIntRef, sizeof(aRndIntRef)) != 0)
4393     {
4394       theDI << "Error: incorrect conversion of a dispersed integer value\n";
4395       isErr = Standard_True;
4396     }
4397   }
4398   
4399   // 2. InverseReal
4400   const unsigned char aRealRef[] = {
4401     0x3F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
4402     0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
4403     0x40,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
4404     0x40,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
4405     0x40,0x14,0x00,0x00,0x00,0x00,0x00,0x00,
4406     0x40,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
4407     0x40,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,
4408     0x40,0x20,0x00,0x00,0x00,0x00,0x00,0x00,
4409     0x40,0x22,0x00,0x00,0x00,0x00,0x00,0x00,
4410     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
4411   const Standard_Real aRealArr[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 0.0};
4412   if (aF.is_open())
4413   {
4414     for(int i = 0; i < 10; ++i)
4415     {
4416       Standard_Real anInv = FSD_BinaryFile::InverseReal(aRealArr[i]);
4417       aF.write(reinterpret_cast<char*>(&anInv), sizeof(anInv));
4418     }
4419   }
4420   else
4421   {
4422     Standard_Real anInv[10];
4423     for(int i = 0; i < 10; ++i)
4424       anInv[i] = FSD_BinaryFile::InverseReal(aRealArr[i]);
4425     if (memcmp(anInv, aRealRef, sizeof(aRealRef)) != 0)
4426     {
4427       theDI << "Error: incorrect conversion of a real value\n";
4428       isErr = Standard_True;
4429     }
4430   }
4431
4432   // 2a. Random InverseReal
4433   const unsigned char aRndRealRef[] = {
4434     0xFE,0x37,0xE4,0x3C,0x88,0x00,0x75,0x9C,
4435     0xBE,0x11,0x2E,0x0B,0xE8,0x26,0xD6,0x95,
4436     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
4437     0x3E,0x11,0x2E,0x0B,0xE8,0x26,0xD6,0x95,
4438     0x3F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
4439     0x40,0x09,0x21,0xDA,0x45,0x5B,0x53,0xE4,
4440     0x54,0xB2,0x49,0xAD,0x25,0x94,0xC3,0x7D,
4441     0x40,0x20,0x00,0x00,0x00,0x00,0x00,0x00,
4442     0xC0,0x23,0xCC,0xCC,0xCC,0xCC,0xCC,0xCD,
4443     0x40,0x23,0xCC,0xCC,0xCC,0xCC,0xCC,0xCD};
4444   const Standard_Real aRndRealArr[] = {-1e300, -1.e-9, 0., 1.e-9, 1., 3.1415296, 1.e100, 8.0, -9.9, 9.9};
4445   if (aF.is_open())
4446   {
4447     for(int i = 0; i < 10; ++i)
4448     {
4449       Standard_Real anInv = FSD_BinaryFile::InverseReal(aRndRealArr[i]);
4450       aF.write(reinterpret_cast<char*>(&anInv), sizeof(anInv));
4451     }
4452   }
4453   else
4454   {
4455     Standard_Real anInv[10];
4456     for(int i = 0; i < 10; ++i)
4457       anInv[i] = FSD_BinaryFile::InverseReal(aRndRealArr[i]);
4458     if (memcmp(anInv, aRndRealRef, sizeof(aRndRealRef)) != 0)
4459     {
4460       theDI << "Error: incorrect conversion of a dispersed real value\n";
4461       isErr = Standard_True;
4462     }
4463   }
4464
4465   // 3. InverseShortReal
4466   const unsigned char aShortRealRef[] = {
4467     0x3F,0x80,0x00,0x00,0x40,0x00,0x00,0x00,
4468     0x40,0x40,0x00,0x00,0x40,0x80,0x00,0x00,
4469     0x40,0xA0,0x00,0x00,0x40,0xC0,0x00,0x00,
4470     0x40,0xE0,0x00,0x00,0x41,0x00,0x00,0x00,
4471     0x41,0x10,0x00,0x00,0x00,0x00,0x00,0x00};
4472   const Standard_ShortReal aShortRealArr[] = {
4473     1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 0.0f};
4474   if (aF.is_open())
4475   {
4476     for(int i = 0; i < 10; ++i)
4477     {
4478       Standard_ShortReal anInv = FSD_BinaryFile::InverseShortReal(aShortRealArr[i]);
4479       aF.write(reinterpret_cast<char*>(&anInv), sizeof(anInv));
4480     }
4481   }
4482   else
4483   {
4484     Standard_ShortReal anInv[10];
4485     for(int i = 0; i < 10; ++i)
4486       anInv[i] = FSD_BinaryFile::InverseShortReal(aShortRealArr[i]);
4487     if (memcmp(anInv, aShortRealRef, sizeof(aShortRealRef)) != 0)
4488     {
4489       theDI << "Error: incorrect conversion of a short real value\n";
4490       isErr = Standard_True;
4491     }
4492   }
4493
4494   // 3a. Random InverseShortReal
4495   const unsigned char aRndShortRealRef[] = {
4496     0xB0,0x89,0x70,0x5F,0x00,0x00,0x00,0x00,
4497     0x30,0x89,0x70,0x5F,0x3F,0x80,0x00,0x00,
4498     0x40,0x49,0x0E,0x56,0xC0,0xD6,0x66,0x66,
4499     0x40,0xD6,0x66,0x66,0x42,0xC5,0xCC,0xCD,
4500     0xC2,0xC7,0xCC,0xCD,0x42,0xC7,0xCC,0xCD};
4501   const Standard_ShortReal aRndShortRealArr[] = {
4502     -1.e-9f, 0.f, 1.e-9f, 1.f, 3.1415f, -6.7f, 6.7f, 98.9f, -99.9f, 99.9f};
4503   if (aF.is_open())
4504   {
4505     for(int i = 0; i < 10; ++i)
4506     {
4507       Standard_ShortReal anInv = FSD_BinaryFile::InverseShortReal(aRndShortRealArr[i]);
4508       aF.write(reinterpret_cast<char*>(&anInv), sizeof(anInv));
4509     }
4510   }
4511   else
4512   {
4513     Standard_ShortReal anInv[10];
4514     for(int i = 0; i < 10; ++i)
4515       anInv[i] = FSD_BinaryFile::InverseShortReal(aRndShortRealArr[i]);
4516     if (memcmp(anInv, aRndShortRealRef, sizeof(aRndShortRealRef)) != 0)
4517     {
4518       theDI << "Error: incorrect conversion of a dispersed short real value\n";
4519       isErr = Standard_True;
4520     }
4521   }
4522
4523   // 4. InverseSize
4524   const Standard_Size aSizeArr[] = {1ul, 2ul, 3ul, 4ul, 5ul, 6ul, 7ul, 8ul, 9ul, 0ul};
4525   if (aF.is_open())
4526   {
4527     for(int i = 0; i < 10; ++i)
4528     {
4529       Standard_Size anInv = FSD_BinaryFile::InverseSize(aSizeArr[i]);
4530       aF.write(reinterpret_cast<char*>(&anInv), sizeof(anInv));
4531     }
4532   }
4533   else
4534   {
4535     Standard_Size anInv[10];
4536     const unsigned char* aSizeRef = SizeRef<sizeof(Standard_Size)>();
4537     for(int i = 0; i < 10; ++i)
4538       anInv[i] = FSD_BinaryFile::InverseSize(aSizeArr[i]);
4539     if (memcmp(anInv, aSizeRef, sizeof(Standard_Size)*10) != 0)
4540     {
4541       theDI << "Error: incorrect conversion of a size value\n";
4542       isErr = Standard_True;
4543     }
4544   }
4545
4546   if (!aF.is_open() && !isErr)
4547     theDI << "Conversion was done OK";
4548   if (aF.is_open())
4549   {
4550     cout << "the file " << argv[1] << " has been created" << endl;
4551     aF.close();
4552   }
4553   return 0;
4554 }
4555
4556
4557 #include <TopExp.hxx>
4558 #include <BRepOffsetAPI_DraftAngle.hxx>
4559 #include <vector>
4560 static TopoDS_Shape taper(const TopoDS_Shape &shape, const TopoDS_Face &face_a, const TopoDS_Face &face_b, Standard_Real angle)
4561 {
4562   // Use maximum face-to-taper z-offset.
4563   const gp_Pln neutral_plane(gp_Ax3(gp_Pnt(0.0, 0.0, 140.0), gp_Dir(0.0, 0.0, 1.0)));
4564
4565   // Draft angle needs to be in radians, and flipped to adhere to our own (arbitrary) draft
4566   // angle definition.
4567   const Standard_Real draft_angle = -(angle / 180.0) * M_PI;
4568
4569   // Add face to draft. The first argument indicates that all material added/removed during
4570   // drafting is located below the neutral plane
4571   BRepOffsetAPI_DraftAngle drafter(shape);
4572   drafter.Add(face_a, gp_Dir(0.0, 0.0, -1.0), draft_angle, neutral_plane);
4573   drafter.Add(face_b, gp_Dir(0.0, 0.0, -1.0), draft_angle, neutral_plane);
4574   drafter.Build();
4575
4576   return drafter.Shape();
4577 }
4578
4579 static void dumpShapeVertices(const TopoDS_Shape &shape, std::vector<Standard_Real>& coords)
4580 {
4581   TopTools_IndexedMapOfShape shape_vertices;
4582   TopExp::MapShapes(shape, TopAbs_VERTEX, shape_vertices);
4583
4584   for (Standard_Integer i = 1; i <= shape_vertices.Extent(); i++)
4585   {
4586     gp_Pnt p = BRep_Tool::Pnt(TopoDS::Vertex(shape_vertices(i)));
4587     coords.push_back(p.X());
4588     coords.push_back(p.Y());
4589     coords.push_back(p.Z());
4590   }
4591 }
4592
4593 static void GetCoords(const Standard_CString& path_to_file, std::vector<Standard_Real>& coords)
4594 {
4595   TopoDS_Shape shape;
4596   BRep_Builder builder;
4597   BRepTools::Read(shape, path_to_file, builder);
4598   TopTools_IndexedMapOfShape shape_faces;
4599   TopExp::MapShapes(shape, TopAbs_FACE, shape_faces);
4600   TopoDS_Face face_a = TopoDS::Face(shape_faces(1));
4601   TopoDS_Face face_b = TopoDS::Face(shape_faces(5));
4602   dumpShapeVertices(taper(shape, face_a, face_b, 5.0), coords);
4603 }
4604
4605 static Standard_Integer OCC26396 (Draw_Interpretor& theDI, Standard_Integer theArgc, const char** theArgv)
4606 {
4607   if (theArgc < 2)
4608   {
4609     theDI << "Error: path to file is missing\n";
4610     return 1;
4611   }
4612
4613   const int maxInd = 50;
4614
4615   std::vector<Standard_Real> ref_coords;
4616   ref_coords.reserve(100);
4617   Standard_Boolean Stat = Standard_True;
4618
4619   GetCoords(theArgv[1], ref_coords);
4620
4621   std::vector<Standard_Real> coords;
4622   coords.reserve(100);
4623   for (int i = 1; i < maxInd; i++)
4624   {
4625     GetCoords(theArgv[1], coords);
4626     if (coords.size() != ref_coords.size())
4627     {
4628       Stat = Standard_False;
4629       break;
4630     }
4631     for (size_t j = 0; j < coords.size(); j++)
4632       if (Abs(ref_coords[j] - coords[j]) > RealEpsilon())
4633       {
4634         Stat = Standard_False;
4635         break;
4636       }
4637     coords.clear();
4638   }
4639   if (!Stat)
4640     theDI << "Error: unstable results";
4641   else
4642     theDI << "test OK";
4643
4644   return 0;
4645 }
4646
4647 //=======================================================================
4648 //function : OCC26750 
4649 //purpose  : 
4650 //=======================================================================
4651 static Standard_Integer OCC26750( Draw_Interpretor& theDI,
4652                                   Standard_Integer  /*theNArg*/,
4653                                   const char ** /*theArgVal*/)
4654 {
4655   const gp_Vec2d aVec1(1.0, 0.0);
4656   const gp_Vec2d aVec2(0.0, -1.0);
4657
4658   if(aVec1.IsNormal(aVec2, Precision::Angular()))
4659   {
4660     theDI << "gp_Vec2d OK. Vectors are normal.\n";
4661   }
4662   else
4663   {
4664     theDI << "Error in gp_Vec2d. Vectors should be normal.\n";
4665   }
4666
4667   const gp_Dir2d aD1(1.0, 0.0);
4668   const gp_Dir2d aD2(0.0, -1.0);
4669
4670   if(aD1.IsNormal(aD2, Precision::Angular()))
4671   {
4672     theDI << "gp_Dir2d OK. Vectors are normal.\n";
4673   }
4674   else
4675   {
4676     theDI << "Error in gp_Dir2d. Vectors should be normal.\n";
4677   }
4678   
4679   return 0;
4680 }
4681
4682 //=======================================================================
4683 //function : OCC26746 
4684 //purpose  : Checks if coefficients of the torus are computed properly.
4685 //=======================================================================
4686 #include <Geom_ToroidalSurface.hxx>
4687 #include <Geom_BSplineCurve.hxx>
4688 static Standard_Integer OCC26746(
4689   Draw_Interpretor& theDI, 
4690   Standard_Integer  theNArg, 
4691   const char **     theArgVal)
4692 {
4693   if(theNArg < 2)
4694   {
4695     theDI << "Use: OCC26746 torus [toler NbCheckedPoints]\n";
4696     return 1;
4697   }
4698
4699   const Handle(Geom_ToroidalSurface) aGtor = 
4700     Handle(Geom_ToroidalSurface)::DownCast(DrawTrSurf::GetSurface(theArgVal[1]));
4701
4702   const Standard_Real aToler = (theNArg >= 3)? Draw::Atof(theArgVal[2]) : 1.0e-7;
4703   const Standard_Integer aNbPntsMax = (theNArg >= 4)? Draw::Atoi(theArgVal[3]) : 5;
4704
4705   const Standard_Integer aLowIndex = 5;
4706   const Standard_Real aStep = 2.0*M_PI/aNbPntsMax;
4707
4708   TColStd_Array1OfReal anArrCoeffs(aLowIndex, aLowIndex+34);
4709   aGtor->Torus().Coefficients(anArrCoeffs);
4710
4711   Standard_Real aUpar = 0.0, aVpar = 0.0;
4712   for(Standard_Integer aUind = 0; aUind <= aNbPntsMax; aUind++)
4713   {
4714     for(Standard_Integer aVind = 0; aVind <= aNbPntsMax; aVind++)
4715     {
4716       const gp_Pnt aPt(aGtor->Value(aUpar, aVpar));
4717       const Standard_Real aX1 = aPt.X();
4718       const Standard_Real aX2 = aX1*aX1;
4719       const Standard_Real aX3 = aX2*aX1;
4720       const Standard_Real aX4 = aX2*aX2;
4721       const Standard_Real aY1 = aPt.Y();
4722       const Standard_Real aY2 = aY1*aY1;
4723       const Standard_Real aY3 = aY2*aY1;
4724       const Standard_Real aY4 = aY2*aY2;
4725       const Standard_Real aZ1 = aPt.Z();
4726       const Standard_Real aZ2 = aZ1*aZ1;
4727       const Standard_Real aZ3 = aZ2*aZ1;
4728       const Standard_Real aZ4 = aZ2*aZ2;
4729
4730       Standard_Integer i = aLowIndex;
4731
4732       Standard_Real aDelta =  anArrCoeffs(i++) * aX4;  //1
4733       aDelta+= anArrCoeffs(i++) * aY4;                 //2
4734       aDelta+= anArrCoeffs(i++) * aZ4;                 //3
4735       aDelta+= anArrCoeffs(i++) * aX3 * aY1;           //4
4736       aDelta+= anArrCoeffs(i++) * aX3 * aZ1;           //5
4737       aDelta+= anArrCoeffs(i++) * aY3 * aX1;           //6
4738       aDelta+= anArrCoeffs(i++) * aY3 * aZ1;           //7
4739       aDelta+= anArrCoeffs(i++) * aZ3 * aX1;           //8
4740       aDelta+= anArrCoeffs(i++) * aZ3 * aY1;           //9
4741       aDelta+= anArrCoeffs(i++) * aX2 * aY2;           //10
4742       aDelta+= anArrCoeffs(i++) * aX2 * aZ2;           //11
4743       aDelta+= anArrCoeffs(i++) * aY2 * aZ2;           //12
4744       aDelta+= anArrCoeffs(i++) * aX2 * aY1 * aZ1;     //13
4745       aDelta+= anArrCoeffs(i++) * aX1 * aY2 * aZ1;     //14
4746       aDelta+= anArrCoeffs(i++) * aX1 * aY1 * aZ2;     //15
4747       aDelta+= anArrCoeffs(i++) * aX3;                 //16
4748       aDelta+= anArrCoeffs(i++) * aY3;                 //17
4749       aDelta+= anArrCoeffs(i++) * aZ3;                 //18
4750       aDelta+= anArrCoeffs(i++) * aX2 * aY1;           //19
4751       aDelta+= anArrCoeffs(i++) * aX2 * aZ1;           //20
4752       aDelta+= anArrCoeffs(i++) * aY2 * aX1;           //21
4753       aDelta+= anArrCoeffs(i++) * aY2 * aZ1;           //22
4754       aDelta+= anArrCoeffs(i++) * aZ2 * aX1;           //23
4755       aDelta+= anArrCoeffs(i++) * aZ2 * aY1;           //24
4756       aDelta+= anArrCoeffs(i++) * aX1 * aY1 * aZ1;     //25
4757       aDelta+= anArrCoeffs(i++) * aX2;                 //26
4758       aDelta+= anArrCoeffs(i++) * aY2;                 //27
4759       aDelta+= anArrCoeffs(i++) * aZ2;                 //28
4760       aDelta+= anArrCoeffs(i++) * aX1 * aY1;           //29
4761       aDelta+= anArrCoeffs(i++) * aX1 * aZ1;           //30
4762       aDelta+= anArrCoeffs(i++) * aY1 * aZ1;           //31
4763       aDelta+= anArrCoeffs(i++) * aX1;                 //32
4764       aDelta+= anArrCoeffs(i++) * aY1;                 //33
4765       aDelta+= anArrCoeffs(i++) * aZ1;                 //34
4766       aDelta+= anArrCoeffs(i++);                       //35
4767
4768       if(Abs(aDelta) > aToler)
4769       {
4770         theDI << "(" << aUpar << ", " << aVpar << "): Error in torus coefficients computation (Delta = " << aDelta << ").\n";
4771       }
4772       else
4773       {
4774         theDI << "(" << aUpar << ", " << aVpar << "): OK (Delta = " << aDelta << ").\n";
4775       }
4776
4777       aVpar = (aVind == aNbPntsMax)? 2.0*M_PI : aVpar + aStep;
4778     }
4779
4780     aVpar = 0.0;
4781     aUpar = (aUind == aNbPntsMax)? 2.0*M_PI : aUpar + aStep;
4782   }
4783
4784   return 0;     
4785 }
4786
4787 DEFINE_STANDARD_HANDLE(QABugs_VertexFilter, SelectMgr_Filter)
4788 class QABugs_VertexFilter: public SelectMgr_Filter
4789 {
4790 public:
4791   Standard_EXPORT QABugs_VertexFilter() : SelectMgr_Filter() {}
4792
4793   Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)&) const
4794   {
4795     return Standard_False;
4796   }
4797 };
4798
4799 //=======================================================================
4800 //function : BUC26658 
4801 //purpose  : Checks selection in the context after using a selection filter
4802 //=======================================================================
4803 static Standard_Integer BUC26658 (Draw_Interpretor& theDI,
4804                                   Standard_Integer  /*theNArg*/,
4805                                   const char ** theArgVal)
4806 {
4807   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4808   if(aContext.IsNull()) {
4809     theDI << "use 'vinit' command before " << theArgVal[0] << "\n";
4810     return 1;
4811   }
4812
4813   TopoDS_Shape aBoxShape = BRepPrimAPI_MakeBox(20,20,20).Shape();
4814   Handle(AIS_Shape) anAISIO = new AIS_Shape(aBoxShape);
4815
4816   // visualization of the box in the local mode with possibility to
4817   // select box vertices
4818   Standard_DISABLE_DEPRECATION_WARNINGS
4819   aContext->OpenLocalContext();
4820   Standard_ENABLE_DEPRECATION_WARNINGS
4821
4822   int aDispMode = 0;// wireframe
4823   anAISIO->SetDisplayMode(aDispMode);
4824   aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed); 
4825   theDI.Eval(" vfit");
4826
4827   aContext->Load(anAISIO, -1, true); /// load allowing decomposition
4828   aContext->Deactivate(anAISIO);
4829   aContext->Activate(anAISIO, AIS_Shape::SelectionMode(TopAbs_VERTEX), false);
4830   aContext->UpdateCurrentViewer();
4831
4832   // select a point on the box
4833   Handle(V3d_View) myV3dView = ViewerTest::CurrentView();
4834   double Xv,Yv;
4835   myV3dView->Project(20,20,0,Xv,Yv);
4836   Standard_Integer Xp,Yp;
4837   myV3dView->Convert(Xv,Yv,Xp,Yp);
4838
4839   aContext->MoveTo (Xp, Yp, myV3dView, Standard_False);
4840   aContext->Select (Standard_False);
4841   bool aHasSelected = false;
4842   for (aContext->InitSelected(); aContext->MoreSelected() && !aHasSelected; aContext->NextSelected()) {
4843     Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
4844     if (!anIO.IsNull()) {
4845       const TopoDS_Shape aShape = aContext->SelectedShape();
4846       if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX)
4847         aHasSelected = true;
4848     }
4849   }
4850   if (aHasSelected)
4851      cout << "has selected vertex : OK"   << endl;
4852   else {
4853     theDI << "has selected vertex : bugged - Faulty\n";
4854     return 1;
4855   }
4856   // filter to deny any selection in the viewer
4857   Handle(QABugs_VertexFilter) aFilter = new QABugs_VertexFilter();
4858   aContext->AddFilter(aFilter);
4859
4860   // update previous selection by hand
4861   Standard_DISABLE_DEPRECATION_WARNINGS
4862   aContext->LocalContext()->ClearOutdatedSelection(anAISIO, true);
4863   Standard_ENABLE_DEPRECATION_WARNINGS
4864
4865   // check that there are no selected vertices
4866   aContext->Select (Standard_True);
4867   aHasSelected = false;
4868   for (aContext->InitSelected(); aContext->MoreSelected() && !aHasSelected; aContext->NextSelected()) {
4869     Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
4870     if (!anIO.IsNull()) {
4871       const TopoDS_Shape aShape = aContext->SelectedShape();
4872       if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX)
4873         aHasSelected = true;
4874     }
4875   }
4876   if (!aHasSelected) cout << "has no selected vertex after filter : OK"   << endl;
4877   else {
4878     theDI << "has no selected vertex after filter : bugged - Faulty\n";
4879     return 1;
4880   }
4881
4882   return 0;
4883 }
4884
4885 //=======================================================================
4886 //function : OCC26945_open
4887 //purpose  : Opens local context and activates given standard selection mode
4888 //=======================================================================
4889 static Standard_Integer OCC26945_open (Draw_Interpretor& theDI, Standard_Integer theArgc, const char** theArgv)
4890 {
4891   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4892   if (aCtx.IsNull())
4893   {
4894     std::cout << "No interactive context. Use 'vinit' command before " << theArgv[0] << "\n";
4895     return 1;
4896   }
4897
4898   if (theArgc < 2)
4899   {
4900     std::cout << "Not enough arguments. See usage:\n";
4901     theDI.PrintHelp (theArgv[0]);
4902     return 1;
4903   }
4904
4905   const TopAbs_ShapeEnum aSelType = AIS_Shape::SelectionType (Draw::Atoi (theArgv[1]));
4906   Standard_DISABLE_DEPRECATION_WARNINGS
4907   Standard_Integer aLocalCtxIdx = aCtx->OpenLocalContext();
4908   aCtx->ActivateStandardMode (aSelType);
4909   Standard_ENABLE_DEPRECATION_WARNINGS
4910   theDI << aLocalCtxIdx;
4911
4912   return 0;
4913 }
4914
4915 //=======================================================================
4916 //function : OCC26945_close
4917 //purpose  : Closes local context with the id given
4918 //=======================================================================
4919 static Standard_Integer OCC26945_close (Draw_Interpretor& theDI, Standard_Integer theArgc, const char** theArgv)
4920 {
4921   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4922   if (aCtx.IsNull())
4923   {
4924     std::cout << "No interactive context. Use 'vinit' command before " << theArgv[0] << "\n";
4925     return 1;
4926   }
4927
4928   if (theArgc < 2)
4929   {
4930     std::cout << "Not enough arguments. See usage:\n";
4931     theDI.PrintHelp (theArgv[0]);
4932     return 1;
4933   }
4934
4935   const Standard_Integer aCtxToClose = Draw::Atoi (theArgv[1]);
4936   Standard_DISABLE_DEPRECATION_WARNINGS
4937   aCtx->CloseLocalContext (aCtxToClose);
4938   Standard_ENABLE_DEPRECATION_WARNINGS
4939
4940   return 0;
4941 }
4942
4943 //=======================================================================
4944 //function : OCC27048
4945 //purpose  : Calculate value of B-spline surface N times
4946 //=======================================================================
4947 static Standard_Integer OCC27048(Draw_Interpretor& theDI, Standard_Integer theArgc, const char** theArgv)
4948 {
4949   if (theArgc != 5)
4950   {
4951     std::cout << "Incorrect number of arguments. See usage:" << std::endl;
4952     theDI.PrintHelp(theArgv[0]);
4953     return 1;
4954   }
4955
4956   Handle(Geom_Surface) aSurf = DrawTrSurf::GetSurface(theArgv[1]);
4957   GeomAdaptor_Surface anAdaptor(aSurf);
4958
4959   Standard_Real aU = Draw::Atof(theArgv[2]);
4960   Standard_Real aV = Draw::Atof(theArgv[3]);
4961   Standard_Integer aN = Draw::Atoi(theArgv[4]);
4962
4963   for (; aN > 0; --aN)
4964     anAdaptor.Value(aU, aV);
4965
4966   return 0;
4967 }
4968
4969 //========================================================================
4970 //function : OCC27065
4971 //purpose  : Tests overloaded method "Generated" of BRepOffsetAPI_MakePipe
4972 //========================================================================
4973 static Standard_Integer OCC27065(Draw_Interpretor& di,
4974                                  Standard_Integer n, const char** a)
4975 {
4976   if (n < 3) return 1;
4977   BRep_Builder BB;
4978
4979   TopoDS_Shape SpineShape = DBRep::Get(a[1],TopAbs_WIRE);
4980   if ( SpineShape.IsNull()) return 1;
4981   TopoDS_Wire Spine = TopoDS::Wire(SpineShape);
4982
4983   TopoDS_Shape Profile = DBRep::Get(a[2]);
4984   if ( Profile.IsNull()) return 1;
4985
4986   BRepOffsetAPI_MakePipe aPipeBuilder(Spine, Profile);
4987   if (!aPipeBuilder.IsDone())
4988   {
4989     di << "Error: failed to create pipe\n";
4990     return 1;
4991   }
4992
4993   TopExp_Explorer Explo(Profile, TopAbs_SHELL);
4994   TopoDS_Shape aShape;
4995   TopTools_ListIteratorOfListOfShape itl;
4996   if (Explo.More())
4997   {
4998     aShape = Explo.Current();
4999     TopoDS_Compound res1;
5000     BB.MakeCompound(res1);
5001     itl.Initialize(aPipeBuilder.Generated(aShape));
5002     for (; itl.More(); itl.Next())
5003       BB.Add(res1, itl.Value());
5004     DBRep::Set("res_shell", res1);
5005   }
5006
5007   Explo.Init(Profile, TopAbs_FACE);
5008   if (Explo.More())
5009   {
5010     aShape = Explo.Current();
5011     TopoDS_Compound res2;
5012     BB.MakeCompound(res2);
5013     itl.Initialize(aPipeBuilder.Generated(aShape));
5014     for (; itl.More(); itl.Next())
5015       BB.Add(res2, itl.Value());
5016     DBRep::Set("res_face", res2);
5017   }
5018   
5019   Explo.Init(Profile, TopAbs_WIRE);
5020   if (Explo.More())
5021   {
5022     aShape = Explo.Current();
5023     TopoDS_Compound res3;
5024     BB.MakeCompound(res3);
5025     itl.Initialize(aPipeBuilder.Generated(aShape));
5026     for (; itl.More(); itl.Next())
5027       BB.Add(res3, itl.Value());
5028     DBRep::Set("res_wire", res3);
5029   }
5030   
5031   Explo.Init(Profile, TopAbs_EDGE);
5032   if (Explo.More())
5033   {
5034     aShape = Explo.Current();
5035     TopoDS_Compound res4;
5036     BB.MakeCompound(res4);
5037     itl.Initialize(aPipeBuilder.Generated(aShape));
5038     for (; itl.More(); itl.Next())
5039       BB.Add(res4, itl.Value());
5040     DBRep::Set("res_edge", res4);
5041   }
5042   
5043   Explo.Init(Profile, TopAbs_VERTEX);
5044   if (Explo.More())
5045   {
5046     aShape = Explo.Current();
5047     TopoDS_Compound res5;
5048     BB.MakeCompound(res5);
5049     itl.Initialize(aPipeBuilder.Generated(aShape));
5050     for (; itl.More(); itl.Next())
5051       BB.Add(res5, itl.Value());
5052     DBRep::Set("res_vertex", res5);
5053   }
5054   
5055   return 0;
5056 }
5057
5058 //========================================================================
5059 //function : OCC27318
5060 //purpose  : Creates a box that is not listed in map of AIS objects of ViewerTest
5061 //========================================================================
5062 static Standard_Integer OCC27318 (Draw_Interpretor& /*theDI*/, Standard_Integer /*theArgc*/, const char** theArgv)
5063 {
5064   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
5065   if (aCtx.IsNull())
5066   {
5067     std::cout << "No interactive context. Use 'vinit' command before " << theArgv[0] << "\n";
5068     return 1;
5069   }
5070
5071   TopoDS_Shape aBox = BRepPrimAPI_MakeBox (20, 20, 20).Shape();
5072   Handle(AIS_Shape) aBoxObj = new AIS_Shape (aBox);
5073   aCtx->Display (aBoxObj, Standard_True);
5074
5075   return 0;
5076 }
5077
5078 //========================================================================
5079 //function : OCC27523
5080 //purpose  : Checks recomputation of deactivated selection mode after object's redisplaying
5081 //========================================================================
5082 static Standard_Integer OCC27523 (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
5083 {
5084   if (theArgNb != 1)
5085   {
5086     std::cerr << "Error: wrong number of arguments! See usage:\n";
5087     theDI.PrintHelp (theArgVec[0]);
5088     return 1;
5089   }
5090
5091   Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
5092   if(anAISContext.IsNull())
5093   {
5094     std::cerr << "Error: no active view. Please call vinit.\n";
5095     return 1;
5096   }
5097
5098   gp_Pnt aStart (100, 100, 100);
5099   gp_Pnt anEnd (300, 400, 600);
5100   BRepBuilderAPI_MakeEdge anEdgeBuilder (aStart, anEnd);
5101   TopoDS_Edge anEdge = anEdgeBuilder.Edge();
5102   Handle(AIS_InteractiveObject) aTestAISShape = new AIS_Shape (anEdge);
5103   anAISContext->Display (aTestAISShape, Standard_False);
5104
5105   // activate it in selection modes
5106   TColStd_SequenceOfInteger aModes;
5107   aModes.Append (AIS_Shape::SelectionMode ((TopAbs_ShapeEnum) TopAbs_VERTEX));
5108
5109   anAISContext->Deactivate (aTestAISShape);
5110   anAISContext->Load (aTestAISShape, -1, true);
5111   anAISContext->Activate (aTestAISShape, 0);
5112   anAISContext->Deactivate (aTestAISShape, 0);
5113
5114   // activate in vertices mode
5115   for (Standard_Integer anIt = 1; anIt <= aModes.Length(); ++anIt)
5116   {
5117     anAISContext->Activate (aTestAISShape, aModes (anIt));
5118   }
5119
5120   TopoDS_Shape aVertexShape = BRepBuilderAPI_MakeVertex (gp_Pnt (75, 0, 0));
5121   TopAbs_ShapeEnum aVertexShapeType = aVertexShape.ShapeType();
5122   Handle(AIS_Shape)::DownCast (aTestAISShape)->Set (aVertexShape);
5123   aTestAISShape->Redisplay();
5124
5125   anAISContext->AddOrRemoveSelected (aTestAISShape, Standard_True);
5126
5127   bool aValidShapeType = false;
5128   for (anAISContext->InitSelected(); anAISContext->MoreSelected(); anAISContext->NextSelected())
5129   {
5130     Handle(SelectMgr_EntityOwner) anOwner = anAISContext->SelectedOwner();
5131     Handle(StdSelect_BRepOwner) aBRO = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
5132     if (!aBRO.IsNull() && aBRO->HasShape())
5133     {
5134       TopoDS_Shape aShape = aBRO->Shape();
5135
5136       aValidShapeType = aShape.ShapeType() == aVertexShapeType;
5137     }
5138   }
5139
5140   if (!aValidShapeType)
5141   {
5142     std::cerr << "Error: shape type is invalid.\n";
5143     return 1;
5144   }
5145
5146   return 0;
5147 }
5148
5149 //========================================================================
5150 //function : OCC27700
5151 //purpose  : glPolygonMode() used for frame drawing affects label text shading
5152 //========================================================================
5153
5154 class OCC27700_Text : public AIS_InteractiveObject
5155 {
5156 public:
5157
5158   DEFINE_STANDARD_RTTI_INLINE (OCC27700_Text, AIS_InteractiveObject)
5159
5160   virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
5161                         const Handle(Prs3d_Presentation)& thePresentation,
5162                         const Standard_Integer /*theMode*/) Standard_OVERRIDE
5163   {
5164     Handle(Graphic3d_ArrayOfTriangles) aFrame = new Graphic3d_ArrayOfTriangles (6, 6);
5165     aFrame->AddVertex (gp_Pnt (-1, 0, 0));
5166     aFrame->AddVertex (gp_Pnt (-1, 1, 0));
5167     aFrame->AddVertex (gp_Pnt ( 3, 1, 0));
5168     aFrame->AddVertex (gp_Pnt ( 3, 0, 0));
5169
5170     aFrame->AddEdge (1);
5171     aFrame->AddEdge (2);
5172     aFrame->AddEdge (3);
5173
5174     aFrame->AddEdge (2);
5175     aFrame->AddEdge (3);
5176     aFrame->AddEdge (4);
5177
5178     Handle(Graphic3d_AspectFillArea3d) aFillAspect =
5179       new Graphic3d_AspectFillArea3d (*myDrawer->ShadingAspect()->Aspect().get());
5180     aFillAspect->SetInteriorStyle (Aspect_IS_POINT);
5181
5182     // create separate group for frame elements
5183     Handle(Graphic3d_Group) aFrameGroup = Prs3d_Root::NewGroup (thePresentation);
5184     aFrameGroup->AddPrimitiveArray (aFrame);
5185     aFrameGroup->SetGroupPrimitivesAspect (aFillAspect);
5186
5187     // create separate group for text elements
5188     Handle(Graphic3d_Group) aTextGroup = Prs3d_Root::NewGroup (thePresentation);
5189     TCollection_ExtendedString aString ("YOU SHOULD SEE THIS TEXT", Standard_True);
5190     Prs3d_Text::Draw (Prs3d_Root::CurrentGroup (thePresentation), myDrawer->TextAspect(), aString, gp_Ax2 (gp::Origin(), gp::DZ()));
5191   }
5192
5193   virtual void ComputeSelection (const Handle(SelectMgr_Selection)& /*theSelection*/,
5194                                  const Standard_Integer /*theMode*/) Standard_OVERRIDE {}
5195 };
5196
5197 static Standard_Integer OCC27700 (Draw_Interpretor& /*theDI*/, Standard_Integer /*theArgNb*/, const char** /*theArgVec*/)
5198 {
5199   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5200   if (aContext.IsNull())
5201   {
5202     std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
5203     return 1;
5204   }
5205   Handle(OCC27700_Text) aPresentation = new OCC27700_Text();
5206   aContext->Display (aPresentation, Standard_True);
5207   return 0;
5208 }
5209
5210 //========================================================================
5211 //function : OCC27757
5212 //purpose  : Creates a box that has a sphere as child object and displays it
5213 //========================================================================
5214 static Standard_Integer OCC27757 (Draw_Interpretor& /*theDI*/, Standard_Integer /*theArgc*/, const char** theArgv)
5215 {
5216   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
5217   if (aCtx.IsNull())
5218   {
5219     std::cout << "No interactive context. Use 'vinit' command before " << theArgv[0] << "\n";
5220     return 1;
5221   }
5222
5223   TopoDS_Shape aBox = BRepPrimAPI_MakeBox (20.0, 20.0, 20.0).Shape();
5224   TopoDS_Shape aSphere = BRepPrimAPI_MakeSphere (10.0).Shape();
5225   gp_Trsf aTrsf;
5226   aTrsf.SetTranslationPart (gp_Vec (20.0, 20.0, 0.0));
5227   aSphere.Located (TopLoc_Location (aTrsf));
5228
5229
5230   Handle(AIS_Shape) aBoxObj = new AIS_Shape (aBox);
5231   Handle(AIS_Shape) aSphereObj = new AIS_Shape (aSphere);
5232   aBoxObj->AddChild (aSphereObj);
5233   aCtx->Display (aBoxObj, 1, 0, Standard_False);
5234   aCtx->UpdateCurrentViewer();
5235
5236   return 0;
5237 }
5238
5239 //========================================================================
5240 //function : OCC27818
5241 //purpose  : Creates three boxes and highlights one of them with own style
5242 //========================================================================
5243 static Standard_Integer OCC27818 (Draw_Interpretor& /*theDI*/, Standard_Integer /*theArgc*/, const char** theArgv)
5244 {
5245   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
5246   if (aCtx.IsNull())
5247   {
5248     std::cout << "No interactive context. Use 'vinit' command before " << theArgv[0] << "\n";
5249     return 1;
5250   }
5251
5252   Handle(AIS_Shape) aBoxObjs[3];
5253   for (Standard_Integer aBoxIdx = 0; aBoxIdx < 3; ++aBoxIdx)
5254   {
5255     TopoDS_Shape aBox = BRepPrimAPI_MakeBox (20.0, 20.0, 20.0).Shape();
5256     aBoxObjs[aBoxIdx] = new AIS_Shape (aBox);
5257     gp_Trsf aTrsf;
5258     aTrsf.SetTranslationPart (gp_Vec (30.0 * aBoxIdx, 30.0 * aBoxIdx, 0.0));
5259     aBoxObjs[aBoxIdx]->SetLocalTransformation (aTrsf);
5260     aBoxObjs[aBoxIdx]->SetHilightMode (AIS_Shaded);
5261   }
5262
5263   {
5264     Handle(Prs3d_Drawer) aHiStyle = new Prs3d_Drawer();
5265     aBoxObjs[1]->SetDynamicHilightAttributes (aHiStyle);
5266     aHiStyle->SetDisplayMode (AIS_Shaded);
5267     aHiStyle->SetColor (Quantity_NOC_RED);
5268     aHiStyle->SetTransparency (0.8f);
5269   }
5270   {
5271     Handle(Prs3d_Drawer) aSelStyle = new Prs3d_Drawer();
5272     aBoxObjs[2]->SetHilightAttributes (aSelStyle);
5273     aSelStyle->SetDisplayMode (AIS_Shaded);
5274     aSelStyle->SetColor (Quantity_NOC_RED);
5275     aSelStyle->SetTransparency (0.0f);
5276     aSelStyle->SetZLayer (Graphic3d_ZLayerId_Topmost);
5277   }
5278
5279   for (Standard_Integer aBoxIdx = 0; aBoxIdx < 3; ++aBoxIdx)
5280   {
5281     aCtx->Display (aBoxObjs[aBoxIdx], AIS_Shaded, 0, Standard_False);
5282   }
5283
5284   aCtx->UpdateCurrentViewer();
5285
5286   return 0;
5287 }
5288
5289 //========================================================================
5290 //function : OCC27893
5291 //purpose  : Creates a box and selects it via AIS_InteractiveContext API
5292 //========================================================================
5293 static Standard_Integer OCC27893 (Draw_Interpretor& /*theDI*/, Standard_Integer /*theArgc*/, const char** theArgv)
5294 {
5295   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
5296   if (aCtx.IsNull())
5297   {
5298     std::cout << "No interactive context. Use 'vinit' command before " << theArgv[0] << "\n";
5299     return 1;
5300   }
5301
5302   TopoDS_Shape aBox = BRepPrimAPI_MakeBox (10.0, 10.0, 10.0).Shape();
5303   Handle(AIS_InteractiveObject) aBoxObj = new AIS_Shape (aBox);
5304   aCtx->Display (aBoxObj, AIS_Shaded, 0, Standard_False);
5305   aCtx->SetSelected (aBoxObj, Standard_True);
5306
5307   return 0;
5308 }
5309
5310 //========================================================================
5311 //function : OCC28310
5312 //purpose  : Tests validness of iterator in AIS_InteractiveContext after
5313 // an removing object from it
5314 //========================================================================
5315 static Standard_Integer OCC28310 (Draw_Interpretor& /*theDI*/, Standard_Integer /*theArgc*/, const char** theArgv)
5316 {
5317   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
5318   if (aCtx.IsNull())
5319   {
5320     std::cout << "No interactive context. Use 'vinit' command before " << theArgv[0] << "\n";
5321     return 1;
5322   }
5323
5324   TopoDS_Shape aBox = BRepPrimAPI_MakeBox (10.0, 10.0, 10.0).Shape();
5325   Handle(AIS_InteractiveObject) aBoxObj = new AIS_Shape (aBox);
5326   aCtx->Display (aBoxObj, AIS_Shaded, 0, Standard_False);
5327   ViewerTest::CurrentView()->FitAll();
5328   aCtx->MoveTo (200, 200, ViewerTest::CurrentView(), Standard_True);
5329   aCtx->Select(Standard_True);
5330
5331   aCtx->Remove (aBoxObj, Standard_True);
5332   // nullify the object explicitly to simulate situation in project,
5333   // when ::Remove is called from another method and the object is destroyed
5334   // before ::DetectedInteractive is called
5335   aBoxObj.Nullify();
5336
5337   for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
5338   {
5339     Handle(AIS_InteractiveObject) anObj = aCtx->DetectedInteractive();
5340   }
5341
5342   return 0;
5343 }
5344
5345 //========================================================================
5346 //function : Commands_19
5347 //purpose  :
5348 //========================================================================
5349
5350 void QABugs::Commands_19(Draw_Interpretor& theCommands) {
5351   const char *group = "QABugs";
5352
5353   Handle(QABugs_HandleClass) aClassPtr = new QABugs_HandleClass();
5354   theCommands.Add ("OCC24202_1", "Test Handle-based procedure",
5355                    __FILE__, aClassPtr, &QABugs_HandleClass::HandleProc, group);
5356   NCollection_Handle<QABugs_NHandleClass> aNClassPtr = new QABugs_NHandleClass();
5357   theCommands.Add ("OCC24202_2", "Test NCollection_Handle-based procedure",
5358                    __FILE__, aNClassPtr, &QABugs_NHandleClass::NHandleProc, group);
5359
5360   theCommands.Add ("OCC230", "OCC230 TrimmedCurve Pnt2d Pnt2d", __FILE__, OCC230, group);
5361   theCommands.Add ("OCC23361", "OCC23361", __FILE__, OCC23361, group);
5362   theCommands.Add ("OCC23237", "OCC23237", __FILE__, OCC23237, group); 
5363   theCommands.Add ("OCC22980", "OCC22980", __FILE__, OCC22980, group);
5364   theCommands.Add ("OCC23595", "OCC23595", __FILE__, OCC23595, group);
5365   theCommands.Add ("OCC22611", "OCC22611 string nb", __FILE__, OCC22611, group);
5366   theCommands.Add ("OCC22595", "OCC22595", __FILE__, OCC22595, group);
5367   theCommands.Add ("OCC23774", "OCC23774 shape1 shape2", __FILE__, OCC23774, group);
5368   theCommands.Add ("OCC23683", "OCC23683 shape", __FILE__, OCC23683, group);
5369   theCommands.Add ("OCC23952sweep", "OCC23952sweep nbupoles shape", __FILE__, OCC23952sweep, group);
5370   theCommands.Add ("OCC23952intersect", "OCC23952intersect nbsol shape1 shape2", __FILE__, OCC23952intersect, group);
5371   theCommands.Add ("test_offset", "test_offset", __FILE__, test_offset, group);
5372   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);
5373   theCommands.Add ("OCC24008", "OCC24008 curve surface", __FILE__, OCC24008, group);
5374   theCommands.Add ("OCC11758", "OCC11758", __FILE__, OCC11758, group);
5375   theCommands.Add ("OCC24005", "OCC24005 result", __FILE__, OCC24005, group);
5376   theCommands.Add ("OCC24137", "OCC24137 face vertex U V [N]", __FILE__, OCC24137, group);
5377   theCommands.Add ("OCC24271", "Boolean operations on NCollection_Map", __FILE__, OCC24271, group);
5378   theCommands.Add ("OCC23972", "OCC23972", __FILE__, OCC23972, group);
5379   theCommands.Add ("OCC24370", "OCC24370 edge pcurve surface prec", __FILE__, OCC24370, group);
5380   theCommands.Add ("OCC24533", "OCC24533", __FILE__, OCC24533, group);
5381   theCommands.Add ("OCC24012", "OCC24012 face edge", __FILE__, OCC24012, group);
5382   theCommands.Add ("OCC24086", "OCC24086 face wire", __FILE__, OCC24086, group);
5383   theCommands.Add ("OCC24667", "OCC24667 result Wire_spine Profile [Mode [Approx]], no args to get help", __FILE__, OCC24667, group);
5384   theCommands.Add ("OCC24755", "OCC24755", __FILE__, OCC24755, group);
5385   theCommands.Add ("OCC24834", "OCC24834", __FILE__, OCC24834, group);
5386   theCommands.Add ("OCC24889", "OCC24889", __FILE__, OCC24889, group);
5387   theCommands.Add ("OCC23951", "OCC23951 path to saved step file", __FILE__, OCC23951, group);
5388   theCommands.Add ("OCC24931", "OCC24931 path to saved xml file", __FILE__, OCC24931, group);
5389   theCommands.Add ("OCC24945", "OCC24945", __FILE__, OCC24945, group);
5390   theCommands.Add ("OCC23950", "OCC23950 step_file", __FILE__, OCC23950, group);
5391   theCommands.Add ("OCC25004", "OCC25004", __FILE__, OCC25004, group);
5392   theCommands.Add ("OCC24925",
5393                    "OCC24925 filename [pluginLib=TKXml storageGuid retrievalGuid]"
5394                    "\nOCAF persistence without setting environment variables",
5395                    __FILE__, OCC24925, group);
5396   theCommands.Add ("OCC25043", "OCC25043 shape", __FILE__, OCC25043, group);
5397   theCommands.Add ("OCC24826,", "This test performs simple saxpy test.\n Usage: OCC24826 length", __FILE__, OCC24826, group);
5398   theCommands.Add ("OCC24606", "OCC24606 : Tests ::FitAll for V3d view ('vfit' is for NIS view)", __FILE__, OCC24606, group);
5399   theCommands.Add ("OCC25202", "OCC25202 res shape numF1 face1 numF2 face2", __FILE__, OCC25202, group);
5400   theCommands.Add ("OCC7570", "OCC7570 shape", __FILE__, OCC7570, group);
5401   theCommands.Add ("OCC25100", "OCC25100 shape", __FILE__, OCC25100, group);
5402   theCommands.Add ("OCC25340", "OCC25340", __FILE__, OCC25340, group);
5403   theCommands.Add ("OCC25348", "OCC25348", __FILE__, OCC25348, group);
5404   theCommands.Add ("OCC25413", "OCC25413 shape", __FILE__, OCC25413, group);
5405   theCommands.Add ("OCC25446", "OCC25446 res b1 b2 op", __FILE__, OCC25446, group);
5406   theCommands.Add ("OCC25545", 
5407                    "no args; tests data race when concurrently accessing \n"
5408                    "\t\tTopLoc_Location::Transformation()",
5409                    __FILE__, OCC25545, group);
5410   theCommands.Add ("OCC25547", "OCC25547", __FILE__, OCC25547, group);
5411   theCommands.Add ("OCC24881", "OCC24881 shape", __FILE__, OCC24881, group);
5412   theCommands.Add ("OCC26172", "OCC26172", __FILE__, OCC26172, group);
5413   theCommands.Add ("xprojponf", "xprojponf p f", __FILE__, xprojponf, group);
5414   theCommands.Add ("OCC24923", "OCC24923", __FILE__, OCC24923, group);
5415   theCommands.Add ("OCC26139", "OCC26139 [-boxsize value] [-boxgrid value] [-compgrid value]", __FILE__, OCC26139, group);
5416   theCommands.Add ("OCC26284", "OCC26284", __FILE__, OCC26284, group);
5417   theCommands.Add ("OCC26446", "OCC26446 r c1 c2", __FILE__, OCC26446, group);
5418   theCommands.Add ("OCC26448", "OCC26448: check method Prepend() of sequence", __FILE__, OCC26448, group);
5419   theCommands.Add ("OCC26407", "OCC26407 result_name", __FILE__, OCC26407, group);
5420   theCommands.Add ("OCC26485", "OCC26485 shape", __FILE__, OCC26485, group);
5421   theCommands.Add ("OCC26553", "OCC26553 file_path", __FILE__, OCC26553, group);
5422   theCommands.Add ("OCC26195",
5423                    "OCC26195: x1_pix y1_pix [x2_pix y2_pix] [toPrintPixelCoord 0|1]"
5424                    "\n\t\t: Draws rectangular selecting frustum defined by point selection in pixel coordinates"
5425                    "\n\t\t: [x1_pix, y1_pix] or rectangular selection in pixel coordinates [x1_pix, y1_pix,"
5426                    "\n\t\t: x2_pix, y2_pix]."
5427                    "\n\t\t: [toPrintPixelCoord 0|1] - prints 3d projection of pixel coordinate or center of"
5428                    "\n\t\t: selecting rectangle onto near and far view frustum planes",
5429                    __FILE__, OCC26195, group);
5430   theCommands.Add ("OCC26462",
5431                    "OCC26462: Checks the ability to manage sensitivity of a particular selection mode in local context",
5432                    __FILE__, OCC26462, group);
5433
5434   theCommands.Add ("OCC26313", "OCC26313 result shape", __FILE__, OCC26313, group);
5435   theCommands.Add ("OCC26396", "OCC26396 shape_file_path", __FILE__, OCC26396, group);
5436   theCommands.Add ("OCC26525", "OCC26525 result edge face ", __FILE__, OCC26525, group);
5437
5438   theCommands.Add ("OCC24537", "OCC24537 [file]", __FILE__, OCC24537, group);
5439   theCommands.Add ("OCC26750", "OCC26750", __FILE__, OCC26750, group);
5440   theCommands.Add ("OCC25574", "OCC25574", __FILE__, OCC25574, group);
5441   theCommands.Add ("OCC26746", "OCC26746 torus [toler NbCheckedPoints] ", __FILE__, OCC26746, group);
5442
5443   theCommands.Add ("BUC26658", "BUC26658 unexpected selection in the context using a selection filter", __FILE__, BUC26658, group);
5444   theCommands.Add ("OCC26945_open",
5445                    "OCC26945 selectionModeToActivate"
5446                    "\n\t\t: Opens a new local context with selectionModeToActivate activated."
5447                    "\n\t\t: Prints the ID of newely opened local context in case of success.",
5448                    __FILE__, OCC26945_open, group);
5449   theCommands.Add ("OCC26945_close",
5450                    "OCC26945 localCtxToClose"
5451                    "\n\t\t: Closes local context with the ID localCtxToClose",
5452                    __FILE__, OCC26945_close, group);
5453
5454   theCommands.Add ("OCC27048",
5455                    "OCC27048 surf U V N\nCalculate value of surface N times in the point (U, V)",
5456                    __FILE__, OCC27048, group);
5457   
5458   theCommands.Add ("OCC27065",
5459                    "OCC27065 spine profile",
5460                    __FILE__, OCC27065, group);
5461
5462   theCommands.Add ("OCC27318",
5463                    "OCC27318: Creates a box that is not listed in map of AIS objects of ViewerTest",
5464                    __FILE__, OCC27318, group);
5465   theCommands.Add ("OCC27523",
5466                    "OCC27523: Checks recomputation of deactivated selection mode after object's redisplaying",
5467                    __FILE__, OCC27523, group);
5468   theCommands.Add ("OCC27700",
5469                    "OCC27700: Checks drawing text after setting interior style",
5470                    __FILE__, OCC27700, group);
5471   theCommands.Add ("OCC27757",
5472                    "OCC27757: Creates a box that has a sphere as child object and displays it",
5473                    __FILE__, OCC27757, group);
5474   theCommands.Add ("OCC27818",
5475                    "OCC27818: Creates three boxes and highlights one of them with own style",
5476                    __FILE__, OCC27818, group);
5477   theCommands.Add ("OCC27893",
5478                    "OCC27893: Creates a box and selects it via AIS_InteractiveContext API",
5479                    __FILE__, OCC27893, group);
5480   theCommands.Add("OCC28310",
5481                   "OCC28310: Tests validness of iterator in AIS_InteractiveContext after an removing object from it",
5482                   __FILE__, OCC28310, group);
5483   return;
5484 }