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 BOOL OCC_App::InitApplication()
38 OSD::SetSignal (false);
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);
55 void OCC_App::SetSamplePath(LPCTSTR aPath)
57 wchar_t anAbsoluteExecutableFileName[MAX_PATH + 1];
58 HMODULE hModule = GetModuleHandleW (NULL);
59 GetModuleFileNameW (hModule, anAbsoluteExecutableFileName, MAX_PATH);
61 SamplePath = CString (anAbsoluteExecutableFileName);
62 int index = SamplePath.ReverseFind('\\');
63 SamplePath.Delete(index+1, SamplePath.GetLength() - index - 1);
67 CString aCInitialDir(aPath);
68 //SamplePath += "..\\" + aCInitialDir;
71 /////////////////////////////////////////////////////////////////////////////
72 // CAboutDlgStd dialog used for App About
74 class CAboutDlgStd : public CDialog
81 //{{AFX_DATA(CAboutDlgStd)
82 enum { IDD = IDD_OCC_ABOUTBOX };
85 // ClassWizard generated virtual function overrides
86 //{{AFX_VIRTUAL(CAboutDlgStd)
88 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
94 //{{AFX_MSG(CAboutDlgStd)
95 // No message handlers
103 CAboutDlgStd::CAboutDlgStd() : CDialog(CAboutDlgStd::IDD)
106 //{{AFX_DATA_INIT(CAboutDlgStd)
110 void CAboutDlgStd::DoDataExchange(CDataExchange* pDX)
112 CDialog::DoDataExchange(pDX);
113 //{{AFX_DATA_MAP(CAboutDlgStd)
115 DDX_Text(pDX, IDC_README, ReadmeText);
118 BEGIN_MESSAGE_MAP(CAboutDlgStd, CDialog)
119 //{{AFX_MSG_MAP(CAboutDlgStd)
120 // No message handlers
124 BOOL CAboutDlgStd::OnInitDialog(){
125 CWnd* Title = GetDlgItem(IDC_ABOUTBOX_TITLE);
127 CString About = "About ";
128 CString Sample = "Sample ";
129 CString SampleName = ((OCC_App*)AfxGetApp())->GetSampleName();
130 CString Cascade = ", Open CASCADE Technology ";
131 CString Version = OCC_VERSION_STRING;
133 CString strTitle = Sample + SampleName + Cascade + Version;
134 CString dlgTitle = About + SampleName;
136 Title->SetWindowText(strTitle);
137 SetWindowText(dlgTitle);
139 CWnd* aReadmeEdit = GetDlgItem(IDC_README);
141 CString aHelpFilePath = CString (((OCC_App*)AfxGetApp())->GetInitDataDir()) + L"\\README.txt";
142 if(aFile.Open (aHelpFilePath, CFile::modeRead))
144 aReadmeEdit->ShowWindow(TRUE);
145 UINT aFileLength = (UINT)aFile.GetLength();
146 char* buffer = new char[aFileLength];
147 aFile.Read(buffer,aFileLength);
150 ReadmeText.Replace (L"\n", L"\r\n");
155 aReadmeEdit->ShowWindow(FALSE);
162 // App command to run the dialog
163 void OCC_App::OnAppAbout()
165 CAboutDlgStd aboutDlg;
169 const wchar_t* OCC_App::GetSampleName() const
171 return (const wchar_t* )SampleName;
174 const wchar_t* OCC_App::GetInitDataDir() const
176 return (const wchar_t* )SamplePath;
179 void OCC_App::SetSampleName (const wchar_t* theName)
181 SampleName = theName;
184 //=============================================================================
185 // function: OnStereo
187 //=============================================================================
188 void OCC_App::OnStereo()
190 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (myGraphicDriver);
192 int anAnswer = MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd,
193 L"It is required to switch OpenGl context to turn on / off hardware stereo support. "
194 L"The document views need to be re-created to change \"GL\" context pixel format. "
195 L"This will close all current views and open new one (the model will be kept).\n"
196 L"Do you want to continue?", L"Enable/disable hardware stereo support", MB_OKCANCEL | MB_ICONQUESTION);
197 if (anAnswer != IDOK)
202 Standard_Boolean& aStereoMode = aDriver->ChangeOptions().contextStereo;
204 aStereoMode = !aStereoMode;
206 // reset document views
207 POSITION aTemplateIt = GetFirstDocTemplatePosition();
209 while (aTemplateIt != NULL)
211 CDocTemplate* aTemplate = (CDocTemplate*)GetNextDocTemplate (aTemplateIt);
213 POSITION aDocumentIt = aTemplate->GetFirstDocPosition();
215 while (aDocumentIt != NULL)
217 OCC_BaseDoc* aDocument = dynamic_cast<OCC_BaseDoc*> (aTemplate->GetNextDoc (aDocumentIt));
218 if (aDocument == NULL)
221 aDocument->ResetDocumentViews (aTemplate);
226 //=============================================================================
227 // function: OnUpdateStereo
229 //=============================================================================
230 void OCC_App::OnUpdateStereo (CCmdUI* theCmdUI)
232 Handle(OpenGl_GraphicDriver) aDriver =
233 Handle(OpenGl_GraphicDriver)::DownCast (myGraphicDriver);
235 theCmdUI->SetCheck (!aDriver.IsNull() && aDriver->Options().contextStereo);