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