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