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

📄 288铣床加工代码生成软件dlg.cpp

📁 G代码生成软件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	fprintf(fp,"%s",str1);
	c1='\n';
   	fputc(c1,fp);
	first=true;
	//////////////////////////////////////////////////////////
	i=0;
	for(k=0;k<=220;)
	{
		            ki=k/220.0;  
	                x=24*pow(ki,2.25);
					a=12.763-x;
					b=40.518*40.518-40.518*(132.96203+2*x)+(27.755+x)*(145.72503+x);
					c=40.518*(98.73830+x)*(34.224+x)+40.518*40.518*(6.294-x)-70.98303*(27.755+x)*(74.742+x);
					y1=(-b-sqrt(b*b-4*a*c))/(2*a);
					y2=(-b+sqrt(b*b-4*a*c))/(2*a);
					if(abs(y1)<=abs(y2))
					{	y=y1+8.32;}
					else
					{	y=y2+8.32;}

				 if(first)
					{
                    str1="G01X";
	               fprintf(fp,"%s",str1);
	                fprintf(fp,"%-6.3f",0-y);
	                c1='Y';
	                fputc(c1,fp);
	                fprintf(fp,"%-6.3f",0-k);
					c1='F';
	                fputc(c1,fp);
                    fprintf(fp,"%d",m_f);
	                c1='\n';
   	                fputc(c1,fp);
                    

					first=false;
					}
					else
					{
                    str1="X";
	                fprintf(fp,"%s",str1);
                    fprintf(fp,"%-6.3f",0-y);
	                c1='Y';
	                fputc(c1,fp);
	                fprintf(fp,"%-6.3f",0-k);
	                c1='\n';
   	                fputc(c1,fp);
					}
					i=i++;
					k=i/(1.0/m_b);
				
	}
    /////////////////////////////////////加工曲线2

	 str1="G00Z";
	fprintf(fp,"%s",str1);
	fprintf(fp,"%-6.3f",m_z);
    c1='\n';
   	fputc(c1,fp);

    str1="M05";
	fprintf(fp,"%s",str1);
	c1='\n';
   	fputc(c1,fp);

    
    str1="G00X0.000Y0.000";
	fprintf(fp,"%s",str1);
	c1='\n';
   	fputc(c1,fp);

   	str1="M02";
	fprintf(fp,"%s",str1);
	c1='\n';
   	fputc(c1,fp);
    str1="%\n";
	fprintf(fp,"%s",str1);
           break;
    case 2:
		break;
	case 3:
		break;
    default:
        AfxMessageBox("您没有选择曲线方程!");
		break;
		}

	fclose(fp);


	AfxMessageBox("代码生成完毕!");
	m_num=m_num+1;
    UpdateData(false);
}


void CMy288Dlg::OnOk2() 
{
	// TODO: Add your control notification handler code here
	bool first=true;
	int n=0;
	n=m_list.GetCurSel();
    UpdateData(true);
	switch(n)
	{
	case 0:m_x2=18.999;break;
	case 1:m_x2=8.319;break;
	case 2:break;
	default:break;
	}
    UpdateData(false);
	CString str1;
	char c1;
    double ki=0.0;
	int i=0;
	double y=0,y1=0,y2=0;
	CFileDialog dlg(FALSE,"CNC",strFilePath,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"CNC加工文件(*.CNC)|*.CNC|所有文件(*.*)|*.*||",NULL);
	if(dlg.DoModal()!=IDOK)
	{
		return;
	}
	strFilePath=dlg.GetPathName();
    delete dlg;	
	
	
	FILE *fp=NULL;
	if( (fp= fopen("tempfile.cnc", "w" )) == NULL )
	{
		;//MessageBox("The file 'data' was not opened!");
	}
      else
    {
		;//MessageBox("The file 'data' was opened!");
	}

	  switch(n)
	  {
	  case 0:
	/////////////////////////////////////////////////////////////////////////
	m_f=(int)m_f;


	////////////////////////////////加工曲线1

	for(k=0.0;k<=220;)
	{
		            ki=k;
	                l=79.055-pow(ki,0.903)*0.317;
					a=l-47.109;
					b=l*l-215.33*l+5705.465208;
					c=11410.93042*l-268778.7605-94.218*l*l;
					e=b*b-4*a*c;
					e=sqrt(e);
					d=0-(b+e)/(2*a);
					x=88.38-l-d;
					fprintf(fp,"%-6.3f",x);
	                c1='\n';
   	                fputc(c1,fp);	
	                fprintf(fp,"%-6.3f",k);
	                c1='\n';
   	                fputc(c1,fp);
				
					//k=k+m_b;
					i=i++;
					k=i/(1.0/m_b);
					
					
				
	}
    /////////////////////////////////////加工曲线2

	i=0;
	for(k=0;k<=220;)
	{
		            ki=k;  
	                l=79.055-pow(ki,0.903)*0.317;
					x=98.054-l;
                   
				
                   
                    fprintf(fp,"%-6.3f",x);
					c1='\n';
   	                fputc(c1,fp);
	               
	                fprintf(fp,"%-6.3f",k);
	                c1='\n';
   	                fputc(c1,fp);
				
					i=i++;
					k=i/(1.0/m_b);
				
	}
    /////////////////////////////////////加工曲线2

	
    break;
  ////////////////////////////////////////////////////////////////////////
	case 1:

      m_f=(int)m_f;

 
	////////////////////////////////加工曲线1
	i=0;

	for(k=0.0;k<=220;)
	{
		            ki=k/220.0;
	                x=24*pow(ki,2.25);
								
				   
					fprintf(fp,"%-6.3f",x);
	                c1='\n';
   	                fputc(c1,fp);
	                fprintf(fp,"%-6.3f",0-k);
	                c1='\n';
   	                fputc(c1,fp);
				
					i=i++;
					k=i/(1.0/m_b);
							
				
	}
    
	//////////////////////////////////////////////////////////
	i=0;
	for(k=0;k<=220;)
	{
		            ki=k/220.0;  
	                x=24*pow(ki,2.25);
					a=12.763-x;
					b=40.518*40.518-40.518*(132.96203+2*x)+(27.755+x)*(145.72503+x);
					c=40.518*(98.73830+x)*(34.224+x)+40.518*40.518*(6.294-x)-70.98303*(27.755+x)*(74.742+x);
					y1=(-b-sqrt(b*b-4*a*c))/(2*a);
					y2=(-b+sqrt(b*b-4*a*c))/(2*a);
					if(abs(y1)<=abs(y2))
					{	y=y1+8.32;}
					else
					{	y=y2+8.32;}

				
					
                   
                    fprintf(fp,"%-6.3f",y);
					c1='\n';
   	                fputc(c1,fp);
	               
	                fprintf(fp,"%-6.3f",0-k);
	                c1='\n';
   	                fputc(c1,fp);
				
					i=i++;
					k=i/(1.0/m_b);
				
	}
    /////////////////////////////////////加工曲线2


           break;
    case 2:
		break;
	case 3:
		break;
    default:
        AfxMessageBox("您没有选择曲线方程!");
		break;
		}

	fclose(fp);



	m_num=m_num+1;
    UpdateData(false);

    bool processed=false;
	float oldkx=0,oldky=0,kx=0,ky=0;
	float subb=0,psubb;
	psubb=m_subb/m_b;
	oldkx=0.0;
	oldky=0.0;
	kx=0.0;
	ky=0.0;
	float rate=99999,oldrate=99999;
    int isfirst=0;
    ifstream  inputfile1;
	ofstream  outputfile2;	 //处理后的NC文件名
	FILE *fp1=NULL;
	if( (fp1= fopen(strFilePath, "w" )) == NULL )
	{
		;//MessageBox("The file 'data' was not opened!");
	}
      else
    {
		;//MessageBox("The file 'data' was opened!");
	}
    inputfile1.open("tempfile.cnc",ios::in);//打开待处理的NC文件
		while(!inputfile1.eof()) //开始处理文件
		{
      
		if(isfirst==0)
		{
		 //////////////////////////////////////////////
		//第一段曲线头
		//////////////////////////////////////////////
        str1="%\n";
	fprintf(fp1,"%s",str1);
    c1='o';
   	fputc(c1,fp1);
    fprintf(fp1,"%04d",m_num);
	c1='\n';
   	fputc(c1,fp1);
    str1="G54";
    fprintf(fp1,"%s",str1);
	c1='\n';
   	fputc(c1,fp1);

    str1="G00Z";
	fprintf(fp1,"%s",str1);
	fprintf(fp1,"%-6.3f",m_z); 
    c1='\n';
   	fputc(c1,fp1);

    str1="G00X0.000Y0.000";
	fprintf(fp1,"%s",str1);
	c1='\n';
   	fputc(c1,fp1);

	str1="M03S";
	fprintf(fp1,"%s",str1);
	fprintf(fp1,"%d",m_x);
	c1='\n';
   	fputc(c1,fp1);
    
  
    str1="G00Z4.000";
	fprintf(fp1,"%s",str1);
	c1='\n';
   	fputc(c1,fp1);
	str1="G01Z0.000F50";
	fprintf(fp,"%s",str1);
	c1='\n';
   	fputc(c1,fp);
	///////////////////////////////////////////////////////////////////
	//
	///////////////////////////////////////////////////////////////////
		inputfile1.operator >>(kx);	
		inputfile1.operator >>(ky);
           
				str1="G01X";
	               fprintf(fp1,"%s",str1);
	                fprintf(fp1,"%-6.3f",0-kx);
	                c1='Y';
	                fputc(c1,fp1);
	                fprintf(fp1,"%-6.3f",ky);
					c1='F';
	                fputc(c1,fp1);
                    fprintf(fp1,"%d",m_f);
 	                c1='\n';
   	                fputc(c1,fp1);
					isfirst=1;
				
		}
		else if(isfirst==1)
		{
		inputfile1.operator >>(kx);	
		inputfile1.operator >>(ky);
		rate=(kx-oldkx)/(ky-oldky);
		   subb=rate-oldrate;
		   if(subb<0.0)subb=0-subb;
		        if(subb>psubb)
				{
		            str1="X";
	               fprintf(fp1,"%s",str1);
	                fprintf(fp1,"%-6.3f",0-kx);
	                c1='Y';
	                fputc(c1,fp1);
	                fprintf(fp1,"%-6.3f",ky);
					c1='\n';
   	                fputc(c1,fp1);
					oldrate=rate;
					if(ky==220.0)processed=true;
				}

		    if(ky==220.0) 
			{
				isfirst=2;

			}

			if(ky==220.0&&!processed) 
			{
				    str1="X";
	               fprintf(fp1,"%s",str1);
	                fprintf(fp1,"%-6.3f",0-kx);
	                c1='Y';
	                fputc(c1,fp1);
	                fprintf(fp1,"%-6.3f",ky);
					c1='\n';
   	                fputc(c1,fp1);
					processed=true;
                    //isfirst=4;
			}

		}
		else if(isfirst==2)
		{
        /////////////////////////////////////////////////////////////
		///第一段曲线结尾,第二段开头
		/////////////////////////////////////////////////////////////
         	str1="G00Z";
	fprintf(fp1,"%s",str1);
	fprintf(fp1,"%-6.3f",m_z);
    c1='\n';
   	fputc(c1,fp1);
	
    str1="G00X";
	fprintf(fp1,"%s",str1);
    fprintf(fp1,"%-6.3f",0-m_x2);
    str1="Y0.000";
	fprintf(fp1,"%s",str1);
   	c1='\n';
   	fputc(c1,fp1);

  	 str1="G00Z4.000";
	fprintf(fp1,"%s",str1);
	c1='\n';
   	fputc(c1,fp1);

	str1="G01Z0.000F50";
	fprintf(fp,"%s",str1);
	c1='\n';
   	fputc(c1,fp);
	/////////////////////////////////////////////////////////////
	////////////
	//////////////////////////////////////////////////////////////
        	inputfile1.operator >>(kx);	
		    inputfile1.operator >>(ky);
                   str1="G01X";
	               fprintf(fp1,"%s",str1);
	                fprintf(fp1,"%-6.3f",0-kx);
	                c1='Y';
	                fputc(c1,fp1);
	                fprintf(fp1,"%-6.3f",ky);
					c1='F';
	                fputc(c1,fp1);
                    fprintf(fp1,"%d",m_f);
 	                c1='\n';
   	                fputc(c1,fp1);
					isfirst=3;
					oldrate=999999;
					rate=9999999;
					oldkx=0;
					oldky=0;
					switch(n)
					{
					case 0:kx=18.999;
						   ky=0;
						   break;
					case 1:kx=8.32;
						   ky=0;
						   break;
					default:kx=0;
						    ky=0;
					}

		}
		else if(isfirst==3)
		{
		inputfile1.operator >>(kx);	
		inputfile1.operator >>(ky);
		rate=(kx-oldkx)/(ky-oldky);
		   subb=rate-oldrate;
		   if(subb<0.0)subb=0-subb;
		        if(subb>psubb)
				{
		            str1="X";
	               fprintf(fp1,"%s",str1);
	                fprintf(fp1,"%-6.3f",0-kx);
	                c1='Y';
	                fputc(c1,fp1);
	                fprintf(fp1,"%-6.3f",ky);
					c1='\n';
   	                fputc(c1,fp1);
					oldrate=rate;
					if(ky==220.0)isfirst=4;
				}

			if(ky==220.0&&isfirst!=4) 
			{
				 str1="X";
	               fprintf(fp1,"%s",str1);
	                fprintf(fp1,"%-6.3f",0-kx);
	                c1='Y';
	                fputc(c1,fp1);
	                fprintf(fp1,"%-6.3f",ky);
					c1='\n';
   	                fputc(c1,fp1);
                    //isfirst=4;
			}


		}
		
		oldkx=kx;
		oldky=ky;
		

		}

		////////////////////////////////////////////////////////
		////////////第二段结尾
		///////////////////////////////////////////////////////
     	 str1="G00Z";
	fprintf(fp1,"%s",str1);
	fprintf(fp1,"%-6.3f",m_z);
    c1='\n';
   	fputc(c1,fp1);

    str1="M05";
	fprintf(fp1,"%s",str1);
	c1='\n';
   	fputc(c1,fp1);

    
    str1="G00X0.000Y0.000";
	fprintf(fp1,"%s",str1);
	c1='\n';
   	fputc(c1,fp1);

   	str1="M02";
	fprintf(fp1,"%s",str1);
	c1='\n';
   	fputc(c1,fp1);
    str1="%\n";
	fprintf(fp1,"%s",str1);
	/////////////////////////////////////////////////////////
	////////////
	/////////////////////////////////////////////////////////
     inputfile1.close();
	 
 	 fclose(fp1);

	AfxMessageBox("代码生成完毕!");
}

⌨️ 快捷键说明

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