Integration of OCCT 6.5.0 from SVN
[occt.git] / samples / mfc / standard / 01_Geometry / src / GeometryApp.cpp
1 // GeometryApp.cpp : Defines the class behaviors for the application.
2 //
3
4 #include "stdafx.h"
5
6 #include "GeometryApp.h"
7 #include "MainFrm.h"
8 #include "ChildFrm.h"
9 #include "GeometryDoc.h"
10 #include "GeometryView.h"
11 #include "GeometryView2d.h"
12 #include "ChildFrm2D.h"
13 #include "GeometryView2d.h"
14
15 /////////////////////////////////////////////////////////////////////////////
16 // CGeometryApp construction
17
18 CGeometryApp::CGeometryApp()
19 {
20         SampleName = "Geometry";        //for about dialog
21
22 }
23
24 CGeometryApp::~CGeometryApp()
25 {
26     delete pDocTemplateForView2d;
27 }
28 /////////////////////////////////////////////////////////////////////////////
29 // The one and only CGeometryApp object
30
31 CGeometryApp theApp;
32
33 /////////////////////////////////////////////////////////////////////////////
34 // CGeometryApp initialization
35
36 BOOL CGeometryApp::InitInstance()
37 {
38     AfxInitRichEdit();
39         AfxEnableControlContainer();
40
41         // Standard initialization
42         // If you are not using these features and wish to reduce the size
43         //  of your final executable, you should remove from the following
44         //  the specific initialization routines you do not need.
45
46         // Change the registry key under which our settings are stored.
47         // You should modify this string to be something appropriate
48         // such as the name of your company or organization.
49         SetRegistryKey(_T("Local AppWizard-Generated Applications"));
50
51         LoadStdProfileSettings();  // Load standard INI file options (including MRU)
52
53         // Register the application's document templates.  Document templates
54         //  serve as the connection between documents, frame windows and views.
55
56         pDocTemplateForView3d = new CMultiDocTemplate(
57                 IDR_3DTYPE,
58                 RUNTIME_CLASS(CGeometryDoc),
59                 RUNTIME_CLASS(CChildFrame), // custom MDI child frame
60                 RUNTIME_CLASS(CGeometryView));
61         AddDocTemplate(pDocTemplateForView3d);
62     
63     pDocTemplateForView2d = new CMultiDocTemplate(
64                 IDR_2DTYPE,
65                 RUNTIME_CLASS(CGeometryDoc),
66                 RUNTIME_CLASS(CChildFrame2D), // custom MDI child frame
67                 RUNTIME_CLASS(CGeometryView2D));
68         //AddDocTemplate(pDocTemplateForView2d);
69
70         // create main MDI Frame window
71         CMainFrame* pMainFrame = new CMainFrame;
72         if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
73                 return FALSE;
74         m_pMainWnd = pMainFrame;
75
76         // Parse command line for standard shell commands, DDE, file open
77         CCommandLineInfo cmdInfo;
78         ParseCommandLine(cmdInfo);
79
80         // Dispatch commands specified on the command line
81         if (!ProcessShellCommand(cmdInfo))
82                 return FALSE;
83
84         // The main window has been initialized, so show and update it.
85         pMainFrame->ShowWindow(m_nCmdShow);
86         pMainFrame->UpdateWindow();
87
88
89         return TRUE;
90 }
91
92 /////////////////////////////////////////////////////////////////////////////
93 // CGeometryApp commands
94
95 //===================================================
96
97 CFrameWnd*  CGeometryApp::CreateView2D(CGeometryDoc* pDoc )
98 {
99   ASSERT_VALID(pDoc);
100   ASSERT_VALID(pDocTemplateForView2d);
101   CRuntimeClass * pViewClass = RUNTIME_CLASS(CGeometryView2D);
102   ASSERT(pViewClass != (CRuntimeClass *)NULL );
103   // Create a new frame window
104   CFrameWnd* pNewFrame = pDocTemplateForView2d->CreateNewFrame(pDoc, NULL);
105   pDocTemplateForView2d->InitialUpdateFrame(pNewFrame, pDoc);
106 return pNewFrame;
107 }
108
109 BOOL CGeometryApp::IsViewExisting(CDocument * pDoc, CRuntimeClass * pViewClass, CView * & pView)
110 {
111   ASSERT_VALID(pDoc);
112   ASSERT(pViewClass != (CRuntimeClass *)NULL );
113
114   POSITION position = pDoc->GetFirstViewPosition();
115   while (position != (POSITION)NULL)
116   {
117     CView* pCurrentView = pDoc->GetNextView(position);
118     ASSERT_VALID(pCurrentView);
119     if (pCurrentView->IsKindOf(pViewClass))
120         {
121       pView = pCurrentView;
122           return TRUE;
123         }
124   }
125   return FALSE;
126 }
127