?? honeycomblikedscanningview.cpp
字號:
// HoneycomblikedscanningView.cpp : implementation of the CHoneycomblikedscanningView class
//
#include "stdafx.h"
#include "Honeycomblikedscanning.h"
#include "HoneycomblikedscanningDoc.h"
#include "HoneycomblikedscanningView.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHoneycomblikedscanningView
IMPLEMENT_DYNCREATE(CHoneycomblikedscanningView, CView)
BEGIN_MESSAGE_MAP(CHoneycomblikedscanningView, CView)
//{{AFX_MSG_MAP(CHoneycomblikedscanningView)
ON_WM_TIMER()
ON_COMMAND(ID_SCANNING, OnScanning)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CHoneycomblikedscanningView construction/destruction
CHoneycomblikedscanningView::CHoneycomblikedscanningView()
{
width=0.0;//六邊形邊長
high=0.0;//平行邊間距
radius=0.0;//外接圓半徑
scanningflag=FALSE;
}
CHoneycomblikedscanningView::~CHoneycomblikedscanningView()
{
}
BOOL CHoneycomblikedscanningView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CHoneycomblikedscanningView drawing
void CHoneycomblikedscanningView::OnDraw(CDC* pDC)
{
CHoneycomblikedscanningDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
//
CRect rec(25,25,625,425);
pDC->Rectangle(rec);
CPoint p1(50,50);
CPoint tempoint;
if (scanningflag==TRUE)
{
//輪廓偏置,殼成型
pDC->MoveTo(p1);
pDC->LineTo(600,50);
sleep(2000);
pDC->LineTo(600,400);
sleep(2000);
pDC->LineTo(50,400);
sleep(2000);
pDC->LineTo(50,50);
sleep(2000);
//正六邊形示意圖
pDC->MoveTo(p1.x,int(p1.y+high/2));
pDC->LineTo(int(p1.x+width/2),p1.y);
sleep(100);
pDC->LineTo(int(p1.x+3*width/2),p1.y);
sleep(100);
pDC->LineTo(int(p1.x+radius),int(p1.y+high/2));
sleep(100);
pDC->LineTo(int(p1.x+3*width/2),int(p1.y+high));
sleep(100);
pDC->LineTo(int(p1.x+width/2),int(p1.y+high));
sleep(100);
pDC->LineTo(p1.x,int(p1.y+high/2));
//開始掃描
//第一組平行邊
tempoint.y=p1.y;
while (tempoint.y<=400)
{
tempoint=CPoint(int(p1.x),int(tempoint.y+high/2));
if (tempoint.y<=400)
{while (tempoint.x<=600)//第一行
{
tempoint.x=int(tempoint.x+radius);
pDC->MoveTo(tempoint);
if (tempoint.x<=600)
{
tempoint.x=int(tempoint.x+width);
if (tempoint.x<=600)
{ pDC->LineTo(tempoint);}
else pDC->LineTo(600,tempoint.y);
sleep(100);
}
}
tempoint.y=int(tempoint.y+high/2);//第二行
if (tempoint.y<=400)
{
tempoint.x=int(50+width/2);
pDC->MoveTo(tempoint);
while (tempoint.x<=600)
{
if (tempoint.x<=600)
{
tempoint.x=int(tempoint.x+width);
if (tempoint.x<=600)
{
pDC->LineTo(tempoint);
tempoint.x=int(tempoint.x+radius);
pDC->MoveTo(tempoint);
sleep(100);
}
else pDC->LineTo(600,tempoint.y);
}
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
///第二組平行邊: 左下——右上
/////////////////////////////////////////////////////////////////////////////
int j=0;
int MAX=int(sqrt(375*375+575*575)/(high/2)); //distance/(high/2)
BOOL flag1=FALSE,flag2=FALSE;
CPoint left_pt,right_pt,mid_pt;
//初始化
left_pt.x=p1.x;
left_pt.y=int(p1.y+high/2);
// mid_pt=left_pt;
right_pt.y=p1.y;
right_pt.x=int(p1.x+width/2);
//掃描
for(j=1;j<=MAX;j++)
//while(right_pt.x<=600||left_pt.y<=400)
{
// j++;
pDC->MoveTo(left_pt);
mid_pt.x=left_pt.x+int(width/2);
mid_pt.y=left_pt.y-int(high/2);
while(mid_pt.x<=right_pt.x&&mid_pt.y>=right_pt.y)
{
if (mid_pt.y<=400&&mid_pt.x<=600)
{
pDC->LineTo(mid_pt);
sleep(100);
}
/*
if (mid_pt.x>600&&flag1==FALSE)
{
pDC->LineTo(600,200);
sleep(100);
flag1=TRUE;
}*/
/*
if (mid_pt.y>400&&flag2==FALSE)
{
pDC->LineTo(300,400);
sleep(100);
flag2=TRUE;
}*/
mid_pt.Offset(int(width),-int(high));
pDC->MoveTo(mid_pt);
if(mid_pt.x<=right_pt.x&&mid_pt.y>=right_pt.y)
mid_pt.Offset(int(width/2),-int(high/2));
}
left_pt.y=int(left_pt.y+high);
right_pt.x=int(right_pt.x+width);
flag1=FALSE;flag2=FALSE;
}
//////////////////////////////////////////////////////////////////////////////////////
//第三組平行邊:右下——左上
/////////////////////////////////////////////////////////////////////////////////////
int n,m;
m=int((600-50-width/2)/width);
if (m%3==1)
{
n=m;
}
if (m%3==2)
{
n=m-1;
}
if (m%3==0)
{
n=m+1;
}
// n=m+2;
//CPoint left_pt,right_pt,mid_pt;
//初始化
right_pt.x=int(n*width+50+width);
right_pt.y=int(50+high/2);
left_pt.y=50;
left_pt.x=int(right_pt.x-width/2);
//掃描
for(j=0;j<n+10;j++)
{
pDC->MoveTo(right_pt);
mid_pt.x=right_pt.x-int(width/2);
mid_pt.y=right_pt.y-int(high/2);
while (mid_pt.x>=left_pt.x&&mid_pt.y>=left_pt.y)
{
pDC->LineTo(mid_pt);
sleep(100);
mid_pt.Offset(-int(width),-int(high));
pDC->MoveTo(mid_pt);
mid_pt.Offset(-int(width/2),-int(high/2));
}
right_pt.Offset(0,int(high));
left_pt.Offset(-int(width),0);
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CHoneycomblikedscanningView printing
BOOL CHoneycomblikedscanningView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CHoneycomblikedscanningView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CHoneycomblikedscanningView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CHoneycomblikedscanningView diagnostics
#ifdef _DEBUG
void CHoneycomblikedscanningView::AssertValid() const
{
CView::AssertValid();
}
void CHoneycomblikedscanningView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CHoneycomblikedscanningDoc* CHoneycomblikedscanningView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHoneycomblikedscanningDoc)));
return (CHoneycomblikedscanningDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CHoneycomblikedscanningView message handlers
void CHoneycomblikedscanningView::OnTimer(UINT nIDEvent)
{
// CDC* pDC;
// pDC->LineTo(250,250);
CView::OnTimer(nIDEvent);
}
void CHoneycomblikedscanningView::OnScanning()
{
if(paradlg.DoModal()==IDOK)
{
// MessageBox("hahah!");
if(paradlg.m_width!=0)
{
width=(double)paradlg.m_width;
high=1.732*width;
radius=2.0*width;
scanningflag=TRUE;
}
else
MessageBox("參數輸入錯誤!","警告!",MB_OK|MB_ICONHAND );
}
/*
//CDC *pDC=pWnd->GetDC();
CWnd *pWnd =::GetWindow((HWND)this,GW_HWNDFIRST);
CClientDC dc=pWnd->GetDC();
// dc->CreateCompatibleDC(pDC);
dc->LineTo(100,100);*/
Invalidate(TRUE);
}
void CHoneycomblikedscanningView::sleep(int i)
{
for(int j=0;j<100000*i;j++)
{
;
;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -