0027957: Visualization, AIS_InteractiveContext - protect from displaying the same...
[occt.git] / src / ViewerTest / ViewerTest_ViewerCommands.cxx
index ddbd7ef..bd57553 100644 (file)
@@ -49,7 +49,6 @@
 #include <Draw_Interpretor.hxx>
 #include <Draw.hxx>
 #include <Draw_Appli.hxx>
-#include <Aspect_PrintAlgo.hxx>
 #include <Image_AlienPixMap.hxx>
 #include <OpenGl_GraphicDriver.hxx>
 #include <OSD_Timer.hxx>
 #if defined(_WIN32)
   #include <WNT_WClass.hxx>
   #include <WNT_Window.hxx>
-
-  #if defined(_MSC_VER)
-    #define _CRT_SECURE_NO_DEPRECATE
-    #pragma warning (disable:4996)
-  #endif
 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
   #include <Cocoa_Window.hxx>
 #else
@@ -564,8 +558,17 @@ TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft
     (void)theDisplayName; // avoid warning on unused argument
     SetDisplayConnection (new Aspect_DisplayConnection ());
   #endif
+
+    if (Draw_VirtualWindows)
+    {
+      // don't waste the time waiting for VSync when window is not displayed on the screen
+      ViewerTest_myDefaultCaps.swapInterval = 0;
+      // alternatively we can disable buffer swap at all, but this might be inappropriate for testing
+      //ViewerTest_myDefaultCaps.buffersNoSwap = true;
+    }
     aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
     aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
+
     ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
     toCreateViewer = Standard_True;
   }
@@ -653,8 +656,7 @@ TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft
   else if (a3DViewer.IsNull())
   {
     toCreateViewer = Standard_True;
-    TCollection_ExtendedString NameOfWindow("Viewer3D");
-    a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
+    a3DViewer = new V3d_Viewer(aGraphicDriver);
     a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
     a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
                                            ViewerTest_DefaultBackground.GradientColor2,
@@ -1136,6 +1138,8 @@ void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const S
           break;
         }
       }
+
+      aCurrentContext->RemoveAll (Standard_False);
       if(isRemoveDriver)
       {
         ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
@@ -1893,7 +1897,7 @@ static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
           ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
         }
 
-        VT_ProcessButton1Release (fwKeys & MK_SHIFT);
+        VT_ProcessButton1Release ((fwKeys & MK_SHIFT) != 0);
       }
       IsDragged = Standard_False;
       return ViewerWindowProc( hwnd, Msg, wParam, lParam );
@@ -2075,13 +2079,13 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
 
         if (Msg == WM_LBUTTONDOWN)
         {
-          if (fwKeys & MK_CONTROL)
+          if ((fwKeys & MK_CONTROL) != 0)
           {
-            Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
+            Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
           }
           else
           {
-            VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
+            VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
           }
         }
         else if (Msg == WM_RBUTTONDOWN)
@@ -2123,27 +2127,32 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
         Y_Motion = HIWORD(lParam);
 
         if ( Up &&
-          fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
+          (fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON )) != 0 )
+          {
             Up = 0;
             X_ButtonPress = LOWORD(lParam);
             Y_ButtonPress = HIWORD(lParam);
 
-            if ( fwKeys & MK_RBUTTON ) {
+            if ((fwKeys & MK_RBUTTON) != 0) {
               // Start rotation
               VT_ProcessButton3Press();
             }
           }
 
-          if ( fwKeys & MK_CONTROL ) {
-            if ( fwKeys & MK_LBUTTON ) {
+          if ((fwKeys & MK_CONTROL) != 0)
+          {
+            if ((fwKeys & MK_LBUTTON) != 0)
+            {
               ProcessControlButton1Motion();
             }
-            else if ( fwKeys & MK_MBUTTON ||
-              ((fwKeys&MK_LBUTTON) &&
-              (fwKeys&MK_RBUTTON) ) ){
-                VT_ProcessControlButton2Motion();
-              }
-            else if ( fwKeys & MK_RBUTTON ) {
+            else if ((fwKeys & MK_MBUTTON) != 0
+                 || ((fwKeys & MK_LBUTTON) != 0
+                  && (fwKeys & MK_RBUTTON) != 0))
+            {
+              VT_ProcessControlButton2Motion();
+            }
+            else if ((fwKeys & MK_RBUTTON) != 0)
+            {
               VT_ProcessControlButton3Motion();
             }
           }
@@ -3384,7 +3393,9 @@ static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** arg
 
   try
   {
+  Standard_DISABLE_DEPRECATION_WARNINGS
     if (!V3dView->Export (argv[1], anExpFormat))
+  Standard_ENABLE_DEPRECATION_WARNINGS
     {
       di << "Error: export of image to " << aFormatStr << " failed!\n";
     }
@@ -3468,9 +3479,10 @@ static int VColorScale (Draw_Interpretor& theDI,
   {
     aCS->SetZLayer (Graphic3d_ZLayerId_TopOSD);
   }
-  if (aCS->GetTransformPersistenceMode() != Graphic3d_TMF_2d)
+  if (aCS->TransformPersistence().IsNull()
+   || aCS->TransformPersistence()->Mode() != Graphic3d_TMF_2d)
   {
-    aContext->SetTransformPersistence (aCS, Graphic3d_TMF_2d, gp_Pnt (-1.0, -1.0, 0.0));
+    aContext->SetTransformPersistence (aCS, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
   }
 
   Standard_Real                   aMinRange    = aCS->GetMin();
@@ -4278,169 +4290,105 @@ static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer th
 }
 
 //==============================================================================
-//function : VPrintView
-//purpose  : Test printing algorithm, print the view to image file with given
-//           width and height. Printing implemented only for WNT.
+//function : VTile
+//purpose  :
 //==============================================================================
-static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
-                       const char** argv)
+static int VTile (Draw_Interpretor& theDI,
+                  Standard_Integer  theArgNb,
+                  const char**      theArgVec)
 {
-#ifndef _WIN32
-  (void )argc;
-  (void )argv;
-  di << "Printing implemented only for WNT!\n";
-  return 0;
-#else
-
-  Handle(AIS_InteractiveContext) aContextAIS = NULL;
-  Handle(V3d_View) aView = NULL;
-  aContextAIS = ViewerTest::GetAISContext();
-  if (!aContextAIS.IsNull())
-  {
-    const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
-    Vwr->InitActiveViews();
-    if(Vwr->MoreActiveViews())
-      aView = Vwr->ActiveView();
-  }
-
-  // check for errors
+  Handle(V3d_View) aView = ViewerTest::CurrentView();
   if (aView.IsNull())
   {
-    di << "Call vinit before!\n";
-    return 1;
-  }
-  else if (argc < 4)
-  {
-    di << "Use: " << argv[0];
-    di << " width height filename [print algo=0] [tile_width tile_height]\n";
-    di << "width, height of the intermediate buffer for operation\n";
-    di << "algo : {0|1}\n";
-    di << "        0 - stretch algorithm\n";
-    di << "        1 - tile algorithm\n";
-    di << "test printing algorithms into an intermediate buffer\n";
-    di << "using specific tile size if provided\n";
-    di << "with saving output to an image file\n";
+    std::cerr << "Error: no active viewer.\n";
     return 1;
   }
 
-  // get the input params
-  Standard_Integer aWidth  = Draw::Atoi (argv[1]);
-  Standard_Integer aHeight = Draw::Atoi (argv[2]);
-  Standard_Integer aMode   = 0;
-  TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
-  if (argc >= 5)
-    aMode = Draw::Atoi (argv[4]);
-
-  Standard_Integer aTileWidth  = 0;
-  Standard_Integer aTileHeight = 0;
-  Standard_Boolean isTileSizeProvided = Standard_False;
-  if (argc == 7)
+  Graphic3d_CameraTile aTile = aView->Camera()->Tile();
+  if (theArgNb < 2)
   {
-    isTileSizeProvided = Standard_True;
-    aTileWidth  = Draw::Atoi (argv[5]);
-    aTileHeight = Draw::Atoi (argv[6]);
+    theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n"
+          << "Tile  size: " << aTile.TileSize.x()  << " " << aTile.TileSize.y()  << "\n"
+          << "Lower left: " << aTile.Offset.x()    << " " << aTile.Offset.y()    << "\n";
+    return 0;
   }
 
-  // check the input parameters
-  if (aWidth <= 0 || aHeight <= 0)
+  aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y());
+  for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
   {
-    di << "Width and height must be positive values!\n";
-    return 1;
-  }
-  if (aMode != 0 && aMode != 1)
-    aMode = 0;
-
-  // define compatible bitmap
-  HDC anDC = CreateCompatibleDC(0);
-  BITMAPINFO aBitmapData;
-  memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
-  aBitmapData.bmiHeader.biSize          = sizeof (BITMAPINFOHEADER);
-  aBitmapData.bmiHeader.biWidth         = aWidth ;
-  aBitmapData.bmiHeader.biHeight        = aHeight;
-  aBitmapData.bmiHeader.biPlanes        = 1;
-  aBitmapData.bmiHeader.biBitCount      = 24;
-  aBitmapData.bmiHeader.biXPelsPerMeter = 0;
-  aBitmapData.bmiHeader.biYPelsPerMeter = 0;
-  aBitmapData.bmiHeader.biClrUsed       = 0;
-  aBitmapData.bmiHeader.biClrImportant  = 0;
-  aBitmapData.bmiHeader.biCompression   = BI_RGB;
-  aBitmapData.bmiHeader.biSizeImage     = 0;
-
-  // Create Device Independent Bitmap
-  void* aBitsOut = NULL;
-  HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
-                                            &aBitsOut, NULL, 0);
-  HGDIOBJ anOldBitmap   = SelectObject(anDC, aMemoryBitmap);
-
-  Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
-  if (aBitsOut != NULL)
-  {
-    if (aMode == 0)
-      isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
-    else
+    TCollection_AsciiString anArg (theArgVec[anArgIter]);
+    anArg.LowerCase();
+    if (anArg == "-lowerleft"
+     || anArg == "-upperleft")
     {
-      if (isTileSizeProvided)
+      if (anArgIter + 3 < theArgNb)
       {
-        Handle(Graphic3d_CView)    aGraphicView = ViewerTest::CurrentView()->View();
-        Handle(Standard_Transient) anOldBuffer  = aGraphicView->FBO();
-        Handle(Standard_Transient) aNewBuffer   = aGraphicView->FBOCreate (aTileWidth, aTileHeight);
-        aGraphicView->SetFBO (aNewBuffer);
-
-        isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
-
-        aGraphicView->FBORelease (aNewBuffer);
-        aGraphicView->SetFBO (anOldBuffer);
+        std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
+        return 1;
       }
-      else
+      aTile.IsTopDown = (anArg == "-upperleft") == Standard_True;
+      aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
+      aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
+    }
+    else if (anArg == "-total"
+          || anArg == "-totalsize"
+          || anArg == "-viewsize")
+    {
+      if (anArgIter + 3 < theArgNb)
+      {
+        std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
+        return 1;
+      }
+      aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
+      aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
+      if (aTile.TotalSize.x() < 1
+       || aTile.TotalSize.y() < 1)
       {
-        isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
+        std::cerr << "Error: total size is incorrect.\n";
+        return 1;
       }
     }
-
-    // successfully printed into an intermediate buffer
-    if (isPrinted)
+    else if (anArg == "-tilesize")
     {
-      Image_PixMap aWrapper;
-      aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
-      aWrapper.SetTopDown (false);
+      if (anArgIter + 3 < theArgNb)
+      {
+        std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
+        return 1;
+      }
 
-      Image_AlienPixMap anImageBitmap;
-      anImageBitmap.InitCopy (aWrapper);
-      isSaved = anImageBitmap.Save (aFileName);
+      aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
+      aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
+      if (aTile.TileSize.x() < 1
+       || aTile.TileSize.y() < 1)
+      {
+        std::cerr << "Error: tile size is incorrect.\n";
+        return 1;
+      }
     }
-    else
+    else if (anArg == "-unset")
     {
-      di << "Print operation failed due to printing errors or\n";
-      di << "insufficient memory available\n";
-      di << "Please, try to use smaller dimensions for this test\n";
-      di << "command, as it allocates intermediate buffer for storing\n";
-      di << "the result\n";
+      aView->Camera()->SetTile (Graphic3d_CameraTile());
+      aView->Redraw();
+      return 0;
     }
   }
-  else
-  {
-    di << "Can't allocate memory for intermediate buffer\n";
-    di << "Please use smaller dimensions\n";
-  }
 
-  if (aMemoryBitmap)
+  if (aTile.TileSize.x() < 1
+   || aTile.TileSize.y() < 1)
   {
-    SelectObject (anDC, anOldBitmap);
-    DeleteObject (aMemoryBitmap);
-    DeleteDC(anDC);
+    std::cerr << "Error: tile size is undefined.\n";
+    return 1;
   }
-
-  if (!isSaved)
+  else if (aTile.TotalSize.x() < 1
+        || aTile.TotalSize.y() < 1)
   {
-    di << "Save to file operation failed. This operation may fail\n";
-    di << "if you don't have enough available memory, then you can\n";
-    di << "use smaller dimensions for the output file\n";
+    std::cerr << "Error: total size is undefined.\n";
     return 1;
   }
 
+  aView->Camera()->SetTile (aTile);
+  aView->Redraw();
   return 0;
-
-#endif
 }
 
 //==============================================================================
@@ -4800,7 +4748,7 @@ static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char**
                             aLineType, aWidth,
                             aTransparency);
 
-  aContext->SetTransformPersistence (aLine, Graphic3d_TMF_2d, gp_Pnt (-1.0, -1.0, 0.0));
+  aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
   aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
   aLine->SetToUpdate();
   aContext->Display (aLine, Standard_True);
@@ -5807,7 +5755,7 @@ static Standard_Integer VSelect (Draw_Interpretor& di,
     }
 
     Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]);
-    myAIScontext->MainSelector()->AllowOverlapDetection((Standard_Boolean)isToAllow);
+    myAIScontext->MainSelector()->AllowOverlapDetection (isToAllow != 0);
     aCoordsNb -= 2;
   }
 
@@ -7684,9 +7632,9 @@ static int VLight (Draw_Interpretor& theDi,
   {
     // print lights info
     Standard_Integer aLightId = 0;
-    for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId)
+    for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId)
     {
-      Handle(V3d_Light) aLight = aView->ActiveLight();
+      Handle(V3d_Light) aLight = aLightIter.Value();
       const Quantity_Color aColor = aLight->Color();
       theDi << "Light" << aLightId << "\n";
       switch (aLight->Type())
@@ -7800,11 +7748,11 @@ static int VLight (Draw_Interpretor& theDi,
           || anArgCase.IsEqual ("CLEAR"))
     {
       toCreate = Standard_False;
-      aView->InitActiveLights();
-      while (aView->MoreActiveLights())
+      for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
       {
-        aViewer->DelLight (aView->ActiveLight());
-        aView->InitActiveLights();
+        Handle(V3d_Light) aLight = aLightIter.Value();
+        aViewer->DelLight (aLight);
+        aLightIter = aView->ActiveLightIterator();
       }
     }
     else if (anArgCase.IsEqual ("AMB")
@@ -7868,11 +7816,11 @@ static int VLight (Draw_Interpretor& theDi,
 
       const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
       Standard_Integer aLightIt = 0;
-      for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
+      for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
       {
         if (aLightIt == aLightId)
         {
-          aLightOld = aView->ActiveLight();
+          aLightOld = aLightIter.Value();
           break;
         }
       }
@@ -7896,9 +7844,9 @@ static int VLight (Draw_Interpretor& theDi,
       const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
       const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
       Standard_Integer aLightIt = 0;
-      for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
+      for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
       {
-        aLightDel = aView->ActiveLight();
+        aLightDel = aLightIter.Value();
         if (aLightIt == aLightDelId)
         {
           break;
@@ -8222,7 +8170,7 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
       case Graphic3d_RM_RAYTRACING:    theDI << "raytrace ";      break;
     }
     theDI << "\n";
-    theDI << "msaa:         " <<  aParams.NbMsaaSamples << "\n";
+    theDI << "msaa:         " <<  aParams.NbMsaaSamples                               << "\n";
     theDI << "rayDepth:     " <<  aParams.RaytracingDepth                             << "\n";
     theDI << "fsaa:         " << (aParams.IsAntialiasingEnabled       ? "on" : "off") << "\n";
     theDI << "shadows:      " << (aParams.IsShadowEnabled             ? "on" : "off") << "\n";
@@ -8230,6 +8178,8 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
     theDI << "gleam:        " << (aParams.IsTransparentShadowEnabled  ? "on" : "off") << "\n";
     theDI << "GI:           " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
     theDI << "blocked RNG:  " << (aParams.CoherentPathTracingMode     ? "on" : "off") << "\n";
+    theDI << "iss:          " << (aParams.AdaptiveScreenSampling      ? "on" : "off") << "\n";
+    theDI << "iss debug:    " << (aParams.ShowSamplingTiles           ? "on" : "off") << "\n";
     theDI << "shadingModel: ";
     switch (aView->ShadingModel())
     {
@@ -8455,6 +8405,38 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
       }
       aParams.CoherentPathTracingMode = toEnable;
     }
+    else if (aFlag == "-iss")
+    {
+      if (toPrint)
+      {
+        theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
+        continue;
+      }
+
+      Standard_Boolean toEnable = Standard_True;
+      if (++anArgIter < theArgNb
+        && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
+      {
+        --anArgIter;
+      }
+      aParams.AdaptiveScreenSampling = toEnable;
+    }
+    else if (aFlag == "-issd")
+    {
+      if (toPrint)
+      {
+        theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
+        continue;
+      }
+
+      Standard_Boolean toEnable = Standard_True;
+      if (++anArgIter < theArgNb
+        && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
+      {
+        --anArgIter;
+      }
+      aParams.ShowSamplingTiles = toEnable;
+    }
     else if (aFlag == "-env")
     {
       if (toPrint)
@@ -8542,6 +8524,23 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
         return 1;
       }
     }
+    else if (aFlag == "-rebuildglsl"
+          || aFlag == "-rebuild")
+    {
+      if (toPrint)
+      {
+        theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
+        continue;
+      }
+
+      Standard_Boolean toEnable = Standard_True;
+      if (++anArgIter < theArgNb
+          && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
+      {
+        --anArgIter;
+      }
+      aParams.RebuildRayTracingShaders = toEnable;
+    }
     else
     {
       std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
@@ -9045,6 +9044,133 @@ static int VManipulator (Draw_Interpretor& theDi,
   return 0;
 }
 
+//===============================================================================================
+//function : parseColor
+//purpose  :
+//===============================================================================================
+static Standard_Boolean parseColor (ViewerTest_CmdParser& theParser,
+                                    const std::string&    theOptionName,
+                                    Quantity_Color&       theColor)
+{
+  std::string aColorArg = theParser.Arg (theOptionName, 0);
+  if (std::isdigit (aColorArg[0]))
+  {
+    Graphic3d_Vec3d aColor = theParser.ArgVec3d (theOptionName);
+    if (aColor.x() < 0.0 || aColor.x() > 1.0
+      || aColor.y() < 0.0 || aColor.y() > 1.0
+      || aColor.z() < 0.0 || aColor.z() > 1.0)
+    {
+      std::cerr << "Error: RGB color values should be within range 0..1!\n";
+      return Standard_False;
+    }
+    theColor.SetValues (aColor.x(), aColor.y(), aColor.z(), Quantity_TOC_RGB);
+  }
+  else
+  {
+    Quantity_NameOfColor aName = Quantity_NOC_BLACK;
+    if (!Quantity_Color::ColorFromName (aColorArg.c_str(), aName))
+    {
+      std::cerr << "Name: " << theParser.Arg (theOptionName, 0)
+                << " does not correspond to any color in Quantity_NameOfColor!"
+                << std::endl;
+      return Standard_False;
+    }
+    theColor.SetValues (aName);
+  }
+
+  return Standard_True;
+}
+
+//===============================================================================================
+//function : VSelectionProperties
+//purpose  :
+//===============================================================================================
+static int VSelectionProperties (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;
+  }
+
+  ViewerTest_CmdParser aCmd;
+
+  aCmd.AddOption ("autoActivate");
+  aCmd.AddOption ("pixTol");
+
+  aCmd.AddOption ("selColor");
+  aCmd.AddOption ("hiColor");
+  aCmd.AddOption ("selTransp");
+  aCmd.AddOption ("hiTransp");
+
+  aCmd.AddOption ("print");
+
+  aCmd.Parse (theArgsNb, theArgVec);
+
+  if (aCmd.HasOption ("help"))
+  {
+    theDi.PrintHelp (theArgVec[0]);
+    return 0;
+  }
+
+  if (aCmd.HasOption ("autoActivate", 1, Standard_False))
+  {
+    aCtx->SetAutoActivateSelection (aCmd.ArgBool ("autoActivate"));
+  }
+  if (aCmd.HasOption ("pixTol", 1, Standard_False))
+  {
+    aCtx->SetPixelTolerance (aCmd.ArgInt ("pixTol"));
+  }
+
+  Handle(Graphic3d_HighlightStyle)& aHiStyle = aCtx->ChangeHighlightStyle();
+  Handle(Graphic3d_HighlightStyle)& aSelStyle = aCtx->ChangeSelectionStyle();
+  Standard_Boolean toRedraw = Standard_False;
+  if (aCmd.HasOption ("selColor"))
+  {
+    Quantity_Color aNewColor;
+    if (!parseColor (aCmd, "selColor", aNewColor))
+      return 1;
+    aSelStyle->SetColor (aNewColor);
+    toRedraw = Standard_True;
+  }
+  if (aCmd.HasOption ("hiColor"))
+  {
+    Quantity_Color aNewColor;
+    if (!parseColor (aCmd, "hiColor", aNewColor))
+      return 1;
+    aHiStyle->SetColor (aNewColor);
+  }
+  if (aCmd.HasOption ("selTransp"))
+  {
+    aSelStyle->SetTransparency (aCmd.ArgFloat ("selTransp"));
+    toRedraw = Standard_True;
+  }
+  if (aCmd.HasOption ("hiTransp"))
+  {
+    aHiStyle->SetTransparency (aCmd.ArgFloat ("hiTransp"));
+  }
+
+  if (aCmd.HasOption ("print") || theArgsNb == 1)
+  {
+    theDi << "Auto-activation                : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
+    theDi << "Selection pixel tolerance      : " << aCtx->MainSelector()->PixelTolerance() << "\n";
+    theDi << "Selection color                : " << Quantity_Color::StringName (aCtx->SelectionStyle()->Color().Name()) << "\n";
+    theDi << "Dynamic highlight color        : " << Quantity_Color::StringName (aCtx->HighlightStyle()->Color().Name()) << "\n";
+    theDi << "Selection transparency         : " << aCtx->SelectionStyle()->Transparency() << "\n";
+    theDi << "Dynamic highlight transparency : " << aCtx->HighlightStyle()->Transparency() << "\n";
+  }
+
+  if (aCtx->NbSelected() != 0 && toRedraw)
+  {
+    aCtx->HilightSelected (Standard_True);
+  }
+
+  return 0;
+}
+
 //=======================================================================
 //function : ViewerCommands
 //purpose  :
@@ -9229,9 +9355,14 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
     " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
     __FILE__,VGraduatedTrihedron,group);
-  theCommands.Add("vprintview" ,
-    "vprintview : width height filename [algo=0] [tile_width tile_height] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
-    __FILE__,VPrintView,group);
+  theCommands.Add("vtile" ,
+            "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]"
+    "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)."
+    "\n\t\t:  -totalSize the size of virtual bigger viewport"
+    "\n\t\t:  -tileSize  tile size (the view size will be used if omitted)"
+    "\n\t\t:  -lowerLeft tile offset as lower left corner"
+    "\n\t\t:  -upperLeft tile offset as upper left corner",
+    __FILE__, VTile, group);
   theCommands.Add("vzlayer",
     "vzlayer add/del/get/settings/enable/disable [id]\n"
     " add - add new z layer to viewer and print its id\n"
@@ -9549,6 +9680,9 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     "\n      '-gi           on|off'  Enables/disables global illumination effects"
     "\n      '-brng         on|off'  Enables/disables blocked RNG (fast coherent PT)"
     "\n      '-env          on|off'  Enables/disables environment map background"
+    "\n      '-iss          on|off'  Enables/disables adaptive screen sampling (PT mode)"
+    "\n      '-issd         on|off'  Shows screen sampling distribution in ISS mode"
+    "\n      '-rebuildGlsl  on|off'  Rebuild Ray-Tracing GLSL programs (for debugging)"
     "\n      '-shadingModel model'   Controls shading model from enumeration"
     "\n                              color, flat, gouraud, phong"
     "\n      '-resolution   value'   Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
@@ -9596,6 +9730,18 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
       "\n      '-zoomable {0|1}'                 - set zoom persistence",
     __FILE__, VManipulator, group);
 
+  theCommands.Add("vselprops",
+    "\n    vselprops [options]"
+    "\n    Customizes selection and dynamic highlight parameters for the whole interactive context:"
+    "\n    -autoActivate {0|1}     : disables|enables default computation and activation of global selection mode"
+    "\n    -pixTol    value        : sets up pixel tolerance"
+    "\n    -selColor  {name|r g b} : sets selection color"
+    "\n    -hiColor   {name|r g b} : sets dynamic highlight color"
+    "\n    -selTransp value        : sets transparency coefficient for selection"
+    "\n    -hiTransp  value        : sets transparency coefficient for dynamic highlight"
+    "\n    -print                  : prints current state of all mentioned parameters",
+    __FILE__, VSelectionProperties, group);
+
 #if defined(_WIN32)
   theCommands.Add("vprogressive",
     "vprogressive",