0022898: IGES import fails in german environment
[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     gp_Pnt p1 = aBstmp->Pole(1);
498     gp_Pnt p2 = aBstmp->Pole(aBstmp->NbPoles());
499     bsplc1 =aBstmp; 
500   }
501   if(bsplc2->FirstParameter() < f2 - Precision::PConfusion() || 
502      bsplc2->LastParameter() > l2 + Precision::PConfusion()) {
503     Handle(Geom_BSplineCurve) aBstmp  = Handle(Geom_BSplineCurve)::DownCast(bsplc2->Copy());
504     aBstmp->Segment(f2,l2);
505     gp_Pnt p1 = aBstmp->Pole(1);
506     gp_Pnt p2 = aBstmp->Pole(aBstmp->NbPoles());
507     bsplc2 =aBstmp; 
508   }
509   gp_Pnt pmid = 0.5 * ( bsplc1->Pole(bsplc1->NbPoles()).XYZ() + bsplc2->Pole(1).XYZ() );
510   bsplc1->SetPole(bsplc1->NbPoles(), pmid);
511   bsplc2->SetPole(1, pmid);
512   GeomConvert_CompCurveToBSplineCurve connect3d(bsplc1);
513   if(!connect3d.Add(bsplc2,Precision::Confusion(), After, Standard_False)) return 1;
514   BRepBuilderAPI_MakeEdge MkEdge(connect3d.BSplineCurve());
515   if(MkEdge.IsDone()) {
516     TopoDS_Edge nedge = MkEdge.Edge();
517     DBRep::Set ( argv[1], nedge );
518     return 0;
519   }
520   else return 1;
521 }
522
523 static Standard_Integer OCC252 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
524 {
525   if(!(argc == 4 || argc == 5)) {
526     di << "Usage : " << argv[0] << " result part tool [ModeOfLimitation=0/1/2]" << "\n";
527     return 1;
528   }
529   
530   TopoDS_Shape s1 = DBRep::Get(argv[2]);
531   TopoDS_Shape s2 = DBRep::Get(argv[3]);
532   if (s1.IsNull() || s2.IsNull()) return 1;
533
534   //QAModTopOpe_ModeOfLimitation ModeOfLimitation = QAModTopOpe_Forward;
535   QANewModTopOpe_ModeOfLimitation ModeOfLimitation = QANewModTopOpe_Forward;
536   if(argc==5) {
537     Standard_Integer ModeOfLimitationInteger = Draw::Atoi(argv[4]);
538     if(!(ModeOfLimitationInteger == 0 || ModeOfLimitationInteger == 1 || ModeOfLimitationInteger == 2)) {
539       di << "Usage : " << argv[0] << " result part tool [ModeOfLimitation=0/1/2]" << "\n";
540       return 1;
541     }
542     //if (ModeOfLimitationInteger == 1) ModeOfLimitation = QAModTopOpe_Reversed;
543     //if (ModeOfLimitationInteger == 2) ModeOfLimitation = QAModTopOpe_BothParts;
544     if (ModeOfLimitationInteger == 1) ModeOfLimitation = QANewModTopOpe_Reversed;
545     if (ModeOfLimitationInteger == 2) ModeOfLimitation = QANewModTopOpe_BothParts;
546   }
547
548   //TopoDS_Shape res = QAModTopOpe_Limitation(s1,s2,ModeOfLimitation);
549   TopoDS_Shape res = QANewModTopOpe_Limitation(s1,s2,ModeOfLimitation);
550   if (res.IsNull()) {
551     di << "Error : result is null" << "\n";
552     return 1;
553   }
554
555   DBRep::Set(argv[1],res);
556
557   return 0;
558 }
559
560 static Standard_Integer OCC307 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
561 {
562   if(!(argc == 4 || argc == 5)) {
563     di << "Usage : " << argv[0] << " result part tool [AllowCutting=0/1]" << "\n";
564     return 1;
565   }
566   
567   TopoDS_Shape s1 = DBRep::Get(argv[2]);
568   TopoDS_Shape s2 = DBRep::Get(argv[3]);
569   if (s1.IsNull() || s2.IsNull()) return 1;
570
571   Standard_Boolean AllowCutting = Standard_False;
572   if(argc==5) {
573     Standard_Integer AllowCuttingInteger = Draw::Atoi(argv[4]);
574     if(!( AllowCuttingInteger == 0 || AllowCuttingInteger == 1)) {
575       di << "Usage : " << argv[0] << " result part tool [AllowCutting=0/1]" << "\n";
576       return 1;
577     }
578     if (AllowCuttingInteger == 1) AllowCutting = Standard_True;
579   }
580
581   //TopoDS_Shape res = QAModTopOpe_Glue(s1,s2,AllowCutting);
582   TopoDS_Shape res = QANewModTopOpe_Glue(s1,s2,AllowCutting);
583   if (res.IsNull()) {
584     di << "Error : result is null" << "\n";
585     return 1;
586   }
587
588   DBRep::Set(argv[1],res);
589
590   return 0;
591 }
592
593 static Standard_Integer OCC395 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
594 {
595   if(argc != 4) {
596     di << "Usage : " << argv[0] << " edge_result edge1 edge2" << "\n";
597     return 1;
598   }
599   //TCollection_AsciiString fnom(a[1]);
600   //Standard_Boolean modfic = XSDRAW::FileAndVar(a[1],a[2],a[3],"IGES",fnom,rnom,resnom);
601   TopoDS_Shape Sh1 = DBRep::Get(argv[2]);
602   TopoDS_Shape Sh2 = DBRep::Get(argv[3]);
603   if(Sh1.IsNull() || Sh2.IsNull()) return 1;
604   if(Sh1.ShapeType() != TopAbs_EDGE || Sh2.ShapeType() != TopAbs_EDGE) return 1;
605   TopoDS_Edge e1 = TopoDS::Edge(Sh1);
606   TopoDS_Edge e2 = TopoDS::Edge(Sh2);
607   Standard_Real f1,l1,f2,l2;
608   Standard_Boolean After =  Standard_True;
609   Handle(Geom_Curve) ac1 = BRep_Tool::Curve(e1,f1,l1);
610   Handle(Geom_Curve) ac2 = BRep_Tool::Curve(e2,f2,l2);
611   if(e1.Orientation() == TopAbs_REVERSED) {
612       //Standard_Real cf = cf1;
613       //cf1 = ac1->ReversedParameter ( cl1 );
614       //cl1 = ac1->ReversedParameter ( cf );
615       ac1 = ac1->Reversed();
616     }
617     if(e2.Orientation() == TopAbs_REVERSED) {
618       //Standard_Real cf = cf2;
619       //ac2 = ac2->ReversedParameter ( cl2 );
620       //ac2 = ac2->ReversedParameter ( cf );
621       ac2 = ac2->Reversed();
622     }
623   Handle(Geom_BSplineCurve) bsplc1 = Handle(Geom_BSplineCurve)::DownCast(ac1);
624   Handle(Geom_BSplineCurve) bsplc2 = Handle(Geom_BSplineCurve)::DownCast(ac2);
625   if(bsplc1.IsNull() || bsplc2.IsNull()) return 1;
626   gp_Pnt pmid = 0.5 * ( bsplc1->Pole(bsplc1->NbPoles()).XYZ() + bsplc2->Pole(1).XYZ() );
627   bsplc1->SetPole(bsplc1->NbPoles(), pmid);
628   bsplc2->SetPole(1, pmid);
629   GeomConvert_CompCurveToBSplineCurve connect3d(bsplc1);
630   if(!connect3d.Add(bsplc2,Precision::Confusion(), After, Standard_False)) return 1;
631   BRepBuilderAPI_MakeEdge MkEdge(connect3d.BSplineCurve());
632   if(MkEdge.IsDone()) {
633     TopoDS_Edge nedge = MkEdge.Edge();
634     DBRep::Set ( argv[1], nedge );
635     return 0;
636   }
637   else return 1;
638 }
639
640 static Standard_Integer OCC394 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
641 {
642   if(argc < 3) {
643     di << "Usage : " << argv[0] << " edge_result edge [tol [mode [tolang]]]" << "\n";
644     return 1;
645   }
646    TopoDS_Shape Sh = DBRep::Get(argv[2]);
647  
648    Standard_Integer k = 3;
649    Standard_Real tol = 100000;
650    Standard_Integer mode = 2;
651    Standard_Real tolang = M_PI/2;
652    if(argc > k) 
653      tol = Draw::Atof(argv[k++]);
654    
655    if(argc > k) 
656      mode=  Draw::Atoi(argv[k++]);
657    
658    if(argc > k) 
659      tolang = Draw::Atof(argv[k++]);
660      
661    
662    Handle(ShapeFix_Wireframe) aSfwr = new ShapeFix_Wireframe();
663    Handle(ShapeBuild_ReShape) aReShape = new ShapeBuild_ReShape;
664    aSfwr->SetContext(aReShape);
665    aSfwr->Load(Sh);
666    aSfwr->SetPrecision(tol);
667    Standard_Boolean aModeDrop = Standard_True;
668    if(mode == 2) 
669      aModeDrop = Standard_False;
670    
671     TopTools_MapOfShape theSmallEdges, theMultyEdges;
672   TopTools_DataMapOfShapeListOfShape theEdgeToFaces,theFaceWithSmall;
673   aSfwr->CheckSmallEdges(theSmallEdges,theEdgeToFaces,theFaceWithSmall, theMultyEdges);
674   aSfwr->MergeSmallEdges (theSmallEdges,theEdgeToFaces,theFaceWithSmall, theMultyEdges, aModeDrop,tolang);
675    //aSfwr->FixSmallEdges(); 
676   TopoDS_Shape resShape =  aSfwr->Shape();;
677   DBRep::Set ( argv[1], resShape );
678   return 0;
679 }
680
681 static Standard_Integer OCC301 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
682 {
683   //Handle(AIS_InteractiveContext)   context= ViewerTest_Tool::MakeContext ("OCC301");
684   //ViewerTest_Tool::InitViewerTest (context);
685   Handle(AIS_InteractiveContext) context = ViewerTest::GetAISContext();
686   if(context.IsNull()) {
687     di << "use 'vinit' command before " << argv[0] << "\n";
688     return 1;
689   }
690   if ( argc != 5 ) {
691     di << "Usage : " << argv[0] << " X Y Z ArrowSize" << "\n";
692     return 1;
693   }
694
695   Standard_Real X = Draw::Atof(argv[1]);
696   Standard_Real Y = Draw::Atof(argv[2]);
697   Standard_Real Z = Draw::Atof(argv[3]);
698   Standard_Real ArrowSize = Draw::Atof(argv[4]);
699
700   gp_Pnt p1 = gp_Pnt(10.,10.,0.);
701   gp_Pnt p2 = gp_Pnt(50.,10.,0.);
702   gp_Pnt p3 = gp_Pnt(50.,50.,0.);
703
704   TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(p1, p2);
705   TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(p2, p3);
706
707   context->Display(new AIS_Shape(E1)); 
708   context->Display(new AIS_Shape(E2)); 
709
710   gp_Pnt plnpt(0, 0, 0);
711   gp_Dir plndir(0, 0, 1);
712   Handle(Geom_Plane) pln = new Geom_Plane(plnpt,plndir);
713
714   Handle(AIS_AngleDimension) AngleDimension = new AIS_AngleDimension(E2, E1, pln, -3.14/2., "Angle");
715
716   AngleDimension->SetPosition(gp_Pnt(X, Y, Z));
717   AngleDimension->SetArrowSize(ArrowSize);
718
719   context->Display(AngleDimension);
720   return 0;
721 }
722
723 static Standard_Integer OCC294 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
724 {
725   if(argc < 4) {
726     di << "Usage : " << argv[0] << " shape_result shape edge" << "\n";
727     return 1;
728   }
729   TopoDS_Shape Sh1 = DBRep::Get(argv[2]);
730   TopoDS_Shape Sh2 = DBRep::Get(argv[3]);
731   if(Sh1.IsNull() || Sh2.IsNull()) return 1;
732   if(Sh2.ShapeType() != TopAbs_EDGE) return 1;
733
734   //QAModTopOpe_ReShaper ReShaper(Sh1);
735   QANewModTopOpe_ReShaper ReShaper(Sh1);
736   ReShaper.Remove(Sh2);
737   const TopoDS_Shape& ResultShape = ReShaper.GetResult();
738   if(ResultShape.IsNull()) {
739     di << "Faulty " << argv[0] << " : " << argv[1] << " - shape_result is null" << "\n";
740     return 1;
741   }
742
743   DBRep::Set ( argv[1], ResultShape);
744   return 0;
745 }
746
747 static Standard_Integer OCC60 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
748 {
749   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
750   if(aContext.IsNull()) { 
751     di << "use 'vinit' command before " << argv[0] << "\n";
752     return 1;
753   }
754   if(argc < 5) {
755     di << "Usage : " << argv[0] << " xmin ymin xmax ymax; selection window" << "\n";
756     return 1;
757   }
758
759   Standard_Integer xmin = Draw::Atoi(argv[1]);
760   Standard_Integer ymin = Draw::Atoi(argv[2]);
761   Standard_Integer xmax = Draw::Atoi(argv[3]);
762   Standard_Integer ymax = Draw::Atoi(argv[4]);
763
764   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
765
766   Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
767   EM->Select(xmin,ymin,xmax,ymax);
768
769   return 0;
770 }
771
772 static Standard_Integer OCC70 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
773 {
774   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
775   if(aContext.IsNull()) { 
776     di << "use 'vinit' command before " << argv[0] << "\n";
777     return 1;
778   }
779   if(argc < 7) {
780     di << "Usage : " << argv[0] << " x1 y1 x2 y2 x3 y3 [x y ...]; polygon of selection" << "\n";
781     return 1;
782   }
783   if (((argc - 1) % 2) != 0) {
784     di << "Usage : " << argv[0] << " x1 y1 x2 y2 x3 y3 [x y ...]; polygon of selection" << "\n";
785     return 1;
786   }
787
788   Standard_Integer i, j, np = (argc-1) / 2;
789   TColgp_Array1OfPnt2d Polyline(1,np);
790   j = 1;
791   for (i = 1; i <= np; i++) {
792     Polyline(i) = gp_Pnt2d(Draw::Atof(argv[j]), Draw::Atof(argv[j+1]));
793     j += 2;
794   }
795
796   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
797
798   aContext->Select(Polyline,V3dView);
799   aContext->UpdateCurrentViewer();
800
801   return 0;
802 }
803
804 static Standard_Integer OCC261 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
805 {
806   if(argc != 2) {
807     di << "Usage : " << argv[0] << " Doc" << "\n";
808     return 1;
809   }
810
811   Handle(TDocStd_Document) Doc;
812   if(DDocStd::GetDocument(argv[1], Doc)) {
813     Doc->ClearRedos();
814     return 0;
815   } else
816     return 1;
817 }
818
819 #include <OSD_File.hxx>
820 static Standard_Integer OCC710 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
821 {
822   if(argc != 2) {
823     di << "Usage : " << argv[0] << " path" << "\n";
824   }
825
826   TCollection_AsciiString in(argv[1]);
827   OSD_File* aFile = new OSD_File(in);
828   Standard_Boolean anExists = aFile->Exists();
829   if(anExists == Standard_True) 
830     di << "1" << "\n";
831   else
832     di << "0" << "\n";
833   return 0;
834 }
835
836 #include <ShapeFix_Shell.hxx>
837 static Standard_Integer OCC904 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
838 {
839   if(argc != 4) {
840     di << "Usage : " << argv[0] << " result shape nonmanifoldmode(0/1)" << "\n";
841   }
842   TopoDS_Shape S = DBRep::Get(argv[2]);
843   if (S.IsNull() || S.ShapeType() != TopAbs_SHELL) {
844     di << " Shape is null" << "\n";
845     return 1;
846   }
847   Standard_Boolean nonmanifmode = (Draw::Atoi(argv[3]) != 0);
848   Handle(ShapeFix_Shell) SFSh = new ShapeFix_Shell;
849   SFSh->FixFaceOrientation(TopoDS::Shell(S),Standard_True,nonmanifmode);
850   DBRep::Set(argv[1],SFSh->Shape());
851   return 0;
852 }
853
854 void QABugs::Commands_16(Draw_Interpretor& theCommands) {
855   const char *group = "QABugs";
856
857   theCommands.Add ("BUC60848", "BUC60848 shape", __FILE__, BUC60848, group);
858   theCommands.Add ("BUC60828", "BUC60828", __FILE__, BUC60828, group);
859   theCommands.Add ("BUC60814", "BUC60814", __FILE__, BUC60814, group);
860   theCommands.Add ("BUC60774", "BUC60774", __FILE__, BUC60774, group);
861   theCommands.Add ("BUC60972", "BUC60972 edge edge plane val text ", __FILE__, BUC60972, group);
862   theCommands.Add ("OCC218", "OCC218 name plane Xlabel Ylabel", __FILE__, OCC218bug, group);
863   theCommands.Add ("OCC295", "OCC295 edge_result edge1 edge2", __FILE__, OCC295, group);
864   theCommands.Add ("OCC49", "OCC49 name", __FILE__, OCC49, group);
865   theCommands.Add ("OCC132", "OCC132 DependentName", __FILE__, OCC132, group);
866   theCommands.Add ("OCC405", "OCC405 edge_result edge1 edge2; merge two edges", __FILE__, OCC405, group);
867   theCommands.Add ("OCC252", "OCC252 result part tool [ModeOfLimitation=0/1/2]", __FILE__, OCC252, group);
868   theCommands.Add ("OCC307", "OCC307 result part tool [AllowCutting=0/1]", __FILE__, OCC307, group);
869   theCommands.Add ("OCC395", "OCC395 edge_result edge1 edge2", __FILE__, OCC395, group);
870   theCommands.Add ("OCC394", "OCC394 edge_result edge [tol [mode [tolang]]]", __FILE__, OCC394, group);
871   theCommands.Add ("OCC301", "OCC301 X Y Z ArrowSize", __FILE__, OCC301, group);
872   theCommands.Add ("OCC294", "OCC294 shape_result shape edge", __FILE__, OCC294, group);
873   theCommands.Add ("OCC60", "OCC60 xmin ymin xmax ymax; selection window", __FILE__, OCC60, group);
874   theCommands.Add ("OCC70", "OCC70 x1 y1 x2 y2 x3 y3 [x y ...]; polygon of selection", __FILE__, OCC70, group);
875   theCommands.Add ("OCC261", "OCC261 Doc", __FILE__, OCC261, group);
876   theCommands.Add ("OCC710", "OCC710 path", __FILE__, OCC710, group);
877   theCommands.Add ("OCC904", "OCC904 result shape nonmanifoldmode(0/1)", __FILE__, OCC904, group);
878
879   return;
880 }