0026462: Visualization - selection does not adapt to line width change
[occt.git] / src / ViewerTest / ViewerTest.cxx
index 5f04601..be00157 100644 (file)
@@ -25,6 +25,7 @@
 #include <Standard_Stream.hxx>
 
 #include <ViewerTest.hxx>
+#include <ViewerTest_CmdParser.hxx>
 
 #include <TopLoc_Location.hxx>
 #include <TopTools_HArray1OfShape.hxx>
@@ -81,8 +82,6 @@
 #pragma warning (disable:4996)
 #endif
 
-#include <NIS_InteractiveContext.hxx>
-#include <NIS_Triangulated.hxx>
 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
 
 #include <Quantity_Color.hxx>
@@ -257,24 +256,20 @@ Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
   return TheMap;
 }
 
-
-//==============================================================================
-//function : VDisplayAISObject
-//purpose  : register interactive object in the map of AIS objects;
-//           if other object with such name already registered, it will be kept
-//           or replaced depending on value of <theReplaceIfExists>,
-//           if "true" - the old object will be cleared from AIS context;
-//           returns Standard_True if <theAISObj> registered in map;
-//==============================================================================
-Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
-                                                    const Handle(AIS_InteractiveObject)& theAISObj,
-                                                    Standard_Boolean theReplaceIfExists = Standard_True)
+//=======================================================================
+//function : Display
+//purpose  :
+//=======================================================================
+Standard_Boolean ViewerTest::Display (const TCollection_AsciiString&       theName,
+                                      const Handle(AIS_InteractiveObject)& theObject,
+                                      const Standard_Boolean               theToUpdate,
+                                      const Standard_Boolean               theReplaceIfExists)
 {
   ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
-  Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
-  if (aContextAIS.IsNull())
+  Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
+  if (aCtx.IsNull())
   {
-    std::cout << "AIS context is not available.\n";
+    std::cout << "Error: AIS context is not available.\n";
     return Standard_False;
   }
 
@@ -282,42 +277,46 @@ Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiStrin
   {
     if (!theReplaceIfExists)
     {
-      std::cout << "Other interactive object has been already "
-                << "registered with name: " << theName << ".\n"
+      std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n"
                 << "Please use another name.\n";
       return Standard_False;
     }
 
-    // stop displaying object
-    Handle(AIS_InteractiveObject) anOldObj =
-       Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
-
+    Handle(AIS_InteractiveObject) anOldObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
     if (!anOldObj.IsNull())
-      aContextAIS->Remove (anOldObj, Standard_True);
-
-    // remove name and old object from map
+    {
+      aCtx->Remove (anOldObj, Standard_True);
+    }
     aMap.UnBind2 (theName);
   }
 
-  if (theAISObj.IsNull())
+  if (theObject.IsNull())
   {
-    // object with specified name already unbound
+    // object with specified name has been already unbound
     return Standard_True;
   }
 
-  // unbind AIS object if was bound with another name
-  aMap.UnBind1 (theAISObj);
+  // unbind AIS object if it was bound with another name
+  aMap.UnBind1 (theObject);
 
   // can be registered without rebinding
-  aMap.Bind (theAISObj, theName);
-  aContextAIS->Display (theAISObj, Standard_True);
+  aMap.Bind (theObject, theName);
+  aCtx->Display (theObject, theToUpdate);
   return Standard_True;
 }
 
+//! Alias for ViewerTest::Display(), compatibility with old code.
+Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString&       theName,
+                                                    const Handle(AIS_InteractiveObject)& theObject,
+                                                    Standard_Boolean theReplaceIfExists = Standard_True)
+{
+  return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
+}
+
 static TColStd_MapOfInteger theactivatedmodes(8);
 static TColStd_ListOfTransient theEventMgrs;
 
-static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView,
+static void VwrTst_InitEventMgr(const Handle(V3d_View)& aView,
                                 const Handle(AIS_InteractiveContext)& Ctx)
 {
   theEventMgrs.Clear();
@@ -345,16 +344,6 @@ void ViewerTest::CurrentView(const Handle(V3d_View)& V)
   a3DView() = V;
 }
 
-Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext()
-{
-  static Handle(NIS_InteractiveContext) aContext;
-  if (aContext.IsNull()) {
-    aContext = new NIS_InteractiveContext;
-    aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal);
-  }
-  return aContext;
-}
-
 const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
 {
   return TheAISContext();
@@ -389,8 +378,7 @@ void ViewerTest::UnsetEventManager()
 
 void ViewerTest::ResetEventManager()
 {
-  const Handle(NIS_View) aView =
-    Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
+  const Handle(V3d_View) aView = ViewerTest::CurrentView();
   VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
 }
 
@@ -399,7 +387,7 @@ Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
   Handle(ViewerTest_EventManager) EM;
   if(theEventMgrs.IsEmpty()) return EM;
   Handle(Standard_Transient) Tr =  theEventMgrs.First();
-  EM = *((Handle(ViewerTest_EventManager)*)&Tr);
+  EM = Handle(ViewerTest_EventManager)::DownCast (Tr);
   return EM;
 }
 
@@ -452,7 +440,7 @@ Handle(AIS_Shape) GetAISShapeFromName(const char* name)
     if (!IO.IsNull()) {
       if(IO->Type()==AIS_KOI_Shape) {
         if(IO->Signature()==0){
-          retsh = *((Handle(AIS_Shape)*)&IO);
+          retsh = Handle(AIS_Shape)::DownCast (IO);
         }
         else
           cout << "an Object which is not an AIS_Shape "
@@ -483,20 +471,12 @@ void ViewerTest::Clear()
     ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
     while ( it.More() ) {
       cout << "Remove " << it.Key2() << endl;
-      if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
-        const Handle(AIS_InteractiveObject) anObj =
-          Handle(AIS_InteractiveObject)::DownCast (it.Key1());
-        TheAISContext()->Remove(anObj,Standard_False);
-      } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
-        const Handle(NIS_InteractiveObject) anObj =
-          Handle(NIS_InteractiveObject)::DownCast (it.Key1());
-        TheNISContext()->Remove(anObj);
-      }
+      const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (it.Key1());
+      TheAISContext()->Remove(anObj,Standard_False);
       it.Next();
     }
     TheAISContext()->RebuildSelectionStructs();
     TheAISContext()->UpdateCurrentViewer();
-//    TheNISContext()->UpdateViews();
     GetMapOfAIS().Clear();
   }
 }
@@ -516,14 +496,14 @@ void ViewerTest::StandardModeActivation(const Standard_Integer mode )
 
     if(!aContext->HasOpenedContext()) {
       // To unhilight the preselected object
-      aContext->UnhilightCurrents(Standard_False);
+      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->FirstCurrentObject().IsNull()){
+      if (!aContext->FirstSelectedObject().IsNull()){
        aContext->OpenLocalContext(Standard_False);
 
-       for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
-         aContext->Load(       aContext->Current(),-1,Standard_True);
+       for(aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected()){
+         aContext->Load(       aContext->SelectedInteractive(),-1,Standard_True);
        }
       }
       else
@@ -597,7 +577,8 @@ static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv
       TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
     di << "IsoOnPlane mode is " <<
       (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
-
+    di << "IsoOnTriangulation mode is " <<
+      (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
     return 0;
   }
 
@@ -749,7 +730,7 @@ static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char
 {
   if( argc > 2 )
   {
-    di << "Use: " << argv[0] << " [tolerance_value]\n";
+    di << "Wrong parameters! Must be: " << argv[0] << " [-unset] [tolerance]\n";
     return 1;
   }
 
@@ -760,19 +741,33 @@ static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char
   if( argc == 1 )
   {
     Standard_Real aPixelTolerance = aContext->PixelTolerance();
-    di << "Precision mode  : 0 (window)\n";
     di << "Pixel tolerance : " << aPixelTolerance << "\n";
   }
   else if (argc == 2)
   {
-
-    Standard_Integer aPixelTolerance = Draw::Atoi (argv[1]);
-    aContext->SetPixelTolerance (aPixelTolerance);
+    TCollection_AsciiString anArg = TCollection_AsciiString (argv[1]);
+    anArg.LowerCase();
+    if (anArg == "-unset")
+    {
+      aContext->SetPixelTolerance (-1);
+    }
+    else
+    {
+      aContext->SetPixelTolerance (anArg.IntegerValue());
+    }
   }
 
   return 0;
 }
 
+//! Auxiliary enumeration
+enum ViewerTest_StereoPair
+{
+  ViewerTest_SP_Single,
+  ViewerTest_SP_SideBySide,
+  ViewerTest_SP_OverUnder
+};
+
 //==============================================================================
 //function : VDump
 //purpose  : To dump the active view snapshot to image file
@@ -791,42 +786,108 @@ static Standard_Integer VDump (Draw_Interpretor& theDI,
   Standard_CString      aFilePath   = theArgVec[anArgIter++];
   Graphic3d_BufferType  aBufferType = Graphic3d_BT_RGB;
   V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
+  ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
   Standard_Integer      aWidth      = 0;
   Standard_Integer      aHeight     = 0;
   for (; anArgIter < theArgNb; ++anArgIter)
   {
     TCollection_AsciiString anArg (theArgVec[anArgIter]);
     anArg.LowerCase();
-    if (anArg == "rgba")
-    {
-      aBufferType = Graphic3d_BT_RGBA;
-    }
-    else if (anArg == "rgb")
+    if (anArg == "-buffer")
     {
-      aBufferType = Graphic3d_BT_RGB;
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at '" << anArg << "'\n";
+        return 1;
+      }
+
+      TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
+      aBufArg.LowerCase();
+      if (aBufArg == "rgba")
+      {
+        aBufferType = Graphic3d_BT_RGBA;
+      }
+      else if (aBufArg == "rgb")
+      {
+        aBufferType = Graphic3d_BT_RGB;
+      }
+      else if (aBufArg == "depth")
+      {
+        aBufferType = Graphic3d_BT_Depth;
+      }
+      else
+      {
+        std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
+        return 1;
+      }
     }
-    else if (anArg == "depth")
+    else if (anArg == "-stereo")
     {
-      aBufferType = Graphic3d_BT_Depth;
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at '" << anArg << "'\n";
+        return 1;
+      }
+
+      TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
+      aStereoArg.LowerCase();
+      if (aStereoArg == "l"
+       || aStereoArg == "left")
+      {
+        aStereoOpts = V3d_SDO_LEFT_EYE;
+      }
+      else if (aStereoArg == "r"
+            || aStereoArg == "right")
+      {
+        aStereoOpts = V3d_SDO_RIGHT_EYE;
+      }
+      else if (aStereoArg == "mono")
+      {
+        aStereoOpts = V3d_SDO_MONO;
+      }
+      else if (aStereoArg == "blended"
+            || aStereoArg == "blend"
+            || aStereoArg == "stereo")
+      {
+        aStereoOpts = V3d_SDO_BLENDED;
+      }
+      else if (aStereoArg == "sbs"
+            || aStereoArg == "sidebyside")
+      {
+        aStereoPair = ViewerTest_SP_SideBySide;
+      }
+      else if (aStereoArg == "ou"
+            || aStereoArg == "overunder")
+      {
+        aStereoPair = ViewerTest_SP_OverUnder;
+      }
+      else
+      {
+        std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
+        return 1;
+      }
     }
-    else if (anArg == "l"
-          || anArg == "left")
+    else if (anArg == "-rgba"
+          || anArg ==  "rgba")
     {
-      aStereoOpts = V3d_SDO_LEFT_EYE;
+      aBufferType = Graphic3d_BT_RGBA;
     }
-    else if (anArg == "r"
-          || anArg == "right")
+    else if (anArg == "-rgb"
+          || anArg ==  "rgb")
     {
-      aStereoOpts = V3d_SDO_RIGHT_EYE;
+      aBufferType = Graphic3d_BT_RGB;
     }
-    else if (anArg == "mono")
+    else if (anArg == "-depth"
+          || anArg ==  "depth")
     {
-      aStereoOpts = V3d_SDO_MONO;
+      aBufferType = Graphic3d_BT_Depth;
     }
-    else if (anArg == "w"
-          || anArg == "width")
+
+    else if (anArg == "-width"
+          || anArg ==  "width"
+          || anArg ==  "sizex")
     {
-      if (aWidth  != 0)
+      if (aWidth != 0)
       {
         std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
         return 1;
@@ -838,36 +899,20 @@ static Standard_Integer VDump (Draw_Interpretor& theDI,
       }
       aWidth = Draw::Atoi (theArgVec[anArgIter]);
     }
-    else if (anArg == "h"
-          || anArg == "height")
+    else if (anArg == "-height"
+          || anArg ==  "height"
+          || anArg ==  "-sizey")
     {
       if (aHeight != 0)
       {
         std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
         return 1;
       }
-      if (++anArgIter >= theArgNb)
-      {
-        std::cout << "Error: integer value is expected right after 'height'\n";
-        return 1;
-      }
-      aHeight = Draw::Atoi (theArgVec[anArgIter]);
-    }
-    else if (anArg.IsIntegerValue())
-    {
-      // compatibility with old syntax
-      if (aWidth  != 0
-       || aHeight != 0)
-      {
-        std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
-        return 1;
-      }
       else if (++anArgIter >= theArgNb)
       {
-        std::cout << "Error: height value is expected right after width\n";
+        std::cout << "Error: integer value is expected right after 'height'\n";
         return 1;
       }
-      aWidth  = Draw::Atoi (theArgVec[anArgIter - 1]);
       aHeight = Draw::Atoi (theArgVec[anArgIter]);
     }
     else
@@ -892,33 +937,82 @@ static Standard_Integer VDump (Draw_Interpretor& theDI,
 
   if (aWidth <= 0 || aHeight <= 0)
   {
-    if (aStereoOpts != V3d_SDO_MONO)
+    aView->Window()->Size (aWidth, aHeight);
+  }
+
+  Image_AlienPixMap aPixMap;
+
+  bool isBigEndian = Image_PixMap::IsBigEndianHost();
+  Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN;
+  switch (aBufferType)
+  {
+    case Graphic3d_BT_RGB:   aFormat = isBigEndian ? Image_PixMap::ImgRGB  : Image_PixMap::ImgBGR;  break;
+    case Graphic3d_BT_RGBA:  aFormat = isBigEndian ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; break;
+    case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; break;
+  }
+
+  switch (aStereoPair)
+  {
+    case ViewerTest_SP_Single:
     {
-      aView->Window()->Size (aWidth, aHeight);
+      if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
+      {
+        theDI << "Fail: view dump failed!\n";
+        return 0;
+      }
+      else if (aPixMap.SizeX() != Standard_Size(aWidth)
+            || aPixMap.SizeY() != Standard_Size(aHeight))
+      {
+        theDI << "Fail: dumped dimensions "    << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
+              << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
+      }
+      break;
     }
-    else
+    case ViewerTest_SP_SideBySide:
     {
-      if (!aView->Dump (aFilePath, aBufferType))
+      if (!aPixMap.InitZero (aFormat, aWidth * 2, aHeight))
+      {
+        theDI << "Fail: not enough memory for image allocation!\n";
+        return 0;
+      }
+
+      Image_PixMap aPixMapL, aPixMapR;
+      aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
+                            aWidth, aHeight, aPixMap.SizeRowBytes());
+      aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aWidth,
+                            aWidth, aHeight, aPixMap.SizeRowBytes());
+      if (!aView->ToPixMap (aPixMapL, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_LEFT_EYE)
+       || !aView->ToPixMap (aPixMapR, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_RIGHT_EYE)
+       )
       {
         theDI << "Fail: view dump failed!\n";
+        return 0;
       }
-      return 0;
+      break;
     }
-  }
+    case ViewerTest_SP_OverUnder:
+    {
+      if (!aPixMap.InitZero (aFormat, aWidth, aHeight * 2))
+      {
+        theDI << "Fail: not enough memory for image allocation!\n";
+        return 0;
+      }
 
-  Image_AlienPixMap aPixMap;
-  if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
-  {
-    theDI << "Fail: view dump failed!\n";
-    return 0;
+      Image_PixMap aPixMapL, aPixMapR;
+      aPixMapL.InitWrapper (aFormat, aPixMap.ChangeData(),
+                            aWidth, aHeight, aPixMap.SizeRowBytes());
+      aPixMapR.InitWrapper (aFormat, aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aHeight,
+                            aWidth, aHeight, aPixMap.SizeRowBytes());
+      if (!aView->ToPixMap (aPixMapL, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_LEFT_EYE)
+       || !aView->ToPixMap (aPixMapR, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_RIGHT_EYE))
+      {
+        theDI << "Fail: view dump failed!\n";
+        return 0;
+      }
+      break;
+    }
   }
 
-  if (aPixMap.SizeX() != Standard_Size(aWidth)
-   || aPixMap.SizeY() != Standard_Size(aHeight))
-  {
-    theDI << "Fail: dumped dimensions "    << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
-          << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
-  }
   if (!aPixMap.Save (aFilePath))
   {
     theDI << "Fail: image can not be saved!\n";
@@ -926,7 +1020,6 @@ static Standard_Integer VDump (Draw_Interpretor& theDI,
   return 0;
 }
 
-
 //==============================================================================
 //function : Displays,Erase...
 //purpose  :
@@ -986,18 +1079,13 @@ static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** ar
   //unset displaymode.. comportement particulier...
   if(TypeOfOperation==4){
     if(argc==1){
-      if(Ctx->NbCurrents()==0 ||
-        Ctx->NbSelected()==0){
+      if(Ctx->NbSelected()==0){
        Handle(AIS_InteractiveObject) IO;
        VwrTst_DispErase(IO,-1,4,Standard_False);
       }
-      else if(!Ctx->HasOpenedContext()){
-       for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
-         VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
-      }
       else{
        for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
-         VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
+         VwrTst_DispErase(Ctx->SelectedInteractive(),-1,4,Standard_False);}
       Ctx->UpdateCurrentViewer();
     }
     else{
@@ -1012,20 +1100,20 @@ static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** ar
   }
   else if(argc==2){
     Standard_Integer Dmode = Draw::Atoi(argv[1]);
-    if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
+    if(Ctx->NbSelected()==0 && TypeOfOperation==3){
       Handle(AIS_InteractiveObject) IO;
       VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
     }
     if(!Ctx->HasOpenedContext()){
       // set/unset display mode sur le Contexte...
-      for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
-       VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
+      for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
+       VwrTst_DispErase(Ctx->SelectedInteractive(),Dmode,TypeOfOperation,Standard_False);
       }
       Ctx->UpdateCurrentViewer();
     }
     else{
       for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
-       Ctx->Display(Ctx->Interactive(),Dmode);
+       Ctx->Display(Ctx->SelectedInteractive(),Dmode);
     }
   }
   else{
@@ -1050,30 +1138,22 @@ static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** arg
   Standard_Integer On = Draw::Atoi(argv[1]);
   const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
 
-  if(argc==2){
-
-    if(!Ctx->HasOpenedContext()){
-      di<<"sub intensite ";
-      if(On==1) di<<"On";
-      else di<<"Off";
-      di<<" pour "<<Ctx->NbCurrents()<<"  objets"<<"\n";
-      for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
-       if(On==1){
-         Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
-       else{
-         di <<"passage dans off"<<"\n";
-         Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
-       }
+  if(argc==2)
+  {
+    TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
+    di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
+    for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
+    {
+      if(On==1)
+      {
+        Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
       }
-    }
-    else{
-      for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
-       if(On==1){
-         Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
-       else{
-         Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
+      else
+      {
+        Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
       }
     }
+
     Ctx->UpdateCurrentViewer();
   }
   else {
@@ -1128,11 +1208,11 @@ public:
       mySource = IterSource_List;
       mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
     }
-    else if (aCtx->NbCurrents() > 0)
+    else if (aCtx->NbSelected() > 0)
     {
       mySource  = IterSource_Selected;
       mySelIter = aCtx;
-      mySelIter->InitCurrent();
+      mySelIter->InitSelected();
     }
     else
     {
@@ -1164,7 +1244,7 @@ public:
     {
       case IterSource_All:      return myMapIter.More();
       case IterSource_List:     return mySeqIter.More();
-      case IterSource_Selected: return mySelIter->MoreCurrent();
+      case IterSource_Selected: return mySelIter->MoreSelected();
     }
     return Standard_False;
   }
@@ -1189,7 +1269,7 @@ public:
       }
       case IterSource_Selected:
       {
-        mySelIter->NextCurrent();
+        mySelIter->NextSelected();
         break;
       }
     }
@@ -1229,10 +1309,10 @@ private:
       }
       case IterSource_Selected:
       {
-        if (mySelIter->MoreCurrent())
+        if (mySelIter->MoreSelected())
         {
-          myCurrentName = GetMapOfAIS().Find1 (mySelIter->Current());
-          myCurrent     = mySelIter->Current();
+          myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
+          myCurrent     = mySelIter->SelectedInteractive();
         }
         break;
       }
@@ -1371,6 +1451,9 @@ struct ViewerTest_AspectsChangeSet
   Standard_Integer         ToSetLineWidth;
   Standard_Real            LineWidth;
 
+  Standard_Integer         ToSetTypeOfLine;
+  Aspect_TypeOfLine        TypeOfLine;
+
   Standard_Integer         ToSetTransparency;
   Standard_Real            Transparency;
 
@@ -1386,6 +1469,15 @@ struct ViewerTest_AspectsChangeSet
   Standard_Integer         ToSetFreeBoundaryColor;
   Quantity_Color           FreeBoundaryColor;
 
+  Standard_Integer         ToEnableIsoOnTriangulation;
+
+  Standard_Integer         ToSetMaxParamValue;
+  Standard_Real            MaxParamValue;
+
+  Standard_Integer         ToSetSensitivity;
+  Standard_Integer         SelectionMode;
+  Standard_Integer         Sensitivity;
+
   //! Empty constructor
   ViewerTest_AspectsChangeSet()
   : ToSetVisibility   (0),
@@ -1394,15 +1486,23 @@ struct ViewerTest_AspectsChangeSet
     Color             (DEFAULT_COLOR),
     ToSetLineWidth    (0),
     LineWidth         (1.0),
+    ToSetTypeOfLine   (0),
+    TypeOfLine        (Aspect_TOL_SOLID),
     ToSetTransparency (0),
     Transparency      (0.0),
     ToSetMaterial     (0),
     Material          (Graphic3d_NOM_DEFAULT),
-    ToSetShowFreeBoundary  (0),
-    ToSetFreeBoundaryWidth (0),
-    FreeBoundaryWidth      (1.0),
-    ToSetFreeBoundaryColor (0),
-    FreeBoundaryColor      (DEFAULT_FREEBOUNDARY_COLOR) {}
+    ToSetShowFreeBoundary      (0),
+    ToSetFreeBoundaryWidth     (0),
+    FreeBoundaryWidth          (1.0),
+    ToSetFreeBoundaryColor     (0),
+    FreeBoundaryColor          (DEFAULT_FREEBOUNDARY_COLOR),
+    ToEnableIsoOnTriangulation (-1),
+    ToSetMaxParamValue (0),
+    MaxParamValue (500000),
+    ToSetSensitivity (0),
+    SelectionMode (-1),
+    Sensitivity (-1) {}
 
   //! @return true if no changes have been requested
   Standard_Boolean IsEmpty() const
@@ -1414,7 +1514,9 @@ struct ViewerTest_AspectsChangeSet
         && ToSetMaterial          == 0
         && ToSetShowFreeBoundary  == 0
         && ToSetFreeBoundaryColor == 0
-        && ToSetFreeBoundaryWidth == 0;
+        && ToSetFreeBoundaryWidth == 0
+        && ToSetMaxParamValue     == 0
+        && ToSetSensitivity       == 0;
   }
 
   //! @return true if properties are valid
@@ -1456,6 +1558,16 @@ struct ViewerTest_AspectsChangeSet
       std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
       isOk = Standard_False;
     }
+    if (MaxParamValue < 0.0)
+    {
+      std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
+      isOk = Standard_False;
+    }
+    if (Sensitivity <= 0 && ToSetSensitivity)
+    {
+      std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
+      isOk = Standard_False;
+    }
     return isOk;
   }
 
@@ -1761,6 +1873,45 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
       aChangeSet->ToSetColor = 1;
       anArgIter += aNbComps;
     }
+    else if (anArg == "-setlinetype")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+
+      TCollection_AsciiString aValue (theArgVec[anArgIter]);
+      aValue.LowerCase();
+
+      if (aValue.IsEqual ("solid"))
+      {
+        aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
+      }
+      else if (aValue.IsEqual ("dot"))
+      {
+        aChangeSet->TypeOfLine = Aspect_TOL_DOT;
+      }
+      else if (aValue.IsEqual ("dash"))
+      {
+        aChangeSet->TypeOfLine = Aspect_TOL_DASH;
+      }
+      else if (aValue.IsEqual ("dotdash"))
+      {
+        aChangeSet->TypeOfLine = Aspect_TOL_DOTDASH;
+      }
+      else
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+
+      aChangeSet->ToSetTypeOfLine = 1;
+    }
+    else if (anArg == "-unsetlinetype")
+    {
+      aChangeSet->ToSetTypeOfLine = -1;
+    }
     else if (anArg == "-unsetcolor")
     {
       aChangeSet->ToSetColor = -1;
@@ -1932,6 +2083,8 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
       aChangeSet->Visibility = 1;
       aChangeSet->ToSetLineWidth = -1;
       aChangeSet->LineWidth = 1.0;
+      aChangeSet->ToSetTypeOfLine = -1;
+      aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
       aChangeSet->ToSetTransparency = -1;
       aChangeSet->Transparency = 0.0;
       aChangeSet->ToSetColor = -1;
@@ -1944,6 +2097,65 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
       aChangeSet->ToSetFreeBoundaryWidth = -1;
       aChangeSet->FreeBoundaryWidth = 1.0;
     }
+    else if (anArg == "-isoontriangulation"
+          || anArg == "-isoontriang")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+      TCollection_AsciiString aValue (theArgVec[anArgIter]);
+      aValue.LowerCase();
+      if (aValue == "on"
+        || aValue == "1")
+      {
+        aChangeSet->ToEnableIsoOnTriangulation = 1;
+      }
+      else if (aValue == "off"
+        || aValue == "0")
+      {
+        aChangeSet->ToEnableIsoOnTriangulation = 0;
+      }
+      else
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+    }
+    else if (anArg == "-setmaxparamvalue")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+      aChangeSet->ToSetMaxParamValue = 1;
+      aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
+    }
+    else if (anArg == "-setsensitivity")
+    {
+      if (isDefaults)
+      {
+        std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
+        return 1;
+      }
+
+      if (aNames.IsEmpty())
+      {
+        std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
+        return 1;
+      }
+
+      if (anArgIter + 2 >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+      aChangeSet->ToSetSensitivity = 1;
+      aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
+      aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
+    }
     else
     {
       std::cout << "Error: wrong syntax at " << anArg << "\n";
@@ -1989,6 +2201,14 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
       aDrawer->WireAspect()->SetColor           (aChangeSet->Color);
       aDrawer->PointAspect()->SetColor          (aChangeSet->Color);
     }
+    if (aChangeSet->ToSetTypeOfLine != 0)
+    {
+      aDrawer->LineAspect()->SetTypeOfLine           (aChangeSet->TypeOfLine);
+      aDrawer->WireAspect()->SetTypeOfLine           (aChangeSet->TypeOfLine);
+      aDrawer->FreeBoundaryAspect()->SetTypeOfLine   (aChangeSet->TypeOfLine);
+      aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
+      aDrawer->SeenLineAspect()->SetTypeOfLine       (aChangeSet->TypeOfLine);
+    }
     if (aChangeSet->ToSetTransparency != 0)
     {
       aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
@@ -2013,6 +2233,14 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
     {
       aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
     }
+    if (aChangeSet->ToEnableIsoOnTriangulation != -1)
+    {
+      aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
+    }
+    if (aChangeSet->ToSetMaxParamValue != 0)
+    {
+      aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
+    }
 
     // redisplay all objects in context
     for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
@@ -2096,6 +2324,15 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
       {
         aCtx->UnsetWidth (aPrs, Standard_False);
       }
+      else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
+      {
+        aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
+        toRedisplay = Standard_True;
+      }
+      else if (aChangeSet->ToSetSensitivity != 0)
+      {
+        aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
+      }
       if (!aDrawer.IsNull())
       {
         if (aChangeSet->ToSetShowFreeBoundary == 1)
@@ -2126,6 +2363,19 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
           aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
           toRedisplay = Standard_True;
         }
+        if (aChangeSet->ToSetTypeOfLine != 0)
+        {
+          aDrawer->LineAspect()->SetTypeOfLine           (aChangeSet->TypeOfLine);
+          aDrawer->WireAspect()->SetTypeOfLine           (aChangeSet->TypeOfLine);
+          aDrawer->FreeBoundaryAspect()->SetTypeOfLine   (aChangeSet->TypeOfLine);
+          aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
+          aDrawer->SeenLineAspect()->SetTypeOfLine       (aChangeSet->TypeOfLine);
+          toRedisplay = Standard_True;
+        }
+        if (aChangeSet->ToSetMaxParamValue != 0)
+        {
+          aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
+        }
       }
 
       for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
@@ -2153,6 +2403,15 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
           {
             aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
           }
+          if (aChangeSet->ToSetMaxParamValue != 0)
+          {
+            Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
+            aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
+          }
+          if (aChangeSet->ToSetSensitivity != 0)
+          {
+            aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
+          }
         }
       }
       if (toDisplay)
@@ -2168,29 +2427,6 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
         aCtx->Redisplay (aColoredPrs, Standard_False);
       }
     }
-    else
-    {
-      Handle(NIS_InteractiveObject) aNisObj = Handle(NIS_InteractiveObject)::DownCast (aPrsIter.CurrentTrs());
-      Handle(NIS_Triangulated)      aNisTri = Handle(NIS_Triangulated)::DownCast (aNisObj);
-      if (!aNisObj.IsNull())
-      {
-        if (aChangeSet->ToSetTransparency != 0)
-        {
-          aNisObj->SetTransparency (aChangeSet->Transparency);
-        }
-      }
-      if (!aNisTri.IsNull())
-      {
-        if (aChangeSet->ToSetColor != 0)
-        {
-          aNisTri->SetColor (aChangeSet->Color);
-        }
-        if (aChangeSet->ToSetLineWidth != 0)
-        {
-          aNisTri->SetLineWidth (aChangeSet->LineWidth);
-        }
-      }
-    }
   }
   return 0;
 }
@@ -2231,14 +2467,14 @@ static int VDonly2 (Draw_Interpretor& ,
   if (anArgIter >= theArgNb)
   {
     // display only selected objects
-    if (aCtx->NbCurrents() < 1)
+    if (aCtx->NbSelected() < 1)
     {
       return 0;
     }
 
-    for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
+    for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
     {
-      aDispSet.Add (aCtx->Current());
+      aDispSet.Add (aCtx->SelectedInteractive());
     }
   }
   else
@@ -2249,18 +2485,12 @@ static int VDonly2 (Draw_Interpretor& ,
       TCollection_AsciiString aName = theArgVec[anArgIter];
       if (GetMapOfAIS().IsBound2 (aName))
       {
-        const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
-        if (anObj->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
+        const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
+        if (!aShape.IsNull())
         {
-          const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
           aCtx->Display (aShape, Standard_False);
+          aDispSet.Add (aShape);
         }
-        else if (anObj->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
-        {
-          Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
-          TheNISContext()->Display (aShape);
-        }
-        aDispSet.Add (anObj);
       }
     }
   }
@@ -2273,16 +2503,11 @@ static int VDonly2 (Draw_Interpretor& ,
       continue;
     }
 
-    if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
+    const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
+    if (aShape.IsNull())
     {
-      const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
       aCtx->Erase (aShape, Standard_False);
     }
-    else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
-    {
-      const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
-      TheNISContext()->Erase (aShape);
-    }
   }
   return 0;
 }
@@ -2379,57 +2604,31 @@ int VRemove (Draw_Interpretor& theDI,
         continue;
       }
 
-      const Handle(Standard_Transient)& aTransientObj = GetMapOfAIS().Find2 (aName);
-
-      const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aTransientObj);
-      if (!anIO.IsNull())
+      const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
+      if (anIO->GetContext() != aCtx)
       {
-        if (anIO->GetContext() != aCtx)
-        {
-          theDI << aName.ToCString() << " was not displayed in current context.\n";
-          theDI << "Please activate view with this object displayed and try again.\n";
-          continue;
-        }
-
-        anIONameList.Append (aName);
+        theDI << aName.ToCString() << " was not displayed in current context.\n";
+        theDI << "Please activate view with this object displayed and try again.\n";
         continue;
       }
 
-      const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (aTransientObj);
-      if (!aNisIO.IsNull())
-      {
-        anIONameList.Append (aName);
-      }
+      anIONameList.Append (aName);
+      continue;
     }
   }
-  else if (aCtx->NbCurrents() > 0
-        || TheNISContext()->GetSelected().Extent() > 0)
+  else if (aCtx->NbSelected() > 0)
   {
     for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
          anIter.More(); anIter.Next())
     {
       const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
-      if (!anIO.IsNull())
+      if (!aCtx->IsSelected (anIO))
       {
-        if (!aCtx->IsCurrent (anIO))
-        {
-          continue;
-        }
-
-        anIONameList.Append (anIter.Key2());
         continue;
       }
 
-      const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
-      if (!aNisIO.IsNull())
-      {
-        if (!TheNISContext()->IsSelected (aNisIO))
-        {
-          continue;
-        }
-
-        anIONameList.Append (anIter.Key2());
-      }
+      anIONameList.Append (anIter.Key2());
+      continue;
     }
   }
 
@@ -2438,25 +2637,10 @@ int VRemove (Draw_Interpretor& theDI,
        anIter.More(); anIter.Next())
   {
     const Handle(AIS_InteractiveObject) anIO  = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
-    if (!anIO.IsNull())
+    aCtx->Remove (anIO, Standard_False);
+    if (toPrintInfo)
     {
-      aCtx->Remove (anIO, Standard_False);
-      if (toPrintInfo)
-      {
-        theDI << anIter.Value().ToCString() << " was removed\n";
-      }
-    }
-    else
-    {
-      const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
-      if (!aNisIO.IsNull())
-      {
-        TheNISContext()->Remove (aNisIO);
-        if (toPrintInfo)
-        {
-          theDI << anIter.Value().ToCString() << " was removed\n";
-        }
-      }
+      theDI << anIter.Value().ToCString() << " was removed\n";
     }
     if (!isContextOnly)
     {
@@ -2563,17 +2747,9 @@ int VErase (Draw_Interpretor& theDI,
           aCtx->Erase (anIO, Standard_False);
         }
       }
-      else
-      {
-        const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj);
-        if (!aNisIO.IsNull())
-        {
-          TheNISContext()->Erase (aNisIO);
-        }
-      }
     }
   }
-  else if (!toEraseAll && aCtx->NbCurrents() > 0)
+  else if (!toEraseAll && aCtx->NbSelected() > 0)
   {
     // Erase selected objects
     for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
@@ -2581,7 +2757,7 @@ int VErase (Draw_Interpretor& theDI,
     {
       const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
       if (!anIO.IsNull()
-       && aCtx->IsCurrent (anIO))
+       && aCtx->IsSelected (anIO))
       {
         theDI << anIter.Key2().ToCString() << " ";
         if (toEraseInView)
@@ -2613,14 +2789,6 @@ int VErase (Draw_Interpretor& theDI,
           aCtx->Erase (anIO, Standard_False);
         }
       }
-      else
-      {
-        const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
-        if (!aNisIO.IsNull())
-        {
-          TheNISContext()->Erase (aNisIO);
-        }
-      }
     }
   }
 
@@ -2683,31 +2851,15 @@ static int VDisplayAll (Draw_Interpretor& ,
   for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
        anIter.More(); anIter.Next())
   {
-    if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
-    {
-      const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
-      aCtx->Erase (aShape, Standard_False);
-    }
-    else if (anIter.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject)))
-    {
-      const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
-      TheNISContext()->Erase (aShape);
-    }
+    const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
+    aCtx->Erase (aShape, Standard_False);
   }
 
   for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
        anIter.More(); anIter.Next())
   {
-    if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject)))
-    {
-      const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
-      aCtx->Display (aShape, Standard_False);
-    }
-    else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject)))
-    {
-      Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
-      TheNISContext()->Display (aShape);
-    }
+    const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
+    aCtx->Display (aShape, Standard_False);
   }
   return 0;
 }
@@ -2762,7 +2914,7 @@ inline void bndPresentation (Draw_Interpretor&                  theDI,
     }
     case BndAction_Show:
     {
-      Handle(Graphic3d_Structure) aPrs = thePrs->Presentation();
+      Handle(Graphic3d_Structure) aPrs (thePrs->Presentation());
       aPrs->CStructure()->HighlightColor.r = 0.988235f;
       aPrs->CStructure()->HighlightColor.g = 0.988235f;
       aPrs->CStructure()->HighlightColor.b = 0.988235f;
@@ -2855,12 +3007,12 @@ int VBounding (Draw_Interpretor& theDI,
       bndPresentation (theDI, aPrs, aName, anAction);
     }
   }
-  else if (aCtx->NbCurrents() > 0)
+  else if (aCtx->NbSelected() > 0)
   {
     // remove all currently selected objects
-    for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
+    for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
     {
-      Handle(AIS_InteractiveObject) anIO = aCtx->Current();
+      Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
       Handle(PrsMgr_Presentation)   aPrs = findPresentation (aCtx, anIO, aMode);
       if (!aPrs.IsNull())
       {
@@ -3487,12 +3639,9 @@ static int VDisplay2 (Draw_Interpretor& theDI,
                                     ? aCtx->DisplayMode()
                                     : 0);
         Standard_Integer aSelMode = -1;
-        if ( isSelectable ==  1
-         || (isSelectable == -1
-          && aCtx->GetAutoActivateSelection()
-          && aShape->GetTransformPersistenceMode() == 0))
+        if (isSelectable ==  1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
         {
-          aSelMode = aShape->HasSelectionMode() ? aShape->SelectionMode() : -1;
+          aSelMode = aShape->GlobalSelectionMode();
         }
 
         aCtx->Display (aShape, aDispMode, aSelMode,
@@ -3514,86 +3663,74 @@ static int VDisplay2 (Draw_Interpretor& theDI,
       continue;
     }
 
-    Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
-    if (anObj->IsKind (STANDARD_TYPE (AIS_InteractiveObject)))
+    Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
+    if (isMutable != -1)
     {
-      Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj);
-      if (isMutable != -1)
-      {
-        aShape->SetMutable (isMutable == 1);
-      }
-      if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
-      {
-        aShape->SetZLayer (aZLayer);
-      }
-      if (toSetTrsfPers)
-      {
-        aShape->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
-      }
-      if (anObjDispMode != -2)
-      {
-        aShape->SetDisplayMode (anObjDispMode);
-      }
-      if (anObjHighMode != -2)
+      aShape->SetMutable (isMutable == 1);
+    }
+    if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
+    {
+      aShape->SetZLayer (aZLayer);
+    }
+    if (toSetTrsfPers)
+    {
+      aShape->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
+    }
+    if (anObjDispMode != -2)
+    {
+      aShape->SetDisplayMode (anObjDispMode);
+    }
+    if (anObjHighMode != -2)
+    {
+      aShape->SetHilightMode (anObjHighMode);
+    }
+    Standard_Integer aDispMode = aShape->HasDisplayMode()
+                                ? aShape->DisplayMode()
+                                : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
+                                ? aCtx->DisplayMode()
+                                : 0);
+    Standard_Integer aSelMode = -1;
+    if (isSelectable ==  1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
+    {
+      aSelMode = aShape->GlobalSelectionMode();
+    }
+
+    if (aShape->Type() == AIS_KOI_Datum)
+    {
+      aCtx->Display (aShape, Standard_False);
+    }
+    else
+    {
+      theDI << "Display " << aName.ToCString() << "\n";
+
+      // update the Shape in the AIS_Shape
+      TopoDS_Shape      aNewShape = GetShapeFromName (aName.ToCString());
+      Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
+      if (!aShapePrs.IsNull())
       {
-        aShape->SetHilightMode (anObjHighMode);
+        if (!aShapePrs->Shape().IsEqual (aNewShape))
+        {
+          toReDisplay = Standard_True;
+        }
+        aShapePrs->Set (aNewShape);
       }
-      Standard_Integer aDispMode = aShape->HasDisplayMode()
-                                  ? aShape->DisplayMode()
-                                  : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
-                                  ? aCtx->DisplayMode()
-                                  : 0);
-      Standard_Integer aSelMode = -1;
-      if ( isSelectable ==  1
-       || (isSelectable == -1
-        && aCtx->GetAutoActivateSelection()
-        && aShape->GetTransformPersistenceMode() == 0))
+      if (toReDisplay)
       {
-        aSelMode = aShape->HasSelectionMode() ? aShape->SelectionMode() : -1;
+        aCtx->Redisplay (aShape, Standard_False);
       }
 
-      if (aShape->Type() == AIS_KOI_Datum)
+      if (aSelMode == -1)
       {
-        aCtx->Display (aShape, Standard_False);
+        aCtx->Erase (aShape);
       }
-      else
+      aCtx->Display (aShape, aDispMode, aSelMode,
+                     Standard_False, aShape->AcceptShapeDecomposition(),
+                     aDispStatus);
+      if (toDisplayInView)
       {
-        theDI << "Display " << aName.ToCString() << "\n";
-
-        // update the Shape in the AIS_Shape
-        TopoDS_Shape      aNewShape = GetShapeFromName (aName.ToCString());
-        Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
-        if (!aShapePrs.IsNull())
-        {
-          if (!aShapePrs->Shape().IsEqual (aNewShape))
-          {
-            toReDisplay = Standard_True;
-          }
-          aShapePrs->Set (aNewShape);
-        }
-        if (toReDisplay)
-        {
-          aCtx->Redisplay (aShape, Standard_False);
-        }
-
-        if (aSelMode == -1)
-        {
-          aCtx->Erase (aShape);
-        }
-        aCtx->Display (aShape, aDispMode, aSelMode,
-                       Standard_False, aShape->AcceptShapeDecomposition(),
-                       aDispStatus);
-        if (toDisplayInView)
-        {
-          aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
-        }
+        aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
       }
     }
-    else if (anObj->IsKind (STANDARD_TYPE (NIS_InteractiveObject)))
-    {
-      Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj);
-      TheNISContext()->Display (aShape);
-    }
   }
 
   return 0;
@@ -3957,11 +4094,11 @@ static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const ch
         // 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()->NbCurrents()>0 ){
-          TheAISContext()->UnhilightCurrents(Standard_False);
+        if (TheAISContext()->NbSelected()>0 ){
+          TheAISContext()->UnhilightSelected(Standard_False);
 
-          for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){
-            ListOfIO.Append(TheAISContext()->Current() );
+          for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
+            ListOfIO.Append(TheAISContext()->SelectedInteractive() );
          }
        }
 
@@ -4009,7 +4146,7 @@ static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const ch
          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()->Interactive();
+           Handle(AIS_InteractiveObject) aIO=TheAISContext()->SelectedInteractive();
 
 
            if (HaveMode(aIO,aMode) ) {
@@ -4272,11 +4409,12 @@ static Standard_Integer VState (Draw_Interpretor& theDI,
       const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->DetectedEntity();
       Handle(SelectMgr_EntityOwner) anOwner    = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
       Handle(AIS_InteractiveObject) anObj      = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
-      SelectMgr_SelectingVolumeManager aMgr = anObj->HasTransformation() ? aSelector->GetManager().Transform (anObj->InversedTransformation())
-                                                                         : aSelector->GetManager();
+      SelectMgr_SelectingVolumeManager aMgr =
+        anObj->HasTransformation() ? aSelector->GetManager().ScaleAndTransform (1, anObj->InversedTransformation())
+                                   : aSelector->GetManager();
       SelectBasics_PickResult aResult;
       anEntity->Matches (aMgr, aResult);
-      NCollection_Vec3<Standard_Real> aDetectedPnt = aMgr.DetectedPoint (aResult.Depth());
+      gp_Pnt aDetectedPnt = aMgr.DetectedPoint (aResult.Depth());
 
       TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
       aName.LeftJustify (20, ' ');
@@ -4285,7 +4423,7 @@ static Standard_Integer VState (Draw_Interpretor& theDI,
                " Depth: %+.3f Distance: %+.3f Point: %+.3f %+.3f %+.3f",
                aResult.Depth(),
                aResult.DistToGeomCenter(),
-               aDetectedPnt.x(), aDetectedPnt.y(), aDetectedPnt.z());
+               aDetectedPnt.X(), aDetectedPnt.Y(), aDetectedPnt.Z());
       theDI << "  " << aName
             << anInfoStr
             << " (" << anEntity->DynamicType()->Name() << ")"
@@ -4340,12 +4478,12 @@ static Standard_Integer VState (Draw_Interpretor& theDI,
     return 0;
   }
 
-  if (aCtx->NbCurrents() > 0
+  if (aCtx->NbSelected() > 0
    && !toShowAll)
   {
-    for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
+    for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
     {
-      Handle(AIS_InteractiveObject) anObj = aCtx->Current();
+      Handle(AIS_InteractiveObject) anObj = aCtx->SelectedInteractive();
       TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
       aName.LeftJustify (20, ' ');
       theDI << aName << " ";
@@ -4530,7 +4668,7 @@ TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
       result = TheAISContext()->SelectedShape();
     else{
       Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
-      result = (*((Handle(AIS_Shape)*) &IO))->Shape();
+      result = Handle(AIS_Shape)::DownCast (IO)->Shape();
     }
   }
 
@@ -4597,7 +4735,7 @@ Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
       thearr->SetValue(i,TheAISContext()->SelectedShape());
     else{
       Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
-      thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape());
+      thearr->SetValue(i,Handle(AIS_Shape)::DownCast (IO)->Shape());
     }
   }
 
@@ -4726,7 +4864,7 @@ static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const c
     else
     {
       Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
-      aShape = (*((Handle(AIS_Shape)*) &IO))->Shape();
+      aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
     }
 
     TCollection_AsciiString aCurrentName = aName;
@@ -4877,7 +5015,7 @@ static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** a
     if(dimension_status == -1)
       TheAISContext()->Erase(curio,Standard_False);
     else {
-      AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
+      AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
       if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
          (dimension_status==1 && KOD != AIS_KOD_NONE))
        TheAISContext()->Erase(curio,Standard_False);
@@ -4910,7 +5048,7 @@ static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char**
     if(dimension_status == -1)
       TheAISContext()->Display(curio,Standard_False);
     else {
-      AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension();
+      AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
       if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
          (dimension_status==1 && KOD != AIS_KOD_NONE))
        TheAISContext()->Display(curio,Standard_False);
@@ -4935,6 +5073,239 @@ static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a
   return 0;
 }
 
+//===============================================================================================
+//function : VBsdf
+//purpose  :
+//===============================================================================================
+static int VBsdf (Draw_Interpretor& theDi,
+                  Standard_Integer  theArgsNb,
+                  const char**      theArgVec)
+{
+  Handle(V3d_View)   aView   = ViewerTest::CurrentView();
+  Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
+  if (aView.IsNull()
+   || aViewer.IsNull())
+  {
+    std::cerr << "No active viewer!\n";
+    return 1;
+  }
+
+  ViewerTest_CmdParser aCmd;
+
+  aCmd.AddDescription ("Adjusts parameters of material BSDF:");
+  aCmd.AddOption ("print|echo|p", "Print BSDF");
+
+  aCmd.AddOption ("kd", "Weight of the Lambertian BRDF");
+  aCmd.AddOption ("kr", "Weight of the reflection BRDF");
+  aCmd.AddOption ("kt", "Weight of the transmission BTDF");
+  aCmd.AddOption ("ks", "Weight of the glossy Blinn BRDF");
+  aCmd.AddOption ("le", "Self-emitted radiance");
+
+  aCmd.AddOption ("fresnel|f", "Fresnel coefficients; Allowed fresnel formats are: Constant x, Schlick x y z, Dielectric x, Conductor x y");
+
+  aCmd.AddOption ("roughness|r",    "Roughness of material (Blinn's exponent)");
+  aCmd.AddOption ("absorpCoeff|af", "Absorption coeff (only for transparent material)");
+  aCmd.AddOption ("absorpColor|ac", "Absorption color (only for transparent material)");
+
+  aCmd.AddOption ("normalize|n", "Normalize BSDF coefficients");
+
+  aCmd.Parse (theArgsNb, theArgVec);
+
+  if (aCmd.HasOption ("help"))
+  {
+    theDi.PrintHelp (theArgVec[0]);
+    return 0;
+  }
+
+  TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
+
+  // find object
+  ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
+  if (!aMap.IsBound2 (aName) )
+  {
+    std::cerr << "Use 'vdisplay' before" << "\n";
+    return 1;
+  }
+
+  Handle(AIS_InteractiveObject) anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
+  Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
+  Graphic3d_BSDF aBSDF = aMaterial.BSDF();
+
+  if (aCmd.HasOption ("print"))
+  {
+    Graphic3d_Vec4 aFresnel = aBSDF.Fresnel.Serialize();
+
+    std::cout << "\n"
+      << "Kd:               " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
+      << "Kr:               " << aBSDF.Kr.r() << ", " << aBSDF.Kr.g() << ", " << aBSDF.Kr.b() << "\n"
+      << "Kt:               " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
+      << "Ks:               " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
+      << "Le:               " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n"
+      << "Fresnel:          ";
+
+    if (aFresnel.x() >= 0.f)
+    {
+      std::cout
+        << "|Schlick| " << aFresnel.x() << ", " << aFresnel.y() << ", " << aFresnel.z() << "\n";
+    }
+    else if (aFresnel.x() >= -1.5f)
+    {
+      std::cout
+        << "|Constant| " << aFresnel.z() << "\n";
+    }
+    else if (aFresnel.x() >= -2.5f)
+    {
+      std::cout
+        << "|Conductor| " << aFresnel.y() << ", " << aFresnel.z() << "\n";
+    }
+    else
+    {
+      std::cout
+        << "|Dielectric| " << aFresnel.y() << "\n";
+    }
+
+
+    std::cout 
+      << "Roughness:        " << aBSDF.Roughness           << "\n"
+      << "Absorption coeff: " << aBSDF.AbsorptionCoeff     << "\n"
+      << "Absorption color: " << aBSDF.AbsorptionColor.r() << ", "
+                              << aBSDF.AbsorptionColor.g() << ", "
+                              << aBSDF.AbsorptionColor.b() << "\n";
+
+    return 0;
+  }
+
+  if (aCmd.HasOption ("roughness", 1, Standard_True))
+  {
+    aCmd.Arg ("roughness", 0);
+    aBSDF.Roughness = aCmd.ArgFloat ("roughness");
+  }
+
+  if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
+  {
+    aBSDF.AbsorptionCoeff = aCmd.ArgFloat ("absorpCoeff");
+  }
+
+  if (aCmd.HasOption ("absorpColor", 3, Standard_True))
+  {
+    aBSDF.AbsorptionColor = aCmd.ArgVec3f ("absorpColor");
+  }
+
+  if (aCmd.HasOption ("kd", 3))
+  {
+    aBSDF.Kd = aCmd.ArgVec3f ("kd");
+  }
+  else if (aCmd.HasOption ("kd", 1, Standard_True))
+  {
+    aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
+  }
+
+  if (aCmd.HasOption ("kr", 3))
+  {
+    aBSDF.Kr = aCmd.ArgVec3f ("kr");
+  }
+  else if (aCmd.HasOption ("kr", 1, Standard_True))
+  {
+    aBSDF.Kr = Graphic3d_Vec3 (aCmd.ArgFloat ("kr"));
+  }
+
+  if (aCmd.HasOption ("kt", 3))
+  {
+    aBSDF.Kt = aCmd.ArgVec3f ("kt");
+  }
+  else if (aCmd.HasOption ("kt", 1, Standard_True))
+  {
+    aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
+  }
+
+  if (aCmd.HasOption ("ks", 3))
+  {
+    aBSDF.Ks = aCmd.ArgVec3f ("ks");
+  }
+  else if (aCmd.HasOption ("ks", 1, Standard_True))
+  {
+    aBSDF.Ks = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
+  }
+
+  if (aCmd.HasOption ("le", 3))
+  {
+    aBSDF.Le = aCmd.ArgVec3f ("le");
+  }
+  else if (aCmd.HasOption ("le", 1, Standard_True))
+  {
+    aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
+  }
+
+  const std::string aFresnelErrorMessage =
+    "Error! Wrong Fresnel type. Allowed types are: Constant x, Schlick x y z, Dielectric x, Conductor x y.\n";
+
+  if (aCmd.HasOption ("fresnel", 4)) // Schlick: type, x, y ,z
+  {
+    std::string aFresnelType = aCmd.Arg ("fresnel", 0);
+    std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
+
+    if (aFresnelType == "schlick")
+    {
+      aBSDF.Fresnel = Graphic3d_Fresnel::CreateSchlick (
+        Graphic3d_Vec3 (static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
+                        static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())),
+                        static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 3).c_str()))));
+    }
+    else
+    {
+      std::cout << aFresnelErrorMessage;
+    }
+  }
+  else if (aCmd.HasOption ("fresnel", 3)) // Conductor: type, x, y
+  {
+    std::string aFresnelType = aCmd.Arg ("fresnel", 0);
+    std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
+
+    if (aFresnelType == "conductor")
+    {
+      aBSDF.Fresnel = Graphic3d_Fresnel::CreateConductor (
+        static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
+        static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())));
+    }
+    else
+    {
+      std::cout << aFresnelErrorMessage;
+    }
+  }
+  else if (aCmd.HasOption ("fresnel", 2)) // Dielectric, Constant: type, x
+  {
+    std::string aFresnelType = aCmd.Arg ("fresnel", 0);
+    std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
+
+    if (aFresnelType == "dielectric")
+    {
+      aBSDF.Fresnel = Graphic3d_Fresnel::CreateDielectric (
+        static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
+    }
+    else if (aFresnelType == "constant")
+    {
+      aBSDF.Fresnel = Graphic3d_Fresnel::CreateConstant (
+        static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
+    }
+    else
+    {
+      std::cout << aFresnelErrorMessage;
+    }
+  }
+
+  if (aCmd.HasOption ("normalize"))
+  {
+    aBSDF.Normalize();
+  }
+
+  aMaterial.SetBSDF (aBSDF);
+  anIObj->SetMaterial (aMaterial);
+
+  aView->Redraw();
+
+  return 0;
+}
+
 //==============================================================================
 //function : VLoadSelection
 //purpose  : Adds given objects to map of AIS and loads selection primitives for them
@@ -4995,8 +5366,11 @@ static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
   {
     const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
 
-    const Handle(AIS_InteractiveObject)& aShape = GetMapOfAIS().IsBound2 (aName) ?
-      Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName)) : GetAISShapeFromName (aName.ToCString());
+    Handle(AIS_InteractiveObject) aShape;
+    if (GetMapOfAIS().IsBound2 (aName))
+      aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
+    else
+      aShape = GetAISShapeFromName (aName.ToCString());
 
     if (!aShape.IsNull())
     {
@@ -5006,7 +5380,7 @@ static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
       }
 
       aCtx->Load (aShape, -1, Standard_False);
-      aCtx->Activate (aShape, aShape->SelectionMode(), Standard_True);
+      aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
     }
   }
 
@@ -5182,16 +5556,16 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
                  "Lists all objects displayed in 3D viewer",
                  __FILE__,VDir,group);
 
+#ifdef HAVE_FREEIMAGE
+  #define DUMP_FORMATS "{png|bmp|jpg|gif}"
+#else
+  #define DUMP_FORMATS "{ppm}"
+#endif
   theCommands.Add("vdump",
-    #ifdef HAVE_FREEIMAGE
-              "vdump <filename>.{png|bmp|jpg|gif} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
-      "\n\t\t:                                    [width Width=0 height Height=0]"
-      "\n\t\t: Dumps content of the active view into PNG, BMP, JPEG or GIF file",
-    #else
-              "vdump <filename>.{ppm} [rgb|rgba|depth=rgb] [mono|left|right=mono]"
-      "\n\t\t:                        [width Width=0 height Height=0]"
-      "\n\t\t: Dumps content of the active view into PPM image file",
-    #endif
+              "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
+      "\n\t\t:       [-buffer rgb|rgba|depth=rgb]"
+      "\n\t\t:       [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
+      "\n\t\t: Dumps content of the active view into image file",
                  __FILE__,VDump,group);
 
   theCommands.Add("vsub",      "vsub 0/1 (off/on) [obj]        : Subintensity(on/off) of selected objects",
@@ -5199,15 +5573,19 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
 
   theCommands.Add("vaspects",
               "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
-      "\n\t\t:          [-setvisibility 0|1]"
-      "\n\t\t:          [-setcolor ColorName] [-setcolor R G B] [-unsetcolor]"
-      "\n\t\t:          [-setmaterial MatName] [-unsetmaterial]"
-      "\n\t\t:          [-settransparency Transp] [-unsettransparency]"
-      "\n\t\t:          [-setwidth LineWidth] [-unsetwidth]"
+      "\n\t\t:          [-setVisibility 0|1]"
+      "\n\t\t:          [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
+      "\n\t\t:          [-setMaterial MatName] [-unsetMaterial]"
+      "\n\t\t:          [-setTransparency Transp] [-unsetTransparency]"
+      "\n\t\t:          [-setWidth LineWidth] [-unsetWidth]"
+      "\n\t\t:          [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
       "\n\t\t:          [-freeBoundary {off/on | 0/1}]"
       "\n\t\t:          [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
       "\n\t\t:          [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
       "\n\t\t:          [-subshapes subname1 [subname2 [...]]]"
+      "\n\t\t:          [-isoontriangulation 0|1]"
+      "\n\t\t:          [-setMaxParamValue {value}]"
+      "\n\t\t:          [-setSensitivity {selection_mode} {value}]"
       "\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."
@@ -5275,7 +5653,9 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
                  __FILE__,VClearSensi,group);
 
   theCommands.Add("vselprecision",
-                 "vselprecision : vselprecision [tolerance_value]",
+                 "vselprecision [-unset] [tolerance_value]"
+                  "\n\t\t  Manages selection precision or prints current value if no parameter is passed."
+                  "\n\t\t  -unset - restores default selection tolerance behavior, based on individual entity tolerance",
                  __FILE__,VSelPrecision,group);
 
   theCommands.Add("vperf",
@@ -5379,6 +5759,23 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
     "\n\t\t:   [0|1] - turn off | on auto activation of selection",
     __FILE__, VAutoActivateSelection, group);
 
+  theCommands.Add("vbsdf", "vbsdf [name] [options]"
+    "\nAdjusts parameters of material BSDF:"
+    "\n    -help : Shows this message"
+    "\n    -print : Print BSDF"
+    "\n    -kd : Weight of the Lambertian BRDF"
+    "\n    -kr : Weight of the reflection BRDF"
+    "\n    -kt : Weight of the transmission BTDF"
+    "\n    -ks : Weight of the glossy Blinn BRDF"
+    "\n    -le : Self-emitted radiance"
+    "\n    -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
+    "\n               Schlick x y z, Dielectric x, Conductor x y"
+    "\n    -roughness : Roughness of material (Blinn's exponent)"
+    "\n    -absorpcoeff : Absorption coefficient (only for transparent material)"
+    "\n    -absorpcolor : Absorption color (only for transparent material)"
+    "\n    -normalize : Normalize BSDF coefficients",
+    __FILE__, VBsdf, group);
+
 }
 
 //=====================================================================