📄 yy0view.cpp
字号:
// yy0View.cpp : implementation of the CYy0View class
//
#include "stdafx.h"
#include "yy0.h"
#include "my.h"
#include "bzDialog.h"
#include "yy0Doc.h"
#include "yy0View.h"
#include "math.h"
#define MA 0.002
#define XYD 300
#define YYD 50
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CYy0View
IMPLEMENT_DYNCREATE(CYy0View, CView)
BEGIN_MESSAGE_MAP(CYy0View, CView)
//{{AFX_MSG_MAP(CYy0View)
ON_COMMAND(ID_SHOWTEXT, OnShowtext)
ON_COMMAND(ID_FILE_NEW, OnFileNew)
ON_COMMAND(ID_START, OnStart)
ON_UPDATE_COMMAND_UI(ID_START, OnUpdateStart)
ON_WM_PAINT()
ON_COMMAND(ID_SHOWBZ, OnShowbz)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CYy0View construction/destruction
CYy0View::CYy0View()
{
// TODO: add construction code here
k=1;
l=1;
x_point[0]=0;
y_point[0]=0;
x_apoint[0]=XYD;
y_apoint[0]=YYD;
x_pos=0;
y_pos=0;
x_pos1=x_pos2=300;
y_pos1=y_pos2=150;
m_Start=FALSE;
}
CYy0View::~CYy0View()
{
}
BOOL CYy0View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CYy0View drawing
void CYy0View::OnDraw(CDC* pDC)
{
CYy0Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CYy0View printing
BOOL CYy0View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CYy0View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CYy0View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CYy0View diagnostics
#ifdef _DEBUG
void CYy0View::AssertValid() const
{
CView::AssertValid();
}
void CYy0View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CYy0Doc* CYy0View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CYy0Doc)));
return (CYy0Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CYy0View message handlers
void CYy0View::OnFileNew()
{
// TODO: Add your command handler code here
Cmy dlg;
dlg.DoModal();
}
void CYy0View::OnShowbz()
{
// TODO: Add your command handler code here
CbzDialog dlg;
dlg.DoModal();
}
void CYy0View::OnShowtext()
{
// TODO: Add your command handler code here
Cmy dlg;
if (dlg.DoModal() != IDOK)
return;
else
{
text1=dlg.m_g90;
text2=dlg.m_g98;
text3=dlg.m_g81;
m_k=dlg.m_zks;
m_r=dlg.m_kd;
m_rc=dlg.m_r + YYD;
m_z1=dlg.m_sz + YYD;
m_z2=dlg.m_ydz + YYD;
x_point[1]=dlg.m_pos1x;
y_point[1]=dlg.m_pos1y;
x_point[2]=dlg.m_pos2x;
y_point[2]=dlg.m_pos2y;
x_point[3]=dlg.m_pos3x;
y_point[3]=dlg.m_pos3y;
x_point[4]=dlg.m_pos4x;
y_point[4]=dlg.m_pos4y;
x_point[5]=dlg.m_pos5x;
y_point[5]=dlg.m_pos5y;
x_point[6]=dlg.m_pos6x;
y_point[6]=dlg.m_pos6y;
x_point[7]=dlg.m_pos7x;
y_point[7]=dlg.m_pos7y;
x_point[8]=dlg.m_pos8x;
y_point[8]=dlg.m_pos8y;
for( int p=0;p<=8;p++)
{
x_apoint[p]=x_point[p] + XYD;
y_apoint[p]=y_point[p] + YYD;
}
//用增量方式
if (text1 == "G91")
{
for (int p=2;p <= m_k;p++)
{
x_point[p]+=x_point[p-1];
y_point[p]+=y_point[p-1];
x_apoint[p]=x_point[p] + XYD;
y_apoint[p]=y_point[p] + YYD;
}
}
}
Invalidate();
}
void CYy0View::OnStart()
{
// TODO: Add your command handler code here
m_Start= !m_Start;
}
void CYy0View::OnUpdateStart(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_Start);
}
void CYy0View::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
//画坐标
dc.SetMapMode(4);
dc.SetViewportOrg(20,260);
dc.MoveTo(-5,260);
dc.LineTo(0,270);
dc.LineTo(5,260);
dc.MoveTo(0,270);
dc.LineTo(0,0);
dc.LineTo(270,0);
dc.LineTo(260,5);
dc.MoveTo(270,0);
dc.LineTo(260,-5);
dc.TextOut(-10,260,"Y",1);
dc.TextOut(-5,-5,"O",1);
dc.TextOut(260,-10,"X",1);
dc.MoveTo(295,260);
dc.LineTo(300,270);
dc.LineTo(305,260);
dc.MoveTo(300,270);
dc.LineTo(300,-10);
dc.MoveTo(300,50);
dc.LineTo(580,50);
dc.LineTo(570,55);
dc.MoveTo(580,50);
dc.LineTo(570,45);
dc.TextOut(280,260,"Z",1);
dc.TextOut(280,40,"O",1);
dc.TextOut(570,70,"X",1);
dc.SelectObject(new CPen(PS_SOLID,4,RGB(0,0,0)));
dc.MoveTo(275,-60);
dc.LineTo(275,300);
dc.TextOut(20,-20,"XOY平面轨迹图",13);
dc.TextOut(320,-20,"XOZ平面轨迹图",13);
if(m_Start) //按开始键
{
while(k<=m_k+1)
{
//求每次移动的距离
d=(int) sqrt(((x_point[k]-x_point[k-1])*(x_point[k]-x_point[k-1])+
(y_point[k]-y_point[k-1])*(y_point[k]-y_point[k-1]))/2);
cy= (y_point[k]-y_point[k-1])/d;
cx= (x_point[k]-x_point[k-1])/d;
t=0; //移动标志
while (t == 0)
{
//擦除轨迹
dc.SelectObject(new CPen(PS_SOLID,2,RGB(255,255,255)));
dc.Ellipse((int) x_pos-m_r/2,(int) y_pos+m_r/2,
(int) x_pos+m_r/2,( int) y_pos-m_r/2);
dc.MoveTo((int) x_pos1,150);
dc.LineTo((int) x_pos1-m_r/2,156);
dc.LineTo((int) x_pos1-m_r/2,166);
dc.MoveTo((int) x_pos1,150);
dc.LineTo((int) x_pos1+m_r/2,156);
dc.LineTo((int) x_pos1+m_r/2,166);
x_pos+=cx;
y_pos+=cy;
x_pos1+=cx;
// 画轨迹
dc.SelectObject(new CPen(PS_SOLID,2,RGB(255,0,0)));
dc.Ellipse((int) x_pos-m_r/2,(int) y_pos+m_r/2,
(int) x_pos+m_r/2,(int) y_pos-m_r/2);
dc.MoveTo((int) x_pos1,150);
dc.LineTo((int) x_pos1-m_r/2,156);
dc.LineTo((int) x_pos1-m_r/2,166);
dc.MoveTo((int) x_pos1,150);
dc.LineTo((int) x_pos1+m_r/2,156);
dc.LineTo((int) x_pos1+m_r/2,166);
Sleep (60);
//误差控制
if (fabs(x_point[k]-x_pos)<=MA && fabs(y_point[k]-y_pos) <=MA)
{
x_point[k]=x_pos;
y_point[k]=y_pos;
}
if (x_point[k] == x_pos && y_point[k] == y_pos)
t=1; //判断是否到达钻孔点
}
if( k == m_k+1 ) break;
x_pos2=(int) x_apoint[k];
pp[0].y=y_pos2=150;
pp[1].y=m_rc;
pp[2].y=m_z1;
pp[3].y=150;
// 钻孔
while (l<=3)
{
if(pp[l].y > pp[l-1].y) m=1;
else m=-1;
cy1=2*m;
dc.SelectObject(new CPen(PS_SOLID,2,RGB(255,255,255)));
dc.MoveTo(x_pos2,y_pos2);
dc.LineTo(x_pos2-m_r/2,y_pos2+6);
dc.LineTo(x_pos2-m_r/2,y_pos2+16);
dc.MoveTo(x_pos2,y_pos2);
dc.LineTo(x_pos2+m_r/2,y_pos2+6);
dc.LineTo(x_pos2+m_r/2,y_pos2+16);
y_pos2=y_pos2+cy1;
dc.SelectObject(new CPen(PS_SOLID,2,RGB(255,0,0)));
dc.MoveTo(x_pos2,y_pos2);
dc.LineTo(x_pos2-m_r/2,y_pos2+6);
dc.LineTo(x_pos2-m_r/2,y_pos2+16);
dc.MoveTo(x_pos2,y_pos2);
dc.LineTo(x_pos2+m_r/2,y_pos2+6);
dc.LineTo(x_pos2+m_r/2,y_pos2+16);
Sleep(100);
if (pp[l].y == y_pos2) l++;
}
if(text2=="G99" && k<m_k) l=2; // 判断是否是G99方式
else l=1;
k++;
}
}
// Do not call CView::OnPaint() for painting messages
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -