0024023: Revamp the OCCT Handle - gcc and clang
[occt.git] / src / ViewerTest / ViewerTest.cxx
index df43089..aac3b95 100644 (file)
 #include <Standard_Stream.hxx>
 
 #include <ViewerTest.hxx>
+#include <ViewerTest_CmdParser.hxx>
+
 #include <TopLoc_Location.hxx>
 #include <TopTools_HArray1OfShape.hxx>
 #include <TColStd_HArray1OfTransient.hxx>
+#include <TColStd_SequenceOfAsciiString.hxx>
 #include <TColStd_HSequenceOfAsciiString.hxx>
+#include <TColStd_MapOfTransient.hxx>
 #include <OSD_Timer.hxx>
 #include <Geom_Axis2Placement.hxx>
 #include <Geom_Axis1Placement.hxx>
@@ -37,7 +41,7 @@
 #include <BRepAdaptor_Curve.hxx>
 #include <StdSelect_ShapeTypeFilter.hxx>
 #include <AIS.hxx>
-#include <AIS_Drawer.hxx>
+#include <AIS_ColoredShape.hxx>
 #include <AIS_InteractiveObject.hxx>
 #include <AIS_Trihedron.hxx>
 #include <AIS_Axis.hxx>
 #include <Aspect_Window.hxx>
 #include <Graphic3d_AspectFillArea3d.hxx>
 #include <Graphic3d_AspectLine3d.hxx>
+#include <Graphic3d_CStructure.hxx>
 #include <Graphic3d_TextureRoot.hxx>
 #include <Image_AlienPixMap.hxx>
+#include <Prs3d_Drawer.hxx>
 #include <Prs3d_ShadingAspect.hxx>
 #include <Prs3d_IsoAspect.hxx>
+#include <Prs3d_PointAspect.hxx>
+#include <Select3D_SensitiveWire.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+#include <StdSelect_BRepOwner.hxx>
+#include <StdSelect_ViewerSelector3d.hxx>
 #include <TopTools_MapOfShape.hxx>
+#include <ViewerTest_AutoUpdater.hxx>
 
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
 #include <stdio.h>
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif
 
 #include <Draw_Interpretor.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <Draw_PluginMacro.hxx>
-#include <ViewerTest.hxx>
 
 // avoid warnings on 'extern "C"' functions returning C++ classes
 #ifdef WNT
@@ -77,8 +82,6 @@
 #pragma warning (disable:4996)
 #endif
 
-#include <NIS_InteractiveContext.hxx>
-#include <NIS_Triangulated.hxx>
 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
 
 #include <Quantity_Color.hxx>
@@ -86,86 +89,70 @@ extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
 
 #include <Graphic3d_NameOfMaterial.hxx>
 
-#define DEFAULT_COLOR    Quantity_NOC_GOLDENROD
-#define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
+#define DEFAULT_COLOR              Quantity_NOC_GOLDENROD
+#define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
+#define DEFAULT_MATERIAL           Graphic3d_NOM_BRASS
 
-enum ViewerTest_RedrawMode
-{
-  ViewerTest_RM_Auto = -1,
-  ViewerTest_RM_RedrawForce,
-  ViewerTest_RM_RedrawSuppress
-};
+//=======================================================================
+//function : GetColorFromName
+//purpose  : get the Quantity_NameOfColor from a string
+//=======================================================================
 
-//! Auxiliary method to parse redraw mode argument
-static Standard_Boolean parseRedrawMode (const TCollection_AsciiString& theArg,
-                                         ViewerTest_RedrawMode&         theMode)
+Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
 {
-  TCollection_AsciiString anArgCase (theArg);
-  anArgCase.LowerCase();
-  if (anArgCase == "-update"
-   || anArgCase == "-redraw")
-  {
-    theMode = ViewerTest_RM_RedrawForce;
-    return Standard_True;
-  }
-  else if (anArgCase == "-noupdate"
-        || anArgCase == "-noredraw")
-  {
-    theMode = ViewerTest_RM_RedrawSuppress;
-    return Standard_True;
-  }
-  return Standard_False;
+  Quantity_NameOfColor aColor = DEFAULT_COLOR;
+  Quantity_Color::ColorFromName (theName, aColor);
+  return aColor;
 }
 
 //=======================================================================
-//function : GetColorFromName
-//purpose  : get the Quantity_NameOfColor from a string
+//function : ParseColor
+//purpose  :
 //=======================================================================
 
-Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
+Standard_Integer ViewerTest::ParseColor (Standard_Integer  theArgNb,
+                                         const char**      theArgVec,
+                                         Quantity_Color&   theColor)
 {
-  for (Standard_Integer anIter = Quantity_NOC_BLACK; anIter <= Quantity_NOC_WHITE; ++anIter)
+  Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
+  if (theArgNb >= 1
+   && Quantity_Color::ColorFromName (theArgVec[0], aColor))
+  {
+    theColor = aColor;
+    return 1;
+  }
+  else if (theArgNb >= 3)
   {
-    Standard_CString aColorName = Quantity_Color::StringName (Quantity_NameOfColor (anIter));
-    if (strcasecmp (theName, aColorName) == 0)
+    const TCollection_AsciiString anRgbStr[3] =
     {
-      return Quantity_NameOfColor (anIter);
+      theArgVec[0],
+      theArgVec[1],
+      theArgVec[2]
+    };
+    if (!anRgbStr[0].IsRealValue()
+     || !anRgbStr[1].IsRealValue()
+     || !anRgbStr[2].IsRealValue())
+    {
+      return 0;
     }
-  }
 
-  return DEFAULT_COLOR;
-}
+    Graphic3d_Vec4d anRgb;
+    anRgb.x() = anRgbStr[0].RealValue();
+    anRgb.y() = anRgbStr[1].RealValue();
+    anRgb.z() = anRgbStr[2].RealValue();
+    if (anRgb.x() < 0.0 || anRgb.x() > 1.0
+     || anRgb.y() < 0.0 || anRgb.y() > 1.0
+     || anRgb.z() < 0.0 || anRgb.z() > 1.0)
+    {
+      std::cout << "Error: RGB color values should be within range 0..1!\n";
+      return 0;
+    }
 
-//=======================================================================
-//function : GetMaterialFromName
-//purpose  : get the Graphic3d_NameOfMaterial from a string
-//=======================================================================
+    theColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
+    return 3;
+  }
 
-static Graphic3d_NameOfMaterial GetMaterialFromName( const char *name )
-{
-  Graphic3d_NameOfMaterial mat = DEFAULT_MATERIAL;
-
-  if      ( !strcasecmp(name,"BRASS" ) )        mat = Graphic3d_NOM_BRASS;
-  else if ( !strcasecmp(name,"BRONZE" ) )        mat = Graphic3d_NOM_BRONZE;
-  else if ( !strcasecmp(name,"COPPER" ) )       mat = Graphic3d_NOM_COPPER;
-  else if ( !strcasecmp(name,"GOLD" ) )         mat = Graphic3d_NOM_GOLD;
-  else if ( !strcasecmp(name,"PEWTER" ) )       mat = Graphic3d_NOM_PEWTER;
-  else if ( !strcasecmp(name,"SILVER" ) )       mat = Graphic3d_NOM_SILVER;
-  else if ( !strcasecmp(name,"STEEL" ) )        mat = Graphic3d_NOM_STEEL;
-  else if ( !strcasecmp(name,"METALIZED" ) )    mat = Graphic3d_NOM_METALIZED;
-  else if ( !strcasecmp(name,"STONE" ) )        mat = Graphic3d_NOM_STONE;
-  else if ( !strcasecmp(name,"CHROME" ) )       mat = Graphic3d_NOM_CHROME;
-  else if ( !strcasecmp(name,"ALUMINIUM" ) )     mat = Graphic3d_NOM_ALUMINIUM;
-  else if ( !strcasecmp(name,"NEON_PHC" ) )     mat = Graphic3d_NOM_NEON_PHC;
-  else if ( !strcasecmp(name,"NEON_GNC" ) )     mat = Graphic3d_NOM_NEON_GNC;
-  else if ( !strcasecmp(name,"PLASTER" ) )      mat = Graphic3d_NOM_PLASTER;
-  else if ( !strcasecmp(name,"SHINY_PLASTIC" ) ) mat = Graphic3d_NOM_SHINY_PLASTIC;
-  else if ( !strcasecmp(name,"SATIN" ) )        mat = Graphic3d_NOM_SATIN;
-  else if ( !strcasecmp(name,"PLASTIC" ) )      mat = Graphic3d_NOM_PLASTIC;
-  else if ( !strcasecmp(name,"OBSIDIAN" ) )     mat = Graphic3d_NOM_OBSIDIAN;
-  else if ( !strcasecmp(name,"JADE" ) )                 mat = Graphic3d_NOM_JADE;
-
-  return mat;
+  return 0;
 }
 
 //=======================================================================
@@ -269,24 +256,20 @@ Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
   return TheMap;
 }
 
-
-//==============================================================================
-//function : VDisplayAISObject
-//purpose  : register interactive object in the map of AIS objects;
-//           if other object with such name already registered, it will be kept
-//           or replaced depending on value of <theReplaceIfExists>,
-//           if "true" - the old object will be cleared from AIS context;
-//           returns Standard_True if <theAISObj> registered in map;
-//==============================================================================
-Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
-                                                    const Handle(AIS_InteractiveObject)& theAISObj,
-                                                    Standard_Boolean theReplaceIfExists = Standard_True)
+//=======================================================================
+//function : Display
+//purpose  :
+//=======================================================================
+Standard_Boolean ViewerTest::Display (const TCollection_AsciiString&       theName,
+                                      const Handle(AIS_InteractiveObject)& theObject,
+                                      const Standard_Boolean               theToUpdate,
+                                      const Standard_Boolean               theReplaceIfExists)
 {
   ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
-  Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
-  if (aContextAIS.IsNull())
+  Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
+  if (aCtx.IsNull())
   {
-    std::cout << "AIS context is not available.\n";
+    std::cout << "Error: AIS context is not available.\n";
     return Standard_False;
   }
 
@@ -294,42 +277,46 @@ Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiStrin
   {
     if (!theReplaceIfExists)
     {
-      std::cout << "Other interactive object has been already "
-                << "registered with name: " << theName << ".\n"
+      std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n"
                 << "Please use another name.\n";
       return Standard_False;
     }
 
-    // stop displaying object
-    Handle(AIS_InteractiveObject) anOldObj =
-       Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
-
+    Handle(AIS_InteractiveObject) anOldObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
     if (!anOldObj.IsNull())
-      aContextAIS->Clear (anOldObj, Standard_True);
-
-    // remove name and old object from map
+    {
+      aCtx->Remove (anOldObj, Standard_True);
+    }
     aMap.UnBind2 (theName);
   }
 
-  if (theAISObj.IsNull())
+  if (theObject.IsNull())
   {
-    // object with specified name already unbound
+    // object with specified name has been already unbound
     return Standard_True;
   }
 
-  // unbind AIS object if was bound with another name
-  aMap.UnBind1 (theAISObj);
+  // unbind AIS object if it was bound with another name
+  aMap.UnBind1 (theObject);
 
   // can be registered without rebinding
-  aMap.Bind (theAISObj, theName);
-  aContextAIS->Display (theAISObj, Standard_True);
+  aMap.Bind (theObject, theName);
+  aCtx->Display (theObject, theToUpdate);
   return Standard_True;
 }
 
+//! Alias for ViewerTest::Display(), compatibility with old code.
+Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString&       theName,
+                                                    const Handle(AIS_InteractiveObject)& theObject,
+                                                    Standard_Boolean theReplaceIfExists = Standard_True)
+{
+  return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
+}
+
 static TColStd_MapOfInteger theactivatedmodes(8);
 static TColStd_ListOfTransient theEventMgrs;
 
-static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
+static void VwrTst_InitEventMgr(const Handle(V3d_View)& aView,
                                 const Handle(AIS_InteractiveContext)& Ctx)
 {
   theEventMgrs.Clear();
@@ -357,16 +344,6 @@ void ViewerTest::CurrentView(const Handle(V3d_View)& V)
   a3DView() = V;
 }
 
-Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
-{
-  static Handle(NIS_InteractiveContext) aContext;
-  if (aContext.IsNull()) {
-    aContext = new NIS_InteractiveContext;
-    aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
-  }
-  return aContext;
-}
-
 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
 {
   return TheAISContext();
@@ -401,8 +378,7 @@ void ViewerTest::UnsetEventManager()
 
 void ViewerTest::ResetEventManager()
 {
-  const Handle(NIS_View) aView =
-    Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
+  const Handle(V3d_View) aView = ViewerTest::CurrentView();
   VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
 }
 
@@ -411,7 +387,7 @@ Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
   Handle(ViewerTest_EventManager) EM;
   if(theEventMgrs.IsEmpty()) return EM;
   Handle(Standard_Transient) Tr =  theEventMgrs.First();
-  EM = *((Handle(ViewerTest_EventManager)*)&Tr);
+  EM = Handle(ViewerTest_EventManager)::DownCast (Tr);
   return EM;
 }
 
@@ -464,7 +440,7 @@ Handle(AIS_Shape) GetAISShapeFromName(const char* name)
     if (!IO.IsNull()) {
       if(IO->Type()==AIS_KOI_Shape) {
         if(IO->Signature()==0){
-          retsh = *((Handle(AIS_Shape)*)&IO);
+          retsh = Handle(AIS_Shape)::DownCast (IO);
         }
         else
           cout << "an Object which is not an AIS_Shape "
@@ -495,19 +471,12 @@ void ViewerTest::Clear()
     ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
     while ( it.More() ) {
       cout << "Remove " << it.Key2() << endl;
-      if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
-        const Handle(AIS_InteractiveObject) anObj =
-          Handle(AIS_InteractiveObject)::DownCast (it.Key1());
-        TheAISContext()->Remove(anObj,Standard_False);
-      } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
-        const Handle(NIS_InteractiveObject) anObj =
-          Handle(NIS_InteractiveObject)::DownCast (it.Key1());
-        TheNISContext()->Remove(anObj);
-      }
+      const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (it.Key1());
+      TheAISContext()->Remove(anObj,Standard_False);
       it.Next();
     }
+    TheAISContext()->RebuildSelectionStructs();
     TheAISContext()->UpdateCurrentViewer();
-//    TheNISContext()->UpdateViews();
     GetMapOfAIS().Clear();
   }
 }
@@ -657,7 +626,7 @@ static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv
       if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
         const Handle(AIS_InteractiveObject) aShape =
         Handle(AIS_InteractiveObject)::DownCast (anObj);
-        Handle(AIS_Drawer) CurDrawer = aShape->Attributes();
+        Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
         Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
         Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
 
@@ -686,51 +655,6 @@ static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv
   return 0;
 }
 
-//==============================================================================
-//function : VDispAreas,VDispSensitive,...
-//purpose  :
-//==============================================================================
-static Standard_Integer VDispAreas (Draw_Interpretor& ,
-                                    Standard_Integer  theArgNb,
-                                    Standard_CString* )
-{
-  if (theArgNb > 1)
-  {
-    std::cout << "Error: wrong syntax!\n";
-    return 1;
-  }
-
-  Handle(AIS_InteractiveContext) aCtx;
-  Handle(V3d_View)               aView;
-  if (!getCtxAndView (aCtx, aView))
-  {
-    return 1;
-  }
-
-  aCtx->DisplayActiveAreas (aView);
-  return 0;
-}
-static Standard_Integer VClearAreas (Draw_Interpretor& ,
-                                     Standard_Integer  theArgNb,
-                                     Standard_CString* )
-{
-  if (theArgNb > 1)
-  {
-    std::cout << "Error: wrong syntax!\n";
-    return 1;
-  }
-
-  Handle(AIS_InteractiveContext) aCtx;
-  Handle(V3d_View)               aView;
-  if (!getCtxAndView (aCtx, aView))
-  {
-    return 1;
-  }
-
-  aCtx->ClearActiveAreas (aView);
-  return 0;
-
-}
 static Standard_Integer VDispSensi (Draw_Interpretor& ,
                                     Standard_Integer  theArgNb,
                                     Standard_CString* )
@@ -796,17 +720,16 @@ static int VDir (Draw_Interpretor& theDI,
 
 //==============================================================================
 //function : VSelPrecision
-//purpose  : To set the selection precision mode and tolerance value
-//Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance
-//           value (integer number of pixel for window mode, double value of
-//           sensitivity for view mode). Without arguments the function just
-//           prints the current precision mode and the corresponding tolerance.
+//purpose  : To set the selection tolerance value
+//Draw arg : Selection tolerance value (real value determining the width and
+//           height of selecting frustum bases). Without arguments the function
+//           just prints current tolerance.
 //==============================================================================
 static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
-  if( argc > 3 )
+  if( argc > 2 )
   {
-    di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n";
+    di << "Wrong parameters! Must be: " << argv[0] << " [-unset] [tolerance]\n";
     return 1;
   }
 
@@ -816,41 +739,34 @@ static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char
 
   if( argc == 1 )
   {
-    StdSelect_SensitivityMode aMode = aContext->SensitivityMode();
-    if( aMode == StdSelect_SM_WINDOW )
-    {
-      Standard_Integer aPixelTolerance = aContext->PixelTolerance();
-      di << "Precision mode  : 0 (window)\n";
-      di << "Pixel tolerance : " << aPixelTolerance << "\n";
-    }
-    else if( aMode == StdSelect_SM_VIEW )
-    {
-      Standard_Real aSensitivity = aContext->Sensitivity();
-      di << "Precision mode : 1 (view)\n";
-      di << "Sensitivity    : " << aSensitivity << "\n";
-    }
+    Standard_Real aPixelTolerance = aContext->PixelTolerance();
+    di << "Pixel tolerance : " << aPixelTolerance << "\n";
   }
-  else if( argc > 1 )
+  else if (argc == 2)
   {
-    StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )Draw::Atoi( argv[1] );
-    aContext->SetSensitivityMode( aMode );
-    if( argc > 2 )
+    TCollection_AsciiString anArg = TCollection_AsciiString (argv[1]);
+    anArg.LowerCase();
+    if (anArg == "-unset")
     {
-      if( aMode == StdSelect_SM_WINDOW )
-      {
-        Standard_Integer aPixelTolerance = Draw::Atoi( argv[2] );
-        aContext->SetPixelTolerance( aPixelTolerance );
-      }
-      else if( aMode == StdSelect_SM_VIEW )
-      {
-        Standard_Real aSensitivity = Draw::Atof( argv[2] );
-        aContext->SetSensitivity( aSensitivity );
-      }
+      aContext->SetPixelTolerance (-1.0);
+    }
+    else
+    {
+      aContext->SetPixelTolerance (anArg.RealValue());
     }
   }
+
   return 0;
 }
 
+//! Auxiliary enumeration
+enum ViewerTest_StereoPair
+{
+  ViewerTest_SP_Single,
+  ViewerTest_SP_SideBySide,
+  ViewerTest_SP_OverUnder
+};
+
 //==============================================================================
 //function : VDump
 //purpose  : To dump the active view snapshot to image file
@@ -869,42 +785,108 @@ static Standard_Integer VDump (Draw_Interpretor& theDI,
   Standard_CString      aFilePath   = theArgVec[anArgIter++];
   Graphic3d_BufferType  aBufferType = Graphic3d_BT_RGB;
   V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
+  ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
   Standard_Integer      aWidth      = 0;
   Standard_Integer      aHeight     = 0;
   for (; anArgIter < theArgNb; ++anArgIter)
   {
     TCollection_AsciiString anArg (theArgVec[anArgIter]);
     anArg.LowerCase();
-    if (anArg == "rgba")
+    if (anArg == "-buffer")
     {
-      aBufferType = Graphic3d_BT_RGBA;
-    }
-    else if (anArg == "rgb")
-    {
-      aBufferType = Graphic3d_BT_RGB;
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at '" << anArg << "'\n";
+        return 1;
+      }
+
+      TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
+      aBufArg.LowerCase();
+      if (aBufArg == "rgba")
+      {
+        aBufferType = Graphic3d_BT_RGBA;
+      }
+      else if (aBufArg == "rgb")
+      {
+        aBufferType = Graphic3d_BT_RGB;
+      }
+      else if (aBufArg == "depth")
+      {
+        aBufferType = Graphic3d_BT_Depth;
+      }
+      else
+      {
+        std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
+        return 1;
+      }
     }
-    else if (anArg == "depth")
+    else if (anArg == "-stereo")
     {
-      aBufferType = Graphic3d_BT_Depth;
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at '" << anArg << "'\n";
+        return 1;
+      }
+
+      TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
+      aStereoArg.LowerCase();
+      if (aStereoArg == "l"
+       || aStereoArg == "left")
+      {
+        aStereoOpts = V3d_SDO_LEFT_EYE;
+      }
+      else if (aStereoArg == "r"
+            || aStereoArg == "right")
+      {
+        aStereoOpts = V3d_SDO_RIGHT_EYE;
+      }
+      else if (aStereoArg == "mono")
+      {
+        aStereoOpts = V3d_SDO_MONO;
+      }
+      else if (aStereoArg == "blended"
+            || aStereoArg == "blend"
+            || aStereoArg == "stereo")
+      {
+        aStereoOpts = V3d_SDO_BLENDED;
+      }
+      else if (aStereoArg == "sbs"
+            || aStereoArg == "sidebyside")
+      {
+        aStereoPair = ViewerTest_SP_SideBySide;
+      }
+      else if (aStereoArg == "ou"
+            || aStereoArg == "overunder")
+      {
+        aStereoPair = ViewerTest_SP_OverUnder;
+      }
+      else
+      {
+        std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
+        return 1;
+      }
     }
-    else if (anArg == "l"
-          || anArg == "left")
+    else if (anArg == "-rgba"
+          || anArg ==  "rgba")
     {
-      aStereoOpts = V3d_SDO_LEFT_EYE;
+      aBufferType = Graphic3d_BT_RGBA;
     }
-    else if (anArg == "r"
-          || anArg == "right")
+    else if (anArg == "-rgb"
+          || anArg ==  "rgb")
     {
-      aStereoOpts = V3d_SDO_RIGHT_EYE;
+      aBufferType = Graphic3d_BT_RGB;
     }
-    else if (anArg == "mono")
+    else if (anArg == "-depth"
+          || anArg ==  "depth")
     {
-      aStereoOpts = V3d_SDO_MONO;
+      aBufferType = Graphic3d_BT_Depth;
     }
-    else if (anArg == "w"
-          || anArg == "width")
+
+    else if (anArg == "-width"
+          || anArg ==  "width"
+          || anArg ==  "sizex")
     {
-      if (aWidth  != 0)
+      if (aWidth != 0)
       {
         std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
         return 1;
@@ -916,36 +898,20 @@ static Standard_Integer VDump (Draw_Interpretor& theDI,
       }
       aWidth = Draw::Atoi (theArgVec[anArgIter]);
     }
-    else if (anArg == "h"
-          || anArg == "height")
+    else if (anArg == "-height"
+          || anArg ==  "height"
+          || anArg ==  "-sizey")
     {
       if (aHeight != 0)
       {
         std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
         return 1;
       }
-      if (++anArgIter >= theArgNb)
-      {
-        std::cout << "Error: integer value is expected right after 'height'\n";
-        return 1;
-      }
-      aHeight = Draw::Atoi (theArgVec[anArgIter]);
-    }
-    else if (anArg.IsIntegerValue())
-    {
-      // compatibility with old syntax
-      if (aWidth  != 0
-       || aHeight != 0)
-      {
-        std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
-        return 1;
-      }
       else if (++anArgIter >= theArgNb)
       {
-        std::cout << "Error: height value is expected right after width\n";
+        std::cout << "Error: integer value is expected right after 'height'\n";
         return 1;
       }
-      aWidth  = Draw::Atoi (theArgVec[anArgIter - 1]);
       aHeight = Draw::Atoi (theArgVec[anArgIter]);
     }
     else
@@ -970,33 +936,82 @@ static Standard_Integer VDump (Draw_Interpretor& theDI,
 
   if (aWidth <= 0 || aHeight <= 0)
   {
-    if (aStereoOpts != V3d_SDO_MONO)
+    aView->Window()->Size (aWidth, aHeight);
+  }
+
+  Image_AlienPixMap aPixMap;
+
+  bool isBigEndian = Image_PixMap::IsBigEndianHost();
+  Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN;
+  switch (aBufferType)
+  {
+    case Graphic3d_BT_RGB:   aFormat = isBigEndian ? Image_PixMap::ImgRGB  : Image_PixMap::ImgBGR;  break;
+    case Graphic3d_BT_RGBA:  aFormat = isBigEndian ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; break;
+    case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; break;
+  }
+
+  switch (aStereoPair)
+  {
+    case ViewerTest_SP_Single:
     {
-      aView->Window()->Size (aWidth, aHeight);
+      if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
+      {
+        theDI << "Fail: view dump failed!\n";
+        return 0;
+      }
+      else if (aPixMap.SizeX() != Standard_Size(aWidth)
+            || aPixMap.SizeY() != Standard_Size(aHeight))
+      {
+        theDI << "Fail: dumped dimensions "    << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
+              << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
+      }
+      break;
     }
-    else
+    case ViewerTest_SP_SideBySide:
     {
-      if (!aView->Dump (aFilePath, aBufferType))
+      if (!aPixMap.InitZero (aFormat, aWidth * 2, aHeight))
+      {
+        theDI << "Fail: not enough memory for image allocation!\n";
+        return 0;
+      }
+
+      Image_PixMap aPixMapL, aPixMapR;
+      aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
+                            aWidth, aHeight, aPixMap.SizeRowBytes());
+      aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aWidth,
+                            aWidth, aHeight, aPixMap.SizeRowBytes());
+      if (!aView->ToPixMap (aPixMapL, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_LEFT_EYE)
+       || !aView->ToPixMap (aPixMapR, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_RIGHT_EYE)
+       )
       {
         theDI << "Fail: view dump failed!\n";
+        return 0;
       }
-      return 0;
+      break;
     }
-  }
+    case ViewerTest_SP_OverUnder:
+    {
+      if (!aPixMap.InitZero (aFormat, aWidth, aHeight * 2))
+      {
+        theDI << "Fail: not enough memory for image allocation!\n";
+        return 0;
+      }
 
-  Image_AlienPixMap aPixMap;
-  if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
-  {
-    theDI << "Fail: view dump failed!\n";
-    return 0;
+      Image_PixMap aPixMapL, aPixMapR;
+      aPixMapL.InitWrapper (aFormat, aPixMap.ChangeData(),
+                            aWidth, aHeight, aPixMap.SizeRowBytes());
+      aPixMapR.InitWrapper (aFormat, aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aHeight,
+                            aWidth, aHeight, aPixMap.SizeRowBytes());
+      if (!aView->ToPixMap (aPixMapL, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_LEFT_EYE)
+       || !aView->ToPixMap (aPixMapR, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_RIGHT_EYE))
+      {
+        theDI << "Fail: view dump failed!\n";
+        return 0;
+      }
+      break;
+    }
   }
 
-  if (aPixMap.SizeX() != Standard_Size(aWidth)
-   || aPixMap.SizeY() != Standard_Size(aHeight))
-  {
-    theDI << "Fail: dumped dimensions "    << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
-          << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
-  }
   if (!aPixMap.Save (aFilePath))
   {
     theDI << "Fail: image can not be saved!\n";
@@ -1004,7 +1019,6 @@ static Standard_Integer VDump (Draw_Interpretor& theDI,
   return 0;
 }
 
-
 //==============================================================================
 //function : Displays,Erase...
 //purpose  :
@@ -1169,494 +1183,1146 @@ static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** arg
     else return 1;
   }
   return 0;
-
 }
-//==============================================================================
-//function : VColor2
-//Author   : ege
-//purpose  : change the color of a selected or named or displayed shape
-//Draw arg : vcolor2 [name] color
-//==============================================================================
-static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
-{
 
-  Standard_Boolean    ThereIsCurrent;
-  Standard_Boolean    ThereIsArgument;
-  Standard_Boolean    IsBound = Standard_False ;
+//! Auxiliary class to iterate presentations from different collections.
+class ViewTest_PrsIter
+{
+public:
 
-  const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0);
-  if (HaveToSet) {
-    if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; }
-    ThereIsArgument = (argc != 2);
+  //! Create and initialize iterator object.
+  ViewTest_PrsIter (const TCollection_AsciiString& theName)
+  : mySource (IterSource_All)
+  {
+    NCollection_Sequence<TCollection_AsciiString> aNames;
+    if (!theName.IsEmpty())
+    aNames.Append (theName);
+    Init (aNames);
   }
-  else {
-    if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; }
-    ThereIsArgument = (argc == 2);
+
+  //! Create and initialize iterator object.
+  ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
+  : mySource (IterSource_All)
+  {
+    Init (theNames);
   }
 
-  if ( !a3DView().IsNull() ) {
-    TCollection_AsciiString name;
-    if (ThereIsArgument) {
-      name = argv[1];
-      IsBound= GetMapOfAIS().IsBound2(name);
+  //! Initialize the iterator.
+  void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
+  {
+    Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
+    mySeq = theNames;
+    mySelIter.Nullify();
+    myCurrent.Nullify();
+    myCurrentTrs.Nullify();
+    if (!mySeq.IsEmpty())
+    {
+      mySource = IterSource_List;
+      mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
     }
-    if (TheAISContext()->HasOpenedContext())
-      TheAISContext()->CloseLocalContext();
+    else if (aCtx->NbCurrents() > 0)
+    {
+      mySource  = IterSource_Selected;
+      mySelIter = aCtx;
+      mySelIter->InitCurrent();
+    }
+    else
+    {
+      mySource = IterSource_All;
+      myMapIter.Initialize (GetMapOfAIS());
+    }
+    initCurrent();
+  }
 
-    //  On set le Booleen There is current
-    if (TheAISContext() -> NbCurrents() > 0  ) {ThereIsCurrent =Standard_True; }
-    else ThereIsCurrent =Standard_False;
+  const TCollection_AsciiString& CurrentName() const
+  {
+    return myCurrentName;
+  }
 
-    //=======================================================================
-    // Il y a un  argument
-    //=======================================================================
-    if ( ThereIsArgument && IsBound ) {
-      const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
-      if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
-        Handle(AIS_InteractiveObject) ashape =
-          Handle(AIS_InteractiveObject)::DownCast (anObj);
-#ifdef DEB
-          if (HaveToSet)
-            di  << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
-          else
-            di  << "HaveToSet 0\n";
-#endif
+  const Handle(AIS_InteractiveObject)& Current() const
+  {
+    return myCurrent;
+  }
 
-        if(HaveToSet)
-          TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[2]) );
-        else
-          TheAISContext()->UnsetColor(ashape);
-      } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
-        Handle(NIS_Triangulated) ashape =
-          Handle(NIS_Triangulated)::DownCast (anObj);
-        if (!ashape.IsNull())
-          ashape->SetColor (ViewerTest::GetColorFromName(argv[2]));
-      }
-    }
+  const Handle(Standard_Transient)& CurrentTrs() const
+  {
+    return myCurrentTrs;
+  }
 
+  //! @return true if iterator points to valid object within collection
+  Standard_Boolean More() const
+  {
+    switch (mySource)
+    {
+      case IterSource_All:      return myMapIter.More();
+      case IterSource_List:     return mySeqIter.More();
+      case IterSource_Selected: return mySelIter->MoreCurrent();
+    }
+    return Standard_False;
+  }
 
-    //=======================================================================
-    // Il n'y a pas d'arguments
-    // Mais un ou plusieurs objets on des current representation
-    //=======================================================================
-    if (ThereIsCurrent && !ThereIsArgument) {
-      for (TheAISContext() -> InitCurrent() ;
-           TheAISContext() -> MoreCurrent() ;
-           TheAISContext() ->NextCurrent() )
+  //! Go to the next item.
+  void Next()
+  {
+    myCurrentName.Clear();
+    myCurrentTrs.Nullify();
+    myCurrent.Nullify();
+    switch (mySource)
+    {
+      case IterSource_All:
       {
-        const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current();
-        if (ashape.IsNull())
-          continue;
-#ifdef DEB
-        if (HaveToSet)
-          di  << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< ViewerTest::GetColorFromName(argv[2]) << "\n";
-        else
-          di  << "HaveToSet 0\n";
-#endif
-        if(HaveToSet)
-          TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
-        else
-          TheAISContext()->UnsetColor(ashape,Standard_False);
-      }
-
-      TheAISContext()->UpdateCurrentViewer();
-    }
-
-    //=======================================================================
-    // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant
-    // on impose a tous les objets du viewer la couleur passee
-    //=======================================================================
-    else if (!ThereIsCurrent && !ThereIsArgument){
-      ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
-      while ( it.More() ) {
-        const Handle(AIS_InteractiveObject) ashape =
-          Handle(AIS_InteractiveObject)::DownCast(it.Key1());
-        if (!ashape.IsNull()) {
-          if(HaveToSet)
-            TheAISContext()->SetColor(ashape,ViewerTest::GetColorFromName(argv[1]),Standard_False);
-          else
-            TheAISContext()->UnsetColor(ashape,Standard_False);
+        myMapIter.Next();
+        break;
+      }
+      case IterSource_List:
+      {
+        mySeqIter.Next();
+        break;
+      }
+      case IterSource_Selected:
+      {
+        mySelIter->NextCurrent();
+        break;
+      }
+    }
+    initCurrent();
+  }
+
+private:
+
+  void initCurrent()
+  {
+    switch (mySource)
+    {
+      case IterSource_All:
+      {
+        if (myMapIter.More())
+        {
+          myCurrentName = myMapIter.Key2();
+          myCurrentTrs  = myMapIter.Key1();
+          myCurrent     = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
+        }
+        break;
+      }
+      case IterSource_List:
+      {
+        if (mySeqIter.More())
+        {
+          if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
+          {
+            std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
+            return;
+          }
+          myCurrentName = mySeqIter.Value();
+          myCurrentTrs  = GetMapOfAIS().Find2 (mySeqIter.Value());
+          myCurrent     = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
         }
-        it.Next();
+        break;
+      }
+      case IterSource_Selected:
+      {
+        if (mySelIter->MoreCurrent())
+        {
+          myCurrentName = GetMapOfAIS().Find1 (mySelIter->Current());
+          myCurrent     = mySelIter->Current();
+        }
+        break;
       }
-      TheAISContext()->UpdateCurrentViewer();
     }
   }
-  return 0;
-}
+
+private:
+
+  enum IterSource
+  {
+    IterSource_All,
+    IterSource_List,
+    IterSource_Selected
+  };
+
+private:
+
+  Handle(AIS_InteractiveContext) mySelIter;    //!< iterator for current (selected) objects (IterSource_Selected)
+  ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
+  NCollection_Sequence<TCollection_AsciiString>           mySeq;
+  NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
+
+  TCollection_AsciiString        myCurrentName;//!< current item name
+  Handle(Standard_Transient)     myCurrentTrs; //!< current item (as transient object)
+  Handle(AIS_InteractiveObject)  myCurrent;    //!< current item
+
+  IterSource                     mySource;     //!< iterated collection
+
+};
 
 //==============================================================================
-//function : VTransparency
-//Author   : ege
-//purpose  : change the transparency of a selected or named or displayed shape
-//Draw arg : vtransparency [name] TransparencyCoeficient
+//function : VInteriorStyle
+//purpose  : sets interior style of the a selected or named or displayed shape
 //==============================================================================
-
-static int VTransparency  (Draw_Interpretor& di, Standard_Integer argc,
-                           const char** argv)
+static int VSetInteriorStyle (Draw_Interpretor& theDI,
+                              Standard_Integer  theArgNb,
+                              const char**      theArgVec)
 {
-  Standard_Boolean    ThereIsCurrent;
-  Standard_Boolean    ThereIsArgument;
-  Standard_Boolean    IsBound = Standard_False ;
-
-  const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0);
-  if (HaveToSet) {
-    if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
-    ThereIsArgument = (argc != 2);
-  }
-  else{
-    if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; }
-    ThereIsArgument = (argc == 2);
+  const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
+  ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
+  if (aCtx.IsNull())
+  {
+    std::cerr << "Error: no active view!\n";
+    return 1;
   }
 
-  if ( !a3DView().IsNull() ) {
-    TCollection_AsciiString name;
-    if (ThereIsArgument) {
-      name = argv[1];
-      IsBound= GetMapOfAIS().IsBound2(name);
+  Standard_Integer anArgIter = 1;
+  for (; anArgIter < theArgNb; ++anArgIter)
+  {
+    if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
+    {
+      break;
     }
-    if (TheAISContext()->HasOpenedContext())
-      TheAISContext()->CloseLocalContext();
+  }
+  TCollection_AsciiString aName;
+  if (theArgNb - anArgIter == 2)
+  {
+    aName = theArgVec[anArgIter++];
+  }
+  else if (theArgNb - anArgIter != 1)
+  {
+    std::cout << "Error: wrong number of arguments! See usage:\n";
+    theDI.PrintHelp (theArgVec[0]);
+    return 1;
+  }
+  Standard_Integer        anInterStyle = Aspect_IS_SOLID;
+  TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
+  aStyleArg.LowerCase();
+  if (aStyleArg == "empty")
+  {
+    anInterStyle = 0;
+  }
+  else if (aStyleArg == "hollow")
+  {
+    anInterStyle = 1;
+  }
+  else if (aStyleArg == "hatch")
+  {
+    anInterStyle = 2;
+  }
+  else if (aStyleArg == "solid")
+  {
+    anInterStyle = 3;
+  }
+  else if (aStyleArg == "hiddenline")
+  {
+    anInterStyle = 4;
+  }
+  else
+  {
+    anInterStyle = aStyleArg.IntegerValue();
+  }
+  if (anInterStyle < Aspect_IS_EMPTY
+   || anInterStyle > Aspect_IS_HIDDENLINE)
+  {
+    std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
+              << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
+    return 1;
+  }
 
-    if (TheAISContext() -> NbCurrents() > 0  ) {ThereIsCurrent =Standard_True; }
-    else ThereIsCurrent = Standard_False;
+  if (!aName.IsEmpty()
+   && !GetMapOfAIS().IsBound2 (aName))
+  {
+    std::cout << "Error: object " << aName << " is not displayed!\n";
+    return 1;
+  }
 
-    //=======================================================================
-    // Il y a des arguments: un nom et une couleur
-    //=======================================================================
-    if ( ThereIsArgument && IsBound ) {
-      const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
-      if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
-        const Handle(AIS_InteractiveObject) ashape =
-          Handle(AIS_InteractiveObject)::DownCast(anObj);
-        if(HaveToSet)
-          TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[2]) );
-        else
-          TheAISContext()->UnsetTransparency(ashape);
-      } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
-        const Handle(NIS_InteractiveObject) ashape =
-          Handle(NIS_InteractiveObject)::DownCast(anObj);
-        if(HaveToSet)
-          ashape->SetTransparency(Draw::Atof(argv[2]) );
-        else
-          ashape->UnsetTransparency();
-      }
-    }
-    //=======================================================================
-    // Il n'y a pas d'arguments
-    // Mais un ou plusieurs objets on des current representation
-    //=======================================================================
-    if (ThereIsCurrent && !ThereIsArgument) {
-      for (TheAISContext() -> InitCurrent() ;
-           TheAISContext() -> MoreCurrent() ;
-           TheAISContext() ->NextCurrent() )
-      {
-        Handle(AIS_InteractiveObject) ashape =  TheAISContext() -> Current();
-        if(HaveToSet)
-          TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
-        else
-          TheAISContext()->UnsetTransparency(ashape,Standard_False);
-      }
-
-      TheAISContext()->UpdateCurrentViewer();
-    }
-    //=======================================================================
-    // Il n'y a pas d'arguments ET aucun objet courrant
-    //=======================================================================
-    else if ( !ThereIsCurrent && !ThereIsArgument ) {
-      ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
-        it(GetMapOfAIS());
-      while ( it.More() ) {
-        Handle(AIS_InteractiveObject) ashape =
-          Handle(AIS_InteractiveObject)::DownCast(it.Key1());
-        if (!ashape.IsNull()) {
-          if(HaveToSet)
-            TheAISContext()->SetTransparency(ashape,Draw::Atof(argv[1]),Standard_False);
-          else
-            TheAISContext()->UnsetTransparency(ashape,Standard_False);
-        }
-        it.Next();
-      }
-      TheAISContext()->UpdateCurrentViewer();
+  if (aCtx->HasOpenedContext())
+  {
+    aCtx->CloseLocalContext();
+  }
+  for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
+  {
+    const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
+    if (!anIO.IsNull())
+    {
+      const Handle(Prs3d_Drawer)& aDrawer        = anIO->Attributes();
+      Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
+      Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
+      aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
+      aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
     }
   }
   return 0;
 }
 
+//! Auxiliary structure for VAspects
+struct ViewerTest_AspectsChangeSet
+{
+  Standard_Integer         ToSetVisibility;
+  Standard_Integer         Visibility;
+
+  Standard_Integer         ToSetColor;
+  Quantity_Color           Color;
+
+  Standard_Integer         ToSetLineWidth;
+  Standard_Real            LineWidth;
+
+  Standard_Integer         ToSetTypeOfLine;
+  Aspect_TypeOfLine        TypeOfLine;
+
+  Standard_Integer         ToSetTransparency;
+  Standard_Real            Transparency;
+
+  Standard_Integer         ToSetMaterial;
+  Graphic3d_NameOfMaterial Material;
+  TCollection_AsciiString  MatName;
+
+  NCollection_Sequence<TopoDS_Shape> SubShapes;
+
+  Standard_Integer         ToSetShowFreeBoundary;
+  Standard_Integer         ToSetFreeBoundaryWidth;
+  Standard_Real            FreeBoundaryWidth;
+  Standard_Integer         ToSetFreeBoundaryColor;
+  Quantity_Color           FreeBoundaryColor;
+
+  //! Empty constructor
+  ViewerTest_AspectsChangeSet()
+  : ToSetVisibility   (0),
+    Visibility        (1),
+    ToSetColor        (0),
+    Color             (DEFAULT_COLOR),
+    ToSetLineWidth    (0),
+    LineWidth         (1.0),
+    ToSetTypeOfLine   (0),
+    TypeOfLine        (Aspect_TOL_SOLID),
+    ToSetTransparency (0),
+    Transparency      (0.0),
+    ToSetMaterial     (0),
+    Material          (Graphic3d_NOM_DEFAULT),
+    ToSetShowFreeBoundary  (0),
+    ToSetFreeBoundaryWidth (0),
+    FreeBoundaryWidth      (1.0),
+    ToSetFreeBoundaryColor (0),
+    FreeBoundaryColor      (DEFAULT_FREEBOUNDARY_COLOR) {}
+
+  //! @return true if no changes have been requested
+  Standard_Boolean IsEmpty() const
+  {
+    return ToSetVisibility        == 0
+        && ToSetLineWidth         == 0
+        && ToSetTransparency      == 0
+        && ToSetColor             == 0
+        && ToSetMaterial          == 0
+        && ToSetShowFreeBoundary  == 0
+        && ToSetFreeBoundaryColor == 0
+        && ToSetFreeBoundaryWidth == 0;
+  }
+
+  //! @return true if properties are valid
+  Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
+  {
+    Standard_Boolean isOk = Standard_True;
+    if (Visibility != 0 && Visibility != 1)
+    {
+      std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
+      isOk = Standard_False;
+    }
+    if (LineWidth <= 0.0
+     || LineWidth >  10.0)
+    {
+      std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
+      isOk = Standard_False;
+    }
+    if (Transparency < 0.0
+     || Transparency > 1.0)
+    {
+      std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
+      isOk = Standard_False;
+    }
+    if (theIsSubPart
+     && ToSetTransparency)
+    {
+      std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
+      isOk = Standard_False;
+    }
+    if (ToSetMaterial == 1
+     && Material == Graphic3d_NOM_DEFAULT)
+    {
+      std::cout << "Error: unknown material " << MatName << ".\n";
+      isOk = Standard_False;
+    }
+    if (FreeBoundaryWidth <= 0.0
+     || FreeBoundaryWidth >  10.0)
+    {
+      std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
+      isOk = Standard_False;
+    }
+    return isOk;
+  }
+
+};
 
 //==============================================================================
-//function : VMaterial
-//Author   : ege
-//purpose  : change the Material of a selected or named or displayed shape
-//Draw arg : vmaterial  [Name] Material
+//function : VAspects
+//purpose  :
 //==============================================================================
-static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
+                                  Standard_Integer  theArgNb,
+                                  const char**      theArgVec)
 {
-
-  Standard_Boolean    ThereIsCurrent;
-  Standard_Boolean    ThereIsName;
-  Standard_Boolean    IsBound = Standard_False ;
-
-  const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetmaterial") == 0);
-  if (HaveToSet) {
-    if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
-    ThereIsName = (argc != 2);
-  }
-  else {
-    if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; }
-    ThereIsName = (argc == 2);
+  TCollection_AsciiString aCmdName (theArgVec[0]);
+  const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
+  ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
+  if (aCtx.IsNull())
+  {
+    std::cerr << "Error: no active view!\n";
+    return 1;
   }
 
-  if ( !a3DView().IsNull() ) {
-    TCollection_AsciiString name;
-    if (ThereIsName) {
-      name = argv[1];
-      IsBound= GetMapOfAIS().IsBound2(name);
+  Standard_Integer anArgIter = 1;
+  Standard_Boolean isDefaults = Standard_False;
+  NCollection_Sequence<TCollection_AsciiString> aNames;
+  for (; anArgIter < theArgNb; ++anArgIter)
+  {
+    TCollection_AsciiString anArg = theArgVec[anArgIter];
+    if (anUpdateTool.parseRedrawMode (anArg))
+    {
+      continue;
+    }
+    else if (!anArg.IsEmpty()
+           && anArg.Value (1) != '-')
+    {
+      aNames.Append (anArg);
     }
-    if (TheAISContext()->HasOpenedContext())
-      TheAISContext()->CloseLocalContext();
-    if (TheAISContext() -> NbCurrents() > 0  )
-      ThereIsCurrent =Standard_True;
     else
-      ThereIsCurrent =Standard_False;
-
-    //=======================================================================
-    // Ther is a name of shape and a material name
-    //=======================================================================
-    if ( ThereIsName && IsBound ) {
-      Handle(AIS_InteractiveObject) ashape =
-        Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name));
-      if (!ashape.IsNull()) {
-        if (HaveToSet)
-          TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2]));
-        else
-          TheAISContext()->UnsetMaterial(ashape);
+    {
+      if (anArg == "-defaults")
+      {
+        isDefaults = Standard_True;
+        ++anArgIter;
       }
+      break;
     }
-    //=======================================================================
-    // Il n'y a pas de nom de shape
-    // Mais un ou plusieurs objets on des current representation
-    //=======================================================================
-    if (ThereIsCurrent && !ThereIsName) {
-      for (TheAISContext() -> InitCurrent() ;
-           TheAISContext() -> MoreCurrent() ;
-           TheAISContext() ->NextCurrent() )
+  }
+
+  if (!aNames.IsEmpty() && isDefaults)
+  {
+    std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
+    return 1;
+  }
+
+  NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
+  aChanges.Append (ViewerTest_AspectsChangeSet());
+  ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
+
+  // parse syntax of legacy commands
+  if (aCmdName == "vsetwidth")
+  {
+    if (aNames.IsEmpty()
+    || !aNames.Last().IsRealValue())
+    {
+      std::cout << "Error: not enough arguments!\n";
+      return 1;
+    }
+    aChangeSet->ToSetLineWidth = 1;
+    aChangeSet->LineWidth = aNames.Last().RealValue();
+    aNames.Remove (aNames.Length());
+  }
+  else if (aCmdName == "vunsetwidth")
+  {
+    aChangeSet->ToSetLineWidth = -1;
+  }
+  else if (aCmdName == "vsetcolor")
+  {
+    if (aNames.IsEmpty())
+    {
+      std::cout << "Error: not enough arguments!\n";
+      return 1;
+    }
+    aChangeSet->ToSetColor = 1;
+
+    Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
+    Standard_Boolean     isOk   = Standard_False;
+    if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
+    {
+      aChangeSet->Color = aColor;
+      aNames.Remove (aNames.Length());
+      isOk = Standard_True;
+    }
+    else if (aNames.Length() >= 3)
+    {
+      const TCollection_AsciiString anRgbStr[3] =
       {
-        Handle(AIS_InteractiveObject) ashape = TheAISContext()->Current();
-        if (HaveToSet)
-          TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
-        else
-          TheAISContext()->UnsetMaterial(ashape,Standard_False);
-      }
-      TheAISContext()->UpdateCurrentViewer();
-    }
-
-    //=======================================================================
-    // Il n'y a pas de noms de shape ET aucun objet courrant
-    // On impose a tous les objets du viewer le material passe en argument
-    //=======================================================================
-    else if (!ThereIsCurrent && !ThereIsName){
-      ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
-        it(GetMapOfAIS());
-      while ( it.More() ) {
-        Handle(AIS_InteractiveObject) ashape =
-          Handle(AIS_InteractiveObject)::DownCast (it.Key1());
-        if (!ashape.IsNull()) {
-          if (HaveToSet)
-            TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False);
-          else
-            TheAISContext()->UnsetMaterial(ashape,Standard_False);
+        aNames.Value (aNames.Upper() - 2),
+        aNames.Value (aNames.Upper() - 1),
+        aNames.Value (aNames.Upper() - 0)
+      };
+      isOk = anRgbStr[0].IsRealValue()
+          && anRgbStr[1].IsRealValue()
+          && anRgbStr[2].IsRealValue();
+      if (isOk)
+      {
+        Graphic3d_Vec4d anRgb;
+        anRgb.x() = anRgbStr[0].RealValue();
+        anRgb.y() = anRgbStr[1].RealValue();
+        anRgb.z() = anRgbStr[2].RealValue();
+        if (anRgb.x() < 0.0 || anRgb.x() > 1.0
+         || anRgb.y() < 0.0 || anRgb.y() > 1.0
+         || anRgb.z() < 0.0 || anRgb.z() > 1.0)
+        {
+          std::cout << "Error: RGB color values should be within range 0..1!\n";
+          return 1;
         }
-        it.Next();
+        aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
+        aNames.Remove (aNames.Length());
+        aNames.Remove (aNames.Length());
+        aNames.Remove (aNames.Length());
       }
-      TheAISContext()->UpdateCurrentViewer();
+    }
+    if (!isOk)
+    {
+      std::cout << "Error: not enough arguments!\n";
+      return 1;
     }
   }
-  return 0;
-}
+  else if (aCmdName == "vunsetcolor")
+  {
+    aChangeSet->ToSetColor = -1;
+  }
+  else if (aCmdName == "vsettransparency")
+  {
+    if (aNames.IsEmpty()
+    || !aNames.Last().IsRealValue())
+    {
+      std::cout << "Error: not enough arguments!\n";
+      return 1;
+    }
+    aChangeSet->ToSetTransparency = 1;
+    aChangeSet->Transparency  = aNames.Last().RealValue();
+    aNames.Remove (aNames.Length());
+  }
+  else if (aCmdName == "vunsettransparency")
+  {
+    aChangeSet->ToSetTransparency = -1;
+  }
+  else if (aCmdName == "vsetmaterial")
+  {
+    if (aNames.IsEmpty())
+    {
+      std::cout << "Error: not enough arguments!\n";
+      return 1;
+    }
+    aChangeSet->ToSetMaterial = 1;
+    aChangeSet->MatName  = aNames.Last();
+    aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
+    aNames.Remove (aNames.Length());
+  }
+  else if (aCmdName == "vunsetmaterial")
+  {
+    aChangeSet->ToSetMaterial = -1;
+  }
+  else if (anArgIter >= theArgNb)
+  {
+    std::cout << "Error: not enough arguments!\n";
+    return 1;
+  }
 
+  if (!aChangeSet->IsEmpty())
+  {
+    anArgIter = theArgNb;
+  }
+  for (; anArgIter < theArgNb; ++anArgIter)
+  {
+    TCollection_AsciiString anArg = theArgVec[anArgIter];
+    anArg.LowerCase();
+    if (anArg == "-setwidth"
+     || anArg == "-setlinewidth")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+      aChangeSet->ToSetLineWidth = 1;
+      aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
+    }
+    else if (anArg == "-unsetwidth"
+          || anArg == "-unsetlinewidth")
+    {
+      aChangeSet->ToSetLineWidth = -1;
+      aChangeSet->LineWidth = 1.0;
+    }
+    else if (anArg == "-settransp"
+          || anArg == "-settransparency")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+      aChangeSet->ToSetTransparency = 1;
+      aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
+      if (aChangeSet->Transparency >= 0.0
+       && aChangeSet->Transparency <= Precision::Confusion())
+      {
+        aChangeSet->ToSetTransparency = -1;
+        aChangeSet->Transparency = 0.0;
+      }
+    }
+    else if (anArg == "-setvis"
+          || anArg == "-setvisibility")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
 
+      aChangeSet->ToSetVisibility = 1;
+      aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
+    }
+    else if (anArg == "-setalpha")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+      aChangeSet->ToSetTransparency = 1;
+      aChangeSet->Transparency  = Draw::Atof (theArgVec[anArgIter]);
+      if (aChangeSet->Transparency < 0.0
+       || aChangeSet->Transparency > 1.0)
+      {
+        std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
+        return 1;
+      }
+      aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
+      if (aChangeSet->Transparency >= 0.0
+       && aChangeSet->Transparency <= Precision::Confusion())
+      {
+        aChangeSet->ToSetTransparency = -1;
+        aChangeSet->Transparency = 0.0;
+      }
+    }
+    else if (anArg == "-unsettransp"
+          || anArg == "-unsettransparency"
+          || anArg == "-unsetalpha"
+          || anArg == "-opaque")
+    {
+      aChangeSet->ToSetTransparency = -1;
+      aChangeSet->Transparency = 0.0;
+    }
+    else if (anArg == "-setcolor")
+    {
+      Standard_Integer aNbComps  = 0;
+      Standard_Integer aCompIter = anArgIter + 1;
+      for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
+      {
+        if (theArgVec[aCompIter][0] == '-')
+        {
+          break;
+        }
+      }
+      switch (aNbComps)
+      {
+        case 1:
+        {
+          Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
+          Standard_CString     aName  = theArgVec[anArgIter + 1];
+          if (!Quantity_Color::ColorFromName (aName, aColor))
+          {
+            std::cout << "Error: unknown color name '" << aName << "'\n";
+            return 1;
+          }
+          aChangeSet->Color = aColor;
+          break;
+        }
+        case 3:
+        {
+          Graphic3d_Vec3d anRgb;
+          anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
+          anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
+          anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
+          if (anRgb.x() < 0.0 || anRgb.x() > 1.0
+           || anRgb.y() < 0.0 || anRgb.y() > 1.0
+           || anRgb.z() < 0.0 || anRgb.z() > 1.0)
+          {
+            std::cout << "Error: RGB color values should be within range 0..1!\n";
+            return 1;
+          }
+          aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
+          break;
+        }
+        default:
+        {
+          std::cout << "Error: wrong syntax at " << anArg << "\n";
+          return 1;
+        }
+      }
+      aChangeSet->ToSetColor = 1;
+      anArgIter += aNbComps;
+    }
+    else if (anArg == "-setlinetype")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
 
-//==============================================================================
-//function : VWidth
-//Author   : ege
-//purpose  : change the width of the edges of a selected or named or displayed shape
-//Draw arg : vwidth  [Name] WidthValue(1->10)
-//==============================================================================
-static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
-{
+      TCollection_AsciiString aValue (theArgVec[anArgIter]);
+      aValue.LowerCase();
 
-  Standard_Boolean    ThereIsCurrent;
-  Standard_Boolean    ThereIsArgument;
-  Standard_Boolean    IsBound = Standard_False ;
+      if (aValue.IsEqual ("solid"))
+      {
+        aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
+      }
+      else if (aValue.IsEqual ("dot"))
+      {
+        aChangeSet->TypeOfLine = Aspect_TOL_DOT;
+      }
+      else if (aValue.IsEqual ("dash"))
+      {
+        aChangeSet->TypeOfLine = Aspect_TOL_DASH;
+      }
+      else if (aValue.IsEqual ("dotdash"))
+      {
+        aChangeSet->TypeOfLine = Aspect_TOL_DOTDASH;
+      }
+      else
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
 
-  const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0);
-  if (HaveToSet) {
-    if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; }
-    ThereIsArgument = (argc != 2);
-  }
-  else {
-    if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1  argument" << "\n"; return 1; }
-    ThereIsArgument = (argc == 2);
-  }
-  if ( !a3DView().IsNull() ) {
-    TCollection_AsciiString name;
-    if (ThereIsArgument) {
-      name = argv[1];
-      IsBound= GetMapOfAIS().IsBound2(name);
+      aChangeSet->ToSetTypeOfLine = 1;
     }
-    if (TheAISContext()->HasOpenedContext())
-      TheAISContext()->CloseLocalContext();
+    else if (anArg == "-unsetlinetype")
+    {
+      aChangeSet->ToSetTypeOfLine = -1;
+    }
+    else if (anArg == "-unsetcolor")
+    {
+      aChangeSet->ToSetColor = -1;
+      aChangeSet->Color = DEFAULT_COLOR;
+    }
+    else if (anArg == "-setmat"
+          || anArg == "-setmaterial")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+      aChangeSet->ToSetMaterial = 1;
+      aChangeSet->MatName  = theArgVec[anArgIter];
+      aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
+    }
+    else if (anArg == "-unsetmat"
+          || anArg == "-unsetmaterial")
+    {
+      aChangeSet->ToSetMaterial = -1;
+      aChangeSet->Material = Graphic3d_NOM_DEFAULT;
+    }
+    else if (anArg == "-subshape"
+          || anArg == "-subshapes")
+    {
+      if (isDefaults)
+      {
+        std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
+        return 1;
+      }
 
-    if (TheAISContext() -> NbCurrents() > 0  )
-      ThereIsCurrent =Standard_True;
-    else
-      ThereIsCurrent =Standard_False;
+      if (aNames.IsEmpty())
+      {
+        std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
+        return 1;
+      }
 
-    if ( ThereIsArgument && IsBound ) {
-      const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
-      if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
-        const Handle(AIS_InteractiveObject) ashape =
-          Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
-        if (HaveToSet)
-          TheAISContext()->SetWidth ( ashape,Draw::Atof (argv[2]) );
-        else
-          TheAISContext()->UnsetWidth (ashape);
-      } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
-        const Handle(NIS_Triangulated) ashape =
-          Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name));
-        if (HaveToSet && !ashape.IsNull())
-          ashape->SetLineWidth ( Draw::Atof (argv[2]) );
-      }
-    }
-
-    //=======================================================================
-    // Il n'y a pas d'arguments
-    // Mais un ou plusieurs objets on des current representation
-    //=======================================================================
-    if (ThereIsCurrent && !ThereIsArgument) {
-      for (TheAISContext() -> InitCurrent() ;
-           TheAISContext() -> MoreCurrent() ;
-           TheAISContext() ->NextCurrent() )
+      aChanges.Append (ViewerTest_AspectsChangeSet());
+      aChangeSet = &aChanges.ChangeLast();
+
+      for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
       {
-        Handle(AIS_InteractiveObject) ashape =  TheAISContext() -> Current();
-        if (HaveToSet)
-          TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
-        else
-          TheAISContext()->UnsetWidth(ashape,Standard_False);
-      }
-      TheAISContext()->UpdateCurrentViewer();
-    }
-    //=======================================================================
-    // Il n'y a pas d'arguments ET aucun objet courrant
-    //=======================================================================
-    else if (!ThereIsCurrent && !ThereIsArgument){
-     ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
-       it(GetMapOfAIS());
-      while ( it.More() ) {
-        Handle(AIS_InteractiveObject) ashape =
-          Handle(AIS_InteractiveObject)::DownCast (it.Key1());
-        if (!ashape.IsNull()) {
-          if (HaveToSet)
-            TheAISContext()->SetWidth(ashape,Draw::Atof(argv[1]),Standard_False);
-          else
-            TheAISContext()->UnsetWidth(ashape,Standard_False);
+        Standard_CString aSubShapeName = theArgVec[anArgIter];
+        if (*aSubShapeName == '-')
+        {
+          --anArgIter;
+          break;
+        }
+
+        TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
+        if (aSubShape.IsNull())
+        {
+          std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
+          return 1;
         }
-        it.Next();
-     }
-     TheAISContext()->UpdateCurrentViewer();
-   }
+        aChangeSet->SubShapes.Append (aSubShape);
+      }
+
+      if (aChangeSet->SubShapes.IsEmpty())
+      {
+        std::cerr << "Error: empty list is specified after -subshapes!\n";
+        return 1;
+      }
+    }
+    else if (anArg == "-freeboundary"
+          || anArg == "-fb")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+      TCollection_AsciiString aValue (theArgVec[anArgIter]);
+      aValue.LowerCase();
+      if (aValue == "on"
+       || aValue == "1")
+      {
+        aChangeSet->ToSetShowFreeBoundary = 1;
+      }
+      else if (aValue == "off"
+            || aValue == "0")
+      {
+        aChangeSet->ToSetShowFreeBoundary = -1;
+      }
+      else
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+    }
+    else if (anArg == "-setfreeboundarywidth"
+          || anArg == "-setfbwidth")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+      aChangeSet->ToSetFreeBoundaryWidth = 1;
+      aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
+    }
+    else if (anArg == "-unsetfreeboundarywidth"
+          || anArg == "-unsetfbwidth")
+    {
+      aChangeSet->ToSetFreeBoundaryWidth = -1;
+      aChangeSet->FreeBoundaryWidth = 1.0;
+    }
+    else if (anArg == "-setfreeboundarycolor"
+          || anArg == "-setfbcolor")
+    {
+      Standard_Integer aNbComps  = 0;
+      Standard_Integer aCompIter = anArgIter + 1;
+      for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
+      {
+        if (theArgVec[aCompIter][0] == '-')
+        {
+          break;
+        }
+      }
+      switch (aNbComps)
+      {
+        case 1:
+        {
+          Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
+          Standard_CString     aName  = theArgVec[anArgIter + 1];
+          if (!Quantity_Color::ColorFromName (aName, aColor))
+          {
+            std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
+            return 1;
+          }
+          aChangeSet->FreeBoundaryColor = aColor;
+          break;
+        }
+        case 3:
+        {
+          Graphic3d_Vec3d anRgb;
+          anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
+          anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
+          anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
+          if (anRgb.x() < 0.0 || anRgb.x() > 1.0
+           || anRgb.y() < 0.0 || anRgb.y() > 1.0
+           || anRgb.z() < 0.0 || anRgb.z() > 1.0)
+          {
+            std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
+            return 1;
+          }
+          aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
+          break;
+        }
+        default:
+        {
+          std::cout << "Error: wrong syntax at " << anArg << "\n";
+          return 1;
+        }
+      }
+      aChangeSet->ToSetFreeBoundaryColor = 1;
+      anArgIter += aNbComps;
+    }
+    else if (anArg == "-unsetfreeboundarycolor"
+          || anArg == "-unsetfbcolor")
+    {
+      aChangeSet->ToSetFreeBoundaryColor = -1;
+      aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
+    }
+    else if (anArg == "-unset")
+    {
+      aChangeSet->ToSetVisibility = 1;
+      aChangeSet->Visibility = 1;
+      aChangeSet->ToSetLineWidth = -1;
+      aChangeSet->LineWidth = 1.0;
+      aChangeSet->ToSetTypeOfLine = -1;
+      aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
+      aChangeSet->ToSetTransparency = -1;
+      aChangeSet->Transparency = 0.0;
+      aChangeSet->ToSetColor = -1;
+      aChangeSet->Color = DEFAULT_COLOR;
+      aChangeSet->ToSetMaterial = -1;
+      aChangeSet->Material = Graphic3d_NOM_DEFAULT;
+      aChangeSet->ToSetShowFreeBoundary = -1;
+      aChangeSet->ToSetFreeBoundaryColor = -1;
+      aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
+      aChangeSet->ToSetFreeBoundaryWidth = -1;
+      aChangeSet->FreeBoundaryWidth = 1.0;
+    }
+    else
+    {
+      std::cout << "Error: wrong syntax at " << anArg << "\n";
+      return 1;
+    }
   }
-  return 0;
-}
 
-//==============================================================================
-//function : VInteriorStyle
-//purpose  : sets interior style of the a selected or named or displayed shape
-//Draw arg : vsetinteriorstyle [shape] style
-//==============================================================================
-static void SetInteriorStyle (const Handle(AIS_InteractiveObject)& theIAO,
-                              const Standard_Integer theStyle,
-                              Draw_Interpretor& di)
-{
-  if (theStyle < Aspect_IS_EMPTY || theStyle > Aspect_IS_HIDDENLINE) {
-    di << "Style must be within a range [0 (Aspect_IS_EMPTY), " << Aspect_IS_HIDDENLINE <<
-      " (Aspect_IS_HIDDENLINE)]\n";
-    return;
+  Standard_Boolean isFirst = Standard_True;
+  for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
+       aChangesIter.More(); aChangesIter.Next())
+  {
+    if (!aChangesIter.Value().Validate (!isFirst))
+    {
+      return 1;
+    }
+    isFirst = Standard_False;
   }
-  const Handle(Prs3d_Drawer)& aDrawer = theIAO->Attributes();
-  Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
-  Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
-  Aspect_InteriorStyle aStyle = (Aspect_InteriorStyle) (theStyle);
-  aFillAspect->SetInteriorStyle (aStyle);
-  TheAISContext()->RecomputePrsOnly (theIAO, Standard_False /*update*/, Standard_True /*all modes*/);
-}
 
-static int VInteriorStyle (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
-{
-  if (argc < 2 || argc > 3) {
-    di << argv[0] << " requires 2 or 3 arguments\n";
-    di << "Usage : " << argv[0] << " [shape] Style : Set interior style" << "\n";
-    di << "Style must match Aspect_InteriorStyle and be one of:\n";
-    di << "         0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE\n";
-    return 1;
+  if (aCtx->HasOpenedContext())
+  {
+    aCtx->CloseLocalContext();
+  }
+
+  // special case for -defaults parameter.
+  // all changed values will be set to DefaultDrawer.
+  if (isDefaults)
+  {
+    const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
+
+    if (aChangeSet->ToSetLineWidth != 0)
+    {
+      aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
+      aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
+      aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
+      aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
+    }
+    if (aChangeSet->ToSetColor != 0)
+    {
+      aDrawer->ShadingAspect()->SetColor        (aChangeSet->Color);
+      aDrawer->LineAspect()->SetColor           (aChangeSet->Color);
+      aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
+      aDrawer->SeenLineAspect()->SetColor       (aChangeSet->Color);
+      aDrawer->WireAspect()->SetColor           (aChangeSet->Color);
+      aDrawer->PointAspect()->SetColor          (aChangeSet->Color);
+    }
+    if (aChangeSet->ToSetTypeOfLine != 0)
+    {
+      aDrawer->LineAspect()->SetTypeOfLine           (aChangeSet->TypeOfLine);
+      aDrawer->WireAspect()->SetTypeOfLine           (aChangeSet->TypeOfLine);
+      aDrawer->FreeBoundaryAspect()->SetTypeOfLine   (aChangeSet->TypeOfLine);
+      aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
+      aDrawer->SeenLineAspect()->SetTypeOfLine       (aChangeSet->TypeOfLine);
+    }
+    if (aChangeSet->ToSetTransparency != 0)
+    {
+      aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
+    }
+    if (aChangeSet->ToSetMaterial != 0)
+    {
+      aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
+    }
+    if (aChangeSet->ToSetShowFreeBoundary == 1)
+    {
+      aDrawer->SetFreeBoundaryDraw (Standard_True);
+    }
+    else if (aChangeSet->ToSetShowFreeBoundary == -1)
+    {
+      aDrawer->SetFreeBoundaryDraw (Standard_False);
+    }
+    if (aChangeSet->ToSetFreeBoundaryWidth != 0)
+    {
+      aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
+    }
+    if (aChangeSet->ToSetFreeBoundaryColor != 0)
+    {
+      aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
+    }
+
+    // redisplay all objects in context
+    for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
+    {
+      Handle(AIS_InteractiveObject)  aPrs = aPrsIter.Current();
+      if (!aPrs.IsNull())
+      {
+        aCtx->Redisplay (aPrs, Standard_False);
+      }
+    }
+    return 0;
   }
 
-  Standard_Boolean    ThereIsCurrent;
-  Standard_Boolean    ThereIsArgument;
-  Standard_Boolean    IsBound = Standard_False ;
-
-  ThereIsArgument = (argc > 2);
-  if ( !a3DView().IsNull() ) {
-    TCollection_AsciiString name;
-    if (ThereIsArgument) {
-      name = argv[1];
-      IsBound= GetMapOfAIS().IsBound2(name);
+  for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
+  {
+    const TCollection_AsciiString& aName   = aPrsIter.CurrentName();
+    Handle(AIS_InteractiveObject)  aPrs    = aPrsIter.Current();
+    Handle(Prs3d_Drawer)           aDrawer = aPrs->Attributes();
+    Handle(AIS_ColoredShape) aColoredPrs;
+    Standard_Boolean toDisplay = Standard_False;
+    Standard_Boolean toRedisplay = Standard_False;
+    if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
+    {
+      Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
+      if (aShapePrs.IsNull())
+      {
+        std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
+        return 1;
+      }
+      aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
+      if (aColoredPrs.IsNull())
+      {
+        aColoredPrs = new AIS_ColoredShape (aShapePrs);
+        aCtx->Remove (aShapePrs, Standard_False);
+        GetMapOfAIS().UnBind2 (aName);
+        GetMapOfAIS().Bind (aColoredPrs, aName);
+        toDisplay = Standard_True;
+        aShapePrs = aColoredPrs;
+        aPrs      = aColoredPrs;
+      }
     }
-    if (TheAISContext()->HasOpenedContext())
-      TheAISContext()->CloseLocalContext();
 
-    if (TheAISContext() -> NbCurrents() > 0  )
-      ThereIsCurrent =Standard_True;
-    else
-      ThereIsCurrent =Standard_False;
+    if (!aPrs.IsNull())
+    {
+      NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
+      aChangeSet = &aChangesIter.ChangeValue();
+      if (aChangeSet->ToSetVisibility == 1)
+      {
+        Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
+        aColDrawer->SetHidden (aChangeSet->Visibility == 0);
+      }
+      else if (aChangeSet->ToSetMaterial == 1)
+      {
+        aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
+      }
+      else if (aChangeSet->ToSetMaterial == -1)
+      {
+        aCtx->UnsetMaterial (aPrs, Standard_False);
+      }
+      if (aChangeSet->ToSetColor == 1)
+      {
+        aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
+      }
+      else if (aChangeSet->ToSetColor == -1)
+      {
+        aCtx->UnsetColor (aPrs, Standard_False);
+      }
+      if (aChangeSet->ToSetTransparency == 1)
+      {
+        aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
+      }
+      else if (aChangeSet->ToSetTransparency == -1)
+      {
+        aCtx->UnsetTransparency (aPrs, Standard_False);
+      }
+      if (aChangeSet->ToSetLineWidth == 1)
+      {
+        aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
+      }
+      else if (aChangeSet->ToSetLineWidth == -1)
+      {
+        aCtx->UnsetWidth (aPrs, Standard_False);
+      }
+      if (!aDrawer.IsNull())
+      {
+        if (aChangeSet->ToSetShowFreeBoundary == 1)
+        {
+          aDrawer->SetFreeBoundaryDraw (Standard_True);
+          toRedisplay = Standard_True;
+        }
+        else if (aChangeSet->ToSetShowFreeBoundary == -1)
+        {
+          aDrawer->SetFreeBoundaryDraw (Standard_False);
+          toRedisplay = Standard_True;
+        }
+        if (aChangeSet->ToSetFreeBoundaryWidth != 0)
+        {
+          Handle(Prs3d_LineAspect) aBoundaryAspect =
+              new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
+          *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
+          aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
+          aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
+          toRedisplay = Standard_True;
+        }
+        if (aChangeSet->ToSetFreeBoundaryColor != 0)
+        {
+          Handle(Prs3d_LineAspect) aBoundaryAspect =
+              new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
+          *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
+          aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
+          aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
+          toRedisplay = Standard_True;
+        }
+        if (aChangeSet->ToSetTypeOfLine != 0)
+        {
+          aDrawer->LineAspect()->SetTypeOfLine           (aChangeSet->TypeOfLine);
+          aDrawer->WireAspect()->SetTypeOfLine           (aChangeSet->TypeOfLine);
+          aDrawer->FreeBoundaryAspect()->SetTypeOfLine   (aChangeSet->TypeOfLine);
+          aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
+          aDrawer->SeenLineAspect()->SetTypeOfLine       (aChangeSet->TypeOfLine);
+          toRedisplay = Standard_True;
+        }
+      }
 
-    if ( ThereIsArgument && IsBound ) {
-      const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
-      if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
-        const Handle(AIS_InteractiveObject) ashape =
-          Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
-        SetInteriorStyle (ashape, Draw::Atoi (argv[2]), di);
-      }
-    }
-    //=======================================================================
-    // No arguments specified
-    // But there are one or more selected objects
-    //=======================================================================
-    if (ThereIsCurrent && !ThereIsArgument) {
-      for (TheAISContext() -> InitCurrent() ;
-           TheAISContext() -> MoreCurrent() ;
-           TheAISContext() ->NextCurrent() )
+      for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
+      {
+        aChangeSet = &aChangesIter.ChangeValue();
+        for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
+             aSubShapeIter.More(); aSubShapeIter.Next())
+        {
+          const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
+          if (aChangeSet->ToSetVisibility == 1)
+          {
+            Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
+            aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
+          }
+          if (aChangeSet->ToSetColor == 1)
+          {
+            aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
+          }
+          if (aChangeSet->ToSetLineWidth == 1)
+          {
+            aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
+          }
+          if (aChangeSet->ToSetColor     == -1
+           || aChangeSet->ToSetLineWidth == -1)
+          {
+            aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
+          }
+        }
+      }
+      if (toDisplay)
       {
-        Handle(AIS_InteractiveObject) ashape =  TheAISContext() -> Current();
-        SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
+        aCtx->Display (aPrs, Standard_False);
       }
-    }
-    //=======================================================================
-    // No arguments specified and there are no selected objects
-    //=======================================================================
-    else if (!ThereIsCurrent && !ThereIsArgument){
-      ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
-       it(GetMapOfAIS());
-      while ( it.More() ) {
-        Handle(AIS_InteractiveObject) ashape =
-          Handle(AIS_InteractiveObject)::DownCast (it.Key1());
-        if (!ashape.IsNull())
-          SetInteriorStyle (ashape, Draw::Atoi (argv[1]), di);
-        it.Next();
+      if (toRedisplay)
+      {
+        aCtx->Redisplay (aPrs, Standard_False);
+      }
+      else if (!aColoredPrs.IsNull())
+      {
+        aCtx->Redisplay (aColoredPrs, Standard_False);
       }
     }
-    TheAISContext()->UpdateCurrentViewer();
   }
   return 0;
 }
@@ -1672,6 +2338,7 @@ static int VDonly2 (Draw_Interpretor& ,
                     const char**      theArgVec)
 {
   const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
+  ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
   if (aCtx.IsNull())
   {
     std::cerr << "Error: no active view!\n";
@@ -1682,12 +2349,11 @@ static int VDonly2 (Draw_Interpretor& ,
   {
     aCtx->CloseLocalContext();
   }
-  ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
 
   Standard_Integer anArgIter = 1;
   for (; anArgIter < theArgNb; ++anArgIter)
   {
-    if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate))
+    if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
     {
       break;
     }
@@ -1715,18 +2381,12 @@ static int VDonly2 (Draw_Interpretor& ,
       TCollection_AsciiString aName = theArgVec[anArgIter];
       if (GetMapOfAIS().IsBound2 (aName))
       {
-        const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
-        if (anObj->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
+        const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
+        if (!aShape.IsNull())
         {
-          const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
           aCtx->Display (aShape, Standard_False);
+          aDispSet.Add (aShape);
         }
-        else if (anObj->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
-        {
-          Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
-          TheNISContext()->Display (aShape);
-        }
-        aDispSet.Add (anObj);
       }
     }
   }
@@ -1739,27 +2399,12 @@ static int VDonly2 (Draw_Interpretor& ,
       continue;
     }
 
-    if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
+    const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
+    if (aShape.IsNull())
     {
-      const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
       aCtx->Erase (aShape, Standard_False);
     }
-    else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
-    {
-      const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
-      TheNISContext()->Erase (aShape);
-    }
-  }
-
-  // update the screen and redraw the view
-  const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
-  a3DView()->SetImmediateUpdate (isAutoUpdate);
-  if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
-   || aToUpdate == ViewerTest_RM_RedrawForce)
-  {
-    TheAISContext()->UpdateCurrentViewer();
   }
-
   return 0;
 }
 
@@ -1775,17 +2420,18 @@ int VRemove (Draw_Interpretor& theDI,
              Standard_Integer  theArgNb,
              const char**      theArgVec)
 {
-  if (a3DView().IsNull())
+  const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
+  ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
+  if (aCtx.IsNull())
   {
-    std::cout << "Error: wrong syntax!\n";
+    std::cerr << "Error: no active view!\n";
     return 1;
   }
 
-  TheAISContext()->CloseAllContexts (Standard_False);
-
-  ViewerTest_RedrawMode aToUpdate     = ViewerTest_RM_Auto;
-  Standard_Boolean      isContextOnly = Standard_False;
-  Standard_Boolean      toRemoveAll   = Standard_False;
+  Standard_Boolean isContextOnly = Standard_False;
+  Standard_Boolean toRemoveAll   = Standard_False;
+  Standard_Boolean toPrintInfo   = Standard_True;
+  Standard_Boolean toRemoveLocal = Standard_False;
 
   Standard_Integer anArgIter = 1;
   for (; anArgIter < theArgNb; ++anArgIter)
@@ -1800,7 +2446,19 @@ int VRemove (Draw_Interpretor& theDI,
     {
       toRemoveAll = Standard_True;
     }
-    else if (!parseRedrawMode (anArg, aToUpdate))
+    else if (anArg == "-noinfo")
+    {
+      toPrintInfo = Standard_False;
+    }
+    else if (anArg == "-local")
+    {
+      toRemoveLocal = Standard_True;
+    }
+    else if (anUpdateTool.parseRedrawMode (anArg))
+    {
+      continue;
+    }
+    else
     {
       break;
     }
@@ -1808,9 +2466,19 @@ int VRemove (Draw_Interpretor& theDI,
   if (toRemoveAll
    && anArgIter < theArgNb)
   {
-    std::cout << "Error: wrong syntax!\n";
+    std::cerr << "Error: wrong syntax!\n";
+    return 1;
+  }
+
+  if (toRemoveLocal && !aCtx->HasOpenedContext())
+  {
+    std::cerr << "Error: local selection context is not open.\n";
     return 1;
   }
+  else if (!toRemoveLocal && aCtx->HasOpenedContext())
+  {
+    aCtx->CloseAllContexts (Standard_False);
+  }
 
   NCollection_List<TCollection_AsciiString> anIONameList;
   if (toRemoveAll)
@@ -1832,57 +2500,31 @@ int VRemove (Draw_Interpretor& theDI,
         continue;
       }
 
-      const Handle(Standard_Transient)& aTransientObj = GetMapOfAIS().Find2 (aName);
-
-      const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aTransientObj);
-      if (!anIO.IsNull())
+      const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
+      if (anIO->GetContext() != aCtx)
       {
-        if (anIO->GetContext() != TheAISContext())
-        {
-          theDI << aName.ToCString() << " was not displayed in current context.\n";
-          theDI << "Please activate view with this object displayed and try again.\n";
-          continue;
-        }
-
-        anIONameList.Append (aName);
+        theDI << aName.ToCString() << " was not displayed in current context.\n";
+        theDI << "Please activate view with this object displayed and try again.\n";
         continue;
       }
 
-      const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (aTransientObj);
-      if (!aNisIO.IsNull())
-      {
-        anIONameList.Append (aName);
-      }
+      anIONameList.Append (aName);
+      continue;
     }
   }
-  else if (TheAISContext()->NbCurrents() > 0
-        || TheNISContext()->GetSelected().Extent() > 0)
+  else if (aCtx->NbCurrents() > 0)
   {
     for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
          anIter.More(); anIter.Next())
     {
       const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
-      if (!anIO.IsNull())
+      if (!aCtx->IsCurrent (anIO))
       {
-        if (!TheAISContext()->IsCurrent (anIO))
-        {
-          continue;
-        }
-
-        anIONameList.Append (anIter.Key2());
         continue;
       }
 
-      const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
-      if (!aNisIO.IsNull())
-      {
-        if (!TheNISContext()->IsSelected (aNisIO))
-        {
-          continue;
-        }
-
-        anIONameList.Append (anIter.Key2());
-      }
+      anIONameList.Append (anIter.Key2());
+      continue;
     }
   }
 
@@ -1891,35 +2533,23 @@ int VRemove (Draw_Interpretor& theDI,
        anIter.More(); anIter.Next())
   {
     const Handle(AIS_InteractiveObject) anIO  = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
-
-    if (!anIO.IsNull())
+    aCtx->Remove (anIO, Standard_False);
+    if (toPrintInfo)
     {
-      TheAISContext()->Remove (anIO, Standard_False);
       theDI << anIter.Value().ToCString() << " was removed\n";
     }
-    else
-    {
-      const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
-      if (!aNisIO.IsNull())
-      {
-        TheNISContext()->Remove (aNisIO);
-        theDI << anIter.Value().ToCString() << " was removed\n";
-      }
-    }
-      
     if (!isContextOnly)
     {
       GetMapOfAIS().UnBind2 (anIter.Value());
     }
   }
 
-  // update the screen and redraw the view
-  const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
-  a3DView()->SetImmediateUpdate (isAutoUpdate);
-  if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
-   || aToUpdate == ViewerTest_RM_RedrawForce)
+  // Close local context if it is empty
+  TColStd_MapOfTransient aLocalIO;
+  if (aCtx->HasOpenedContext()
+   && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
   {
-    TheAISContext()->UpdateCurrentViewer();
+    aCtx->CloseAllContexts (Standard_False);
   }
 
   return 0;
@@ -1934,37 +2564,66 @@ int VErase (Draw_Interpretor& theDI,
             Standard_Integer  theArgNb,
             const char**      theArgVec)
 {
-  if (a3DView().IsNull())
+  const Handle(AIS_InteractiveContext)& aCtx  = ViewerTest::GetAISContext();
+  const Handle(V3d_View)&               aView = ViewerTest::CurrentView();
+  ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
+  if (aCtx.IsNull())
   {
-    std::cout << "Error: no active view!\n";
+    std::cerr << "Error: no active view!\n";
     return 1;
   }
-  TheAISContext()->CloseAllContexts (Standard_False);
 
-  ViewerTest_RedrawMode  aToUpdate  = ViewerTest_RM_Auto;
   const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
 
   Standard_Integer anArgIter = 1;
+  Standard_Boolean toEraseLocal  = Standard_False;
+  Standard_Boolean toEraseInView = Standard_False;
+  TColStd_SequenceOfAsciiString aNamesOfEraseIO;
   for (; anArgIter < theArgNb; ++anArgIter)
   {
-    if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate))
+    TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
+    anArgCase.LowerCase();
+    if (anUpdateTool.parseRedrawMode (anArgCase))
     {
-      break;
+      continue;
+    }
+    else if (anArgCase == "-local")
+    {
+      toEraseLocal = Standard_True;
+    }
+    else if (anArgCase == "-view"
+          || anArgCase == "-inview")
+    {
+      toEraseInView = Standard_True;
+    }
+    else
+    {
+      aNamesOfEraseIO.Append (theArgVec[anArgIter]);
     }
   }
 
-  if (anArgIter < theArgNb)
+  if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
   {
-    if (toEraseAll)
-    {
-      std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
-      return 1;
-    }
+    std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
+    return 1;
+  }
 
-    // has a list of names
-    for (; anArgIter < theArgNb; ++anArgIter)
+  if (toEraseLocal && !aCtx->HasOpenedContext())
+  {
+    std::cerr << "Error: local selection context is not open.\n";
+    return 1;
+  }
+  else if (!toEraseLocal && aCtx->HasOpenedContext())
+  {
+    aCtx->CloseAllContexts (Standard_False);
+  }
+
+  if (!aNamesOfEraseIO.IsEmpty())
+  {
+    // Erase named objects
+    for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
     {
-      TCollection_AsciiString aName = theArgVec[anArgIter];
+      TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
       if (!GetMapOfAIS().IsBound2 (aName))
       {
         continue;
@@ -1975,65 +2634,60 @@ int VErase (Draw_Interpretor& theDI,
       theDI << aName.ToCString() << " ";
       if (!anIO.IsNull())
       {
-        TheAISContext()->Erase (anIO, Standard_False);
-      }
-      else
-      {
-        const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj);
-        if (!aNisIO.IsNull())
+        if (toEraseInView)
+        {
+          aCtx->SetViewAffinity (anIO, aView, Standard_False);
+        }
+        else
         {
-          TheNISContext()->Erase (aNisIO);
+          aCtx->Erase (anIO, Standard_False);
         }
       }
     }
   }
-  else if (!toEraseAll
-        && TheAISContext()->NbCurrents() > 0)
+  else if (!toEraseAll && aCtx->NbCurrents() > 0)
   {
-    // remove all currently selected objects
+    // Erase selected objects
     for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
          anIter.More(); anIter.Next())
     {
       const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
       if (!anIO.IsNull()
-       && TheAISContext()->IsCurrent (anIO))
+       && aCtx->IsCurrent (anIO))
       {
         theDI << anIter.Key2().ToCString() << " ";
-        TheAISContext()->Erase (anIO, Standard_False);
+        if (toEraseInView)
+        {
+          aCtx->SetViewAffinity (anIO, aView, Standard_False);
+        }
+        else
+        {
+          aCtx->Erase (anIO, Standard_False);
+        }
       }
     }
   }
   else
   {
-    // erase entire viewer
+    // Erase all objects
     for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
          anIter.More(); anIter.Next())
     {
       const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
       if (!anIO.IsNull())
       {
-        TheAISContext()->Erase (anIO, Standard_False);
-      }
-      else
-      {
-        const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
-        if (!aNisIO.IsNull())
+        if (toEraseInView)
+        {
+          aCtx->SetViewAffinity (anIO, aView, Standard_False);
+        }
+        else
         {
-          TheNISContext()->Erase (aNisIO);
+          aCtx->Erase (anIO, Standard_False);
         }
       }
     }
   }
 
-  // update the screen and redraw the view
-  const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
-  a3DView()->SetImmediateUpdate (isAutoUpdate);
-  if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
-   || aToUpdate == ViewerTest_RM_RedrawForce)
-  {
-    TheAISContext()->UpdateCurrentViewer();
-  }
-
   return 0;
 }
 
@@ -2047,18 +2701,29 @@ static int VDisplayAll (Draw_Interpretor& ,
                         const char**      theArgVec)
 
 {
-  if (a3DView().IsNull())
+  const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
+  ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
+  if (aCtx.IsNull())
   {
-    std::cout << "Error: no active view!\n";
+    std::cerr << "Error: no active view!\n";
     return 1;
   }
 
-  ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
-
   Standard_Integer anArgIter = 1;
+  Standard_Boolean toDisplayLocal = Standard_False;
   for (; anArgIter < theArgNb; ++anArgIter)
   {
-    if (!parseRedrawMode (theArgVec[anArgIter], aToUpdate))
+    TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
+    anArgCase.LowerCase();
+    if (anArgCase == "-local")
+    {
+      toDisplayLocal = Standard_True;
+    }
+    else if (anUpdateTool.parseRedrawMode (anArgCase))
+    {
+      continue;
+    }
+    else
     {
       break;
     }
@@ -2069,50 +2734,202 @@ static int VDisplayAll (Draw_Interpretor& ,
     return 1;
   }
 
-  if (TheAISContext()->HasOpenedContext())
+  if (toDisplayLocal && !aCtx->HasOpenedContext())
   {
-    TheAISContext()->CloseLocalContext();
+    std::cerr << "Error: local selection context is not open.\n";
+    return 1;
+  }
+  else if (!toDisplayLocal && aCtx->HasOpenedContext())
+  {
+    aCtx->CloseLocalContext (Standard_False);
+  }
+
+  for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
+       anIter.More(); anIter.Next())
+  {
+    const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
+    aCtx->Erase (aShape, Standard_False);
   }
 
   for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
        anIter.More(); anIter.Next())
   {
-    if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
+    const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
+    aCtx->Display (aShape, Standard_False);
+  }
+  return 0;
+}
+
+//! Auxiliary method to find presentation
+inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
+                                                     const Handle(AIS_InteractiveObject)&  theIO,
+                                                     const Standard_Integer                theMode)
+{
+  if (theIO.IsNull())
+  {
+    return Handle(PrsMgr_Presentation)();
+  }
+
+  if (theMode != -1)
+  {
+    if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
+    {
+      return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
+    }
+  }
+  else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
+  {
+    return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
+  }
+  else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
+  {
+    return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
+  }
+  return Handle(PrsMgr_Presentation)();
+}
+
+enum ViewerTest_BndAction
+{
+  BndAction_Hide,
+  BndAction_Show,
+  BndAction_Print
+};
+
+//! Auxiliary method to print bounding box of presentation
+inline void bndPresentation (Draw_Interpretor&                  theDI,
+                             const Handle(PrsMgr_Presentation)& thePrs,
+                             const TCollection_AsciiString&     theName,
+                             const ViewerTest_BndAction         theAction)
+{
+  switch (theAction)
+  {
+    case BndAction_Hide:
+    {
+      thePrs->Presentation()->GraphicUnHighlight();
+      break;
+    }
+    case BndAction_Show:
+    {
+      Handle(Graphic3d_Structure) aPrs (thePrs->Presentation());
+      aPrs->CStructure()->HighlightColor.r = 0.988235f;
+      aPrs->CStructure()->HighlightColor.g = 0.988235f;
+      aPrs->CStructure()->HighlightColor.b = 0.988235f;
+      aPrs->CStructure()->HighlightWithBndBox (aPrs, Standard_True);
+      break;
+    }
+    case BndAction_Print:
+    {
+      Bnd_Box aBox = thePrs->Presentation()->MinMaxValues();
+      gp_Pnt aMin = aBox.CornerMin();
+      gp_Pnt aMax = aBox.CornerMax();
+      theDI << theName  << "\n"
+            << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
+            << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
+      break;
+    }
+  }
+}
+
+//==============================================================================
+//function : VBounding
+//purpose  :
+//==============================================================================
+int VBounding (Draw_Interpretor& theDI,
+               Standard_Integer  theArgNb,
+               const char**      theArgVec)
+{
+  Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
+  ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
+  if (aCtx.IsNull())
+  {
+    std::cout << "Error: no active view!\n";
+    return 1;
+  }
+
+  ViewerTest_BndAction anAction = BndAction_Show;
+  Standard_Integer     aMode    = -1;
+
+  Standard_Integer anArgIter = 1;
+  for (; anArgIter < theArgNb; ++anArgIter)
+  {
+    TCollection_AsciiString anArg (theArgVec[anArgIter]);
+    anArg.LowerCase();
+    if (anArg == "-print")
+    {
+      anAction = BndAction_Print;
+    }
+    else if (anArg == "-show")
+    {
+      anAction = BndAction_Show;
+    }
+    else if (anArg == "-hide")
+    {
+      anAction = BndAction_Hide;
+    }
+    else if (anArg == "-mode")
     {
-      const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
-      TheAISContext()->Erase (aShape, Standard_False);
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+      aMode = Draw::Atoi (theArgVec[anArgIter]);
     }
-    else if (anIter.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject)))
+    else if (!anUpdateTool.parseRedrawMode (anArg))
     {
-      const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
-      TheNISContext()->Erase (aShape);
+      break;
     }
   }
 
-  for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
-       anIter.More(); anIter.Next())
+  if (anArgIter < theArgNb)
   {
-    if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
+    // has a list of names
+    for (; anArgIter < theArgNb; ++anArgIter)
     {
-      const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
-      TheAISContext()->Display (aShape, Standard_False);
+      TCollection_AsciiString aName = theArgVec[anArgIter];
+      if (!GetMapOfAIS().IsBound2 (aName))
+      {
+        std::cout << "Error: presentation " << aName << " does not exist\n";
+        return 1;
+      }
+
+      Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
+      Handle(PrsMgr_Presentation)   aPrs = findPresentation (aCtx, anIO, aMode);
+      if (aPrs.IsNull())
+      {
+        std::cout << "Error: presentation " << aName << " does not exist\n";
+        return 1;
+      }
+      bndPresentation (theDI, aPrs, aName, anAction);
     }
-    else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
+  }
+  else if (aCtx->NbCurrents() > 0)
+  {
+    // remove all currently selected objects
+    for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
     {
-      Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
-      TheNISContext()->Display (aShape);
+      Handle(AIS_InteractiveObject) anIO = aCtx->Current();
+      Handle(PrsMgr_Presentation)   aPrs = findPresentation (aCtx, anIO, aMode);
+      if (!aPrs.IsNull())
+      {
+        bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
+      }
     }
   }
-
-  // update the screen and redraw the view
-  const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
-  a3DView()->SetImmediateUpdate (isAutoUpdate);
-  if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
-   || aToUpdate == ViewerTest_RM_RedrawForce)
+  else
   {
-    TheAISContext()->UpdateCurrentViewer();
+    // all objects
+    for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
+         anIter.More(); anIter.Next())
+    {
+      Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
+      Handle(PrsMgr_Presentation)   aPrs = findPresentation (aCtx, anIO, aMode);
+      if (!aPrs.IsNull())
+      {
+        bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
+      }
+    }
   }
-
   return 0;
 }
 
@@ -2275,7 +3092,7 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
   }
   else
   {
-    anAISContext->Clear (anIO, Standard_False);
+    anAISContext->Remove (anIO, Standard_False);
     aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
     GetMapOfAIS().UnBind1 (anIO);
     GetMapOfAIS().UnBind2 (aShapeName);
@@ -2405,6 +3222,42 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
   return 0;
 }
 
+//! Auxiliary method to parse transformation persistence flags
+inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
+                                           Standard_Integer&              theFlags)
+{
+  if (theFlagString == "pan")
+  {
+    theFlags |= Graphic3d_TMF_PanPers;
+  }
+  else if (theFlagString == "zoom")
+  {
+    theFlags |= Graphic3d_TMF_ZoomPers;
+  }
+  else if (theFlagString == "rotate")
+  {
+    theFlags |= Graphic3d_TMF_RotatePers;
+  }
+  else if (theFlagString == "trihedron")
+  {
+    theFlags = Graphic3d_TMF_TriedronPers;
+  }
+  else if (theFlagString == "full")
+  {
+    theFlags = Graphic3d_TMF_FullPers;
+  }
+  else if (theFlagString == "none")
+  {
+    theFlags = Graphic3d_TMF_None;
+  }
+  else
+  {
+    return Standard_False;
+  }
+
+  return Standard_True;
+}
+
 //==============================================================================
 //function : VDisplay2
 //author   : ege
@@ -2416,82 +3269,372 @@ static int VDisplay2 (Draw_Interpretor& theDI,
 {
   if (theArgNb < 2)
   {
-    std::cout << theArgVec[0] << "Error: wrong syntax!\n";
+    std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
     return 1;
   }
-  else if (a3DView().IsNull())
-  {
-    ViewerTest::ViewerInit();
-    std::cout << "Command vinit should be called before!\n";
-    // return 1;
-  }
 
-  const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
-  if (aCtx->HasOpenedContext())
+  Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
+  if (aCtx.IsNull())
   {
-    aCtx->CloseLocalContext();
-  }
-
-  ViewerTest_RedrawMode aToUpdate = ViewerTest_RM_Auto;
+    ViewerTest::ViewerInit();
+    aCtx = ViewerTest::GetAISContext();
+  }
+
+  // Parse input arguments
+  ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
+  Standard_Integer   isMutable      = -1;
+  Graphic3d_ZLayerId aZLayer        = Graphic3d_ZLayerId_UNKNOWN;
+  Standard_Boolean   toDisplayLocal = Standard_False;
+  Standard_Boolean   toReDisplay    = Standard_False;
+  Standard_Integer   isSelectable   = -1;
+  Standard_Integer   anObjDispMode  = -2;
+  Standard_Integer   anObjHighMode  = -2;
+  Standard_Boolean   toSetTrsfPers  = Standard_False;
+  Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
+  gp_Pnt aTPPosition;
+  TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
+  AIS_DisplayStatus aDispStatus = AIS_DS_None;
+  Standard_Integer toDisplayInView = Standard_False;
   for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
   {
-    const TCollection_AsciiString aName = theArgVec[anArgIter];
-    if (parseRedrawMode (aName, aToUpdate))
+    const TCollection_AsciiString aName     = theArgVec[anArgIter];
+    TCollection_AsciiString       aNameCase = aName;
+    aNameCase.LowerCase();
+    if (anUpdateTool.parseRedrawMode (aName))
     {
       continue;
     }
-    else if (!GetMapOfAIS().IsBound2 (aName))
+    else if (aNameCase == "-mutable")
     {
-      // create the AIS_Shape from a name
-      const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
-      if (!aShape.IsNull())
+      isMutable = 1;
+    }
+    else if (aNameCase == "-neutral")
+    {
+      aDispStatus = AIS_DS_Displayed;
+    }
+    else if (aNameCase == "-immediate"
+          || aNameCase == "-top")
+    {
+      aZLayer = Graphic3d_ZLayerId_Top;
+    }
+    else if (aNameCase == "-topmost")
+    {
+      aZLayer = Graphic3d_ZLayerId_Topmost;
+    }
+    else if (aNameCase == "-osd"
+          || aNameCase == "-toposd"
+          || aNameCase == "-overlay")
+    {
+      aZLayer = Graphic3d_ZLayerId_TopOSD;
+    }
+    else if (aNameCase == "-botosd"
+          || aNameCase == "-underlay")
+    {
+      aZLayer = Graphic3d_ZLayerId_BotOSD;
+    }
+    else if (aNameCase == "-select"
+          || aNameCase == "-selectable")
+    {
+      isSelectable = 1;
+    }
+    else if (aNameCase == "-noselect"
+          || aNameCase == "-noselection")
+    {
+      isSelectable = 0;
+    }
+    else if (aNameCase == "-dispmode"
+          || aNameCase == "-displaymode")
+    {
+      if (++anArgIter >= theArgNb)
       {
-        GetMapOfAIS().Bind (aShape, aName);
-        aCtx->Display (aShape, Standard_False);
+        std::cerr << "Error: wrong syntax at " << aName << ".\n";
+        return 1;
       }
-      continue;
+
+      anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
     }
+    else if (aNameCase == "-highmode"
+          || aNameCase == "-highlightmode")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cerr << "Error: wrong syntax at " << aName << ".\n";
+        return 1;
+      }
 
-    Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
-    if (anObj->IsKind (STANDARD_TYPE (AIS_InteractiveObject)))
+      anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
+    }
+    else if (aNameCase == "-3d")
+    {
+      toSetTrsfPers  = Standard_True;
+      aTrsfPersFlags = Graphic3d_TMF_None;
+    }
+    else if (aNameCase == "-2d")
+    {
+      toSetTrsfPers  = Standard_True;
+      aTrsfPersFlags = Graphic3d_TMF_2d;
+    }
+    else if (aNameCase == "-2dtopdown")
+    {
+      toSetTrsfPers  = Standard_True;
+      aTrsfPersFlags = Graphic3d_TMF_2d | Graphic3d_TMF_2d_IsTopDown;
+    }
+    else if (aNameCase == "-trsfpers"
+          || aNameCase == "-pers")
     {
-      Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
-      if (aShape->Type() == AIS_KOI_Datum)
+      if (++anArgIter >= theArgNb)
       {
-        aCtx->Display (aShape, Standard_False);
+        std::cerr << "Error: wrong syntax at " << aName << ".\n";
+        return 1;
       }
-      else
+
+      toSetTrsfPers  = Standard_True;
+      aTrsfPersFlags = Graphic3d_TMF_None;
+      TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
+      aPersFlags.LowerCase();
+      for (Standard_Integer aParserPos = aPersFlags.Search ("|");; aParserPos = aPersFlags.Search ("|"))
       {
-        theDI << "Display " << aName.ToCString() << "\n";
-        // get the Shape from a name
-        TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
+        if (aParserPos == -1)
+        {
+          if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
+          {
+            std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
+            return 1;
+          }
+          break;
+        }
 
-        // update the Shape in the AIS_Shape
-        Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
-        if (!aShapePrs.IsNull())
+        TCollection_AsciiString anOtherFlags = aPersFlags.Split (aParserPos - 1);
+        if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
         {
-          aShapePrs->Set (aNewShape);
+          std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
+          return 1;
         }
-        aCtx->Redisplay (aShape, Standard_False);
-        aCtx->Display   (aShape, Standard_False);
+        aPersFlags = anOtherFlags;
+      }
+    }
+    else if (aNameCase == "-trsfperspos"
+          || aNameCase == "-perspos")
+    {
+      if (anArgIter + 2 >= theArgNb)
+      {
+        std::cerr << "Error: wrong syntax at " << aName << ".\n";
+        return 1;
+      }
+
+      TCollection_AsciiString aX (theArgVec[++anArgIter]);
+      TCollection_AsciiString aY (theArgVec[++anArgIter]);
+      TCollection_AsciiString aZ = "0";
+      if (!aX.IsIntegerValue()
+       || !aY.IsIntegerValue())
+      {
+        std::cerr << "Error: wrong syntax at " << aName << ".\n";
+        return 1;
+      }
+      if (anArgIter + 1 < theArgNb)
+      {
+        TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
+        if (aTemp.IsIntegerValue())
+        {
+          aZ = aTemp;
+          ++anArgIter;
+        }
+      }
+      aTPPosition.SetCoord (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue());
+    }
+    else if (aNameCase == "-layer")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cerr << "Error: wrong syntax at " << aName << ".\n";
+        return 1;
       }
-      aShape.Nullify();
+
+      TCollection_AsciiString aValue (theArgVec[anArgIter]);
+      if (!aValue.IsIntegerValue())
+      {
+        std::cerr << "Error: wrong syntax at " << aName << ".\n";
+        return 1;
+      }
+
+      aZLayer = aValue.IntegerValue();
+    }
+    else if (aNameCase == "-view"
+          || aNameCase == "-inview")
+    {
+      toDisplayInView = Standard_True;
+    }
+    else if (aNameCase == "-local")
+    {
+      aDispStatus = AIS_DS_Temporary;
+      toDisplayLocal = Standard_True;
+    }
+    else if (aNameCase == "-redisplay")
+    {
+      toReDisplay = Standard_True;
     }
-    else if (anObj->IsKind (STANDARD_TYPE (NIS_InteractiveObject)))
+    else
     {
-      Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
-      TheNISContext()->Display (aShape);
+      aNamesOfDisplayIO.Append (aName);
     }
   }
 
-  const Standard_Boolean isAutoUpdate = a3DView()->SetImmediateUpdate (Standard_False);
-  a3DView()->SetImmediateUpdate (isAutoUpdate);
-  if ((isAutoUpdate && aToUpdate != ViewerTest_RM_RedrawSuppress)
-   || aToUpdate == ViewerTest_RM_RedrawForce)
+  if (aNamesOfDisplayIO.IsEmpty())
+  {
+    std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
+    return 1;
+  }
+
+  // Prepare context for display
+  if (toDisplayLocal && !aCtx->HasOpenedContext())
   {
-    // update the screen and redraw the view
-    aCtx->UpdateCurrentViewer();
+    aCtx->OpenLocalContext (Standard_False);
+  }
+  else if (!toDisplayLocal && aCtx->HasOpenedContext())
+  {
+    aCtx->CloseAllContexts (Standard_False);
+  }
+
+  // Display interactive objects
+  for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
+  {
+    const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
+
+    if (!GetMapOfAIS().IsBound2 (aName))
+    {
+      // create the AIS_Shape from a name
+      const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
+      if (!aShape.IsNull())
+      {
+        if (isMutable != -1)
+        {
+          aShape->SetMutable (isMutable == 1);
+        }
+        if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
+        {
+          aShape->SetZLayer (aZLayer);
+        }
+        if (toSetTrsfPers)
+        {
+          aShape->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
+        }
+        if (anObjDispMode != -2)
+        {
+          aShape->SetDisplayMode (anObjDispMode);
+        }
+        if (anObjHighMode != -2)
+        {
+          aShape->SetHilightMode (anObjHighMode);
+        }
+        if (!toDisplayLocal)
+          GetMapOfAIS().Bind (aShape, aName);
+
+        Standard_Integer aDispMode = aShape->HasDisplayMode()
+                                   ? aShape->DisplayMode()
+                                   : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
+                                    ? aCtx->DisplayMode()
+                                    : 0);
+        Standard_Integer aSelMode = -1;
+        if ( isSelectable ==  1
+         || (isSelectable == -1
+          && aCtx->GetAutoActivateSelection()
+          && aShape->GetTransformPersistenceMode() == 0))
+        {
+          aSelMode = aShape->HasSelectionMode() ? aShape->SelectionMode() : -1;
+        }
+
+        aCtx->Display (aShape, aDispMode, aSelMode,
+                       Standard_False, aShape->AcceptShapeDecomposition(),
+                       aDispStatus);
+        if (toDisplayInView)
+        {
+          for (aCtx->CurrentViewer()->InitDefinedViews(); aCtx->CurrentViewer()->MoreDefinedViews(); aCtx->CurrentViewer()->NextDefinedViews())
+          {
+            aCtx->SetViewAffinity (aShape, aCtx->CurrentViewer()->DefinedView(), Standard_False);
+          }
+          aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
+        }
+      }
+      else
+      {
+        std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
+      }
+      continue;
+    }
+
+    Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
+    if (isMutable != -1)
+    {
+      aShape->SetMutable (isMutable == 1);
+    }
+    if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
+    {
+      aShape->SetZLayer (aZLayer);
+    }
+    if (toSetTrsfPers)
+    {
+      aShape->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
+    }
+    if (anObjDispMode != -2)
+    {
+      aShape->SetDisplayMode (anObjDispMode);
+    }
+    if (anObjHighMode != -2)
+    {
+      aShape->SetHilightMode (anObjHighMode);
+    }
+    Standard_Integer aDispMode = aShape->HasDisplayMode()
+                                ? aShape->DisplayMode()
+                                : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
+                                ? aCtx->DisplayMode()
+                                : 0);
+    Standard_Integer aSelMode = -1;
+    if ( isSelectable ==  1
+     || (isSelectable == -1
+      && aCtx->GetAutoActivateSelection()
+      && aShape->GetTransformPersistenceMode() == 0))
+    {
+      aSelMode = aShape->HasSelectionMode() ? aShape->SelectionMode() : -1;
+    }
+
+    if (aShape->Type() == AIS_KOI_Datum)
+    {
+      aCtx->Display (aShape, Standard_False);
+    }
+    else
+    {
+      theDI << "Display " << aName.ToCString() << "\n";
+
+      // update the Shape in the AIS_Shape
+      TopoDS_Shape      aNewShape = GetShapeFromName (aName.ToCString());
+      Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
+      if (!aShapePrs.IsNull())
+      {
+        if (!aShapePrs->Shape().IsEqual (aNewShape))
+        {
+          toReDisplay = Standard_True;
+        }
+        aShapePrs->Set (aNewShape);
+      }
+      if (toReDisplay)
+      {
+        aCtx->Redisplay (aShape, Standard_False);
+      }
+
+      if (aSelMode == -1)
+      {
+        aCtx->Erase (aShape);
+      }
+      aCtx->Display (aShape, aDispMode, aSelMode,
+                     Standard_False, aShape->AcceptShapeDecomposition(),
+                     aDispStatus);
+      if (toDisplayInView)
+      {
+        aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
+      }
+    }
   }
+
   return 0;
 }
 
@@ -2667,14 +3810,19 @@ static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char**
   GetMapOfAIS().Bind(myAisCrankArm,"c");
   GetMapOfAIS().Bind(myAisPropeller,"d");
 
-  TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED);
-  TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED);
-  TheAISContext()->SetColor(myAisPropeller   , Quantity_NOC_GREEN);
+  myAisCylinderHead->SetMutable (Standard_True);
+  myAisEngineBlock ->SetMutable (Standard_True);
+  myAisCrankArm    ->SetMutable (Standard_True);
+  myAisPropeller   ->SetMutable (Standard_True);
+
+  TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED);
+  TheAISContext()->SetColor (myAisEngineBlock,  Quantity_NOC_RED);
+  TheAISContext()->SetColor (myAisPropeller,    Quantity_NOC_GREEN);
 
-  TheAISContext()->Display(myAisCylinderHead,Standard_False);
-  TheAISContext()->Display(myAisEngineBlock,Standard_False );
-  TheAISContext()->Display(myAisCrankArm,Standard_False    );
-  TheAISContext()->Display(myAisPropeller,Standard_False);
+  TheAISContext()->Display (myAisCylinderHead, Standard_False);
+  TheAISContext()->Display (myAisEngineBlock,  Standard_False);
+  TheAISContext()->Display (myAisCrankArm,     Standard_False);
+  TheAISContext()->Display (myAisPropeller,    Standard_False);
 
   TheAISContext()->Deactivate(myAisCylinderHead);
   TheAISContext()->Deactivate(myAisEngineBlock );
@@ -2703,11 +3851,11 @@ static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char**
     TheAISContext()->UpdateCurrentViewer();
   }
 
-  TopoDS_Shape myNewCrankArm  =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() );
-  TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() );
+  TopoDS_Shape myNewCrankArm  =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() );
+  TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() );
 
-  myAisCrankArm ->ResetLocation();
-  myAisPropeller->ResetLocation();
+  myAisCrankArm ->ResetTransformation();
+  myAisPropeller->ResetTransformation();
 
   myAisCrankArm  -> Set(myNewCrankArm );
   myAisPropeller -> Set(myNewPropeller);
@@ -3101,31 +4249,105 @@ static void localCtxInfo (Draw_Interpretor& theDI)
         case TopAbs_SHAPE:     aShapeName = "    Shape"; break;
       }
 
-      if (aParentName != aPrevName)
+      if (aParentName != aPrevName)
+      {
+        theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
+        aPrevName = aParentName;
+      }
+      theDI << "  " << aShapeName << " #" << aNumber << "\n";
+      break;
+    }
+  }
+}
+
+//==============================================================================
+//function : VState
+//purpose  :
+//==============================================================================
+static Standard_Integer VState (Draw_Interpretor& theDI,
+                                Standard_Integer  theArgNb,
+                                Standard_CString* theArgVec)
+{
+  Handle(AIS_InteractiveContext) aCtx = TheAISContext();
+  if (aCtx.IsNull())
+  {
+    std::cerr << "Error: No opened viewer!\n";
+    return 1;
+  }
+
+  Standard_Boolean toPrintEntities = Standard_False;
+  Standard_Boolean toCheckSelected = Standard_False;
+
+  for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
+  {
+    TCollection_AsciiString anOption (theArgVec[anArgIdx]);
+    anOption.LowerCase();
+    if (anOption == "-detectedentities"
+      || anOption == "-entities")
+    {
+      toPrintEntities = Standard_True;
+    }
+    else if (anOption == "-hasselected")
+    {
+      toCheckSelected = Standard_True;
+    }
+  }
+
+  if (toCheckSelected)
+  {
+    aCtx->InitSelected();
+    TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
+    theDI << "Check if context has selected shape: " << hasSelected << "\n";
+
+    return 0;
+  }
+
+  if (toPrintEntities)
+  {
+    theDI << "Detected entities:\n";
+    Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
+    for (aSelector->InitDetected(); aSelector->MoreDetected(); aSelector->NextDetected())
+    {
+      const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->DetectedEntity();
+      Handle(SelectMgr_EntityOwner) anOwner    = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
+      Handle(AIS_InteractiveObject) anObj      = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
+      SelectMgr_SelectingVolumeManager aMgr = anObj->HasTransformation() ? aSelector->GetManager().Transform (anObj->InversedTransformation())
+                                                                         : aSelector->GetManager();
+      SelectBasics_PickResult aResult;
+      anEntity->Matches (aMgr, aResult);
+      NCollection_Vec3<Standard_Real> aDetectedPnt = aMgr.DetectedPoint (aResult.Depth());
+
+      TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
+      aName.LeftJustify (20, ' ');
+      char anInfoStr[512];
+      Sprintf (anInfoStr,
+               " Depth: %+.3f Distance: %+.3f Point: %+.3f %+.3f %+.3f",
+               aResult.Depth(),
+               aResult.DistToGeomCenter(),
+               aDetectedPnt.x(), aDetectedPnt.y(), aDetectedPnt.z());
+      theDI << "  " << aName
+            << anInfoStr
+            << " (" << anEntity->DynamicType()->Name() << ")"
+            << "\n";
+
+      Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
+      if (!aBRepOwner.IsNull())
+      {
+        theDI << "                       Detected Shape: "
+              << aBRepOwner->Shape().TShape()->DynamicType()->Name()
+              << "\n";
+      }
+
+      Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
+      if (!aWire.IsNull())
       {
-        theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
-        aPrevName = aParentName;
+        Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
+        theDI << "                       Detected Child: "
+              << aSen->DynamicType()->Name()
+              << "\n";
       }
-      theDI << "  " << aShapeName << " #" << aNumber << "\n";
-      break;
     }
-  }
-}
-
-//==============================================================================
-//function : VState
-//purpose  :
-//Draw arg : vstate [nameA] ... [nameN]
-//==============================================================================
-static Standard_Integer VState (Draw_Interpretor& theDI,
-                                Standard_Integer  theArgNb,
-                                Standard_CString* theArgVec)
-{
-  Handle(AIS_InteractiveContext) aCtx = TheAISContext();
-  if (aCtx.IsNull())
-  {
-    std::cerr << "Error: No opened viewer!\n";
-    return 1;
+    return 0;
   }
 
   NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
@@ -3347,7 +4569,7 @@ TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
       result = TheAISContext()->SelectedShape();
     else{
       Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
-      result = (*((Handle(AIS_Shape)*) &IO))->Shape();
+      result = Handle(AIS_Shape)::DownCast (IO)->Shape();
     }
   }
 
@@ -3414,7 +4636,7 @@ Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
       thearr->SetValue(i,TheAISContext()->SelectedShape());
     else{
       Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
-      thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
+      thearr->SetValue(i,Handle(AIS_Shape)::DownCast (IO)->Shape());
     }
   }
 
@@ -3514,6 +4736,54 @@ static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char**
   return 0;
 }
 
+//=======================================================================
+//function : VPickSelected
+//purpose  :
+//=======================================================================
+static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
+{
+  static Standard_Integer aCount = 0;
+  TCollection_AsciiString aName = "PickedShape_";
+
+  if (theArgNb > 1)
+  {
+    aName = theArgs[1];
+  }
+  else
+  {
+    aName = aName + aCount++ + "_";
+  }
+
+  Standard_Integer anIdx = 0;
+  for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
+  {
+    TopoDS_Shape aShape;
+    if (TheAISContext()->HasSelectedShape())
+    {
+      aShape = TheAISContext()->SelectedShape();
+    }
+    else
+    {
+      Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
+      aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
+    }
+
+    TCollection_AsciiString aCurrentName = aName;
+    if (anIdx > 0)
+    {
+      aCurrentName += anIdx;
+    }
+
+    DBRep::Set ((aCurrentName).ToCString(), aShape);
+
+    Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
+    GetMapOfAIS().Bind (aNewShape, aCurrentName);
+    TheAISContext()->Display (aNewShape);
+  }
+
+  return 0;
+}
+
 //=======================================================================
 //function : list of known objects
 //purpose  :
@@ -3646,7 +4916,7 @@ static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** a
     if(dimension_status == -1)
       TheAISContext()->Erase(curio,Standard_False);
     else {
-      AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
+      AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
       if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
          (dimension_status==1 && KOD != AIS_KOD_NONE))
        TheAISContext()->Erase(curio,Standard_False);
@@ -3679,7 +4949,7 @@ static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char**
     if(dimension_status == -1)
       TheAISContext()->Display(curio,Standard_False);
     else {
-      AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
+      AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
       if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
          (dimension_status==1 && KOD != AIS_KOD_NONE))
        TheAISContext()->Display(curio,Standard_False);
@@ -3691,83 +4961,375 @@ static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char**
   return 0;
 }
 
-//==============================================================================
-//function : VSetTransMode
+static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
+{
+  ifstream s(a[1]);
+  BRep_Builder builder;
+  TopoDS_Shape shape;
+  BRepTools::Read(shape, s, builder);
+  DBRep::Set(a[1], shape);
+  Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
+  Handle(AIS_Shape) ais = new AIS_Shape(shape);
+  Ctx->Display(ais);
+  return 0;
+}
+
+//===============================================================================================
+//function : VBsdf
 //purpose  :
-//Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]
+//===============================================================================================
+static int VBsdf (Draw_Interpretor& theDi,
+                  Standard_Integer  theArgsNb,
+                  const char**      theArgVec)
+{
+  Handle(V3d_View)   aView   = ViewerTest::CurrentView();
+  Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
+  if (aView.IsNull()
+   || aViewer.IsNull())
+  {
+    std::cerr << "No active viewer!\n";
+    return 1;
+  }
+
+  ViewerTest_CmdParser aCmd;
+
+  aCmd.AddDescription ("Adjusts parameters of material BSDF:");
+  aCmd.AddOption ("print|echo|p", "Print BSDF");
+
+  aCmd.AddOption ("kd", "Weight of the Lambertian BRDF");
+  aCmd.AddOption ("kr", "Weight of the reflection BRDF");
+  aCmd.AddOption ("kt", "Weight of the transmission BTDF");
+  aCmd.AddOption ("ks", "Weight of the glossy Blinn BRDF");
+  aCmd.AddOption ("le", "Self-emitted radiance");
+
+  aCmd.AddOption ("fresnel|f", "Fresnel coefficients; Allowed fresnel formats are: Constant x, Schlick x y z, Dielectric x, Conductor x y");
+
+  aCmd.AddOption ("roughness|r",    "Roughness of material (Blinn's exponent)");
+  aCmd.AddOption ("absorpCoeff|af", "Absorption coeff (only for transparent material)");
+  aCmd.AddOption ("absorpColor|ac", "Absorption color (only for transparent material)");
+
+  aCmd.AddOption ("normalize|n", "Normalize BSDF coefficients");
+
+  aCmd.Parse (theArgsNb, theArgVec);
+
+  if (aCmd.HasOption ("help"))
+  {
+    theDi.PrintHelp (theArgVec[0]);
+    return 0;
+  }
+
+  TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
+
+  // find object
+  ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
+  if (!aMap.IsBound2 (aName) )
+  {
+    std::cerr << "Use 'vdisplay' before" << "\n";
+    return 1;
+  }
+
+  Handle(AIS_InteractiveObject) anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
+  Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
+  Graphic3d_BSDF aBSDF = aMaterial.BSDF();
+
+  if (aCmd.HasOption ("print"))
+  {
+    Graphic3d_Vec4 aFresnel = aBSDF.Fresnel.Serialize();
+
+    std::cout << "\n"
+      << "Kd:               " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
+      << "Kr:               " << aBSDF.Kr.r() << ", " << aBSDF.Kr.g() << ", " << aBSDF.Kr.b() << "\n"
+      << "Kt:               " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
+      << "Ks:               " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
+      << "Le:               " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n"
+      << "Fresnel:          ";
+
+    if (aFresnel.x() >= 0.f)
+    {
+      std::cout
+        << "|Schlick| " << aFresnel.x() << ", " << aFresnel.y() << ", " << aFresnel.z() << "\n";
+    }
+    else if (aFresnel.x() >= -1.5f)
+    {
+      std::cout
+        << "|Constant| " << aFresnel.z() << "\n";
+    }
+    else if (aFresnel.x() >= -2.5f)
+    {
+      std::cout
+        << "|Conductor| " << aFresnel.y() << ", " << aFresnel.z() << "\n";
+    }
+    else
+    {
+      std::cout
+        << "|Dielectric| " << aFresnel.y() << "\n";
+    }
+
+
+    std::cout 
+      << "Roughness:        " << aBSDF.Roughness           << "\n"
+      << "Absorption coeff: " << aBSDF.AbsorptionCoeff     << "\n"
+      << "Absorption color: " << aBSDF.AbsorptionColor.r() << ", "
+                              << aBSDF.AbsorptionColor.g() << ", "
+                              << aBSDF.AbsorptionColor.b() << "\n";
+
+    return 0;
+  }
+
+  if (aCmd.HasOption ("roughness", 1, Standard_True))
+  {
+    aCmd.Arg ("roughness", 0);
+    aBSDF.Roughness = aCmd.ArgFloat ("roughness");
+  }
+
+  if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
+  {
+    aBSDF.AbsorptionCoeff = aCmd.ArgFloat ("absorpCoeff");
+  }
+
+  if (aCmd.HasOption ("absorpColor", 3, Standard_True))
+  {
+    aBSDF.AbsorptionColor = aCmd.ArgVec3f ("absorpColor");
+  }
+
+  if (aCmd.HasOption ("kd", 3))
+  {
+    aBSDF.Kd = aCmd.ArgVec3f ("kd");
+  }
+  else if (aCmd.HasOption ("kd", 1, Standard_True))
+  {
+    aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
+  }
+
+  if (aCmd.HasOption ("kr", 3))
+  {
+    aBSDF.Kr = aCmd.ArgVec3f ("kr");
+  }
+  else if (aCmd.HasOption ("kr", 1, Standard_True))
+  {
+    aBSDF.Kr = Graphic3d_Vec3 (aCmd.ArgFloat ("kr"));
+  }
+
+  if (aCmd.HasOption ("kt", 3))
+  {
+    aBSDF.Kt = aCmd.ArgVec3f ("kt");
+  }
+  else if (aCmd.HasOption ("kt", 1, Standard_True))
+  {
+    aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
+  }
+
+  if (aCmd.HasOption ("ks", 3))
+  {
+    aBSDF.Ks = aCmd.ArgVec3f ("ks");
+  }
+  else if (aCmd.HasOption ("ks", 1, Standard_True))
+  {
+    aBSDF.Ks = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
+  }
+
+  if (aCmd.HasOption ("le", 3))
+  {
+    aBSDF.Le = aCmd.ArgVec3f ("le");
+  }
+  else if (aCmd.HasOption ("le", 1, Standard_True))
+  {
+    aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
+  }
+
+  const std::string aFresnelErrorMessage =
+    "Error! Wrong Fresnel type. Allowed types are: Constant x, Schlick x y z, Dielectric x, Conductor x y.\n";
+
+  if (aCmd.HasOption ("fresnel", 4)) // Schlick: type, x, y ,z
+  {
+    std::string aFresnelType = aCmd.Arg ("fresnel", 0);
+    std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
+
+    if (aFresnelType == "schlick")
+    {
+      aBSDF.Fresnel = Graphic3d_Fresnel::CreateSchlick (
+        Graphic3d_Vec3 (static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
+                        static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())),
+                        static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 3).c_str()))));
+    }
+    else
+    {
+      std::cout << aFresnelErrorMessage;
+    }
+  }
+  else if (aCmd.HasOption ("fresnel", 3)) // Conductor: type, x, y
+  {
+    std::string aFresnelType = aCmd.Arg ("fresnel", 0);
+    std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
+
+    if (aFresnelType == "conductor")
+    {
+      aBSDF.Fresnel = Graphic3d_Fresnel::CreateConductor (
+        static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
+        static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())));
+    }
+    else
+    {
+      std::cout << aFresnelErrorMessage;
+    }
+  }
+  else if (aCmd.HasOption ("fresnel", 2)) // Dielectric, Constant: type, x
+  {
+    std::string aFresnelType = aCmd.Arg ("fresnel", 0);
+    std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
+
+    if (aFresnelType == "dielectric")
+    {
+      aBSDF.Fresnel = Graphic3d_Fresnel::CreateDielectric (
+        static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
+    }
+    else if (aFresnelType == "constant")
+    {
+      aBSDF.Fresnel = Graphic3d_Fresnel::CreateConstant (
+        static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
+    }
+    else
+    {
+      std::cout << aFresnelErrorMessage;
+    }
+  }
+
+  if (aCmd.HasOption ("normalize"))
+  {
+    aBSDF.Normalize();
+  }
+
+  aMaterial.SetBSDF (aBSDF);
+  anIObj->SetMaterial (aMaterial);
+
+  aView->Redraw();
+
+  return 0;
+}
+
+//==============================================================================
+//function : VLoadSelection
+//purpose  : Adds given objects to map of AIS and loads selection primitives for them
 //==============================================================================
+static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
+                                        Standard_Integer theArgNb,
+                                        const char** theArgVec)
+{
+  if (theArgNb < 2)
+  {
+    std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
+    return 1;
+  }
 
-static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
-  // Verification des arguments
-  if ( a3DView().IsNull() ) {
+  Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
+  if (aCtx.IsNull())
+  {
     ViewerTest::ViewerInit();
-    di << "La commande vinit n'a pas ete appele avant" << "\n";
+    aCtx = ViewerTest::GetAISContext();
   }
 
-  if ( argc < 3 || argc > 8 ) {
-    di << argv[0] << " Invalid number of arguments" << "\n";
-    return 1;
+  // Parse input arguments
+  TColStd_SequenceOfAsciiString aNamesOfIO;
+  Standard_Boolean isLocal = Standard_False;
+  for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
+  {
+    const TCollection_AsciiString aName     = theArgVec[anArgIter];
+    TCollection_AsciiString       aNameCase = aName;
+    aNameCase.LowerCase();
+    if (aNameCase == "-local")
+    {
+      isLocal = Standard_True;
+    }
+    else
+    {
+      aNamesOfIO.Append (aName);
+    }
   }
 
-  TCollection_AsciiString shapeName;
-  shapeName = argv[1];
-  Standard_Integer persFlag1 = Draw::Atoi(argv[2]);
-  Standard_Integer persFlag2 = 0;
-  Standard_Integer persFlag3 = 0;
-  gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 );
-  if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) {
-    persFlag2 = Draw::Atoi(argv[3]);
+  if (aNamesOfIO.IsEmpty())
+  {
+    std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
+    return 1;
   }
-  if ( argc == 5 || argc == 8 ) {
-    persFlag3 = Draw::Atoi(argv[4]);
+
+  // Prepare context
+  if (isLocal && !aCtx->HasOpenedContext())
+  {
+    aCtx->OpenLocalContext (Standard_False);
   }
-  if ( argc >= 6 ) {
-    origin.SetX( Draw::Atof(argv[argc - 3]) );
-    origin.SetY( Draw::Atof(argv[argc - 2]) );
-    origin.SetZ( Draw::Atof(argv[argc - 1]) );
+  else if (!isLocal && aCtx->HasOpenedContext())
+  {
+    aCtx->CloseAllContexts (Standard_False);
   }
 
-  Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName);
-  Handle(Standard_Transient) anObj;
-  if ( IsBound ) {
-    anObj = GetMapOfAIS().Find2(shapeName);
-    if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) {
-      Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
-      aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
-      if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) {
-        di << argv[0] << " All persistence modifiers were removed" << "\n";
+  // Load selection of interactive objects
+  for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
+  {
+    const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
+
+    Handle(AIS_InteractiveObject) aShape;
+    if (GetMapOfAIS().IsBound2 (aName))
+      aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
+    else
+      aShape = GetAISShapeFromName (aName.ToCString());
+
+    if (!aShape.IsNull())
+    {
+      if (!GetMapOfAIS().IsBound2 (aName))
+      {
+        GetMapOfAIS().Bind (aShape, aName);
       }
-    } else {
-      di << argv[0] << " Wrong object type" << "\n";
-      return 1;
-    }
-  } else { // Create the AIS_Shape from a name
-    const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString());
-    if ( !aShape.IsNull() ) {
-      GetMapOfAIS().Bind( aShape, shapeName );
-      aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin );
-      TheAISContext()->Display( aShape, Standard_False );
-    } else {
-      di << argv[0] << " Object not found" << "\n";
-      return 1;
+
+      aCtx->Load (aShape, -1, Standard_False);
+      aCtx->Activate (aShape, aShape->SelectionMode(), Standard_True);
     }
   }
 
-  // Upadate the screen and redraw the view
-  TheAISContext()->UpdateCurrentViewer();
   return 0;
 }
 
-static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
+//==============================================================================
+//function : VAutoActivateSelection
+//purpose  : Activates or deactivates auto computation of selection
+//==============================================================================
+static int VAutoActivateSelection (Draw_Interpretor& theDi,
+                                   Standard_Integer theArgNb,
+                                   const char** theArgVec)
 {
-  ifstream s(a[1]);
-  BRep_Builder builder;
-  TopoDS_Shape shape;
-  BRepTools::Read(shape, s, builder);
-  DBRep::Set(a[1], shape);
-  Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
-  Handle(AIS_Shape) ais = new AIS_Shape(shape);
-  Ctx->Display(ais);
+
+  if (theArgNb > 2)
+  {
+    std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
+    return 1;
+  }
+
+  Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
+  if (aCtx.IsNull())
+  {
+    ViewerTest::ViewerInit();
+    aCtx = ViewerTest::GetAISContext();
+  }
+
+  if (theArgNb == 1)
+  {
+    TCollection_AsciiString aSelActivationString;
+    if (aCtx->GetAutoActivateSelection())
+    {
+      aSelActivationString.Copy ("ON");
+    }
+    else
+    {
+      aSelActivationString.Copy ("OFF");
+    }
+
+    theDi << "Auto activation of selection is: " << aSelActivationString << "\n";
+  }
+  else
+  {
+    Standard_Boolean toActivate = Draw::Atoi (theArgVec[1]);
+    aCtx->SetAutoActivateSelection (toActivate);
+  }
+
   return 0;
 }
 
@@ -3789,15 +5351,28 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
 
   // display
   theCommands.Add("visos",
-                  "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
-                  "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
-                 __FILE__, visos, group);
+      "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
+      "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
+      __FILE__, visos, group);
 
   theCommands.Add("vdisplay",
-                 "vdisplay [-noupdate|-update] name1 [name2] ... [name n]"
+              "vdisplay [-noupdate|-update] [-local] [-mutable] [-overlay|-underlay]"
+      "\n\t\t:          [-trsfPers flags] [-trsfPersPos X Y [Z]] [-3d|-2d|-2dTopDown]"
+      "\n\t\t:          [-dispMode mode] [-highMode mode]"
+      "\n\t\t:          name1 [name2] ... [name n]"
       "\n\t\t: Displays named objects."
-      "\n\t\t: Option -noupdate suppresses viewer redraw call."
-                 __FILE__,VDisplay2,group);
+      "\n\t\t: Option -local enables displaying of objects in local"
+      "\n\t\t: selection context. Local selection context will be opened"
+      "\n\t\t: if there is not any."
+      "\n\t\t:  -noupdate    suppresses viewer redraw call."
+      "\n\t\t:  -mutable     enables optimizations for mutable objects."
+      "\n\t\t:  -overlay     draws objects in overlay."
+      "\n\t\t:  -underlay    draws objects in underlay."
+      "\n\t\t:  -selectable|-noselect controls selection of objects."
+      "\n\t\t:  -trsfPers    sets a transform persistence flags."
+      "\n\t\t:  -trsfPersPos sets an anchor point for transform persistence."
+      "\n\t\t:  -2d|-2dTopDown displays object in screen coordinates.",
+      __FILE__, VDisplay2, group);
 
   theCommands.Add ("vupdate",
       "vupdate name1 [name2] ... [name n]"
@@ -3805,18 +5380,24 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
       __FILE__, VUpdate, group);
 
   theCommands.Add("verase",
-      "verase [-noupdate|-update] [name1] ...  [name n]"
+      "verase [-noupdate|-update] [-local] [name1] ...  [name n]"
       "\n\t\t: Erases selected or named objects."
-      "\n\t\t: If there are no selected or named objects the whole viewer is erased.",
-                 __FILE__, VErase, group);
+      "\n\t\t: If there are no selected or named objects the whole viewer is erased."
+      "\n\t\t: Option -local enables erasing of selected or named objects without"
+      "\n\t\t: closing local selection context.",
+      __FILE__, VErase, group);
 
   theCommands.Add("vremove",
-    "vremove [-noupdate|-update] [-context] [-all] [name1] ...  [name n]"
-    "or vremove [-context] -all to remove all objects"
+      "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ...  [name n]"
+      "or vremove [-context] -all to remove all objects"
       "\n\t\t: Removes selected or named objects."
       "\n\t\t  If -context is in arguments, the objects are not deleted"
       "\n\t\t  from the map of objects and names."
-      "\n\t\t: Option -noupdate suppresses viewer redraw call.",
+      "\n\t\t: Option -local enables removing of selected or named objects without"
+      "\n\t\t: closing local selection context. Empty local selection context will be"
+      "\n\t\t: closed."
+      "\n\t\t: Option -noupdate suppresses viewer redraw call."
+      "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
       __FILE__, VRemove, group);
 
   theCommands.Add("vdonly",
@@ -3825,17 +5406,30 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
                  __FILE__,VDonly2,group);
 
   theCommands.Add("vdisplayall",
-                 "Displays all erased interactive objects (see vdir and vstate)",
-                 __FILE__,VDisplayAll,group);
+      "vidsplayall [-local]"
+      "\n\t\t: Displays all erased interactive objects (see vdir and vstate)."
+      "\n\t\t: Option -local enables displaying of the objects in local"
+      "\n\t\t: selection context.",
+      __FILE__, VDisplayAll, group);
 
   theCommands.Add("veraseall",
-                 "Erases all objects displayed in the viewer",
-                 __FILE__, VErase, group);
+      "veraseall [-local]"
+      "\n\t\t: Erases all objects displayed in the viewer."
+      "\n\t\t: Option -local enables erasing of the objects in local"
+      "\n\t\t: selection context.",
+      __FILE__, VErase, group);
 
   theCommands.Add("verasetype",
-                 "verasetype <Type>"
+      "verasetype <Type>"
       "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
-                 __FILE__,VEraseType,group);
+      __FILE__, VEraseType, group);
+  theCommands.Add("vbounding",
+              "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
+      "\n\t\t:           [-print] [-hide]"
+      "\n\t\t: Temporarily display bounding box of specified Interactive"
+      "\n\t\t: Objects, or print it to console if -print is specified."
+      "\n\t\t: Already displayed box might be hidden by -hide option.",
+                 __FILE__,VBounding,group);
 
   theCommands.Add("vdisplaytype",
                  "vdisplaytype        : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
@@ -3863,69 +5457,91 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
                  "Lists all objects displayed in 3D viewer",
                  __FILE__,VDir,group);
 
+#ifdef HAVE_FREEIMAGE
+  #define DUMP_FORMATS "{png|bmp|jpg|gif}"
+#else
+  #define DUMP_FORMATS "{ppm}"
+#endif
   theCommands.Add("vdump",
-    #ifdef HAVE_FREEIMAGE
-              "vdump <filename>.{png|bmp|jpg|gif} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
-      "\n\t\t:                                    [width Width=0 height Height=0]"
-      "\n\t\t: Dumps content of the active view into PNG, BMP, JPEG or GIF file",
-    #else
-              "vdump <filename>.{ppm} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
-      "\n\t\t:                        [width Width=0 height Height=0]"
-      "\n\t\t: Dumps content of the active view into PPM image file",
-    #endif
+              "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
+      "\n\t\t:       [-buffer rgb|rgba|depth=rgb]"
+      "\n\t\t:       [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
+      "\n\t\t: Dumps content of the active view into image file",
                  __FILE__,VDump,group);
 
   theCommands.Add("vsub",      "vsub 0/1 (off/on) [obj]        : Subintensity(on/off) of selected objects",
                  __FILE__,VSubInt,group);
 
+  theCommands.Add("vaspects",
+              "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
+      "\n\t\t:          [-setVisibility 0|1]"
+      "\n\t\t:          [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
+      "\n\t\t:          [-setMaterial MatName] [-unsetMaterial]"
+      "\n\t\t:          [-setTransparency Transp] [-unsetTransparency]"
+      "\n\t\t:          [-setWidth LineWidth] [-unsetWidth]"
+      "\n\t\t:          [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
+      "\n\t\t:          [-freeBoundary {off/on | 0/1}]"
+      "\n\t\t:          [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
+      "\n\t\t:          [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
+      "\n\t\t:          [-subshapes subname1 [subname2 [...]]]"
+      "\n\t\t: Manage presentation properties of all, selected or named objects."
+      "\n\t\t: When -subshapes is specified than following properties will be"
+      "\n\t\t: assigned to specified sub-shapes."
+      "\n\t\t: When -defaults is specified than presentation properties will be"
+      "\n\t\t: assigned to all objects that have not their own specified properties"
+      "\n\t\t: and to all objects to be displayed in the future."
+      "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
+                 __FILE__,VAspects,group);
+
   theCommands.Add("vsetcolor",
-                 "vsetcolor [name] ColorName"
-      "\n\t\t: Sets color for all, selected or named objects.",
-                 __FILE__,VColor2,group);
+      "vsetcolor [-noupdate|-update] [name] ColorName"
+      "\n\t\t: Sets color for all, selected or named objects."
+      "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
+                 __FILE__,VAspects,group);
 
   theCommands.Add("vunsetcolor",
-                 "vunsetcolor [name]"
-      "\n\t\t: Resets color for all, selected or named objects.",
-                 __FILE__,VColor2,group);
+                 "vunsetcolor [-noupdate|-update] [name]"
+      "\n\t\t: Resets color for all, selected or named objects."
+      "\n\t\t: Alias for vaspects -unsetcolor [name].",
+                 __FILE__,VAspects,group);
 
   theCommands.Add("vsettransparency",
-                 "vsettransparency [name] Coefficient"
+                 "vsettransparency [-noupdate|-update] [name] Coefficient"
       "\n\t\t: Sets transparency for all, selected or named objects."
-      "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent).",
-                 __FILE__,VTransparency,group);
+      "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
+      "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
+                 __FILE__,VAspects,group);
 
   theCommands.Add("vunsettransparency",
-                 "vunsettransparency [name]"
-      "\n\t\t: Resets transparency for all, selected or named objects.",
-                 __FILE__,VTransparency,group);
+                 "vunsettransparency [-noupdate|-update] [name]"
+      "\n\t\t: Resets transparency for all, selected or named objects."
+      "\n\t\t: Alias for vaspects -unsettransp [name].",
+                 __FILE__,VAspects,group);
 
   theCommands.Add("vsetmaterial",
-                 "vmaterial          : vmaterial  [name of shape] MaterialName",
-                 __FILE__,VMaterial,group);
+                 "vsetmaterial [-noupdate|-update] [name] MaterialName"
+      "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
+                 __FILE__,VAspects,group);
 
   theCommands.Add("vunsetmaterial",
-                 "vmaterial          : vmaterial  [name of shape]",
-                 __FILE__,VMaterial,group);
+                 "vunsetmaterial [-noupdate|-update] [name]"
+      "\n\t\t: Alias for vaspects -unsetmaterial [name].",
+                 __FILE__,VAspects,group);
 
   theCommands.Add("vsetwidth",
-                 "vsetwidth          : vwidth  [name of shape] width(0->10)",
-                 __FILE__,VWidth,group);
+                 "vsetwidth [-noupdate|-update] [name] width(0->10)"
+      "\n\t\t: Alias for vaspects -setwidth [name] width.",
+                 __FILE__,VAspects,group);
 
   theCommands.Add("vunsetwidth",
-                 "vunsetwidth          : vwidth  [name of shape]",
-                 __FILE__,VWidth,group);
+                 "vunsetwidth [-noupdate|-update] [name]"
+      "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
+                 __FILE__,VAspects,group);
 
   theCommands.Add("vsetinteriorstyle",
-                 "vsetinteriorstyle    : vsetinteriorstyle [name of shape] style",
-                 __FILE__,VInteriorStyle,group);
-
-  theCommands.Add("vardis",
-                 "vardis          : display activeareas",
-                 __FILE__,VDispAreas,group);
-
-  theCommands.Add("varera",
-                 "varera           : erase activeareas",
-                 __FILE__,VClearAreas,group);
+                 "vsetinteriorstyle [-noupdate|-update] [name] style"
+      "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
+                 __FILE__,VSetInteriorStyle,group);
 
   theCommands.Add("vsensdis",
                  "vardisp           : display active entities",
@@ -3935,7 +5551,9 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
                  __FILE__,VClearSensi,group);
 
   theCommands.Add("vselprecision",
-                 "vselprecision : vselprecision [precision_mode [tolerance_value]]",
+                 "vselprecision [-unset] [tolerance_value]"
+                  "\n\t\t  Manages selection precision or prints current value if no parameter is passed."
+                  "\n\t\t  -unset - restores default selection tolerance behavior, based on individual entity tolerance",
                  __FILE__,VSelPrecision,group);
 
   theCommands.Add("vperf",
@@ -4007,8 +5625,10 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
                  __FILE__,VActivatedMode,group);
 
   theCommands.Add("vstate",
-      "vstate [name1] ... [nameN]"
-      "\n\t\t: Reports show/hidden state for selected or named objects",
+      "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
+      "\n\t\t: Reports show/hidden state for selected or named objects"
+      "\n\t\t:   -entities - print low-level information about detected entities"
+      "\n\t\t:   -hasSelected - prints 1 if context has selected shape and 0 otherwise",
                  __FILE__,VState,group);
 
   theCommands.Add("vpickshapes",
@@ -4019,13 +5639,41 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
                  "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
                  VIOTypes,group);
 
-  theCommands.Add("vsettransmode",
-                 "vsettransmode   : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]",
-                 __FILE__,VSetTransMode,group);
-
   theCommands.Add("vr", "vr : reading of the shape",
                  __FILE__,vr, group);
 
+  theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
+    __FILE__, VPickSelected, group);
+
+  theCommands.Add ("vloadselection",
+    "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
+    "\n\t\t: primitives for the shapes with names given without displaying them."
+    "\n\t\t:   -local - open local context before selection computation",
+    __FILE__, VLoadSelection, group);
+
+  theCommands.Add ("vautoactivatesel",
+    "vautoactivatesel [0|1] : manage or display the option to automatically"
+    "\n\t\t: activate selection for newly displayed objects"
+    "\n\t\t:   [0|1] - turn off | on auto activation of selection",
+    __FILE__, VAutoActivateSelection, group);
+
+  theCommands.Add("vbsdf", "vbsdf [name] [options]"
+    "\nAdjusts parameters of material BSDF:"
+    "\n    -help : Shows this message"
+    "\n    -print : Print BSDF"
+    "\n    -kd : Weight of the Lambertian BRDF"
+    "\n    -kr : Weight of the reflection BRDF"
+    "\n    -kt : Weight of the transmission BTDF"
+    "\n    -ks : Weight of the glossy Blinn BRDF"
+    "\n    -le : Self-emitted radiance"
+    "\n    -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
+    "\n               Schlick x y z, Dielectric x, Conductor x y"
+    "\n    -roughness : Roughness of material (Blinn's exponent)"
+    "\n    -absorpcoeff : Absorption coefficient (only for transparent material)"
+    "\n    -absorpcolor : Absorption color (only for transparent material)"
+    "\n    -normalize : Normalize BSDF coefficients",
+    __FILE__, VBsdf, group);
+
 }
 
 //=====================================================================
@@ -4060,14 +5708,14 @@ static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
   TCollection_AsciiString checkValid = check.Value();
   Standard_Boolean ToCheck = Standard_True;
   if (!checkValid.IsEmpty()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
 #endif
     if ( checkValid=="true" || checkValid=="TRUE" ) {
       ToCheck= Standard_False;
     }
   } else {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n";
 #endif
   }
@@ -4225,7 +5873,7 @@ void ViewerTest::Factory(Draw_Interpretor& theDI)
   ViewerTest::Commands(theDI);
   ViewerTest::AviCommands(theDI);
 
-#ifdef DEB
+#ifdef OCCT_DEBUG
       theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n";
 #endif
 }