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