Integration of OCCT 6.5.0 from SVN
[occt.git] / samples / mfc / standard / 05_ImportExport / src / ImportExportApp.cpp
CommitLineData
7fd59977 1// ImportExportApp.cpp : Defines the class behaviors for the application.
2//
3
4#include "stdafx.h"
5
6#include "ImportExportApp.h"
7
8#include "OCC_MainFrame.h"
9#include "OCC_3dChildFrame.h"
10#include "ImportExportDoc.h"
11#include <OCC_3dView.h>
12#include <res\resource.h>
13
14BEGIN_MESSAGE_MAP(CImportExportApp, OCC_3dApp)
15 //{{AFX_MSG_MAP(CSerializeApp)
16 ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
17 //}}AFX_MSG_MAP
18END_MESSAGE_MAP()
19
20/////////////////////////////////////////////////////////////////////////////
21// CImportExportApp construction
22
23CImportExportApp::CImportExportApp()
24{
25 // Set the local system units
26 try
27 { UnitsAPI::SetLocalSystem(UnitsAPI_MDTV); }
28 catch (Standard_Failure)
29 {
30 AfxMessageBox("Fatal Error in units initialisation");
31 }
32 SampleName = "ImportExport"; //for about dialog
33}
34
35/////////////////////////////////////////////////////////////////////////////
36// The one and only CImportExportApp object
37
38CImportExportApp theApp;
39
40/////////////////////////////////////////////////////////////////////////////
41// CImportExportApp initialization
42
43BOOL CImportExportApp::InitInstance()
44{
45 AfxEnableControlContainer();
46
47 // Standard initialization
48 // If you are not using these features and wish to reduce the size
49 // of your final executable, you should remove from the following
50 // the specific initialization routines you do not need.
51
52 // Change the registry key under which our settings are stored.
53 // You should modify this string to be something appropriate
54 // such as the name of your company or organization.
55 // Modified by CasCade :
56 SetRegistryKey(_T("Local CasCade Applications"));
57
58 LoadStdProfileSettings(); // Load standard INI file options (including MRU)
59
60 // Register the application's document templates. Document templates
61 // serve as the connection between documents, frame windows and views.
62
63 CMultiDocTemplate* pDocTemplate;
64 pDocTemplate = new CMultiDocTemplate(
65 IDR_3DTYPE,
66 RUNTIME_CLASS(CImportExportDoc),
67 RUNTIME_CLASS(OCC_3dChildFrame),
68 RUNTIME_CLASS(OCC_3dView));
69 AddDocTemplate(pDocTemplate);
70
71 // create main MDI Frame window
72 OCC_MainFrame* pMainFrame = new OCC_MainFrame(with_AIS_TB);
73 if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
74 return FALSE;
75 m_pMainWnd = pMainFrame;
76
77 // Parse command line for standard shell commands, DDE, file open
78 CCommandLineInfo cmdInfo;
79 ParseCommandLine(cmdInfo);
80
81 // Dispatch commands specified on the command line
82 if (!ProcessShellCommand(cmdInfo))
83 return FALSE;
84
85 // The main window has been initialized, so show and update it.
86 pMainFrame->ShowWindow(m_nCmdShow);
87 pMainFrame->UpdateWindow();
88
89 return TRUE;
90}
91
92CDocument* CImportExportApp::OpenDocumentFile(LPCTSTR lpszFileName)
93{
94 CFile cf;
95
96 if (!cf.Open(lpszFileName,CFile::modeReadWrite)){
97 AfxMessageBox("File not found!");
98 return NULL;
99 }
100 cf.Close();
101 return CWinApp::OpenDocumentFile(lpszFileName);
102}
103
104void CImportExportApp::OnFileOpen()
105{
106 CFileDialog dlg(TRUE,
107 NULL,
108 NULL,
109 OFN_HIDEREADONLY | OFN_FILEMUSTEXIST,
110 NULL,
111 NULL );
112
113
114 CString initdir(((OCC_BaseApp*) AfxGetApp())->GetInitDataDir());
115 initdir += "\\Data";
116
117 dlg.m_ofn.lpstrInitialDir = initdir;
118
119 CString strFilter;
120 CString strDefault;
121
122 POSITION pos = GetFirstDocTemplatePosition();
123
124 CDocTemplate* pTemplate = GetNextDocTemplate(pos);
125 CString strFilterExt, strFilterName;
126 if (pTemplate->GetDocString(strFilterExt, CDocTemplate::filterExt) &&
127 !strFilterExt.IsEmpty() &&
128 pTemplate->GetDocString(strFilterName, CDocTemplate::filterName) &&
129 !strFilterName.IsEmpty()) {
130 // add to filter
131 strFilter += strFilterName;
132 ASSERT(!strFilter.IsEmpty()); // must have a file type name
133 strFilter += (TCHAR)'\0'; // next string please
134 strFilter += (TCHAR)'*';
135 strFilter += strFilterExt;
136 strFilter += (TCHAR)'\0'; // next string please
137 dlg.m_ofn.nMaxCustFilter++;
138 }
139 // append the "*.*" all files filter
140 CString allFilter;
141 VERIFY(allFilter.LoadString(AFX_IDS_ALLFILTER));
142 strFilter += allFilter;
143 strFilter += (TCHAR)'\0'; // next string please
144 strFilter += _T("*.*");
145 strFilter += (TCHAR)'\0'; // last string
146 dlg.m_ofn.nMaxCustFilter++;
147 dlg.m_ofn.lpstrFilter = strFilter;
148
149 if (dlg.DoModal() == IDOK)
150 {
151 AfxGetApp()->OpenDocumentFile(dlg.GetPathName());
152 }
153}