1 // OCC_App.cpp: implementation of the OCC_App class.
3 //////////////////////////////////////////////////////////////////////
8 #include "OCC_BaseDoc.h"
9 #include <res\OCC_Resource.h>
11 #include <Standard_Version.hxx>
12 #include <OpenGl_GraphicDriver.hxx>
17 /////////////////////////////////////////////////////////////////////////////
20 BEGIN_MESSAGE_MAP(OCC_App, CWinApp)
21 //{{AFX_MSG_MAP(OCC_App)
22 ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
23 // NOTE - the ClassWizard will add and remove mapping macros here.
24 // DO NOT EDIT what you see in these blocks of generated code!
26 // Standard file based document commands
27 ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
28 ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
29 ON_COMMAND(ID_BUTTON_STEREO, &OCC_App::OnStereo)
30 ON_UPDATE_COMMAND_UI(ID_BUTTON_STEREO, &OCC_App::OnUpdateStereo)
33 /////////////////////////////////////////////////////////////////////////////
34 // OCC_App construction
36 OCC_App::OCC_App() : CWinApp()
38 OSD::SetSignal (Standard_True);
43 Handle(Aspect_DisplayConnection) aDisplayConnection;
44 myGraphicDriver = new OpenGl_GraphicDriver (aDisplayConnection);
46 catch(Standard_Failure)
48 AfxMessageBox (L"Fatal error during graphic initialization", MB_ICONSTOP);
53 void OCC_App::SetSamplePath(LPCTSTR aPath)
55 wchar_t anAbsoluteExecutableFileName[MAX_PATH + 1];
56 HMODULE hModule = GetModuleHandleW (NULL);
57 GetModuleFileNameW (hModule, anAbsoluteExecutableFileName, MAX_PATH);
59 SamplePath = CString (anAbsoluteExecutableFileName);
60 int index = SamplePath.ReverseFind('\\');
61 SamplePath.Delete(index+1, SamplePath.GetLength() - index - 1);
65 CString aCInitialDir(aPath);
66 //SamplePath += "..\\" + aCInitialDir;
69 /////////////////////////////////////////////////////////////////////////////
70 // CAboutDlgStd dialog used for App About
72 class CAboutDlgStd : public CDialog
79 //{{AFX_DATA(CAboutDlgStd)
80 enum { IDD = IDD_OCC_ABOUTBOX };
83 // ClassWizard generated virtual function overrides
84 //{{AFX_VIRTUAL(CAboutDlgStd)
86 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
92 //{{AFX_MSG(CAboutDlgStd)
93 // No message handlers
101 CAboutDlgStd::CAboutDlgStd() : CDialog(CAboutDlgStd::IDD)
104 //{{AFX_DATA_INIT(CAboutDlgStd)
108 void CAboutDlgStd::DoDataExchange(CDataExchange* pDX)
110 CDialog::DoDataExchange(pDX);
111 //{{AFX_DATA_MAP(CAboutDlgStd)
113 DDX_Text(pDX, IDC_README, ReadmeText);
116 BEGIN_MESSAGE_MAP(CAboutDlgStd, CDialog)
117 //{{AFX_MSG_MAP(CAboutDlgStd)
118 // No message handlers
122 BOOL CAboutDlgStd::OnInitDialog(){
123 CWnd* Title = GetDlgItem(IDC_ABOUTBOX_TITLE);
125 CString About = "About ";
126 CString Sample = "Sample ";
127 CString SampleName = ((OCC_App*)AfxGetApp())->GetSampleName();
128 CString Cascade = ", Open CASCADE Technology ";
129 CString Version = OCC_VERSION_STRING;
131 CString strTitle = Sample + SampleName + Cascade + Version;
132 CString dlgTitle = About + SampleName;
134 Title->SetWindowText(strTitle);
135 SetWindowText(dlgTitle);
137 CWnd* aReadmeEdit = GetDlgItem(IDC_README);
139 CString aHelpFilePath = CString (((OCC_App*)AfxGetApp())->GetInitDataDir()) + L"\\README.txt";
140 if(aFile.Open (aHelpFilePath, CFile::modeRead))
142 aReadmeEdit->ShowWindow(TRUE);
143 UINT aFileLength = (UINT)aFile.GetLength();
144 char* buffer = new char[aFileLength];
145 aFile.Read(buffer,aFileLength);
148 ReadmeText.Replace (L"\n", L"\r\n");
153 aReadmeEdit->ShowWindow(FALSE);
160 // App command to run the dialog
161 void OCC_App::OnAppAbout()
163 CAboutDlgStd aboutDlg;
167 const wchar_t* OCC_App::GetSampleName() const
169 return (const wchar_t* )SampleName;
172 const wchar_t* OCC_App::GetInitDataDir() const
174 return (const wchar_t* )SamplePath;
177 void OCC_App::SetSampleName (const wchar_t* theName)
179 SampleName = theName;
182 //=============================================================================
183 // function: OnStereo
185 //=============================================================================
186 void OCC_App::OnStereo()
188 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (myGraphicDriver);
190 int anAnswer = MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd,
191 L"It is required to switch OpenGl context to turn on / off hardware stereo support. "
192 L"The document views need to be re-created to change \"GL\" context pixel format. "
193 L"This will close all current views and open new one (the model will be kept).\n"
194 L"Do you want to continue?", L"Enable/disable hardware stereo support", MB_OKCANCEL | MB_ICONQUESTION);
195 if (anAnswer != IDOK)
200 Standard_Boolean& aStereoMode = aDriver->ChangeOptions().contextStereo;
202 aStereoMode = !aStereoMode;
204 // reset document views
205 POSITION aTemplateIt = GetFirstDocTemplatePosition();
207 while (aTemplateIt != NULL)
209 CDocTemplate* aTemplate = (CDocTemplate*)GetNextDocTemplate (aTemplateIt);
211 POSITION aDocumentIt = aTemplate->GetFirstDocPosition();
213 while (aDocumentIt != NULL)
215 OCC_BaseDoc* aDocument = dynamic_cast<OCC_BaseDoc*> (aTemplate->GetNextDoc (aDocumentIt));
216 if (aDocument == NULL)
219 aDocument->ResetDocumentViews (aTemplate);
224 //=============================================================================
225 // function: OnUpdateStereo
227 //=============================================================================
228 void OCC_App::OnUpdateStereo (CCmdUI* theCmdUI)
230 Handle(OpenGl_GraphicDriver) aDriver =
231 Handle(OpenGl_GraphicDriver)::DownCast (myGraphicDriver);
233 theCmdUI->SetCheck (!aDriver.IsNull() && aDriver->Options().contextStereo);