0028355: Stating wrong parent class in DEFINE_STANDARD_RTTIEXT is not recognized...
[occt.git] / src / ViewerTest / ViewerTest_ObjectCommands.cxx
old mode 100755 (executable)
new mode 100644 (file)
index d64bf6b..358a35a
@@ -1,55 +1,42 @@
 // Created on: 1998-11-12
 // Created by: Robert COUBLANC
 // Copyright (c) 1998-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
 //
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
 //
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
 //
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-
-
-//===============================================
-//    AIS Objects Creation : Datums (axis,trihedrons,lines,planes)
-//===============================================
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
 #include <ViewerTest.hxx>
 
-#include <string.h>
-
 #include <Quantity_NameOfColor.hxx>
 #include <Draw_Interpretor.hxx>
 #include <Draw.hxx>
 #include <Draw_Appli.hxx>
 #include <DBRep.hxx>
 
+#include <Font_BRepFont.hxx>
+#include <Font_BRepTextBuilder.hxx>
+#include <Font_FontMgr.hxx>
 #include <OSD_Chronometer.hxx>
 #include <TCollection_AsciiString.hxx>
-#include <Visual3d_View.hxx>
 #include <V3d_Viewer.hxx>
 #include <V3d_View.hxx>
-#include <V3d_Plane.hxx>
 #include <V3d.hxx>
 
 #include <AIS_Shape.hxx>
 #include <AIS_DisplayMode.hxx>
+#include <AIS_PointCloud.hxx>
 #include <TColStd_MapOfInteger.hxx>
 #include <AIS_MapOfInteractive.hxx>
+#include <ViewerTest_AutoUpdater.hxx>
 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
 #include <ViewerTest_EventManager.hxx>
@@ -81,8 +68,8 @@
 #include <AIS_InteractiveContext.hxx>
 #include <Geom_Plane.hxx>
 #include <gp_Pln.hxx>
-#include <AIS_AngleDimension.hxx>
 #include <TCollection_ExtendedString.hxx>
+#include <TCollection_HAsciiString.hxx>
 #include <GC_MakePlane.hxx>
 #include <gp_Circ.hxx>
 #include <AIS_Axis.hxx>
@@ -91,6 +78,7 @@
 #include <AIS_Trihedron.hxx>
 #include <AIS_Axis.hxx>
 #include <gp_Trsf.hxx>
+#include <gp_Quaternion.hxx>
 #include <TopLoc_Location.hxx>
 
 #include <HLRAlgo_Projector.hxx>
 #include <Graphic3d_ArrayOfQuadrangles.hxx>
 #include <Graphic3d_ArrayOfQuadrangleStrips.hxx>
 #include <Graphic3d_ArrayOfPolygons.hxx>
+#include <Graphic3d_AspectMarker3d.hxx>
 #include <Graphic3d_Group.hxx>
 #include <Standard_Real.hxx>
 
 #include <AIS_Circle.hxx>
-#include <AIS_Drawer.hxx>
 #include <BRepBuilderAPI_MakeEdge.hxx>
 #include <BRepBuilderAPI_MakeFace.hxx>
 #include <BRepBuilderAPI_MakeWire.hxx>
 #include <StdPrs_ShadedShape.hxx>
 #include <TopoDS_Wire.hxx>
 
-#include <AIS_ConnectedShape.hxx>
 #include <AIS_MultipleConnectedInteractive.hxx>
-#include <AIS_MultipleConnectedShape.hxx>
+#include <AIS_ConnectedInteractive.hxx>
+#include <AIS_TextLabel.hxx>
 #include <TopLoc_Location.hxx>
 #include <TColStd_ListOfInteger.hxx>
 #include <TColStd_ListIteratorOfListOfInteger.hxx>
 
 #include <Select3D_SensitiveTriangle.hxx>
 #include <Select3D_SensitiveCurve.hxx>
+#include <Select3D_SensitivePoint.hxx>
 #include <BRepAdaptor_Curve.hxx>
 #include <StdPrs_Curve.hxx>
 
 #include <BRepExtrema_ExtPC.hxx>
 #include <BRepExtrema_ExtPF.hxx>
 
+#include <Prs3d_DatumAspect.hxx>
+#include <Prs3d_Drawer.hxx>
+#include <Prs3d_VertexDrawMode.hxx>
 #include <Prs3d_LineAspect.hxx>
+#include <Prs3d_PointAspect.hxx>
+#include <Prs3d_TextAspect.hxx>
 
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-
-#ifdef WNT
-#define _CRT_SECURE_NO_DEPRECATE
-#pragma warning (disable:4996)
-#endif
+#include <Image_AlienPixMap.hxx>
+#include <TColStd_HArray1OfAsciiString.hxx>
+#include <TColStd_HSequenceOfAsciiString.hxx>
 
 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
@@ -158,85 +147,62 @@ extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theNam
 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
 extern Handle(AIS_InteractiveContext)& TheAISContext();
 
-
 //==============================================================================
 //function : Vtrihedron 2d
 //purpose  : Create a plane with a 2D  trihedron from a faceselection
 //Draw arg : vtri2d  name
 //==============================================================================
 #include <AIS_PlaneTrihedron.hxx>
+static int VTrihedron2D (Draw_Interpretor& /*theDI*/,
+                         Standard_Integer  theArgsNum,
+                         const char**      theArgVec)
+{
+  if (theArgsNum != 2)
+  {
+    std::cerr << theArgVec[0]<< " error.\n";
+    return 1;
+  }
 
+  TopTools_ListOfShape aShapes;
+  ViewerTest::GetSelectedShapes (aShapes);
 
+  if (aShapes.Extent() != 1)
+  {
+    std::cerr << "Error: wrong number of selected shapes.\n";
+    return 1;
+  }
 
-static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+  const TopoDS_Shape& aShape = aShapes.First();
 
-{
-  // Verification des arguments
-  if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
+  TopoDS_Face     aFace = TopoDS::Face (aShape);
+  TopExp_Explorer aFaceExp (aFace, TopAbs_EDGE);
+  TopoDS_Edge     anEdge0 = TopoDS::Edge (aFaceExp.Current());
 
-  // Declarations
-  Standard_Integer myCurrentIndex;
-  // Fermeture des contextes
-  TheAISContext()->CloseAllContexts();
-  // Ouverture d'un contexte local et recuperation de son index.
-  TheAISContext()->OpenLocalContext();
-  myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
-  // On active les modes de selections faces.
-  TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
-  di<<" Select a face ."<<"\n";
-
-  // Boucle d'attente waitpick.
-  Standard_Integer argccc = 5;
-  const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-  const char **argvvv = (const char **) bufff;
-  while (ViewerMainLoop( argccc, argvvv) ) { }
-  // fin de la boucle
-
-  TopoDS_Shape ShapeB;
-  for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
-    ShapeB = TheAISContext()->SelectedShape();
-  }
-
-  TopoDS_Face  FaceB=TopoDS::Face(ShapeB);
-
-  // Construction du Plane
-  // recuperation des edges des faces.
-  TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
-
-  TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
-  // declarations
   gp_Pnt A,B,C;
-
-  // si il y a plusieurs edges
-  if (FaceExpB.More() ) {
-    FaceExpB.Next();
-    TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() );
-    BRepAdaptor_Curve theCurveB(EdgeB);
-    BRepAdaptor_Curve theCurveC(EdgeC);
-    A=theCurveC.Value(0.1);
-    B=theCurveC.Value(0.9);
-    C=theCurveB.Value(0.5);
+  if (aFaceExp.More())
+  {
+    aFaceExp.Next();
+    TopoDS_Edge anEdge1 = TopoDS::Edge (aFaceExp.Current() );
+    BRepAdaptor_Curve aCurve0 (anEdge0);
+    BRepAdaptor_Curve aCurve1 (anEdge1);
+    A = aCurve1.Value (0.1);
+    B = aCurve1.Value (0.9);
+    C = aCurve0.Value (0.5);
   }
-  else {
-    // FaceB a 1 unique edge courbe
-    BRepAdaptor_Curve theCurveB(EdgeB);
-    A=theCurveB.Value(0.1);
-    B=theCurveB.Value(0.9);
-    C=theCurveB.Value(0.5);
+  else
+  {
+    BRepAdaptor_Curve aCurve0 (anEdge0);
+    A = aCurve0.Value (0.1);
+    B = aCurve0.Value (0.9);
+    C = aCurve0.Value (0.5);
   }
-  // Construction du Geom_Plane
-  GC_MakePlane MkPlane(A,B,C);
-  Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
 
-  // Construction de l'AIS_PlaneTrihedron
-  Handle(AIS_PlaneTrihedron) theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane );
+  GC_MakePlane aMkPlane (A,B,C);
 
-  // Fermeture du contexte local.
-  TheAISContext()->CloseLocalContext(myCurrentIndex);
+  Handle(AIS_PlaneTrihedron) anAISPlaneTri = new AIS_PlaneTrihedron (aMkPlane.Value());
+  TCollection_AsciiString aName (theArgVec[1]);
 
-  // on le display & bind
-  TheAISContext()->Display(theAISPlaneTri );
-  GetMapOfAIS().Bind ( theAISPlaneTri ,argv[1]);
+  VDisplayAISObject (aName, anAISPlaneTri);
 
   return 0;
 }
@@ -250,47 +216,126 @@ static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char
 //Draw arg : vtrihedron  name  [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw]
 //==============================================================================
 
-static int VTrihedron (Draw_Interpretor& theDi,
+static int VTrihedron (Draw_Interpretor& /*theDi*/,
                        Standard_Integer  theArgsNb,
                        const char**      theArgVec)
 {
-  if (theArgsNb != 2 && theArgsNb != 5 && theArgsNb != 11)
+  if (theArgsNb < 2 || theArgsNb > 11)
+  {
+    std::cout << theArgVec[0] << " syntax error\n";
+    return 1;
+  }
+
+  // Parse parameters
+  NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
+  TCollection_AsciiString aParseKey;
+  for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
+  {
+    TCollection_AsciiString anArg (theArgVec [anArgIt]);
+
+    if (anArg.Value (1) == '-' && !anArg.IsRealValue())
+    {
+      aParseKey = anArg;
+      aParseKey.Remove (1);
+      aParseKey.LowerCase();
+      aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
+      continue;
+    }
+
+    if (aParseKey.IsEmpty())
+    {
+      continue;
+    }
+
+    aMapOfArgs(aParseKey)->Append (anArg);
+  }
+
+  // Check parameters
+  if ( (aMapOfArgs.IsBound ("xaxis") && !aMapOfArgs.IsBound ("zaxis"))
+    || (!aMapOfArgs.IsBound ("xaxis") && aMapOfArgs.IsBound ("zaxis")) )
   {
-    theDi << theArgVec[0] << " Syntax error\n";
+    std::cout << theArgVec[0] << " error: -xaxis and -yaxis parameters are to set together.\n";
     return 1;
   }
 
+  for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
+       aMapIt.More(); aMapIt.Next())
+  {
+    const TCollection_AsciiString& aKey = aMapIt.Key();
+    const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
+
+    // Bool key, without arguments
+    if (aKey.IsEqual ("hidelabels") && anArgs->IsEmpty())
+    {
+      continue;
+    }
+
+    if ( (aKey.IsEqual ("xaxis") || aKey.IsEqual ("zaxis") || aKey.IsEqual ("origin")) && anArgs->Length() == 3
+      && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue() && anArgs->Value(3).IsRealValue() )
+    {
+      continue;
+    }
+  }
+
+  // Process parameters
   gp_Pnt anOrigin (0.0, 0.0, 0.0);
   gp_Dir aDirZ = gp::DZ();
   gp_Dir aDirX = gp::DX();
-  Standard_Integer anArgIter = 2; // 1st is an IO name
-  if (anArgIter < theArgsNb)
+
+  Handle(TColStd_HSequenceOfAsciiString) aValues;
+
+  if (aMapOfArgs.Find ("origin", aValues))
   {
-    anOrigin.SetX (Draw::Atof (theArgVec[anArgIter++]));
-    anOrigin.SetY (Draw::Atof (theArgVec[anArgIter++]));
-    anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter++]));
-    if (anArgIter < theArgsNb)
-    {
-      Standard_Real aX = Draw::Atof (theArgVec[anArgIter++]);
-      Standard_Real aY = Draw::Atof (theArgVec[anArgIter++]);
-      Standard_Real aZ = Draw::Atof (theArgVec[anArgIter++]);
-      aDirZ.SetCoord (aX, aY, aZ);
+    anOrigin.SetX (aValues->Value(1).RealValue());
+    anOrigin.SetY (aValues->Value(2).RealValue());
+    anOrigin.SetZ (aValues->Value(3).RealValue());
+  }
 
-      aX = Draw::Atof (theArgVec[anArgIter++]);
-      aY = Draw::Atof (theArgVec[anArgIter++]);
-      aZ = Draw::Atof (theArgVec[anArgIter++]);
-      aDirX.SetCoord (aX, aY, aZ);
-    }
+  Handle(TColStd_HSequenceOfAsciiString) aValues2;
+  if (aMapOfArgs.Find ("xaxis", aValues) && aMapOfArgs.Find ("zaxis", aValues2))
+  {
+    Standard_Real aX = aValues->Value(1).RealValue();
+    Standard_Real aY = aValues->Value(2).RealValue();
+    Standard_Real aZ = aValues->Value(3).RealValue();
+    aDirX.SetCoord (aX, aY, aZ);
+
+    aX = aValues->Value(1).RealValue();
+    aY = aValues->Value(2).RealValue();
+    aZ = aValues->Value(3).RealValue();
+    aDirZ.SetCoord (aX, aY, aZ);
   }
 
   if (!aDirZ.IsNormal (aDirX, M_PI / 180.0))
   {
-    theDi << theArgVec[0] << " - VectorX is not normal to VectorZ\n";
+    std::cout << theArgVec[0] << " error - VectorX is not normal to VectorZ\n";
     return 1;
   }
 
   Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (anOrigin, aDirZ, aDirX);
   Handle(AIS_Trihedron) aShape = new AIS_Trihedron (aPlacement);
+
+  if (aMapOfArgs.Find ("hidelabels", aValues))
+  {
+    const Handle(Prs3d_Drawer)& aDrawer = aShape->Attributes();
+
+    if(!aDrawer->HasOwnDatumAspect())
+    {
+      Handle(Prs3d_DatumAspect) aDefAspect = ViewerTest::GetAISContext()->DefaultDrawer()->DatumAspect();
+
+      Handle(Prs3d_DatumAspect) aDatumAspect = new Prs3d_DatumAspect();
+      aDatumAspect->FirstAxisAspect()->SetAspect (aDefAspect->FirstAxisAspect()->Aspect());
+      aDatumAspect->SecondAxisAspect()->SetAspect (aDefAspect->SecondAxisAspect()->Aspect());
+      aDatumAspect->ThirdAxisAspect()->SetAspect (aDefAspect->ThirdAxisAspect()->Aspect());
+      aDatumAspect->SetAxisLength (aDefAspect->FirstAxisLength(),
+                                   aDefAspect->SecondAxisLength(),
+                                   aDefAspect->ThirdAxisLength());
+
+      aDrawer->SetDatumAspect (aDatumAspect);
+    }
+
+    aDrawer->DatumAspect()->SetToDrawLabels (Standard_False);
+  }
+
   VDisplayAISObject (theArgVec[1], aShape);
   return 0;
 }
@@ -312,26 +357,19 @@ static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv
   Standard_Boolean             ThereIsCurrent;
   Standard_Real                value;
   Standard_Boolean             hascol;
-#ifdef DEB
-  Quantity_NameOfColor         col;
-#else
+
   Quantity_NameOfColor         col = Quantity_NOC_BLACK ;
-#endif
 
   // Verification des arguments
-  if ( argc>3 ) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;}
+  if ( argc>3 ) {di<<argv[0]<<" Syntaxe error\n"; return 1;}
 
   // Verification du nombre d'arguments
   if (argc==1)      {ThereIsName=Standard_False;value=100;}
   else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);}
   else              {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);}
 
-  // On ferme le contexte local pour travailler dans le contexte global
-  if(TheAISContext()->HasOpenedContext())
-    TheAISContext()->CloseLocalContext();
-
   // On set le booleen ThereIsCurrent
-  if (TheAISContext() -> NbCurrents() > 0) {ThereIsCurrent=Standard_True;}
+  if (TheAISContext() -> NbSelected() > 0) {ThereIsCurrent=Standard_True;}
   else {ThereIsCurrent=Standard_False;}
 
 
@@ -350,7 +388,7 @@ static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv
       Handle(AIS_InteractiveObject) aShape=
         Handle(AIS_InteractiveObject)::DownCast(it.Key1());
 
-      if (!aShape.IsNull() &&  TheAISContext()->IsCurrent(aShape) )
+      if (!aShape.IsNull() &&  TheAISContext()->IsSelected(aShape) )
       {
 
         // On verifie que l'AIS InteraciveObject selectionne est bien
@@ -367,7 +405,7 @@ static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv
 
           // On downcast aShape  de AIS_InteractiveObject a AIS_Trihedron
           // pour lui appliquer la methode SetSize()
-          Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
+          Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
 
           // C'est bien un triedre,on chage sa valeur!
           aTrihedron->SetSize(value);
@@ -428,7 +466,7 @@ static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv
 
         // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
         // pour lui appliquer la methode SetSize()
-        Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape;
+        Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
 
         // C'est bien un triedre,on chage sa valeur
         aTrihedron->SetSize(value);
@@ -464,59 +502,24 @@ static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const c
 
 {
   // Verification des arguments
-  if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;}
+  if ( argc!=2) {di<<argv[0]<<" error\n"; return 1;}
 
-  // Declarations
-  Standard_Integer myCurrentIndex;
-  // Fermeture des contextes locaux
-  TheAISContext()->CloseAllContexts();
-
-  // On recupere tous les trihedrons de la GetMapOfAIS()
-  // et on active le mode de selection par face.
-  // =================================================
-
-  // Ouverture d'un contexte local et recuperation de son index.
-  TheAISContext()->OpenLocalContext(Standard_False);
-  myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
-
-  ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
-    it (GetMapOfAIS());
-  while(it.More()){
-    Handle(AIS_InteractiveObject) ShapeA =
-      Handle(AIS_InteractiveObject)::DownCast(it.Key1());
-    // On verifie que c'est bien un trihedron
-    if (!ShapeA.IsNull() &&
-      ShapeA->Type()==AIS_KOI_Datum  && ShapeA->Signature()==3  ) {
-        // on le downcast
-        Handle(AIS_Trihedron) TrihedronA =((*(Handle(AIS_Trihedron)*)&ShapeA));
-        // on le charge dans le contexte et on active le mode Plane.
-        TheAISContext()->Load(TrihedronA,0,Standard_False);
-        TheAISContext()->Activate(TrihedronA,3);
-      }
-      it.Next();
+  if (TheAISContext()->NbSelected() != 1)
+  {
+    std::cerr << "Error: Wrong number of selected shapes.\n";
+    return 1;
   }
 
-  di<<" Select a plane."<<"\n";
-  // Boucle d'attente waitpick.
-  Standard_Integer argccc = 5;
-  const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-  const char **argvvv = (const char **) bufff;
-  while (ViewerMainLoop( argccc, argvvv) ) { }
-  // fin de la boucle
-
-  Handle(AIS_InteractiveObject) theIOB;
-  for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
-    theIOB = TheAISContext()->Interactive();
+  TheAISContext()->InitSelected();
+  Handle(AIS_InteractiveObject) aTest = TheAISContext()->SelectedInteractive();
+  Handle(AIS_Plane) aPlane = Handle(AIS_Plane)::DownCast (aTest);
+  if (aPlane.IsNull())
+  {
+    std::cerr << "Error: Selected shape is not a plane.\n";
+    return 1;
   }
-  // on le downcast
-  Handle(AIS_Plane) PlaneB =((*(Handle(AIS_Plane)*)&theIOB));
 
-  // Fermeture du contexte local.
-  TheAISContext()->CloseLocalContext(myCurrentIndex);
-
-  // on le display & bind
-  TheAISContext()->Display(PlaneB );
-  GetMapOfAIS().Bind ( PlaneB ,argv[1]);
+  VDisplayAISObject (argv[1], aPlane);
 
   return 0;
 }
@@ -548,16 +551,16 @@ static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char*
   // Declarations
   Standard_Boolean HasArg;
   TCollection_AsciiString name;
-  Standard_Integer MyCurrentIndex;
 
   // Verification
-  if (argc<2 || argc>8 ) {di<<" Syntaxe error"<<"\n";return 1;}
+  if (argc<2 || argc>8 ) {di<<" Syntaxe error\n";return 1;}
   if (argc==8) HasArg=Standard_True;
   else HasArg=Standard_False;
 
   name=argv[1];
-  // Fermeture des contextes
-  TheAISContext()->CloseAllContexts();
+
+  TopTools_ListOfShape aShapes;
+  ViewerTest::GetSelectedShapes (aShapes);
 
   // Cas ou il y a des arguments
   // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
@@ -572,7 +575,7 @@ static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char*
     Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
     Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
     GetMapOfAIS().Bind (TheAxis,name);
-    TheAISContext()->Display(TheAxis);
+    TheAISContext()->Display(TheAxis, Standard_True);
   }
 
   // Pas d'arguments
@@ -580,70 +583,41 @@ static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char*
     // fonction vaxis
     // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
     if ( !strcasecmp(argv[0], "vaxis")) {
-      TheAISContext()->OpenLocalContext();
-      MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
-
-      // Active le mode edge et le mode vertex
-      TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
-      TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
-      di<<" Select an edge or a vertex."<<"\n";
-
-      // Boucle d'attente waitpick.
-      Standard_Integer argcc = 5;
-      const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-      const char **argvv = (const char **) buff;
-      while (ViewerMainLoop( argcc, argvv) ) { }
-      // fin de la boucle
-
-      // recuperation de la shape.
-      TopoDS_Shape ShapeA;
-      for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
-        ShapeA = TheAISContext()->SelectedShape();
-      }
-      // recuperation de l'AIS_InteractiveObject
-      //Handle(AIS_InteractiveObject) myAISio=TheAISContext()->Current();
-      // down cast en AIS_Point si sig et type
-      // AIS_Point -> Geom_Pnt ....
-
-      if (ShapeA.ShapeType()==TopAbs_VERTEX) {
-        // on desactive le mode edge
-        TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
-        di<<" Select a different vertex."<<"\n";
-
-        TopoDS_Shape ShapeB;
-        do {
-          // Boucle d'attente waitpick.
-          Standard_Integer argccc = 5;
-          const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-          const char **argvvv = (const char **) bufff;
-          while (ViewerMainLoop( argccc, argvvv) ) { }
-          // fin de la boucle
-          for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
-            ShapeB = TheAISContext()->SelectedShape();
-          }
-
+      if (aShapes.Extent() != 2 && aShapes.Extent() != 1)
+      {
+        std::cerr << "Error: Wrong number of selected shapes.\n";
+        return 1;
+      }
 
-        } while(ShapeB.IsSame(ShapeA) );
+      const TopoDS_Shape& aShapeA = aShapes.First();
+      if (aShapeA.ShapeType() == TopAbs_VERTEX)
+      {
+        if (aShapes.Extent() != 2)
+        {
+          std::cerr << "Error: Wron number of selected shapes.\n";
+          return 1;
+        }
 
-        // Fermeture du context local
-        TheAISContext()->CloseLocalContext(MyCurrentIndex);
+        const TopoDS_Shape& aShapeB = aShapes.Last();
+        if (aShapeB.ShapeType() != TopAbs_VERTEX)
+        {
+          std::cerr << "Syntax error: You should select two vertices or one edge.\n";
+          return 1;
+        }
 
         // Construction de l'axe
-        gp_Pnt   A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA)  );
-        gp_Pnt   B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB)  );
-        gp_Vec   V (A,B);
-        gp_Dir   D (V);
+        gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
+        gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
+        gp_Vec V (A,B);
+        gp_Dir D (V);
         Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
         Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
         GetMapOfAIS().Bind (TheAxis,name);
-        TheAISContext()->Display(TheAxis);
-      }
-      else {
-        // Un unique edge (ShapeA) a ete picke
-        // Fermeture du context local
-        TheAISContext()->CloseLocalContext(MyCurrentIndex);
-        // Constuction de l'axe
-        TopoDS_Edge    ed =TopoDS::Edge(ShapeA);
+        TheAISContext()->Display (TheAxis, Standard_True);
+      }
+      else
+      {
+        TopoDS_Edge    ed =TopoDS::Edge (aShapeA);
         TopoDS_Vertex  Va,Vb;
         TopExp::Vertices(ed,Va,Vb );
         gp_Pnt A=BRep_Tool::Pnt(Va);
@@ -653,56 +627,32 @@ static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char*
         Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
         Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
         GetMapOfAIS().Bind (TheAxis,name);
-        TheAISContext()->Display(TheAxis);
+        TheAISContext()->Display (TheAxis, Standard_True);
       }
 
     }
 
     // Fonction axispara
     // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
-    else if ( !strcasecmp(argv[0], "vaxispara")) {
-
-      TheAISContext()->OpenLocalContext();
-      MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
-
-      // Active le mode edge
-      TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
-      di<<" Select an edge."<<"\n";
-
-      // Boucle d'attente waitpick.
-      Standard_Integer argcc = 5;
-      const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-      const char **argvv = (const char **) buff;
-      while (ViewerMainLoop( argcc, argvv) ) { }
-      // fin de la boucle
-
-      TopoDS_Shape ShapeA;
-      for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
-        ShapeA = TheAISContext()->SelectedShape();
-      }
-      // Active le mode vertex et deactive edges
-      TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
-      TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
-      di<<" Select a vertex."<<"\n";
-
-      // Boucle d'attente waitpick.
-      Standard_Integer argccc = 5;
-      const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-      const char **argvvv = (const char **) bufff;
-      while (ViewerMainLoop( argccc, argvvv) ) { }
-      // fin de la boucle
-
-      // On peut choisir un pnt sur l'edge
-      TopoDS_Shape ShapeB;
-      for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
-        ShapeB = TheAISContext()->SelectedShape();
-      }
-      // Fermeture du context local
-      TheAISContext()->CloseLocalContext(MyCurrentIndex);
+    else if ( !strcasecmp(argv[0], "vaxispara"))
+    {
+      if (aShapes.Extent() != 2)
+      {
+        std::cerr << "Error: Wrong number of selected shapes.\n";
+        return 1;
+      }
 
-      // Construction de l'axe
-      TopoDS_Edge    ed=TopoDS::Edge(ShapeA) ;
-      gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
+      const TopoDS_Shape& aShapeA = aShapes.First();
+      const TopoDS_Shape& aShapeB = aShapes.Last();
+      if (!(aShapeA.ShapeType() == TopAbs_EDGE
+         && aShapeB.ShapeType() == TopAbs_VERTEX))
+      {
+        std::cerr << "Syntax error: You should select face and then vertex.\n";
+        return 1;
+      }
+
+      TopoDS_Edge    ed=TopoDS::Edge (aShapeA);
+      gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
       TopoDS_Vertex  Va,Vc;
       TopExp::Vertices(ed,Va,Vc );
       gp_Pnt A=BRep_Tool::Pnt(Va);
@@ -712,53 +662,31 @@ static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char*
       Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
       Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
       GetMapOfAIS().Bind (TheAxis,name);
-      TheAISContext()->Display(TheAxis);
+      TheAISContext()->Display (TheAxis, Standard_True);
 
     }
 
     // Fonction axisortho
-    else  {
-      TheAISContext()->OpenLocalContext();
-      MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
-
-      // Active le mode edge
-      TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) );
-      di<<" Select an edge."<<"\n";
-
-      // Boucle d'attente waitpick.
-      Standard_Integer argcc = 5;
-      const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-      const char **argvv = (const char **) buff;
-      while (ViewerMainLoop( argcc, argvv) ) { }
-      // fin de la boucle
-
-      TopoDS_Shape ShapeA;
-      for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
-        ShapeA = TheAISContext()->SelectedShape();
-      }
-      // Active le mode vertex et deactive edges
-      TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) );
-      TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) );
-      di<<" Slect a vertex."<<"\n";
-
-      // Boucle d'attente waitpick.
-      Standard_Integer argccc = 5;
-      const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-      const char **argvvv = (const char **) bufff;
-      while (ViewerMainLoop( argccc, argvvv) ) { }
-      // fin de la boucle
-
-      // On peut choisir un pnt sur l'edge
-      TopoDS_Shape ShapeB;
-      for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
-        ShapeB = TheAISContext()->SelectedShape();
-      }
-      // Fermeture du context local
-      TheAISContext()->CloseLocalContext(MyCurrentIndex);
+    else
+    {
+      if (aShapes.Extent() != 2)
+      {
+        std::cerr << "Error: Wrong number of selected shapes.\n";
+        return 1;
+      }
+
+      const TopoDS_Shape& aShapeA = aShapes.First();
+      const TopoDS_Shape& aShapeB = aShapes.Last();
+      if (!(aShapeA.ShapeType() == TopAbs_EDGE
+         && aShapeB.ShapeType() == TopAbs_VERTEX))
+      {
+        std::cerr << "Syntax error: You should select face and then vertex.\n";
+        return 1;
+      }
 
       // Construction de l'axe
-      TopoDS_Edge    ed=TopoDS::Edge(ShapeA) ;
-      gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
+      TopoDS_Edge    ed=TopoDS::Edge(aShapeA) ;
+      gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB) );
       TopoDS_Vertex  Va,Vc;
       TopExp::Vertices(ed,Va,Vc );
       gp_Pnt A=BRep_Tool::Pnt(Va);
@@ -769,7 +697,7 @@ static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char*
       Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
       Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
       GetMapOfAIS().Bind (TheAxis,name);
-      TheAISContext()->Display(TheAxis);
+      TheAISContext()->Display (TheAxis, Standard_True);
 
     }
 
@@ -801,16 +729,13 @@ static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char
   // Declarations
   Standard_Boolean HasArg;
   TCollection_AsciiString name;
-  Standard_Integer myCurrentIndex;
 
   // Verification
-  if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;}
+  if (argc<2 || argc>5 ) {di<<" Syntaxe error\n";return 1;}
   if (argc==5) HasArg=Standard_True;
   else HasArg=Standard_False;
 
   name=argv[1];
-  // Fermeture des contextes
-  TheAISContext()->CloseAllContexts();
 
   // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom)
   if (HasArg) {
@@ -820,50 +745,35 @@ static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char
     Handle(Geom_CartesianPoint )  myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]);
     Handle(AIS_Point)  myAISPoint=new AIS_Point(myGeomPoint );
     GetMapOfAIS().Bind (myAISPoint,name);
-    TheAISContext()->Display(myAISPoint);
+    TheAISContext()->Display (myAISPoint, Standard_True);
   }
 
   // Il n'a pas d'arguments
-  else {
-    TheAISContext()->OpenLocalContext();
-    myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
-
-    // Active le mode Vertex et Edges
-    TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
-    TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
-    di<<" Select a vertex or an edge(build the middle)"<<"\n";
-
-    // Boucle d'attente waitpick.
-    Standard_Integer argcc = 5;
-    const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-    const char **argvv = (const char **) buff;
-    while (ViewerMainLoop( argcc, argvv) ) { }
-    // fin de la boucle
+  else
+  {
+    TopTools_ListOfShape aShapes;
+    ViewerTest::GetSelectedShapes (aShapes);
 
-    TopoDS_Shape ShapeA;
-    for (TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
-      ShapeA= TheAISContext()->SelectedShape();
+    if (aShapes.Extent() != 1)
+    {
+      std::cerr << "Error: Wrong number of selected shapes.\n";
+      std::cerr << "\tYou should select one edge or vertex.\n";
+      return 1;
     }
 
-    if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
-      // Un vertex a ete selectionne
-      // Fermeture du context local
-      TheAISContext()->CloseLocalContext(myCurrentIndex);
+    const TopoDS_Shape& aShapeA = aShapes.First();
 
-      // Construction du point
-      gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
+    if (aShapeA.ShapeType()==TopAbs_VERTEX )
+    {
+      gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(aShapeA ) );
       Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A );
       Handle(AIS_Point)  myAISPoint = new AIS_Point  (myGeomPoint );
       GetMapOfAIS().Bind(myAISPoint,name);
-      TheAISContext()->Display(myAISPoint);
+      TheAISContext()->Display (myAISPoint, Standard_True);
     }
-    else {
-      // Un Edge a ete selectionne
-      // Fermeture du context local
-      TheAISContext()->CloseLocalContext(myCurrentIndex);
-
-      // Construction du point milieu de l'edge
-      TopoDS_Edge myEdge=TopoDS::Edge(ShapeA);
+    else
+    {
+      TopoDS_Edge myEdge=TopoDS::Edge(aShapeA);
       TopoDS_Vertex myVertexA,myVertexB;
       TopExp::Vertices (myEdge ,myVertexA ,myVertexB );
       gp_Pnt A=BRep_Tool::Pnt(myVertexA );
@@ -872,7 +782,7 @@ static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char
       Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2  , (A.Y()+B.Y())/2  , (A.Z()+B.Z())/2  );
       Handle(AIS_Point)  myAISPointM = new AIS_Point  (myGeomPointM );
       GetMapOfAIS().Bind(myAISPointM,name);
-      TheAISContext()->Display(myAISPointM);
+      TheAISContext()->Display (myAISPointM, Standard_True);
     }
 
   }
@@ -895,34 +805,31 @@ static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char
 //==============================================================================
 //function : VPlaneBuilder
 //purpose  : Build an AIS_Plane from selected entities or Named AIS components
-//Draw arg : vplane PlaneName [AxisName]  [PointName]
-//                            [PointName] [PointName] [PointName]
-//                            [PlaneName] [PointName]
+//Draw arg : vplane PlaneName [AxisName]  [PointName] [TypeOfSensitivity]
+//                            [PointName] [PointName] [PointName] [TypeOfSensitivity]
+//                            [PlaneName] [PointName] [TypeOfSensitivity]
 //==============================================================================
 
-static Standard_Integer VPlaneBuilder (Draw_Interpretor& di,
+static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/,
                                        Standard_Integer argc,
                                        const char** argv)
 {
   // Declarations
   Standard_Boolean hasArg;
   TCollection_AsciiString aName;
-  Standard_Integer aCurrentIndex;
 
   // Verification
-  if (argc<2 || argc>5 )
+  if (argc<2 || argc>6 )
   {
     std::cout<<" Syntax error\n";
     return 1;
   }
-  if (argc==5 || argc==4)
+  if (argc == 6 || argc==5 || argc==4)
     hasArg=Standard_True;
   else 
     hasArg=Standard_False;
 
   aName=argv[1];
-  // Close all contexts
-  TheAISContext()->CloseAllContexts();
 
   // There are some arguments
   if (hasArg)
@@ -995,21 +902,21 @@ static Standard_Integer VPlaneBuilder (Draw_Interpretor& di,
            Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
         {
           // B=A
-          std::cout<<"vplane error: same points"<<"\n";return 1;
+          std::cout<<"vplane error: same points\n";return 1;
         }
         if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
            Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
            Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
         {
           // C=A
-          std::cout<<"vplane error: same points"<<"\n";return 1;
+          std::cout<<"vplane error: same points\n";return 1;
         }
         if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
            Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
            Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
         {
           // C=B
-          std::cout<<"vplane error: same points"<<"\n";return 1;
+          std::cout<<"vplane error: same points\n";return 1;
         }
 
         gp_Pnt A = aCartPointA->Pnt();
@@ -1021,7 +928,24 @@ static Standard_Integer VPlaneBuilder (Draw_Interpretor& di,
         Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
         Handle(AIS_Plane)  anAISPlane = new AIS_Plane(aGeomPlane );
         GetMapOfAIS().Bind (anAISPlane,aName );
-        TheAISContext()->Display(anAISPlane);
+        if (argc == 6)
+        {
+          Standard_Integer aType = Draw::Atoi (argv[5]);
+          if (aType != 0 && aType != 1)
+          {
+            std::cout << "vplane error: wrong type of sensitivity!\n"
+                      << "Should be one of the following values:\n"
+                      << "0 - Interior\n"
+                      << "1 - Boundary"
+                      << std::endl;
+            return 1;
+          }
+          else
+          {
+            anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
+          }
+        }
+        TheAISContext()->Display (anAISPlane, Standard_True);
       }
 
       // The first argument is an AIS_Axis
@@ -1062,7 +986,24 @@ static Standard_Integer VPlaneBuilder (Draw_Interpretor& di,
       Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
       Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
       GetMapOfAIS().Bind (anAISPlane,aName );
-      TheAISContext()->Display(anAISPlane);
+      if (argc == 5)
+      {
+        Standard_Integer aType = Draw::Atoi (argv[4]);
+        if (aType != 0 && aType != 1)
+        {
+          std::cout << "vplane error: wrong type of sensitivity!\n"
+                    << "Should be one of the following values:\n"
+                    << "0 - Interior\n"
+                    << "1 - Boundary"
+                    << std::endl;
+          return 1;
+        }
+        else
+        {
+          anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
+        }
+      }
+      TheAISContext()->Display (anAISPlane, Standard_True);
 
     }
     // The first argumnet is an AIS_Plane
@@ -1100,7 +1041,24 @@ static Standard_Integer VPlaneBuilder (Draw_Interpretor& di,
       // Construction of an AIS_Plane
       Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
       GetMapOfAIS().Bind (anAISPlane, aName);
-      TheAISContext()->Display(anAISPlane);
+      if (argc == 5)
+      {
+        Standard_Integer aType = Draw::Atoi (argv[4]);
+        if (aType != 0 && aType != 1)
+        {
+          std::cout << "vplane error: wrong type of sensitivity!\n"
+                    << "Should be one of the following values:\n"
+                    << "0 - Interior\n"
+                    << "1 - Boundary"
+                    << std::endl;
+          return 1;
+        }
+        else
+        {
+          anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
+        }
+      }
+      TheAISContext()->Display (anAISPlane, Standard_True);
     }
     // Error
     else
@@ -1112,103 +1070,32 @@ static Standard_Integer VPlaneBuilder (Draw_Interpretor& di,
   // There are no arguments
   else 
   {
+    TopTools_ListOfShape aShapes;
+    ViewerTest::GetSelectedShapes (aShapes);
+
     // Function vplane
     // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
     if (!strcasecmp(argv[0], "vplane"))
     {
-      TheAISContext()->OpenLocalContext();
-      aCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
-
-      // Active modes Vertex, Edge and Face
-      TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
-      TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
-      TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
-      std::cout<<"Select a vertex, a face or an edge\n";
-
-      // Wait for picking
-      Standard_Integer argcc = 5;
-      const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-      const char **argvv = (const char **) buff;
-      while (ViewerMainLoop( argcc, argvv) ) { }
-      // end of the loop
-
-      TopoDS_Shape aShapeA;
-      for (TheAISContext()->InitSelected();
-           TheAISContext()->MoreSelected();
-           TheAISContext()->NextSelected())
+      if (aShapes.Extent() < 1 || aShapes.Extent() > 3)
       {
-        aShapeA = TheAISContext()->SelectedShape();
+        std::cerr << "Error: Wront number of selected shapes.\n";
+        std::cerr << "\tYou should one of variant: face, edge and vertex or three vertices.\n";
+        return 1;
       }
 
-      // aShapeA is a Vertex
-      if (aShapeA.ShapeType()==TopAbs_VERTEX )
+      const TopoDS_Shape& aShapeA = aShapes.First();
+      if (aShapeA.ShapeType() == TopAbs_VERTEX)
       {
-        TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
-        std::cout<<" Select an edge or a different vertex\n";
-
-        // Wait for picking
-        Standard_Integer argccc = 5;
-        const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-        const char **argvvv = (const char **) bufff;
-        while (ViewerMainLoop( argccc, argvvv) ) { }
-        // end of the loop
-
-        TopoDS_Shape aShapeB;
-        for (TheAISContext()->InitSelected();
-          TheAISContext()->MoreSelected();
-          TheAISContext()->NextSelected())
-        {
-          aShapeB = TheAISContext()->SelectedShape();
-        }
-        // aShapeB is a Vertex
-        if (aShapeB.ShapeType()==TopAbs_VERTEX)
+        if (aShapes.Extent() == 2)
         {
-          // A and B are the same
-          if (aShapeB.IsSame(aShapeA))
+          const TopoDS_Shape& aShapeB = aShapes.Last();
+          if (aShapeB.ShapeType() != TopAbs_EDGE)
           {
-            std::cout<<" vplane: error, same points selected\n";
+            std::cerr << "Syntax error: Together with vertex should be edge.\n";
             return 1;
           }
-          TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
-          std::cout<<" Select a different vertex\n";
-
-          // Wait for picking
-          Standard_Integer argcccc = 5;
-          const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-          const char **argvvvv = (const char **) buffff;
-          while (ViewerMainLoop( argcccc, argvvvv) ) { }
-          // end of the loop
-
-          TopoDS_Shape aShapeC;
-          for (TheAISContext()->InitSelected();
-               TheAISContext()->MoreSelected();
-               TheAISContext()->NextSelected())
-          {
-            aShapeC = TheAISContext()->SelectedShape();
-          }
-          // aShapeC is the same as A or B
-          if (aShapeC.IsSame(aShapeA)||aShapeC.IsSame(aShapeB))
-          {
-            std::cout<<" vplane: error, same points selected\n";
-            return 1;
-          }
-
-          // Close the local context
-          TheAISContext()->CloseLocalContext(aCurrentIndex);
 
-          // Construction of plane
-          gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
-          gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
-          gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
-          GC_MakePlane MkPlane(A, B, C);
-          Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
-          Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
-          GetMapOfAIS().Bind (anAISPlane, aName);
-          TheAISContext()->Display(anAISPlane);
-        }
-        // ShapeB is an edge
-        else
-        {
           // Verify that the vertex is not on the edge ShapeB
           TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
           TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
@@ -1222,9 +1109,6 @@ static Standard_Integer VPlaneBuilder (Draw_Interpretor& di,
           }
           else
           {
-            // Close the local context
-            TheAISContext()->CloseLocalContext(aCurrentIndex);
-            // Construction of plane
             gp_Pnt A = BRep_Tool::Pnt(aVertA);
             TopoDS_Vertex aVBa, aVBb;
             TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
@@ -1234,32 +1118,56 @@ static Standard_Integer VPlaneBuilder (Draw_Interpretor& di,
             Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
             Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
             GetMapOfAIS().Bind (anAISPlane, aName);
-            TheAISContext()->Display(anAISPlane);
+            TheAISContext()->Display (anAISPlane, Standard_True);
+          }
+        }
+        else if (aShapes.Extent() == 3)
+        {
+          TopTools_ListOfShape::Iterator anIter (aShapes);
+
+          anIter.Next();
+          const TopoDS_Shape& aShapeB = anIter.Value();
+
+          anIter.Next();
+          const TopoDS_Shape& aShapeC = anIter.Value();
+
+          if (!(aShapeB.ShapeType() == TopAbs_VERTEX
+             && aShapeC.ShapeType() == TopAbs_VERTEX))
+          {
+            std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n";
+            return 1;
           }
+
+          gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
+          gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
+          gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
+          GC_MakePlane MkPlane(A, B, C);
+          Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
+          Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
+          GetMapOfAIS().Bind (anAISPlane, aName);
+          TheAISContext()->Display (anAISPlane, Standard_True);
+        }
+        else
+        {
+          std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n";
+          return 1;
         }
       }
-      // aShapeA is an edge
-      else if (aShapeA.ShapeType()==TopAbs_EDGE)
+      else if (aShapeA.ShapeType() == TopAbs_EDGE)
       {
-        TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
-        TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
-        std::cout<<" Select a vertex that don't belong to the edge\n";
-
-        // Wait for picking
-        Standard_Integer argccc = 5;
-        const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-        const char **argvvv = (const char **) bufff;
-        while (ViewerMainLoop( argccc, argvvv) ) { }
-        // end of the loop
+        if (aShapes.Extent() != 2)
+        {
+          std::cerr << "Error: wrong number of selected shapes.\n";
+          return 1;
+        }
 
-        TopoDS_Shape aShapeB;
-        for (TheAISContext()->InitSelected();
-             TheAISContext()->MoreSelected();
-             TheAISContext()->NextSelected())
+        const TopoDS_Shape& aShapeB = aShapes.Last();
+        if (aShapeB.ShapeType() != TopAbs_VERTEX)
         {
-          aShapeB = TheAISContext()->SelectedShape();
+          std::cerr << "Syntax error: Together with edge should be vertex.\n";
+          return 1;
         }
-        // aShapeB should be a Vertex
+
         // Check that the vertex aShapeB is not on the edge
         TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
         TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
@@ -1271,29 +1179,20 @@ static Standard_Integer VPlaneBuilder (Draw_Interpretor& di,
           std::cout<<" vplane: error point is on the edge\n";
           return 1;
         }
-        else
-        {
-          // Close the local context
-          TheAISContext()->CloseLocalContext(aCurrentIndex);
-          // Construction of plane
-          gp_Pnt B = BRep_Tool::Pnt(aVertB);
-          TopoDS_Vertex aVAa, aVAb;
-          TopExp::Vertices(anEdgeA, aVAa, aVAb);
-          gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
-          gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
-          GC_MakePlane MkPlane (B,Aa,Ab);
-          Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
-          Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
-          GetMapOfAIS().Bind (anAISPlane ,aName);
-          TheAISContext()->Display(anAISPlane);
-        }
+
+        gp_Pnt B = BRep_Tool::Pnt(aVertB);
+        TopoDS_Vertex aVAa, aVAb;
+        TopExp::Vertices(anEdgeA, aVAa, aVAb);
+        gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
+        gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
+        GC_MakePlane MkPlane (B,Aa,Ab);
+        Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
+        Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
+        GetMapOfAIS().Bind (anAISPlane ,aName);
+        TheAISContext()->Display (anAISPlane, Standard_True);
       }
-      // aShapeA is a Face
-      else
+      else if (aShapeA.ShapeType() == TopAbs_FACE)
       {
-        // Close the local context: nothing to select
-        TheAISContext()->CloseLocalContext(aCurrentIndex);
-        // Construction of plane
         TopoDS_Face aFace = TopoDS::Face(aShapeA);
         BRepAdaptor_Surface aSurface (aFace, Standard_False);
         if (aSurface.GetType()==GeomAbs_Plane)
@@ -1302,7 +1201,7 @@ static Standard_Integer VPlaneBuilder (Draw_Interpretor& di,
           Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
           Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
           GetMapOfAIS().Bind (anAISPlane, aName);
-          TheAISContext()->Display(anAISPlane);
+          TheAISContext()->Display (anAISPlane, Standard_True);
         }
         else
         {
@@ -1310,6 +1209,11 @@ static Standard_Integer VPlaneBuilder (Draw_Interpretor& di,
           return 1;
         }
       }
+      else
+      {
+        std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n";
+        return 1;
+      }
     }
 
     // Function vPlanePara
@@ -1317,120 +1221,44 @@ static Standard_Integer VPlaneBuilder (Draw_Interpretor& di,
     // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
     else if (!strcasecmp(argv[0], "vplanepara"))
     {
-      TheAISContext()->OpenLocalContext();
-      aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
-
-      // Activate modes Vertex and Face
-      TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
-      TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
-      std::cout<<" Select a vertex or a face\n";
-
-      // Wait for picking
-      Standard_Integer argcc = 5;
-      const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-      const char **argvv = (const char **) buff;
-      while (ViewerMainLoop( argcc, argvv) ) { }
-      // end of the loop
-
-      TopoDS_Shape aShapeA;
-      for (TheAISContext()->InitSelected();
-           TheAISContext()->MoreSelected();
-           TheAISContext()->NextSelected())
+      if (aShapes.Extent() != 2)
       {
-        aShapeA = TheAISContext()->SelectedShape();
+        std::cerr << "Error: Wrong number of selected shapes.\n";
+        return 1;
       }
 
-      if (aShapeA.ShapeType()==TopAbs_VERTEX )
+      const TopoDS_Shape* aShapeA = &aShapes.First();
+      const TopoDS_Shape* aShapeB = &aShapes.Last();
+      if (aShapeA->ShapeType() != TopAbs_VERTEX)
       {
-        // aShapeA is a vertex
-        // Deactivate the mode Vertex
-        TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1));
-        std::cout<<" Select a face\n";
-
-        // Wait for picking
-        Standard_Integer argccc = 5;
-        const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-        const char **argvvv = (const char **) bufff;
-        while (ViewerMainLoop( argccc, argvvv) ) { }
-        // end of the loop
-
-        TopoDS_Shape aShapeB;
-        for (TheAISContext()->InitSelected();
-             TheAISContext()->MoreSelected();
-             TheAISContext()->NextSelected())
-        {
-          // A vertex ShapeA can be on Face ShapeB
-          aShapeB = TheAISContext()->SelectedShape();
-        }
+        std::swap (aShapeA, aShapeB);
+      }
 
-        // Close the local context
-        TheAISContext()->CloseLocalContext(aCurrentIndex);
+      if (!(aShapeA->ShapeType() == TopAbs_VERTEX
+         && aShapeB->ShapeType() == TopAbs_FACE))
+      {
+        std::cerr << "Syntax error: you should select face and vertex.\n";
+        return 1;
+      }
 
-        // Construction of plane
-        gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
+      gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(*aShapeA));
 
-        TopoDS_Face aFace = TopoDS::Face(aShapeB);
-        BRepAdaptor_Surface aSurface (aFace, Standard_False);
-        if (aSurface.GetType()==GeomAbs_Plane )
-        {
-          gp_Pln aPlane = aSurface.Plane();
-          // Construct a plane parallel to aGeomPlane through A
-          aPlane.SetLocation(A);
-          Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
-          Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
-          GetMapOfAIS().Bind (aAISPlane ,aName);
-          TheAISContext()->Display(aAISPlane);
-        }
-        else
-        {
-          std::cout<<" vplanepara: error\n";
-          return 1;
-        }
+      TopoDS_Face aFace = TopoDS::Face(*aShapeB);
+      BRepAdaptor_Surface aSurface (aFace, Standard_False);
+      if (aSurface.GetType() == GeomAbs_Plane)
+      {
+        gp_Pln aPlane = aSurface.Plane();
+        // Construct a plane parallel to aGeomPlane through A
+        aPlane.SetLocation(A);
+        Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
+        Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
+        GetMapOfAIS().Bind (aAISPlane ,aName);
+        TheAISContext()->Display (aAISPlane, Standard_True);
       }
       else
       {
-        // ShapeA is a Face
-        // Deactive the mode Face
-        TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
-        std::cout<<" Select a vertex\n";
-
-        // Wait for picking
-        Standard_Integer argccc = 5;
-        const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-        const char **argvvv = (const char **) bufff;
-        while (ViewerMainLoop( argccc, argvvv) ) { }
-        // end of the loop
-
-        TopoDS_Shape aShapeB;
-        for (TheAISContext()->InitSelected();
-             TheAISContext()->MoreSelected();
-             TheAISContext()->NextSelected())
-        {
-          // A vertex ShapeB can be on Face ShapeA
-          aShapeB = TheAISContext()->SelectedShape();
-        }
-        // Close the local context
-        TheAISContext()->CloseLocalContext(aCurrentIndex);
-
-        // Construction of plane
-        gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
-
-        TopoDS_Face aFace=TopoDS::Face(aShapeA);
-        BRepAdaptor_Surface aSurface (aFace, Standard_False);
-        if (aSurface.GetType()==GeomAbs_Plane )
-        {
-          gp_Pln aPlane = aSurface.Plane();
-          aPlane.SetLocation(B);
-          Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
-          // Construct a plane parallel to aGeomPlane through B
-          Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, B);
-          GetMapOfAIS().Bind (anAISPlane, aName);
-          TheAISContext()->Display(anAISPlane);
-        }
-        else
-        {
-          std::cout<<" vplanepara: error"<<"\n";return 1;
-        }
+        std::cerr << "Error: Builded surface is not a plane.\n";
+        return 1;
       }
     }
 
@@ -1439,171 +1267,182 @@ static Standard_Integer VPlaneBuilder (Draw_Interpretor& di,
     // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
     else
     {
-      TheAISContext()->OpenLocalContext();
-      aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
-
-      // Activate the modes Edge and Face
-      TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
-      TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
-      std::cout<<" Select a face and an edge coplanar\n";
+      if (aShapes.Extent() != 2)
+      {
+        std::cerr << "Error: wrong number of selected shapes.\n";
+        return 1;
+      }
 
-      // Wait for picking
-      Standard_Integer argcc = 5;
-      const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-      const char **argvv = (const char **) buff;
-      while (ViewerMainLoop( argcc, argvv) ) { }
-      // end of the loop
+      const TopoDS_Shape* aShapeA = &aShapes.First();
+      const TopoDS_Shape* aShapeB = &aShapes.Last();
 
-      TopoDS_Shape aShapeA;
-      for (TheAISContext()->InitSelected();
-           TheAISContext()->MoreSelected();
-           TheAISContext()->NextSelected())
+      if (aShapeA->ShapeType() != TopAbs_EDGE)
       {
-        aShapeA = TheAISContext()->SelectedShape();
+        std::swap (aShapeA, aShapeB);
       }
 
-      if (aShapeA.ShapeType()==TopAbs_EDGE )
+      if (!(aShapeA->ShapeType() == TopAbs_EDGE
+         && aShapeB->ShapeType() == TopAbs_FACE))
       {
-        // ShapeA is an edge, deactivate the mode Edge...
-        TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
-        std::cout<<" Select a face\n";
-
-        // Wait for picking
-        Standard_Integer argccc = 5;
-        const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-        const char **argvvv = (const char **) bufff;
-        while (ViewerMainLoop( argccc, argvvv) ) { }
-        // end of the loop
-
-        TopoDS_Shape aShapeB;
-        for (TheAISContext()->InitSelected();
-             TheAISContext()->MoreSelected();
-             TheAISContext()->NextSelected())
-        {
-          // Edge ShapeA can be on Face ShapeB
-          aShapeB = TheAISContext()->SelectedShape();
-        }
-
-        // Close the local context
-        TheAISContext()->CloseLocalContext(aCurrentIndex);
+        std::cerr << "Error: you should select edge and face.\n";
+        return 1;
+      }
 
-        // Construction of plane
-        TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
-        TopoDS_Vertex aVAa, aVAb;
-        TopExp::Vertices(anEdgeA, aVAa, aVAb);
-        gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
-        gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
-        gp_Vec ab (Aa,Ab);
-
-        gp_Dir Dab (ab);
-        // Creation of rotation axis
-        gp_Ax1 aRotAxis (Aa,Dab);
-
-        TopoDS_Face aFace = TopoDS::Face(aShapeB);
-        // The edge must be parallel to the face
-        BRepExtrema_ExtPF aHeightA (aVAa, aFace);
-        BRepExtrema_ExtPF aHeightB (aVAb, aFace);
-        // Compare to heights
-        if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
-            >Precision::Confusion())
-        {
-          // the edge is not parallel to the face
-          std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
-          return 1;
-        }
-        // the edge is OK
-        BRepAdaptor_Surface aSurface (aFace, Standard_False);
-        if (aSurface.GetType()==GeomAbs_Plane)
-        {
-          gp_Pln aPlane = aSurface.Plane();
-          // It rotates a half turn round the axis of rotation
-          aPlane.Rotate(aRotAxis , M_PI/2);
-
-          Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
-          // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
-          gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
-          Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
-          GetMapOfAIS().Bind (anAISPlane, aName);
-          TheAISContext()->Display(anAISPlane);
-        }
-        else
-        {
-          std::cout<<" vplaneortho: error\n";
-          return 1;
-        }
+      // Construction of plane
+      TopoDS_Edge anEdgeA = TopoDS::Edge(*aShapeA);
+      TopoDS_Vertex aVAa, aVAb;
+      TopExp::Vertices(anEdgeA, aVAa, aVAb);
+      gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
+      gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
+      gp_Vec ab (Aa,Ab);
+
+      gp_Dir Dab (ab);
+      // Creation of rotation axis
+      gp_Ax1 aRotAxis (Aa,Dab);
+
+      TopoDS_Face aFace = TopoDS::Face(*aShapeB);
+      // The edge must be parallel to the face
+      BRepExtrema_ExtPF aHeightA (aVAa, aFace);
+      BRepExtrema_ExtPF aHeightB (aVAb, aFace);
+      // Compare to heights
+      if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
+          >Precision::Confusion())
+      {
+        // the edge is not parallel to the face
+        std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
+        return 1;
+      }
+      // the edge is OK
+      BRepAdaptor_Surface aSurface (aFace, Standard_False);
+      if (aSurface.GetType()==GeomAbs_Plane)
+      {
+        gp_Pln aPlane = aSurface.Plane();
+        // It rotates a half turn round the axis of rotation
+        aPlane.Rotate(aRotAxis , M_PI/2);
+
+        Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
+        // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
+        gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
+        Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
+        GetMapOfAIS().Bind (anAISPlane, aName);
+        TheAISContext()->Display (anAISPlane, Standard_True);
       }
       else
       {
-        // ShapeA is a Face, deactive the mode Face.
-        TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
-        std::cout<<" Select an edge\n";
-
-        // Wait for picking
-        Standard_Integer argccc = 5;
-        const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-        const char **argvvv = (const char **) bufff;
-        while (ViewerMainLoop( argccc, argvvv) ) { }
-        // end of the loop
-
-        TopoDS_Shape aShapeB;
-        for (TheAISContext()->InitSelected();
-             TheAISContext()->MoreSelected();
-             TheAISContext()->NextSelected())
-        {
-          // Edge ShapeB can be on Face ShapeA
-          aShapeB = TheAISContext()->SelectedShape();
-        }
-        // Close the local context
-        TheAISContext()->CloseLocalContext(aCurrentIndex);
-
-        // Construction of plane
-        TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
-        TopoDS_Vertex aVBa, aVBb;
-        TopExp::Vertices(anEdgeB, aVBa, aVBb);
-        gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
-        gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
-        gp_Vec ab (aBa,aBb);
-        gp_Dir Dab (ab);
-        // Creation of rotation axe
-        gp_Ax1 aRotAxis (aBa,Dab);
-
-        TopoDS_Face aFace = TopoDS::Face(aShapeA);
-        // The edge must be parallel to the face
-        BRepExtrema_ExtPF aHeightA (aVBa, aFace);
-        BRepExtrema_ExtPF aHeightB (aVBb, aFace);
-        // Comparing the two heights
-        if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
-            >Precision::Confusion())
-        {
-          // the edge is not parallel to the face
-          std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
-          return 1;
-        }
-        // The edge is OK
-        BRepAdaptor_Surface aSurface (aFace, Standard_False);
-        if (aSurface.GetType()==GeomAbs_Plane)
-        {
-          gp_Pln aPlane = aSurface.Plane();
-          // It rotates a half turn round the axis of rotation
-          aPlane.Rotate(aRotAxis , M_PI/2);
-          Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
-          // constructed aGeomPlane parallel to a plane containing the edge theGeomPlane (center mid-edge)
-          gp_Pnt aMiddle ((aBa.X()+aBb.X() )/2 , (aBa.Y()+aBb.Y() )/2 , (aBa.Z()+aBb.Z() )/2 );
-          Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
-          GetMapOfAIS().Bind (anAISPlane ,aName);
-          TheAISContext()->Display(anAISPlane);
-        }
-        else
-        {
-          std::cout<<" vplaneortho: error\n";
-          return 1;
-        }
+        std::cout<<" vplaneortho: error\n";
+        return 1;
       }
     }
   }
   return 0;
 }
 
+//===============================================================================================
+//function : VChangePlane
+//purpose  :
+//===============================================================================================
+static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
+{
+  Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
+  if (aContextAIS.IsNull())
+  {
+    std::cout << theArgVec[0] << "AIS context is not available.\n";
+    return 1;
+  }
+
+  if (theArgsNb < 3 || theArgsNb > 11)
+  {
+    std::cerr << theArgVec[0] 
+              << ": incorrect number of command arguments.\n"
+              << "Type help for more information.\n";
+    return 1;
+  }
+
+  TCollection_AsciiString aName (theArgVec[1]);
+
+  Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName)
+    ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName))
+    : NULL;
+
+  if ( aPlane.IsNull() )
+  {
+    std::cout << theArgVec[0] 
+              << ": there is no interactive plane with the given name."
+              << "Type help for more information.\n";
+    return 1;
+  }
+
+  Standard_Real aCenterX = aPlane->Center().X();
+  Standard_Real aCenterY = aPlane->Center().Y();
+  Standard_Real aCenterZ = aPlane->Center().Z();
+
+  Standard_Real aDirX = aPlane->Component()->Axis().Direction().X();
+  Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y();
+  Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z();
+
+  Standard_Real aSizeX = 0.0;
+  Standard_Real aSizeY = 0.0;
+  aPlane->Size (aSizeX, aSizeY);
+  Standard_Boolean isUpdate = Standard_True;
+
+  TCollection_AsciiString aPName, aPValue;
+  for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
+  {
+    const TCollection_AsciiString anArg = theArgVec[anArgIt];
+    TCollection_AsciiString anArgCase = anArg;
+    anArgCase.UpperCase();
+    if (ViewerTest::SplitParameter (anArg, aPName, aPValue))
+    {
+      aPName.UpperCase();
+      if (aPName.IsEqual ("X"))
+      {
+        aCenterX = aPValue.RealValue();
+      }
+      else if (aPName.IsEqual ("Y"))
+      {
+        aCenterY = aPValue.RealValue();
+      }
+      else if (aPName.IsEqual ("Z"))
+      {
+        aCenterZ = aPValue.RealValue();
+      }
+      else if (aPName.IsEqual ("DX"))
+      {
+        aDirX = aPValue.RealValue();
+      }
+      else if (aPName.IsEqual ("DY"))
+      {
+        aDirY = aPValue.RealValue();
+      }
+      else if (aPName.IsEqual ("DZ"))
+      {
+        aDirZ = aPValue.RealValue();
+      }
+      else if (aPName.IsEqual ("SX"))
+      {
+        aSizeX = aPValue.RealValue();
+      }
+      else if (aPName.IsEqual ("SY"))
+      {
+        aSizeY = aPValue.RealValue();
+      }
+    }
+    else if (anArg.IsEqual ("NOUPDATE"))
+    {
+      isUpdate = Standard_False;
+    }
+  }
+
+  gp_Dir aDirection (aDirX, aDirY, aDirZ);
+  gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ);
+  aPlane->SetCenter (aCenterPnt);
+  aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection));
+  aPlane->SetSize (aSizeX, aSizeY);
+
+  aContextAIS->Update (aPlane, isUpdate);
+
+  return 0;
+}
 
 //==============================================================================
 // Fonction  vline
@@ -1622,11 +1461,8 @@ static Standard_Integer VPlaneBuilder (Draw_Interpretor& di,
 
 static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
-  Standard_Integer myCurrentIndex;
   // Verifications
-  if (argc!=4 && argc!=8 && argc!=2 )  {di<<"vline error: number of arguments not correct "<<"\n";return 1; }
-  // Fermeture des contextes
-  TheAISContext()->CloseAllContexts();
+  if (argc!=4 && argc!=8 && argc!=2 )  {di<<"vline error: number of arguments not correct \n";return 1; }
 
   // On recupere les parametres
   Handle(AIS_InteractiveObject) theShapeA;
@@ -1646,31 +1482,31 @@ static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char*
         if (theShapeA.IsNull() ||
           (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
         {
-          di <<"vline error: wrong type of 2de argument."<<"\n";
+          di <<"vline error: wrong type of 2de argument.\n";
           return 1;
         }
       }
-    else {di <<"vline error: wrong type of 1st argument."<<"\n";return 1; }
+    else {di <<"vline error: wrong type of 1st argument.\n";return 1; }
     // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
-    Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA;
-    Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
+    Handle(AIS_Point) theAISPointA= Handle(AIS_Point)::DownCast (theShapeA);
+    Handle(AIS_Point) theAISPointB= Handle(AIS_Point)::DownCast (theShapeB);
 
     Handle(Geom_Point ) myGeomPointBA=  theAISPointA->Component();
-    Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)&  myGeomPointBA);
+    Handle(Geom_CartesianPoint ) myCartPointA= Handle(Geom_CartesianPoint)::DownCast (myGeomPointBA);
     //    Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
 
     Handle(Geom_Point ) myGeomPointB=  theAISPointB->Component();
-    Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)&  myGeomPointB);
+    Handle(Geom_CartesianPoint ) myCartPointB= Handle(Geom_CartesianPoint)::DownCast (myGeomPointB);
     //    Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
 
     if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
       // B=A
-      di<<"vline error: same points"<<"\n";return 1;
+      di<<"vline error: same points\n";return 1;
     }
     // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
     Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
     GetMapOfAIS().Bind(theAISLine,argv[1] );
-    TheAISContext()->Display(theAISLine );
+    TheAISContext()->Display (theAISLine, Standard_True);
 
   }
 
@@ -1691,74 +1527,43 @@ static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char*
 
     Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
     GetMapOfAIS().Bind(theAISLine,argv[1] );
-    TheAISContext()->Display(theAISLine );
+    TheAISContext()->Display (theAISLine, Standard_True);
 
   }
 
   // Pas de parametres: Selection dans le viewer.
   // ============================================
 
-  else {
-    TheAISContext()->OpenLocalContext();
-    myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
-
-    // Active le mode Vertex.
-    TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
-    di<<" Select a vertex "<<"\n";
-
-    // Boucle d'attente waitpick.
-    Standard_Integer argcc = 5;
-    const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-    const char **argvv = (const char **) buff;
-    while (ViewerMainLoop( argcc, argvv) ) { }
-    // fin de la boucle
-
-    TopoDS_Shape ShapeA;
-    for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
-      ShapeA = TheAISContext()->SelectedShape();
+  else
+  {
+    TopTools_ListOfShape aShapes;
+    ViewerTest::GetSelectedShapes (aShapes);
+    if (aShapes.Extent() != 2)
+    {
+      std::cerr << "Error: wrong number of selected shapes.\n";
+      return 1;
     }
 
-    // ShapeA est un Vertex
-    if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
-
-      di<<" Select a different vertex."<<"\n";
-
-      TopoDS_Shape ShapeB;
-      do {
-
-        // Boucle d'attente waitpick.
-        Standard_Integer argccc = 5;
-        const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-        const char **argvvv = (const char **) bufff;
-        while (ViewerMainLoop( argccc, argvvv) ) { }
-        // fin de la boucle
-
-        for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
-          ShapeB = TheAISContext()->SelectedShape();
-        }
-
-
-      } while(ShapeB.IsSame(ShapeA) );
+    const TopoDS_Shape& aShapeA = aShapes.First();
+    const TopoDS_Shape& aShapeB = aShapes.Last();
 
-      // Fermeture du context local
-      TheAISContext()->CloseLocalContext(myCurrentIndex);
-
-      // Construction de la line
-      gp_Pnt   A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA)  );
-      gp_Pnt   B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB)  );
-
-      Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
-      Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
+    if (!(aShapeA.ShapeType() == TopAbs_VERTEX
+       && aShapeB.ShapeType() == TopAbs_VERTEX))
+    {
+      std::cerr << "Error: you should select two different vertex.\n";
+      return 1;
+    }
 
-      Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
-      GetMapOfAIS().Bind(theAISLine,argv[1] );
-      TheAISContext()->Display(theAISLine );
+    // Construction de la line
+    gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
+    gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
 
-    }
-    else  {
-      di<<"vline error."<<"\n";
-    }
+    Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
+    Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
 
+    Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
+    GetMapOfAIS().Bind(theAISLine,argv[1] );
+    TheAISContext()->Display (theAISLine, Standard_True);
   }
 
   return 0;
@@ -1783,13 +1588,11 @@ Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
   return aCircle;
 }
 
-DEFINE_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
-
 class FilledCircle : public AIS_InteractiveObject 
 {
 public:
     // CASCADE RTTI
-    DEFINE_STANDARD_RTTI(FilledCircle); 
+    DEFINE_STANDARD_RTTI_INLINE(FilledCircle,AIS_InteractiveObject); 
 
     FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
     FilledCircle(Handle(Geom_Circle) theCircle);
@@ -1800,10 +1603,10 @@ private:
     // Virtual methods implementation
     void Compute (  const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
                   const Handle(Prs3d_Presentation)& thePresentation,
-                  const Standard_Integer theMode);
+                  const Standard_Integer theMode) Standard_OVERRIDE;
 
     void ComputeSelection (  const Handle(SelectMgr_Selection)& theSelection, 
-                           const Standard_Integer theMode);
+                           const Standard_Integer theMode) Standard_OVERRIDE;
 
 protected:
     Handle(Geom_Circle) myCircle;
@@ -1811,8 +1614,6 @@ protected:
 
 }; 
 
-IMPLEMENT_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject)
-IMPLEMENT_STANDARD_RTTIEXT(FilledCircle, AIS_InteractiveObject)
 
 FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius) 
 {
@@ -1843,8 +1644,8 @@ TopoDS_Face FilledCircle::ComputeFace()
   return aFace;
 }
 
-void FilledCircle::Compute(const Handle_PrsMgr_PresentationManager3d &thePresentationManager
-                           const Handle_Prs3d_Presentation &thePresentation, 
+void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/
+                           const Handle(Prs3d_Presentation) &thePresentation, 
                            const Standard_Integer theMode) 
 {
   thePresentation->Clear();
@@ -1857,8 +1658,8 @@ void FilledCircle::Compute(const Handle_PrsMgr_PresentationManager3d &thePresent
   StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
 }
 
-void FilledCircle::ComputeSelection(const Handle_SelectMgr_Selection &theSelection, 
-                                    const Standard_Integer theMode)
+void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection, 
+                                    const Standard_Integer /*theMode*/)
 {
   Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
   Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner, 
@@ -1890,6 +1691,7 @@ void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
   else
   {
     aCircle = new AIS_Circle(theGeomCircle);
+    Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False);
   }
 
   // Check if there is an object with given name
@@ -1907,27 +1709,25 @@ void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
    GetMapOfAIS().Bind(aCircle, theName);
 
    // Display the circle
-   TheAISContext()->Display(aCircle);
+   TheAISContext()->Display (aCircle, Standard_True);
   
 }
 
-static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
 {
-  Standard_Integer myCurrentIndex;
   // Verification of the arguments
   if (argc>6 || argc<2) 
   { 
     std::cout << "vcircle error: expect 4 arguments.\n"; 
     return 1; // TCL_ERROR 
   }
-  TheAISContext()->CloseAllContexts();
 
   // There are all arguments
   if (argc == 6) 
   {
     // Get arguments
     TCollection_AsciiString aName(argv[1]);
-    Standard_Boolean isFilled = (Standard_Boolean)Draw::Atoi(argv[5]);
+    Standard_Boolean isFilled = Draw::Atoi(argv[5]) != 0;
 
     Handle(AIS_InteractiveObject) theShapeA;
     Handle(AIS_InteractiveObject) theShapeB;
@@ -2027,7 +1827,7 @@ static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const cha
         std::cout << "vcircle error: 2d element is a unexpected to be a point.\n"; 
         return 1; // TCL_ERROR 
       }
-      // Ã‘heck that the radius is >= 0
+      // Check that the radius is >= 0
       if (Draw::Atof(argv[4]) <= 0 ) 
       {
         std::cout << "vcircle error: the radius must be >=0.\n"; 
@@ -2079,85 +1879,40 @@ static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const cha
     // Get the name of the circle 
     TCollection_AsciiString aName(argv[1]);
 
-    TheAISContext()->OpenLocalContext();
-    myCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
-
-    // Activate selection mode for vertices and faces
-    TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
-    TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
-    std::cout << " Select a vertex or a face\n";
-
-    // Wait for picking
-    Standard_Integer argcc = 5;
-    const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-    const char **argvv = (const char **) buff;
-    while (ViewerMainLoop( argcc, argvv) ) { }
-    // end of the loop
-
-    TopoDS_Shape ShapeA;
-    for(TheAISContext()->InitSelected(); 
-      TheAISContext()->MoreSelected(); 
-      TheAISContext()->NextSelected() ) 
+    TopTools_ListOfShape aShapes;
+    ViewerTest::GetSelectedShapes (aShapes);
+    if (aShapes.Extent() != 3 && aShapes.Extent() != 2)
     {
-      ShapeA = TheAISContext()->SelectedShape();
+      std::cerr << "Error: Wrong number of selected shapes.\n";
+      return 1;
     }
 
-    // ShapeA is a Vertex
-    if (ShapeA.ShapeType() == TopAbs_VERTEX ) 
+    const TopoDS_Shape& aShapeA = aShapes.First();
+    if (aShapeA.ShapeType() == TopAbs_VERTEX ) 
     {
-      TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
-      std::cout << " Select a different vertex\n";
-
-      TopoDS_Shape ShapeB;
-      do 
+      if (aShapes.Extent() != 3)
       {
-        // Wait for picking
-        Standard_Integer argccc = 5;
-        const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-        const char **argvvv = (const char **) bufff;
-        while (ViewerMainLoop( argccc, argvvv) ) { }
-        // end of the loop
+        std::cerr << "Error: wrong number of selected shapes.\n";
+        return 1;
+      }
 
-        for(TheAISContext()->InitSelected(); 
-          TheAISContext()->MoreSelected(); 
-          TheAISContext()->NextSelected() ) 
-        {
-          ShapeB = TheAISContext()->SelectedShape();
-        }
-      } while(ShapeB.IsSame(ShapeA) );
+      TopTools_ListOfShape::Iterator anIter (aShapes);
 
-      // Selection of ShapeC
-      std::cout << " Select the last vertex\n";
-      TopoDS_Shape ShapeC;
-      do 
-      {
-        // Wait for picking
-        Standard_Integer argcccc = 5;
-        const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-        const char **argvvvv = (const char **) buffff;
-        while (ViewerMainLoop( argcccc, argvvvv) ) { }
-        // end of the loop
+      anIter.Next();
+      const TopoDS_Shape& aShapeB = anIter.Value();
 
-        for(TheAISContext()->InitSelected(); 
-          TheAISContext()->MoreSelected(); 
-          TheAISContext()->NextSelected() ) 
-        {
-          ShapeC = TheAISContext()->SelectedShape();
-        }
-      } while(ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB) );
+      anIter.Next();
+      const TopoDS_Shape& aShapeC = anIter.Value();
       
       // Get isFilled
       Standard_Boolean isFilled;
       std::cout << "Enter filled status (0 or 1)\n";
       cin >> isFilled;
 
-      // Close the local context
-      TheAISContext()->CloseLocalContext(myCurrentIndex);
-
       // Construction of the circle
-      gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA));
-      gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
-      gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(ShapeC));
+      gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
+      gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
+      gp_Pnt C = BRep_Tool::Pnt (TopoDS::Vertex (aShapeC));
 
       GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
       Handle (Geom_Circle) theGeomCircle;
@@ -2174,26 +1929,9 @@ static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const cha
       DisplayCircle(theGeomCircle, aName, isFilled);
 
     }
-    // Shape is a face
-    else
+    else if (aShapeA.ShapeType() == TopAbs_FACE)
     {
-      std::cout << " Select a vertex (in your face)\n";
-      TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
-
-      TopoDS_Shape ShapeB;
-      // Wait for picking
-      Standard_Integer argccc = 5;
-      const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
-      const char **argvvv = (const char **) bufff;
-      while (ViewerMainLoop( argccc, argvvv) ) { }
-      // end of the loop
-
-      for(TheAISContext()->InitSelected(); 
-        TheAISContext()->MoreSelected(); 
-        TheAISContext()->NextSelected() ) 
-      {
-        ShapeB = TheAISContext()->SelectedShape();
-      }
+      const TopoDS_Shape& aShapeB = aShapes.Last();
 
       // Recover the radius 
       Standard_Real theRad;
@@ -2208,12 +1946,8 @@ static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const cha
       std::cout << "Enter filled status (0 or 1)\n";
       cin >> isFilled;
 
-      // Close the local context
-      TheAISContext()->CloseLocalContext(myCurrentIndex);
-      // Construction of the circle
-
       // Recover the normal to the plane. tag
-      TopoDS_Face myFace = TopoDS::Face(ShapeA);
+      TopoDS_Face myFace = TopoDS::Face(aShapeA);
       BRepAdaptor_Surface mySurface (myFace, Standard_False);
       gp_Pln myPlane = mySurface.Plane();
       Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
@@ -2222,9 +1956,9 @@ static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const cha
       gp_Dir theDir = thegpAxe.Direction();
 
       // Recover the center
-      gp_Pnt theCenter = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB));
+      gp_Pnt theCenter = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
 
-      // Ã‘onstruct the circle
+      // Construct the circle
       GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
       Handle (Geom_Circle) theGeomCircle;
       try 
@@ -2238,251 +1972,421 @@ static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const cha
       }
 
       DisplayCircle(theGeomCircle, aName, isFilled);
-      
     }
-
+    else
+    {
+      std::cerr << "Error: You should select face and vertex or three vertices.\n";
+      return 1;
+    }
   }
 
   return 0;
 }
 
-
-//===============================================================================================
+//=======================================================================
 //function : VDrawText
-//author   : psn
-//purpose  : Create a text.
-//Draw arg : vdrawtext  name  [X] [Y] [Z] [R] [G] [B] [hor_align] [ver_align] [angle] [zoomable]
-//===============================================================================================
-#include <Graphic3d_Group.hxx>
-#include <Graphic3d_Structure.hxx>
-#include <Graphic3d_AspectText3d.hxx>
-#include <Graphic3d_AspectFillArea3d.hxx>
-#include <Graphic3d_StructureManager.hxx>
-#include <Graphic3d_VerticalTextAlignment.hxx>
-#include <Graphic3d_HorizontalTextAlignment.hxx>
-
-#include <Font_NameOfFont.hxx>
-
-#include <Visual3d_ViewManager.hxx>
-#include <ViewerTest_Tool.ixx>
-
-#include <Standard_DefineHandle.hxx>
-
-#include <Prs3d_Root.hxx>
-#include <Prs3d_Text.hxx>
-#include <Prs3d_TextAspect.hxx>
-#include <Prs3d_ShadingAspect.hxx>
-#include <PrsMgr_PresentationManager3d.hxx>
-
-#include <TCollection_ExtendedString.hxx>
-#include <TCollection_AsciiString.hxx>
-
-#include <gp_Pnt.hxx>
-#include <Quantity_NameOfColor.hxx>
-#include <Quantity_Color.hxx>
-
-
-DEFINE_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
-
-class MyTextClass:public AIS_InteractiveObject
-{
-public:
-  // CASCADE RTTI
-  DEFINE_STANDARD_RTTI(MyTextClass );
-
-  MyTextClass(){};
-
-  MyTextClass
-    (
-      const TCollection_ExtendedString& , const gp_Pnt& ,
-      Quantity_Color color,
-      Standard_Integer aHJust,
-      Standard_Integer aVJust ,
-      Standard_Real Angle ,
-      Standard_Boolean Zoom ,
-      Standard_Real  Height,
-      Font_FontAspect FontAspect,
-      Standard_CString Font
-    );
-
-private:
-
-  void Compute (  const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
-                  const Handle(Prs3d_Presentation)& aPresentation,
-                  const Standard_Integer aMode);
-
-  void ComputeSelection (  const Handle(SelectMgr_Selection)& aSelection,
-                           const Standard_Integer aMode){} ;
-
-protected:
-  TCollection_ExtendedString          aText;
-  gp_Pnt                              aPosition;
-  Standard_Real                       Red;
-  Standard_Real                       Green;
-  Standard_Real                       Blue;
-  Standard_Real                       aAngle;
-  Standard_Real                       aHeight;
-  Standard_Boolean                    aZoomable;
-  Quantity_Color                      aColor;
-  Standard_CString                    aFont;
-  Font_FontAspect                     aFontAspect;
-  Graphic3d_HorizontalTextAlignment   aHJustification;
-  Graphic3d_VerticalTextAlignment     aVJustification;
-};
-
-
-
-IMPLEMENT_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject)
-IMPLEMENT_STANDARD_RTTIEXT(MyTextClass, AIS_InteractiveObject)
-
-
-MyTextClass::MyTextClass( const TCollection_ExtendedString& text, const gp_Pnt& position,
-                          Quantity_Color    color       = Quantity_NOC_YELLOW,
-                          Standard_Integer  aHJust      = Graphic3d_HTA_LEFT,
-                          Standard_Integer  aVJust      = Graphic3d_VTA_BOTTOM,
-                          Standard_Real     angle       = 0.0 ,
-                          Standard_Boolean  zoomable    = Standard_True,
-                          Standard_Real     height      = 12.,
-                          Font_FontAspect   fontAspect  = Font_FA_Regular,
-                          Standard_CString  font        = "Courier")
-{
-  aText           = text;
-  aPosition       = position;
-  aHJustification = Graphic3d_HorizontalTextAlignment(aHJust);
-  aVJustification = Graphic3d_VerticalTextAlignment(aVJust);
-  aAngle          = angle;
-  aZoomable       = zoomable;
-  aHeight         = height;
-  aColor          = color;
-  aFontAspect     = fontAspect;
-  aFont           = font;
-};
-
-
-
-//////////////////////////////////////////////////////////////////////////////
-void MyTextClass::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
-                          const Handle(Prs3d_Presentation)& aPresentation,
-                          const Standard_Integer aMode)
+//purpose  :
+//=======================================================================
+static int VDrawText (Draw_Interpretor& theDI,
+                      Standard_Integer  theArgsNb,
+                      const char**      theArgVec)
 {
+  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
+  if (theArgsNb < 3)
+  {
+    std::cout << "Error: wrong number of arguments! See usage:\n";
+    theDI.PrintHelp (theArgVec[0]);
+    return 1;
+  }
+  else if (aContext.IsNull())
+  {
+    std::cout << "Error: no active view!\n";
+    return 1;
+  }
 
-  aPresentation->Clear();
-
-  Handle_Prs3d_TextAspect asp = myDrawer->TextAspect();
-
-  asp->SetFont(aFont);
-  asp->SetColor(aColor);
-  asp->SetHeight(aHeight); // I am changing the myHeight value
-
-  asp->SetHorizontalJustification(aHJustification);
-  asp->SetVerticalJustification(aVJustification);
-  asp->Aspect()->SetTextZoomable(aZoomable);
-  asp->Aspect()->SetTextAngle(aAngle);
-  asp->Aspect()->SetTextFontAspect(aFontAspect);
-  Prs3d_Text::Draw(aPresentation, asp, aText, aPosition);
-
-  /* This comment code is worked
-  Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
-  Handle(Graphic3d_AspectFillArea3d) aspect = myDrawer->ShadingAspect()->Aspect();
-  Graphic3d_Vertex vertices_text;
-  vertices_text.SetCoord(aPosition.X(),aPosition.Y(),aPosition.Y());
-  TheGroup->SetPrimitivesAspect(aspect);
-  TheGroup->Text(aText,vertices_text,aHeight,Standard_True);
-  */
-};
+  Standard_Integer           anArgIt = 1;
+  TCollection_ExtendedString aName (theArgVec[anArgIt++], Standard_True);
+  TCollection_ExtendedString aText (theArgVec[anArgIt++], Standard_True);
+  Handle(AIS_TextLabel)      aTextPrs;
+  ViewerTest_AutoUpdater     anAutoUpdater (aContext, ViewerTest::CurrentView());
 
-static int VDrawText (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
-{
-  // Check arguments
-  if (argc < 14)
+  Standard_Boolean isNewPrs = Standard_False;
+  if (GetMapOfAIS().IsBound2 (aName))
   {
-    di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
-    di<<"Usage: type help "<<argv[0]<<"\n";
-    return 1; //TCL_ERROR
+    aTextPrs = Handle(AIS_TextLabel)::DownCast (GetMapOfAIS().Find2 (aName));
   }
 
-  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
-
-  // Create 3D view if it doesn't exist
-  if ( aContext.IsNull() )
+  if (aTextPrs.IsNull())
   {
-    ViewerTest::ViewerInit();
-    aContext = ViewerTest::GetAISContext();
-    if( aContext.IsNull() )
-    {
-      di << "Error: Cannot create a 3D view\n";
-      return 1; //TCL_ERROR
-    }
+    isNewPrs = Standard_True;
+    aTextPrs = new AIS_TextLabel();
+    aTextPrs->SetFont ("Courier");
   }
 
-  // Text position
-  const Standard_Real X = Draw::Atof(argv[2]);
-  const Standard_Real Y = Draw::Atof(argv[3]);
-  const Standard_Real Z = Draw::Atof(argv[4]);
-  const gp_Pnt pnt(X,Y,Z);
+  aTextPrs->SetText (aText);
 
-  // Text color
-  const Quantity_Parameter R = Draw::Atof(argv[5])/255.;
-  const Quantity_Parameter G = Draw::Atof(argv[6])/255.;
-  const Quantity_Parameter B = Draw::Atof(argv[7])/255.;
-  const Quantity_Color aColor( R, G, B, Quantity_TOC_RGB );
+  Handle(Graphic3d_TransformPers) aTrsfPers;
+  Aspect_TypeOfDisplayText aDisplayType = Aspect_TODT_NORMAL;
 
-  // Text alignment
-  const int hor_align = Draw::Atoi(argv[8]);
-  const int ver_align = Draw::Atoi(argv[9]);
+  Standard_Boolean aHasPlane = Standard_False;
+  gp_Dir           aNormal;
+  gp_Dir           aDirection;
+  gp_Pnt           aPos;
 
-  // Text angle
-  const Standard_Real angle = Draw::Atof(argv[10]);
+  for (; anArgIt < theArgsNb; ++anArgIt)
+  {
+    TCollection_AsciiString aParam (theArgVec[anArgIt]);
+    aParam.LowerCase();
 
-  // Text zooming
-  const Standard_Boolean zoom = Draw::Atoi(argv[11]);
+    if (anAutoUpdater.parseRedrawMode (aParam))
+    {
+      continue;
+    }
+    else if (aParam == "-pos"
+          || aParam == "-position")
+    {
+      if (anArgIt + 3 >= theArgsNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
 
-  // Text height
-  const Standard_Real height = Draw::Atof(argv[12]);
+      aPos.SetX (Draw::Atof (theArgVec[++anArgIt]));
+      aPos.SetY (Draw::Atof (theArgVec[++anArgIt]));
+      aPos.SetZ (Draw::Atof (theArgVec[++anArgIt]));
+      aTextPrs->SetPosition (aPos);
+    }
+    else if (aParam == "-color")
+    {
+      if (anArgIt + 1 >= theArgsNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
 
-  // Text aspect
-  const Font_FontAspect aspect = Font_FontAspect(Draw::Atoi(argv[13]));
+      TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
+      Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
+      if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
+      {
+        anArgIt += 1;
+        aTextPrs->SetColor (aNameOfColor);
+        continue;
+      }
+      else if (anArgIt + 3 >= theArgsNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
 
-  // Text font
-  TCollection_AsciiString font;
-  if(argc < 15)
-    font.AssignCat("Courier");
-  else
-    font.AssignCat(argv[14]);
+      TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
+      TCollection_AsciiString aBlue  (theArgVec[anArgIt + 3]);
+      if (!aColor.IsRealValue()
+       || !aGreen.IsRealValue()
+       || !aBlue.IsRealValue())
+      {
+        std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
 
-  // Text is multibyte
-  const Standard_Boolean isMultibyte = (argc < 16)? Standard_False : (Draw::Atoi(argv[15]) != 0);
+      const Graphic3d_Vec3d anRGB (aColor.RealValue(),
+                                   aGreen.RealValue(),
+                                   aBlue.RealValue());
 
-  // Read text string
-  TCollection_ExtendedString name;
-  if (isMultibyte)
-  {
-    const char *str = argv[1];
-    while ( *str || *(str+1)=='\x0A' || *(str+1)=='\x0B' || *(str+1)=='\x0C' || *(str+1)=='\x0D'
-                 || *(str+1)=='\x07' || *(str+1)=='\x08' || *(str+1)=='\x09' )
-    {
-      unsigned short c1 = *str++;
-      unsigned short c2 = *str++;
-      if (!c2) break;
-      name += (Standard_ExtCharacter)((c1 << 8) | c2);
+      aTextPrs->SetColor (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
+      anArgIt += 3;
     }
-  }
-  else
-  {
-    name += argv[1];
-  }
-
-  if (name.Length())
-  {
-    Handle(MyTextClass) myT = new MyTextClass(name,pnt,aColor,hor_align,ver_align,angle,zoom,height,aspect,font.ToCString());
-    aContext->Display(myT,Standard_True);
-  }
+    else if (aParam == "-halign")
+    {
+      if (++anArgIt >= theArgsNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
 
-  return 0;
-}
+      TCollection_AsciiString aType (theArgVec[anArgIt]);
+      aType.LowerCase();
+      if (aType == "left")
+      {
+        aTextPrs->SetHJustification (Graphic3d_HTA_LEFT);
+      }
+      else if (aType == "center")
+      {
+        aTextPrs->SetHJustification (Graphic3d_HTA_CENTER);
+      }
+      else if (aType == "right")
+      {
+        aTextPrs->SetHJustification (Graphic3d_HTA_RIGHT);
+      }
+      else
+      {
+        std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+    }
+    else if (aParam == "-valign")
+    {
+      if (++anArgIt >= theArgsNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
 
-#include <math.h>
-#include <gp_Pnt.hxx>
+      TCollection_AsciiString aType (theArgVec[anArgIt]);
+      aType.LowerCase();
+      if (aType == "top")
+      {
+        aTextPrs->SetVJustification (Graphic3d_VTA_TOP);
+      }
+      else if (aType == "center")
+      {
+        aTextPrs->SetVJustification (Graphic3d_VTA_CENTER);
+      }
+      else if (aType == "bottom")
+      {
+        aTextPrs->SetVJustification (Graphic3d_VTA_BOTTOM);
+      }
+      else if (aType == "topfirstline")
+      {
+        aTextPrs->SetVJustification (Graphic3d_VTA_TOPFIRSTLINE);
+      }
+      else
+      {
+        std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+    }
+    else if (aParam == "-angle")
+    {
+      if (++anArgIt >= theArgsNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+
+      aTextPrs->SetAngle (Draw::Atof (theArgVec[anArgIt]) * (M_PI / 180.0));
+    }
+    else if (aParam == "-zoom")
+    {
+      if (++anArgIt >= theArgsNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+
+      aTextPrs->SetZoomable (Draw::Atoi (theArgVec[anArgIt]) == 1);
+    }
+    else if (aParam == "-height")
+    {
+      if (++anArgIt >= theArgsNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+
+      aTextPrs->SetHeight (Draw::Atof(theArgVec[anArgIt]));
+    }
+    else if (aParam == "-aspect")
+    {
+      if (++anArgIt >= theArgsNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+
+      TCollection_AsciiString anOption (theArgVec[anArgIt]);
+      anOption.LowerCase();
+      if (anOption.IsEqual ("regular"))
+      {
+        aTextPrs->SetFontAspect (Font_FA_Regular);
+      }
+      else if (anOption.IsEqual ("bold"))
+      {
+        aTextPrs->SetFontAspect (Font_FA_Bold);
+      }
+      else if (anOption.IsEqual ("italic"))
+      {
+        aTextPrs->SetFontAspect (Font_FA_Italic);
+      }
+      else if (anOption.IsEqual ("bolditalic"))
+      {
+        aTextPrs->SetFontAspect (Font_FA_BoldItalic);
+      }
+    }
+    else if (aParam == "-font")
+    {
+      if (++anArgIt >= theArgsNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+
+      aTextPrs->SetFont (theArgVec[anArgIt]);
+    }
+    else if (aParam == "-plane")
+    {
+      if (anArgIt + 6 >= theArgsNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+
+      Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]);
+      Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]);
+      Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]);
+      aNormal.SetCoord (aX, aY, aZ);
+
+      aX = Draw::Atof (theArgVec[++anArgIt]);
+      aY = Draw::Atof (theArgVec[++anArgIt]);
+      aZ = Draw::Atof (theArgVec[++anArgIt]);
+      aDirection.SetCoord (aX, aY, aZ);
+
+      aHasPlane = Standard_True;
+    }
+    else if (aParam == "-flipping")
+    {
+      aTextPrs->SetFlipping (Standard_True);
+    }
+    else if (aParam == "-disptype"
+          || aParam == "-displaytype")
+    {
+      if (++anArgIt >= theArgsNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+      TCollection_AsciiString aType (theArgVec[anArgIt]);
+      aType.LowerCase();
+      if (aType == "subtitle")
+        aDisplayType = Aspect_TODT_SUBTITLE;
+      else if (aType == "decal")
+        aDisplayType = Aspect_TODT_DEKALE;
+      else if (aType == "blend")
+        aDisplayType = Aspect_TODT_BLEND;
+      else if (aType == "dimension")
+        aDisplayType = Aspect_TODT_DIMENSION;
+      else if (aType == "normal")
+        aDisplayType = Aspect_TODT_NORMAL;
+      else
+      {
+        std::cout << "Error: wrong display type '" << aType << "'.\n";
+        return 1;
+      }
+    }
+    else if (aParam == "-subcolor"
+          || aParam == "-subtitlecolor")
+    {
+      if (anArgIt + 1 >= theArgsNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+
+      TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
+      Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
+      if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
+      {
+        anArgIt += 1;
+        aTextPrs->SetColorSubTitle (aNameOfColor);
+        continue;
+      }
+      else if (anArgIt + 3 >= theArgsNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+
+      TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
+      TCollection_AsciiString aBlue  (theArgVec[anArgIt + 3]);
+      if (!aColor.IsRealValue()
+       || !aGreen.IsRealValue()
+       || !aBlue.IsRealValue())
+      {
+        std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+
+      const Graphic3d_Vec3d anRGB (aColor.RealValue(),
+                                   aGreen.RealValue(),
+                                   aBlue.RealValue());
+
+      aTextPrs->SetColorSubTitle (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
+      anArgIt += 3;
+    }
+    else if (aParam == "-2d")
+    {
+      aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_2d);
+    }
+    else if (aParam == "-trsfperspos"
+          || aParam == "-perspos")
+    {
+      if (anArgIt + 2 >= theArgsNb)
+      {
+        std::cerr << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+
+      TCollection_AsciiString aX (theArgVec[++anArgIt]);
+      TCollection_AsciiString aY (theArgVec[++anArgIt]);
+      TCollection_AsciiString aZ = "0";
+      if (!aX.IsIntegerValue()
+       || !aY.IsIntegerValue())
+      {
+        std::cerr << "Error: wrong syntax at '" << aParam << "'.\n";
+        return 1;
+      }
+      if (anArgIt + 1 < theArgsNb)
+      {
+        TCollection_AsciiString aTemp = theArgVec[anArgIt + 1];
+        if (aTemp.IsIntegerValue())
+        {
+          aZ = aTemp;
+          ++anArgIt;
+        }
+      }
+
+      aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (Graphic3d_TMF_2d, gp_Pnt (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue()));
+    }
+    else
+    {
+      std::cout << "Error: unknown argument '" << aParam << "'\n";
+      return 1;
+    }
+  }
+
+  if (aHasPlane)
+  {
+    aTextPrs->SetOrientation3D (gp_Ax2 (aPos, aNormal, aDirection));
+  }
+
+  aTextPrs->SetDisplayType (aDisplayType);
+
+  if (!aTrsfPers.IsNull())
+  {
+    aContext->SetTransformPersistence (aTextPrs, aTrsfPers);
+    aTextPrs->SetZLayer(Graphic3d_ZLayerId_TopOSD);
+    if (aTextPrs->Position().Z() != 0)
+    {
+      aTextPrs->SetPosition (gp_Pnt(aTextPrs->Position().X(), aTextPrs->Position().Y(), 0));
+    }
+  }
+  else if (!aTextPrs->TransformPersistence().IsNull())
+  {
+    aContext->SetTransformPersistence (aTextPrs, Handle(Graphic3d_TransformPers)());
+  }
+
+  if (isNewPrs)
+  {
+    ViewerTest::Display (aName, aTextPrs, Standard_False);
+  }
+  else
+  {
+    aContext->Redisplay (aTextPrs, Standard_False, Standard_True);
+  }
+  return 0;
+}
+
+#include <math.h>
+#include <gp_Pnt.hxx>
 #include <Graphic3d_ArrayOfPoints.hxx>
 #include <Graphic3d_ArrayOfPrimitives.hxx>
 #include <Graphic3d_ArrayOfTriangles.hxx>
@@ -2494,8 +2398,7 @@ static int VDrawText (Draw_Interpretor& di, Standard_Integer argc, const char**
 #include <TShort_HArray1OfShortReal.hxx>
 
 #include <AIS_Triangulation.hxx>
-#include <Aspect_GraphicDevice.hxx>
-#include <StdPrs_ToolShadedShape.hxx>
+#include <StdPrs_ToolTriangulatedShape.hxx>
 #include <Poly_Connect.hxx>
 #include <TColgp_Array1OfDir.hxx>
 #include <Graphic3d_GraphicDriver.hxx>
@@ -2511,6 +2414,7 @@ static int VDrawText (Draw_Interpretor& di, Standard_Integer argc, const char**
 #include <TopExp_Explorer.hxx>
 #include <TopAbs.hxx>
 #include <StdSelect_ShapeTypeFilter.hxx>
+#include <AIS_InteractiveObject.hxx>
 
 
 //===============================================================================================
@@ -2537,7 +2441,6 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z
 
   int i, j;
   int jStart, jEnd, numOffset;
-  int numPts, numPolys;
   double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
   double startTheta, endTheta, startPhi, endPhi;
   int base, numPoles=0, thetaResolution, phiResolution;
@@ -2567,9 +2470,6 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z
   localStartTheta = localStartTheta + (double)(start) * deltaTheta;
   localThetaResolution = end - start;
 
-  numPts =  mPhiResolution * localThetaResolution + 2;
-  numPolys =  mPhiResolution * 2 * localThetaResolution;
-
   // Create north pole if needed
   int number_point = 0;
   int number_pointArray = 0;
@@ -2733,11 +2633,11 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z
         Nor = gp_Dir(eqPlan);
       else
         Nor = gp_Dir(0., 0., 1.);
-
-      Standard_Integer j = (i - PointsOfArray.Lower()) * 3;
-      Normals->SetValue(j + 1, (Standard_ShortReal)Nor.X());
-      Normals->SetValue(j + 2, (Standard_ShortReal)Nor.Y());
-      Normals->SetValue(j + 3, (Standard_ShortReal)Nor.Z());
+      
+      Standard_Integer k = (i - PointsOfArray.Lower()) * 3;
+      Normals->SetValue(k + 1, (Standard_ShortReal)Nor.X());
+      Normals->SetValue(k + 2, (Standard_ShortReal)Nor.Y());
+      Normals->SetValue(k + 3, (Standard_ShortReal)Nor.Z());
   }
 
   delete pc;
@@ -2751,7 +2651,7 @@ Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z
 //author   : psn
 //purpose  : Create an AIS shape.
 //===============================================================================================
-static int VDrawSphere (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
 {
   // check for errors
   Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
@@ -2763,7 +2663,7 @@ static int VDrawSphere (Draw_Interpretor& di, Standard_Integer argc, const char*
   else if (argc < 3)
   {
     std::cout << "Use: " << argv[0]
-              << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToEnableVBO=1] [NumberOfViewerUpdate=1] [ToShowEdges=0]\n";
+              << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n";
     return 1;
   }
 
@@ -2774,12 +2674,14 @@ static int VDrawSphere (Draw_Interpretor& di, Standard_Integer argc, const char*
   Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0;
   Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0;
   Standard_Real aRadius =  (argc > 6) ? Draw::Atof (argv[6]) : 100.0;
-  Standard_Boolean toShowEdges =  (argc > 7) ? Draw::Atoi (argv[7]) : Standard_False;
+  Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False;
+  Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True;
 
   // remove AIS object with given name from map
   VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
 
-  std::cout << "Compute Triangulation...\n";
+  if (toPrintInfo)
+    std::cout << "Compute Triangulation...\n";
   Handle(AIS_Triangulation) aShape
     = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
                                                   aResolution,
@@ -2789,20 +2691,13 @@ static int VDrawSphere (Draw_Interpretor& di, Standard_Integer argc, const char*
 
   // stupid initialization of Green color in RGBA space as integer
   // probably wrong for big-endian CPUs
-  Standard_Integer aRed    = 0;
-  Standard_Integer aGreen  = 255;
-  Standard_Integer aBlue   = 0;
-  Standard_Integer anAlpha = 0; // not used
-  Standard_Integer aColorInt = aRed;
-  aColorInt += aGreen  << 8;
-  aColorInt += aBlue   << 16;
-  aColorInt += anAlpha << 24;
+  const Graphic3d_Vec4ub aColor (0, 255, 0, 0);
 
   // setup colors array per vertex
   Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
   for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
   {
-    aColorArray->SetValue (aNodeId, aColorInt);
+    aColorArray->SetValue (aNodeId, *reinterpret_cast<const Standard_Integer*> (&aColor));
   }
   aShape->SetColors (aColorArray);
 
@@ -2818,12 +2713,15 @@ static int VDrawSphere (Draw_Interpretor& di, Standard_Integer argc, const char*
   aColorsSize >>= 20;
   aTrianglesSize >>= 20;
   aPolyConnectSize >>= 20;
-  std::cout << "NumberOfPoints:    " << aNumberPoints << "\n"
-            << "NumberOfTriangles: " << aNumberTriangles << "\n"
-            << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
-            << "Amount of memory for colors: " << aColorsSize << " Mb\n"
-            << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
-            << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
+  if (toPrintInfo)
+  {
+    std::cout << "NumberOfPoints:    " << aNumberPoints << "\n"
+      << "NumberOfTriangles: " << aNumberTriangles << "\n"
+      << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n"
+      << "Amount of memory for colors: " << aColorsSize << " Mb\n"
+      << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n"
+      << "Amount of graphic card memory required: " << aTotalSize << " Mb\n";
+  }
 
   // Setting material properties, very important for desirable visual result!
   Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC);
@@ -2853,181 +2751,6 @@ static int VDrawSphere (Draw_Interpretor& di, Standard_Integer argc, const char*
   return 0;
 }
 
-//===============================================================================================
-//function : VClipPlane
-//purpose  :
-//===============================================================================================
-static int VClipPlane (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
-{
-  Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
-  Handle(V3d_View) aView = ViewerTest::CurrentView();
-  Standard_Real coeffA, coeffB, coeffC, coeffD;
-  if (aViewer.IsNull() || aView.IsNull())
-  {
-    std::cout << "Viewer not initialized!\n";
-    return 1;
-  }
-
-  // count an active planes count
-  Standard_Integer aNewPlaneId = 1;
-  Standard_Integer anActivePlanes = 0;
-  for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->NextDefinedPlanes(), ++aNewPlaneId)
-  {
-    Handle(V3d_Plane) aPlaneV3d = aViewer->DefinedPlane();
-    if (aView->IsActivePlane (aPlaneV3d))
-    {
-      ++anActivePlanes;
-    }
-  }
-
-  if (argc == 1)
-  {
-    // just show info about existing planes
-    Standard_Integer aPlaneId = 1;
-    std::cout << "Active planes: " << anActivePlanes << " from maximal " << aView->View()->PlaneLimit() << "\n";
-    for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->NextDefinedPlanes(), ++aPlaneId)
-    {
-      Handle(V3d_Plane) aPlaneV3d = aViewer->DefinedPlane();
-      aPlaneV3d->Plane (coeffA, coeffB, coeffC, coeffD);
-      gp_Pln aPlane (coeffA, coeffB, coeffC, coeffD);
-      const gp_Pnt& aLoc = aPlane.Location();
-      const gp_Dir& aNor = aPlane.Axis().Direction();
-      Standard_Boolean isActive = aView->IsActivePlane (aPlaneV3d);
-      std::cout << "Plane #" << aPlaneId
-        << " " << aLoc.X() << " " << aLoc.Y() << " " << aLoc.Z()
-        << " " << aNor.X() << " " << aNor.Y() << " " << aNor.Z()
-        << (isActive ? " on" : " off")
-        << (aPlaneV3d->IsDisplayed() ? ", displayed" : ", hidden")
-        << "\n";
-    }
-    if (aPlaneId == 1)
-    {
-      std::cout << "No defined clipping planes\n";
-    }
-    return 0;
-  }
-  else if (argc == 2 || argc == 3)
-  {
-    Standard_Integer aPlaneIdToOff = (argc == 3) ? Draw::Atoi (argv[1]) : 1;
-    Standard_Boolean toIterateAll = (argc == 2);
-    TCollection_AsciiString isOnOffStr ((argc == 3) ? argv[2] : argv[1]);
-    isOnOffStr.LowerCase();
-    Standard_Integer aPlaneId = 1;
-    for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->NextDefinedPlanes(), ++aPlaneId)
-    {
-      if (aPlaneIdToOff == aPlaneId || toIterateAll)
-      {
-        Handle(V3d_Plane) aPlaneV3d = aViewer->DefinedPlane();
-        if (isOnOffStr.Search ("off") >= 0)
-        {
-          aView->SetPlaneOff (aPlaneV3d);
-          std::cout << "Clipping plane #" << aPlaneId << " was disabled\n";
-        }
-        else if (isOnOffStr.Search ("on") >= 0)
-        {
-          // avoid z-fighting glitches
-          aPlaneV3d->Erase();
-          if (!aView->IsActivePlane (aPlaneV3d))
-          {
-            if (anActivePlanes < aView->View()->PlaneLimit())
-            {
-              aView->SetPlaneOn (aPlaneV3d);
-              std::cout << "Clipping plane #" << aPlaneId << " was enabled\n";
-            }
-            else
-            {
-              std::cout << "Maximal active planes limit exceeded (" << anActivePlanes << ")\n"
-                        << "You should disable or remove some existing plane to activate this one\n";
-            }
-          }
-          else
-          {
-            std::cout << "Clipping plane #" << aPlaneId << " was already enabled\n";
-          }
-        }
-        else if (isOnOffStr.Search ("del") >= 0 || isOnOffStr.Search ("rem") >= 0)
-        {
-          aPlaneV3d->Erase(); // not performed on destructor!!!
-          aView->SetPlaneOff (aPlaneV3d);
-          aViewer->DelPlane (aPlaneV3d);
-          std::cout << "Clipping plane #" << aPlaneId << " was removed\n";
-          if (toIterateAll)
-          {
-            for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->InitDefinedPlanes(), ++aPlaneId)
-            {
-              aPlaneV3d = aViewer->DefinedPlane();
-              aPlaneV3d->Erase(); // not performed on destructor!!!
-              aView->SetPlaneOff (aPlaneV3d);
-              aViewer->DelPlane (aPlaneV3d);
-              std::cout << "Clipping plane #" << aPlaneId << " was removed\n";
-            }
-            break;
-          }
-          else
-          {
-            break;
-          }
-        }
-        else if (isOnOffStr.Search ("disp") >= 0 || isOnOffStr.Search ("show") >= 0)
-        {
-          // avoid z-fighting glitches
-          aView->SetPlaneOff (aPlaneV3d);
-          aPlaneV3d->Display (aView);
-          std::cout << "Clipping plane #" << aPlaneId << " was shown and disabled\n";
-        }
-        else if (isOnOffStr.Search ("hide") >= 0)
-        {
-          aPlaneV3d->Erase();
-          std::cout << "Clipping plane #" << aPlaneId << " was hidden\n";
-        }
-        else
-        {
-          std::cout << "Usage: " << argv[0] << " [x y z dx dy dz] [planeId {on/off/del/display/hide}]\n";
-          return 1;
-        }
-      }
-    }
-    if (aPlaneIdToOff >= aPlaneId && !toIterateAll)
-    {
-      std::cout << "Clipping plane with id " << aPlaneIdToOff << " not found!\n";
-      return 1;
-    }
-    aView->Update();
-    return 0;
-  }
-  else if (argc != 7)
-  {
-    std::cout << "Usage: " << argv[0] << " [x y z dx dy dz] [planeId {on/off/del/display/hide}]\n";
-    return 1;
-  }
-
-  Standard_Real aLocX = Draw::Atof (argv[1]);
-  Standard_Real aLocY = Draw::Atof (argv[2]);
-  Standard_Real aLocZ = Draw::Atof (argv[3]);
-  Standard_Real aNormDX = Draw::Atof (argv[4]);
-  Standard_Real aNormDY = Draw::Atof (argv[5]);
-  Standard_Real aNormDZ = Draw::Atof (argv[6]);
-
-  Handle(V3d_Plane) aPlaneV3d = new V3d_Plane();
-  gp_Pln aPlane (gp_Pnt (aLocX, aLocY, aLocZ), gp_Dir (aNormDX, aNormDY, aNormDZ));
-  aPlane.Coefficients (coeffA, coeffB, coeffC, coeffD);
-  aPlaneV3d->SetPlane(coeffA, coeffB, coeffC, coeffD);
-
-  aViewer->AddPlane (aPlaneV3d); // add to defined planes list
-  std::cout << "Added clipping plane #" << aNewPlaneId << "\n";
-  if (anActivePlanes < aView->View()->PlaneLimit())
-  {
-    aView->SetPlaneOn (aPlaneV3d); // add to enabled planes list
-    aView->Update();
-  }
-  else
-  {
-    std::cout << "Maximal active planes limit exceeded (" << anActivePlanes << ")\n"
-              << "You should disable or remove some existing plane to activate the new one\n";
-  }
-  return 0;
-}
-
 //=============================================================================
 //function : VComputeHLR
 //purpose  :
@@ -3048,7 +2771,7 @@ static int VComputeHLR (Draw_Interpretor& di,
   if ( argc != 3 &&  argc != 12 )
   {
     di << "Usage: " << argv[0] << " ShapeName HlrName "
-       << "[ eye_x eye_y eye_z dir_x dir_y dir_z upx upy upz ]" << "\n"
+       << "[ eye_x eye_y eye_z dir_x dir_y dir_z upx upy upz ]\n"
        << "                    ShapeName - name of the initial shape\n"
        << "                    HlrName - result hlr object from initial shape\n"
        << "                    eye, dir are eye position and look direction\n"
@@ -3079,10 +2802,6 @@ static int VComputeHLR (Draw_Interpretor& di,
     return 1;
   }
 
-  // close local context
-  if (aContextAIS->HasOpenedContext ())
-    aContextAIS->CloseLocalContext ();
-
   Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo();
   HLRBRep_PolyHLRToShape aHLRToShape;
 
@@ -3155,7 +2874,7 @@ static int VComputeHLR (Draw_Interpretor& di,
   // create an AIS shape and display it
   Handle(AIS_Shape) anObject = new AIS_Shape (aHlrShape);
   GetMapOfAIS().Bind (anObject, aHlrName);
-  aContextAIS->Display (anObject);
+  aContextAIS->Display (anObject, Standard_False);
 
   aContextAIS->UpdateCurrentViewer ();
 
@@ -3164,181 +2883,113 @@ static int VComputeHLR (Draw_Interpretor& di,
 
 // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for
 // manipulating and displaying such an array with AIS context
-DEFINE_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
+
 class MyPArrayObject : public AIS_InteractiveObject
 {
 
 public:
 
-  MyPArrayObject (const Handle(Graphic3d_ArrayOfPrimitives) theArray)
+  MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDescription,
+                  Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
   {
-    myArray = theArray;
+    myArrayDescription = theArrayDescription;
+    myMarkerAspect = theMarkerAspect;
   }
 
-  DEFINE_STANDARD_RTTI(MyPArrayObject);
+  DEFINE_STANDARD_RTTI_INLINE(MyPArrayObject,AIS_InteractiveObject);
 
 private:
 
   void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
                 const Handle(Prs3d_Presentation)& aPresentation,
-                const Standard_Integer aMode);
+                const Standard_Integer aMode) Standard_OVERRIDE;
+
+  void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
+                         const Standard_Integer /*theMode*/) Standard_OVERRIDE;
 
-  void ComputeSelection (const Handle(SelectMgr_Selection)& aSelection,
-                         const Standard_Integer aMode) {};
+  bool CheckInputCommand (const TCollection_AsciiString theCommand,
+                          const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
+                          Standard_Integer &theArgIndex,
+                          Standard_Integer theArgCount,
+                          Standard_Integer theMaxArgs);
 
 protected:
 
-  Handle(Graphic3d_ArrayOfPrimitives) myArray;
+  Handle(TColStd_HArray1OfAsciiString) myArrayDescription;
+  Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
 
 };
 
-IMPLEMENT_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject)
-IMPLEMENT_STANDARD_RTTIEXT(MyPArrayObject, AIS_InteractiveObject)
 
-void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
+void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
                               const Handle(Prs3d_Presentation)& aPresentation,
-                              const Standard_Integer aMode)
-{
-  aPresentation->Clear();
-  Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (myArray);
-}
-
-static bool CheckInputCommand (const TCollection_AsciiString theCommand,
-                               const char **theArgStr, int &theArgIndex,
-                               int theArgCount, int theMaxArgs)
+                              const Standard_Integer /*aMode*/)
 {
-  // check if there is more elements than expected
-  if (theArgIndex >= theMaxArgs)
-    return false;
 
-  TCollection_AsciiString aStrCommand(theArgStr[theArgIndex]);
-  aStrCommand.LowerCase();
-  if (aStrCommand.Search(theCommand) != 1 ||
-      theArgIndex + (theArgCount - 1) >= theMaxArgs)
-    return false;
+  // Parsing array description
+  Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
+  Standard_Boolean hasVColors, hasBColors, hasNormals, hasTexels;
+  hasVColors = hasNormals = hasBColors = hasTexels = Standard_False;
 
-  // go to the first data element
-  theArgIndex++;
+  Standard_Integer anArgIndex = 0;
+  Standard_Integer anArgsCount = myArrayDescription->Length();
+  TCollection_AsciiString anArrayType = myArrayDescription->Value (anArgIndex++);
 
-  // check data if it can be converted to numeric
-  for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
+  TCollection_AsciiString aCommand;
+  while (anArgIndex < anArgsCount)
   {
-    aStrCommand = theArgStr[theArgIndex];
-    if (!aStrCommand.IsRealValue())
-      return false;
-  }
+    aCommand = myArrayDescription->Value (anArgIndex);
+    aCommand.LowerCase();
 
-  return true;
-}
+    // vertex command
+    if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
+    {
+      // vertex has a normal or normal with color or texel
+      if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
+        hasNormals = Standard_True;
 
-//=============================================================================
-//function : VDrawPArray
-//purpose  : Draws primitives array from list of vertexes, bounds, edges
-//=============================================================================
-
-static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
-{
-  Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
-  if (aContextAIS.IsNull())
-  {
-    di << "Call vinit before!\n";
-    return 1;
-  }
-  else if (argc < 3)
-  {
-    di << "Use: " << argv[0] << " Name TypeOfArray"
-       << " [vertex] ... [bounds] ... [edges]\n"
-       << "  TypeOfArray={ points | segments | polylines | triangles |\n"
-       << "                trianglefans | trianglestrips | quads |\n"
-       << "                quadstrips | polygons }\n"
-       << "  vertex={ 'v' x y z [normal={ 'n' nx ny nz }] [color={ 'c' r g b }]"
-       << " [texel={ 't' tx ty }] } \n"
-       << "  bounds={ 'b' verticies_count [color={ 'c' r g b }] }\n"
-       << "  edges={ 'e' vertex_id [hidden_edge={'h'}] }\n";
-    return 1;
-  }
-
-  // read the arguments
-  Standard_Integer aArgIndex = 1;
-  TCollection_AsciiString aName (argv[aArgIndex++]);
-  TCollection_AsciiString anArrayType (argv[aArgIndex++]);
-  const Standard_Integer anArgsFrom = aArgIndex;
-
-  // parse number of verticies, bounds, edges
-  Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
-  Standard_Boolean hasVColors, hasBColors, hasNormals, hasInfos, hasTexels;
-  hasVColors = hasNormals = hasBColors = hasInfos = hasTexels = Standard_False;
-
-  TCollection_AsciiString aCommand;
-  while (aArgIndex < argc)
-  {
-    aCommand = argv[aArgIndex];
-    aCommand.LowerCase();
-    if (!aCommand.IsAscii())
-    {
-      di << "Unexpected argument: #" << aArgIndex - 1 << " , "
-         << "should be an array element: 'v', 'b', 'e' \n";
-      break;
-    }
-
-    // vertex command
-    if (CheckInputCommand ("v", argv, aArgIndex, 3, argc))
-    {
-      // vertex has a normal or normal with color or texel
-      if (CheckInputCommand ("n", argv, aArgIndex, 3, argc))
-        hasNormals = Standard_True;
-
-      // vertex has a color
-      if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
-        hasVColors = Standard_True;
+      // vertex has a color
+      if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
+        hasVColors = Standard_True;
 
       // vertex has a texel
-      if (CheckInputCommand ("t", argv, aArgIndex, 2, argc))
+      if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
         hasTexels = Standard_True;
 
       aVertexNum++;
     }
     // bound command
-    else if (CheckInputCommand ("b", argv, aArgIndex, 1, argc))
+    else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
     {
       // bound has color
-      if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
+      if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
         hasBColors = Standard_True;
 
       aBoundNum++;
     }
     // edge command
-    else if (CheckInputCommand ("e", argv, aArgIndex, 1, argc))
+    else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
     {
-      // edge has a hide flag
-      if (CheckInputCommand ("h", argv, aArgIndex, 0, argc))
-        hasInfos = Standard_True;
-
       aEdgeNum++;
     }
     // unknown command
     else
-      aArgIndex++;
-  }
-
-  if (aVertexNum == 0)
-  {
-    di << "You should pass any verticies in the list of array elements\n";
-    return 1;
+      anArgIndex++;
   }
 
-  // create an array of primitives by types
   Handle(Graphic3d_ArrayOfPrimitives) anArray;
   if (anArrayType == "points")
+  {
     anArray = new Graphic3d_ArrayOfPoints (aVertexNum);
+  }
   else if (anArrayType == "segments")
     anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors);
   else if (anArrayType == "polylines")
     anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum,
-                                              hasVColors, hasBColors, hasInfos);
+                                              hasVColors, hasBColors);
   else if (anArrayType == "triangles")
     anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals,
-                                              hasVColors, hasTexels, hasInfos);
+                                              hasVColors, hasTexels);
   else if (anArrayType == "trianglefans")
     anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum,
                                                  hasNormals, hasVColors,
@@ -3350,7 +3001,7 @@ static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char*
   else if (anArrayType == "quads")
     anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum,
                                                 hasNormals, hasVColors,
-                                                hasTexels, hasInfos);
+                                                hasTexels);
   else if (anArrayType == "quadstrips")
     anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum,
                                                      hasNormals, hasVColors,
@@ -3358,352 +3009,631 @@ static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char*
   else if (anArrayType == "polygons")
     anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum,
                                              hasNormals, hasVColors, hasBColors,
-                                             hasTexels, hasInfos);
-  else
-  {
-    di << "Unexpected type of primitiives array\n";
-    return 1;
-  }
+                                             hasTexels);
 
-  // parse an array of primitives
-  aArgIndex = anArgsFrom;
-  while (aArgIndex < argc)
+  anArgIndex = 1;
+  while (anArgIndex < anArgsCount)
   {
-    aCommand = argv[aArgIndex];
+    aCommand = myArrayDescription->Value (anArgIndex);
     aCommand.LowerCase();
     if (!aCommand.IsAscii())
       break;
 
     // vertex command
-    if (CheckInputCommand ("v", argv, aArgIndex, 3, argc))
+    if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
     {
-      anArray->AddVertex (Draw::Atof (argv[aArgIndex - 3]),
-                          Draw::Atof (argv[aArgIndex - 2]),
-                          Draw::Atof (argv[aArgIndex - 1]));
+      anArray->AddVertex (myArrayDescription->Value (anArgIndex - 3).RealValue(),
+                          myArrayDescription->Value (anArgIndex - 2).RealValue(),
+                          myArrayDescription->Value (anArgIndex - 1).RealValue());
+      const Standard_Integer aVertIndex = anArray->VertexNumber();
 
       // vertex has a normal or normal with color or texel
-      if (CheckInputCommand ("n", argv, aArgIndex, 3, argc))
-        anArray->SetVertexNormal (anArray->VertexNumber (),
-                                  Draw::Atof (argv[aArgIndex - 3]),
-                                  Draw::Atof (argv[aArgIndex - 2]),
-                                  Draw::Atof (argv[aArgIndex - 1]));
+      if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
+        anArray->SetVertexNormal (aVertIndex,
+                                  myArrayDescription->Value (anArgIndex - 3).RealValue(),
+                                  myArrayDescription->Value (anArgIndex - 2).RealValue(),
+                                  myArrayDescription->Value (anArgIndex - 1).RealValue());
       
-      if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
-        anArray->SetVertexColor (anArray->VertexNumber (),
-                                 Draw::Atof (argv[aArgIndex - 3]),
-                                 Draw::Atof (argv[aArgIndex - 2]),
-                                 Draw::Atof (argv[aArgIndex - 1]));
+      if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
+        anArray->SetVertexColor (aVertIndex,
+                                 myArrayDescription->Value (anArgIndex - 3).RealValue(),
+                                 myArrayDescription->Value (anArgIndex - 2).RealValue(),
+                                 myArrayDescription->Value (anArgIndex - 1).RealValue());
       
-      if (CheckInputCommand ("t", argv, aArgIndex, 2, argc))
-        anArray->SetVertexTexel (anArray->VertexNumber (),
-                                 Draw::Atof (argv[aArgIndex - 2]),
-                                 Draw::Atof (argv[aArgIndex - 1]));
+      if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
+        anArray->SetVertexTexel (aVertIndex,
+                                 myArrayDescription->Value (anArgIndex - 2).RealValue(),
+                                 myArrayDescription->Value (anArgIndex - 1).RealValue());
     }
     // bounds command
-    else if (CheckInputCommand ("b", argv, aArgIndex, 1, argc))
+    else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
     {
-      Standard_Integer aVertCount = Draw::Atoi (argv[aArgIndex - 1]);
+      Standard_Integer aVertCount = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
 
-      if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
+      if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
         anArray->AddBound (aVertCount,
-                           Draw::Atof (argv[aArgIndex - 3]),
-                           Draw::Atof (argv[aArgIndex - 2]),
-                           Draw::Atof (argv[aArgIndex - 1]));
+                           myArrayDescription->Value (anArgIndex - 3).RealValue(),
+                           myArrayDescription->Value (anArgIndex - 2).RealValue(),
+                           myArrayDescription->Value (anArgIndex - 1).RealValue());
 
       else
         anArray->AddBound (aVertCount);
     }
     // edge command
-    else if (CheckInputCommand ("e", argv, aArgIndex, 1, argc))
+    else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
     {
-      Standard_Integer aVertIndex = Draw::Atoi (argv[aArgIndex - 1]);
-
-      // edge has/hasn't hide flag
-      if (CheckInputCommand ("h", argv, aArgIndex, 0, argc))
-        anArray->AddEdge (aVertIndex, Standard_False);
-      else
-        anArray->AddEdge (aVertIndex, Standard_True);
+      const Standard_Integer aVertIndex = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
+      anArray->AddEdge (aVertIndex);
     }
     // unknown command
     else
-      aArgIndex++;
+      anArgIndex++;
   }
 
-  // create primitives array object
-  Handle (MyPArrayObject) aPObject = new MyPArrayObject (anArray);
+  aPresentation->Clear();
+  if (!myMarkerAspect.IsNull())
+  {
+    Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
+  }
+  Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
+  Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
+  Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
+}
 
-  // register the object in map
-  VDisplayAISObject (aName, aPObject);
+void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
+                                       const Standard_Integer /*theMode*/)
+{
+  Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
 
-  return 0;
+  Standard_Integer anArgIndex = 1;
+  while (anArgIndex < myArrayDescription->Length())
+  {
+    if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, myArrayDescription->Length()))
+    {
+      gp_Pnt aPoint (myArrayDescription->Value (anArgIndex - 3).RealValue(),
+                     myArrayDescription->Value (anArgIndex - 2).RealValue(),
+                     myArrayDescription->Value (anArgIndex - 1).RealValue());
+      Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
+      theSelection->Add (aSensetivePoint);
+    }
+    else
+    {
+      anArgIndex++;
+    }
+  }
 }
 
-//=======================================================================
-//function : VSetLocation
-//purpose  : Change location of AIS interactive object
-//=======================================================================
+bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand,
+                                       const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
+                                       Standard_Integer &theArgIndex,
+                                       Standard_Integer theArgCount,
+                                       Standard_Integer theMaxArgs)
+{
+  // check if there is more elements than expected
+  if (theArgIndex >= theMaxArgs)
+    return false;
+
+  TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex);
+  aStrCommand.LowerCase();
+  if (aStrCommand.Search(theCommand) != 1 ||
+      theArgIndex + (theArgCount - 1) >= theMaxArgs)
+    return false;
+
+  // go to the first data element
+  theArgIndex++;
+
+  // check data if it can be converted to numeric
+  for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
+  {
+    aStrCommand = theArgsArray->Value (theArgIndex);
+    if (!aStrCommand.IsRealValue())
+      return false;
+  }
+
+  return true;
+}
+
+//=============================================================================
+//function : VDrawPArray
+//purpose  : Draws primitives array from list of vertexes, bounds, edges
+//=============================================================================
 
-static Standard_Integer VSetLocation (Draw_Interpretor& di,
-                                      Standard_Integer argc,
-                                      const char ** argv)
+static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
-  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
-  if (aContext.IsNull())
+  Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
+  if (aContextAIS.IsNull())
   {
-    di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
+    di << "Call vinit before!\n";
     return 1;
   }
-
-  if (argc != 5)
+  else if (argc < 3)
   {
-    di << "ERROR : Usage : " << argv[0] << " name x y z; new location" << "\n";
+    di << "Use: " << argv[0] << " Name TypeOfArray"
+       << " [vertex] ... [bounds] ... [edges]\n"
+       << "  TypeOfArray={ points | segments | polylines | triangles |\n"
+       << "                trianglefans | trianglestrips | quads |\n"
+       << "                quadstrips | polygons }\n"
+       << "  vertex={ 'v' x y z [normal={ 'n' nx ny nz }] [color={ 'c' r g b }]"
+       << " [texel={ 't' tx ty }] } \n"
+       << "  bounds={ 'b' verticies_count [color={ 'c' r g b }] }\n"
+       << "  edges={ 'e' vertex_id }\n";
     return 1;
   }
 
-  TCollection_AsciiString aName (argv[1]);
-  Standard_Real aX = Draw::Atof (argv[2]);
-  Standard_Real aY = Draw::Atof (argv[3]);
-  Standard_Real aZ = Draw::Atof (argv[4]);
+  // read the arguments
+  Standard_Integer aArgIndex = 1;
+  TCollection_AsciiString aName (argv[aArgIndex++]);
+  TCollection_AsciiString anArrayType (argv[aArgIndex++]);
 
-  // find object
-  ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
-  Handle(AIS_InteractiveObject) anIObj;
-  if (!aMap.IsBound2 (aName))
+  Standard_Boolean hasVertex = Standard_False;
+
+  Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 2);
+  anArgsArray->SetValue (0, anArrayType);
+
+  if (anArrayType != "points"         &&
+      anArrayType != "segments"       &&
+      anArrayType != "polylines"      &&
+      anArrayType != "triangles"      &&
+      anArrayType != "trianglefans"   &&
+      anArrayType != "trianglestrips" &&
+      anArrayType != "quads"          &&
+      anArrayType != "quadstrips"     &&
+      anArrayType != "polygons")
   {
-    di << "Use 'vdisplay' before" << "\n";
+    di << "Unexpected type of primitives array\n";
     return 1;
   }
-  else
+
+  TCollection_AsciiString aCommand;
+  for (Standard_Integer anArgIndex = 3; anArgIndex < argc; anArgIndex++)
   {
-    anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
+    aCommand = argv[anArgIndex];
+    aCommand.LowerCase();
+    if (!aCommand.IsAscii())
+    {
+      di << "Unexpected argument: #" << aArgIndex - 1 << " , "
+         << "should be an array element: 'v', 'b', 'e' \n";
+      break;
+    }
 
-    // not an AIS_InteractiveObject
-    if (anIObj.IsNull())
+    if (aCommand == "v")
     {
-      di << argv[1] << " : Not an AIS interactive object" << "\n";
-      return 1;
+      hasVertex = Standard_True;
     }
 
-    gp_Trsf aTrsf;
-    aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
-    TopLoc_Location aLocation (aTrsf);
-    aContext->SetLocation (anIObj, aLocation);
-    aContext->UpdateCurrentViewer();
+    anArgsArray->SetValue (anArgIndex - 2, aCommand);
+  }
+
+  if (!hasVertex)
+  {
+    di << "You should pass any verticies in the list of array elements\n";
+    return 1;
+  }
+
+  Handle(Graphic3d_AspectMarker3d)    anAspPoints;
+  if (anArrayType == "points")
+  {
+    anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f);
   }
 
+  // create primitives array object
+  Handle(MyPArrayObject) aPObject = new MyPArrayObject (anArgsArray, anAspPoints);
+
+  // register the object in map
+  VDisplayAISObject (aName, aPObject);
+
   return 0;
 }
 
-//===============================================================================================
-//function : VConnect
-//purpose  : Creates and displays AIS_ConnectedInteractive object from input object and location 
-//Draw arg : vconnect name Xo Yo Zo Xu Xv Xw Zu Zv Zw object1 object2 ... [color=NAME]
-//===============================================================================================
-
-static Standard_Integer VConnect(Draw_Interpretor& di, 
-                                 Standard_Integer argc, 
-                                 const char ** argv) 
+namespace
 {
-  // Check the viewer
-  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
-  if (aContext.IsNull())
+  //! Auxiliary function for parsing translation vector - either 2D or 3D.
+  static Standard_Integer parseTranslationVec (Standard_Integer theArgNb,
+                                               const char**     theArgVec,
+                                               gp_Vec&          theVec)
   {
-    std::cout << "vconnect error : call vinit before\n";
-    return 1; // TCL_ERROR
-  }
-  // Check argumnets 
-  if (argc < 12)
-  {
-    std::cout << "vconnect error: expect at least 11 arguments\n";
-    return 1; // TCL_ERROR
+    if (theArgNb < 2)
+    {
+      return 0;
+    }
+
+    TCollection_AsciiString anX (theArgVec[0]);
+    TCollection_AsciiString anY (theArgVec[1]);
+    if (!anX.IsRealValue()
+     || !anY.IsRealValue())
+    {
+      return 0;
+    }
+
+    theVec.SetX (anX.RealValue());
+    theVec.SetY (anY.RealValue());
+    if (theArgNb >= 3)
+    {
+      TCollection_AsciiString anZ (theArgVec[2]);
+      if (anZ.IsRealValue())
+      {
+        theVec.SetZ (anZ.RealValue());
+        return 3;
+      }
+    }
+    return 2;
   }
+}
 
-  // Get values
-  Standard_Integer anArgIter = 1;
-  TCollection_AsciiString aName (argv[anArgIter++]);
-  Handle(AIS_InteractiveObject) anOriginObject;
-  TCollection_AsciiString aColorString (argv[argc-1]);
-  Standard_CString aColorName;
-  Standard_Boolean hasColor = Standard_False;
-  if (aColorString.Search ("color=") != -1)
+//=======================================================================
+//function : VSetLocation
+//purpose  : Change location of AIS interactive object
+//=======================================================================
+
+static Standard_Integer VSetLocation (Draw_Interpretor& theDI,
+                                      Standard_Integer  theArgNb,
+                                      const char**      theArgVec)
+{
+  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
+  ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
+  if (aContext.IsNull())
   {
-    hasColor = Standard_True;
-    aColorString.Remove (1, 6);
-    aColorName = aColorString.ToCString();
+    std::cout << "Error: no active view!\n";
+    return 1;
   }
-  Handle(AIS_InteractiveObject) anObject;
 
-  // AIS_ConnectedInteractive
-  if (argc == 12 || (argc == 13 && hasColor))
+  Standard_Boolean toPrintInfo = Standard_True;
+  Handle(AIS_InteractiveObject) anObj;
+  TCollection_AsciiString aCmdName (theArgVec[0]);
+  aCmdName.LowerCase();
+  for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
   {
-    TCollection_AsciiString anOriginObjectName(argv[11]);
-    if (aName.IsEqual (anOriginObjectName))
+    TCollection_AsciiString anArg = theArgVec[anArgIter];
+    anArg.LowerCase();
+    if (anUpdateTool.parseRedrawMode (anArg))
     {
-      std::cout << "vconnect error: equal names for connected objects\n"; 
-      return 1; // TCL_ERROR
+      continue;
     }
-    if (GetMapOfAIS().IsBound2 (anOriginObjectName))
+    else if (anObj.IsNull())
     {
-      Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
-      anOriginObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
-      if (anOriginObject.IsNull())
+      const TCollection_AsciiString aName (theArgVec[anArgIter]);
+      const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
+      if (aMap.IsBound2 (aName))
       {
-        std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
-        return 1; // TCL_ERROR
+        anObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
+      }
+      if (anObj.IsNull())
+      {
+        std::cout << "Error: object '" << aName << "' is not displayed!\n";
+        return 1;
       }
     }
-    else
+    else if (anArg == "-reset")
     {
-      Standard_CString aName = anOriginObjectName.ToCString();
-      TopoDS_Shape aTDShape = DBRep::Get (aName);
-      if (aTDShape.IsNull())
+      toPrintInfo = Standard_False;
+      aContext->SetLocation (anObj, gp_Trsf());
+    }
+    else if (anArg == "-copyfrom"
+          || anArg == "-copy")
+    {
+      if (anArgIter + 1 >= theArgNb)
       {
-        std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
-        return 1; // TCL_ERROR
+        std::cout << "Syntax error at '" << anArg << "'\n";
+        return 1;
+      }
+
+      const TCollection_AsciiString aName2 (theArgVec[anArgIter + 1]);
+      const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
+      Handle(AIS_InteractiveObject) anObj2;
+      if (aMap.IsBound2 (aName2))
+      {
+        anObj2 = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName2));
       }
-      anOriginObject = new AIS_Shape (aTDShape);
-      if (hasColor)
+      if (anObj2.IsNull())
       {
-        anOriginObject->SetColor (ViewerTest::GetColorFromName (aColorName));
+        std::cout << "Error: object '" << aName2 << "' is not displayed!\n";
+        return 1;
       }
+
+      ++anArgIter;
+      aContext->SetLocation (anObj, anObj2->LocalTransformation());
     }
-  }
-  // AIS_MultipleConnectedInteractive
-  else
-  {
-    const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc;
-    for (Standard_Integer i = 11; i < aNbShapes; ++i)
+    else if (anArg == "-rotate")
     {
-      TCollection_AsciiString anOriginObjectName (argv[i]);
-      if (aName.IsEqual (anOriginObjectName))
+      toPrintInfo = Standard_False;
+      if (anArgIter + 7 >= theArgNb)
       {
-        std::cout << "vconnect error: equal names for connected objects\n";
-        continue;
+        std::cout << "Syntax error at '" << anArg << "'\n";
+        return 1;
+      }
+
+      gp_Trsf aTrsf;
+      aTrsf.SetRotation (gp_Ax1 (gp_Pnt (Draw::Atof (theArgVec[anArgIter + 1]),
+                                         Draw::Atof (theArgVec[anArgIter + 2]),
+                                         Draw::Atof (theArgVec[anArgIter + 3])),
+                                 gp_Vec (Draw::Atof (theArgVec[anArgIter + 4]),
+                                         Draw::Atof (theArgVec[anArgIter + 5]),
+                                         Draw::Atof (theArgVec[anArgIter + 6]))),
+                                         Draw::Atof (theArgVec[anArgIter + 7]) * (M_PI / 180.0));
+      anArgIter += 7;
+
+      aTrsf = anObj->LocalTransformation() * aTrsf;
+      aContext->SetLocation (anObj, aTrsf);
+    }
+    else if (anArg == "-translate")
+    {
+      toPrintInfo = Standard_False;
+      gp_Vec aLocVec;
+      Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec);
+      anArgIter += aNbParsed;
+      if (aNbParsed == 0)
+      {
+        std::cout << "Syntax error at '" << anArg << "'\n";
+        return 1;
       }
-      if (GetMapOfAIS().IsBound2 (anOriginObjectName))
+
+      gp_Trsf aTrsf;
+      aTrsf.SetTranslationPart (aLocVec);
+      aTrsf = anObj->LocalTransformation() * aTrsf;
+      aContext->SetLocation (anObj, aTrsf);
+    }
+    else if (anArg == "-scale"
+          || anArg == "-setscale")
+    {
+      toPrintInfo = Standard_False;
+      gp_XYZ aScaleLoc;
+      Standard_Real aScale = 1.0;
+      Standard_Boolean toPrintScale = Standard_True;
+      Standard_Boolean hasScaleLoc  = Standard_False;
+      if (anArgIter + 4 < theArgNb)
       {
-        Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
-        anObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
-        if (anObject.IsNull())
+        TCollection_AsciiString aScaleArgs[4] =
         {
-          std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
-          continue;
+          TCollection_AsciiString (theArgVec[anArgIter + 1]),
+          TCollection_AsciiString (theArgVec[anArgIter + 2]),
+          TCollection_AsciiString (theArgVec[anArgIter + 3]),
+          TCollection_AsciiString (theArgVec[anArgIter + 4])
+        };
+        Standard_Integer aScaleArgIter = 0;
+        for (; aScaleArgIter < 4; ++aScaleArgIter)
+        {
+          if (!aScaleArgs[aScaleArgIter].IsRealValue())
+          {
+            break;
+          }
+        }
+        if (aScaleArgIter == 4)
+        {
+          aScaleLoc.SetCoord (aScaleArgs[0].RealValue(), aScaleArgs[1].RealValue(), aScaleArgs[2].RealValue());
+          aScale = aScaleArgs[3].RealValue();
+          anArgIter += 4;
+          toPrintScale = Standard_False;
+          hasScaleLoc  = Standard_True;
+        }
+        else if (aScaleArgIter >= 1)
+        {
+          aScale = aScaleArgs[0].RealValue();
+          ++anArgIter;
+          toPrintScale = Standard_False;
         }
       }
-      else
+      else if (anArgIter + 1 < theArgNb)
       {
-        Standard_CString aName = anOriginObjectName.ToCString();
-        TopoDS_Shape aTDShape = DBRep::Get (aName);
-        if (aTDShape.IsNull())
+        TCollection_AsciiString aScaleArg (theArgVec[anArgIter + 1]);
+        if (aScaleArg.IsRealValue())
         {
-          std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
-          continue;
+          aScale = aScaleArg.RealValue();
+          ++anArgIter;
+          toPrintScale = Standard_False;
         }
-        anObject = new AIS_Shape (aTDShape);
-        anObject->SetColor (ViewerTest::GetColorFromName (aColorName));
       }
-      if (anOriginObject.IsNull())
+
+      if (toPrintScale)
       {
-        anOriginObject = new AIS_MultipleConnectedInteractive();
-        Handle(AIS_MultipleConnectedInteractive)::DownCast(anOriginObject)->Connect (anObject);
+        if (anArg == "-setscale")
+        {
+          std::cout << "Syntax error at '" << anArg << "'\n";
+          return 1;
+        }
+
+        char aText[1024];
+        Sprintf (aText, "%g ", anObj->LocalTransformation().ScaleFactor());
+        theDI << aText;
+        continue;
       }
-      else
+
+      if (anArg == "-setscale")
       {
-        Handle(AIS_MultipleConnectedInteractive)::DownCast(anOriginObject)->Connect (anObject);
-      }
-    }
-    if (anOriginObject.IsNull())
+        gp_Trsf aTrsf = anObj->LocalTransformation();
+        if (hasScaleLoc)
+        {
+          aTrsf.SetScale (aScaleLoc, aScale);
+        }
+        else
+        {
+          aTrsf.SetScaleFactor (aScale);
+        }
+        aContext->SetLocation (anObj, aTrsf);
+      }
+      else
+      {
+        gp_Trsf aTrsf;
+        if (hasScaleLoc)
+        {
+          aTrsf.SetScale (aScaleLoc, aScale);
+          aTrsf = anObj->LocalTransformation() * aTrsf;
+        }
+        else
+        {
+          aTrsf = anObj->LocalTransformation();
+          aTrsf.SetScaleFactor (aTrsf.ScaleFactor() * aScale);
+        }
+        aContext->SetLocation (anObj, aTrsf);
+      }
+    }
+    else if (anArg == "-mirror")
     {
-      std::cout << "vconect error : can't connect input objects\n";
-      return 1; // TCL_ERROR
+      toPrintInfo = Standard_False;
+      if (anArgIter + 6 >= theArgNb)
+      {
+        std::cout << "Syntax error at '" << anArg << "'\n";
+        return 1;
+      }
+
+      gp_Trsf aTrsf;
+      aTrsf.SetMirror (gp_Ax2 (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 6]),
+                                       Draw::Atof(theArgVec[theArgNb - 5]),
+                                       Draw::Atof(theArgVec[theArgNb - 4])),
+                               gp_Vec (Draw::Atof(theArgVec[theArgNb - 3]),
+                                       Draw::Atof(theArgVec[theArgNb - 2]),
+                                       Draw::Atof(theArgVec[theArgNb - 1]))));
+      anArgIter += 6;
+      aTrsf = anObj->LocalTransformation() * aTrsf;
+      aContext->SetLocation (anObj, aTrsf);
     }
-  }
+    else if (anArg == "-setrotation"
+          || anArg == "-rotation")
+    {
+      toPrintInfo = Standard_False;
+      if (anArgIter + 4 < theArgNb)
+      {
+        TCollection_AsciiString aQuatArgs[4] =
+        {
+          TCollection_AsciiString (theArgVec[anArgIter + 1]),
+          TCollection_AsciiString (theArgVec[anArgIter + 2]),
+          TCollection_AsciiString (theArgVec[anArgIter + 3]),
+          TCollection_AsciiString (theArgVec[anArgIter + 4])
+        };
+        Standard_Integer aQuatArgIter = 0;
+        for (; aQuatArgIter < 4; ++aQuatArgIter)
+        {
+          if (!aQuatArgs[aQuatArgIter].IsRealValue())
+          {
+            break;
+          }
+        }
 
-  // Get location data
-  Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
-  Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
-  Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
-  Standard_Real aXu = Draw::Atof (argv[anArgIter++]);
-  Standard_Real aXv = Draw::Atof (argv[anArgIter++]);
-  Standard_Real aXw = Draw::Atof (argv[anArgIter++]);
-  Standard_Real aZu = Draw::Atof (argv[anArgIter++]);
-  Standard_Real aZv = Draw::Atof (argv[anArgIter++]);
-  Standard_Real aZw = Draw::Atof (argv[anArgIter++]);
+        if (aQuatArgIter == 4)
+        {
+          anArgIter += 4;
+          const gp_Quaternion aQuat (aQuatArgs[0].RealValue(),
+                                     aQuatArgs[1].RealValue(),
+                                     aQuatArgs[2].RealValue(),
+                                     aQuatArgs[3].RealValue());
+          gp_Trsf aTrsf = anObj->LocalTransformation();
+          aTrsf.SetRotation (aQuat);
+          aContext->SetLocation (anObj, aTrsf);
+          continue;
+        }
+        else if (anArg == "-setrotation")
+        {
+          std::cout << "Syntax error at '" << anArg << "'\n";
+          return 1;
+        }
+      }
 
-  // Create transformation
-  gp_Pnt aPoint(aXo, aYo, aZo);
-  gp_Dir anXDir(aXu, aXv, aXw), aZDir(aZu, aZv, aZw);
-  if(!anXDir.IsNormal(aZDir, Precision::Angular()))
-  {
-    std::cout << "vconnect error : XDir expects to be normal to ZDir\n"; 
-    return 1; // TCL_ERROR
-  } 
-  gp_Ax3 anAx3(aPoint, aZDir, anXDir); 
-  gp_Trsf aTrsf; 
-  aTrsf.SetTransformation(anAx3); 
-  TopLoc_Location aLocation(aTrsf);
+      char aText[1024];
+      const gp_Quaternion aQuat = anObj->LocalTransformation().GetRotation();
+      Sprintf (aText, "%g %g %g %g ", aQuat.X(), aQuat.Y(), aQuat.Z(), aQuat.W());
+      theDI << aText;
+    }
+    else if (anArg == "-setlocation"
+          || anArg == "-location")
+    {
+      toPrintInfo = Standard_False;
+      gp_Vec aLocVec;
+      Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec);
+      anArgIter += aNbParsed;
+      if (aNbParsed != 0)
+      {
+        gp_Trsf aTrsf = anObj->LocalTransformation();
+        aTrsf.SetTranslationPart (aLocVec);
+        aContext->SetLocation (anObj, aTrsf);
+      }
+      else if (anArg == "-setlocation")
+      {
+        std::cout << "Syntax error at '" << anArg << "'\n";
+        return 1;
+      }
 
-  // Create connected object
-  Handle(AIS_ConnectedInteractive) aConnected = new AIS_ConnectedInteractive();
-  Handle(AIS_MultipleConnectedInteractive) anOrigin = Handle(AIS_MultipleConnectedInteractive)::DownCast(anOriginObject);
-  if (anOrigin.IsNull())
-  {
-    aConnected->Connect (anOriginObject, aLocation);
+      char aText[1024];
+      const gp_XYZ aLoc = anObj->LocalTransformation().TranslationPart();
+      Sprintf (aText, "%g %g %g ", aLoc.X(), aLoc.Y(), aLoc.Z());
+      theDI << aText;
+    }
+    else if (aCmdName == "vsetlocation")
+    {
+      // compatibility with old syntax
+      gp_Vec aLocVec;
+      Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter, theArgVec + anArgIter, aLocVec);
+      if (aNbParsed == 0)
+      {
+        std::cout << "Syntax error at '" << anArg << "'\n";
+        return 1;
+      }
+      anArgIter = anArgIter + aNbParsed - 1;
+
+      gp_Trsf aTrsf;
+      aTrsf.SetTranslationPart (aLocVec);
+      aContext->SetLocation (anObj, aTrsf);
+      toPrintInfo = Standard_False;
+    }
+    else
+    {
+      std::cout << "Error: unknown argument '" << anArg << "'\n";
+      return 1;
+    }
   }
-  else
+
+  if (anObj.IsNull())
   {
-    aConnected->Connect (anOrigin, aLocation);
+    std::cout << "Syntax error - wrong number of arguments\n";
+    return 1;
   }
-
-  // Check if there is another object with given name
-  // and remove it from context
-  if(GetMapOfAIS().IsBound2(aName))
+  else if (!toPrintInfo)
   {
-    Handle(AIS_InteractiveObject) anObj = 
-      Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
-    TheAISContext()->Remove(anObj, Standard_False);
-    GetMapOfAIS().UnBind2(aName);
+    return 0;
   }
 
-  // Bind connected object to its name
-  GetMapOfAIS().Bind (aConnected, aName);
-
-  // Display connected object
-  TheAISContext()->Display (aConnected);
-
+  const gp_Trsf       aTrsf = anObj->LocalTransformation();
+  const gp_XYZ        aLoc  = aTrsf.TranslationPart();
+  const gp_Quaternion aRot  = aTrsf.GetRotation();
+  char aText[4096];
+  Sprintf (aText, "Location: %g %g %g\n"
+                  "Rotation: %g %g %g %g\n"
+                  "Scale:    %g\n",
+                  aLoc.X(), aLoc.Y(), aLoc.Z(),
+                  aRot.X(), aRot.Y(), aRot.Z(), aRot.W(),
+                  aTrsf.ScaleFactor());
+  theDI << aText;
   return 0;
 }
 
 //===============================================================================================
-//function : VConnectShape
-//purpose  : Creates and displays AIS_ConnectedShape from input shape and location 
-//Draw arg : vconnectsh name Xo Yo Zo Xu Xv Xw Zu Zv Zw shape1 shape2 ... [color=NAME]
+//function : VConnect
+//purpose  : Creates and displays AIS_ConnectedInteractive object from input object and location 
+//Draw arg : vconnect name Xo Yo Zo object1 object2 ... [color=NAME]
 //===============================================================================================
 
-static Standard_Integer VConnectShape(Draw_Interpretor& di
-                                      Standard_Integer argc, 
-                                      const char ** argv) 
+static Standard_Integer VConnect (Draw_Interpretor& /*di*/
+                                  Standard_Integer argc, 
+                                  const char ** argv) 
 {
   // Check the viewer
   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
   if (aContext.IsNull())
   {
-    std::cout << "vconnectsh error : call vinit before\n";
+    std::cout << "vconnect error : call vinit before\n";
     return 1; // TCL_ERROR
   }
-  // Check argumnets
-  if (argc < 12)
+  // Check argumnets 
+  if (argc < 6)
   {
-    std::cout << "vconnectsh error: expect at least 11 arguments\n";
+    std::cout << "vconnect error: expect at least 5 arguments\n";
     return 1; // TCL_ERROR
   }
 
   // Get values
   Standard_Integer anArgIter = 1;
   TCollection_AsciiString aName (argv[anArgIter++]);
-  Handle(AIS_InteractiveObject) anOriginShape;
-  TCollection_AsciiString aColorString(argv[argc-1]);
-  Standard_CString aColorName;
+  Handle(AIS_MultipleConnectedInteractive) anOriginObject;
+  TCollection_AsciiString aColorString (argv[argc-1]);
+  Standard_CString aColorName = "";
   Standard_Boolean hasColor = Standard_False;
   if (aColorString.Search ("color=") != -1)
   {
@@ -3711,134 +3641,68 @@ static Standard_Integer VConnectShape(Draw_Interpretor& di,
     aColorString.Remove (1, 6);
     aColorName = aColorString.ToCString();
   }
-  Handle(AIS_Shape) aShape;
+  Handle(AIS_InteractiveObject) anObject;
 
-  // AIS_ConnectedShape
-  if (argc == 12 || (argc == 13 && hasColor))
+  // AIS_MultipleConnectedInteractive
+  const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc;
+  for (Standard_Integer i = 5; i < aNbShapes; ++i)
   {
-    TCollection_AsciiString anOriginShapeName (argv[11]);
-    if (aName.IsEqual (anOriginShapeName))
+    TCollection_AsciiString anOriginObjectName (argv[i]);
+    if (aName.IsEqual (anOriginObjectName))
     {
-      std::cout << "vconnectsh error: equal names for connected shapes\n";
-      return 1; // TCL_ERROR
+      std::cout << "vconnect error: equal names for connected objects\n";
+      continue;
     }
-    if (GetMapOfAIS().IsBound2 (anOriginShapeName))
+    if (GetMapOfAIS().IsBound2 (anOriginObjectName))
     {
-      Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginShapeName);
-      anOriginShape = Handle(AIS_Shape)::DownCast(anObj);
-      if (anOriginShape.IsNull())
+      Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
+      anObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
+      if (anObject.IsNull())
       {
-        std::cout << "Shape " << anOriginShapeName << " is used for non AIS viewer\n!";
-        return 1; // TCL_ERROR
+        std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
+        continue;
       }
     }
     else
     {
-      Standard_CString aName = anOriginShapeName.ToCString();
-      TopoDS_Shape aTDShape = DBRep::Get (aName);
+      Standard_CString aOriginName = anOriginObjectName.ToCString();
+      TopoDS_Shape aTDShape = DBRep::Get (aOriginName);
       if (aTDShape.IsNull())
       {
-        std::cout << "vconnectsh error: object " << anOriginShapeName << " doesn't exist\n";
-        return 1; // TCL_ERROR
-      }
-      anOriginShape = new AIS_Shape (aTDShape);
-      if (hasColor)
-      {
-        anOriginShape->SetColor (ViewerTest::GetColorFromName (aColorName));
-      }
-    }
-  }
-  // AIS_MultipleConnectedShape
-  else
-  {
-    const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc;
-    for (Standard_Integer i = 11; i < aNbShapes; ++i)
-    {
-      TCollection_AsciiString anOriginShapeName (argv[i]);
-      if (aName.IsEqual (anOriginShapeName))
-      {
-        std::cout << "vconnectsh error: equal names for connected shapes\n";
+        std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
         continue;
       }
-      if (GetMapOfAIS().IsBound2 (anOriginShapeName))
-      {
-        Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginShapeName);
-        aShape = Handle(AIS_Shape)::DownCast(anObj);
-        if (aShape.IsNull())
-        {
-          std::cout << "Shape " << anOriginShapeName << " is used for non AIS viewer\n";
-          continue;
-        }
-      }
-      else
-      {
-        Standard_CString aName = anOriginShapeName.ToCString();
-        TopoDS_Shape aTDShape = DBRep::Get (aName);
-        if (aTDShape.IsNull())
-        {
-          std::cout << "vconnectsh error: object " << anOriginShapeName << " doesn't exist\n";
-          continue;
-        }
-        aShape = new AIS_Shape (aTDShape);
-        if (hasColor)
-        {
-          aShape->SetColor (ViewerTest::GetColorFromName (aColorName));
-        }
-      }
-      if (anOriginShape.IsNull())
-      {
-        anOriginShape = new AIS_MultipleConnectedShape (aShape->Shape());
-        Handle(AIS_MultipleConnectedShape)::DownCast(anOriginShape)->Connect (aShape);
-      }
-      else
-      {
-        Handle(AIS_MultipleConnectedShape)::DownCast(anOriginShape)->Connect (aShape);
-      }
+      anObject = new AIS_Shape (aTDShape);
+      aContext->Load (anObject);
+      anObject->SetColor (ViewerTest::GetColorFromName (aColorName));
     }
-    if (anOriginShape.IsNull())
+
+    if (anOriginObject.IsNull())
     {
-      std::cout << "vconectsh error : can't connect input objects\n";
-      return 1; // TCL_ERROR
+      anOriginObject = new AIS_MultipleConnectedInteractive();
     }
+
+    anOriginObject->Connect (anObject);
+  }
+  if (anOriginObject.IsNull())
+  {
+    std::cout << "vconect error : can't connect input objects\n";
+    return 1; // TCL_ERROR
   }
 
-  // Get location data  
+  // Get location data
   Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
   Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
   Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
-  Standard_Real aXu = Draw::Atof (argv[anArgIter++]);
-  Standard_Real aXv = Draw::Atof (argv[anArgIter++]);
-  Standard_Real aXw = Draw::Atof (argv[anArgIter++]);
-  Standard_Real aZu = Draw::Atof (argv[anArgIter++]);
-  Standard_Real aZv = Draw::Atof (argv[anArgIter++]);
-  Standard_Real aZw = Draw::Atof (argv[anArgIter++]);
 
   // Create transformation
-  gp_Pnt aPoint(aXo, aYo, aZo);
-  gp_Dir anXDir(aXu, aXv, aXw), aZDir(aZu, aZv, aZw);
-  if(!anXDir.IsNormal(aZDir, Precision::Angular()))
-  {
-    std::cout << "vconnectsh error : XDir expects to be normal to ZDir\n"; 
-    return 1; // TCL_ERROR
-  } 
-  gp_Ax3 anAx3(aPoint, aZDir, anXDir); 
+  gp_Vec aTranslation (aXo, aYo, aZo);
+
   gp_Trsf aTrsf; 
-  aTrsf.SetTransformation(anAx3); 
-  TopLoc_Location aLocation(aTrsf);
+  aTrsf.SetTranslationPart (aTranslation);
+  TopLoc_Location aLocation (aTrsf);
 
-  // Create connected shape
-  Handle(AIS_ConnectedInteractive) aConnected;
-  Handle(AIS_Shape) anOrigin = Handle(AIS_Shape)::DownCast(anOriginShape);
-  if (!anOrigin.IsNull())
-  {
-    aConnected = new AIS_ConnectedShape (anOrigin);
-    aConnected->Connect (anOrigin, aLocation);
-  }
-  else
-  {
-    aConnected = new AIS_ConnectedInteractive();
-    aConnected->Connect (anOriginShape, aLocation);
-  }
+  anOriginObject->SetLocalTransformation (aTrsf);
 
   // Check if there is another object with given name
   // and remove it from context
@@ -3850,195 +3714,542 @@ static Standard_Integer VConnectShape(Draw_Interpretor& di,
     GetMapOfAIS().UnBind2(aName);
   }
 
-  // Bind connected shape to its name
-  GetMapOfAIS().Bind (aConnected, aName);
+  // Bind connected object to its name
+  GetMapOfAIS().Bind (anOriginObject, aName);
 
-  // Display connected shape
-  TheAISContext()->Display (aConnected);
+  // Display connected object
+  TheAISContext()->Display (anOriginObject, Standard_True);
 
   return 0;
 }
 
 //===============================================================================================
-//function : VSetSelectionMode
-//purpose  : Sets input selection mode for input object or for all displayed objects 
-//Draw arg : vselmode [object] mode On/Off (1/0)
+//function : VConnectTo
+//purpose  : Creates and displays AIS_ConnectedInteractive object from input object and location 
+//Draw arg : vconnectto name Xo Yo Zo object [-nodisplay|-noupdate|-update]
 //===============================================================================================
 
-// function : InList 
-// purpose  : checks if theMode is already turned on for theObj
-Standard_Boolean InList(Handle(AIS_InteractiveContext) theAISContext, 
-                          Handle(AIS_InteractiveObject) theObj, 
-                          Standard_Integer theMode)
+static Standard_Integer VConnectTo (Draw_Interpretor& /*di*/, 
+                                    Standard_Integer argc, 
+                                    const char ** argv) 
 {
-  TColStd_ListOfInteger anArray; 
-  theAISContext->ActivatedModes(theObj, anArray);
-  TColStd_ListIteratorOfListOfInteger anIt(anArray);
-  for(; anIt.More(); anIt.Next())
+  // Check the viewer
+  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
+  ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
+  if (aContext.IsNull())
   {
-    if(anIt.Value() == theMode) 
-      return Standard_True;
+    std::cout << "vconnect error : call vinit before\n";
+    return 1; // TCL_ERROR
   }
-  return Standard_False;
-}
-
-static Standard_Integer VSetSelectionMode(Draw_Interpretor& di, 
-                                          Standard_Integer argc, 
-                                          const char ** argv)
-{
-  // Check errors
-  Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
-  if(anAISContext.IsNull())
+  // Check argumnets 
+  if (argc != 6 && argc != 7)
   {
-    std::cout << "Call vinit before!\n";
+    std::cout << "vconnect error: expect at least 5 arguments\n";
     return 1; // TCL_ERROR
   }
 
-  // Check the arguments 
-  if(argc != 3 && argc != 4)
+  // Get values
+  Standard_Integer anArgIter = 1;
+  TCollection_AsciiString aName (argv[anArgIter++]);
+  Handle(AIS_InteractiveObject) anOriginObject;
+
+  TCollection_AsciiString anOriginObjectName(argv[5]);
+  if (aName.IsEqual (anOriginObjectName))
   {
-    std::cout << "vselmode error : expects at least 2 arguments\n"; 
+    std::cout << "vconnect error: equal names for connected objects\n"; 
     return 1; // TCL_ERROR
   }
+  if (GetMapOfAIS().IsBound2 (anOriginObjectName))
+  {
+    Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName);
+    anOriginObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
+    if (anOriginObject.IsNull())
+    {
+      std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n";
+      return 1; // TCL_ERROR
+    }
+  }
+  else
+  {
+    Standard_CString aOriginName = anOriginObjectName.ToCString();
+    TopoDS_Shape aTDShape = DBRep::Get (aOriginName);
+    if (aTDShape.IsNull())
+    {
+      std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n";
+      return 1; // TCL_ERROR
+    }
+    anOriginObject = new AIS_Shape (aTDShape);
+    GetMapOfAIS().Bind (anOriginObject, anOriginObjectName);
+  }
+  // Get location data
+  Standard_Real aXo = Draw::Atof (argv[anArgIter++]);
+  Standard_Real aYo = Draw::Atof (argv[anArgIter++]);
+  Standard_Real aZo = Draw::Atof (argv[anArgIter++]);
 
-  Handle(AIS_InteractiveObject) anObj;
+  // Create transformation
+  gp_Vec aTranslation (aXo, aYo, aZo);
+
+  gp_Trsf aTrsf; 
+  aTrsf.SetTranslationPart (aTranslation);
+  Handle(AIS_ConnectedInteractive) aConnected;
 
-  // Set new selection mode for all objects in context
-  if(argc == 3)
+  aConnected = new AIS_ConnectedInteractive();
+
+  aConnected->Connect (anOriginObject, aTrsf);
+
+  // Check if there is another object with given name
+  // and remove it from context
+  if(GetMapOfAIS().IsBound2(aName))
   {
-    // Get arguments 
-    Standard_Integer aMode = Draw::Atoi(argv[1]);
-    Standard_Boolean isTurnOn = Draw::Atoi(argv[2]); 
+    Handle(AIS_InteractiveObject) anObj = 
+      Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
+    TheAISContext()->Remove(anObj, Standard_False);
+    GetMapOfAIS().UnBind2(aName);
+  }
 
-    // Get all displayed objects
-    AIS_ListOfInteractive anObjList;
-    anAISContext->DisplayedObjects(anObjList);
-    AIS_ListIteratorOfListOfInteractive anObjIter;
+  // Bind connected object to its name
+  GetMapOfAIS().Bind (aConnected, aName);
 
-    if(aMode == 0)
-    {
-      if(anAISContext->HasOpenedContext())
-        anAISContext->CloseLocalContext();
-    }
+  if (argc == 7)
+  {
+    TCollection_AsciiString anArg = argv[6];
+    anArg.LowerCase();
+    if (anArg == "-nodisplay")
+      return 0;
 
-    // Turn on aMode
-    if(aMode != 0 && isTurnOn)
+    if (!anUpdateTool.parseRedrawMode (anArg))
     {
-      if(!anAISContext->HasOpenedContext())
-      {
-        anAISContext->OpenLocalContext(); 
-        for(anObjIter.Initialize(anObjList); anObjIter.More(); anObjIter.Next())
-        {
-          anAISContext->Activate(anObjIter.Value(), aMode); 
-        }
-      }
-      else
-      {
-        for(anObjIter.Initialize(anObjList); anObjIter.More(); anObjIter.Next())
-        {
-          anObj = anObjIter.Value();
-          if(!InList(anAISContext, anObj, aMode))
-            anAISContext->Activate(anObj, aMode);
-        }
-      }
+      std::cout << "Warning! Unknown argument '" << anArg << "' passed, -nodisplay|-noupdate|-update expected at this point.\n";
     }
+  }
+
+  // Display connected object
+  TheAISContext()->Display (aConnected, Standard_False);
+
+  return 0;
+}
+
+//=======================================================================
+//function : VDisconnect
+//purpose  :
+//=======================================================================
+static Standard_Integer VDisconnect (Draw_Interpretor& di,
+                                     Standard_Integer argc,
+                                     const char ** argv)
+{
+  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
+  if (aContext.IsNull())
+  {
+    std::cout << argv[0] << "ERROR : use 'vinit' command before \n";
+    return 1;
+  }
+  
+  if (argc != 3)
+  {
+    std::cout << "ERROR : Usage : " << argv[0] << " name object\n";
+    return 1;
+  }
+
+  TCollection_AsciiString aName (argv[1]);
+  TCollection_AsciiString anObject (argv[2]);
+  Standard_Integer anObjectNumber = Draw::Atoi (argv[2]);
+
+  // find objects
+  ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
+  Handle(AIS_MultipleConnectedInteractive) anAssembly;
+  if (!aMap.IsBound2 (aName) )
+  {
+    std::cout << "Use 'vdisplay' before\n";
+    return 1;
+  }
+
+  anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
+  if (anAssembly.IsNull())
+  {
+    di << "Not an assembly\n";
+    return 1;
+  }
 
-    // Turn off aMode
-    if(aMode != 0 && !isTurnOn)
+  Handle(AIS_InteractiveObject) anIObj;
+  if (!aMap.IsBound2 (anObject))
+  {
+    // try to interpret second argument as child number
+    if (anObjectNumber > 0 && anObjectNumber <= anAssembly->Children().Size())
     {
-      if(anAISContext->HasOpenedContext())
+      Standard_Integer aCounter = 1;
+      for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
       {
-        for(anObjIter.Initialize(anObjList); anObjIter.More(); anObjIter.Next())
+        if (aCounter == anObjectNumber)
         {
-          anObj = anObjIter.Value();
-          if(InList(anAISContext, anObj, aMode))
-            anAISContext->Deactivate(anObj, aMode);
+          anIObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
+          break;
         }
+        ++aCounter;
       }
     }
+    else
+    {
+      std::cout << "Use 'vdisplay' before\n";
+      return 1;
+    }    
   }
 
-  // Set new selection mode for named object 
-  else
+  // if object was found by name
+  if (anIObj.IsNull())
   {
-    // Get argumnets 
-    Standard_Integer aMode = Draw::Atoi(argv[2]);
-    Standard_Boolean isTurnOn = Draw::Atoi(argv[3]);
-    TCollection_AsciiString aName(argv[1]); 
+    anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject));
+  }
 
-    // Check if there is an object with given name in context
-    if(GetMapOfAIS().IsBound2(aName))
-    {
-      anObj = Handle(AIS_InteractiveObject)::
-        DownCast(GetMapOfAIS().Find2(aName));
-      if(anObj.IsNull())
-      {
-        std::cout << "vselmode error : object name is used for non AIS viewer\n"; 
-        return 1; // TCL_ERROR
-      }
-    }
+  aContext->Disconnect (anAssembly, anIObj);
+  aContext->UpdateCurrentViewer();
 
-    if(aMode == 0)
-    {
-      if(anAISContext->HasOpenedContext())
-        anAISContext->CloseLocalContext();
-    }
-    // Turn on aMode
-    if(aMode != 0 && isTurnOn) 
-    {
-      if(!anAISContext->HasOpenedContext())
-      {
-        anAISContext->OpenLocalContext(); 
-        anAISContext->Activate(anObj, aMode);
+  return 0;
+}
+
+//=======================================================================
+//function : VAddConnected
+//purpose  :
+//=======================================================================
+static Standard_Integer VAddConnected (Draw_Interpretor& di,
+                                       Standard_Integer argc,
+                                       const char ** argv)
+{
+  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
+  if (aContext.IsNull())
+  {
+    std::cout << argv[0] << "error : use 'vinit' command before \n";
+    return 1;
+  }
+  
+  if (argc != 6)
+  {
+    std::cout << argv[0] << " error: expect 5 arguments\n";
+    return 1;
+  }
+
+  TCollection_AsciiString aName (argv[1]);
+  TCollection_AsciiString anObject (argv[5]);
+  Standard_Real aX = Draw::Atof (argv[2]);
+  Standard_Real aY = Draw::Atof (argv[3]);
+  Standard_Real aZ = Draw::Atof (argv[4]);
+
+  // find object
+  ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
+  Handle(AIS_MultipleConnectedInteractive) anAssembly;
+  if (!aMap.IsBound2 (aName) )
+  {
+    std::cout << "Use 'vdisplay' before\n";
+    return 1;
+  }
+
+  anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
+  if (anAssembly.IsNull())
+  {
+    di << "Not an assembly\n";
+    return 1;
+  }
+
+  Handle(AIS_InteractiveObject) anIObj;
+  if (!aMap.IsBound2 (anObject))
+  {
+      std::cout << "Use 'vdisplay' before\n";
+      return 1; 
+  }
+
+  anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject));
+
+  gp_Trsf aTrsf;
+  aTrsf.SetTranslation (gp_Vec (aX, aY, aZ));
+  anAssembly->Connect (anIObj, aTrsf);
+  TheAISContext()->Display (anAssembly, Standard_False);
+  TheAISContext()->RecomputeSelectionOnly (anAssembly);
+  aContext->UpdateCurrentViewer();
+
+  return 0;
+}
+
+//=======================================================================
+//function : VListConnected
+//purpose  :
+//=======================================================================
+static Standard_Integer VListConnected (Draw_Interpretor& /*di*/,
+                                        Standard_Integer argc,
+                                        const char ** argv)
+{
+  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
+  if (aContext.IsNull())
+  {
+    std::cout << argv[0] << "ERROR : use 'vinit' command before \n";
+    return 1;
+  }
+  
+  if (argc != 2)
+  {
+    std::cout << "ERROR : Usage : " << argv[0] << " name\n";
+    return 1;
+  }
+
+  TCollection_AsciiString aName (argv[1]);
+
+  // find object
+  ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
+  Handle(AIS_MultipleConnectedInteractive) anAssembly;
+  if (!aMap.IsBound2 (aName) )
+  {
+    std::cout << "Use 'vdisplay' before\n";
+    return 1;
+  }
+
+  anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName));
+  if (anAssembly.IsNull())
+  {
+    std::cout << "Not an assembly\n";
+    return 1;
+  }
+
+  std::cout << "Children of " << aName << ":\n";
+
+  Standard_Integer aCounter = 1;
+  for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next())
+  {
+    if (GetMapOfAIS().IsBound1 (anIter.Value()))
+    {
+      TCollection_AsciiString aCuurrentName = GetMapOfAIS().Find1 (anIter.Value());
+      std::cout << aCounter << ")  " << aCuurrentName << "    (" << anIter.Value()->DynamicType()->Name() << ")";
+    }
+
+    std::cout << aCounter << ")  " << anIter.Value()->DynamicType()->Name();
+
+    Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (anIter.Value());
+    if (!aConnected.IsNull() && !aConnected->ConnectedTo().IsNull() && aMap.IsBound1 (aConnected->ConnectedTo()))
+    {
+      std::cout << " connected to " << aMap.Find1 (aConnected->ConnectedTo());
+    }
+    std::cout << std::endl;
+    
+    ++aCounter;
+  }
+
+  return 0;
+}
+
+namespace
+{
+  //! Checks if theMode is already turned on for theObj.
+  static Standard_Boolean InList (const Handle(AIS_InteractiveContext)& theAISContext,
+                                  const Handle(AIS_InteractiveObject)&  theObj,
+                                  const Standard_Integer                theMode)
+  {
+    TColStd_ListOfInteger anActiveModes;
+    theAISContext->ActivatedModes (theObj, anActiveModes);
+    for (TColStd_ListIteratorOfListOfInteger aModeIt (anActiveModes); aModeIt.More(); aModeIt.Next())
+    {
+      if (aModeIt.Value() == theMode)
+      {
+        return Standard_True;
       }
-      else
+    }
+    return Standard_False;
+  }
+}
+
+//===============================================================================================
+//function : VSetSelectionMode
+//purpose  : Sets input selection mode for input object or for all displayed objects 
+//Draw arg : vselmode [object] mode On/Off (1/0)
+//===============================================================================================
+static Standard_Integer VSetSelectionMode (Draw_Interpretor& /*di*/,
+                                           Standard_Integer  theArgc,
+                                           const char**      theArgv)
+{
+  // Check errors
+  Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
+  if (anAISContext.IsNull())
+  {
+    std::cerr << "Call vinit before!" << std::endl;
+    return 1;
+  }
+
+  // Check the arguments
+  if (theArgc < 3 && theArgc > 5)
+  {
+    std::cerr << "vselmode error : expects at least 2 arguments.\n"
+              << "Type help "<< theArgv[0] <<" for more information." << std::endl;
+    return 1;
+  }
+
+  TCollection_AsciiString aLastArg (theArgv[theArgc - 1]);
+  aLastArg.LowerCase();
+  Standard_Boolean isToOpenLocalCtx = aLastArg == "-local";
+
+  // get objects to change selection mode
+  AIS_ListOfInteractive aTargetIOs;
+  Standard_Integer anArgNb = isToOpenLocalCtx ? theArgc - 1 : theArgc;
+  if (anArgNb == 3)
+  {
+    anAISContext->DisplayedObjects (aTargetIOs);
+  }
+  else
+  {
+    // Check if there is an object with given name in context
+    const TCollection_AsciiString aNameIO (theArgv[1]);
+    if (GetMapOfAIS().IsBound2 (aNameIO))
+    {
+      Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aNameIO));
+      if (anIO.IsNull())
       {
-        if(!InList(anAISContext, anObj, aMode))
-          anAISContext->Activate(anObj, aMode);
+        std::cerr << "vselmode error : object name is used for non AIS viewer" << std::endl;
+        return 1;
       }
+      aTargetIOs.Append (anIO);
     }
+  }
+
+  const Standard_Integer aSelectionMode = Draw::Atoi (anArgNb == 3 ? theArgv[1] : theArgv[2]);
+  const Standard_Boolean toTurnOn       = Draw::Atoi (anArgNb == 3 ? theArgv[2] : theArgv[3]) != 0;
+  Standard_DISABLE_DEPRECATION_WARNINGS
+  if (aSelectionMode == 0 && anAISContext->HasOpenedContext())
+  {
+    anAISContext->CloseLocalContext();
+  }
+  Standard_ENABLE_DEPRECATION_WARNINGS
 
-    // Turn off aMode
-    if(aMode != 0 && !isTurnOn)
+  if (aSelectionMode == 0)
+  {
+    if (toTurnOn)
+    {
+      for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
+      {
+        const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
+        TColStd_ListOfInteger anActiveModes;
+        anAISContext->ActivatedModes (anIO, anActiveModes);
+        if (!anActiveModes.IsEmpty())
+        {
+          anAISContext->Deactivate (anIO);
+        }
+        if (!InList (anAISContext, anIO, aSelectionMode))
+        {
+          anAISContext->Activate (anIO);
+        }
+      }
+    }
+    else
     {
-      if(anAISContext->HasOpenedContext())
+      for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
       {
-        if(InList(anAISContext, anObj, aMode))
-          anAISContext->Deactivate(anObj, aMode);
+        const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
+        if (InList (anAISContext, anIO, aSelectionMode))
+        {
+          anAISContext->Deactivate (anIO);
+        }
       }
     }
   }
+
+  if (aSelectionMode != 0 && toTurnOn) // Turn on specified mode
+  {
+    Standard_DISABLE_DEPRECATION_WARNINGS
+    if (!anAISContext->HasOpenedContext() && isToOpenLocalCtx)
+    {
+      anAISContext->OpenLocalContext (Standard_False);
+    }
+    Standard_ENABLE_DEPRECATION_WARNINGS
+
+    for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
+    {
+      const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value();
+      anAISContext->Deactivate (anIO, 0);
+      anAISContext->Load (anIO, -1, Standard_True);
+      anAISContext->Activate (anIO, aSelectionMode);
+    }
+  }
+
+  if (aSelectionMode != 0 && !toTurnOn) // Turn off specified mode
+  {
+    for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next())
+    {
+      anAISContext->Deactivate (aSelectionMode);
+    }
+  }
+
+  return 0;
+}
+
+//===============================================================================================
+//function : VSelectionNext
+//purpose  : 
+//===============================================================================================
+static Standard_Integer VSelectionNext(Draw_Interpretor& /*theDI*/,
+                                 Standard_Integer /*theArgsNb*/,
+                                 const char** /*theArgVec*/)
+{
+  // Check errors
+  Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
+  Handle(V3d_View) aView = ViewerTest::CurrentView();
+
+  if (anAISContext.IsNull())
+  {
+    std::cerr << "Call vinit before!" << std::endl;
+    return 1;
+  }
+
+  anAISContext->HilightNextDetected (aView);
+  return 0;
+}
+
+//===============================================================================================
+//function : VSelectionPrevious
+//purpose  : 
+//===============================================================================================
+static Standard_Integer VSelectionPrevious(Draw_Interpretor& /*theDI*/,
+                                 Standard_Integer /*theArgsNb*/,
+                                 const char** /*theArgVec*/)
+{
+  // Check errors
+  Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
+  Handle(V3d_View) aView = ViewerTest::CurrentView();
+
+  if (anAISContext.IsNull())
+  {
+    std::cerr << "Call vinit before!" << std::endl;
+    return 1;
+  }
+
+  anAISContext->HilightPreviousDetected (aView);
   return 0;
 }
 
+
 //==========================================================================
 //class   : Triangle 
 //purpose : creates Triangle based on AIS_InteractiveObject. 
 //          This class was implemented for testing Select3D_SensitiveTriangle
 //===========================================================================
-DEFINE_STANDARD_HANDLE(Triangle, AIS_InteractiveObject)
+
 class Triangle: public AIS_InteractiveObject 
 {
 public: 
   // CASCADE RTTI
-  DEFINE_STANDARD_RTTI(FilledCircle); 
+  DEFINE_STANDARD_RTTI_INLINE(Triangle,AIS_InteractiveObject);
   Triangle (const gp_Pnt& theP1, 
             const gp_Pnt& theP2, 
             const gp_Pnt& theP3);
 protected:
   void Compute (  const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
                   const Handle(Prs3d_Presentation)& thePresentation,
-                  const Standard_Integer theMode);
+                  const Standard_Integer theMode) Standard_OVERRIDE;
 
   void ComputeSelection (  const Handle(SelectMgr_Selection)& theSelection, 
-                           const Standard_Integer theMode);
+                           const Standard_Integer theMode) Standard_OVERRIDE;
 private: 
   gp_Pnt myPoint1;
   gp_Pnt myPoint2;
   gp_Pnt myPoint3;
 };
-IMPLEMENT_STANDARD_HANDLE(Triangle, AIS_InteractiveObject)
-IMPLEMENT_STANDARD_RTTIEXT(Triangle, AIS_InteractiveObject)
+
 
 Triangle::Triangle (const gp_Pnt& theP1,
                     const gp_Pnt& theP2,
@@ -4049,9 +4260,9 @@ Triangle::Triangle (const gp_Pnt& theP1,
   myPoint3 = theP3;
 }
 
-void Triangle::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+void Triangle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
                        const Handle(Prs3d_Presentation)& thePresentation,
-                       const Standard_Integer theMode)
+                       const Standard_Integer /*theMode*/)
 {
   thePresentation->Clear();
 
@@ -4077,7 +4288,7 @@ void Triangle::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentati
 }
 
 void Triangle::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection, 
-                                const Standard_Integer theMode)
+                                const Standard_Integer /*theMode*/)
 {
   Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
   Handle(Select3D_SensitiveTriangle) aSensTriangle = 
@@ -4125,7 +4336,7 @@ Standard_Boolean IsMatch (const Handle(Geom_CartesianPoint)& thePoint1,
   return Standard_False;
 }
 
-static Standard_Integer VTriangle (Draw_Interpretor& di,
+static Standard_Integer VTriangle (Draw_Interpretor& /*di*/,
                                    Standard_Integer argc,
                                    const char ** argv)
 {
@@ -4136,8 +4347,6 @@ static Standard_Integer VTriangle (Draw_Interpretor& di,
     return 1; // TCL_ERROR
   }
 
-  TheAISContext()->CloseAllContexts();
-
   // Get and check values
   TCollection_AsciiString aName(argv[1]);
 
@@ -4204,33 +4413,32 @@ static Standard_Integer VTriangle (Draw_Interpretor& di,
   GetMapOfAIS().Bind(aTriangle, aName);
 
   // Display triangle
-  TheAISContext()->Display(aTriangle);
+  TheAISContext()->Display (aTriangle, Standard_True);
   return 0;
 }
 
 //class  : SegmentObject
 //purpose: creates segment based on AIS_InteractiveObject.
 //         This class was implemented for testing Select3D_SensitiveCurve
-DEFINE_STANDARD_HANDLE(SegmentObject, AIS_InteractiveObject)
+
 class SegmentObject: public AIS_InteractiveObject
 {
 public:
   // CASCADE RTTI
-  DEFINE_STANDARD_RTTI(SegmentObject); 
+  DEFINE_STANDARD_RTTI_INLINE(SegmentObject,AIS_InteractiveObject); 
   SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2);
 protected:
   void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
                 const Handle(Prs3d_Presentation)& thePresentation,
-                const Standard_Integer theMode);
+                const Standard_Integer theMode) Standard_OVERRIDE;
 
   void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, 
-                         const Standard_Integer theMode);
+                         const Standard_Integer theMode) Standard_OVERRIDE;
 private:
   gp_Pnt myPoint1;
   gp_Pnt myPoint2;
 };
-IMPLEMENT_STANDARD_HANDLE(SegmentObject, AIS_InteractiveObject)
-IMPLEMENT_STANDARD_RTTIEXT(SegmentObject, AIS_InteractiveObject)
+
 
 SegmentObject::SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2)
 {
@@ -4238,9 +4446,9 @@ SegmentObject::SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2)
   myPoint2 = thePnt2;
 }
 
-void SegmentObject::Compute (const Handle_PrsMgr_PresentationManager3d &thePresentationManager,
-                             const Handle_Prs3d_Presentation &thePresentation,
-                             const Standard_Integer theMode)
+void SegmentObject::Compute (const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
+                             const Handle(Prs3d_Presentation) &thePresentation,
+                             const Standard_Integer /*theMode*/)
 {
   thePresentation->Clear();
   BRepBuilderAPI_MakeEdge anEdgeMaker(myPoint1, myPoint2);
@@ -4251,8 +4459,8 @@ void SegmentObject::Compute (const Handle_PrsMgr_PresentationManager3d &thePrese
   StdPrs_Curve::Add(thePresentation, aCurveAdaptor, myDrawer);
 }
 
-void SegmentObject::ComputeSelection (const Handle_SelectMgr_Selection &theSelection,
-                                      const Standard_Integer theMode)
+void SegmentObject::ComputeSelection (const Handle(SelectMgr_Selection) &theSelection,
+                                      const Standard_Integer /*theMode*/)
 {
   Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner(this);
   Handle(TColgp_HArray1OfPnt) anArray = new TColgp_HArray1OfPnt(1, 2);
@@ -4268,7 +4476,7 @@ void SegmentObject::ComputeSelection (const Handle_SelectMgr_Selection &theSelec
 //Draw args : vsegment Name PointName PointName
 //purpose   : creates and displays Segment
 //=======================================================================
-static Standard_Integer VSegment (Draw_Interpretor& di,
+static Standard_Integer VSegment (Draw_Interpretor& /*di*/,
                                   Standard_Integer argc,
                                   const char ** argv)
 {
@@ -4279,8 +4487,6 @@ static Standard_Integer VSegment (Draw_Interpretor& di,
     return 1; // TCL_ERROR
   }
 
-  TheAISContext()->CloseAllContexts();
-
   // Get and check arguments
   TCollection_AsciiString aName(argv[1]);
   Handle(AIS_Point) aPoint1, aPoint2;
@@ -4322,7 +4528,7 @@ static Standard_Integer VSegment (Draw_Interpretor& di,
   GetMapOfAIS().Bind(aSegment, aName);
 
   // Display segment
-  TheAISContext()->Display(aSegment);
+  TheAISContext()->Display (aSegment, Standard_True);
   return 0;
 }
 
@@ -4363,7 +4569,7 @@ static Standard_Integer VObjZLayer (Draw_Interpretor& di,
   ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
   if (!aMap.IsBound2 (aName))
   {
-    di << "Use 'vdisplay' before" << "\n";
+    di << "Use 'vdisplay' before\n";
     return 1;
   }
 
@@ -4377,216 +4583,1354 @@ static Standard_Integer VObjZLayer (Draw_Interpretor& di,
     return 1;
   }
 
-  // process operation
-  if (aOperation.IsEqual ("set"))
+  // process operation
+  if (aOperation.IsEqual ("set"))
+  {
+    Standard_Integer aLayerId = Draw::Atoi (argv [3]);
+    aContext->SetZLayer (anInterObj, aLayerId);
+  }
+  else if (aOperation.IsEqual ("get"))
+  {
+    di << "Z layer id: " << aContext->GetZLayer (anInterObj);
+  }
+  
+  return 0;
+}
+
+//=======================================================================
+//function : VPolygonOffset
+//purpose  : Set or get polygon offset parameters
+//=======================================================================
+static Standard_Integer VPolygonOffset(Draw_Interpretor& /*di*/,
+                                       Standard_Integer argc,
+                                       const char ** argv)
+{
+  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
+  if (aContext.IsNull())
+  {
+    std::cout << argv[0] << " Call 'vinit' before!\n";
+    return 1;
+  }
+
+  if (argc > 2 && argc != 5)
+  {
+    std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object,"
+      "without arguments prints the default values" << std::endl;
+    return 1;
+  }
+
+  // find object
+  Handle(AIS_InteractiveObject) anInterObj;
+  if (argc >= 2)
+  {
+    TCollection_AsciiString aName (argv[1]);
+    ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
+    if (!aMap.IsBound2 (aName))
+    {
+      std::cout << "Use 'vdisplay' before" << std::endl;
+      return 1;
+    }
+
+    // find interactive object
+    Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
+    anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
+    if (anInterObj.IsNull())
+    {
+      std::cout << "Not an AIS interactive object!" << std::endl;
+      return 1;
+    }
+  }
+
+  Standard_Integer aMode;
+  Standard_ShortReal    aFactor, aUnits;
+  if (argc == 5)
+  {
+    aMode   = Draw::Atoi(argv[2]);
+    aFactor = (Standard_ShortReal) Draw::Atof(argv[3]);
+    aUnits  = (Standard_ShortReal) Draw::Atof(argv[4]);
+
+    anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits);
+    aContext->UpdateCurrentViewer();
+    return 0;
+  }
+  else if (argc == 2)
+  {
+    if (anInterObj->HasPolygonOffsets())
+    {
+      anInterObj->PolygonOffsets(aMode, aFactor, aUnits);
+      std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl;
+      std::cout << "\tMode: "   << aMode   << std::endl;
+      std::cout << "\tFactor: " << aFactor << std::endl;
+      std::cout << "\tUnits: "  << aUnits  << std::endl;
+      return 0;
+    }
+    else
+    {
+      std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl;
+    }
+  }
+
+  std::cout << "Default polygon offset parameters:" << std::endl;
+  aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits);
+  std::cout << "\tMode: "   << aMode   << std::endl;
+  std::cout << "\tFactor: " << aFactor << std::endl;
+  std::cout << "\tUnits: "  << aUnits  << std::endl;
+
+  return 0;
+}
+
+//=======================================================================
+//function : VShowFaceBoundaries
+//purpose  : Set face boundaries drawing on/off for ais object
+//=======================================================================
+static Standard_Integer VShowFaceBoundary (Draw_Interpretor& /*di*/,
+                                           Standard_Integer argc,
+                                           const char ** argv)
+{
+  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext ();
+  if (aContext.IsNull ())
+  {
+    std::cout << argv[0] << " Call 'vinit' before!\n";
+    return 1;
+  }
+
+  if ((argc != 3 && argc < 6) || argc > 8)
+  {
+    std::cout << "Usage :\n " << argv[0]
+              << " ObjectName isOn [R G B [LineWidth [LineStyle]]]\n"
+              << "   ObjectName - name of AIS interactive object. \n"
+              << "                if ObjectName = \"\", then set as default\n"
+              << "                settings for all newly displayed objects\n"
+              << "   isOn       - flag indicating whether the boundaries\n"
+              << "                should be turned on or off (can be set\n"
+              << "                to 0 (off) or 1 (on)).\n"
+              << "   R, G, B    - red, green and blue components of boundary\n"
+              << "                color in range (0 - 255).\n"
+              << "                (default is (0, 0, 0)\n"
+              << "   LineWidth  - line width\n"
+              << "                (default is 1)\n"
+              << "   LineStyle  - line fill style :\n"
+              << "                 0 - solid  \n"
+              << "                 1 - dashed \n"
+              << "                 2 - dot    \n"
+              << "                 3 - dashdot\n"
+              << "                 (default is solid)";
+    return 1;
+  }
+
+  TCollection_AsciiString aName (argv[1]);
+
+  Quantity_Parameter aRed      = 0.0;
+  Quantity_Parameter aGreen    = 0.0;
+  Quantity_Parameter aBlue     = 0.0;
+  Standard_Real      aWidth    = 1.0;
+  Aspect_TypeOfLine  aLineType = Aspect_TOL_SOLID;
+  
+  // find object
+  Handle(AIS_InteractiveObject) anInterObj;
+
+  // if name is empty - apply attributes for default aspect
+  if (!aName.IsEmpty ())
+  {
+    ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS ();
+    if (!aMap.IsBound2 (aName))
+    {
+      std::cout << "Use 'vdisplay' on " << aName << " before" << std::endl;
+      return 1;
+    }
+
+    // find interactive object
+    Handle(Standard_Transient) anObj = GetMapOfAIS ().Find2 (aName);
+    anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
+    if (anInterObj.IsNull ())
+    {
+      std::cout << "Not an AIS interactive object!" << std::endl;
+      return 1;
+    }
+  }
+  
+  const Handle(Prs3d_Drawer)& aDrawer = (aName.IsEmpty ()) ?
+    TheAISContext ()->DefaultDrawer () : anInterObj->Attributes ();
+
+  // turn boundaries on/off
+  Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[2]) == 1);
+  aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
+  
+  // set boundary line color
+  if (argc >= 6)
+  {
+    // Text color
+    aRed   = Draw::Atof (argv[3])/255.;
+    aGreen = Draw::Atof (argv[4])/255.;
+    aBlue  = Draw::Atof (argv[5])/255.;
+  }
+
+  // set line width
+  if (argc >= 7)
+  {
+    aWidth = (Standard_Real)Draw::Atof (argv[6]);
+  }
+
+  // select appropriate line type
+  if (argc == 8)
+  {
+    if (!ViewerTest::ParseLineType (argv[7], aLineType))
+    {
+      std::cout << "Syntax error: unknown line type '" << argv[7] << "'\n";
+      return 1;
+    }
+  }
+
+  Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
+
+  Handle(Prs3d_LineAspect) aBoundaryAspect = 
+    new Prs3d_LineAspect (aColor, aLineType, aWidth);
+
+  aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
+
+  TheAISContext()->Redisplay (anInterObj, Standard_True);
+  
+  return 0;
+}
+
+// This class is used for testing markers.
+
+class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject
+{
+
+public:
+
+  ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint,
+                                 const Standard_Integer& thePointsOnSide,
+                                 Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
+  {
+    myStartPoint = theStartPoint;
+    myPointsOnSide = thePointsOnSide;
+    myMarkerAspect = theMarkerAspect;
+  }
+
+  DEFINE_STANDARD_RTTI_INLINE(ViewerTest_MarkersArrayObject,AIS_InteractiveObject);
+
+private:
+
+  void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
+                const Handle(Prs3d_Presentation)& aPresentation,
+                const Standard_Integer aMode) Standard_OVERRIDE;
+
+  void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
+                         const Standard_Integer /*theMode*/) Standard_OVERRIDE;
+
+protected:
+
+  gp_XYZ myStartPoint;
+  Standard_Integer myPointsOnSide;
+  Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
+};
+
+
+void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
+                              const Handle(Prs3d_Presentation)& aPresentation,
+                              const Standard_Integer /*aMode*/)
+{
+  Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1);
+  if (myPointsOnSide == 1)
+  {
+    anArray->AddVertex (myStartPoint);
+  }
+  else
+  {
+    for (Standard_Real i = 1; i <= myPointsOnSide; i++)
+    {
+      for (Standard_Real j = 1; j <= myPointsOnSide; j++)
+      {
+        for (Standard_Real k = 1; k <= myPointsOnSide; k++)
+        {
+          anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
+          anArray->SetVertexColor (anArray->VertexNumber(),
+                                   i / myPointsOnSide,
+                                   j / myPointsOnSide,
+                                   k / myPointsOnSide);
+        }
+      }
+    }
+  }
+
+  aPresentation->Clear();
+  if (!myMarkerAspect.IsNull())
+  {
+    Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
+  }
+  Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
+}
+
+void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
+                                       const Standard_Integer /*theMode*/)
+{
+  Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
+
+  if (myPointsOnSide == 1)
+  {
+    gp_Pnt aPoint (myStartPoint);
+    Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
+    theSelection->Add (aSensetivePoint);
+  }
+  else
+  {
+    for (Standard_Real i = 1; i <= myPointsOnSide; i++)
+    {
+      for (Standard_Real j = 1; j <= myPointsOnSide; j++)
+      {
+        for (Standard_Real k = 1; k <= myPointsOnSide; k++)
+        {
+          gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
+          Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
+          theSelection->Add (aSensetivePoint);
+        }
+      }
+    }
+  }
+}
+//=======================================================================
+//function : VMarkersTest
+//purpose  : Draws an array of markers for testing purposes.
+//=======================================================================
+static Standard_Integer VMarkersTest (Draw_Interpretor&,
+                                      Standard_Integer  theArgNb,
+                                      const char**      theArgVec)
+{
+  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
+  if (aContext.IsNull())
+  {
+    std::cerr << "Call 'vinit' before!\n";
+    return 1;
+  }
+
+  if (theArgNb < 5)
+  {
+    std::cerr << "Usage :\n " << theArgVec[0]
+              << "name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n";
+    return 1;
+  }
+
+  Standard_Integer anArgIter = 1;
+
+  TCollection_AsciiString aName (theArgVec[anArgIter++]);
+  TCollection_AsciiString aFileName;
+  gp_XYZ aPnt (Atof (theArgVec[anArgIter]),
+               Atof (theArgVec[anArgIter + 1]),
+               Atof (theArgVec[anArgIter + 2]));
+  anArgIter += 3;
+
+  Standard_Integer aPointsOnSide = 10;
+  Standard_Integer aMarkerType   = -1;
+  Standard_Real    aScale        = 1.0;
+  for (; anArgIter < theArgNb; ++anArgIter)
+  {
+    const TCollection_AsciiString anArg (theArgVec[anArgIter]);
+    if (anArg.Search ("PointsOnSide=") > -1)
+    {
+      aPointsOnSide = anArg.Token ("=", 2).IntegerValue();
+    }
+    else if (anArg.Search ("MarkerType=") > -1)
+    {
+      aMarkerType = anArg.Token ("=", 2).IntegerValue();
+    }
+    else if (anArg.Search ("Scale=") > -1)
+    {
+      aScale = anArg.Token ("=", 2).RealValue();
+    }
+    else if (anArg.Search ("FileName=") > -1)
+    {
+      aFileName = anArg.Token ("=", 2);
+    }
+    else
+    {
+      std::cerr << "Wrong argument: " << anArg << "\n";
+      return 1;
+    }
+  }
+
+  Handle(Graphic3d_AspectMarker3d) anAspect;
+  Handle(Image_AlienPixMap) anImage;
+  Quantity_Color aColor (Quantity_NOC_GREEN1);
+  if ((aMarkerType == Aspect_TOM_USERDEFINED || aMarkerType < 0)
+   && !aFileName.IsEmpty())
+  {
+    anImage = new Image_AlienPixMap();
+    if (!anImage->Load (aFileName))
+    {
+      std::cerr << "Could not load image from file '" << aFileName << "'!\n";
+      return 1;
+    }
+    if (anImage->Format() == Image_PixMap::ImgGray)
+    {
+      anImage->SetFormat (Image_PixMap::ImgAlpha);
+    }
+    else if (anImage->Format() == Image_PixMap::ImgGrayF)
+    {
+      anImage->SetFormat (Image_PixMap::ImgAlphaF);
+    }
+    anAspect = new Graphic3d_AspectMarker3d (anImage);
+  }
+  else
+  {
+    anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale);
+  }
+
+  Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect);
+  VDisplayAISObject (aName, aMarkersArray);
+
+  return 0;
+}
+
+//! Auxiliary function to parse font aspect style argument
+static Standard_Boolean parseFontStyle (const TCollection_AsciiString& theArg,
+                                        Font_FontAspect&               theAspect)
+{
+  if (theArg == "regular"
+   || *theArg.ToCString() == 'r')
+  {
+    theAspect = Font_FA_Regular;
+    return Standard_True;
+  }
+  else if (theArg == "bolditalic")
+  {
+    theAspect = Font_FA_BoldItalic;
+    return Standard_True;
+  }
+  else if (theArg == "bold"
+        || *theArg.ToCString() == 'b')
+  {
+    theAspect = Font_FA_Bold;
+    return Standard_True;
+  }
+  else if (theArg == "italic"
+        || *theArg.ToCString() == 'i')
+  {
+    theAspect = Font_FA_Italic;
+    return Standard_True;
+  }
+  return Standard_False;
+}
+
+//! Auxiliary function
+static TCollection_AsciiString fontStyleString (const Font_FontAspect theAspect)
+{
+  switch (theAspect)
+  {
+    case Font_FA_Regular:    return "regular";
+    case Font_FA_BoldItalic: return "bolditalic";
+    case Font_FA_Bold:       return "bold";
+    case Font_FA_Italic:     return "italic";
+    default:                 return "undefined";
+  }
+}
+
+//=======================================================================
+//function : TextToBrep
+//purpose  : Tool for conversion text to occt-shapes
+//=======================================================================
+static int TextToBRep (Draw_Interpretor& /*theDI*/,
+                       Standard_Integer  theArgNb,
+                       const char**      theArgVec)
+{
+  // Check arguments
+  if (theArgNb < 3)
+  {
+    std::cerr << "Error: " << theArgVec[0] << " - invalid syntax\n";
+    return 1;
+  }
+
+  Standard_Integer anArgIt = 1;
+  Standard_CString aName   = theArgVec[anArgIt++];
+  Standard_CString aText   = theArgVec[anArgIt++];
+
+  Font_BRepFont           aFont;
+  TCollection_AsciiString aFontName ("Courier");
+  Standard_Real           aTextHeight        = 16.0;
+  Font_FontAspect         aFontAspect        = Font_FA_Regular;
+  Standard_Boolean        anIsCompositeCurve = Standard_False;
+  gp_Ax3                  aPenAx3    (gp::XOY());
+  gp_Dir                  aNormal    (0.0, 0.0, 1.0);
+  gp_Dir                  aDirection (1.0, 0.0, 0.0);
+  gp_Pnt                  aPenLoc;
+
+  Graphic3d_HorizontalTextAlignment aHJustification = Graphic3d_HTA_LEFT;
+  Graphic3d_VerticalTextAlignment   aVJustification = Graphic3d_VTA_BOTTOM;
+
+  for (; anArgIt < theArgNb; ++anArgIt)
+  {
+    TCollection_AsciiString aParam (theArgVec[anArgIt]);
+    aParam.LowerCase();
+
+    if (aParam == "-pos"
+     || aParam == "-position")
+    {
+      if (anArgIt + 3 >= theArgNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+
+      aPenLoc.SetX (Draw::Atof(theArgVec[++anArgIt]));
+      aPenLoc.SetY (Draw::Atof(theArgVec[++anArgIt]));
+      aPenLoc.SetZ (Draw::Atof(theArgVec[++anArgIt]));
+    }
+    else if (aParam == "-halign")
+    {
+      if (++anArgIt >= theArgNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+
+      TCollection_AsciiString aType (theArgVec[anArgIt]);
+      aType.LowerCase();
+      if (aType == "left")
+      {
+        aHJustification = Graphic3d_HTA_LEFT;
+      }
+      else if (aType == "center")
+      {
+        aHJustification = Graphic3d_HTA_CENTER;
+      }
+      else if (aType == "right")
+      {
+        aHJustification = Graphic3d_HTA_RIGHT;
+      }
+      else
+      {
+        std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+    }
+    else if (aParam == "-valign")
+    {
+      if (++anArgIt >= theArgNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+
+      TCollection_AsciiString aType (theArgVec[anArgIt]);
+      aType.LowerCase();
+      if (aType == "top")
+      {
+        aVJustification = Graphic3d_VTA_TOP;
+      }
+      else if (aType == "center")
+      {
+        aVJustification = Graphic3d_VTA_CENTER;
+      }
+      else if (aType == "bottom")
+      {
+        aVJustification = Graphic3d_VTA_BOTTOM;
+      }
+      else if (aType == "topfirstline")
+      {
+        aVJustification = Graphic3d_VTA_TOPFIRSTLINE;
+      }
+      else
+      {
+        std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+    }
+    else if (aParam == "-height")
+    {
+      if (++anArgIt >= theArgNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+
+      aTextHeight = Draw::Atof(theArgVec[anArgIt]);
+    }
+    else if (aParam == "-aspect")
+    {
+      if (++anArgIt >= theArgNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+
+      TCollection_AsciiString anOption (theArgVec[anArgIt]);
+      anOption.LowerCase();
+
+      if (anOption.IsEqual ("regular"))
+      {
+        aFontAspect = Font_FA_Regular;
+      }
+      else if (anOption.IsEqual ("bold"))
+      {
+        aFontAspect = Font_FA_Bold;
+      }
+      else if (anOption.IsEqual ("italic"))
+      {
+        aFontAspect = Font_FA_Italic;
+      }
+      else if (anOption.IsEqual ("bolditalic"))
+      {
+        aFontAspect = Font_FA_BoldItalic;
+      }
+      else
+      {
+        std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+    }
+    else if (aParam == "-font")
+    {
+      if (++anArgIt >= theArgNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+
+      aFontName = theArgVec[anArgIt];
+    }
+    else if (aParam == "-composite")
+    {
+      if (++anArgIt >= theArgNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+
+      ViewerTest::ParseOnOff (theArgVec[anArgIt], anIsCompositeCurve);
+    }
+    else if (aParam == "-plane")
+    {
+      if (anArgIt + 6 >= theArgNb)
+      {
+        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+
+      Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]);
+      Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]);
+      Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]);
+      aNormal.SetCoord (aX, aY, aZ);
+
+      aX = Draw::Atof (theArgVec[++anArgIt]);
+      aY = Draw::Atof (theArgVec[++anArgIt]);
+      aZ = Draw::Atof (theArgVec[++anArgIt]);
+      aDirection.SetCoord (aX, aY, aZ);
+    }
+    else
+    {
+      std::cerr << "Warning! Unknown argument '" << aParam << "'\n";
+    }
+  }
+
+  aFont.SetCompositeCurveMode (anIsCompositeCurve);
+  if (!aFont.Init (aFontName.ToCString(), aFontAspect, aTextHeight))
+  {
+    std::cerr << "Font initialization error\n";
+    return 1;
+  }
+
+  aPenAx3 = gp_Ax3 (aPenLoc, aNormal, aDirection);
+
+  Font_BRepTextBuilder aBuilder;
+  DBRep::Set (aName, aBuilder.Perform (aFont, aText, aPenAx3, aHJustification, aVJustification));
+  return 0;
+}
+
+//=======================================================================
+//function : VFont
+//purpose  : Font management
+//=======================================================================
+
+static int VFont (Draw_Interpretor& theDI,
+                  Standard_Integer  theArgNb,
+                  const char**      theArgVec)
+{
+  Handle(Font_FontMgr) aMgr = Font_FontMgr::GetInstance();
+  if (theArgNb < 2)
+  {
+    // just print the list of available fonts
+    Standard_Boolean isFirst = Standard_True;
+    for (Font_NListOfSystemFont::Iterator anIter (aMgr->GetAvailableFonts());
+         anIter.More(); anIter.Next())
+    {
+      const Handle(Font_SystemFont)& aFont = anIter.Value();
+      if (!isFirst)
+      {
+        theDI << "\n";
+      }
+
+      theDI << aFont->FontName()->String()
+            << " " << fontStyleString (aFont->FontAspect())
+            << " " << aFont->FontPath()->String();
+      isFirst = Standard_False;
+    }
+    return 0;
+  }
+
+  for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
+  {
+    const TCollection_AsciiString anArg (theArgVec[anArgIter]);
+    TCollection_AsciiString anArgCase (anArg);
+    anArgCase.LowerCase();
+    if (anArgCase == "find")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n";
+        return 1;
+      }
+
+      Standard_CString aFontName   = theArgVec[anArgIter];
+      Font_FontAspect  aFontAspect = Font_FA_Undefined;
+      if (++anArgIter < theArgNb)
+      {
+        anArgCase = theArgVec[anArgIter];
+        anArgCase.LowerCase();
+        if (!parseFontStyle (anArgCase, aFontAspect))
+        {
+          --anArgIter;
+        }
+      }
+      Handle(Font_SystemFont) aFont = aMgr->FindFont (new TCollection_HAsciiString (aFontName), aFontAspect, -1);
+      if (aFont.IsNull())
+      {
+        std::cerr << "Error: font '" << aFontName << "' is not found!\n";
+        continue;
+      }
+
+      theDI << aFont->FontName()->String()
+            << " " << fontStyleString (aFont->FontAspect())
+            << " " << aFont->FontPath()->String();
+    }
+    else if (anArgCase == "add"
+          || anArgCase == "register")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n";
+        return 1;
+      }
+      Standard_CString aFontPath   = theArgVec[anArgIter];
+      Standard_CString aFontName   = NULL;
+      Font_FontAspect  aFontAspect = Font_FA_Undefined;
+      if (++anArgIter < theArgNb)
+      {
+        if (!parseFontStyle (anArgCase, aFontAspect))
+        {
+          aFontName = theArgVec[anArgIter];
+        }
+        if (++anArgIter < theArgNb)
+        {
+          anArgCase = theArgVec[anArgIter];
+          anArgCase.LowerCase();
+          if (!parseFontStyle (anArgCase, aFontAspect))
+          {
+            --anArgIter;
+          }
+        }
+      }
+
+      Handle(Font_SystemFont) aFont = aMgr->CheckFont (aFontPath);
+      if (aFont.IsNull())
+      {
+        std::cerr << "Error: font '" << aFontPath << "' is not found!\n";
+        continue;
+      }
+
+      if (aFontAspect != Font_FA_Undefined
+       || aFontName   != NULL)
+      {
+        if (aFontAspect == Font_FA_Undefined)
+        {
+          aFontAspect = aFont->FontAspect();
+        }
+        Handle(TCollection_HAsciiString) aName = aFont->FontName();
+        if (aFontName != NULL)
+        {
+          aName = new TCollection_HAsciiString (aFontName);
+        }
+        aFont = new Font_SystemFont (aName, aFontAspect, new TCollection_HAsciiString (aFontPath));
+      }
+
+      aMgr->RegisterFont (aFont, Standard_True);
+      theDI << aFont->FontName()->String()
+            << " " << fontStyleString (aFont->FontAspect())
+            << " " << aFont->FontPath()->String();
+    }
+    else
+    {
+      std::cerr << "Warning! Unknown argument '" << anArg.ToCString() << "'\n";
+    }
+  }
+
+  return 0;
+}
+
+//=======================================================================
+//function : VSetEdgeType
+//purpose  : Edges type management
+//=======================================================================
+
+static int VSetEdgeType (Draw_Interpretor& theDI,
+                         Standard_Integer  theArgNum,
+                         const char**      theArgs)
+{
+  if (theArgNum < 4 || theArgNum > 9)
+  {
+    theDI << theArgs[0] << " error: wrong number of parameters. Type 'help "
+          << theArgs[0] << "' for more information.\n";
+    return 1;
+  }
+
+  Standard_Boolean isForceRedisplay = Standard_False;
+
+  // Get shape name
+  TCollection_AsciiString aName(theArgs[1]);
+  if (!GetMapOfAIS().IsBound2 (aName))
+  {
+    theDI <<  theArgs[0] << " error: wrong object name.\n";
+    return 1;
+  }
+  
+  Handle(AIS_InteractiveObject) anObject = 
+    Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
+  
+  // Enable triangle edge mode
+  if (!anObject->Attributes()->HasOwnShadingAspect())
+  {
+    anObject->Attributes()->SetShadingAspect (new Prs3d_ShadingAspect());
+    *anObject->Attributes()->ShadingAspect()->Aspect() = *anObject->Attributes()->Link()->ShadingAspect()->Aspect();
+  }
+  const Handle(Prs3d_ShadingAspect)& aFillAreaAspect = anObject->Attributes()->ShadingAspect();
+  aFillAreaAspect->Aspect()->SetEdgeOn();
+
+  // Parse parameters
+  for (Standard_Integer anIt = 2; anIt < theArgNum; ++anIt)
+  {
+    TCollection_AsciiString aParam ((theArgs[anIt]));
+    if (aParam.Value (1) == '-' && !aParam.IsRealValue())
+    {
+      if (aParam.IsEqual ("-type"))
+      {
+        if (theArgNum <= anIt + 1)
+        {
+          theDI <<  theArgs[0] << " error: wrong number of values for parameter '"
+                << aParam.ToCString() << "'.\n";
+          return 1;
+        }
+
+        ++anIt;
+        Aspect_TypeOfLine aTypeEnum = Aspect_TOL_SOLID;
+        if (!ViewerTest::ParseLineType (theArgs[anIt], aTypeEnum))
+        {
+          std::cout << "Syntax error: wrong line type: '" << theArgs[anIt] << "'.\n";
+          return 1;
+        }
+        anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType (aTypeEnum);
+      }
+      else if (aParam.IsEqual ("-color"))
+      {
+        if (theArgNum <= anIt + 3)
+        {
+          theDI <<  theArgs[0] << " error: wrong number of values for parameter '"
+                << aParam.ToCString() << "'.\n";
+          return 1;
+        }
+
+        Quantity_Parameter aR = Draw::Atof(theArgs[++anIt]);
+        Quantity_Parameter aG = Draw::Atof(theArgs[++anIt]);
+        Quantity_Parameter aB = Draw::Atof(theArgs[++anIt]);
+        Quantity_Color aColor = Quantity_Color (aR > 1 ? aR / 255.0 : aR,
+                                                aG > 1 ? aG / 255.0 : aG,
+                                                aB > 1 ? aB / 255.0 : aB,
+                                                Quantity_TOC_RGB);
+
+        aFillAreaAspect->Aspect()->SetEdgeColor (aColor);
+      }
+      else if (aParam.IsEqual ("-force"))
+      {
+        isForceRedisplay = Standard_True;
+      }
+      else
+      {
+        theDI <<  theArgs[0] << " error: unknown parameter '"
+              << aParam.ToCString() << "'.\n";
+        return 1;
+      }
+    }
+  }
+
+  // Update shape presentation as aspect parameters were changed
+  if (isForceRedisplay)
+  {
+    ViewerTest::GetAISContext()->Redisplay (anObject, Standard_False);
+  }
+  else
+  {
+    anObject->SetAspect (aFillAreaAspect);
+  }
+
+  //Update view
+  ViewerTest::CurrentView()->Redraw();
+
+  return 0;
+}
+
+//=======================================================================
+//function : VUnsetEdgeType
+//purpose  : Unsets edges visibility in shading mode
+//=======================================================================
+
+static int VUnsetEdgeType (Draw_Interpretor& theDI,
+                         Standard_Integer  theArgNum,
+                         const char**      theArgs)
+{
+  if (theArgNum != 2 && theArgNum != 3)
+  {
+    theDI << theArgs[0] << " error: wrong number of parameters. Type 'help "
+          << theArgs[0] << "' for more information.\n";
+    return 1;
+  }
+
+  Standard_Boolean isForceRedisplay = Standard_False;
+
+  // Get shape name
+  TCollection_AsciiString aName (theArgs[1]);
+  if (!GetMapOfAIS().IsBound2 (aName))
+  {
+    theDI <<  theArgs[0] << " error: wrong object name.\n";
+    return 1;
+  }
+
+  Handle(AIS_InteractiveObject) anObject = 
+    Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName));
+
+  // Enable trianle edge mode
+  anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOff();
+
+  // Parse parameters
+  if (theArgNum == 3)
+  {
+    TCollection_AsciiString aParam ((theArgs[2]));
+    if (aParam.IsEqual ("-force"))
+    {
+      isForceRedisplay = Standard_True;
+    }
+    else
+    {
+       theDI <<  theArgs[0] << " error: unknown parameter '"
+              << aParam.ToCString() << "'.\n";
+       return 1;
+    }
+  }
+
+  // Update shape presentation as aspect parameters were changed
+  if (isForceRedisplay)
   {
-    Standard_Integer aLayerId = Draw::Atoi (argv [3]);
-    aContext->SetZLayer (anInterObj, aLayerId);
+    ViewerTest::GetAISContext()->Redisplay (anObject, Standard_False);
   }
-  else if (aOperation.IsEqual ("get"))
+  else
   {
-    di << "Z layer id: " << aContext->GetZLayer (anInterObj);
+    anObject->SetAspect (anObject->Attributes()->ShadingAspect());
   }
-  
+
+  //Update view
+  ViewerTest::CurrentView()->Redraw();
+
   return 0;
 }
 
+
 //=======================================================================
-//function : VPolygonOffset
-//purpose  : Set or get polygon offset parameters
+//function : VVertexMode
+//purpose  : Switches vertex display mode for AIS_Shape or displays the current value
 //=======================================================================
-static Standard_Integer VPolygonOffset(Draw_Interpretor& di,
-                                       Standard_Integer argc,
-                                       const char ** argv)
+
+static int VVertexMode (Draw_Interpretor& theDI,
+                         Standard_Integer  theArgNum,
+                         const char**      theArgs)
 {
   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
   if (aContext.IsNull())
   {
-    std::cout << argv[0] << " Call 'vinit' before!\n";
+    std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
     return 1;
   }
 
-  if (argc > 2 && argc != 5)
+  // No arguments --> print the current default vertex draw mode
+  if (theArgNum == 1)
   {
-    std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object,"
-      "without arguments prints the default values" << std::endl;
-    return 1;
+    Prs3d_VertexDrawMode aCurrMode = aContext->DefaultDrawer()->VertexDrawMode();
+    theDI <<  "Default vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
+    return 0;
   }
 
-  // find object
-  Handle(AIS_InteractiveObject) anInterObj;
-  if (argc >= 2)
+  // -set argument --> change the default vertex draw mode and the mode for all displayed or given object(s)
+  TCollection_AsciiString aParam (theArgs[1]);
+  if (aParam == "-set")
   {
-    TCollection_AsciiString aName (argv[1]);
-    ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
-    if (!aMap.IsBound2 (aName))
+    if (theArgNum == 2)
     {
-      std::cout << "Use 'vdisplay' before" << std::endl;
+      std::cout << "Error: '-set' option not followed by the mode and optional object name(s)" << std::endl;
+      std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
       return 1;
     }
 
-    // find interactive object
-    Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
-    anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
-    if (anInterObj.IsNull())
+    TCollection_AsciiString aModeStr (theArgs[2]);
+    Prs3d_VertexDrawMode aNewMode =
+       aModeStr == "isolated" ? Prs3d_VDM_Isolated :
+      (aModeStr == "all"      ? Prs3d_VDM_All :
+                                Prs3d_VDM_Inherited);
+
+    Standard_Boolean aRedrawNeeded = Standard_False;
+    AIS_ListOfInteractive anObjs;
+
+    // No object(s) specified -> use all displayed
+    if (theArgNum == 3)
     {
-      std::cout << "Not an AIS interactive object!" << std::endl;
-      return 1;
+      theDI << "Setting the default vertex draw mode and updating all displayed objects...\n";
+      aContext->DisplayedObjects (anObjs);
+      aContext->DefaultDrawer()->SetVertexDrawMode (aNewMode);
+      aRedrawNeeded = Standard_True;
     }
-  }
-
-  Standard_Integer aMode;
-  Standard_ShortReal    aFactor, aUnits;
-  if (argc == 5)
-  {
-    aMode   = Draw::Atoi(argv[2]);
-    aFactor = (Standard_ShortReal) Draw::Atof(argv[3]);
-    aUnits  = (Standard_ShortReal) Draw::Atof(argv[4]);
 
-    anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits);
-    aContext->UpdateCurrentViewer();
-    return 0;
-  }
-  else if (argc == 2)
-  {
-    if (anInterObj->HasPolygonOffsets())
+    Handle(AIS_InteractiveObject) anObject;
+    for (Standard_Integer aCount = 3; aCount < theArgNum; aCount++)
     {
-      anInterObj->PolygonOffsets(aMode, aFactor, aUnits);
-      std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl;
-      std::cout << "\tMode: "   << aMode   << std::endl;
-      std::cout << "\tFactor: " << aFactor << std::endl;
-      std::cout << "\tUnits: "  << aUnits  << std::endl;
-      return 0;
+      TCollection_AsciiString aName (theArgs[aCount]);
+      if (!GetMapOfAIS().IsBound2 (aName))
+      {
+        theDI << "Warning: wrong object name ignored - " << theArgs[0] << "\n";
+        continue;
+      }
+      anObject = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName));
+      anObjs.Append (anObject);
     }
-    else
+
+    for (AIS_ListIteratorOfListOfInteractive anIt (anObjs); anIt.More(); anIt.Next())
     {
-      std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl;
+      anObject = anIt.Value();
+      anObject->Attributes()->SetVertexDrawMode (aNewMode);
+      aContext->Redisplay (anObject, Standard_False);
+      aRedrawNeeded = Standard_True;
     }
+
+    if (aRedrawNeeded)
+      ViewerTest::CurrentView()->Redraw();
+
+    return 0;
   }
 
-  std::cout << "Default polygon offset parameters:" << std::endl;
-  aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits);
-  std::cout << "\tMode: "   << aMode   << std::endl;
-  std::cout << "\tFactor: " << aFactor << std::endl;
-  std::cout << "\tUnits: "  << aUnits  << std::endl;
+  if (theArgNum > 2)
+  {
+    std::cout << "Error: invalid number of arguments" << std::endl;
+    std::cout << "Type 'help vvertexmode' for usage hints" << std::endl;
+    return 1;
+  }
 
+  // One argument (object name) --> print the current vertex draw mode for the object
+  Handle(AIS_InteractiveObject) anObject =
+    Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aParam));
+  Prs3d_VertexDrawMode aCurrMode = anObject->Attributes()->VertexDrawMode();
+  theDI <<  "Object's vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n";
   return 0;
 }
 
 //=======================================================================
-//function : VShowFaceBoundaries
-//purpose  : Set face boundaries drawing on/off for ais object
+//function : VPointCloud
+//purpose  : Create interactive object for arbitary set of points.
 //=======================================================================
-static Standard_Integer VShowFaceBoundary (Draw_Interpretor& di,
-                                           Standard_Integer argc,
-                                           const char ** argv)
+static Standard_Integer VPointCloud (Draw_Interpretor& theDI,
+                                     Standard_Integer  theArgNum,
+                                     const char**      theArgs)
 {
-  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext ();
-  if (aContext.IsNull ())
+  Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
+  if (anAISContext.IsNull())
   {
-    std::cout << argv[0] << " Call 'vinit' before!\n";
+    std::cerr << "Error: no active view!\n";
     return 1;
   }
 
-  if ((argc != 3 && argc < 6) || argc > 8)
+  // command to execute
+  enum Command
   {
-    std::cout << "Usage :\n " << argv[0]
-              << " ObjectName isOn [R G B [LineWidth [LineStyle]]]\n"
-              << "   ObjectName - name of AIS interactive object. \n"
-              << "                if ObjectName = \"\", then set as default\n"
-              << "                settings for all newly displayed objects\n"
-              << "   isOn       - flag indicating whether the boundaries\n"
-              << "                should be turned on or off (can be set\n"
-              << "                to 0 (off) or 1 (on)).\n"
-              << "   R, G, B    - red, green and blue components of boundary\n"
-              << "                color in range (0 - 255).\n"
-              << "                (default is (0, 0, 0)\n"
-              << "   LineWidth  - line width\n"
-              << "                (default is 1)\n"
-              << "   LineStyle  - line fill style :\n"
-              << "                 0 - solid  \n"
-              << "                 1 - dashed \n"
-              << "                 2 - dot    \n"
-              << "                 3 - dashdot\n"
-              << "                 (default is solid)";
-    return 1;
+    CloudForShape, // generate point cloud for shape
+    CloudSphere,   // generate point cloud for generic sphere
+    Unknow
+  };
+
+  // count number of non-optional command arguments
+  Command aCmd = Unknow;
+  Standard_Integer aCmdArgs = 0;
+  for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
+  {
+    Standard_CString anArg = theArgs[anArgIter];
+    TCollection_AsciiString aFlag (anArg);
+    aFlag.LowerCase();
+    if (aFlag.IsRealValue() || aFlag.Search ("-") != 1)
+    {
+      aCmdArgs++;
+    }
+  }
+  switch (aCmdArgs)
+  {
+    case 2  : aCmd = CloudForShape; break;
+    case 7  : aCmd = CloudSphere; break;
+    default :
+      std::cout << "Error: wrong number of arguments! See usage:\n";
+      theDI.PrintHelp (theArgs[0]);
+      return 1;
   }
 
-  TCollection_AsciiString aName (argv[1]);
+  // parse options
+  Standard_Boolean toRandColors = Standard_False;
+  Standard_Boolean hasNormals   = Standard_True;
+  Standard_Boolean isSetArgNorm = Standard_False;
+  for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter)
+  {
+    Standard_CString anArg = theArgs[anArgIter];
+    TCollection_AsciiString aFlag (anArg);
+    aFlag.LowerCase();
+    if (aFlag == "-randcolors"
+     || aFlag == "-randcolor")
+    {
+      if (isSetArgNorm && hasNormals)
+      {
+        std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
+        return 1;
+      }
+      toRandColors = Standard_True;
+      hasNormals   = Standard_False;
+    }
+    else if (aFlag == "-normals"
+          || aFlag == "-normal")
+    {
+      if (toRandColors)
+      {
+        std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n";
+        return 1;
+      }
+      isSetArgNorm = Standard_True;
+      hasNormals   = Standard_True;
+    }
+    else if (aFlag == "-nonormals"
+          || aFlag == "-nonormal")
+    {
+      isSetArgNorm = Standard_True;
+      hasNormals   = Standard_False;
+    }
+  }
 
-  Quantity_Parameter aRed      = 0.0;
-  Quantity_Parameter aGreen    = 0.0;
-  Quantity_Parameter aBlue     = 0.0;
-  Standard_Real      aWidth    = 1.0;
-  Aspect_TypeOfLine  aLineType = Aspect_TOL_SOLID;
-  
-  // find object
-  Handle(AIS_InteractiveObject) anInterObj;
+  Standard_CString aName = theArgs[1];
 
-  // if name is empty - apply attributes for default aspect
-  if (!aName.IsEmpty ())
+  // generate arbitrary set of points
+  Handle(Graphic3d_ArrayOfPoints) anArrayPoints;
+  if (aCmd == CloudForShape)
   {
-    ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS ();
-    if (!aMap.IsBound2 (aName))
+    Standard_CString aShapeName = theArgs[2];
+    TopoDS_Shape     aShape     = DBRep::Get (aShapeName);
+
+    if (aShape.IsNull())
     {
-      std::cout << "Use 'vdisplay' on " << aName << " before" << std::endl;
+      std::cout << "Error: no shape with name '" << aShapeName << "' found\n";
       return 1;
     }
 
-    // find interactive object
-    Handle(Standard_Transient) anObj = GetMapOfAIS ().Find2 (aName);
-    anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj);
-    if (anInterObj.IsNull ())
+    // calculate number of points
+    TopLoc_Location  aLocation;
+    Standard_Integer aNbPoints = 0;
+    for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
     {
-      std::cout << "Not an AIS interactive object!" << std::endl;
+      const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
+      Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation);
+      if (!aTriangulation.IsNull())
+      {
+        aNbPoints += aTriangulation->NbNodes();
+      }
+    }
+    if (aNbPoints < 3)
+    {
+      std::cout << "Error: shape should be triangulated!\n";
       return 1;
     }
-  }
-  
-  const Handle(Prs3d_Drawer)& aDrawer = (aName.IsEmpty ()) ?
-    TheAISContext ()->DefaultDrawer () : anInterObj->Attributes ();
 
-  // turn boundaries on/off
-  Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[2]) == 1);
-  aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
-  
-  // set boundary line color
-  if (argc >= 6)
+    anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals);
+    for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next())
+    {
+      const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current());
+      Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation);
+      if (aTriangulation.IsNull())
+      {
+        continue;
+      }
+
+      const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
+      const gp_Trsf&            aTrsf  = aLocation.Transformation();
+
+      // extract normals from nodes
+      TColgp_Array1OfDir aNormals (aNodes.Lower(), hasNormals ? aNodes.Upper() : aNodes.Lower());
+      if (hasNormals)
+      {
+        Poly_Connect aPolyConnect (aTriangulation);
+        StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect, aNormals);
+      }
+
+      for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter)
+      {
+        gp_Pnt aPoint = aNodes (aNodeIter);
+        if (!aLocation.IsIdentity())
+        {
+          aPoint.Transform (aTrsf);
+          if (hasNormals)
+          {
+            aNormals (aNodeIter).Transform (aTrsf);
+          }
+        }
+
+        // add vertex into array of points
+        const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
+        if (toRandColors)
+        {
+          Quantity_Color aColor (360.0 * Standard_Real(anIndexOfPoint) / Standard_Real(aNbPoints),
+                                 1.0, 0.5, Quantity_TOC_HLS);
+          anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
+        }
+
+        if (hasNormals)
+        {
+          anArrayPoints->SetVertexNormal (anIndexOfPoint, aNormals (aNodeIter));
+        }
+      }
+    }
+  }
+  else if (aCmd == CloudSphere)
   {
-    // Text color
-    aRed   = Draw::Atof (argv[3])/255.;
-    aGreen = Draw::Atof (argv[4])/255.;
-    aBlue  = Draw::Atof (argv[5])/255.;
+    Standard_Real aCenterX       = Draw::Atof (theArgs[2]);
+    Standard_Real aCenterY       = Draw::Atof (theArgs[3]);
+    Standard_Real aCenterZ       = Draw::Atof (theArgs[4]);
+    Standard_Real aRadius        = Draw::Atof (theArgs[5]);
+    Standard_Integer aNbPoints   = Draw::Atoi (theArgs[6]);
+
+    TCollection_AsciiString aDistribution = TCollection_AsciiString(theArgs[7]);
+    aDistribution.LowerCase();
+    if ( aDistribution != "surface" && aDistribution != "volume" )
+    {
+      std::cout << "Error: wrong arguments! See usage:\n";
+      theDI.PrintHelp (theArgs[0]);
+      return 1;
+    }
+    Standard_Boolean isSurface = aDistribution == "surface";
+
+    gp_Pnt aCenter(aCenterX, aCenterY, aCenterZ);
+
+    anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals);
+    for (Standard_Integer aPntIt = 0; aPntIt < aNbPoints; ++aPntIt)
+    {
+      Standard_Real anAlpha   = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
+      Standard_Real aBeta     = (Standard_Real (rand() % 2000) / 1000.0) * M_PI;
+      Standard_Real aDistance = isSurface ?
+        aRadius : (Standard_Real (rand() % aNbPoints) / aNbPoints) * aRadius;
+
+      gp_Dir aDir (Cos (anAlpha) * Sin (aBeta),
+                   Sin (anAlpha),
+                   Cos (anAlpha) * Cos (aBeta));
+      gp_Pnt aPoint = aCenter.Translated (aDir.XYZ() * aDistance);
+
+      const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint);
+      if (toRandColors)
+      {
+        Quantity_Color aColor (360.0 * Standard_Real (anIndexOfPoint) / Standard_Real (aNbPoints),
+                               1.0, 0.5, Quantity_TOC_HLS);
+        anArrayPoints->SetVertexColor (anIndexOfPoint, aColor);
+      }
+
+      if (hasNormals)
+      {
+        anArrayPoints->SetVertexNormal (anIndexOfPoint, aDir);
+      }
+    }
   }
 
-  // set line width
-  if (argc >= 7)
+  // set array of points in point cloud object
+  Handle(AIS_PointCloud) aPointCloud = new AIS_PointCloud();
+  aPointCloud->SetPoints (anArrayPoints);
+  VDisplayAISObject (aName, aPointCloud);
+  return 0;
+}
+
+//=======================================================================
+//function : VPriority
+//purpose  : Prints or sets the display priority for an object
+//=======================================================================
+
+static int VPriority (Draw_Interpretor& theDI,
+                      Standard_Integer  theArgNum,
+                      const char**      theArgs)
+{
+  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
+  ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
+  if (aContext.IsNull())
   {
-    aWidth = (Standard_Real)Draw::Atof (argv[6]);
+    std::cout << "Error: no view available, call 'vinit' before!" << std::endl;
+    return 1;
   }
 
-  // select appropriate line type
-  if (argc == 8)
+  TCollection_AsciiString aLastArg (theArgs[theArgNum - 1]);
+  Standard_Integer aPriority = -1;
+  Standard_Integer aNbArgs   = theArgNum;
+  if (aLastArg.IsIntegerValue())
   {
-    switch (Draw::Atoi (argv[7]))
+    aPriority = aLastArg.IntegerValue();
+    --aNbArgs;
+    if (aPriority < 0 || aPriority > 10)
     {
-      case 1: aLineType = Aspect_TOL_DASH;    break;
-      case 2: aLineType = Aspect_TOL_DOT;     break;
-      case 3: aLineType = Aspect_TOL_DOTDASH; break;
-      default:
-        aLineType = Aspect_TOL_SOLID;
+      std::cout << "Error: the specified display priority value '" << aLastArg
+                << "' is outside the valid range [0..10]" << std::endl;
+      return 1;
     }
   }
+  else
+  {
+    anUpdateTool.Invalidate();
+  }
 
-  Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
+  if (aNbArgs < 2)
+  {
+    std::cout << "Error: wrong number of arguments! See usage:\n";
+    theDI.PrintHelp (theArgs[0]);
+    return 1;
+  }
 
-  Handle(Prs3d_LineAspect) aBoundaryAspect = 
-    new Prs3d_LineAspect (aColor, aLineType, aWidth);
+  for (Standard_Integer anArgIter = 1; anArgIter < aNbArgs; ++anArgIter)
+  {
+    if (anUpdateTool.parseRedrawMode (theArgs[anArgIter]))
+    {
+      continue;
+    }
 
-  aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
+    TCollection_AsciiString aName (theArgs[anArgIter]);
+    Handle(AIS_InteractiveObject) anIObj;
+    if (GetMapOfAIS().IsBound2 (aName))
+    {
+      anIObj = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
+    }
 
-  TheAISContext()->Redisplay (anInterObj);
-  
+    if (anIObj.IsNull())
+    {
+      std::cout << "Error: the object '" << theArgs[1] << "' is not displayed" << std::endl;
+      return 1;
+    }
+
+    if (aPriority < 1)
+    {
+      theDI << aContext->DisplayPriority (anIObj) << " ";
+    }
+    else
+    {
+      aContext->SetDisplayPriority (anIObj, aPriority);
+    }
+  }
   return 0;
 }
 
@@ -4599,71 +5943,143 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
 {
   const char *group ="AISObjects";
   theCommands.Add("vtrihedron",
-    "vtrihedron         : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] ",
+    "vtrihedron         : vtrihedron name [ -origin x y z ] [ -zaxis u v w -xaxis u v w ] [ -hidelabels ]"
+    "\n\t\t: Creates a new *AIS_Trihedron* object. If no argument is set, the default trihedron (0XYZ) is created."
+     "\n\t\t: -hidelabels allows to draw trihedron without axes labels. By default, they are displayed.",
     __FILE__,VTrihedron,group);
 
   theCommands.Add("vtri2d",
-    "vtri2d Name Selection in the viewer only ",
+    "vtri2d Name"
+    "\n\t\t: Creates a plane with a 2D trihedron from an interactively selected face.",
     __FILE__,VTrihedron2D ,group);
 
   theCommands.Add("vplanetri",
-    "vplanetri Name Selection in the viewer only ",
+    "vplanetri name"
+    "\n\t\t: Create a plane from a trihedron selection. If no arguments are set, the default",
     __FILE__,VPlaneTrihedron ,group);
 
   theCommands.Add("vsize",
-    "vsize       : vsize [name(Default=Current)] [size(Default=100)] ",
+    "vsize       : vsize [name(Default=Current)] [size(Default=100)] "
+    "\n\t\t: Changes the size of a named or selected trihedron."
+    "\n\t\t: If the name is not defined: it affects the selected trihedrons otherwise nothing is done."
+    "\n\t\t: If the value is not defined: it is set to 100 by default.",
     __FILE__,VSize,group);
 
   theCommands.Add("vaxis",
-    "vaxis nom [Xa] [Ya] [Za] [Xb] [Yb] [Zb]",
+    "vaxis name [Xa] [Ya] [Za] [Xb] [Yb] [Zb]"
+    "\n\t\t: Creates an axis. If  the values are not defined, an axis is created by interactive selection of two vertices or one edge",
     __FILE__,VAxisBuilder,group);
 
   theCommands.Add("vaxispara",
-    "vaxispara  nom ",
+    "vaxispara name "
+    "\n\t\t: Creates an axis by interactive selection of an edge and a vertex.",
     __FILE__,VAxisBuilder,group);
 
   theCommands.Add("vaxisortho",
-    "vaxisotho  nom ",
+    "vaxisortho name "
+    "\n\t\t: Creates an axis by interactive selection of an edge and a vertex. The axis will be orthogonal to the selected edge.",
     __FILE__,VAxisBuilder,group);
 
   theCommands.Add("vpoint",
-    "vpoint  PointName [Xa] [Ya] [Za] ",
+    "vpoint  PointName [Xa] [Ya] [Za] "
+    "\n\t\t: Creates a point from coordinates. If the values are not defined,"
+    "\n\t\t: a point is created by interactive selection of a vertice or an edge (in the center of the edge).",
     __FILE__,VPointBuilder,group);
 
   theCommands.Add("vplane",
-    "vplane  PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] ",
+    "vplane  PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] [TypeOfSensitivity {0|1}]"
+    "\n\t\t: Creates a plane from named or interactively selected entities."
+    "\n\t\t: TypeOfSensitivity:"
+    "\n\t\t:   0 - Interior"
+    "\n\t\t:   1 - Boundary",
     __FILE__,VPlaneBuilder,group);
 
+  theCommands.Add ("vchangeplane", "vchangeplane usage: \n"
+    "   vchangeplane <plane_name>"
+    " [x=center_x y=center_y z=center_z]"
+    " [dx=dir_x dy=dir_y dz=dir_z]"
+    " [sx=size_x sy=size_y]"
+    " [noupdate]\n"
+    "   - changes parameters of the plane:\n"
+    "   - x y z     - center\n"
+    "   - dx dy dz  - normal\n"
+    "   - sx sy     - plane sizes\n"
+    "   - noupdate  - do not update/redisplay the plane in context\n"
+    "   Please enter coordinates in format \"param=value\" in arbitrary order.",
+    __FILE__, VChangePlane, group);
+
   theCommands.Add("vplanepara",
-    "vplanepara  PlaneName  ",
+    "vplanepara  PlaneName  "
+    "\n\t\t: Creates a plane from interactively selected vertex and face.",
     __FILE__,VPlaneBuilder,group);
 
   theCommands.Add("vplaneortho",
-    "vplaneortho  PlaneName  ",
+    "vplaneortho  PlaneName  "
+    "\n\t\t: Creates a plane from interactive selected face and coplanar edge. ",
     __FILE__,VPlaneBuilder,group);
 
   theCommands.Add("vline",
-    "vline: vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb]  ",
+    "vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb]  "
+    "\n\t\t: Creates a line from coordinates, named or interactively selected vertices. ",
     __FILE__,VLineBuilder,group);
 
   theCommands.Add("vcircle",
-    "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]",
+    "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]"
+    "\n\t\t: Creates a circle from named or interactively selected entities."
+    "\n\t\t: Parameter IsFilled is defined as 0 or 1.",
     __FILE__,VCircleBuilder,group);
 
-  theCommands.Add("vdrawtext",
-    "vdrawtext  : vdrawtext name X Y Z R G B hor_align ver_align angle zoomable height Aspect [Font [isMultiByte]]",
-    __FILE__,VDrawText,group);
+  theCommands.Add ("vdrawtext",
+                   "vdrawtext name text"
+                   "\n\t\t: [-pos X=0 Y=0 Z=0]"
+                   "\n\t\t: [-color {R G B|name}=yellow]"
+                   "\n\t\t: [-halign {left|center|right}=left]"
+                   "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]"
+                   "\n\t\t: [-angle angle=0]"
+                   "\n\t\t: [-zoom {0|1}=0]"
+                   "\n\t\t: [-height height=16]"
+                   "\n\t\t: [-aspect {regular|bold|italic|bolditalic}=regular]"
+                   "\n\t\t: [-font font=Times]"
+                   "\n\t\t: [-2d]"
+                   "\n\t\t: [-perspos {X Y Z}=0 0 0], where"
+                   "\n\t\t X and Y define the coordinate origin in 2d space relative to the view window"
+                   "\n\t\t Example: X=0 Y=0 is center, X=1 Y=1 is upper right corner etc..."
+                   "\n\t\t Z coordinate defines the gap from border of view window (except center position)."
+                   "\n\t\t: [-disptype {blend|decal|subtitle|dimension|normal}=normal}"
+                   "\n\t\t: [-subcolor {R G B|name}=white]"
+                   "\n\t\t: [-noupdate]"
+                   "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]"
+                   "\n\t\t: [-flipping]"
+                   "\n\t\t: Display text label at specified position.",
+    __FILE__, VDrawText, group);
 
   theCommands.Add("vdrawsphere",
-    "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n",
+    "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0] [ToPrintInfo=1]\n",
     __FILE__,VDrawSphere,group);
 
-  theCommands.Add("vclipplane",
-    "vclipplane : vclipplane [x y z dx dy dz] [planeId {on/off/del/display/hide}]",
-    __FILE__,VClipPlane,group);
-
+  theCommands.Add ("vlocation",
+                "vlocation name"
+      "\n\t\t:   [-reset]"
+      "\n\t\t:   [-copyFrom otherName]"
+      "\n\t\t:   [-translate X Y [Z]]"
+      "\n\t\t:   [-rotate x y z dx dy dz angle]"
+      "\n\t\t:   [-scale [X Y Z] scale]"
+      "\n\t\t:   [-mirror x y z dx dy dz]"
+      "\n\t\t:   [-setLocation X Y [Z]]"
+      "\n\t\t:   [-setRotation QX QY QZ QW]"
+      "\n\t\t:   [-setScale [X Y Z] scale]"
+      "\n\t\t: Object local transformation management:"
+      "\n\t\t:   -reset       reset transformation to identity"
+      "\n\t\t:   -translate   translate object"
+      "\n\t\t:   -rotate      applies rotation to local transformation"
+      "\n\t\t:   -scale       applies scale    to local transformation"
+      "\n\t\t:   -mirror      applies mirror   to local transformation"
+      "\n\t\t:   -setLocation assign object location"
+      "\n\t\t:   -setRotation assign object rotation (quaternion)"
+      "\n\t\t:   -setScale    assign object scale factor",
+        __FILE__, VSetLocation, group);
   theCommands.Add ("vsetlocation",
-        "vsetlocation : name x y z; set new location for an interactive object",
+                   "alias for vlocation",
         __FILE__, VSetLocation, group);
 
   theCommands.Add (
@@ -4672,27 +6088,73 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
     __FILE__, VComputeHLR, group);
 
   theCommands.Add("vdrawparray",
-    "vdrawparray : vdrawparray Name TypeOfArray [vertex = { 'v' x y z [vertex_normal = { 'n' x y z }] [vertex_color = { 'c' r g b }] ] ... [bound = { 'b' vertex_count [bound_color = { 'c' r g b }] ] ... [edge = { 'e' vertex_id [edge_hidden = { 'h' }] ]",
+    "vdrawparray : vdrawparray Name TypeOfArray [vertex = { 'v' x y z [vertex_normal = { 'n' x y z }] [vertex_color = { 'c' r g b }] ] ... [bound = { 'b' vertex_count [bound_color = { 'c' r g b }] ] ... [edge = { 'e' vertex_id ]",
     __FILE__,VDrawPArray,group);
 
   theCommands.Add("vconnect", 
-    "vconnect : name Xo Yo Zo Xu Xv Xw Zu Zv Zw object1 object2 ... [color=NAME]", 
+    "vconnect name Xo Yo Zo object1 object2 ... [color=NAME]"
+    "\n\t\t: Creates and displays AIS_ConnectedInteractive object from input object and location.",
     __FILE__, VConnect, group);
 
-  theCommands.Add("vconnectsh", 
-    "vconnectsh : name Xo Yo Zo Xu Xv Xw Zu Zv Zw shape1 shape2 ... [color=NAME]", 
-    __FILE__, VConnectShape, group);
+  theCommands.Add("vconnectto",
+    "vconnectto : instance_name Xo Yo Zo object [-nodisplay|-noupdate|-update]"
+    "  Makes an instance 'instance_name' of 'object' with position (Xo Yo Zo)."
+    "\n\t\t:   -nodisplay - only creates interactive object, but not displays it",
+    __FILE__, VConnectTo,group);
+
+  theCommands.Add("vdisconnect",
+    "vdisconnect assembly_name (object_name | object_number | 'all')"
+    "  Disconnects all objects from assembly or disconnects object by name or number (use vlistconnected to enumerate assembly children).",
+    __FILE__,VDisconnect,group);
+
+  theCommands.Add("vaddconnected",
+    "vaddconnected assembly_name object_name"
+    "Adds object to assembly.",
+    __FILE__,VAddConnected,group);
+
+  theCommands.Add("vlistconnected",
+    "vlistconnected assembly_name"
+    "Lists objects in assembly.",
+    __FILE__,VListConnected,group);
+
 
   theCommands.Add("vselmode", 
-    "vselmode : [object] mode On/Off (1/0)", 
+    "vselmode : [object] mode_number is_turned_on=(1|0)\n"
+    "  switches selection mode for the determined object or\n"
+    "  for all objects in context.\n"
+    "  mode_number is non-negative integer that has different\n"
+    "    meaning for different interactive object classes.\n"
+    "    For shapes the following mode_number values are allowed:\n"
+    "      0 - shape\n"
+    "      1 - vertex\n"
+    "      2 - edge\n"
+    "      3 - wire\n"
+    "      4 - face\n"
+    "      5 - shell\n"
+    "      6 - solid\n"
+    "      7 - compsolid\n"
+    "      8 - compound\n"
+    "  is_turned_on is:\n"
+    "    1 if mode is to be switched on\n"
+    "    0 if mode is to be switched off\n", 
     __FILE__, VSetSelectionMode, group);
 
+  theCommands.Add("vselnext",
+    "vselnext : hilight next detected",
+    __FILE__, VSelectionNext, group);
+
+  theCommands.Add("vselprev",
+    "vselnext : hilight previous detected",
+    __FILE__, VSelectionPrevious, group);
+
   theCommands.Add("vtriangle",
-    "vtriangle Name PointName PointName PointName", 
+    "vtriangle Name PointName PointName PointName"
+    "\n\t\t: Creates and displays a filled triangle from named points.", 
     __FILE__, VTriangle,group);
 
   theCommands.Add("vsegment",
-    "vsegment Name PointName PointName", 
+    "vsegment Name PointName PointName"
+    "\n\t\t: Creates and displays a segment from named points.", 
     __FILE__, VSegment,group);
 
   theCommands.Add("vobjzlayer",
@@ -4708,4 +6170,66 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
     "- turns on/off drawing of face boundaries for ais object "
     "and defines boundary line style.",
     __FILE__, VShowFaceBoundary, group);
+
+  theCommands.Add ("vmarkerstest",
+                   "vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n",
+                   __FILE__, VMarkersTest, group);
+
+  theCommands.Add ("text2brep",
+                   "text2brep: name text"
+                   "\n\t\t: [-pos X=0 Y=0 Z=0]"
+                   "\n\t\t: [-halign {left|center|right}=left]"
+                   "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]"
+                   "\n\t\t: [-height height=16]"
+                   "\n\t\t: [-aspect {regular|bold|italic|bolditalic}=regular]"
+                   "\n\t\t: [-font font=Courier]"
+                   "\n\t\t: [-composite {on|off}=off]"
+                   "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]",
+                   __FILE__, TextToBRep, group);
+  theCommands.Add ("vfont",
+                            "vfont [add pathToFont [fontName] [regular,bold,italic,bolditalic=undefined]]"
+                   "\n\t\t:        [find fontName [regular,bold,italic,bolditalic=undefined]]",
+                   __FILE__, VFont, group);
+  
+  theCommands.Add ("vsetedgetype",
+                   "vsetedgetype usage:\n"
+                   "vsetedgetype ShapeName [-force] [-type {solid, dash, dot}] [-color R G B] "
+                   "\n\t\t:        Sets edges type and color for input shape",
+                   __FILE__, VSetEdgeType, group);
+
+  theCommands.Add ("vunsetedgetype",
+                   "vunsetedgetype usage:\n"
+                   "vunsetedgetype ShapeName [-force]"
+                   "\n\t\t:        Unsets edges type and color for input shape",
+                   __FILE__, VUnsetEdgeType, group);
+
+  theCommands.Add ("vvertexmode",
+                   "vvertexmode [name | -set {isolated | all | inherited} [name1 name2 ...]]\n"
+                   "vvertexmode - prints the default vertex draw mode\n"
+                   "vvertexmode name - prints the vertex draw mode of the given object\n"
+                   "vvertexmode -set {isolated | all | inherited} - sets the default vertex draw mode and updates the mode for all displayed objects\n"
+                   "vvertexmode -set {isolated | all | inherited} name1 name2 ... - sets the vertex draw mode for the specified object(s)\n",
+                   __FILE__, VVertexMode, group);
+
+  theCommands.Add ("vpointcloud",
+                   "vpointcloud name shape [-randColor] [-normals] [-noNormals]"
+                   "\n\t\t: Create an interactive object for arbitary set of points"
+                   "\n\t\t: from triangulated shape."
+                   "\n"
+                   "vpointcloud name x y z r npts {surface|volume}\n"
+                   "            ... [-randColor] [-normals] [-noNormals]"
+                   "\n\t\t: Create arbitrary set of points (npts) randomly distributed"
+                   "\n\t\t: on spheric surface or within spheric volume (x y z r)."
+                   "\n\t\t:"
+                   "\n\t\t: Additional options:"
+                   "\n\t\t:  -randColor - generate random color per point"
+                   "\n\t\t:  -normals   - generate normal per point (default)"
+                   "\n\t\t:  -noNormals - do not generate normal per point"
+                   "\n",
+                   __FILE__, VPointCloud, group);
+
+  theCommands.Add("vpriority",
+    "vpriority [-noupdate|-update] name [value]\n\t\t  prints or sets the display priority for an object",
+    __FILE__,
+    VPriority, group);
 }