0024312: Compilation issues on OS X 10.9 Maverics SDK
[occt.git] / src / ViewerTest / ViewerTest_ViewerCommands.cxx
index 271371e..f764a1f 100755 (executable)
 // purpose or non-infringement. Please see the License for the specific terms
 // and conditions governing the rights and limitations under the License.
 
-
-// Robert Boehne 30 May 2000 : Dec Osf
-
 #ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#ifdef WNT
-#include <windows.h>
+  #include <config.h>
 #endif
 
+#include <OpenGl_GlCore20.hxx>
 #include <AIS_Shape.hxx>
 #include <AIS_Drawer.hxx>
 #include <AIS_InteractiveObject.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 #include <DBRep.hxx>
 #include <Graphic3d_AspectMarker3d.hxx>
-#include <Graphic3d_GraphicDriver.hxx>
 #include <Graphic3d_ExportFormat.hxx>
 #include <Graphic3d_NameOfTextureEnv.hxx>
 #include <Graphic3d_TextureEnv.hxx>
 #include <Graphic3d_TextureParams.hxx>
 #include <Graphic3d_TypeOfTextureFilter.hxx>
+#include <Graphic3d_AspectFillArea3d.hxx>
 #include <ViewerTest.hxx>
 #include <ViewerTest_EventManager.hxx>
 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
+#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
 #include <Visual3d_View.hxx>
 #include <Visual3d_ViewManager.hxx>
 #include <V3d_LayerMgr.hxx>
@@ -60,6 +55,7 @@
 #include <Draw_Appli.hxx>
 #include <Aspect_PrintAlgo.hxx>
 #include <Image_AlienPixMap.hxx>
+#include <OpenGl_GraphicDriver.hxx>
 #include <OSD_Timer.hxx>
 #include <TColStd_SequenceOfInteger.hxx>
 #include <TColStd_HSequenceOfReal.hxx>
 #include <Image_Diff.hxx>
 #include <Aspect_DisplayConnection.hxx>
 #include <Graphic3d.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_Dir.hxx>
+#include <gp_Pln.hxx>
+#include <PrsMgr_PresentableObject.hxx>
+#include <Graphic3d_ClipPlane.hxx>
+#include <NCollection_DataMap.hxx>
+#include <Graphic3d_Texture2Dmanual.hxx>
+#include <Prs3d_ShadingAspect.hxx>
 
 #ifdef WNT
 #undef DrawText
@@ -79,7 +83,7 @@
 #include <Visual3d_Layer.hxx>
 #include <cstdlib>
 
-#if defined(_WIN32) || defined(__WIN32__)
+#if defined(_WIN32)
   #include <WNT_WClass.hxx>
   #include <WNT_Window.hxx>
 
@@ -89,7 +93,6 @@
   #endif
 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
   #include <Cocoa_Window.hxx>
-  #include <tk.h>
 #else
   #include <Xw_Window.hxx>
   #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
   #include <tk.h>
 #endif
 
-//==============================================================================
+// Auxiliary definitions
+static const char THE_KEY_DELETE = 127;
 
 //==============================================================================
 //  VIEWER GLOBAL VARIABLES
 //==============================================================================
 
 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
+Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
 
 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
 extern const Handle(NIS_InteractiveContext)& TheNISContext();
 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
 
-#if defined(_WIN32) || defined(__WIN32__)
+extern int VErase (Draw_Interpretor& theDI,
+                   Standard_Integer  theArgNb,
+                   const char**      theArgVec);
+
+#if defined(_WIN32)
 static Handle(WNT_Window)& VT_GetWindow() {
   static Handle(WNT_Window) WNTWin;
   return WNTWin;
@@ -144,11 +153,11 @@ static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDis
   GetDisplayConnection() = theDisplayConnection;
 }
 
-#if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
+#if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
 {
-  Aspect_Handle aWindowHandle = NULL;
-#if defined(_WIN32) || defined(__WIN32__)
+  Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
+#if defined(_WIN32)
   const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
   if (!aWindow.IsNull())
     return aWindow->HWindow();
@@ -164,9 +173,9 @@ Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
 static Standard_Boolean MyHLRIsOn = Standard_False;
 
 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
-static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
+static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>  ViewerTest_myContexts;
 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
-
+static OpenGl_Caps ViewerTest_myDefaultCaps;
 
 #define ZCLIPWIDTH 1.
 
@@ -209,7 +218,7 @@ static LRESULT WINAPI AdvViewerWindowProc(
 const Handle(MMgt_TShared)& ViewerTest::WClass()
 {
   static Handle(MMgt_TShared) theWClass;
-#if defined(_WIN32) || defined(__WIN32__)
+#if defined(_WIN32)
   if (theWClass.IsNull())
   {
     theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
@@ -409,7 +418,7 @@ Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theVie
 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
                      Standard_CString theTitle)
 {
-#if defined(_WIN32) || defined(__WIN32__)
+#if defined(_WIN32)
   SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
     theTitle);
 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
@@ -488,15 +497,13 @@ TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft
   // window fit in the small screens (actual for remote desktops, see #23003).
   // The position corresponds to the window's client area, thus some
   // gap is added for window frame to be visible.
-
   Standard_Integer aPxLeft   = 20;
   Standard_Integer aPxTop    = 40;
   Standard_Integer aPxWidth  = 409;
   Standard_Integer aPxHeight = 409;
   Standard_Boolean toCreateViewer = Standard_False;
 
-
-  Handle(Graphic3d_GraphicDriver) aGraphicDriver;
+  Handle(OpenGl_GraphicDriver) aGraphicDriver;
   ViewerTest_Names aViewNames(theViewName);
   if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
     aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
@@ -509,28 +516,29 @@ TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft
     aPxWidth = thePxWidth;
   if (thePxHeight != 0)
     aPxHeight = thePxHeight;
+
   // Get graphic driver (create it or get from another view)
   if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
   {
     // Get connection string
-  #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
+  #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
     TCollection_AsciiString aDisplayName(theDisplayName);
-    if (aDisplayName.IsEmpty())
+    if (!aDisplayName.IsEmpty())
       SetDisplayConnection (new Aspect_DisplayConnection ());
     else
       SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
-
   #else
+    (void)theDisplayName; // avoid warning on unused argument
     SetDisplayConnection (new Aspect_DisplayConnection ());
   #endif
-    aGraphicDriver = Graphic3d::InitGraphicDriver (GetDisplayConnection());
+    aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
+    aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
     ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
     toCreateViewer = Standard_True;
   }
   else
   {
-    aGraphicDriver = ViewerTest_myDrivers.Find1(aViewNames.GetDriverName());
+    aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
   }
 
   //Dispose the window if input parameters are default
@@ -558,8 +566,8 @@ TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft
 #endif
 
     TCollection_AsciiString anOverlappedViewId("");
-    Standard_Boolean isOverlapped = Standard_False;
-    while (isOverlapped = IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
+
+    while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
     {
       ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
 
@@ -594,7 +602,7 @@ TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft
   }
 
   // Create viewer
-  Handle(V3d_Viewer) a3DViewer, a3DCollector;
+  Handle(V3d_Viewer) a3DViewer;
   // If it's the single view, we first look for empty context
   if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
   {
@@ -603,25 +611,21 @@ TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft
     if (anIter.More())
       ViewerTest::SetAISContext (anIter.Value());
     a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
-    a3DCollector= ViewerTest::GetAISContext()->Collector();
   }
   else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
   {
     ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
     a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
-    a3DCollector= ViewerTest::GetAISContext()->Collector();
   }
-  else if (a3DViewer.IsNull() || a3DCollector.IsNull())
+  else if (a3DViewer.IsNull())
   {
     toCreateViewer = Standard_True;
     TCollection_ExtendedString NameOfWindow("Viewer3D");
     a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
 
     NameOfWindow = TCollection_ExtendedString("Collector");
-    a3DCollector = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
 
     a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
-    a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
   }
 
   // AIS context setup
@@ -629,7 +633,7 @@ TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft
       !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
   {
     Handle(AIS_InteractiveContext) aContext =
-      new AIS_InteractiveContext(a3DViewer, a3DCollector);
+      new AIS_InteractiveContext(a3DViewer);
     ViewerTest::SetAISContext (aContext);
     ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
   }
@@ -640,7 +644,7 @@ TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft
 #if defined(_WIN32) || defined(__WIN32__)
       VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
                                        Handle(WNT_WClass)::DownCast (WClass()),
-                                       WS_OVERLAPPEDWINDOW,
+                                       Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW,
                                        aPxLeft, aPxTop,
                                        aPxWidth, aPxHeight,
                                        Quantity_NOC_BLACK);
@@ -659,7 +663,7 @@ TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft
 
   // NIS setup
   Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
-  
+
   ViewerTest::CurrentView(aView);
   ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
   TheNISContext()->AttachView (aView);
@@ -692,7 +696,7 @@ TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft
   #endif
 
   VT_GetWindow()->Map();
-  
+
   // Set the handle of created view in the event manager
   ViewerTest::ResetEventManager();
 
@@ -700,18 +704,31 @@ TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft
 
   aView.Nullify();
   a3DViewer.Nullify();
-  a3DCollector.Nullify();
 
   return aViewNames.GetViewName();
 }
 
 //==============================================================================
-//function : SplitParameter
-//purpose  : Split parameter string to parameter name an patameter value
+//function : RedrawAllViews
+//purpose  : Redraw all created views
+//==============================================================================
+void ViewerTest::RedrawAllViews()
+{
+  NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
+  for (; aViewIt.More(); aViewIt.Next())
+  {
+    const Handle(V3d_View)& aView = aViewIt.Key2();
+    aView->Redraw();
+  }
+}
+
+//==============================================================================
+//function : splitParameter
+//purpose  : Split parameter string to parameter name an parameter value
 //==============================================================================
-Standard_Boolean SplitParameter (const TCollection_AsciiString& theString,
-                                      TCollection_AsciiString& theName,
-                                      TCollection_AsciiString& theValue)
+Standard_Boolean splitParameter (const TCollection_AsciiString& theString,
+                                 TCollection_AsciiString&       theName,
+                                 TCollection_AsciiString&       theValue)
 {
   Standard_Integer aParamNameEnd = theString.FirstLocationInSet("=",1, theString.Length());
   if (aParamNameEnd == 0)
@@ -750,7 +767,7 @@ if (theArgsNb > 9)
   for (Standard_Integer i = 1; i < theArgsNb; ++i)
   {
     TCollection_AsciiString aName = "", aValue = "";
-    if(!SplitParameter (TCollection_AsciiString(theArgVec[i]),aName,aValue) && theArgsNb == 2)
+    if(!splitParameter (TCollection_AsciiString(theArgVec[i]),aName,aValue) && theArgsNb == 2)
     {
       // In case of syntax: vinit ViewName
       aViewName = theArgVec[1];
@@ -1060,44 +1077,56 @@ void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const S
 //purpose  : Remove the view defined by its name
 //==============================================================================
 
-static int VClose (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
+static int VClose (Draw_Interpretor& /*theDi*/,
+                   Standard_Integer  theArgsNb,
+                   const char**      theArgVec)
 {
-  if (theArgsNb < 2)
-  {
-    theDi << theArgVec[0] << ": incorrect number of command arguments.\n"
-      << "Type help " << theArgVec[0] << " for more information.\n";
-    return 1;
-  }
-
-  if (ViewerTest_myViews.IsEmpty())
-  {
-    theDi << theArgVec[0] <<": there is no views to close.\n";
-    return 0;
-  }
-
-  TCollection_AsciiString anInputString(theArgVec[1]);
-  
-  // Create list to iterate and remove views from the map of views
   NCollection_List<TCollection_AsciiString> aViewList;
-  if (TCollection_AsciiString::ISSIMILAR (anInputString, TCollection_AsciiString("ALL")))
+  if (theArgsNb > 1)
   {
-    for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter(ViewerTest_myViews);
-         anIter.More(); anIter.Next())
+    TCollection_AsciiString anArg (theArgVec[1]);
+    anArg.UpperCase();
+    if (anArg.IsEqual ("ALL")
+     || anArg.IsEqual ("*"))
+    {
+      for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
+           anIter.More(); anIter.Next())
+      {
+        aViewList.Append (anIter.Key1());
+      }
+      if (aViewList.IsEmpty())
+      {
+        std::cout << "No view to close\n";
+        return 0;
+      }
+    }
+    else
     {
-      aViewList.Append(anIter.Key1());
+      ViewerTest_Names aViewName (theArgVec[1]);
+      if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
+      {
+        std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
+        return 1;
+      }
+      aViewList.Append (aViewName.GetViewName());
     }
   }
   else
   {
-    ViewerTest_Names aViewNames(anInputString);
-    aViewList.Append(aViewNames.GetViewName());
+    // close active view
+    if (ViewerTest::CurrentView().IsNull())
+    {
+      std::cerr << "No active view!\n";
+      return 1;
+    }
+    aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
   }
 
-  Standard_Boolean isContextRemoved = (theArgsNb == 3 && atoi(theArgVec[2])==1) ? Standard_False : Standard_True;
+  Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
   for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
        anIter.More(); anIter.Next())
   {
-    ViewerTest::RemoveView(anIter.Value(), isContextRemoved);
+    ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
   }
 
   return 0;
@@ -1123,7 +1152,7 @@ static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const
   }
 
   TCollection_AsciiString aNameString(theArgVec[1]);
-  if (TCollection_AsciiString::ISSIMILAR (aNameString, TCollection_AsciiString("NONE")))
+  if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
   {
     TCollection_AsciiString aTitle("3D View - ");
     aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
@@ -1174,16 +1203,14 @@ static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const
   if (theArgsNb > 2)
   {
     theDi << theArgVec[0] << ": Wrong number of command arguments\n"
-      << "Usage: " << theArgVec[0];
+          << "Usage: " << theArgVec[0] << " name";
     return 1;
   }
   if (ViewerTest_myContexts.Size() < 1)
     return 0;
 
-  TCollection_AsciiString aNameString(theArgsNb==2?theArgVec[1]:"");
   Standard_Boolean isTreeView =
-    TCollection_AsciiString::ISSIMILAR (aNameString, TCollection_AsciiString("long"))?
-    Standard_False:Standard_True;
+    (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
 
   if (isTreeView)
     theDi << theArgVec[0] <<":\n";
@@ -1241,28 +1268,33 @@ void VT_ProcessKeyPress (const char* buf_ret)
   const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
   // Letter in alphabetic order
 
-  if ( !strcasecmp(buf_ret, "A") ) {
+  if (!strcasecmp (buf_ret, "A"))
+  {
     // AXO
     aView->SetProj(V3d_XposYnegZpos);
   }
-  else if ( !strcasecmp(buf_ret, "D") ) {
+  else if (!strcasecmp (buf_ret, "D"))
+  {
     // Reset
     aView->Reset();
   }
-  else if ( !strcasecmp(buf_ret, "F") ) {
+  else if (!strcasecmp (buf_ret, "F"))
+  {
     // FitAll
     if (aNisView.IsNull())
       aView->FitAll();
     else
       aNisView->FitAll3d();
   }
-  else if ( !strcasecmp(buf_ret, "H") ) {
+  else if (!strcasecmp (buf_ret, "H"))
+  {
     // HLR
     cout << "HLR" << endl;
     aView->SetComputedMode (!aView->ComputedMode());
     MyHLRIsOn = aView->ComputedMode();
   }
-  else if ( !strcasecmp(buf_ret, "P") ) {
+  else if (!strcasecmp (buf_ret, "P"))
+  {
     // Type of HLR
     Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
     if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
@@ -1302,11 +1334,11 @@ void VT_ProcessKeyPress (const char* buf_ret)
     }
 
     aContext->UpdateCurrentViewer();
-    
+
   }
-  else if ( !strcasecmp(buf_ret, "S") ) {
-    // SHADING
-    cout << "passage en mode 1 (shading pour les shapes)" << endl;
+  else if (!strcasecmp (buf_ret, "S"))
+  {
+    std::cout << "setup Shaded display mode" << std::endl;
 
     Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
     if(Ctx->NbCurrents()==0 ||
@@ -1324,9 +1356,10 @@ void VT_ProcessKeyPress (const char* buf_ret)
       Ctx->UpdateCurrentViewer();
     }
   }
-  else if ( !strcasecmp(buf_ret, "U") ) {
+  else if (!strcasecmp (buf_ret, "U"))
+  {
     // Unset display mode
-    cout<<"passage au mode par defaut"<<endl;
+    std::cout << "reset display mode to defaults" << std::endl;
 
     Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
     if(Ctx->NbCurrents()==0 ||
@@ -1345,26 +1378,29 @@ void VT_ProcessKeyPress (const char* buf_ret)
     }
 
   }
-  else if ( !strcasecmp(buf_ret, "T") ) {
+  else if (!strcasecmp (buf_ret, "T"))
+  {
     // Top
     aView->SetProj(V3d_Zpos);
   }
-  else if ( !strcasecmp(buf_ret, "B") ) {
+  else if (!strcasecmp (buf_ret, "B"))
+  {
     // Bottom
     aView->SetProj(V3d_Zneg);
   }
-  else if ( !strcasecmp(buf_ret, "L") ) {
+  else if (!strcasecmp (buf_ret, "L"))
+  {
     // Left
     aView->SetProj(V3d_Xneg);
   }
-  else if ( !strcasecmp(buf_ret, "R") ) {
+  else if (!strcasecmp (buf_ret, "R"))
+  {
     // Right
     aView->SetProj(V3d_Xpos);
   }
-
-  else if ( !strcasecmp(buf_ret, "W") ) {
-    // WIREFRAME
-    cout << "passage en mode 0 (filaire pour les shapes)" << endl;
+  else if (!strcasecmp (buf_ret, "W"))
+  {
+    std::cout << "setup WireFrame display mode" << std::endl;
     Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
     if(Ctx->NbCurrents()==0 ||
       Ctx->NbSelected()==0)
@@ -1381,9 +1417,9 @@ void VT_ProcessKeyPress (const char* buf_ret)
       Ctx->UpdateCurrentViewer();
     }
   }
-  else if ( !strcasecmp(buf_ret, "Z") ) {
+  else if (!strcasecmp (buf_ret, "Z"))
+  {
     // ZCLIP
-
     if ( ZClipIsOn ) {
       cout << "ZClipping OFF" << endl;
       ZClipIsOn = 0;
@@ -1399,16 +1435,27 @@ void VT_ProcessKeyPress (const char* buf_ret)
       aView->Redraw();
     }
   }
-  else if ( !strcasecmp(buf_ret, ",") ) {
+  else if (!strcasecmp (buf_ret, ","))
+  {
     ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
-
-
   }
-  else if ( !strcasecmp(buf_ret, ".") ) {
+  else if (!strcasecmp (buf_ret, "."))
+  {
     ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
   }
-  // Number
-  else{
+  else if (*buf_ret == THE_KEY_DELETE)
+  {
+    Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
+    if (!aCtx.IsNull()
+     && aCtx->NbCurrents() > 0
+     && aCtx->NbSelected() > 0)
+    {
+      Draw_Interprete ("verase");
+    }
+  }
+  else
+  {
+    // Number
     Standard_Integer Num = Draw::Atoi(buf_ret);
     if(Num>=0 && Num<=7)
       ViewerTest::StandardModeActivation(Num);
@@ -1746,6 +1793,7 @@ static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
   di << "W : Wireframe" << "\n";
   di << "H : HidelLineRemoval" << "\n";
   di << "U : Unset display mode" << "\n";
+  di << "Delete : Remove selection from viewer" << "\n";
 
   di << "========================="<<"\n";
   di << "Selection mode "<<"\n";
@@ -1896,6 +1944,10 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
         char c[2];
         c[0] = (char) wParam;
         c[1] = '\0';
+        if (wParam == VK_DELETE)
+        {
+          c[0] = THE_KEY_DELETE;
+        }
         VT_ProcessKeyPress (c);
       }
       break;
@@ -1979,7 +2031,8 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
               }
           }
 #endif
-          else
+          else if (GetWindowHandle (VT_GetWindow()) == hwnd)
+          {
             if ((fwKeys & MK_MBUTTON
             || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
             {
@@ -1989,6 +2042,7 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
             {
               VT_ProcessMotion();
             }
+          }
       }
       break;
 
@@ -2010,7 +2064,7 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
 //==============================================================================
 
 
-static int ViewerMainLoop(Standard_Integer argc, const char** argv)
+int ViewerMainLoop(Standard_Integer argc, const char** argv)
 {
   Ppick = (argc > 0)? 1 : 0;
   Pargc = argc;
@@ -2056,7 +2110,7 @@ int max( int a, int b )
 
 int ViewerMainLoop(Standard_Integer argc, const char** argv)
 
-{ 
+{
   static XEvent aReport;
   Standard_Boolean pick = argc > 0;
   Display *aDisplay = GetDisplayConnection()->GetDisplay();
@@ -2191,6 +2245,10 @@ int ViewerMainLoop(Standard_Integer argc, const char** argv)
         break;
       case MotionNotify:
         {
+          if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
+          {
+            break;
+          }
           if( IsDragged )
           {
             Aspect_Handle aWindow = VT_GetWindow()->XWindow();
@@ -2274,13 +2332,13 @@ static void VProcessEvents(ClientData,int)
        anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
   {
     anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
-  } 
+  }
     // Handle events for every display
   int anEventIter = 0;
   for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
        anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
   {
-    for (int i = 0; i < anEventNumbers.Value(anEventIter) && 
+    for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
          XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
     {
       SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
@@ -2290,9 +2348,9 @@ static void VProcessEvents(ClientData,int)
        return;
     }
   }
-  
+
   SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
-  
+
 }
 #endif
 
@@ -2504,26 +2562,20 @@ static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char**
     di << "use 'vinit' command before " << argv[0] << "\n";
     return 1;
   }
-
-  Aspect_FillMethod aFillType;
-  if (argc == 2)
+  Aspect_FillMethod aFillType = Aspect_FM_NONE;
+  const char* szType = argv[1];
+  if      (strcmp(szType, "NONE"    ) == 0) aFillType = Aspect_FM_NONE;
+  else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
+  else if (strcmp(szType, "TILED"   ) == 0) aFillType = Aspect_FM_TILED;
+  else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
+  else
   {
-    const char* szType = argv[1];
-    if      (strcmp(szType, "NONE"    ) == 0) aFillType = Aspect_FM_NONE;
-    else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
-    else if (strcmp(szType, "TILED"   ) == 0) aFillType = Aspect_FM_TILED;
-    else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
-    else
-    {
-      di << "Wrong fill type : " << szType << "\n";
-      di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
-      return 1;
-    }
+    di << "Wrong fill type : " << szType << "\n";
+    di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
+    return 1;
   }
-
   Handle(V3d_View) V3dView = ViewerTest::CurrentView();
   V3dView->SetBgImageStyle(aFillType, Standard_True);
-
   return 0;
 }
 
@@ -3324,14 +3376,13 @@ private:
 
   Standard_Real            myX1;
   Standard_Real            myY1;
-  Standard_Real            myHeight;
   TCollection_AsciiString  myText;
-  TCollection_AsciiString  myFontName;
+  Standard_Real            myHeight;
+  Handle(Visual3d_Layer)   myLayer;
   Quantity_Color           myColor;
   Quantity_Color           mySubtitleColor;
   Aspect_TypeOfDisplayText myType;
-  Handle(Visual3d_Layer)   myLayer;
-
+  TCollection_AsciiString  myFontName;
 };
 
 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
@@ -3396,10 +3447,10 @@ public:
 private:
 
   Standard_Real       myX1, myY1, myX2, myY2;
+  V3d_LayerMgrPointer myLayerMgr;
+  Aspect_TypeOfLine   myType;
   Standard_Real       myWidth;
   Standard_Real       myTransparency;
-  Aspect_TypeOfLine   myType;
-  V3d_LayerMgrPointer myLayerMgr;
 };
 
 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
@@ -3553,7 +3604,7 @@ static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char
     di << "  height - pixel height of the text (default=10.0)\n";
     di << "  font_name - name of font (default=courier)\n";
     di << "  text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
-    di << "  display_type = {normal/subtitle/decal/blend}, (default=normal)\n";
+    di << "  display_type = {normal/subtitle/decal/blend/dimension}, (default=normal)\n";
     di << "  background_color- R G B values used for subtitle and decal text\n";
     di << "(default=255.0 255.0 255.0)\n";
     return 1;
@@ -3592,6 +3643,8 @@ static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char
     aTextType = Aspect_TODT_DEKALE;
   else if (aDispStr.IsEqual ("blend"))
     aTextType = Aspect_TODT_BLEND;
+  else if (aDispStr.IsEqual ("dimension"))
+    aTextType = Aspect_TODT_DIMENSION;
 
   // subtitle color
   Quantity_Parameter aSubRed   = 1.0;
@@ -3634,7 +3687,7 @@ static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char
 //purpose  :
 //==============================================================================
 
-static int VGrid (Draw_Interpretor& theDI,
+static int VGrid (Draw_Interpretor& /*theDI*/,
                   Standard_Integer  theArgNb,
                   const char**      theArgVec)
 {
@@ -3784,6 +3837,34 @@ static int VFps (Draw_Interpretor& theDI,
   return 0;
 }
 
+//==============================================================================
+//function : VGlDebug
+//purpose  :
+//==============================================================================
+
+static int VGlDebug (Draw_Interpretor& theDI,
+                     Standard_Integer  theArgNb,
+                     const char**      theArgVec)
+{
+  if (theArgNb < 2)
+  {
+    Handle(V3d_View) aView = ViewerTest::CurrentView();
+    if (aView.IsNull())
+    {
+      std::cerr << "No active view. Please call vinit.\n";
+      return 0;
+    }
+
+    Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )glGetString (GL_EXTENSIONS),
+                                                                "GL_ARB_debug_output");
+    std::cout << "Active graphic driver: debug " << (isActive ? "ON" : "OFF") << "\n";
+    theDI << (isActive ? "1" : "0");
+    return 0;
+  }
+
+  ViewerTest_myDefaultCaps.contextDebug = Draw::Atoi (theArgVec[1]) != 0;
+  return 0;
+}
 
 //==============================================================================
 //function : VVbo
@@ -3794,31 +3875,89 @@ static int VVbo (Draw_Interpretor& theDI,
                  Standard_Integer  theArgNb,
                  const char**      theArgVec)
 {
+  const Standard_Boolean toSet    = (theArgNb > 1);
+  const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
+  if (toSet)
+  {
+    ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
+  }
+
   // get the context
   Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
   if (aContextAIS.IsNull())
   {
-    std::cerr << "No active view. Please call vinit.\n";
+    if (!toSet)
+    {
+      std::cerr << "No active view!\n";
+    }
     return 1;
   }
+  Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
+  if (!aDriver.IsNull())
+  {
+    if (!toSet)
+    {
+      theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
+    }
+    else
+    {
+      aDriver->ChangeOptions().vboDisable = toUseVbo;
+    }
+  }
 
-  Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
+  return 0;
+}
 
-  if (aDriver.IsNull())
+//==============================================================================
+//function : VCaps
+//purpose  :
+//==============================================================================
+
+static int VCaps (Draw_Interpretor& theDI,
+                  Standard_Integer  theArgNb,
+                  const char**      theArgVec)
+{
+  OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
+  Handle(OpenGl_GraphicDriver)   aDriver;
+  Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
+  if (!aContextAIS.IsNull())
   {
-    std::cerr << "Graphic driver not available.\n";
-    return 1;
+    aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
+    aCaps   = &aDriver->ChangeOptions();
   }
 
   if (theArgNb < 2)
   {
-    //theDI << "VBO: " << aDriver->ToUseVBO() << "\n";
-    //return 0;
-    std::cerr << "Wrong number of arguments.\n";
-    return 1;
+    theDI << "VBO:     " << (aCaps->vboDisable        ? "0" : "1") << "\n";
+    theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
+    theDI << "SoftMode:" << (aCaps->contextNoAccel    ? "1" : "0") << "\n";
+    return 0;
   }
 
-  aDriver->EnableVBO (Draw::Atoi(theArgVec[1]) != 0);
+  for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
+  {
+    const TCollection_AsciiString anArg (theArgVec[anArgIter]);
+    if (anArg.Search ("vbo=") > -1)
+    {
+      aCaps->vboDisable        = anArg.Token ("=", 2).IntegerValue() == 0;
+    }
+    else if (anArg.Search ("sprites=") > -1)
+    {
+      aCaps->pntSpritesDisable = anArg.Token ("=", 2).IntegerValue() == 0;
+    }
+    else if (anArg.Search ("soft=") > -1)
+    {
+      aCaps->contextNoAccel = anArg.Token ("=", 2).IntegerValue() != 0;
+    }
+    else
+    {
+      std::cerr << "Unknown argument: " << anArg << "\n";
+    }
+  }
+  if (aCaps != &ViewerTest_myDefaultCaps)
+  {
+    ViewerTest_myDefaultCaps = *aCaps;
+  }
   return 0;
 }
 
@@ -3840,7 +3979,6 @@ static int VMemGpu (Draw_Interpretor& theDI,
   }
 
   Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
-
   if (aDriver.IsNull())
   {
     std::cerr << "Graphic driver not available.\n";
@@ -3905,39 +4043,39 @@ static int VReadPixel (Draw_Interpretor& theDI,
   Standard_Boolean toShowHls  = Standard_False;
   for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
   {
-    TCollection_AsciiString aParam (theArgVec[anIter]);
-    if (TCollection_AsciiString::ISSIMILAR      (aParam, TCollection_AsciiString ("rgb")))
+    const char* aParam = theArgVec[anIter];
+    if ( strcasecmp( aParam, "rgb" ) == 0 )
     {
       aFormat     = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
       aBufferType = Graphic3d_BT_RGB;
     }
-    else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("hls")))
+    else if ( strcasecmp( aParam, "hls" ) == 0 )
     {
       aFormat     = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
       aBufferType = Graphic3d_BT_RGB;
       toShowHls   = Standard_True;
     }
-    else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgbf")))
+    else if ( strcasecmp( aParam, "rgbf" ) == 0 )
     {
       aFormat     = Image_PixMap::ImgRGBF;
       aBufferType = Graphic3d_BT_RGB;
     }
-    else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgba")))
+    else if ( strcasecmp( aParam, "rgba" ) == 0 )
     {
       aFormat     = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
       aBufferType = Graphic3d_BT_RGBA;
     }
-    else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgbaf")))
+    else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
     {
       aFormat     = Image_PixMap::ImgRGBAF;
       aBufferType = Graphic3d_BT_RGBA;
     }
-    else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("depth")))
+    else if ( strcasecmp( aParam, "depth" ) == 0 )
     {
       aFormat     = Image_PixMap::ImgGrayF;
       aBufferType = Graphic3d_BT_Depth;
     }
-    else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("name")))
+    else if ( strcasecmp( aParam, "name" ) == 0 )
     {
       toShowName = Standard_True;
     }
@@ -4269,7 +4407,7 @@ static Standard_Integer VZClipping (Draw_Interpretor& di,
     return 1;
   }
   Handle(V3d_View) aView = ViewerTest::CurrentView();
-  V3d_TypeOfZclipping aZClippingMode;
+  V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
   if(argc==1)
   {
     TCollection_AsciiString aZClippingModeString;
@@ -4423,16 +4561,11 @@ static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
                                 Standard_Integer argc,
                                 const char ** argv)
 {
-  if (argc > 2)
+  if (argc > 1)
   {
-    di << "Usage : " << argv[0] << " [CollectorToo = 0|1]" << "\n";
+    di << "Usage : " << argv[0] << "\n";
     return 1;
   }
-  Standard_Boolean isCollectorToo = Standard_False;
-  if (argc == 2)
-  {
-      isCollectorToo = (atoi(argv [1]) != 0);
-  }
   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
   if (aContext.IsNull())
   {
@@ -4440,7 +4573,7 @@ static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
     return 1;
   }
   aContext->CloseAllContexts(Standard_False);
-  di << aContext->PurgeDisplay(isCollectorToo) << "\n";
+  di << aContext->PurgeDisplay() << "\n";
   return 0;
 }
 
@@ -4622,7 +4755,7 @@ void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
   myParams->SetRotation   (theAngle);
 }
 
-static int VTextureEnv (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
+static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
 {
   // get the active view
   Handle(V3d_View) aView = ViewerTest::CurrentView();
@@ -4715,6 +4848,631 @@ static int VTextureEnv (Draw_Interpretor& theDI, Standard_Integer theArgNb, cons
   return 0;
 }
 
+//===============================================================================================
+//function : VClipPlane
+//purpose  :
+//===============================================================================================
+static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
+{
+  // use short-cut for created clip planes map of created (or "registered by name") clip planes
+  typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
+  static MapOfPlanes aRegPlanes;
+
+  if (theArgsNb < 2)
+  {
+    theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n";
+    return 1;
+  }
+
+  TCollection_AsciiString aCommand (theArgVec[1]);
+
+  // print maximum number of planes for current viewer
+  if (aCommand == "maxplanes")
+  {
+    if (theArgsNb < 3)
+    {
+      theDi << theArgVec[0] << ": view name is required. Type help for more information.\n";
+      return 1;
+    }
+
+    TCollection_AsciiString aViewName (theArgVec[2]);
+
+    if (!ViewerTest_myViews.IsBound1 (aViewName))
+    {
+      theDi << theArgVec[0] << ": view is not found.\n";
+      return 1;
+    }
+
+    const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
+
+    theDi << theArgVec[0] << ": "
+                          << aView->Viewer()->Driver()->InquirePlaneLimit()
+                          << " plane slots provided by driver."
+                          << " Note that 2 more planes might be used (reserved for z-clipping).\n";
+
+    return 0;
+  }
+
+  // create / delete plane instance
+  if (aCommand == "create" || aCommand == "delete" || aCommand == "clone")
+  {
+    if (theArgsNb < 3)
+    {
+      theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n";
+      return 1;
+    }
+
+    Standard_Boolean toCreate = (aCommand == "create");
+    Standard_Boolean toClone  = (aCommand == "clone");
+    TCollection_AsciiString aPlane (theArgVec[2]);
+
+    if (toCreate)
+    {
+      if (aRegPlanes.IsBound (aPlane))
+      {
+        theDi << theArgVec[0] << ": plane name is in use.\n";
+        return 1;
+      }
+
+      aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
+    }
+    else if (toClone) // toClone
+    {
+      if (!aRegPlanes.IsBound (aPlane))
+      {
+        theDi << theArgVec[0] << ": no such plane.\n";
+        return 1;
+      }
+
+      if (theArgsNb < 4)
+      {
+        theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n";
+        return 1;
+      }
+
+      TCollection_AsciiString aClone (theArgVec[3]);
+      if (aRegPlanes.IsBound (aClone))
+      {
+        theDi << theArgVec[0] << ": plane name is in use.\n";
+        return 1;
+      }
+
+      const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
+
+      aRegPlanes.Bind (aClone, aClipPlane->Clone());
+    }
+    else// toDelete
+    {
+      if (!aRegPlanes.IsBound (aPlane))
+      {
+        theDi << theArgVec[0] << ": no such plane.\n";
+        return 1;
+      }
+
+      Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane);
+      aRegPlanes.UnBind (aPlane);
+
+      ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
+      for (; anIObjIt.More(); anIObjIt.Next())
+      {
+        Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
+        aPrs->RemoveClipPlane(aClipPlane);
+      }
+
+      NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
+      for (; aViewIt.More(); aViewIt.Next())
+      {
+        const Handle(V3d_View)& aView = aViewIt.Key2();
+        aView->RemoveClipPlane(aClipPlane);
+      }
+
+      ViewerTest::RedrawAllViews();
+    }
+
+    return 0;
+  }
+
+  // set / unset plane command
+  if (aCommand == "set" || aCommand == "unset")
+  {
+    if (theArgsNb < 4)
+    {
+      theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
+      return 1;
+    }
+
+    Standard_Boolean toSet = (aCommand == "set");
+    TCollection_AsciiString aPlane (theArgVec [2]);
+    if (!aRegPlanes.IsBound (aPlane))
+    {
+      theDi << theArgVec[0] << ": no such plane.\n";
+      return 1;
+    }
+
+    const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
+
+    TCollection_AsciiString aTarget (theArgVec [3]);
+    if (aTarget != "object" && aTarget != "view")
+    {
+      theDi << theArgVec[0] << ": invalid target.\n";
+      return 1;
+    }
+
+    if (aTarget == "object" || aTarget == "view")
+    {
+      if (theArgsNb < 5)
+      {
+        theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
+        return 1;
+      }
+
+      Standard_Boolean isObject = (aTarget == "object");
+
+      for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
+      {
+        TCollection_AsciiString anEntityName (theArgVec[anIt]);
+        if (isObject) // to object
+        {
+          if (!GetMapOfAIS().IsBound2 (anEntityName))
+          {
+            theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n";
+            continue;
+          }
+
+          Handle(AIS_InteractiveObject) aIObj =
+            Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
+
+          if (toSet)
+            aIObj->AddClipPlane (aClipPlane);
+          else
+            aIObj->RemoveClipPlane (aClipPlane);
+        }
+        else // to view
+        {
+          if (!ViewerTest_myViews.IsBound1 (anEntityName))
+          {
+            theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n";
+            continue;
+          }
+
+          Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName);
+          if (toSet)
+            aView->AddClipPlane (aClipPlane);
+          else
+            aView->RemoveClipPlane (aClipPlane);
+        }
+      }
+
+      ViewerTest::RedrawAllViews();
+    }
+
+    return 0;
+  }
+
+  // change plane command
+  if (aCommand == "change")
+  {
+    if (theArgsNb < 4)
+    {
+      theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
+      return 1;
+    }
+
+    TCollection_AsciiString aPlane (theArgVec [2]);
+    if (!aRegPlanes.IsBound (aPlane))
+    {
+      theDi << theArgVec[0] << ": no such plane.\n";
+      return 1;
+    }
+
+    const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
+
+    TCollection_AsciiString aChangeArg (theArgVec [3]);
+    if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation")
+    {
+      theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
+      return 1;
+    }
+
+    if (aChangeArg == "on" || aChangeArg == "off") // on / off
+    {
+      aClipPlane->SetOn (aChangeArg == "on");
+    }
+    else if (aChangeArg == "equation") // change equation
+    {
+      if (theArgsNb < 8)
+      {
+        theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
+        return 1;
+      }
+
+      Standard_Real aCoeffA = atof (theArgVec [4]);
+      Standard_Real aCoeffB = atof (theArgVec [5]);
+      Standard_Real aCoeffC = atof (theArgVec [6]);
+      Standard_Real aCoeffD = atof (theArgVec [7]);
+      aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
+    }
+    else if (aChangeArg == "capping") // change capping aspects
+    {
+      if (theArgsNb < 5)
+      {
+        theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
+        return 1;
+      }
+
+      TCollection_AsciiString aCappingArg (theArgVec [4]);
+      if (aCappingArg != "on" && aCappingArg != "off" &&
+          aCappingArg != "color" && aCappingArg != "texname" &&
+          aCappingArg != "texscale" && aCappingArg != "texorigin" &&
+          aCappingArg != "texrotate" && aCappingArg != "hatch")
+      {
+        theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
+        return 1;
+      }
+
+      if (aCappingArg == "on" || aCappingArg == "off") // on / off capping
+      {
+        aClipPlane->SetCapping (aCappingArg == "on");
+      }
+      else if (aCappingArg == "color") // color aspect for capping
+      {
+        if (theArgsNb < 8)
+        {
+          theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
+          return 1;
+        }
+
+        Standard_Real aRed = atof (theArgVec [5]);
+        Standard_Real aGrn = atof (theArgVec [6]);
+        Standard_Real aBlu = atof (theArgVec [7]);
+
+        Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
+        aMat.SetColor (Quantity_Color (aRed, aGrn, aBlu, Quantity_TOC_RGB));
+        aClipPlane->SetCappingMaterial (aMat);
+      }
+      else if (aCappingArg == "texname") // texture name
+      {
+        if (theArgsNb < 6)
+        {
+          theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
+          return 1;
+        }
+
+        TCollection_AsciiString aTextureName (theArgVec [5]);
+
+        Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
+        if (!aTexture->IsDone ())
+        {
+          aClipPlane->SetCappingTexture (NULL);
+        }
+        else
+        {
+          aTexture->EnableModulate();
+          aTexture->EnableRepeat();
+          aClipPlane->SetCappingTexture (aTexture);
+        }
+      }
+      else if (aCappingArg == "texscale") // texture scale
+      {
+        if (aClipPlane->CappingTexture().IsNull())
+        {
+          theDi << theArgVec[0] << ": no texture is set.\n";
+          return 1;
+        }
+
+        if (theArgsNb < 7)
+        {
+          theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
+          return 1;
+        }
+
+        Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]);
+        Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]);
+
+        aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
+      }
+      else if (aCappingArg == "texorigin") // texture origin
+      {
+        if (aClipPlane->CappingTexture().IsNull())
+        {
+          theDi << theArgVec[0] << ": no texture is set.\n";
+          return 1;
+        }
+
+        if (theArgsNb < 7)
+        {
+          theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
+          return 1;
+        }
+
+        Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]);
+        Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]);
+
+        aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
+      }
+      else if (aCappingArg == "texrotate") // texture rotation
+      {
+        if (aClipPlane->CappingTexture().IsNull())
+        {
+          theDi << theArgVec[0] << ": no texture is set.\n";
+          return 1;
+        }
+
+        if (theArgsNb < 6)
+        {
+          theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
+          return 1;
+        }
+
+        Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]);
+
+        aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
+      }
+      else if (aCappingArg == "hatch") // hatch style
+      {
+        if (theArgsNb < 6)
+        {
+          theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
+          return 1;
+        }
+
+        TCollection_AsciiString aHatchStr (theArgVec [5]);
+        if (aHatchStr == "on")
+        {
+          aClipPlane->SetCappingHatchOn();
+        }
+        else if (aHatchStr == "off")
+        {
+          aClipPlane->SetCappingHatchOff();
+        }
+        else
+        {
+          aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5]));
+        }
+      }
+    }
+
+    ViewerTest::RedrawAllViews();
+
+    return 0;
+  }
+
+  theDi << theArgVec[0] << ": invalid command. Type help for more information.\n";
+  return 1;
+}
+
+//===============================================================================================
+//function : VSetTextureMode
+//purpose  :
+//===============================================================================================
+static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
+{
+  if (theArgsNb < 3)
+  {
+    theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n";
+    return 1;
+  }
+
+  TCollection_AsciiString aViewName (theArgVec[1]);
+  if (!ViewerTest_myViews.IsBound1 (aViewName))
+  {
+    theDi << theArgVec[0] << ": view is not found.\n";
+    return 1;
+  }
+
+  const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
+  switch (atoi (theArgVec[2]))
+  {
+    case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break;
+    case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break;
+    case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break;
+    default:
+      theDi << theArgVec[0] << ": invalid mode.\n";
+      return 1;
+  }
+
+  aView->Redraw();
+  return 0;
+}
+
+//===============================================================================================
+//function : VDefaults
+//purpose  :
+//===============================================================================================
+static int VDefaults (Draw_Interpretor& theDi,
+                      Standard_Integer  theArgsNb,
+                      const char**      theArgVec)
+{
+  const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
+  if (aCtx.IsNull())
+  {
+    std::cerr << "No active viewer!\n";
+    return 1;
+  }
+
+  Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
+  if (theArgsNb < 2)
+  {
+    if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
+    {
+      theDi << "DeflType:           relative\n"
+            << "DeviationCoeff:     " << aDefParams->DeviationCoefficient() << "\n";
+    }
+    else
+    {
+      theDi << "DeflType:           absolute\n"
+            << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
+    }
+    theDi << "AngularDeflection:  " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
+    return 0;
+  }
+
+  for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
+  {
+    TCollection_AsciiString anArg (theArgVec[anArgIter]);
+    TCollection_AsciiString aKey, aValue;
+    if (!splitParameter (anArg, aKey, aValue)
+     || aValue.IsEmpty())
+    {
+      std::cerr << "Error, wrong syntax at: '" << anArg.ToCString() << "'!\n";
+      return 1;
+    }
+
+    aKey.UpperCase();
+    if (aKey == "ABSDEFL"
+     || aKey == "ABSOLUTEDEFLECTION"
+     || aKey == "DEFL"
+     || aKey == "DEFLECTION")
+    {
+      aDefParams->SetTypeOfDeflection         (Aspect_TOD_ABSOLUTE);
+      aDefParams->SetMaximalChordialDeviation (aValue.RealValue());
+    }
+    else if (aKey == "RELDEFL"
+          || aKey == "RELATIVEDEFLECTION"
+          || aKey == "DEVCOEFF"
+          || aKey == "DEVIATIONCOEFF"
+          || aKey == "DEVIATIONCOEFFICIENT")
+    {
+      aDefParams->SetTypeOfDeflection     (Aspect_TOD_RELATIVE);
+      aDefParams->SetDeviationCoefficient (aValue.RealValue());
+    }
+    else if (aKey == "ANGDEFL"
+          || aKey == "ANGULARDEFL"
+          || aKey == "ANGULARDEFLECTION")
+    {
+      // currently HLRDeviationAngle is used instead of DeviationAngle in most places
+      aDefParams->SetHLRAngle (M_PI * aValue.RealValue() / 180.0);
+    }
+    else
+    {
+      std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
+    }
+  }
+
+  return 0;
+}
+
+//==============================================================================
+//function : VClInfo
+//purpose  : Prints info about active OpenCL device
+//==============================================================================
+
+static Standard_Integer VClInfo (Draw_Interpretor& theDi,
+                                 Standard_Integer,
+                                 const char**)
+{
+  Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
+  if (aContextAIS.IsNull())
+  {
+    std::cerr << "Call vinit before!\n";
+    return 1;
+  }
+
+  Handle(OpenGl_GraphicDriver) aDrv = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
+  Graphic3d_CView* aCView = static_cast<Graphic3d_CView*> (ViewerTest::CurrentView()->View()->CView());
+  NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> anInfo;
+  if (aDrv.IsNull()
+   || aCView == NULL
+   || !aDrv->GetOpenClDeviceInfo (*aCView, anInfo))
+  {
+    theDi << "OpenCL device info is unavailable!\n";
+    return 0;
+  }
+
+  theDi << "OpenCL device info:\n";
+  for (NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString>::Iterator anIter (anInfo);
+       anIter.More(); anIter.Next())
+  {
+    theDi << anIter.Key() << ": \t" << anIter.Value() << "\n";
+  }
+  return 0;
+}
+
+//=======================================================================
+//function : VRaytrace
+//purpose  : Enables/disables OpenCL-based ray-tracing
+//=======================================================================
+
+static Standard_Integer VRaytrace (Draw_Interpretor& ,
+                                   Standard_Integer  theArgNb,
+                                   const char**      theArgVec)
+{
+  Handle(V3d_View) aView = ViewerTest::CurrentView();
+  if (aView.IsNull())
+  {
+    std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n";
+    return 1;
+  }
+
+  if (theArgNb < 2
+   || Draw::Atoi (theArgVec[1]))
+  {
+    aView->SetRaytracingMode();
+  }
+  else
+  {
+    aView->SetRasterizationMode();
+  }
+  aView->Redraw();
+  return 0;
+}
+
+//=======================================================================
+//function : VSetRaytraceMode
+//purpose  : Enables/disables features of OpenCL-based ray-tracing
+//=======================================================================
+
+static Standard_Integer VSetRaytraceMode (Draw_Interpretor&,
+                                          Standard_Integer theArgNb,
+                                          const char ** theArgVec)
+{
+  Handle(V3d_View) aView = ViewerTest::CurrentView();
+  if (aView.IsNull())
+  {
+    std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n";
+    return 1;
+  }
+  else if (theArgNb < 2)
+  {
+    std::cerr << "Usage : " << theArgVec[0] << " [shad=0|1] [refl=0|1] [aa=0|1]\n";
+    return 1;
+  }
+
+  for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
+  {
+    const TCollection_AsciiString anArg (theArgVec[anArgIter]);
+
+    if (anArg.Search ("shad=") > -1)
+    {
+      if (anArg.Token ("=", 2).IntegerValue() != 0)
+        aView->EnableRaytracedShadows();
+      else
+        aView->DisableRaytracedShadows();
+    }
+    else if (anArg.Search ("refl=") > -1)
+    {
+      if (anArg.Token ("=", 2).IntegerValue() != 0)
+        aView->EnableRaytracedReflections();
+      else
+        aView->DisableRaytracedReflections();
+    }
+    else if (anArg.Search ("aa=") > -1)
+    {
+      if (anArg.Token ("=", 2).IntegerValue() != 0)
+        aView->EnableRaytracedAntialiasing();
+      else
+        aView->DisableRaytracedAntialiasing();
+    }
+    else
+    {
+      std::cerr << "Unknown argument: " << anArg << "\n";
+    }
+  }
+
+  aView->Redraw();
+  return 0;
+}
+
 //=======================================================================
 //function : ViewerCommands
 //purpose  :
@@ -4745,7 +5503,7 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
     __FILE__,VInit,group);
   theCommands.Add("vclose" ,
-    "view_id [keep_context=0|1]\n"
+    "[view_id [keep_context=0|1]]\n"
     "or vclose ALL - to remove all created views\n"
     " - removes view(viewer window) defined by its view_id.\n"
     " - keep_context: by default 0; if 1 and the last view is deleted"
@@ -4868,9 +5626,17 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
   theCommands.Add ("vfps",
     "vfps [framesNb=100] : estimate average frame rate for active view",
     __FILE__, VFps, group);
+  theCommands.Add ("vgldebug",
+    "vgldebug [{0|1}] : request debug GL context, should be called before vinit\n"
+    "                : this function is implemented only for Windows\n"
+    "                : GL_ARB_debug_output extension should be exported by OpenGL driver!",
+    __FILE__, VGlDebug, group);
   theCommands.Add ("vvbo",
-    "vvbo {0|1} : turn VBO usage On/Off; affects only newly displayed objects",
+    "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
     __FILE__, VVbo, group);
+  theCommands.Add ("vcaps",
+    "vcaps [vbo={0|1}] [sprites={0|1}] [soft={0|1}] : modify particular graphic driver options",
+    __FILE__, VCaps, group);
   theCommands.Add ("vmemgpu",
     "vmemgpu [f]: print system-dependent GPU memory information if available;"
     " with f option returns free memory in bytes",
@@ -4913,7 +5679,7 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     "vantialiasing 1|0",
     __FILE__,VAntialiasing,group);
   theCommands.Add ("vpurgedisplay",
-    "vpurgedisplay [CollectorToo = 0|1]"
+    "vpurgedisplay"
     "- removes structures which don't belong to objects displayed in neutral point",
     __FILE__, VPurgeDisplay, group);
   theCommands.Add("vsetviewsize",
@@ -4955,4 +5721,41 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     "If shapes are not given HLR algoithm of given type is applied"
     " to all shapes in the view\n",
     __FILE__,VHLRType,group);
+  theCommands.Add("vclipplane", "vclipplane usage: \n"
+    "  maxplanes <view_name> - get plane limit for view.\n"
+    "  create <plane_name> - create new plane.\n"
+    "  delete <plane_name> - delete plane.\n"
+    "  clone <source_plane> <plane_name> - clone the plane definition.\n"
+    "  set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
+    "  set/unset <plane_name> view <view list> - set/unset plane for view.\n"
+    "  change <plane_name> on/off - turn clipping on/off.\n"
+    "  change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
+    "  change <plane_name> capping on/off - turn capping on/off.\n"
+    "  change <plane_name> capping color <r> <g> <b> - set color.\n"
+    "  change <plane name> capping texname <texture> - set texture.\n"
+    "  change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
+    "  change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
+    "  change <plane_name> capping texrotate <angle> - set tex rotation.\n"
+    "  change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
+    "  please use VSetTextureMode command to enable texture rendering in view.\n"
+    , __FILE__, VClipPlane, group);
+  theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
+    "  mode can be:\n"
+    "  0 - no textures enabled in view.\n"
+    "  1 - only environment textures enabled.\n"
+    "  2 - all textures enabled.\n"
+    "  this command sets texture details mode for the specified view.\n"
+    , __FILE__, VSetTextureMode, group);
+  theCommands.Add("vdefaults",
+    "vdefaults [absDefl=value] [devCoeff=value] [angDefl=value]",
+    __FILE__, VDefaults, group);
+  theCommands.Add("vraytrace",
+    "vraytrace 0|1",
+    __FILE__,VRaytrace,group);
+  theCommands.Add("vclinfo",
+    "vclinfo",
+    __FILE__,VClInfo,group);
+  theCommands.Add("vsetraytracemode",
+    "vsetraytracemode [shad=0|1] [refl=0|1] [aa=0|1]",
+    __FILE__,VSetRaytraceMode,group);
 }