0023776: Redesign of MFC samples after V2d viewer removing
[occt.git] / samples / mfc / standard / 03_Viewer2d / src / Viewer2dDoc.cpp
index d01019c..d6edf55 100755 (executable)
@@ -2,33 +2,13 @@
 //
 
 #include "stdafx.h"
-
 #include "Viewer2dDoc.h"
-
-#include "OCC_BaseApp.h"
-
-#include <Aspect_ColorMap.hxx>
-#include <Aspect_MarkMapEntry.hxx>
-#include <Aspect_ColorMapEntry.hxx>
-#include <Aspect_GenericColorMap.hxx>
-
-#include <TopoDS_Shape.hxx>
-#include <TopoDS.hxx>
-
-#include <BRep_Builder.hxx>
-
-#include <BRepTools.hxx>
-
+#include "OCC_App.h"
 #include "Primitive\Sample2D_Markers.h"
-#include "Primitive\Sample2D_Line.h"
 #include "Primitive\Sample2D_Text.h"
 #include "Primitive\Sample2D_Face.h"
-#include "Primitive\Sample2D_Curve.h"
-#include "Primitive\Sample2D_Rectangle.h"
 #include "Primitive\Sample2D_Image.h"
 
-#include "PropertiesSheet.h"
-
 /////////////////////////////////////////////////////////////////////////////
 // CViewer2dDoc
 
@@ -36,12 +16,11 @@ IMPLEMENT_DYNCREATE(CViewer2dDoc, CDocument)
 
 BEGIN_MESSAGE_MAP(CViewer2dDoc, CDocument)
        //{{AFX_MSG_MAP(CViewer2dDoc)
-       ON_COMMAND(ID_MENU_CASCADE_PROPERTIES, OnBUTTONTest2DProperties)
        ON_COMMAND(ID_BUTTON_Test_Text, OnBUTTONTestText)
        ON_COMMAND(ID_BUTTON_Test_Markers, OnBUTTONTestMarkers)
        ON_COMMAND(ID_BUTTON_Test_Line, OnBUTTONTestLine)
        ON_COMMAND(ID_BUTTON_Erase, OnBUTTONErase)
-       ON_COMMAND(ID_BUTTON_Test_Face, OnBUTTONTestFase)
+       ON_COMMAND(ID_BUTTON_Test_Face, OnBUTTONTestFace)
        ON_COMMAND(ID_BUTTON_Test_Rect, OnBUTTONTestRect)
        ON_COMMAND(ID_BUTTON_Test_Curve, OnBUTTONTestCurve)
        ON_COMMAND(ID_BUTTON32793, OnBUTTONTestImage) // test image
@@ -76,356 +55,188 @@ void CViewer2dDoc::Dump(CDumpContext& dc) const
 /////////////////////////////////////////////////////////////////////////////
 // CViewer2dDoc commands
 
-void CViewer2dDoc::OnBUTTONTest2DProperties() 
-{
-// TODO: Add your command handler code here
-  CPropertiesSheet aDial;
-  aDial.SetViewer(my2DViewer);
-  aDial.DoModal();
-}
-
-//=================================================================
-//=================================================================
-//=================================================================
-
 void CViewer2dDoc::OnBUTTONErase() 
 {
-   myAISInteractiveContext2D->EraseAll();
-  // Update Get information to update Result dialog
-
-  UINT anID=ID_BUTTON_Erase;
-  TCollection_AsciiString Message("\
-call :    \n\
-   myAISInteractiveContext2D->EraseAll();");
-
-  // Update The Result Dialog
-  UpdateResultDialog(anID,Message);
+  if(myAISContext->HasOpenedContext())
+    myAISContext->CloseAllContexts(); 
+  myAISContext->EraseAll();
 }
 
-
-
 void CViewer2dDoc::OnBUTTONTestText() 
 {
Standard_Integer color=1;
int aColor= 1;
  Standard_Real j;
  for (j=15;j<=20;j++)
   {
-    TCollection_AsciiString Text("font 0 scale ");Text+=j/20;
+    TCollection_AsciiString Text("font 0 scale ");Text+=j/20.0;
     Handle (Sample2D_Text) aText  = 
         new Sample2D_Text(Text,
-                       0,15*(j-15),      //  anX  , anY 
-                       Aspect_TOT_SOLID,//  aType  
-                       20.0*M_PI/180 ,            //  anAngle  
-                       0.0 ,            //  aSlant  
-                       color++,               //  aColorIndex  
-                       0,               //  aFontIndex  
-                       j/20,                //  aScale 
-                       Standard_False,  // aIsUnderline
-                       Standard_False,   // aIsZoomable
-                       Graphic2d_TOA_LEFT); // aTypeOfAlignment
-    myAISInteractiveContext2D->Display(aText,            // object
-                                       Standard_False);  // Redraw
-    if (color == my2DViewer->ColorMap()->Size()) color =1;
+                       gp_Pnt(0.0,15.0*(j-15.0),0.0),    //  thePosition
+                       Aspect_TOT_SOLID,                 //  theType  
+                       10.0*M_PI,                        //  theAngle    
+                       (Quantity_NameOfColor)(aColor++), //  theColor  
+                       Font_FA_Regular,                  //  theFontAspect  
+                       "Courier",                        //  theFont
+                       j,                                // theScale
+                       Graphic3d_HTA_LEFT,
+                       Graphic3d_VTA_BOTTOM,
+                       Standard_False);                  // aIsZoomable
+
+    myAISContext->Display(aText, Standard_False);
   }
 
-  for (int j=5;j<=10;j+=1)
+  for (j=10;j<=15;j++)
   {
-    TCollection_AsciiString Text("font 1 scale ");Text+=j/10;
+    TCollection_AsciiString Text("font 1 scale ");Text+=j/10.0;
     Handle (Sample2D_Text) aText  = 
         new Sample2D_Text(Text,
-                       80,15*(j-5),  //  anX  , anY 
-                       Aspect_TOT_SOLID,//  aType  
-                       0.0 ,            //  anAngle  
-                       0.0 ,            //  aSlant  
-                       color++,         //  aColorIndex  
-                       1,               //  aFontIndex  
-                       j/10,                //  aScale 
-                       Standard_True,  // aIsUnderline
-                       Standard_True,   // aIsZoomable
-                       Graphic2d_TOA_CENTER); // aTypeOfAlignment
-
-    myAISInteractiveContext2D->Display(aText,            // object
-                                       Standard_False);  // Redraw
-    if (color == my2DViewer->ColorMap()->Size()) color =1;
+                       gp_Pnt(80.,15.0*(j-10.0),0.0),     //  thePosition
+                       Aspect_TOT_SOLID,                  //  theType  
+                       0.0,                               //  theAngle    
+                       (Quantity_NameOfColor)(aColor++),  //  theColor  
+                       Font_FA_BoldItalic,                //  theFontAspect  
+                       "Cambria",                         //  theFont
+                       j*2,                               // theScale
+                       Graphic3d_HTA_LEFT,
+                       Graphic3d_VTA_BOTTOM,
+                       Standard_False);                   // aIsZoomable
+
+    myAISContext->Display(aText, Standard_False);
   }
-    
-  for (j=5;j<=10;j+=1)
+  aColor = 1;
+  for (j=5;j<=10;j++)
   {
-    TCollection_AsciiString Text("font 2 scale ");Text+=j/10;
+    TCollection_AsciiString Text("font 2 scale ");Text+=j/10.0; 
     Handle (Sample2D_Text) aText  = 
         new Sample2D_Text(Text,
-                       140,15*(j-5),  //  anX  , anY 
-                       Aspect_TOT_SOLID,//  aType  
-                       0.0 ,            //  anAngle  
-                       0.0 ,            //  aSlant  
-                       color++,         //  aColorIndex  
-                       2,               //  aFontIndex  
-                       j/10,               //  aScale 
-                       Standard_False,  // aIsUnderline
-                       Standard_True,   // aIsZoomable
-                       Graphic2d_TOA_TOPLEFT); // aTypeOfAlignment
-    myAISInteractiveContext2D->Display(aText,            // object
-                                       Standard_False);  // Redraw
-    if (color == my2DViewer->ColorMap()->Size()) color =1;
+                       gp_Pnt(140.0,15.0*(j-5.0),0.0),   //  thePosition
+                       Aspect_TOT_SOLID,                 //  theType  
+                       0.0,                              //  theAngle    
+                       (Quantity_NameOfColor)(aColor++), //  theColor  
+                       Font_FA_Bold,                     //  theFontAspect  
+                       "Arial",                          //  theFont
+                       j*2,                              // theScale
+                       Graphic3d_HTA_LEFT,
+                       Graphic3d_VTA_BOTTOM,
+                       Standard_False);                  // aIsZoomable
+    myAISContext->Display(aText,Standard_False);
   }
-    
-  for (j=10;j<=15;j+=1)
+for (j=10;j<=15;j++)
   {
-    TCollection_AsciiString Text("font 3 scale ");Text+=j/10;
-    Handle (Sample2D_Text) aText  = 
+    TCollection_AsciiString Text("font 3 scale ");Text+=j/10.0;
+        Handle (Sample2D_Text) aText  = 
         new Sample2D_Text(Text,
-                       260,15*(j-10),      //  anX  , anY 
-                       Aspect_TOT_SOLID,//  aType  
-                       0 ,            //  anAngle  
-                       0.0 ,            //  aSlant  
-                       color++,               //  aColorIndex  
-                       3,               //  aFontIndex  
-                       j/10,                //  aScale 
-                       Standard_False,  // aIsUnderline
-                       Standard_False,   // aIsZoomable
-                       Graphic2d_TOA_LEFT); // aTypeOfAlignment
-    myAISInteractiveContext2D->Display(aText,            // object
-                                       Standard_False);  // Redraw
-    if (color == my2DViewer->ColorMap()->Size()) color =1;
+                       gp_Pnt(200.0,15.0*(j-10.0),0.0), //  thePosition
+                       Aspect_TOT_SOLID,                //  theType  
+                       0.0,                             //  theAngle    
+                       (Quantity_NameOfColor)(aColor++),//  theColor  
+                       Font_FA_Italic,                  //  theFontAspect  
+                       "Georgia",                       //  theFont
+                       j*2,                             // theScale
+                       Graphic3d_HTA_LEFT,
+                       Graphic3d_VTA_BOTTOM,
+                       Standard_False);                 // aIsZoomable
+        myAISContext->Display(aText,Standard_False);
   }
 
   FitAll2DViews(Standard_True); // Update Viewer
-  // Update Get information to update Result dialog
-  UINT anID=ID_BUTTON_Test_Text;
-  TCollection_AsciiString Message("  \
-create a set of Sample2D_Text,display it and declare selectable :    \n\
------------------------------------------------------------------------------- \n\
-    Handle (Sample2D_Text) aText;                          \n\
-    // aText = new ...                                            \n\
-   myAISInteractiveContext2D->Display(aText,            // object     \n\
-                                      Standard_False);  // Redraw       \n\
------------------------------------------------------------------------------- \n\
-   after that the system call the SetContext Method for the display,\n\
------------------------------------------------------------------------------- \n\
-                                                                  \n\
-void Sample2D_Text::SetContext(const Handle(AIS2D_InteractiveContext)& theContext) \n\
-{ \n\
-  AIS2D_InteractiveObject::SetContext(theContext); \n\
-\n\
-  Handle(Graphic2d_Text) text; \n\
-  text = new Graphic2d_Text(this, myText, myX, myY, myAngle,myTypeOfText,myScale); \n\
-  text->SetFontIndex  (myFontIndex); \n\
-  text->SetColorIndex (myColorIndex); \n\
-  text->SetSlant      (mySlant); \n\
-  text->SetUnderline  (myIsUnderline); \n\
-  text->SetZoomable   (myIsZoomable); \n\
-  text->SetAlignment  (myTypeOfAlignment); \n\
-}");
-
-  // Update The Result Dialog
-  UpdateResultDialog(anID,Message);
 }
 
 
 void CViewer2dDoc::OnBUTTONTestMarkers() 
 {
-    {    // generic Markers
-      Standard_Integer MaxIndex = my2DViewer->MarkMap()->Size();
-      
-         for (int i=1;i<=MaxIndex;i++)
-      {
-        Standard_Integer EntryNumber =  (my2DViewer->MarkMap()->Entry(i)).Index () ;
-
-        Handle (Sample2D_Markers) Marker  = 
-          new Sample2D_Markers(EntryNumber, // generic marker index
-                               10*i,0,// display point
-                               5,5, // size
-                               0); // angle in radian
-        myAISInteractiveContext2D->Display(Marker,            // object
-                                           Standard_False);  // Redraw
-
-      }
-      for (int i=1;i<=MaxIndex;i++)
-      {
-        Standard_Integer EntryNumber =  (my2DViewer->MarkMap()->Entry(i)).Index () ;
-        Handle (Sample2D_Markers) Marker  = 
-          new Sample2D_Markers(EntryNumber, // generic marker index
-                               10*i,10,// display point
-                               5,5, // size
-                               20*M_PI/180); // angle in radian
-        myAISInteractiveContext2D->Display(Marker,            // object
-                                           Standard_False);  // Redraw
-      }
-    }
-
-    
-    {  // a Circle Marker 
-      Handle (Sample2D_Markers) Marker  = 
-        new Sample2D_Markers(10,20,// reference point
-                             0,0, // display point
-                             2); // radius
-      myAISInteractiveContext2D->Display(Marker,            // object
-                                         Standard_False);  // Redraw
-
-    }
-    
-    {  // an ellips Marker 
-      Handle (Sample2D_Markers) Marker  = 
-        new Sample2D_Markers(20,20, // reference point
-                             0,0,  // display point
-                             3,2,    // major, minor radius
-                             20*M_PI/180); // angle
-      myAISInteractiveContext2D->Display(Marker,            // object
-                                         Standard_False);  // Redraw
-    }
-
-    {  // a polyline  Marker 
-
-      Graphic2d_Array1OfVertex myListVertex(1,6);
-      myListVertex(1)=Graphic2d_Vertex(0.,0.);
-      myListVertex(2)=Graphic2d_Vertex(0.,5.);
-      myListVertex(3)=Graphic2d_Vertex(10.,0.);
-      myListVertex(4)=Graphic2d_Vertex(10.,5.);
-      myListVertex(5)=Graphic2d_Vertex(20.,0.);
-      myListVertex(6)=Graphic2d_Vertex(20.,5.);
-
-      Handle (Sample2D_Markers) Marker  = 
-        new Sample2D_Markers(30,20, // reference point
-                             myListVertex); 
-      myAISInteractiveContext2D->Display(Marker,            // object
-                                         Standard_True);  // Redraw
+  // generic Markers
+  Standard_Integer aColor = 20;
+  for (int i=1;i<=2;i++)
+  {
+    Handle (Sample2D_Markers) aMarker  = 
+      new Sample2D_Markers(10+5,5*i,Aspect_TOM_POINT,Quantity_NOC_YELLOW,2.0);
+    myAISContext->Display(aMarker, Standard_False);
+  }
+  for (int i=1;i<=2;i++)
+  {
+    Handle (Sample2D_Markers) aMarker  = 
+      new Sample2D_Markers(10+10,5*i,Aspect_TOM_O,(Quantity_NameOfColor)(aColor++));
+    myAISContext->Display(aMarker, Standard_False);
+  }
+  for (int i=1;i<=2;i++)
+  {
+    Handle (Sample2D_Markers) aMarker  = 
+      new Sample2D_Markers(10+15,5*i,Aspect_TOM_O_PLUS,(Quantity_NameOfColor)(aColor++));
+    myAISContext->Display(aMarker, Standard_False);
+  }
+  for (int i=1;i<=2;i++)
+  {
+    Handle (Sample2D_Markers) aMarker  = 
+      new Sample2D_Markers(10+20,5*i,Aspect_TOM_BALL,(Quantity_NameOfColor)(aColor++));
+    myAISContext->Display(aMarker, Standard_False);
+  }
+  for (int i=1;i<=2;i++)
+  {
 
-    }
+    Handle (Sample2D_Markers) aMarker  = 
+      new Sample2D_Markers(10+25,5*i,Aspect_TOM_STAR,(Quantity_NameOfColor)(aColor++));
+    myAISContext->Display(aMarker, Standard_False);
+  }
+  for (int i=1;i<=2;i++)
+  {
+    Handle (Sample2D_Markers) aMarker  = 
+      new Sample2D_Markers(10+30,5*i,Aspect_TOM_O_X,(Quantity_NameOfColor)(aColor++));
+    myAISContext->Display(aMarker, Standard_False);
+  }
 
   FitAll2DViews(Standard_False); // Update Viewer
-  // Update Get information to update Result dialog
-
-  UINT anID=ID_BUTTON_Test_Markers;
-  TCollection_AsciiString Message(" \
-create a set of Sample2D_Markers and display it :\n\
----------------------------------------------------\n\
-    {\n\
-      Standard_Integer MaxIndex = my2DViewer->MarkMap()->Size();\n\
-      for (int i=1;i<=MaxIndex;i++) {\n\
-        Standard_Integer EntryNumber =  (my2DViewer->MarkMap()->Entry(10)).Index () ;\n\
-        Handle (Sample2D_Markers) Marker  = \n\
-          new Sample2D_Markers(EntryNumber, // generic marker index\n\
-                               10*i,0,// display point\n\
-                               5,5, // size\n\
-                               0); // angle in radian\n\
-        myAISInteractiveContext2D->Display(Marker,            // object\n\
-                                           Standard_False);  // Redraw\n\
-\n\
-    }\n\
-  //...\n\
-\n\
-   after that the system call the SetContext Methods :                    \n\
-\n\
-void Sample2D_Markers::SetContext(const Handle(AIS2D_InteractiveContext)& theContext)  \n\
-{ \n\
- AIS2D_InteractiveObject::SetContext(theContext); \n\
- if (myCurrentTypeOfMarker == 2D_CTOM_Generic) \n\
-   if ( myIndex == 0 ) {\n\
-     Handle(Graphic2d_Marker) aMarker=  \n\
-        new Graphic2d_Marker(this, \n\
-        myXPosition ,myYPosition); \n\
-   }\n\
-   else {\n\
-     Handle(Graphic2d_Marker) aMarker=  \n\
-        new Graphic2d_Marker(this,myIndex, \n\
-        myXPosition ,myYPosition, \n\
-        myWidth,myHeight,myAngle); \n\
-   }\n\
- \n\
- if (myCurrentTypeOfMarker == 2D_CTOM_Polyline) \n\
-   Handle(Graphic2d_PolylineMarker) aMarker=  \n\
-      new Graphic2d_PolylineMarker(this, \n\
-      myXPosition,myYPosition, \n\
-      myListVertex); \n\
- \n\
- if (myCurrentTypeOfMarker == 2D_CTOM_Circle) \n\
-   Handle(Graphic2d_CircleMarker) aMarker=  \n\
-      new Graphic2d_CircleMarker(this, \n\
-      myXPosition,myYPosition, \n\
-      myX ,myY,myRadius  ); \n\
- \n\
- if (myCurrentTypeOfMarker == 2D_CTOM_Ellips) \n\
-   Handle(Graphic2d_EllipsMarker) aMarker=  \n\
-      new Graphic2d_EllipsMarker(this, \n\
-      myXPosition,myYPosition, \n\
-      myX,myY, \n\
-      myMajorRadius,myMinorRadius, \n\
-      myAngle ); \n\
- \n\
-} \n\n");
-  // Update The Result Dialog
-  UpdateResultDialog(anID,Message);
 }
-
-
 void CViewer2dDoc::OnBUTTONTestLine() 
 {
-  //Handle(ISessionSample2D_Line) aLine = new ISessionSample2D_Line();
-  Handle(Sample2D_Line) aLine = new Sample2D_Line();
-
-//  myInteractiveContext2D->Display(aLine,           // object
-//                                Standard_True);  // Redraw
-
-  myAISInteractiveContext2D->Display(aLine,           // object
-                                     Standard_True);  // Redraw
+  for (int i=0;i<=13;++i)
+   for (int j=0;j<=5;++j)
+   {
+      //set of rectangles here
+      TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(gp_Pnt(10*i,10*j,0.), gp_Pnt(10*i+7,10*j,0.));
+      TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(gp_Pnt(10*i+7,10*j,0.), gp_Pnt(10*i+7,10*j+5,0.));
+      TopoDS_Edge E3 = BRepBuilderAPI_MakeEdge(gp_Pnt(10*i+7,10*j+5,0.), gp_Pnt(10*i,10*j+5,0.));
+      TopoDS_Edge E4 = BRepBuilderAPI_MakeEdge(gp_Pnt(10*i,10*j+5,0.), gp_Pnt(10*i,10*j,0.));
+      TopoDS_Wire W = BRepBuilderAPI_MakeWire(E1,E2,E3,E4);
+      TopoDS_Face F = BRepBuilderAPI_MakeFace(W);
+      Handle_AIS_Shape aRect = new AIS_Shape(F);
+      //set attributes of boundaries
+      Handle(AIS_Drawer) aDrawer = new AIS_Drawer();
+      Handle(Prs3d_LineAspect) aLineAttrib = 
+        new Prs3d_LineAspect(Quantity_NOC_YELLOW,
+        (Aspect_TypeOfLine)(Aspect_TOL_SOLID+j),1);
+      aDrawer->SetFaceBoundaryAspect(aLineAttrib);
+      aDrawer->SetFaceBoundaryDraw(Standard_True);
+      aRect->SetAttributes(aDrawer);
+      
+      myAISContext->SetDisplayMode(aRect,1);
+      myAISContext->SetColor(aRect,(Quantity_NameOfColor)(Quantity_NOC_CADETBLUE+2*i),Standard_False);
+           myAISContext->SetMaterial(aRect,Graphic3d_NOM_PLASTIC,Standard_False);
+      myAISContext->Display(aRect, Standard_False);
 
-  FitAll2DViews(Standard_False); // Update Viewer
-  // Update Get information to update Result dialog
+   }
+   this->FitAll2DViews(Standard_True);
+}
 
-  UINT anID=ID_BUTTON_Test_Line;
-  TCollection_AsciiString Message(" \
-create a Sample2D_Line and display it :    \n\
------------------------------------------------------------------------------- \n\
-  Handle(Sample2D_Line) aLine = new Sample2D_Line();\n\
-  myAISInteractiveContext2D->Display(aLine,           // object\n\
-                                     Standard_True);  // Redraw\n\
-  FitAll2DViews(Standard_False); // Update Viewer\n\
------------------------------------------------------------------------------- \n\
-   after that the system call the SetContext Methods :                    \n\
------------------------------------------------------------------------------- \n\
-void Sample2D_Line::SetContext(const Handle(AIS2D_InteractiveContext)& theContext) \n\
-{\n\
-  AIS2D_InteractiveObject::SetContext(theContext); \n\
-\n\
-  Handle(Prs2d_AspectLine) aLineAspect = new Prs2d_AspectLine;  \n\
-  aLineAspect->SetTypeOfFill(Graphic2d_TOPF_FILLED); \n\
-  aLineAspect->SetWidthIndex(0); \n\
-\n\
- for (int i=0;i<=13;i++)\n\
-  for (int j=0;j<=5;j++)\n\
-  {\n\
-   {\n\
-    Graphic2d_Array1OfVertex anArrayVertex(1,5);\n\
-    anArrayVertex(1)=Graphic2d_Vertex(20.*i,10.*j+0);\n\
-    anArrayVertex(2)=Graphic2d_Vertex(20.*i+10,10.*j+0);\n\
-    anArrayVertex(3)=Graphic2d_Vertex(20.*i+10,10.*j+5);\n\
-    anArrayVertex(4)=Graphic2d_Vertex(20.*i,10.*j+5);\n\
-    anArrayVertex(5)=Graphic2d_Vertex(20.*i,10.*j+0);\n\
-    Handle(Graphic2d_Polyline) aPolyline = \n\
-        new Graphic2d_Polyline(this,anArrayVertex);\n\
-\n\
-    SetAspect(aLineAspect, aPolyline); \n\
-\n\
-    aPolyline->SetInteriorColorIndex(i); // to use with Graphic2d_TOPF_FILLED \n\
-    aPolyline->SetTypeIndex(j);          // type of the polyline \n\
-   }\n\
- }\n}");
 
-  // Update The Result Dialog
-  UpdateResultDialog(anID,Message);
-}
+#include <AIS_Trihedron.hxx>
+#include <Geom_Axis2Placement.hxx>
 
-void CViewer2dDoc::OnBUTTONTestFase()
+void CViewer2dDoc::OnBUTTONTestFace()
 {
-  myAISInteractiveContext2D->EraseAll();
+  //erase all
+  if(myAISContext->HasOpenedContext())
+    myAISContext->CloseAllContexts();
+  myAISContext->EraseAll();
+
   CFileDialog dlg(TRUE,
-                  NULL,
-                  NULL,
-                  OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
-                  "BRep Files (*.brep)|*.brep; ||", 
-                  NULL );
+    NULL,
+    NULL,
+    OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
+    "BRep Files (*.brep)|*.brep; ||", 
+    NULL );
 
-  CString initdir(((OCC_BaseApp*) AfxGetApp())->GetInitDataDir());
+  CString initdir(((OCC_App*) AfxGetApp())->GetInitDataDir());
   initdir += "\\Data";
 
   dlg.m_ofn.lpstrInitialDir = initdir;
@@ -436,375 +247,71 @@ void CViewer2dDoc::OnBUTTONTestFase()
     CString filename = dlg.GetPathName();
     Standard_CString aFileName = (Standard_CString)(LPCTSTR)filename;
 
-    TopoDS_Shape aFace;
-       BRep_Builder aBuilder;
-       Standard_Boolean result = BRepTools::Read(aFace,aFileName,aBuilder);
-
-       if(aFace.IsNull() || aFace.ShapeType() != TopAbs_FACE) {
-               AfxMessageBox("The shape must be not a null Face");
-               return;
-       }
-
-//     Handle(ISessionSample2D_Face) aDisplayableFace = new ISessionSample2D_Face( TopoDS::Face(aFace)  );
-       Handle(Sample2D_Face) aDisplayableFace = new Sample2D_Face( TopoDS::Face(aFace)  );
-
-    myAISInteractiveContext2D->Display(aDisplayableFace,  // object
-                                       Standard_True);     // Redraw
+    TopoDS_Shape aFaceShape;
+    BRep_Builder aBuilder;
+    Standard_Boolean result = BRepTools::Read(aFaceShape,aFileName,aBuilder);
 
-    Handle(Aspect_ColorMap) aColorMap = my2DViewer->ColorMap();
-    Aspect_ColorMapEntry aFORWARDColorMapEntry  = aColorMap->FindEntry(aDisplayableFace->FORWARDColorIndex());
-    Aspect_ColorMapEntry aREVERSEDColorMapEntry = aColorMap->FindEntry(aDisplayableFace->REVERSEDColorIndex());
-    Aspect_ColorMapEntry aINTERNALColorMapEntry = aColorMap->FindEntry(aDisplayableFace->INTERNALColorIndex());
-    Aspect_ColorMapEntry aEXTERNALColorMapEntry = aColorMap->FindEntry(aDisplayableFace->EXTERNALColorIndex());
-
-    Quantity_Color TheFORWARDColor  =  aFORWARDColorMapEntry.Color();
-    Quantity_Color TheREVERSEDColor =  aREVERSEDColorMapEntry.Color();
-    Quantity_Color TheINTERNALColor =  aINTERNALColorMapEntry.Color();
-    Quantity_Color TheEXTERNALColor =  aEXTERNALColorMapEntry.Color();
-
-    Standard_CString FORWARDStringName (Quantity_Color::StringName(TheFORWARDColor.Name()));
-    Standard_CString REVERSEDStringName(Quantity_Color::StringName(TheREVERSEDColor.Name()));
-    Standard_CString INTERNALStringName(Quantity_Color::StringName(TheINTERNALColor.Name()));
-    Standard_CString EXTERNALStringName(Quantity_Color::StringName(TheEXTERNALColor.Name()));
-    FitAll2DViews(Standard_False); // Update Viewer
-  // Update Get information to update Result dialog
+    if(aFaceShape.IsNull() || aFaceShape.ShapeType() != TopAbs_FACE) 
+    {
+      AfxMessageBox("The shape must be not a null Face");
+      return;
+    }
 
-    UINT anID=ID_BUTTON_Test_Face;
-    TCollection_AsciiString Message("Forward is \t");
-    Message +=  FORWARDStringName;
-    Message += "\nReversed is \t";
-    Message +=  REVERSEDStringName;
-    Message += "\nInternal is \t";
-    Message +=  INTERNALStringName;
-    Message += "\nExternal is \t";
-    Message +=  EXTERNALStringName;
-    Message += "\n";
-    Message += "\
------------------------------------------------------------------------------- \n\
-create an Sample2D_Face and display it     \n\
------------------------------------------------------------------------------- \n\
-//...\n\
-       TopoDS_Face aFace;\n\
-       BRep_Builder aBuilder;\n\
-       Standard_Boolean result = BRepTools::Read(aFace,aFileName,aBuilder);\n\
-\n\
-       Handle(ISessionSample2D_Face) aDisplayableFace = new ISessionSample2D_Face( aFace  );\n\
-       myInteractiveContext2D->Display(aDisplayableFace,  // object\n\
-                                                                       Standard_True);     // Redraw\n\
-//...\n\
------------------------------------------------------------------------------- \n\
-void _Face::SetContext() \n\
-{\n\
-    Handle(Prs2d_AspectLine) aLineAspect_FORWARD = new Prs2d_AspectLine;  \n\
-    aLineAspect_FORWARD->SetTypeOfFill(Graphic2d_TOPF_EMPTY);\n\
-       aLineAspect_FORWARD->SetTypeIndex(myTypeIndex); \n\
-    aLineAspect_FORWARD->SetWidthIndex(myWidthIndex);\n\
-    aLineAspect_FORWARD->SetColorIndex(myFORWARDColorIndex);\n\
-\n\
-    Handle(Prs2d_AspectLine) aLineAspect_REVERSED = new Prs2d_AspectLine;  \n\
-    aLineAspect_REVERSED->SetTypeOfFill(Graphic2d_TOPF_EMPTY);\n\
-    aLineAspect_REVERSED->SetTypeIndex(myTypeIndex);\n\
-    aLineAspect_REVERSED->SetWidthIndex(myWidthIndex);\n\
-    aLineAspect_REVERSED->SetColorIndex(myREVERSEDColorIndex);\n\
-\n\
-    Handle(Prs2d_AspectLine) aLineAspect_INTERNAL = new Prs2d_AspectLine;  \n\
-    aLineAspect_INTERNAL->SetTypeOfFill(Graphic2d_TOPF_EMPTY);\n\
-    aLineAspect_INTERNAL->SetTypeIndex(myTypeIndex);\n\
-    aLineAspect_INTERNAL->SetWidthIndex(myWidthIndex);\n\
-    aLineAspect_INTERNAL->SetColorIndex(myINTERNALColorIndex);\n\
-\n\
-    Handle(Prs2d_AspectLine) aLineAspect_EXTERNAL = new Prs2d_AspectLine;  \n\
-    aLineAspect_EXTERNAL->SetTypeOfFill(Graphic2d_TOPF_EMPTY);\n\
-    aLineAspect_EXTERNAL->SetTypeIndex(myTypeIndex);\n\
-    aLineAspect_EXTERNAL->SetWidthIndex(myWidthIndex);\n\
-    aLineAspect_EXTERNAL->SetColorIndex(myEXTERNALColorIndex);";
+    TopoDS_Face aFace = TopoDS::Face(aFaceShape);
+    Handle(Sample2D_Face) anAISFace = new Sample2D_Face(aFaceShape);
+    myAISContext->Display(anAISFace,Standard_True);
+    //activate selection mode for edges selection
+    myAISContext->OpenLocalContext();
+    myAISContext->Activate(anAISFace,2);
 
-Message +="\
-\n\
-//pcurves of the face \n\
-\n\
-    Handle(Graphic2d_SetOfCurves) segment_FORWARD;\n\
-    segment_FORWARD = new Graphic2d_SetOfCurves(this); \n\
-\n\
-    Handle(Graphic2d_SetOfCurves) segment_REVERSED;\n\
-    segment_REVERSED = new Graphic2d_SetOfCurves(this); \n\
-\n\
-    Handle(Graphic2d_SetOfCurves) segment_INTERNAL;\n\
-    segment_INTERNAL = new Graphic2d_SetOfCurves(this); \n\
-\n\
-    Handle(Graphic2d_SetOfCurves) segment_EXTERNAL;\n\
-    segment_EXTERNAL = new Graphic2d_SetOfCurves(this); \n\
-\n\
-    Standard_Real f,l;\n\
-    Standard_Integer i = 1;\n\
-    myFace.Orientation(TopAbs_FORWARD);\n\
-    TopExp_Explorer ex(myFace,TopAbs_EDGE);\n\
-    while (ex.More()) {\n\
-      const Handle(Geom2d_Curve) Curve = BRep_Tool::CurveOnSurface\n\
-                (TopoDS::Edge(ex.Current()),TopoDS::Face(myFace),f,l);\n\
-\n\
-      Handle(Geom2d_TrimmedCurve) c = new Geom2d_TrimmedCurve(Curve,f,l);\n\
-";
-Message += "\
-      if (c.IsNull())\n\
-      {\n\
-        // null curve --> EDGE have a null lenght\n\
-        // --> get first and last Vertices\n\
-        TopoDS_Edge CurrentEdge= TopoDS::Edge(ex.Current());\n\
-\n\
-        TopoDS_Vertex FirstVertex = TopExp::FirstVertex(CurrentEdge);\n\
-        TopoDS_Vertex LastVertex  = TopExp::LastVertex(CurrentEdge);\n\
-\n\
-        if (FirstVertex != LastVertex)\n\
-          Standard_Failure::Raise(\"Null Edge pcurve But different vertices\");\n\
-\n\
-         gp_Pnt aPnt  = BRep_Tool::Pnt(FirstVertex);\n\
-\n\
-        Handle(Graphic2d_Marker) aMarker= \n\
-           new Graphic2d_Marker(this,myMarkerIndex,\n\
-                                aPnt.X() ,aPnt.Y(),\n\
-                                myMarkerWidth,myMarkerHeight,0);\n\
-\n\
-";
-Message += "\
-        switch (ex.Current().Orientation())\n\
-        {\n\
-          case TopAbs_FORWARD:  aMarker->SetColorIndex (myFORWARDColorIndex);   break;\n\
-          case TopAbs_REVERSED: aMarker->SetColorIndex (myREVERSEDColorIndex);  break;\n\
-          case TopAbs_INTERNAL: aMarker->SetColorIndex (myINTERNALColorIndex);  break;\n\
-          case TopAbs_EXTERNAL: aMarker->SetColorIndex (myEXTERNALColorIndex);  break;\n\
-          default : break;\n\
-        }\n\
-        ex.Next();\n\
-      }\n\
-      else\n\
-      {\n\
-        // Display the Curve\n\
-        // display the orientation\n\
-\n\
-        gp_Pnt2d p1,p2;\n\
-        gp_Vec2d v;\n\
-        c->D1(l,p1,v);\n\
-        Graphic2d_Array1OfVertex aListVertex(1,3);\n\
-        if (v.Magnitude() > gp::Resolution()) {\n\
-            Standard_Real L = 2;\n\
-            Standard_Real H = 1;\n\
-            gp_Dir2d d(v);\n\
-            p2.SetCoord(- L*d.X() - H*d.Y(),- L*d.Y() + H*d.X());\n\
-            aListVertex(1)=Graphic2d_Vertex(p2.X(),p2.Y());\n\
-            \n\
-            p2.SetCoord(- L*d.X() + H*d.Y(),- L*d.Y() - H*d.X());\n\
-            aListVertex(2)=Graphic2d_Vertex(0.,0.);\n\
-            aListVertex(3)=Graphic2d_Vertex(p2.X(),p2.Y()); \n\
-        }\n\
-";
-Message += "\
-\n\
-        Handle(Graphic2d_PolylineMarker) aMarker= \n\
-          new Graphic2d_PolylineMarker(this,p1.X(),p1.Y(),aListVertex);\n\
-\n\
-               switch (ex.Current().Orientation()) \n\
-        {\n\
-        case TopAbs_FORWARD: {\n\
-             segment_FORWARD->Add(c); \n\
-             SetAspect(aLineAspect_FORWARD, aMarker);  \n\
-             break;\n\
-        }\n\
-        case TopAbs_REVERSED: {\n\
-             segment_REVERSED->Add(c); \n\
-             SetAspect(aLineAspect_REVERSED, aMarker); \n\
-             break; \n\
-        } \n\
-        case TopAbs_INTERNAL: { \n\
-             segment_INTERNAL->Add(c); \n\
-             SetAspect(aLineAspect_INTERNAL, aMarker); \n\
-             break; \n\
-        } \n\
-        case TopAbs_EXTERNAL: { \n\
-             segment_EXTERNAL->Add(c); \n\
-             SetAspect(aLineAspect_EXTERNAL, aMarker); \n\
-             break; \n\
-        } \n\
-        default : break; \n\
-        } \n\
-      }\n\
-      ex.Next();\n\
-    }\n\
-\n\
-       SetAspect(aLineAspect_FORWARD, segment_FORWARD);\n\
-       SetAspect(aLineAspect_REVERSED, segment_REVERSED);\n\
-       SetAspect(aLineAspect_INTERNAL, segment_INTERNAL);\n\
-       SetAspect(aLineAspect_EXTERNAL, segment_EXTERNAL);\n\
-\n\
-}\n\
-";
+    FitAll2DViews(Standard_False);
 
-  // Update The Result Dialog
-  UpdateResultDialog(anID,Message);
   }
-
 }
 
-void CViewer2dDoc::OnBUTTONTestRect()
-{
-   Handle (Sample2D_Rectangle) aRectangle = new Sample2D_Rectangle(
-                                                0,0,       // display point
-                                             50,80,     // size
-                                             20*M_PI/180); // angle in radian
 
-   aRectangle->SetHighlightMode(AIS2D_TOD_OBJECT);
-   myAISInteractiveContext2D->Display(aRectangle, Standard_False);  // Display rectangle
-  
 
-   Handle (Sample2D_Rectangle) aRectangle2 = new Sample2D_Rectangle(
-                                              80,0,       // display point
-                                           50,90,     // size
-                                           20*M_PI/180); // angle in radian
-
-   aRectangle2->SetHighlightMode(AIS2D_TOD_ELEMENT);
-   myAISInteractiveContext2D->Display(aRectangle2);  // Display rectangle
+void CViewer2dDoc::OnBUTTONTestRect()
+{
+  //First rectangle
+  TopoDS_Edge E11 = BRepBuilderAPI_MakeEdge(gp_Pnt(40.,0.,0.), gp_Pnt(82.5,25.,0.));
+       TopoDS_Edge E12 = BRepBuilderAPI_MakeEdge(gp_Pnt(82.5,25.,0.), gp_Pnt(42.5,93.,0.));
+       TopoDS_Edge E13 = BRepBuilderAPI_MakeEdge(gp_Pnt(42.5,93.,0.), gp_Pnt(0.,68.,0.));
+  TopoDS_Edge E14 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.,68.,0.), gp_Pnt(40.,0.,0.));
+       TopoDS_Wire W1 = BRepBuilderAPI_MakeWire(E11,E12,E13,E14);
+  Handle_AIS_Shape aRect1 = new AIS_Shape(W1); 
+  myAISContext->Display(aRect1);
+  myAISContext->SetColor(aRect1,Quantity_NOC_YELLOW);
   
+  //Second rectangle
+  TopoDS_Edge E21 = BRepBuilderAPI_MakeEdge(gp_Pnt(110.,0.,0.), gp_Pnt(152.5,25.,0.));
+       TopoDS_Edge E22 = BRepBuilderAPI_MakeEdge(gp_Pnt(152.5,25.,0.), gp_Pnt(112.5,93.,0.));
+       TopoDS_Edge E23 = BRepBuilderAPI_MakeEdge(gp_Pnt(112.5,93.,0.), gp_Pnt(70.,68.,0.));
+  TopoDS_Edge E24 = BRepBuilderAPI_MakeEdge(gp_Pnt(70.,68.,0.), gp_Pnt(110.,0.,0.));
+       TopoDS_Wire W2 = BRepBuilderAPI_MakeWire(E21,E22,E23,E24);
+  Handle_AIS_Shape aRect2 = new AIS_Shape(W2); 
+  myAISContext->Display(aRect2);
+  myAISContext->SetColor(aRect2,Quantity_NOC_YELLOW);
+  myAISContext->SetSelectionMode(aRect2,2);
 
-   FitAll2DViews(Standard_False); // Update Viewer
-
-  // Update Get information to update Result dialog
-
-  UINT anID=ID_BUTTON_Test_Rect;
-  TCollection_AsciiString Message(" \
-create a two of Sample2D_Rectangle and display it :    \n\
------------------------------------------------------------------------------- \n\
-  {                                                                    \n\
-   Handle (Sample2D_Rectangle) aRectangle  =                   \n\
-        new Sample2D_Rectangle(0,0,       // display point \n\
-                                             50,80,     // size              \n\
-                                             20*PI180); // angle in radian  \n\
-\n\
-   aRectangle->SetHighlightMode(AIS2D_TOD_OBJECT); \n\
-   myASIInteractiveContext2D->Display(aRectangle, Standard_False);  // Display rectangle  \n\
-  }                                                              \n\
-  {                                                                 \n\
-  Handle (Sample2D_Rectangle) aRectangle  =  \n\
-        new Sample2D_Rectangle(80,0,       // display point \n\
-                                             50,90,     // size  \n\
-                                             20*PI180); // angle in radian \n\
-\n\
-  aRectangle2->SetHighlightMode(AIS2D_TOD_ELEMENT);  //Set selection sub elements    \n\
-  myAISInteractiveContext2D->Display(aRectangle);  // Dispaly rectangle    \n\
-  }\n\
-  FitAll2DViews(Standard_False); // Update Viewer\n\
-\n\
----------------------------------------------------------------- \n\
-   after that the system call the SetContext Methods :                    \n\
----------------------------------------------------------------- \n\
-void Sample2D_Rectangle::SetContext(const Handle(AIS2D_InteractiveContext)& theContext) \n\
-{\n\
-\n\
-  AIS2D_InteractiveObject::SetContext(theContext); \n\
-\n\
-  // add the polyline in the representation, for all modes\n\
-  Handle(Graphic2d_Polyline) ThePolyline;\n\
-  ThePolyline = new Graphic2d_Polyline(this,myArray1OfVertex );\n\
-  ThePolyline->SetColorIndex ( 1 );\n\
-  ThePolyline->SetWidthIndex ( 1 );\n\
-  ThePolyline->SetTypeIndex  ( 1 );\n\
-\n");
-Message+= "\
------------------------------------------------------------------------------- \n\
-   after on WM_MOUSEMOVE event call a method MoveTo of AIS2D_InteractiveContext  \n\
-   and on WM_LBUTTONUP enent call a method Select of AIS2D_InteractiveContext\n\
-------------------------------------------------------------------------------";
-
-  // Update The Result Dialog
-  UpdateResultDialog(anID,Message);
+  FitAll2DViews(Standard_True); // Update Viewer
 }
 
 void CViewer2dDoc::OnBUTTONTestCurve()
 {
-  Standard_Integer color = 1;
-  Standard_Integer type = 1;
-  Standard_Integer width = 1;
-
-  for (Standard_Integer i=0;i<=5;i++) 
-   for (Standard_Integer j=0;j<=5;j++)
-   {
-     Handle_Geom2d_Curve aNewCurve  = GCE2d_MakeSegment ( gp_Pnt2d(10*i,10*j) , 
-                                                          gp_Pnt2d(10*i+5,10*j+10 )).Value() ; 
-     Handle(Sample2D_Curve) aCurve   = new Sample2D_Curve(aNewCurve);
-
-        aCurve->SetTypeOfLineIndex(type++);
-        aCurve->SetWidthOfLineIndex(width++);
-     aCurve->SetColorIndex(color++);
-     
-        aCurve->SetHighlightMode(AIS2D_TOD_OBJECT);
-
-        myAISInteractiveContext2D->Display(aCurve,            // object
-                                        Standard_False);  // Redraw
-
-     if (type == 5) type = 1; 
-     if (width == 9) width = 1;       
-     if (color == 2) color = 3;  // 2 = noir !!
-     if (color == 13) color = 1; // 13 = nbcolor by default
-   }
-
-  FitAll2DViews(Standard_True); // Update Viewer
-  // Update Get information to update Result dialog
-
-  UINT anID=ID_BUTTON_Test_Curve;
-  TCollection_AsciiString Message(" \
-create a set of Sample2D_Curve and display it:    \n\
------------------------------------------------------------------------------- \n\
-  Standard_Integer color = 1;\n\
-  Standard_Integer type = 1; \n\
-  Standard_Integer width = 1; \n\
-\n\
-  for (Standard_Integer i=0;i<=5;i++) \n\
-   for (Standard_Integer j=0;j<=5;j++)\n\
-   {\n\
-     Handle_Geom2d_Curve aNewCurve  = GCE2d_MakeSegment ( gp_Pnt2d(10*i,10*j) , \n\
-                                                          gp_Pnt2d(10*i+5,10*j+10 )).Value() ; \n\
-     Handle(Sample2D_Curve) aCurve   = new Sample2D_Curve(aNewCurve);\n\
-     aCurve->SetColorIndex(color++);\n\
-     aCurve->SetTypeOfLineIndex(type++);\n\
-     aCurve->SetWidthOfLineIndex(width++);\n\
-     aCurve->SetHighlightMode(AIS2D_TOD_OBJECT); \n\
- \n\
-     myAISInteractiveContext2D->Display(aCurve,            // object\n\
-                                        Standard_False);   // Redraw\n\
-     if (type == 5) type = 1; //Max number of types + 1\n\
-     if (width == 9) width = 1;  \n\
-     if (color == 2) color =3;  // 2 = noir !!\n\
-     if (color == 13) color =1; // 13 = nbcolor by default\n\
-   }\n\
------------------------------------------------------------------------------- \n\
-   after that the system call the SetContext Methods :                    \n\
------------------------------------------------------------------------------- \n");
-Message += "\
-void Sample2D_Curve::Compute(const Handle(AIS2D_InteractiveContext)& theContext) \n\
-{\n\
-  AIS2D_InteractiveObject::SetContext(theContext); \n\
-\n\
-  Handle(Prs2d_AspectLine) aLineAspect = new Prs2d_AspectLine;  \n\
-  aLineAspect->SetTypeOfFill(Graphic2d_TOPF_FILLED); \n\
-\n\
-  \n\
-  Handle(Graphic2d_SetOfCurves) segment;\n\
-  segment = new Graphic2d_SetOfCurves(this);\n\
-\n\
-  segment->Add(myGeom2dCurve);\n\
-  \n\
-\n\
-  segment->SetColorIndex (myColorIndex);\n\
-  segment->SetWidthIndex (myWidthOfLineIndex );\n\
-  segment->SetTypeIndex  (myTypeOfLineIndex  );\n\
-  \n\
-  SetAspect(aLineAspect); \n\
-}\n\
-\n";
-
-  // Update The Result Dialog
-  UpdateResultDialog(anID,Message);
+  for(int i=0;i<=5;++i)
+    for(int j=0;j<=5;++j)
+    {
+      Handle(Geom_Point) aStart = new Geom_CartesianPoint(gp_Pnt(10*i,10*j,0.));
+      Handle(Geom_Point) anEnd = new Geom_CartesianPoint(gp_Pnt(10*i+5,10*j+10,0.));
+      Handle(AIS_Line) aLine = new AIS_Line(aStart,anEnd);
+      Handle(Prs3d_LineAspect) aLineAttrib = 
+        new Prs3d_LineAspect((Quantity_NameOfColor)(Quantity_NOC_CADETBLUE+2*i+2*j),
+        (Aspect_TypeOfLine)((Aspect_TOL_DASH+i+j)%5),2+i+j);
+      aLine->Attributes()->SetLineAspect(aLineAttrib);
+      myAISContext->Display(aLine,Standard_False);   
+    }
+   FitAll2DViews(Standard_True);
 }
 
 void CViewer2dDoc::OnBUTTONTestImage()
@@ -813,78 +320,32 @@ void CViewer2dDoc::OnBUTTONTestImage()
                   NULL,
                   NULL,
                   OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
-                  "image Files (*.bmp , *.gif , *.xwd)|*.bmp; *.gif; *.xwd; | all files (*.*)|*.*;||", 
+                  "image Files (*.bmp , *.gif , *.jpeg, *.bmp, *.ppm, *.exr, *.tga, *.tiff, *.pgf, *.pdf)"
+                  "|*.bmp; *.gif; *.jpeg;  *.bmp; *.ppm; *.exr; *.tga; *.tiff; *.pgf; *.pdf;"
+                  "| all files (*.*)|*.*;||",  
                   NULL );
 
-  CString initdir(((OCC_BaseApp*) AfxGetApp())->GetInitDataDir());
+  CString initdir(((OCC_App*) AfxGetApp())->GetInitDataDir());
   initdir += "\\Data";
 
   dlg.m_ofn.lpstrInitialDir = initdir;
-  
-  if (dlg.DoModal() == IDOK) 
+  if(dlg.DoModal() == IDOK)
   {
     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
     CString filename = dlg.GetPathName();
-    Standard_CString aFileName = (Standard_CString)(LPCTSTR)filename;
-    Handle(Sample2D_Image) anImage = new Sample2D_Image(aFileName);
+    TCollection_AsciiString aFileName(filename);
 
-    anImage->SetCoord(0,0) ;
-    anImage->SetTypeOfPlacement(Aspect_CP_Center) ;
-       anImage->SetIsZoomable(Standard_True);
+    //erase viewer
+    if(myAISContext->HasOpenedContext())
+      myAISContext->CloseAllContexts();
+    myAISContext->EraseAll();
 
-    myAISInteractiveContext2D->Display(anImage,           // object
-                                    Standard_True);  // Redraw
-  
-  // Update Get information to update Result dialog
-
-  UINT anID=ID_BUTTON_Test_Image;
-  TCollection_AsciiString Message(" \
-create a Sample2D_Image and display it :    \n\
------------------------------------------------------------------------------- \n\
-  CFileDialog dlg(TRUE,   \n\
-                       NULL,                                         \n\
-                        NULL,                         \n\
-                        OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,\n\
-                  \"image Files (*.bmp , *.gif , *.xwd)|*.bmp; *.gif; *.xwd; | all files (*.*)|*.*;||\", \n\
-                             NULL );\n\
-  if (dlg.DoModal() == IDOK) \n\
-  {\n\
-    SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));\n\
-    CString filename = dlg.GetPathName();\n\
-    Standard_CString aFileName = (Standard_CString)(LPCTSTR)filename;\n\
-    Handle(Sample2D_Image) anImage = new Sample2D_Image(aFileName);\n\
-\n\
-    anImage->SetCoord(0,0) ;\n\
-    anImage->SetTypeOfPlacement(Aspect_CP_Center) ;\n\
-       anImage->SetIsZoomable(Standard_True);\n\
-\n\
-    myAISInteractiveContext2D->Display(anImage,           // Display object\n\
-                                         Standard_True);  \n\
-  }\n\
------------------------------------------------------------------------------- \n\
-   after that the system call the SetContext method :                    \n\
------------------------------------------------------------------------------- \n\
-void Sample2D_Image::SetContext(const Handle(AIS2D_InteractiveContext) theContext)) \n\
-{\n\
-  //Set AIS2D_InteractiveContext and default Graphic2d_View \n\
-  AIS2D_InteractiveObject::SetContext(theContext); \n\
-  Graphic2d_GraphicObject::SetView(theContext->CurrentViewer()->View()); \n\
-\n\
-  Handle(GraphicSample2D_ImageFile) aGraphic2dImageFile =\n\
-    new GraphicSample2D_ImageFile (aGrObj,\n\
-                                        myFile,\n\
-                                        myX, \n\
-                                        myY,\n\
-                                        myDx,\n\
-                                        myDy,\n\
-                                        myTypeOfPlacement,\n\
-                                        myScale); \n\
-  if (myIsZoomable)\n\
-    aGraphic2dImageFile->SetZoomable(Standard_True);\n\
-}\n\n");
-
-  // Update The Result Dialog
-  UpdateResultDialog(filename,Message);
+    Handle(Sample2D_Image) anImage = new Sample2D_Image(aFileName);
+    anImage->SetCoord(40,50) ;
+    anImage->SetScale(1.0);
+    myAISContext->Display(anImage, Standard_False);
+    myAISContext->SetDisplayMode(anImage,3,Standard_False);
+    FitAll2DViews(Standard_True);
   }
 }
 
@@ -894,148 +355,75 @@ void CViewer2dDoc::OnBUTTONMultipleImage()
                   NULL,
                   NULL,
                   OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
-                  "image Files (*.bmp , *.gif , *.xwd)|*.bmp; *.gif; *.xwd; | all files (*.*)|*.*;||", 
+                  "image Files (*.bmp , *.gif , *.jpeg, *.bmp, *.ppm, *.exr, *.tga, *.tiff, *.pgf, *.pdf)"
+                  "|*.bmp; *.gif; *.jpeg;  *.bmp; *.ppm; *.exr; *.tga; *.tiff; *.pgf; *.pdf;"
+                  "| all files (*.*)|*.*;||",  
                   NULL );
 
-  CString initdir(((OCC_BaseApp*) AfxGetApp())->GetInitDataDir());
+  CString initdir(((OCC_App*) AfxGetApp())->GetInitDataDir());
   initdir += "\\Data";
 
   dlg.m_ofn.lpstrInitialDir = initdir;
-  
 
   if (dlg.DoModal() == IDOK) 
   {
     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
     CString filename = dlg.GetPathName();
-    Standard_CString aFileName = (Standard_CString)(LPCTSTR)filename;
+    TCollection_AsciiString aFileName(filename);
+    //erase viewer
+    if(myAISContext->HasOpenedContext())
+      myAISContext->CloseAllContexts();
+    myAISContext->EraseAll();
+    //create images
     {  // 1
     Handle(Sample2D_Image) anImage = new Sample2D_Image(aFileName);
-
     anImage->SetCoord(40,50) ;
-    anImage->SetTypeOfPlacement(Aspect_CP_SouthEast) ;
-       anImage->SetIsZoomable(Standard_True);
-
-    myAISInteractiveContext2D->Display(anImage,           // Display object
-                                       Standard_False);  
+    anImage->SetScale(0.5);
+    myAISContext->Display(anImage, Standard_False);
+    myAISContext->SetDisplayMode(anImage,3,Standard_False);
     }
     {  // 2
     Handle(Sample2D_Image) anImage = new Sample2D_Image(aFileName);
 
-    anImage->SetCoord(50,50) ;
-    anImage->SetTypeOfPlacement(Aspect_CP_SouthWest) ;
-       anImage->SetIsZoomable(Standard_True);
-
-    myAISInteractiveContext2D->Display(anImage,           // Display object
-                                       Standard_False);     
+    anImage->SetCoord(100,50) ;
+         anImage->SetScale(0.9);
+    myAISContext->Display(anImage,Standard_False);
+    myAISContext->SetDisplayMode(anImage,3,Standard_False);
     }
     {  // 3
     Handle(Sample2D_Image) anImage = new Sample2D_Image(aFileName);
-
     anImage->SetCoord(40,40) ;
-    anImage->SetTypeOfPlacement(Aspect_CP_NorthEast) ;
-       anImage->SetIsZoomable(Standard_True);
-
-    myAISInteractiveContext2D->Display(anImage,           // Display object
-                                       Standard_False);  
+    anImage->SetScale(0.3);
+    myAISContext->Display(anImage, Standard_False);
+    myAISContext->SetDisplayMode(anImage,3,Standard_False);
     }
     {  // 4
     Handle(Sample2D_Image) anImage = new Sample2D_Image(aFileName);
-
     anImage->SetCoord(50,40) ;
-    anImage->SetTypeOfPlacement(Aspect_CP_NorthWest) ;
-       anImage->SetIsZoomable(Standard_True);
-
-    myAISInteractiveContext2D->Display(anImage,           // Display object
-                                       Standard_False);  
+    myAISContext->Display(anImage, Standard_False);
+    myAISContext->SetDisplayMode(anImage,3,Standard_False);
     }
     {  // 5
     Handle(Sample2D_Image) anImage = new Sample2D_Image(aFileName);
-
     anImage->SetCoord(80,45) ;
-    anImage->SetTypeOfPlacement(Aspect_CP_West) ;
-       anImage->SetIsZoomable(Standard_True);
-       anImage->SetScale(2);
-    myAISInteractiveContext2D->Display(anImage,           // Display object
-                                       Standard_False);  
+         anImage->SetScale(2);
+    myAISContext->Display(anImage,  Standard_False);
+    myAISContext->SetDisplayMode(anImage,3,Standard_False);
     }
-    {  // 6 : Non Zoomable 
+    {  // 6
     Handle(Sample2D_Image) anImage = new Sample2D_Image(aFileName);
-
     anImage->SetCoord(20,-20) ;
-    anImage->SetTypeOfPlacement(Aspect_CP_NorthWest) ;
-
-       anImage->SetIsZoomable(Standard_False);
-
-    myAISInteractiveContext2D->Display(anImage,           // Display object
-                                       Standard_False);  
+    myAISContext->Display(anImage, Standard_False);
+    myAISContext->SetDisplayMode(anImage,3,Standard_False);
     }
-    {  // 7 : Non Zoomable
+    {  // 7
     Handle(Sample2D_Image) anImage = new Sample2D_Image(aFileName);
-
     anImage->SetCoord(0,0) ;
-    anImage->SetOffset(60,-20) ; // new zoom center
-    anImage->SetTypeOfPlacement(Aspect_CP_NorthWest) ;
-       anImage->SetScale(0.5);
-       anImage->SetIsZoomable(Standard_False);
-
-    myAISInteractiveContext2D->Display(anImage,           // Display object
-                                       Standard_False);  
+         anImage->SetScale(0.5);
+    myAISContext->Display(anImage, Standard_False);
+    myAISContext->SetDisplayMode(anImage,3,Standard_False);
     }
     FitAll2DViews(Standard_True); // Update Viewer
-  // Update Get information to update Result dialog
-
-  UINT anID=ID_BUTTON_Test_MultiImages;
-  TCollection_AsciiString Message(" \
-create a set of Sample2D_Image and display it :    \n\
------------------------------------------------------------------------------- \n\
-  CFileDialog dlg(TRUE, \n\
-                  NULL, \n\
-                  NULL, \n\
-                  OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, \n\
-                  \"image Files (*.bmp , *.gif , *.xwd)|*.bmp; *.gif; *.xwd; | all files (*.*)|*.*;||\", \n\
-                  NULL ); \n\
-  if (dlg.DoModal() == IDOK)  \n\
-  { \n\
-    SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT)); \n\
-    CString filename = dlg.GetPathName(); \n\
-    Standard_CString aFileName = (Standard_CString)(LPCTSTR)filename; \n\
-    {  // 1 \n\
-    Handle(Sample2D_Image) anImage = new Sample2D_Image(aFileName); \n\
- \n\
-    anImage->SetCoord(40,50) ; \n\
-    anImage->SetTypeOfPlacement(Aspect_CP_SouthEast) ; \n\
-       anImage->SetIsZoomable(Standard_True); \n\
- \n\
-    myAISInteractiveContext2D->Display(anImage,           // object \n\
-                                        Standard_False);  // Redraw \n\
-    } \n\
-    //... \n\
-} \n\
------------------------------------------------------------------------------- \n\
-   after that the system call the SetContext Methods :                    \n\
------------------------------------------------------------------------------- \n\
-void Sample2D_Image::SetContext(const Handle(AIS2D_InteractiveContext) theContext)) \n\
-{\n\
-\n\
-  if(theContext.IsNull() || theContext->CurrentViewer().IsNull()) return; \n\
-\n\
-  //Set AIS2D_InteractiveContext and default Graphic2d_View \n\
-  AIS2D_InteractiveObject::SetContext(theContext); \n\
-  Graphic2d_GraphicObject::SetView(theContext->CurrentViewer()->View()); \n\
-\n\
-  Handle(GraphicSample2D_ImageFile) aGraphic2dImageFile =\n\
-    new GraphicSample2D_ImageFile (aGrObj,\n\
-                                        myFile,\n\
-                                        myX, \n\
-                                        myY,\n\
-                                        myDx,\n\
-                                        myDy,\n\
-                                        myTypeOfPlacement,\n\
-                                        myScale); \n\
-  if (myIsZoomable)\n\
-    aGraphic2dImageFile->SetZoomable(Standard_True);\n\
-}\n\n");
-  // Update The Result Dialog
-  UpdateResultDialog(filename,Message);
   }
 }