Solidgraph.cpp
Upload User: kairuinn
Upload Date: 2009-02-07
Package Size: 2922k
Code Size: 15k
Category:

Graph program

Development Platform:

Visual C++

  1. // Solidgraph.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include <shlwapi.h>
  5. #include "Solidgraph.h"
  6. #include "MainFrm.h"
  7. #include "DocManagerEx.h"
  8. #include "OneDocTemplate.h"
  9. #include "ChildFrm.h"
  10. #include "SolidgraphDoc.h"
  11. #include "SolidgraphView.h"
  12. #include "ReportChildFrame.h"
  13. #include "ReportCreatorDoc.h"
  14. #include "ReportCreatorView.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #endif
  18. // CSolidgraphApp
  19. BEGIN_MESSAGE_MAP(CSolidgraphApp, CWinApp)
  20.   ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  21.   // Standard file based document commands
  22.   ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  23.   ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  24.   ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  25.   ON_COMMAND(ID_REPORT_FILE_NEW, CWinApp::OnFileNew)
  26.   ON_COMMAND(ID_REPORT_FILE_OPEN, CWinApp::OnFileOpen)
  27.   // Standard print setup command
  28. END_MESSAGE_MAP()
  29. // CSolidgraphApp construction
  30. CSolidgraphApp::CSolidgraphApp()
  31. {
  32.   EnableHtmlHelp();
  33.   //m_main_tree_control = new CGlobalTree;
  34.   m_main_pluginer = new CPluginLoader;
  35.   m_reg_manager   = NULL;
  36. }
  37. CSolidgraphApp::~CSolidgraphApp()
  38. {
  39.   if (m_main_pluginer)
  40.     delete m_main_pluginer;
  41.   if (m_main_tree_control)
  42.     delete m_main_tree_control;
  43.   if (m_reg_manager)
  44.   delete m_reg_manager;
  45. }
  46. // The one and only CSolidgraphApp object
  47. CSolidgraphApp theApp;
  48. bool translate_messages_through_app = false;
  49. static UINT menuIDs[] =
  50. {
  51.     1, // STUB
  52.     ID_FILE_OPEN,
  53.     NULL
  54. };
  55. BOOL CSolidgraphApp::InitInstance()
  56. {
  57.   typedef void(*LPDLLFUNC_START_SPLASH)();
  58.   LPDLLFUNC_START_SPLASH lpfnDllFuncStartSplash = NULL;
  59.   typedef void(*LPDLLFUNC_END_SPLASH)(HWND);
  60.   LPDLLFUNC_END_SPLASH lpfnDllFuncEndSplash = NULL;
  61.   HINSTANCE hDLL = NULL;
  62.   hDLL = AfxLoadLibrary("SplashLib.dll");
  63.   if(hDLL)
  64.   {
  65.     lpfnDllFuncStartSplash = (LPDLLFUNC_START_SPLASH)::GetProcAddress(hDLL,"StartSplash");
  66.     if (!lpfnDllFuncStartSplash)
  67.     {
  68.       AfxFreeLibrary(hDLL);
  69.       hDLL = NULL;
  70.     }
  71.     lpfnDllFuncEndSplash = (LPDLLFUNC_END_SPLASH)::GetProcAddress(hDLL,"EndSplash");
  72.     if (!lpfnDllFuncEndSplash)
  73.     {
  74.       AfxFreeLibrary(hDLL);
  75.       hDLL = NULL;
  76.     }
  77.     lpfnDllFuncStartSplash();
  78.   }
  79.   // InitCommonControls() is required on Windows XP if an application
  80.   // manifest specifies use of ComCtl32.dll version 6 or later to enable
  81.   // visual styles.  Otherwise, any window creation will fail.
  82.   InitCommonControls();
  83.   CWinApp::InitInstance();
  84.   m_main_tree_control = new CGlobalTree;
  85.   // Initialize OLE libraries
  86.   if (!AfxOleInit())
  87.   {
  88.     AfxMessageBox(IDP_OLE_INIT_FAILED);
  89.     if(hDLL)
  90.     {
  91.       if (lpfnDllFuncEndSplash)
  92.         lpfnDllFuncEndSplash(NULL);
  93.       AfxFreeLibrary(hDLL);
  94.       hDLL = NULL;
  95.     }
  96.     return FALSE;
  97.   }
  98.   AfxInitRichEdit();
  99.   AfxEnableControlContainer();
  100.   // Standard initialization
  101.   // If you are not using these features and wish to reduce the size
  102.   // of your final executable, you should remove from the following
  103.   // the specific initialization routines you do not need
  104.   // Change the registry key under which our settings are stored
  105.   // TODO: You should modify this string to be something appropriate
  106.   // such as the name of your company or organization
  107.   SetRegistryKey(COMPANY_NAME_FOR_REGISTER);
  108.   m_reg_manager = new CRegisterManager(this);
  109.   LoadStdProfileSettings(4);  // Load standard INI file options (including MRU)
  110.   // Register the application's document templates.  Document templates
  111.   //  serve as the connection between documents, frame windows and views
  112.   m_reg_manager->LoadSettings();
  113.   CEGMenu::SetMenuDrawMode( m_reg_manager->m_register_settings.interface_theme );
  114.   CEGMenu::SetXpBlending(FALSE);
  115.   CEGMenu::SetAcceleratorsDraw(TRUE);
  116.   HMODULE h = ::GetModuleHandle( NULL );
  117.   TCHAR szPath[MAX_PATH];
  118.   GetModuleFileName( h, szPath, MAX_PATH );
  119.   PathRemoveFileSpec(szPath);
  120.   CString tmpStr(szPath);
  121.   tmpStr += "\";
  122.   m_application_Path = tmpStr;
  123.   m_FontsPathsArray.clear();
  124.   sgInitKernel();
  125.   sgC3DObject::AutoTriangulate(true, SG_DELAUNAY_TRIANGULATION);
  126.   LuaRegister();
  127.   sgSetApplicationInterface(this);
  128.   GetFontFiles("");
  129.   /*
  130. Only in register version
  131. */
  132.   
  133.   if (m_main_pluginer)
  134.     m_main_pluginer->LoadAllPlugins();
  135.   m_pDocManager = new CDocManagerEx;        // we replace the default doc manager
  136.   COneDocTemplate* pDocTemplateGeometry;
  137.   pDocTemplateGeometry = new COneDocTemplate(IDR_GEOMETRY_TYPE,
  138.     RUNTIME_CLASS(CSolidgraphDoc),
  139.     RUNTIME_CLASS(CChildFrame),
  140.     RUNTIME_CLASS(CSolidgraphView));
  141.   if (!pDocTemplateGeometry)
  142.   {
  143.     if(hDLL)
  144.     {
  145.       if (lpfnDllFuncEndSplash)
  146.         lpfnDllFuncEndSplash(NULL);
  147.       AfxFreeLibrary(hDLL);
  148.       hDLL = NULL;
  149.     }
  150.     return FALSE;
  151.   }
  152.   AddDocTemplate(pDocTemplateGeometry);
  153.   COneDocTemplate* pDocTemplateReport;
  154.   pDocTemplateReport = new COneDocTemplate(IDR_REPORT_TYPE,
  155.     RUNTIME_CLASS(CReportCreatorDoc),
  156.     RUNTIME_CLASS(CReportChildFrame),
  157.     RUNTIME_CLASS(CReportCreatorView));
  158.   if (!pDocTemplateReport)
  159.   {
  160.     if(hDLL)
  161.     {
  162.       if (lpfnDllFuncEndSplash)
  163.         lpfnDllFuncEndSplash(NULL);
  164.       AfxFreeLibrary(hDLL);
  165.       hDLL = NULL;
  166.     }
  167.     return FALSE;
  168.   }
  169.   AddDocTemplate(pDocTemplateReport);
  170.   HBITMAP hBmp = CombineResources( 16, IDB_GEOMETRY_TOOLBAR_TC, NULL );
  171.   BITMAPINFO bi;
  172.   memset( &bi, 0, sizeof(BITMAPINFO) );
  173.   GetBitmapInfo( hBmp, &bi );
  174.   pDocTemplateGeometry->m_NewMenuShared.LoadToolBar( hBmp, CSize( bi.bmiHeader.biWidth, 16 ), menuIDs, CLR_NONE );
  175.   pDocTemplateGeometry->m_NewMenuShared.SetMenuItemBitmap(ID_FILE_OPEN,IDB_DEL_OBJ_TC,AfxGetResourceHandle());
  176.   DeleteObject(hBmp);
  177.   // create main MDI Frame window
  178.   CMainFrame* pMainFrame = new CMainFrame;
  179.   if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
  180.   {
  181.     if(hDLL)
  182.     {
  183.       if (lpfnDllFuncEndSplash)
  184.         lpfnDllFuncEndSplash(NULL);
  185.       AfxFreeLibrary(hDLL);
  186.       hDLL = NULL;
  187.     }
  188.     return FALSE;
  189.   }
  190.   m_pMainWnd = pMainFrame;
  191.   // call DragAcceptFiles only if there's a suffix
  192.   //  In an MDI app, this should occur immediately after setting m_pMainWnd
  193.   // Enable drag/drop open
  194.   m_pMainWnd->DragAcceptFiles();
  195.   // Enable DDE Execute open
  196.   EnableShellOpen();
  197.   RegisterShellFileTypes();
  198.   // Parse command line for standard shell commands, DDE, file open
  199.   CCommandLineInfo cmdInfo;
  200.   ParseCommandLine(cmdInfo);
  201.   // Dispatch commands specified on the command line.  Will return FALSE if
  202.   // app was launched with /RegServer, /Register, /Unregserver or /Unregister.
  203.   //if (cmdInfo.m_strFileName.IsEmpty())
  204.   //  cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
  205.   ((CDocManagerEx*)m_pDocManager)->StartApplication(cmdInfo);
  206.   if(hDLL)
  207.   {
  208.     if (lpfnDllFuncEndSplash)
  209.       lpfnDllFuncEndSplash(pMainFrame->m_hWnd);
  210.     AfxFreeLibrary(hDLL);
  211.     hDLL = NULL;
  212.   }
  213.   // The main window has been initialized, so show and update it
  214.   pMainFrame->ShowWindow(SW_SHOWMAXIMIZED);
  215.   pMainFrame->UpdateWindow();
  216.   return TRUE;
  217. }
  218. IProgresser*  CSolidgraphApp::GetProgresser()
  219. {return  static_cast<CMainFrame*>(m_pMainWnd);}
  220. ISceneTreeControl*  CSolidgraphApp::GetSceneTreeControl()
  221. {return m_main_tree_control;}
  222. void  CSolidgraphApp::GetFontFiles(CString sPath)
  223. {
  224.   if (m_FontsPathsArray.size()>=512)
  225.     return;
  226.   CString sStr;
  227.   CString sCurFullPath=m_application_Path;
  228.   sCurFullPath+=sPath;
  229.   sCurFullPath+="*";
  230.   WIN32_FIND_DATA FindData;
  231.   HANDLE hFindFiles=FindFirstFile(sCurFullPath,&FindData);
  232.   if (hFindFiles==INVALID_HANDLE_VALUE) return;
  233.   for(;;)
  234.   {
  235.     if ((strcmp(FindData.cFileName,".")!=0) && (strcmp(FindData.cFileName,"..")!=0))
  236.     {
  237.       if (FindData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
  238.       {
  239.         sStr=sPath;
  240.         sStr+=FindData.cFileName;
  241.         sStr+="\";
  242.         GetFontFiles(sStr);
  243.       }
  244.       else
  245.       {
  246.         char *ptr=strrchr(FindData.cFileName,'.');
  247.         if (ptr)
  248.         {
  249.           if (strlen(ptr)==4)
  250.           {
  251.             if ((ptr[1]=='s' && ptr[2]=='h' && ptr[3]=='x') ||
  252.               (ptr[1]=='S' && ptr[2]=='H' && ptr[3]=='X'))   //镳钼屦赅 疣聒桊屙