0023776: Redesign of MFC samples after V2d viewer removing
[occt.git] / samples / mfc / standard / Common / OCC_2dDoc.cpp
index 05e1e80..35e2b08 100755 (executable)
@@ -6,7 +6,7 @@
 
 #include "OCC_2dDoc.h"
 
-#include "OCC_2dApp.h"
+#include "OCC_App.h"
 #include "OCC_2dView.h"
 
 IMPLEMENT_DYNCREATE(OCC_2dDoc, CDocument)
@@ -15,80 +15,59 @@ IMPLEMENT_DYNCREATE(OCC_2dDoc, CDocument)
 // Construction/Destruction
 //////////////////////////////////////////////////////////////////////
 
-OCC_2dDoc::OCC_2dDoc()
+OCC_2dDoc::OCC_2dDoc() : OCC_BaseDoc()
 {
-       // Get the Graphic Device from the application 
-       Handle(WNT_GraphicDevice) theGraphicDevice = 
-         ((OCC_2dApp*)AfxGetApp())->GetGraphicDevice();
-
-       // create the Viewer
-       TCollection_ExtendedString Name("Viewer 2D");
-       TCollection_AsciiString Domain("My Domain");
-       my2DViewer = new V2d_Viewer(theGraphicDevice,
-                                                         Name.ToExtString(),
-                                                         Domain.ToCString());
-
-       // set default values for grids
-       my2DViewer->SetCircularGridValues(0,0,10,8,0);
-       my2DViewer->SetRectangularGridValues(0,0,10,10,0);
-
-       myAISInteractiveContext2D = new AIS2D_InteractiveContext(my2DViewer);
-
-       
-       AfxInitRichEdit();
-       myCResultDialog.Create(CResultDialog::IDD,NULL);
-
-       RECT dlgrect;
-       myCResultDialog.GetWindowRect(&dlgrect);
-       LONG width = dlgrect.right-dlgrect.left;
-       LONG height = dlgrect.bottom-dlgrect.top;
-
-       RECT MainWndRect;
-       AfxGetApp()->m_pMainWnd->GetWindowRect(&MainWndRect);
-       LONG left = MainWndRect.left+3;
-       LONG top = MainWndRect.top + 108;
-       //LONG height = MainWndRect.bottom - MainWndRect.top;
-
-       myCResultDialog.MoveWindow(left,top,width,height);
-       
-}
+  // Get the Graphic Driver from the application 
+  Handle(Graphic3d_GraphicDriver) aGraphicDriver = 
+    ((OCC_App*)AfxGetApp())->GetGraphicDriver();
 
-OCC_2dDoc::~OCC_2dDoc()
-{
+  // create the Viewer
+  TCollection_ExtendedString aName ("Viewer 2D");
+  TCollection_AsciiString aDomain ("My Domain");
+
+  myViewer = new V3d_Viewer (aGraphicDriver,
+                             aName.ToExtString(),
+                             aDomain.ToCString());
+
+  myViewer->SetDefaultLights();
+  myViewer->SetLightOn();
+  myViewer->SetDefaultViewProj (V3d_Zpos);
+
+  // set default values for grids
+  myViewer->SetCircularGridValues (0, 0, 10, 8, 0);
+  myViewer->SetRectangularGridValues (0, 0, 10, 10, 0);
 
+  myAISContext = new AIS_InteractiveContext (myViewer);
+
+  AfxInitRichEdit();
 }
 
-void OCC_2dDoc::FitAll2DViews(Standard_Boolean UpdateViewer)
+void OCC_2dDoc::FitAll2DViews(Standard_Boolean theUpdateViewer)
 {
-  if (UpdateViewer)   my2DViewer->Update();
-  POSITION position = GetFirstViewPosition();
-  while (position != (POSITION)NULL)
+  if (theUpdateViewer)
   {
-    OCC_2dView* pCurrentView = (OCC_2dView*)GetNextView(position);
-    ASSERT_VALID(pCurrentView);
-    pCurrentView->GetV2dView()->Fitall();
+    myViewer->Update();
+  }
+
+  POSITION aPosition = GetFirstViewPosition();
+  while (aPosition != (POSITION)NULL)
+  {
+    OCC_2dView* aCurrentView = (OCC_2dView*)GetNextView (aPosition);
+    ASSERT_VALID (aCurrentView);
+    aCurrentView->GetV2dView()->FitAll();
   }
 }
 
-void OCC_2dDoc::UpdateResultDialog(UINT anID,TCollection_AsciiString aMessage)
+void OCC_2dDoc::MoveEvent(const Standard_Integer theMouseX,
+                          const Standard_Integer theMouseY,
+                          const Handle(V3d_View)& theView)
 {
-    CString text(aMessage.ToCString());
-    myCResultDialog.SetText(text);
-
-    CString s;
-    if (! s.LoadString( anID )) AfxMessageBox("Error Loading String: ");
-    CString Title = s.Left( s.Find( '\n' ));
-    myCResultDialog.SetTitle(Title);
-    SetTitle(Title);
-//    myCResultDialog.ShowWindow(SW_RESTORE);
+  myAISContext->MoveTo (theMouseX, theMouseY, theView);
 }
 
-void OCC_2dDoc::UpdateResultDialog(CString& title,TCollection_AsciiString aMessage)
+void OCC_2dDoc::ShiftMoveEvent(const Standard_Integer theMouseX,
+                               const Standard_Integer theMouseY,
+                               const Handle(V3d_View)& theView)
 {
-    CString text(aMessage.ToCString());
-    myCResultDialog.SetText(text);
-    myCResultDialog.SetTitle(title);
-    SetTitle(title);
-//    myCResultDialog.ShowWindow(SW_RESTORE);
+  myAISContext->MoveTo (theMouseX, theMouseY, theView);
 }
-