1 // ImportExportApp.cpp : Defines the class behaviors for the application.
6 #include "ImportExportApp.h"
8 #include "OCC_MainFrame.h"
9 #include "OCC_3dChildFrame.h"
10 #include "ImportExportDoc.h"
11 #include <OCC_3dView.h>
12 #include <res/resource.h>
14 BEGIN_MESSAGE_MAP(CImportExportApp, OCC_App)
15 //{{AFX_MSG_MAP(CSerializeApp)
16 ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
20 /////////////////////////////////////////////////////////////////////////////
21 // CImportExportApp construction
23 CImportExportApp::CImportExportApp() : OCC_App()
25 // Set the local system units
28 UnitsAPI::SetLocalSystem (UnitsAPI_MDTV);
30 catch (Standard_Failure)
32 AfxMessageBox ("Fatal Error in units initialisation");
35 SampleName = "ImportExport"; //for about dialog
38 /////////////////////////////////////////////////////////////////////////////
39 // The one and only CImportExportApp object
41 CImportExportApp theApp;
43 /////////////////////////////////////////////////////////////////////////////
44 // CImportExportApp initialization
46 BOOL CImportExportApp::InitInstance()
48 AfxEnableControlContainer();
50 // Standard initialization
51 // If you are not using these features and wish to reduce the size
52 // of your final executable, you should remove from the following
53 // the specific initialization routines you do not need.
55 // Change the registry key under which our settings are stored.
56 // You should modify this string to be something appropriate
57 // such as the name of your company or organization.
58 // Modified by CasCade :
59 SetRegistryKey(_T("Local CasCade Applications"));
61 LoadStdProfileSettings(); // Load standard INI file options (including MRU)
63 // Register the application's document templates. Document templates
64 // serve as the connection between documents, frame windows and views.
66 CMultiDocTemplate* pDocTemplate;
67 pDocTemplate = new CMultiDocTemplate(
69 RUNTIME_CLASS(CImportExportDoc),
70 RUNTIME_CLASS(OCC_3dChildFrame),
71 RUNTIME_CLASS(OCC_3dView));
72 AddDocTemplate(pDocTemplate);
74 // create main MDI Frame window
75 OCC_MainFrame* pMainFrame = new OCC_MainFrame(with_AIS_TB);
76 if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
78 m_pMainWnd = pMainFrame;
80 // Parse command line for standard shell commands, DDE, file open
81 CCommandLineInfo cmdInfo;
82 ParseCommandLine(cmdInfo);
84 // Dispatch commands specified on the command line
85 if (!ProcessShellCommand(cmdInfo))
88 // The main window has been initialized, so show and update it.
89 pMainFrame->ShowWindow(m_nCmdShow);
90 pMainFrame->UpdateWindow();
95 CDocument* CImportExportApp::OpenDocumentFile(LPCTSTR lpszFileName)
99 if (!cf.Open(lpszFileName,CFile::modeReadWrite)){
100 AfxMessageBox("File not found!");
104 return CWinApp::OpenDocumentFile(lpszFileName);
107 void CImportExportApp::OnFileOpen()
109 CFileDialog dlg(TRUE,
112 OFN_HIDEREADONLY | OFN_FILEMUSTEXIST,
117 CString initdir(((OCC_App*) AfxGetApp())->GetInitDataDir());
120 dlg.m_ofn.lpstrInitialDir = initdir;
125 POSITION pos = GetFirstDocTemplatePosition();
127 CDocTemplate* pTemplate = GetNextDocTemplate(pos);
128 CString strFilterExt, strFilterName;
129 if (pTemplate->GetDocString(strFilterExt, CDocTemplate::filterExt) &&
130 !strFilterExt.IsEmpty() &&
131 pTemplate->GetDocString(strFilterName, CDocTemplate::filterName) &&
132 !strFilterName.IsEmpty()) {
134 strFilter += strFilterName;
135 ASSERT(!strFilter.IsEmpty()); // must have a file type name
136 strFilter += (TCHAR)'\0'; // next string please
137 strFilter += (TCHAR)'*';
138 strFilter += strFilterExt;
139 strFilter += (TCHAR)'\0'; // next string please
140 dlg.m_ofn.nMaxCustFilter++;
142 // append the "*.*" all files filter
144 VERIFY(allFilter.LoadString(AFX_IDS_ALLFILTER));
145 strFilter += allFilter;
146 strFilter += (TCHAR)'\0'; // next string please
147 strFilter += _T("*.*");
148 strFilter += (TCHAR)'\0'; // last string
149 dlg.m_ofn.nMaxCustFilter++;
150 dlg.m_ofn.lpstrFilter = strFilter;
152 if (dlg.DoModal() == IDOK)
154 AfxGetApp()->OpenDocumentFile(dlg.GetPathName());