📄 forestview.cpp
字号:
// forestView.cpp : implementation of the CForestView class
//
#include "stdafx.h"
#include "forest.h"
#include "forestDoc.h"
#include "forestView.h"
#include "height.h"
#include <stdio.h>
#include <fstream.h>
#include <math.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CString str;//文件路径
int begin=0;
int onlyonce=1;
/////////////////////////////////////////////////////////////////////////////
// CForestView
IMPLEMENT_DYNCREATE(CForestView, CView)
BEGIN_MESSAGE_MAP(CForestView, CView)
//{{AFX_MSG_MAP(CForestView)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_HEIGHT, OnHeight)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CForestView construction/destruction
CForestView::CForestView()
{
// TODO: add construction code here
type=5;
}
CForestView::~CForestView()
{
}
BOOL CForestView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CForestView drawing
void CForestView::OnDraw(CDC* pDC)
{
CForestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
if(onlyonce) {MessageBox("请在文件菜单下打开数据文件");onlyonce=0;}
if(begin) Draw();
}
/////////////////////////////////////////////////////////////////////////////
// CForestView printing
BOOL CForestView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CForestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CForestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CForestView diagnostics
#ifdef _DEBUG
void CForestView::AssertValid() const
{
CView::AssertValid();
}
void CForestView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CForestDoc* CForestView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CForestDoc)));
return (CForestDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CForestView message handlers
void CForestView::OnFileOpen()
{
// TODO: Add your command handler code here
CFileDialog dlg(TRUE);
if(dlg.DoModal()==IDOK)
{
str=dlg.GetPathName();
begin=1;
Draw();
MessageBox(" 仅供参考,请勿转载。");
}
}
void CForestView::OnPrepareDC(CDC *pDC, CPrintInfo *pInfo)
{
}
void CForestView::OnHeight()
{
// TODO: Add your command handler code here
height dlg;
dlg.m_height=type;
if(IDOK==dlg.DoModal())
{
type=dlg.m_height;
}
Invalidate();
}
void CForestView::Draw()
{
FILE *f1=fopen(str,"r");
if(f1==NULL)
{
MessageBox("文件打不开!");
exit(1);
}
ifstream fin;
fin.open (str,ios::in|ios::nocreate);
if(!fin)
{
cerr<<"文件打不开!"<<endl;
exit(1);
}
char str1[10];
fin>>str1;
int scal;
fin>>scal;
double x1,x2,y1,y2;
char c;
fin>>x1>>c>>x2>>c>>y1>>c>>y2;
CClientDC dc(this);
dc.SetMapMode(MM_ANISOTROPIC);
dc.SetWindowOrg(x1+7500,y1);
dc.SetWindowExt(fabs(x1-x2)-9500,fabs(y1-y2)-2000);
dc.SetViewportExt(1100,650);
while(1)
{
int mark,draw=0;int Hdraw=0;
fin>>mark;
if(mark==0) break;
if(mark==71011) draw=1;
else draw=2;
float height;
fin>>height;
if(int(height)%type==0) Hdraw=1;
int number;
fin>>number;
float startx,starty;char c;
fin>>startx>>c>>starty;
switch(draw)
{
case 1:
{
for(int i=0;i<number-1;i++)
{
float x,y;char c;
fin>>x>>c>>y;
if(Hdraw)
{
dc.MoveTo(startx,starty);
dc.LineTo(x,y);
startx=x;
starty=y;
}
}
}
break;
case 2:
{
for(int j=0;j<number-1;j++)
{
float x,y;char c;
fin>>x>>c>>y;
if(Hdraw)
{
CPen pen(0,1,RGB(0,255,0));
CPen *oldpen=dc.SelectObject(&pen);
dc.MoveTo(startx,starty);
dc.LineTo(x,y);
startx=x;
starty=y;
dc.SelectObject(oldpen);
}
}
}
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -