0022980: Fixed Standard_Atomic.hxx
[occt.git] / src / QABugs / QABugs_16.cxx
1 // Created on: 2002-03-18
2 // Created by: QA Admin
3 // Copyright (c) 2002-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20
21
22 #include <QABugs.hxx>
23
24 #include <Draw_Interpretor.hxx>
25 #include <DBRep.hxx>
26 #include <DrawTrSurf.hxx>
27 #include <AIS_InteractiveContext.hxx>
28 #include <ViewerTest.hxx>
29 #include <AIS_Shape.hxx>
30 #include <TopoDS_Shape.hxx>
31
32 #include <GProp_GProps.hxx>
33 #include <BRepGProp.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <BRepBuilderAPI_MakeEdge.hxx>
36 #include <AIS_Trihedron.hxx>
37 #include <Geom_Axis2Placement.hxx>
38 #include <gp_Ax2.hxx>
39 #include <Geom_Circle.hxx>
40 #include <AIS_Circle.hxx>
41 #include <V3d_View.hxx>
42 #include <TopoDS.hxx>
43 #include <Geom_Plane.hxx>
44 #include <gp_Pln.hxx>
45 #include <AIS_AngleDimension.hxx>
46
47 #include <TopExp_Explorer.hxx>
48 #include <BRepAdaptor_Curve.hxx>
49 #include <GC_MakePlane.hxx>
50 #include <AIS_PlaneTrihedron.hxx>
51 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
52
53 #include <BRep_Tool.hxx>
54 #include <Geom_BSplineCurve.hxx>
55 #include <GeomConvert_CompCurveToBSplineCurve.hxx>
56 #include <BRepBuilderAPI_MakeEdge.hxx>
57 #include <Precision.hxx>
58
59 #include <GProp_PrincipalProps.hxx>
60
61 #include <OSD_Path.hxx>
62 #include <Standard_ProgramError.hxx>
63
64 //#include <QAModTopOpe_Limitation.hxx>
65 #include <QANewModTopOpe_Limitation.hxx>
66
67 //#include <QAModTopOpe_Glue.hxx>
68 #include <QANewModTopOpe_Glue.hxx>
69
70 #include <ShapeFix_Wireframe.hxx>
71 #include <ShapeBuild_ReShape.hxx>
72
73 #include <ViewerTest_Tool.hxx>
74 #include <BRepBuilderAPI_MakeEdge.hxx>
75
76 //#include <QAModTopOpe_ReShaper.hxx>
77 #include <QANewModTopOpe_ReShaper.hxx>
78
79 #include <ViewerTest_EventManager.hxx>
80
81 #include <TColgp_Array1OfPnt2d.hxx>
82
83 #include <DDocStd.hxx>
84 #include <TDocStd_Document.hxx>
85 #include <Standard_ErrorHandler.hxx>
86
87 #if ! defined(WNT)
88 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
89 #else
90 Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
91 #endif
92
93 static Standard_Integer BUC60848 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
94 {
95   if ( argc != 2 ) {
96     di << "Usage : " << argv[0] << " shape " << "\n";
97     return 1;
98   }
99   TopoDS_Shape S = DBRep::Get( argv[1] );
100   if ( S.IsNull() ) {
101     di << "Shape is empty" << "\n";
102     return 1;
103   }
104   GProp_GProps G;
105   BRepGProp::VolumeProperties( S,G );
106   Standard_Real GRes;
107   GRes = G.Mass();
108   if ( GRes < 0 ) {
109     di << "Result is negative : " << GRes << "\n";
110     return 1;
111   } else {
112     di << "Volume : " << GRes << "\n";
113   }
114
115   return 0;
116 }
117
118 static Standard_Integer BUC60828 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/)
119 {
120   TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(0.,0.,0.), gp_Pnt(0.,0.,1.)); 
121   Standard_Boolean aValue; 
122   aValue=anEdge.Infinite(); 
123   di << "Initial flag : " << (Standard_Integer) aValue << "\n";
124   anEdge.Infinite(Standard_True); 
125   Standard_Boolean aValue1; 
126   aValue1=anEdge.Infinite(); 
127   di << "Current flag : " << (Standard_Integer) aValue1 << "\n";
128   if(aValue1) di << "Flag was set properly." << "\n";
129   else di << "Faulty : flag was not set properly." << "\n";
130   return 0;
131 }
132
133 static Standard_Integer  BUC60814(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
134 {
135   if(argc!=1)
136   {
137     di << "Usage : " << argv[0] << "\n";
138     return 1;
139   }
140
141
142   Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
143   if(myAISContext.IsNull()) {
144     di << "use 'vinit' command before " << argv[0] << "\n";
145     return 1;
146   }
147   
148   // TRIHEDRON
149   Handle(AIS_Trihedron) aTrihedron;
150   Handle(Geom_Axis2Placement) aTrihedronAxis=new Geom_Axis2Placement(gp::XOY());
151   aTrihedron=new AIS_Trihedron(aTrihedronAxis);
152   myAISContext->Display(aTrihedron);
153   
154   //Circle
155   gp_Pnt P(10,10,10);
156   gp_Dir V(1,0,0);
157   gp_Ax2 aAx2(P,V);
158   
159   Handle(Geom_Circle) ahCircle=new Geom_Circle(aAx2,20);
160   Handle(AIS_Circle)   aCircle=new AIS_Circle(ahCircle);
161   myAISContext->Display(aCircle);
162     
163   myAISContext->SelectionColor(Quantity_NOC_BLUE1);
164   
165   myAISContext->AddOrRemoveSelected(aTrihedron);
166   myAISContext->AddOrRemoveSelected(aCircle);
167   
168   return 0;
169 }
170
171 static Standard_Integer  BUC60774(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
172 {
173   if(argc!=1)
174   {
175     di << "Usage : " << argv[0] << "\n";
176     return -1;
177   }
178
179   Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
180   if(myAISContext.IsNull()) 
181   {
182     di << "use 'vinit' command before " << argv[0] << "\n";
183     return -1;
184   }
185
186   Handle(V3d_View) myV3dView = ViewerTest::CurrentView();
187   
188   double Xc,Yc,Width, Height;
189   myV3dView->Center(Xc,Yc);
190   myV3dView-> Size (Width, Height);
191   
192   double Xmin,Ymin;
193   Xmin=Xc-Width/2;
194   Ymin=Yc-Height/2;
195   double Xmax,Ymax;
196   Xmax=Xc+Width/2;
197   Ymax=Yc+Height/2;
198     
199   Standard_Integer XPmin,YPmin;
200   myV3dView->Convert(Xmin,Ymin,XPmin,YPmin);
201 //  cout<<Xmin<<"\t"<<Ymin<<endl;
202 //  cout<<XPmin<<"\t"<<YPmin<<endl;
203
204   Standard_Integer XPmax,YPmax;
205   myV3dView->Convert(Xmax,Ymax,XPmax,YPmax);
206 //  cout<<Xmax<<"\t"<<Ymax<<endl;
207 //  cout<<XPmax<<"\t"<<YPmax<<endl;
208   
209   AIS_StatusOfPick status;
210   if ((status=myAISContext->Select(XPmin,YPmin,XPmax,YPmax,myV3dView))==AIS_SOP_NothingSelected)
211              di << "status = AIS_SOP_NothingSelected : OK"   << "\n";
212   else       di << "status = AIS_SOP_NothingSelected : bugged - Faulty "   << "\n";
213   
214   di.Eval("box b 10 10 10");
215   di.Eval(" vdisplay b");
216
217   if ((status=myAISContext->Select(XPmin,YPmin,XPmax,YPmax,myV3dView))==AIS_SOP_OneSelected)
218              di << "status = AIS_SOP_OneSelected : OK"   << "\n";
219   else       di << "status = AIS_SOP_OneSelected : bugged - Faulty "   << "\n";
220
221   di.Eval("box w 20 20 20 20 20 20");
222   di.Eval(" vdisplay w");
223
224   if ((status=myAISContext->Select(XPmin,YPmin,XPmax,YPmax,myV3dView))==AIS_SOP_SeveralSelected)
225              di << "status = AIS_SOP_SeveralSelected : OK"   << "\n";
226   else       di << "status = AIS_SOP_SeveralSelected : bugged - Faulty "   << "\n";
227   
228   return 0;
229
230 }  
231
232 static Standard_Integer BUC60972 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
233 {
234   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
235   if(aContext.IsNull()) { 
236     di << "use 'vinit' command before " << argv[0] << "\n";
237     return 1;
238   }
239
240   if(argc != 6) {
241     di << "Usage : " << argv[0] << " edge edge plane val text" << "\n";
242     return 1;
243   }
244   
245   TopoDS_Edge aFirst = TopoDS::Edge(DBRep::Get(argv[1],TopAbs_EDGE));
246   TopoDS_Edge aSecond = TopoDS::Edge(DBRep::Get(argv[2],TopAbs_EDGE));
247   Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(DrawTrSurf::GetSurface(argv[3]));
248   if(aPlane.IsNull())
249     return 1;
250   
251   di << aPlane->Pln().SquareDistance( gp_Pnt(0,0,0) ) << "\n";
252   
253   TCollection_ExtendedString aText(argv[5]);
254   //Standard_ExtString ExtString_aText = aText.ToExtString();
255   //di << ExtString_aText << " " << atof(argv[4]) << "\n";
256   di << argv[5] << " " << atof(argv[4]) << "\n";
257   
258   Handle(AIS_AngleDimension) aDim = new AIS_AngleDimension(aFirst, aSecond, aPlane, atof(argv[4]), aText);
259   aContext->Display(aDim);                                                         
260   
261   return 0;
262 }
263
264 static Standard_Integer OCC218bug (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
265 {
266   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
267   if(aContext.IsNull()) { 
268     di << "use 'vinit' command before " << argv[0] << "\n";
269     return 1;
270   }
271
272   if(argc != 5) {
273     di << "Usage : " << argv[0] << " name plane Xlabel Ylabel" << "\n";
274     return 1;
275   }
276
277   TopoDS_Shape S = DBRep::Get( argv[2] );
278   if ( S.IsNull() ) {
279     di << "Shape is empty" << "\n";
280     return 1;
281   }
282
283   TCollection_AsciiString name(argv[1]);
284   TCollection_AsciiString Xlabel(argv[3]);
285   TCollection_AsciiString Ylabel(argv[4]);
286   
287   // Construction de l'AIS_PlaneTrihedron
288   Handle(AIS_PlaneTrihedron) theAISPlaneTri;
289
290   Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
291   if (IsBound) {
292     // on recupere la shape dans la map des objets displayes
293     Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
294       
295     // On verifie que l'AIS InteraciveObject est bien 
296     // un AIS_PlaneTrihedron
297     if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==4) {
298       // On downcast aShape de AIS_InteractiveObject a AIS_PlaneTrihedron
299       theAISPlaneTri = *(Handle(AIS_PlaneTrihedron)*) &aShape;
300
301       theAISPlaneTri->SetXLabel(Xlabel);
302       theAISPlaneTri->SetYLabel(Ylabel);
303   
304       aContext->Redisplay(theAISPlaneTri, Standard_False);
305       aContext->UpdateCurrentViewer();
306     }
307   } else {
308     TopoDS_Face  FaceB=TopoDS::Face(S);
309   
310     // Construction du Plane
311     // recuperation des edges des faces.
312     TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
313   
314     TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
315     // declarations 
316     gp_Pnt A,B,C;
317   
318     // si il y a plusieurs edges
319     if (FaceExpB.More() ) {
320       FaceExpB.Next();
321       TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
322       BRepAdaptor_Curve theCurveB(EdgeB);
323       BRepAdaptor_Curve theCurveC(EdgeC);
324       A=theCurveC.Value(0.1);
325       B=theCurveC.Value(0.9);
326       C=theCurveB.Value(0.5);
327     }
328     else {
329       // FaceB a 1 unique edge courbe
330       BRepAdaptor_Curve theCurveB(EdgeB);
331       A=theCurveB.Value(0.1);
332       B=theCurveB.Value(0.9);
333       C=theCurveB.Value(0.5);
334     }
335     // Construction du Geom_Plane
336     GC_MakePlane MkPlane(A,B,C);
337     Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
338     
339     // on le display & bind
340     theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
341     
342     theAISPlaneTri->SetXLabel(Xlabel);
343     theAISPlaneTri->SetYLabel(Ylabel);
344     
345     GetMapOfAIS().Bind ( theAISPlaneTri, name);
346     aContext->Display(theAISPlaneTri );
347   }
348   return 0;
349 }
350
351 static Standard_Integer OCC295(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
352 {
353   if(argc != 4) {
354     di << "Usage : " << argv[0] << " edge_result edge1 edge2" << "\n";
355     return 1;
356   }
357   
358   TopoDS_Shape Sh1 = DBRep::Get(argv[2]);
359   TopoDS_Shape Sh2 = DBRep::Get(argv[3]);
360   if(Sh1.IsNull() || Sh2.IsNull()) return 1;
361   if(Sh1.ShapeType() != TopAbs_EDGE || Sh2.ShapeType() != TopAbs_EDGE) return 1;
362   TopoDS_Edge e1 = TopoDS::Edge(Sh1);
363   TopoDS_Edge e2 = TopoDS::Edge(Sh2);
364   Standard_Real f1,l1,f2,l2;
365   Standard_Boolean After =  Standard_True;
366   Handle(Geom_Curve) ac1 = BRep_Tool::Curve(e1,f1,l1);
367   Handle(Geom_Curve) ac2 = BRep_Tool::Curve(e2,f2,l2);
368   Handle(Geom_BSplineCurve) bsplc1 = Handle(Geom_BSplineCurve)::DownCast(ac1);
369   Handle(Geom_BSplineCurve) bsplc2 = Handle(Geom_BSplineCurve)::DownCast(ac2);
370   if(bsplc1.IsNull() || bsplc2.IsNull()) return 1;
371   gp_Pnt pmid = 0.5 * ( bsplc1->Pole(bsplc1->NbPoles()).XYZ() + bsplc2->Pole(1).XYZ() );
372   bsplc1->SetPole(bsplc1->NbPoles(), pmid);
373   bsplc2->SetPole(1, pmid);
374   GeomConvert_CompCurveToBSplineCurve connect3d(bsplc1);
375   if(!connect3d.Add(bsplc2,Precision::Confusion(), After, Standard_False)) return 1;
376   BRepBuilderAPI_MakeEdge MkEdge(connect3d.BSplineCurve());
377   if(MkEdge.IsDone()) {
378     TopoDS_Edge nedge = MkEdge.Edge();
379     DBRep::Set ( argv[1], nedge );
380     return 0;
381   }
382   else return 1;
383 }
384
385 static Standard_Integer OCC49 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
386 {
387
388   if ( argc != 2 ) {
389     di << "Usage : " << argv[0] << " name" << "\n";
390     return 1;
391   }
392
393   TopoDS_Shape S = DBRep::Get(argv[1]);
394   if (S.IsNull()) return 0;
395
396   GProp_GProps G;
397   BRepGProp::VolumeProperties(S,G);
398   GProp_PrincipalProps Pr = G.PrincipalProperties();
399   Standard_Boolean Result = Pr.HasSymmetryAxis();
400   if (Result) {
401     di << "1" << "\n";
402   } else {
403     di << "0" << "\n";
404   }
405   return 0;
406 }
407
408 static Standard_Integer OCC132 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
409 {
410   /*
411      OCC132:
412      =======
413
414      ... the validation of the name of files in Analyse_DOS and Analyse_UNIX is : 
415
416      characters not allowed in DOS/WNT names are 
417      / 
418      : 
419      * 
420      ? 
421      " 
422      < 
423      > 
424      | 
425      and  more than one dot in filename.
426      */
427
428   if ( argc != 2 ) {
429     di << "Usage : " << argv[0] << " DependentName" << "\n";
430     return 1;
431   }
432
433   OSD_SysType SysType1 = OSD_OS2;
434   OSD_SysType SysType2 = OSD_WindowsNT;
435
436   {
437     try {
438       OCC_CATCH_SIGNALS
439       OSD_Path Path (argv[1], SysType1);
440     }
441     catch (Standard_ProgramError) {
442       di << "1" << "\n";
443       return 0;
444     }
445   }
446
447   {
448     try {
449       OCC_CATCH_SIGNALS
450       OSD_Path Path (argv[1], SysType2);
451     }
452     catch (Standard_ProgramError) {
453       di << "2" << "\n";
454       return 0;
455     }
456   }
457   
458   di << "0" << "\n";
459   return 0;
460 }
461
462 static Standard_Integer OCC405 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
463 {
464   if(argc != 4) {
465     di << "Usage : " << argv[0] << " edge_result edge1 edge2; merge two edges" << "\n";
466     return 1;
467   }
468   
469   TopoDS_Shape Sh1 = DBRep::Get(argv[2]);
470   TopoDS_Shape Sh2 = DBRep::Get(argv[3]);
471   if(Sh1.IsNull() || Sh2.IsNull()) return 1;
472   if(Sh1.ShapeType() != TopAbs_EDGE || Sh2.ShapeType() != TopAbs_EDGE) return 1;
473   TopoDS_Edge e1 = TopoDS::Edge(Sh1);
474   TopoDS_Edge e2 = TopoDS::Edge(Sh2);
475   Standard_Real f1,l1,f2,l2;
476   Standard_Boolean After =  Standard_True;
477   Handle(Geom_Curve) ac1 = BRep_Tool::Curve(e1,f1,l1);
478   Handle(Geom_Curve) ac2 = BRep_Tool::Curve(e2,f2,l2);
479   if(e1.Orientation() == TopAbs_REVERSED) {
480     Standard_Real cf = f1;
481       f1 = ac1->ReversedParameter ( l1 );
482       l1 = ac1->ReversedParameter ( cf );
483       ac1 = ac1->Reversed();
484     }
485     if(e2.Orientation() == TopAbs_REVERSED) {
486       Standard_Real cf = f2;
487       f2 = ac2->ReversedParameter ( l2 );
488       l2 = ac2->ReversedParameter ( cf );
489       ac2 = ac2->Reversed();
490     }
491   Handle(Geom_BSplineCurve) bsplc1 = Handle(Geom_BSplineCurve)::DownCast(ac1);
492   Handle(Geom_BSplineCurve) bsplc2 = Handle(Geom_BSplineCurve)::DownCast(ac2);
493   if(bsplc1.IsNull() || bsplc2.IsNull()) return 1;
494   if(bsplc1->FirstParameter() < f1 - Precision::PConfusion() || 
495      bsplc1->LastParameter() > l1 + Precision::PConfusion()) {
496     Handle(Geom_BSplineCurve) aBstmp  = Handle(Geom_BSplineCurve)::DownCast(bsplc1->Copy());
497     aBstmp->Segment(f1,l1);
498     gp_Pnt p1 = aBstmp->Pole(1);
499     gp_Pnt p2 = aBstmp->Pole(aBstmp->NbPoles());
500     bsplc1 =aBstmp; 
501   }
502   if(bsplc2->FirstParameter() < f2 - Precision::PConfusion() || 
503      bsplc2->LastParameter() > l2 + Precision::PConfusion()) {
504     Handle(Geom_BSplineCurve) aBstmp  = Handle(Geom_BSplineCurve)::DownCast(bsplc2->Copy());
505     aBstmp->Segment(f2,l2);
506     gp_Pnt p1 = aBstmp->Pole(1);
507     gp_Pnt p2 = aBstmp->Pole(aBstmp->NbPoles());
508     bsplc2 =aBstmp; 
509   }
510   gp_Pnt pmid = 0.5 * ( bsplc1->Pole(bsplc1->NbPoles()).XYZ() + bsplc2->Pole(1).XYZ() );
511   bsplc1->SetPole(bsplc1->NbPoles(), pmid);
512   bsplc2->SetPole(1, pmid);
513   GeomConvert_CompCurveToBSplineCurve connect3d(bsplc1);
514   if(!connect3d.Add(bsplc2,Precision::Confusion(), After, Standard_False)) return 1;
515   BRepBuilderAPI_MakeEdge MkEdge(connect3d.BSplineCurve());
516   if(MkEdge.IsDone()) {
517     TopoDS_Edge nedge = MkEdge.Edge();
518     DBRep::Set ( argv[1], nedge );
519     return 0;
520   }
521   else return 1;
522 }
523
524 static Standard_Integer OCC252 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
525 {
526   if(!(argc == 4 || argc == 5)) {
527     di << "Usage : " << argv[0] << " result part tool [ModeOfLimitation=0/1/2]" << "\n";
528     return 1;
529   }
530   
531   TopoDS_Shape s1 = DBRep::Get(argv[2]);
532   TopoDS_Shape s2 = DBRep::Get(argv[3]);
533   if (s1.IsNull() || s2.IsNull()) return 1;
534
535   //QAModTopOpe_ModeOfLimitation ModeOfLimitation = QAModTopOpe_Forward;
536   QANewModTopOpe_ModeOfLimitation ModeOfLimitation = QANewModTopOpe_Forward;
537   if(argc==5) {
538     Standard_Integer ModeOfLimitationInteger = atoi(argv[4]);
539     if(!(ModeOfLimitationInteger == 0 || ModeOfLimitationInteger == 1 || ModeOfLimitationInteger == 2)) {
540       di << "Usage : " << argv[0] << " result part tool [ModeOfLimitation=0/1/2]" << "\n";
541       return 1;
542     }
543     //if (ModeOfLimitationInteger == 1) ModeOfLimitation = QAModTopOpe_Reversed;
544     //if (ModeOfLimitationInteger == 2) ModeOfLimitation = QAModTopOpe_BothParts;
545     if (ModeOfLimitationInteger == 1) ModeOfLimitation = QANewModTopOpe_Reversed;
546     if (ModeOfLimitationInteger == 2) ModeOfLimitation = QANewModTopOpe_BothParts;
547   }
548
549   //TopoDS_Shape res = QAModTopOpe_Limitation(s1,s2,ModeOfLimitation);
550   TopoDS_Shape res = QANewModTopOpe_Limitation(s1,s2,ModeOfLimitation);
551   if (res.IsNull()) {
552     di << "Error : result is null" << "\n";
553     return 1;
554   }
555
556   DBRep::Set(argv[1],res);
557
558   return 0;
559 }
560
561 static Standard_Integer OCC307 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
562 {
563   if(!(argc == 4 || argc == 5)) {
564     di << "Usage : " << argv[0] << " result part tool [AllowCutting=0/1]" << "\n";
565     return 1;
566   }
567   
568   TopoDS_Shape s1 = DBRep::Get(argv[2]);
569   TopoDS_Shape s2 = DBRep::Get(argv[3]);
570   if (s1.IsNull() || s2.IsNull()) return 1;
571
572   Standard_Boolean AllowCutting = Standard_False;
573   if(argc==5) {
574     Standard_Integer AllowCuttingInteger = atoi(argv[4]);
575     if(!( AllowCuttingInteger == 0 || AllowCuttingInteger == 1)) {
576       di << "Usage : " << argv[0] << " result part tool [AllowCutting=0/1]" << "\n";
577       return 1;
578     }
579     if (AllowCuttingInteger == 1) AllowCutting = Standard_True;
580   }
581
582   //TopoDS_Shape res = QAModTopOpe_Glue(s1,s2,AllowCutting);
583   TopoDS_Shape res = QANewModTopOpe_Glue(s1,s2,AllowCutting);
584   if (res.IsNull()) {
585     di << "Error : result is null" << "\n";
586     return 1;
587   }
588
589   DBRep::Set(argv[1],res);
590
591   return 0;
592 }
593
594 static Standard_Integer OCC395 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
595 {
596   if(argc != 4) {
597     di << "Usage : " << argv[0] << " edge_result edge1 edge2" << "\n";
598     return 1;
599   }
600   //TCollection_AsciiString fnom(a[1]);
601   //Standard_Boolean modfic = XSDRAW::FileAndVar(a[1],a[2],a[3],"IGES",fnom,rnom,resnom);
602   TopoDS_Shape Sh1 = DBRep::Get(argv[2]);
603   TopoDS_Shape Sh2 = DBRep::Get(argv[3]);
604   if(Sh1.IsNull() || Sh2.IsNull()) return 1;
605   if(Sh1.ShapeType() != TopAbs_EDGE || Sh2.ShapeType() != TopAbs_EDGE) return 1;
606   TopoDS_Edge e1 = TopoDS::Edge(Sh1);
607   TopoDS_Edge e2 = TopoDS::Edge(Sh2);
608   Standard_Real f1,l1,f2,l2;
609   Standard_Boolean After =  Standard_True;
610   Handle(Geom_Curve) ac1 = BRep_Tool::Curve(e1,f1,l1);
611   Handle(Geom_Curve) ac2 = BRep_Tool::Curve(e2,f2,l2);
612   if(e1.Orientation() == TopAbs_REVERSED) {
613       //Standard_Real cf = cf1;
614       //cf1 = ac1->ReversedParameter ( cl1 );
615       //cl1 = ac1->ReversedParameter ( cf );
616       ac1 = ac1->Reversed();
617     }
618     if(e2.Orientation() == TopAbs_REVERSED) {
619       //Standard_Real cf = cf2;
620       //ac2 = ac2->ReversedParameter ( cl2 );
621       //ac2 = ac2->ReversedParameter ( cf );
622       ac2 = ac2->Reversed();
623     }
624   Handle(Geom_BSplineCurve) bsplc1 = Handle(Geom_BSplineCurve)::DownCast(ac1);
625   Handle(Geom_BSplineCurve) bsplc2 = Handle(Geom_BSplineCurve)::DownCast(ac2);
626   if(bsplc1.IsNull() || bsplc2.IsNull()) return 1;
627   gp_Pnt pmid = 0.5 * ( bsplc1->Pole(bsplc1->NbPoles()).XYZ() + bsplc2->Pole(1).XYZ() );
628   bsplc1->SetPole(bsplc1->NbPoles(), pmid);
629   bsplc2->SetPole(1, pmid);
630   GeomConvert_CompCurveToBSplineCurve connect3d(bsplc1);
631   if(!connect3d.Add(bsplc2,Precision::Confusion(), After, Standard_False)) return 1;
632   BRepBuilderAPI_MakeEdge MkEdge(connect3d.BSplineCurve());
633   if(MkEdge.IsDone()) {
634     TopoDS_Edge nedge = MkEdge.Edge();
635     DBRep::Set ( argv[1], nedge );
636     return 0;
637   }
638   else return 1;
639 }
640
641 static Standard_Integer OCC394 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
642 {
643   if(argc < 3) {
644     di << "Usage : " << argv[0] << " edge_result edge [tol [mode [tolang]]]" << "\n";
645     return 1;
646   }
647    TopoDS_Shape Sh = DBRep::Get(argv[2]);
648  
649    Standard_Integer k = 3;
650    Standard_Real tol = 100000;
651    Standard_Integer mode = 2;
652    Standard_Real tolang = M_PI/2;
653    if(argc > k) 
654      tol = atof(argv[k++]);
655    
656    if(argc > k) 
657      mode=  atoi(argv[k++]);
658    
659    if(argc > k) 
660      tolang = atof(argv[k++]);
661      
662    
663    Handle(ShapeFix_Wireframe) aSfwr = new ShapeFix_Wireframe();
664    Handle(ShapeBuild_ReShape) aReShape = new ShapeBuild_ReShape;
665    aSfwr->SetContext(aReShape);
666    aSfwr->Load(Sh);
667    aSfwr->SetPrecision(tol);
668    Standard_Boolean aModeDrop = Standard_True;
669    if(mode == 2) 
670      aModeDrop = Standard_False;
671    
672     TopTools_MapOfShape theSmallEdges, theMultyEdges;
673   TopTools_DataMapOfShapeListOfShape theEdgeToFaces,theFaceWithSmall;
674   aSfwr->CheckSmallEdges(theSmallEdges,theEdgeToFaces,theFaceWithSmall, theMultyEdges);
675   aSfwr->MergeSmallEdges (theSmallEdges,theEdgeToFaces,theFaceWithSmall, theMultyEdges, aModeDrop,tolang);
676    //aSfwr->FixSmallEdges(); 
677   TopoDS_Shape resShape =  aSfwr->Shape();;
678   DBRep::Set ( argv[1], resShape );
679   return 0;
680 }
681
682 static Standard_Integer OCC301 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
683 {
684   //Handle(AIS_InteractiveContext)   context= ViewerTest_Tool::MakeContext ("OCC301");
685   //ViewerTest_Tool::InitViewerTest (context);
686   Handle(AIS_InteractiveContext) context = ViewerTest::GetAISContext();
687   if(context.IsNull()) {
688     di << "use 'vinit' command before " << argv[0] << "\n";
689     return 1;
690   }
691   if ( argc != 5 ) {
692     di << "Usage : " << argv[0] << " X Y Z ArrowSize" << "\n";
693     return 1;
694   }
695
696   Standard_Real X = atof(argv[1]);
697   Standard_Real Y = atof(argv[2]);
698   Standard_Real Z = atof(argv[3]);
699   Standard_Real ArrowSize = atof(argv[4]);
700
701   gp_Pnt p1 = gp_Pnt(10.,10.,0.);
702   gp_Pnt p2 = gp_Pnt(50.,10.,0.);
703   gp_Pnt p3 = gp_Pnt(50.,50.,0.);
704
705   TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(p1, p2);
706   TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(p2, p3);
707
708   context->Display(new AIS_Shape(E1)); 
709   context->Display(new AIS_Shape(E2)); 
710
711   gp_Pnt plnpt(0, 0, 0);
712   gp_Dir plndir(0, 0, 1);
713   Handle(Geom_Plane) pln = new Geom_Plane(plnpt,plndir);
714
715   Handle(AIS_AngleDimension) AngleDimension = new AIS_AngleDimension(E2, E1, pln, -3.14/2., "Angle");
716
717   AngleDimension->SetPosition(gp_Pnt(X, Y, Z));
718   AngleDimension->SetArrowSize(ArrowSize);
719
720   context->Display(AngleDimension);
721   return 0;
722 }
723
724 static Standard_Integer OCC294 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
725 {
726   if(argc < 4) {
727     di << "Usage : " << argv[0] << " shape_result shape edge" << "\n";
728     return 1;
729   }
730   TopoDS_Shape Sh1 = DBRep::Get(argv[2]);
731   TopoDS_Shape Sh2 = DBRep::Get(argv[3]);
732   if(Sh1.IsNull() || Sh2.IsNull()) return 1;
733   if(Sh2.ShapeType() != TopAbs_EDGE) return 1;
734
735   //QAModTopOpe_ReShaper ReShaper(Sh1);
736   QANewModTopOpe_ReShaper ReShaper(Sh1);
737   ReShaper.Remove(Sh2);
738   const TopoDS_Shape& ResultShape = ReShaper.GetResult();
739   if(ResultShape.IsNull()) {
740     di << "Faulty " << argv[0] << " : " << argv[1] << " - shape_result is null" << "\n";
741     return 1;
742   }
743
744   DBRep::Set ( argv[1], ResultShape);
745   return 0;
746 }
747
748 static Standard_Integer OCC60 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
749 {
750   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
751   if(aContext.IsNull()) { 
752     di << "use 'vinit' command before " << argv[0] << "\n";
753     return 1;
754   }
755   if(argc < 5) {
756     di << "Usage : " << argv[0] << " xmin ymin xmax ymax; selection window" << "\n";
757     return 1;
758   }
759
760   Standard_Integer xmin = atoi(argv[1]);
761   Standard_Integer ymin = atoi(argv[2]);
762   Standard_Integer xmax = atoi(argv[3]);
763   Standard_Integer ymax = atoi(argv[4]);
764
765   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
766
767   Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
768   EM->Select(xmin,ymin,xmax,ymax);
769
770   return 0;
771 }
772
773 static Standard_Integer OCC70 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
774 {
775   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
776   if(aContext.IsNull()) { 
777     di << "use 'vinit' command before " << argv[0] << "\n";
778     return 1;
779   }
780   if(argc < 7) {
781     di << "Usage : " << argv[0] << " x1 y1 x2 y2 x3 y3 [x y ...]; polygon of selection" << "\n";
782     return 1;
783   }
784   if (((argc - 1) % 2) != 0) {
785     di << "Usage : " << argv[0] << " x1 y1 x2 y2 x3 y3 [x y ...]; polygon of selection" << "\n";
786     return 1;
787   }
788
789   Standard_Integer i, j, np = (argc-1) / 2;
790   TColgp_Array1OfPnt2d Polyline(1,np);
791   j = 1;
792   for (i = 1; i <= np; i++) {
793     Polyline(i) = gp_Pnt2d(atof(argv[j]), atof(argv[j+1]));
794     j += 2;
795   }
796
797   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
798
799   aContext->Select(Polyline,V3dView);
800   aContext->UpdateCurrentViewer();
801
802   return 0;
803 }
804
805 static Standard_Integer OCC261 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
806 {
807   if(argc != 2) {
808     di << "Usage : " << argv[0] << " Doc" << "\n";
809     return 1;
810   }
811
812   Handle(TDocStd_Document) Doc;
813   if(DDocStd::GetDocument(argv[1], Doc)) {
814     Doc->ClearRedos();
815     return 0;
816   } else
817     return 1;
818 }
819
820 #include <OSD_File.hxx>
821 static Standard_Integer OCC710 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
822 {
823   if(argc != 2) {
824     di << "Usage : " << argv[0] << " path" << "\n";
825   }
826
827   TCollection_AsciiString in(argv[1]);
828   OSD_File* aFile = new OSD_File(in);
829   Standard_Boolean anExists = aFile->Exists();
830   if(anExists == Standard_True) 
831     di << "1" << "\n";
832   else
833     di << "0" << "\n";
834   return 0;
835 }
836
837 #include <ShapeFix_Shell.hxx>
838 static Standard_Integer OCC904 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
839 {
840   if(argc != 4) {
841     di << "Usage : " << argv[0] << " result shape nonmanifoldmode(0/1)" << "\n";
842   }
843   TopoDS_Shape S = DBRep::Get(argv[2]);
844   if (S.IsNull() || S.ShapeType() != TopAbs_SHELL) {
845     di << " Shape is null" << "\n";
846     return 1;
847   }
848   Standard_Boolean nonmanifmode = (atoi(argv[3]) != 0);
849   Handle(ShapeFix_Shell) SFSh = new ShapeFix_Shell;
850   SFSh->FixFaceOrientation(TopoDS::Shell(S),Standard_True,nonmanifmode);
851   DBRep::Set(argv[1],SFSh->Shape());
852   return 0;
853 }
854
855 void QABugs::Commands_16(Draw_Interpretor& theCommands) {
856   const char *group = "QABugs";
857
858   theCommands.Add ("BUC60848", "BUC60848 shape", __FILE__, BUC60848, group);
859   theCommands.Add ("BUC60828", "BUC60828", __FILE__, BUC60828, group);
860   theCommands.Add ("BUC60814", "BUC60814", __FILE__, BUC60814, group);
861   theCommands.Add ("BUC60774", "BUC60774", __FILE__, BUC60774, group);
862   theCommands.Add ("BUC60972", "BUC60972 edge edge plane val text ", __FILE__, BUC60972, group);
863   theCommands.Add ("OCC218", "OCC218 name plane Xlabel Ylabel", __FILE__, OCC218bug, group);
864   theCommands.Add ("OCC295", "OCC295 edge_result edge1 edge2", __FILE__, OCC295, group);
865   theCommands.Add ("OCC49", "OCC49 name", __FILE__, OCC49, group);
866   theCommands.Add ("OCC132", "OCC132 DependentName", __FILE__, OCC132, group);
867   theCommands.Add ("OCC405", "OCC405 edge_result edge1 edge2; merge two edges", __FILE__, OCC405, group);
868   theCommands.Add ("OCC252", "OCC252 result part tool [ModeOfLimitation=0/1/2]", __FILE__, OCC252, group);
869   theCommands.Add ("OCC307", "OCC307 result part tool [AllowCutting=0/1]", __FILE__, OCC307, group);
870   theCommands.Add ("OCC395", "OCC395 edge_result edge1 edge2", __FILE__, OCC395, group);
871   theCommands.Add ("OCC394", "OCC394 edge_result edge [tol [mode [tolang]]]", __FILE__, OCC394, group);
872   theCommands.Add ("OCC301", "OCC301 X Y Z ArrowSize", __FILE__, OCC301, group);
873   theCommands.Add ("OCC294", "OCC294 shape_result shape edge", __FILE__, OCC294, group);
874   theCommands.Add ("OCC60", "OCC60 xmin ymin xmax ymax; selection window", __FILE__, OCC60, group);
875   theCommands.Add ("OCC70", "OCC70 x1 y1 x2 y2 x3 y3 [x y ...]; polygon of selection", __FILE__, OCC70, group);
876   theCommands.Add ("OCC261", "OCC261 Doc", __FILE__, OCC261, group);
877   theCommands.Add ("OCC710", "OCC710 path", __FILE__, OCC710, group);
878   theCommands.Add ("OCC904", "OCC904 result shape nonmanifoldmode(0/1)", __FILE__, OCC904, group);
879
880   return;
881 }