⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1view.cpp

📁 该软件能很好地实现数控机床上的G00
💻 CPP
字号:
// 1View.cpp : implementation of the CMy1View class
//

#include "stdafx.h"
#include "1.h"
#include "stdio.h"
#include "1Doc.h"
#include "1View.h"
#include "string.h"
#include "FDialog.h"
#include "math.h"
#include "conio.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#define WM_MYSTRING WM_USER + 100
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMy1View

IMPLEMENT_DYNCREATE(CMy1View, CEditView)

BEGIN_MESSAGE_MAP(CMy1View, CEditView)
	//{{AFX_MSG_MAP(CMy1View)
	ON_BN_CLICKED(IDC_BUTTONFZ, OnButtonfz)
	ON_WM_ERASEBKGND()
	ON_BN_CLICKED(IDC_BUTTONCX, OnButtoncx)
	ON_EN_UPDATE(IDC_EDITX, OnUpdateEditx)
	ON_BN_CLICKED(IDC_BUTTONX1, OnButtonx1)
	ON_BN_CLICKED(IDC_BUTTONX2, OnButtonx2)
	ON_BN_CLICKED(IDC_BUTTONY1, OnButtony1)
	ON_BN_CLICKED(IDC_BUTTONY2, OnButtony2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy1View construction/destruction
CMy1View::CMy1View()
{ 
	// TODO: add construction code here

}

CMy1View::~CMy1View()
{
}

BOOL CMy1View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	BOOL bPreCreated = CEditView::PreCreateWindow(cs);
	cs.style &= ~(ES_AUTOHSCROLL|WS_HSCROLL);	// Enable word-wrapping

	return bPreCreated;
}

/////////////////////////////////////////////////////////////////////////////
// CMy1View drawing


/////////////////////////////////////////////////////////////////////////////
// CMy1View diagnostics

#ifdef _DEBUG
void CMy1View::AssertValid() const
{
	CEditView::AssertValid();
}

void CMy1View::Dump(CDumpContext& dc) const
{
	CEditView::Dump(dc);
}

CMy1Doc* CMy1View::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMy1Doc)));
	return (CMy1Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMy1View message handlers
void CMy1View::OnButtonfz() 
{
	// TODO: Add your control notification handler code here
CRect rc;
GetClientRect(&rc);
CClientDC dc(this);
CPen NewPen(PS_SOLID,0,RGB(0,255,0));
CPen *pOldPen=dc.SelectObject(&NewPen);
CEditView::GetWindowText(m);
dc.FillSolidRect(rc,0);
m_nMapMode=MM_ISOTROPIC;
dc.SetMapMode(m_nMapMode);
dc.SetViewportOrg(CPoint(rc.right/2,rc.bottom/2));
dc.SetWindowExt(2000,2000);
X=0,Y=0;
float x=0,f=0,y=0,a=0,b=0,s=0,r=0,s1=0,r1=0,v=0,x0,y0,c;
for(int i=0;i<m.GetLength();i++)
{switch(m[i])
{case '\r':
  if(G==1)
{CPen NewPen(PS_SOLID,0,RGB(0,255,0));
CPen *pOldPen=dc.SelectObject(&NewPen);
	  if((X-s==0) && (Y-r>0))
  {r1=Y-r;
	  for(c=1;c<=r1;c++)
	  {r=r+1;dc.LineTo(s,r);
	  Sleep(1);
	  }
  break;}
  else if((X-s==0) && (Y-r<0))
  {r1=r-Y;
	  for(c=1;c<=r1;c++)
	  {r=r-1;
	  dc.LineTo(s,r);
	  Sleep(1);
	  }
  break;}
  else if((X-s>0) && (Y-r==0))
  {s1=X-s;
	  for(c=1;c<=s1;c++)
	  {s=s+1;
	  dc.LineTo(s,r);
	  Sleep(1);
	  }
  break;}
  else if((X-s<0) && (Y-r==0))
  {s1=s-X;
	  for(c=1;c<=s1;c++)
	  {s=s-1;
	  dc.LineTo(s,r);
	  Sleep(1);
	  }
  break;}
  else if((X-s>0) && (Y-r>0))  //第一
  {s1=X-s,r1=Y-r,x=0,y=0,v=s1+r1;
  {for(c=1;c<=v;c++)
	{if(f>=0)
	{s=s+1,f=f-r1;dc.LineTo(s,r);
	Sleep(1);
  }
    else
	{r=r+1,f=f+s1;
    dc.LineTo(s,r);
	Sleep(1);}
	}
  }
   f=0;
  break;
  }
  else if((Y-r>0) && (X-s<0))  //第二
  {s1=X-s,r1=Y-r,x=0,y=0;
  {for(c=1;c<=(r1-s1);c++)
	{if(f>=0)
	{s=s-1,f=f-r1;
   dc.LineTo(s,r);
   Sleep(1);
	}
    else
	{r=r+1,f=f-s1;
    dc.LineTo(s,r);
	Sleep(1);}
	}
  }
   f=0;
  break;
  }
  else if((Y-r<0) && (X-s<0))
  {s1=X-s,r1=Y-r,x=0,y=0;
  {for(c=1;c<=(0-s1-r1);c++)
	{if(f>=0)
	{s=s-1,f=f+r1;
   dc.LineTo(s,r);
   Sleep(1);
	}
    else
	{r=r-1,f=f-s1;
    dc.LineTo(s,r);
	Sleep(1);}
	}
  }
   f=0;
  break;
  }
  else if((Y-r<0) && (X-s>0))
  {s1=X-s,r1=Y-r,x=0,y=0;
  {for(c=1;c<=(s1-r1);c++)
	{if(f>=0)
	{s=s+1,f=f+r1;
   dc.LineTo(s,r);
   Sleep(1);
	}
    else
	{r=r-1,f=f+s1;
    dc.LineTo(s,r);
	Sleep(1);}
	}
  }
   f=0;
  break;
  }
  }
  else if(G==0)
  {CPen NewPen(PS_SOLID,0,RGB(0,0,0));
CPen *pOldPen=dc.SelectObject(&NewPen);
  dc.LineTo(X,Y);
  s=X,r=Y;
  break;}
  else if(G==2)
  {x0=s-I,y0=r-J,R=sqrt(I*I+J*J);//圆心坐标
  CPen NewPen(PS_SOLID,0,RGB(0,255,0));
CPen *pOldPen=dc.SelectObject(&NewPen);
   float f1=0,f2=0,f3=0,f4=0;
  {for(int j=1;(s!=X) || (r!=Y);j++)
   {if((s-x0>=0) && (r-y0>0))
   {if(f1>=0)
   {f1=f1-2*(r-y0)+1,r=r-1;
     dc.LineTo(s,r);
	 Sleep(1);
   }
   else
   {f1=f1+2*(s-x0)+1,s=s+1;
     dc.LineTo(s,r);
	 Sleep(1);
   }
   }
   else if((s-x0>0) && (r-y0<=0))
   {if(f2>=0)
   {f2=f2-2*(s-x0)+1,s=s-1;
     dc.LineTo(s,r);
	 Sleep(1);
   }
   else
   {f2=f2-2*(r-y0)+1,r=r-1;
    dc.LineTo(s,r);
	Sleep(1);
   }
   }
   else if((s-x0<=0) && (r-y0<0))
   {if(f3>=0)
   {f3=f3+2*(r-y0)+1,r=r+1;
     dc.LineTo(s,r);
	 Sleep(1);
   }
   else
   {f3=f3-2*(s-x0)+1,s=s-1;
    dc.LineTo(s,r);
	Sleep(1);
   }
   }
   else if((s-x0<0) && (r-y0>=0))
   {if(f4>=0)
   {f4=f4+2*(s-x0)+1,s=s+1;
     dc.LineTo(s,r);
	 Sleep(1);
   }
   else
   {f4=f4+2*(r-y0)+1,r=r+1;
    dc.LineTo(s,r);
	Sleep(1);
   }
   }
  }
  }
   break;}
   else if(G==3)
    {x0=s-I,y0=r-J;//圆心坐标
   CPen NewPen(PS_SOLID,0,RGB(0,255,0));
CPen *pOldPen=dc.SelectObject(&NewPen);
   float f1=0,f2=0,f3=0,f4=0;
  {for(int K=1;(s!=X) || (r!=Y);K++)
   {if((s-x0>0) && (r-y0>=0))
   {if(f1>=0)
   {f1=f1-2*(s-x0)+1,s=s-1;
     dc.LineTo(s,r);
	 Sleep(1);
   }
   else
   {f1=f1+2*(r-y0)+1,r=r+1;
     dc.LineTo(s,r);
	 Sleep(1);
   }
   }
   else if((s-x0>=0) && (r-y0<0))
   {if(f2>=0)
   {f2=f2+2*(r-y0)+1,r=r+1;
     dc.LineTo(s,r);
	 Sleep(1);
   }
   else
   {f2=f2+2*(s-x0)+1,s=s+1;
    dc.LineTo(s,r);
	Sleep(1);
   }
   }
   else if((s-x0<0) && (r-y0<=0))
   {if(f3>=0)
   {f3=f3+2*(s-x0)+1,s=s+1;
     dc.LineTo(s,r);
	 Sleep(1);
   }
   else
   {f3=f3-2*(r-y0)+1,r=r-1;
    dc.LineTo(s,r);
	Sleep(1);
   }
   }
   else if((s-x0<=0) && (r-y0>0))
   {if(f4>=0)
   {f4=f4-2*(r-y0)+1,r=r-1;
     dc.LineTo(s,r);
	 Sleep(1);
   }
   else
   {f4=f4-2*(s-x0)+1,s=s-1;
    dc.LineTo(s,r);
	Sleep(1);
   }
   }
   }
 }
  break;}
  else
         break;
 case 'G':i++;
        G=m[i]-48;i++;
		G=G+m[i]-48;
	    break;
 case 'X':i++;
	      if(m[i]=='-')
          {i++;
	        a=0-(m[i]-48)*100;i++;
		    b=(m[i]-48)*10;
		    if((b>=0) && (b<=90))
			 {X=a-b;}
			else if(m[i]=='\r')
			{i--;
			X=a/10;}
			else
			{X=a/10;}
		  }
		  else if(m[i]=='0')
		  {X=0;}
		  else 
		  {a=(m[i]-48)*100;i++;
		    b=(m[i]-48)*10;
          if((b>=0) && (b<=90))
		  {X=a+b;}
		  else if(m[i]=='\r')
			{i--;
			X=a/10;}
		  else
		  {X=a/10;}
		  }
		  break;
 case 'Y':i++;
	      if(m[i]=='-')
          {i++;
	        a=0-(m[i]-48)*100;i++;
		    b=(m[i]-48)*10;
		    if((b>=0) && (b<=90))
			 {Y=a-b;}
			else if(m[i]=='\r')
			{i--;
			Y=a/10;}
			else
			{Y=a/10;}
		  }
		  else if(m[i]=='0')
		  {Y=0;}
		  else 
		  {a=(m[i]-48)*100;i++;
		    b=(m[i]-48)*10;
          if((b>=0) && (b<=90))
		  {Y=a+b;}
		  else if(m[i]=='\r')
			{i--;
			Y=a/10;}
		  else
		  {Y=a/10;}
		  }
		  break;
 case 'I':i++;
	      if(m[i]=='-')
          {i++;
	        a=0-(m[i]-48)*100;i++;
		    b=(m[i]-48)*10;
		    if((b>=0) && (b<=90))
			 {I=a-b;}
			else if(m[i]=='\r')
			{i--;
			I=a/10;}
			else
			{I=a/10;}
		  }
		  else if(m[i]=='0')
		  {I=0;}
		  else 
		  {a=(m[i]-48)*100;i++;
		    b=(m[i]-48)*10;
          if((b>=0) && (b<=90))
		  {I=a+b;}
		  else if(m[i]=='\r')
			{i--;
			I=a/10;}
		  else
		  {I=a/10;}
		  }
		  break;
 case 'J':i++;
	      if(m[i]=='-')
          {i++;
	        a=0-(m[i]-48)*100;i++;
		    b=(m[i]-48)*10;
		    if((b>=0) && (b<=90))
			 {J=a-b;}
			else if(m[i]=='\r')
			{i--;
			J=a/10;}
			else
			{J=a/10;}
		  }
		  else if(m[i]=='0')
		  {J=0;}
		  else 
		  {a=(m[i]-48)*100;i++;
		    b=(m[i]-48)*10;
          if((b>=0) && (b<=90))
		  {J=a+b;}
		  else if(m[i]=='\r')
			{i--;
			J=a/10;}
		  else
		  {J=a/10;}
		  }
		  break;
 default :break;
}
}
}


BOOL CMy1View::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	CRect rc;
	GetClientRect(rc);
	pDC->FillSolidRect(rc,RGB(0,0,0));
	return true;
	return CEditView::OnEraseBkgnd(pDC);
}

void CMy1View::OnButtoncx() 
{
	// TODO: Add your control notification handler code here
	Invalidate();
}

void CMy1View::DoDataExchange(CDataExchange* pDX) 
{
	// TODO: Add your specialized code here and/or call the base class
	CEditView::DoDataExchange(pDX);
}

void CMy1View::OnUpdateEditx() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CEditView::OnInitDialog()
	// function to send the EM_SETEVENTMASK message to the control
	// with the ENM_UPDATE flag ORed into the lParam mask.
	
	// TODO: Add your control notification handler code here
}

void CMy1View::OnButtonx1() 
{
	// TODO: Add your control notification handler code here
	
}

void CMy1View::OnButtonx2() 
{
	// TODO: Add your control notification handler code here
	
}

void CMy1View::OnButtony1() 
{
	// TODO: Add your control notification handler code here
	
}

void CMy1View::OnButtony2() 
{
	// TODO: Add your control notification handler code here
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -