Warnings is IntPatch_ImpImpIntersection_4.gxx on unix platforms and in ViewerTest...
[occt.git] / src / ViewerTest / ViewerTest.cxx
index f66ed35..c6725bf 100644 (file)
@@ -27,6 +27,7 @@
 #include <ViewerTest.hxx>
 #include <ViewerTest_CmdParser.hxx>
 
+#include <Draw.hxx>
 #include <TopLoc_Location.hxx>
 #include <TopTools_HArray1OfShape.hxx>
 #include <TColStd_HArray1OfTransient.hxx>
@@ -173,6 +174,63 @@ Standard_Boolean ViewerTest::ParseOnOff (Standard_CString  theArg,
   return Standard_False;
 }
 
+//=======================================================================
+//function : GetSelectedShapes
+//purpose  :
+//=======================================================================
+void ViewerTest::GetSelectedShapes (TopTools_ListOfShape& theSelectedShapes)
+{
+  for (GetAISContext()->InitSelected(); GetAISContext()->MoreSelected(); GetAISContext()->NextSelected())
+  {
+    TopoDS_Shape aShape = GetAISContext()->SelectedShape();
+    if (!aShape.IsNull())
+    {
+      theSelectedShapes.Append (aShape);
+    }
+  }
+}
+
+//=======================================================================
+//function : ParseLineType
+//purpose  :
+//=======================================================================
+Standard_Boolean ViewerTest::ParseLineType (Standard_CString   theArg,
+                                            Aspect_TypeOfLine& theType)
+{
+  TCollection_AsciiString aTypeStr (theArg);
+  aTypeStr.LowerCase();
+  if (aTypeStr == "empty")
+  {
+    theType = Aspect_TOL_EMPTY;
+  }
+  else if (aTypeStr == "solid")
+  {
+    theType = Aspect_TOL_SOLID;
+  }
+  else if (aTypeStr == "dot")
+  {
+    theType = Aspect_TOL_DOT;
+  }
+  else if (aTypeStr == "dash")
+  {
+    theType = Aspect_TOL_DASH;
+  }
+  else if (aTypeStr == "dotdash")
+  {
+    theType = Aspect_TOL_DOTDASH;
+  }
+  else
+  {
+    const int aTypeInt = Draw::Atoi (theArg);
+    if (aTypeInt < -1 || aTypeInt >= Aspect_TOL_USERDEFINED)
+    {
+      return Standard_False;
+    }
+    theType = (Aspect_TypeOfLine )aTypeInt;
+  }
+  return Standard_True;
+}
+
 //=======================================================================
 //function : GetTypeNames
 //purpose  :
@@ -303,7 +361,7 @@ Standard_Boolean ViewerTest::Display (const TCollection_AsciiString&       theNa
     Handle(AIS_InteractiveObject) anOldObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
     if (!anOldObj.IsNull())
     {
-      aCtx->Remove (anOldObj, Standard_True);
+      aCtx->Remove (anOldObj, theObject.IsNull() && theToUpdate);
     }
     aMap.UnBind2 (theName);
   }
@@ -484,8 +542,6 @@ Handle(AIS_Shape) GetAISShapeFromName(const char* name)
 void ViewerTest::Clear()
 {
   if ( !a3DView().IsNull() ) {
-    if (TheAISContext()->HasOpenedContext())
-      TheAISContext()->CloseLocalContext();
     ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
     while ( it.More() ) {
       cout << "Remove " << it.Key2() << endl;
@@ -504,12 +560,15 @@ void ViewerTest::Clear()
 //purpose  : Activate a selection mode, vertex, edge, wire ..., in a local
 //           Context
 //==============================================================================
+Standard_DISABLE_DEPRECATION_WARNINGS
 void ViewerTest::StandardModeActivation(const Standard_Integer mode )
 {
   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
   if(mode==0) {
     if (TheAISContext()->HasOpenedContext())
+    {
       aContext->CloseLocalContext();
+    }
   } else {
 
     if(!aContext->HasOpenedContext()) {
@@ -518,14 +577,16 @@ void ViewerTest::StandardModeActivation(const Standard_Integer mode )
       // Open a local Context in order to be able to select subshape from
       // the selected shape if any or for all if there is no selection
       if (!aContext->FirstSelectedObject().IsNull()){
-       aContext->OpenLocalContext(Standard_False);
+        aContext->OpenLocalContext(Standard_False);
 
        for(aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected()){
          aContext->Load(       aContext->SelectedInteractive(),-1,Standard_True);
        }
       }
       else
-       aContext->OpenLocalContext();
+      {
+        aContext->OpenLocalContext();
+      }
     }
 
     const char *cmode="???";
@@ -543,19 +604,20 @@ void ViewerTest::StandardModeActivation(const Standard_Integer mode )
     }
 
     if(theactivatedmodes.Contains(mode))
-      { // Desactivate
-       aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
-       theactivatedmodes.Remove(mode);
-       cout<<"Mode "<< cmode <<" OFF"<<endl;
-      }
+    { // Desactivate
+      aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
+      theactivatedmodes.Remove(mode);
+      cout<<"Mode "<< cmode <<" OFF"<<endl;
+    }
     else
-      { // Activate
-       aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
-       theactivatedmodes.Add(mode);
-       cout<<"Mode "<< cmode << " ON" << endl;
-      }
+    { // Activate
+      aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
+      theactivatedmodes.Add(mode);
+      cout<<"Mode "<< cmode << " ON" << endl;
+    }
   }
 }
+Standard_ENABLE_DEPRECATION_WARNINGS
 
 //==============================================================================
 //function : CopyIsoAspect
@@ -735,47 +797,6 @@ static int VDir (Draw_Interpretor& theDI,
   return 0;
 }
 
-//==============================================================================
-//function : VSelPrecision
-//purpose  : To set the selection tolerance value
-//Draw arg : Selection tolerance value (real value determining the width and
-//           height of selecting frustum bases). Without arguments the function
-//           just prints current tolerance.
-//==============================================================================
-static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
-{
-  if( argc > 2 )
-  {
-    di << "Wrong parameters! Must be: " << argv[0] << " [-unset] [tolerance]\n";
-    return 1;
-  }
-
-  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
-  if( aContext.IsNull() )
-    return 1;
-
-  if( argc == 1 )
-  {
-    Standard_Real aPixelTolerance = aContext->PixelTolerance();
-    di << "Pixel tolerance : " << aPixelTolerance << "\n";
-  }
-  else if (argc == 2)
-  {
-    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
 {
@@ -965,13 +986,11 @@ static Standard_Integer VDump (Draw_Interpretor& theDI,
   }
 
   Image_AlienPixMap aPixMap;
-
-  bool isBigEndian = Image_PixMap::IsBigEndianHost();
   Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN;
   switch (aParams.BufferType)
   {
-    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_RGB:   aFormat = Image_PixMap::ImgRGB;   break;
+    case Graphic3d_BT_RGBA:  aFormat = Image_PixMap::ImgRGBA;  break;
     case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; break;
   }
 
@@ -1026,9 +1045,9 @@ static Standard_Integer VDump (Draw_Interpretor& theDI,
       }
 
       Image_PixMap aPixMapL, aPixMapR;
-      aPixMapL.InitWrapper (aFormat, aPixMap.ChangeData(),
+      aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
                             aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
-      aPixMapR.InitWrapper (aFormat, aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height,
+      aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height,
                             aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
 
       aParams.StereoOptions = V3d_SDO_LEFT_EYE;
@@ -1463,10 +1482,6 @@ static int VSetInteriorStyle (Draw_Interpretor& theDI,
     return 1;
   }
 
-  if (aCtx->HasOpenedContext())
-  {
-    aCtx->CloseLocalContext();
-  }
   for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
   {
     const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
@@ -1521,6 +1536,10 @@ struct ViewerTest_AspectsChangeSet
   Standard_Integer         SelectionMode;
   Standard_Integer         Sensitivity;
 
+  Standard_Integer         ToSetHatch;
+  Standard_Integer         StdHatchStyle;
+  TCollection_AsciiString  PathToHatchPattern;
+
   //! Empty constructor
   ViewerTest_AspectsChangeSet()
   : ToSetVisibility   (0),
@@ -1545,7 +1564,10 @@ struct ViewerTest_AspectsChangeSet
     MaxParamValue (500000),
     ToSetSensitivity (0),
     SelectionMode (-1),
-    Sensitivity (-1) {}
+    Sensitivity (-1),
+    ToSetHatch (0),
+    StdHatchStyle (-1)
+    {}
 
   //! @return true if no changes have been requested
   Standard_Boolean IsEmpty() const
@@ -1559,7 +1581,8 @@ struct ViewerTest_AspectsChangeSet
         && ToSetFreeBoundaryColor == 0
         && ToSetFreeBoundaryWidth == 0
         && ToSetMaxParamValue     == 0
-        && ToSetSensitivity       == 0;
+        && ToSetSensitivity       == 0
+        && ToSetHatch             == 0;
   }
 
   //! @return true if properties are valid
@@ -1611,6 +1634,11 @@ struct ViewerTest_AspectsChangeSet
       std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
       isOk = Standard_False;
     }
+    if (ToSetHatch == 1 && StdHatchStyle < 0 && PathToHatchPattern == "")
+    {
+      std::cout << "Error: hatch style must be specified\n";
+      isOk = Standard_False;
+    }
     return isOk;
   }
 
@@ -1923,27 +1951,7 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
         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
+      if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aChangeSet->TypeOfLine))
       {
         std::cout << "Error: wrong syntax at " << anArg << "\n";
         return 1;
@@ -2139,6 +2147,9 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
       aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
       aChangeSet->ToSetFreeBoundaryWidth = -1;
       aChangeSet->FreeBoundaryWidth = 1.0;
+      aChangeSet->ToSetHatch = -1;
+      aChangeSet->StdHatchStyle = -1;
+      aChangeSet->PathToHatchPattern.Clear();
     }
     else if (anArg == "-isoontriangulation"
           || anArg == "-isoontriang")
@@ -2199,6 +2210,31 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
       aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
       aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
     }
+    else if (anArg == "-sethatch")
+    {
+      if (isDefaults)
+      {
+        std::cout << "Error: wrong syntax. -setHatch can not be used together with -defaults call!\n";
+        return 1;
+      }
+
+      if (aNames.IsEmpty())
+      {
+        std::cout << "Error: object should be specified explicitly when -setHatch is used!\n";
+        return 1;
+      }
+
+      aChangeSet->ToSetHatch = 1;
+      TCollection_AsciiString anArgHatch (theArgVec[++anArgIter]);
+      if (anArgHatch.Length() <= 2)
+      {
+        aChangeSet->StdHatchStyle = Draw::Atoi (anArgHatch.ToCString());
+      }
+      else
+      {
+        aChangeSet->PathToHatchPattern = anArgHatch;
+      }
+    }
     else
     {
       std::cout << "Error: wrong syntax at " << anArg << "\n";
@@ -2217,11 +2253,6 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
     isFirst = Standard_False;
   }
 
-  if (aCtx->HasOpenedContext())
-  {
-    aCtx->CloseLocalContext();
-  }
-
   // special case for -defaults parameter.
   // all changed values will be set to DefaultDrawer.
   if (isDefaults)
@@ -2424,6 +2455,42 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
         {
           aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
         }
+        if (aChangeSet->ToSetHatch != 0)
+        {
+          if (!aDrawer->HasOwnShadingAspect())
+          {
+            aDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
+            *aDrawer->ShadingAspect()->Aspect() = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
+          }
+
+          Handle(Graphic3d_AspectFillArea3d) anAsp = aDrawer->ShadingAspect()->Aspect();
+          if (aChangeSet->ToSetHatch == -1)
+          {
+            anAsp->SetInteriorStyle (Aspect_IS_SOLID);
+          }
+          else
+          {
+            anAsp->SetInteriorStyle (Aspect_IS_HATCH);
+            if (!aChangeSet->PathToHatchPattern.IsEmpty())
+            {
+              Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
+              if (anImage->Load (TCollection_AsciiString (aChangeSet->PathToHatchPattern.ToCString())))
+              {
+                anAsp->SetHatchStyle (new Graphic3d_HatchStyle (anImage));
+              }
+              else
+              {
+                std::cout << "Error: cannot load the following image: " << aChangeSet->PathToHatchPattern << std::endl;
+                return 1;
+              }
+            }
+            else if (aChangeSet->StdHatchStyle != -1)
+            {
+              anAsp->SetHatchStyle (new Graphic3d_HatchStyle ((Aspect_HatchStyle)aChangeSet->StdHatchStyle));
+            }
+          }
+          toRedisplay = Standard_True;
+        }
       }
 
       for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
@@ -2497,10 +2564,12 @@ static int VDonly2 (Draw_Interpretor& ,
     return 1;
   }
 
+  Standard_DISABLE_DEPRECATION_WARNINGS
   if (aCtx->HasOpenedContext())
   {
     aCtx->CloseLocalContext();
   }
+  Standard_ENABLE_DEPRECATION_WARNINGS
 
   Standard_Integer anArgIter = 1;
   for (; anArgIter < theArgNb; ++anArgIter)
@@ -2622,6 +2691,7 @@ int VRemove (Draw_Interpretor& theDI,
     return 1;
   }
 
+  Standard_DISABLE_DEPRECATION_WARNINGS
   if (toRemoveLocal && !aCtx->HasOpenedContext())
   {
     std::cerr << "Error: local selection context is not open.\n";
@@ -2631,6 +2701,7 @@ int VRemove (Draw_Interpretor& theDI,
   {
     aCtx->CloseAllContexts (Standard_False);
   }
+  Standard_ENABLE_DEPRECATION_WARNINGS
 
   NCollection_List<TCollection_AsciiString> anIONameList;
   if (toRemoveAll)
@@ -2698,11 +2769,13 @@ int VRemove (Draw_Interpretor& theDI,
 
   // Close local context if it is empty
   TColStd_MapOfTransient aLocalIO;
+  Standard_DISABLE_DEPRECATION_WARNINGS
   if (aCtx->HasOpenedContext()
    && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
   {
     aCtx->CloseAllContexts (Standard_False);
   }
+  Standard_ENABLE_DEPRECATION_WARNINGS
 
   return 0;
 }
@@ -2760,6 +2833,7 @@ int VErase (Draw_Interpretor& theDI,
     return 1;
   }
 
+  Standard_DISABLE_DEPRECATION_WARNINGS
   if (toEraseLocal && !aCtx->HasOpenedContext())
   {
     std::cerr << "Error: local selection context is not open.\n";
@@ -2769,6 +2843,7 @@ int VErase (Draw_Interpretor& theDI,
   {
     aCtx->CloseAllContexts (Standard_False);
   }
+  Standard_ENABLE_DEPRECATION_WARNINGS
 
   if (!aNamesOfEraseIO.IsEmpty())
   {
@@ -2892,6 +2967,7 @@ static int VDisplayAll (Draw_Interpretor& ,
     return 1;
   }
 
+  Standard_DISABLE_DEPRECATION_WARNINGS
   if (toDisplayLocal && !aCtx->HasOpenedContext())
   {
     std::cerr << "Error: local selection context is not open.\n";
@@ -2901,6 +2977,7 @@ static int VDisplayAll (Draw_Interpretor& ,
   {
     aCtx->CloseLocalContext (Standard_False);
   }
+  Standard_ENABLE_DEPRECATION_WARNINGS
 
   for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
        anIter.More(); anIter.Next())
@@ -2918,32 +2995,33 @@ static int VDisplayAll (Draw_Interpretor& ,
   return 0;
 }
 
-//! Auxiliary method to find presentation
-inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
-                                                     const Handle(AIS_InteractiveObject)&  theIO,
-                                                     const Standard_Integer                theMode)
+//! Auxiliary method to check if presentation exists
+inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
+                                   const Handle(AIS_InteractiveObject)&  theIO,
+                                   const Standard_Integer                theMode)
 {
-  if (theIO.IsNull())
+  if (theIO.IsNull() || theCtx.IsNull())
   {
-    return Handle(PrsMgr_Presentation)();
+    return -1;
   }
 
   if (theMode != -1)
   {
     if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
     {
-      return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
+      return theMode;
     }
   }
   else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
   {
-    return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
+    return theIO->DisplayMode();
   }
   else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
   {
-    return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
+    return theCtx->DisplayMode();
   }
-  return Handle(PrsMgr_Presentation)();
+
+  return -1;
 }
 
 enum ViewerTest_BndAction
@@ -2954,28 +3032,36 @@ enum ViewerTest_BndAction
 };
 
 //! Auxiliary method to print bounding box of presentation
-inline void bndPresentation (Draw_Interpretor&                  theDI,
-                             const Handle(PrsMgr_Presentation)& thePrs,
-                             const TCollection_AsciiString&     theName,
-                             const ViewerTest_BndAction         theAction)
+inline void bndPresentation (Draw_Interpretor&                         theDI,
+                             const Handle(PrsMgr_PresentationManager)& theMgr,
+                             const Handle(AIS_InteractiveObject)&      theObj,
+                             const Standard_Integer                    theDispMode,
+                             const TCollection_AsciiString&            theName,
+                             const ViewerTest_BndAction                theAction,
+                             const Handle(Prs3d_Drawer)&               theStyle)
 {
   switch (theAction)
   {
     case BndAction_Hide:
     {
-      thePrs->Presentation()->GraphicUnHighlight();
+      theMgr->Unhighlight (theObj);
       break;
     }
     case BndAction_Show:
     {
-      Handle(Graphic3d_Structure) aPrs (thePrs->Presentation());
-      aPrs->CStructure()->HighlightColor = Quantity_NOC_GRAY99;
-      aPrs->CStructure()->HighlightWithBndBox (aPrs, Standard_True);
+      theMgr->Color (theObj, theStyle, theDispMode);
       break;
     }
     case BndAction_Print:
     {
-      Bnd_Box aBox = thePrs->Presentation()->MinMaxValues();
+      Bnd_Box aBox;
+      for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
+      {
+        if (aPrsIter.Value().Mode() != theDispMode)
+          continue;
+
+        aBox = aPrsIter.Value().Presentation()->Presentation()->MinMaxValues();
+      }
       gp_Pnt aMin = aBox.CornerMin();
       gp_Pnt aMax = aBox.CornerMax();
       theDI << theName  << "\n"
@@ -3005,6 +3091,8 @@ int VBounding (Draw_Interpretor& theDI,
   ViewerTest_BndAction anAction = BndAction_Show;
   Standard_Integer     aMode    = -1;
 
+  Handle(Prs3d_Drawer) aStyle;
+
   Standard_Integer anArgIter = 1;
   for (; anArgIter < theArgNb; ++anArgIter)
   {
@@ -3037,6 +3125,14 @@ int VBounding (Draw_Interpretor& theDI,
     }
   }
 
+  if (anAction == BndAction_Show)
+  {
+    aStyle = new Prs3d_Drawer();
+    aStyle->SetMethod (Aspect_TOHM_BOUNDBOX);
+    aStyle->SetColor  (Quantity_NOC_GRAY99);
+  }
+
+  Standard_Integer aHighlightedMode = -1;
   if (anArgIter < theArgNb)
   {
     // has a list of names
@@ -3050,13 +3146,13 @@ int VBounding (Draw_Interpretor& theDI,
       }
 
       Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
-      Handle(PrsMgr_Presentation)   aPrs = findPresentation (aCtx, anIO, aMode);
-      if (aPrs.IsNull())
+      aHighlightedMode = checkMode (aCtx, anIO, aMode);
+      if (aHighlightedMode == -1)
       {
-        std::cout << "Error: presentation " << aName << " does not exist\n";
+        std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl;
         return 1;
       }
-      bndPresentation (theDI, aPrs, aName, anAction);
+      bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
     }
   }
   else if (aCtx->NbSelected() > 0)
@@ -3065,10 +3161,11 @@ int VBounding (Draw_Interpretor& theDI,
     for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
     {
       Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
-      Handle(PrsMgr_Presentation)   aPrs = findPresentation (aCtx, anIO, aMode);
-      if (!aPrs.IsNull())
+      aHighlightedMode = checkMode (aCtx, anIO, aMode);
+      if (aHighlightedMode != -1)
       {
-        bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
+        bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
+          GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
       }
     }
   }
@@ -3079,10 +3176,10 @@ int VBounding (Draw_Interpretor& theDI,
          anIter.More(); anIter.Next())
     {
       Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
-      Handle(PrsMgr_Presentation)   aPrs = findPresentation (aCtx, anIO, aMode);
-      if (!aPrs.IsNull())
+      aHighlightedMode = checkMode (aCtx, anIO, aMode);
+      if (aHighlightedMode != -1)
       {
-        bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
+        bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
       }
     }
   }
@@ -3727,6 +3824,7 @@ static int VDisplay2 (Draw_Interpretor& theDI,
   }
 
   // Prepare context for display
+  Standard_DISABLE_DEPRECATION_WARNINGS
   if (toDisplayLocal && !aCtx->HasOpenedContext())
   {
     aCtx->OpenLocalContext (Standard_False);
@@ -3735,6 +3833,7 @@ static int VDisplay2 (Draw_Interpretor& theDI,
   {
     aCtx->CloseAllContexts (Standard_False);
   }
+  Standard_ENABLE_DEPRECATION_WARNINGS
 
   // Display interactive objects
   for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
@@ -3936,9 +4035,6 @@ static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, con
 static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
 
   OSD_Timer myTimer;
-  if (TheAISContext()->HasOpenedContext())
-    TheAISContext()->CloseLocalContext();
-
   Standard_Real Step=4*M_PI/180;
   Standard_Real Angle=0;
 
@@ -3998,125 +4094,6 @@ static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
   return 0;
 }
 
-
-//==================================================================================
-// Function : VAnimation
-//==================================================================================
-static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
-  if (argc != 5) {
-    di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile\n";
-    return 1;
-  }
-
-  Standard_Real thread = 4;
-  Standard_Real angleA=0;
-  Standard_Real angleB;
-  Standard_Real X;
-  gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
-
-  BRep_Builder B;
-  TopoDS_Shape CrankArm;
-  TopoDS_Shape CylinderHead;
-  TopoDS_Shape Propeller;
-  TopoDS_Shape EngineBlock;
-
-  //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
-  //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
-  //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
-  //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
-  BRepTools::Read(CrankArm,argv[1],B);
-  BRepTools::Read(CylinderHead,argv[2],B);
-  BRepTools::Read(Propeller,argv[3],B);
-  BRepTools::Read(EngineBlock,argv[4],B);
-
-  if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure.\n";}
-
-
-  OSD_Timer myTimer;
-  myTimer.Start();
-
-  Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
-  Handle(AIS_Shape) myAisEngineBlock  = new AIS_Shape (EngineBlock);
-  Handle(AIS_Shape) myAisCrankArm     = new AIS_Shape (CrankArm);
-  Handle(AIS_Shape) myAisPropeller    = new AIS_Shape (Propeller);
-
-  GetMapOfAIS().Bind(myAisCylinderHead,"a");
-  GetMapOfAIS().Bind(myAisEngineBlock,"b");
-  GetMapOfAIS().Bind(myAisCrankArm,"c");
-  GetMapOfAIS().Bind(myAisPropeller,"d");
-
-  myAisCylinderHead->SetMutable (Standard_True);
-  myAisEngineBlock ->SetMutable (Standard_True);
-  myAisCrankArm    ->SetMutable (Standard_True);
-  myAisPropeller   ->SetMutable (Standard_True);
-
-  TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED);
-  TheAISContext()->SetColor (myAisEngineBlock,  Quantity_NOC_RED);
-  TheAISContext()->SetColor (myAisPropeller,    Quantity_NOC_GREEN);
-
-  TheAISContext()->Display (myAisCylinderHead, Standard_False);
-  TheAISContext()->Display (myAisEngineBlock,  Standard_False);
-  TheAISContext()->Display (myAisCrankArm,     Standard_False);
-  TheAISContext()->Display (myAisPropeller,    Standard_False);
-
-  TheAISContext()->Deactivate(myAisCylinderHead);
-  TheAISContext()->Deactivate(myAisEngineBlock );
-  TheAISContext()->Deactivate(myAisCrankArm    );
-  TheAISContext()->Deactivate(myAisPropeller   );
-
-  // Boucle de mouvement
-  for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
-
-    angleA = thread*myAngle*M_PI/180;
-    X = Sin(angleA)*3/8;
-    angleB = atan(X / Sqrt(-X * X + 1));
-    Standard_Real decal(25*0.6);
-
-
-    //Build a transformation on the display
-    gp_Trsf aPropellerTrsf;
-    aPropellerTrsf.SetRotation(Ax1,angleA);
-    TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
-
-    gp_Ax3 base(gp_Pnt(3*decal*(1-Cos(angleA)),-3*decal*Sin(angleA),0),gp_Vec(0,0,1),gp_Vec(1,0,0));
-    gp_Trsf aCrankArmTrsf;
-    aCrankArmTrsf.SetTransformation(   base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
-    TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
-
-    TheAISContext()->UpdateCurrentViewer();
-  }
-
-  TopoDS_Shape myNewCrankArm  =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() );
-  TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() );
-
-  myAisCrankArm ->ResetTransformation();
-  myAisPropeller->ResetTransformation();
-
-  myAisCrankArm  -> Set(myNewCrankArm );
-  myAisPropeller -> Set(myNewPropeller);
-
-  TheAISContext()->Activate(myAisCylinderHead,0);
-  TheAISContext()->Activate(myAisEngineBlock,0 );
-  TheAISContext()->Activate(myAisCrankArm ,0   );
-  TheAISContext()->Activate(myAisPropeller ,0  );
-
-  myTimer.Stop();
-  myTimer.Show();
-  myTimer.Start();
-
-  TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
-  TheAISContext()->Redisplay(myAisPropeller,Standard_False);
-
-  TheAISContext()->UpdateCurrentViewer();
-  a3DView()->Redraw();
-
-  myTimer.Stop();
-  myTimer.Show();
-
-  return 0;
-
-}
-
 //==============================================================================
 //function : VShading
 //purpose  : Sharpen or roughten the quality of the shading
@@ -4129,10 +4106,6 @@ static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
 
   // Verifications
   const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
-
-  if (TheAISContext()->HasOpenedContext())
-    TheAISContext()->CloseLocalContext();
-
   if (argc < 3) {
     myDevCoef  = 0.0008;
   } else {
@@ -4198,15 +4171,20 @@ static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const ch
       if (argc<2||argc>3) { di<<" Syntaxe error\n";return 1;}
       ThereIsName = (argc == 3);
     }
-    else {
+    else
+    {
+      Standard_DISABLE_DEPRECATION_WARNINGS
       // vunsetam
       if (argc>1) {di<<" Syntaxe error\n";return 1;}
       else {
         di<<" R.A.Z de tous les modes de selecion\n";
         di<<" Fermeture du Context local\n";
         if (TheAISContext()->HasOpenedContext())
+        {
           TheAISContext()->CloseLocalContext();
+        }
       }
+      Standard_ENABLE_DEPRECATION_WARNINGS
     }
 
     // IL n'y a aps de nom de shape passe en argument
@@ -4239,7 +4217,9 @@ static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const ch
          }
        }
 
+  Standard_DISABLE_DEPRECATION_WARNINGS
        TheAISContext()->OpenLocalContext(Standard_False);
+  Standard_ENABLE_DEPRECATION_WARNINGS
        ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
           it (GetMapOfAIS());
        while(it.More()){
@@ -4342,7 +4322,9 @@ static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const ch
         }
 
         if( !TheAISContext()->HasOpenedContext() ) {
+          Standard_DISABLE_DEPRECATION_WARNINGS
           TheAISContext()->OpenLocalContext(Standard_False);
+          Standard_ENABLE_DEPRECATION_WARNINGS
           // On charge tous les objets de la map
           ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
           while(it.More()){
@@ -4543,7 +4525,9 @@ static Standard_Integer VState (Draw_Interpretor& theDI,
   if (toPrintEntities)
   {
     theDI << "Detected entities:\n";
+    Standard_DISABLE_DEPRECATION_WARNINGS
     Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
+    Standard_ENABLE_DEPRECATION_WARNINGS
     SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
     for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
     {
@@ -4555,7 +4539,7 @@ static Standard_Integer VState (Draw_Interpretor& theDI,
       aName.LeftJustify (20, ' ');
       char anInfoStr[512];
       Sprintf (anInfoStr,
-               " Depth: %+.3f Distance: %+.3f Point: %+.3f %+.3f %+.3f",
+               " Depth: %g Distance: %g Point: %g %g %g",
                aPickData.Depth,
                aPickData.MinDist,
                aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
@@ -4593,10 +4577,12 @@ static Standard_Integer VState (Draw_Interpretor& theDI,
   }
 
   NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
+  Standard_DISABLE_DEPRECATION_WARNINGS
   for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
   {
     aDetected.Add (aCtx->DetectedCurrentObject());
   }
+  Standard_ENABLE_DEPRECATION_WARNINGS
 
   const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
   if (theArgNb >= 2
@@ -4662,8 +4648,10 @@ static Standard_Integer VState (Draw_Interpretor& theDI,
     theDI << "\n";
   }
   printLocalSelectionInfo (aCtx, theDI);
+  Standard_DISABLE_DEPRECATION_WARNINGS
   if (aCtx->HasOpenedContext())
     printLocalSelectionInfo (aCtx->LocalContext(), theDI);
+  Standard_ENABLE_DEPRECATION_WARNINGS
   return 0;
 }
 
@@ -4677,7 +4665,9 @@ Standard_Boolean  ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& ar
                                          const Standard_Integer MaxPick)
 {
   Handle(AIS_InteractiveObject) IO;
+  Standard_DISABLE_DEPRECATION_WARNINGS
   Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
+  Standard_ENABLE_DEPRECATION_WARNINGS
 
   // step 1: prepare the data
   if(curindex !=0){
@@ -4717,9 +4707,12 @@ Standard_Boolean  ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& ar
     arr->SetValue(i,IO2);
   }
 
-
-  if(curindex>0)
+  Standard_DISABLE_DEPRECATION_WARNINGS
+  if (curindex > 0)
+  {
     TheAISContext()->CloseLocalContext(curindex);
+  }
+  Standard_ENABLE_DEPRECATION_WARNINGS
 
   return Standard_True;
 }
@@ -4734,7 +4727,9 @@ Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive
                                                     const Standard_Integer MaxPick)
 {
   Handle(AIS_InteractiveObject) IO;
+  Standard_DISABLE_DEPRECATION_WARNINGS
   Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
+  Standard_ENABLE_DEPRECATION_WARNINGS
 
   // step 1: prepare the data
 
@@ -4765,8 +4760,12 @@ Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive
     IO = TheAISContext()->SelectedInteractive();
   }
 
-  if(curindex!=0)
+  Standard_DISABLE_DEPRECATION_WARNINGS
+  if (curindex != 0)
+  {
     TheAISContext()->CloseLocalContext(curindex);
+  }
+  Standard_ENABLE_DEPRECATION_WARNINGS
   return IO;
 }
 
@@ -4781,8 +4780,9 @@ TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
 {
 
   // step 1: prepare the data
-
+  Standard_DISABLE_DEPRECATION_WARNINGS
   Standard_Integer curindex = TheAISContext()->OpenLocalContext();
+  Standard_ENABLE_DEPRECATION_WARNINGS
   TopoDS_Shape result;
 
   if(TheType==TopAbs_SHAPE){
@@ -4792,8 +4792,9 @@ TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
   else{
     Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
     TheAISContext()->AddFilter(TF);
+    Standard_DISABLE_DEPRECATION_WARNINGS
     TheAISContext()->ActivateStandardMode(TheType);
-
+    Standard_ENABLE_DEPRECATION_WARNINGS
   }
 
 
@@ -4825,8 +4826,12 @@ TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
     }
   }
 
-  if(curindex>0)
+  Standard_DISABLE_DEPRECATION_WARNINGS
+  if (curindex > 0)
+  {
     TheAISContext()->CloseLocalContext(curindex);
+  }
+  Standard_ENABLE_DEPRECATION_WARNINGS
 
   return result;
 }
@@ -4846,7 +4851,9 @@ Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
     cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
 
   // step 1: prepare the data
+  Standard_DISABLE_DEPRECATION_WARNINGS
   Standard_Integer curindex = TheAISContext()->OpenLocalContext();
+  Standard_ENABLE_DEPRECATION_WARNINGS
   if(TheType==TopAbs_SHAPE){
     Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
     TheAISContext()->AddFilter(F1);
@@ -4854,8 +4861,9 @@ Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
   else{
     Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
     TheAISContext()->AddFilter(TF);
+    Standard_DISABLE_DEPRECATION_WARNINGS
     TheAISContext()->ActivateStandardMode(TheType);
-
+    Standard_ENABLE_DEPRECATION_WARNINGS
   }
 
   // step 2 : wait for the selection...
@@ -4892,7 +4900,9 @@ Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
     }
   }
 
+  Standard_DISABLE_DEPRECATION_WARNINGS
   TheAISContext()->CloseLocalContext(curindex);
+  Standard_ENABLE_DEPRECATION_WARNINGS
   return Standard_True;
 }
 
@@ -5505,6 +5515,7 @@ static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
   }
 
   // Prepare context
+  Standard_DISABLE_DEPRECATION_WARNINGS
   if (isLocal && !aCtx->HasOpenedContext())
   {
     aCtx->OpenLocalContext (Standard_False);
@@ -5513,6 +5524,7 @@ static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
   {
     aCtx->CloseAllContexts (Standard_False);
   }
+  Standard_ENABLE_DEPRECATION_WARNINGS
 
   // Load selection of interactive objects
   for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
@@ -5540,51 +5552,6 @@ static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
   return 0;
 }
 
-//==============================================================================
-//function : VAutoActivateSelection
-//purpose  : Activates or deactivates auto computation of selection
-//==============================================================================
-static int VAutoActivateSelection (Draw_Interpretor& theDi,
-                                   Standard_Integer theArgNb,
-                                   const char** theArgVec)
-{
-
-  if (theArgNb > 2)
-  {
-    std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
-    return 1;
-  }
-
-  Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
-  if (aCtx.IsNull())
-  {
-    ViewerTest::ViewerInit();
-    aCtx = ViewerTest::GetAISContext();
-  }
-
-  if (theArgNb == 1)
-  {
-    TCollection_AsciiString aSelActivationString;
-    if (aCtx->GetAutoActivateSelection())
-    {
-      aSelActivationString.Copy ("ON");
-    }
-    else
-    {
-      aSelActivationString.Copy ("OFF");
-    }
-
-    theDi << "Auto activation of selection is: " << aSelActivationString << "\n";
-  }
-  else
-  {
-    Standard_Boolean toActivate = Draw::Atoi (theArgVec[1]) != 0;
-    aCtx->SetAutoActivateSelection (toActivate);
-  }
-
-  return 0;
-}
-
 //==============================================================================
 //function : ViewerTest::Commands
 //purpose  : Add all the viewer command in the Draw_Interpretor
@@ -5828,21 +5795,11 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
       "vsensera : erase active entities",
       __FILE__,VClearSensi,group);
 
-  theCommands.Add("vselprecision",
-                 "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",
       "vperf: vperf  ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)"
       "\n\t\t: Tests the animation of an object along a predefined trajectory.",
       __FILE__,VPerf,group);
 
-  theCommands.Add("vanimation",
-                 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
-                 __FILE__,VAnimation,group);
-
   theCommands.Add("vsetshading",
       "vsetshading  : vsetshading name Quality(default=0.0008) "
       "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
@@ -5944,12 +5901,6 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
     "\n\t\t:   -local - open local context before selection computation",
     __FILE__, VLoadSelection, group);
 
-  theCommands.Add ("vautoactivatesel",
-    "vautoactivatesel [0|1] : manage or display the option to automatically"
-    "\n\t\t: activate selection for newly displayed objects"
-    "\n\t\t:   [0|1] - turn off | on auto activation of selection",
-    __FILE__, VAutoActivateSelection, group);
-
   theCommands.Add("vbsdf", "vbsdf [name] [options]"
     "\nAdjusts parameters of material BSDF:"
     "\n    -help : Shows this message"
@@ -6164,7 +6115,6 @@ void ViewerTest::Factory(Draw_Interpretor& theDI)
 {
   // definition of Viewer Command
   ViewerTest::Commands(theDI);
-  ViewerTest::AviCommands(theDI);
 
 #ifdef OCCT_DEBUG
       theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";