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

📄 viewerdoc.cpp

📁 GIS格式转换软件vc源码.GIS格式转换软件vc源码.
💻 CPP
字号:
// ViewerDoc.cpp : implementation of the CViewerDoc class
//

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

#include "ViewerDoc.h"

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

#include <strstream>

#include "ireader.h"
#include "irectangle.h"
#include "ilogfile.h"
#include "ifeature.h"
#include "idialog.h"
#include "ipipeline.h"
using namespace std;
/////////////////////////////////////////////////////////////////////////////
// CViewerDoc

IMPLEMENT_DYNCREATE(CViewerDoc, CDocument)

BEGIN_MESSAGE_MAP(CViewerDoc, CDocument)
   //{{AFX_MSG_MAP(CViewerDoc)
   ON_COMMAND(ID_FILE_READ, OnFileRead)
   //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CViewerDoc construction/destruction

CViewerDoc::CViewerDoc()
{
   // TODO: add one-time construction code here
   fmeReader_ = NULL;
   fmeBoundingBox_ = NULL;
   fmePipeline_ = NULL;
   fileOpened_ = FME_FALSE;
   fileOpenNew_ = FME_FALSE;
}

CViewerDoc::~CViewerDoc()
{
}


/////////////////////////////////////////////////////////////////////////////
// CViewerDoc serialization

void CViewerDoc::Serialize(CArchive& ar)
{
   if (ar.IsStoring())
   {
      // TODO: add storing code here
   }
   else
   {
      // TODO: add loading code here
   }
}

/////////////////////////////////////////////////////////////////////////////
// CViewerDoc diagnostics

#ifdef _DEBUG
void CViewerDoc::AssertValid() const
{
   CDocument::AssertValid();
}

void CViewerDoc::Dump(CDumpContext& dc) const
{
   CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CViewerDoc commands

// SDI documents will reuse this document.
BOOL CViewerDoc::OnNewDocument()
{
   if (!CDocument::OnNewDocument())
      return FALSE;
      // TODO: Add your specialized creation code here

   SetTitle("FME Objects Sample Application");
   CViewerApp* app = (CViewerApp*)AfxGetApp();

   if (!fmePipeline_)
   {
      fmePipeline_ = app->fmePipeline_;
   }

   return TRUE;
}

void CViewerDoc::OnFileRead()
{
   // TODO: Add your command handler code here

   CViewerApp* app = (CViewerApp*)AfxGetApp();
   IFMESession* fmeSession = app->fmeSession_;
   IFMELogFile* logFile = app->fmeLogFile_;
   IFMEDialog* dialog = app->fmeDialog_;
   FME_MsgNum err = 0;

   // Create FMEStringArray object for reader directives.
   IFMEStringArray *directives = fmeSession->createStringArray();

   // FME String and String Array to hold the values of the
   // FME Source Dialog.
   IFMEString* format  = fmeSession->createString();
   IFMEString* dataset = fmeSession->createString();

   // Prompt for source dataset.
   if (!dialog->sourcePrompt(NULL, ".\\data", *format, *dataset, *directives))
   {
      // Cancelled, perform local clean up.
      fmeSession->destroyString(format);
      fmeSession->destroyString(dataset);
      fmeSession->destroyStringArray(directives);
      return;
   }

   if (fmeReader_)
   {
      CloseDocument();
   }

   CWaitCursor hourglass;

   const string polygonPipelineFileName("polygon.fmi");
   string polygonPipelineFilePath;

   polygonPipelineFilePath = app->moduleFolder_ + polygonPipelineFileName;

   directives->append(kFME_UserPipeline);
   directives->append(polygonPipelineFilePath.c_str());

   // Create a new reader using caching.
   fmeReader_ = fmeSession->createReader(format->data(), FME_TRUE, directives);

   // Create FMEStringArray object for reader parameters.
   IFMEStringArray *parameters = fmeSession->createStringArray();

   // Open the reader on the input dataset.
   err = fmeReader_->open(dataset->data(), *parameters);
   if (err)
   {
      logFile->logMessageString("Error opening reader");
      logFile->logMessageString(fmeSession->getLastErrorMsg());
      AfxMessageBox(fmeSession->getLastErrorMsg());
      AfxGetMainWnd()->PostMessage(WM_CLOSE);
      return;
   }

   fmeSession->destroyString(format);
   fmeSession->destroyString(dataset);
   fmeSession->destroyStringArray(parameters);
   fmeSession->destroyStringArray(directives);

   //Get the bounding box in ground units.
   FME_Real64 minX, maxX, minY, maxY;
   logFile->logMessageString("Retrieving features:");
   fmeBoundingBox_ = fmeSession->createRectangle(0,0,0,0);
   IFMERectangle* featureBoundingBox = fmeSession->createRectangle(0,0,0,0);
   IFMEFeature* feature = fmeSession->createFeature();
   FME_Boolean endOfFile = FME_FALSE;
   FME_UInt32 featCount = 0;
   while (endOfFile == FME_FALSE)
   {
      err = fmeReader_->read(*feature, endOfFile);
      if (err)
      {
         logFile->logMessageString("Error reading feature");
         logFile->logMessageString(fmeSession->getLastErrorMsg());
         AfxMessageBox(fmeSession->getLastErrorMsg());
         AfxGetMainWnd()->PostMessage(WM_CLOSE);
         return;
      }
      feature->boundingBox(minX, maxX, minY, maxY);
      featureBoundingBox->minX() = minX;
      featureBoundingBox->maxX() = maxX;
      featureBoundingBox->minY() = minY;
      featureBoundingBox->maxY() = maxY;
      if (featCount == 0)
      {
         fmeBoundingBox_->minX() = featureBoundingBox->minX();
         fmeBoundingBox_->maxX() = featureBoundingBox->maxX();
         fmeBoundingBox_->minY() = featureBoundingBox->minY();
         fmeBoundingBox_->maxY() = featureBoundingBox->maxY();
      }
      else
      {
         *fmeBoundingBox_ | *featureBoundingBox;
      }
      // Log the feature.
      if (endOfFile == FME_FALSE)
      {
         featCount++;
//         fmeSession->logFile()->logFeature(*feature);
      }
      if (featCount%100 == 0)
      {
         CString statusMsg;
         statusMsg.Format("Reading feature %d", featCount);
         app->mainFrame_->m_wndStatusBar.SetWindowText(statusMsg);
      }
   }
   CString statusMsg;
   statusMsg.Format("Read %d features", featCount);
   app->mainFrame_->m_wndStatusBar.SetWindowText(statusMsg);

   // Log the number of features retrieved.
   ostrstream logMsg;
   logMsg << "Num features read: " << featCount << " from file." << endl;
   char* buf = logMsg.str();
   logFile->logMessageString(buf);
   delete buf;

   // New file is opened
   fileOpenNew_ = FME_TRUE;
   fileOpened_ = FME_TRUE;

   // Clean up.
   fmeSession->destroyRectangle(featureBoundingBox);
   fmeSession->destroyFeature(feature);

   UpdateAllViews(NULL);
}

void CViewerDoc::CloseDocument()
{
   if (fmeReader_)
   {
      // Close the reader and destroy it.
      CViewerApp* app = (CViewerApp*)AfxGetApp();
      IFMESession* fmeSession = app->fmeSession_;
      IFMELogFile* logFile = app->fmeLogFile_;
      FME_MsgNum err = 0;

      err = fmeReader_->close();
      if (err)
      {
         logFile->logMessageString("Error closing reader");
         logFile->logMessageString(fmeSession->getLastErrorMsg());
      }
      fmeSession->destroyReader(fmeReader_);
      fmeSession->destroyRectangle(fmeBoundingBox_);
      fmeReader_ = NULL;
      fmeBoundingBox_ = NULL;
   }
}

void CViewerDoc::OnCloseDocument()
{
   // TODO: Add your specialized code here and/or call the base class

   if (fmePipeline_)
   {
      // Destroy the pipeline.
      CViewerApp* app = (CViewerApp*)AfxGetApp();
      IFMESession* fmeSession = app->fmeSession_;
      fmeSession->destroyFactoryPipeline(fmePipeline_);
      fmePipeline_ = NULL;
   }
   CDocument::OnCloseDocument();
}

⌨️ 快捷键说明

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