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 (L"Fatal Error in units initialisation");
35 SampleName = "ImportExport"; //for about dialog
36 SetSamplePath (L"..\\..\\05_ImportExport");
39 /////////////////////////////////////////////////////////////////////////////
40 // The one and only CImportExportApp object
42 CImportExportApp theApp;
44 /////////////////////////////////////////////////////////////////////////////
45 // CImportExportApp initialization
47 BOOL CImportExportApp::InitInstance()
49 AfxEnableControlContainer();
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.
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"));
62 LoadStdProfileSettings(); // Load standard INI file options (including MRU)
64 // Register the application's document templates. Document templates
65 // serve as the connection between documents, frame windows and views.
67 CMultiDocTemplate* pDocTemplate;
68 pDocTemplate = new CMultiDocTemplate(
70 RUNTIME_CLASS(CImportExportDoc),
71 RUNTIME_CLASS(OCC_3dChildFrame),
72 RUNTIME_CLASS(OCC_3dView));
73 AddDocTemplate(pDocTemplate);
75 // create main MDI Frame window
76 OCC_MainFrame* pMainFrame = new OCC_MainFrame(with_AIS_TB);
77 if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
79 m_pMainWnd = pMainFrame;
81 // Parse command line for standard shell commands, DDE, file open
82 CCommandLineInfo cmdInfo;
83 ParseCommandLine(cmdInfo);
85 // Dispatch commands specified on the command line
86 if (!ProcessShellCommand(cmdInfo))
89 // The main window has been initialized, so show and update it.
90 pMainFrame->ShowWindow(m_nCmdShow);
91 pMainFrame->UpdateWindow();
96 CDocument* CImportExportApp::OpenDocumentFile(LPCTSTR lpszFileName)
100 if (!cf.Open(lpszFileName,CFile::modeReadWrite)){
101 AfxMessageBox (L"File not found!");
105 return CWinApp::OpenDocumentFile(lpszFileName);
108 void CImportExportApp::OnFileOpen()
110 CFileDialog dlg(TRUE,
113 OFN_HIDEREADONLY | OFN_FILEMUSTEXIST,
119 initdir.GetEnvironmentVariable (L"CSF_OCCTDataPath");
121 dlg.m_ofn.lpstrInitialDir = initdir;
126 POSITION pos = GetFirstDocTemplatePosition();
128 CDocTemplate* pTemplate = GetNextDocTemplate(pos);
129 CString strFilterExt, strFilterName;
130 if (pTemplate->GetDocString(strFilterExt, CDocTemplate::filterExt) &&
131 !strFilterExt.IsEmpty() &&
132 pTemplate->GetDocString(strFilterName, CDocTemplate::filterName) &&
133 !strFilterName.IsEmpty()) {
135 strFilter += strFilterName;
136 ASSERT(!strFilter.IsEmpty()); // must have a file type name
137 strFilter += L'\0'; // next string please
139 strFilter += strFilterExt;
140 strFilter += L'\0'; // next string please
141 dlg.m_ofn.nMaxCustFilter++;
143 // append the "*.*" all files filter
145 VERIFY(allFilter.LoadString(AFX_IDS_ALLFILTER));
146 strFilter += allFilter;
147 strFilter += L'\0'; // next string please
149 strFilter += L'\0'; // last string
150 dlg.m_ofn.nMaxCustFilter++;
151 dlg.m_ofn.lpstrFilter = strFilter;
153 if (dlg.DoModal() == IDOK)
155 AfxGetApp()->OpenDocumentFile(dlg.GetPathName());