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