⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 viewer.cpp

📁 GIS格式转换软件vc源码.GIS格式转换软件vc源码.
💻 CPP
字号:
// Viewer.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "Viewer.h"

#include "MainFrm.h"
#include "ViewerDoc.h"
#include "ViewerView.h"

#include <idialog.h>
#include <ilogfile.h>
#include <ifeature.h>
#include <ipipeline.h>


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CViewerApp

BEGIN_MESSAGE_MAP(CViewerApp, CWinApp)
   //{{AFX_MSG_MAP(CViewerApp)
   ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
      // NOTE - the ClassWizard will add and remove mapping macros here.
      //    DO NOT EDIT what you see in these blocks of generated code!
   //}}AFX_MSG_MAP
   // Standard file based document commands
   ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
   ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CViewerApp construction

CViewerApp::CViewerApp()
{
   // TODO: add construction code here,
   // Place all significant initialization in InitInstance
   fmeSession_ = NULL;
   fmeLogFile_ = NULL;
   fmeDialog_ = NULL;
   fmePipeline_ = NULL;
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CViewerApp object

CViewerApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CViewerApp initialization

BOOL CViewerApp::InitInstance()
{
   // Standard initialization
   // If you are not using these features and wish to reduce the size
   //  of your final executable, you should remove from the following
   //  the specific initialization routines you do not need.



   // Change the registry key under which our settings are stored.
   // TODO: You should modify this string to be something appropriate
   // such as the name of your company or organization.
   SetRegistryKey(_T("Local AppWizard-Generated Applications"));

   LoadStdProfileSettings(0);  // Load standard INI file options (including MRU)

   // Register the application's document templates.  Document templates
   //  serve as the connection between documents, frame windows and views.
   CSingleDocTemplate* pDocTemplate;
   pDocTemplate = new CSingleDocTemplate(
      IDR_MAINFRAME,
      RUNTIME_CLASS(CViewerDoc),
      RUNTIME_CLASS(CMainFrame),       // main SDI frame window
      RUNTIME_CLASS(CViewerView));

   AddDocTemplate(pDocTemplate);

   // Create main Frame window.
//   CMainFrame* pMainFrame = new CMainFrame;
//   if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
//      return FALSE;
//   m_pMainWnd = pMainFrame;

   // Create the FMESession object
   FME_MsgNum err = FME_createSession(fmeSession_);
   if (err)
   {
      AfxMessageBox("FME session creation failed.");
      return FALSE;
   }

   // Initialize the FMESession object
   err = fmeSession_->init(NULL);
   if (err)
   {
      AfxMessageBox("FME session initialization failed.");
      return FALSE;
   }

   // Get the FMELogFile object
   fmeLogFile_ = fmeSession_->logFile();

   // Put the log file in the current directory
   string modulePath, moduleName;
   string logFilePath, logFileFolder, logFileName;
   const string logFileExtension("log");
   const string releaseFolderName("Release\\");
   const string debugFolderName("Debug\\");

   char tempPath[1000];
   GetModuleFileName(NULL, tempPath, 1000);
   modulePath = tempPath;
   string::size_type idx = modulePath.rfind('\\');
   moduleName = modulePath.substr(idx+1, string::npos);
   moduleFolder_ = modulePath.substr(0, idx+1); // keep the trailing separator.
   logFileName = moduleName;
   idx = logFileName.find('.');
   logFileName.replace(idx+1, string::npos, logFileExtension);

   // Strip of the Release or Debug Folder if they are present
   idx = moduleFolder_.length() - releaseFolderName.length();
   if (moduleFolder_.substr(idx) == releaseFolderName)
   {
      moduleFolder_ = moduleFolder_.substr(0, idx);
   }
   else
   {
      idx = moduleFolder_.length() - debugFolderName.length();
      if (moduleFolder_.substr(idx) == debugFolderName)
      {
         moduleFolder_ = moduleFolder_.substr(0, idx);
      }
   }
   logFilePath = moduleFolder_ + logFileName;

   // Set the logfile name
   err = fmeLogFile_->setFileName(logFilePath.c_str(), FME_FALSE);
   if (err)
   {
      AfxMessageBox(fmeSession_->getLastErrorMsg());
      return FALSE;
   }

   fmeLogFile_->logMessageString("Viewer instance initialization completed.");

   err = fmeSession_->createDialog(fmeDialog_);
   if (err)
   {
      fmeLogFile_->logMessageString("Error creating dialog");
      fmeLogFile_->logMessageString(fmeSession_->getLastErrorMsg());
      AfxMessageBox(fmeSession_->getLastErrorMsg());
      return FALSE;
   }

   const string arcPipelineFileName("arc.fmi");
   string arcPipelineFilePath;

   arcPipelineFilePath = moduleFolder_ + arcPipelineFileName;

   fmePipeline_ = fmeSession_->createFactoryPipeline("Stroke Arcs", NULL);
   if (!fmePipeline_)
   {
      fmeLogFile_->logMessageString("Error creating pipeline.");
      fmeLogFile_->logMessageString(fmeSession_->getLastErrorMsg());
      AfxMessageBox(fmeSession_->getLastErrorMsg());
      return FALSE;
   }
   err = fmePipeline_->addFactories(arcPipelineFilePath.c_str());
   if (err)
   {
      fmeLogFile_->logMessageString("Error adding Stroke Arcs factories to pipeline.");
      fmeLogFile_->logMessageString(fmeSession_->getLastErrorMsg());
      AfxMessageBox(fmeSession_->getLastErrorMsg());
      return FALSE;
   }

   // Force a new document/frame/view to be created right now
   OnFileNew();

   // The one and only window has been initialized, so show and update it
   m_pMainWnd->UpdateWindow();

   // This window is actually our main frame class, let's store it for later
   // so we can update the nav bar whenever we want.
   ASSERT(m_pMainWnd->IsKindOf(RUNTIME_CLASS(CMainFrame)));
   mainFrame_ = (CMainFrame *)m_pMainWnd;

   // Set the FME Dialog package to know the parent window
   fmeDialog_->setParentWindow(mainFrame_->m_hWnd);

   // Parse command line for standard shell commands, DDE, file open
   CCommandLineInfo cmdInfo;
   ParseCommandLine(cmdInfo);

   // Dispatch commands specified on the command line
   if (!ProcessShellCommand(cmdInfo))
      return FALSE;

   // The one and only window has been initialized, so show and update it.
   m_pMainWnd->ShowWindow(SW_SHOW);
   m_pMainWnd->UpdateWindow();

   return TRUE;
}


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
   CAboutDlg();

// Dialog Data
   //{{AFX_DATA(CAboutDlg)
   enum { IDD = IDD_ABOUTBOX };
   //}}AFX_DATA

   // ClassWizard generated virtual function overrides
   //{{AFX_VIRTUAL(CAboutDlg)
   protected:
   virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
   //}}AFX_VIRTUAL

// Implementation
protected:
   //{{AFX_MSG(CAboutDlg)
      // No message handlers
   //}}AFX_MSG
   DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
   //{{AFX_DATA_INIT(CAboutDlg)
   //}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
   CDialog::DoDataExchange(pDX);
   //{{AFX_DATA_MAP(CAboutDlg)
   //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
   //{{AFX_MSG_MAP(CAboutDlg)
      // No message handlers
   //}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void CViewerApp::OnAppAbout()
{
   CAboutDlg aboutDlg;
   aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CViewerApp message handlers


int CViewerApp::ExitInstance()
{
   // TODO: Add your specialized code here and/or call the base class

   fmeSession_->destroyDialog(fmeDialog_);
   FME_MsgNum err = FME_destroySession(fmeSession_);
   if (err)
   {
      fmeLogFile_->logMessageString("Error destroying session.");
   }

   return CWinApp::ExitInstance();
}

void CViewerApp::AddToRecentFileList(LPCTSTR lpszPathName)
{
   // TODO: Add your specialized code here and/or call the base class

   CWinApp::AddToRecentFileList(lpszPathName);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -