0022898: IGES import fails in german environment
[occt.git] / src / ViewerTest / ViewerTest_ViewerCommands.cxx
1 // Created on: 1998-09-01
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 // Robert Boehne 30 May 2000 : Dec Osf
23
24 #ifdef HAVE_CONFIG_H
25 # include <config.h>
26 #endif
27
28 #ifdef WNT
29 #include <windows.h>
30 #endif
31
32 #include <Graphic3d_AspectMarker3d.hxx>
33 #include <Graphic3d_GraphicDriver.hxx>
34 #include <Graphic3d_ExportFormat.hxx>
35 #include <ViewerTest.hxx>
36 #include <ViewerTest_EventManager.hxx>
37 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
38 #include <Visual3d_View.hxx>
39 #include <Visual3d_ViewManager.hxx>
40 #include <V3d_LayerMgr.hxx>
41 #include <NIS_View.hxx>
42 #include <NIS_Triangulated.hxx>
43 #include <NIS_InteractiveContext.hxx>
44 #include <AIS_InteractiveContext.hxx>
45 #include <Draw_Interpretor.hxx>
46 #include <Draw.hxx>
47 #include <Draw_Appli.hxx>
48 #include <Aspect_PrintAlgo.hxx>
49 #include <Image_AlienPixMap.hxx>
50 #include <OSD_Timer.hxx>
51 #include <TColStd_SequenceOfInteger.hxx>
52 #include <TColStd_HSequenceOfReal.hxx>
53 #include <TColgp_Array1OfPnt2d.hxx>
54 #include <Visual3d_LayerItem.hxx>
55 #include <V3d_LayerMgr.hxx>
56 #include <V3d_LayerMgrPointer.hxx>
57 #include <Aspect_TypeOfLine.hxx>
58 #include <Image_Diff.hxx>
59
60 #ifdef WNT
61 #undef DrawText
62 #endif
63
64 #include <Visual3d_Layer.hxx>
65 #include <cstdlib>
66
67 #if defined(_WIN32) || defined(__WIN32__)
68   #include <Graphic3d_WNTGraphicDevice.hxx>
69   #include <WNT_WClass.hxx>
70   #include <WNT_Window.hxx>
71
72   #if defined(_MSC_VER)
73     #define _CRT_SECURE_NO_DEPRECATE
74     #pragma warning (disable:4996)
75   #endif
76 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
77   #include <Graphic3d_GraphicDevice.hxx>
78   #include <Cocoa_Window.hxx>
79   #include <tk.h>
80 #else
81   #include <Graphic3d_GraphicDevice.hxx>
82   #include <Xw_GraphicDevice.hxx>
83   #include <Xw_WindowQuality.hxx>
84   #include <Xw_Window.hxx>
85   #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
86   #include <X11/Xutil.h>
87   #include <tk.h>
88 #endif
89
90 //==============================================================================
91
92 //==============================================================================
93 //  VIEWER GLOBAL VARIABLES
94 //==============================================================================
95
96 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
97
98 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
99 extern const Handle(NIS_InteractiveContext)& TheNISContext();
100 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
101
102 #if defined(_WIN32) || defined(__WIN32__)
103 static Handle(Graphic3d_WNTGraphicDevice)& GetG3dDevice(){
104   static Handle(Graphic3d_WNTGraphicDevice) GD;
105   return GD;
106 }
107
108 static Handle(WNT_Window)& VT_GetWindow() {
109   static Handle(WNT_Window) WNTWin;
110   return WNTWin;
111 }
112 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
113 static Handle(Graphic3d_GraphicDevice)& GetG3dDevice()
114 {
115   static Handle(Graphic3d_GraphicDevice) aGraphicDevice;
116   return aGraphicDevice;
117 }
118 static Handle(Cocoa_Window)& VT_GetWindow()
119 {
120   static Handle(Cocoa_Window) aWindow;
121   return aWindow;
122 }
123 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
124 #else
125 static Handle(Graphic3d_GraphicDevice)& GetG3dDevice(){
126   static Handle(Graphic3d_GraphicDevice) GD;
127   return GD;
128 }
129 static Handle(Xw_Window)& VT_GetWindow(){
130   static Handle(Xw_Window) XWWin;
131   return XWWin;
132 }
133 static Display *display;
134
135 static void VProcessEvents(ClientData,int);
136 #endif
137
138 static Standard_Boolean DegenerateMode = Standard_True;
139
140 #define ZCLIPWIDTH 1.
141
142 static void OSWindowSetup();
143
144 //==============================================================================
145 //  EVENT GLOBAL VARIABLES
146 //==============================================================================
147
148 static int Start_Rot = 0;
149 static int ZClipIsOn = 0;
150 int X_Motion = 0; // Current cursor position
151 int Y_Motion = 0;
152 int X_ButtonPress = 0; // Last ButtonPress position
153 int Y_ButtonPress = 0;
154 Standard_Boolean IsDragged = Standard_False;
155 Standard_Boolean DragFirst;
156
157 //==============================================================================
158
159 #ifdef WNT
160 static LRESULT WINAPI ViewerWindowProc(
161                                        HWND hwnd,
162                                        UINT uMsg,
163                                        WPARAM wParam,
164                                        LPARAM lParam );
165 static LRESULT WINAPI AdvViewerWindowProc(
166   HWND hwnd,
167   UINT uMsg,
168   WPARAM wParam,
169   LPARAM lParam );
170 #endif
171
172
173 //==============================================================================
174 //function : WClass
175 //purpose  :
176 //==============================================================================
177
178 const Handle(MMgt_TShared)& ViewerTest::WClass()
179 {
180   static Handle(MMgt_TShared) theWClass;
181 #if defined(_WIN32) || defined(__WIN32__)
182   if (theWClass.IsNull())
183   {
184     theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
185       CS_VREDRAW | CS_HREDRAW, 0, 0,
186       ::LoadCursor (NULL, IDC_ARROW));
187   }
188 #endif
189   return theWClass;
190 }
191
192 //==============================================================================
193 //function : ViewerInit
194 //purpose  : Create the window viewer and initialize all the global variable
195 //==============================================================================
196
197 void ViewerTest::ViewerInit (const Standard_Integer thePxLeft,  const Standard_Integer thePxTop,
198                              const Standard_Integer thePxWidth, const Standard_Integer thePxHeight)
199 {
200   static Standard_Boolean isFirst = Standard_True;
201
202   // Default position and dimension of the viewer window.
203   // Note that left top corner is set to be sufficiently small to have
204   // window fit in the small screens (actual for remote desktops, see #23003).
205   // The position corresponds to the window's client area, thus some
206   // gap is added for window frame to be visible.
207   Standard_Integer aPxLeft   = 20;
208   Standard_Integer aPxTop    = 40;
209   Standard_Integer aPxWidth  = 409;
210   Standard_Integer aPxHeight = 409;
211   if (thePxWidth != 0 && thePxHeight != 0)
212   {
213     aPxLeft   = thePxLeft;
214     aPxTop    = thePxTop;
215     aPxWidth  = thePxWidth;
216     aPxHeight = thePxHeight;
217   }
218
219   if (isFirst)
220   {
221     // Create the Graphic device
222 #if defined(_WIN32) || defined(__WIN32__)
223     if (GetG3dDevice().IsNull()) GetG3dDevice() = new Graphic3d_WNTGraphicDevice();
224     if (VT_GetWindow().IsNull())
225     {
226       // Create the Graphic device and the window
227       Handle(WNT_GraphicDevice) g_Device = new WNT_GraphicDevice();
228
229       VT_GetWindow() = new WNT_Window (g_Device, "Test3d",
230                                        Handle(WNT_WClass)::DownCast (WClass()),
231                                        WS_OVERLAPPEDWINDOW,
232                                        aPxLeft, aPxTop,
233                                        aPxWidth, aPxHeight,
234                                        Quantity_NOC_BLACK);
235     }
236 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
237     if (GetG3dDevice().IsNull())
238     {
239       GetG3dDevice() = new Graphic3d_GraphicDevice (getenv ("DISPLAY"), Xw_TOM_READONLY);
240     }
241     if (VT_GetWindow().IsNull())
242     {
243       VT_GetWindow() = new Cocoa_Window ("Test3d",
244                                          aPxLeft, aPxTop,
245                                          aPxWidth, aPxHeight);
246       ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
247     }
248 #else
249     if (GetG3dDevice().IsNull()) GetG3dDevice() =
250       new Graphic3d_GraphicDevice (getenv ("DISPLAY"), Xw_TOM_READONLY);
251     if (VT_GetWindow().IsNull())
252     {
253       VT_GetWindow() = new Xw_Window (GetG3dDevice(),
254                                       "Test3d",
255                                       aPxLeft, aPxTop,
256                                       aPxWidth, aPxHeight,
257                                       Xw_WQ_3DQUALITY,
258                                       Quantity_NOC_BLACK);
259     }
260 #endif
261     VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
262
263     Handle(V3d_Viewer) a3DViewer, a3DCollector;
264     // Viewer and View creation
265
266     TCollection_ExtendedString NameOfWindow("Visu3D");
267
268     a3DViewer = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
269     NameOfWindow = TCollection_ExtendedString("Collector");
270     a3DCollector = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
271     a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
272     a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
273     Handle(NIS_View) aView = Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
274     if (aView.IsNull())
275     {
276       //Handle(V3d_View) a3DViewCol = a3DViewer->CreateView();
277       aView = new NIS_View (a3DViewer, VT_GetWindow());
278       ViewerTest::CurrentView(aView);
279       TheNISContext()->AttachView (aView);
280     }
281
282     // AIS setup
283     if ( ViewerTest::GetAISContext().IsNull() ) {
284       Handle(AIS_InteractiveContext) C =
285         new AIS_InteractiveContext(a3DViewer,a3DCollector);
286       ViewerTest::SetAISContext(C);
287     }
288
289     // Setup for X11 or NT
290     OSWindowSetup();
291     // Viewer and View creation
292
293     a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
294
295     Handle (V3d_View) V = ViewerTest::CurrentView();
296
297     V->SetDegenerateModeOn();
298     DegenerateMode = V->DegenerateModeIsOn();
299     //    V->SetWindow(VT_GetWindow(), NULL, MyViewProc, NULL);
300
301     V->SetZClippingDepth(0.5);
302     V->SetZClippingWidth(ZCLIPWIDTH/2.);
303     a3DViewer->SetDefaultLights();
304     a3DViewer->SetLightOn();
305
306   #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
307   #if TCL_MAJOR_VERSION  < 8
308     Tk_CreateFileHandler((void*)ConnectionNumber(display),
309       TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
310   #else
311     Tk_CreateFileHandler(ConnectionNumber(display),
312       TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
313   #endif
314   #endif
315
316     isFirst = Standard_False;
317   }
318
319   VT_GetWindow()->Map();
320   ViewerTest::CurrentView()->Redraw();
321 }
322
323 //==============================================================================
324 //function : Vinit
325 //purpose  : Create the window viewer and initialize all the global variable
326 //    Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
327 //==============================================================================
328
329 static int VInit (Draw_Interpretor& , Standard_Integer argc, const char** argv)
330 {
331   Standard_Integer aPxLeft   = (argc > 1) ? Draw::Atoi (argv[1]) : 0;
332   Standard_Integer aPxTop    = (argc > 2) ? Draw::Atoi (argv[2]) : 0;
333   Standard_Integer aPxWidth  = (argc > 3) ? Draw::Atoi (argv[3]) : 0;
334   Standard_Integer aPxHeight = (argc > 4) ? Draw::Atoi (argv[4]) : 0;
335   ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight);
336   return 0;
337 }
338
339 //==============================================================================
340 //function : VT_ProcessKeyPress
341 //purpose  : Handle KeyPress event from a CString
342 //==============================================================================
343 void VT_ProcessKeyPress (const char* buf_ret)
344 {
345   //cout << "KeyPress" << endl;
346   const Handle(V3d_View) aView = ViewerTest::CurrentView();
347   const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
348   // Letter in alphabetic order
349
350   if ( !strcasecmp(buf_ret, "A") ) {
351     // AXO
352     aView->SetProj(V3d_XposYnegZpos);
353   }
354   else if ( !strcasecmp(buf_ret, "D") ) {
355     // Reset
356     aView->Reset();
357   }
358   else if ( !strcasecmp(buf_ret, "F") ) {
359     // FitAll
360     if (aNisView.IsNull())
361       aView->FitAll();
362     else
363       aNisView->FitAll3d();
364   }
365   else if ( !strcasecmp(buf_ret, "H") ) {
366     // HLR
367     cout << "HLR" << endl;
368
369     if (aView->DegenerateModeIsOn()) ViewerTest::CurrentView()->SetDegenerateModeOff();
370     else aView->SetDegenerateModeOn();
371     DegenerateMode = aView->DegenerateModeIsOn();
372   }
373   else if ( !strcasecmp(buf_ret, "S") ) {
374     // SHADING
375     cout << "passage en mode 1 (shading pour les shapes)" << endl;
376
377     Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
378     if(Ctx->NbCurrents()==0 ||
379       Ctx->NbSelected()==0)
380       Ctx->SetDisplayMode(AIS_Shaded);
381     else{
382       if(Ctx->HasOpenedContext()){
383         for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
384           Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
385       }
386       else{
387         for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
388           Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
389       }
390       Ctx->UpdateCurrentViewer();
391     }
392   }
393   else if ( !strcasecmp(buf_ret, "U") ) {
394     // Unset display mode
395     cout<<"passage au mode par defaut"<<endl;
396
397     Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
398     if(Ctx->NbCurrents()==0 ||
399       Ctx->NbSelected()==0)
400       Ctx->SetDisplayMode(AIS_WireFrame);
401     else{
402       if(Ctx->HasOpenedContext()){
403         for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
404           Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
405       }
406       else{
407         for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
408           Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
409       }
410       Ctx->UpdateCurrentViewer();
411     }
412
413   }
414   else if ( !strcasecmp(buf_ret, "T") ) {
415     // Top
416     aView->SetProj(V3d_Zpos);
417   }
418   else if ( !strcasecmp(buf_ret, "B") ) {
419     // Bottom
420     aView->SetProj(V3d_Zneg);
421   }
422   else if ( !strcasecmp(buf_ret, "L") ) {
423     // Left
424     aView->SetProj(V3d_Xneg);
425   }
426   else if ( !strcasecmp(buf_ret, "R") ) {
427     // Right
428     aView->SetProj(V3d_Xpos);
429   }
430
431   else if ( !strcasecmp(buf_ret, "W") ) {
432     // WIREFRAME
433     cout << "passage en mode 0 (filaire pour les shapes)" << endl;
434     Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
435     if(Ctx->NbCurrents()==0 ||
436       Ctx->NbSelected()==0)
437       Ctx->SetDisplayMode(AIS_WireFrame);
438     else{
439       if(Ctx->HasOpenedContext()){
440         for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
441           Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
442       }
443       else{
444         for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
445           Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
446       }
447       Ctx->UpdateCurrentViewer();
448     }
449   }
450   else if ( !strcasecmp(buf_ret, "Z") ) {
451     // ZCLIP
452
453     if ( ZClipIsOn ) {
454       cout << "ZClipping OFF" << endl;
455       ZClipIsOn = 0;
456
457       aView->SetZClippingType(V3d_OFF);
458       aView->Redraw();
459     }
460     else {
461       cout << "ZClipping ON" << endl;
462       ZClipIsOn = 1;
463
464       aView->SetZClippingType(V3d_FRONT);
465       aView->Redraw();
466     }
467   }
468   else if ( !strcasecmp(buf_ret, ",") ) {
469     ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
470
471
472   }
473   else if ( !strcasecmp(buf_ret, ".") ) {
474     ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
475   }
476   // Number
477   else{
478     Standard_Integer Num = Draw::Atoi(buf_ret);
479     if(Num>=0 && Num<=7)
480       ViewerTest::StandardModeActivation(Num);
481   }
482 }
483
484 //==============================================================================
485 //function : VT_ProcessExpose
486 //purpose  : Redraw the View on an Expose Event
487 //==============================================================================
488 void VT_ProcessExpose()
489 {
490   Handle(V3d_View) aView3d = ViewerTest::CurrentView();
491   if (!aView3d.IsNull())
492   {
493     aView3d->Redraw();
494   }
495 }
496
497 //==============================================================================
498 //function : VT_ProcessConfigure
499 //purpose  : Resize the View on an Configure Event
500 //==============================================================================
501 void VT_ProcessConfigure()
502 {
503   Handle(V3d_View) aView3d = ViewerTest::CurrentView();
504   if (aView3d.IsNull())
505   {
506     return;
507   }
508
509   aView3d->MustBeResized();
510   aView3d->Update();
511   aView3d->Redraw();
512 }
513
514 //==============================================================================
515 //function : VT_ProcessButton1Press
516 //purpose  : Picking
517 //==============================================================================
518 Standard_Boolean VT_ProcessButton1Press(
519   Standard_Integer ,
520   const char**     argv,
521   Standard_Boolean pick,
522   Standard_Boolean shift)
523 {
524   Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
525   if ( pick ) {
526     Standard_Real X, Y, Z;
527
528     ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
529
530     Draw::Set(argv[1], X);
531     Draw::Set(argv[2], Y);
532     Draw::Set(argv[3], Z);}
533
534   if(shift)
535     EM->ShiftSelect();
536   else
537     EM->Select();
538
539   pick = 0;
540   return pick;
541 }
542
543 //==============================================================================
544 //function : VT_ProcessButton1Release
545 //purpose  : End selecting
546 //==============================================================================
547 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
548 {
549   if (IsDragged)
550   {
551     IsDragged = Standard_False;
552     Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
553     if (theIsShift)
554     {
555       EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
556                        Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
557     }
558     else
559     {
560       EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
561                   Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
562     }
563   }
564 }
565
566 //==============================================================================
567 //function : VT_ProcessButton3Press
568 //purpose  : Start Rotation
569 //==============================================================================
570 void VT_ProcessButton3Press()
571 {
572   Start_Rot = 1;
573   ViewerTest::CurrentView()->SetDegenerateModeOn();
574   ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
575 }
576
577 //==============================================================================
578 //function : VT_ProcessButton3Release
579 //purpose  : End rotation
580 //==============================================================================
581 void VT_ProcessButton3Release()
582 {
583   if (Start_Rot)
584   {
585     Start_Rot = 0;
586     if (!DegenerateMode) ViewerTest::CurrentView()->SetDegenerateModeOff();
587   }
588 }
589
590 //==============================================================================
591 //function : ProcessZClipMotion
592 //purpose  : Zoom
593 //==============================================================================
594
595 void ProcessZClipMotion()
596 {
597   Handle(V3d_View)  a3DView = ViewerTest::CurrentView();
598   if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
599     static Standard_Real CurZPos = 0.;
600
601     //Quantity_Length VDX, VDY;
602     //a3DView->Size(VDX,VDY);
603     //Standard_Real VDZ = a3DView->ZSize();
604     //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
605
606     Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
607
608     // Front = Depth + width/2.
609     Standard_Real D = 0.5;
610     Standard_Real W = 0.1;
611
612     CurZPos += (dx);
613
614     D += CurZPos;
615
616     //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
617
618     a3DView->SetZClippingType(V3d_OFF);
619     a3DView->SetZClippingDepth(D);
620     a3DView->SetZClippingWidth(W);
621     a3DView->SetZClippingType(V3d_FRONT);
622
623     a3DView->Redraw();
624
625     X_ButtonPress = X_Motion;
626     Y_ButtonPress = Y_Motion;
627   }
628 }
629
630 //==============================================================================
631 //function : ProcessControlButton1Motion
632 //purpose  : Zoom
633 //==============================================================================
634
635 static void ProcessControlButton1Motion()
636 {
637   ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
638
639   X_ButtonPress = X_Motion;
640   Y_ButtonPress = Y_Motion;
641 }
642
643 //==============================================================================
644 //function : VT_ProcessControlButton2Motion
645 //purpose  : Panning
646 //==============================================================================
647 void VT_ProcessControlButton2Motion()
648 {
649   Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
650   Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
651
652   dy = -dy; // Xwindow Y axis is from top to Bottom
653
654   ViewerTest::CurrentView()->Panning( dx, dy );
655
656   X_ButtonPress = X_Motion;
657   Y_ButtonPress = Y_Motion;
658 }
659
660 //==============================================================================
661 //function : VT_ProcessControlButton3Motion
662 //purpose  : Rotation
663 //==============================================================================
664 void VT_ProcessControlButton3Motion()
665 {
666   if (Start_Rot)
667   {
668     ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
669   }
670 }
671
672 //==============================================================================
673 //function : VT_ProcessMotion
674 //purpose  :
675 //==============================================================================
676 void VT_ProcessMotion()
677 {
678   //pre-hilights detected objects at mouse position
679
680   Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
681   EM->MoveTo(X_Motion, Y_Motion);
682 }
683
684
685 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
686 {
687   Xpix = X_Motion;Ypix=Y_Motion;
688 }
689
690 //==============================================================================
691 //function : ViewProject: implements VAxo, VTop, VLeft, ...
692 //purpose  : Switches to an axonometric, top, left and other views
693 //==============================================================================
694
695 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
696 {
697   if ( ViewerTest::CurrentView().IsNull() )
698   {
699     di<<"Call vinit before this command, please"<<"\n";
700     return 1;
701   }
702
703   ViewerTest::CurrentView()->SetProj(ori);
704   return 0;
705 }
706
707 //==============================================================================
708 //function : VAxo
709 //purpose  : Switch to an Axonometric view
710 //Draw arg : No args
711 //==============================================================================
712
713 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
714 {
715   return ViewProject(di, V3d_XposYnegZpos);
716 }
717
718 //==============================================================================
719 //function : VTop
720 //purpose  : Switch to a Top View
721 //Draw arg : No args
722 //==============================================================================
723
724 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
725 {
726   return ViewProject(di, V3d_Zpos);
727 }
728
729 //==============================================================================
730 //function : VBottom
731 //purpose  : Switch to a Bottom View
732 //Draw arg : No args
733 //==============================================================================
734
735 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
736 {
737   return ViewProject(di, V3d_Zneg);
738 }
739
740 //==============================================================================
741 //function : VLeft
742 //purpose  : Switch to a Left View
743 //Draw arg : No args
744 //==============================================================================
745
746 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
747 {
748   return ViewProject(di, V3d_Ypos);
749 }
750
751 //==============================================================================
752 //function : VRight
753 //purpose  : Switch to a Right View
754 //Draw arg : No args
755 //==============================================================================
756
757 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
758 {
759   return ViewProject(di, V3d_Yneg);
760 }
761
762 //==============================================================================
763 //function : VFront
764 //purpose  : Switch to a Front View
765 //Draw arg : No args
766 //==============================================================================
767
768 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
769 {
770   return ViewProject(di, V3d_Xpos);
771 }
772
773 //==============================================================================
774 //function : VBack
775 //purpose  : Switch to a Back View
776 //Draw arg : No args
777 //==============================================================================
778
779 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
780 {
781   return ViewProject(di, V3d_Xneg);
782 }
783
784 //==============================================================================
785 //function : VHelp
786 //purpose  : Dsiplay help on viewer Keyboead and mouse commands
787 //Draw arg : No args
788 //==============================================================================
789
790 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
791 {
792
793   di << "Q : Quit the application" << "\n";
794
795   di << "========================="<<"\n";
796   di << "F : FitAll" << "\n";
797   di << "T : TopView" << "\n";
798   di << "B : BottomView" << "\n";
799   di << "R : RightView" << "\n";
800   di << "L : LeftView" << "\n";
801   di << "A : AxonometricView" << "\n";
802   di << "D : ResetView" << "\n";
803
804   di << "========================="<<"\n";
805   di << "S : Shading" << "\n";
806   di << "W : Wireframe" << "\n";
807   di << "H : HidelLineRemoval" << "\n";
808   di << "U : Unset display mode" << "\n";
809
810   di << "========================="<<"\n";
811   di << "Selection mode "<<"\n";
812   di << "0 : Shape" <<"\n";
813   di << "1 : Vertex" <<"\n";
814   di << "2 : Edge" <<"\n";
815   di << "3 : Wire" <<"\n";
816   di << "4 : Face" <<"\n";
817   di << "5 : Shell" <<"\n";
818   di << "6 : Solid" <<"\n";
819   di << "7 : Compound" <<"\n";
820
821   di << "========================="<<"\n";
822   di << "Z : Switch Z clipping On/Off" << "\n";
823   di << ", : Hilight next detected" << "\n";
824   di << ". : Hilight previous detected" << "\n";
825
826   return 0;
827 }
828
829 #ifdef WNT
830
831 static Standard_Boolean Ppick = 0;
832 static Standard_Integer Pargc = 0;
833 static const char**           Pargv = NULL;
834
835
836 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
837                                           UINT Msg,
838                                           WPARAM wParam,
839                                           LPARAM lParam )
840 {
841   if ( !ViewerTest::CurrentView().IsNull() ) {
842
843     WPARAM fwKeys = wParam;
844
845     switch( Msg ) {
846
847     case WM_LBUTTONUP:
848       IsDragged = Standard_False;
849       if( !DragFirst )
850       {
851         HDC hdc = GetDC( hwnd );
852         HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
853         SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
854         SetROP2( hdc, R2_NOT );
855         Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
856         ReleaseDC( hwnd, hdc );
857
858         const Handle(ViewerTest_EventManager) EM =
859           ViewerTest::CurrentEventManager();
860         if ( fwKeys & MK_SHIFT )
861           EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
862           max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
863         else
864           EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
865           max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
866       }
867       return ViewerWindowProc( hwnd, Msg, wParam, lParam );
868
869     case WM_LBUTTONDOWN:
870       if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
871       {
872         IsDragged = Standard_True;
873         DragFirst = Standard_True;
874         X_ButtonPress = LOWORD(lParam);
875         Y_ButtonPress = HIWORD(lParam);
876       }
877       return ViewerWindowProc( hwnd, Msg, wParam, lParam );
878
879       break;
880
881     case WM_MOUSEMOVE:
882       if( IsDragged )
883       {
884         HDC hdc = GetDC( hwnd );
885
886         HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
887         SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
888         SetROP2( hdc, R2_NOT );
889
890         if( !DragFirst )
891           Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
892
893         DragFirst = Standard_False;
894         X_Motion = LOWORD(lParam);
895         Y_Motion = HIWORD(lParam);
896
897         Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
898
899         SelectObject( hdc, anObj );
900
901         ReleaseDC( hwnd, hdc );
902       }
903       else
904         return ViewerWindowProc( hwnd, Msg, wParam, lParam );
905       break;
906
907     default:
908       return ViewerWindowProc( hwnd, Msg, wParam, lParam );
909     }
910     return 0;
911   }
912   return ViewerWindowProc( hwnd, Msg, wParam, lParam );
913 }
914
915
916 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
917                                        UINT Msg,
918                                        WPARAM wParam,
919                                        LPARAM lParam )
920 {
921   /*static Standard_Boolean Ppick = 0;
922   static Standard_Integer Pargc = 0;
923   static char**           Pargv = NULL;*/
924
925   static int Up = 1;
926
927   if ( !ViewerTest::CurrentView().IsNull() ) {
928     PAINTSTRUCT    ps;
929
930     switch( Msg ) {
931     case WM_CLOSE:
932       // do not destroy the window - just hide it!
933       VT_GetWindow()->Unmap();
934       return 0;
935     case WM_PAINT:
936       BeginPaint(hwnd, &ps);
937       EndPaint(hwnd, &ps);
938       VT_ProcessExpose();
939       break;
940
941     case WM_SIZE:
942       VT_ProcessConfigure();
943       break;
944
945     case WM_KEYDOWN:
946       if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
947       {
948         char c[2];
949         c[0] = (char) wParam;
950         c[1] = '\0';
951         VT_ProcessKeyPress (c);
952       }
953       break;
954
955     case WM_LBUTTONUP:
956     case WM_MBUTTONUP:
957     case WM_RBUTTONUP:
958       Up = 1;
959       VT_ProcessButton3Release();
960       break;
961
962     case WM_LBUTTONDOWN:
963     case WM_MBUTTONDOWN:
964     case WM_RBUTTONDOWN:
965       {
966         WPARAM fwKeys = wParam;
967
968         Up = 0;
969
970         X_ButtonPress = LOWORD(lParam);
971         Y_ButtonPress = HIWORD(lParam);
972
973         if (Msg == WM_LBUTTONDOWN)
974         {
975           if (fwKeys & MK_CONTROL)
976           {
977             Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
978           }
979           else
980           {
981             VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
982           }
983         }
984         else if (Msg == WM_RBUTTONDOWN)
985         {
986           // Start rotation
987           VT_ProcessButton3Press();
988         }
989       }
990       break;
991
992     case WM_MOUSEMOVE:
993       {
994         //cout << "\t WM_MOUSEMOVE" << endl;
995         WPARAM fwKeys = wParam;
996         X_Motion = LOWORD(lParam);
997         Y_Motion = HIWORD(lParam);
998
999         if ( Up &&
1000           fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
1001             Up = 0;
1002             X_ButtonPress = LOWORD(lParam);
1003             Y_ButtonPress = HIWORD(lParam);
1004
1005             if ( fwKeys & MK_RBUTTON ) {
1006               // Start rotation
1007               VT_ProcessButton3Press();
1008             }
1009           }
1010
1011           if ( fwKeys & MK_CONTROL ) {
1012             if ( fwKeys & MK_LBUTTON ) {
1013               ProcessControlButton1Motion();
1014             }
1015             else if ( fwKeys & MK_MBUTTON ||
1016               ((fwKeys&MK_LBUTTON) &&
1017               (fwKeys&MK_RBUTTON) ) ){
1018                 VT_ProcessControlButton2Motion();
1019               }
1020             else if ( fwKeys & MK_RBUTTON ) {
1021               VT_ProcessControlButton3Motion();
1022             }
1023           }
1024 #ifdef BUG
1025           else if ( fwKeys & MK_SHIFT ) {
1026             if ( fwKeys & MK_MBUTTON ||
1027               ((fwKeys&MK_LBUTTON) &&
1028               (fwKeys&MK_RBUTTON) ) ) {
1029                 cout << "ProcessZClipMotion()" << endl;
1030                 ProcessZClipMotion();
1031               }
1032           }
1033 #endif
1034           else
1035             if ((fwKeys & MK_MBUTTON
1036             || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
1037             {
1038               ProcessZClipMotion();
1039             }
1040             else
1041             {
1042               VT_ProcessMotion();
1043             }
1044       }
1045       break;
1046
1047     default:
1048       return( DefWindowProc( hwnd, Msg, wParam, lParam ));
1049     }
1050     return 0L;
1051   }
1052
1053   return DefWindowProc( hwnd, Msg, wParam, lParam );
1054 }
1055
1056
1057
1058
1059 //==============================================================================
1060 //function : ViewerMainLoop
1061 //purpose  : Get a Event on the view and dispatch it
1062 //==============================================================================
1063
1064
1065 static int ViewerMainLoop(Standard_Integer argc, const char** argv)
1066 {
1067
1068   //cout << "No yet implemented on WNT" << endl;
1069   /*static Standard_Boolean Ppick = 0;
1070   static Standard_Integer Pargc = 0;
1071   static char**           Pargv = NULL;*/
1072
1073   //Ppick = (argc > 0)? -1 : 0;
1074   Ppick = (argc > 0)? 1 : 0;
1075   Pargc = argc;
1076   Pargv = argv;
1077
1078   if ( Ppick ) {
1079     MSG msg;
1080     msg.wParam = 1;
1081
1082     cout << "Start picking" << endl;
1083
1084     //while ( Ppick == -1 ) {
1085     while ( Ppick == 1 ) {
1086       // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
1087       if (GetMessage(&msg, NULL, 0, 0) ) {
1088         TranslateMessage(&msg);
1089         DispatchMessage(&msg);
1090       }
1091     }
1092
1093     cout << "Picking done" << endl;
1094   }
1095
1096   return Ppick;
1097 }
1098
1099 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
1100
1101 int min( int a, int b )
1102 {
1103   if( a<b )
1104     return a;
1105   else
1106     return b;
1107 }
1108
1109 int max( int a, int b )
1110 {
1111   if( a>b )
1112     return a;
1113   else
1114     return b;
1115 }
1116
1117 int ViewerMainLoop(Standard_Integer argc, const char** argv)
1118
1119 { Standard_Boolean pick = argc > 0;
1120
1121 // X11 Event loop
1122
1123 static XEvent report;
1124
1125 XNextEvent( display, &report );
1126 //    cout << "rep type = " << report.type << endl;
1127 //    cout << "rep button = " << report.xbutton.button << endl;
1128
1129 switch ( report.type ) {
1130       case Expose:
1131         {
1132           VT_ProcessExpose();
1133         }
1134         break;
1135       case ConfigureNotify:
1136         {
1137           VT_ProcessConfigure();
1138         }
1139         break;
1140       case KeyPress:
1141         {
1142
1143           KeySym ks_ret ;
1144           char buf_ret[11] ;
1145           int ret_len ;
1146           XComposeStatus status_in_out;
1147
1148           ret_len = XLookupString( ( XKeyEvent *)&report ,
1149             (char *) buf_ret , 10 ,
1150             &ks_ret , &status_in_out ) ;
1151
1152
1153           buf_ret[ret_len] = '\0' ;
1154
1155           if (ret_len)
1156           {
1157             VT_ProcessKeyPress (buf_ret);
1158           }
1159         }
1160         break;
1161       case ButtonPress:
1162         //  cout << "ButtonPress" << endl;
1163         {
1164           X_ButtonPress = report.xbutton.x;
1165           Y_ButtonPress = report.xbutton.y;
1166
1167           if (report.xbutton.button == Button1)
1168           {
1169             if (report.xbutton.state & ControlMask)
1170             {
1171               pick = VT_ProcessButton1Press (argc, argv, pick, (report.xbutton.state & ShiftMask));
1172             }
1173             else
1174             {
1175               IsDragged = Standard_True;
1176               X_ButtonPress = X_ButtonPress;
1177               Y_ButtonPress = Y_ButtonPress;
1178               DragFirst = Standard_True;
1179             }
1180           }
1181           else if (report.xbutton.button == Button3)
1182           {
1183             // Start rotation
1184             VT_ProcessButton3Press();
1185           }
1186         }
1187         break;
1188       case ButtonRelease:
1189         {
1190           //    cout<<"relachement du bouton "<<(report.xbutton.button==3 ? "3": "on s'en fout") <<endl;
1191           //    cout << IsDragged << endl;
1192           //    cout << DragFirst << endl;
1193
1194           if( IsDragged )
1195           {
1196             if( !DragFirst )
1197             {
1198               Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1199               GC gc = XCreateGC( display, aWindow, 0, 0 );
1200               //  XSetFunction( display, gc, GXinvert );
1201               XDrawRectangle( display, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
1202             }
1203
1204             Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1205             if( aContext.IsNull() )
1206             {
1207               cout << "The context is null. Please use vinit before createmesh" << endl;
1208               return 0;
1209             }
1210
1211             Standard_Boolean ShiftPressed = ( report.xbutton.state & ShiftMask );
1212             if( report.xbutton.button==1 )
1213               if( DragFirst )
1214                 if( ShiftPressed )
1215                 {
1216                   aContext->ShiftSelect();
1217                   //                   cout << "shift select" << endl;
1218                 }
1219                 else
1220                 {
1221                   aContext->Select();
1222                   //                   cout << "select" << endl;
1223                 }
1224               else
1225                 if( ShiftPressed )
1226                 {
1227                   aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
1228                     max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1229                     ViewerTest::CurrentView());
1230                   //                   cout << "shift select" << endl;
1231                 }
1232                 else
1233                 {
1234                   aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
1235                     max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1236                     ViewerTest::CurrentView() );
1237                   //                   cout << "select" << endl;
1238                 }
1239             else
1240               VT_ProcessButton3Release();
1241
1242             IsDragged = Standard_False;
1243           }
1244           else
1245             VT_ProcessButton3Release();
1246         }
1247         break;
1248       case MotionNotify:
1249         {
1250           //    XEvent dummy;
1251
1252           X_Motion = report.xmotion.x;
1253           Y_Motion = report.xmotion.y;
1254
1255           if( IsDragged )
1256           {
1257             Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1258             GC gc = XCreateGC( display, aWindow, 0, 0 );
1259             XSetFunction( display, gc, GXinvert );
1260
1261             if( !DragFirst )
1262               XDrawRectangle( display, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
1263
1264             X_Motion = X_Motion;
1265             Y_Motion = Y_Motion;
1266             DragFirst = Standard_False;
1267
1268             //cout << "draw rect : " << X_Motion << ", " << Y_Motion << endl;
1269             XDrawRectangle( display, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
1270           }
1271           else
1272           {
1273
1274             //cout << "MotionNotify " << X_Motion << "," << Y_Motion << endl;
1275
1276             // remove all the ButtonMotionMask
1277             while( XCheckMaskEvent( display, ButtonMotionMask, &report) ) ;
1278
1279             if ( ZClipIsOn && report.xmotion.state & ShiftMask ) {
1280               if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1281
1282                 Quantity_Length VDX, VDY;
1283
1284                 ViewerTest::CurrentView()->Size(VDX,VDY);
1285                 Standard_Real VDZ =0 ;
1286                 VDZ = ViewerTest::CurrentView()->ZSize();
1287
1288                 //          printf("%lf,%lf,%lf\n", VDX, VDY, VDZ);
1289                 printf("%f,%f,%f\n", VDX, VDY, VDZ);
1290
1291                 Quantity_Length dx = 0 ;
1292                 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1293
1294                 cout << dx << endl;
1295
1296                 dx = dx / VDX * VDZ;
1297
1298                 cout << dx << endl;
1299
1300                 // Front = Depth + width/2.
1301                 //ViewerTest::CurrentView()->SetZClippingDepth(dx);
1302                 //ViewerTest::CurrentView()->SetZClippingWidth(0.);
1303
1304                 ViewerTest::CurrentView()->Redraw();
1305               }
1306             }
1307
1308             if ( report.xmotion.state & ControlMask ) {
1309               if ( report.xmotion.state & Button1Mask ) {
1310                 ProcessControlButton1Motion();
1311               }
1312               else if ( report.xmotion.state & Button2Mask ) {
1313                 VT_ProcessControlButton2Motion();
1314               }
1315               else if ( report.xmotion.state & Button3Mask ) {
1316                 VT_ProcessControlButton3Motion();
1317               }
1318             }
1319             else
1320             {
1321               VT_ProcessMotion();
1322             }
1323           }
1324         }
1325         break;
1326 }
1327
1328
1329 return pick;
1330 }
1331
1332 //==============================================================================
1333 //function : VProcessEvents
1334 //purpose  : call by Tk_CreateFileHandler() to be able to manage the
1335 //       event in the Viewer window
1336 //==============================================================================
1337
1338 static void VProcessEvents(ClientData,int)
1339 {
1340   //cout << "VProcessEvents" << endl;
1341
1342   // test for X Event
1343   while (XPending(display)) {
1344     ViewerMainLoop( 0, NULL);
1345   }
1346 }
1347 #endif
1348
1349 //==============================================================================
1350 //function : OSWindowSetup
1351 //purpose  : Setup for the X11 window to be able to cath the event
1352 //==============================================================================
1353
1354
1355 static void OSWindowSetup()
1356 {
1357 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1358   // X11
1359
1360   Window  window   = VT_GetWindow()->XWindow();
1361
1362   Standard_Address theDisplay = GetG3dDevice()->XDisplay();
1363   display = (Display * ) theDisplay;
1364   //  display = (Display *)GetG3dDevice()->XDisplay();
1365
1366   XSynchronize(display, 1);
1367
1368   VT_GetWindow()->Map();
1369
1370   // X11 : For keyboard on SUN
1371   XWMHints wmhints;
1372   wmhints.flags = InputHint;
1373   wmhints.input = 1;
1374
1375   XSetWMHints( display, window, &wmhints);
1376
1377   XSelectInput( display, window,  ExposureMask | KeyPressMask |
1378     ButtonPressMask | ButtonReleaseMask |
1379     StructureNotifyMask |
1380     PointerMotionMask |
1381     Button1MotionMask | Button2MotionMask |
1382     Button3MotionMask
1383     );
1384
1385   XSynchronize(display, 0);
1386
1387 #else
1388   // WNT
1389 #endif
1390
1391 }
1392
1393
1394 //==============================================================================
1395 //function : VFit
1396
1397 //purpose  : Fitall, no DRAW arguments
1398 //Draw arg : No args
1399 //==============================================================================
1400
1401 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
1402 {
1403   const Handle(V3d_View) aView = ViewerTest::CurrentView();
1404   Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
1405   if (V.IsNull() == Standard_False) {
1406     V->FitAll3d();
1407   } else if (aView.IsNull() == Standard_False) {
1408     aView->FitAll();
1409   }
1410   return 0;
1411 }
1412
1413 //==============================================================================
1414 //function : VZFit
1415 //purpose  : ZFitall, no DRAW arguments
1416 //Draw arg : No args
1417 //==============================================================================
1418
1419 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
1420 {
1421   Handle(V3d_View) V = ViewerTest::CurrentView();
1422   if ( !V.IsNull() ) V->ZFitAll(); return 0; }
1423
1424
1425 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
1426 {
1427   Handle(V3d_View) V = ViewerTest::CurrentView();
1428   if ( !V.IsNull() ) V->Redraw(); return 0;
1429 }
1430
1431
1432 //==============================================================================
1433 //function : VClear
1434 //purpose  : Remove all the object from the viewer
1435 //Draw arg : No args
1436 //==============================================================================
1437
1438 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
1439 {
1440   Handle(V3d_View) V = ViewerTest::CurrentView();
1441   if(!V.IsNull())
1442     ViewerTest::Clear();
1443   return 0;
1444 }
1445
1446 //==============================================================================
1447 //function : VPick
1448 //purpose  :
1449 //==============================================================================
1450
1451 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1452 { if (ViewerTest::CurrentView().IsNull() ) return 1;
1453
1454 if ( argc < 4 ) {
1455   di << argv[0] << "Invalid number of arguments" << "\n";
1456   return 1;
1457 }
1458
1459 while (ViewerMainLoop( argc, argv)) {
1460 }
1461
1462 return 0;
1463 }
1464
1465 //==============================================================================
1466 //function : InitViewerTest
1467 //purpose  : initialisation de toutes les variables static de  ViewerTest (dp)
1468 //==============================================================================
1469
1470 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& context)
1471 {
1472   Handle(V3d_Viewer) viewer = context->CurrentViewer();
1473   ViewerTest::SetAISContext(context);
1474   viewer->InitActiveViews();
1475   Handle(V3d_View) view = viewer->ActiveView();
1476   if (viewer->MoreActiveViews()) ViewerTest::CurrentView(view);
1477   ViewerTest::ResetEventManager();
1478   Handle(Aspect_GraphicDevice) device = viewer->Device();
1479   Handle(Aspect_Window) window = view->Window();
1480 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1481   // X11
1482   VT_GetWindow() = Handle(Xw_Window)::DownCast(window);
1483   GetG3dDevice() = Handle(Graphic3d_GraphicDevice)::DownCast(device);
1484   OSWindowSetup();
1485   static int first = 1;
1486   if ( first ) {
1487 #if TCL_MAJOR_VERSION  < 8
1488     Tk_CreateFileHandler((void*)ConnectionNumber(display),
1489       TK_READABLE, VProcessEvents, (ClientData) 0);
1490 #else
1491     Tk_CreateFileHandler(ConnectionNumber(display),
1492       TK_READABLE, VProcessEvents, (ClientData) 0);
1493 #endif
1494     first = 0;
1495   }
1496 #endif
1497 }
1498
1499 //==============================================================================
1500 //function : VSetBg
1501 //purpose  : Load image as background
1502 //==============================================================================
1503
1504 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1505 {
1506   if (argc < 2 || argc > 3)
1507   {
1508     di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
1509     di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1510     return 1;
1511   }
1512
1513   Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1514   if(AISContext.IsNull())
1515   {
1516     di << "use 'vinit' command before " << argv[0] << "\n";
1517     return 1;
1518   }
1519
1520   Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
1521   if (argc == 3)
1522   {
1523     const char* szType = argv[2];
1524     if      (strcmp(szType, "NONE"    ) == 0) aFillType = Aspect_FM_NONE;
1525     else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1526     else if (strcmp(szType, "TILED"   ) == 0) aFillType = Aspect_FM_TILED;
1527     else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1528     else
1529     {
1530       di << "Wrong fill type : " << szType << "\n";
1531       di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1532       return 1;
1533     }
1534   }
1535
1536   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1537   V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
1538
1539   return 0;
1540 }
1541
1542 //==============================================================================
1543 //function : VSetBgMode
1544 //purpose  : Change background image fill type
1545 //==============================================================================
1546
1547 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1548 {
1549   if (argc != 2)
1550   {
1551     di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
1552     di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1553     return 1;
1554   }
1555
1556   Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1557   if(AISContext.IsNull())
1558   {
1559     di << "use 'vinit' command before " << argv[0] << "\n";
1560     return 1;
1561   }
1562
1563   Aspect_FillMethod aFillType;
1564   if (argc == 2)
1565   {
1566     const char* szType = argv[1];
1567     if      (strcmp(szType, "NONE"    ) == 0) aFillType = Aspect_FM_NONE;
1568     else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1569     else if (strcmp(szType, "TILED"   ) == 0) aFillType = Aspect_FM_TILED;
1570     else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1571     else
1572     {
1573       di << "Wrong fill type : " << szType << "\n";
1574       di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1575       return 1;
1576     }
1577   }
1578
1579   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1580   V3dView->SetBgImageStyle(aFillType, Standard_True);
1581
1582   return 0;
1583 }
1584
1585 //==============================================================================
1586 //function : VSetGradientBg
1587 //purpose  : Mount gradient background
1588 //==============================================================================
1589 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1590 {
1591   if (argc != 8 )
1592   {
1593     di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
1594     di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
1595     di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1596     di << "                    5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1597     return 1;
1598   }
1599
1600   Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1601   if(AISContext.IsNull())
1602   {
1603     di << "use 'vinit' command before " << argv[0] << "\n";
1604     return 1;
1605   }
1606   if (argc == 8)
1607   {
1608
1609     Standard_Real R1 = Draw::Atof(argv[1])/255.;
1610     Standard_Real G1 = Draw::Atof(argv[2])/255.;
1611     Standard_Real B1 = Draw::Atof(argv[3])/255.;
1612     Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
1613
1614     Standard_Real R2 = Draw::Atof(argv[4])/255.;
1615     Standard_Real G2 = Draw::Atof(argv[5])/255.;
1616     Standard_Real B2 = Draw::Atof(argv[6])/255.;
1617
1618     Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
1619     int aType = Draw::Atoi(argv[7]);
1620     if( aType < 0 || aType > 8 )
1621     {
1622       di << "Wrong fill type " << "\n";
1623       di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1624       di << "               5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1625       return 1;
1626     }
1627
1628     Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1629
1630     Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1631     V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
1632   }
1633
1634   return 0;
1635 }
1636
1637 //==============================================================================
1638 //function : VSetGradientBgMode
1639 //purpose  : Change gradient background fill style
1640 //==============================================================================
1641 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1642 {
1643   if (argc != 2 )
1644   {
1645     di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
1646     di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1647     di << "                    5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1648     return 1;
1649   }
1650
1651   Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1652   if(AISContext.IsNull())
1653   {
1654     di << "use 'vinit' command before " << argv[0] << "\n";
1655     return 1;
1656   }
1657   if (argc == 2)
1658   {
1659     int aType = Draw::Atoi(argv[1]);
1660     if( aType < 0 || aType > 8 )
1661     {
1662       di << "Wrong fill type " << "\n";
1663       di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1664       di << "               5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1665       return 1;
1666     }
1667
1668     Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1669
1670     Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1671     V3dView->SetBgGradientStyle( aMethod, 1 );
1672   }
1673
1674   return 0;
1675 }
1676
1677 //==============================================================================
1678 //function : VSetColorBg
1679 //purpose  : Set color background
1680 //==============================================================================
1681 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1682 {
1683   if (argc != 4 )
1684   {
1685     di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
1686     di << "R,G,B = [0..255]" << "\n";
1687     return 1;
1688   }
1689
1690   Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1691   if(AISContext.IsNull())
1692   {
1693     di << "use 'vinit' command before " << argv[0] << "\n";
1694     return 1;
1695   }
1696   if (argc == 4)
1697   {
1698
1699     Standard_Real R = Draw::Atof(argv[1])/255.;
1700     Standard_Real G = Draw::Atof(argv[2])/255.;
1701     Standard_Real B = Draw::Atof(argv[3])/255.;
1702     Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
1703
1704     Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1705     V3dView->SetBackgroundColor( aColor );
1706     V3dView->Update();
1707   }
1708
1709   return 0;
1710 }
1711
1712 //==============================================================================
1713 //function : VScale
1714 //purpose  : View Scaling
1715 //==============================================================================
1716
1717 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1718 {
1719   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1720   if ( V3dView.IsNull() ) return 1;
1721
1722   if ( argc != 4 ) {
1723     di << argv[0] << "Invalid number of arguments" << "\n";
1724     return 1;
1725   }
1726   V3dView->SetAxialScale( Draw::Atof(argv[1]),  Draw::Atof(argv[2]),  Draw::Atof(argv[3]) );
1727   return 0;
1728 }
1729 //==============================================================================
1730 //function : VTestZBuffTrihedron
1731 //purpose  : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
1732 //==============================================================================
1733
1734 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1735 {
1736   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1737   if ( V3dView.IsNull() ) return 1;
1738
1739   V3dView->ZBufferTriedronSetup();
1740
1741   if ( argc == 1 ) {
1742     // Set up default trihedron parameters
1743     V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
1744   } else
1745   if ( argc == 7 )
1746   {
1747     Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
1748     const char* aPosType = argv[1];
1749
1750     if ( strcmp(aPosType, "center") == 0 )
1751     {
1752       aPosition = Aspect_TOTP_CENTER;
1753     } else
1754     if (strcmp(aPosType, "left_lower") == 0)
1755     {
1756       aPosition = Aspect_TOTP_LEFT_LOWER;
1757     } else
1758     if (strcmp(aPosType, "left_upper") == 0)
1759     {
1760       aPosition = Aspect_TOTP_LEFT_UPPER;
1761     } else
1762     if (strcmp(aPosType, "right_lower") == 0)
1763     {
1764       aPosition = Aspect_TOTP_RIGHT_LOWER;
1765     } else
1766     if (strcmp(aPosType, "right_upper") == 0)
1767     {
1768       aPosition = Aspect_TOTP_RIGHT_UPPER;
1769     } else
1770     {
1771       di << argv[1] << " Invalid type of alignment"  << "\n";
1772       di << "Must be one of [ center, left_lower,"   << "\n";
1773       di << "left_upper, right_lower, right_upper ]" << "\n";
1774       return 1;
1775     }
1776
1777     Standard_Real R = Draw::Atof(argv[2])/255.;
1778     Standard_Real G = Draw::Atof(argv[3])/255.;
1779     Standard_Real B = Draw::Atof(argv[4])/255.;
1780     Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
1781
1782     Standard_Real aScale = Draw::Atof(argv[5]);
1783
1784     if( aScale <= 0.0 )
1785     {
1786       di << argv[5] << " Invalid value. Must be > 0" << "\n";
1787       return 1;
1788     }
1789
1790     V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
1791     const char* aPresType = argv[6];
1792
1793     if ( strcmp(aPresType, "wireframe") == 0 )
1794     {
1795       aPresentation = V3d_WIREFRAME;
1796     } else
1797     if (strcmp(aPresType, "zbuffer") == 0)
1798     {
1799       aPresentation = V3d_ZBUFFER;
1800     } else
1801     {
1802       di << argv[6] << " Invalid type of visualization" << "\n";
1803       di << "Must be one of [ wireframe, zbuffer ]"     << "\n";
1804       return 1;
1805     }
1806
1807     V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
1808
1809   } else
1810   {
1811     di << argv[0] << " Invalid number of arguments" << "\n";
1812     return 1;
1813   }
1814
1815   V3dView->ZFitAll();
1816
1817   return 0;
1818 }
1819
1820 //==============================================================================
1821 //function : VRotate
1822 //purpose  : Camera Rotating
1823 //==============================================================================
1824
1825 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1826   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1827   if ( V3dView.IsNull() ) {
1828     return 1;
1829   }
1830
1831   if ( argc == 4 ) {
1832     V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
1833     return 0;
1834   } else if ( argc == 7 ) {
1835     V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]), Draw::Atof(argv[4]), Draw::Atof(argv[5]), Draw::Atof(argv[6]) );
1836     return 0;
1837   } else {
1838     di << argv[0] << " Invalid number of arguments" << "\n";
1839     return 1;
1840   }
1841 }
1842
1843 //==============================================================================
1844 //function : VZoom
1845 //purpose  : View zoom in / out (relative to current zoom)
1846 //==============================================================================
1847
1848 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1849   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1850   if ( V3dView.IsNull() ) {
1851     return 1;
1852   }
1853
1854   if ( argc == 2 ) {
1855     Standard_Real coef = Draw::Atof(argv[1]);
1856     if ( coef <= 0.0 ) {
1857       di << argv[1] << "Invalid value" << "\n";
1858       return 1;
1859     }
1860     V3dView->SetZoom( Draw::Atof(argv[1]) );
1861     return 0;
1862   } else {
1863     di << argv[0] << " Invalid number of arguments" << "\n";
1864     return 1;
1865   }
1866 }
1867
1868 //==============================================================================
1869 //function : VPan
1870 //purpose  : View panning (in pixels)
1871 //==============================================================================
1872
1873 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1874   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1875   if ( V3dView.IsNull() ) return 1;
1876
1877   if ( argc == 3 ) {
1878     V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
1879     return 0;
1880   } else {
1881     di << argv[0] << " Invalid number of arguments" << "\n";
1882     return 1;
1883   }
1884 }
1885
1886
1887 //==============================================================================
1888 //function : VExport
1889 //purpose  : Export the view to a vector graphic format (PS, EMF, PDF)
1890 //==============================================================================
1891
1892 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1893 {
1894   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1895   if (V3dView.IsNull())
1896     return 1;
1897
1898   if (argc == 1)
1899   {
1900     std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
1901     return 1;
1902   }
1903
1904   Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
1905   TCollection_AsciiString aFormatStr;
1906
1907   TCollection_AsciiString aFileName (argv[1]);
1908   Standard_Integer aLen = aFileName.Length();
1909
1910   if (argc > 2)
1911   {
1912     aFormatStr = TCollection_AsciiString (argv[2]);
1913   }
1914   else if (aLen >= 4)
1915   {
1916     if (aFileName.Value (aLen - 2) == '.')
1917     {
1918       aFormatStr = aFileName.SubString (aLen - 1, aLen);
1919     }
1920     else if (aFileName.Value (aLen - 3) == '.')
1921     {
1922       aFormatStr = aFileName.SubString (aLen - 2, aLen);
1923     }
1924     else
1925     {
1926       std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1927       return 1;
1928     }
1929   }
1930   else
1931   {
1932     std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1933     return 1;
1934   }
1935
1936   aFormatStr.UpperCase();
1937   if (aFormatStr == "PS")
1938     anExpFormat = Graphic3d_EF_PostScript;
1939   else if (aFormatStr == "EPS")
1940     anExpFormat = Graphic3d_EF_EnhPostScript;
1941   else if (aFormatStr == "TEX")
1942     anExpFormat = Graphic3d_EF_TEX;
1943   else if (aFormatStr == "PDF")
1944     anExpFormat = Graphic3d_EF_PDF;
1945   else if (aFormatStr == "SVG")
1946     anExpFormat = Graphic3d_EF_SVG;
1947   else if (aFormatStr == "PGF")
1948     anExpFormat = Graphic3d_EF_PGF;
1949   else if (aFormatStr == "EMF")
1950     anExpFormat = Graphic3d_EF_EMF;
1951   else
1952   {
1953     std::cout << "Invalid export format '" << aFormatStr << "'\n";
1954     return 1;
1955   }
1956
1957   if (!V3dView->View()->Export (argv[1], anExpFormat))
1958   {
1959     std::cout << "Export failed!\n";
1960     return 1;
1961   }
1962   return 0;
1963 }
1964
1965 //==============================================================================
1966 //function : VColorScale
1967 //purpose  : representation color scale
1968 //==============================================================================
1969 #include <V3d_ColorScale.hxx>
1970
1971 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1972 {
1973   if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
1974   {
1975     di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0]  " << "\n";
1976     return 1;
1977   }
1978
1979   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1980   if(aContext.IsNull()) {
1981     di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
1982     return -1;
1983   }
1984
1985   Standard_Real minRange = 0. , maxRange = 100. ;
1986
1987   Standard_Integer numIntervals = 10 ;
1988   Standard_Integer textHeight = 16;
1989   Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
1990   Standard_Real X = 0., Y = 0. ;
1991
1992   if ( argc < 9 )
1993   {
1994      if( argc > 3 )
1995      {
1996        minRange = Draw::Atof( argv[1] );
1997        maxRange = Draw::Atof( argv[2] );
1998        numIntervals = Draw::Atoi( argv[3] );
1999      }
2000      if ( argc > 4 )
2001        textHeight = Draw::Atoi( argv[4] );
2002      if ( argc > 5 )
2003        position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
2004      if ( argc > 7 )
2005      {
2006        X = Draw::Atof( argv[6] );
2007        Y = Draw::Atof( argv[7] );
2008      }
2009   }
2010   Handle(V3d_View) curView = ViewerTest::CurrentView( );
2011   if ( curView.IsNull( ) )
2012     return 1;
2013   Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
2014   Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
2015   if( ! aCS.IsNull( ) )
2016   {
2017     aCS->SetPosition( X , Y );
2018     aCS->SetHeight( 0.95) ;
2019     aCS->SetTextHeight( textHeight );
2020     aCS->SetRange( minRange , maxRange );
2021     aCS->SetNumberOfIntervals( numIntervals );
2022     aCS->SetLabelPosition( position );
2023     if( !curView->ColorScaleIsDisplayed() )
2024       curView->ColorScaleDisplay( );
2025   }
2026   return 0;
2027 }
2028
2029 //==============================================================================
2030 //function : VGraduatedTrihedron
2031 //purpose  : Displays a graduated trihedron
2032 //==============================================================================
2033
2034 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
2035 {
2036   const char *str = arg;
2037   while (*str)
2038   {
2039     unsigned short c1 = *str++;
2040     unsigned short c2 = *str++;
2041     if (!c1 || !c2) break;
2042     name += (Standard_ExtCharacter)((c1 << 8) | c2);
2043   }
2044 }
2045
2046 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2047 {
2048   // Check arguments
2049   if (argc != 2 && argc < 5)
2050   {
2051     di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
2052     di<<"Usage: type help "<<argv[0]<<"\n";
2053     return 1; //TCL_ERROR
2054   }
2055
2056   Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
2057
2058   // Create 3D view if it doesn't exist
2059   if ( aV3dView.IsNull() )
2060   {
2061     ViewerTest::ViewerInit();
2062     aV3dView = ViewerTest::CurrentView();
2063     if( aV3dView.IsNull() )
2064     {
2065       di << "Error: Cannot create a 3D view\n";
2066       return 1; //TCL_ERROR
2067     }
2068   }
2069
2070   // Erase (==0) or display (!=0)
2071   const int display = Draw::Atoi(argv[1]);
2072
2073   if (display)
2074   {
2075     // Text font
2076     TCollection_AsciiString font;
2077     if (argc < 6)
2078       font.AssignCat("Courier");
2079     else
2080       font.AssignCat(argv[5]);
2081
2082     // Text is multibyte
2083     const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
2084
2085     // Set axis names
2086     TCollection_ExtendedString xname, yname, zname;
2087     if (argc >= 5)
2088     {
2089       if (isMultibyte)
2090       {
2091         AddMultibyteString(xname, argv[2]);
2092         AddMultibyteString(yname, argv[3]);
2093         AddMultibyteString(zname, argv[4]);
2094       }
2095       else
2096       {
2097         xname += argv[2];
2098         yname += argv[3];
2099         zname += argv[4];
2100       }
2101     }
2102     else
2103     {
2104       xname += "X (mm)";
2105       yname += "Y (mm)";
2106       zname += "Z (mm)";
2107     }
2108
2109     aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
2110                                         Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
2111                                         Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
2112                                         Standard_True/*drawgrid*/,
2113                                         Standard_True/*drawaxes*/,
2114                                         5/*nbx*/, 5/*nby*/, 5/*nbz*/,
2115                                         10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
2116                                         30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
2117                                         Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
2118                                         10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
2119                                         Quantity_NOC_WHITE/*gridcolor*/,
2120                                         Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
2121                                         Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
2122   }
2123   else
2124     aV3dView->GraduatedTrihedronErase();
2125
2126   ViewerTest::GetAISContext()->UpdateCurrentViewer();
2127   aV3dView->Redraw();
2128
2129   return 0;
2130 }
2131
2132 //==============================================================================
2133 //function : VPrintView
2134 //purpose  : Test printing algorithm, print the view to image file with given
2135 //           width and height. Printing implemented only for WNT.
2136 //==============================================================================
2137 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
2138                        const char** argv)
2139 {
2140 #ifndef WNT
2141   di << "Printing implemented only for wnt!\n";
2142   return 1;
2143 #else
2144
2145   Handle(AIS_InteractiveContext) aContextAIS = NULL;
2146   Handle(V3d_View) aView = NULL;
2147   aContextAIS = ViewerTest::GetAISContext();
2148   if (!aContextAIS.IsNull())
2149   {
2150     const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
2151     Vwr->InitActiveViews();
2152     if(Vwr->MoreActiveViews())
2153       aView = Vwr->ActiveView();
2154   }
2155
2156   // check for errors
2157   if (aView.IsNull())
2158   {
2159     di << "Call vinit before!\n";
2160     return 1;
2161   }
2162   else if (argc < 4)
2163   {
2164     di << "Use: " << argv[0];
2165     di << " width height filename [print algo=0]\n";
2166     di << "width, height of the intermediate buffer for operation\n";
2167     di << "algo : {0|1}\n";
2168     di << "        0 - stretch algorithm\n";
2169     di << "        1 - tile algorithm\n";
2170     di << "test printing algorithms into an intermediate buffer\n";
2171     di << "with saving output to an image file\n";
2172     return 1;
2173   }
2174
2175   // get the input params
2176   Standard_Integer aWidth  = Draw::Atoi (argv[1]);
2177   Standard_Integer aHeight = Draw::Atoi (argv[2]);
2178   Standard_Integer aMode   = 0;
2179   TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
2180   if (argc==5)
2181     aMode = Draw::Atoi (argv[4]);
2182
2183   // check the input parameters
2184   if (aWidth <= 0 || aHeight <= 0)
2185   {
2186     di << "Width and height must be positive values!\n";
2187     return 1;
2188   }
2189   if (aMode != 0 && aMode != 1)
2190     aMode = 0;
2191
2192   // define compatible bitmap
2193   HDC anDC = CreateCompatibleDC(0);
2194   BITMAPINFO aBitmapData;
2195   memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
2196   aBitmapData.bmiHeader.biSize          = sizeof (BITMAPINFOHEADER);
2197   aBitmapData.bmiHeader.biWidth         = aWidth ;
2198   aBitmapData.bmiHeader.biHeight        = aHeight;
2199   aBitmapData.bmiHeader.biPlanes        = 1;
2200   aBitmapData.bmiHeader.biBitCount      = 24;
2201   aBitmapData.bmiHeader.biXPelsPerMeter = 0;
2202   aBitmapData.bmiHeader.biYPelsPerMeter = 0;
2203   aBitmapData.bmiHeader.biClrUsed       = 0;
2204   aBitmapData.bmiHeader.biClrImportant  = 0;
2205   aBitmapData.bmiHeader.biCompression   = BI_RGB;
2206   aBitmapData.bmiHeader.biSizeImage     = 0;
2207
2208   // Create Device Independent Bitmap
2209   void* aBitsOut = NULL;
2210   HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
2211                                             &aBitsOut, NULL, 0);
2212   HGDIOBJ anOldBitmap   = SelectObject(anDC, aMemoryBitmap);
2213
2214   Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
2215   if (aBitsOut != NULL)
2216   {
2217     if (aMode == 0)
2218       isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
2219     else
2220       isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
2221
2222     // succesfully printed into an intermediate buffer
2223     if (isPrinted)
2224     {
2225       Image_PixMap aWrapper;
2226       aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
2227       aWrapper.SetTopDown (false);
2228
2229       Image_AlienPixMap anImageBitmap;
2230       anImageBitmap.InitCopy (aWrapper);
2231       isSaved = anImageBitmap.Save (aFileName);
2232     }
2233     else
2234     {
2235       di << "Print operation failed due to printing errors or\n";
2236       di << "insufficient memory available\n";
2237       di << "Please, try to use smaller dimensions for this test\n";
2238       di << "command, as it allocates intermediate buffer for storing\n";
2239       di << "the result\n";
2240     }
2241   }
2242   else
2243   {
2244     di << "Can't allocate memory for intermediate buffer\n";
2245     di << "Please use smaller dimensions\n";
2246   }
2247
2248   if (aMemoryBitmap)
2249   {
2250     SelectObject (anDC, anOldBitmap);
2251     DeleteObject (aMemoryBitmap);
2252     DeleteDC(anDC);
2253   }
2254
2255   if (!isSaved)
2256   {
2257     di << "Save to file operation failed. This operation may fail\n";
2258     di << "if you don't have enough available memory, then you can\n";
2259     di << "use smaller dimensions for the output file\n";
2260     return 1;
2261   }
2262
2263   return 0;
2264
2265 #endif
2266 }
2267
2268 //==============================================================================
2269 //function : VZLayer
2270 //purpose  : Test z layer operations for v3d viewer
2271 //==============================================================================
2272 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2273 {
2274   Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
2275   if (aContextAIS.IsNull())
2276   {
2277     di << "Call vinit before!\n";
2278     return 1;
2279   }
2280   else if (argc < 2)
2281   {
2282     di << "Use: vzlayer " << argv[0];
2283     di << " add/del/get [id]\n";
2284     di << " add - add new z layer to viewer and print its id\n";
2285     di << " del - del z layer by its id\n";
2286     di << " get - print sequence of z layers in increasing order of their overlay level\n";
2287     di << "id - the layer identificator value defined when removing z layer\n";
2288     return 1;
2289   }
2290
2291   const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
2292   if (aViewer.IsNull())
2293   {
2294     di << "No active viewer!\n";
2295     return 1;
2296   }
2297
2298   // perform operation
2299   TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
2300   if (anOp == "add")
2301   {
2302     Standard_Integer aNewId;
2303     if (!aViewer->AddZLayer (aNewId))
2304     {
2305       di << "Impossible to add new z layer!\n";
2306       return 1;
2307     }
2308
2309     di << "New z layer added with index: " << aNewId << "\n";
2310   }
2311   else if (anOp == "del")
2312   {
2313     if (argc < 3)
2314     {
2315       di << "Please also provide as argument id of z layer to remove\n";
2316       return 1;
2317     }
2318
2319     Standard_Integer aDelId = Draw::Atoi (argv[2]);
2320     if (!aViewer->RemoveZLayer (aDelId))
2321     {
2322       di << "Impossible to remove the z layer or invalid id!\n";
2323       return 1;
2324     }
2325
2326     di << "Z layer " << aDelId << " has been removed\n";
2327   }
2328   else if (anOp == "get")
2329   {
2330     TColStd_SequenceOfInteger anIds;
2331     aViewer->GetAllZLayers (anIds);
2332     for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
2333     {
2334       di << anIds.Value (aSeqIdx) << " ";
2335     }
2336
2337     di << "\n";
2338   }
2339   else
2340   {
2341     di << "Invalid operation, please use { add / del / get }\n";
2342     return 1;
2343   }
2344
2345   return 0;
2346 }
2347
2348 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2349
2350 // this class provides a presentation of text item in v3d view under-/overlayer
2351 class V3d_TextItem : public Visual3d_LayerItem
2352 {
2353 public:
2354
2355   // CASCADE RTTI
2356   DEFINE_STANDARD_RTTI(V3d_TextItem)
2357
2358   // constructor
2359   Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
2360                                const Standard_Real theX1,
2361                                const Standard_Real theY1,
2362                                const Standard_Real theHeight,
2363                                const TCollection_AsciiString& theFontName,
2364                                const Quantity_Color& theColor,
2365                                const Quantity_Color& theSubtitleColor,
2366                                const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2367                                const Handle(Visual3d_Layer)& theLayer);
2368
2369   // redraw method
2370   Standard_EXPORT void RedrawLayerPrs();
2371
2372 private:
2373
2374   Standard_Real            myX1;
2375   Standard_Real            myY1;
2376   Standard_Real            myHeight;
2377   TCollection_AsciiString  myText;
2378   TCollection_AsciiString  myFontName;
2379   Quantity_Color           myColor;
2380   Quantity_Color           mySubtitleColor;
2381   Aspect_TypeOfDisplayText myType;
2382   Handle(Visual3d_Layer)   myLayer;
2383
2384 };
2385
2386 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2387 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
2388
2389 // create and add to display the text item
2390 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
2391                             const Standard_Real theX1,
2392                             const Standard_Real theY1,
2393                             const Standard_Real theHeight,
2394                             const TCollection_AsciiString& theFontName,
2395                             const Quantity_Color& theColor,
2396                             const Quantity_Color& theSubtitleColor,
2397                             const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2398                             const Handle(Visual3d_Layer)& theLayer)
2399  : myX1 (theX1), myY1 (theY1),
2400    myText (theText),
2401    myHeight (theHeight),
2402    myLayer (theLayer),
2403    myColor (theColor),
2404    mySubtitleColor (theSubtitleColor),
2405    myType (theTypeOfDisplay),
2406    myFontName (theFontName)
2407 {
2408   if (!myLayer.IsNull ())
2409     myLayer->AddLayerItem (this);
2410 }
2411
2412 // render item
2413 void V3d_TextItem::RedrawLayerPrs ()
2414 {
2415   if (myLayer.IsNull ())
2416     return;
2417
2418   myLayer->SetColor (myColor);
2419   myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
2420   myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
2421 }
2422
2423 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
2424
2425 // The Visual3d_LayerItem line item for "vlayerline" command
2426 // it provides a presentation of line with user-defined
2427 // linewidth, linetype and transparency.
2428 class V3d_LineItem : public Visual3d_LayerItem
2429 {
2430 public:
2431   // CASCADE RTTI
2432   DEFINE_STANDARD_RTTI(V3d_LineItem)
2433
2434   // constructor
2435   Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
2436                                Standard_Real X2, Standard_Real Y2,
2437                                V3d_LayerMgrPointer theLayerMgr,
2438                                Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
2439                                Standard_Real theWidth    = 0.5,
2440                                Standard_Real theTransp   = 1.0);
2441
2442   // redraw method
2443   Standard_EXPORT   void RedrawLayerPrs();
2444
2445 private:
2446
2447   Standard_Real       myX1, myY1, myX2, myY2;
2448   Standard_Real       myWidth;
2449   Standard_Real       myTransparency;
2450   Aspect_TypeOfLine   myType;
2451   V3d_LayerMgrPointer myLayerMgr;
2452 };
2453
2454 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
2455 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
2456
2457 // default constructor for line item
2458 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
2459                            Standard_Real X2, Standard_Real Y2,
2460                            V3d_LayerMgrPointer theLayerMgr,
2461                            Aspect_TypeOfLine theType,
2462                            Standard_Real theWidth,
2463                            Standard_Real theTransp) :
2464   myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
2465   myType(theType), myWidth(theWidth), myTransparency(theTransp)
2466 {
2467   if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
2468     myLayerMgr->Overlay()->AddLayerItem (this);
2469 }
2470
2471 // render line
2472 void V3d_LineItem::RedrawLayerPrs ()
2473 {
2474   Handle (Visual3d_Layer) aOverlay;
2475
2476   if (myLayerMgr)
2477     aOverlay = myLayerMgr->Overlay();
2478
2479   if (!aOverlay.IsNull())
2480   {
2481     Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
2482     aOverlay->SetColor(aColor);
2483     aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
2484     aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
2485     aOverlay->BeginPolyline();
2486     aOverlay->AddVertex(myX1, myY1);
2487     aOverlay->AddVertex(myX2, myY2);
2488     aOverlay->ClosePrimitive();
2489   }
2490 }
2491
2492 //=============================================================================
2493 //function : VLayerLine
2494 //purpose  : Draws line in the v3d view layer with given attributes: linetype,
2495 //         : linewidth, transparency coefficient
2496 //============================================================================
2497 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2498 {
2499   // get the active view
2500   Handle(V3d_View) aView = ViewerTest::CurrentView();
2501   if (aView.IsNull())
2502   {
2503     di << "Call vinit before!\n";
2504     return 1;
2505   }
2506   else if (argc < 5)
2507   {
2508     di << "Use: " << argv[0];
2509     di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
2510     di << " linetype : { 0 | 1 | 2 | 3 } \n";
2511     di << "              0 - solid  \n";
2512     di << "              1 - dashed \n";
2513     di << "              2 - dot    \n";
2514     di << "              3 - dashdot\n";
2515     di << " transparency : { 0.0 - 1.0 } \n";
2516     di << "                  0.0 - transparent\n";
2517     di << "                  1.0 - visible    \n";
2518     return 1;
2519   }
2520
2521   // get the input params
2522   Standard_Real X1 = Draw::Atof(argv[1]);
2523   Standard_Real Y1 = Draw::Atof(argv[2]);
2524   Standard_Real X2 = Draw::Atof(argv[3]);
2525   Standard_Real Y2 = Draw::Atof(argv[4]);
2526
2527   Standard_Real    aWidth = 0.5;
2528   Standard_Integer aType  = 0;
2529   Standard_Real    aTransparency = 1.0;
2530
2531   // has width
2532   if (argc > 5)
2533     aWidth = Draw::Atof(argv[5]);
2534
2535   // has type
2536   if (argc > 6)
2537      aType = (Standard_Integer) Draw::Atoi(argv[6]);
2538
2539   // has transparency
2540   if (argc > 7)
2541   {
2542     aTransparency = Draw::Atof(argv[7]);
2543     if (aTransparency < 0 || aTransparency > 1.0)
2544       aTransparency = 1.0;
2545   }
2546
2547   // select appropriate line type
2548   Aspect_TypeOfLine aLineType;
2549   switch (aType)
2550   {
2551     case 1:
2552       aLineType = Aspect_TOL_DASH;
2553     break;
2554
2555     case 2:
2556       aLineType = Aspect_TOL_DOT;
2557     break;
2558
2559     case 3:
2560       aLineType = Aspect_TOL_DOTDASH;
2561     break;
2562
2563     default:
2564       aLineType = Aspect_TOL_SOLID;
2565   }
2566
2567   // replace layer manager
2568   Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
2569   aView->SetLayerMgr(aMgr);
2570
2571   // add line item
2572   Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
2573                                                   aMgr.operator->(),
2574                                                   aLineType, aWidth,
2575                                                   aTransparency);
2576
2577   // update view
2578   aView->MustBeResized();
2579   aView->Redraw();
2580
2581   return 0;
2582 }
2583
2584 //=======================================================================
2585 //function : VOverlayText
2586 //purpose  : Test text displaying in view overlay
2587 //=======================================================================
2588 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
2589 {
2590   // get the active view
2591   Handle(V3d_View) aView = ViewerTest::CurrentView();
2592   if (aView.IsNull())
2593   {
2594     di << "No active view. Please call vinit.\n";
2595     return 1;
2596   }
2597   else if (argc < 4 || argc > 13)
2598   {
2599     di << "Use: " << argv[0];
2600     di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
2601     di << "[background_color: R G B]\n";
2602     di << "  height - pixel height of the text (default=10.0)\n";
2603     di << "  font_name - name of font (default=courier)\n";
2604     di << "  text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
2605     di << "  display_type = {normal/subtitle/decal/blend}, (default=normal)\n";
2606     di << "  background_color- R G B values used for subtitle and decal text\n";
2607     di << "(default=255.0 255.0 255.0)\n";
2608     return 1;
2609   }
2610
2611   TCollection_AsciiString aText (argv[1]);
2612   Standard_Real aPosX = Draw::Atof(argv[2]);
2613   Standard_Real aPosY = Draw::Atof(argv[3]);
2614   Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
2615
2616   // font name
2617   TCollection_AsciiString aFontName = "Courier";
2618   if (argc >= 6)
2619     aFontName = TCollection_AsciiString (argv[5]);
2620
2621   // text colors
2622   Quantity_Parameter aColorRed   = 1.0;
2623   Quantity_Parameter aColorGreen = 1.0;
2624   Quantity_Parameter aColorBlue  = 1.0;
2625   if (argc >= 9)
2626   {
2627     aColorRed   = Draw::Atof (argv[6])/255.;
2628     aColorGreen = Draw::Atof (argv[7])/255.;
2629     aColorBlue  = Draw::Atof (argv[8])/255.;
2630   }
2631
2632   // display type
2633   TCollection_AsciiString aDispStr;
2634   if (argc >= 10)
2635     aDispStr = TCollection_AsciiString (argv[9]);
2636
2637   Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
2638   if (aDispStr.IsEqual ("subtitle"))
2639     aTextType = Aspect_TODT_SUBTITLE;
2640   else if (aDispStr.IsEqual ("decal"))
2641     aTextType = Aspect_TODT_DEKALE;
2642   else if (aDispStr.IsEqual ("blend"))
2643     aTextType = Aspect_TODT_BLEND;
2644
2645   // subtitle color
2646   Quantity_Parameter aSubRed   = 1.0;
2647   Quantity_Parameter aSubGreen = 1.0;
2648   Quantity_Parameter aSubBlue  = 1.0;
2649   if (argc == 13)
2650   {
2651     aSubRed   = Draw::Atof (argv[10])/255.;
2652     aSubGreen = Draw::Atof (argv[11])/255.;
2653     aSubBlue  = Draw::Atof (argv[12])/255.;
2654   }
2655
2656   // check fo current overlay
2657   Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
2658   if (anOverlay.IsNull ())
2659   {
2660     Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
2661     anOverlay = aMgr->Overlay ();
2662     aView->SetLayerMgr (aMgr);
2663   }
2664
2665   Quantity_Color aTextColor (aColorRed, aColorGreen,
2666     aColorBlue, Quantity_TOC_RGB);
2667   Quantity_Color aSubtColor (aSubRed, aSubGreen,
2668     aSubBlue, Quantity_TOC_RGB);
2669
2670   // add text item
2671   Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
2672     aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
2673
2674   // update view
2675   aView->MustBeResized();
2676   aView->Redraw();
2677
2678   return 0;
2679 }
2680
2681 //==============================================================================
2682 //function : VGrid
2683 //purpose  :
2684 //==============================================================================
2685
2686 static int VGrid (Draw_Interpretor& theDI,
2687                   Standard_Integer  theArgNb,
2688                   const char**      theArgVec)
2689 {
2690   // get the active view
2691   Handle(V3d_View)   aView   = ViewerTest::CurrentView();
2692   Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
2693   if (aView.IsNull() || aViewer.IsNull())
2694   {
2695     std::cerr << "No active view. Please call vinit.\n";
2696     return 1;
2697   }
2698
2699   Aspect_GridType     aType = aViewer->GridType();
2700   Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
2701
2702   Standard_Integer anIter = 1;
2703   for (; anIter < theArgNb; ++anIter)
2704   {
2705     const char* aValue = theArgVec[anIter];
2706     if (*aValue == 'r')
2707     {
2708       aType = Aspect_GT_Rectangular;
2709     }
2710     else if (*aValue == 'c')
2711     {
2712       aType = Aspect_GT_Circular;
2713     }
2714     else if (*aValue == 'l')
2715     {
2716       aMode = Aspect_GDM_Lines;
2717     }
2718     else if (*aValue == 'p')
2719     {
2720       aMode = Aspect_GDM_Points;
2721     }
2722     else if (strcmp (aValue, "off" ) == 0)
2723     {
2724       aViewer->DeactivateGrid();
2725       return 0;
2726     }
2727     else
2728     {
2729       break;
2730     }
2731   }
2732
2733   Standard_Integer aTail = (theArgNb - anIter);
2734   if (aTail == 0)
2735   {
2736     aViewer->ActivateGrid (aType, aMode);
2737     return 0;
2738   }
2739   else if (aTail != 2 && aTail != 5)
2740   {
2741     std::cerr << "Incorrect arguments number! Usage:\n"
2742               << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
2743     return 1;
2744   }
2745
2746   Quantity_Length anOriginX, anOriginY;
2747   Quantity_PlaneAngle aRotAngle;
2748   if (aType == Aspect_GT_Rectangular)
2749   {
2750     Quantity_Length aRStepX, aRStepY;
2751     aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
2752
2753     anOriginX = Draw::Atof (theArgVec[anIter++]);
2754     anOriginY = Draw::Atof (theArgVec[anIter++]);
2755     if (aTail == 5)
2756     {
2757       aRStepX   = Draw::Atof (theArgVec[anIter++]);
2758       aRStepY   = Draw::Atof (theArgVec[anIter++]);
2759       aRotAngle = Draw::Atof (theArgVec[anIter++]);
2760     }
2761     aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
2762     aViewer->ActivateGrid (aType, aMode);
2763   }
2764   else if (aType == Aspect_GT_Circular)
2765   {
2766     Quantity_Length aRadiusStep;
2767     Standard_Integer aDivisionNumber;
2768     aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
2769
2770     anOriginX = Draw::Atof (theArgVec[anIter++]);
2771     anOriginY = Draw::Atof (theArgVec[anIter++]);
2772     if (aTail == 5)
2773     {
2774       aRadiusStep     = Draw::Atof (theArgVec[anIter++]);
2775       aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
2776       aRotAngle       = Draw::Atof (theArgVec[anIter++]);
2777     }
2778
2779     aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
2780     aViewer->ActivateGrid (aType, aMode);
2781   }
2782
2783   return 0;
2784 }
2785
2786 //==============================================================================
2787 //function : VFps
2788 //purpose  :
2789 //==============================================================================
2790
2791 static int VFps (Draw_Interpretor& theDI,
2792                  Standard_Integer  theArgNb,
2793                  const char**      theArgVec)
2794 {
2795   // get the active view
2796   Handle(V3d_View) aView = ViewerTest::CurrentView();
2797   if (aView.IsNull())
2798   {
2799     std::cerr << "No active view. Please call vinit.\n";
2800     return 1;
2801   }
2802
2803   Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
2804   if (aFramesNb <= 0)
2805   {
2806     std::cerr << "Incorrect arguments!\n";
2807     return 1;
2808   }
2809
2810   // the time is meaningless for first call
2811   // due to async OpenGl rendering
2812   aView->Redraw();
2813
2814   // redraw view in loop to estimate average values
2815   OSD_Timer aTimer;
2816   aTimer.Start();
2817   for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
2818   {
2819     aView->Redraw();
2820   }
2821   aTimer.Stop();
2822   Standard_Real aCpu;
2823   const Standard_Real aTime = aTimer.ElapsedTime();
2824   aTimer.OSD_Chronometer::Show (aCpu);
2825
2826   const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
2827   const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
2828
2829   // return statistics
2830   theDI << "FPS: " << aFpsAver << "\n"
2831         << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
2832
2833   return 0;
2834 }
2835
2836
2837 //==============================================================================
2838 //function : VVbo
2839 //purpose  :
2840 //==============================================================================
2841
2842 static int VVbo (Draw_Interpretor& theDI,
2843                  Standard_Integer  theArgNb,
2844                  const char**      theArgVec)
2845 {
2846   // get the context
2847   Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2848   if (aContextAIS.IsNull())
2849   {
2850     std::cerr << "No active view. Please call vinit.\n";
2851     return 1;
2852   }
2853
2854   Handle(Graphic3d_GraphicDriver) aDriver =
2855          Handle(Graphic3d_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Device()->GraphicDriver());
2856   if (aDriver.IsNull())
2857   {
2858     std::cerr << "Graphic driver not available.\n";
2859     return 1;
2860   }
2861
2862   if (theArgNb < 2)
2863   {
2864     //theDI << "VBO: " << aDriver->ToUseVBO() << "\n";
2865     //return 0;
2866     std::cerr << "Wrong number of arguments.\n";
2867     return 1;
2868   }
2869
2870   aDriver->EnableVBO (Draw::Atoi(theArgVec[1]) != 0);
2871   return 0;
2872 }
2873
2874 //==============================================================================
2875 //function : VMemGpu
2876 //purpose  :
2877 //==============================================================================
2878
2879 static int VMemGpu (Draw_Interpretor& theDI,
2880                     Standard_Integer  theArgNb,
2881                     const char**      theArgVec)
2882 {
2883   // get the context
2884   Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2885   if (aContextAIS.IsNull())
2886   {
2887     std::cerr << "No active view. Please call vinit.\n";
2888     return 1;
2889   }
2890
2891   Handle(Graphic3d_GraphicDriver) aDriver =
2892          Handle(Graphic3d_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Device()->GraphicDriver());
2893   if (aDriver.IsNull())
2894   {
2895     std::cerr << "Graphic driver not available.\n";
2896     return 1;
2897   }
2898
2899   Standard_Size aFreeBytes = 0;
2900   TCollection_AsciiString anInfo;
2901   if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
2902   {
2903     std::cerr << "Information not available.\n";
2904     return 1;
2905   }
2906
2907   if (theArgNb > 1 && *theArgVec[1] == 'f')
2908   {
2909     theDI << Standard_Real (aFreeBytes);
2910   }
2911   else
2912   {
2913     theDI << anInfo;
2914   }
2915
2916   return 0;
2917 }
2918
2919 // ==============================================================================
2920 // function : VReadPixel
2921 // purpose  :
2922 // ==============================================================================
2923 static int VReadPixel (Draw_Interpretor& theDI,
2924                        Standard_Integer  theArgNb,
2925                        const char**      theArgVec)
2926 {
2927   // get the active view
2928   Handle(V3d_View) aView = ViewerTest::CurrentView();
2929   if (aView.IsNull())
2930   {
2931     std::cerr << "No active view. Please call vinit.\n";
2932     return 1;
2933   }
2934   else if (theArgNb < 3)
2935   {
2936     std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
2937     return 1;
2938   }
2939
2940   Image_PixMap::ImgFormat aFormat     = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
2941   Graphic3d_BufferType    aBufferType = Graphic3d_BT_RGBA;
2942
2943   Standard_Integer aWidth, aHeight;
2944   aView->Window()->Size (aWidth, aHeight);
2945   const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
2946   const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
2947   if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
2948   {
2949     std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
2950     return 1;
2951   }
2952
2953   Standard_Boolean toShowName = Standard_False;
2954   Standard_Boolean toShowHls  = Standard_False;
2955   for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
2956   {
2957     TCollection_AsciiString aParam (theArgVec[anIter]);
2958     if (TCollection_AsciiString::ISSIMILAR      (aParam, TCollection_AsciiString ("rgb")))
2959     {
2960       aFormat     = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
2961       aBufferType = Graphic3d_BT_RGB;
2962     }
2963     else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("hls")))
2964     {
2965       aFormat     = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
2966       aBufferType = Graphic3d_BT_RGB;
2967       toShowHls   = Standard_True;
2968     }
2969     else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgbf")))
2970     {
2971       aFormat     = Image_PixMap::ImgRGBF;
2972       aBufferType = Graphic3d_BT_RGB;
2973     }
2974     else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgba")))
2975     {
2976       aFormat     = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
2977       aBufferType = Graphic3d_BT_RGBA;
2978     }
2979     else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgbaf")))
2980     {
2981       aFormat     = Image_PixMap::ImgRGBAF;
2982       aBufferType = Graphic3d_BT_RGBA;
2983     }
2984     else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("depth")))
2985     {
2986       aFormat     = Image_PixMap::ImgGrayF;
2987       aBufferType = Graphic3d_BT_Depth;
2988     }
2989     else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("name")))
2990     {
2991       toShowName = Standard_True;
2992     }
2993   }
2994
2995   Image_PixMap anImage;
2996   if (!anImage.InitTrash (aFormat, aWidth, aHeight))
2997   {
2998     std::cerr << "Image allocation failed\n";
2999     return 1;
3000   }
3001   else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
3002   {
3003     std::cerr << "Image dump failed\n";
3004     return 1;
3005   }
3006
3007   Quantity_Parameter anAlpha;
3008   Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
3009   if (toShowName)
3010   {
3011     if (aBufferType == Graphic3d_BT_RGBA)
3012     {
3013       theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha << "\n";
3014     }
3015     else
3016     {
3017       theDI << Quantity_Color::StringName (aColor.Name()) << "\n";
3018     }
3019   }
3020   else
3021   {
3022     switch (aBufferType)
3023     {
3024       default:
3025       case Graphic3d_BT_RGB:
3026       {
3027         if (toShowHls)
3028         {
3029           theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation() << "\n";
3030         }
3031         else
3032         {
3033           theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << "\n";
3034         }
3035         break;
3036       }
3037       case Graphic3d_BT_RGBA:
3038       {
3039         theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha << "\n";
3040         break;
3041       }
3042       case Graphic3d_BT_Depth:
3043       {
3044         theDI << aColor.Red() << "\n";
3045         break;
3046       }
3047     }
3048   }
3049
3050   return 0;
3051 }
3052
3053 //==============================================================================
3054 //function : VDiffImage
3055 //purpose  : The draw-command compares two images.
3056 //==============================================================================
3057
3058 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3059 {
3060   if (theArgNb < 6)
3061   {
3062     theDI << "Not enough arguments.\n";
3063     return 1;
3064   }
3065
3066   // image file names
3067   const char* anImgPathRef = theArgVec[1];
3068   const char* anImgPathNew = theArgVec[2];
3069
3070   // get string tolerance and check its validity
3071   Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
3072   if (aTolColor < 0.0)
3073     aTolColor = 0.0;
3074   if (aTolColor > 1.0)
3075     aTolColor = 1.0;
3076
3077   Standard_Boolean toBlackWhite     = (Draw::Atoi (theArgVec[4]) == 1);
3078   Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
3079
3080   // image file of difference
3081   const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
3082
3083   // compare the images
3084   Image_Diff aComparer;
3085   if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
3086   {
3087     return 1;
3088   }
3089
3090   aComparer.SetColorTolerance (aTolColor);
3091   aComparer.SetBorderFilterOn (isBorderFilterOn);
3092   Standard_Integer aDiffColorsNb = aComparer.Compare();
3093   theDI << aDiffColorsNb << "\n";
3094
3095   // save image of difference
3096   if (aDiffImagePath != NULL)
3097   {
3098     aComparer.SaveDiffImage (aDiffImagePath);
3099   }
3100
3101   return 0;
3102 }
3103
3104 //=======================================================================
3105 //function : VSelect
3106 //purpose  : Emulates different types of selection by mouse:
3107 //           1) single click selection
3108 //           2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
3109 //           3) selection with polygon having corners at
3110 //           pixel positions (x1,y1),...,(xn,yn) 
3111 //           4) any of these selections with shift button pressed
3112 //=======================================================================
3113 static Standard_Integer VSelect (Draw_Interpretor& di,
3114                                  Standard_Integer argc,
3115                                  const char ** argv)
3116 {
3117   if(argc < 3) 
3118   {
3119     di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
3120     return 1;
3121   }
3122
3123   Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
3124   if(myAIScontext.IsNull()) 
3125   {
3126     di << "use 'vinit' command before " << argv[0] << "\n";
3127     return 1;
3128   }
3129   const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
3130   Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
3131   aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
3132   if(argc <= 4)
3133   {
3134     if(isShiftSelection)
3135       aCurrentEventManager->ShiftSelect();
3136     else
3137       aCurrentEventManager->Select();
3138   }
3139   else if(argc <= 6)
3140   {
3141     if(isShiftSelection)
3142       aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
3143     else
3144       aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
3145   }
3146   else
3147   {
3148     Standard_Integer anUpper = 0;
3149
3150     if(isShiftSelection)
3151       anUpper = (argc-1)/2;
3152     else
3153       anUpper = argc/2;
3154     TColgp_Array1OfPnt2d aPolyline(1,anUpper);
3155
3156     for(Standard_Integer i=1;i<=anUpper;++i)
3157       aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
3158
3159     if(isShiftSelection)
3160       aCurrentEventManager->ShiftSelect(aPolyline);
3161     else
3162       aCurrentEventManager->Select(aPolyline);
3163   }
3164   return 0;
3165 }
3166
3167 //=======================================================================
3168 //function : VMoveTo
3169 //purpose  : Emulates cursor movement to defined pixel position     
3170 //=======================================================================
3171 static Standard_Integer VMoveTo (Draw_Interpretor& di,
3172                                 Standard_Integer argc,
3173                                 const char ** argv)
3174 {
3175   if(argc != 3) 
3176   {
3177     di << "Usage : " << argv[0] << " x y" << "\n";
3178     return 1;
3179   }
3180
3181   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3182   if(aContext.IsNull()) 
3183   {
3184     di << "use 'vinit' command before " << argv[0] << "\n";
3185     return 1;
3186   }
3187   ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
3188   return 0;
3189 }
3190
3191 //=======================================================================
3192 //function : VViewParams
3193 //purpose  : Gets or sets AIS View characteristics      
3194 //=======================================================================
3195 static Standard_Integer VViewParams (Draw_Interpretor& di,
3196                                 Standard_Integer argc,
3197                                 const char ** argv)
3198 {
3199   if ( argc != 1 && argc != 13) 
3200   {
3201     di << "Usage : " << argv[0] << "\n";
3202     return 1;
3203   }
3204   Handle (V3d_View) anAISView = ViewerTest::CurrentView ();
3205   if ( anAISView.IsNull () ) 
3206   {
3207     di << "use 'vinit' command before " << argv[0] << "\n";
3208     return 1;
3209   }
3210   if(argc==1){
3211     Quantity_Factor anAISViewScale = anAISView -> V3d_View::Scale ();
3212     Standard_Real anAISViewCenterCoordinateX = 0.0;
3213     Standard_Real anAISViewCenterCoordinateY = 0.0;
3214     anAISView -> V3d_View::Center (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
3215     Standard_Real anAISViewProjX = 0.0;
3216     Standard_Real anAISViewProjY = 0.0;
3217     Standard_Real anAISViewProjZ = 0.0;
3218     anAISView -> V3d_View::Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
3219     Standard_Real anAISViewUpX = 0.0;
3220     Standard_Real anAISViewUpY = 0.0;
3221     Standard_Real anAISViewUpZ = 0.0;
3222     anAISView -> V3d_View::Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
3223     Standard_Real anAISViewAtX = 0.0;
3224     Standard_Real anAISViewAtY = 0.0;
3225     Standard_Real anAISViewAtZ = 0.0;
3226     anAISView -> V3d_View::At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
3227     di << "Scale of current view: " << anAISViewScale << "\n";
3228     di << "Center on X : "<< anAISViewCenterCoordinateX << "; on Y: " << anAISViewCenterCoordinateY << "\n";
3229     di << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
3230     di << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
3231     di << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
3232   }
3233   else
3234   {
3235     Quantity_Factor anAISViewScale = atof (argv [1]);
3236     Standard_Real anAISViewCenterCoordinateX = atof (argv [2]);
3237     Standard_Real anAISViewCenterCoordinateY = atof (argv [3]);
3238     Standard_Real anAISViewProjX = atof (argv [4]);
3239     Standard_Real anAISViewProjY = atof (argv [5]);
3240     Standard_Real anAISViewProjZ = atof (argv [6]);
3241     Standard_Real anAISViewUpX = atof (argv [7]);
3242     Standard_Real anAISViewUpY = atof (argv [8]);
3243     Standard_Real anAISViewUpZ = atof (argv [9]);
3244     Standard_Real anAISViewAtX = atof (argv [10]);
3245     Standard_Real anAISViewAtY = atof (argv [11]);
3246     Standard_Real anAISViewAtZ = atof (argv [12]);
3247     anAISView -> V3d_View::SetScale (anAISViewScale);
3248     anAISView -> V3d_View::SetCenter (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
3249     anAISView -> V3d_View::SetAt (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
3250     anAISView -> V3d_View::SetProj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
3251     anAISView -> V3d_View::SetUp (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
3252   }
3253   return 0;
3254 }
3255
3256 //=======================================================================
3257 //function : VChangeSelected
3258 //purpose  : Adds the shape to selection or remove one from it    
3259 //=======================================================================
3260 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
3261                                 Standard_Integer argc,
3262                                 const char ** argv)
3263 {
3264   if(argc != 2)
3265   {
3266     di<<"Usage : " << argv[0] << " shape \n";
3267     return 1;
3268   }
3269   //get AIS_Shape:
3270   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3271   ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3272   TCollection_AsciiString aName(argv[1]);
3273   Handle(AIS_InteractiveObject) anAISObject;
3274
3275   if(!aMap.IsBound2(aName))
3276   {
3277     di<<"Use 'vdisplay' before";
3278     return 1;
3279   }
3280   else
3281   {
3282     anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
3283     if(anAISObject.IsNull()){
3284       di<<"No interactive object \n";
3285       return 1;
3286     }
3287
3288     if(aContext->HasOpenedContext())
3289     {
3290       aContext->AddOrRemoveSelected(anAISObject);
3291     }
3292     else 
3293     {
3294       aContext->AddOrRemoveCurrentObject(anAISObject);
3295     }
3296   }
3297   return 0;
3298 }
3299
3300 //=======================================================================
3301 //function : VZClipping
3302 //purpose  : Gets or sets ZClipping mode, width and depth   
3303 //=======================================================================
3304 static Standard_Integer VZClipping (Draw_Interpretor& di,
3305                                 Standard_Integer argc,
3306                                 const char ** argv)
3307 {
3308   if(argc>4) 
3309   {
3310     di << "Usage : " << argv[0] << " [mode] [depth  width]" << "\n"
3311       <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
3312     return -1;
3313   }
3314   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3315   if(aContext.IsNull()) 
3316   {
3317     di << "use 'vinit' command before " << argv[0] << "\n";
3318     return 1;
3319   }
3320   Handle(V3d_View) aView = ViewerTest::CurrentView();
3321   V3d_TypeOfZclipping aZClippingMode;
3322   if(argc==1)
3323   {
3324     TCollection_AsciiString aZClippingModeString;
3325     Quantity_Length aDepth, aWidth;
3326     aZClippingMode = aView->ZClipping(aDepth, aWidth);
3327     switch (aZClippingMode)
3328     {
3329     case V3d_OFF:
3330       aZClippingModeString.Copy("OFF");
3331       break;
3332     case V3d_BACK:
3333       aZClippingModeString.Copy("BACK");
3334       break;
3335     case V3d_FRONT:
3336       aZClippingModeString.Copy("FRONT");
3337       break;
3338     case V3d_SLICE:
3339       aZClippingModeString.Copy("SLICE");
3340       break;
3341     default:
3342       aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
3343       break;
3344     }
3345     di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
3346       << "ZClipping depth = " << aDepth << "\n"
3347       << "ZClipping width = " << aWidth << "\n";
3348   }
3349   else
3350   {
3351     if(argc !=3)
3352     {
3353       Standard_Integer aStatus = 0;
3354       if ( strcmp (argv [1], "OFF") == 0 ) {
3355         aStatus = 1;
3356         aZClippingMode = V3d_OFF;
3357       }
3358       if ( strcmp (argv [1], "BACK") == 0 ) {
3359         aStatus = 1;
3360         aZClippingMode = V3d_BACK;
3361       }
3362       if ( strcmp (argv [1], "FRONT") == 0 ) {
3363         aStatus = 1;
3364         aZClippingMode = V3d_FRONT;
3365       }
3366       if ( strcmp (argv [1], "SLICE") == 0 ) {
3367         aStatus = 1;
3368         aZClippingMode = V3d_SLICE;
3369       }
3370       if (aStatus != 1)
3371       {
3372         di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
3373           << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
3374         return 1;
3375       } 
3376       aView->SetZClippingType(aZClippingMode);
3377     }
3378     if(argc >2)
3379     {
3380       Quantity_Length aDepth = 0., aWidth = 1.;
3381       if(argc == 3)
3382       {
3383         aDepth = atof(argv[1]);
3384         aWidth = atof(argv[2]);
3385       }
3386       else if(argc == 4)
3387       {
3388         aDepth = atof(argv[2]);
3389         aWidth = atof(argv[3]);
3390       }
3391       
3392       if(aDepth<0. || aDepth>1.)
3393       {
3394         di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
3395         << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
3396         return 1;
3397       }
3398       if(aWidth<0. || aWidth>1.)
3399       {
3400         di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
3401         << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
3402         return 1;
3403       }
3404
3405       aView->SetZClippingDepth(aDepth);
3406       aView->SetZClippingWidth(aWidth);
3407     }
3408     aView->Redraw();
3409   }
3410   return 0;
3411 }
3412
3413 //=======================================================================
3414 //function : VNbSelected
3415 //purpose  : Returns number of selected objects  
3416 //=======================================================================
3417 static Standard_Integer VNbSelected (Draw_Interpretor& di,
3418                                 Standard_Integer argc,
3419                                 const char ** argv)
3420 {
3421   if(argc != 1)
3422   {
3423     di << "Usage : " << argv[0] << "\n";
3424     return 1;
3425   }
3426   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3427   if(aContext.IsNull())
3428   {
3429     di << "use 'vinit' command before " << argv[0] << "\n";
3430     return 1;
3431   }
3432   di << aContext->NbSelected() << "\n";
3433   return 0;
3434 }
3435
3436 //=======================================================================
3437 //function : VAntialiasing
3438 //purpose  : Switches altialiasing on or off  
3439 //=======================================================================
3440 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
3441                                 Standard_Integer argc,
3442                                 const char ** argv)
3443 {
3444   if(argc > 2)
3445   {
3446     di << "Usage : " << argv[0] << " [1|0]" << "\n";
3447     return 1;
3448   }
3449
3450   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3451   if(aContext.IsNull())
3452   {
3453     di << "use 'vinit' command before " << argv[0] << "\n";
3454     return 1;
3455   }
3456
3457   Handle(V3d_View) aView = ViewerTest::CurrentView();
3458
3459   if((argc == 2) && (atof(argv[1]) == 0))
3460     aView->SetAntialiasingOff();
3461   else
3462     aView->SetAntialiasingOn();
3463   aView->Update();
3464   return 0;
3465 }
3466
3467 //=======================================================================
3468 //function : VPurgeDisplay
3469 //purpose  : Switches altialiasing on or off  
3470 //=======================================================================
3471 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
3472                                 Standard_Integer argc,
3473                                 const char ** argv)
3474 {
3475   if (argc > 2)
3476   {
3477     di << "Usage : " << argv[0] << " [CollectorToo = 0|1]" << "\n";
3478     return 1;
3479   }
3480   Standard_Boolean isCollectorToo = Standard_False;
3481   if (argc == 2)
3482   {
3483       isCollectorToo = (atoi(argv [1]) != 0);
3484   }
3485   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3486   if (aContext.IsNull())
3487   {
3488     di << "use 'vinit' command before " << argv[0] << "\n";
3489     return 1;
3490   }
3491   aContext->CloseAllContexts(Standard_False);
3492   di << aContext->PurgeDisplay(isCollectorToo) << "\n";
3493   return 0;
3494 }
3495
3496 //=======================================================================
3497 //function : VSetViewSize
3498 //purpose  :
3499 //=======================================================================
3500 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
3501                                 Standard_Integer argc,
3502                                 const char ** argv)
3503 {
3504   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3505   if(aContext.IsNull())
3506   {
3507     di << "use 'vinit' command before " << argv[0] << "\n";
3508     return 1;
3509   }
3510   if(argc != 2)
3511   {
3512     di<<"Usage : " << argv[0] << " Size\n";
3513     return 1;
3514   }
3515   Standard_Real aSize = atof(argv[1]);
3516   if (aSize <= 0.)
3517   {
3518     di<<"Bad Size value  : " << aSize << "\n";
3519     return 1;
3520   }
3521
3522   Handle(V3d_View) aView = ViewerTest::CurrentView();
3523   aView->SetSize(aSize);
3524   return 0;
3525 }
3526
3527 //=======================================================================
3528 //function : VMoveView
3529 //purpose  :
3530 //=======================================================================
3531 static Standard_Integer VMoveView (Draw_Interpretor& di,
3532                                 Standard_Integer argc,
3533                                 const char ** argv)
3534 {
3535   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3536   if(aContext.IsNull())
3537   {
3538     di << "use 'vinit' command before " << argv[0] << "\n";
3539     return 1;
3540   }
3541   if(argc < 4 || argc > 5)
3542   {
3543     di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
3544     return 1;
3545   }
3546   Standard_Real Dx = atof(argv[1]);
3547   Standard_Real Dy = atof(argv[2]);
3548   Standard_Real Dz = atof(argv[3]);
3549   Standard_Boolean aStart = Standard_True;
3550   if (argc == 5)
3551   {
3552       aStart = (atoi(argv[4]) > 0);
3553   }
3554
3555   Handle(V3d_View) aView = ViewerTest::CurrentView();
3556   aView->Move(Dx,Dy,Dz,aStart);
3557   return 0;
3558 }
3559
3560 //=======================================================================
3561 //function : VTranslateView
3562 //purpose  :
3563 //=======================================================================
3564 static Standard_Integer VTranslateView (Draw_Interpretor& di,
3565                                 Standard_Integer argc,
3566                                 const char ** argv)
3567 {
3568   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3569   if(aContext.IsNull())
3570   {
3571     di << "use 'vinit' command before " << argv[0] << "\n";
3572     return 1;
3573   }
3574   if(argc < 4 || argc > 5)
3575   {
3576     di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
3577     return 1;
3578   }
3579   Standard_Real Dx = atof(argv[1]);
3580   Standard_Real Dy = atof(argv[2]);
3581   Standard_Real Dz = atof(argv[3]);
3582   Standard_Boolean aStart = Standard_True;
3583   if (argc == 5) 
3584   {
3585       aStart = (atoi(argv[4]) > 0);
3586   }
3587
3588   Handle(V3d_View) aView = ViewerTest::CurrentView();
3589   aView->Translate(Dx,Dy,Dz,aStart);
3590   return 0;
3591 }
3592
3593 //=======================================================================
3594 //function : VTurnView
3595 //purpose  :
3596 //=======================================================================
3597 static Standard_Integer VTurnView (Draw_Interpretor& di,
3598                                 Standard_Integer argc,
3599                                 const char ** argv)
3600 {
3601   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3602   if(aContext.IsNull()) {
3603     di << "use 'vinit' command before " << argv[0] << "\n";
3604     return 1;
3605   }
3606   if(argc < 4 || argc > 5){
3607     di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
3608     return 1;
3609   }
3610   Standard_Real Ax = atof(argv[1]);
3611   Standard_Real Ay = atof(argv[2]);
3612   Standard_Real Az = atof(argv[3]);
3613   Standard_Boolean aStart = Standard_True;
3614   if (argc == 5) 
3615   {
3616       aStart = (atoi(argv[4]) > 0);
3617   }
3618
3619   Handle(V3d_View) aView = ViewerTest::CurrentView();
3620   aView->Turn(Ax,Ay,Az,aStart);
3621   return 0;
3622 }
3623
3624 //=======================================================================
3625 //function : ViewerCommands
3626 //purpose  :
3627 //=======================================================================
3628
3629 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
3630 {
3631
3632   const char *group = "ZeViewer";
3633   theCommands.Add("vinit" ,
3634     "vinit            : vinit [leftPx topPx widthPx heightPx] : Create the Viewer window",
3635     __FILE__,VInit,group);
3636   theCommands.Add("vhelp" ,
3637     "vhelp            : display help on the viewer commands",
3638     __FILE__,VHelp,group);
3639   theCommands.Add("vtop" ,
3640     "vtop or <T>      : Top view" ,
3641     __FILE__,VTop,group);
3642   theCommands.Add("vbottom" ,
3643     "vbottom          : Bottom view" ,
3644     __FILE__,VBottom,group);
3645   theCommands.Add("vleft" ,
3646     "vleft            : Left view" ,
3647     __FILE__,VLeft,group);
3648   theCommands.Add("vright" ,
3649     "vright           : Right view" ,
3650     __FILE__,VRight,group);
3651   theCommands.Add("vaxo" ,
3652     " vaxo or <A>     : Axonometric view ",
3653     __FILE__,VAxo,group);
3654   theCommands.Add("vfront" ,
3655     "vfront           : Front view" ,
3656     __FILE__,VFront,group);
3657   theCommands.Add("vback" ,
3658     "vback            : Back view" ,
3659     __FILE__,VBack,group);
3660   theCommands.Add("vpick" ,
3661     "vpick           : vpick X Y Z [shape subshape] ( all variables as string )",
3662     VPick,group);
3663   theCommands.Add("vfit"    ,
3664     "vfit or <F>         : vfit",
3665     __FILE__,VFit,group);
3666   theCommands.Add("vzfit"    ,
3667     "vzfit",
3668     __FILE__,VZFit,group);
3669   theCommands.Add("vrepaint",
3670     "vrepaint        : vrepaint, force redraw",
3671     __FILE__,VRepaint,group);
3672   theCommands.Add("vclear",
3673     "vclear          : vclear",
3674     __FILE__,VClear,group);
3675   theCommands.Add("vsetbg",
3676     "vsetbg          : vsetbg imagefile [filltype] : Load image as background",
3677     __FILE__,VSetBg,group);
3678   theCommands.Add("vsetbgmode",
3679     "vsetbgmode      : vsetbgmode filltype : Change background image fill type",
3680     __FILE__,VSetBgMode,group);
3681   theCommands.Add("vsetgradientbg",
3682     "vsetgradientbg  : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
3683     __FILE__,VSetGradientBg,group);
3684   theCommands.Add("vsetgrbgmode",
3685     "vsetgrbgmode    : vsetgrbgmode filltype : Change gradient background fill type",
3686     __FILE__,VSetGradientBgMode,group);
3687   theCommands.Add("vsetcolorbg",
3688     "vsetcolorbg     : vsetcolorbg r g b : Set background color",
3689     __FILE__,VSetColorBg,group);
3690   theCommands.Add("vscale",
3691     "vscale          : vscale X Y Z",
3692     __FILE__,VScale,group);
3693   theCommands.Add("vzbufftrihedron",
3694     "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
3695     " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
3696     " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
3697     __FILE__,VTestZBuffTrihedron,group);
3698   theCommands.Add("vrotate",
3699     "vrotate         : vrotate AX AY AZ [X Y Z]",
3700     __FILE__,VRotate,group);
3701   theCommands.Add("vzoom",
3702     "vzoom           : vzoom coef",
3703     __FILE__,VZoom,group);
3704   theCommands.Add("vpan",
3705     "vpan            : vpan dx dy",
3706     __FILE__,VPan,group);
3707   theCommands.Add("vexport",
3708     "vexport         : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
3709     " : exports the view to a vector file of a given format"
3710     " : notice that EMF format requires patched gl2ps",
3711     __FILE__,VExport,group);
3712   theCommands.Add("vcolorscale",
3713     "vcolorscale     : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
3714     __FILE__,VColorScale,group);
3715   theCommands.Add("vgraduatedtrihedron",
3716     "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
3717     __FILE__,VGraduatedTrihedron,group);
3718   theCommands.Add("vprintview" ,
3719     "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
3720     __FILE__,VPrintView,group);
3721   theCommands.Add("vzlayer",
3722     "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
3723     __FILE__,VZLayer,group);
3724   theCommands.Add("voverlaytext",
3725     "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
3726     " : height - pixel height of the text (default=10.0)"
3727     " : font_name - name of font (default=courier)"
3728     " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
3729     " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
3730     " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
3731     __FILE__,VOverlayText,group);
3732   theCommands.Add("vlayerline",
3733     "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
3734     __FILE__,VLayerLine,group);
3735   theCommands.Add ("vgrid",
3736     "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
3737     " : Mode - rectangular or circular"
3738     " : Type - lines or points",
3739     __FILE__, VGrid, group);
3740   theCommands.Add ("vfps",
3741     "vfps [framesNb=100] : estimate average frame rate for active view",
3742     __FILE__, VFps, group);
3743   theCommands.Add ("vvbo",
3744     "vvbo {0|1} : turn VBO usage On/Off; affects only newly displayed objects",
3745     __FILE__, VVbo, group);
3746   theCommands.Add ("vmemgpu",
3747     "vmemgpu [f]: print system-dependent GPU memory information if available;"
3748     " with f option returns free memory in bytes",
3749     __FILE__, VMemGpu, group);
3750   theCommands.Add ("vreadpixel",
3751     "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
3752     " : Read pixel value for active view",
3753     __FILE__, VReadPixel, group);
3754   theCommands.Add("diffimage",
3755     "diffimage     : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
3756     __FILE__, VDiffImage, group);
3757   theCommands.Add ("vselect",
3758     "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
3759     "- emulates different types of selection:\n"
3760     "- 1) single click selection\n"
3761     "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
3762     "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
3763     "- 4) any of these selections with shift button pressed",
3764     __FILE__, VSelect, group);
3765   theCommands.Add ("vmoveto",
3766     "vmoveto x y"
3767     "- emulates cursor movement to pixel postion (x,y)",
3768     __FILE__, VMoveTo, group);
3769   theCommands.Add("vviewparams",
3770     "vviewparams [scale center_X center_Y proj_X proj_Y proj_Z up_X up_Y up_Z at_X at_Y at_Z]"
3771     "- gets or sets current view characteristics",
3772     __FILE__,VViewParams, group);
3773   theCommands.Add("vchangeselected",
3774     "vchangeselected shape" 
3775     "- adds to shape to selection or remove one from it",
3776                 __FILE__, VChangeSelected, group);
3777   theCommands.Add("vzclipping",
3778     "vzclipping [mode] [depth width]\n"
3779     "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
3780     "- gets or sets ZClipping mode, width and depth",
3781     __FILE__,VZClipping,group);
3782   theCommands.Add ("vnbselected",
3783     "vnbselected", __FILE__, VNbSelected, group);
3784   theCommands.Add("vantialiasing",
3785     "vantialiasing 1|0",
3786     __FILE__,VAntialiasing,group);
3787   theCommands.Add ("vpurgedisplay",
3788     "vpurgedisplay [CollectorToo = 0|1]"
3789     "- removes structures which don't belong to objects displayed in neutral point",
3790     __FILE__, VPurgeDisplay, group);
3791   theCommands.Add("vsetviewsize",
3792     "vsetviewsize size",
3793     __FILE__,VSetViewSize,group);
3794   theCommands.Add("vmoveview",
3795     "vmoveview Dx Dy Dz [Start = 1|0]",
3796     __FILE__,VMoveView,group);
3797   theCommands.Add("vtranslateview",
3798     "vtranslateview Dx Dy Dz [Start = 1|0)]",
3799     __FILE__,VTranslateView,group);
3800   theCommands.Add("vturnview",
3801     "vturnview Ax Ay Az [Start = 1|0]",
3802     __FILE__,VTurnView,group);
3803 }