0029739: Draw Harness - vdonly does not hide displayed objects
[occt.git] / src / ViewerTest / ViewerTest.cxx
index c6725bf..6f53cd3 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-// Modified by  Eric Gouthiere [sep-oct 98] -> add commands for display...
-// Modified by  Robert Coublanc [nov 16-17-18 1998]
-//             -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
-//                                                  ViewerTest_ObjectCommands.cxx
-//                                                  ViewerTest_RelationCommands.cxx
-//             -add Functions and commands for interactive selection of shapes and objects
-//              in AIS Viewers. (PickShape(s), PickObject(s),
-
 #include <Standard_Stream.hxx>
 
 #include <ViewerTest.hxx>
 #include <Graphic3d_AspectFillArea3d.hxx>
 #include <Graphic3d_AspectLine3d.hxx>
 #include <Graphic3d_CStructure.hxx>
-#include <Graphic3d_TextureRoot.hxx>
+#include <Graphic3d_Texture2Dmanual.hxx>
+#include <Graphic3d_GraphicDriver.hxx>
 #include <Image_AlienPixMap.hxx>
+#include <OSD_File.hxx>
 #include <Prs3d_Drawer.hxx>
 #include <Prs3d_ShadingAspect.hxx>
 #include <Prs3d_IsoAspect.hxx>
@@ -231,6 +225,165 @@ Standard_Boolean ViewerTest::ParseLineType (Standard_CString   theArg,
   return Standard_True;
 }
 
+//=======================================================================
+//function : ParseMarkerType
+//purpose  :
+//=======================================================================
+Standard_Boolean ViewerTest::ParseMarkerType (Standard_CString theArg,
+                                              Aspect_TypeOfMarker& theType,
+                                              Handle(Image_PixMap)& theImage)
+{
+  theImage.Nullify();
+  TCollection_AsciiString aTypeStr (theArg);
+  aTypeStr.LowerCase();
+  if (aTypeStr == "empty")
+  {
+    theType = Aspect_TOM_EMPTY;
+  }
+  else if (aTypeStr == "point"
+        || aTypeStr == "dot"
+        || aTypeStr == ".")
+  {
+    theType = Aspect_TOM_POINT;
+  }
+  else if (aTypeStr == "plus"
+        || aTypeStr == "+")
+  {
+    theType = Aspect_TOM_PLUS;
+  }
+  else if (aTypeStr == "star"
+        || aTypeStr == "*")
+  {
+    theType = Aspect_TOM_STAR;
+  }
+  else if (aTypeStr == "cross"
+        || aTypeStr == "x")
+  {
+    theType = Aspect_TOM_X;
+  }
+  else if (aTypeStr == "circle"
+        || aTypeStr == "o")
+  {
+    theType = Aspect_TOM_O;
+  }
+  else if (aTypeStr == "pointincircle")
+  {
+    theType = Aspect_TOM_O_POINT;
+  }
+  else if (aTypeStr == "plusincircle")
+  {
+    theType = Aspect_TOM_O_PLUS;
+  }
+  else if (aTypeStr == "starincircle")
+  {
+    theType = Aspect_TOM_O_STAR;
+  }
+  else if (aTypeStr == "crossincircle"
+        || aTypeStr == "xcircle")
+  {
+    theType = Aspect_TOM_O_X;
+  }
+  else if (aTypeStr == "ring1")
+  {
+    theType = Aspect_TOM_RING1;
+  }
+  else if (aTypeStr == "ring2")
+  {
+    theType = Aspect_TOM_RING2;
+  }
+  else if (aTypeStr == "ring"
+        || aTypeStr == "ring3")
+  {
+    theType = Aspect_TOM_RING3;
+  }
+  else if (aTypeStr == "ball")
+  {
+    theType = Aspect_TOM_BALL;
+  }
+  else if (aTypeStr.IsIntegerValue())
+  {
+    const int aTypeInt = aTypeStr.IntegerValue();
+    if (aTypeInt < -1 || aTypeInt >= Aspect_TOM_USERDEFINED)
+    {
+      return Standard_False;
+    }
+    theType = (Aspect_TypeOfMarker )aTypeInt;
+  }
+  else
+  {
+    theType = Aspect_TOM_USERDEFINED;
+    Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
+    if (!anImage->Load (theArg))
+    {
+      return Standard_False;
+    }
+    if (anImage->Format() == Image_Format_Gray)
+    {
+      anImage->SetFormat (Image_Format_Alpha);
+    }
+    else if (anImage->Format() == Image_Format_GrayF)
+    {
+      anImage->SetFormat (Image_Format_AlphaF);
+    }
+    theImage = anImage;
+  }
+  return Standard_True;
+}
+
+//=======================================================================
+//function : ParseShadingModel
+//purpose  :
+//=======================================================================
+Standard_Boolean ViewerTest::ParseShadingModel (Standard_CString              theArg,
+                                                Graphic3d_TypeOfShadingModel& theModel)
+{
+  TCollection_AsciiString aTypeStr (theArg);
+  aTypeStr.LowerCase();
+  if (aTypeStr == "unlit"
+   || aTypeStr == "color"
+   || aTypeStr == "none")
+  {
+    theModel = Graphic3d_TOSM_UNLIT;
+  }
+  else if (aTypeStr == "flat"
+        || aTypeStr == "facet")
+  {
+    theModel = Graphic3d_TOSM_FACET;
+  }
+  else if (aTypeStr == "gouraud"
+        || aTypeStr == "vertex"
+        || aTypeStr == "vert")
+  {
+    theModel = Graphic3d_TOSM_VERTEX;
+  }
+  else if (aTypeStr == "phong"
+        || aTypeStr == "fragment"
+        || aTypeStr == "frag"
+        || aTypeStr == "pixel")
+  {
+    theModel = Graphic3d_TOSM_FRAGMENT;
+  }
+  else if (aTypeStr == "default"
+        || aTypeStr == "def")
+  {
+    theModel = Graphic3d_TOSM_DEFAULT;
+  }
+  else if (aTypeStr.IsIntegerValue())
+  {
+    const int aTypeInt = aTypeStr.IntegerValue();
+    if (aTypeInt <= Graphic3d_TOSM_DEFAULT || aTypeInt >= Graphic3d_TypeOfShadingModel_NB)
+    {
+      return Standard_False;
+    }
+    theModel = (Graphic3d_TypeOfShadingModel)aTypeInt;
+  }
+  else
+  {
+    return Standard_False;
+  }
+  return Standard_True;
+}
+
 //=======================================================================
 //function : GetTypeNames
 //purpose  :
@@ -299,7 +452,6 @@ void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,S
 
 #include <AIS_InteractiveContext.hxx>
 #include <AIS_Shape.hxx>
-#include <AIS_TexturedShape.hxx>
 #include <AIS_DisplayMode.hxx>
 #include <TColStd_MapOfInteger.hxx>
 #include <AIS_MapOfInteractive.hxx>
@@ -322,7 +474,6 @@ void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,S
 #include <AIS_DisplayMode.hxx>
 #include <TopTools_ListOfShape.hxx>
 #include <BRepOffsetAPI_MakeThickSolid.hxx>
-#include <BRepOffset.hxx>
 
 //==============================================================================
 //  VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
@@ -541,83 +692,39 @@ Handle(AIS_Shape) GetAISShapeFromName(const char* name)
 //==============================================================================
 void ViewerTest::Clear()
 {
-  if ( !a3DView().IsNull() ) {
-    ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
-    while ( it.More() ) {
-      cout << "Remove " << it.Key2() << endl;
-      const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (it.Key1());
-      TheAISContext()->Remove(anObj,Standard_False);
-      it.Next();
-    }
-    TheAISContext()->RebuildSelectionStructs();
-    TheAISContext()->UpdateCurrentViewer();
-    GetMapOfAIS().Clear();
+  if (a3DView().IsNull())
+  {
+    return;
   }
-}
 
-//==============================================================================
-//function : StandardModesActivation
-//purpose  : Activate a selection mode, vertex, edge, wire ..., in a local
-//           Context
-//==============================================================================
-Standard_DISABLE_DEPRECATION_WARNINGS
-void ViewerTest::StandardModeActivation(const Standard_Integer mode )
-{
-  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
-  if(mode==0) {
-    if (TheAISContext()->HasOpenedContext())
+  NCollection_Sequence<Handle(AIS_InteractiveObject)> aListRemoved;
+  for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); anObjIter.More(); anObjIter.Next())
+  {
+    const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
+    if (anObj->GetContext() != TheAISContext())
     {
-      aContext->CloseLocalContext();
-    }
-  } else {
-
-    if(!aContext->HasOpenedContext()) {
-      // To unhilight the preselected object
-      aContext->UnhilightSelected(Standard_False);
-      // Open a local Context in order to be able to select subshape from
-      // the selected shape if any or for all if there is no selection
-      if (!aContext->FirstSelectedObject().IsNull()){
-        aContext->OpenLocalContext(Standard_False);
-
-       for(aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected()){
-         aContext->Load(       aContext->SelectedInteractive(),-1,Standard_True);
-       }
-      }
-      else
-      {
-        aContext->OpenLocalContext();
-      }
+      continue;
     }
 
-    const char *cmode="???";
-
-    switch (mode) {
-    case 0: cmode = "Shape"; break;
-    case 1: cmode = "Vertex"; break;
-    case 2: cmode = "Edge"; break;
-    case 3: cmode = "Wire"; break;
-    case 4: cmode = "Face"; break;
-    case 5: cmode = "Shell"; break;
-    case 6: cmode = "Solid"; break;
-    case 7: cmode = "Compsolid"; break;
-    case 8: cmode = "Compound"; break;
-    }
+    std::cout << "Remove " << anObjIter.Key2() << std::endl;
+    TheAISContext()->Remove (anObj, Standard_False);
+    aListRemoved.Append (anObj);
+  }
 
-    if(theactivatedmodes.Contains(mode))
-    { // Desactivate
-      aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
-      theactivatedmodes.Remove(mode);
-      cout<<"Mode "<< cmode <<" OFF"<<endl;
-    }
-    else
-    { // Activate
-      aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
-      theactivatedmodes.Add(mode);
-      cout<<"Mode "<< cmode << " ON" << endl;
+  TheAISContext()->RebuildSelectionStructs();
+  TheAISContext()->UpdateCurrentViewer();
+  if (aListRemoved.Size() == GetMapOfAIS().Extent())
+  {
+    GetMapOfAIS().Clear();
+  }
+  else
+  {
+    for (NCollection_Sequence<Handle(AIS_InteractiveObject)>::Iterator anObjIter (aListRemoved); anObjIter.More(); anObjIter.Next())
+    {
+      GetMapOfAIS().UnBind1 (anObjIter.Value());
     }
   }
 }
-Standard_ENABLE_DEPRECATION_WARNINGS
 
 //==============================================================================
 //function : CopyIsoAspect
@@ -714,7 +821,7 @@ static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv
           CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
           TheAISContext()->SetLocalAttributes
                   (aShape, CurDrawer, Standard_False);
-          TheAISContext()->Redisplay(aShape);
+          TheAISContext()->Redisplay (aShape, Standard_False);
         } else {
           di << "Number of isos for " << argv[i] << " : "
              << aUIso->Number() << " " << aVIso->Number() << "\n";
@@ -986,12 +1093,13 @@ static Standard_Integer VDump (Draw_Interpretor& theDI,
   }
 
   Image_AlienPixMap aPixMap;
-  Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN;
+  Image_Format aFormat = Image_Format_UNKNOWN;
   switch (aParams.BufferType)
   {
-    case Graphic3d_BT_RGB:   aFormat = Image_PixMap::ImgRGB;   break;
-    case Graphic3d_BT_RGBA:  aFormat = Image_PixMap::ImgRGBA;  break;
-    case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; break;
+    case Graphic3d_BT_RGB:                 aFormat = Image_Format_RGB;   break;
+    case Graphic3d_BT_RGBA:                aFormat = Image_Format_RGBA;  break;
+    case Graphic3d_BT_Depth:               aFormat = Image_Format_GrayF; break;
+    case Graphic3d_BT_RGB_RayTraceHdrLeft: aFormat = Image_Format_RGBF;  break;
   }
 
   switch (aStereoPair)
@@ -1225,9 +1333,9 @@ static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** arg
       IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
       if (!IO.IsNull()) {
         if(On==1)
-          Ctx->SubIntensityOn(IO);
+          Ctx->SubIntensityOn(IO, Standard_True);
         else
-          Ctx->SubIntensityOff(IO);
+          Ctx->SubIntensityOff(IO, Standard_True);
       }
     }
     else return 1;
@@ -1440,39 +1548,44 @@ static int VSetInteriorStyle (Draw_Interpretor& theDI,
     theDI.PrintHelp (theArgVec[0]);
     return 1;
   }
-  Standard_Integer        anInterStyle = Aspect_IS_SOLID;
+  Aspect_InteriorStyle    anInterStyle = Aspect_IS_SOLID;
   TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
   aStyleArg.LowerCase();
   if (aStyleArg == "empty")
   {
-    anInterStyle = 0;
+    anInterStyle = Aspect_IS_EMPTY;
   }
   else if (aStyleArg == "hollow")
   {
-    anInterStyle = 1;
+    anInterStyle = Aspect_IS_HOLLOW;
   }
   else if (aStyleArg == "hatch")
   {
-    anInterStyle = 2;
+    anInterStyle = Aspect_IS_HATCH;
   }
   else if (aStyleArg == "solid")
   {
-    anInterStyle = 3;
+    anInterStyle = Aspect_IS_SOLID;
   }
   else if (aStyleArg == "hiddenline")
   {
-    anInterStyle = 4;
+    anInterStyle = Aspect_IS_HIDDENLINE;
   }
-  else
+  else if (aStyleArg == "point")
   {
-    anInterStyle = aStyleArg.IntegerValue();
+    anInterStyle = Aspect_IS_POINT;
   }
-  if (anInterStyle < Aspect_IS_EMPTY
-   || anInterStyle > Aspect_IS_HIDDENLINE)
+  else
   {
-    std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
-              << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
-    return 1;
+    const Standard_Integer anIntStyle = aStyleArg.IntegerValue();
+    if (anIntStyle < Aspect_IS_EMPTY
+     || anIntStyle > Aspect_IS_POINT)
+    {
+      std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
+                << Aspect_IS_POINT << " (Aspect_IS_POINT)]\n";
+      return 1;
+    }
+    anInterStyle = (Aspect_InteriorStyle )anIntStyle;
   }
 
   if (!aName.IsEmpty()
@@ -1490,7 +1603,12 @@ static int VSetInteriorStyle (Draw_Interpretor& theDI,
       const Handle(Prs3d_Drawer)& aDrawer        = anIO->Attributes();
       Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
       Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
-      aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
+      aFillAspect->SetInteriorStyle (anInterStyle);
+      if (anInterStyle == Aspect_IS_HATCH
+       && aFillAspect->HatchStyle().IsNull())
+      {
+        aFillAspect->SetHatchStyle (Aspect_HS_VERTICAL);
+      }
       aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
     }
   }
@@ -1500,45 +1618,60 @@ static int VSetInteriorStyle (Draw_Interpretor& theDI,
 //! Auxiliary structure for VAspects
 struct ViewerTest_AspectsChangeSet
 {
-  Standard_Integer         ToSetVisibility;
-  Standard_Integer         Visibility;
+  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         ToSetColor;
-  Quantity_Color           Color;
+  Standard_Integer             ToSetTypeOfMarker;
+  Aspect_TypeOfMarker          TypeOfMarker;
+  Handle(Image_PixMap)         MarkerImage;
 
-  Standard_Integer         ToSetLineWidth;
-  Standard_Real            LineWidth;
+  Standard_Integer             ToSetMarkerSize;
+  Standard_Real                MarkerSize;
 
-  Standard_Integer         ToSetTypeOfLine;
-  Aspect_TypeOfLine        TypeOfLine;
+  Standard_Integer             ToSetTransparency;
+  Standard_Real                Transparency;
 
-  Standard_Integer         ToSetTransparency;
-  Standard_Real            Transparency;
+  Standard_Integer             ToSetAlphaMode;
+  Graphic3d_AlphaMode          AlphaMode;
+  Standard_ShortReal           AlphaCutoff;
 
-  Standard_Integer         ToSetMaterial;
-  Graphic3d_NameOfMaterial Material;
-  TCollection_AsciiString  MatName;
+  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;
+  Standard_Integer             ToSetShowFreeBoundary;
+  Standard_Integer             ToSetFreeBoundaryWidth;
+  Standard_Real                FreeBoundaryWidth;
+  Standard_Integer             ToSetFreeBoundaryColor;
+  Quantity_Color               FreeBoundaryColor;
 
-  Standard_Integer         ToEnableIsoOnTriangulation;
+  Standard_Integer             ToEnableIsoOnTriangulation;
 
-  Standard_Integer         ToSetMaxParamValue;
-  Standard_Real            MaxParamValue;
+  Standard_Integer             ToSetMaxParamValue;
+  Standard_Real                MaxParamValue;
 
-  Standard_Integer         ToSetSensitivity;
-  Standard_Integer         SelectionMode;
-  Standard_Integer         Sensitivity;
+  Standard_Integer             ToSetSensitivity;
+  Standard_Integer             SelectionMode;
+  Standard_Integer             Sensitivity;
 
-  Standard_Integer         ToSetHatch;
-  Standard_Integer         StdHatchStyle;
-  TCollection_AsciiString  PathToHatchPattern;
+  Standard_Integer             ToSetHatch;
+  Standard_Integer             StdHatchStyle;
+  TCollection_AsciiString      PathToHatchPattern;
+
+  Standard_Integer             ToSetShadingModel;
+  Graphic3d_TypeOfShadingModel ShadingModel;
+  TCollection_AsciiString      ShadingModelName;
 
   //! Empty constructor
   ViewerTest_AspectsChangeSet()
@@ -1550,8 +1683,15 @@ struct ViewerTest_AspectsChangeSet
     LineWidth         (1.0),
     ToSetTypeOfLine   (0),
     TypeOfLine        (Aspect_TOL_SOLID),
+    ToSetTypeOfMarker (0),
+    TypeOfMarker      (Aspect_TOM_PLUS),
+    ToSetMarkerSize   (0),
+    MarkerSize        (1.0),
     ToSetTransparency (0),
     Transparency      (0.0),
+    ToSetAlphaMode    (0),
+    AlphaMode         (Graphic3d_AlphaMode_BlendAuto),
+    AlphaCutoff       (0.5f),
     ToSetMaterial     (0),
     Material          (Graphic3d_NOM_DEFAULT),
     ToSetShowFreeBoundary      (0),
@@ -1560,13 +1700,15 @@ struct ViewerTest_AspectsChangeSet
     ToSetFreeBoundaryColor     (0),
     FreeBoundaryColor          (DEFAULT_FREEBOUNDARY_COLOR),
     ToEnableIsoOnTriangulation (-1),
-    ToSetMaxParamValue (0),
-    MaxParamValue (500000),
-    ToSetSensitivity (0),
-    SelectionMode (-1),
-    Sensitivity (-1),
-    ToSetHatch (0),
-    StdHatchStyle (-1)
+    ToSetMaxParamValue         (0),
+    MaxParamValue              (500000),
+    ToSetSensitivity           (0),
+    SelectionMode              (-1),
+    Sensitivity                (-1),
+    ToSetHatch                 (0),
+    StdHatchStyle              (-1),
+    ToSetShadingModel          (0),
+    ShadingModel               (Graphic3d_TOSM_DEFAULT)
     {}
 
   //! @return true if no changes have been requested
@@ -1575,6 +1717,7 @@ struct ViewerTest_AspectsChangeSet
     return ToSetVisibility        == 0
         && ToSetLineWidth         == 0
         && ToSetTransparency      == 0
+        && ToSetAlphaMode         == 0
         && ToSetColor             == 0
         && ToSetMaterial          == 0
         && ToSetShowFreeBoundary  == 0
@@ -1582,7 +1725,8 @@ struct ViewerTest_AspectsChangeSet
         && ToSetFreeBoundaryWidth == 0
         && ToSetMaxParamValue     == 0
         && ToSetSensitivity       == 0
-        && ToSetHatch             == 0;
+        && ToSetHatch             == 0
+        && ToSetShadingModel      == 0;
   }
 
   //! @return true if properties are valid
@@ -1607,11 +1751,17 @@ struct ViewerTest_AspectsChangeSet
       isOk = Standard_False;
     }
     if (theIsSubPart
-     && ToSetTransparency)
+     && ToSetTransparency != 0)
     {
       std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
       isOk = Standard_False;
     }
+    if (ToSetAlphaMode == 1
+     && (AlphaCutoff <= 0.0f || AlphaCutoff >= 1.0f))
+    {
+      std::cout << "Error: alpha cutoff value should be within (0; 1) range (specified " << AlphaCutoff << ")\n";
+      isOk = Standard_False;
+    }
     if (ToSetMaterial == 1
      && Material == Graphic3d_NOM_DEFAULT)
     {
@@ -1639,6 +1789,12 @@ struct ViewerTest_AspectsChangeSet
       std::cout << "Error: hatch style must be specified\n";
       isOk = Standard_False;
     }
+    if (ToSetShadingModel == 1
+    && (ShadingModel < Graphic3d_TOSM_DEFAULT || ShadingModel > Graphic3d_TOSM_FRAGMENT))
+    {
+      std::cout << "Error: unknown shading model " << ShadingModelName << ".\n";
+      isOk = Standard_False;
+    }
     return isOk;
   }
 
@@ -1851,6 +2007,53 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
         aChangeSet->Transparency = 0.0;
       }
     }
+    else if (anArg == "-setalphamode")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+      aChangeSet->ToSetAlphaMode = 1;
+      aChangeSet->AlphaCutoff = 0.5f;
+      {
+        TCollection_AsciiString aParam (theArgVec[anArgIter]);
+        aParam.LowerCase();
+        if (aParam == "opaque")
+        {
+          aChangeSet->AlphaMode = Graphic3d_AlphaMode_Opaque;
+        }
+        else if (aParam == "mask")
+        {
+          aChangeSet->AlphaMode = Graphic3d_AlphaMode_Mask;
+        }
+        else if (aParam == "blend")
+        {
+          aChangeSet->AlphaMode = Graphic3d_AlphaMode_Blend;
+        }
+        else if (aParam == "blendauto"
+              || aParam == "auto")
+        {
+          aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
+        }
+        else
+        {
+          std::cout << "Error: wrong syntax at " << aParam << "\n";
+          return 1;
+        }
+      }
+
+      if (anArgIter + 1 < theArgNb
+       && theArgVec[anArgIter + 1][0] != '-')
+      {
+        TCollection_AsciiString aParam2 (theArgVec[anArgIter + 1]);
+        if (aParam2.IsRealValue())
+        {
+          aChangeSet->AlphaCutoff = (float )aParam2.RealValue();
+          ++anArgIter;
+        }
+      }
+    }
     else if (anArg == "-setvis"
           || anArg == "-setvisibility")
     {
@@ -1963,6 +2166,44 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
     {
       aChangeSet->ToSetTypeOfLine = -1;
     }
+    else if (anArg == "-setmarkertype"
+          || anArg == "-setpointtype")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+      if (!ViewerTest::ParseMarkerType (theArgVec[anArgIter], aChangeSet->TypeOfMarker, aChangeSet->MarkerImage))
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+
+      aChangeSet->ToSetTypeOfMarker = 1;
+    }
+    else if (anArg == "-unsetmarkertype"
+          || anArg == "-unsetpointtype")
+    {
+      aChangeSet->ToSetTypeOfMarker = -1;
+    }
+    else if (anArg == "-setmarkersize"
+          || anArg == "-setpointsize")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+      aChangeSet->ToSetMarkerSize = 1;
+      aChangeSet->MarkerSize = Draw::Atof (theArgVec[anArgIter]);
+    }
+    else if (anArg == "-unsetmarkersize"
+          || anArg == "-unsetpointsize")
+    {
+      aChangeSet->ToSetMarkerSize = -1;
+      aChangeSet->MarkerSize = 1.0;
+    }
     else if (anArg == "-unsetcolor")
     {
       aChangeSet->ToSetColor = -1;
@@ -2136,8 +2377,15 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
       aChangeSet->LineWidth = 1.0;
       aChangeSet->ToSetTypeOfLine = -1;
       aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
+      aChangeSet->ToSetTypeOfMarker = -1;
+      aChangeSet->TypeOfMarker = Aspect_TOM_PLUS;
+      aChangeSet->ToSetMarkerSize = -1;
+      aChangeSet->MarkerSize = 1.0;
       aChangeSet->ToSetTransparency = -1;
       aChangeSet->Transparency = 0.0;
+      aChangeSet->ToSetAlphaMode = -1;
+      aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto;
+      aChangeSet->AlphaCutoff = 0.5f;
       aChangeSet->ToSetColor = -1;
       aChangeSet->Color = DEFAULT_COLOR;
       aChangeSet->ToSetMaterial = -1;
@@ -2150,6 +2398,8 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
       aChangeSet->ToSetHatch = -1;
       aChangeSet->StdHatchStyle = -1;
       aChangeSet->PathToHatchPattern.Clear();
+      aChangeSet->ToSetShadingModel = -1;
+      aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
     }
     else if (anArg == "-isoontriangulation"
           || anArg == "-isoontriang")
@@ -2228,13 +2478,40 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
       TCollection_AsciiString anArgHatch (theArgVec[++anArgIter]);
       if (anArgHatch.Length() <= 2)
       {
-        aChangeSet->StdHatchStyle = Draw::Atoi (anArgHatch.ToCString());
+        const Standard_Integer anIntStyle = Draw::Atoi (anArgHatch.ToCString());
+        if (anIntStyle < 0
+         || anIntStyle >= Aspect_HS_NB)
+        {
+          std::cout << "Error: hatch style is out of range [0, " << (Aspect_HS_NB - 1) << "]!\n";
+          return 1;
+        }
+        aChangeSet->StdHatchStyle = anIntStyle;
       }
       else
       {
         aChangeSet->PathToHatchPattern = anArgHatch;
       }
     }
+    else if (anArg == "-setshadingmodel")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+      aChangeSet->ToSetShadingModel = 1;
+      aChangeSet->ShadingModelName  = theArgVec[anArgIter];
+      if (!ViewerTest::ParseShadingModel (theArgVec[anArgIter], aChangeSet->ShadingModel))
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+    }
+    else if (anArg == "-unsetshadingmodel")
+    {
+      aChangeSet->ToSetShadingModel = -1;
+      aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT;
+    }
     else
     {
       std::cout << "Error: wrong syntax at " << anArg << "\n";
@@ -2283,10 +2560,25 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
       aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
       aDrawer->SeenLineAspect()->SetTypeOfLine       (aChangeSet->TypeOfLine);
     }
+    if (aChangeSet->ToSetTypeOfMarker != 0)
+    {
+      aDrawer->PointAspect()->SetTypeOfMarker (aChangeSet->TypeOfMarker);
+      aDrawer->PointAspect()->Aspect()->SetMarkerImage (aChangeSet->MarkerImage.IsNull()
+                                                      ? Handle(Graphic3d_MarkerImage)()
+                                                      : new Graphic3d_MarkerImage (aChangeSet->MarkerImage));
+    }
+    if (aChangeSet->ToSetMarkerSize != 0)
+    {
+      aDrawer->PointAspect()->SetScale (aChangeSet->MarkerSize);
+    }
     if (aChangeSet->ToSetTransparency != 0)
     {
       aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
     }
+    if (aChangeSet->ToSetAlphaMode != 0)
+    {
+      aDrawer->ShadingAspect()->Aspect()->SetAlphaMode (aChangeSet->AlphaMode, aChangeSet->AlphaCutoff);
+    }
     if (aChangeSet->ToSetMaterial != 0)
     {
       aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
@@ -2315,6 +2607,10 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
     {
       aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
     }
+    if (aChangeSet->ToSetShadingModel == 1)
+    {
+      aDrawer->ShadingAspect()->Aspect()->SetShadingModel (aChangeSet->ShadingModel);
+    }
 
     // redisplay all objects in context
     for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
@@ -2451,6 +2747,25 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
           aDrawer->SeenLineAspect()->SetTypeOfLine       (aChangeSet->TypeOfLine);
           toRedisplay = Standard_True;
         }
+        if (aChangeSet->ToSetTypeOfMarker != 0)
+        {
+          Handle(Prs3d_PointAspect) aMarkerAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.0);
+          *aMarkerAspect->Aspect() = *aDrawer->PointAspect()->Aspect();
+          aMarkerAspect->SetTypeOfMarker (aChangeSet->TypeOfMarker);
+          aMarkerAspect->Aspect()->SetMarkerImage (aChangeSet->MarkerImage.IsNull()
+                                                 ? Handle(Graphic3d_MarkerImage)()
+                                                 : new Graphic3d_MarkerImage (aChangeSet->MarkerImage));
+          aDrawer->SetPointAspect (aMarkerAspect);
+          toRedisplay = Standard_True;
+        }
+        if (aChangeSet->ToSetMarkerSize != 0)
+        {
+          Handle(Prs3d_PointAspect) aMarkerAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.0);
+          *aMarkerAspect->Aspect() = *aDrawer->PointAspect()->Aspect();
+          aMarkerAspect->SetScale (aChangeSet->MarkerSize);
+          aDrawer->SetPointAspect (aMarkerAspect);
+          toRedisplay = Standard_True;
+        }
         if (aChangeSet->ToSetMaxParamValue != 0)
         {
           aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
@@ -2491,6 +2806,21 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
           }
           toRedisplay = Standard_True;
         }
+        if (aChangeSet->ToSetShadingModel != 0)
+        {
+          aDrawer->SetShadingModel ((aChangeSet->ToSetShadingModel == -1) ? Graphic3d_TOSM_DEFAULT : aChangeSet->ShadingModel, aChangeSet->ToSetShadingModel != -1);
+          toRedisplay = Standard_True;
+        }
+        if (aChangeSet->ToSetAlphaMode != 0)
+        {
+          if (!aDrawer->HasOwnShadingAspect())
+          {
+            aDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
+            *aDrawer->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
+          }
+          aDrawer->ShadingAspect()->Aspect()->SetAlphaMode (aChangeSet->AlphaMode, aChangeSet->AlphaCutoff);
+          toRedisplay = Standard_True;
+        }
       }
 
       for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
@@ -2527,6 +2857,11 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
           {
             aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
           }
+          if (aChangeSet->ToSetShadingModel != 0)
+          {
+            Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
+            aCurColDrawer->SetShadingModel ((aChangeSet->ToSetShadingModel == -1) ? Graphic3d_TOSM_DEFAULT : aChangeSet->ShadingModel, aChangeSet->ToSetShadingModel != -1);
+          }
         }
       }
       if (toDisplay)
@@ -2621,7 +2956,7 @@ static int VDonly2 (Draw_Interpretor& ,
     }
 
     const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
-    if (aShape.IsNull())
+    if (!aShape.IsNull())
     {
       aCtx->Erase (aShape, Standard_False);
     }
@@ -2926,7 +3261,6 @@ int VErase (Draw_Interpretor& theDI,
 
 //==============================================================================
 //function : VDisplayAll
-//author   : ege
 //purpose  : Display all the objects of the Map
 //==============================================================================
 static int VDisplayAll (Draw_Interpretor& ,
@@ -3190,200 +3524,320 @@ int VBounding (Draw_Interpretor& theDI,
 //function : VTexture
 //purpose  :
 //==============================================================================
-Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
+Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
 {
-  TCollection_AsciiString aCommandName (theArgv[0]);
+  const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
+  if (aCtx.IsNull())
+  {
+    std::cout << "Error: no active view!\n";
+    return 1;
+  }
+
+  int  toModulate     = -1;
+  bool toSetFilter    = false;
+  bool toSetAniso     = false;
+  bool toSetTrsfAngle = false;
+  bool toSetTrsfTrans = false;
+  bool toSetTrsfScale = false;
+  Standard_ShortReal aTrsfRotAngle = 0.0f;
+  Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f);
+  Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f);
+  Graphic3d_TypeOfTextureFilter      aFilter       = Graphic3d_TOTF_NEAREST;
+  Graphic3d_LevelOfTextureAnisotropy anAnisoFilter = Graphic3d_LOTA_OFF;
+
+  Handle(AIS_Shape) aTexturedIO;
+  Handle(Graphic3d_TextureSet) aTextureSetOld;
+  NCollection_Vector<Handle(Graphic3d_Texture2Dmanual)> aTextureVecNew;
+  bool toSetGenRepeat = false;
+  bool toSetGenScale  = false;
+  bool toSetGenOrigin = false;
+  bool toSetImage     = false;
+  bool toComputeUV    = false;
+
+  const TCollection_AsciiString aCommandName (theArgVec[0]);
+  bool toSetDefaults = aCommandName == "vtexdefault";
 
-  NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
-  if (aCommandName == "vtexture")
+  ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
+  for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
   {
-    if (theArgsNb < 2)
+    const TCollection_AsciiString aName     = theArgVec[anArgIter];
+    TCollection_AsciiString       aNameCase = aName;
+    aNameCase.LowerCase();
+    if (anUpdateTool.parseRedrawMode (aName))
     {
-      std::cout << theArgv[0] << ":  invalid arguments.\n";
-      std::cout << "Type help for more information.\n";
-      return 1;
+      continue;
     }
-
-    // look for options of vtexture command
-    TCollection_AsciiString aParseKey;
-    for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
+    else if (aTexturedIO.IsNull())
     {
-      TCollection_AsciiString anArg (theArgv [anArgIt]);
-
-      anArg.UpperCase();
-      if (anArg.Value (1) == '-' && !anArg.IsRealValue())
+      const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
+      if (aMapOfIO.IsBound2 (aName))
       {
-        aParseKey = anArg;
-        aParseKey.Remove (1);
-        aParseKey.UpperCase();
-        aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
-        continue;
+        aTexturedIO = Handle(AIS_Shape)::DownCast (aMapOfIO.Find2 (aName));
       }
-
-      if (aParseKey.IsEmpty())
+      if (aTexturedIO.IsNull())
       {
-        continue;
+        std::cout << "Syntax error: shape " << aName << " does not exists in the viewer.\n";
+        return 1;
       }
 
-      aMapOfArgs(aParseKey)->Append (anArg);
-    }
-  }
-  else if (aCommandName == "vtexscale"
-        || aCommandName == "vtexorigin"
-        || aCommandName == "vtexrepeat")
-  {
-    // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
-    // equal to -scale, -origin, -repeat options of vtexture command
-    if (theArgsNb < 2 || theArgsNb > 4)
-    {
-      std::cout << theArgv[0] << ":  invalid arguments.\n";
-      std::cout << "Type help for more information.\n";
-      return 1;
+      if (aTexturedIO->Attributes()->HasOwnShadingAspect())
+      {
+        aTextureSetOld = aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureSet();
+      }
     }
-
-    Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
-    if (theArgsNb == 2)
+    else if (aNameCase == "-scale"
+          || aNameCase == "-setscale"
+          || aCommandName == "vtexscale")
     {
-      anArgs->Append ("OFF");
-    }
-    else if (theArgsNb == 4)
+      if (aCommandName != "vtexscale")
+      {
+        ++anArgIter;
+      }
+      if (anArgIter < theArgsNb)
+      {
+        TCollection_AsciiString aValU (theArgVec[anArgIter]);
+        TCollection_AsciiString aValUCase = aValU;
+        aValUCase.LowerCase();
+        toSetGenScale = true;
+        if (aValUCase == "off")
+        {
+          aTexturedIO->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0));
+          continue;
+        }
+        else if (anArgIter + 1 < theArgsNb)
+        {
+          TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
+          if (aValU.IsRealValue()
+           && aValV.IsRealValue())
+          {
+            aTexturedIO->SetTextureScaleUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
+            ++anArgIter;
+            continue;
+          }
+        }
+      }
+      std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
+      return 1;
+    }
+    else if (aNameCase == "-origin"
+          || aNameCase == "-setorigin"
+          || aCommandName == "vtexorigin")
     {
-      anArgs->Append (TCollection_AsciiString (theArgv[2]));
-      anArgs->Append (TCollection_AsciiString (theArgv[3]));
+      if (aCommandName != "vtexorigin")
+      {
+        ++anArgIter;
+      }
+      if (anArgIter < theArgsNb)
+      {
+        TCollection_AsciiString aValU (theArgVec[anArgIter]);
+        TCollection_AsciiString aValUCase = aValU;
+        aValUCase.LowerCase();
+        toSetGenOrigin = true;
+        if (aValUCase == "off")
+        {
+          aTexturedIO->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
+          continue;
+        }
+        else if (anArgIter + 1 < theArgsNb)
+        {
+          TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
+          if (aValU.IsRealValue()
+           && aValV.IsRealValue())
+          {
+            aTexturedIO->SetTextureOriginUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
+            ++anArgIter;
+            continue;
+          }
+        }
+      }
+      std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
+      return 1;
     }
-
-    TCollection_AsciiString anArgKey;
-    if (aCommandName == "vtexscale")
+    else if (aNameCase == "-repeat"
+          || aNameCase == "-setrepeat"
+          || aCommandName == "vtexrepeat")
     {
-      anArgKey = "SCALE";
+      if (aCommandName != "vtexrepeat")
+      {
+        ++anArgIter;
+      }
+      if (anArgIter < theArgsNb)
+      {
+        TCollection_AsciiString aValU (theArgVec[anArgIter]);
+        TCollection_AsciiString aValUCase = aValU;
+        aValUCase.LowerCase();
+        toSetGenRepeat = true;
+        if (aValUCase == "off")
+        {
+          aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
+          continue;
+        }
+        else if (anArgIter + 1 < theArgsNb)
+        {
+          TCollection_AsciiString aValV (theArgVec[anArgIter + 1]);
+          if (aValU.IsRealValue()
+           && aValV.IsRealValue())
+          {
+            aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue()));
+            ++anArgIter;
+            continue;
+          }
+        }
+      }
+      std::cout << "Syntax error: unexpected argument '" << aName << "'\n";
+      return 1;
     }
-    else if (aCommandName == "vtexorigin")
+    else if (aNameCase == "-modulate")
     {
-      anArgKey = "ORIGIN";
+      bool toModulateBool = true;
+      if (anArgIter + 1 < theArgsNb
+       && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toModulateBool))
+      {
+        ++anArgIter;
+      }
+      toModulate = toModulateBool ? 1 : 0;
     }
-    else
+    else if ((aNameCase == "-setfilter"
+           || aNameCase == "-filter")
+           && anArgIter + 1 < theArgsNb)
     {
-      anArgKey = "REPEAT";
+      TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
+      aValue.LowerCase();
+      ++anArgIter;
+      toSetFilter = true;
+      if (aValue == "nearest")
+      {
+        aFilter = Graphic3d_TOTF_NEAREST;
+      }
+      else if (aValue == "bilinear")
+      {
+        aFilter = Graphic3d_TOTF_BILINEAR;
+      }
+      else if (aValue == "trilinear")
+      {
+        aFilter = Graphic3d_TOTF_TRILINEAR;
+      }
+      else
+      {
+        std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
+        return 1;
+      }
     }
-
-    aMapOfArgs.Bind (anArgKey, anArgs);
-  }
-  else if (aCommandName == "vtexdefault")
-  {
-    // scan for parameters of vtexdefault command
-    // equal to -default option of vtexture command
-    aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
-  }
-
-  // Check arguments for validity
-  NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
-  for (; aMapIt.More(); aMapIt.Next())
-  {
-    const TCollection_AsciiString& aKey = aMapIt.Key();
-    const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
-
-    // -scale, -origin, -repeat: one argument "off", or two real values
-    if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
-      && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
-       || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
+    else if ((aNameCase == "-setaniso"
+           || aNameCase == "-setanisofilter"
+           || aNameCase == "-aniso"
+           || aNameCase == "-anisofilter")
+           && anArgIter + 1 < theArgsNb)
     {
-      continue;
+      TCollection_AsciiString aValue (theArgVec[anArgIter + 1]);
+      aValue.LowerCase();
+      ++anArgIter;
+      toSetAniso = true;
+      if (aValue == "off")
+      {
+        anAnisoFilter = Graphic3d_LOTA_OFF;
+      }
+      else if (aValue == "fast")
+      {
+        anAnisoFilter = Graphic3d_LOTA_FAST;
+      }
+      else if (aValue == "middle")
+      {
+        anAnisoFilter = Graphic3d_LOTA_MIDDLE;
+      }
+      else if (aValue == "quality"
+            || aValue == "high")
+      {
+        anAnisoFilter =  Graphic3d_LOTA_QUALITY;
+      }
+      else
+      {
+        std::cout << "Syntax error: unexpected argument '" << aValue << "'\n";
+        return 1;
+      }
     }
-
-    // -modulate: single argument "on" / "off"
-    if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
+    else if ((aNameCase == "-rotateangle"
+           || aNameCase == "-rotangle"
+           || aNameCase == "-rotate"
+           || aNameCase == "-angle"
+           || aNameCase == "-trsfangle")
+           && anArgIter + 1 < theArgsNb)
     {
-      continue;
+      aTrsfRotAngle  = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
+      toSetTrsfAngle = true;
+      ++anArgIter;
     }
-
-    // -default: no arguments
-    if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
+    else if ((aNameCase == "-trsftrans"
+           || aNameCase == "-trsftranslate"
+           || aNameCase == "-translate"
+           || aNameCase == "-translation")
+           && anArgIter + 2 < theArgsNb)
     {
-      continue;
+      aTrsfTrans.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
+      aTrsfTrans.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
+      toSetTrsfTrans = true;
+      anArgIter += 2;
     }
-
-    TCollection_AsciiString aLowerKey;
-    aLowerKey  = "-";
-    aLowerKey += aKey;
-    aLowerKey.LowerCase();
-    std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
-    std::cout << "Type help for more information.\n";
-    return 1;
-  }
-
-  Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
-  if (anAISContext.IsNull())
-  {
-    std::cout << aCommandName << ":  please use 'vinit' command to initialize view.\n";
-    return 1;
-  }
-
-  Standard_Integer aPreviousMode = 0;
-
-  TCollection_AsciiString aShapeName (theArgv[1]);
-  Handle(AIS_InteractiveObject) anIO;
-
-  const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
-  if (aMapOfIO.IsBound2 (aShapeName))
-  {
-    anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
-  }
-
-  if (anIO.IsNull())
-  {
-    std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
-    return 1;
-  }
-
-  Handle(AIS_TexturedShape) aTexturedIO;
-  if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
-  {
-    aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
-    aPreviousMode = aTexturedIO->DisplayMode();
-  }
-  else
-  {
-    aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
-
-    if (anIO->HasTransformation())
+    else if ((aNameCase == "-trsfscale")
+           && anArgIter + 2 < theArgsNb)
     {
-      const gp_Trsf& aLocalTrsf = anIO->LocalTransformation();
-      aTexturedIO->SetLocalTransformation (aLocalTrsf);
+      aTrsfScale.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1]));
+      aTrsfScale.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2]));
+      toSetTrsfScale = true;
+      anArgIter += 2;
     }
-
-    anAISContext->Remove (anIO, Standard_False);
-    GetMapOfAIS().UnBind1 (anIO);
-    GetMapOfAIS().UnBind2 (aShapeName);
-    GetMapOfAIS().Bind (aTexturedIO, aShapeName);
-  }
-
-  // -------------------------------------------
-  //  Turn texturing on/off - only for vtexture
-  // -------------------------------------------
-
-  if (aCommandName == "vtexture")
-  {
-    TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
-
-    if (aTextureArg.IsEmpty())
+    else if (aNameCase == "-default"
+          || aNameCase == "-defaults")
     {
-      std::cout << aCommandName << ":  Texture mapping disabled.\n";
-      std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n\n";
+      toSetDefaults = true;
+    }
+    else if (aCommandName == "vtexture"
+          && (aTextureVecNew.IsEmpty()
+           || aNameCase.StartsWith ("-tex")))
+    {
+      Standard_Integer aTexIndex = 0;
+      TCollection_AsciiString aTexName = aName;
+      if (aNameCase.StartsWith ("-tex"))
+      {
+        if (anArgIter + 1 >= theArgsNb
+         || aNameCase.Length() < 5)
+        {
+          std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
+          return 1;
+        }
 
-      anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
-      if (aPreviousMode == 3)
+        TCollection_AsciiString aTexIndexStr = aNameCase.SubString (5, aNameCase.Length());
+        if (!aTexIndexStr.IsIntegerValue())
+        {
+          std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
+          return 1;
+        }
+
+        aTexIndex = aTexIndexStr.IntegerValue();
+        aTexName  = theArgVec[anArgIter + 1];
+        ++anArgIter;
+      }
+      if (aTexIndex >= Graphic3d_TextureUnit_NB
+       || aTexIndex >= aCtx->CurrentViewer()->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxCombinedTextureUnits))
       {
-        anAISContext->RecomputePrsOnly (aTexturedIO);
+        std::cout << "Error: too many textures specified\n";
+        return 1;
       }
 
-      anAISContext->Display (aTexturedIO, Standard_True);
-      return 0;
-    }
-    else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
-    {
-      if (aTextureArg == "?")
+      toSetImage = true;
+      if (aTexName.IsIntegerValue())
+      {
+        const Standard_Integer aValue = aTexName.IntegerValue();
+        if (aValue < 0 || aValue >= Graphic3d_Texture2D::NumberOfTextures())
+        {
+          std::cout << "Syntax error: texture with ID " << aValue << " is undefined!\n";
+          return 1;
+        }
+        aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (Graphic3d_NameOfTexture2D (aValue)));
+      }
+      else if (aTexName == "?")
       {
-        TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
+        const TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
 
         theDi << "\n Files in current directory : \n\n";
         theDi.Eval ("glob -nocomplain *");
@@ -3392,91 +3846,206 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
         aCmnd += aTextureFolder;
         aCmnd += "/* ";
 
-        theDi << "Files in " << aTextureFolder.ToCString() << " : \n\n";
+        theDi << "Files in " << aTextureFolder << " : \n\n";
         theDi.Eval (aCmnd.ToCString());
         return 0;
       }
+      else if (aTexName != "off")
+      {
+        if (!OSD_File (aTexName).Exists())
+        {
+          std::cout << "Syntax error: non-existing image file has been specified '" << aTexName << "'.\n";
+          return 1;
+        }
+        aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (aTexName));
+      }
       else
       {
-        aTexturedIO->SetTextureFileName (aTextureArg);
+        aTextureVecNew.SetValue (aTexIndex, Handle(Graphic3d_Texture2Dmanual)());
+      }
+
+      if (aTextureVecNew.Value (aTexIndex))
+      {
+        aTextureVecNew.ChangeValue(aTexIndex)->GetParams()->SetTextureUnit((Graphic3d_TextureUnit)aTexIndex);
       }
     }
+    else
+    {
+      std::cout << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'\n";
+      return 1;
+    }
   }
 
-  // ------------------------------------
-  //  Process other options and commands
-  // ------------------------------------
-
-  Handle(TColStd_HSequenceOfAsciiString) aValues;
-  if (aMapOfArgs.Find ("DEFAULT", aValues))
-  {
-    aTexturedIO->SetTextureRepeat (Standard_False);
-    aTexturedIO->SetTextureOrigin (Standard_False);
-    aTexturedIO->SetTextureScale  (Standard_False);
-    aTexturedIO->EnableTextureModulate();
-  }
-  else
+  if (toSetImage)
   {
-    if (aMapOfArgs.Find ("SCALE", aValues))
+    // check if new image set is equal to already set one
+    Standard_Integer aNbChanged = 0;
+    Handle(Graphic3d_TextureSet) aTextureSetNew;
+    if (!aTextureVecNew.IsEmpty())
     {
-      if (aValues->Value(1) != "OFF")
-      {
-        aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
-      }
-      else
+      aNbChanged = aTextureVecNew.Size();
+      aTextureSetNew = new Graphic3d_TextureSet (aTextureVecNew.Size());
+      for (Standard_Integer aTexIter = 0; aTexIter < aTextureSetNew->Size(); ++aTexIter)
       {
-        aTexturedIO->SetTextureScale (Standard_False);
+        Handle(Graphic3d_Texture2Dmanual)& aTextureNew = aTextureVecNew.ChangeValue (aTexIter);
+        Handle(Graphic3d_TextureRoot) aTextureOld;
+        if (!aTextureSetOld.IsNull()
+          && aTexIter < aTextureSetOld->Size())
+        {
+          aTextureOld = aTextureSetOld->Value (aTexIter);
+        }
+
+        if (!aTextureOld.IsNull()
+         && !aTextureNew.IsNull())
+        {
+          *aTextureNew->GetParams() = *aTextureOld->GetParams();
+          if (Handle(Graphic3d_Texture2Dmanual) anOldManualTex = Handle(Graphic3d_Texture2Dmanual)::DownCast (aTextureOld))
+          {
+            TCollection_AsciiString aFilePathOld, aFilePathNew;
+            aTextureOld->Path().SystemName (aFilePathOld);
+            aTextureNew->Path().SystemName (aFilePathNew);
+            if (aTextureNew->Name() == anOldManualTex->Name()
+             && aFilePathOld == aFilePathNew
+             && (!aFilePathNew.IsEmpty() || aTextureNew->Name() != Graphic3d_NOT_2D_UNKNOWN))
+            {
+              --aNbChanged;
+              aTextureNew = anOldManualTex;
+            }
+          }
+        }
+        aTextureSetNew->SetValue (aTexIter, aTextureNew);
       }
     }
+    if (aNbChanged == 0
+     && ((aTextureSetOld.IsNull() && aTextureSetNew.IsNull())
+      || (aTextureSetOld->Size() == aTextureSetNew->Size())))
+    {
+      aTextureSetNew = aTextureSetOld;
+    }
 
-    if (aMapOfArgs.Find ("ORIGIN", aValues))
+    if (!aTexturedIO->Attributes()->HasOwnShadingAspect())
     {
-      if (aValues->Value(1) != "OFF")
-      {
-        aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
-      }
-      else
-      {
-        aTexturedIO->SetTextureOrigin (Standard_False);
-      }
+      aTexturedIO->Attributes()->SetShadingAspect (new Prs3d_ShadingAspect());
+      *aTexturedIO->Attributes()->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
     }
 
-    if (aMapOfArgs.Find ("REPEAT", aValues))
+    toComputeUV = !aTextureSetNew.IsNull() && aTextureSetOld.IsNull();
+    aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (!aTextureSetNew.IsNull());
+    aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aTextureSetNew);
+    aTextureSetOld.Nullify();
+  }
+
+  if (toSetDefaults)
+  {
+    if (toModulate != -1)
     {
-      if (aValues->Value(1) != "OFF")
-      {
-        aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
-      }
-      else
-      {
-        aTexturedIO->SetTextureRepeat (Standard_False);
-      }
+      toModulate = 1;
+    }
+    if (!toSetFilter)
+    {
+      toSetFilter = true;
+      aFilter     = Graphic3d_TOTF_BILINEAR;
+    }
+    if (!toSetAniso)
+    {
+      toSetAniso    = true;
+      anAnisoFilter = Graphic3d_LOTA_OFF;
+    }
+    if (!toSetTrsfAngle)
+    {
+      toSetTrsfAngle = true;
+      aTrsfRotAngle  = 0.0f;
+    }
+    if (!toSetTrsfTrans)
+    {
+      toSetTrsfTrans = true;
+      aTrsfTrans = Graphic3d_Vec2 (0.0f, 0.0f);
     }
+    if (!toSetTrsfScale)
+    {
+      toSetTrsfScale = true;
+      aTrsfScale = Graphic3d_Vec2 (1.0f, 1.0f);
+    }
+  }
 
-    if (aMapOfArgs.Find ("MODULATE", aValues))
+  if (aCommandName == "vtexture"
+   && theArgsNb == 2)
+  {
+    if (!aTextureSetOld.IsNull())
     {
-      if (aValues->Value(1) == "ON")
-      {
-        aTexturedIO->EnableTextureModulate();
-      }
-      else
-      {
-        aTexturedIO->DisableTextureModulate();
-      }
+      //toComputeUV = true; // we can keep UV vertex attributes
+      aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
+      aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (Handle(Graphic3d_TextureSet)());
+      aTextureSetOld.Nullify();
     }
   }
 
-  if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
+  if (aTexturedIO->Attributes()->HasOwnShadingAspect()
+  && !aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap().IsNull())
   {
-    anAISContext->RecomputePrsOnly (aTexturedIO);
+    if (toModulate != -1)
+    {
+      aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetModulate (toModulate == 1);
+    }
+    if (toSetTrsfAngle)
+    {
+      aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetRotation (aTrsfRotAngle); // takes degrees
+    }
+    if (toSetTrsfTrans)
+    {
+      aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetTranslation (aTrsfTrans);
+    }
+    if (toSetTrsfScale)
+    {
+      aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetScale (aTrsfScale);
+    }
+    if (toSetFilter)
+    {
+      aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetFilter (aFilter);
+    }
+    if (toSetAniso)
+    {
+      aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetAnisoFilter (anAnisoFilter);
+    }
   }
-  else
+
+  // set default values if requested
+  if (!toSetGenRepeat
+   && (aCommandName == "vtexrepeat"
+    || toSetDefaults))
+  {
+    aTexturedIO->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0));
+    toSetGenRepeat = true;
+  }
+  if (!toSetGenOrigin
+   && (aCommandName == "vtexorigin"
+    || toSetDefaults))
+  {
+    aTexturedIO->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0));
+    toSetGenOrigin = true;
+  }
+  if (!toSetGenScale
+   && (aCommandName == "vtexscale"
+    || toSetDefaults))
   {
-    anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
-    anAISContext->Display (aTexturedIO, Standard_True);
-    anAISContext->Update (aTexturedIO,Standard_True);
+    aTexturedIO->SetTextureScaleUV  (gp_Pnt2d (1.0, 1.0));
+    toSetGenScale = true;
   }
 
+  if (toSetGenRepeat || toSetGenOrigin || toSetGenScale || toComputeUV)
+  {
+    aTexturedIO->SetToUpdate (AIS_Shaded);
+    if (toSetImage)
+    {
+      if ((aTexturedIO->HasDisplayMode() && aTexturedIO->DisplayMode() != AIS_Shaded)
+       || aCtx->DisplayMode() != AIS_Shaded)
+      {
+        aCtx->SetDisplayMode (aTexturedIO, AIS_Shaded, false);
+      }
+    }
+  }
+  aCtx->Display (aTexturedIO, false);
+  aTexturedIO->SynchronizeAspects();
   return 0;
 }
 
@@ -3811,6 +4380,11 @@ static int VDisplay2 (Draw_Interpretor& theDI,
     {
       toReDisplay = Standard_True;
     }
+    else if (aNameCase == "-erased"
+          || aNameCase == "-load")
+    {
+      aDispStatus = AIS_DS_Erased;
+    }
     else
     {
       aNamesOfDisplayIO.Append (aName);
@@ -3957,7 +4531,7 @@ static int VDisplay2 (Draw_Interpretor& theDI,
 
       if (aSelMode == -1)
       {
-        aCtx->Erase (aShape);
+        aCtx->Erase (aShape, Standard_False);
       }
       aCtx->Display (aShape, aDispMode, aSelMode,
                      Standard_False, aShape->AcceptShapeDecomposition(),
@@ -3972,6 +4546,41 @@ static int VDisplay2 (Draw_Interpretor& theDI,
   return 0;
 }
 
+//=======================================================================
+//function : VNbDisplayed
+//purpose  : Returns number of displayed objects
+//=======================================================================
+static Standard_Integer VNbDisplayed (Draw_Interpretor& theDi,
+                                      Standard_Integer theArgsNb,
+                                      const char** theArgVec)
+{
+  if(theArgsNb != 1)
+  {
+    theDi << "Usage : " << theArgVec[0] << "\n";
+    return 1;
+  }
+
+  Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
+  if (aContextAIS.IsNull())
+  {
+    std::cout << theArgVec[0] << "AIS context is not available.\n";
+    return 1;
+  }
+
+  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
+  if(aContext.IsNull())
+  {
+    theDi << "use 'vinit' command before " << theArgVec[0] << "\n";
+    return 1;
+  }
+
+  AIS_ListOfInteractive aListOfIO;
+  aContextAIS->DisplayedObjects(aListOfIO, false);
+
+  theDi << aListOfIO.Extent() << "\n";
+  return 0;
+}
+
 //===============================================================================================
 //function : VUpdate
 //purpose  :
@@ -4025,75 +4634,6 @@ static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, con
   return 0;
 }
 
-//==============================================================================
-//function : VPerf
-//purpose  : Test the annimation of an object along a
-//           predifined trajectory
-//Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
-//==============================================================================
-
-static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
-
-  OSD_Timer myTimer;
-  Standard_Real Step=4*M_PI/180;
-  Standard_Real Angle=0;
-
-  Handle(AIS_InteractiveObject) aIO;
-  if (GetMapOfAIS().IsBound2(argv[1]))
-    aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
-  if (aIO.IsNull())
-    return 1;
-
-  Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
-
-  myTimer.Start();
-
-  if (Draw::Atoi(argv[3])==1 ) {
-    di<<" Primitives sensibles OFF\n";
-    TheAISContext()->Deactivate(aIO);
-  }
-  else {
-    di<<" Primitives sensibles ON\n";
-  }
-  // Movement par transformation
-  if(Draw::Atoi(argv[2]) ==1) {
-    di<<" Calcul par Transformation\n";
-    for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
-
-      Angle=Step*myAngle;
-      gp_Trsf myTransfo;
-      myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
-      TheAISContext()->SetLocation(aShape,myTransfo);
-      TheAISContext() ->UpdateCurrentViewer();
-
-    }
-  }
-  else {
-    di<<" Calcul par Locations\n";
-    gp_Trsf myAngleTrsf;
-    myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step  );
-    TopLoc_Location myDeltaAngle (myAngleTrsf);
-    TopLoc_Location myTrueLoc;
-
-    for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
-
-      Angle=Step*myAngle;
-      myTrueLoc=myTrueLoc*myDeltaAngle;
-      TheAISContext()->SetLocation(aShape,myTrueLoc );
-      TheAISContext() ->UpdateCurrentViewer();
-    }
-  }
-  if (Draw::Atoi(argv[3])==1 ){
-    // On reactive la selection des primitives sensibles
-    TheAISContext()->Activate(aIO,0);
-  }
-  a3DView() -> Redraw();
-  myTimer.Stop();
-  di<<" Temps ecoule \n";
-  myTimer.Show();
-  return 0;
-}
-
 //==============================================================================
 //function : VShading
 //purpose  : Sharpen or roughten the quality of the shading
@@ -4123,235 +4663,7 @@ static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
   else
     TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
 
-  TheAISContext()->Redisplay(TheAisIO);
-  return 0;
-}
-//==============================================================================
-//function : HaveMode
-//use      : VActivatedModes
-//==============================================================================
-#include <TColStd_ListIteratorOfListOfInteger.hxx>
-
-Standard_Boolean  HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode  )
-{
-  TColStd_ListOfInteger List;
-  TheAISContext()->ActivatedModes (TheAisIO,List);
-  TColStd_ListIteratorOfListOfInteger it;
-  Standard_Boolean Found=Standard_False;
-  for (it.Initialize(List); it.More()&&!Found; it.Next() ){
-    if (it.Value()==mode ) Found=Standard_True;
-  }
-  return Found;
-}
-
-
-
-//==============================================================================
-//function : VActivatedMode
-//author   : ege
-//purpose  : permet d'attribuer a chacune des shapes un mode d'activation
-//           (edges,vertex...)qui lui est propre et le mode de selection standard.
-//           La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
-//             Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
-//           qu'un nom et qu'un mode.
-//Draw arg : vsetam  [ShapeName] mode(0,1,2,3,4,5,6,7)
-//==============================================================================
-#include <AIS_ListIteratorOfListOfInteractive.hxx>
-
-static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
-
-{
-  Standard_Boolean ThereIsName = Standard_False ;
-
-  if(!a3DView().IsNull()){
-
-    const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
-    // verification des arguments
-    if (HaveToSet) {
-      if (argc<2||argc>3) { di<<" Syntaxe error\n";return 1;}
-      ThereIsName = (argc == 3);
-    }
-    else
-    {
-      Standard_DISABLE_DEPRECATION_WARNINGS
-      // vunsetam
-      if (argc>1) {di<<" Syntaxe error\n";return 1;}
-      else {
-        di<<" R.A.Z de tous les modes de selecion\n";
-        di<<" Fermeture du Context local\n";
-        if (TheAISContext()->HasOpenedContext())
-        {
-          TheAISContext()->CloseLocalContext();
-        }
-      }
-      Standard_ENABLE_DEPRECATION_WARNINGS
-    }
-
-    // IL n'y a aps de nom de shape passe en argument
-    if (HaveToSet && !ThereIsName){
-      Standard_Integer aMode=Draw::Atoi(argv [1]);
-
-      const char *cmode="???";
-      switch (aMode) {
-      case 0: cmode = "Shape"; break;
-      case 1: cmode = "Vertex"; break;
-      case 2: cmode = "Edge"; break;
-      case 3: cmode = "Wire"; break;
-      case 4: cmode = "Face"; break;
-      case 5: cmode = "Shell"; break;
-      case 6: cmode = "Solid"; break;
-      case 7: cmode = "Compound"; break;
-      }
-
-      if( !TheAISContext()->HasOpenedContext() ) {
-        // il n'y a pas de Context local d'ouvert
-        // on en ouvre un et on charge toutes les shapes displayees
-        // on load tous les objets displayees et on Activate les objets de la liste
-        AIS_ListOfInteractive ListOfIO;
-        // on sauve dans une AISListOfInteractive tous les objets currents
-        if (TheAISContext()->NbSelected()>0 ){
-          TheAISContext()->UnhilightSelected(Standard_False);
-
-          for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
-            ListOfIO.Append(TheAISContext()->SelectedInteractive() );
-         }
-       }
-
-  Standard_DISABLE_DEPRECATION_WARNINGS
-       TheAISContext()->OpenLocalContext(Standard_False);
-  Standard_ENABLE_DEPRECATION_WARNINGS
-       ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
-          it (GetMapOfAIS());
-       while(it.More()){
-         Handle(AIS_InteractiveObject) aIO =
-            Handle(AIS_InteractiveObject)::DownCast(it.Key1());
-          if (!aIO.IsNull())
-            TheAISContext()->Load(aIO,0,Standard_False);
-         it.Next();
-       }
-       // traitement des objets qui etaient currents dans le Contexte global
-       if (!ListOfIO.IsEmpty() ) {
-         // il y avait des objets currents
-         AIS_ListIteratorOfListOfInteractive iter;
-         for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
-           Handle(AIS_InteractiveObject) aIO=iter.Value();
-           TheAISContext()->Activate(aIO,aMode);
-           di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString()  <<"\n";
-         }
-       }
-       else {
-         // On applique le mode a tous les objets displayes
-         ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
-            it2 (GetMapOfAIS());
-         while(it2.More()){
-            Handle(AIS_InteractiveObject) aIO =
-              Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
-            if (!aIO.IsNull()) {
-              di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
-              TheAISContext()->Activate(aIO,aMode);
-            }
-           it2.Next();
-         }
-       }
-
-      }
-
-      else {
-       // un Context local est deja ouvert
-       // Traitement des objets du Context local
-       if (TheAISContext()->NbSelected()>0 ){
-         TheAISContext()->UnhilightSelected(Standard_False);
-         // il y a des objets selected,on les parcourt
-         for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
-           Handle(AIS_InteractiveObject) aIO=TheAISContext()->SelectedInteractive();
-
-
-           if (HaveMode(aIO,aMode) ) {
-             di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
-             TheAISContext()->Deactivate(aIO,aMode);
-           }
-           else{
-             di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
-             TheAISContext()->Activate(aIO,aMode);
-           }
-
-         }
-       }
-       else{
-         // il n'y a pas d'objets selected
-         // tous les objets diplayes sont traites
-         ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
-            it (GetMapOfAIS());
-         while(it.More()){
-           Handle(AIS_InteractiveObject) aIO =
-              Handle(AIS_InteractiveObject)::DownCast(it.Key1());
-            if (!aIO.IsNull()) {
-              if (HaveMode(aIO,aMode) ) {
-                di<<" Mode: "<<cmode<<" OFF pour "
-                  <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
-                TheAISContext()->Deactivate(aIO,aMode);
-              }
-              else{
-                di<<" Mode: "<<cmode<<" ON pour"
-                  <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
-                TheAISContext()->Activate(aIO,aMode);
-              }
-            }
-           it.Next();
-          }
-       }
-      }
-    }
-    else if (HaveToSet && ThereIsName){
-      Standard_Integer aMode=Draw::Atoi(argv [2]);
-      Handle(AIS_InteractiveObject) aIO =
-        Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
-
-      if (!aIO.IsNull()) {
-        const char *cmode="???";
-
-        switch (aMode) {
-        case 0: cmode = "Shape"; break;
-        case 1: cmode = "Vertex"; break;
-        case 2: cmode = "Edge"; break;
-        case 3: cmode = "Wire"; break;
-        case 4: cmode = "Face"; break;
-        case 5: cmode = "Shell"; break;
-        case 6: cmode = "Solid"; break;
-        case 7: cmode = "Compound"; break;
-        }
-
-        if( !TheAISContext()->HasOpenedContext() ) {
-          Standard_DISABLE_DEPRECATION_WARNINGS
-          TheAISContext()->OpenLocalContext(Standard_False);
-          Standard_ENABLE_DEPRECATION_WARNINGS
-          // On charge tous les objets de la map
-          ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
-          while(it.More()){
-            Handle(AIS_InteractiveObject) aShape=
-              Handle(AIS_InteractiveObject)::DownCast(it.Key1());
-            if (!aShape.IsNull())
-              TheAISContext()->Load(aShape,0,Standard_False);
-            it.Next();
-          }
-          TheAISContext()->Activate(aIO,aMode);
-          di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
-        }
-
-        else {
-          // un Context local est deja ouvert
-          if (HaveMode(aIO,aMode) ) {
-            di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
-            TheAISContext()->Deactivate(aIO,aMode);
-          }
-          else{
-            di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
-            TheAISContext()->Activate(aIO,aMode);
-          }
-        }
-      }
-    }
-  }
+  TheAISContext()->Redisplay (TheAisIO, Standard_True);
   return 0;
 }
 
@@ -4634,139 +4946,25 @@ static Standard_Integer VState (Draw_Interpretor& theDI,
   theDI << "Neutral-point state:\n";
   for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
        anObjIter.More(); anObjIter.Next())
-  {
-    Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
-    if (anObj.IsNull())
-    {
-      continue;
-    }
-
-    TCollection_AsciiString aName = anObjIter.Key2();
-    aName.LeftJustify (20, ' ');
-    theDI << "  " << aName << " ";
-    objInfo (aDetected, anObj, theDI);
-    theDI << "\n";
-  }
-  printLocalSelectionInfo (aCtx, theDI);
-  Standard_DISABLE_DEPRECATION_WARNINGS
-  if (aCtx->HasOpenedContext())
-    printLocalSelectionInfo (aCtx->LocalContext(), theDI);
-  Standard_ENABLE_DEPRECATION_WARNINGS
-  return 0;
-}
-
-//=======================================================================
-//function : PickObjects
-//purpose  :
-//=======================================================================
-Standard_Boolean  ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
-                                         const AIS_KindOfInteractive TheType,
-                                         const Standard_Integer TheSignature,
-                                         const Standard_Integer MaxPick)
-{
-  Handle(AIS_InteractiveObject) IO;
-  Standard_DISABLE_DEPRECATION_WARNINGS
-  Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
-  Standard_ENABLE_DEPRECATION_WARNINGS
-
-  // step 1: prepare the data
-  if(curindex !=0){
-    Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
-    TheAISContext()->AddFilter(F1);
-  }
-
-  // step 2 : wait for the selection...
-  Standard_Integer NbPickGood (0),NbToReach(arr->Length());
-  Standard_Integer NbPickFail(0);
-  Standard_Integer argccc = 5;
-  const char *bufff[] = { "A", "B", "C","D", "E" };
-  const char **argvvv = (const char **) bufff;
-
-
-  while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
-    while(ViewerMainLoop(argccc,argvvv)){}
-    Standard_Integer NbStored = TheAISContext()->NbSelected();
-    if(NbStored != NbPickGood)
-      NbPickGood= NbStored;
-    else
-      NbPickFail++;
-    cout<<"NbPicked =  "<<NbPickGood<<" |  Nb Pick Fail :"<<NbPickFail<<endl;
-  }
-
-  // step3 get result.
-
-  if (NbPickFail >= NbToReach)
-    return Standard_False;
-
-  Standard_Integer i(0);
-  for(TheAISContext()->InitSelected();
-      TheAISContext()->MoreSelected();
-      TheAISContext()->NextSelected()){
-    i++;
-    Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
-    arr->SetValue(i,IO2);
-  }
-
-  Standard_DISABLE_DEPRECATION_WARNINGS
-  if (curindex > 0)
-  {
-    TheAISContext()->CloseLocalContext(curindex);
-  }
-  Standard_ENABLE_DEPRECATION_WARNINGS
-
-  return Standard_True;
-}
-
-
-//=======================================================================
-//function : PickObject
-//purpose  :
-//=======================================================================
-Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
-                                                    const Standard_Integer TheSignature,
-                                                    const Standard_Integer MaxPick)
-{
-  Handle(AIS_InteractiveObject) IO;
-  Standard_DISABLE_DEPRECATION_WARNINGS
-  Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
-  Standard_ENABLE_DEPRECATION_WARNINGS
-
-  // step 1: prepare the data
-
-  if(curindex !=0){
-    Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
-    TheAISContext()->AddFilter(F1);
-  }
-
-  // step 2 : wait for the selection...
-  Standard_Boolean IsGood (Standard_False);
-  Standard_Integer NbPick(0);
-  Standard_Integer argccc = 5;
-  const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-  const char **argvvv = (const char **) bufff;
-
-
-  while(!IsGood && NbPick<= MaxPick){
-    while(ViewerMainLoop(argccc,argvvv)){}
-    IsGood = (TheAISContext()->NbSelected()>0) ;
-    NbPick++;
-    cout<<"Nb Pick :"<<NbPick<<endl;
-  }
-
+  {
+    Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
+    if (anObj.IsNull())
+    {
+      continue;
+    }
 
-  // step3 get result.
-  if(IsGood){
-    TheAISContext()->InitSelected();
-    IO = TheAISContext()->SelectedInteractive();
+    TCollection_AsciiString aName = anObjIter.Key2();
+    aName.LeftJustify (20, ' ');
+    theDI << "  " << aName << " ";
+    objInfo (aDetected, anObj, theDI);
+    theDI << "\n";
   }
-
+  printLocalSelectionInfo (aCtx, theDI);
   Standard_DISABLE_DEPRECATION_WARNINGS
-  if (curindex != 0)
-  {
-    TheAISContext()->CloseLocalContext(curindex);
-  }
+  if (aCtx->HasOpenedContext())
+    printLocalSelectionInfo (aCtx->LocalContext(), theDI);
   Standard_ENABLE_DEPRECATION_WARNINGS
-  return IO;
+  return 0;
 }
 
 //=======================================================================
@@ -4775,224 +4973,245 @@ Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive
 //           pick objets that are of type <TheType>...
 //=======================================================================
 
-TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
-                                  const Standard_Integer MaxPick)
+TopoDS_Shape ViewerTest::PickShape (const TopAbs_ShapeEnum theShapeType,
+                                    const Standard_Integer theMaxPick)
 {
-
-  // step 1: prepare the data
-  Standard_DISABLE_DEPRECATION_WARNINGS
-  Standard_Integer curindex = TheAISContext()->OpenLocalContext();
-  Standard_ENABLE_DEPRECATION_WARNINGS
-  TopoDS_Shape result;
-
-  if(TheType==TopAbs_SHAPE){
-    Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
-    TheAISContext()->AddFilter(F1);
-  }
-  else{
-    Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
-    TheAISContext()->AddFilter(TF);
-    Standard_DISABLE_DEPRECATION_WARNINGS
-    TheAISContext()->ActivateStandardMode(TheType);
-    Standard_ENABLE_DEPRECATION_WARNINGS
-  }
-
-
-  // step 2 : wait for the selection...
-  Standard_Boolean NoShape (Standard_True);
-  Standard_Integer NbPick(0);
-  Standard_Integer argccc = 5;
-  const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-  const char **argvvv = (const char **) bufff;
-
-
-  while(NoShape && NbPick<= MaxPick){
-    while(ViewerMainLoop(argccc,argvvv)){}
-    NoShape = (TheAISContext()->NbSelected()==0) ;
-    NbPick++;
-    cout<<"Nb Pick :"<<NbPick<<endl;
-  }
-
-  // step3 get result.
-
-  if(!NoShape){
-
-    TheAISContext()->InitSelected();
-    if(TheAISContext()->HasSelectedShape())
-      result = TheAISContext()->SelectedShape();
-    else{
-      Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
-      result = Handle(AIS_Shape)::DownCast (IO)->Shape();
-    }
-  }
-
-  Standard_DISABLE_DEPRECATION_WARNINGS
-  if (curindex > 0)
-  {
-    TheAISContext()->CloseLocalContext(curindex);
-  }
-  Standard_ENABLE_DEPRECATION_WARNINGS
-
-  return result;
+  Handle(TopTools_HArray1OfShape) aResArray = new TopTools_HArray1OfShape (1, 1);
+  PickShapes (theShapeType, aResArray, theMaxPick);
+  return aResArray->First();
 }
 
-
 //=======================================================================
 //function : PickShapes
 //purpose  :
 //=======================================================================
-Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
-                                        Handle(TopTools_HArray1OfShape)& thearr,
-                                        const Standard_Integer MaxPick)
+Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum theShapeType,
+                                         Handle(TopTools_HArray1OfShape)& theResArray,
+                                         const Standard_Integer theMaxPick)
 {
-
-  Standard_Integer Taille = thearr->Length();
-  if(Taille>1)
-    cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
+  const Standard_Integer aNbToReach = theResArray->Length();
+  if (aNbToReach > 1)
+  {
+    std::cout << " WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
+  }
 
   // step 1: prepare the data
-  Standard_DISABLE_DEPRECATION_WARNINGS
-  Standard_Integer curindex = TheAISContext()->OpenLocalContext();
-  Standard_ENABLE_DEPRECATION_WARNINGS
-  if(TheType==TopAbs_SHAPE){
-    Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
-    TheAISContext()->AddFilter(F1);
+  Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
+  aCtx->RemoveFilters();
+  AIS_ListOfInteractive aDispObjects;
+  aCtx->DisplayedObjects (aDispObjects);
+  if (theShapeType == TopAbs_SHAPE)
+  {
+    aCtx->AddFilter (new AIS_TypeFilter (AIS_KOI_Shape));
   }
-  else{
-    Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
-    TheAISContext()->AddFilter(TF);
-    Standard_DISABLE_DEPRECATION_WARNINGS
-    TheAISContext()->ActivateStandardMode(TheType);
-    Standard_ENABLE_DEPRECATION_WARNINGS
+  else
+  {
+    aCtx->AddFilter (new StdSelect_ShapeTypeFilter (theShapeType));
+  }
+
+  const Standard_Integer aSelMode = AIS_Shape::SelectionMode (theShapeType);
+  for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
+  {
+    if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
+    {
+      aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
+    }
   }
 
   // step 2 : wait for the selection...
-  Standard_Integer NbPickGood (0),NbToReach(thearr->Length());
-  Standard_Integer NbPickFail(0);
+  Standard_Integer aNbPickGood = 0, aNbPickFail = 0;
   Standard_Integer argccc = 5;
-  const char *bufff[] = { "A", "B", "C","D", "E" };
-  const char **argvvv = (const char **) bufff;
-
-
-  while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
-    while(ViewerMainLoop(argccc,argvvv)){}
-    Standard_Integer NbStored = TheAISContext()->NbSelected();
-    if (NbStored != NbPickGood)
-      NbPickGood= NbStored;
+  const char *bufff[] = { "A", "B", "C", "D", "E" };
+  const char **argvvv = (const char** )bufff;
+  for (; aNbPickGood < aNbToReach && aNbPickFail <= theMaxPick; )
+  {
+    while (ViewerMainLoop (argccc, argvvv)) {}
+    Standard_Integer aNbStored = aCtx->NbSelected();
+    if (aNbStored != aNbPickGood)
+    {
+      aNbPickGood = aNbStored;
+    }
     else
-      NbPickFail++;
-    cout<<"NbPicked =  "<<NbPickGood<<" |  Nb Pick Fail :"<<NbPickFail<<"\n";
+    {
+      ++aNbPickFail;
+    }
+    std::cout << "NbPicked =  " << aNbPickGood << " |  Nb Pick Fail :" << aNbPickFail << "\n";
   }
 
   // step3 get result.
-
-  if (NbPickFail >= NbToReach)
+  if (aNbPickFail >= aNbToReach)
+  {
     return Standard_False;
+  }
 
-  Standard_Integer i(0);
-  for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
-    i++;
-    if(TheAISContext()->HasSelectedShape())
-      thearr->SetValue(i,TheAISContext()->SelectedShape());
-    else{
-      Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
-      thearr->SetValue(i,Handle(AIS_Shape)::DownCast (IO)->Shape());
+  Standard_Integer anIndex = theResArray->Lower();
+  for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected(), ++anIndex)
+  {
+    if (aCtx->HasSelectedShape())
+    {
+      theResArray->SetValue (anIndex, aCtx->SelectedShape());
+    }
+    else
+    {
+      Handle(AIS_InteractiveObject) IO = aCtx->SelectedInteractive();
+      theResArray->SetValue (anIndex, Handle(AIS_Shape)::DownCast (IO)->Shape());
     }
   }
 
-  Standard_DISABLE_DEPRECATION_WARNINGS
-  TheAISContext()->CloseLocalContext(curindex);
-  Standard_ENABLE_DEPRECATION_WARNINGS
+  aCtx->RemoveFilters();
+  if (theShapeType != TopAbs_SHAPE)
+  {
+    for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next())
+    {
+      if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value()))
+      {
+        aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single);
+      }
+    }
+  }
   return Standard_True;
 }
 
-
 //=======================================================================
 //function : VPickShape
 //purpose  :
 //=======================================================================
 static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
-  TopoDS_Shape PickSh;
-  TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
-
-  if(argc==1)
-    theType = TopAbs_SHAPE;
-  else{
-    if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
-    else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
-    else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
-    else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
-    else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
-    else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
-    else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
+  TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
+  if (argc != 1)
+  {
+    TCollection_AsciiString aShapeArg (argv[1]);
+    aShapeArg.LowerCase();
+    aShapeType = TopAbs_COMPOUND;
+    if      (aShapeArg == "v"
+          || aShapeArg == "vertex") aShapeType = TopAbs_VERTEX;
+    else if (aShapeArg == "e"
+          || aShapeArg == "edge")   aShapeType = TopAbs_EDGE;
+    else if (aShapeArg == "w"
+          || aShapeArg == "wire")   aShapeType = TopAbs_WIRE;
+    else if (aShapeArg == "f"
+          || aShapeArg == "face")   aShapeType = TopAbs_FACE;
+    else if (aShapeArg == "shape")  aShapeType = TopAbs_SHAPE;
+    else if (aShapeArg == "shell")  aShapeType = TopAbs_SHELL;
+    else if (aShapeArg == "solid")  aShapeType = TopAbs_SOLID;
+    else
+    {
+      std::cout << "Syntax error at '" << argv[1] << "'\n";
+      return 1;
+    }
   }
 
-  static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
-  static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
-
-  TCollection_AsciiString name;
-
+  static Standard_Integer THE_NB_SHAPES_OF_TYPE[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+  static const TCollection_AsciiString THE_NAME_TYPE[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
 
-  Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
-  if(NbToPick==1){
-    PickSh = ViewerTest::PickShape(theType);
-
-    if(PickSh.IsNull())
+  const Standard_Integer aNbToPick = argc > 2 ? argc - 2 : 1;
+  if (aNbToPick == 1)
+  {
+    TopoDS_Shape aPickedShape = ViewerTest::PickShape (aShapeType);
+    if (aPickedShape.IsNull())
+    {
       return 1;
-    if(argc>2){
-      name += argv[2];
     }
-    else{
 
-      if(!PickSh.IsNull()){
-       nbOfSub[Standard_Integer(theType)]++;
-       name += "Picked_";
-       name += nameType[Standard_Integer(theType)];
-       TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
-       name +="_";
-       name+=indxstring;
+    TCollection_AsciiString aName;
+    if (argc > 2)
+    {
+      aName = argv[2];
+    }
+    else
+    {
+      const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
+      aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
+    }
+
+    DBRep::Set (aName.ToCString(), aPickedShape);
+    Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
+    ViewerTest::Display (aName, aShapePrs, false, true);
+    di << "Name of picked shape: " << aName <<"\n";
+  }
+  else
+  {
+    TCollection_AsciiString aName (argv[2]);
+    aName.LowerCase();
+    const Standard_Boolean isAutoNaming = aName == ".";
+    Handle(TopTools_HArray1OfShape) aPickedArray = new TopTools_HArray1OfShape (1, aNbToPick);
+    if (ViewerTest::PickShapes (aShapeType, aPickedArray))
+    {
+      for (Standard_Integer aPickedIter = aPickedArray->Lower(); aPickedIter <= aPickedArray->Upper(); ++aPickedIter)
+      {
+        TopoDS_Shape aPickedShape = aPickedArray->Value (aPickedIter);
+        aName.Clear();
+        if (!aPickedShape.IsNull()
+         && isAutoNaming)
+        {
+          const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)];
+          aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex;
+        }
+        else
+        {
+          aName = argv[1 + aPickedIter];
+        }
+
+        DBRep::Set (aName.ToCString(), aPickedShape);
+        Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape);
+        di << "Display of picked shape #" << aPickedIter << " - name: " << aName <<"\n";
+        ViewerTest::Display (aName, aShapePrs, false, true);
       }
     }
-    // si on avait une petite methode pour voir si la shape
-    // est deja dans la Double map, ca eviterait de creer....
-    DBRep::Set(name.ToCString(),PickSh);
+  }
+  TheAISContext()->UpdateCurrentViewer();
+  return 0;
+}
 
-    Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
-    GetMapOfAIS().Bind(newsh, name);
-    TheAISContext()->Display(newsh);
-    di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
+//=======================================================================
+//function : VSelFilter
+//purpose  :
+//=======================================================================
+static int VSelFilter(Draw_Interpretor& , Standard_Integer theArgc,
+                      const char** theArgv)
+{
+  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
+  if (aContext.IsNull())
+  {
+    std::cout << "Error: AIS context is not available.\n";
+    return 1;
   }
 
-  // Plusieurs objets a picker, vite vite vite....
-  //
-  else{
-    Standard_Boolean autonaming = !strcasecmp(argv[2],".");
-    Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
-    if(ViewerTest::PickShapes(theType,arr)){
-      for(Standard_Integer i=1;i<=NbToPick;i++){
-       PickSh = arr->Value(i);
-       if(!PickSh.IsNull()){
-         if(autonaming){
-           nbOfSub[Standard_Integer(theType)]++;
-           name.Clear();
-           name += "Picked_";
-           name += nameType[Standard_Integer(theType)];
-           TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
-           name +="_";
-           name+=indxstring;
-         }
-       }
-       else
-         name = argv[1+i];
-
-       DBRep::Set(name.ToCString(),PickSh);
-       Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
-       GetMapOfAIS().Bind(newsh, name);
-       di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
-       TheAISContext()->Display(newsh);
+  for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
+  {
+    TCollection_AsciiString anArg (theArgv[anArgIter]);
+    anArg.LowerCase();
+    if (anArg == "-clear")
+    {
+      aContext->RemoveFilters();
+    }
+    else if (anArg == "-type"
+          && anArgIter + 1 < theArgc)
+    {
+      TCollection_AsciiString aVal (theArgv[++anArgIter]);
+      TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
+      if (!TopAbs::ShapeTypeFromString (aVal.ToCString(), aShapeType))
+      {
+        std::cout << "Syntax error: wrong command attribute value '" << aVal << "'\n";
+        return 1;
+      }
 
+      Handle(SelectMgr_Filter) aFilter;
+      if (aShapeType == TopAbs_SHAPE)
+      {
+        aFilter = new AIS_TypeFilter (AIS_KOI_Shape);
+      }
+      else
+      {
+        aFilter = new StdSelect_ShapeTypeFilter (aShapeType);
       }
+      aContext->AddFilter (aFilter);
+    }
+    else
+    {
+      std::cout << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'\n";
+      return 1;
     }
   }
   return 0;
@@ -5040,9 +5259,11 @@ static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const c
 
     Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
     GetMapOfAIS().Bind (aNewShape, aCurrentName);
-    TheAISContext()->Display (aNewShape);
+    TheAISContext()->Display (aNewShape, Standard_False);
   }
 
+  TheAISContext()->UpdateCurrentViewer();
+
   return 0;
 }
 
@@ -5232,7 +5453,7 @@ static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a
   DBRep::Set(a[1], shape);
   Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
   Handle(AIS_Shape) ais = new AIS_Shape(shape);
-  Ctx->Display(ais);
+  Ctx->Display (ais, Standard_True);
   return 0;
 }
 
@@ -5240,7 +5461,7 @@ static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a
 //function : VBsdf
 //purpose  :
 //===============================================================================================
-static int VBsdf (Draw_Interpretor& theDi,
+static int VBsdf (Draw_Interpretor& theDI,
                   Standard_Integer  theArgsNb,
                   const char**      theArgVec)
 {
@@ -5256,30 +5477,47 @@ static int VBsdf (Draw_Interpretor& theDi,
   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 ("print|echo|p", "Prints BSDF");
 
-  aCmd.AddOption ("fresnel|f", "Fresnel coefficients; Allowed fresnel formats are: Constant x, Schlick x y z, Dielectric x, Conductor x y");
+  aCmd.AddOption ("noupdate|update", "Suppresses viewer redraw call");
 
-  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 ("kc", "Weight of coat specular/glossy BRDF");
+  aCmd.AddOption ("kd", "Weight of base diffuse BRDF");
+  aCmd.AddOption ("ks", "Weight of base specular/glossy BRDF");
+  aCmd.AddOption ("kt", "Weight of base specular/glossy BTDF");
+  aCmd.AddOption ("le", "Radiance emitted by surface");
 
-  aCmd.AddOption ("normalize|n", "Normalize BSDF coefficients");
+  aCmd.AddOption ("coatFresnel|cf", "Fresnel reflectance of coat layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
+  aCmd.AddOption ("baseFresnel|bf", "Fresnel reflectance of base layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K");
+
+  aCmd.AddOption ("coatRoughness|cr", "Roughness of coat glossy BRDF");
+  aCmd.AddOption ("baseRoughness|br", "Roughness of base glossy BRDF");
+
+  aCmd.AddOption ("absorpCoeff|af", "Absorption coeff of base transmission BTDF");
+  aCmd.AddOption ("absorpColor|ac", "Absorption color of base transmission BTDF");
+
+  aCmd.AddOption ("normalize|n", "Normalizes BSDF to ensure energy conservation");
 
   aCmd.Parse (theArgsNb, theArgVec);
 
   if (aCmd.HasOption ("help"))
   {
-    theDi.PrintHelp (theArgVec[0]);
+    theDI.PrintHelp (theArgVec[0]);
     return 0;
   }
 
+  // check viewer update mode
+  ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
+
+  for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
+  {
+    if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
+    {
+      break;
+    }
+  }
+
   TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
 
   // find object
@@ -5296,62 +5534,92 @@ static int VBsdf (Draw_Interpretor& theDi,
 
   if (aCmd.HasOption ("print"))
   {
-    Graphic3d_Vec4 aFresnel = aBSDF.Fresnel.Serialize();
-
-    std::cout << "\n"
+    theDI << "\n"
+      << "Kc:               " << aBSDF.Kc.r() << ", " << aBSDF.Kc.g() << ", " << aBSDF.Kc.b() << "\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:          ";
+      << "Kt:               " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
+      << "Le:               " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n";
 
-    if (aFresnel.x() >= 0.f)
-    {
-      std::cout
-        << "|Schlick| " << aFresnel.x() << ", " << aFresnel.y() << ", " << aFresnel.z() << "\n";
-    }
-    else if (aFresnel.x() >= -1.5f)
+    for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
     {
-      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";
-    }
+      const Graphic3d_Vec4 aFresnel = aLayerID < 1 ? aBSDF.FresnelCoat.Serialize()
+                                                   : aBSDF.FresnelBase.Serialize();
 
+      theDI << (aLayerID < 1 ? "Coat Fresnel:     "
+                             : "Base Fresnel:     ");
+
+      if (aFresnel.x() >= 0.f)
+      {
+        theDI << "Schlick " << "R = " << aFresnel.r() << ", "
+                            << "G = " << aFresnel.g() << ", "
+                            << "B = " << aFresnel.b() << "\n";
+      }
+      else if (aFresnel.x() >= -1.5f)
+      {
+        theDI << "Constant " << aFresnel.z() << "\n";
+      }
+      else if (aFresnel.x() >= -2.5f)
+      {
+        theDI << "Conductor " << "N = " << aFresnel.y() << ", "
+                              << "K = " << aFresnel.z() << "\n";
+      }
+      else
+      {
+        theDI << "Dielectric " << "N = " << 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";
+    theDI << "Coat roughness:   " << aBSDF.Kc.w() << "\n"
+          << "Base roughness:   " << aBSDF.Ks.w() << "\n"
+          << "Absorption coeff: " << aBSDF.Absorption.w() << "\n"
+          << "Absorption color: " << aBSDF.Absorption.r() << ", "
+                                  << aBSDF.Absorption.g() << ", "
+                                  << aBSDF.Absorption.b() << "\n";
 
     return 0;
   }
 
-  if (aCmd.HasOption ("roughness", 1, Standard_True))
+  if (aCmd.HasOption ("coatRoughness", 1, Standard_True))
+  {
+    aBSDF.Kc.w() = aCmd.ArgFloat ("coatRoughness");
+  }
+
+  if (aCmd.HasOption ("baseRoughness", 1, Standard_True))
   {
-    aCmd.Arg ("roughness", 0);
-    aBSDF.Roughness = aCmd.ArgFloat ("roughness");
+    aBSDF.Ks.w () = aCmd.ArgFloat ("baseRoughness");
   }
 
   if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
   {
-    aBSDF.AbsorptionCoeff = aCmd.ArgFloat ("absorpCoeff");
+    aBSDF.Absorption.w() = aCmd.ArgFloat ("absorpCoeff");
   }
 
   if (aCmd.HasOption ("absorpColor", 3, Standard_True))
   {
-    aBSDF.AbsorptionColor = aCmd.ArgVec3f ("absorpColor");
+    const Graphic3d_Vec3 aRGB = aCmd.ArgVec3f ("absorpColor");
+
+    aBSDF.Absorption.r() = aRGB.r();
+    aBSDF.Absorption.g() = aRGB.g();
+    aBSDF.Absorption.b() = aRGB.b();
+  }
+
+  if (aCmd.HasOption ("kc", 3) || aCmd.HasOption ("kc", 1, Standard_True))
+  {
+    Graphic3d_Vec3 aKc;
+
+    if (aCmd.HasOption ("kc", 3))
+    {
+      aKc = aCmd.ArgVec3f ("kc");
+    }
+    else
+    {
+      aKc = Graphic3d_Vec3 (aCmd.ArgFloat ("kc"));
+    }
+
+    aBSDF.Kc.r() = aKc.r();
+    aBSDF.Kc.g() = aKc.g();
+    aBSDF.Kc.b() = aKc.b();
   }
 
   if (aCmd.HasOption ("kd", 3))
@@ -5363,13 +5631,22 @@ static int VBsdf (Draw_Interpretor& theDi,
     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))
+  if (aCmd.HasOption ("ks", 3) || aCmd.HasOption ("ks", 1, Standard_True))
   {
-    aBSDF.Kr = Graphic3d_Vec3 (aCmd.ArgFloat ("kr"));
+    Graphic3d_Vec3 aKs;
+
+    if (aCmd.HasOption ("ks", 3))
+    {
+      aKs = aCmd.ArgVec3f ("ks");
+    }
+    else
+    {
+      aKs = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
+    }
+
+    aBSDF.Ks.r() = aKs.r();
+    aBSDF.Ks.g() = aKs.g();
+    aBSDF.Ks.b() = aKs.b();
   }
 
   if (aCmd.HasOption ("kt", 3))
@@ -5381,15 +5658,6 @@ static int VBsdf (Draw_Interpretor& theDi,
     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");
@@ -5400,59 +5668,73 @@ static int VBsdf (Draw_Interpretor& theDi,
   }
 
   const std::string aFresnelErrorMessage =
-    "Error! Wrong Fresnel type. Allowed types are: Constant x, Schlick x y z, Dielectric x, Conductor x y.\n";
+    "Error! Wrong Fresnel type. Allowed types are: Constant F, Schlick R G B, Dielectric N, Conductor N K\n";
 
-  if (aCmd.HasOption ("fresnel", 4)) // Schlick: type, x, y ,z
+  for (int aLayerID = 0; aLayerID < 2; ++aLayerID)
   {
-    std::string aFresnelType = aCmd.Arg ("fresnel", 0);
-    std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
+    const std::string aFresnel = aLayerID < 1 ? "baseFresnel"
+                                              : "coatFresnel";
 
-    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
+    if (aCmd.HasOption (aFresnel, 4)) // Schlick: type R G B
     {
-      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);
+      std::string aFresnelType = aCmd.Arg (aFresnel, 0);
+      std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
 
-    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 == "schlick")
+      {
+        Graphic3d_Vec3 aRGB (static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())),
+                             static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str())),
+                             static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 3).c_str())));
 
-    if (aFresnelType == "dielectric")
-    {
-      aBSDF.Fresnel = Graphic3d_Fresnel::CreateDielectric (
-        static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
+        aRGB.r() = std::min (std::max (aRGB.r(), 0.f), 1.f);
+        aRGB.g() = std::min (std::max (aRGB.g(), 0.f), 1.f);
+        aRGB.b() = std::min (std::max (aRGB.b(), 0.f), 1.f);
+
+        (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateSchlick (aRGB);
+      }
+      else
+      {
+        theDI << aFresnelErrorMessage.c_str() << "\n";
+      }
     }
-    else if (aFresnelType == "constant")
+    else if (aCmd.HasOption (aFresnel, 3)) // Conductor: type N K
     {
-      aBSDF.Fresnel = Graphic3d_Fresnel::CreateConstant (
-        static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
+      std::string aFresnelType = aCmd.Arg (aFresnel, 0);
+      std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
+
+      if (aFresnelType == "conductor")
+      {
+        const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
+        const float aK = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str()));
+
+        (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConductor (aN, aK);
+      }
+      else
+      {
+        theDI << aFresnelErrorMessage.c_str() << "\n";
+      }
     }
-    else
+    else if (aCmd.HasOption (aFresnel, 2)) // Dielectric or Constant: type N|C
     {
-      std::cout << aFresnelErrorMessage;
+      std::string aFresnelType = aCmd.Arg (aFresnel, 0);
+      std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase);
+
+      if (aFresnelType == "constant")
+      {
+        const float aR = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
+
+        (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConstant (aR);
+      }
+      else if (aFresnelType == "dielectric")
+      {
+        const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str()));
+
+        (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateDielectric (aN);
+      }
+      else
+      {
+        theDI << aFresnelErrorMessage.c_str() << "\n";
+      }
     }
   }
 
@@ -5464,8 +5746,6 @@ static int VBsdf (Draw_Interpretor& theDi,
   aMaterial.SetBSDF (aBSDF);
   anIObj->SetMaterial (aMaterial);
 
-  aView->Redraw();
-
   return 0;
 }
 
@@ -5582,7 +5862,7 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
       "\n\t\t:                                         [offsetX offsetY]]]"
       "\n\t\t:          [-dispMode mode] [-highMode mode]"
       "\n\t\t:          [-layer index] [-top|-topmost|-overlay|-underlay]"
-      "\n\t\t:          [-redisplay]"
+      "\n\t\t:          [-redisplay] [-erased]"
       "\n\t\t:          name1 [name2] ... [name n]"
       "\n\t\t: Displays named objects."
       "\n\t\t: Option -local enables displaying of objects in local"
@@ -5591,6 +5871,7 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
       "\n\t\t:  -noupdate    Suppresses viewer redraw call."
       "\n\t\t:  -mutable     Enables optimizations for mutable objects."
       "\n\t\t:  -neutral     Draws objects in main viewer."
+      "\n\t\t:  -erased      Loads the object into context, but does not display it."
       "\n\t\t:  -layer       Sets z-layer for objects."
       "\n\t\t:               Alternatively -overlay|-underlay|-top|-topmost"
       "\n\t\t:               options can be used for the default z-layers."
@@ -5612,6 +5893,11 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
       "\n\t\t:  -redisplay   Recomputes presentation of objects.",
       __FILE__, VDisplay2, group);
 
+  theCommands.Add ("vnbdisplayed",
+      "vnbdisplayed"
+      "\n\t\t: Returns number of displayed objects",
+      __FILE__, VNbDisplayed, group);
+
   theCommands.Add ("vupdate",
       "vupdate name1 [name2] ... [name n]"
       "\n\t\t: Updates named objects in interactive context",
@@ -5711,6 +5997,9 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
       "\n\t\t:          [-setTransparency Transp] [-unsetTransparency]"
       "\n\t\t:          [-setWidth LineWidth] [-unsetWidth]"
       "\n\t\t:          [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
+      "\n\t\t:          [-setMarkerType {.|+|x|O|xcircle|pointcircle|ring1|ring2|ring3|ball|ImagePath}]"
+      "\n\t\t:          [-unsetMarkerType]"
+      "\n\t\t:          [-setMarkerSize Scale] [-unsetMarkerSize]"
       "\n\t\t:          [-freeBoundary {off/on | 0/1}]"
       "\n\t\t:          [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
       "\n\t\t:          [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
@@ -5718,6 +6007,10 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
       "\n\t\t:          [-isoontriangulation 0|1]"
       "\n\t\t:          [-setMaxParamValue {value}]"
       "\n\t\t:          [-setSensitivity {selection_mode} {value}]"
+      "\n\t\t:          [-setHatch HatchStyle]"
+      "\n\t\t:          [-setShadingModel {color|flat|gouraud|phong}]"
+      "\n\t\t:          [-unsetShadingModel]"
+      "\n\t\t:          [-setAlphaMode {opaque|mask|blend|blendauto} [alphaCutOff=0.5]]"
       "\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."
@@ -5795,11 +6088,6 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
       "vsensera : erase active entities",
       __FILE__,VClearSensi,group);
 
-  theCommands.Add("vperf",
-      "vperf: vperf  ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)"
-      "\n\t\t: Tests the animation of an object along a predefined trajectory.",
-      __FILE__,VPerf,group);
-
   theCommands.Add("vsetshading",
       "vsetshading  : vsetshading name Quality(default=0.0008) "
       "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
@@ -5811,67 +6099,49 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
       __FILE__,VShading,group);
 
   theCommands.Add ("vtexture",
-                   "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
-                   "                         [-scale u v]  [-scale off]\n"
-                   "                         [-origin u v] [-origin off]\n"
-                   "                         [-repeat u v] [-repeat off]\n"
-                   "                         [-modulate {on | off}]"
-                   "                         [-default]'\n"
-                   " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
-                   " specifying one of the predefined textures.\n"
-                   " The options are: \n"
-                   "  -scale u v : enable texture scaling and set scale factors\n"
-                   "  -scale off : disable texture scaling\n"
-                   "  -origin u v : enable texture origin positioning and set the origin\n"
-                   "  -origin off : disable texture origin positioning\n"
-                   "  -repeat u v : enable texture repeat and set texture coordinate scaling\n"
-                   "  -repeat off : disable texture repeat\n"
-                   "  -modulate {on | off} : enable or disable texture modulation\n"
-                   "  -default : sets texture mapping default parameters\n"
-                   "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
-                   "or 'vtexture NameOfShape ?' to list available textures\n",
+                   "vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]"
+                   "\n\t\t:          [-tex0 Image0] [-tex1 Image1] [...]"
+                   "\n\t\t:          [-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]"
+                   "\n\t\t:          [-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]"
+                   "\n\t\t:          [-modulate {on|off}]"
+                   "\n\t\t:          [-setFilter {nearest|bilinear|trilinear}]"
+                   "\n\t\t:          [-setAnisoFilter {off|low|middle|quality}]"
+                   "\n\t\t:          [-default]"
+                   "\n\t\t: The texture can be specified by filepath"
+                   "\n\t\t: or as ID (0<=IdOfTexture<=20) specifying one of the predefined textures."
+                   "\n\t\t: The options are:"
+                   "\n\t\t:   -scale     Setup texture scaling for generating coordinates; (1, 1) by default"
+                   "\n\t\t:   -origin    Setup texture origin  for generating coordinates; (0, 0) by default"
+                   "\n\t\t:   -repeat    Setup texture repeat  for generating coordinates; (1, 1) by default"
+                   "\n\t\t:   -modulate  Enable or disable texture color modulation"
+                   "\n\t\t:   -trsfAngle Setup dynamic texture coordinates transformation - rotation angle"
+                   "\n\t\t:   -trsfTrans Setup dynamic texture coordinates transformation - translation vector"
+                   "\n\t\t:   -trsfScale Setup dynamic texture coordinates transformation - scale vector"
+                   "\n\t\t:   -setFilter Setup texture filter"
+                   "\n\t\t:   -setAnisoFilter Setup anisotropic filter for texture with mip-levels"
+                   "\n\t\t:   -default   Sets texture mapping default parameters",
                     __FILE__, VTexture, group);
 
   theCommands.Add("vtexscale",
-                 "'vtexscale  NameOfShape ScaleU ScaleV' \n \
-                   or 'vtexscale NameOfShape ScaleUV' \n \
-                   or 'vtexscale NameOfShape' to disable scaling\n ",
+                  "vtexscale name ScaleU ScaleV"
+                  "\n\t\t: Alias for vtexture name -setScale ScaleU ScaleV.",
                  __FILE__,VTexture,group);
 
   theCommands.Add("vtexorigin",
-                 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
-                   or 'vtexorigin NameOfShape UVOrigin' \n \
-                   or 'vtexorigin NameOfShape' to disable origin positioning\n ",
+                  "vtexorigin name OriginU OriginV"
+                  "\n\t\t: Alias for vtexture name -setOrigin OriginU OriginV.",
                  __FILE__,VTexture,group);
 
   theCommands.Add("vtexrepeat",
-                 "'vtexrepeat  NameOfShape URepeat VRepeat' \n \
-                   or 'vtexrepeat NameOfShape UVRepeat \n \
-                   or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
+                  "vtexrepeat name RepeatU RepeatV"
+                  "\n\t\t: Alias for vtexture name -setRepeat RepeatU RepeatV.",
                  VTexture,group);
 
   theCommands.Add("vtexdefault",
-                 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
+                  "vtexdefault name"
+                  "\n\t\t: Alias for vtexture name -default.",
                  VTexture,group);
 
-  theCommands.Add("vsetam",
-      "vsetam [shapename] mode"
-      "\n\t\t: Activates selection mode for all selected or named shapes."
-      "\n\t\t: Mod can be:"
-      "\n\t\t:   0 - for shape itself" 
-      "\n\t\t:   1 - vertices"
-      "\n\t\t:   2 - edges"
-      "\n\t\t:   3 - wires"
-      "\n\t\t:   4 - faces"
-      "\n\t\t:   5 - shells"
-      "\n\t\t:   6 - solids"
-      "\n\t\t:   7 - compounds"
-      __FILE__,VActivatedMode,group);
-
-  theCommands.Add("vunsetam",
-      "vunsetam : Deactivates all selection modes for all shapes.",
-      __FILE__,VActivatedMode,group);
-
   theCommands.Add("vstate",
       "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
       "\n\t\t: Reports show/hidden state for selected or named objects"
@@ -5880,8 +6150,10 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
                  __FILE__,VState,group);
 
   theCommands.Add("vpickshapes",
-                 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
-                 __FILE__,VPickShape,group);
+                  "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]"
+                  "\n\t\t: Hold Ctrl and pick object by clicking Left mouse button."
+                  "\n\t\t: Hold also Shift for multiple selection.",
+                  __FILE__, VPickShape, group);
 
   theCommands.Add("vtypes",
                  "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
@@ -5892,6 +6164,13 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
       "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
                  __FILE__,vr, group);
 
+  theCommands.Add("vselfilter",
+                  "vselfilter [-type {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}] [-clear]"
+    "\nSets selection shape type filter in context or remove all filters."
+    "\n    : Option -type set type of selection filter. Filters are applyed with Or combination."
+    "\n    : Option -clear remove all filters in context",
+                 __FILE__,VSelFilter,group);
+
   theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
     __FILE__, VPickSelected, group);