0023654: Problem with displaying vertices in OCC view after closing all OCC views...
[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 #include <OpenGl_GlCore20.hxx>
29 #include <AIS_Shape.hxx>
30 #include <AIS_Drawer.hxx>
31 #include <AIS_InteractiveObject.hxx>
32 #include <AIS_ListOfInteractive.hxx>
33 #include <AIS_ListIteratorOfListOfInteractive.hxx>
34 #include <DBRep.hxx>
35 #include <Graphic3d_AspectMarker3d.hxx>
36 #include <Graphic3d_ExportFormat.hxx>
37 #include <Graphic3d_NameOfTextureEnv.hxx>
38 #include <Graphic3d_TextureEnv.hxx>
39 #include <Graphic3d_TextureParams.hxx>
40 #include <Graphic3d_TypeOfTextureFilter.hxx>
41 #include <Graphic3d_AspectFillArea3d.hxx>
42 #include <ViewerTest.hxx>
43 #include <ViewerTest_EventManager.hxx>
44 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
45 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
46 #include <Visual3d_View.hxx>
47 #include <Visual3d_ViewManager.hxx>
48 #include <V3d_LayerMgr.hxx>
49 #include <NCollection_DoubleMap.hxx>
50 #include <NCollection_List.hxx>
51 #include <NCollection_Vector.hxx>
52 #include <NIS_View.hxx>
53 #include <NIS_Triangulated.hxx>
54 #include <NIS_InteractiveContext.hxx>
55 #include <AIS_InteractiveContext.hxx>
56 #include <Draw_Interpretor.hxx>
57 #include <Draw.hxx>
58 #include <Draw_Appli.hxx>
59 #include <Aspect_PrintAlgo.hxx>
60 #include <Image_AlienPixMap.hxx>
61 #include <OpenGl_GraphicDriver.hxx>
62 #include <OSD_Timer.hxx>
63 #include <TColStd_SequenceOfInteger.hxx>
64 #include <TColStd_HSequenceOfReal.hxx>
65 #include <TColgp_Array1OfPnt2d.hxx>
66 #include <Visual3d_LayerItem.hxx>
67 #include <V3d_LayerMgr.hxx>
68 #include <V3d_LayerMgrPointer.hxx>
69 #include <Aspect_TypeOfLine.hxx>
70 #include <Image_Diff.hxx>
71 #include <Aspect_DisplayConnection.hxx>
72 #include <Graphic3d.hxx>
73 #include <gp_Pnt.hxx>
74 #include <gp_Dir.hxx>
75 #include <gp_Pln.hxx>
76 #include <PrsMgr_PresentableObject.hxx>
77 #include <Graphic3d_ClipPlane.hxx>
78 #include <NCollection_DataMap.hxx>
79 #include <Graphic3d_Texture2Dmanual.hxx>
80 #include <Prs3d_ShadingAspect.hxx>
81
82 #ifdef WNT
83 #undef DrawText
84 #endif
85
86 #include <Visual3d_Layer.hxx>
87 #include <cstdlib>
88
89 #if defined(_WIN32)
90   #include <WNT_WClass.hxx>
91   #include <WNT_Window.hxx>
92
93   #if defined(_MSC_VER)
94     #define _CRT_SECURE_NO_DEPRECATE
95     #pragma warning (disable:4996)
96   #endif
97 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
98   #include <Cocoa_Window.hxx>
99   #include <tk.h>
100 #else
101   #include <Xw_Window.hxx>
102   #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
103   #include <X11/Xutil.h>
104   #include <tk.h>
105 #endif
106
107 //==============================================================================
108
109 //==============================================================================
110 //  VIEWER GLOBAL VARIABLES
111 //==============================================================================
112
113 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
114
115 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
116 extern const Handle(NIS_InteractiveContext)& TheNISContext();
117 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
118
119 #if defined(_WIN32)
120 static Handle(WNT_Window)& VT_GetWindow() {
121   static Handle(WNT_Window) WNTWin;
122   return WNTWin;
123 }
124 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
125 static Handle(Cocoa_Window)& VT_GetWindow()
126 {
127   static Handle(Cocoa_Window) aWindow;
128   return aWindow;
129 }
130 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
131 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
132 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
133
134 #else
135 static Handle(Xw_Window)& VT_GetWindow(){
136   static Handle(Xw_Window) XWWin;
137   return XWWin;
138 }
139
140 static void VProcessEvents(ClientData,int);
141 #endif
142
143 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
144 {
145   static Handle(Aspect_DisplayConnection) aDisplayConnection;
146   return aDisplayConnection;
147 }
148
149 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
150 {
151   GetDisplayConnection() = theDisplayConnection;
152 }
153
154 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
155 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
156 {
157   Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
158 #if defined(_WIN32)
159   const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
160   if (!aWindow.IsNull())
161     return aWindow->HWindow();
162 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
163   const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
164   if (!aWindow.IsNull())
165   return aWindow->XWindow();
166 #endif
167   return aWindowHandle;
168 }
169 #endif
170
171 static Standard_Boolean MyHLRIsOn = Standard_False;
172
173 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
174 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>  ViewerTest_myContexts;
175 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
176 static OpenGl_Caps ViewerTest_myDefaultCaps;
177
178 #define ZCLIPWIDTH 1.
179
180 static void OSWindowSetup();
181
182 //==============================================================================
183 //  EVENT GLOBAL VARIABLES
184 //==============================================================================
185
186 static int Start_Rot = 0;
187 static int ZClipIsOn = 0;
188 int X_Motion = 0; // Current cursor position
189 int Y_Motion = 0;
190 int X_ButtonPress = 0; // Last ButtonPress position
191 int Y_ButtonPress = 0;
192 Standard_Boolean IsDragged = Standard_False;
193 Standard_Boolean DragFirst;
194
195 //==============================================================================
196
197 #ifdef WNT
198 static LRESULT WINAPI ViewerWindowProc(
199                                        HWND hwnd,
200                                        UINT uMsg,
201                                        WPARAM wParam,
202                                        LPARAM lParam );
203 static LRESULT WINAPI AdvViewerWindowProc(
204   HWND hwnd,
205   UINT uMsg,
206   WPARAM wParam,
207   LPARAM lParam );
208 #endif
209
210
211 //==============================================================================
212 //function : WClass
213 //purpose  :
214 //==============================================================================
215
216 const Handle(MMgt_TShared)& ViewerTest::WClass()
217 {
218   static Handle(MMgt_TShared) theWClass;
219 #if defined(_WIN32)
220   if (theWClass.IsNull())
221   {
222     theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
223       CS_VREDRAW | CS_HREDRAW, 0, 0,
224       ::LoadCursor (NULL, IDC_ARROW));
225   }
226 #endif
227   return theWClass;
228 }
229
230 //==============================================================================
231 //function : CreateName
232 //purpose  : Create numerical name for new object in theMap
233 //==============================================================================
234 template <typename ObjectType>
235 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
236                                     const TCollection_AsciiString& theDefaultString)
237 {
238   if (theObjectMap.IsEmpty())
239     return theDefaultString + TCollection_AsciiString(1);
240
241   Standard_Integer aNextKey = 1;
242   Standard_Boolean isFound = Standard_False;
243   while (!isFound)
244   {
245     TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
246     // Look for objects with default names
247     if (theObjectMap.IsBound1(aStringKey))
248     {
249       aNextKey++;
250     }
251     else
252       isFound = Standard_True;
253   }
254
255   return theDefaultString + TCollection_AsciiString(aNextKey);
256 }
257
258 //==============================================================================
259 //structure : ViewerTest_Names
260 //purpose   : Allow to operate with full view name: driverName/viewerName/viewName
261 //==============================================================================
262 struct ViewerTest_Names
263 {
264 private:
265   TCollection_AsciiString myDriverName;
266   TCollection_AsciiString myViewerName;
267   TCollection_AsciiString myViewName;
268
269 public:
270
271   const TCollection_AsciiString& GetDriverName () const
272   {
273     return myDriverName;
274   }
275   void SetDriverName (const TCollection_AsciiString& theDriverName)
276   {
277     myDriverName = theDriverName;
278   }
279   const TCollection_AsciiString& GetViewerName () const
280   {
281     return myViewerName;
282   }
283   void SetViewerName (const TCollection_AsciiString& theViewerName)
284   {
285     myViewerName = theViewerName;
286   }
287   const TCollection_AsciiString& GetViewName () const
288   {
289     return myViewName;
290   }
291   void SetViewName (const TCollection_AsciiString& theViewName)
292   {
293     myViewName = theViewName;
294   }
295
296   //===========================================================================
297   //function : Constructor for ViewerTest_Names
298   //purpose  : Get view, viewer, driver names from custom string
299   //===========================================================================
300
301   ViewerTest_Names (const TCollection_AsciiString& theInputString)
302   {
303     TCollection_AsciiString aName(theInputString);
304     if (theInputString.IsEmpty())
305     {
306       // Get current configuration
307       if (ViewerTest_myDrivers.IsEmpty())
308         myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
309           (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
310       else
311         myDriverName = ViewerTest_myDrivers.Find2
312         (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
313
314       if(ViewerTest_myContexts.IsEmpty())
315       {
316         myViewerName = CreateName <Handle(AIS_InteractiveContext)>
317           (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
318       }
319       else
320         myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
321
322         myViewName = CreateName <Handle(V3d_View)>
323           (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
324     }
325     else
326     {
327       // There is at least view name
328       Standard_Integer aParserNumber = 0;
329       for (Standard_Integer i = 0; i < 3; ++i)
330       {
331         Standard_Integer aParserPos = aName.SearchFromEnd("/");
332         if(aParserPos != -1)
333         {
334           aParserNumber++;
335           aName.Split(aParserPos-1);
336         }
337         else
338           break;
339       }
340       if (aParserNumber == 0)
341       {
342         // Only view name
343         if (!ViewerTest::GetAISContext().IsNull())
344         {
345           myDriverName = ViewerTest_myDrivers.Find2
346           (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
347           myViewerName = ViewerTest_myContexts.Find2
348           (ViewerTest::GetAISContext());
349         }
350         else
351         {
352           // There is no opened contexts here, need to create names for viewer and driver
353           myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
354             (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
355
356           myViewerName = CreateName <Handle(AIS_InteractiveContext)>
357             (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
358         }
359         myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
360       }
361       else if (aParserNumber == 1)
362       {
363         // Here is viewerName/viewName
364         if (!ViewerTest::GetAISContext().IsNull())
365           myDriverName = ViewerTest_myDrivers.Find2
366           (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
367         else
368         {
369           // There is no opened contexts here, need to create name for driver
370           myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
371             (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
372         }
373         myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
374
375         myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
376       }
377       else
378       {
379         //Here is driverName/viewerName/viewName
380         myDriverName = TCollection_AsciiString(aName);
381
382         TCollection_AsciiString aViewerName(theInputString);
383         aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
384         myViewerName = TCollection_AsciiString(aViewerName);
385
386         myViewName = TCollection_AsciiString(theInputString);
387       }
388     }
389   }
390 };
391
392 //==============================================================================
393 //function : FindContextByView
394 //purpose  : Find AIS_InteractiveContext by View
395 //==============================================================================
396
397 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
398 {
399   Handle(AIS_InteractiveContext) anAISContext;
400
401   for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
402        anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
403   {
404     if (anIter.Value()->CurrentViewer() == theView->Viewer())
405        return anIter.Key2();
406   }
407   return anAISContext;
408 }
409
410
411 //==============================================================================
412 //function : SetWindowTitle
413 //purpose  : Set window title
414 //==============================================================================
415
416 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
417                      Standard_CString theTitle)
418 {
419 #if defined(_WIN32)
420   SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
421     theTitle);
422 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
423   SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
424 #else
425   if(GetDisplayConnection()->GetDisplay())
426   {
427     Window aWindow =
428       Handle(Xw_Window)::DownCast(theWindow)->XWindow();
429     XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
430   }
431 #endif
432 }
433
434 //==============================================================================
435 //function : IsWindowOverlapped
436 //purpose  : Check if theWindow overlapp another view
437 //==============================================================================
438
439 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
440                                      const Standard_Integer thePxTop,
441                                      const Standard_Integer thePxRight,
442                                      const Standard_Integer thePxBottom,
443                                      TCollection_AsciiString& theViewId)
444 {
445   for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
446       anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
447   {
448     Standard_Integer aTop = 0,
449       aLeft = 0,
450       aRight = 0,
451       aBottom = 0;
452     anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
453     if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
454         (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
455         (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
456         (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
457     {
458       theViewId = anIter.Key1();
459       return Standard_True;
460     }
461   }
462   return Standard_False;
463 }
464
465 // Workaround: to create and delete non-orthographic views outside ViewerTest
466 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
467 {
468   ViewerTest_myViews.UnBind1 (theName);
469 }
470
471 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
472                                const Handle(V3d_View)& theView)
473 {
474   ViewerTest_myViews.Bind (theName, theView);
475 }
476
477 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
478 {
479   return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
480 }
481 //==============================================================================
482 //function : ViewerInit
483 //purpose  : Create the window viewer and initialize all the global variable
484 //==============================================================================
485
486 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
487                                                 const Standard_Integer thePxTop,
488                                                 const Standard_Integer thePxWidth,
489                                                 const Standard_Integer thePxHeight,
490                                                 Standard_CString theViewName,
491                                                 Standard_CString theDisplayName)
492 {
493   // Default position and dimension of the viewer window.
494   // Note that left top corner is set to be sufficiently small to have
495   // window fit in the small screens (actual for remote desktops, see #23003).
496   // The position corresponds to the window's client area, thus some
497   // gap is added for window frame to be visible.
498   Standard_Integer aPxLeft   = 20;
499   Standard_Integer aPxTop    = 40;
500   Standard_Integer aPxWidth  = 409;
501   Standard_Integer aPxHeight = 409;
502   Standard_Boolean toCreateViewer = Standard_False;
503
504   Handle(OpenGl_GraphicDriver) aGraphicDriver;
505   ViewerTest_Names aViewNames(theViewName);
506   if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
507     aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
508
509   if (thePxLeft != 0)
510     aPxLeft = thePxLeft;
511   if (thePxTop != 0)
512     aPxTop = thePxTop;
513   if (thePxWidth != 0)
514     aPxWidth = thePxWidth;
515   if (thePxHeight != 0)
516     aPxHeight = thePxHeight;
517
518   // Get graphic driver (create it or get from another view)
519   if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
520   {
521     // Get connection string
522   #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
523     TCollection_AsciiString aDisplayName(theDisplayName);
524     if (!aDisplayName.IsEmpty())
525       SetDisplayConnection (new Aspect_DisplayConnection ());
526     else
527       SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
528   #else
529     (void)theDisplayName; // avoid warning on unused argument
530     SetDisplayConnection (new Aspect_DisplayConnection ());
531   #endif
532     aGraphicDriver = new OpenGl_GraphicDriver();
533     aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
534     aGraphicDriver->Begin (GetDisplayConnection());
535     ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
536     toCreateViewer = Standard_True;
537   }
538   else
539   {
540     aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
541   }
542
543   //Dispose the window if input parameters are default
544   if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
545   {
546     Standard_Integer aTop = 0,
547                      aLeft = 0,
548                      aRight = 0,
549                      aBottom = 0,
550                      aScreenWidth = 0,
551                      aScreenHeight = 0;
552
553     // Get screen resolution
554 #if defined(_WIN32) || defined(__WIN32__)
555     RECT aWindowSize;
556     GetClientRect(GetDesktopWindow(), &aWindowSize);
557     aScreenHeight = aWindowSize.bottom;
558     aScreenWidth = aWindowSize.right;
559 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
560     GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
561 #else
562     Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
563     aScreenWidth = WidthOfScreen(aScreen);
564     aScreenHeight = HeightOfScreen(aScreen);
565 #endif
566
567     TCollection_AsciiString anOverlappedViewId("");
568
569     while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
570     {
571       ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
572
573       if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
574         && aRight + 2*aPxWidth + 40 > aScreenWidth)
575       {
576         if (aBottom + aPxHeight + 40 > aScreenHeight)
577         {
578           aPxLeft = 20;
579           aPxTop = 40;
580           break;
581         }
582         aPxLeft = 20;
583         aPxTop = aBottom + 40;
584       }
585       else
586         aPxLeft = aRight + 20;
587     }
588   }
589
590   // Get viewer name
591   TCollection_AsciiString aTitle("3D View - ");
592   aTitle = aTitle + aViewNames.GetViewName() + "(*)";
593
594   // Change name of current active window
595   if (!ViewerTest::CurrentView().IsNull())
596   {
597     TCollection_AsciiString aTitle("3D View - ");
598     aTitle = aTitle
599       + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
600     SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
601   }
602
603   // Create viewer
604   Handle(V3d_Viewer) a3DViewer;
605   // If it's the single view, we first look for empty context
606   if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
607   {
608     NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
609       anIter(ViewerTest_myContexts);
610     if (anIter.More())
611       ViewerTest::SetAISContext (anIter.Value());
612     a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
613   }
614   else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
615   {
616     ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
617     a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
618   }
619   else if (a3DViewer.IsNull())
620   {
621     toCreateViewer = Standard_True;
622     TCollection_ExtendedString NameOfWindow("Viewer3D");
623     a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
624
625     NameOfWindow = TCollection_ExtendedString("Collector");
626
627     a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
628   }
629
630   // AIS context setup
631   if (ViewerTest::GetAISContext().IsNull() ||
632       !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
633   {
634     Handle(AIS_InteractiveContext) aContext =
635       new AIS_InteractiveContext(a3DViewer);
636     ViewerTest::SetAISContext (aContext);
637     ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
638   }
639   else
640     ViewerTest::ResetEventManager();
641
642   // Create window
643 #if defined(_WIN32) || defined(__WIN32__)
644       VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
645                                        Handle(WNT_WClass)::DownCast (WClass()),
646                                        Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW,
647                                        aPxLeft, aPxTop,
648                                        aPxWidth, aPxHeight,
649                                        Quantity_NOC_BLACK);
650 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
651       VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
652                                          aPxLeft, aPxTop,
653                                          aPxWidth, aPxHeight);
654       ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
655 #else
656       VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
657                                       aTitle.ToCString(),
658                                       aPxLeft, aPxTop,
659                                       aPxWidth, aPxHeight);
660 #endif
661   VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
662
663   // NIS setup
664   Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
665
666   ViewerTest::CurrentView(aView);
667   ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
668   TheNISContext()->AttachView (aView);
669
670   // Setup for X11 or NT
671   OSWindowSetup();
672
673   // Set parameters for V3d_View and V3d_Viewer
674   const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
675   aV3dView->SetComputedMode(Standard_False);
676   MyHLRIsOn = aV3dView->ComputedMode();
677   aV3dView->SetZClippingDepth(0.5);
678   aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
679
680   a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
681   if (toCreateViewer)
682   {
683     a3DViewer->SetDefaultLights();
684     a3DViewer->SetLightOn();
685   }
686
687   #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
688   #if TCL_MAJOR_VERSION  < 8
689   Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
690       TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
691   #else
692   Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
693       TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
694   #endif
695   #endif
696
697   VT_GetWindow()->Map();
698
699   // Set the handle of created view in the event manager
700   ViewerTest::ResetEventManager();
701
702   ViewerTest::CurrentView()->Redraw();
703
704   aView.Nullify();
705   a3DViewer.Nullify();
706
707   return aViewNames.GetViewName();
708 }
709
710 //==============================================================================
711 //function : RedrawAllViews
712 //purpose  : Redraw all created views
713 //==============================================================================
714 void ViewerTest::RedrawAllViews()
715 {
716   NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
717   for (; aViewIt.More(); aViewIt.Next())
718   {
719     const Handle(V3d_View)& aView = aViewIt.Key2();
720     aView->Redraw();
721   }
722 }
723
724 //==============================================================================
725 //function : SplitParameter
726 //purpose  : Split parameter string to parameter name an patameter value
727 //==============================================================================
728 Standard_Boolean SplitParameter (const TCollection_AsciiString& theString,
729                                       TCollection_AsciiString& theName,
730                                       TCollection_AsciiString& theValue)
731 {
732   Standard_Integer aParamNameEnd = theString.FirstLocationInSet("=",1, theString.Length());
733   if (aParamNameEnd == 0)
734     return Standard_False;
735   TCollection_AsciiString aString(theString);
736   if (aParamNameEnd != 0)
737   {
738     theValue = aString.Split(aParamNameEnd);
739     aString.Split(aString.Length()-1);
740     theName = aString;
741   }
742   return Standard_True;
743 }
744
745 //==============================================================================
746 //function : Vinit
747 //purpose  : Create the window viewer and initialize all the global variable
748 //    Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
749 //==============================================================================
750
751 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
752 {
753 if (theArgsNb > 9)
754   {
755     theDi << theArgVec[0] << ": incorrect number of command arguments.\n"
756       << "Type help for more information.\n";
757     return 1;
758   }
759   TCollection_AsciiString aViewName (""),
760                           aDisplayName ("");
761   Standard_Integer aPxLeft = 0,
762                   aPxTop = 0,
763                   aPxWidth = 0,
764                   aPxHeight = 0;
765
766   for (Standard_Integer i = 1; i < theArgsNb; ++i)
767   {
768     TCollection_AsciiString aName = "", aValue = "";
769     if(!SplitParameter (TCollection_AsciiString(theArgVec[i]),aName,aValue) && theArgsNb == 2)
770     {
771       // In case of syntax: vinit ViewName
772       aViewName = theArgVec[1];
773     }
774     else
775     {
776       if (aName == "name")
777       {
778         aViewName = aValue;
779       }
780       else if (aName == "l" || aName == "left")
781         aPxLeft = aValue.IntegerValue();
782       else if (aName == "t" || aName == "top")
783         aPxTop = aValue.IntegerValue();
784 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
785       else if (aName == "display")
786         aDisplayName = aValue;
787 #endif
788       else if (aName == "w" || aName == "width")
789         aPxWidth = aValue.IntegerValue();
790       else if (aName == "h" || aName == "height")
791         aPxHeight = aValue.IntegerValue();
792       else
793       {
794         theDi << theArgVec[0] << ": Warning: unknown parameter " << aName.ToCString() << ".\n";
795       }
796     }
797   }
798
799   ViewerTest_Names aViewNames (aViewName);
800   if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
801   {
802     TCollection_AsciiString aCommand("vactivate ");
803     aCommand = aCommand + aViewNames.GetViewName();
804     theDi.Eval(aCommand.ToCString());
805     return 0;
806   }
807
808   TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
809                                                             aViewName.ToCString(),
810                                                             aDisplayName.ToCString());
811   cout << theArgVec[0] << ": 3D View - " << aViewId << " was created.\n";
812   return 0;
813 }
814
815 //==============================================================================
816 //function : VHLR
817 //purpose  : hidden lines removal algorithm
818 //==============================================================================
819
820 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
821 {
822   if (ViewerTest::CurrentView().IsNull())
823   {
824     di << argv[0] << ": Call vinit before this command, please.\n";
825     return 1;
826   }
827
828   if (argc != 2)
829   {
830     di << argv[0] << ": Wrong number of command arguments.\n"
831       << "Type help " << argv[0] << " for more information.\n";
832     return 1;
833   }
834
835   Standard_Boolean isHLROn =
836     (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
837
838   if (isHLROn == MyHLRIsOn)
839   {
840     return 0;
841   }
842
843   MyHLRIsOn = isHLROn;
844   ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
845
846   return 0;
847 }
848
849 //==============================================================================
850 //function : VHLRType
851 //purpose  : change type of using HLR algorithm
852 //==============================================================================
853
854 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
855 {
856   if (ViewerTest::CurrentView().IsNull())
857   {
858     di << argv[0] << ": Call vinit before this command, please.\n";
859     return 1;
860   }
861
862   if (argc < 2)
863   {
864     di << argv[0] << ": Wrong number of command arguments.\n"
865       << "Type help " << argv[0] << " for more information.\n";
866     return 1;
867   }
868
869   Prs3d_TypeOfHLR aTypeOfHLR =
870     (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
871
872   if (argc == 2)
873   {
874     AIS_ListOfInteractive aListOfShapes;
875     ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
876     ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
877     for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
878       anIter.More(); anIter.Next())
879     {
880       Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
881       if (aShape.IsNull())
882         continue;
883       if (aShape->TypeOfHLR() != aTypeOfHLR)
884         aShape->SetTypeOfHLR (aTypeOfHLR);
885       if (MyHLRIsOn)
886         aShape->Redisplay();
887     }
888     ViewerTest::CurrentView()->Update();
889     return 0;
890   }
891   else
892   {
893     for (Standard_Integer i = 2; i < argc; ++i)
894     {
895       ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
896       TCollection_AsciiString aName (argv[i]);
897
898       if (!aMap.IsBound2 (aName))
899       {
900         di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
901         continue;
902       }
903       Handle(AIS_Shape) anAISObject =
904         Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
905       if (anAISObject.IsNull())
906         continue;
907       anAISObject->SetTypeOfHLR (aTypeOfHLR);
908       if (MyHLRIsOn)
909         anAISObject->Redisplay();
910     }
911     ViewerTest::CurrentView()->Update();
912   }
913
914   return 0;
915 }
916
917 //==============================================================================
918 //function : FindViewIdByWindowHandle
919 //purpose  : Find theView Id in the map of views by window handle
920 //==============================================================================
921 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
922 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
923 {
924   for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
925        anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
926   {
927     Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
928     if (aWindowHandle == theWindowHandle)
929       return anIter.Key1();
930   }
931   return TCollection_AsciiString("");
932 }
933 #endif
934
935 //==============================================================================
936 //function : ActivateView
937 //purpose  : Make the view active
938 //==============================================================================
939
940 void ActivateView (const TCollection_AsciiString& theViewName)
941 {
942   const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
943   if (!aView.IsNull())
944   {
945     Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
946     if (!anAISContext.IsNull())
947     {
948       if (!ViewerTest::CurrentView().IsNull())
949       {
950         TCollection_AsciiString aTitle("3D View - ");
951         aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
952         SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
953       }
954
955       ViewerTest::CurrentView (aView);
956       // Update degenerate mode
957       MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
958       ViewerTest::SetAISContext (anAISContext);
959       TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
960       aTitle = aTitle + theViewName + "(*)";
961       SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
962 #if defined(_WIN32) || defined(__WIN32__)
963       VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
964 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
965       VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
966 #else
967       VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
968 #endif
969       SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
970       ViewerTest::CurrentView()->Redraw();
971     }
972   }
973 }
974
975 //==============================================================================
976 //function : RemoveView
977 //purpose  : Close and remove view from display, clear maps if neccessary
978 //==============================================================================
979 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
980 {
981   if (!ViewerTest_myViews.IsBound1(theViewName))
982   {
983     cout << "Wrong view name\n";
984     return;
985   }
986
987   // Activate another view if it's active now
988   if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
989   {
990     if (ViewerTest_myViews.Extent() > 1)
991     {
992       TCollection_AsciiString aNewViewName;
993       for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
994            anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
995         if (anIter.Key1() != theViewName)
996         {
997           aNewViewName = anIter.Key1();
998           break;
999         }
1000         ActivateView (aNewViewName);
1001     }
1002     else
1003     {
1004       Handle(V3d_View) anEmptyView;
1005 #if defined(_WIN32) || defined(__WIN32__)
1006       Handle(WNT_Window) anEmptyWindow;
1007 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1008       Handle(Cocoa_Window) anEmptyWindow;
1009 #else
1010       Handle(Xw_Window) anEmptyWindow;
1011 #endif
1012       VT_GetWindow() = anEmptyWindow;
1013       ViewerTest::CurrentView (anEmptyView);
1014       if (isContextRemoved)
1015       {
1016         Handle(AIS_InteractiveContext) anEmptyContext;
1017         ViewerTest::SetAISContext(anEmptyContext);
1018       }
1019     }
1020   }
1021
1022   // Delete view
1023   Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1024   Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1025
1026   // Remove view resources
1027   TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
1028   ViewerTest_myViews.UnBind1(theViewName);
1029   aView->Remove();
1030
1031 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1032   XFlush (GetDisplayConnection()->GetDisplay());
1033 #endif
1034
1035   // Keep context opened only if the closed view is last to avoid
1036   // unused empty contexts
1037   if (!aCurrentContext.IsNull())
1038   {
1039     // Check if there are more difined views in the viewer
1040     aCurrentContext->CurrentViewer()->InitDefinedViews();
1041     if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1042     {
1043       // Remove driver if there is no viewers that use it
1044       Standard_Boolean isRemoveDriver = Standard_True;
1045       for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1046           anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1047       {
1048         if (aCurrentContext != anIter.Key2() &&
1049           aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1050         {
1051           isRemoveDriver = Standard_False;
1052           break;
1053         }
1054       }
1055       if(isRemoveDriver)
1056       {
1057         ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1058       #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1059         #if TCL_MAJOR_VERSION  < 8
1060         Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1061         #else
1062         Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1063         #endif
1064       #endif
1065       }
1066
1067       ViewerTest_myContexts.UnBind2(aCurrentContext);
1068     }
1069   }
1070   cout << "3D View - " << theViewName << " was deleted.\n";
1071
1072 }
1073
1074 //==============================================================================
1075 //function : VClose
1076 //purpose  : Remove the view defined by its name
1077 //==============================================================================
1078
1079 static int VClose (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1080 {
1081   if (theArgsNb < 2)
1082   {
1083     theDi << theArgVec[0] << ": incorrect number of command arguments.\n"
1084       << "Type help " << theArgVec[0] << " for more information.\n";
1085     return 1;
1086   }
1087
1088   if (ViewerTest_myViews.IsEmpty())
1089   {
1090     theDi << theArgVec[0] <<": there is no views to close.\n";
1091     return 0;
1092   }
1093
1094   TCollection_AsciiString anInputString(theArgVec[1]);
1095
1096   // Create list to iterate and remove views from the map of views
1097   NCollection_List<TCollection_AsciiString> aViewList;
1098   if ( strcasecmp( anInputString.ToCString(), "ALL" ) == 0 )
1099   {
1100     for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter(ViewerTest_myViews);
1101          anIter.More(); anIter.Next())
1102     {
1103       aViewList.Append(anIter.Key1());
1104     }
1105   }
1106   else
1107   {
1108     ViewerTest_Names aViewNames(anInputString);
1109     aViewList.Append(aViewNames.GetViewName());
1110   }
1111
1112   Standard_Boolean isContextRemoved = (theArgsNb == 3 && atoi(theArgVec[2])==1) ? Standard_False : Standard_True;
1113   for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1114        anIter.More(); anIter.Next())
1115   {
1116     ViewerTest::RemoveView(anIter.Value(), isContextRemoved);
1117   }
1118
1119   return 0;
1120 }
1121
1122 //==============================================================================
1123 //function : VActivate
1124 //purpose  : Activate the view defined by its ID
1125 //==============================================================================
1126
1127 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1128 {
1129   if (theArgsNb > 2)
1130   {
1131     theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1132     << "Usage: " << theArgVec[0] << " ViewID\n";
1133     return 1;
1134   }
1135   if(theArgsNb == 1)
1136   {
1137     theDi.Eval("vviewlist");
1138     return 0;
1139   }
1140
1141   TCollection_AsciiString aNameString(theArgVec[1]);
1142   if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1143   {
1144     TCollection_AsciiString aTitle("3D View - ");
1145     aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1146     SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1147     Handle(V3d_View) anEmptyView;
1148 #if defined(_WIN32) || defined(__WIN32__)
1149     Handle(WNT_Window) anEmptyWindow;
1150 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1151     Handle(Cocoa_Window) anEmptyWindow;
1152 #else
1153     Handle(Xw_Window) anEmptyWindow;
1154 #endif
1155     VT_GetWindow() = anEmptyWindow;
1156     ViewerTest::CurrentView (anEmptyView);
1157     ViewerTest::ResetEventManager();
1158     theDi << theArgVec[0] << ": all views are inactive\n";
1159     return 0;
1160   }
1161
1162   ViewerTest_Names aViewNames(aNameString);
1163
1164   // Check if this view exists in the viewer with the driver
1165   if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1166   {
1167     theDi << "Wrong view name\n";
1168     return 1;
1169   }
1170
1171   // Check if it is active already
1172   if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1173   {
1174     theDi << theArgVec[0] << ": the view is active already\n";
1175     return 0;
1176   }
1177
1178   ActivateView (aViewNames.GetViewName());
1179   return 0;
1180 }
1181
1182 //==============================================================================
1183 //function : VViewList
1184 //purpose  : Print current list of views per viewer and graphic driver ID
1185 //           shared between viewers
1186 //==============================================================================
1187
1188 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1189 {
1190   if (theArgsNb > 2)
1191   {
1192     theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1193           << "Usage: " << theArgVec[0] << " name";
1194     return 1;
1195   }
1196   if (ViewerTest_myContexts.Size() < 1)
1197     return 0;
1198
1199   Standard_Boolean isTreeView =
1200     (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1201
1202   if (isTreeView)
1203     theDi << theArgVec[0] <<":\n";
1204
1205     for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1206       aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1207     {
1208       if (isTreeView)
1209         theDi << aDriverIter.Key1() << ":\n";
1210
1211       for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1212         aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1213       {
1214         if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1215         {
1216           if (isTreeView)
1217           {
1218             TCollection_AsciiString aContextName(aContextIter.Key1());
1219             theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1220           }
1221
1222           for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1223             aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1224           {
1225             if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1226             {
1227               TCollection_AsciiString aViewName(aViewIter.Key1());
1228               if (isTreeView)
1229               {
1230                 if (aViewIter.Value() == ViewerTest::CurrentView())
1231                   theDi << "  " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1232                 else
1233                   theDi << "  " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1234               }
1235               else
1236               {
1237                 theDi << aViewName << " ";
1238               }
1239             }
1240           }
1241         }
1242       }
1243     }
1244   return 0;
1245 }
1246
1247 //==============================================================================
1248 //function : VT_ProcessKeyPress
1249 //purpose  : Handle KeyPress event from a CString
1250 //==============================================================================
1251 void VT_ProcessKeyPress (const char* buf_ret)
1252 {
1253   //cout << "KeyPress" << endl;
1254   const Handle(V3d_View) aView = ViewerTest::CurrentView();
1255   const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1256   // Letter in alphabetic order
1257
1258   if ( !strcasecmp(buf_ret, "A") ) {
1259     // AXO
1260     aView->SetProj(V3d_XposYnegZpos);
1261   }
1262   else if ( !strcasecmp(buf_ret, "D") ) {
1263     // Reset
1264     aView->Reset();
1265   }
1266   else if ( !strcasecmp(buf_ret, "F") ) {
1267     // FitAll
1268     if (aNisView.IsNull())
1269       aView->FitAll();
1270     else
1271       aNisView->FitAll3d();
1272   }
1273   else if ( !strcasecmp(buf_ret, "H") ) {
1274     // HLR
1275     cout << "HLR" << endl;
1276     aView->SetComputedMode (!aView->ComputedMode());
1277     MyHLRIsOn = aView->ComputedMode();
1278   }
1279   else if ( !strcasecmp(buf_ret, "P") ) {
1280     // Type of HLR
1281     Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1282     if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1283       aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1284     else
1285       aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1286     if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1287     {
1288       AIS_ListOfInteractive aListOfShapes;
1289       aContext->DisplayedObjects(aListOfShapes);
1290       for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1291         anIter.More(); anIter.Next())
1292       {
1293         Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1294         if (aShape.IsNull())
1295           continue;
1296         if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1297           aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1298         else
1299           aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1300         aShape->Redisplay();
1301       }
1302     }
1303     else
1304     {
1305       for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1306       {
1307         Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1308         if (aShape.IsNull())
1309           continue;
1310         if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1311           aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1312         else
1313           aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1314         aShape->Redisplay();
1315       }
1316     }
1317
1318     aContext->UpdateCurrentViewer();
1319
1320   }
1321   else if ( !strcasecmp(buf_ret, "S") ) {
1322     // SHADING
1323     cout << "passage en mode 1 (shading pour les shapes)" << endl;
1324
1325     Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1326     if(Ctx->NbCurrents()==0 ||
1327       Ctx->NbSelected()==0)
1328       Ctx->SetDisplayMode(AIS_Shaded);
1329     else{
1330       if(Ctx->HasOpenedContext()){
1331         for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1332           Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1333       }
1334       else{
1335         for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1336           Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1337       }
1338       Ctx->UpdateCurrentViewer();
1339     }
1340   }
1341   else if ( !strcasecmp(buf_ret, "U") ) {
1342     // Unset display mode
1343     cout<<"passage au mode par defaut"<<endl;
1344
1345     Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1346     if(Ctx->NbCurrents()==0 ||
1347       Ctx->NbSelected()==0)
1348       Ctx->SetDisplayMode(AIS_WireFrame);
1349     else{
1350       if(Ctx->HasOpenedContext()){
1351         for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1352           Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1353       }
1354       else{
1355         for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1356           Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1357       }
1358       Ctx->UpdateCurrentViewer();
1359     }
1360
1361   }
1362   else if ( !strcasecmp(buf_ret, "T") ) {
1363     // Top
1364     aView->SetProj(V3d_Zpos);
1365   }
1366   else if ( !strcasecmp(buf_ret, "B") ) {
1367     // Bottom
1368     aView->SetProj(V3d_Zneg);
1369   }
1370   else if ( !strcasecmp(buf_ret, "L") ) {
1371     // Left
1372     aView->SetProj(V3d_Xneg);
1373   }
1374   else if ( !strcasecmp(buf_ret, "R") ) {
1375     // Right
1376     aView->SetProj(V3d_Xpos);
1377   }
1378
1379   else if ( !strcasecmp(buf_ret, "W") ) {
1380     // WIREFRAME
1381     cout << "passage en mode 0 (filaire pour les shapes)" << endl;
1382     Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1383     if(Ctx->NbCurrents()==0 ||
1384       Ctx->NbSelected()==0)
1385       Ctx->SetDisplayMode(AIS_WireFrame);
1386     else{
1387       if(Ctx->HasOpenedContext()){
1388         for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1389           Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1390       }
1391       else{
1392         for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1393           Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1394       }
1395       Ctx->UpdateCurrentViewer();
1396     }
1397   }
1398   else if ( !strcasecmp(buf_ret, "Z") ) {
1399     // ZCLIP
1400
1401     if ( ZClipIsOn ) {
1402       cout << "ZClipping OFF" << endl;
1403       ZClipIsOn = 0;
1404
1405       aView->SetZClippingType(V3d_OFF);
1406       aView->Redraw();
1407     }
1408     else {
1409       cout << "ZClipping ON" << endl;
1410       ZClipIsOn = 1;
1411
1412       aView->SetZClippingType(V3d_FRONT);
1413       aView->Redraw();
1414     }
1415   }
1416   else if ( !strcasecmp(buf_ret, ",") ) {
1417     ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1418
1419
1420   }
1421   else if ( !strcasecmp(buf_ret, ".") ) {
1422     ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1423   }
1424   // Number
1425   else{
1426     Standard_Integer Num = Draw::Atoi(buf_ret);
1427     if(Num>=0 && Num<=7)
1428       ViewerTest::StandardModeActivation(Num);
1429   }
1430 }
1431
1432 //==============================================================================
1433 //function : VT_ProcessExpose
1434 //purpose  : Redraw the View on an Expose Event
1435 //==============================================================================
1436 void VT_ProcessExpose()
1437 {
1438   Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1439   if (!aView3d.IsNull())
1440   {
1441     aView3d->Redraw();
1442   }
1443 }
1444
1445 //==============================================================================
1446 //function : VT_ProcessConfigure
1447 //purpose  : Resize the View on an Configure Event
1448 //==============================================================================
1449 void VT_ProcessConfigure()
1450 {
1451   Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1452   if (aView3d.IsNull())
1453   {
1454     return;
1455   }
1456
1457   aView3d->MustBeResized();
1458   aView3d->Update();
1459   aView3d->Redraw();
1460 }
1461
1462 //==============================================================================
1463 //function : VT_ProcessButton1Press
1464 //purpose  : Picking
1465 //==============================================================================
1466 Standard_Boolean VT_ProcessButton1Press(
1467   Standard_Integer ,
1468   const char**     argv,
1469   Standard_Boolean pick,
1470   Standard_Boolean shift)
1471 {
1472   Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1473   if ( pick ) {
1474     Standard_Real X, Y, Z;
1475
1476     ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
1477
1478     Draw::Set(argv[1], X);
1479     Draw::Set(argv[2], Y);
1480     Draw::Set(argv[3], Z);}
1481
1482   if(shift)
1483     EM->ShiftSelect();
1484   else
1485     EM->Select();
1486
1487   pick = 0;
1488   return pick;
1489 }
1490
1491 //==============================================================================
1492 //function : VT_ProcessButton1Release
1493 //purpose  : End selecting
1494 //==============================================================================
1495 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1496 {
1497   if (IsDragged)
1498   {
1499     IsDragged = Standard_False;
1500     Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1501     if (theIsShift)
1502     {
1503       EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1504                        Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1505     }
1506     else
1507     {
1508       EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1509                   Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1510     }
1511   }
1512 }
1513
1514 //==============================================================================
1515 //function : VT_ProcessButton3Press
1516 //purpose  : Start Rotation
1517 //==============================================================================
1518 void VT_ProcessButton3Press()
1519 {
1520   Start_Rot = 1;
1521   if (MyHLRIsOn)
1522   {
1523     ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1524   }
1525   ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1526 }
1527
1528 //==============================================================================
1529 //function : VT_ProcessButton3Release
1530 //purpose  : End rotation
1531 //==============================================================================
1532 void VT_ProcessButton3Release()
1533 {
1534   if (Start_Rot)
1535   {
1536     Start_Rot = 0;
1537     if (MyHLRIsOn)
1538     {
1539       ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1540     }
1541   }
1542 }
1543
1544 //==============================================================================
1545 //function : ProcessZClipMotion
1546 //purpose  : Zoom
1547 //==============================================================================
1548
1549 void ProcessZClipMotion()
1550 {
1551   Handle(V3d_View)  a3DView = ViewerTest::CurrentView();
1552   if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1553     static Standard_Real CurZPos = 0.;
1554
1555     //Quantity_Length VDX, VDY;
1556     //a3DView->Size(VDX,VDY);
1557     //Standard_Real VDZ = a3DView->ZSize();
1558     //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1559
1560     Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1561
1562     // Front = Depth + width/2.
1563     Standard_Real D = 0.5;
1564     Standard_Real W = 0.1;
1565
1566     CurZPos += (dx);
1567
1568     D += CurZPos;
1569
1570     //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1571
1572     a3DView->SetZClippingType(V3d_OFF);
1573     a3DView->SetZClippingDepth(D);
1574     a3DView->SetZClippingWidth(W);
1575     a3DView->SetZClippingType(V3d_FRONT);
1576
1577     a3DView->Redraw();
1578
1579     X_ButtonPress = X_Motion;
1580     Y_ButtonPress = Y_Motion;
1581   }
1582 }
1583
1584 //==============================================================================
1585 //function : ProcessControlButton1Motion
1586 //purpose  : Zoom
1587 //==============================================================================
1588
1589 static void ProcessControlButton1Motion()
1590 {
1591   ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1592
1593   X_ButtonPress = X_Motion;
1594   Y_ButtonPress = Y_Motion;
1595 }
1596
1597 //==============================================================================
1598 //function : VT_ProcessControlButton2Motion
1599 //purpose  : Panning
1600 //==============================================================================
1601 void VT_ProcessControlButton2Motion()
1602 {
1603   Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1604   Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
1605
1606   dy = -dy; // Xwindow Y axis is from top to Bottom
1607
1608   ViewerTest::CurrentView()->Panning( dx, dy );
1609
1610   X_ButtonPress = X_Motion;
1611   Y_ButtonPress = Y_Motion;
1612 }
1613
1614 //==============================================================================
1615 //function : VT_ProcessControlButton3Motion
1616 //purpose  : Rotation
1617 //==============================================================================
1618 void VT_ProcessControlButton3Motion()
1619 {
1620   if (Start_Rot)
1621   {
1622     ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1623   }
1624 }
1625
1626 //==============================================================================
1627 //function : VT_ProcessMotion
1628 //purpose  :
1629 //==============================================================================
1630 void VT_ProcessMotion()
1631 {
1632   //pre-hilights detected objects at mouse position
1633
1634   Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1635   EM->MoveTo(X_Motion, Y_Motion);
1636 }
1637
1638
1639 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1640 {
1641   Xpix = X_Motion;Ypix=Y_Motion;
1642 }
1643
1644 //==============================================================================
1645 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1646 //purpose  : Switches to an axonometric, top, left and other views
1647 //==============================================================================
1648
1649 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1650 {
1651   if ( ViewerTest::CurrentView().IsNull() )
1652   {
1653     di<<"Call vinit before this command, please"<<"\n";
1654     return 1;
1655   }
1656
1657   ViewerTest::CurrentView()->SetProj(ori);
1658   return 0;
1659 }
1660
1661 //==============================================================================
1662 //function : VAxo
1663 //purpose  : Switch to an Axonometric view
1664 //Draw arg : No args
1665 //==============================================================================
1666
1667 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1668 {
1669   return ViewProject(di, V3d_XposYnegZpos);
1670 }
1671
1672 //==============================================================================
1673 //function : VTop
1674 //purpose  : Switch to a Top View
1675 //Draw arg : No args
1676 //==============================================================================
1677
1678 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1679 {
1680   return ViewProject(di, V3d_Zpos);
1681 }
1682
1683 //==============================================================================
1684 //function : VBottom
1685 //purpose  : Switch to a Bottom View
1686 //Draw arg : No args
1687 //==============================================================================
1688
1689 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1690 {
1691   return ViewProject(di, V3d_Zneg);
1692 }
1693
1694 //==============================================================================
1695 //function : VLeft
1696 //purpose  : Switch to a Left View
1697 //Draw arg : No args
1698 //==============================================================================
1699
1700 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1701 {
1702   return ViewProject(di, V3d_Ypos);
1703 }
1704
1705 //==============================================================================
1706 //function : VRight
1707 //purpose  : Switch to a Right View
1708 //Draw arg : No args
1709 //==============================================================================
1710
1711 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1712 {
1713   return ViewProject(di, V3d_Yneg);
1714 }
1715
1716 //==============================================================================
1717 //function : VFront
1718 //purpose  : Switch to a Front View
1719 //Draw arg : No args
1720 //==============================================================================
1721
1722 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1723 {
1724   return ViewProject(di, V3d_Xpos);
1725 }
1726
1727 //==============================================================================
1728 //function : VBack
1729 //purpose  : Switch to a Back View
1730 //Draw arg : No args
1731 //==============================================================================
1732
1733 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1734 {
1735   return ViewProject(di, V3d_Xneg);
1736 }
1737
1738 //==============================================================================
1739 //function : VHelp
1740 //purpose  : Dsiplay help on viewer Keyboead and mouse commands
1741 //Draw arg : No args
1742 //==============================================================================
1743
1744 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1745 {
1746
1747   di << "Q : Quit the application" << "\n";
1748
1749   di << "========================="<<"\n";
1750   di << "F : FitAll" << "\n";
1751   di << "T : TopView" << "\n";
1752   di << "B : BottomView" << "\n";
1753   di << "R : RightView" << "\n";
1754   di << "L : LeftView" << "\n";
1755   di << "A : AxonometricView" << "\n";
1756   di << "D : ResetView" << "\n";
1757
1758   di << "========================="<<"\n";
1759   di << "S : Shading" << "\n";
1760   di << "W : Wireframe" << "\n";
1761   di << "H : HidelLineRemoval" << "\n";
1762   di << "U : Unset display mode" << "\n";
1763
1764   di << "========================="<<"\n";
1765   di << "Selection mode "<<"\n";
1766   di << "0 : Shape" <<"\n";
1767   di << "1 : Vertex" <<"\n";
1768   di << "2 : Edge" <<"\n";
1769   di << "3 : Wire" <<"\n";
1770   di << "4 : Face" <<"\n";
1771   di << "5 : Shell" <<"\n";
1772   di << "6 : Solid" <<"\n";
1773   di << "7 : Compound" <<"\n";
1774
1775   di << "========================="<<"\n";
1776   di << "Z : Switch Z clipping On/Off" << "\n";
1777   di << ", : Hilight next detected" << "\n";
1778   di << ". : Hilight previous detected" << "\n";
1779
1780   return 0;
1781 }
1782
1783 #ifdef WNT
1784
1785 static Standard_Boolean Ppick = 0;
1786 static Standard_Integer Pargc = 0;
1787 static const char**           Pargv = NULL;
1788
1789
1790 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1791                                           UINT Msg,
1792                                           WPARAM wParam,
1793                                           LPARAM lParam )
1794 {
1795   if (!ViewerTest_myViews.IsEmpty()) {
1796
1797     WPARAM fwKeys = wParam;
1798
1799     switch( Msg ) {
1800     case WM_CLOSE:
1801        {
1802          // Delete view from map of views
1803          ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1804          return 0;
1805        }
1806        break;
1807     case WM_ACTIVATE:
1808       if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1809         || ViewerTest::CurrentView().IsNull())
1810       {
1811         // Activate inactive window
1812         if(GetWindowHandle(VT_GetWindow()) != hwnd)
1813         {
1814           ActivateView (FindViewIdByWindowHandle(hwnd));
1815         }
1816       }
1817       break;
1818     case WM_LBUTTONUP:
1819       IsDragged = Standard_False;
1820       if( !DragFirst )
1821       {
1822         HDC hdc = GetDC( hwnd );
1823         SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1824         SetROP2( hdc, R2_NOT );
1825         Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1826         ReleaseDC( hwnd, hdc );
1827
1828         const Handle(ViewerTest_EventManager) EM =
1829           ViewerTest::CurrentEventManager();
1830         if ( fwKeys & MK_SHIFT )
1831           EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1832           max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1833         else
1834           EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1835           max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1836       }
1837       return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1838
1839     case WM_LBUTTONDOWN:
1840       if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1841       {
1842         IsDragged = Standard_True;
1843         DragFirst = Standard_True;
1844         X_ButtonPress = LOWORD(lParam);
1845         Y_ButtonPress = HIWORD(lParam);
1846       }
1847       return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1848
1849       break;
1850
1851     case WM_MOUSEMOVE:
1852       if( IsDragged )
1853       {
1854         HDC hdc = GetDC( hwnd );
1855
1856         HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1857         SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1858         SetROP2( hdc, R2_NOT );
1859
1860         if( !DragFirst )
1861           Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1862
1863         DragFirst = Standard_False;
1864         X_Motion = LOWORD(lParam);
1865         Y_Motion = HIWORD(lParam);
1866
1867         Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1868
1869         SelectObject( hdc, anObj );
1870
1871         ReleaseDC( hwnd, hdc );
1872       }
1873       else
1874         return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1875       break;
1876
1877     default:
1878       return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1879     }
1880     return 0;
1881   }
1882   return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1883 }
1884
1885
1886 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1887                                        UINT Msg,
1888                                        WPARAM wParam,
1889                                        LPARAM lParam )
1890 {
1891   static int Up = 1;
1892
1893   if ( !ViewerTest::CurrentView().IsNull() ) {
1894     PAINTSTRUCT    ps;
1895
1896     switch( Msg ) {
1897     case WM_PAINT:
1898       BeginPaint(hwnd, &ps);
1899       EndPaint(hwnd, &ps);
1900       VT_ProcessExpose();
1901       break;
1902
1903     case WM_SIZE:
1904       VT_ProcessConfigure();
1905       break;
1906
1907     case WM_KEYDOWN:
1908       if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
1909       {
1910         char c[2];
1911         c[0] = (char) wParam;
1912         c[1] = '\0';
1913         VT_ProcessKeyPress (c);
1914       }
1915       break;
1916
1917     case WM_LBUTTONUP:
1918     case WM_MBUTTONUP:
1919     case WM_RBUTTONUP:
1920       Up = 1;
1921       VT_ProcessButton3Release();
1922       break;
1923
1924     case WM_LBUTTONDOWN:
1925     case WM_MBUTTONDOWN:
1926     case WM_RBUTTONDOWN:
1927       {
1928         WPARAM fwKeys = wParam;
1929
1930         Up = 0;
1931
1932         X_ButtonPress = LOWORD(lParam);
1933         Y_ButtonPress = HIWORD(lParam);
1934
1935         if (Msg == WM_LBUTTONDOWN)
1936         {
1937           if (fwKeys & MK_CONTROL)
1938           {
1939             Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1940           }
1941           else
1942           {
1943             VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1944           }
1945         }
1946         else if (Msg == WM_RBUTTONDOWN)
1947         {
1948           // Start rotation
1949           VT_ProcessButton3Press();
1950         }
1951       }
1952       break;
1953
1954     case WM_MOUSEMOVE:
1955       {
1956         //cout << "\t WM_MOUSEMOVE" << endl;
1957         WPARAM fwKeys = wParam;
1958         X_Motion = LOWORD(lParam);
1959         Y_Motion = HIWORD(lParam);
1960
1961         if ( Up &&
1962           fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
1963             Up = 0;
1964             X_ButtonPress = LOWORD(lParam);
1965             Y_ButtonPress = HIWORD(lParam);
1966
1967             if ( fwKeys & MK_RBUTTON ) {
1968               // Start rotation
1969               VT_ProcessButton3Press();
1970             }
1971           }
1972
1973           if ( fwKeys & MK_CONTROL ) {
1974             if ( fwKeys & MK_LBUTTON ) {
1975               ProcessControlButton1Motion();
1976             }
1977             else if ( fwKeys & MK_MBUTTON ||
1978               ((fwKeys&MK_LBUTTON) &&
1979               (fwKeys&MK_RBUTTON) ) ){
1980                 VT_ProcessControlButton2Motion();
1981               }
1982             else if ( fwKeys & MK_RBUTTON ) {
1983               VT_ProcessControlButton3Motion();
1984             }
1985           }
1986 #ifdef BUG
1987           else if ( fwKeys & MK_SHIFT ) {
1988             if ( fwKeys & MK_MBUTTON ||
1989               ((fwKeys&MK_LBUTTON) &&
1990               (fwKeys&MK_RBUTTON) ) ) {
1991                 cout << "ProcessZClipMotion()" << endl;
1992                 ProcessZClipMotion();
1993               }
1994           }
1995 #endif
1996           else if (GetWindowHandle (VT_GetWindow()) == hwnd)
1997           {
1998             if ((fwKeys & MK_MBUTTON
1999             || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2000             {
2001               ProcessZClipMotion();
2002             }
2003             else
2004             {
2005               VT_ProcessMotion();
2006             }
2007           }
2008       }
2009       break;
2010
2011     default:
2012       return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2013     }
2014     return 0L;
2015   }
2016
2017   return DefWindowProc( hwnd, Msg, wParam, lParam );
2018 }
2019
2020
2021
2022
2023 //==============================================================================
2024 //function : ViewerMainLoop
2025 //purpose  : Get a Event on the view and dispatch it
2026 //==============================================================================
2027
2028
2029 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2030 {
2031   Ppick = (argc > 0)? 1 : 0;
2032   Pargc = argc;
2033   Pargv = argv;
2034
2035   if ( Ppick ) {
2036     MSG msg;
2037     msg.wParam = 1;
2038
2039     cout << "Start picking" << endl;
2040
2041     while ( Ppick == 1 ) {
2042       // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2043       if (GetMessage(&msg, NULL, 0, 0) ) {
2044         TranslateMessage(&msg);
2045         DispatchMessage(&msg);
2046       }
2047     }
2048
2049     cout << "Picking done" << endl;
2050   }
2051
2052   return Ppick;
2053 }
2054
2055 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2056
2057 int min( int a, int b )
2058 {
2059   if( a<b )
2060     return a;
2061   else
2062     return b;
2063 }
2064
2065 int max( int a, int b )
2066 {
2067   if( a>b )
2068     return a;
2069   else
2070     return b;
2071 }
2072
2073 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2074
2075 {
2076   static XEvent aReport;
2077   Standard_Boolean pick = argc > 0;
2078   Display *aDisplay = GetDisplayConnection()->GetDisplay();
2079   XNextEvent (aDisplay, &aReport);
2080
2081   // Handle event for the chosen display connection
2082   switch (aReport.type) {
2083       case ClientMessage:
2084         {
2085           if(aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2086           {
2087             // Close the window
2088             ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2089           }
2090         }
2091         return 0;
2092      case FocusIn:
2093       {
2094          // Activate inactive view
2095          Window aWindow = GetWindowHandle(VT_GetWindow());
2096          if(aWindow != aReport.xfocus.window)
2097          {
2098            ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2099          }
2100       }
2101       break;
2102       case Expose:
2103         {
2104           VT_ProcessExpose();
2105         }
2106         break;
2107       case ConfigureNotify:
2108         {
2109           VT_ProcessConfigure();
2110         }
2111         break;
2112       case KeyPress:
2113         {
2114
2115           KeySym ks_ret ;
2116           char buf_ret[11] ;
2117           int ret_len ;
2118           XComposeStatus status_in_out;
2119
2120           ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2121             (char *) buf_ret , 10 ,
2122             &ks_ret , &status_in_out ) ;
2123
2124
2125           buf_ret[ret_len] = '\0' ;
2126
2127           if (ret_len)
2128           {
2129             VT_ProcessKeyPress (buf_ret);
2130           }
2131         }
2132         break;
2133       case ButtonPress:
2134         {
2135           X_ButtonPress = aReport.xbutton.x;
2136           Y_ButtonPress = aReport.xbutton.y;
2137
2138           if (aReport.xbutton.button == Button1)
2139           {
2140             if (aReport.xbutton.state & ControlMask)
2141             {
2142               pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2143             }
2144             else
2145             {
2146               IsDragged = Standard_True;
2147               DragFirst = Standard_True;
2148             }
2149           }
2150           else if (aReport.xbutton.button == Button3)
2151           {
2152             // Start rotation
2153             VT_ProcessButton3Press();
2154           }
2155         }
2156         break;
2157       case ButtonRelease:
2158         {
2159           if( IsDragged )
2160           {
2161             if( !DragFirst )
2162             {
2163               Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2164               GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2165               XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2166             }
2167
2168             Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2169             if( aContext.IsNull() )
2170             {
2171               cout << "The context is null. Please use vinit before createmesh" << endl;
2172               return 0;
2173             }
2174
2175             Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2176             if( aReport.xbutton.button==1 )
2177               if( DragFirst )
2178                 if( ShiftPressed )
2179                 {
2180                   aContext->ShiftSelect();
2181                 }
2182                 else
2183                 {
2184                   aContext->Select();
2185                 }
2186               else
2187                 if( ShiftPressed )
2188                 {
2189                   aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2190                     max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2191                     ViewerTest::CurrentView());
2192                 }
2193                 else
2194                 {
2195                   aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2196                     max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2197                     ViewerTest::CurrentView() );
2198                 }
2199             else
2200               VT_ProcessButton3Release();
2201
2202             IsDragged = Standard_False;
2203           }
2204           else
2205             VT_ProcessButton3Release();
2206         }
2207         break;
2208       case MotionNotify:
2209         {
2210           if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2211           {
2212             break;
2213           }
2214           if( IsDragged )
2215           {
2216             Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2217             GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2218             XSetFunction( aDisplay, gc, GXinvert );
2219
2220             if( !DragFirst )
2221               XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2222
2223             X_Motion = aReport.xmotion.x;
2224             Y_Motion = aReport.xmotion.y;
2225             DragFirst = Standard_False;
2226
2227             XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2228           }
2229           else
2230           {
2231             X_Motion = aReport.xmotion.x;
2232             Y_Motion = aReport.xmotion.y;
2233
2234             // remove all the ButtonMotionMaskr
2235             while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2236
2237             if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2238               if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2239
2240                 Quantity_Length VDX, VDY;
2241
2242                 ViewerTest::CurrentView()->Size(VDX,VDY);
2243                 Standard_Real VDZ =0 ;
2244                 VDZ = ViewerTest::CurrentView()->ZSize();
2245
2246                 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2247
2248                 Quantity_Length dx = 0 ;
2249                 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2250
2251                 cout << dx << endl;
2252
2253                 dx = dx / VDX * VDZ;
2254
2255                 cout << dx << endl;
2256
2257                 ViewerTest::CurrentView()->Redraw();
2258               }
2259             }
2260
2261             if ( aReport.xmotion.state & ControlMask ) {
2262               if ( aReport.xmotion.state & Button1Mask ) {
2263                 ProcessControlButton1Motion();
2264               }
2265               else if ( aReport.xmotion.state & Button2Mask ) {
2266                 VT_ProcessControlButton2Motion();
2267               }
2268               else if ( aReport.xmotion.state & Button3Mask ) {
2269                 VT_ProcessControlButton3Motion();
2270               }
2271             }
2272             else
2273             {
2274               VT_ProcessMotion();
2275             }
2276           }
2277         }
2278         break;
2279 }
2280 return pick;
2281 }
2282
2283 //==============================================================================
2284 //function : VProcessEvents
2285 //purpose  : call by Tk_CreateFileHandler() to be able to manage the
2286 //       event in the Viewer window
2287 //==============================================================================
2288
2289 static void VProcessEvents(ClientData,int)
2290 {
2291   NCollection_Vector<int> anEventNumbers;
2292   // Get number of messages from every display
2293   for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2294        anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2295   {
2296     anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2297   }
2298     // Handle events for every display
2299   int anEventIter = 0;
2300   for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2301        anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2302   {
2303     for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2304          XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2305     {
2306       SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2307       int anEventResult = ViewerMainLoop( 0, NULL);
2308       // If window is closed or context was not found finish current event processing loop
2309       if (!anEventResult)
2310         return;
2311     }
2312   }
2313
2314   SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2315
2316 }
2317 #endif
2318
2319 //==============================================================================
2320 //function : OSWindowSetup
2321 //purpose  : Setup for the X11 window to be able to cath the event
2322 //==============================================================================
2323
2324
2325 static void OSWindowSetup()
2326 {
2327 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2328   // X11
2329
2330   Window  window   = VT_GetWindow()->XWindow();
2331   SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2332   Display *aDisplay = GetDisplayConnection()->GetDisplay();
2333   XSynchronize(aDisplay, 1);
2334
2335   // X11 : For keyboard on SUN
2336   XWMHints wmhints;
2337   wmhints.flags = InputHint;
2338   wmhints.input = 1;
2339
2340   XSetWMHints( aDisplay, window, &wmhints);
2341
2342   XSelectInput( aDisplay, window,  ExposureMask | KeyPressMask |
2343     ButtonPressMask | ButtonReleaseMask |
2344     StructureNotifyMask |
2345     PointerMotionMask |
2346     Button1MotionMask | Button2MotionMask |
2347     Button3MotionMask | FocusChangeMask
2348     );
2349   Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2350   XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2351
2352   XSynchronize(aDisplay, 0);
2353
2354 #else
2355   // WNT
2356 #endif
2357
2358 }
2359
2360
2361 //==============================================================================
2362 //function : VFit
2363
2364 //purpose  : Fitall, no DRAW arguments
2365 //Draw arg : No args
2366 //==============================================================================
2367
2368 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2369 {
2370   const Handle(V3d_View) aView = ViewerTest::CurrentView();
2371   Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2372   if (V.IsNull() == Standard_False) {
2373     V->FitAll3d();
2374   } else if (aView.IsNull() == Standard_False) {
2375     aView->FitAll();
2376   }
2377   return 0;
2378 }
2379
2380 //==============================================================================
2381 //function : VZFit
2382 //purpose  : ZFitall, no DRAW arguments
2383 //Draw arg : No args
2384 //==============================================================================
2385
2386 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
2387 {
2388   Handle(V3d_View) V = ViewerTest::CurrentView();
2389   if ( !V.IsNull() ) V->ZFitAll(); return 0; }
2390
2391
2392 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
2393 {
2394   Handle(V3d_View) V = ViewerTest::CurrentView();
2395   if ( !V.IsNull() ) V->Redraw(); return 0;
2396 }
2397
2398
2399 //==============================================================================
2400 //function : VClear
2401 //purpose  : Remove all the object from the viewer
2402 //Draw arg : No args
2403 //==============================================================================
2404
2405 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2406 {
2407   Handle(V3d_View) V = ViewerTest::CurrentView();
2408   if(!V.IsNull())
2409     ViewerTest::Clear();
2410   return 0;
2411 }
2412
2413 //==============================================================================
2414 //function : VPick
2415 //purpose  :
2416 //==============================================================================
2417
2418 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2419 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2420
2421 if ( argc < 4 ) {
2422   di << argv[0] << "Invalid number of arguments" << "\n";
2423   return 1;
2424 }
2425
2426 while (ViewerMainLoop( argc, argv)) {
2427 }
2428
2429 return 0;
2430 }
2431
2432 //==============================================================================
2433 //function : InitViewerTest
2434 //purpose  : initialisation de toutes les variables static de  ViewerTest (dp)
2435 //==============================================================================
2436
2437 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& theContext)
2438 {
2439   Handle(V3d_Viewer) aViewer = theContext->CurrentViewer();
2440   ViewerTest::SetAISContext(theContext);
2441   aViewer->InitActiveViews();
2442   Handle(V3d_View) aView = aViewer->ActiveView();
2443   if (aViewer->MoreActiveViews()) ViewerTest::CurrentView(aView);
2444   ViewerTest::ResetEventManager();
2445   Handle(Aspect_Window) aWindow = aView->Window();
2446 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2447   // X11
2448   VT_GetWindow() = Handle(Xw_Window)::DownCast(aWindow);
2449   OSWindowSetup();
2450   static int aFirst = 1;
2451   if ( aFirst ) {
2452 #if TCL_MAJOR_VERSION  < 8
2453     Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2454       TK_READABLE, VProcessEvents, (ClientData) 0);
2455 #else
2456     Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
2457       TK_READABLE, VProcessEvents, (ClientData) 0);
2458 #endif
2459     aFirst = 0;
2460   }
2461 #endif
2462 }
2463
2464 //==============================================================================
2465 //function : VSetBg
2466 //purpose  : Load image as background
2467 //==============================================================================
2468
2469 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2470 {
2471   if (argc < 2 || argc > 3)
2472   {
2473     di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2474     di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2475     return 1;
2476   }
2477
2478   Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2479   if(AISContext.IsNull())
2480   {
2481     di << "use 'vinit' command before " << argv[0] << "\n";
2482     return 1;
2483   }
2484
2485   Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2486   if (argc == 3)
2487   {
2488     const char* szType = argv[2];
2489     if      (strcmp(szType, "NONE"    ) == 0) aFillType = Aspect_FM_NONE;
2490     else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2491     else if (strcmp(szType, "TILED"   ) == 0) aFillType = Aspect_FM_TILED;
2492     else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2493     else
2494     {
2495       di << "Wrong fill type : " << szType << "\n";
2496       di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2497       return 1;
2498     }
2499   }
2500
2501   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2502   V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2503
2504   return 0;
2505 }
2506
2507 //==============================================================================
2508 //function : VSetBgMode
2509 //purpose  : Change background image fill type
2510 //==============================================================================
2511
2512 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2513 {
2514   if (argc != 2)
2515   {
2516     di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2517     di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2518     return 1;
2519   }
2520
2521   Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2522   if(AISContext.IsNull())
2523   {
2524     di << "use 'vinit' command before " << argv[0] << "\n";
2525     return 1;
2526   }
2527   Aspect_FillMethod aFillType = Aspect_FM_NONE;
2528   const char* szType = argv[1];
2529   if      (strcmp(szType, "NONE"    ) == 0) aFillType = Aspect_FM_NONE;
2530   else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2531   else if (strcmp(szType, "TILED"   ) == 0) aFillType = Aspect_FM_TILED;
2532   else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2533   else
2534   {
2535     di << "Wrong fill type : " << szType << "\n";
2536     di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2537     return 1;
2538   }
2539   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2540   V3dView->SetBgImageStyle(aFillType, Standard_True);
2541   return 0;
2542 }
2543
2544 //==============================================================================
2545 //function : VSetGradientBg
2546 //purpose  : Mount gradient background
2547 //==============================================================================
2548 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2549 {
2550   if (argc != 8 )
2551   {
2552     di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2553     di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2554     di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2555     di << "                    5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2556     return 1;
2557   }
2558
2559   Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2560   if(AISContext.IsNull())
2561   {
2562     di << "use 'vinit' command before " << argv[0] << "\n";
2563     return 1;
2564   }
2565   if (argc == 8)
2566   {
2567
2568     Standard_Real R1 = Draw::Atof(argv[1])/255.;
2569     Standard_Real G1 = Draw::Atof(argv[2])/255.;
2570     Standard_Real B1 = Draw::Atof(argv[3])/255.;
2571     Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2572
2573     Standard_Real R2 = Draw::Atof(argv[4])/255.;
2574     Standard_Real G2 = Draw::Atof(argv[5])/255.;
2575     Standard_Real B2 = Draw::Atof(argv[6])/255.;
2576
2577     Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2578     int aType = Draw::Atoi(argv[7]);
2579     if( aType < 0 || aType > 8 )
2580     {
2581       di << "Wrong fill type " << "\n";
2582       di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2583       di << "               5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2584       return 1;
2585     }
2586
2587     Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2588
2589     Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2590     V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2591   }
2592
2593   return 0;
2594 }
2595
2596 //==============================================================================
2597 //function : VSetGradientBgMode
2598 //purpose  : Change gradient background fill style
2599 //==============================================================================
2600 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2601 {
2602   if (argc != 2 )
2603   {
2604     di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2605     di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2606     di << "                    5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2607     return 1;
2608   }
2609
2610   Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2611   if(AISContext.IsNull())
2612   {
2613     di << "use 'vinit' command before " << argv[0] << "\n";
2614     return 1;
2615   }
2616   if (argc == 2)
2617   {
2618     int aType = Draw::Atoi(argv[1]);
2619     if( aType < 0 || aType > 8 )
2620     {
2621       di << "Wrong fill type " << "\n";
2622       di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2623       di << "               5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2624       return 1;
2625     }
2626
2627     Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2628
2629     Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2630     V3dView->SetBgGradientStyle( aMethod, 1 );
2631   }
2632
2633   return 0;
2634 }
2635
2636 //==============================================================================
2637 //function : VSetColorBg
2638 //purpose  : Set color background
2639 //==============================================================================
2640 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2641 {
2642   if (argc != 4 )
2643   {
2644     di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2645     di << "R,G,B = [0..255]" << "\n";
2646     return 1;
2647   }
2648
2649   Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2650   if(AISContext.IsNull())
2651   {
2652     di << "use 'vinit' command before " << argv[0] << "\n";
2653     return 1;
2654   }
2655   if (argc == 4)
2656   {
2657
2658     Standard_Real R = Draw::Atof(argv[1])/255.;
2659     Standard_Real G = Draw::Atof(argv[2])/255.;
2660     Standard_Real B = Draw::Atof(argv[3])/255.;
2661     Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2662
2663     Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2664     V3dView->SetBackgroundColor( aColor );
2665     V3dView->Update();
2666   }
2667
2668   return 0;
2669 }
2670
2671 //==============================================================================
2672 //function : VScale
2673 //purpose  : View Scaling
2674 //==============================================================================
2675
2676 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2677 {
2678   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2679   if ( V3dView.IsNull() ) return 1;
2680
2681   if ( argc != 4 ) {
2682     di << argv[0] << "Invalid number of arguments" << "\n";
2683     return 1;
2684   }
2685   V3dView->SetAxialScale( Draw::Atof(argv[1]),  Draw::Atof(argv[2]),  Draw::Atof(argv[3]) );
2686   return 0;
2687 }
2688 //==============================================================================
2689 //function : VTestZBuffTrihedron
2690 //purpose  : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
2691 //==============================================================================
2692
2693 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2694 {
2695   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2696   if ( V3dView.IsNull() ) return 1;
2697
2698   V3dView->ZBufferTriedronSetup();
2699
2700   if ( argc == 1 ) {
2701     // Set up default trihedron parameters
2702     V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
2703   } else
2704   if ( argc == 7 )
2705   {
2706     Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2707     const char* aPosType = argv[1];
2708
2709     if ( strcmp(aPosType, "center") == 0 )
2710     {
2711       aPosition = Aspect_TOTP_CENTER;
2712     } else
2713     if (strcmp(aPosType, "left_lower") == 0)
2714     {
2715       aPosition = Aspect_TOTP_LEFT_LOWER;
2716     } else
2717     if (strcmp(aPosType, "left_upper") == 0)
2718     {
2719       aPosition = Aspect_TOTP_LEFT_UPPER;
2720     } else
2721     if (strcmp(aPosType, "right_lower") == 0)
2722     {
2723       aPosition = Aspect_TOTP_RIGHT_LOWER;
2724     } else
2725     if (strcmp(aPosType, "right_upper") == 0)
2726     {
2727       aPosition = Aspect_TOTP_RIGHT_UPPER;
2728     } else
2729     {
2730       di << argv[1] << " Invalid type of alignment"  << "\n";
2731       di << "Must be one of [ center, left_lower,"   << "\n";
2732       di << "left_upper, right_lower, right_upper ]" << "\n";
2733       return 1;
2734     }
2735
2736     Standard_Real R = Draw::Atof(argv[2])/255.;
2737     Standard_Real G = Draw::Atof(argv[3])/255.;
2738     Standard_Real B = Draw::Atof(argv[4])/255.;
2739     Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
2740
2741     Standard_Real aScale = Draw::Atof(argv[5]);
2742
2743     if( aScale <= 0.0 )
2744     {
2745       di << argv[5] << " Invalid value. Must be > 0" << "\n";
2746       return 1;
2747     }
2748
2749     V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
2750     const char* aPresType = argv[6];
2751
2752     if ( strcmp(aPresType, "wireframe") == 0 )
2753     {
2754       aPresentation = V3d_WIREFRAME;
2755     } else
2756     if (strcmp(aPresType, "zbuffer") == 0)
2757     {
2758       aPresentation = V3d_ZBUFFER;
2759     } else
2760     {
2761       di << argv[6] << " Invalid type of visualization" << "\n";
2762       di << "Must be one of [ wireframe, zbuffer ]"     << "\n";
2763       return 1;
2764     }
2765
2766     V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
2767
2768   } else
2769   {
2770     di << argv[0] << " Invalid number of arguments" << "\n";
2771     return 1;
2772   }
2773
2774   V3dView->ZFitAll();
2775
2776   return 0;
2777 }
2778
2779 //==============================================================================
2780 //function : VRotate
2781 //purpose  : Camera Rotating
2782 //==============================================================================
2783
2784 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2785   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2786   if ( V3dView.IsNull() ) {
2787     return 1;
2788   }
2789
2790   if ( argc == 4 ) {
2791     V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2792     return 0;
2793   } else if ( argc == 7 ) {
2794     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]) );
2795     return 0;
2796   } else {
2797     di << argv[0] << " Invalid number of arguments" << "\n";
2798     return 1;
2799   }
2800 }
2801
2802 //==============================================================================
2803 //function : VZoom
2804 //purpose  : View zoom in / out (relative to current zoom)
2805 //==============================================================================
2806
2807 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2808   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2809   if ( V3dView.IsNull() ) {
2810     return 1;
2811   }
2812
2813   if ( argc == 2 ) {
2814     Standard_Real coef = Draw::Atof(argv[1]);
2815     if ( coef <= 0.0 ) {
2816       di << argv[1] << "Invalid value" << "\n";
2817       return 1;
2818     }
2819     V3dView->SetZoom( Draw::Atof(argv[1]) );
2820     return 0;
2821   } else {
2822     di << argv[0] << " Invalid number of arguments" << "\n";
2823     return 1;
2824   }
2825 }
2826
2827 //==============================================================================
2828 //function : VPan
2829 //purpose  : View panning (in pixels)
2830 //==============================================================================
2831
2832 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2833   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2834   if ( V3dView.IsNull() ) return 1;
2835
2836   if ( argc == 3 ) {
2837     V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
2838     return 0;
2839   } else {
2840     di << argv[0] << " Invalid number of arguments" << "\n";
2841     return 1;
2842   }
2843 }
2844
2845
2846 //==============================================================================
2847 //function : VExport
2848 //purpose  : Export the view to a vector graphic format (PS, EMF, PDF)
2849 //==============================================================================
2850
2851 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2852 {
2853   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2854   if (V3dView.IsNull())
2855     return 1;
2856
2857   if (argc == 1)
2858   {
2859     std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
2860     return 1;
2861   }
2862
2863   Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
2864   TCollection_AsciiString aFormatStr;
2865
2866   TCollection_AsciiString aFileName (argv[1]);
2867   Standard_Integer aLen = aFileName.Length();
2868
2869   if (argc > 2)
2870   {
2871     aFormatStr = TCollection_AsciiString (argv[2]);
2872   }
2873   else if (aLen >= 4)
2874   {
2875     if (aFileName.Value (aLen - 2) == '.')
2876     {
2877       aFormatStr = aFileName.SubString (aLen - 1, aLen);
2878     }
2879     else if (aFileName.Value (aLen - 3) == '.')
2880     {
2881       aFormatStr = aFileName.SubString (aLen - 2, aLen);
2882     }
2883     else
2884     {
2885       std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2886       return 1;
2887     }
2888   }
2889   else
2890   {
2891     std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2892     return 1;
2893   }
2894
2895   aFormatStr.UpperCase();
2896   if (aFormatStr == "PS")
2897     anExpFormat = Graphic3d_EF_PostScript;
2898   else if (aFormatStr == "EPS")
2899     anExpFormat = Graphic3d_EF_EnhPostScript;
2900   else if (aFormatStr == "TEX")
2901     anExpFormat = Graphic3d_EF_TEX;
2902   else if (aFormatStr == "PDF")
2903     anExpFormat = Graphic3d_EF_PDF;
2904   else if (aFormatStr == "SVG")
2905     anExpFormat = Graphic3d_EF_SVG;
2906   else if (aFormatStr == "PGF")
2907     anExpFormat = Graphic3d_EF_PGF;
2908   else if (aFormatStr == "EMF")
2909     anExpFormat = Graphic3d_EF_EMF;
2910   else
2911   {
2912     std::cout << "Invalid export format '" << aFormatStr << "'\n";
2913     return 1;
2914   }
2915
2916   try {
2917     if (!V3dView->View()->Export (argv[1], anExpFormat))
2918     {
2919       di << "Error: export of image to " << aFormatStr << " failed!\n";
2920     }
2921   }
2922   catch (Standard_Failure)
2923   {
2924     di << "Error: export of image to " << aFormatStr << " failed";
2925     di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
2926   }
2927   return 0;
2928 }
2929
2930 //==============================================================================
2931 //function : VColorScale
2932 //purpose  : representation color scale
2933 //==============================================================================
2934 #include <V3d_ColorScale.hxx>
2935
2936 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2937 {
2938   if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
2939   {
2940     di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0]  " << "\n";
2941     return 1;
2942   }
2943
2944   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2945   if(aContext.IsNull()) {
2946     di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
2947     return -1;
2948   }
2949
2950   Standard_Real minRange = 0. , maxRange = 100. ;
2951
2952   Standard_Integer numIntervals = 10 ;
2953   Standard_Integer textHeight = 16;
2954   Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
2955   Standard_Real X = 0., Y = 0. ;
2956
2957   if ( argc < 9 )
2958   {
2959      if( argc > 3 )
2960      {
2961        minRange = Draw::Atof( argv[1] );
2962        maxRange = Draw::Atof( argv[2] );
2963        numIntervals = Draw::Atoi( argv[3] );
2964      }
2965      if ( argc > 4 )
2966        textHeight = Draw::Atoi( argv[4] );
2967      if ( argc > 5 )
2968        position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
2969      if ( argc > 7 )
2970      {
2971        X = Draw::Atof( argv[6] );
2972        Y = Draw::Atof( argv[7] );
2973      }
2974   }
2975   Handle(V3d_View) curView = ViewerTest::CurrentView( );
2976   if ( curView.IsNull( ) )
2977     return 1;
2978   Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
2979   Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
2980   if( ! aCS.IsNull( ) )
2981   {
2982     aCS->SetPosition( X , Y );
2983     aCS->SetHeight( 0.95) ;
2984     aCS->SetTextHeight( textHeight );
2985     aCS->SetRange( minRange , maxRange );
2986     aCS->SetNumberOfIntervals( numIntervals );
2987     aCS->SetLabelPosition( position );
2988     if( !curView->ColorScaleIsDisplayed() )
2989       curView->ColorScaleDisplay( );
2990   }
2991   return 0;
2992 }
2993
2994 //==============================================================================
2995 //function : VGraduatedTrihedron
2996 //purpose  : Displays a graduated trihedron
2997 //==============================================================================
2998
2999 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
3000 {
3001   const char *str = arg;
3002   while (*str)
3003   {
3004     unsigned short c1 = *str++;
3005     unsigned short c2 = *str++;
3006     if (!c1 || !c2) break;
3007     name += (Standard_ExtCharacter)((c1 << 8) | c2);
3008   }
3009 }
3010
3011 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3012 {
3013   // Check arguments
3014   if (argc != 2 && argc < 5)
3015   {
3016     di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
3017     di<<"Usage: type help "<<argv[0]<<"\n";
3018     return 1; //TCL_ERROR
3019   }
3020
3021   Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
3022
3023   // Create 3D view if it doesn't exist
3024   if ( aV3dView.IsNull() )
3025   {
3026     ViewerTest::ViewerInit();
3027     aV3dView = ViewerTest::CurrentView();
3028     if( aV3dView.IsNull() )
3029     {
3030       di << "Error: Cannot create a 3D view\n";
3031       return 1; //TCL_ERROR
3032     }
3033   }
3034
3035   // Erase (==0) or display (!=0)
3036   const int display = Draw::Atoi(argv[1]);
3037
3038   if (display)
3039   {
3040     // Text font
3041     TCollection_AsciiString font;
3042     if (argc < 6)
3043       font.AssignCat("Courier");
3044     else
3045       font.AssignCat(argv[5]);
3046
3047     // Text is multibyte
3048     const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
3049
3050     // Set axis names
3051     TCollection_ExtendedString xname, yname, zname;
3052     if (argc >= 5)
3053     {
3054       if (isMultibyte)
3055       {
3056         AddMultibyteString(xname, argv[2]);
3057         AddMultibyteString(yname, argv[3]);
3058         AddMultibyteString(zname, argv[4]);
3059       }
3060       else
3061       {
3062         xname += argv[2];
3063         yname += argv[3];
3064         zname += argv[4];
3065       }
3066     }
3067     else
3068     {
3069       xname += "X (mm)";
3070       yname += "Y (mm)";
3071       zname += "Z (mm)";
3072     }
3073
3074     aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
3075                                         Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
3076                                         Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
3077                                         Standard_True/*drawgrid*/,
3078                                         Standard_True/*drawaxes*/,
3079                                         5/*nbx*/, 5/*nby*/, 5/*nbz*/,
3080                                         10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
3081                                         30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
3082                                         Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
3083                                         10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
3084                                         Quantity_NOC_WHITE/*gridcolor*/,
3085                                         Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
3086                                         Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
3087   }
3088   else
3089     aV3dView->GraduatedTrihedronErase();
3090
3091   ViewerTest::GetAISContext()->UpdateCurrentViewer();
3092   aV3dView->Redraw();
3093
3094   return 0;
3095 }
3096
3097 //==============================================================================
3098 //function : VPrintView
3099 //purpose  : Test printing algorithm, print the view to image file with given
3100 //           width and height. Printing implemented only for WNT.
3101 //==============================================================================
3102 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
3103                        const char** argv)
3104 {
3105 #ifndef WNT
3106   di << "Printing implemented only for wnt!\n";
3107   return 1;
3108 #else
3109
3110   Handle(AIS_InteractiveContext) aContextAIS = NULL;
3111   Handle(V3d_View) aView = NULL;
3112   aContextAIS = ViewerTest::GetAISContext();
3113   if (!aContextAIS.IsNull())
3114   {
3115     const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
3116     Vwr->InitActiveViews();
3117     if(Vwr->MoreActiveViews())
3118       aView = Vwr->ActiveView();
3119   }
3120
3121   // check for errors
3122   if (aView.IsNull())
3123   {
3124     di << "Call vinit before!\n";
3125     return 1;
3126   }
3127   else if (argc < 4)
3128   {
3129     di << "Use: " << argv[0];
3130     di << " width height filename [print algo=0]\n";
3131     di << "width, height of the intermediate buffer for operation\n";
3132     di << "algo : {0|1}\n";
3133     di << "        0 - stretch algorithm\n";
3134     di << "        1 - tile algorithm\n";
3135     di << "test printing algorithms into an intermediate buffer\n";
3136     di << "with saving output to an image file\n";
3137     return 1;
3138   }
3139
3140   // get the input params
3141   Standard_Integer aWidth  = Draw::Atoi (argv[1]);
3142   Standard_Integer aHeight = Draw::Atoi (argv[2]);
3143   Standard_Integer aMode   = 0;
3144   TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
3145   if (argc==5)
3146     aMode = Draw::Atoi (argv[4]);
3147
3148   // check the input parameters
3149   if (aWidth <= 0 || aHeight <= 0)
3150   {
3151     di << "Width and height must be positive values!\n";
3152     return 1;
3153   }
3154   if (aMode != 0 && aMode != 1)
3155     aMode = 0;
3156
3157   // define compatible bitmap
3158   HDC anDC = CreateCompatibleDC(0);
3159   BITMAPINFO aBitmapData;
3160   memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
3161   aBitmapData.bmiHeader.biSize          = sizeof (BITMAPINFOHEADER);
3162   aBitmapData.bmiHeader.biWidth         = aWidth ;
3163   aBitmapData.bmiHeader.biHeight        = aHeight;
3164   aBitmapData.bmiHeader.biPlanes        = 1;
3165   aBitmapData.bmiHeader.biBitCount      = 24;
3166   aBitmapData.bmiHeader.biXPelsPerMeter = 0;
3167   aBitmapData.bmiHeader.biYPelsPerMeter = 0;
3168   aBitmapData.bmiHeader.biClrUsed       = 0;
3169   aBitmapData.bmiHeader.biClrImportant  = 0;
3170   aBitmapData.bmiHeader.biCompression   = BI_RGB;
3171   aBitmapData.bmiHeader.biSizeImage     = 0;
3172
3173   // Create Device Independent Bitmap
3174   void* aBitsOut = NULL;
3175   HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
3176                                             &aBitsOut, NULL, 0);
3177   HGDIOBJ anOldBitmap   = SelectObject(anDC, aMemoryBitmap);
3178
3179   Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
3180   if (aBitsOut != NULL)
3181   {
3182     if (aMode == 0)
3183       isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
3184     else
3185       isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
3186
3187     // succesfully printed into an intermediate buffer
3188     if (isPrinted)
3189     {
3190       Image_PixMap aWrapper;
3191       aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
3192       aWrapper.SetTopDown (false);
3193
3194       Image_AlienPixMap anImageBitmap;
3195       anImageBitmap.InitCopy (aWrapper);
3196       isSaved = anImageBitmap.Save (aFileName);
3197     }
3198     else
3199     {
3200       di << "Print operation failed due to printing errors or\n";
3201       di << "insufficient memory available\n";
3202       di << "Please, try to use smaller dimensions for this test\n";
3203       di << "command, as it allocates intermediate buffer for storing\n";
3204       di << "the result\n";
3205     }
3206   }
3207   else
3208   {
3209     di << "Can't allocate memory for intermediate buffer\n";
3210     di << "Please use smaller dimensions\n";
3211   }
3212
3213   if (aMemoryBitmap)
3214   {
3215     SelectObject (anDC, anOldBitmap);
3216     DeleteObject (aMemoryBitmap);
3217     DeleteDC(anDC);
3218   }
3219
3220   if (!isSaved)
3221   {
3222     di << "Save to file operation failed. This operation may fail\n";
3223     di << "if you don't have enough available memory, then you can\n";
3224     di << "use smaller dimensions for the output file\n";
3225     return 1;
3226   }
3227
3228   return 0;
3229
3230 #endif
3231 }
3232
3233 //==============================================================================
3234 //function : VZLayer
3235 //purpose  : Test z layer operations for v3d viewer
3236 //==============================================================================
3237 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3238 {
3239   Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3240   if (aContextAIS.IsNull())
3241   {
3242     di << "Call vinit before!\n";
3243     return 1;
3244   }
3245   else if (argc < 2)
3246   {
3247     di << "Use: vzlayer " << argv[0];
3248     di << " add/del/get [id]\n";
3249     di << " add - add new z layer to viewer and print its id\n";
3250     di << " del - del z layer by its id\n";
3251     di << " get - print sequence of z layers in increasing order of their overlay level\n";
3252     di << "id - the layer identificator value defined when removing z layer\n";
3253     return 1;
3254   }
3255
3256   const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
3257   if (aViewer.IsNull())
3258   {
3259     di << "No active viewer!\n";
3260     return 1;
3261   }
3262
3263   // perform operation
3264   TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
3265   if (anOp == "add")
3266   {
3267     Standard_Integer aNewId;
3268     if (!aViewer->AddZLayer (aNewId))
3269     {
3270       di << "Impossible to add new z layer!\n";
3271       return 1;
3272     }
3273
3274     di << "New z layer added with index: " << aNewId << "\n";
3275   }
3276   else if (anOp == "del")
3277   {
3278     if (argc < 3)
3279     {
3280       di << "Please also provide as argument id of z layer to remove\n";
3281       return 1;
3282     }
3283
3284     Standard_Integer aDelId = Draw::Atoi (argv[2]);
3285     if (!aViewer->RemoveZLayer (aDelId))
3286     {
3287       di << "Impossible to remove the z layer or invalid id!\n";
3288       return 1;
3289     }
3290
3291     di << "Z layer " << aDelId << " has been removed\n";
3292   }
3293   else if (anOp == "get")
3294   {
3295     TColStd_SequenceOfInteger anIds;
3296     aViewer->GetAllZLayers (anIds);
3297     for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
3298     {
3299       di << anIds.Value (aSeqIdx) << " ";
3300     }
3301
3302     di << "\n";
3303   }
3304   else
3305   {
3306     di << "Invalid operation, please use { add / del / get }\n";
3307     return 1;
3308   }
3309
3310   return 0;
3311 }
3312
3313 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3314
3315 // this class provides a presentation of text item in v3d view under-/overlayer
3316 class V3d_TextItem : public Visual3d_LayerItem
3317 {
3318 public:
3319
3320   // CASCADE RTTI
3321   DEFINE_STANDARD_RTTI(V3d_TextItem)
3322
3323   // constructor
3324   Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
3325                                const Standard_Real theX1,
3326                                const Standard_Real theY1,
3327                                const Standard_Real theHeight,
3328                                const TCollection_AsciiString& theFontName,
3329                                const Quantity_Color& theColor,
3330                                const Quantity_Color& theSubtitleColor,
3331                                const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3332                                const Handle(Visual3d_Layer)& theLayer);
3333
3334   // redraw method
3335   Standard_EXPORT void RedrawLayerPrs();
3336
3337 private:
3338
3339   Standard_Real            myX1;
3340   Standard_Real            myY1;
3341   TCollection_AsciiString  myText;
3342   Standard_Real            myHeight;
3343   Handle(Visual3d_Layer)   myLayer;
3344   Quantity_Color           myColor;
3345   Quantity_Color           mySubtitleColor;
3346   Aspect_TypeOfDisplayText myType;
3347   TCollection_AsciiString  myFontName;
3348 };
3349
3350 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
3351 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
3352
3353 // create and add to display the text item
3354 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
3355                             const Standard_Real theX1,
3356                             const Standard_Real theY1,
3357                             const Standard_Real theHeight,
3358                             const TCollection_AsciiString& theFontName,
3359                             const Quantity_Color& theColor,
3360                             const Quantity_Color& theSubtitleColor,
3361                             const Aspect_TypeOfDisplayText& theTypeOfDisplay,
3362                             const Handle(Visual3d_Layer)& theLayer)
3363  : myX1 (theX1), myY1 (theY1),
3364    myText (theText),
3365    myHeight (theHeight),
3366    myLayer (theLayer),
3367    myColor (theColor),
3368    mySubtitleColor (theSubtitleColor),
3369    myType (theTypeOfDisplay),
3370    myFontName (theFontName)
3371 {
3372   if (!myLayer.IsNull ())
3373     myLayer->AddLayerItem (this);
3374 }
3375
3376 // render item
3377 void V3d_TextItem::RedrawLayerPrs ()
3378 {
3379   if (myLayer.IsNull ())
3380     return;
3381
3382   myLayer->SetColor (myColor);
3383   myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
3384   myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
3385 }
3386
3387 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3388
3389 // The Visual3d_LayerItem line item for "vlayerline" command
3390 // it provides a presentation of line with user-defined
3391 // linewidth, linetype and transparency.
3392 class V3d_LineItem : public Visual3d_LayerItem
3393 {
3394 public:
3395   // CASCADE RTTI
3396   DEFINE_STANDARD_RTTI(V3d_LineItem)
3397
3398   // constructor
3399   Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3400                                Standard_Real X2, Standard_Real Y2,
3401                                V3d_LayerMgrPointer theLayerMgr,
3402                                Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
3403                                Standard_Real theWidth    = 0.5,
3404                                Standard_Real theTransp   = 1.0);
3405
3406   // redraw method
3407   Standard_EXPORT   void RedrawLayerPrs();
3408
3409 private:
3410
3411   Standard_Real       myX1, myY1, myX2, myY2;
3412   V3d_LayerMgrPointer myLayerMgr;
3413   Aspect_TypeOfLine   myType;
3414   Standard_Real       myWidth;
3415   Standard_Real       myTransparency;
3416 };
3417
3418 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
3419 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
3420
3421 // default constructor for line item
3422 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
3423                            Standard_Real X2, Standard_Real Y2,
3424                            V3d_LayerMgrPointer theLayerMgr,
3425                            Aspect_TypeOfLine theType,
3426                            Standard_Real theWidth,
3427                            Standard_Real theTransp) :
3428   myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
3429   myType(theType), myWidth(theWidth), myTransparency(theTransp)
3430 {
3431   if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
3432     myLayerMgr->Overlay()->AddLayerItem (this);
3433 }
3434
3435 // render line
3436 void V3d_LineItem::RedrawLayerPrs ()
3437 {
3438   Handle (Visual3d_Layer) aOverlay;
3439
3440   if (myLayerMgr)
3441     aOverlay = myLayerMgr->Overlay();
3442
3443   if (!aOverlay.IsNull())
3444   {
3445     Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
3446     aOverlay->SetColor(aColor);
3447     aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
3448     aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
3449     aOverlay->BeginPolyline();
3450     aOverlay->AddVertex(myX1, myY1);
3451     aOverlay->AddVertex(myX2, myY2);
3452     aOverlay->ClosePrimitive();
3453   }
3454 }
3455
3456 //=============================================================================
3457 //function : VLayerLine
3458 //purpose  : Draws line in the v3d view layer with given attributes: linetype,
3459 //         : linewidth, transparency coefficient
3460 //============================================================================
3461 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3462 {
3463   // get the active view
3464   Handle(V3d_View) aView = ViewerTest::CurrentView();
3465   if (aView.IsNull())
3466   {
3467     di << "Call vinit before!\n";
3468     return 1;
3469   }
3470   else if (argc < 5)
3471   {
3472     di << "Use: " << argv[0];
3473     di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
3474     di << " linetype : { 0 | 1 | 2 | 3 } \n";
3475     di << "              0 - solid  \n";
3476     di << "              1 - dashed \n";
3477     di << "              2 - dot    \n";
3478     di << "              3 - dashdot\n";
3479     di << " transparency : { 0.0 - 1.0 } \n";
3480     di << "                  0.0 - transparent\n";
3481     di << "                  1.0 - visible    \n";
3482     return 1;
3483   }
3484
3485   // get the input params
3486   Standard_Real X1 = Draw::Atof(argv[1]);
3487   Standard_Real Y1 = Draw::Atof(argv[2]);
3488   Standard_Real X2 = Draw::Atof(argv[3]);
3489   Standard_Real Y2 = Draw::Atof(argv[4]);
3490
3491   Standard_Real    aWidth = 0.5;
3492   Standard_Integer aType  = 0;
3493   Standard_Real    aTransparency = 1.0;
3494
3495   // has width
3496   if (argc > 5)
3497     aWidth = Draw::Atof(argv[5]);
3498
3499   // has type
3500   if (argc > 6)
3501      aType = (Standard_Integer) Draw::Atoi(argv[6]);
3502
3503   // has transparency
3504   if (argc > 7)
3505   {
3506     aTransparency = Draw::Atof(argv[7]);
3507     if (aTransparency < 0 || aTransparency > 1.0)
3508       aTransparency = 1.0;
3509   }
3510
3511   // select appropriate line type
3512   Aspect_TypeOfLine aLineType;
3513   switch (aType)
3514   {
3515     case 1:
3516       aLineType = Aspect_TOL_DASH;
3517     break;
3518
3519     case 2:
3520       aLineType = Aspect_TOL_DOT;
3521     break;
3522
3523     case 3:
3524       aLineType = Aspect_TOL_DOTDASH;
3525     break;
3526
3527     default:
3528       aLineType = Aspect_TOL_SOLID;
3529   }
3530
3531   // replace layer manager
3532   Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
3533   aView->SetLayerMgr(aMgr);
3534
3535   // add line item
3536   Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
3537                                                   aMgr.operator->(),
3538                                                   aLineType, aWidth,
3539                                                   aTransparency);
3540
3541   // update view
3542   aView->MustBeResized();
3543   aView->Redraw();
3544
3545   return 0;
3546 }
3547
3548 //=======================================================================
3549 //function : VOverlayText
3550 //purpose  : Test text displaying in view overlay
3551 //=======================================================================
3552 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
3553 {
3554   // get the active view
3555   Handle(V3d_View) aView = ViewerTest::CurrentView();
3556   if (aView.IsNull())
3557   {
3558     di << "No active view. Please call vinit.\n";
3559     return 1;
3560   }
3561   else if (argc < 4 || argc > 13)
3562   {
3563     di << "Use: " << argv[0];
3564     di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
3565     di << "[background_color: R G B]\n";
3566     di << "  height - pixel height of the text (default=10.0)\n";
3567     di << "  font_name - name of font (default=courier)\n";
3568     di << "  text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
3569     di << "  display_type = {normal/subtitle/decal/blend}, (default=normal)\n";
3570     di << "  background_color- R G B values used for subtitle and decal text\n";
3571     di << "(default=255.0 255.0 255.0)\n";
3572     return 1;
3573   }
3574
3575   TCollection_AsciiString aText (argv[1]);
3576   Standard_Real aPosX = Draw::Atof(argv[2]);
3577   Standard_Real aPosY = Draw::Atof(argv[3]);
3578   Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
3579
3580   // font name
3581   TCollection_AsciiString aFontName = "Courier";
3582   if (argc >= 6)
3583     aFontName = TCollection_AsciiString (argv[5]);
3584
3585   // text colors
3586   Quantity_Parameter aColorRed   = 1.0;
3587   Quantity_Parameter aColorGreen = 1.0;
3588   Quantity_Parameter aColorBlue  = 1.0;
3589   if (argc >= 9)
3590   {
3591     aColorRed   = Draw::Atof (argv[6])/255.;
3592     aColorGreen = Draw::Atof (argv[7])/255.;
3593     aColorBlue  = Draw::Atof (argv[8])/255.;
3594   }
3595
3596   // display type
3597   TCollection_AsciiString aDispStr;
3598   if (argc >= 10)
3599     aDispStr = TCollection_AsciiString (argv[9]);
3600
3601   Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
3602   if (aDispStr.IsEqual ("subtitle"))
3603     aTextType = Aspect_TODT_SUBTITLE;
3604   else if (aDispStr.IsEqual ("decal"))
3605     aTextType = Aspect_TODT_DEKALE;
3606   else if (aDispStr.IsEqual ("blend"))
3607     aTextType = Aspect_TODT_BLEND;
3608
3609   // subtitle color
3610   Quantity_Parameter aSubRed   = 1.0;
3611   Quantity_Parameter aSubGreen = 1.0;
3612   Quantity_Parameter aSubBlue  = 1.0;
3613   if (argc == 13)
3614   {
3615     aSubRed   = Draw::Atof (argv[10])/255.;
3616     aSubGreen = Draw::Atof (argv[11])/255.;
3617     aSubBlue  = Draw::Atof (argv[12])/255.;
3618   }
3619
3620   // check fo current overlay
3621   Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
3622   if (anOverlay.IsNull ())
3623   {
3624     Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
3625     anOverlay = aMgr->Overlay ();
3626     aView->SetLayerMgr (aMgr);
3627   }
3628
3629   Quantity_Color aTextColor (aColorRed, aColorGreen,
3630     aColorBlue, Quantity_TOC_RGB);
3631   Quantity_Color aSubtColor (aSubRed, aSubGreen,
3632     aSubBlue, Quantity_TOC_RGB);
3633
3634   // add text item
3635   Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
3636     aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
3637
3638   // update view
3639   aView->MustBeResized();
3640   aView->Redraw();
3641
3642   return 0;
3643 }
3644
3645 //==============================================================================
3646 //function : VGrid
3647 //purpose  :
3648 //==============================================================================
3649
3650 static int VGrid (Draw_Interpretor& /*theDI*/,
3651                   Standard_Integer  theArgNb,
3652                   const char**      theArgVec)
3653 {
3654   // get the active view
3655   Handle(V3d_View)   aView   = ViewerTest::CurrentView();
3656   Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
3657   if (aView.IsNull() || aViewer.IsNull())
3658   {
3659     std::cerr << "No active view. Please call vinit.\n";
3660     return 1;
3661   }
3662
3663   Aspect_GridType     aType = aViewer->GridType();
3664   Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
3665
3666   Standard_Integer anIter = 1;
3667   for (; anIter < theArgNb; ++anIter)
3668   {
3669     const char* aValue = theArgVec[anIter];
3670     if (*aValue == 'r')
3671     {
3672       aType = Aspect_GT_Rectangular;
3673     }
3674     else if (*aValue == 'c')
3675     {
3676       aType = Aspect_GT_Circular;
3677     }
3678     else if (*aValue == 'l')
3679     {
3680       aMode = Aspect_GDM_Lines;
3681     }
3682     else if (*aValue == 'p')
3683     {
3684       aMode = Aspect_GDM_Points;
3685     }
3686     else if (strcmp (aValue, "off" ) == 0)
3687     {
3688       aViewer->DeactivateGrid();
3689       return 0;
3690     }
3691     else
3692     {
3693       break;
3694     }
3695   }
3696
3697   Standard_Integer aTail = (theArgNb - anIter);
3698   if (aTail == 0)
3699   {
3700     aViewer->ActivateGrid (aType, aMode);
3701     return 0;
3702   }
3703   else if (aTail != 2 && aTail != 5)
3704   {
3705     std::cerr << "Incorrect arguments number! Usage:\n"
3706               << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
3707     return 1;
3708   }
3709
3710   Quantity_Length anOriginX, anOriginY;
3711   Quantity_PlaneAngle aRotAngle;
3712   if (aType == Aspect_GT_Rectangular)
3713   {
3714     Quantity_Length aRStepX, aRStepY;
3715     aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3716
3717     anOriginX = Draw::Atof (theArgVec[anIter++]);
3718     anOriginY = Draw::Atof (theArgVec[anIter++]);
3719     if (aTail == 5)
3720     {
3721       aRStepX   = Draw::Atof (theArgVec[anIter++]);
3722       aRStepY   = Draw::Atof (theArgVec[anIter++]);
3723       aRotAngle = Draw::Atof (theArgVec[anIter++]);
3724     }
3725     aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
3726     aViewer->ActivateGrid (aType, aMode);
3727   }
3728   else if (aType == Aspect_GT_Circular)
3729   {
3730     Quantity_Length aRadiusStep;
3731     Standard_Integer aDivisionNumber;
3732     aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3733
3734     anOriginX = Draw::Atof (theArgVec[anIter++]);
3735     anOriginY = Draw::Atof (theArgVec[anIter++]);
3736     if (aTail == 5)
3737     {
3738       aRadiusStep     = Draw::Atof (theArgVec[anIter++]);
3739       aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
3740       aRotAngle       = Draw::Atof (theArgVec[anIter++]);
3741     }
3742
3743     aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
3744     aViewer->ActivateGrid (aType, aMode);
3745   }
3746
3747   return 0;
3748 }
3749
3750 //==============================================================================
3751 //function : VFps
3752 //purpose  :
3753 //==============================================================================
3754
3755 static int VFps (Draw_Interpretor& theDI,
3756                  Standard_Integer  theArgNb,
3757                  const char**      theArgVec)
3758 {
3759   // get the active view
3760   Handle(V3d_View) aView = ViewerTest::CurrentView();
3761   if (aView.IsNull())
3762   {
3763     std::cerr << "No active view. Please call vinit.\n";
3764     return 1;
3765   }
3766
3767   Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
3768   if (aFramesNb <= 0)
3769   {
3770     std::cerr << "Incorrect arguments!\n";
3771     return 1;
3772   }
3773
3774   // the time is meaningless for first call
3775   // due to async OpenGl rendering
3776   aView->Redraw();
3777
3778   // redraw view in loop to estimate average values
3779   OSD_Timer aTimer;
3780   aTimer.Start();
3781   for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
3782   {
3783     aView->Redraw();
3784   }
3785   aTimer.Stop();
3786   Standard_Real aCpu;
3787   const Standard_Real aTime = aTimer.ElapsedTime();
3788   aTimer.OSD_Chronometer::Show (aCpu);
3789
3790   const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
3791   const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
3792
3793   // return statistics
3794   theDI << "FPS: " << aFpsAver << "\n"
3795         << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
3796
3797   return 0;
3798 }
3799
3800 //==============================================================================
3801 //function : VGlDebug
3802 //purpose  :
3803 //==============================================================================
3804
3805 static int VGlDebug (Draw_Interpretor& theDI,
3806                      Standard_Integer  theArgNb,
3807                      const char**      theArgVec)
3808 {
3809   if (theArgNb < 2)
3810   {
3811     Handle(V3d_View) aView = ViewerTest::CurrentView();
3812     if (aView.IsNull())
3813     {
3814       std::cerr << "No active view. Please call vinit.\n";
3815       return 0;
3816     }
3817
3818     Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )glGetString (GL_EXTENSIONS),
3819                                                                 "GL_ARB_debug_output");
3820     std::cout << "Active graphic driver: debug " << (isActive ? "ON" : "OFF") << "\n";
3821     theDI << (isActive ? "1" : "0");
3822     return 0;
3823   }
3824
3825   ViewerTest_myDefaultCaps.contextDebug = Draw::Atoi (theArgVec[1]) != 0;
3826   return 0;
3827 }
3828
3829 //==============================================================================
3830 //function : VVbo
3831 //purpose  :
3832 //==============================================================================
3833
3834 static int VVbo (Draw_Interpretor& theDI,
3835                  Standard_Integer  theArgNb,
3836                  const char**      theArgVec)
3837 {
3838   const Standard_Boolean toSet    = (theArgNb > 1);
3839   const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
3840   if (toSet)
3841   {
3842     ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
3843   }
3844
3845   // get the context
3846   Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3847   if (aContextAIS.IsNull())
3848   {
3849     if (!toSet)
3850     {
3851       std::cerr << "No active view!\n";
3852     }
3853     return 1;
3854   }
3855   Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
3856   if (!aDriver.IsNull())
3857   {
3858     if (!toSet)
3859     {
3860       theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
3861     }
3862     else
3863     {
3864       aDriver->ChangeOptions().vboDisable = toUseVbo;
3865     }
3866   }
3867
3868   return 0;
3869 }
3870
3871 //==============================================================================
3872 //function : VCaps
3873 //purpose  :
3874 //==============================================================================
3875
3876 static int VCaps (Draw_Interpretor& theDI,
3877                   Standard_Integer  theArgNb,
3878                   const char**      theArgVec)
3879 {
3880   OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
3881   Handle(OpenGl_GraphicDriver)   aDriver;
3882   Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3883   if (!aContextAIS.IsNull())
3884   {
3885     aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
3886     aCaps   = &aDriver->ChangeOptions();
3887   }
3888
3889   if (theArgNb < 2)
3890   {
3891     theDI << "VBO:     " << (aCaps->vboDisable        ? "0" : "1") << "\n";
3892     theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
3893     theDI << "SoftMode:" << (aCaps->contextNoAccel    ? "1" : "0") << "\n";
3894     return 0;
3895   }
3896
3897   for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3898   {
3899     const TCollection_AsciiString anArg (theArgVec[anArgIter]);
3900     if (anArg.Search ("vbo=") > -1)
3901     {
3902       aCaps->vboDisable        = anArg.Token ("=", 2).IntegerValue() == 0;
3903     }
3904     else if (anArg.Search ("sprites=") > -1)
3905     {
3906       aCaps->pntSpritesDisable = anArg.Token ("=", 2).IntegerValue() == 0;
3907     }
3908     else if (anArg.Search ("soft=") > -1)
3909     {
3910       aCaps->contextNoAccel = anArg.Token ("=", 2).IntegerValue() != 0;
3911     }
3912     else
3913     {
3914       std::cerr << "Unknown argument: " << anArg << "\n";
3915     }
3916   }
3917   if (aCaps != &ViewerTest_myDefaultCaps)
3918   {
3919     ViewerTest_myDefaultCaps = *aCaps;
3920   }
3921   return 0;
3922 }
3923
3924 //==============================================================================
3925 //function : VMemGpu
3926 //purpose  :
3927 //==============================================================================
3928
3929 static int VMemGpu (Draw_Interpretor& theDI,
3930                     Standard_Integer  theArgNb,
3931                     const char**      theArgVec)
3932 {
3933   // get the context
3934   Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3935   if (aContextAIS.IsNull())
3936   {
3937     std::cerr << "No active view. Please call vinit.\n";
3938     return 1;
3939   }
3940
3941   Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
3942   if (aDriver.IsNull())
3943   {
3944     std::cerr << "Graphic driver not available.\n";
3945     return 1;
3946   }
3947
3948   Standard_Size aFreeBytes = 0;
3949   TCollection_AsciiString anInfo;
3950   if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
3951   {
3952     std::cerr << "Information not available.\n";
3953     return 1;
3954   }
3955
3956   if (theArgNb > 1 && *theArgVec[1] == 'f')
3957   {
3958     theDI << Standard_Real (aFreeBytes);
3959   }
3960   else
3961   {
3962     theDI << anInfo;
3963   }
3964
3965   return 0;
3966 }
3967
3968 // ==============================================================================
3969 // function : VReadPixel
3970 // purpose  :
3971 // ==============================================================================
3972 static int VReadPixel (Draw_Interpretor& theDI,
3973                        Standard_Integer  theArgNb,
3974                        const char**      theArgVec)
3975 {
3976   // get the active view
3977   Handle(V3d_View) aView = ViewerTest::CurrentView();
3978   if (aView.IsNull())
3979   {
3980     std::cerr << "No active view. Please call vinit.\n";
3981     return 1;
3982   }
3983   else if (theArgNb < 3)
3984   {
3985     std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
3986     return 1;
3987   }
3988
3989   Image_PixMap::ImgFormat aFormat     = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
3990   Graphic3d_BufferType    aBufferType = Graphic3d_BT_RGBA;
3991
3992   Standard_Integer aWidth, aHeight;
3993   aView->Window()->Size (aWidth, aHeight);
3994   const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
3995   const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
3996   if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
3997   {
3998     std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
3999     return 1;
4000   }
4001
4002   Standard_Boolean toShowName = Standard_False;
4003   Standard_Boolean toShowHls  = Standard_False;
4004   for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
4005   {
4006     const char* aParam = theArgVec[anIter];
4007     if ( strcasecmp( aParam, "rgb" ) == 0 )
4008     {
4009       aFormat     = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4010       aBufferType = Graphic3d_BT_RGB;
4011     }
4012     else if ( strcasecmp( aParam, "hls" ) == 0 )
4013     {
4014       aFormat     = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4015       aBufferType = Graphic3d_BT_RGB;
4016       toShowHls   = Standard_True;
4017     }
4018     else if ( strcasecmp( aParam, "rgbf" ) == 0 )
4019     {
4020       aFormat     = Image_PixMap::ImgRGBF;
4021       aBufferType = Graphic3d_BT_RGB;
4022     }
4023     else if ( strcasecmp( aParam, "rgba" ) == 0 )
4024     {
4025       aFormat     = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4026       aBufferType = Graphic3d_BT_RGBA;
4027     }
4028     else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
4029     {
4030       aFormat     = Image_PixMap::ImgRGBAF;
4031       aBufferType = Graphic3d_BT_RGBA;
4032     }
4033     else if ( strcasecmp( aParam, "depth" ) == 0 )
4034     {
4035       aFormat     = Image_PixMap::ImgGrayF;
4036       aBufferType = Graphic3d_BT_Depth;
4037     }
4038     else if ( strcasecmp( aParam, "name" ) == 0 )
4039     {
4040       toShowName = Standard_True;
4041     }
4042   }
4043
4044   Image_PixMap anImage;
4045   if (!anImage.InitTrash (aFormat, aWidth, aHeight))
4046   {
4047     std::cerr << "Image allocation failed\n";
4048     return 1;
4049   }
4050   else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
4051   {
4052     std::cerr << "Image dump failed\n";
4053     return 1;
4054   }
4055
4056   Quantity_Parameter anAlpha;
4057   Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
4058   if (toShowName)
4059   {
4060     if (aBufferType == Graphic3d_BT_RGBA)
4061     {
4062       theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha << "\n";
4063     }
4064     else
4065     {
4066       theDI << Quantity_Color::StringName (aColor.Name()) << "\n";
4067     }
4068   }
4069   else
4070   {
4071     switch (aBufferType)
4072     {
4073       default:
4074       case Graphic3d_BT_RGB:
4075       {
4076         if (toShowHls)
4077         {
4078           theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation() << "\n";
4079         }
4080         else
4081         {
4082           theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << "\n";
4083         }
4084         break;
4085       }
4086       case Graphic3d_BT_RGBA:
4087       {
4088         theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha << "\n";
4089         break;
4090       }
4091       case Graphic3d_BT_Depth:
4092       {
4093         theDI << aColor.Red() << "\n";
4094         break;
4095       }
4096     }
4097   }
4098
4099   return 0;
4100 }
4101
4102 //==============================================================================
4103 //function : VDiffImage
4104 //purpose  : The draw-command compares two images.
4105 //==============================================================================
4106
4107 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
4108 {
4109   if (theArgNb < 6)
4110   {
4111     theDI << "Not enough arguments.\n";
4112     return 1;
4113   }
4114
4115   // image file names
4116   const char* anImgPathRef = theArgVec[1];
4117   const char* anImgPathNew = theArgVec[2];
4118
4119   // get string tolerance and check its validity
4120   Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
4121   if (aTolColor < 0.0)
4122     aTolColor = 0.0;
4123   if (aTolColor > 1.0)
4124     aTolColor = 1.0;
4125
4126   Standard_Boolean toBlackWhite     = (Draw::Atoi (theArgVec[4]) == 1);
4127   Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
4128
4129   // image file of difference
4130   const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
4131
4132   // compare the images
4133   Image_Diff aComparer;
4134   if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
4135   {
4136     return 1;
4137   }
4138
4139   aComparer.SetColorTolerance (aTolColor);
4140   aComparer.SetBorderFilterOn (isBorderFilterOn);
4141   Standard_Integer aDiffColorsNb = aComparer.Compare();
4142   theDI << aDiffColorsNb << "\n";
4143
4144   // save image of difference
4145   if (aDiffImagePath != NULL)
4146   {
4147     aComparer.SaveDiffImage (aDiffImagePath);
4148   }
4149
4150   return 0;
4151 }
4152
4153 //=======================================================================
4154 //function : VSelect
4155 //purpose  : Emulates different types of selection by mouse:
4156 //           1) single click selection
4157 //           2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
4158 //           3) selection with polygon having corners at
4159 //           pixel positions (x1,y1),...,(xn,yn)
4160 //           4) any of these selections with shift button pressed
4161 //=======================================================================
4162 static Standard_Integer VSelect (Draw_Interpretor& di,
4163                                  Standard_Integer argc,
4164                                  const char ** argv)
4165 {
4166   if(argc < 3)
4167   {
4168     di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
4169     return 1;
4170   }
4171
4172   Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
4173   if(myAIScontext.IsNull())
4174   {
4175     di << "use 'vinit' command before " << argv[0] << "\n";
4176     return 1;
4177   }
4178   const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
4179   Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
4180   aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
4181   if(argc <= 4)
4182   {
4183     if(isShiftSelection)
4184       aCurrentEventManager->ShiftSelect();
4185     else
4186       aCurrentEventManager->Select();
4187   }
4188   else if(argc <= 6)
4189   {
4190     if(isShiftSelection)
4191       aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4192     else
4193       aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
4194   }
4195   else
4196   {
4197     Standard_Integer anUpper = 0;
4198
4199     if(isShiftSelection)
4200       anUpper = (argc-1)/2;
4201     else
4202       anUpper = argc/2;
4203     TColgp_Array1OfPnt2d aPolyline(1,anUpper);
4204
4205     for(Standard_Integer i=1;i<=anUpper;++i)
4206       aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
4207
4208     if(isShiftSelection)
4209       aCurrentEventManager->ShiftSelect(aPolyline);
4210     else
4211       aCurrentEventManager->Select(aPolyline);
4212   }
4213   return 0;
4214 }
4215
4216 //=======================================================================
4217 //function : VMoveTo
4218 //purpose  : Emulates cursor movement to defined pixel position
4219 //=======================================================================
4220 static Standard_Integer VMoveTo (Draw_Interpretor& di,
4221                                 Standard_Integer argc,
4222                                 const char ** argv)
4223 {
4224   if(argc != 3)
4225   {
4226     di << "Usage : " << argv[0] << " x y" << "\n";
4227     return 1;
4228   }
4229
4230   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4231   if(aContext.IsNull())
4232   {
4233     di << "use 'vinit' command before " << argv[0] << "\n";
4234     return 1;
4235   }
4236   ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
4237   return 0;
4238 }
4239
4240 //=======================================================================
4241 //function : VViewParams
4242 //purpose  : Gets or sets AIS View characteristics
4243 //=======================================================================
4244 static Standard_Integer VViewParams (Draw_Interpretor& di,
4245                                 Standard_Integer argc,
4246                                 const char ** argv)
4247 {
4248   if ( argc != 1 && argc != 13)
4249   {
4250     di << "Usage : " << argv[0] << "\n";
4251     return 1;
4252   }
4253   Handle (V3d_View) anAISView = ViewerTest::CurrentView ();
4254   if ( anAISView.IsNull () )
4255   {
4256     di << "use 'vinit' command before " << argv[0] << "\n";
4257     return 1;
4258   }
4259   if(argc==1){
4260     Quantity_Factor anAISViewScale = anAISView -> V3d_View::Scale ();
4261     Standard_Real anAISViewCenterCoordinateX = 0.0;
4262     Standard_Real anAISViewCenterCoordinateY = 0.0;
4263     anAISView -> V3d_View::Center (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
4264     Standard_Real anAISViewProjX = 0.0;
4265     Standard_Real anAISViewProjY = 0.0;
4266     Standard_Real anAISViewProjZ = 0.0;
4267     anAISView -> V3d_View::Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4268     Standard_Real anAISViewUpX = 0.0;
4269     Standard_Real anAISViewUpY = 0.0;
4270     Standard_Real anAISViewUpZ = 0.0;
4271     anAISView -> V3d_View::Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4272     Standard_Real anAISViewAtX = 0.0;
4273     Standard_Real anAISViewAtY = 0.0;
4274     Standard_Real anAISViewAtZ = 0.0;
4275     anAISView -> V3d_View::At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4276     di << "Scale of current view: " << anAISViewScale << "\n";
4277     di << "Center on X : "<< anAISViewCenterCoordinateX << "; on Y: " << anAISViewCenterCoordinateY << "\n";
4278     di << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
4279     di << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
4280     di << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
4281   }
4282   else
4283   {
4284     Quantity_Factor anAISViewScale = atof (argv [1]);
4285     Standard_Real anAISViewCenterCoordinateX = atof (argv [2]);
4286     Standard_Real anAISViewCenterCoordinateY = atof (argv [3]);
4287     Standard_Real anAISViewProjX = atof (argv [4]);
4288     Standard_Real anAISViewProjY = atof (argv [5]);
4289     Standard_Real anAISViewProjZ = atof (argv [6]);
4290     Standard_Real anAISViewUpX = atof (argv [7]);
4291     Standard_Real anAISViewUpY = atof (argv [8]);
4292     Standard_Real anAISViewUpZ = atof (argv [9]);
4293     Standard_Real anAISViewAtX = atof (argv [10]);
4294     Standard_Real anAISViewAtY = atof (argv [11]);
4295     Standard_Real anAISViewAtZ = atof (argv [12]);
4296     anAISView -> V3d_View::SetScale (anAISViewScale);
4297     anAISView -> V3d_View::SetCenter (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
4298     anAISView -> V3d_View::SetAt (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
4299     anAISView -> V3d_View::SetProj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
4300     anAISView -> V3d_View::SetUp (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
4301   }
4302   return 0;
4303 }
4304
4305 //=======================================================================
4306 //function : VChangeSelected
4307 //purpose  : Adds the shape to selection or remove one from it
4308 //=======================================================================
4309 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
4310                                 Standard_Integer argc,
4311                                 const char ** argv)
4312 {
4313   if(argc != 2)
4314   {
4315     di<<"Usage : " << argv[0] << " shape \n";
4316     return 1;
4317   }
4318   //get AIS_Shape:
4319   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4320   ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
4321   TCollection_AsciiString aName(argv[1]);
4322   Handle(AIS_InteractiveObject) anAISObject;
4323
4324   if(!aMap.IsBound2(aName))
4325   {
4326     di<<"Use 'vdisplay' before";
4327     return 1;
4328   }
4329   else
4330   {
4331     anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
4332     if(anAISObject.IsNull()){
4333       di<<"No interactive object \n";
4334       return 1;
4335     }
4336
4337     if(aContext->HasOpenedContext())
4338     {
4339       aContext->AddOrRemoveSelected(anAISObject);
4340     }
4341     else
4342     {
4343       aContext->AddOrRemoveCurrentObject(anAISObject);
4344     }
4345   }
4346   return 0;
4347 }
4348
4349 //=======================================================================
4350 //function : VZClipping
4351 //purpose  : Gets or sets ZClipping mode, width and depth
4352 //=======================================================================
4353 static Standard_Integer VZClipping (Draw_Interpretor& di,
4354                                 Standard_Integer argc,
4355                                 const char ** argv)
4356 {
4357   if(argc>4)
4358   {
4359     di << "Usage : " << argv[0] << " [mode] [depth  width]" << "\n"
4360       <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4361     return -1;
4362   }
4363   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4364   if(aContext.IsNull())
4365   {
4366     di << "use 'vinit' command before " << argv[0] << "\n";
4367     return 1;
4368   }
4369   Handle(V3d_View) aView = ViewerTest::CurrentView();
4370   V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
4371   if(argc==1)
4372   {
4373     TCollection_AsciiString aZClippingModeString;
4374     Quantity_Length aDepth, aWidth;
4375     aZClippingMode = aView->ZClipping(aDepth, aWidth);
4376     switch (aZClippingMode)
4377     {
4378     case V3d_OFF:
4379       aZClippingModeString.Copy("OFF");
4380       break;
4381     case V3d_BACK:
4382       aZClippingModeString.Copy("BACK");
4383       break;
4384     case V3d_FRONT:
4385       aZClippingModeString.Copy("FRONT");
4386       break;
4387     case V3d_SLICE:
4388       aZClippingModeString.Copy("SLICE");
4389       break;
4390     default:
4391       aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
4392       break;
4393     }
4394     di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
4395       << "ZClipping depth = " << aDepth << "\n"
4396       << "ZClipping width = " << aWidth << "\n";
4397   }
4398   else
4399   {
4400     if(argc !=3)
4401     {
4402       Standard_Integer aStatus = 0;
4403       if ( strcmp (argv [1], "OFF") == 0 ) {
4404         aStatus = 1;
4405         aZClippingMode = V3d_OFF;
4406       }
4407       if ( strcmp (argv [1], "BACK") == 0 ) {
4408         aStatus = 1;
4409         aZClippingMode = V3d_BACK;
4410       }
4411       if ( strcmp (argv [1], "FRONT") == 0 ) {
4412         aStatus = 1;
4413         aZClippingMode = V3d_FRONT;
4414       }
4415       if ( strcmp (argv [1], "SLICE") == 0 ) {
4416         aStatus = 1;
4417         aZClippingMode = V3d_SLICE;
4418       }
4419       if (aStatus != 1)
4420       {
4421         di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4422           << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4423         return 1;
4424       }
4425       aView->SetZClippingType(aZClippingMode);
4426     }
4427     if(argc >2)
4428     {
4429       Quantity_Length aDepth = 0., aWidth = 1.;
4430       if(argc == 3)
4431       {
4432         aDepth = atof(argv[1]);
4433         aWidth = atof(argv[2]);
4434       }
4435       else if(argc == 4)
4436       {
4437         aDepth = atof(argv[2]);
4438         aWidth = atof(argv[3]);
4439       }
4440
4441       if(aDepth<0. || aDepth>1.)
4442       {
4443         di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4444         << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4445         return 1;
4446       }
4447       if(aWidth<0. || aWidth>1.)
4448       {
4449         di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
4450         << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
4451         return 1;
4452       }
4453
4454       aView->SetZClippingDepth(aDepth);
4455       aView->SetZClippingWidth(aWidth);
4456     }
4457     aView->Redraw();
4458   }
4459   return 0;
4460 }
4461
4462 //=======================================================================
4463 //function : VNbSelected
4464 //purpose  : Returns number of selected objects
4465 //=======================================================================
4466 static Standard_Integer VNbSelected (Draw_Interpretor& di,
4467                                 Standard_Integer argc,
4468                                 const char ** argv)
4469 {
4470   if(argc != 1)
4471   {
4472     di << "Usage : " << argv[0] << "\n";
4473     return 1;
4474   }
4475   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4476   if(aContext.IsNull())
4477   {
4478     di << "use 'vinit' command before " << argv[0] << "\n";
4479     return 1;
4480   }
4481   di << aContext->NbSelected() << "\n";
4482   return 0;
4483 }
4484
4485 //=======================================================================
4486 //function : VAntialiasing
4487 //purpose  : Switches altialiasing on or off
4488 //=======================================================================
4489 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
4490                                 Standard_Integer argc,
4491                                 const char ** argv)
4492 {
4493   if(argc > 2)
4494   {
4495     di << "Usage : " << argv[0] << " [1|0]" << "\n";
4496     return 1;
4497   }
4498
4499   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4500   if(aContext.IsNull())
4501   {
4502     di << "use 'vinit' command before " << argv[0] << "\n";
4503     return 1;
4504   }
4505
4506   Handle(V3d_View) aView = ViewerTest::CurrentView();
4507
4508   if((argc == 2) && (atof(argv[1]) == 0))
4509     aView->SetAntialiasingOff();
4510   else
4511     aView->SetAntialiasingOn();
4512   aView->Update();
4513   return 0;
4514 }
4515
4516 //=======================================================================
4517 //function : VPurgeDisplay
4518 //purpose  : Switches altialiasing on or off
4519 //=======================================================================
4520 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
4521                                 Standard_Integer argc,
4522                                 const char ** argv)
4523 {
4524   if (argc > 1)
4525   {
4526     di << "Usage : " << argv[0] << "\n";
4527     return 1;
4528   }
4529   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4530   if (aContext.IsNull())
4531   {
4532     di << "use 'vinit' command before " << argv[0] << "\n";
4533     return 1;
4534   }
4535   aContext->CloseAllContexts(Standard_False);
4536   di << aContext->PurgeDisplay() << "\n";
4537   return 0;
4538 }
4539
4540 //=======================================================================
4541 //function : VSetViewSize
4542 //purpose  :
4543 //=======================================================================
4544 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
4545                                 Standard_Integer argc,
4546                                 const char ** argv)
4547 {
4548   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4549   if(aContext.IsNull())
4550   {
4551     di << "use 'vinit' command before " << argv[0] << "\n";
4552     return 1;
4553   }
4554   if(argc != 2)
4555   {
4556     di<<"Usage : " << argv[0] << " Size\n";
4557     return 1;
4558   }
4559   Standard_Real aSize = atof(argv[1]);
4560   if (aSize <= 0.)
4561   {
4562     di<<"Bad Size value  : " << aSize << "\n";
4563     return 1;
4564   }
4565
4566   Handle(V3d_View) aView = ViewerTest::CurrentView();
4567   aView->SetSize(aSize);
4568   return 0;
4569 }
4570
4571 //=======================================================================
4572 //function : VMoveView
4573 //purpose  :
4574 //=======================================================================
4575 static Standard_Integer VMoveView (Draw_Interpretor& di,
4576                                 Standard_Integer argc,
4577                                 const char ** argv)
4578 {
4579   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4580   if(aContext.IsNull())
4581   {
4582     di << "use 'vinit' command before " << argv[0] << "\n";
4583     return 1;
4584   }
4585   if(argc < 4 || argc > 5)
4586   {
4587     di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4588     return 1;
4589   }
4590   Standard_Real Dx = atof(argv[1]);
4591   Standard_Real Dy = atof(argv[2]);
4592   Standard_Real Dz = atof(argv[3]);
4593   Standard_Boolean aStart = Standard_True;
4594   if (argc == 5)
4595   {
4596       aStart = (atoi(argv[4]) > 0);
4597   }
4598
4599   Handle(V3d_View) aView = ViewerTest::CurrentView();
4600   aView->Move(Dx,Dy,Dz,aStart);
4601   return 0;
4602 }
4603
4604 //=======================================================================
4605 //function : VTranslateView
4606 //purpose  :
4607 //=======================================================================
4608 static Standard_Integer VTranslateView (Draw_Interpretor& di,
4609                                 Standard_Integer argc,
4610                                 const char ** argv)
4611 {
4612   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4613   if(aContext.IsNull())
4614   {
4615     di << "use 'vinit' command before " << argv[0] << "\n";
4616     return 1;
4617   }
4618   if(argc < 4 || argc > 5)
4619   {
4620     di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
4621     return 1;
4622   }
4623   Standard_Real Dx = atof(argv[1]);
4624   Standard_Real Dy = atof(argv[2]);
4625   Standard_Real Dz = atof(argv[3]);
4626   Standard_Boolean aStart = Standard_True;
4627   if (argc == 5)
4628   {
4629       aStart = (atoi(argv[4]) > 0);
4630   }
4631
4632   Handle(V3d_View) aView = ViewerTest::CurrentView();
4633   aView->Translate(Dx,Dy,Dz,aStart);
4634   return 0;
4635 }
4636
4637 //=======================================================================
4638 //function : VTurnView
4639 //purpose  :
4640 //=======================================================================
4641 static Standard_Integer VTurnView (Draw_Interpretor& di,
4642                                 Standard_Integer argc,
4643                                 const char ** argv)
4644 {
4645   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4646   if(aContext.IsNull()) {
4647     di << "use 'vinit' command before " << argv[0] << "\n";
4648     return 1;
4649   }
4650   if(argc < 4 || argc > 5){
4651     di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
4652     return 1;
4653   }
4654   Standard_Real Ax = atof(argv[1]);
4655   Standard_Real Ay = atof(argv[2]);
4656   Standard_Real Az = atof(argv[3]);
4657   Standard_Boolean aStart = Standard_True;
4658   if (argc == 5)
4659   {
4660       aStart = (atoi(argv[4]) > 0);
4661   }
4662
4663   Handle(V3d_View) aView = ViewerTest::CurrentView();
4664   aView->Turn(Ax,Ay,Az,aStart);
4665   return 0;
4666 }
4667
4668 //==============================================================================
4669 //function : VTextureEnv
4670 //purpose  : ENables or disables environment mapping
4671 //==============================================================================
4672 class OCC_TextureEnv : public Graphic3d_TextureEnv
4673 {
4674 public:
4675   OCC_TextureEnv(const Standard_CString FileName);
4676   OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
4677   void SetTextureParameters(const Standard_Boolean theRepeatFlag,
4678                             const Standard_Boolean theModulateFlag,
4679                             const Graphic3d_TypeOfTextureFilter theFilter,
4680                             const Standard_ShortReal theXScale,
4681                             const Standard_ShortReal theYScale,
4682                             const Standard_ShortReal theXShift,
4683                             const Standard_ShortReal theYShift,
4684                             const Standard_ShortReal theAngle);
4685   DEFINE_STANDARD_RTTI(OCC_TextureEnv);
4686 };
4687 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4688 IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
4689 IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
4690
4691 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
4692   : Graphic3d_TextureEnv(theFileName)
4693 {
4694 }
4695
4696 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
4697   : Graphic3d_TextureEnv(theTexId)
4698 {
4699 }
4700
4701 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
4702                                           const Standard_Boolean theModulateFlag,
4703                                           const Graphic3d_TypeOfTextureFilter theFilter,
4704                                           const Standard_ShortReal theXScale,
4705                                           const Standard_ShortReal theYScale,
4706                                           const Standard_ShortReal theXShift,
4707                                           const Standard_ShortReal theYShift,
4708                                           const Standard_ShortReal theAngle)
4709 {
4710   myParams->SetRepeat     (theRepeatFlag);
4711   myParams->SetModulate   (theModulateFlag);
4712   myParams->SetFilter     (theFilter);
4713   myParams->SetScale      (Graphic3d_Vec2(theXScale, theYScale));
4714   myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
4715   myParams->SetRotation   (theAngle);
4716 }
4717
4718 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
4719 {
4720   // get the active view
4721   Handle(V3d_View) aView = ViewerTest::CurrentView();
4722   if (aView.IsNull())
4723   {
4724     std::cerr << "No active view. Please call vinit.\n";
4725     return 1;
4726   }
4727
4728   // Checking the input arguments
4729   Standard_Boolean anEnableFlag = Standard_False;
4730   Standard_Boolean isOk         = theArgNb >= 2;
4731   if (isOk)
4732   {
4733     TCollection_AsciiString anEnableOpt(theArgVec[1]);
4734     anEnableFlag = anEnableOpt.IsEqual("on");
4735     isOk         = anEnableFlag || anEnableOpt.IsEqual("off");
4736   }
4737   if (anEnableFlag)
4738   {
4739     isOk = (theArgNb == 3 || theArgNb == 11);
4740     if (isOk)
4741     {
4742       TCollection_AsciiString aTextureOpt(theArgVec[2]);
4743       isOk = (!aTextureOpt.IsIntegerValue() ||
4744              (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
4745
4746       if (isOk && theArgNb == 11)
4747       {
4748         TCollection_AsciiString aRepeatOpt  (theArgVec[3]),
4749                                 aModulateOpt(theArgVec[4]),
4750                                 aFilterOpt  (theArgVec[5]),
4751                                 aSScaleOpt  (theArgVec[6]),
4752                                 aTScaleOpt  (theArgVec[7]),
4753                                 aSTransOpt  (theArgVec[8]),
4754                                 aTTransOpt  (theArgVec[9]),
4755                                 anAngleOpt  (theArgVec[10]);
4756         isOk = ((aRepeatOpt.  IsEqual("repeat")   || aRepeatOpt.  IsEqual("clamp")) &&
4757                 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
4758                 (aFilterOpt.  IsEqual("nearest")  || aFilterOpt.  IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
4759                 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
4760                 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
4761                 anAngleOpt.IsRealValue());
4762       }
4763     }
4764   }
4765
4766   if (!isOk)
4767   {
4768     std::cerr << "Usage :" << std::endl;
4769     std::cerr << theArgVec[0] << " off" << std::endl;
4770     std::cerr << theArgVec[0] << " on {index_of_std_texture(0..7)|texture_file_name} [{clamp|repeat} {decal|modulate} {nearest|bilinear|trilinear} scale_s scale_t translation_s translation_t rotation_degrees]" << std::endl;
4771     return 1;
4772   }
4773
4774   if (anEnableFlag)
4775   {
4776     TCollection_AsciiString aTextureOpt(theArgVec[2]);
4777     Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
4778                                      new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
4779                                      new OCC_TextureEnv(theArgVec[2]);
4780
4781     if (theArgNb == 11)
4782     {
4783       TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
4784       aTexEnv->SetTextureParameters(
4785         aRepeatOpt.  IsEqual("repeat"),
4786         aModulateOpt.IsEqual("modulate"),
4787         aFilterOpt.  IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
4788                                           aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
4789                                                                            Graphic3d_TOTF_TRILINEAR,
4790         (Standard_ShortReal)Draw::Atof(theArgVec[6]),
4791         (Standard_ShortReal)Draw::Atof(theArgVec[7]),
4792         (Standard_ShortReal)Draw::Atof(theArgVec[8]),
4793         (Standard_ShortReal)Draw::Atof(theArgVec[9]),
4794         (Standard_ShortReal)Draw::Atof(theArgVec[10])
4795         );
4796     }
4797     aView->SetTextureEnv(aTexEnv);
4798     aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
4799   }
4800   else // Disabling environment mapping
4801   {
4802     aView->SetSurfaceDetail(V3d_TEX_NONE);
4803     Handle(Graphic3d_TextureEnv) aTexture;
4804     aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
4805   }
4806
4807   aView->Redraw();
4808   return 0;
4809 }
4810
4811 //===============================================================================================
4812 //function : VClipPlane
4813 //purpose  :
4814 //===============================================================================================
4815 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
4816 {
4817   // use short-cut for created clip planes map of created (or "registered by name") clip planes
4818   typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
4819   static MapOfPlanes aRegPlanes;
4820
4821   if (theArgsNb < 2)
4822   {
4823     theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n";
4824     return 1;
4825   }
4826
4827   TCollection_AsciiString aCommand (theArgVec[1]);
4828
4829   // print maximum number of planes for current viewer
4830   if (aCommand == "maxplanes")
4831   {
4832     if (theArgsNb < 3)
4833     {
4834       theDi << theArgVec[0] << ": view name is required. Type help for more information.\n";
4835       return 1;
4836     }
4837
4838     TCollection_AsciiString aViewName (theArgVec[2]);
4839
4840     if (!ViewerTest_myViews.IsBound1 (aViewName))
4841     {
4842       theDi << theArgVec[0] << ": view is not found.\n";
4843       return 1;
4844     }
4845
4846     const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
4847
4848     theDi << theArgVec[0] << ": "
4849                           << aView->Viewer()->Driver()->InquirePlaneLimit()
4850                           << " plane slots provided by driver."
4851                           << " Note that 2 more planes might be used (reserved for z-clipping).\n";
4852
4853     return 0;
4854   }
4855
4856   // create / delete plane instance
4857   if (aCommand == "create" || aCommand == "delete" || aCommand == "clone")
4858   {
4859     if (theArgsNb < 3)
4860     {
4861       theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n";
4862       return 1;
4863     }
4864
4865     Standard_Boolean toCreate = (aCommand == "create");
4866     Standard_Boolean toClone  = (aCommand == "clone");
4867     TCollection_AsciiString aPlane (theArgVec[2]);
4868
4869     if (toCreate)
4870     {
4871       if (aRegPlanes.IsBound (aPlane))
4872       {
4873         theDi << theArgVec[0] << ": plane name is in use.\n";
4874         return 1;
4875       }
4876
4877       aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
4878     }
4879     else if (toClone) // toClone
4880     {
4881       if (!aRegPlanes.IsBound (aPlane))
4882       {
4883         theDi << theArgVec[0] << ": no such plane.\n";
4884         return 1;
4885       }
4886
4887       if (theArgsNb < 4)
4888       {
4889         theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n";
4890         return 1;
4891       }
4892
4893       TCollection_AsciiString aClone (theArgVec[3]);
4894       if (aRegPlanes.IsBound (aClone))
4895       {
4896         theDi << theArgVec[0] << ": plane name is in use.\n";
4897         return 1;
4898       }
4899
4900       const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
4901
4902       aRegPlanes.Bind (aClone, aClipPlane->Clone());
4903     }
4904     else// toDelete
4905     {
4906       if (!aRegPlanes.IsBound (aPlane))
4907       {
4908         theDi << theArgVec[0] << ": no such plane.\n";
4909         return 1;
4910       }
4911
4912       Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane);
4913       aRegPlanes.UnBind (aPlane);
4914
4915       ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
4916       for (; anIObjIt.More(); anIObjIt.Next())
4917       {
4918         Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
4919         aPrs->RemoveClipPlane(aClipPlane);
4920       }
4921
4922       NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
4923       for (; aViewIt.More(); aViewIt.Next())
4924       {
4925         const Handle(V3d_View)& aView = aViewIt.Key2();
4926         aView->RemoveClipPlane(aClipPlane);
4927       }
4928
4929       ViewerTest::RedrawAllViews();
4930     }
4931
4932     return 0;
4933   }
4934
4935   // set / unset plane command
4936   if (aCommand == "set" || aCommand == "unset")
4937   {
4938     if (theArgsNb < 4)
4939     {
4940       theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
4941       return 1;
4942     }
4943
4944     Standard_Boolean toSet = (aCommand == "set");
4945     TCollection_AsciiString aPlane (theArgVec [2]);
4946     if (!aRegPlanes.IsBound (aPlane))
4947     {
4948       theDi << theArgVec[0] << ": no such plane.\n";
4949       return 1;
4950     }
4951
4952     const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
4953
4954     TCollection_AsciiString aTarget (theArgVec [3]);
4955     if (aTarget != "object" && aTarget != "view")
4956     {
4957       theDi << theArgVec[0] << ": invalid target.\n";
4958       return 1;
4959     }
4960
4961     if (aTarget == "object" || aTarget == "view")
4962     {
4963       if (theArgsNb < 5)
4964       {
4965         theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
4966         return 1;
4967       }
4968
4969       Standard_Boolean isObject = (aTarget == "object");
4970
4971       for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
4972       {
4973         TCollection_AsciiString anEntityName (theArgVec[anIt]);
4974         if (isObject) // to object
4975         {
4976           if (!GetMapOfAIS().IsBound2 (anEntityName))
4977           {
4978             theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n";
4979             continue;
4980           }
4981
4982           Handle(AIS_InteractiveObject) aIObj =
4983             Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
4984
4985           if (toSet)
4986             aIObj->AddClipPlane (aClipPlane);
4987           else
4988             aIObj->RemoveClipPlane (aClipPlane);
4989         }
4990         else // to view
4991         {
4992           if (!ViewerTest_myViews.IsBound1 (anEntityName))
4993           {
4994             theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n";
4995             continue;
4996           }
4997
4998           Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName);
4999           if (toSet)
5000             aView->AddClipPlane (aClipPlane);
5001           else
5002             aView->RemoveClipPlane (aClipPlane);
5003         }
5004       }
5005
5006       ViewerTest::RedrawAllViews();
5007     }
5008
5009     return 0;
5010   }
5011
5012   // change plane command
5013   if (aCommand == "change")
5014   {
5015     if (theArgsNb < 4)
5016     {
5017       theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5018       return 1;
5019     }
5020
5021     TCollection_AsciiString aPlane (theArgVec [2]);
5022     if (!aRegPlanes.IsBound (aPlane))
5023     {
5024       theDi << theArgVec[0] << ": no such plane.\n";
5025       return 1;
5026     }
5027
5028     const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5029
5030     TCollection_AsciiString aChangeArg (theArgVec [3]);
5031     if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation")
5032     {
5033       theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5034       return 1;
5035     }
5036
5037     if (aChangeArg == "on" || aChangeArg == "off") // on / off
5038     {
5039       aClipPlane->SetOn (aChangeArg == "on");
5040     }
5041     else if (aChangeArg == "equation") // change equation
5042     {
5043       if (theArgsNb < 8)
5044       {
5045         theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5046         return 1;
5047       }
5048
5049       Standard_Real aCoeffA = atof (theArgVec [4]);
5050       Standard_Real aCoeffB = atof (theArgVec [5]);
5051       Standard_Real aCoeffC = atof (theArgVec [6]);
5052       Standard_Real aCoeffD = atof (theArgVec [7]);
5053       aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
5054     }
5055     else if (aChangeArg == "capping") // change capping aspects
5056     {
5057       if (theArgsNb < 5)
5058       {
5059         theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5060         return 1;
5061       }
5062
5063       TCollection_AsciiString aCappingArg (theArgVec [4]);
5064       if (aCappingArg != "on" && aCappingArg != "off" &&
5065           aCappingArg != "color" && aCappingArg != "texname" &&
5066           aCappingArg != "texscale" && aCappingArg != "texorigin" &&
5067           aCappingArg != "texrotate" && aCappingArg != "hatch")
5068       {
5069         theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
5070         return 1;
5071       }
5072
5073       if (aCappingArg == "on" || aCappingArg == "off") // on / off capping
5074       {
5075         aClipPlane->SetCapping (aCappingArg == "on");
5076       }
5077       else if (aCappingArg == "color") // color aspect for capping
5078       {
5079         if (theArgsNb < 8)
5080         {
5081           theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5082           return 1;
5083         }
5084
5085         Standard_Real aRed = atof (theArgVec [5]);
5086         Standard_Real aGrn = atof (theArgVec [6]);
5087         Standard_Real aBlu = atof (theArgVec [7]);
5088
5089         Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
5090         aMat.SetColor (Quantity_Color (aRed, aGrn, aBlu, Quantity_TOC_RGB));
5091         aClipPlane->SetCappingMaterial (aMat);
5092       }
5093       else if (aCappingArg == "texname") // texture name
5094       {
5095         if (theArgsNb < 6)
5096         {
5097           theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5098           return 1;
5099         }
5100
5101         TCollection_AsciiString aTextureName (theArgVec [5]);
5102
5103         Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
5104         if (!aTexture->IsDone ())
5105         {
5106           aClipPlane->SetCappingTexture (NULL);
5107         }
5108         else
5109         {
5110           aTexture->EnableModulate();
5111           aTexture->EnableRepeat();
5112           aClipPlane->SetCappingTexture (aTexture);
5113         }
5114       }
5115       else if (aCappingArg == "texscale") // texture scale
5116       {
5117         if (aClipPlane->CappingTexture().IsNull())
5118         {
5119           theDi << theArgVec[0] << ": no texture is set.\n";
5120           return 1;
5121         }
5122
5123         if (theArgsNb < 7)
5124         {
5125           theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5126           return 1;
5127         }
5128
5129         Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]);
5130         Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]);
5131
5132         aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
5133       }
5134       else if (aCappingArg == "texorigin") // texture origin
5135       {
5136         if (aClipPlane->CappingTexture().IsNull())
5137         {
5138           theDi << theArgVec[0] << ": no texture is set.\n";
5139           return 1;
5140         }
5141
5142         if (theArgsNb < 7)
5143         {
5144           theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5145           return 1;
5146         }
5147
5148         Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]);
5149         Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]);
5150
5151         aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
5152       }
5153       else if (aCappingArg == "texrotate") // texture rotation
5154       {
5155         if (aClipPlane->CappingTexture().IsNull())
5156         {
5157           theDi << theArgVec[0] << ": no texture is set.\n";
5158           return 1;
5159         }
5160
5161         if (theArgsNb < 6)
5162         {
5163           theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5164           return 1;
5165         }
5166
5167         Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]);
5168
5169         aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
5170       }
5171       else if (aCappingArg == "hatch") // hatch style
5172       {
5173         if (theArgsNb < 6)
5174         {
5175           theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5176           return 1;
5177         }
5178
5179         TCollection_AsciiString aHatchStr (theArgVec [5]);
5180         if (aHatchStr == "on")
5181         {
5182           aClipPlane->SetCappingHatchOn();
5183         }
5184         else if (aHatchStr == "off")
5185         {
5186           aClipPlane->SetCappingHatchOff();
5187         }
5188         else
5189         {
5190           aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5]));
5191         }
5192       }
5193     }
5194
5195     ViewerTest::RedrawAllViews();
5196
5197     return 0;
5198   }
5199
5200   theDi << theArgVec[0] << ": invalid command. Type help for more information.\n";
5201   return 1;
5202 }
5203
5204 //===============================================================================================
5205 //function : VSetTextureMode
5206 //purpose  :
5207 //===============================================================================================
5208 static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5209 {
5210   if (theArgsNb < 3)
5211   {
5212     theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n";
5213     return 1;
5214   }
5215
5216   TCollection_AsciiString aViewName (theArgVec[1]);
5217   if (!ViewerTest_myViews.IsBound1 (aViewName))
5218   {
5219     theDi << theArgVec[0] << ": view is not found.\n";
5220     return 1;
5221   }
5222
5223   const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
5224   switch (atoi (theArgVec[2]))
5225   {
5226     case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break;
5227     case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break;
5228     case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break;
5229     default:
5230       theDi << theArgVec[0] << ": invalid mode.\n";
5231       return 1;
5232   }
5233
5234   aView->Redraw();
5235   return 0;
5236 }
5237
5238 //=======================================================================
5239 //function : ViewerCommands
5240 //purpose  :
5241 //=======================================================================
5242
5243 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
5244 {
5245
5246   const char *group = "ZeViewer";
5247   theCommands.Add("vinit",
5248 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
5249     "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
5250 #else
5251     "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
5252 #endif
5253     " - Creates new View window with specified name view_name.\n"
5254     "By default the new view is created in the viewer and in"
5255     " graphic driver shared with active view.\n"
5256     " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
5257     "If driverName isn't specified the driver will be shared with active view.\n"
5258     "If viewerName isn't specified the viewer will be shared with active view.\n"
5259 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
5260     " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
5261     "is used in creation of graphic driver\n"
5262 #endif
5263     " - l, t: pixel position of left top corner of the window\n"
5264     " - w,h: width and heigth of window respectively.\n"
5265     "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
5266     __FILE__,VInit,group);
5267   theCommands.Add("vclose" ,
5268     "view_id [keep_context=0|1]\n"
5269     "or vclose ALL - to remove all created views\n"
5270     " - removes view(viewer window) defined by its view_id.\n"
5271     " - keep_context: by default 0; if 1 and the last view is deleted"
5272     " the current context is not removed.",
5273     __FILE__,VClose,group);
5274   theCommands.Add("vactivate" ,
5275     "view_id"
5276     " - activates view(viewer window) defined by its view_id",
5277     __FILE__,VActivate,group);
5278   theCommands.Add("vviewlist",
5279     "vviewlist [format={tree, long}]"
5280     " - prints current list of views per viewer and graphic_driver ID shared between viewers"
5281     " - format: format of result output, if tree the output is a tree view;"
5282     "otherwise it's a list of full view names. By default format = tree",
5283     __FILE__,VViewList,group);
5284   theCommands.Add("vhelp" ,
5285     "vhelp            : display help on the viewer commands",
5286     __FILE__,VHelp,group);
5287   theCommands.Add("vtop" ,
5288     "vtop or <T>      : Top view" ,
5289     __FILE__,VTop,group);
5290   theCommands.Add("vbottom" ,
5291     "vbottom          : Bottom view" ,
5292     __FILE__,VBottom,group);
5293   theCommands.Add("vleft" ,
5294     "vleft            : Left view" ,
5295     __FILE__,VLeft,group);
5296   theCommands.Add("vright" ,
5297     "vright           : Right view" ,
5298     __FILE__,VRight,group);
5299   theCommands.Add("vaxo" ,
5300     " vaxo or <A>     : Axonometric view ",
5301     __FILE__,VAxo,group);
5302   theCommands.Add("vfront" ,
5303     "vfront           : Front view" ,
5304     __FILE__,VFront,group);
5305   theCommands.Add("vback" ,
5306     "vback            : Back view" ,
5307     __FILE__,VBack,group);
5308   theCommands.Add("vpick" ,
5309     "vpick           : vpick X Y Z [shape subshape] ( all variables as string )",
5310     VPick,group);
5311   theCommands.Add("vfit"    ,
5312     "vfit or <F>         : vfit",
5313     __FILE__,VFit,group);
5314   theCommands.Add("vzfit"    ,
5315     "vzfit",
5316     __FILE__,VZFit,group);
5317   theCommands.Add("vrepaint",
5318     "vrepaint        : vrepaint, force redraw",
5319     __FILE__,VRepaint,group);
5320   theCommands.Add("vclear",
5321     "vclear          : vclear",
5322     __FILE__,VClear,group);
5323   theCommands.Add("vsetbg",
5324     "vsetbg          : vsetbg imagefile [filltype] : Load image as background",
5325     __FILE__,VSetBg,group);
5326   theCommands.Add("vsetbgmode",
5327     "vsetbgmode      : vsetbgmode filltype : Change background image fill type",
5328     __FILE__,VSetBgMode,group);
5329   theCommands.Add("vsetgradientbg",
5330     "vsetgradientbg  : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
5331     __FILE__,VSetGradientBg,group);
5332   theCommands.Add("vsetgrbgmode",
5333     "vsetgrbgmode    : vsetgrbgmode filltype : Change gradient background fill type",
5334     __FILE__,VSetGradientBgMode,group);
5335   theCommands.Add("vsetcolorbg",
5336     "vsetcolorbg     : vsetcolorbg r g b : Set background color",
5337     __FILE__,VSetColorBg,group);
5338   theCommands.Add("vscale",
5339     "vscale          : vscale X Y Z",
5340     __FILE__,VScale,group);
5341   theCommands.Add("vzbufftrihedron",
5342     "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
5343     " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
5344     " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
5345     __FILE__,VTestZBuffTrihedron,group);
5346   theCommands.Add("vrotate",
5347     "vrotate         : vrotate AX AY AZ [X Y Z]",
5348     __FILE__,VRotate,group);
5349   theCommands.Add("vzoom",
5350     "vzoom           : vzoom coef",
5351     __FILE__,VZoom,group);
5352   theCommands.Add("vpan",
5353     "vpan            : vpan dx dy",
5354     __FILE__,VPan,group);
5355   theCommands.Add("vexport",
5356     "vexport         : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
5357     " : exports the view to a vector file of a given format"
5358     " : notice that EMF format requires patched gl2ps",
5359     __FILE__,VExport,group);
5360   theCommands.Add("vcolorscale",
5361     "vcolorscale     : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
5362     __FILE__,VColorScale,group);
5363   theCommands.Add("vgraduatedtrihedron",
5364     "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
5365     __FILE__,VGraduatedTrihedron,group);
5366   theCommands.Add("vprintview" ,
5367     "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
5368     __FILE__,VPrintView,group);
5369   theCommands.Add("vzlayer",
5370     "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
5371     __FILE__,VZLayer,group);
5372   theCommands.Add("voverlaytext",
5373     "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
5374     " : height - pixel height of the text (default=10.0)"
5375     " : font_name - name of font (default=courier)"
5376     " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
5377     " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
5378     " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
5379     __FILE__,VOverlayText,group);
5380   theCommands.Add("vlayerline",
5381     "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
5382     __FILE__,VLayerLine,group);
5383   theCommands.Add ("vgrid",
5384     "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
5385     " : Mode - rectangular or circular"
5386     " : Type - lines or points",
5387     __FILE__, VGrid, group);
5388   theCommands.Add ("vfps",
5389     "vfps [framesNb=100] : estimate average frame rate for active view",
5390     __FILE__, VFps, group);
5391   theCommands.Add ("vgldebug",
5392     "vgldebug [{0|1}] : request debug GL context, should be called before vinit\n"
5393     "                : this function is implemented only for Windows\n"
5394     "                : GL_ARB_debug_output extension should be exported by OpenGL driver!",
5395     __FILE__, VGlDebug, group);
5396   theCommands.Add ("vvbo",
5397     "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
5398     __FILE__, VVbo, group);
5399   theCommands.Add ("vcaps",
5400     "vcaps [vbo={0|1}] [sprites={0|1}] [soft={0|1}] : modify particular graphic driver options",
5401     __FILE__, VCaps, group);
5402   theCommands.Add ("vmemgpu",
5403     "vmemgpu [f]: print system-dependent GPU memory information if available;"
5404     " with f option returns free memory in bytes",
5405     __FILE__, VMemGpu, group);
5406   theCommands.Add ("vreadpixel",
5407     "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
5408     " : Read pixel value for active view",
5409     __FILE__, VReadPixel, group);
5410   theCommands.Add("diffimage",
5411     "diffimage     : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
5412     __FILE__, VDiffImage, group);
5413   theCommands.Add ("vselect",
5414     "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
5415     "- emulates different types of selection:\n"
5416     "- 1) single click selection\n"
5417     "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
5418     "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
5419     "- 4) any of these selections with shift button pressed",
5420     __FILE__, VSelect, group);
5421   theCommands.Add ("vmoveto",
5422     "vmoveto x y"
5423     "- emulates cursor movement to pixel postion (x,y)",
5424     __FILE__, VMoveTo, group);
5425   theCommands.Add("vviewparams",
5426     "vviewparams [scale center_X center_Y proj_X proj_Y proj_Z up_X up_Y up_Z at_X at_Y at_Z]"
5427     "- gets or sets current view characteristics",
5428     __FILE__,VViewParams, group);
5429   theCommands.Add("vchangeselected",
5430     "vchangeselected shape"
5431     "- adds to shape to selection or remove one from it",
5432                 __FILE__, VChangeSelected, group);
5433   theCommands.Add("vzclipping",
5434     "vzclipping [mode] [depth width]\n"
5435     "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
5436     "- gets or sets ZClipping mode, width and depth",
5437     __FILE__,VZClipping,group);
5438   theCommands.Add ("vnbselected",
5439     "vnbselected", __FILE__, VNbSelected, group);
5440   theCommands.Add("vantialiasing",
5441     "vantialiasing 1|0",
5442     __FILE__,VAntialiasing,group);
5443   theCommands.Add ("vpurgedisplay",
5444     "vpurgedisplay"
5445     "- removes structures which don't belong to objects displayed in neutral point",
5446     __FILE__, VPurgeDisplay, group);
5447   theCommands.Add("vsetviewsize",
5448     "vsetviewsize size",
5449     __FILE__,VSetViewSize,group);
5450   theCommands.Add("vmoveview",
5451     "vmoveview Dx Dy Dz [Start = 1|0]",
5452     __FILE__,VMoveView,group);
5453   theCommands.Add("vtranslateview",
5454     "vtranslateview Dx Dy Dz [Start = 1|0)]",
5455     __FILE__,VTranslateView,group);
5456   theCommands.Add("vturnview",
5457     "vturnview Ax Ay Az [Start = 1|0]",
5458     __FILE__,VTurnView,group);
5459   theCommands.Add("vtextureenv",
5460     "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
5461     "or user-defined file and optionally applying texture mapping parameters\n"
5462     "                  Usage:\n"
5463     "                  vtextureenv off - disables environment mapping\n"
5464     "                  vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
5465     "                              std_texture = (0..7)\n"
5466     "                              rep         = {clamp|repeat}\n"
5467     "                              mod         = {decal|modulate}\n"
5468     "                              flt         = {nearest|bilinear|trilinear}\n"
5469     "                              ss, st      - scale factors for s and t texture coordinates\n"
5470     "                              ts, tt      - translation for s and t texture coordinates\n"
5471     "                              rot         - texture rotation angle in degrees",
5472     __FILE__, VTextureEnv, group);
5473   theCommands.Add("vhlr" ,
5474     "is_enabled={on|off}"
5475     " - Hidden line removal algorithm:"
5476     " - is_enabled: if is on HLR algorithm is applied\n",
5477     __FILE__,VHLR,group);
5478   theCommands.Add("vhlrtype" ,
5479     "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
5480     " - Changes the type of HLR algorithm using for shapes."
5481     " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
5482     "   if equals to polyalgo, polygonal HLR algorithm is applied."
5483     "If shapes are not given HLR algoithm of given type is applied"
5484     " to all shapes in the view\n",
5485     __FILE__,VHLRType,group);
5486   theCommands.Add("vclipplane", "vclipplane usage: \n"
5487     "  maxplanes <view_name> - get plane limit for view.\n"
5488     "  create <plane_name> - create new plane.\n"
5489     "  delete <plane_name> - delete plane.\n"
5490     "  clone <source_plane> <plane_name> - clone the plane definition.\n"
5491     "  set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
5492     "  set/unset <plane_name> view <view list> - set/unset plane for view.\n"
5493     "  change <plane_name> on/off - turn clipping on/off.\n"
5494     "  change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
5495     "  change <plane_name> capping on/off - turn capping on/off.\n"
5496     "  change <plane_name> capping color <r> <g> <b> - set color.\n"
5497     "  change <plane name> capping texname <texture> - set texture.\n"
5498     "  change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
5499     "  change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
5500     "  change <plane_name> capping texrotate <angle> - set tex rotation.\n"
5501     "  change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
5502     "  please use VSetTextureMode command to enable texture rendering in view.\n"
5503     , __FILE__, VClipPlane, group);
5504   theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
5505     "  mode can be:\n"
5506     "  0 - no textures enabled in view.\n"
5507     "  1 - only environment textures enabled.\n"
5508     "  2 - all textures enabled.\n"
5509     "  this command sets texture details mode for the specified view.\n"
5510     , __FILE__, VSetTextureMode, group);
5511 }