0031456: Visualization - move out Dimensions and Relations from package AIS to PrsDims
[occt.git] / src / ViewerTest / ViewerTest.cxx
index d52acd1..029a5c4 100644 (file)
 #include <TopExp_Explorer.hxx>
 #include <BRepAdaptor_Curve.hxx>
 #include <StdSelect_ShapeTypeFilter.hxx>
-#include <AIS.hxx>
 #include <AIS_ColoredShape.hxx>
 #include <AIS_InteractiveObject.hxx>
 #include <AIS_Trihedron.hxx>
 #include <AIS_Axis.hxx>
-#include <AIS_Relation.hxx>
+#include <PrsDim.hxx>
+#include <PrsDim_Relation.hxx>
 #include <AIS_TypeFilter.hxx>
 #include <AIS_SignatureFilter.hxx>
 #include <AIS_ListOfInteractive.hxx>
@@ -50,6 +50,7 @@
 #include <Graphic3d_CStructure.hxx>
 #include <Graphic3d_Texture2Dmanual.hxx>
 #include <Graphic3d_GraphicDriver.hxx>
+#include <Graphic3d_MediaTextureSet.hxx>
 #include <Image_AlienPixMap.hxx>
 #include <OSD_File.hxx>
 #include <Prs3d_Drawer.hxx>
@@ -81,9 +82,164 @@ extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
 #define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
 #define DEFAULT_MATERIAL           Graphic3d_NOM_BRASS
 
+namespace
+{
+
+  const Standard_Integer THE_MAX_INTEGER_COLOR_COMPONENT = 255;
+
+  const Standard_ShortReal THE_MAX_REAL_COLOR_COMPONENT = 1.0f;
+
+  //! Parses string and get an integer color component (only values within range 0 .. 255 are allowed)
+  //! @param theColorComponentString the string representing the color component
+  //! @param theIntegerColorComponent an integer color component that is a result of parsing
+  //! @return true if parsing was successful, or false otherwise
+  static bool parseNumericalColorComponent (const Standard_CString theColorComponentString,
+                                            Standard_Integer&      theIntegerColorComponent)
+  {
+    Standard_Integer anIntegerColorComponent;
+    if (!Draw::ParseInteger (theColorComponentString, anIntegerColorComponent))
+    {
+      return false;
+    }
+    if ((anIntegerColorComponent < 0) || (anIntegerColorComponent > THE_MAX_INTEGER_COLOR_COMPONENT))
+    {
+      return false;
+    }
+    theIntegerColorComponent = anIntegerColorComponent;
+    return true;
+  }
+
+  //! Parses the string and gets a real color component from it (only values within range 0.0 .. 1.0 are allowed)
+  //! @param theColorComponentString the string representing the color component
+  //! @param theRealColorComponent a real color component that is a result of parsing
+  //! @return true if parsing was successful, or false otherwise
+  static bool parseNumericalColorComponent (const Standard_CString theColorComponentString,
+                                            Standard_ShortReal&    theRealColorComponent)
+  {
+    Standard_Real aRealColorComponent;
+    if (!Draw::ParseReal (theColorComponentString, aRealColorComponent))
+    {
+      return false;
+    }
+    const Standard_ShortReal aShortRealColorComponent = static_cast<Standard_ShortReal> (aRealColorComponent);
+    if ((aShortRealColorComponent < 0.0f) || (aShortRealColorComponent > THE_MAX_REAL_COLOR_COMPONENT))
+    {
+      return false;
+    }
+    theRealColorComponent = aShortRealColorComponent;
+    return true;
+  }
+
+  //! Parses the string and gets a real color component from it (integer values 2 .. 255 are scaled to the 0.0 .. 1.0
+  //! range, values 0 and 1 are leaved as they are)
+  //! @param theColorComponentString the string representing the color component
+  //! @param theColorComponent a color component that is a result of parsing
+  //! @return true if parsing was successful, or false otherwise
+  static bool parseColorComponent (const Standard_CString theColorComponentString,
+                                   Standard_ShortReal&    theColorComponent)
+  {
+    Standard_Integer anIntegerColorComponent;
+    if (parseNumericalColorComponent (theColorComponentString, anIntegerColorComponent))
+    {
+      if (anIntegerColorComponent == 1)
+      {
+        theColorComponent = THE_MAX_REAL_COLOR_COMPONENT;
+      }
+      else
+      {
+        theColorComponent = anIntegerColorComponent * 1.0f / THE_MAX_INTEGER_COLOR_COMPONENT;
+      }
+      return true;
+    }
+    return parseNumericalColorComponent (theColorComponentString, theColorComponent);
+  }
+
+  //! Parses the array of strings and gets an integer color (only values within range 0 .. 255 are allowed and at least
+  //! one of components must be greater than 1)
+  //! @tparam TheNumber the type of resulting color vector elements
+  //! @param theNumberOfColorComponents the number of color components
+  //! @param theColorComponentStrings the array of strings representing color components
+  //! @param theNumericalColor a 4-component vector that is a result of parsing
+  //! @return true if parsing was successful, or false otherwise
+  template <typename TheNumber>
+  static bool parseNumericalColor (Standard_Integer&            theNumberOfColorComponents,
+                                   const char* const* const     theColorComponentStrings,
+                                   NCollection_Vec4<TheNumber>& theNumericalColor)
+  {
+    for (Standard_Integer aColorComponentIndex = 0; aColorComponentIndex < theNumberOfColorComponents;
+         ++aColorComponentIndex)
+    {
+      const char* const aColorComponentString = theColorComponentStrings[aColorComponentIndex];
+      TheNumber         aNumericalColorComponent;
+      if (parseNumericalColorComponent (aColorComponentString, aNumericalColorComponent))
+      {
+        theNumericalColor[aColorComponentIndex] = aNumericalColorComponent;
+      }
+      else
+      {
+        if (aColorComponentIndex == 3)
+        {
+          theNumberOfColorComponents = 3;
+        }
+        else
+        {
+          return false;
+        }
+      }
+    }
+    return true;
+  }
+
+  //! Parses an array of strings and get an integer color (only values within range 0 .. 255 are allowed and at least
+  //! one of components must be greater than 1)
+  //! @param theNumberOfColorComponents the number of color components
+  //! @param theColorComponentStrings the array of strings representing color components
+  //! @param theColor a color that is a result of parsing
+  //! @return true if parsing was successful, or false otherwise
+  static bool parseIntegerColor (Standard_Integer&        theNumberOfColorComponents,
+                                 const char* const* const theColorComponentStrings,
+                                 Quantity_ColorRGBA&      theColor)
+  {
+    const Standard_Integer THE_COLOR_COMPONENT_NOT_PARSED = -1;
+    Graphic3d_Vec4i        anIntegerColor (THE_COLOR_COMPONENT_NOT_PARSED);
+    if (!parseNumericalColor (theNumberOfColorComponents, theColorComponentStrings, anIntegerColor)
+      || anIntegerColor.maxComp() <= 1)
+    {
+      return false;
+    }
+    if (anIntegerColor.a() == THE_COLOR_COMPONENT_NOT_PARSED)
+    {
+      anIntegerColor.a() = THE_MAX_INTEGER_COLOR_COMPONENT;
+    }
+
+    const Graphic3d_Vec4 aRealColor = Graphic3d_Vec4 (anIntegerColor) / static_cast<Standard_ShortReal> (THE_MAX_INTEGER_COLOR_COMPONENT);
+    theColor = Quantity_ColorRGBA (Quantity_ColorRGBA::Convert_sRGB_To_LinearRGB (aRealColor));
+    return true;
+  }
+
+  //! Parses an array of strings and get a real color (only values within range 0.0 .. 1.0 are allowed)
+  //! @param theNumberOfColorComponents the number of color components
+  //! @param theColorComponentStrings the array of strings representing color components
+  //! @param theColor a color that is a result of parsing
+  //! @return true if parsing was successful, or false otherwise
+  static bool parseRealColor (Standard_Integer&        theNumberOfColorComponents,
+                              const char* const* const theColorComponentStrings,
+                              Quantity_ColorRGBA&      theColor)
+  {
+    Graphic3d_Vec4 aRealColor (THE_MAX_REAL_COLOR_COMPONENT);
+    if (!parseNumericalColor (theNumberOfColorComponents, theColorComponentStrings, aRealColor))
+    {
+      return false;
+    }
+    theColor = Quantity_ColorRGBA (aRealColor);
+    return true;
+  }
+
+} // namespace
+
 //=======================================================================
-//function : GetColorFromName
-//purpose  : get the Quantity_NameOfColor from a string
+// function : GetColorFromName
+// purpose  : get the Quantity_NameOfColor from a string
 //=======================================================================
 
 Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
@@ -93,67 +249,48 @@ Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theNam
   return aColor;
 }
 
-
 //=======================================================================
-//function : parseColor
-//purpose  :
+// function : parseColor
+// purpose  :
 //=======================================================================
-Standard_Integer ViewerTest::parseColor (Standard_Integer  theArgNb,
-                                         const char**      theArgVec,
-                                         Quantity_ColorRGBA& theColor,
-                                         bool theToParseAlpha)
+Standard_Integer ViewerTest::parseColor (const Standard_Integer   theArgNb,
+                                         const char* const* const theArgVec,
+                                         Quantity_ColorRGBA&      theColor,
+                                         const bool               theToParseAlpha)
 {
-  Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
-  if (theArgNb >= 1
-   && Quantity_Color::ColorFromName (theArgVec[0], aColor))
+  if ((theArgNb >= 1) && Quantity_ColorRGBA::ColorFromHex (theArgVec[0], theColor, !theToParseAlpha))
   {
-    theColor = Quantity_ColorRGBA (aColor);
-    if (theArgNb >= 2
-     && theToParseAlpha)
+    return 1;
+  }
+  if (theArgNb >= 1 && Quantity_ColorRGBA::ColorFromName (theArgVec[0], theColor))
+  {
+    if (theArgNb >= 2 && theToParseAlpha)
     {
-      const TCollection_AsciiString anAlphaStr (theArgVec[1]);
-      if (anAlphaStr.IsRealValue())
+      const Standard_CString anAlphaStr = theArgVec[1];
+      Standard_ShortReal     anAlphaComponent;
+      if (parseColorComponent (anAlphaStr, anAlphaComponent))
       {
-        float anAlpha = (float )anAlphaStr.RealValue();
-        if (anAlpha < 0.0f || anAlpha > 1.0f)
-        {
-          std::cout << "Syntax error: alpha should be within range 0..1!\n";
-          return 0;
-        }
+        theColor.SetAlpha (anAlphaComponent);
         return 2;
       }
     }
     return 1;
   }
-  else if (theArgNb >= 3)
+  if (theArgNb >= 3)
   {
-    Graphic3d_Vec4 anRgba;
-    Standard_Integer aNbComps = Min (theArgNb, theToParseAlpha ? 4 : 3);
-    for (int aCompIter = 0; aCompIter < aNbComps; ++aCompIter)
+    const Standard_Integer aNumberOfColorComponentsToParse = Min (theArgNb, theToParseAlpha ? 4 : 3);
+    Standard_Integer aNumberOfColorComponentsParsed = aNumberOfColorComponentsToParse;
+    if (parseIntegerColor (aNumberOfColorComponentsParsed, theArgVec, theColor))
     {
-      const TCollection_AsciiString anRgbaStr (theArgVec[aCompIter]);
-      if (!anRgbaStr.IsRealValue())
-      {
-        if (aCompIter == 3)
-        {
-          anRgba.a() = 1.0f;
-          aNbComps = 3;
-          break;
-        }
-        return 0;
-      }
-
-      anRgba[aCompIter] = (float )anRgbaStr.RealValue();
-      if (anRgba[aCompIter] < 0.0 || anRgba[aCompIter] > 1.0)
-      {
-        std::cout << "Error: RGBA color values should be within range 0..1!\n";
-        return 0;
-      }
+      return aNumberOfColorComponentsParsed;
     }
-    theColor = Quantity_ColorRGBA (anRgba);
-    return aNbComps;
+    aNumberOfColorComponentsParsed = aNumberOfColorComponentsToParse;
+    if (parseRealColor (aNumberOfColorComponentsParsed, theArgVec, theColor))
+    {
+      return aNumberOfColorComponentsParsed;
+    }
+    return 0;
   }
-
   return 0;
 }
 
@@ -201,43 +338,74 @@ void ViewerTest::GetSelectedShapes (TopTools_ListOfShape& theSelectedShapes)
 //function : ParseLineType
 //purpose  :
 //=======================================================================
-Standard_Boolean ViewerTest::ParseLineType (Standard_CString   theArg,
-                                            Aspect_TypeOfLine& theType)
+Standard_Boolean ViewerTest::ParseLineType (Standard_CString theArg,
+                                            Aspect_TypeOfLine& theType,
+                                            uint16_t& thePattern)
 {
   TCollection_AsciiString aTypeStr (theArg);
   aTypeStr.LowerCase();
-  if (aTypeStr == "empty")
+  if (aTypeStr == "empty"
+   || aTypeStr == "-1")
   {
     theType = Aspect_TOL_EMPTY;
+    thePattern = Graphic3d_Aspects::DefaultLinePatternForType (theType);
   }
-  else if (aTypeStr == "solid")
+  else if (aTypeStr == "solid"
+        || aTypeStr == "0")
   {
     theType = Aspect_TOL_SOLID;
+    thePattern = Graphic3d_Aspects::DefaultLinePatternForType (theType);
   }
-  else if (aTypeStr == "dot")
+  else if (aTypeStr == "dot"
+        || aTypeStr == "2")
   {
     theType = Aspect_TOL_DOT;
+    thePattern = Graphic3d_Aspects::DefaultLinePatternForType (theType);
   }
-  else if (aTypeStr == "dash")
+  else if (aTypeStr == "dash"
+        || aTypeStr == "1")
   {
     theType = Aspect_TOL_DASH;
+    thePattern = Graphic3d_Aspects::DefaultLinePatternForType (theType);
   }
-  else if (aTypeStr == "dotdash")
+  else if (aTypeStr == "dotdash"
+        || aTypeStr == "3")
   {
     theType = Aspect_TOL_DOTDASH;
+    thePattern = Graphic3d_Aspects::DefaultLinePatternForType (theType);
   }
-  else if (aTypeStr.IsIntegerValue())
+  else
   {
-    const int aTypeInt = aTypeStr.IntegerValue();
-    if (aTypeInt < -1 || aTypeInt >= Aspect_TOL_USERDEFINED)
+    if (aTypeStr.StartsWith ("0x"))
+    {
+      aTypeStr = aTypeStr.SubString (3, aTypeStr.Length());
+    }
+
+    if (aTypeStr.Length() != 4
+    || !std::isxdigit (static_cast<unsigned char> (aTypeStr.Value (1)))
+    || !std::isxdigit (static_cast<unsigned char> (aTypeStr.Value (2)))
+    || !std::isxdigit (static_cast<unsigned char> (aTypeStr.Value (3)))
+    || !std::isxdigit (static_cast<unsigned char> (aTypeStr.Value (4))))
     {
       return Standard_False;
     }
-    theType = (Aspect_TypeOfLine )aTypeInt;
-  }
-  else
-  {
-    return Standard_False;
+
+    std::stringstream aStream;
+    aStream << std::setbase (16) << aTypeStr.ToCString();
+    if (aStream.fail())
+    {
+      return Standard_False;
+    }
+
+    Standard_Integer aNumber = -1;
+    aStream >> aNumber;
+    if (aStream.fail())
+    {
+      return Standard_False;
+    }
+
+    thePattern = (uint16_t )aNumber;
+    theType = Graphic3d_Aspects::DefaultLineTypeForPattern (thePattern);
   }
   return Standard_True;
 }
@@ -380,6 +548,14 @@ Standard_Boolean ViewerTest::ParseShadingModel (Standard_CString              th
   {
     theModel = Graphic3d_TOSM_FRAGMENT;
   }
+  else if (aTypeStr == "pbr")
+  {
+    theModel = Graphic3d_TOSM_PBR;
+  }
+  else if (aTypeStr == "pbr_facet")
+  {
+    theModel = Graphic3d_TOSM_PBR_FACET;
+  }
   else if (aTypeStr == "default"
         || aTypeStr == "def")
   {
@@ -401,6 +577,75 @@ Standard_Boolean ViewerTest::ParseShadingModel (Standard_CString              th
   return Standard_True;
 }
 
+//=======================================================================
+//function : parseZLayer
+//purpose  :
+//=======================================================================
+Standard_Boolean ViewerTest::parseZLayer (Standard_CString theArg,
+                                          Standard_Boolean theToAllowInteger,
+                                          Graphic3d_ZLayerId& theLayer)
+{
+  TCollection_AsciiString aName (theArg);
+  aName.LowerCase();
+  if (aName == "default"
+   || aName == "def")
+  {
+    theLayer = Graphic3d_ZLayerId_Default;
+  }
+  else if (aName == "top")
+  {
+    theLayer = Graphic3d_ZLayerId_Top;
+  }
+  else if (aName == "topmost")
+  {
+    theLayer = Graphic3d_ZLayerId_Topmost;
+  }
+  else if (aName == "overlay"
+        || aName == "toposd")
+  {
+    theLayer = Graphic3d_ZLayerId_TopOSD;
+  }
+  else if (aName == "underlay"
+        || aName == "botosd")
+  {
+    theLayer = Graphic3d_ZLayerId_BotOSD;
+  }
+  else if (aName == "undefined")
+  {
+    theLayer = Graphic3d_ZLayerId_UNKNOWN;
+  }
+  else if (!GetAISContext().IsNull())
+  {
+    const Handle(V3d_Viewer)& aViewer = ViewerTest::GetAISContext()->CurrentViewer();
+    TColStd_SequenceOfInteger aLayers;
+    aViewer->GetAllZLayers (aLayers);
+    for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
+    {
+      Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
+      if (TCollection_AsciiString::IsSameString (aSettings.Name(), aName, Standard_False))
+      {
+        theLayer = aLayeriter.Value();
+        return true;
+      }
+    }
+
+    if (!theToAllowInteger
+     || !aName.IsIntegerValue())
+    {
+      return false;
+    }
+    Graphic3d_ZLayerId aLayer = aName.IntegerValue();
+    if (aLayer == Graphic3d_ZLayerId_UNKNOWN
+     || std::find (aLayers.begin(), aLayers.end(), aLayer) != aLayers.end())
+    {
+      theLayer = aLayer;
+      return true;
+    }
+    return false;
+  }
+  return true;
+}
+
 //=======================================================================
 //function : GetTypeNames
 //purpose  :
@@ -556,15 +801,7 @@ Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiStrin
   return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
 }
 
-static TColStd_MapOfInteger theactivatedmodes(8);
-static TColStd_ListOfTransient theEventMgrs;
-
-static void VwrTst_InitEventMgr(const Handle(V3d_View)& aView,
-                                const Handle(AIS_InteractiveContext)& Ctx)
-{
-  theEventMgrs.Clear();
-  theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
-}
+static NCollection_List<Handle(ViewerTest_EventManager)> theEventMgrs;
 
 static Handle(V3d_View)&  a3DView()
 {
@@ -621,17 +858,15 @@ void ViewerTest::UnsetEventManager()
 
 void ViewerTest::ResetEventManager()
 {
-  const Handle(V3d_View) aView = ViewerTest::CurrentView();
-  VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
+  theEventMgrs.Clear();
+  theEventMgrs.Prepend (new ViewerTest_EventManager (ViewerTest::CurrentView(), ViewerTest::GetAISContext()));
 }
 
 Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
 {
-  Handle(ViewerTest_EventManager) EM;
-  if(theEventMgrs.IsEmpty()) return EM;
-  Handle(Standard_Transient) Tr =  theEventMgrs.First();
-  EM = Handle(ViewerTest_EventManager)::DownCast (Tr);
-  return EM;
+  return !theEventMgrs.IsEmpty()
+        ? theEventMgrs.First()
+        : Handle(ViewerTest_EventManager)();
 }
 
 //=======================================================================
@@ -851,14 +1086,55 @@ static Standard_Integer VClearSensi (Draw_Interpretor& ,
 //purpose  : To list the displayed object with their attributes
 //==============================================================================
 static int VDir (Draw_Interpretor& theDI,
-                 Standard_Integer ,
-                 const char** )
+                 Standard_Integer theNbArgs,
+                 const char** theArgVec)
 {
-  for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
-       anIter.More(); anIter.Next())
+  TCollection_AsciiString aMatch;
+  Standard_Boolean toFormat = Standard_False;
+  for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
   {
-    theDI << "\t" << anIter.Key2() << "\n";
+    TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
+    anArgCase.LowerCase();
+    if (anArgCase == "-list"
+     || anArgCase == "-format")
+    {
+      toFormat = Standard_True;
+    }
+    else if (aMatch.IsEmpty())
+    {
+      aMatch = theArgVec[anArgIter];
+    }
+    else
+    {
+      std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
+      return 1;
+    }
+  }
+
+  TCollection_AsciiString aRes;
+  for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
+  {
+    if (!aMatch.IsEmpty())
+    {
+      const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aMatch + "' '" + anIter.Key2() + "'";
+      if (theDI.Eval (aCheck.ToCString()) == 0
+      && *theDI.Result() != '1')
+      {
+        continue;
+      }
+    }
+
+    if (toFormat)
+    {
+      aRes += TCollection_AsciiString("\t") + anIter.Key2() + "\n";
+    }
+    else
+    {
+      aRes += anIter.Key2() + " ";
+    }
   }
+  theDI.Reset();
+  theDI << aRes;
   return 0;
 }
 
@@ -912,6 +1188,10 @@ static Standard_Integer VDump (Draw_Interpretor& theDI,
       {
         aParams.BufferType = Graphic3d_BT_RGB;
       }
+      else if (aBufArg == "red")
+      {
+        aParams.BufferType = Graphic3d_BT_Red;
+      }
       else if (aBufArg == "depth")
       {
         aParams.BufferType = Graphic3d_BT_Depth;
@@ -978,6 +1258,11 @@ static Standard_Integer VDump (Draw_Interpretor& theDI,
     {
       aParams.BufferType = Graphic3d_BT_RGB;
     }
+    else if (anArg == "-red"
+          || anArg ==  "red")
+    {
+      aParams.BufferType = Graphic3d_BT_Red;
+    }
     else if (anArg == "-depth"
           || anArg ==  "depth")
     {
@@ -1058,6 +1343,7 @@ static Standard_Integer VDump (Draw_Interpretor& theDI,
     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;
+    case Graphic3d_BT_Red:                 aFormat = Image_Format_Gray;  break;
   }
 
   switch (aStereoPair)
@@ -1521,12 +1807,14 @@ struct ViewerTest_AspectsChangeSet
 
   Standard_Integer             ToSetColor;
   Quantity_Color               Color;
+  Standard_Integer             ToSetBackFaceColor;
+  Quantity_Color               BackFaceColor;
 
   Standard_Integer             ToSetLineWidth;
   Standard_Real                LineWidth;
 
   Standard_Integer             ToSetTypeOfLine;
-  Aspect_TypeOfLine            TypeOfLine;
+  uint16_t                     StippleLinePattern;
 
   Standard_Integer             ToSetTypeOfMarker;
   Aspect_TypeOfMarker          TypeOfMarker;
@@ -1607,10 +1895,12 @@ struct ViewerTest_AspectsChangeSet
     Visibility        (1),
     ToSetColor        (0),
     Color             (DEFAULT_COLOR),
+    ToSetBackFaceColor(0),
+    BackFaceColor     (DEFAULT_COLOR),
     ToSetLineWidth    (0),
     LineWidth         (1.0),
     ToSetTypeOfLine   (0),
-    TypeOfLine        (Aspect_TOL_SOLID),
+    StippleLinePattern(0xFFFF),
     ToSetTypeOfMarker (0),
     TypeOfMarker      (Aspect_TOM_PLUS),
     ToSetMarkerSize   (0),
@@ -1668,6 +1958,7 @@ struct ViewerTest_AspectsChangeSet
         && ToSetTransparency      == 0
         && ToSetAlphaMode         == 0
         && ToSetColor             == 0
+        && ToSetBackFaceColor     == 0
         && ToSetMaterial          == 0
         && ToSetShowFreeBoundary  == 0
         && ToSetFreeBoundaryColor == 0
@@ -1718,12 +2009,6 @@ struct ViewerTest_AspectsChangeSet
       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)
-    {
-      std::cout << "Error: unknown material " << MatName << ".\n";
-      isOk = Standard_False;
-    }
     if (FreeBoundaryWidth <= 0.0
      || FreeBoundaryWidth >  10.0)
     {
@@ -1746,7 +2031,7 @@ struct ViewerTest_AspectsChangeSet
       isOk = Standard_False;
     }
     if (ToSetShadingModel == 1
-    && (ShadingModel < Graphic3d_TOSM_DEFAULT || ShadingModel > Graphic3d_TOSM_FRAGMENT))
+    && (ShadingModel < Graphic3d_TOSM_DEFAULT || ShadingModel > Graphic3d_TOSM_PBR_FACET))
     {
       std::cout << "Error: unknown shading model " << ShadingModelName << ".\n";
       isOk = Standard_False;
@@ -1797,11 +2082,11 @@ struct ViewerTest_AspectsChangeSet
        || theDrawer->HasOwnSeenLineAspect())
       {
         toRecompute = theDrawer->SetOwnLineAspects() || toRecompute;
-        theDrawer->LineAspect()->SetTypeOfLine           (TypeOfLine);
-        theDrawer->WireAspect()->SetTypeOfLine           (TypeOfLine);
-        theDrawer->FreeBoundaryAspect()->SetTypeOfLine   (TypeOfLine);
-        theDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (TypeOfLine);
-        theDrawer->SeenLineAspect()->SetTypeOfLine       (TypeOfLine);
+        theDrawer->LineAspect()->Aspect()->SetLinePattern (StippleLinePattern);
+        theDrawer->WireAspect()->Aspect()->SetLinePattern (StippleLinePattern);
+        theDrawer->FreeBoundaryAspect()->Aspect()->SetLinePattern (StippleLinePattern);
+        theDrawer->UnFreeBoundaryAspect()->Aspect()->SetLinePattern (StippleLinePattern);
+        theDrawer->SeenLineAspect()->Aspect()->SetLinePattern (StippleLinePattern);
       }
     }
     if (ToSetTypeOfMarker != 0)
@@ -1902,6 +2187,15 @@ struct ViewerTest_AspectsChangeSet
         theDrawer->ShadingAspect()->Aspect()->SetShadingModel (ShadingModel);
       }
     }
+    if (ToSetBackFaceColor != 0)
+    {
+      if (ToSetBackFaceColor != -1
+       || theDrawer->HasOwnShadingAspect())
+      {
+        toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute;
+        theDrawer->ShadingAspect()->SetColor (BackFaceColor, Aspect_TOFM_BACK_SIDE);
+      }
+    }
     if (ToSetAlphaMode != 0)
     {
       if (ToSetAlphaMode != -1
@@ -2033,7 +2327,7 @@ struct ViewerTest_AspectsChangeSet
 //function : VAspects
 //purpose  :
 //==============================================================================
-static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
+static Standard_Integer VAspects (Draw_Interpretor& theDI,
                                   Standard_Integer  theArgNb,
                                   const char**      theArgVec)
 {
@@ -2084,6 +2378,9 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
 
   // parse syntax of legacy commands
   bool toParseAliasArgs = false;
+  Standard_Boolean toDump = 0;
+  Standard_Boolean toCompactDump = 0;
+  Standard_Integer aDumpDepth = -1;
   if (aCmdName == "vsetwidth")
   {
     if (aNames.IsEmpty()
@@ -2117,6 +2414,11 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
       aNames.Remove (aNames.Length());
       isOk = Standard_True;
     }
+    else if (Quantity_Color::ColorFromHex (aNames.Last().ToCString(), aChangeSet->Color))
+    {
+      aNames.Remove (aNames.Length());
+      isOk = Standard_True;
+    }
     else if (aNames.Length() >= 3)
     {
       const char* anArgVec[3] =
@@ -2166,9 +2468,13 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
       return 1;
     }
     aChangeSet->ToSetMaterial = 1;
-    aChangeSet->MatName  = aNames.Last();
-    aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
+    aChangeSet->MatName = aNames.Last();
     aNames.Remove (aNames.Length());
+    if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString(), aChangeSet->Material))
+    {
+      std::cout << "Syntax error: unknown material '" << aChangeSet->MatName << "'.\n";
+      return 1;
+    }
   }
   else if (aCmdName == "vunsetmaterial")
   {
@@ -2233,7 +2539,7 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
         aChangeSet->FaceBoundaryColor = Quantity_Color (aNames.Value (3).IntegerValue() / 255.0,
                                                         aNames.Value (4).IntegerValue() / 255.0,
                                                         aNames.Value (5).IntegerValue() / 255.0,
-                                                        Quantity_TOC_RGB);
+                                                        Quantity_TOC_sRGB);
         aNames.Remove (5);
         aNames.Remove (4);
         aNames.Remove (3);
@@ -2434,6 +2740,10 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
     }
     else if (anArg == "-setcolor"
           || anArg == "-color"
+          || anArg == "-setbackfacecolor"
+          || anArg == "-backfacecolor"
+          || anArg == "-setbackcolor"
+          || anArg == "-backcolor"
           || anArg == "-setfaceboundarycolor"
           || anArg == "-setboundarycolor"
           || anArg == "-faceboundarycolor"
@@ -2463,6 +2773,14 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
         aChangeSet->ToSetFaceBoundaryColor = 1;
         aChangeSet->FaceBoundaryColor = aColor;
       }
+      else if (anArg == "-setbackfacecolor"
+            || anArg == "-backfacecolor"
+            || anArg == "-setbackcolor"
+            || anArg == "-backcolor")
+      {
+        aChangeSet->ToSetBackFaceColor = 1;
+        aChangeSet->BackFaceColor = aColor;
+      }
       else
       {
         aChangeSet->ToSetColor = 1;
@@ -2490,18 +2808,20 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
         return 1;
       }
       Aspect_TypeOfLine aLineType = Aspect_TOL_EMPTY;
-      if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aLineType))
+      uint16_t aLinePattern = 0xFFFF;
+      if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aLineType, aLinePattern))
       {
         std::cout << "Error: wrong syntax at " << anArg << "\n";
         return 1;
       }
+
       if (anArg == "-setedgetype"
        || anArg == "-setedgestype"
        || anArg == "-edgetype"
        || anArg == "-edgestype"
        || aCmdName == "vsetedgetype")
       {
-        aChangeSet->TypeOfEdge = aLineType;
+        aChangeSet->TypeOfEdge = Graphic3d_Aspects::DefaultLineTypeForPattern (aLinePattern);
         aChangeSet->ToSetTypeOfEdge = 1;
       }
       else if (anArg == "-setfaceboundarystyle"
@@ -2513,12 +2833,12 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
             || anArg == "-boundarytype"
             || aCmdName == "vshowfaceboundary")
       {
-        aChangeSet->TypeOfFaceBoundaryLine = aLineType;
+        aChangeSet->TypeOfFaceBoundaryLine = Graphic3d_Aspects::DefaultLineTypeForPattern (aLinePattern);
         aChangeSet->ToSetTypeOfFaceBoundaryLine = 1;
       }
       else
       {
-        aChangeSet->TypeOfLine = aLineType;
+        aChangeSet->StippleLinePattern = aLinePattern;
         aChangeSet->ToSetTypeOfLine = 1;
       }
     }
@@ -2594,8 +2914,12 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
         return 1;
       }
       aChangeSet->ToSetMaterial = 1;
-      aChangeSet->MatName  = theArgVec[anArgIter];
-      aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
+      aChangeSet->MatName = theArgVec[anArgIter];
+      if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString(), aChangeSet->Material))
+      {
+        std::cout << "Syntax error: unknown material '" << aChangeSet->MatName << "'.\n";
+        return 1;
+      }
     }
     else if (anArg == "-unsetmat"
           || anArg == "-unsetmaterial")
@@ -2965,7 +3289,7 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
       aChangeSet->ToSetLineWidth = -1;
       aChangeSet->LineWidth = 1.0;
       aChangeSet->ToSetTypeOfLine = -1;
-      aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
+      aChangeSet->StippleLinePattern = 0xFFFF;
       aChangeSet->ToSetTypeOfMarker = -1;
       aChangeSet->TypeOfMarker = Aspect_TOM_PLUS;
       aChangeSet->ToSetMarkerSize = -1;
@@ -2977,6 +3301,8 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
       aChangeSet->AlphaCutoff = 0.5f;
       aChangeSet->ToSetColor = -1;
       aChangeSet->Color = DEFAULT_COLOR;
+      //aChangeSet->ToSetBackFaceColor = -1; // should be reset by ToSetColor
+      //aChangeSet->BackFaceColor = DEFAULT_COLOR;
       aChangeSet->ToSetMaterial = -1;
       aChangeSet->Material = Graphic3d_NOM_DEFAULT;
       aChangeSet->ToSetShowFreeBoundary = -1;
@@ -3013,6 +3339,25 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
       aChangeSet->ToSetTypeOfEdge = -1;
       aChangeSet->TypeOfEdge = Aspect_TOL_SOLID;
     }
+    else if (anArg == "-dumpjson")
+    {
+      toDump = Standard_True;
+    }
+    else if (anArg == "-dumpcompact")
+    {
+      toCompactDump = Standard_False;
+      if (++anArgIter >= theArgNb && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toCompactDump))
+        ++anArgIter;
+    }
+    else if (anArg == "-dumpdepth")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+      aDumpDepth = Draw::Atoi (theArgVec[anArgIter]);
+    }
     else
     {
       std::cout << "Error: wrong syntax at " << anArg << "\n";
@@ -3073,6 +3418,16 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
         aCtx->Redisplay (aPrs, Standard_False);
       }
     }
+    if (toDump)
+    {
+      Standard_SStream aStream;
+      aDrawer->DumpJson (aStream, aDumpDepth);
+
+      if (toCompactDump)
+        theDI << Standard_Dump::Text (aStream);
+      else
+        theDI << Standard_Dump::FormatJson (aStream);
+    }
     return 0;
   }
 
@@ -3226,6 +3581,16 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
       {
         aPrs->SynchronizeAspects();
       }
+
+      if (toDump)
+      {
+        Standard_SStream aStream;
+        aDrawer->DumpJson (aStream);
+
+        theDI << aName << ": \n";
+        theDI << Standard_Dump::FormatJson (aStream);
+        theDI << "\n";
+      }
     }
   }
   return 0;
@@ -3327,6 +3692,7 @@ int VRemove (Draw_Interpretor& theDI,
   Standard_Boolean isContextOnly = Standard_False;
   Standard_Boolean toRemoveAll   = Standard_False;
   Standard_Boolean toPrintInfo   = Standard_True;
+  Standard_Boolean toFailOnError = Standard_True;
 
   Standard_Integer anArgIter = 1;
   for (; anArgIter < theArgNb; ++anArgIter)
@@ -3345,6 +3711,11 @@ int VRemove (Draw_Interpretor& theDI,
     {
       toPrintInfo = Standard_False;
     }
+    else if (anArg == "-noerror"
+          || anArg == "-nofail")
+    {
+      toFailOnError = Standard_False;
+    }
     else if (anUpdateTool.parseRedrawMode (anArg))
     {
       continue;
@@ -3374,23 +3745,48 @@ int VRemove (Draw_Interpretor& theDI,
   {
     for (; anArgIter < theArgNb; ++anArgIter)
     {
-      TCollection_AsciiString aName = theArgVec[anArgIter];
-      Handle(AIS_InteractiveObject) anIO;
-      if (!GetMapOfAIS().Find2 (aName, anIO))
+      const TCollection_AsciiString aName (theArgVec[anArgIter]);
+      if (aName.Search ("*") != -1)
       {
-        theDI << aName << " was not bound to some object.\n";
+        for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName aPrsIter (GetMapOfAIS()); aPrsIter.More(); aPrsIter.Next())
+        {
+          if (aPrsIter.Key1()->GetContext() != aCtx)
+          {
+            continue;
+          }
+          const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aName + "' '" + aPrsIter.Key2() + "'";
+          if (theDI.Eval (aCheck.ToCString()) == 0
+          && *theDI.Result() == '1')
+          {
+            anIONameList.Append (aPrsIter.Key2());
+          }
+        }
+        theDI.Reset();
         continue;
       }
 
-      if (anIO->GetContext() != aCtx)
+      Handle(AIS_InteractiveObject) anIO;
+      if (!GetMapOfAIS().Find2 (aName, anIO))
       {
-        theDI << aName << " was not displayed in current context.\n";
-        theDI << "Please activate view with this object displayed and try again.\n";
-        continue;
+        if (toFailOnError)
+        {
+          std::cout << "Syntax error: '" << aName << "' was not bound to some object.\n";
+          return 1;
+        }
+      }
+      else if (anIO->GetContext() != aCtx)
+      {
+        if (toFailOnError)
+        {
+          std::cout << "Syntax error: '" << aName << "' was not displayed in current context.\n"
+                    << "Please activate view with this object displayed and try again.\n";
+          return 1;
+        }
+      }
+      else
+      {
+        anIONameList.Append (aName);
       }
-
-      anIONameList.Append (aName);
-      continue;
     }
   }
   else if (aCtx->NbSelected() > 0)
@@ -3416,7 +3812,7 @@ int VRemove (Draw_Interpretor& theDI,
     aCtx->Remove (anIO, Standard_False);
     if (toPrintInfo)
     {
-      theDI << anIter.Value() << " was removed\n";
+      theDI << anIter.Value() << " ";
     }
     if (!isContextOnly)
     {
@@ -3448,6 +3844,7 @@ int VErase (Draw_Interpretor& theDI,
 
   Standard_Integer anArgIter = 1;
   Standard_Boolean toEraseInView = Standard_False;
+  Standard_Boolean toFailOnError = Standard_True;
   TColStd_SequenceOfAsciiString aNamesOfEraseIO;
   for (; anArgIter < theArgNb; ++anArgIter)
   {
@@ -3462,6 +3859,11 @@ int VErase (Draw_Interpretor& theDI,
     {
       toEraseInView = Standard_True;
     }
+    else if (anArgCase == "-noerror"
+          || anArgCase == "-nofail")
+    {
+      toFailOnError = Standard_False;
+    }
     else
     {
       aNamesOfEraseIO.Append (theArgVec[anArgIter]);
@@ -3477,28 +3879,53 @@ int VErase (Draw_Interpretor& theDI,
   if (!aNamesOfEraseIO.IsEmpty())
   {
     // Erase named objects
-    for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
+    NCollection_IndexedDataMap<Handle(AIS_InteractiveObject), TCollection_AsciiString> aPrsList;
+    for (TColStd_SequenceOfAsciiString::Iterator anIter (aNamesOfEraseIO); anIter.More(); anIter.Next())
     {
-      TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
-      Handle(AIS_InteractiveObject) anIO;
-      if (!GetMapOfAIS().Find2 (aName, anIO))
+      const TCollection_AsciiString& aName = anIter.Value();
+      if (aName.Search ("*") != -1)
       {
-        continue;
+        for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName aPrsIter (GetMapOfAIS()); aPrsIter.More(); aPrsIter.Next())
+        {
+          const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aName + "' '" + aPrsIter.Key2() + "'";
+          if (theDI.Eval (aCheck.ToCString()) == 0
+          && *theDI.Result() == '1')
+          {
+            aPrsList.Add (aPrsIter.Key1(), aPrsIter.Key2());
+          }
+        }
+        theDI.Reset();
       }
-
-      theDI << aName << " ";
-      if (!anIO.IsNull())
+      else
       {
-        if (toEraseInView)
+        Handle(AIS_InteractiveObject) anIO;
+        if (!GetMapOfAIS().Find2 (aName, anIO))
         {
-          aCtx->SetViewAffinity (anIO, aView, Standard_False);
+          if (toFailOnError)
+          {
+            std::cout << "Syntax error: '" << aName << "' is not found\n";
+            return 1;
+          }
         }
         else
         {
-          aCtx->Erase (anIO, Standard_False);
+          aPrsList.Add (anIO, aName);
         }
       }
     }
+
+    for (NCollection_IndexedDataMap<Handle(AIS_InteractiveObject), TCollection_AsciiString>::Iterator anIter (aPrsList); anIter.More(); anIter.Next())
+    {
+      theDI << anIter.Value() << " ";
+      if (toEraseInView)
+      {
+        aCtx->SetViewAffinity (anIter.Key(), aView, Standard_False);
+      }
+      else
+      {
+        aCtx->Erase (anIter.Key(), Standard_False);
+      }
+    }
   }
   else if (!toEraseAll && aCtx->NbSelected() > 0)
   {
@@ -3660,10 +4087,10 @@ inline void bndPresentation (Draw_Interpretor&                         theDI,
       Bnd_Box aBox;
       for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
       {
-        if (aPrsIter.Value().Mode() != theDispMode)
+        if (aPrsIter.Value()->Mode() != theDispMode)
           continue;
 
-        aBox = aPrsIter.Value().Presentation()->Presentation()->MinMaxValues();
+        aBox = aPrsIter.Value()->MinMaxValues();
       }
       gp_Pnt aMin = aBox.CornerMin();
       gp_Pnt aMax = aBox.CornerMax();
@@ -4065,6 +4492,38 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
     {
       toSetDefaults = true;
     }
+    else if ((aNameCase == "-video")
+           && anArgIter + 1 < theArgsNb)
+    {
+      const TCollection_AsciiString anInput (theArgVec[++anArgIter]);
+      Handle(Graphic3d_MediaTextureSet) aMedia = Handle(Graphic3d_MediaTextureSet)::DownCast (aTextureSetOld);
+      if (aMedia.IsNull())
+      {
+        aMedia = new Graphic3d_MediaTextureSet();
+      }
+      if (aMedia->Input() != anInput)
+      {
+        aMedia->OpenInput (anInput, false);
+      }
+      else
+      {
+        if (aMedia->SwapFrames()
+        && !aCtx->CurrentViewer()->ZLayerSettings (aTexturedIO->ZLayer()).IsImmediate())
+        {
+          ViewerTest::CurrentView()->Invalidate();
+        }
+      }
+      if (aTexturedIO->Attributes()->SetupOwnShadingAspect (aCtx->DefaultDrawer())
+       && aTexturedShape.IsNull())
+      {
+        aTexturedIO->SetToUpdate();
+      }
+
+      toComputeUV = aTextureSetOld.IsNull();
+      aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (true);
+      aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aMedia);
+      aTextureSetOld.Nullify();
+    }
     else if (aCommandName == "vtexture"
           && (aTextureVecNew.IsEmpty()
            || aNameCase.StartsWith ("-tex")))
@@ -4442,6 +4901,12 @@ static int VDisplay2 (Draw_Interpretor& theDI,
     std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
     return 1;
   }
+  if (theArgNb == 2
+   && TCollection_AsciiString (theArgVec[1]) == "*")
+  {
+    // alias
+    return VDisplayAll (theDI, 1, theArgVec);
+  }
 
   Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
   if (aCtx.IsNull())
@@ -4521,7 +4986,8 @@ static int VDisplay2 (Draw_Interpretor& theDI,
 
       anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
     }
-    else if (aNameCase == "-highmode"
+    else if (aNameCase == "-himode"
+          || aNameCase == "-highmode"
           || aNameCase == "-highlightmode")
     {
       if (++anArgIter >= theArgNb)
@@ -4634,22 +5100,17 @@ static int VDisplay2 (Draw_Interpretor& theDI,
         aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (aTrsfPers->Mode(), aPnt);
       }
     }
-    else if (aNameCase == "-layer")
+    else if (aNameCase == "-layer"
+          || aNameCase == "-zlayer")
     {
-      if (++anArgIter >= theArgNb)
-      {
-        std::cerr << "Error: wrong syntax at " << aName << ".\n";
-        return 1;
-      }
-
-      TCollection_AsciiString aValue (theArgVec[anArgIter]);
-      if (!aValue.IsIntegerValue())
+      ++anArgIter;
+      if (anArgIter >= theArgNb
+      || !ViewerTest::ParseZLayer (theArgVec[anArgIter], aZLayer)
+      ||  aZLayer == Graphic3d_ZLayerId_UNKNOWN)
       {
         std::cerr << "Error: wrong syntax at " << aName << ".\n";
         return 1;
       }
-
-      aZLayer = aValue.IntegerValue();
     }
     else if (aNameCase == "-view"
           || aNameCase == "-inview")
@@ -4703,10 +5164,28 @@ static int VDisplay2 (Draw_Interpretor& theDI,
         }
         if (anObjDispMode != -2)
         {
-          aShape->SetDisplayMode (anObjDispMode);
+          if (anObjDispMode == -1)
+          {
+            aShape->UnsetDisplayMode();
+          }
+          if (!aShape->AcceptDisplayMode (anObjDispMode))
+          {
+            std::cout << "Syntax error: " << aShape->DynamicType()->Name() << " rejects " << anObjDispMode << " display mode\n";
+            return 1;
+          }
+          else
+          {
+            aShape->SetDisplayMode (anObjDispMode);
+          }
         }
         if (anObjHighMode != -2)
         {
+          if (anObjHighMode != -1
+          && !aShape->AcceptDisplayMode (anObjHighMode))
+          {
+            std::cout << "Syntax error: " << aShape->DynamicType()->Name() << " rejects " << anObjHighMode << " display mode\n";
+            return 1;
+          }
           aShape->SetHilightMode (anObjHighMode);
         }
 
@@ -4962,17 +5441,17 @@ static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDe
   }
   else if (theObj->Type() == AIS_KOI_Relation)
   {
-    // AIS_Dimention and AIS_Relation
-    Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (theObj);
+    // PrsDim_Dimention and AIS_Relation
+    Handle(PrsDim_Relation) aRelation = Handle(PrsDim_Relation)::DownCast (theObj);
     switch (aRelation->KindOfDimension())
     {
-      case AIS_KOD_PLANEANGLE:     theDI << " AIS_AngleDimension"; break;
-      case AIS_KOD_LENGTH:         theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
-      case AIS_KOD_DIAMETER:       theDI << " AIS_DiameterDimension"; break;
-      case AIS_KOD_ELLIPSERADIUS:  theDI << " AIS_EllipseRadiusDimension"; break;
-      //case AIS_KOD_FILLETRADIUS:   theDI << " AIS_FilletRadiusDimension "; break;
-      case AIS_KOD_OFFSET:         theDI << " AIS_OffsetDimension"; break;
-      case AIS_KOD_RADIUS:         theDI << " AIS_RadiusDimension"; break;
+      case PrsDim_KOD_PLANEANGLE:     theDI << " PrsDim_AngleDimension"; break;
+      case PrsDim_KOD_LENGTH:         theDI << " PrsDim_Chamf2/3dDimension/PrsDim_LengthDimension"; break;
+      case PrsDim_KOD_DIAMETER:       theDI << " PrsDim_DiameterDimension"; break;
+      case PrsDim_KOD_ELLIPSERADIUS:  theDI << " PrsDim_EllipseRadiusDimension"; break;
+      //case PrsDim_KOD_FILLETRADIUS:   theDI << " PrsDim_FilletRadiusDimension "; break;
+      case PrsDim_KOD_OFFSET:         theDI << " PrsDim_OffsetDimension"; break;
+      case PrsDim_KOD_RADIUS:         theDI << " PrsDim_RadiusDimension"; break;
       default:                     theDI << " UNKNOWN dimension"; break;
     }
   }
@@ -5102,11 +5581,13 @@ static Standard_Integer VState (Draw_Interpretor& theDI,
     SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
     for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
     {
-      const SelectMgr_SortCriterion&              aPickData = aSelector->PickedData (aPickIter);
-      const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
-      Handle(SelectMgr_EntityOwner) anOwner    = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
-      Handle(AIS_InteractiveObject) anObj      = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
-      TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
+      const SelectMgr_SortCriterion&         aPickData = aSelector->PickedData (aPickIter);
+      const Handle(Select3D_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
+      const Handle(SelectMgr_EntityOwner)& anOwner = anEntity->OwnerId();
+      Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
+
+      TCollection_AsciiString aName;
+      GetMapOfAIS().Find1 (anObj, aName);
       aName.LeftJustify (20, ' ');
       char anInfoStr[512];
       Sprintf (anInfoStr,
@@ -5186,7 +5667,8 @@ static Standard_Integer VState (Draw_Interpretor& theDI,
       // handle whole object selection
       if (anOwner == anObj->GlobalSelOwner())
       {
-        TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
+        TCollection_AsciiString aName;
+        GetMapOfAIS().Find1 (anObj, aName);
         aName.LeftJustify (20, ' ');
         theDI << aName << " ";
         objInfo (aDetected, anObj, theDI);
@@ -5651,9 +6133,9 @@ 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)::DownCast (curio)->KindOfDimension();
-      if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
-         (dimension_status==1 && KOD != AIS_KOD_NONE))
+      PrsDim_KindOfDimension KOD = Handle(PrsDim_Relation)::DownCast (curio)->KindOfDimension();
+      if ((dimension_status==0 && KOD == PrsDim_KOD_NONE)||
+         (dimension_status==1 && KOD != PrsDim_KOD_NONE))
        TheAISContext()->Erase(curio,Standard_False);
     }
   }
@@ -5684,9 +6166,9 @@ 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)::DownCast (curio)->KindOfDimension();
-      if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
-         (dimension_status==1 && KOD != AIS_KOD_NONE))
+      PrsDim_KindOfDimension KOD = Handle(PrsDim_Relation)::DownCast (curio)->KindOfDimension();
+      if ((dimension_status==0 && KOD == PrsDim_KOD_NONE)||
+         (dimension_status==1 && KOD != PrsDim_KOD_NONE))
        TheAISContext()->Display(curio,Standard_False);
     }
 
@@ -5698,7 +6180,7 @@ static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char**
 
 static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
 {
-  ifstream s(a[1]);
+  std::ifstream s(a[1]);
   BRep_Builder builder;
   TopoDS_Shape shape;
   BRepTools::Read(shape, s, builder);
@@ -5728,7 +6210,7 @@ static int VBsdf (Draw_Interpretor& theDI,
 
   ViewerTest_CmdParser aCmd;
 
-  aCmd.AddDescription ("Adjusts parameters of material BSDF:");
+  aCmd.SetDescription ("Adjusts parameters of material BSDF:");
 
   aCmd.AddOption ("print|echo|p", "Prints BSDF");
 
@@ -5770,7 +6252,7 @@ static int VBsdf (Draw_Interpretor& theDI,
   }
 
   // find object
-  TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
+  TCollection_AsciiString aName (aCmd.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0).c_str());
   Handle(AIS_InteractiveObject) anIObj;
   if (!GetMapOfAIS().Find2 (aName, anIObj))
   {
@@ -6117,15 +6599,16 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
       __FILE__, VUpdate, group);
 
   theCommands.Add("verase",
-      "verase [-noupdate|-update] [-local] [name1] ...  [name n]"
+      "verase [-noupdate|-update] [-local] [name1] ...  [name n] [-noerror]"
       "\n\t\t: Erases selected or named objects."
       "\n\t\t: If there are no selected or named objects the whole viewer is erased."
       "\n\t\t: Option -local enables erasing of selected or named objects without"
-      "\n\t\t: closing local selection context.",
+      "\n\t\t: closing local selection context."
+      "\n\t\t: Option -noerror prevents exception on non-existing objects.",
       __FILE__, VErase, group);
 
   theCommands.Add("vremove",
-      "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ...  [name n]"
+      "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ...  [name n] [-noerror]"
       "or vremove [-context] -all to remove all objects"
       "\n\t\t: Removes selected or named objects."
       "\n\t\t  If -context is in arguments, the objects are not deleted"
@@ -6134,7 +6617,8 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
       "\n\t\t: closing local selection context. Empty local selection context will be"
       "\n\t\t: closed."
       "\n\t\t: Option -noupdate suppresses viewer redraw call."
-      "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
+      "\n\t\t: Option -noinfo suppresses displaying the list of removed objects."
+      "\n\t\t: Option -noerror prevents exception on non-existing objects.",
       __FILE__, VRemove, group);
 
   theCommands.Add("vdonly",
@@ -6179,7 +6663,10 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
                  __FILE__,VDispMode,group);
 
   theCommands.Add("vdir",
-                 "Lists all objects displayed in 3D viewer",
+              "vdir [mask] [-list]"
+      "\n\t\t: Lists all objects displayed in 3D viewer"
+      "\n\t\t:    mask - name filter like prefix*"
+      "\n\t\t:   -list - format list with new-line per name; OFF by default",
                  __FILE__,VDir,group);
 
 #ifdef HAVE_FREEIMAGE
@@ -6202,10 +6689,11 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
               "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:          [-setBackFaceColor Color]"
       "\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:          [-setLineType {solid|dash|dot|dotDash|0xHexPattern}] [-unsetLineType]"
       "\n\t\t:          [-setMarkerType {.|+|x|O|xcircle|pointcircle|ring1|ring2|ring3|ball|ImagePath}]"
       "\n\t\t:          [-unsetMarkerType]"
       "\n\t\t:          [-setMarkerSize Scale] [-unsetMarkerSize]"
@@ -6216,7 +6704,7 @@ 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:          [-setShadingModel {color|flat|gouraud|phong}]"
+      "\n\t\t:          [-setShadingModel {unlit|flat|gouraud|phong}]"
       "\n\t\t:          [-unsetShadingModel]"
       "\n\t\t:          [-setInterior {solid|hatch|hidenline|point}]"
       "\n\t\t:          [-unsetInterior] [-setHatch HatchStyle]"
@@ -6225,13 +6713,19 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
       "\n\t\t:          [-setDrawEdges {0|1}] [-setEdgeType LineType] [-setEdgeColor R G B] [-setQuadEdges {0|1}]"
       "\n\t\t:          [-setDrawSilhouette {0|1}]"
       "\n\t\t:          [-setAlphaMode {opaque|mask|blend|blendauto} [alphaCutOff=0.5]]"
+      "\n\t\t:          [-dumpJson]"
+      "\n\t\t:          [-dumpCompact {0|1}]"
+      "\n\t\t:          [-dumpDepth depth]"
+      "\n\t\t:          [-freeBoundary {off/on | 0/1}]"
       "\n\t\t: Manage presentation properties of all, selected or named objects."
       "\n\t\t: When -subshapes is specified than following properties will be"
       "\n\t\t: assigned to specified sub-shapes."
       "\n\t\t: When -defaults is specified than presentation properties will be"
       "\n\t\t: assigned to all objects that have not their own specified properties"
       "\n\t\t: and to all objects to be displayed in the future."
-      "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
+      "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier."
+      "\n\t\t: See also vlistcolors and vlistmaterials to list named colors and materials"
+      "\n\t\t: accepted by arguments -setMaterial and -setColor",
                  __FILE__,VAspects,group);
 
   theCommands.Add("vsetcolor",
@@ -6434,17 +6928,11 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
 #include <DBRep.hxx>
 #include <TopoDS_Face.hxx>
 #include <gp_Pln.hxx>
-#include <AIS_KindOfSurface.hxx>
 #include <BRepOffsetAPI_DraftAngle.hxx>
 #include <Precision.hxx>
 #include <BRepAlgo.hxx>
 #include <OSD_Environment.hxx>
 #include <DrawTrSurf.hxx>
-//#include <DbgTools.hxx>
-//#include <FeatAlgo_MakeLinearForm.hxx>
-
-
-
 
 //=======================================================================
 //function : IsValid
@@ -6460,14 +6948,14 @@ static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
   Standard_Boolean ToCheck = Standard_True;
   if (!checkValid.IsEmpty()) {
 #ifdef OCCT_DEBUG
-    cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
+    std::cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
 #endif
     if ( checkValid=="true" || checkValid=="TRUE" ) {
       ToCheck= Standard_False;
     }
   } else {
 #ifdef OCCT_DEBUG
-    cout <<"DONT_SWITCH_IS_VALID non positionne\n";
+    std::cout <<"DONT_SWITCH_IS_VALID non positionne\n";
 #endif
   }
   Standard_Boolean IsValid = Standard_True;
@@ -6506,7 +6994,7 @@ static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, cons
   anAngle = 2*M_PI * anAngle / 360.0;
   gp_Pln aPln;
   Handle( Geom_Surface )aSurf;
-  AIS_KindOfSurface aSurfType;
+  PrsDim_KindOfSurface aSurfType;
   Standard_Real Offset;
   gp_Dir aDir;
   if(argc > 4) { // == 5
@@ -6515,7 +7003,7 @@ static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, cons
   }
 
   TopoDS_Face face2 = TopoDS::Face(Plane);
-  if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
+  if(!PrsDim::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
     {
       di << "TEST : Can't find plane\n";
       return 1;