0022554: Application hangs on selection
[occt.git] / src / ViewerTest / ViewerTest_ObjectCommands.cxx
index 589abbb..8fd4287 100755 (executable)
 #include <TColStd_ListOfInteger.hxx>
 #include <TColStd_ListIteratorOfListOfInteger.hxx>
 
+#include <Select3D_SensitiveTriangle.hxx>
+#include <Select3D_SensitiveCurve.hxx>
+#include <BRepAdaptor_Curve.hxx>
+#include <StdPrs_Curve.hxx>
+
+#include <BRepExtrema_ExtPC.hxx>
+#include <BRepExtrema_ExtPF.hxx>
+
 #ifdef HAVE_STRINGS_H
 #include <strings.h>
 #endif
@@ -856,7 +864,7 @@ static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char
 }
 
 //==============================================================================
-// Fonction        1st click   2de click  3de click
+// Function        1st click   2de click  3de click
 // vplane          Vertex      Vertex     Vertex
 //                 Vertex      Edge
 //                 Edge        Vertex
@@ -869,651 +877,714 @@ 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
+//purpose  : Build an AIS_Plane from selected entities or Named AIS components
 //Draw arg : vplane PlaneName [AxisName]  [PointName]
 //                            [PointName] [PointName] [PointName]
 //                            [PlaneName] [PointName]
 //==============================================================================
 
-#include <TopoDS_Edge.hxx>
-#include <TopoDS_Vertex.hxx>
-#include <TopoDS_Face.hxx>
-#include <TopExp.hxx>
-#include <AIS_Plane.hxx>
-#include <Geom_CartesianPoint.hxx>
-#include <Geom_Plane.hxx>
-#include <BRepExtrema_ExtPC.hxx>
-#include <BRepExtrema_ExtPF.hxx>
-#include <BRepAdaptor_Surface.hxx>
-#include <gp_Pln.hxx>
-#include <GC_MakePlane.hxx>
-
-static int VPlaneBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static Standard_Integer VPlaneBuilder (Draw_Interpretor& di,
+                                       Standard_Integer argc,
+                                       const char** argv)
 {
   // Declarations
-  Standard_Boolean HasArg;
-  TCollection_AsciiString name;
-  Standard_Integer myCurrentIndex;
+  Standard_Boolean hasArg;
+  TCollection_AsciiString aName;
+  Standard_Integer aCurrentIndex;
 
   // Verification
-  if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;}
-  if (argc==5 || argc==4) HasArg=Standard_True;
-  else HasArg=Standard_False;
+  if (argc<2 || argc>5 )
+  {
+    std::cout<<" Syntax error\n";
+    return 1;
+  }
+  if (argc==5 || argc==4)
+    hasArg=Standard_True;
+  else 
+    hasArg=Standard_False;
 
-  name=argv[1];
-  // Fermeture des contextes
+  aName=argv[1];
+  // Close all contexts
   TheAISContext()->CloseAllContexts();
 
-
-  // Il y a des arguments
-  if (HasArg) {
-    if (!GetMapOfAIS().IsBound2(argv[2] ) ) {di<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()."<<"\n";return 1;}
-    // on recupere la shape dans la map
-    Handle(AIS_InteractiveObject) theShapeA =
+  // There are some arguments
+  if (hasArg)
+  {
+    if (!GetMapOfAIS().IsBound2(argv[2] ))
+    {
+      std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
+      return 1;
+    }
+    // Get shape from map
+    Handle(AIS_InteractiveObject) aShapeA =
       Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] ));
 
-    // Le premier argument est un AIS_Point 1
-    if (!theShapeA.IsNull() &&
-      theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
-        // le deuxieme argument doit etre un AIS_Point aussi
-        if (argc<5 || !GetMapOfAIS().IsBound2(argv[3] ) ) {di<<"vplane: error 2de name doesn't exist in the GetMapOfAIS()."<<"\n";return 1;}
-        // on recupere la shape dans la map
-        Handle(AIS_InteractiveObject) theShapeB =
+    // The first argument is an AIS_Point
+    if (!aShapeA.IsNull() &&
+        aShapeA->Type()==AIS_KOI_Datum &&
+        aShapeA->Signature()==1)
+    {
+        // The second argument must also be an AIS_Point
+        if (argc<5 || !GetMapOfAIS().IsBound2(argv[3]))
+        {
+          std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
+          return 1;
+        }
+        // Get shape from map
+        Handle(AIS_InteractiveObject) aShapeB =
           Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
-        // si B n'est pas un AIS_Point
-        if (theShapeB.IsNull() ||
-          (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
+        // If B is not an AIS_Point
+        if (aShapeB.IsNull() ||
+          (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
         {
-          di<<"vplane: error 2de object is expected to be an AIS_Point. "<<"\n";
+          std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
           return 1;
         }
-        // le troisieme objet est un AIS_Point
-        if (!GetMapOfAIS().IsBound2(argv[4]) ) {di<<"vplane: error 3de name doesn't exist in the GetMapOfAIS()."<<"\n";return 1; }
-        // on recupere la shape dans la map
-        Handle(AIS_InteractiveObject) theShapeC =
+        // The third object is an AIS_Point
+        if (!GetMapOfAIS().IsBound2(argv[4]) ) 
+        {
+          std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
+          return 1; 
+        }
+        // Get shape from map
+        Handle(AIS_InteractiveObject) aShapeC =
           Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4]));
-        // si C n'est pas un AIS_Point
-        if (theShapeC.IsNull() ||
-          (!(theShapeC->Type()==AIS_KOI_Datum && theShapeC->Signature()==1)))
+        // If C is not an AIS_Point
+        if (aShapeC.IsNull() ||
+          (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
         {
-          di<<"vplane: error 3de object is expected to be an AIS_Point. "<<"\n";
+          std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
           return 1;
         }
 
-        // Traitement des objets A,B,C
-        // Downcaste de AIS_IO en AIS_Point
-        Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA;
-        Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
-        Handle(AIS_Point) theAISPointC= *(Handle(AIS_Point)*)& theShapeC;
+        // Treatment of objects A, B, C
+        // Downcast an AIS_IO to AIS_Point
+        Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
+        Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
+        Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
 
-        Handle(Geom_Point ) myGeomPointA=  theAISPointA->Component();
-        Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)&  myGeomPointA);
-        //      Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
+        Handle(Geom_CartesianPoint ) aCartPointA = 
+          Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
 
-        Handle(Geom_Point ) myGeomPointB =  theAISPointB->Component();
-        Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)&  theAISPointB);
-        //      Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
+        Handle(Geom_CartesianPoint ) aCartPointB = 
+          Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
 
-        Handle(Geom_Point ) myGeomPointBC=  theAISPointC->Component();
-        Handle(Geom_CartesianPoint ) myCartPointC= *((Handle(Geom_CartesianPoint)*)&  theAISPointC);
-        //      Handle(Geom_CartesianPoint ) myCartPointC= *(Handle(Geom_CartesianPoint)*)& (theAISPointC->Component() ) ;
+        Handle(Geom_CartesianPoint ) aCartPointC = 
+          Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
 
-        // Verification que les 3 points sont bien differents.
-        if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
+        // Verification that the three points are different
+        if(abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
+           abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
+           abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
+        {
           // B=A
-          di<<"vplane error: same points"<<"\n";return 1;
+          std::cout<<"vplane error: same points"<<"\n";return 1;
         }
-        if (myCartPointC->X()==myCartPointA->X() && myCartPointC->Y()==myCartPointA->Y() && myCartPointC->Z()==myCartPointA->Z() ) {
+        if(abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
+           abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
+           abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
+        {
           // C=A
-          di<<"vplane error: same points"<<"\n";return 1;
+          std::cout<<"vplane error: same points"<<"\n";return 1;
         }
-        if (myCartPointC->X()==myCartPointB->X() && myCartPointC->Y()==myCartPointB->Y() && myCartPointC->Z()==myCartPointB->Z() ) {
+        if(abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
+           abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
+           abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
+        {
           // C=B
-          di<<"vplane error: same points"<<"\n";return 1;
+          std::cout<<"vplane error: same points"<<"\n";return 1;
         }
 
-        gp_Pnt A= myCartPointA->Pnt();
-        gp_Pnt B= myCartPointB->Pnt();
-        gp_Pnt C= myCartPointC->Pnt();
+        gp_Pnt A = aCartPointA->Pnt();
+        gp_Pnt B = aCartPointB->Pnt();
+        gp_Pnt C = aCartPointC->Pnt();
 
-        // Construction de l'AIS_Plane
+        // Construction of AIS_Plane
         GC_MakePlane MkPlane (A,B,C);
-        Handle(Geom_Plane) myGeomPlane = MkPlane.Value();
-        Handle(AIS_Plane)  myAISPlane = new AIS_Plane(myGeomPlane );
-        GetMapOfAIS().Bind (myAISPlane,name );
-        TheAISContext()->Display(myAISPlane);
+        Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
+        Handle(AIS_Plane)  anAISPlane = new AIS_Plane(aGeomPlane );
+        GetMapOfAIS().Bind (anAISPlane,aName );
+        TheAISContext()->Display(anAISPlane);
       }
 
-      // si le premier argument est un AIS_Axis 2
-      // creation d'un plan orthogonal a l'axe passant par un point
-    else if (theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==2 ) {
-      // le deuxieme argument doit etre un AIS_Point
+      // The first argument is an AIS_Axis
+      // Creation of a plane orthogonal to the axis through a point
+    else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
+      // The second argument should be an AIS_Point
       if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) )
       {
-        di<<"vplane: error 2de name doesn't exist in the GetMapOfAIS()."<<"\n";
+        std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
         return 1;
       }
-      // on recupere la shape dans la map
-      Handle(AIS_InteractiveObject) theShapeB =
+      // Get shape from map
+      Handle(AIS_InteractiveObject) aShapeB =
         Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
-      // si B n'est pas un AIS_Point
-      if (theShapeB.IsNull() ||
-        (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
+      // If B is not an AIS_Point
+      if (aShapeB.IsNull() ||
+        (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
       {
-        di<<"vplane: error 2de object is expected to be an AIS_Point. "<<"\n";
+        std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
         return 1;
       }
 
-      // Traitement des objets A et B
-      Handle(AIS_Axis) theAISAxisA= *(Handle(AIS_Axis)*)& theShapeA;
-      Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
-
-      Handle(Geom_Line ) myGeomLineA = theAISAxisA ->Component();
-      Handle(Geom_Point) myGeomPointB= theAISPointB->Component()  ;
+      // Treatment of objects A and B
+      Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
+      Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
 
-      gp_Ax1 myAxis= myGeomLineA->Position();
-      Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint )*)& myGeomPointB;
+      Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
+      Handle(Geom_Point) aGeomPointB = anAISPointB->Component()  ;
 
-      // Pas de moyens de verifier que le point B n'est pas sur l'axe
+      gp_Ax1 anAxis = aGeomLineA->Position();
+      Handle(Geom_CartesianPoint) aCartPointB = 
+        Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
 
-      gp_Dir D=myAxis.Direction();
-      gp_Pnt B= myCartPointB->Pnt();
+      gp_Dir D =anAxis.Direction();
+      gp_Pnt B = aCartPointB->Pnt();
 
-      // Construction de l'AIS_Plane
-      Handle(Geom_Plane) myGeomPlane= new Geom_Plane(B,D);
-      Handle(AIS_Plane)  myAISPlane = new AIS_Plane(myGeomPlane,B );
-      GetMapOfAIS().Bind (myAISPlane,name );
-      TheAISContext()->Display(myAISPlane);
+      // Construction of AIS_Plane
+      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);
 
     }
-    // Si le premier argument est un AIS_Plane 7
-    // Creation d'un Plan parallele a ce plan passant par le point
-    else if (theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==7 ) {
-      // le deuxieme argument doit etre un AISPoint
-      if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) ) {
-        di<<"vplane: error 2de name doesn't exist in the GetMapOfAIS()."<<"\n";
+    // The first argumnet is an AIS_Plane
+    // Creation of a plane parallel to the plane passing through the point
+    else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
+    {
+      // The second argument should be an AIS_Point
+      if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3]))
+      {
+        std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
         return 1;
       }
-      // on recupere la shape dans la map
-      Handle(AIS_InteractiveObject) theShapeB =
+      // Get shape from map
+      Handle(AIS_InteractiveObject) aShapeB =
         Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
-      // si B n'est pas un AIS_Point
-      if (theShapeB.IsNull() ||
-        (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
+      // B should be an AIS_Point
+      if (aShapeB.IsNull() ||
+         (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
       {
-        di<<"vplane: error 2de object is expected to be an AIS_Point. "<<"\n";
+        std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
         return 1;
       }
 
-      // Traitement des objets A et B
-      Handle(AIS_Plane) theAISPlaneA= *(Handle(AIS_Plane)*)& theShapeA;
-      Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
-
-      Handle (Geom_Plane) theNewGeomPlane= theAISPlaneA->Component();
-      Handle(Geom_Point) myGeomPointB= theAISPointB->Component()  ;
+      // Treatment of objects A and B
+      Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
+      Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
 
-      Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint )*)& myGeomPointB;
-      gp_Pnt B= myCartPointB->Pnt();
+      Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
+      Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
 
-      // Construction de l'AIS_Plane
-      Handle(AIS_Plane)  myAISPlane = new AIS_Plane(theNewGeomPlane,B );
-      GetMapOfAIS().Bind (myAISPlane,name );
-      TheAISContext()->Display(myAISPlane);
+      Handle(Geom_CartesianPoint) aCartPointB = 
+        Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
+      gp_Pnt B= aCartPointB->Pnt();
 
+      // Construction of an AIS_Plane
+      Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
+      GetMapOfAIS().Bind (anAISPlane, aName);
+      TheAISContext()->Display(anAISPlane);
+    }
+    // Error
+    else
+    {
+      std::cout<<"vplane: error 1st object is not an AIS\n";
+      return 1;
     }
-    // Sinon erreur
-    else {di<<"vplane: error 1st object is not an AIS. "<<"\n";return 1;}
-
   }
-
-  // Il n'y a pas d'arguments
-  else {
-
-    // Fonction vplane
-    // Teste le constructeur AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
-    if (!strcasecmp(argv[0] ,"vplane" ) ) {
+  // There are no arguments
+  else 
+  {
+    // Function vplane
+    // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
+    if (!strcasecmp(argv[0], "vplane"))
+    {
       TheAISContext()->OpenLocalContext();
-      myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
+      aCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
 
-      // Active les modes Vertex, Edge et Face
-      TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
-      TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
-      TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
-      di<<"Select a vertex, a face or an edge. "<<"\n";
+      // 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";
 
-      // Boucle d'attente waitpick.
+      // 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) ) { }
-      // fin de la boucle
+      // end of the loop
 
-      TopoDS_Shape ShapeA;
-      for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
-        ShapeA = TheAISContext()->SelectedShape();
+      TopoDS_Shape aShapeA;
+      for (TheAISContext()->InitSelected();
+           TheAISContext()->MoreSelected();
+           TheAISContext()->NextSelected())
+      {
+        aShapeA = TheAISContext()->SelectedShape();
       }
 
-      // ShapeA est un Vertex
-      if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
-        TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
-        di<<" Select an edge or a different vertex."<<"\n";
+      // aShapeA is a Vertex
+      if (aShapeA.ShapeType()==TopAbs_VERTEX )
+      {
+        TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
+        std::cout<<" Select an edge or a different vertex\n";
 
-        // Boucle d'attente waitpick.
+        // 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) ) { }
-        // fin de la boucle
+        // end of the loop
 
-        TopoDS_Shape ShapeB;
-        for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
-          ShapeB = TheAISContext()->SelectedShape();
+        TopoDS_Shape aShapeB;
+        for (TheAISContext()->InitSelected();
+          TheAISContext()->MoreSelected();
+          TheAISContext()->NextSelected())
+        {
+          aShapeB = TheAISContext()->SelectedShape();
         }
-        // ShapeB est un Vertex
-        if (ShapeB.ShapeType()==TopAbs_VERTEX ) {
-          // Si A et B sont le meme point
-          if (ShapeB.IsSame(ShapeA) ) {di<<" vplane: error, same points selected"<<"\n";return 1; }
-          TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
-          di<<" Select a different vertex."<<"\n";
+        // aShapeB is a Vertex
+        if (aShapeB.ShapeType()==TopAbs_VERTEX)
+        {
+          // A and B are the same
+          if (aShapeB.IsSame(aShapeA))
+          {
+            std::cout<<" vplane: error, same points selected\n";
+            return 1;
+          }
+          TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
+          std::cout<<" Select a different vertex\n";
 
-          // Boucle d'attente waitpick.
+          // 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) ) { }
-          // fin de la boucle
+          // end of the loop
 
-          TopoDS_Shape ShapeC;
-          for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
-            ShapeC = TheAISContext()->SelectedShape();
+          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;
           }
-          // ShapeC est aussi un vertex...
-          if (ShapeC.IsSame(ShapeA)||ShapeC.IsSame(ShapeB) ) {di<<" vplane: error, same points selected"<<"\n";return 1; }
-
-          // Fermeture du contexte local
-          TheAISContext()->CloseLocalContext(myCurrentIndex);
-
-          // Construction du plane
-          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 ) );
-          GC_MakePlane MkPlane(A,B,C);
-          Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
-          Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane );
-          GetMapOfAIS().Bind (myAISPlane ,name );
-          TheAISContext()->Display(myAISPlane);
 
+          // 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 est un edge
-        else  {
-          // il s'agit de verifier que le  vertex ShapeA n'est pas sur l'edge ShapeB
-          TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
-          TopoDS_Vertex VertA=TopoDS::Vertex(ShapeA);
-
-          BRepExtrema_ExtPC OrthoProj (VertA, EdgeB );
-          if (OrthoProj.SquareDistance(1)<1e-6 ) {
-            // Le vertex est sur l'edge
-            di<<" vplane: error point is on the edge."<<"\n";return 1;
-          }
-          else {
-            // le vertex n'appartient pes a l'edge on peut construire le plane
-            // Fermeture du contexte local
-            TheAISContext()->CloseLocalContext(myCurrentIndex);
-            // Construction du plane
-            gp_Pnt A=BRep_Tool::Pnt(VertA );
-            TopoDS_Vertex VBa,VBb;
-            TopExp::Vertices(EdgeB ,VBa ,VBb );
-            gp_Pnt Ba=BRep_Tool::Pnt(VBa);
-            gp_Pnt Bb=BRep_Tool::Pnt(VBb);
-            GC_MakePlane MkPlane (A,Ba,Bb);
-            Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
-            Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane );
-            GetMapOfAIS().Bind (myAISPlane ,name );
-            TheAISContext()->Display(myAISPlane);
+        // 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);
 
+          BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
+          if (OrthoProj.SquareDistance(1)<Precision::Approximation())
+          {
+            // The vertex is on the edge
+            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 A = BRep_Tool::Pnt(aVertA);
+            TopoDS_Vertex aVBa, aVBb;
+            TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
+            gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
+            gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
+            GC_MakePlane MkPlane (A, aBa, aBb);
+            Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
+            Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
+            GetMapOfAIS().Bind (anAISPlane, aName);
+            TheAISContext()->Display(anAISPlane);
           }
-
         }
-
       }
-      // ShapeA est un edge
-      else if (ShapeA.ShapeType()==TopAbs_EDGE ) {
-
-        TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
-        TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
-        di<<" Select a vertex that don't belong to the edge."<<"\n";
+      // aShapeA is an 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";
 
-        // Boucle d'attente waitpick.
+        // 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) ) { }
-        // fin de la boucle
+        // end of the loop
 
-        TopoDS_Shape ShapeB;
-        for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
-          ShapeB = TheAISContext()->SelectedShape();
+        TopoDS_Shape aShapeB;
+        for (TheAISContext()->InitSelected();
+             TheAISContext()->MoreSelected();
+             TheAISContext()->NextSelected())
+        {
+          aShapeB = TheAISContext()->SelectedShape();
         }
-        // ShapeB est forcement un Vertex
-        // On verifie que le vertex ShapeB n'est pas sur l'edge ShapeA
-        TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
-        TopoDS_Vertex VertB=TopoDS::Vertex(ShapeB);
-
-        BRepExtrema_ExtPC OrthoProj (VertB,EdgeA );
-        if (OrthoProj.SquareDistance(1)<1e-6) {
-          // Le vertex est sur l'edge
-          di<<" vplane: error point is on the edge."<<"\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);
+
+        BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
+        if (OrthoProj.SquareDistance(1)<Precision::Approximation())
+        {
+          // The vertex is on the edge
+          std::cout<<" vplane: error point is on the edge\n";
+          return 1;
         }
-        else {
-          // le vertex n'appartient pas a l'edge on peut construire le plane
-          // Fermeture du contexte local
-          TheAISContext()->CloseLocalContext(myCurrentIndex);
-          // Construction du plane
-          gp_Pnt B=BRep_Tool::Pnt(VertB );
-          TopoDS_Vertex VAa,VAb;
-          TopExp::Vertices(EdgeA ,VAa ,VAb );
-          gp_Pnt Aa=BRep_Tool::Pnt(VAa);
-          gp_Pnt Ab=BRep_Tool::Pnt(VAb);
+        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) theGeomPlane=MkPlane.Value();
-          Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane );
-          GetMapOfAIS().Bind (myAISPlane ,name );
-          TheAISContext()->Display(myAISPlane);
-
+          Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
+          Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
+          GetMapOfAIS().Bind (anAISPlane ,aName);
+          TheAISContext()->Display(anAISPlane);
         }
-
-
       }
-      // ShapeA est une Face
-      else {
-        // Fermeture du contexte local: Plus rien a selectionner
-        TheAISContext()->CloseLocalContext(myCurrentIndex);
-        // Construction du plane
-        TopoDS_Face myFace=TopoDS::Face(ShapeA);
-        BRepAdaptor_Surface mySurface (myFace, Standard_False );
-        if (mySurface.GetType()==GeomAbs_Plane ) {
-          gp_Pln myPlane=mySurface.Plane();
-          Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
-          Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane );
-          GetMapOfAIS().Bind (myAISPlane ,name );
-          TheAISContext()->Display(myAISPlane);
-
+      // aShapeA is a Face
+      else
+      {
+        // 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)
+        {
+          gp_Pln aPlane = aSurface.Plane();
+          Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
+          Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
+          GetMapOfAIS().Bind (anAISPlane, aName);
+          TheAISContext()->Display(anAISPlane);
         }
-        else {
-          di<<" vplane: error"<<"\n";return 1;
+        else
+        {
+          std::cout<<" vplane: error\n";
+          return 1;
         }
-
       }
-
     }
 
-    // Fonction vPlanePara
+    // Function vPlanePara
     // ===================
-    // teste le constructeur AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt )
-    else if (!strcasecmp(argv[0] ,"vplanepara" )) {
-
+    // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
+    else if (!strcasecmp(argv[0], "vplanepara"))
+    {
       TheAISContext()->OpenLocalContext();
-      myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
+      aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
 
-      // Active les modes Vertex et Face
-      TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
-      TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
-      di<<" Select a vertex or a face."<<"\n";
+      // 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";
 
-      // Boucle d'attente waitpick.
+      // 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) ) { }
-      // fin de la boucle
+      // end of the loop
 
-      TopoDS_Shape ShapeA;
-      for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
-        ShapeA = TheAISContext()->SelectedShape();
+      TopoDS_Shape aShapeA;
+      for (TheAISContext()->InitSelected();
+           TheAISContext()->MoreSelected();
+           TheAISContext()->NextSelected())
+      {
+        aShapeA = TheAISContext()->SelectedShape();
       }
 
-      if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
-        // ShapeA est un vertex
-        // On desactive le mode Vertex
-        TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1) );
-        di<<" Select a face."<<"\n";
+      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";
 
-        // Boucle d'attente waitpick.
+        // 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) ) { }
-        // fin de la boucle
+        // end of the loop
 
-        TopoDS_Shape ShapeB;
-        for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
-          // Le vertex ShapeA peut etre dans la Face ShapeB
-          ShapeB = TheAISContext()->SelectedShape();
+        TopoDS_Shape aShapeB;
+        for (TheAISContext()->InitSelected();
+             TheAISContext()->MoreSelected();
+             TheAISContext()->NextSelected())
+        {
+          // A vertex ShapeA can be on Face ShapeB
+          aShapeB = TheAISContext()->SelectedShape();
         }
 
-        // Fermeture du context local
-        TheAISContext()->CloseLocalContext(myCurrentIndex);
-
-        // Construction du plane
-        gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
-
-        TopoDS_Face myFace=TopoDS::Face(ShapeB);
-        BRepAdaptor_Surface mySurface (myFace, Standard_False );
-        if (mySurface.GetType()==GeomAbs_Plane ) {
-          gp_Pln myPlane=mySurface.Plane();
-          // construit un plan parallele a theGeomPlane passant par A
-          myPlane.SetLocation(A);
-          Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
-          Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,A );
-          GetMapOfAIS().Bind (myAISPlane ,name );
-          TheAISContext()->Display(myAISPlane);
+        // Close the local context
+        TheAISContext()->CloseLocalContext(aCurrentIndex);
 
+        // Construction of plane
+        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 {
-          di<<" vplane: error"<<"\n";return 1;
+        else
+        {
+          std::cout<<" vplanepara: error\n";
+          return 1;
         }
-
       }
-      else{
-        // ShapeA est une Face
-        // On desactive le mode Face
-        TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
-        di<<" Select a vertex."<<"\n";
+      else
+      {
+        // ShapeA is a Face
+        // Deactive the mode Face
+        TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
+        std::cout<<" Select a vertex\n";
 
-        // Boucle d'attente waitpick.
+        // 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) ) { }
-        // fin de la boucle
+        // end of the loop
 
-        TopoDS_Shape ShapeB;
-        for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
-          // Le vertex ShapeB peut etre dans la Face ShapeA
-          ShapeB = TheAISContext()->SelectedShape();
+        TopoDS_Shape aShapeB;
+        for (TheAISContext()->InitSelected();
+             TheAISContext()->MoreSelected();
+             TheAISContext()->NextSelected())
+        {
+          // A vertex ShapeB can be on Face ShapeA
+          aShapeB = TheAISContext()->SelectedShape();
         }
-        // Fermeture du context local
-        TheAISContext()->CloseLocalContext(myCurrentIndex);
-
-        // Construction du plane
-        gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB ) );
-
-        TopoDS_Face myFace=TopoDS::Face(ShapeA);
-        BRepAdaptor_Surface mySurface (myFace, Standard_False );
-        if (mySurface.GetType()==GeomAbs_Plane ) {
-          gp_Pln myPlane=mySurface.Plane();
-          myPlane.SetLocation(B);
-          Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
-          // construit un plan parallele a theGeomPlane passant par B
-          Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,B );
-          GetMapOfAIS().Bind (myAISPlane ,name );
-          TheAISContext()->Display(myAISPlane);
+        // 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 {
-          di<<" vplane: error"<<"\n";return 1;
+        else
+        {
+          std::cout<<" vplanepara: error"<<"\n";return 1;
         }
-
       }
-
     }
 
-    // Fonction vplaneortho
+    // Function vplaneortho
     // ====================
-    // teste le constructeur AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
-    else {
-
+    // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
+    else
+    {
       TheAISContext()->OpenLocalContext();
-      myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
+      aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
 
-      // Active les modes Edge et Face
-      TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
-      TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
-      di<<" Select a face and an edge coplanar."<<"\n";
+      // 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";
 
-      // Boucle d'attente waitpick.
+      // 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) ) { }
-      // fin de la boucle
+      // end of the loop
 
-      TopoDS_Shape ShapeA;
-      for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
-        ShapeA = TheAISContext()->SelectedShape();
+      TopoDS_Shape aShapeA;
+      for (TheAISContext()->InitSelected();
+           TheAISContext()->MoreSelected();
+           TheAISContext()->NextSelected())
+      {
+        aShapeA = TheAISContext()->SelectedShape();
       }
 
-      if (ShapeA.ShapeType()==TopAbs_EDGE ) {
-        // ShapeA est un edge, on desactive le mode edge...
-        TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
-        di<<" Select a face."<<"\n";
+      if (aShapeA.ShapeType()==TopAbs_EDGE )
+      {
+        // ShapeA is an edge, deactivate the mode Edge...
+        TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
+        std::cout<<" Select a face\n";
 
-        // Boucle d'attente waitpick.
+        // 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) ) { }
-        // fin de la boucle
+        // end of the loop
 
-        TopoDS_Shape ShapeB;
-        for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
-          // L'edge ShapeA peut etre dans la Face ShapeB
-          ShapeB = TheAISContext()->SelectedShape();
+        TopoDS_Shape aShapeB;
+        for (TheAISContext()->InitSelected();
+             TheAISContext()->MoreSelected();
+             TheAISContext()->NextSelected())
+        {
+          // Edge ShapeA can be on Face ShapeB
+          aShapeB = TheAISContext()->SelectedShape();
         }
 
-        // Fermeture du context local
-        TheAISContext()->CloseLocalContext(myCurrentIndex);
+        // Close the local context
+        TheAISContext()->CloseLocalContext(aCurrentIndex);
 
-        // Construction du plane
-        TopoDS_Edge  EdgeA=TopoDS::Edge(ShapeA);
-        TopoDS_Vertex VAa,VAb;
-        // vi
-        TopExp::Vertices(EdgeA ,VAa ,VAb );
-        gp_Pnt Aa=BRep_Tool::Pnt(VAa);
-        gp_Pnt Ab=BRep_Tool::Pnt(VAb);
-        gp_Vec ab  (Aa,Ab);
+        // 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 de mon axe de rotation
-        gp_Ax1 myRotAxis (Aa,Dab);
-
-        TopoDS_Face myFace=TopoDS::Face(ShapeB);
-        // Il faut imperativement que l'edge soit parallele a la face
-        // vi
-        BRepExtrema_ExtPF myHauteurA (VAa , myFace );
-        BRepExtrema_ExtPF myHauteurB (VAb , myFace );
-        // on compare les deux hauteurs a la tolerance pres
-        if ( fabs(sqrt(myHauteurA.SquareDistance(1)) - sqrt (myHauteurB.SquareDistance(1)) )>0.1 ) {
-          // l'edge n'est pas parallele a la face
-          di<<" vplaneOrtho error: l'edge n'est pas parallele a la face."<<"\n";return 1;
+        // 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;
         }
-        // l'edge est OK
-        BRepAdaptor_Surface mySurface (myFace, Standard_False );
-        if (mySurface.GetType()==GeomAbs_Plane ) {
-          gp_Pln myPlane=mySurface.Plane();
-          // On effectue une rotation d'1/2 tour autour de l'axe de rotation
-          myPlane.Rotate(myRotAxis , M_PI/2 );
-
-          Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
-          // construit un plan parallele a theGeomPlane contenant l'edgeA (De centre le milieu de l'edgeA)
-          gp_Pnt theMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
-          Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,theMiddle );
-          GetMapOfAIS().Bind (myAISPlane ,name );
-          TheAISContext()->Display(myAISPlane);
-
+        // 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 {
-          di<<" vplaneOrtho: error"<<"\n";return 1;
+        else
+        {
+          std::cout<<" vplaneortho: error\n";
+          return 1;
         }
-
       }
+      else
+      {
+        // ShapeA is a Face, deactive the mode Face.
+        TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
+        std::cout<<" Select an edge\n";
 
-      else {
-        // ShapeA est une Face, on desactive le mode face.
-        TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
-        di<<" Select an edge."<<"\n";
-
-        // Boucle d'attente waitpick.
+        // 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) ) { }
-        // fin de la boucle
+        // end of the loop
 
-        TopoDS_Shape ShapeB;
-        for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
-          // L'edge ShapeB peut etre dans la Face ShapeA
-          ShapeB = TheAISContext()->SelectedShape();
+        TopoDS_Shape aShapeB;
+        for (TheAISContext()->InitSelected();
+             TheAISContext()->MoreSelected();
+             TheAISContext()->NextSelected())
+        {
+          // Edge ShapeB can be on Face ShapeA
+          aShapeB = TheAISContext()->SelectedShape();
         }
-
-        // Fermeture du context local
-        TheAISContext()->CloseLocalContext(myCurrentIndex);
-
-        // Construction du plane
-        TopoDS_Edge  EdgeB=TopoDS::Edge(ShapeB);
-        TopoDS_Vertex VBa,VBb;
-        TopExp::Vertices(EdgeB ,VBa ,VBb );
-        gp_Pnt Ba=BRep_Tool::Pnt(VBa);
-        gp_Pnt Bb=BRep_Tool::Pnt(VBb);
-        gp_Vec ab  (Ba,Bb);
+        // 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 de mon axe de rotation
-        gp_Ax1 myRotAxis (Ba,Dab);
-
-        TopoDS_Face myFace=TopoDS::Face(ShapeA);
-        // Il faut imperativement que l'edge soit parallele a la face
-        BRepExtrema_ExtPF myHauteurA (VBa , myFace );
-        BRepExtrema_ExtPF myHauteurB (VBb , myFace );
-        // on compare les deux hauteurs a la tolerance pres
-        if ( fabs(sqrt(myHauteurA.SquareDistance(1)) - sqrt(myHauteurB.SquareDistance(1)) )>0.1 ) {
-          // l'edge n'est pas parallele a la face
-          di<<" vplaneOrtho error: l'edge n'est pas parallele a la face."<<"\n";return 1;
+        // 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;
         }
-        // l'edge est OK
-        BRepAdaptor_Surface mySurface (myFace, Standard_False );
-        if (mySurface.GetType()==GeomAbs_Plane ) {
-          gp_Pln myPlane=mySurface.Plane();
-          // On effectue une rotation d'1/2 tour autour de l'axe de rotation
-          myPlane.Rotate(myRotAxis , M_PI/2  );
-          Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
-          // construit un plan parallele a theGeomPlane contenant l'edgeA (De centre le milieu de l'edgeA)
-          gp_Pnt theMiddle ((Ba.X()+Bb.X() )/2 , (Ba.Y()+Bb.Y() )/2 , (Ba.Z()+Bb.Z() )/2 );
-          Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,theMiddle );
-          GetMapOfAIS().Bind (myAISPlane ,name );
-          TheAISContext()->Display(myAISPlane);
-
+        // 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 {
-          di<<" vplaneOrtho: error"<<"\n";return 1;
+        else
+        {
+          std::cout<<" vplaneortho: error\n";
+          return 1;
         }
-
       }
-
     }
-
   }
   return 0;
-
 }
 
 
@@ -1997,7 +2068,7 @@ static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const cha
     // 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";
+    std::cout << " Select a vertex or a face\n";
 
     // Wait for picking
     Standard_Integer argcc = 5;
@@ -2018,7 +2089,7 @@ static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const cha
     if (ShapeA.ShapeType() == TopAbs_VERTEX ) 
     {
       TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
-      std::cout << " Select a different vertex.\n";
+      std::cout << " Select a different vertex\n";
 
       TopoDS_Shape ShapeB;
       do 
@@ -2039,7 +2110,7 @@ static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const cha
       } while(ShapeB.IsSame(ShapeA) );
 
       // Selection of ShapeC
-      std::cout << " Select the last vertex.\n";
+      std::cout << " Select the last vertex\n";
       TopoDS_Shape ShapeC;
       do 
       {
@@ -2087,9 +2158,9 @@ static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const cha
 
     }
     // Shape is a face
-    else  
+    else
     {
-      std::cout << " Select a vertex (in your face).\n";
+      std::cout << " Select a vertex (in your face)\n";
       TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
 
       TopoDS_Shape ShapeB;
@@ -2158,6 +2229,7 @@ static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const cha
   return 0;
 }
 
+
 //===============================================================================================
 //function : VDrawText
 //author   : psn
@@ -3811,6 +3883,321 @@ static Standard_Integer VSetSelectionMode(Draw_Interpretor& di,
   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); 
+  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);
+
+  void ComputeSelection (  const Handle(SelectMgr_Selection)& theSelection, 
+                           const Standard_Integer theMode);
+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,
+                    const gp_Pnt& theP3)
+{
+  myPoint1 = theP1;
+  myPoint2 = theP2;
+  myPoint3 = theP3;
+}
+
+void Triangle::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+                       const Handle(Prs3d_Presentation)& thePresentation,
+                       const Standard_Integer theMode)
+{
+  thePresentation->Clear();
+
+  BRepBuilderAPI_MakeEdge anEdgeMaker1(myPoint1, myPoint2),
+                          anEdgeMaker2(myPoint2, myPoint3),
+                          anEdgeMaker3(myPoint3, myPoint1);
+
+  TopoDS_Edge anEdge1 = anEdgeMaker1.Edge(),
+              anEdge2 = anEdgeMaker2.Edge(),
+              anEdge3 = anEdgeMaker3.Edge();
+  if(anEdge1.IsNull() || anEdge2.IsNull() || anEdge3.IsNull())
+    return;
+
+  BRepBuilderAPI_MakeWire aWireMaker(anEdge1, anEdge2, anEdge3);
+  TopoDS_Wire aWire = aWireMaker.Wire();
+  if(aWire.IsNull()) return;
+
+  BRepBuilderAPI_MakeFace aFaceMaker(aWire);
+  TopoDS_Face aFace = aFaceMaker.Face();
+  if(aFace.IsNull()) return;
+
+  StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
+}
+
+void Triangle::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection, 
+                                const Standard_Integer theMode)
+{
+  Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
+  Handle(Select3D_SensitiveTriangle) aSensTriangle = 
+    new Select3D_SensitiveTriangle(anEntityOwner, myPoint1, myPoint2, myPoint3);
+  theSelection->Add(aSensTriangle);
+}
+
+//===========================================================================
+//function : VTriangle 
+//Draw arg : vtriangle Name PointName PointName PointName
+//purpose  : creates and displays Triangle
+//===========================================================================
+
+//function: IsPoint
+//purpose : checks if the object with theName is AIS_Point, 
+//          if yes initialize thePoint from MapOfAIS
+Standard_Boolean IsPoint (const TCollection_AsciiString& theName,
+                          Handle(AIS_Point)& thePoint)
+{
+  Handle(AIS_InteractiveObject) anObject = 
+    Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(theName));
+  if(anObject.IsNull() || 
+     anObject->Type() != AIS_KOI_Datum || 
+     anObject->Signature() != 1)
+  {
+    return Standard_False;
+  }
+  thePoint = Handle(AIS_Point)::DownCast(anObject);
+  if(thePoint.IsNull())
+    return Standard_False;
+  return Standard_True;
+}
+
+//function: IsMatch
+//purpose: checks if thePoint1 is equal to thePoint2
+Standard_Boolean IsMatch (const Handle(Geom_CartesianPoint)& thePoint1,
+                          const Handle(Geom_CartesianPoint)& thePoint2)
+{
+  if(abs(thePoint1->X()-thePoint2->X()) <= Precision::Confusion() &&
+     abs(thePoint1->Y()-thePoint2->Y()) <= Precision::Confusion() &&
+     abs(thePoint1->Z()-thePoint2->Z()) <= Precision::Confusion())
+  {
+    return Standard_True;
+  }
+  return Standard_False;
+}
+
+static Standard_Integer VTriangle (Draw_Interpretor& di,
+                                   Standard_Integer argc,
+                                   const char ** argv)
+{
+  // Check arguments
+  if (argc != 5)
+  {
+    std::cout<<"vtriangle error: expects 4 argumnets\n";
+    return 1; // TCL_ERROR
+  }
+
+  TheAISContext()->CloseAllContexts();
+
+  // Get and check values
+  TCollection_AsciiString aName(argv[1]);
+
+  Handle(AIS_Point) aPoint1, aPoint2, aPoint3;
+  if (!IsPoint(argv[2], aPoint1))
+  {
+    std::cout<<"vtriangle error: the 2nd argument must be a point\n";
+    return 1; // TCL_ERROR
+  }
+  if (!IsPoint(argv[3], aPoint2))
+  {
+    std::cout<<"vtriangle error: the 3d argument must be a point\n";
+    return 1; // TCL_ERROR
+  }
+  if (!IsPoint(argv[4], aPoint3))
+  {
+    std::cout<<"vtriangle error: the 4th argument must be a point\n";
+    return 1; // TCL_ERROR
+  }
+
+  // Check that points are different
+  Handle(Geom_CartesianPoint) aCartPoint1 = 
+    Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
+  Handle(Geom_CartesianPoint) aCartPoint2 = 
+    Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
+  // Test aPoint1 = aPoint2
+  if (IsMatch(aCartPoint1, aCartPoint2))
+  {
+    std::cout<<"vtriangle error: the 1st and the 2nd points are equal\n";
+    return 1; // TCL_ERROR
+  }
+  // Test aPoint2 = aPoint3
+  Handle(Geom_CartesianPoint) aCartPoint3 = 
+    Handle(Geom_CartesianPoint)::DownCast(aPoint3->Component());
+  if (IsMatch(aCartPoint2, aCartPoint3))
+  {
+    std::cout<<"vtriangle error: the 2nd and the 3d points are equal\n";
+    return 1; // TCL_ERROR
+  }
+  // Test aPoint3 = aPoint1
+  if (IsMatch(aCartPoint1, aCartPoint3))
+  {
+    std::cout<<"vtriangle error: the 1st and the 3d points are equal\n";
+    return 1; // TCL_ERROR
+  }
+
+  // Create triangle
+  Handle(Triangle) aTriangle = new Triangle(aCartPoint1->Pnt(),
+                                            aCartPoint2->Pnt(),
+                                            aCartPoint3->Pnt());
+
+  // Check if there is an object with given name
+  // and remove it from context
+  if (GetMapOfAIS().IsBound2(aName))
+  {
+    Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
+    Handle(AIS_InteractiveObject) anInterObj = 
+         Handle(AIS_InteractiveObject)::DownCast(anObj);
+    TheAISContext()->Remove(anInterObj, Standard_False);
+    GetMapOfAIS().UnBind2(aName);
+  }
+
+  // Bind triangle to its name
+  GetMapOfAIS().Bind(aTriangle, aName);
+
+  // Display triangle
+  TheAISContext()->Display(aTriangle);
+  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); 
+  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);
+
+  void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, 
+                         const Standard_Integer theMode);
+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)
+{
+  myPoint1 = thePnt1;
+  myPoint2 = thePnt2;
+}
+
+void SegmentObject::Compute (const Handle_PrsMgr_PresentationManager3d &thePresentationManager,
+                             const Handle_Prs3d_Presentation &thePresentation,
+                             const Standard_Integer theMode)
+{
+  thePresentation->Clear();
+  BRepBuilderAPI_MakeEdge anEdgeMaker(myPoint1, myPoint2);
+  TopoDS_Edge anEdge = anEdgeMaker.Edge();
+  if (anEdge.IsNull())
+    return;
+  BRepAdaptor_Curve aCurveAdaptor(anEdge);
+  StdPrs_Curve::Add(thePresentation, aCurveAdaptor, myDrawer);
+}
+
+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);
+  anArray->SetValue(1, myPoint1);
+  anArray->SetValue(2, myPoint2);
+  Handle(Select3D_SensitiveCurve) aSensCurve = 
+    new Select3D_SensitiveCurve(anOwner, anArray);
+  theSelection->Add(aSensCurve);
+}
+
+//=======================================================================
+//function  : VSegment
+//Draw args : vsegment Name PointName PointName
+//purpose   : creates and displays Segment
+//=======================================================================
+static Standard_Integer VSegment (Draw_Interpretor& di,
+                                  Standard_Integer argc,
+                                  const char ** argv)
+{
+  // Check arguments
+  if(argc!=4)
+  {
+    std::cout<<"vsegment error: expects 3 arguments\n";
+    return 1; // TCL_ERROR
+  }
+
+  TheAISContext()->CloseAllContexts();
+
+  // Get and check arguments
+  TCollection_AsciiString aName(argv[1]);
+  Handle(AIS_Point) aPoint1, aPoint2;
+  if (!IsPoint(argv[2], aPoint1))
+  {
+    std::cout<<"vsegment error: the 2nd argument should be a point\n";
+    return 1; // TCL_ERROR
+  }
+  if (!IsPoint(argv[3], aPoint2))
+  {
+    std::cout<<"vsegment error: the 3d argument should be a point\n";
+    return 1; // TCL_ERROR
+  }
+  //Check that points are different
+  Handle(Geom_CartesianPoint) aCartPoint1 = 
+    Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
+  Handle(Geom_CartesianPoint) aCartPoint2 = 
+    Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
+  if(IsMatch(aCartPoint1, aCartPoint2))
+  {
+    std::cout<<"vsegment error: equal points\n";
+    return 1; // TCL_ERROR
+  }
+  
+  // Create segment
+  Handle(SegmentObject) aSegment = new SegmentObject(aCartPoint1->Pnt(), aCartPoint2->Pnt());
+  // Check if there is an object with given name
+  // and remove it from context
+  if (GetMapOfAIS().IsBound2(aName))
+  {
+    Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
+    Handle(AIS_InteractiveObject) anInterObj = 
+         Handle(AIS_InteractiveObject)::DownCast(anObj);
+    TheAISContext()->Remove(anInterObj, Standard_False);
+    GetMapOfAIS().UnBind2(aName);
+  }
+
+  // Bind segment to its name
+  GetMapOfAIS().Bind(aSegment, aName);
+
+  // Display segment
+  TheAISContext()->Display(aSegment);
+  return 0;
+}
+
 //=======================================================================
 //function : ObjectsCommands
 //purpose  :
@@ -3907,4 +4294,12 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
   theCommands.Add("vselmode", 
     "vselmode : [object] mode On/Off (1/0)", 
     __FILE__, VSetSelectionMode, group);
+
+  theCommands.Add("vtriangle",
+    "vtriangle Name PointName PointName PointName", 
+    __FILE__, VTriangle,group);
+
+  theCommands.Add("vsegment",
+    "vsegment Name PointName PointName", 
+    __FILE__, VSegment,group);
 }