0030991: Draw Harness - ViewerTest::ParseColor() defines out-of-range alpha component
[occt.git] / src / ViewerTest / ViewerTest.cxx
index bee28db..2c16941 100644 (file)
@@ -202,22 +202,17 @@ namespace
   {
     const Standard_Integer THE_COLOR_COMPONENT_NOT_PARSED = -1;
     Graphic3d_Vec4i        anIntegerColor (THE_COLOR_COMPONENT_NOT_PARSED);
-    if (!parseNumericalColor (theNumberOfColorComponents, theColorComponentStrings, anIntegerColor))
+    if (!parseNumericalColor (theNumberOfColorComponents, theColorComponentStrings, anIntegerColor)
+      || anIntegerColor.maxComp() <= 1)
     {
       return false;
     }
-
-    const bool hasColorComponentGreaterThanOne = (anIntegerColor.maxComp() > 1);
     if (anIntegerColor.a() == THE_COLOR_COMPONENT_NOT_PARSED)
     {
       anIntegerColor.a() = THE_MAX_INTEGER_COLOR_COMPONENT;
     }
 
-    Graphic3d_Vec4 aRealColor (anIntegerColor);
-    if (hasColorComponentGreaterThanOne)
-    {
-      aRealColor /= static_cast<Standard_ShortReal> (THE_MAX_INTEGER_COLOR_COMPONENT);
-    }
+    const Graphic3d_Vec4 aRealColor = Graphic3d_Vec4 (anIntegerColor) / static_cast<Standard_ShortReal> (THE_MAX_INTEGER_COLOR_COMPONENT);
     theColor = Quantity_ColorRGBA (aRealColor);
     return true;
   }
@@ -284,11 +279,12 @@ Standard_Integer ViewerTest::parseColor (const Standard_Integer   theArgNb,
   if (theArgNb >= 3)
   {
     const Standard_Integer aNumberOfColorComponentsToParse = Min (theArgNb, theToParseAlpha ? 4 : 3);
-    Standard_Integer       aNumberOfColorComponentsParsed  = aNumberOfColorComponentsToParse;
+    Standard_Integer aNumberOfColorComponentsParsed = aNumberOfColorComponentsToParse;
     if (parseIntegerColor (aNumberOfColorComponentsParsed, theArgVec, theColor))
     {
       return aNumberOfColorComponentsParsed;
     }
+    aNumberOfColorComponentsParsed = aNumberOfColorComponentsToParse;
     if (parseRealColor (aNumberOfColorComponentsParsed, theArgVec, theColor))
     {
       return aNumberOfColorComponentsParsed;
@@ -766,15 +762,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()
 {
@@ -831,17 +819,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)();
 }
 
 //=======================================================================
@@ -1061,14 +1047,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)
+  {
+    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())
   {
-    theDI << "\t" << anIter.Key2() << "\n";
+    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;
 }
 
@@ -1731,6 +1758,8 @@ struct ViewerTest_AspectsChangeSet
 
   Standard_Integer             ToSetColor;
   Quantity_Color               Color;
+  Standard_Integer             ToSetBackFaceColor;
+  Quantity_Color               BackFaceColor;
 
   Standard_Integer             ToSetLineWidth;
   Standard_Real                LineWidth;
@@ -1817,6 +1846,8 @@ struct ViewerTest_AspectsChangeSet
     Visibility        (1),
     ToSetColor        (0),
     Color             (DEFAULT_COLOR),
+    ToSetBackFaceColor(0),
+    BackFaceColor     (DEFAULT_COLOR),
     ToSetLineWidth    (0),
     LineWidth         (1.0),
     ToSetTypeOfLine   (0),
@@ -1878,6 +1909,7 @@ struct ViewerTest_AspectsChangeSet
         && ToSetTransparency      == 0
         && ToSetAlphaMode         == 0
         && ToSetColor             == 0
+        && ToSetBackFaceColor     == 0
         && ToSetMaterial          == 0
         && ToSetShowFreeBoundary  == 0
         && ToSetFreeBoundaryColor == 0
@@ -1928,12 +1960,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)
     {
@@ -2112,6 +2138,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
@@ -2243,7 +2278,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)
 {
@@ -2294,6 +2329,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()
@@ -2327,6 +2365,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] =
@@ -2376,9 +2419,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")
   {
@@ -2644,6 +2691,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"
@@ -2673,6 +2724,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;
@@ -2804,8 +2863,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")
@@ -3187,6 +3250,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;
@@ -3223,6 +3288,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";
@@ -3283,6 +3367,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;
   }
 
@@ -3436,6 +3530,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;
@@ -3537,6 +3641,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)
@@ -3555,6 +3660,11 @@ int VRemove (Draw_Interpretor& theDI,
     {
       toPrintInfo = Standard_False;
     }
+    else if (anArg == "-noerror"
+          || anArg == "-nofail")
+    {
+      toFailOnError = Standard_False;
+    }
     else if (anUpdateTool.parseRedrawMode (anArg))
     {
       continue;
@@ -3584,23 +3694,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)
@@ -3626,7 +3761,7 @@ int VRemove (Draw_Interpretor& theDI,
     aCtx->Remove (anIO, Standard_False);
     if (toPrintInfo)
     {
-      theDI << anIter.Value() << " was removed\n";
+      theDI << anIter.Value() << " ";
     }
     if (!isContextOnly)
     {
@@ -3658,6 +3793,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)
   {
@@ -3672,6 +3808,11 @@ int VErase (Draw_Interpretor& theDI,
     {
       toEraseInView = Standard_True;
     }
+    else if (anArgCase == "-noerror"
+          || anArgCase == "-nofail")
+    {
+      toFailOnError = Standard_False;
+    }
     else
     {
       aNamesOfEraseIO.Append (theArgVec[anArgIter]);
@@ -3687,28 +3828,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)
   {
@@ -3870,10 +4036,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();
@@ -4684,6 +4850,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())
@@ -4763,7 +4935,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)
@@ -4940,10 +5113,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);
         }
 
@@ -5339,11 +5530,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,
@@ -5423,7 +5616,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);
@@ -5935,7 +6129,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);
@@ -5965,7 +6159,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");
 
@@ -6007,7 +6201,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))
   {
@@ -6354,15 +6548,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"
@@ -6371,7 +6566,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",
@@ -6416,7 +6612,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
@@ -6439,6 +6638,7 @@ 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]"
@@ -6453,7 +6653,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]"
@@ -6462,13 +6662,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",
@@ -6697,14 +6903,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;