0024023: Revamp the OCCT Handle -- general
[occt.git] / src / ViewerTest / ViewerTest_ViewerCommands.cxx
index e1d466e..d616d20 100644 (file)
@@ -45,9 +45,6 @@
 #include <NCollection_DoubleMap.hxx>
 #include <NCollection_List.hxx>
 #include <NCollection_Vector.hxx>
-#include <NIS_View.hxx>
-#include <NIS_Triangulated.hxx>
-#include <NIS_InteractiveContext.hxx>
 #include <AIS_InteractiveContext.hxx>
 #include <Draw_Interpretor.hxx>
 #include <Draw.hxx>
@@ -130,7 +127,6 @@ 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();
 
 extern int VErase (Draw_Interpretor& theDI,
@@ -681,12 +677,12 @@ TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft
 #endif
   VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
 
-  // NIS setup
-  Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
+  // View setup
+  Handle(V3d_View) aView = a3DViewer->CreateView();
+  aView->SetWindow (VT_GetWindow());
 
   ViewerTest::CurrentView(aView);
   ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
-  TheNISContext()->AttachView (aView);
 
   // Setup for X11 or NT
   OSWindowSetup();
@@ -1096,7 +1092,6 @@ void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const S
   Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
 
   // Remove view resources
-  TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
   ViewerTest_myViews.UnBind1(theViewName);
   aView->Remove();
 
@@ -1336,7 +1331,6 @@ void VT_ProcessKeyPress (const char* buf_ret)
 {
   //cout << "KeyPress" << endl;
   const Handle(V3d_View) aView = ViewerTest::CurrentView();
-  const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
   // Letter in alphabetic order
 
   if (!strcasecmp (buf_ret, "A"))
@@ -1351,11 +1345,15 @@ void VT_ProcessKeyPress (const char* buf_ret)
   }
   else if (!strcasecmp (buf_ret, "F"))
   {
-    // FitAll
-    if (aNisView.IsNull())
-      aView->FitAll();
+    if (ViewerTest::GetAISContext()->NbSelected() > 0)
+    {
+      ViewerTest::GetAISContext()->FitSelected (aView);
+    }
     else
-      aNisView->FitAll3d();
+    {
+      // FitAll
+      aView->FitAll();
+    }
   }
   else if (!strcasecmp (buf_ret, "H"))
   {
@@ -1514,6 +1512,24 @@ void VT_ProcessKeyPress (const char* buf_ret)
   {
     ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
   }
+  else if (!strcasecmp (buf_ret, "/"))
+  {
+    Handle(Graphic3d_Camera) aCamera = aView->Camera();
+    if (aCamera->IsStereo())
+    {
+      aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
+      aView->Redraw();
+    }
+  }
+  else if (!strcasecmp (buf_ret, "*"))
+  {
+    Handle(Graphic3d_Camera) aCamera = aView->Camera();
+    if (aCamera->IsStereo())
+    {
+      aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
+      aView->Redraw();
+    }
+  }
   else if (*buf_ret == THE_KEY_DELETE)
   {
     Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
@@ -1606,13 +1622,13 @@ void VT_ProcessButton1Release (Standard_Boolean theIsShift)
     Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
     if (theIsShift)
     {
-      EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
-                       Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
+      EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
+                       X_Motion, Y_Motion);
     }
     else
     {
-      EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
-                  Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
+      EM->Select (X_ButtonPress, Y_ButtonPress,
+                  X_Motion, Y_Motion);
     }
   }
 }
@@ -1656,29 +1672,24 @@ void ProcessZClipMotion()
 {
   Handle(V3d_View)  a3DView = ViewerTest::CurrentView();
   if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
-    static Standard_Real CurZPos = 0.;
 
     //Quantity_Length VDX, VDY;
     //a3DView->Size(VDX,VDY);
     //Standard_Real VDZ = a3DView->ZSize();
     //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
 
-    Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
+    Quantity_Length aDx = a3DView->Convert(X_Motion - X_ButtonPress);
 
     // Front = Depth + width/2.
-    Standard_Real D = 0.5;
-    Standard_Real W = 0.1;
+    Standard_Real aDepth = 0.5;
+    Standard_Real aWidth = 0.1;
+    a3DView->ZClipping(aDepth,aWidth);
 
-    CurZPos += (dx);
-
-    D += CurZPos;
+    aDepth += aDx;
 
     //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
 
-    a3DView->SetZClippingType(V3d_OFF);
-    a3DView->SetZClippingDepth(D);
-    a3DView->SetZClippingWidth(W);
-    a3DView->SetZClippingType(V3d_FRONT);
+    a3DView->SetZClippingDepth(aDepth);
 
     a3DView->Redraw();
 
@@ -1990,8 +2001,12 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
                                        LPARAM lParam )
 {
   static int Up = 1;
+  const Handle(V3d_View)& aView = ViewerTest::CurrentView();
+  if (aView.IsNull())
+  {
+    return DefWindowProc( hwnd, Msg, wParam, lParam );
+  }
 
-  if ( !ViewerTest::CurrentView().IsNull() ) {
     PAINTSTRUCT    ps;
 
     switch( Msg ) {
@@ -2004,6 +2019,20 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
     case WM_SIZE:
       VT_ProcessConfigure();
       break;
+    case WM_MOVE:
+    case WM_MOVING:
+    case WM_SIZING:
+      switch (aView->RenderingParams().StereoMode)
+      {
+        case Graphic3d_StereoMode_RowInterlaced:
+        case Graphic3d_StereoMode_ColumnInterlaced:
+        case Graphic3d_StereoMode_ChessBoard:
+          VT_ProcessConfigure(); // track window moves to reverse stereo pair
+          break;
+        default:
+          break;
+      }
+      break;
 
     case WM_KEYDOWN:
       if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
@@ -2025,6 +2054,15 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
         {
           c[0] = '.';
         }
+        else if (wParam == VK_DIVIDE)
+        {
+          c[0] = '/';
+        }
+        // dot
+        else if (wParam == VK_MULTIPLY)
+        {
+          c[0] = '*';
+        }
         VT_ProcessKeyPress (c);
       }
       break;
@@ -2066,6 +2104,29 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
       }
       break;
 
+    case WM_MOUSEWHEEL:
+    {
+      int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
+      if (wParam & MK_CONTROL)
+      {
+        if (aView->Camera()->IsStereo())
+        {
+          Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
+          if (aFocus > 0.2
+           && aFocus < 2.0)
+          {
+            aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
+            aView->Redraw();
+          }
+        }
+      }
+      else
+      {
+        aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
+      }
+      break;
+    }
+
     case WM_MOUSEMOVE:
       {
         //cout << "\t WM_MOUSEMOVE" << endl;
@@ -2127,9 +2188,6 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
       return( DefWindowProc( hwnd, Msg, wParam, lParam ));
     }
     return 0L;
-  }
-
-  return DefWindowProc( hwnd, Msg, wParam, lParam );
 }
 
 
@@ -2472,7 +2530,6 @@ static void OSWindowSetup()
 
 }
 
-
 //==============================================================================
 //function : VFit
 
@@ -2480,13 +2537,27 @@ static void OSWindowSetup()
 //Draw arg : No args
 //==============================================================================
 
-static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
+static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgc, const char** theArgv)
 {
+  if (theArgc > 2)
+  {
+    std::cout << "Wrong number of arguments! Use: vfit [-selected]" << std::endl;
+  }
+
   const Handle(V3d_View) aView = ViewerTest::CurrentView();
-  Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
-  if (V.IsNull() == Standard_False) {
-    V->FitAll3d();
-  } else if (aView.IsNull() == Standard_False) {
+
+  if (theArgc == 2)
+  {
+    TCollection_AsciiString anArg (theArgv[1]);
+    anArg.LowerCase();
+    if (anArg == "-selected")
+    {
+      ViewerTest::GetAISContext()->FitSelected (aView);
+      return 0;
+    }
+  }
+  if (aView.IsNull() == Standard_False) {
+
     aView->FitAll();
   }
   return 0;
@@ -2857,93 +2928,228 @@ static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv
   return 0;
 }
 //==============================================================================
-//function : VTestZBuffTrihedron
-//purpose  : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
+//function : VZBuffTrihedron
+//purpose  :
 //==============================================================================
 
-static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
+                            Standard_Integer  theArgNb,
+                            const char**      theArgVec)
 {
-  Handle(V3d_View) V3dView = ViewerTest::CurrentView();
-  if ( V3dView.IsNull() ) return 1;
+  Handle(V3d_View) aView = ViewerTest::CurrentView();
+  if (aView.IsNull())
+  {
+    std::cout << "Error: no active viewer!\n";
+    return 1;
+  }
 
-  V3dView->ZBufferTriedronSetup();
+  ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
 
-  if ( argc == 1 ) {
-    // Set up default trihedron parameters
-    V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
-  } else
-  if ( argc == 7 )
+  Aspect_TypeOfTriedronPosition aPosition     = Aspect_TOTP_LEFT_LOWER;
+  V3d_TypeOfVisualization       aVisType      = V3d_ZBUFFER;
+  Quantity_Color                aLabelsColor  = Quantity_NOC_WHITE;
+  Quantity_Color                anArrowColorX = Quantity_NOC_RED;
+  Quantity_Color                anArrowColorY = Quantity_NOC_GREEN;
+  Quantity_Color                anArrowColorZ = Quantity_NOC_BLUE1;
+  Standard_Real                 aScale        = 0.1;
+  Standard_Real                 aSizeRatio    = 0.8;
+  Standard_Real                 anArrowDiam   = 0.05;
+  Standard_Integer              aNbFacets     = 12;
+  for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
   {
-    Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
-    const char* aPosType = argv[1];
-
-    if ( strcmp(aPosType, "center") == 0 )
+    Standard_CString        anArg = theArgVec[anArgIter];
+    TCollection_AsciiString aFlag (anArg);
+    aFlag.LowerCase();
+    if (anUpdateTool.parseRedrawMode (aFlag))
     {
-      aPosition = Aspect_TOTP_CENTER;
-    } else
-    if (strcmp(aPosType, "left_lower") == 0)
+      continue;
+    }
+    else if (aFlag == "-on")
     {
-      aPosition = Aspect_TOTP_LEFT_LOWER;
-    } else
-    if (strcmp(aPosType, "left_upper") == 0)
+      continue;
+    }
+    else if (aFlag == "-off")
     {
-      aPosition = Aspect_TOTP_LEFT_UPPER;
-    } else
-    if (strcmp(aPosType, "right_lower") == 0)
+      aView->TriedronErase();
+      return 0;
+    }
+    else if (aFlag == "-pos"
+          || aFlag == "-position"
+          || aFlag == "-corner")
     {
-      aPosition = Aspect_TOTP_RIGHT_LOWER;
-    } else
-    if (strcmp(aPosType, "right_upper") == 0)
+      if (++anArgIter >= theArgNb)
+      {
+        std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
+        return 1;
+      }
+
+      TCollection_AsciiString aPosName (theArgVec[anArgIter]);
+      aPosName.LowerCase();
+      if (aPosName == "center")
+      {
+        aPosition = Aspect_TOTP_CENTER;
+      }
+      else if (aPosName == "left_lower"
+            || aPosName == "lower_left"
+            || aPosName == "leftlower"
+            || aPosName == "lowerleft")
+      {
+        aPosition = Aspect_TOTP_LEFT_LOWER;
+      }
+      else if (aPosName == "left_upper"
+            || aPosName == "upper_left"
+            || aPosName == "leftupper"
+            || aPosName == "upperleft")
+      {
+        aPosition = Aspect_TOTP_LEFT_UPPER;
+      }
+      else if (aPosName == "right_lower"
+            || aPosName == "lower_right"
+            || aPosName == "rightlower"
+            || aPosName == "lowerright")
+      {
+        aPosition = Aspect_TOTP_RIGHT_LOWER;
+      }
+      else if (aPosName == "right_upper"
+            || aPosName == "upper_right"
+            || aPosName == "rightupper"
+            || aPosName == "upperright")
+      {
+        aPosition = Aspect_TOTP_RIGHT_UPPER;
+      }
+      else
+      {
+        std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
+        return 1;
+      }
+    }
+    else if (aFlag == "-type")
     {
-      aPosition = Aspect_TOTP_RIGHT_UPPER;
-    } else
+      if (++anArgIter >= theArgNb)
+      {
+        std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
+        return 1;
+      }
+
+      TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
+      aTypeName.LowerCase();
+      if (aTypeName == "wireframe"
+       || aTypeName == "wire")
+      {
+        aVisType = V3d_WIREFRAME;
+      }
+      else if (aTypeName == "zbuffer"
+            || aTypeName == "shaded")
+      {
+        aVisType = V3d_ZBUFFER;
+      }
+      else
+      {
+        std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
+      }
+    }
+    else if (aFlag == "-scale")
     {
-      di << argv[1] << " Invalid type of alignment"  << "\n";
-      di << "Must be one of [ center, left_lower,"   << "\n";
-      di << "left_upper, right_lower, right_upper ]" << "\n";
-      return 1;
+      if (++anArgIter >= theArgNb)
+      {
+        std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
+        return 1;
+      }
+
+      aScale = Draw::Atof (theArgVec[anArgIter]);
     }
+    else if (aFlag == "-size"
+          || aFlag == "-sizeratio")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
+        return 1;
+      }
 
-    Standard_Real R = Draw::Atof(argv[2])/255.;
-    Standard_Real G = Draw::Atof(argv[3])/255.;
-    Standard_Real B = Draw::Atof(argv[4])/255.;
-    Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
+      aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
+    }
+    else if (aFlag == "-arrowdiam"
+          || aFlag == "-arrowdiameter")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
+        return 1;
+      }
 
-    Standard_Real aScale = Draw::Atof(argv[5]);
+      anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
+    }
+    else if (aFlag == "-nbfacets")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
+        return 1;
+      }
 
-    if( aScale <= 0.0 )
+      aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
+    }
+    else if (aFlag == "-colorlabel"
+          || aFlag == "-colorlabels")
     {
-      di << argv[5] << " Invalid value. Must be > 0" << "\n";
-      return 1;
+      Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb  - anArgIter - 1,
+                                                           theArgVec + anArgIter + 1,
+                                                           aLabelsColor);
+      if (aNbParsed == 0)
+      {
+        std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
+        return 1;
+      }
+      anArgIter += aNbParsed;
     }
-
-    V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
-    const char* aPresType = argv[6];
-
-    if ( strcmp(aPresType, "wireframe") == 0 )
+    else if (aFlag == "-colorarrowx")
+    {
+      Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb  - anArgIter - 1,
+                                                           theArgVec + anArgIter + 1,
+                                                           anArrowColorX);
+      if (aNbParsed == 0)
+      {
+        std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
+        return 1;
+      }
+      anArgIter += aNbParsed;
+    }
+    else if (aFlag == "-colorarrowy")
     {
-      aPresentation = V3d_WIREFRAME;
-    } else
-    if (strcmp(aPresType, "zbuffer") == 0)
+      Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb  - anArgIter - 1,
+                                                           theArgVec + anArgIter + 1,
+                                                           anArrowColorY);
+      if (aNbParsed == 0)
+      {
+        std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
+        return 1;
+      }
+      anArgIter += aNbParsed;
+    }
+    else if (aFlag == "-colorarrowz")
     {
-      aPresentation = V3d_ZBUFFER;
-    } else
+      Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb  - anArgIter - 1,
+                                                           theArgVec + anArgIter + 1,
+                                                           anArrowColorZ);
+      if (aNbParsed == 0)
+      {
+        std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
+        return 1;
+      }
+      anArgIter += aNbParsed;
+    }
+    else
     {
-      di << argv[6] << " Invalid type of visualization" << "\n";
-      di << "Must be one of [ wireframe, zbuffer ]"     << "\n";
+      std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
       return 1;
     }
-
-    V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
-
-  } else
-  {
-    di << argv[0] << " Invalid number of arguments" << "\n";
-    return 1;
   }
 
-  V3dView->View()->ZFitAll();
-
+  aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
+                               aSizeRatio, anArrowDiam, aNbFacets);
+  aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
+  aView->View()->ZFitAll();
   return 0;
 }
 
@@ -3719,7 +3925,8 @@ static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer th
     // On/off arguments
     if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
         || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
-        || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues"))
+        || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
+        || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
         && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
     {
       continue;
@@ -3798,15 +4005,15 @@ static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer th
   }
   if (aMapOfArgs.Find ("xdrawname", aValues))
   {
-    aTrihedronData.ChangeXAxisAspect().SetToDrawName (aValues->Value(1).IsEqual ("on"));
+    aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
   }
   if (aMapOfArgs.Find ("ydrawname", aValues))
   {
-    aTrihedronData.ChangeYAxisAspect().SetToDrawName (aValues->Value(1).IsEqual ("on"));
+    aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
   }
   if (aMapOfArgs.Find ("zdrawname", aValues))
   {
-    aTrihedronData.ChangeZAxisAspect().SetToDrawName (aValues->Value(1).IsEqual ("on"));
+    aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
   }
   if (aMapOfArgs.Find ("xnameoffset", aValues))
   {
@@ -3880,53 +4087,53 @@ static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer th
   // TICKMARKS
   if (aMapOfArgs.Find ("xticks", aValues))
   {
-    aTrihedronData.ChangeXAxisAspect().SetTickmarkNumber (aValues->Value(1).IntegerValue());
+    aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
   }
   if (aMapOfArgs.Find ("yticks", aValues))
   {
-    aTrihedronData.ChangeYAxisAspect().SetTickmarkNumber (aValues->Value(1).IntegerValue());
+    aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
   }
   if (aMapOfArgs.Find ("zticks", aValues))
   {
-    aTrihedronData.ChangeZAxisAspect().SetTickmarkNumber (aValues->Value(1).IntegerValue());
+    aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
   }
   if (aMapOfArgs.Find ("xticklength", aValues))
   {
-    aTrihedronData.ChangeXAxisAspect().SetTickmarkLength (aValues->Value(1).IntegerValue());
+    aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
   }
   if (aMapOfArgs.Find ("yticklength", aValues))
   {
-    aTrihedronData.ChangeYAxisAspect().SetTickmarkLength (aValues->Value(1).IntegerValue());
+    aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
   }
   if (aMapOfArgs.Find ("zticklength", aValues))
   {
-    aTrihedronData.ChangeZAxisAspect().SetTickmarkLength (aValues->Value(1).IntegerValue());
+    aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
   }
   if (aMapOfArgs.Find ("xdrawticks", aValues))
   {
-    aTrihedronData.ChangeXAxisAspect().SetToDrawTickmarks (aValues->Value(1).IsEqual ("on"));
+    aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
   }
   if (aMapOfArgs.Find ("ydrawticks", aValues))
   {
-    aTrihedronData.ChangeYAxisAspect().SetToDrawTickmarks (aValues->Value(1).IsEqual ("on"));
+    aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
   }
   if (aMapOfArgs.Find ("zdrawticks", aValues))
   {
-    aTrihedronData.ChangeZAxisAspect().SetToDrawTickmarks (aValues->Value(1).IsEqual ("on"));
+    aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
   }
 
   // VALUES
   if (aMapOfArgs.Find ("xdrawvalues", aValues))
   {
-    aTrihedronData.ChangeXAxisAspect().SetToDrawValues (aValues->Value(1).IsEqual ("on"));
+    aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
   }
   if (aMapOfArgs.Find ("ydrawvalues", aValues))
   {
-    aTrihedronData.ChangeYAxisAspect().SetToDrawValues (aValues->Value(1).IsEqual ("on"));
+    aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
   }
   if (aMapOfArgs.Find ("zdrawvalues", aValues))
   {
-    aTrihedronData.ChangeZAxisAspect().SetToDrawValues (aValues->Value(1).IsEqual ("on"));
+    aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
   }
   if (aMapOfArgs.Find ("xvaluesoffset", aValues))
   {
@@ -3944,7 +4151,7 @@ static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer th
   // ARROWS
   if (aMapOfArgs.Find ("arrowlength", aValues))
   {
-    aTrihedronData.SetArrowLength ((Standard_ShortReal) aValues->Value(1).RealValue());
+    aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
   }
 
   // FONTS
@@ -3957,6 +4164,15 @@ static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer th
     aTrihedronData.SetValuesFont (aValues->Value(1));
   }
 
+  if (aMapOfArgs.Find ("drawgrid", aValues))
+  {
+    aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
+  }
+  if (aMapOfArgs.Find ("drawaxes", aValues))
+  {
+    aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
+  }
+
   // The final step: display of erase trihedron
   if (toDisplay)
   {
@@ -4352,15 +4568,13 @@ static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** ar
   return 0;
 }
 
-DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
-
 // this class provides a presentation of text item in v3d view under-/overlayer
 class V3d_TextItem : public Visual3d_LayerItem
 {
 public:
 
   // CASCADE RTTI
-  DEFINE_STANDARD_RTTI(V3d_TextItem)
+  DEFINE_STANDARD_RTTI(V3d_TextItem, Visual3d_LayerItem)
 
   // constructor
   Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
@@ -4389,8 +4603,6 @@ private:
   TCollection_AsciiString  myFontName;
 };
 
-IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
-IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
 
 // create and add to display the text item
 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
@@ -4426,8 +4638,6 @@ void V3d_TextItem::RedrawLayerPrs ()
   myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
 }
 
-DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
-
 // The Visual3d_LayerItem line item for "vlayerline" command
 // it provides a presentation of line with user-defined
 // linewidth, linetype and transparency.
@@ -4435,7 +4645,7 @@ class V3d_LineItem : public Visual3d_LayerItem
 {
 public:
   // CASCADE RTTI
-  DEFINE_STANDARD_RTTI(V3d_LineItem)
+  DEFINE_STANDARD_RTTI(V3d_LineItem, Visual3d_LayerItem)
 
   // constructor
   Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
@@ -4457,8 +4667,6 @@ private:
   Standard_Real       myTransparency;
 };
 
-IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
-IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
 
 // default constructor for line item
 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
@@ -4791,6 +4999,221 @@ static int VGrid (Draw_Interpretor& /*theDI*/,
   return 0;
 }
 
+//==============================================================================
+//function : VPriviledgedPlane
+//purpose  :
+//==============================================================================
+
+static int VPriviledgedPlane (Draw_Interpretor& theDI,
+                              Standard_Integer  theArgNb,
+                              const char**      theArgVec)
+{
+  if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
+  {
+    std::cerr << "Error: wrong number of arguments! See usage:\n";
+    theDI.PrintHelp (theArgVec[0]);
+    return 1;
+  }
+
+  // get the active viewer
+  Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
+  if (aViewer.IsNull())
+  {
+    std::cerr << "Error: no active viewer. Please call vinit.\n";
+    return 1;
+  }
+
+  if (theArgNb == 1)
+  {
+    gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
+    const gp_Pnt& anOrig = aPriviledgedPlane.Location();
+    const gp_Dir& aNorm = aPriviledgedPlane.Direction();
+    const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
+    theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
+          << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
+          << "X-dir: "  << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
+    return 0;
+  }
+
+  Standard_Integer anArgIdx = 1;
+  Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
+  Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
+  Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
+  Standard_Real aNormX  = Draw::Atof (theArgVec[anArgIdx++]);
+  Standard_Real aNormY  = Draw::Atof (theArgVec[anArgIdx++]);
+  Standard_Real aNormZ  = Draw::Atof (theArgVec[anArgIdx++]);
+
+  gp_Ax3 aPriviledgedPlane;
+  gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
+  gp_Dir aNorm (aNormX, aNormY, aNormZ);
+  if (theArgNb > 7)
+  {
+    Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
+    Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
+    Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
+    gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
+    aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
+  }
+  else
+  {
+    aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
+  }
+
+  aViewer->SetPrivilegedPlane (aPriviledgedPlane);
+
+  return 0;
+}
+
+//==============================================================================
+//function : VConvert
+//purpose  :
+//==============================================================================
+
+static int VConvert (Draw_Interpretor& theDI,
+                     Standard_Integer  theArgNb,
+                     const char**      theArgVec)
+{
+  // get the active view
+  Handle(V3d_View) aView = ViewerTest::CurrentView();
+  if (aView.IsNull())
+  {
+    std::cerr << "Error: no active view. Please call vinit.\n";
+    return 1;
+  }
+
+  enum { Model, Ray, View, Window, Grid } aMode = Model;
+
+  // access coordinate arguments
+  TColStd_SequenceOfReal aCoord;
+  Standard_Integer anArgIdx = 1;
+  for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
+  {
+    TCollection_AsciiString anArg (theArgVec[anArgIdx]);
+    if (!anArg.IsRealValue())
+    {
+      break;
+    }
+    aCoord.Append (anArg.RealValue());
+  }
+
+  // non-numeric argument too early
+  if (aCoord.IsEmpty())
+  {
+    std::cerr << "Error: wrong number of arguments! See usage:\n";
+    theDI.PrintHelp (theArgVec[0]);
+    return 1;
+  }
+
+  // collect all other arguments and options
+  for (; anArgIdx < theArgNb; ++anArgIdx)
+  {
+    TCollection_AsciiString anArg (theArgVec[anArgIdx]);
+    anArg.LowerCase();
+    if      (anArg == "window") aMode = Window;
+    else if (anArg == "view")   aMode = View;
+    else if (anArg == "grid")   aMode = Grid;
+    else if (anArg == "ray")    aMode = Ray;
+    else
+    {
+      std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
+      theDI.PrintHelp (theArgVec[0]);
+      return 1;
+    }
+  }
+
+  // complete input checks
+  if ((aCoord.Length() == 1 && theArgNb > 3) ||
+      (aCoord.Length() == 2 && theArgNb > 4) ||
+      (aCoord.Length() == 3 && theArgNb > 5))
+  {
+    std::cerr << "Error: wrong number of arguments! See usage:\n";
+    theDI.PrintHelp (theArgVec[0]);
+    return 1;
+  }
+
+  Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
+  Standard_Integer aXYp[2] = {0, 0};
+
+  // convert one-dimensional coordinate
+  if (aCoord.Length() == 1)
+  {
+    switch (aMode)
+    {
+      case View   : theDI << "View Vv: "   << aView->Convert ((Standard_Integer) aCoord (1)); return 0;
+      case Window : theDI << "Window Vp: " << aView->Convert ((Quantity_Length) aCoord (1));  return 0;
+      default:
+        std::cerr << "Error: wrong arguments! See usage:\n";
+        theDI.PrintHelp (theArgVec[0]);
+        return 1;
+    }
+  }
+
+  // convert 2D coordinates from projection or view reference space
+  if (aCoord.Length() == 2)
+  {
+    switch (aMode)
+    {
+      case Model :
+        aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
+        theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
+        return 0;
+
+      case View :
+        aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
+        theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
+        return 0;
+
+      case Window :
+        aView->Convert ((V3d_Coordinate) aCoord (1), (V3d_Coordinate) aCoord (2), aXYp[0], aXYp[1]);
+        theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
+        return 0;
+
+      case Grid :
+        aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
+        aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
+        theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
+        return 0;
+
+      case Ray :
+        aView->ConvertWithProj ((Standard_Integer) aCoord (1),
+                                (Standard_Integer) aCoord (2),
+                                aXYZ[0], aXYZ[1], aXYZ[2],
+                                aXYZ[3], aXYZ[4], aXYZ[5]);
+        theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
+        return 0;
+
+      default:
+        std::cerr << "Error: wrong arguments! See usage:\n";
+        theDI.PrintHelp (theArgVec[0]);
+        return 1;
+    }
+  }
+
+  // convert 3D coordinates from view reference space
+  else if (aCoord.Length() == 3)
+  {
+    switch (aMode)
+    {
+      case Window :
+        aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
+        theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
+        return 0;
+
+      case Grid :
+        aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
+        theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
+        return 0;
+
+      default:
+        std::cerr << "Error: wrong arguments! See usage:\n";
+        theDI.PrintHelp (theArgVec[0]);
+        return 1;
+    }
+  }
+
+  return 0;
+}
+
 //==============================================================================
 //function : VFps
 //purpose  :
@@ -4856,30 +5279,128 @@ static int VGlDebug (Draw_Interpretor& theDI,
   {
     aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
   }
+  OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
+  OpenGl_Caps* aCaps    = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
+
   if (theArgNb < 2)
   {
-    if (aDriver.IsNull())
+    TCollection_AsciiString aDebActive, aSyncActive;
+    if (aCaps == NULL)
     {
-      std::cerr << "No active view. Please call vinit.\n";
-      return 0;
+      aCaps = aDefCaps;
+    }
+    else
+    {
+      Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
+                                                                  "GL_ARB_debug_output");
+      aDebActive = isActive ? " (active)" : " (inactive)";
+      if (isActive)
+      {
+        // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
+        aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
+      }
+    }
+
+    theDI << "debug:   " << (aCaps->contextDebug      ? "1" : "0") << aDebActive  << "\n"
+          << "sync:    " << (aCaps->contextSyncDebug  ? "1" : "0") << aSyncActive << "\n"
+          << "glslWarn:" << (aCaps->glslWarnings      ? "1" : "0") << "\n"
+          << "extraMsg:" << (aCaps->suppressExtraMsg  ? "0" : "1") << "\n";
+    return 0;
+  }
+
+  for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
+  {
+    Standard_CString        anArg     = theArgVec[anArgIter];
+    TCollection_AsciiString anArgCase (anArg);
+    anArgCase.LowerCase();
+    Standard_Boolean toEnableDebug = Standard_True;
+    if (anArgCase == "-glsl"
+     || anArgCase == "-glslwarn"
+     || anArgCase == "-glslwarns"
+     || anArgCase == "-glslwarnings")
+    {
+      Standard_Boolean toShowWarns = Standard_True;
+      if (++anArgIter < theArgNb
+      && !parseOnOff (theArgVec[anArgIter], toShowWarns))
+      {
+        --anArgIter;
+      }
+      aDefCaps->glslWarnings = toShowWarns;
+      if (aCaps != NULL)
+      {
+        aCaps->glslWarnings = toShowWarns;
+      }
+    }
+    else if (anArgCase == "-extra"
+          || anArgCase == "-extramsg"
+          || anArgCase == "-extramessages")
+    {
+      Standard_Boolean toShow = Standard_True;
+      if (++anArgIter < theArgNb
+      && !parseOnOff (theArgVec[anArgIter], toShow))
+      {
+        --anArgIter;
+      }
+      aDefCaps->suppressExtraMsg = !toShow;
+      if (aCaps != NULL)
+      {
+        aCaps->suppressExtraMsg = !toShow;
+      }
+    }
+    else if (anArgCase == "-noextra"
+          || anArgCase == "-noextramsg"
+          || anArgCase == "-noextramessages")
+    {
+      Standard_Boolean toSuppress = Standard_True;
+      if (++anArgIter < theArgNb
+      && !parseOnOff (theArgVec[anArgIter], toSuppress))
+      {
+        --anArgIter;
+      }
+      aDefCaps->suppressExtraMsg = toSuppress;
+      if (aCaps != NULL)
+      {
+        aCaps->suppressExtraMsg = toSuppress;
+      }
+    }
+    else if (anArgCase == "-sync")
+    {
+      Standard_Boolean toSync = Standard_True;
+      if (++anArgIter < theArgNb
+      && !parseOnOff (theArgVec[anArgIter], toSync))
+      {
+        --anArgIter;
+      }
+      aDefCaps->contextSyncDebug = toSync;
+      if (toSync)
+      {
+        aDefCaps->contextDebug = Standard_True;
+      }
+    }
+    else if (anArgCase == "-debug")
+    {
+      if (++anArgIter < theArgNb
+      && !parseOnOff (theArgVec[anArgIter], toEnableDebug))
+      {
+        --anArgIter;
+      }
+      aDefCaps->contextDebug = toEnableDebug;
+    }
+    else if (parseOnOff (anArg, toEnableDebug)
+          && (anArgIter + 1 == theArgNb))
+    {
+      // simple alias to turn on almost everything
+      aDefCaps->contextDebug     = toEnableDebug;
+      aDefCaps->contextSyncDebug = toEnableDebug;
+      aDefCaps->glslWarnings     = toEnableDebug;
+    }
+    else
+    {
+      std::cout << "Error: wrong syntax at '" << anArg << "'\n";
+      return 1;
     }
-
-    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;
-  }
-
-  const Standard_Boolean toEnableDebug = Draw::Atoi (theArgVec[1]) != 0;
-  ViewerTest_myDefaultCaps.contextDebug = toEnableDebug;
-  ViewerTest_myDefaultCaps.glslWarnings = toEnableDebug;
-  if (aDriver.IsNull())
-  {
-    return 0;
   }
 
-  aDriver->ChangeOptions().glslWarnings = toEnableDebug;
   return 0;
 }
 
@@ -4949,7 +5470,9 @@ static int VCaps (Draw_Interpretor& theDI,
     theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
     theDI << "SoftMode:" << (aCaps->contextNoAccel    ? "1" : "0") << "\n";
     theDI << "FFP:     " << (aCaps->ffpEnable         ? "1" : "0") << "\n";
+    theDI << "VSync:   " <<  aCaps->swapInterval                   << "\n";
     theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
+    theDI << "Stereo:  " << (aCaps->contextStereo ? "1" : "0") << "\n";
     return 0;
   }
 
@@ -4963,6 +5486,17 @@ static int VCaps (Draw_Interpretor& theDI,
     {
       continue;
     }
+    else if (anArgCase == "-vsync"
+          || anArgCase == "-swapinterval")
+    {
+      Standard_Boolean toEnable = Standard_True;
+      if (++anArgIter < theArgNb
+      && !parseOnOff (theArgVec[anArgIter], toEnable))
+      {
+        --anArgIter;
+      }
+      aCaps->swapInterval = toEnable;
+    }
     else if (anArgCase == "-ffp")
     {
       Standard_Boolean toEnable = Standard_True;
@@ -5047,6 +5581,17 @@ static int VCaps (Draw_Interpretor& theDI,
         aCaps->ffpEnable = Standard_False;
       }
     }
+    else if (anArgCase == "-stereo"
+          || anArgCase == "-quadbuffer")
+    {
+      Standard_Boolean toEnable = Standard_True;
+      if (++anArgIter < theArgNb
+      && !parseOnOff (theArgVec[anArgIter], toEnable))
+      {
+        --anArgIter;
+      }
+      aCaps->contextStereo = toEnable;
+    }
     else
     {
       std::cout << "Error: unknown argument '" << anArg << "'\n";
@@ -5281,7 +5826,7 @@ static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const
   theDI << aDiffColorsNb << "\n";
 
   // save image of difference
-  if (aDiffImagePath != NULL)
+  if (aDiffColorsNb >0 && aDiffImagePath != NULL)
   {
     aComparer.SaveDiffImage (aDiffImagePath);
   }
@@ -5314,34 +5859,48 @@ static Standard_Integer VSelect (Draw_Interpretor& di,
     di << "use 'vinit' command before " << argv[0] << "\n";
     return 1;
   }
-  const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
+
+  const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1));
+  Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1;
+  TCollection_AsciiString anArg;
+  anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2];
+  anArg.LowerCase();
+  if (anArg == "-allowoverlap")
+  {
+    Standard_Boolean isValidated = isShiftSelection ? argc == 8
+      : argc == 7;
+    if (!isValidated)
+    {
+      di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection";
+      return 1;
+    }
+
+    Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]);
+    myAIScontext->MainSelector()->AllowOverlapDetection((Standard_Boolean)isToAllow);
+    aCoordsNb -= 2;
+  }
+
   Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
   aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
-  if(argc <= 4)
+  if(aCoordsNb == 2)
   {
     if(isShiftSelection)
       aCurrentEventManager->ShiftSelect();
     else
       aCurrentEventManager->Select();
   }
-  else if(argc <= 6)
+  else if(aCoordsNb == 4)
   {
     if(isShiftSelection)
-      aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
+      aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
     else
-      aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
+      aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
   }
   else
   {
-    Standard_Integer anUpper = 0;
+    TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2);
 
-    if(isShiftSelection)
-      anUpper = (argc-1)/2;
-    else
-      anUpper = argc/2;
-    TColgp_Array1OfPnt2d aPolyline(1,anUpper);
-
-    for(Standard_Integer i=1;i<=anUpper;++i)
+    for(Standard_Integer i=1;i<=aCoordsNb / 2;++i)
       aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
 
     if(isShiftSelection)
@@ -5956,11 +6515,12 @@ public:
                             const Standard_ShortReal theXShift,
                             const Standard_ShortReal theYShift,
                             const Standard_ShortReal theAngle);
-  DEFINE_STANDARD_RTTI(OCC_TextureEnv);
+  DEFINE_STANDARD_RTTI(OCC_TextureEnv, Graphic3d_TextureEnv);
 };
 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
-IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
-IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
+
+
+
 
 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
   : Graphic3d_TextureEnv(theFileName)
@@ -6823,6 +7383,94 @@ static int VCamera (Draw_Interpretor& theDI,
   return 0;
 }
 
+//! Parse stereo output mode
+inline Standard_Boolean parseStereoMode (Standard_CString      theArg,
+                                         Graphic3d_StereoMode& theMode)
+{
+  TCollection_AsciiString aFlag (theArg);
+  aFlag.LowerCase();
+  if (aFlag == "quadbuffer")
+  {
+    theMode = Graphic3d_StereoMode_QuadBuffer;
+  }
+  else if (aFlag == "anaglyph")
+  {
+    theMode = Graphic3d_StereoMode_Anaglyph;
+  }
+  else if (aFlag == "row"
+        || aFlag == "rowinterlaced")
+  {
+    theMode = Graphic3d_StereoMode_RowInterlaced;
+  }
+  else if (aFlag == "col"
+        || aFlag == "colinterlaced"
+        || aFlag == "columninterlaced")
+  {
+    theMode = Graphic3d_StereoMode_ColumnInterlaced;
+  }
+  else if (aFlag == "chess"
+        || aFlag == "chessboard")
+  {
+    theMode = Graphic3d_StereoMode_ChessBoard;
+  }
+  else if (aFlag == "sbs"
+        || aFlag == "sidebyside")
+  {
+    theMode = Graphic3d_StereoMode_SideBySide;
+  }
+  else if (aFlag == "ou"
+        || aFlag == "overunder")
+  {
+    theMode = Graphic3d_StereoMode_OverUnder;
+  }
+  else if (aFlag == "pageflip"
+        || aFlag == "softpageflip")
+  {
+    theMode = Graphic3d_StereoMode_SoftPageFlip;
+  }
+  else
+  {
+    return Standard_False;
+  }
+  return Standard_True;
+}
+
+//! Parse anaglyph filter
+inline Standard_Boolean parseAnaglyphFilter (Standard_CString                     theArg,
+                                             Graphic3d_RenderingParams::Anaglyph& theFilter)
+{
+  TCollection_AsciiString aFlag (theArg);
+  aFlag.LowerCase();
+  if (aFlag == "redcyansimple")
+  {
+    theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
+  }
+  else if (aFlag == "redcyan"
+        || aFlag == "redcyanoptimized")
+  {
+    theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
+  }
+  else if (aFlag == "yellowbluesimple")
+  {
+    theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
+  }
+  else if (aFlag == "yellowblue"
+        || aFlag == "yellowblueoptimized")
+  {
+    theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
+  }
+  else if (aFlag == "greenmagenta"
+        || aFlag == "greenmagentasimple")
+  {
+    theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
+  }
+  else
+  {
+    return Standard_False;
+  }
+  return Standard_True;
+}
+
 //==============================================================================
 //function : VStereo
 //purpose  :
@@ -6832,12 +7480,12 @@ static int VStereo (Draw_Interpretor& theDI,
                     Standard_Integer  theArgNb,
                     const char**      theArgVec)
 {
+  Handle(V3d_View) aView = ViewerTest::CurrentView();
   if (theArgNb < 2)
   {
-    Handle(V3d_View) aView = ViewerTest::CurrentView();
     if (aView.IsNull())
     {
-      std::cerr << "No active view. Please call vinit.\n";
+      std::cout << "Error: no active viewer!\n";
       return 0;
     }
 
@@ -6846,7 +7494,130 @@ static int VStereo (Draw_Interpretor& theDI,
     return 0;
   }
 
-  ViewerTest_myDefaultCaps.contextStereo = Draw::Atoi (theArgVec[1]) != 0;
+  Handle(Graphic3d_Camera) aCamera;
+  Graphic3d_RenderingParams*   aParams   = NULL;
+  Graphic3d_StereoMode         aMode     = Graphic3d_StereoMode_QuadBuffer;
+  if (!aView.IsNull())
+  {
+    aParams   = &aView->ChangeRenderingParams();
+    aMode     = aParams->StereoMode;
+    aCamera   = aView->Camera();
+  }
+
+  ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
+  for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
+  {
+    Standard_CString        anArg = theArgVec[anArgIter];
+    TCollection_AsciiString aFlag (anArg);
+    aFlag.LowerCase();
+    if (anUpdateTool.parseRedrawMode (aFlag))
+    {
+      continue;
+    }
+    else if (aFlag == "0"
+          || aFlag == "off")
+    {
+      if (++anArgIter < theArgNb)
+      {
+        std::cout << "Error: wrong number of arguments!\n";
+        return 1;
+      }
+
+      if (!aCamera.IsNull()
+       &&  aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
+      {
+        aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
+      }
+      ViewerTest_myDefaultCaps.contextStereo = Standard_False;
+      return 0;
+    }
+    else if (aFlag == "1"
+          || aFlag == "on")
+    {
+      if (++anArgIter < theArgNb)
+      {
+        std::cout << "Error: wrong number of arguments!\n";
+        return 1;
+      }
+
+      if (!aCamera.IsNull())
+      {
+        aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
+      }
+      ViewerTest_myDefaultCaps.contextStereo = Standard_True;
+      return 0;
+    }
+    else if (aFlag == "-reverse"
+          || aFlag == "-reversed"
+          || aFlag == "-swap")
+    {
+      Standard_Boolean toEnable = Standard_True;
+      if (++anArgIter < theArgNb
+      && !parseOnOff (theArgVec[anArgIter], toEnable))
+      {
+        --anArgIter;
+      }
+      aParams->ToReverseStereo = toEnable;
+    }
+    else if (aFlag == "-noreverse"
+          || aFlag == "-noswap")
+    {
+      Standard_Boolean toDisable = Standard_True;
+      if (++anArgIter < theArgNb
+      && !parseOnOff (theArgVec[anArgIter], toDisable))
+      {
+        --anArgIter;
+      }
+      aParams->ToReverseStereo = !toDisable;
+    }
+    else if (aFlag == "-mode"
+          || aFlag == "-stereomode")
+    {
+      if (++anArgIter >= theArgNb
+      || !parseStereoMode (theArgVec[anArgIter], aMode))
+      {
+        std::cout << "Error: syntax error at '" << anArg << "'\n";
+        return 1;
+      }
+
+      if (aMode == Graphic3d_StereoMode_QuadBuffer)
+      {
+        ViewerTest_myDefaultCaps.contextStereo = Standard_True;
+      }
+    }
+    else if (aFlag == "-anaglyph"
+          || aFlag == "-anaglyphfilter")
+    {
+      Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
+      if (++anArgIter >= theArgNb
+      || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
+      {
+        std::cout << "Error: syntax error at '" << anArg << "'\n";
+        return 1;
+      }
+
+      aMode = Graphic3d_StereoMode_Anaglyph;
+      aParams->AnaglyphFilter = aFilter;
+    }
+    else if (parseStereoMode (anArg, aMode)) // short syntax
+    {
+      if (aMode == Graphic3d_StereoMode_QuadBuffer)
+      {
+        ViewerTest_myDefaultCaps.contextStereo = Standard_True;
+      }
+    }
+    else
+    {
+      std::cout << "Error: syntax error at '" << anArg << "'\n";
+      return 1;
+    }
+  }
+
+  if (!aView.IsNull())
+  {
+    aParams->StereoMode = aMode;
+    aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
+  }
   return 0;
 }
 
@@ -6926,9 +7697,9 @@ static int VDefaults (Draw_Interpretor& theDi,
       // currently HLRDeviationAngle is used instead of DeviationAngle in most places
       aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
     }
-    if (anArg == "-AUTOTR"
-     || anArg == "-AUTOTRIANG"
-     || anArg == "-AUTOTRIANGULATION")
+    else if (anArg == "-AUTOTR"
+          || anArg == "-AUTOTRIANG"
+          || anArg == "-AUTOTRIANGULATION")
     {
       if (++anArgIter >= theArgsNb)
       {
@@ -7024,58 +7795,64 @@ static int VLight (Draw_Interpretor& theDi,
       {
         case V3d_AMBIENT:
         {
-          theDi << "  Type:      Ambient\n";
+          theDi << "  Type:       Ambient\n";
+          theDi << "  Intensity:  " << aLight->Intensity() << "\n";
           break;
         }
         case V3d_DIRECTIONAL:
         {
           Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
-          theDi << "  Type:      Directional\n";
-          theDi << "  Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
+          theDi << "  Type:       Directional\n";
+          theDi << "  Intensity:  " << aLight->Intensity() << "\n";
+          theDi << "  Headlight:  " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
+          theDi << "  Smoothness: " << aLight->Smoothness() << "\n";
           if (!aLightDir.IsNull())
           {
             aLightDir->Position  (anXYZ[0], anXYZ[1], anXYZ[2]);
-            theDi << "  Position:  " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
+            theDi << "  Position:   " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
             aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
-            theDi << "  Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
+            theDi << "  Direction:  " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
           }
           break;
         }
         case V3d_POSITIONAL:
         {
           Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
-          theDi << "  Type:      Positional\n";
-          theDi << "  Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
+          theDi << "  Type:       Positional\n";
+          theDi << "  Intensity:  " << aLight->Intensity() << "\n";
+          theDi << "  Headlight:  " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
+          theDi << "  Smoothness: " << aLight->Smoothness() << "\n";
           if (!aLightPos.IsNull())
           {
             aLightPos->Position  (anXYZ[0], anXYZ[1], anXYZ[2]);
-            theDi << "  Position:  " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
+            theDi << "  Position:   " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
             aLightPos->Attenuation (anAtten[0], anAtten[1]);
-            theDi << "  Atten.:    " << anAtten[0] << " " << anAtten[1] << "\n";
+            theDi << "  Atten.:     " << anAtten[0] << " " << anAtten[1] << "\n";
           }
           break;
         }
         case V3d_SPOT:
         {
           Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
-          theDi << "  Type:      Spot\n";
-          theDi << "  Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
+          theDi << "  Type:       Spot\n";
+          theDi << "  Intensity:  " << aLight->Intensity() << "\n";
+          theDi << "  Headlight:  " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
           if (!aLightSpot.IsNull())
           {
             aLightSpot->Position  (anXYZ[0], anXYZ[1], anXYZ[2]);
-            theDi << "  Position:  " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
+            theDi << "  Position:   " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
             aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
-            theDi << "  Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
+            theDi << "  Direction:  " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
             aLightSpot->Attenuation (anAtten[0], anAtten[1]);
-            theDi << "  Atten.:    " << anAtten[0] << " " << anAtten[1] << "\n";
-            theDi << "  Angle:     " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
-            theDi << "  Exponent:  " << aLightSpot->Concentration() << "\n";
+            theDi << "  Atten.:     " << anAtten[0] << " " << anAtten[1] << "\n";
+            theDi << "  Angle:      " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
+            theDi << "  Exponent:   " << aLightSpot->Concentration() << "\n";
           }
           break;
         }
         default:
         {
-          theDi << "  Type:      UNKNOWN\n";
+          theDi << "  Type:       UNKNOWN\n";
           break;
         }
       }
@@ -7307,6 +8084,56 @@ static int VLight (Draw_Interpretor& theDi,
         return 1;
       }
     }
+    else if (anArgCase.IsEqual ("SM")
+          || anArgCase.IsEqual ("SMOOTHNESS"))
+    {
+      if (++anArgIt >= theArgsNb)
+      {
+        std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
+        return 1;
+      }
+
+      Standard_Real aSmoothness = Atof (theArgVec[anArgIt]);
+
+      if (fabs (aSmoothness) < Precision::Confusion())
+      {
+        aLightCurr->SetIntensity (1.f);
+      }
+      else if (fabs (aLightCurr->Smoothness()) < Precision::Confusion())
+      {
+        aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
+      }
+      else
+      {
+        Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
+        aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
+      }
+
+      if (!aLightPos.IsNull())
+      {
+        aLightPos->SetSmoothRadius (aSmoothness);
+      }
+      else if (!aLightDir.IsNull())
+      {
+        aLightDir->SetSmoothAngle (aSmoothness);
+      }
+    }
+    else if (anArgCase.IsEqual ("INT")
+          || anArgCase.IsEqual ("INTENSITY"))
+    {
+      if (++anArgIt >= theArgsNb)
+      {
+        std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
+        return 1;
+      }
+
+      Standard_Real aIntensity = Atof (theArgVec[anArgIt]);
+
+      if (!aLightCurr.IsNull())
+      {
+        aLightCurr->SetIntensity (aIntensity);
+      }
+    }
     else if (anArgCase.IsEqual ("ANG")
           || anArgCase.IsEqual ("ANGLE"))
     {
@@ -7497,11 +8324,12 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
       case Graphic3d_RM_RAYTRACING:    theDI << "raytrace ";      break;
     }
     theDI << "\n";
-    theDI << "fsaa:         " << (aParams.IsAntialiasingEnabled      ? "on" : "off") << "\n";
-    theDI << "shadows:      " << (aParams.IsShadowEnabled            ? "on" : "off") << "\n";
-    theDI << "reflections:  " << (aParams.IsReflectionEnabled        ? "on" : "off") << "\n";
-    theDI << "rayDepth:     " <<  aParams.RaytracingDepth                            << "\n";
-    theDI << "gleam:        " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
+    theDI << "fsaa:         " << (aParams.IsAntialiasingEnabled       ? "on" : "off") << "\n";
+    theDI << "shadows:      " << (aParams.IsShadowEnabled             ? "on" : "off") << "\n";
+    theDI << "reflections:  " << (aParams.IsReflectionEnabled         ? "on" : "off") << "\n";
+    theDI << "rayDepth:     " <<  aParams.RaytracingDepth                             << "\n";
+    theDI << "gleam:        " << (aParams.IsTransparentShadowEnabled  ? "on" : "off") << "\n";
+    theDI << "GI:           " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
     theDI << "shadingModel: ";
     switch (aView->ShadingModel())
     {
@@ -7588,7 +8416,9 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
       }
 
       const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
-      if (aDepth < 1 || aDepth > 10)
+
+      // We allow RaytracingDepth be more than 10 in case of GI enabled
+      if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
       {
         std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
         return 1;
@@ -7664,6 +8494,42 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
       }
       aParams.IsTransparentShadowEnabled = toEnable;
     }
+    else if (aFlag == "-gi")
+    {
+      if (toPrint)
+      {
+        theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
+        continue;
+      }
+
+      Standard_Boolean toEnable = Standard_True;
+      if (++anArgIter < theArgNb
+      && !parseOnOff (theArgVec[anArgIter], toEnable))
+      {
+        --anArgIter;
+      }
+      aParams.IsGlobalIlluminationEnabled = toEnable;
+      if (!toEnable)
+      {
+        aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
+      }
+    }
+    else if (aFlag == "-env")
+    {
+      if (toPrint)
+      {
+        theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
+        continue;
+      }
+
+      Standard_Boolean toEnable = Standard_True;
+      if (++anArgIter < theArgNb
+        && !parseOnOff (theArgVec[anArgIter], toEnable))
+      {
+        --anArgIter;
+      }
+      aParams.UseEnvironmentMapBackground = toEnable;
+    }
     else if (aFlag == "-shademodel"
           || aFlag == "-shadingmodel"
           || aFlag == "-shading")
@@ -7722,8 +8588,55 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
       return 1;
     }
   }
+
+  return 0;
+}
+
+//=======================================================================
+//function : VProgressiveMode
+//purpose  :
+//=======================================================================
+#if defined(_WIN32)
+static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
+                                          Standard_Integer  /*theNbArgs*/,
+                                          const char**      /*theArgs*/)
+{
+  Handle(V3d_View) aView = ViewerTest::CurrentView();
+  if (aView.IsNull())
+  {
+    std::cerr << "Error: no active viewer!\n";
+    return 1;
+  }
+
+  std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl;
+
+  for (;;)
+  {
+    aView->Redraw();
+
+    Standard_Boolean toExit = Standard_False;
+
+    MSG aMsg;
+    while (PeekMessage (&aMsg, NULL, NULL, NULL, PM_REMOVE))
+    {
+      if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b))
+      {
+        toExit = Standard_True;
+      }
+
+      TranslateMessage (&aMsg);
+      DispatchMessage  (&aMsg);
+    }
+
+    if (toExit)
+    {
+      break;
+    }
+  }
+
   return 0;
 }
+#endif
 
 //=======================================================================
 //function : VFrustumCulling
@@ -7957,7 +8870,8 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     "vpick           : vpick X Y Z [shape subshape] ( all variables as string )",
     VPick,group);
   theCommands.Add("vfit"    ,
-    "vfit or <F>         : vfit",
+    "vfit or <F> [-selected]"
+    "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
     __FILE__,VFit,group);
   theCommands.Add ("vfitarea",
     "vfitarea x1 y1 x2 y2"
@@ -7994,10 +8908,13 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     "vscale          : vscale X Y Z",
     __FILE__,VScale,group);
   theCommands.Add("vzbufftrihedron",
-    "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
-    " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
-    " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
-    __FILE__,VTestZBuffTrihedron,group);
+            "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
+    "\n\t\t:       [-position center|left_lower|left_upper|right_lower|right_upper]"
+    "\n\t\t:       [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
+    "\n\t\t:       [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
+    "\n\t\t:       [-nbfacets value=12] [-colorLabels color=WHITE]"
+    "\n\t\t: Displays a trihedron",
+    __FILE__,VZBuffTrihedron,group);
   theCommands.Add("vrotate",
     "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
     "\n                : Option -mouseStart starts rotation according to the mouse position"
@@ -8045,6 +8962,7 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
     "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
     "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
+    "\t[-drawgrid on/off] [-drawaxes on/off]\n"
     " - Displays or erases graduated trihedron"
     " - xname, yname, zname - names of axes, default: X, Y, Z\n"
     " - namefont - font of axes names. Default: Arial\n"
@@ -8091,23 +9009,72 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     " : Mode - rectangular or circular"
     " : Type - lines or points",
     __FILE__, VGrid, group);
+  theCommands.Add ("vpriviledgedplane",
+    "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
+    "\n\t\t:   Ox, Oy, Oz - plane origin"
+    "\n\t\t:   Nx, Ny, Nz - plane normal direction"
+    "\n\t\t:   Xx, Xy, Xz - plane x-reference axis direction"
+    "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
+    __FILE__, VPriviledgedPlane, group);
+  theCommands.Add ("vconvert",
+    "vconvert v [Mode={window|view}]"
+    "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
+    "\n\t\t: vconvert x y z [Mode={window|grid}]"
+    "\n\t\t:   window - convert to window coordinates, pixels"
+    "\n\t\t:   view   - convert to view projection plane"
+    "\n\t\t:   grid   - convert to model coordinates, given on grid"
+    "\n\t\t:   ray    - convert projection ray to model coordiantes"
+    "\n\t\t: - vconvert v window : convert view to window;"
+    "\n\t\t: - vconvert v view   : convert window to view;"
+    "\n\t\t: - vconvert x y window : convert view to window;"
+    "\n\t\t: - vconvert x y view : convert window to view;"
+    "\n\t\t: - vconvert x y : convert window to model;"
+    "\n\t\t: - vconvert x y grid : convert window to model using grid;"
+    "\n\t\t: - vconvert x y ray : convert window projection line to model;"
+    "\n\t\t: - vconvert x y z window : convert model to window;"
+    "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
+    "\n\t\t: Converts the given coordinates to window/view/model space.",
+    __FILE__, VConvert, group);
   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!",
+            "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
+    "\n\t\t:          [-extraMsg {0|1}] [{0|1}]"
+    "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
+    "\n\t\t: Debug context can be requested only on Windows"
+    "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
+    "\n\t\t:  -sync     - request synchronized debug GL context"
+    "\n\t\t:  -glslWarn - log GLSL compiler/linker warnings,"
+    "\n\t\t:              which are suppressed by default,"
+    "\n\t\t:  -extraMsg - log extra diagnostic messages from GL context,"
+    "\n\t\t:              which are suppressed by default",
     __FILE__, VGlDebug, group);
   theCommands.Add ("vvbo",
     "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
     __FILE__, VVbo, group);
   theCommands.Add ("vstereo",
-    "\nvstereo [{0|1}] : turn stereo usage On/Off; affects only newly displayed objects",
+            "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
+    "\n\t\t:         [-anaglyph Filter]"
+    "\n\t\t: Control stereo output mode. Available modes for -mode:"
+    "\n\t\t:  quadBuffer        - OpenGL QuadBuffer stereo,"
+    "\n\t\t:                     requires driver support."
+    "\n\t\t:                     Should be called BEFORE vinit!"
+    "\n\t\t:  anaglyph         - Anaglyph glasses"
+    "\n\t\t:  rowInterlaced    - row-interlaced display"
+    "\n\t\t:  columnInterlaced - column-interlaced display"
+    "\n\t\t:  chessBoard       - chess-board output"
+    "\n\t\t:  sideBySide       - horizontal pair"
+    "\n\t\t:  overUnder        - vertical   pair"
+    "\n\t\t: Available Anaglyph filters for -anaglyph:"
+    "\n\t\t:  redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
+    "\n\t\t:  greenMagentaSimple",
     __FILE__, VStereo, group);
   theCommands.Add ("vcaps",
             "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]"
     "\n\t\t:       [-compatibleContext {0|1}]"
+    "\n\t\t:       [-vsync {0|1}]"
+    "\n\t\t:       [-quadBuffer {0|1}] [-stereo {0|1}]"
     "\n\t\t:       [-softMode {0|1}] [-noupdate|-update]"
     "\n\t\t: Modify particular graphic driver options:"
     "\n\t\t:  FFP      - use fixed-function pipeline instead of"
@@ -8116,9 +9083,11 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     "\n\t\t:  VBO      - use Vertex Buffer Object (copy vertex"
     "\n\t\t:             arrays to GPU memory)"
     "\n\t\t:  sprite   - use textured sprites instead of bitmaps"
+    "\n\t\t:  vsync    - switch VSync on or off"
     "\n\t\t: Context creation options:"
     "\n\t\t:  softMode          - software OpenGL implementation"
     "\n\t\t:  compatibleProfile - backward-compatible profile"
+    "\n\t\t:  quadbuffer        - QuadBuffer"
     "\n\t\t: Unlike vrenderparams, these parameters control alternative"
     "\n\t\t: rendering paths producing the same visual result when"
     "\n\t\t: possible."
@@ -8136,12 +9105,14 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     "diffimage     : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
     __FILE__, VDiffImage, group);
   theCommands.Add ("vselect",
-    "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
+    "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
     "- emulates different types of selection:\n"
     "- 1) single click selection\n"
     "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
     "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
-    "- 4) any of these selections with shift button pressed",
+    "- 4) -allowoverlap determines will partially included objects be selected in rectangular selection"
+    " (partial inclusion - overlap - is not allowed by default)\n"
+    "- 5) any of these selections with shift button pressed",
     __FILE__, VSelect, group);
   theCommands.Add ("vmoveto",
     "vmoveto x y"
@@ -8299,6 +9270,8 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     "\n        {dir}ection X Y Z (for directional light or for spotlight)"
     "\n        color colorName"
     "\n        {head}light 0|1"
+    "\n        {sm}oothness value"
+    "\n        {int}ensity value"
     "\n        {constAtten}uation value"
     "\n        {linearAtten}uation value"
     "\n        angle angleDeg"
@@ -8309,7 +9282,7 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     __FILE__, VLight, group);
   theCommands.Add("vraytrace",
             "vraytrace [0|1]"
-    "\n\t\t: Turn on/off raytracing renderer."
+    "\n\t\t: Turns on/off ray-tracing renderer."
     "\n\t\t:   'vraytrace 0' alias for 'vrenderparams -raster'."
     "\n\t\t:   'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
     __FILE__, VRenderParams, group);
@@ -8322,6 +9295,8 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     "\n      '-reflections  on|off'  Enables/disables specular reflections"
     "\n      '-fsaa         on|off'  Enables/disables adaptive anti-aliasing"
     "\n      '-gleam        on|off'  Enables/disables transparency shadow effects"
+    "\n      '-gi           on|off'  Enables/disables global illumination effects"
+    "\n      '-env          on|off'  Enables/disables environment map background"
     "\n      '-shadingModel model'   Controls shading model from enumeration"
     "\n                              color, flat, gouraud, phong"
     "\n    Unlike vcaps, these parameters dramatically change visual properties."
@@ -8343,4 +9318,9 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     "vxrotate",
     __FILE__,VXRotate,group);
 
+#if defined(_WIN32)
+  theCommands.Add("vprogressive",
+    "vprogressive",
+    __FILE__, VProgressiveMode, group);
+#endif
 }