0024943: Port MFC samples to UNICODE for compatibility with VS2013
[occt.git] / samples / mfc / standard / 08_HLR / src / HLRApp.cpp
1 // HLRApp.cpp : Defines the class behaviors for the application.
2 //
3
4 #include "stdafx.h"
5
6 #include "HLRApp.h"
7
8 #include <OCC_MainFrame.h>
9 #include <OCC_3dChildFrame.h>
10 #include "HLRDoc.h"
11 #include <OCC_2dChildFrame.h>
12 #include "HLRView2D.h"
13 #include <OCC_3dView.h>
14 // End CasCade
15
16 #ifdef _DEBUG
17 // CasCade :
18 //#define new DEBUG_NEW
19 // End CasCade
20
21 #undef THIS_FILE
22 static char THIS_FILE[] = __FILE__;
23 #endif
24
25 /////////////////////////////////////////////////////////////////////////////
26 // CHLRApp construction
27
28 CHLRApp::CHLRApp() : OCC_App()
29 {
30   SampleName = "HLR"; //for about dialog
31   SetSamplePath (L"..\\..\\08_HLR");
32 }
33
34 CHLRApp::~CHLRApp()
35 {
36   delete pDocTemplateForView2d;
37 }
38
39 /////////////////////////////////////////////////////////////////////////////
40 // The one and only CHLRApp object
41
42 CHLRApp theApp;
43
44 /////////////////////////////////////////////////////////////////////////////
45 // CHLRApp initialization
46
47 BOOL CHLRApp::InitInstance()
48 {
49   AfxEnableControlContainer();
50
51   // Standard initialization
52   // If you are not using these features and wish to reduce the size
53   //  of your final executable, you should remove from the following
54   //  the specific initialization routines you do not need.
55
56   // Change the registry key under which our settings are stored.
57   // You should modify this string to be something appropriate
58   // such as the name of your company or organization.
59   // Modified by CasCade :
60   SetRegistryKey(_T("Local CasCade Applications"));
61
62   LoadStdProfileSettings();  // Load standard INI file options (including MRU)
63
64   // Register the application's document templates.  Document templates
65   //  serve as the connection between documents, frame windows and views.
66
67   // CasCade :
68
69
70   pDocTemplateForView2d = new CMultiDocTemplate(
71     IDR_2DTYPE,
72     RUNTIME_CLASS(CHLRDoc),
73     RUNTIME_CLASS(OCC_2dChildFrame), // custom MDI child frame
74     RUNTIME_CLASS(CHLRView2D));
75
76 // AddDocTemplate(pDocTemplateForView2d);
77
78 // End CasCade
79   pDocTemplateForView3d  = new CMultiDocTemplate(
80     IDR_3DTYPE,
81     RUNTIME_CLASS(CHLRDoc),
82     RUNTIME_CLASS(OCC_3dChildFrame), // custom MDI child frame
83     RUNTIME_CLASS(OCC_3dView));
84
85   AddDocTemplate(pDocTemplateForView3d);
86
87
88   // create main MDI Frame window
89   OCC_MainFrame* pMainFrame = new OCC_MainFrame(with_AIS_TB);
90   if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
91     return FALSE;
92   m_pMainWnd = pMainFrame;
93
94   // Parse command line for standard shell commands, DDE, file open
95   CCommandLineInfo cmdInfo;
96   ParseCommandLine(cmdInfo);
97
98   // Dispatch commands specified on the command line
99   if (!ProcessShellCommand(cmdInfo))
100     return FALSE;
101
102   // The main window has been initialized, so show and update it.
103   pMainFrame->MDITile(MDITILE_VERTICAL);
104   pMainFrame->ShowWindow(m_nCmdShow);
105   pMainFrame->UpdateWindow();
106
107   return TRUE;
108 }
109
110 /////////////////////////////////////////////////////////////////////////////
111 // CHLRApp commands
112
113 //===================================================
114
115 CFrameWnd*  CHLRApp::CreateView2D(CHLRDoc* pDoc )
116 {
117   ASSERT_VALID(pDoc);
118   ASSERT_VALID(pDocTemplateForView2d);
119   CRuntimeClass * pViewClass = RUNTIME_CLASS(OCC_2dView);
120   ASSERT(pViewClass != (CRuntimeClass *)NULL );
121   // Create a new frame window
122   CFrameWnd* pNewFrame = pDocTemplateForView2d->CreateNewFrame(pDoc, NULL);
123   ASSERT_VALID(pDoc);
124   pDocTemplateForView2d->InitialUpdateFrame(pNewFrame, pDoc);
125   ASSERT_VALID(pDoc);
126 return pNewFrame;
127 }
128
129 //===================================================
130 CFrameWnd*  CHLRApp::CreateView3D(CHLRDoc* pDoc )
131 {
132   ASSERT_VALID(pDoc);
133   ASSERT_VALID(pDocTemplateForView3d);
134   CRuntimeClass * pViewClass = RUNTIME_CLASS(OCC_3dView);
135   ASSERT(pViewClass != (CRuntimeClass *)NULL );
136   // Create a new frame window
137   CFrameWnd* pNewFrame = pDocTemplateForView3d->CreateNewFrame(pDoc, NULL);
138   pDocTemplateForView3d->InitialUpdateFrame(pNewFrame, pDoc);
139 return pNewFrame;
140
141 }
142
143
144 BOOL CHLRApp::IsViewExisting(CDocument * pDoc, CRuntimeClass * pViewClass, CView * & pView)
145 {
146   ASSERT_VALID(pDoc);
147   ASSERT(pViewClass != (CRuntimeClass *)NULL );
148
149   POSITION position = pDoc->GetFirstViewPosition();
150   while (position != (POSITION)NULL)
151   {
152     CView* pCurrentView = pDoc->GetNextView(position);
153     ASSERT_VALID(pCurrentView);
154     if (pCurrentView->IsKindOf(pViewClass))
155         {
156       pView = pCurrentView;
157           return TRUE;
158         }
159   }
160   return FALSE;
161 }
162
163
164