📄 lsview.cpp
字号:
// LSView.cpp : implementation of the CLSView class
//
#include "stdafx.h"
#include "LandSoft.h"
#include "mainfrm.h"
#include "tname.h"
#include "LSDoc.h"
#include "LSView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLSView
IMPLEMENT_DYNCREATE(CLSView, CScrollView)
BEGIN_MESSAGE_MAP(CLSView, CScrollView)
//{{AFX_MSG_MAP(CLSView)
ON_WM_QUERYNEWPALETTE()
ON_WM_PALETTECHANGED()
ON_UPDATE_COMMAND_UI(ID_INDICATOR_BYTES, OnUpdateIndicatorBytes)
ON_UPDATE_COMMAND_UI(ID_INDICATOR_COMPRESS, OnUpdateIndicatorCompress)
ON_UPDATE_COMMAND_UI(ID_INDICATOR_PIXELS, OnUpdateIndicatorPixels)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_UPDATE_COMMAND_UI(ID_INDICATOR_XY,OnUpdateXY)
ON_WM_CREATE()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLSView construction/destruction
CLSView::CLSView()
{
m_ptPrev.x=0;
m_ptPrev.y=0;
}
CLSView::~CLSView()
{
}
BOOL CLSView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CLSView drawing
void CLSView::OnDraw(CDC* pDC) // 图像的显示,调用图像类的Draw()函数
{
CLSDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CRect r;
GetClientRect (r);
pDoc->m_dib.Draw (pDC, r.Width (), r.Height ());
if(pDoc->m_bInfo&&pDoc->m_bShowLine)
{
for(int i=0;i<pDoc->m_InfoLines.GetSize();i++)
{
DrawLine(pDoc->m_InfoLines[i].x1,pDoc->m_InfoLines[i].y1,
pDoc->m_InfoLines[i].x2,pDoc->m_InfoLines[i].y2,pDoc->m_nInfoLeng,i+1);
}
}
if(pDoc->m_bEverAllSpace&&pDoc->m_bShowBox&&(pDoc->m_bRandom==FALSE))
{
double XLong=pDoc->m_nWidth/pDoc->m_nXBox*pDoc->m_Compress;
double YLong=pDoc->m_nHeight/pDoc->m_nYBox*pDoc->m_Compress;
for(int x=1;x<pDoc->m_nXBox;x++)
{
pDC->MoveTo(x*XLong+0.5,0);
pDC->LineTo(x*XLong+0.5,pDoc->m_nHeight);
}
for(int y=1;y<pDoc->m_nYBox;y++)
{
pDC->MoveTo(0,y*YLong+0.5);
pDC->LineTo(pDoc->m_nWidth,y*YLong+0.5);
}
if(XLong>25&&YLong>20)
{
pDC->SetBkMode(TRANSPARENT);
for(int ybox=0;ybox<pDoc->m_nYBox;ybox++)
{
for(int xbox=0;xbox<pDoc->m_nXBox;xbox++)
{
CString tmpstr;
tmpstr.Format("%d",ybox*pDoc->m_nXBox+xbox+1);
pDC->TextOut((xbox+0.5)*XLong-10,(ybox+0.5)*YLong-10,tmpstr);
}
}
}
}
if(pDoc->m_bShowPoint&&pDoc->m_bEverAllSpace)
{
UINT pointnum=pDoc->m_aBoxCoords.GetSize();
double boxleng=pDoc->m_nBoxlong*pDoc->m_Compress;
for(UINT pointi=0;pointi<pointnum;pointi++)
{
int centerx=pDoc->m_aBoxCoords[pointi].x*pDoc->m_Compress+boxleng/2;
int centery=pDoc->m_aBoxCoords[pointi].y*pDoc->m_Compress+boxleng/2;
pDC->Ellipse(centerx-4,centery-4,centerx+4,centery+4);
}
}
}
void CLSView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
OnUpdate (NULL,0,NULL);
// Calc the size of bitmap and set the window position
CSize size(GetDocument()->m_dib.GetSize());
CSize sizeScreen (GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN)); // 得到当前分辨率
int x=size.cx;
int y=size.cy;
GetDocument()->m_Compress=1;
if (x>(sizeScreen.cx*3/4)||y>(sizeScreen.cy*3/4)) // 调整视的大小
{
if ((x/(sizeScreen.cx*3/4))>(y/(sizeScreen.cy*3/4)))
{
x=sizeScreen.cx*3/4;
y=size.cy*(sizeScreen.cx*3/4)/size.cx;
GetDocument()->m_Compress=((double)sizeScreen.cx)*3/4/((double)size.cx);
}
else
{
y=sizeScreen.cy*3/4;
x=size.cx*(sizeScreen.cy*3/4)/size.cy;
GetDocument()->m_Compress=((double)sizeScreen.cy)*3/4/((double)size.cy);
}
}
CRect r(CPoint(0,0),CPoint(x,y));
GetParentFrame()->CalcWindowRect(r);
GetParentFrame()->SetWindowPos(NULL,0,0,r.Width()+4,
r.Height()+GetSystemMetrics(SM_CXVSCROLL)+5,
SWP_NOACTIVATE | SWP_NOZORDER); // 设置视的属性
SetScrollSizes(MM_TEXT, CSize(0,0));
SetWindowText("景观图形显示");
}
/////////////////////////////////////////////////////////////////////////////
// CLSView printing
BOOL CLSView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CLSView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CLSView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CLSView diagnostics
#ifdef _DEBUG
void CLSView::AssertValid() const
{
CScrollView::AssertValid();
}
void CLSView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CLSDoc* CLSView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CLSDoc)));
return (CLSDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CLSView message handlers
// 处理调色版改变消息
BOOL CLSView::RealizePalette(BOOL bForceBkgnd)
{
UINT nColorsChanged;
{
CClientDC dc (this);
nColorsChanged=
DrawDibRealize (GetDocument()->m_dib, dc.GetSafeHdc(), bForceBkgnd);
}
if (nColorsChanged || bForceBkgnd)
Invalidate ();
return (BOOL) nColorsChanged;
}
void CLSView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
if (bActivate)
{
// We're going active to realize our palette in
// the foreground.
RealizePalette (FALSE);
// DrawDibRealize sends WM_PALETTECHANGED to all apps
// if it realizes any new colors. If CDC::RealizePallete
// were used instead of DrawDibRealize, this next line
// of code would be necessary.
// AfxGetMainWnd ()->SendMessage (WM_PALETTECHANGED,
// (WPARAM) GetSafeHwnd (), 0);
}
// CScrollView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}
void CLSView:: OnPaletteChanged (CWnd * pFocusWnd)
{
// Ignore this message if we sent it
if (pFocusWnd == this || IsChild (pFocusWnd))
return;
RealizePalette (TRUE);
}
BOOL CLSView::OnQueryNewPalette()
{
return RealizePalette (FALSE);
// return CScrollView::OnQueryNewPalette();
}
// 以下三个函数显示状态栏数据
void CLSView::OnUpdateIndicatorBytes(CCmdUI* pCmdUI)
{
DWORD dwBytes=GetDocument()->m_dib.FileSize;
CString msg;
msg.Format("%ldK字节",dwBytes/1024);
pCmdUI->SetText(msg);
}
void CLSView::OnUpdateIndicatorCompress(CCmdUI* pCmdUI)
{
double compress=GetDocument()->m_Compress;
CString msg;
if(compress==1)
msg.Format(" ");
else
msg.Format("缩小为:%.4f",compress);
pCmdUI->SetText(msg);
}
void CLSView::OnUpdateIndicatorPixels(CCmdUI* pCmdUI)
{
CLSDoc *pDoc=GetDocument();
CSize size=pDoc->GetSize();
CString msg;
msg.Format("%dx%d像素", size.cx, size.cy);
pCmdUI->SetText(msg);
}
void CLSView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
if(lHint==TXTVIEW)
return;
RedrawWindow();
}
void CLSView::DrawLine(double x1, double y1, double x2, double y2, UINT segleng,int i)
{
double compress=GetDocument()->m_Compress;
x1=x1*compress;
y1=y1*compress;
x2=x2*compress;
y2=y2*compress;
double seg=segleng*compress;
CClientDC dc(this);
OnPrepareDC(&dc);
CPen* pPen=new CPen(PS_SOLID,1,RGB(0,0,0));
dc.SelectObject(pPen);
UINT xx1,xx2,yy1,yy2;
xx1=x1+0.5;
yy1=y1+0.5;
xx2=x2+0.5;
yy2=y2+0.5;
dc.MoveTo(xx1,yy1);
dc.LineTo(xx2,yy2);
CString tmpstr;
tmpstr.Format("样线%d",i);
dc.TextOut((xx1+xx2)/2-25,(yy1+yy2)/2-8,tmpstr);
delete pPen;
if(segleng==0)
return;
pPen=new CPen(PS_SOLID,1,RGB(255,255,0));
dc.SelectObject(pPen);
if(x1==x2)
{
if(y1>y2)
{
double tmp=y2;
y2=y1;
y1=tmp;
}
double pointy=y1;
while(pointy<y2)
{
dc.MoveTo(x1-2+0.5,pointy+0.5);
dc.LineTo(x1+2+0.5,pointy+0.5);
pointy+=seg;
}
delete pPen;
return;
}
if(y1==y2)
{
if(x1>x2)
{
double tmp=x2;
x2=x1;
x1=tmp;
}
double pointx=x1;
while(pointx<x2)
{
dc.MoveTo(pointx+0.5,y1-2+0.5);
dc.LineTo(pointx+0.5,y1+2+0.5);
pointx+=seg;
}
delete pPen;
return;
}
if(x1>x2)
{
double tmpx=x2;
double tmpy=y2;
x2=x1;
y2=y1;
x1=tmpx;
y1=tmpy;
}
double leng=sqrt((x2-x1+1)*(x2-x1+1)+(y2-y1+1)*(y2-y1+1));
double k=(y2-y1)/(x2-x1);
double segx=seg*(x2-x1+1)/leng;
double pointx=x1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -