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

📄 mshowview.cpp

📁 数控译码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                {
					if(xpe>0&&ype>=0)      yps++;
					else if(xpe>=0&&ype<0) xps++;
					else if(xpe<0&&ype<=0) yps--;
					else                   xps--;

                
				}
				
				dc.LineTo(x+Datumx+Last_x+xps,y-(Datumy+Last_y+yps)); 
				
                pn=i;
				px=xps;
				py=yps; 

							   		 
			}
			
			xp.Format("%d",(Datumx + xps+Last_x));
			yp.Format("%d",(Datumy + yps+Last_y));
			pMshowview->m_pdlgbar->GetDlgItem(IDC_STATIC1)->SetWindowText(xp);
			pMshowview->m_pdlgbar->GetDlgItem(IDC_STATIC2)->SetWindowText(yp);

		    Last_x+=X[i];
            Last_y+=Y[i];

			break;

		case 02:   /*  CW */
			/*
			ox=Last_x+I[i];
			            oy=Last_y+J[i];
						xps=Last_x-ox;
						yps=Last_y-oy;
						xpe=X[i]-ox;
						ype=Y[i]-oy;*/
			

			ox=Last_x+I[i];
            oy=Last_y+J[i];
			xps=-I[i];
			yps=-J[i];
			xpe=X[i]-I[i];
			ype=Y[i]-J[i];
			while(xps!=xpe||yps!=ype)
			{
				while(pthread==1)
				{
                if(thread!=1)break;
				};
				if(thread!=1)break;
				
			
				xp.Format("%d",(Datumx+xps+ox));
                yp.Format("%d",(Datumy+yps+oy));
                pMshowview->m_pdlgbar->GetDlgItem(IDC_STATIC1)->SetWindowText(xp);
                pMshowview->m_pdlgbar->GetDlgItem(IDC_STATIC2)->SetWindowText(yp);
				
				Sleep(20);
				d = ( xps*xps + yps*yps - xpe*xpe - ype*ype );
				if(d >= 0)
				{
				   if(xps>0 && yps>=0)		yps--;
				   else if(xps>=0 && yps<0) xps--;
				   else if(xps<0 && yps<=0) yps++; 
				   else						xps++; 
				}
				else
				{
				   if(xps>=0 && yps>0)		xps++; 
	   			   else if(xps>0 && yps<=0) yps--; 
				   else if(xps<=0 && yps<0) xps--; 
				   else						yps++; 
				}
				
				dc.LineTo(x+Datumx+xps+ox,y-(Datumy+oy+yps)); 
				pn=i;
				px=xps;
				py=yps;
				
			}

			xp.Format("%d",(Datumx+xps+ox));
			yp.Format("%d",(Datumy+yps+oy));
			pMshowview->m_pdlgbar->GetDlgItem(IDC_STATIC1)->SetWindowText(xp);
			pMshowview->m_pdlgbar->GetDlgItem(IDC_STATIC2)->SetWindowText(yp);
			
			Last_x+=X[i];
            Last_y+=Y[i];
			break;
		case 03:   /*  CCW */	    	
           /*
            ox=Last_x+I[i];
                       oy=Last_y+J[i];
           			xps=Last_x-ox;
           			yps=Last_y-oy;
           			xpe=X[i]-ox;
           			ype=Y[i]-oy;*/
		
			ox=Last_x+I[i];
			oy=Last_y+J[i];
			xps=-I[i];
			yps=-J[i];
			xpe=X[i]-I[i];
			ype=Y[i]-J[i];

			while(xps!=xpe||yps!=ype)
			{
				while(pthread==1)
				{
                if(thread!=1)break;
				};
				if(thread!=1)break;
				
			
				xp.Format("%d",(Datumx+xps+ox));
                yp.Format("%d",(Datumy+yps+oy));
                pMshowview->m_pdlgbar->GetDlgItem(IDC_STATIC1)->SetWindowText(xp);
                pMshowview->m_pdlgbar->GetDlgItem(IDC_STATIC2)->SetWindowText(yp);
				Sleep(20);
				
				
				d = ( xps*xps + yps*yps - xpe*xpe - ype*ype );
				
				if(d >= 0)
				{
				   if(xps>0 && yps>=0)		 xps--;
				   else if(xps>=0 && yps<0)  yps++;
				   else if(xps<0 && yps<=0)  xps++;
				   else						 yps--; 
				}
				else
				{
				   if(xps>0 && yps>=0)		 yps++; 
	   			   else if(xps>=0 && yps<0)  xps++; 
				   else if(xps<0 && yps<=0)  yps--; 
				   else						 xps--; 
				}
				
				dc.LineTo(x+Datumx+xps+ox,y-(Datumy+oy+yps));
				pn=i;
				px=xps;
				py=yps;
				
			}

			xp.Format("%d",(Datumx+xps+ox));
			yp.Format("%d",(Datumy+yps+oy));
			pMshowview->m_pdlgbar->GetDlgItem(IDC_STATIC1)->SetWindowText(xp);
			pMshowview->m_pdlgbar->GetDlgItem(IDC_STATIC2)->SetWindowText(yp);

			Last_x+=X[i];
            Last_y+=Y[i];
			break;
		case 04:  /*pause*/
		
			break;
		
		default:
			break;
	}
	
}




        dc.SelectObject(oldpen);
		newpen.DeleteObject();
thread=0;
start=1;
work=1;
pause=0;
stop=0;

done =1;
return 0;
}

void CMshowView::OnSenddate() 
{
	// 菜单编译
	GetDocument()->UpdateAllViews(NULL,1);
}

void CMshowView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	
	if(lHint==1)
	{
	  CMshowDoc*pDoc=(CMshowDoc*)GetDocument();
	  
	  m_n=pDoc->CodeNum;
	  for(int i=0;i<m_n;i++)
	  {
          m_M[i]=pDoc->GSim[i].m;   
	      m_F[i]=pDoc->GSim[i].f;
	      m_S[i]=pDoc->GSim[i].s;
//	 	  m_R[i]=pDoc->GSim[i].r;
	      m_K[i]=pDoc->GSim[i].k;
	      m_J[i]=pDoc->GSim[i].j;
	      m_I[i]=pDoc->GSim[i].i;
	      m_Z[i]=pDoc->GSim[i].z;
	      m_Y[i]=pDoc->GSim[i].y;
	      m_X[i]=pDoc->GSim[i].x;
	      m_G[i]=pDoc->GSim[i].g;
//	      m_N[i]=pDoc->GSim[i].n;
		
	  }
		AfxMessageBox("编译完成,数据转换成功!");
		Invalidate();
		start=1;
		work=1;
	}
	
	
}
void CMshowView::OnUpdateXY(CCmdUI* pCmdUI)
{
	pCmdUI->Enable(TRUE);
}




BOOL CMshowView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
	SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR));
	return true;
	
	//return CView::OnSetCursor(pWnd, nHitTest, message);
}



void CMshowView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CString str;
	CMainFrame*pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
	CStatusBar*pStatus=&pFrame->m_wndStatusBar;
	if(pStatus)
	{
		str.Format("实际(%d/%d)",point.x,point.y);
		pStatus->SetPaneText(2,str);
		str.Format("X=%d",(point.x-x));
		pStatus->SetPaneText(3,str);
		str.Format("Y=%d",(y-point.y));
		pStatus->SetPaneText(4,str);
	}
	CView::OnMouseMove(nFlags, point);
}

void CMshowView::OnInitialUpdate() 
{
	CView::OnInitialUpdate();
//	m_pdlgbar->Create(this,IDD_DIALOGBAR,CBRS_LEFT,IDD_DIALOGBAR);
}

void CMshowView::OnUpdateStartthread(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	
	if(start==0)pCmdUI->Enable(FALSE);
	
}
void CMshowView::OnUpdateStartwork(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(work==0)pCmdUI->Enable(FALSE);
}
void CMshowView::OnUpdatePausethread(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(pause==0)pCmdUI->Enable(FALSE);
}

void CMshowView::OnUpdateStopthread(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(stop==0)pCmdUI->Enable(FALSE);
}





void CMshowView::OnUpdateZB(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(b==1)pCmdUI->SetCheck(TRUE);

}

void CMshowView::OnZB() 
{
	if(b==1)b=0;
	else b=1;
	Invalidate();

	// TODO: Add your command handler code here
	
	
}



void CMshowView::Onpaint()
{	
	CClientDC dc(this);
	CPen newpen;
		CPen *oldpen;
		newpen.CreatePen(PS_SOLID,1,RGB(255,0,0));
		oldpen=dc.SelectObject(&newpen);


	CString xp,yp;
		

    int ox=0,oy=0,xps=0,yps=0,xpe=0,ype=0,d=0,Last_x=0,Last_y=0;
	
	int Datumx = DUIDAOX,Datumy = DUIDAOY, Datumz = DUIDAOZ;
    
     dc.MoveTo(x+Datumx,y-Datumy);
    for(int i=0;i<m_n;i++)
	{  
	if(done == 0) 
	{
		break;	
	}
	
	if (m_gflag[i] == 0 )
		continue;
	
	
	switch (m_G[i])
	{
		case 90:
		
			break;
		case 91:
		
			break;
		case 00:  
            
            
		case 01:   /*line interloation*/			
		    /*
		    xpe=m_X[i]-Last_x;
		    			ype=m_Y[i]-Last_y;*/
			xpe=m_X[i];
			ype=m_Y[i];
		    
			
			xps = yps = 0;
	
		
			while(xps!=xpe||yps!=ype)
			{
				
				

				d = ( xpe*yps -  xps*ype  );
				
				if(m_G[i] = 01)		Sleep(20);

				if(d >= 0)
				{                                           
					if(xpe>0&&ype>=0)	   xps++;
					else if(xpe>=0&&ype<0) yps--;
					else if(xpe<0&&ype<=0) xps--;
					else				   yps++; 
					
               
				}
                else 
                {
					if(xpe>0&&ype>=0)      yps++;
					else if(xpe>=0&&ype<0) xps++;
					else if(xpe<0&&ype<=0) yps--;
					else                   xps--;

                
				}
				
				dc.LineTo(x+Datumx+Last_x+xps,y-(Datumy+Last_y+yps)); 
				
                m_pn=i;
				m_px=xps;
				m_py=yps; 

							   		 
			}
			

		    Last_x+=m_X[i];
            Last_y+=m_Y[i];

			break;

		case 02:   /*  CW */
			

			ox=Last_x+m_I[i];
            oy=Last_y+m_J[i];
			xps=-m_I[i];
			yps=-m_J[i];
			xpe=m_X[i]-m_I[i];
			ype=m_Y[i]-m_J[i];
			while(xps!=xpe||yps!=ype)
			{
				/*
				while(pthread==1)
								{
				                if(thread!=1)break;
								};
								if(thread!=1)break;*/
				
				
			
/*
				xp.Format("%d",(xps+ox));
                yp.Format("%d",(yps+oy));
                pMshowview->m_pdlgbar->GetDlgItem(IDC_STATIC1)->SetWindowText(xp);
                pMshowview->m_pdlgbar->GetDlgItem(IDC_STATIC2)->SetWindowText(yp);
				*/

				Sleep(20);
				d = ( xps*xps + yps*yps - xpe*xpe - ype*ype );
				if(d >= 0)
				{
				   if(xps>0 && yps>=0)		yps--;
				   else if(xps>=0 && yps<0) xps--;
				   else if(xps<0 && yps<=0) yps++; 
				   else						xps++; 
				}
				else
				{
				   if(xps>=0 && yps>0)		xps++; 
	   			   else if(xps>0 && yps<=0) yps--; 
				   else if(xps<=0 && yps<0) xps--; 
				   else						yps++; 
				}
				
				dc.LineTo(x+Datumx+xps+ox,y-(Datumy+oy+yps)); 
				m_pn=i;
				m_px=xps;
				m_py=yps;
				
			}

/*
			xp.Format("%d",(xps+ox));
			yp.Format("%d",(yps+oy));
			pMshowview->m_pdlgbar->GetDlgItem(IDC_STATIC1)->SetWindowText(xp);
			pMshowview->m_pdlgbar->GetDlgItem(IDC_STATIC2)->SetWindowText(yp);*/

			
			Last_x+=m_X[i];
            Last_y+=m_Y[i];
			break;
		case 03:   /*  CCW */	    	
           /*
            ox=Last_x+m_I[i];
                       oy=Last_y+m_J[i];
           			xps=Last_x-ox;
           			yps=Last_y-oy;
           			xpe=m_X[i]-ox;
           			ype=m_Y[i]-oy;*/
		
			ox=Last_x+m_I[i];
			oy=Last_y+m_J[i];
			xps=-m_I[i];
			yps=-m_J[i];
			xpe=m_X[i]-m_I[i];
			ype=m_Y[i]-m_J[i];

			while(xps!=xpe||yps!=ype)
			{
			/*
				while(pthread==1)
							{
			                if(thread!=1)break;
							};
							if(thread!=1)break;*/
			
				
			
/*
				xp.Format("%d",(xps+ox));
                yp.Format("%d",(yps+oy));
                pMshowview->m_pdlgbar->GetDlgItem(IDC_STATIC1)->SetWindowText(xp);
                pMshowview->m_pdlgbar->GetDlgItem(IDC_STATIC2)->SetWindowText(yp);
				Sleep(20);
				*/

				
				d = ( xps*xps + yps*yps - xpe*xpe - ype*ype );
				
				if(d >= 0)
				{
				   if(xps>0 && yps>=0)		 xps--;
				   else if(xps>=0 && yps<0)  yps++;
				   else if(xps<0 && yps<=0)  xps++;
				   else						 yps--; 
				}
				else
				{
				   if(xps>0 && yps>=0)		 yps++; 
	   			   else if(xps>=0 && yps<0)  xps++; 
				   else if(xps<0 && yps<=0)  yps--; 
				   else						 xps--; 
				}
				
				dc.LineTo(x+Datumx+xps+ox,y-(Datumy+oy+yps));
				m_pn=i;
				m_px=xps;
				m_py=yps;
				
			}


			Last_x+=m_X[i];
            Last_y+=m_Y[i];
			break;
		case 04:  /*pause*/
		
			break;
		
		default:
			break;
				}
	
}
        dc.SelectObject(oldpen);
		newpen.DeleteObject();
}




void CMshowView::OnButtonSim() 
{
	// TODO: Add your control notification handler code here
	CMshowDoc*pDoc=(CMshowDoc*)GetDocument();
	
	m_n=pDoc->CodeNum;
	for(int i=0;i<m_n;i++)
	{
		m_M[i]=pDoc->GSim[i].m;   
		m_F[i]=pDoc->GSim[i].f;
		m_S[i]=pDoc->GSim[i].s;
		m_K[i]=pDoc->GSim[i].k;
		m_J[i]=pDoc->GSim[i].j;
		m_I[i]=pDoc->GSim[i].i;
		m_Z[i]=pDoc->GSim[i].z;
		m_Y[i]=pDoc->GSim[i].y;
		m_X[i]=pDoc->GSim[i].x;
		m_G[i]=pDoc->GSim[i].g;
		m_gflag[i] = pDoc->GSim[i].gflag;
		
	}
//for 刀补
	n=pDoc->GCodeNum;
	for(int i=0;i<n;i++)
	{
		M[i]=pDoc->GCode[i].m;   
		F[i]=pDoc->GCode[i].f;
		S[i]=pDoc->GCode[i].s;
		K[i]=pDoc->GCode[i].k;
		J[i]=pDoc->GCode[i].j;
		I[i]=pDoc->GCode[i].i;
		Z[i]=pDoc->GCode[i].z;
		Y[i]=pDoc->GCode[i].y;
		X[i]=pDoc->GCode[i].x;
		G[i]=pDoc->GCode[i].g;
		gflag[i] = pDoc->GCode[i].gflag;
		
	}	
	
	
	(((CMainFrame*)AfxGetMainWnd())->m_wndDialogBar).GetDlgItem(IDC_STATIC_SIM)->SetWindowText("建立");

	Invalidate();
	start=1;
	work=1;

	done = 0;


	
}

⌨️ 快捷键说明

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