0022898: IGES import fails in german environment
[occt.git] / src / QABugs / QABugs_8.cxx
1 // Created on: 2002-03-19
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 <TColStd_Array2OfReal.hxx>
32 #include <V3d_View.hxx>
33 #include <Visual3d_View.hxx>
34
35 #include <BRepOffsetAPI_Sewing.hxx>
36
37 #include <AIS_ListOfInteractive.hxx>
38 #include <AIS_ListIteratorOfListOfInteractive.hxx>
39
40 #include <BRepPrimAPI_MakeBox.hxx>
41
42 static Standard_Integer BUC60753 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
43 {
44   if(argc!=3)
45   {
46     di << "Usage : " << argv[0] << " mode (0 <=mode<=5) ratio (0.0<=ration<=1.0)" <<"\n";
47     return -1;
48   }
49
50   Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext();
51   if(myAISContext.IsNull()) {
52     di << "use 'vinit' command before " << argv[0] << "\n";
53     return 1;
54   }
55            
56   Standard_Real Alpha = M_PI/10.;
57   Standard_Real CosAlpha = Cos (Alpha);
58   Standard_Real SinAlpha = Sin (Alpha);
59   Standard_Real MoinsCosAlpha = Cos (-Alpha);
60   Standard_Real MoinsSinAlpha = Sin (-Alpha);
61   TColStd_Array2OfReal TrsfI (0, 3, 0, 3);
62   TColStd_Array2OfReal TrsfX (0, 3, 0, 3);
63   TColStd_Array2OfReal TrsfY (0, 3, 0, 3);
64   TColStd_Array2OfReal TrsfZ (0, 3, 0, 3);
65   TColStd_Array2OfReal Trsfx (0, 3, 0, 3);
66   TColStd_Array2OfReal Trsfy (0, 3, 0, 3);
67   TColStd_Array2OfReal Trsfz (0, 3, 0, 3);
68   Standard_Integer i,j;
69   for (i=0; i<=3; i++)
70     for (j=0; j<=3; j++)
71       if (i == j) { 
72         TrsfX.SetValue (i, j, 1.0);
73         TrsfY.SetValue (i, j, 1.0);
74         TrsfZ.SetValue (i, j, 1.0);
75         Trsfx.SetValue (i, j, 1.0);
76         Trsfy.SetValue (i, j, 1.0);
77         Trsfz.SetValue (i, j, 1.0);
78         TrsfI.SetValue (i, j, 1.0);
79       } else { 
80         TrsfX.SetValue (i, j, 0.0);
81         TrsfY.SetValue (i, j, 0.0);
82         TrsfZ.SetValue (i, j, 0.0);
83         Trsfx.SetValue (i, j, 0.0);
84         Trsfy.SetValue (i, j, 0.0);
85         Trsfz.SetValue (i, j, 0.0);
86         TrsfI.SetValue (i, j, 0.0);
87       }
88         
89   // Rotation Alpha autour de l'axe X
90   TrsfX.SetValue (1, 1, CosAlpha);
91   TrsfX.SetValue (2, 2, CosAlpha);
92   TrsfX.SetValue (1, 2, -SinAlpha);
93   TrsfX.SetValue (2, 1, SinAlpha);
94   
95   // Rotation Alpha autour de l'axe Y
96   TrsfY.SetValue (0, 0, CosAlpha);
97   TrsfY.SetValue (2, 2, CosAlpha);
98   TrsfY.SetValue (0, 2, SinAlpha);
99   TrsfY.SetValue (2, 0, -SinAlpha);
100   
101   // Rotation Alpha autour de l'axe Z
102   TrsfZ.SetValue (0, 0, CosAlpha);
103   TrsfZ.SetValue (1, 1, CosAlpha);
104   TrsfZ.SetValue (0, 1, -SinAlpha);
105   TrsfZ.SetValue (1, 0, SinAlpha);
106   
107   // Rotation -Alpha autour de l'axe X
108   Trsfx.SetValue (1, 1, MoinsCosAlpha);
109   Trsfx.SetValue (2, 2, MoinsCosAlpha);
110   Trsfx.SetValue (1, 2, -MoinsSinAlpha);
111   Trsfx.SetValue (2, 1, MoinsSinAlpha);
112   
113   // Rotation -Alpha autour de l'axe Y
114   Trsfy.SetValue (0, 0, MoinsCosAlpha);
115   Trsfy.SetValue (2, 2, MoinsCosAlpha);
116   Trsfy.SetValue (0, 2, MoinsSinAlpha);
117         Trsfy.SetValue (2, 0, -MoinsSinAlpha);
118   
119   // Rotation -Alpha autour de l'axe Z
120   Trsfz.SetValue (0, 0, MoinsCosAlpha);
121   Trsfz.SetValue (1, 1, MoinsCosAlpha);
122   Trsfz.SetValue (0, 1, -MoinsSinAlpha);
123   Trsfz.SetValue (1, 0, MoinsSinAlpha);
124   
125   Handle(V3d_View) myV3dView = ViewerTest::CurrentView();
126   
127   myV3dView->SetAnimationMode(Standard_True,Standard_True);
128   myAISContext-> SetDegenerateModel((Aspect_TypeOfDegenerateModel) Draw::Atoi(argv[1]),Draw::Atof(argv[2]));
129   
130 //                Timer.Reset ();
131 //                Timer.Start ();
132   myV3dView->SetAnimationModeOn();
133   myV3dView->SetComputedMode ( Standard_False );
134   for (i=0;i<40;i++) {
135     myV3dView->View()->SetTransform (Trsfz);
136     myV3dView->View()->Update ();
137   }
138   myV3dView->SetAnimationModeOff();
139 //                Timer.Stop ();
140 //                Timer.Show (cout);   
141
142   return 0;
143 }
144
145 static Standard_Integer  OCC162 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
146 {
147   if ( argc != 2 ) {
148     di << "Usage : " << argv[0] << " name" << "\n";
149     return 1;
150   }
151
152   TopoDS_Shape aShape = DBRep::Get(argv[1]);
153   if (aShape.IsNull()) return 0;
154
155   Standard_Real tolValue = 0.0001;
156   BRepOffsetAPI_Sewing sew(tolValue);
157   sew.Add(aShape);
158   sew.Perform();
159   TopoDS_Shape aSewed = sew.SewedShape();
160   
161   return 0;     
162 }
163
164 static Standard_Integer  OCC172 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv)
165 {
166   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
167   if(aContext.IsNull()) { 
168     di << "use 'vinit' command before " << argv[0] << "\n";
169     return 1;
170   }
171   
172   AIS_ListOfInteractive aListOfIO;
173   aContext->DisplayedObjects(aListOfIO);
174   AIS_ListIteratorOfListOfInteractive It;
175   for (It.Initialize(aListOfIO);It.More();It.Next())
176     {
177       aContext->AddOrRemoveCurrentObject(It.Value());
178     }
179   
180   return 0;     
181 }
182
183 static Standard_Integer  OCC204 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
184 {
185   if ( argc != 2 ) {
186     di << "Usage : " << argv[0] << " updateviewer=0/1" << "\n";
187     return 1;
188   }
189
190   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
191   if (aContext.IsNull()) { 
192     di << "use 'vinit' command before " << argv[0] << "\n";
193     return 1;
194   }
195   Standard_Boolean UpdateViewer = Standard_True;
196   Standard_Integer IntegerUpdateViewer = Draw::Atoi(argv[1]);
197   if (IntegerUpdateViewer == 0) {
198     UpdateViewer = Standard_False;
199   }
200
201   Standard_Integer deltaY = -500;
202   BRepPrimAPI_MakeBox box1(gp_Pnt(0, 0 + deltaY, 0),  gp_Pnt(100, 100 + deltaY, 100));
203   BRepPrimAPI_MakeBox box2(gp_Pnt(120, 120 + deltaY, 120),  gp_Pnt(300, 300 + deltaY,300));
204   BRepPrimAPI_MakeBox box3(gp_Pnt(320, 320 + deltaY, 320),  gp_Pnt(500, 500 + deltaY,500));
205
206   Handle_AIS_Shape ais1 = new AIS_Shape(box1.Shape());
207   Handle_AIS_Shape ais2 = new AIS_Shape(box2.Shape());
208   Handle_AIS_Shape ais3 = new AIS_Shape(box3.Shape());
209
210   aContext->Display(ais1);
211   aContext->Display(ais2);
212   aContext->Display(ais3);
213
214   aContext->AddOrRemoveCurrentObject(ais1);
215   aContext->AddOrRemoveCurrentObject(ais2);
216   aContext->AddOrRemoveCurrentObject(ais3);
217
218   //printf("\n No of currents = %d", aContext->NbCurrents());
219
220   aContext->InitCurrent();
221   
222   //int count = 1;
223   while(aContext->MoreCurrent())
224   {
225     //printf("\n count is = %d",  count++);
226     Handle_AIS_InteractiveObject ais = aContext->Current();
227     aContext->Remove(ais, UpdateViewer);
228     aContext->InitCurrent();
229   }
230   
231   return 0;     
232 }
233
234 #include <gp_Lin.hxx>
235 #include <BRepClass3d_Intersector3d.hxx>
236 #include <TopoDS.hxx>
237 static Standard_Integer OCC1651 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
238 {
239   if ( argc != 8 ) {
240     di << "Usage : " << argv[0] << " Shape PntX PntY PntZ DirX DirY DirZ" << "\n";
241     return 1;
242   }
243
244   TopoDS_Shape aShape = DBRep::Get(argv[1]);
245   if (aShape.IsNull()) return 0;
246
247   gp_Pnt aP1(Draw::Atof(argv[2]), Draw::Atof(argv[3]), Draw::Atof(argv[4]));
248   gp_Dir aD1(Draw::Atof(argv[5]), Draw::Atof(argv[6]), Draw::Atof(argv[7]));
249   gp_Lin aL1(aP1,aD1);
250   BRepClass3d_Intersector3d aI1;
251   aI1.Perform(aL1, -250, 1e-7, TopoDS::Face(aShape));
252   if(aI1.IsDone() && aI1.HasAPoint()) {
253     gp_Pnt aR1 = aI1.Pnt();
254     di << aR1.X() << " " << aR1.Y() << " " << aR1.Z() << "\n";
255   }
256
257   return 0;
258 }
259
260 void QABugs::Commands_8(Draw_Interpretor& theCommands) {
261   const char *group = "QABugs";
262
263   theCommands.Add("BUC60753", "BUC60753 mode ratio", __FILE__, BUC60753, group);
264   theCommands.Add("OCC162", "OCC162 name", __FILE__, OCC162, group);
265   theCommands.Add("OCC172", "OCC172", __FILE__, OCC172, group);
266   theCommands.Add("OCC204", "OCC204 updateviewer=0/1", __FILE__, OCC204, group);
267   theCommands.Add("OCC1651", "OCC1651 Shape PntX PntY PntZ DirX DirY DirZ", __FILE__, OCC1651, group);
268
269   return;
270 }