📄 viewerview.cpp
字号:
// ViewerView.cpp : implementation of the CViewerView class
//
#include "stdafx.h"
#include "Viewer.h"
#include "ViewerDoc.h"
#include "ViewerView.h"
#include <strstream>
#include "ilogfile.h"
#include "ifeature.h"
#include "ireader.h"
#include "irectangle.h"
#include "ipipeline.h"
#include "istring.h"
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// Constants
static const FME_Int32 kMaxZoomFactor = 35;
static const FME_Int32 kMinZoomFactor = 5;
static const FME_Int32 kZoomIncrement = 5;
static const FME_Int32 kDefaultZoomFactor = 0;
/////////////////////////////////////////////////////////////////////////////
// CViewerView
IMPLEMENT_DYNCREATE(CViewerView, CView)
BEGIN_MESSAGE_MAP(CViewerView, CView)
//{{AFX_MSG_MAP(CViewerView)
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CViewerView construction/destruction
CViewerView::CViewerView()
{
// TODO: add construction code here
zoomFactor_ = 0;
}
CViewerView::~CViewerView()
{
}
BOOL CViewerView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CViewerView drawing
void CViewerView::OnDraw(CDC* pDC)
{
CViewerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
FME_Real64 dMinX;
FME_Real64 dMinY;
FME_Real64 dMaxX;
FME_Real64 dMaxY;
FME_Real64 dRangeX;
FME_Real64 dRangeY;
long sCanvasWidth;
long sCanvasHeight;
FME_Real64 dScaleX;
FME_Real64 dScaleY;
int dX;
int dY;
long i;
long coordCount;
CViewerApp* app = (CViewerApp*)AfxGetApp();
ASSERT(app);
IFMESession* session = app->fmeSession_;
ASSERT(session);
IFMELogFile* logFile = app->fmeLogFile_;
ASSERT(logFile);
IFMEUniversalReader* reader = pDoc->fmeReader_;
if (!reader)
{
return;
}
IFMERectangle* boundingBox = pDoc->fmeBoundingBox_;
ASSERT(boundingBox);
IFMEFactoryPipeline* pipeline = pDoc->fmePipeline_;
ASSERT(pipeline);
FME_MsgNum err = 0;
IFMEFeature* feature = session->createFeature();
ASSERT(feature);
CRect rectClip;
GetClientRect(rectClip);
// Calculate parameters needed for viewport mapping.
dMinX = boundingBox->minX();
dMinY = boundingBox->minY();
dMaxX = boundingBox->maxX();
dMaxY = boundingBox->maxY();
sCanvasWidth = rectClip.right;
sCanvasHeight = rectClip.bottom;
dRangeX = dMaxX - dMinX;
dRangeY = dMaxY - dMinY;
// Compensate for zero width ranges.
if (dRangeX == 0 && dRangeY == 0)
{
dMinX = dMinX - 0.5;
dMinY = dMinY - 0.5;
dMaxX = dMaxX + 0.5;
dMaxY = dMaxY + 0.5;
dRangeX = 1;
dRangeY = 1;
}
else if (dRangeX == 0)
{
dRangeX = dRangeY * 5 / 100;
dMinX = dMinX - dRangeX / 2;
dMaxX = dMaxX + dRangeX / 2;
}
else if ( dRangeY == 0)
{
dRangeY = dRangeX * 5 / 100;
dMinY = dMinY - dRangeY / 2;
dMaxY = dMaxY + dRangeY / 2;
}
// Set to default zoomFactor_ so that view is normal for any new files just opened.
if (pDoc->fileOpenNew_ == FME_TRUE)
{
pDoc->fileOpenNew_ = FME_FALSE;
zoomFactor_ = kDefaultZoomFactor;
}
// Reduce the range of the bounding box around the center. Bounded according to zoomFactor_.
FME_Real64 fmeZoomedMinX = dMinX + ((zoomFactor_ / 100.0) * dRangeX);
FME_Real64 fmeZoomedMaxX = dMaxX - ((zoomFactor_ / 100.0) * dRangeX);
FME_Real64 fmeZoomedMinY = dMinY + ((zoomFactor_ / 100.0) * dRangeY);
FME_Real64 fmeZoomedMaxY = dMaxY - ((zoomFactor_ / 100.0) * dRangeY);
FME_Real64 fmeZoomedRangeX = fmeZoomedMaxX - fmeZoomedMinX;
FME_Real64 fmeZoomedRangeY = fmeZoomedMaxY - fmeZoomedMinY;
// Zoomed too close
if(fmeZoomedRangeX <=0 || fmeZoomedRangeY <=0)
{
return;
}
// This will set the offset so that the constrained area is fully displayed
dScaleX = sCanvasWidth / fmeZoomedRangeX;
dScaleY = sCanvasHeight / fmeZoomedRangeY;
int offSetX = int((zoomFactor_ / 100.0) * dRangeX * dScaleX);
int offSetY = int((zoomFactor_ / 100.0) * dRangeY * dScaleY);
// Set the spatial constraints depending on the zoomFactor_.
feature->setAttribute("fme_search_type", "fme_envelope_intersects");
feature->addCoordinate(fmeZoomedMinX, fmeZoomedMinY);
feature->addCoordinate(fmeZoomedMaxX, fmeZoomedMaxY);
err = reader->setConstraints(*feature);
if (err)
{
logFile->logMessageString("Error setting reader constaints.");
logFile->logMessageString(session->getLastErrorMsg());
return;
}
// Draw the features.
IFMEString* fmeFeatureType = session->createString();
logFile->logMessageString("Drawing features:");
FME_Boolean endOfFile = FME_FALSE;
FME_Boolean endOfPipeline = FME_FALSE;
FME_UInt32 featCount = 0;
while (endOfFile == FME_FALSE)
{
err = reader->read(*feature, endOfFile);
// logFile->logFeature(*feature);
if (err)
{
logFile->logMessageString("Error reading feature.");
logFile->logMessageString(session->getLastErrorMsg());
return;
}
feature->getAttribute("fme_type", *fmeFeatureType);
if (!strcmp(fmeFeatureType->data(), "fme_arc") ||
!strcmp(fmeFeatureType->data(), "fme_ellipse"))
{
err = pipeline->processFeature(*feature);
if (err)
{
logFile->logMessageString("Error processing feature.");
logFile->logMessageString(session->getLastErrorMsg());
return;
}
err = pipeline->getOutputFeature(*feature,endOfPipeline);
if (err)
{
logFile->logMessageString("Error getting output feature.");
logFile->logMessageString(session->getLastErrorMsg());
return;
}
}
// logFile->logFeature(*feature);
coordCount = feature->numCoords();
if (coordCount == 1)
{
dX = int((feature->getXCoordinate(0) - dMinX) * dScaleX) - offSetX;
dY = int((feature->getYCoordinate(0) - dMinY) * dScaleY) - offSetY;
pDC->MoveTo(dX - 1, sCanvasHeight - dY);
pDC->LineTo(dX, sCanvasHeight - dY + 1);
pDC->LineTo(dX + 1, sCanvasHeight - dY);
pDC->LineTo(dX, sCanvasHeight - dY - 1);
pDC->LineTo(dX - 1, sCanvasHeight - dY);
}
else if (coordCount > 1)
{
dX = int((feature->getXCoordinate(0) - dMinX) * dScaleX) - offSetX;
dY = int((feature->getYCoordinate(0) - dMinY) * dScaleY) - offSetY;
pDC->MoveTo(dX, sCanvasHeight - dY);
for (i = 1; i < coordCount; i++)
{
dX = int((feature->getXCoordinate(i) - dMinX) * dScaleX) - offSetX;
dY = int((feature->getYCoordinate(i) - dMinY) * dScaleY) - offSetY;
pDC->LineTo(dX, sCanvasHeight - dY);
}
}
}
// Clean up.
session->destroyString(fmeFeatureType);
session->destroyFeature(feature);
}
/////////////////////////////////////////////////////////////////////////////
// CViewerView diagnostics
#ifdef _DEBUG
void CViewerView::AssertValid() const
{
CView::AssertValid();
}
void CViewerView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CViewerDoc* CViewerView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CViewerDoc)));
return (CViewerDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CViewerView message handlers
void CViewerView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CViewerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if ((pDoc->fileOpened_ == FME_TRUE) && (zoomFactor_ < kMaxZoomFactor))
{
zoomFactor_ += kZoomIncrement;
Invalidate();
}
CView::OnLButtonDown(nFlags, point);
}
void CViewerView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CViewerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if ((pDoc->fileOpened_ == FME_TRUE) && (zoomFactor_ > kMinZoomFactor))
{
zoomFactor_ -= kZoomIncrement;
Invalidate();
}
CView::OnRButtonDown(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -