0031521: Samples - update MFC ImportExport sample to use AIS_ViewController
[occt.git] / samples / mfc / standard / Common / OCC_2dDoc.cpp
1 // OCC_2dDoc.cpp: implementation of the OCC_2dDoc class.
2 //
3 //////////////////////////////////////////////////////////////////////
4
5 #include <stdafx.h>
6
7 #include "OCC_2dDoc.h"
8
9 #include "OCC_App.h"
10 #include "OCC_2dView.h"
11
12 IMPLEMENT_DYNCREATE(OCC_2dDoc, CDocument)
13
14 //////////////////////////////////////////////////////////////////////
15 // Construction/Destruction
16 //////////////////////////////////////////////////////////////////////
17
18 OCC_2dDoc::OCC_2dDoc() : OCC_BaseDoc()
19 {
20   // Get the Graphic Driver from the application 
21   Handle(Graphic3d_GraphicDriver) aGraphicDriver = ((OCC_App*)AfxGetApp())->GetGraphicDriver();
22
23   // create the Viewer
24   myViewer = new V3d_Viewer (aGraphicDriver);
25   myViewer->SetDefaultLights();
26   myViewer->SetLightOn();
27   myViewer->SetDefaultViewProj (V3d_Zpos);
28
29   // set default values for grids
30   myViewer->SetCircularGridValues (0, 0, 10, 8, 0);
31   myViewer->SetRectangularGridValues (0, 0, 10, 10, 0);
32
33   myAISContext = new AIS_InteractiveContext (myViewer);
34
35   AfxInitRichEdit();
36 }
37
38 OCC_2dDoc::~OCC_2dDoc()
39 {
40 }
41
42 void OCC_2dDoc::FitAll2DViews(Standard_Boolean theUpdateViewer)
43 {
44   if (theUpdateViewer)
45   {
46     myViewer->Update();
47   }
48
49   POSITION aPosition = GetFirstViewPosition();
50   while (aPosition != (POSITION)NULL)
51   {
52     OCC_2dView* aCurrentView = (OCC_2dView*)GetNextView (aPosition);
53     ASSERT_VALID (aCurrentView);
54     aCurrentView->GetView()->FitAll();
55   }
56 }
57
58 void OCC_2dDoc::Popup (const Standard_Integer theMouseX,
59                        const Standard_Integer theMouseY,
60                        const Handle(V3d_View)& theView)
61 {
62   // load the 'normal' popup
63   CMenu aMenu;
64   VERIFY(aMenu.LoadMenu(IDR_Popup2D));
65   // activate the sub menu '0'
66   CMenu* aPopup = aMenu.GetSubMenu(0);
67   ASSERT(aPopup != NULL);
68
69   // display the popup
70   POINT aWinCoord = { theMouseX, theMouseY };
71   ClientToScreen ((HWND )theView->Window()->NativeHandle(), &aWinCoord);
72   aPopup->TrackPopupMenu (TPM_LEFTALIGN | TPM_RIGHTBUTTON, aWinCoord.x, aWinCoord.y, AfxGetMainWnd());
73 }