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

📄 arraycalculate.cpp

📁 在数控机床的坐标文件
💻 CPP
字号:
// ArrayCalculate.cpp: implementation of the CArrayCalculate class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "NC.h"
#include "ArrayCalculate.h"
#include "windows.h"
#include <math.h>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
int CArrayCalculate::FindMin(CReadFile *p_file)
{
	p_file->ReadLine(1,file->maxLine[1]);
	double temp=p_file->sl-m_l;
	p_file->ReadLine(1,2);
	double minval=fabs(p_file->sl-temp);
	int index=2;
	for(int i=3;i<=p_file->maxLine[1]-1;i++)
	{
		p_file->ReadLine(1,i);
		if(minval>=fabs(p_file->sl-temp))
		{
			minval=fabs(p_file->sl-temp);
			index=i;
		}
	}
	return index;
}
CArrayCalculate::CArrayCalculate(CReadFile * file)
{
	m_l1 = 0;
	m_l2 = 0;
	m_l3 = 0;
	m_l4 = 0;
	m_l5 = 0;
	m_l6 = 0;
	m_C = 0.0;
	m_U = 0;
	m_l = 0;
	if(file==NULL)
	{
		MessageBox("传递的file指针为空","计算结果",MB_OK);
		return;
	}
	this->file=file;
}

CArrayCalculate::~CArrayCalculate()
{

	delete []d1;
	delete []d2;
	delete []d3;
	delete []A;

}

void CArrayCalculate::ParameterSet(int m_l1,int m_l2,int m_l3,int m_l4,int m_l5,int	m_l6,double	m_C,int	m_U,int m_l)
{
	this->m_l1=m_l1;
	this->m_l2=m_l2;
	this->m_l3=m_l3;
	this->m_l4=m_l4;
	this->m_l5=m_l5;
	this->m_l6=m_l6;
	this->m_l=m_l;
	this->m_C=m_C;
	this->m_U=m_U;
}

void CArrayCalculate::Calculate()
{
	int len=file->maxLine[1];
	d1=new double[len];
	d2=new double[len];
	d3=new double[len];
	A=new double[len];
	for(int i=1;i<len;i++)
	{
		file->ReadLine(1,i+1);
		
		double Q5=acos(file->vz/sqrt(file->vx*file->vx+file->vy*file->vy+file->vz*file->vz))*180/3.1415926;
		d1[i]=file->x+m_l1-cos(m_C)*sin(Q5)+sin(m_C)*m_l5;
		d2[i]=file->y+m_l2-sin(m_C)*sin(Q5)*m_l6-cos(m_C)*m_l5;
		d3[i]=m_l3-file->z-m_l4-m_l6*cos(Q5);
		A[i]=Q5;
	}
}

void CArrayCalculate::SaveFinalCode()
{
	CStdioFile tempfile("NC模版.txt",CFile::modeCreate | CFile::modeWrite|CFile::typeText);
	CString str,temp;
	str+="G04 P1.0";
	str+="\r\n";
	str+="M22 M25 M20";
	str+="\r\n";
	str+="G04 P3.0";
	str+="\r\n";
	str+="G91 F20 V-180";
	str+="\r\n";
	str+="G04 P1.0";
	str+="\r\n";
	str+="M23";
	str+="\r\n";
	str+="G04 P1.0";
	str+="\r\n";
	str+="U-377";
	str+="\r\n";
	temp.Format("G90 F30 V0 C%lf A%lf\r\n",m_C,A[1]);
	str+=temp;
	temp.Format("G90 X%lf Y%lf Z%lf\r\n",d1[1],d2[1],d3[1]);
	str+=temp;
	str+="G04 P1.0";
	str+="\r\n";
	str+="M24 G01 G90";
	str+="\r\n";
	str+="M28";
	str+="\r\n";
	str+="G04 P1.0";
	str+="\r\n";
	str+="G90 G01 F30";
	str+="\r\n";
	for(int i=2;i<=6;i++)
	{
		temp.Format("X%lf Y%lf Z%lf A%lf\r\n",d1[i],d2[i],d3[i],A[i]);
		str+=temp;
	}
	str+="G04 P1.0";
	str+="\r\n";
	str+="M24";
	str+="\r\n";
	str+="G04 P1.0";
	str+="\r\n";
	
     int L=FindMin(file)-1;
	 for(int j=7;j<=L;j++)
	 {
		temp.Format("X%lf Y%lf Z%lf A%lf\r\n",d1[j],d2[j],d3[j],A[j]);
		str+=temp;
	 }
	 str+="G04 P1.0";
	str+="\r\n";
	str+="M22 M25";
	str+="\r\n";
	str+="G04 P1.0";
	str+="\r\n";
	str+="G91 F20 V180 ";
	str+="\r\n";
	str+="G04 P1.0 ";
	str+="\r\n";
	str+="M23";
	str+="\r\n";
	str+="G04 P1.0";
	str+="\r\n";
	for(int k=L+1;k<=file->maxLine[1]-11;k++)
	{
		temp.Format("X%lf Y%lf Z%lf A%lf\r\n",d1[k],d2[k],d3[k],A[k]);
		str+=temp;
		
	}
	str+="G04 P1.0";
	str+="\r\n";
	str+="M21";
	str+="\r\n";
	str+="G04 P1.0";
	str+="\r\n";
	for(int l=file->maxLine[1]-10;l<=file->maxLine[1]-1;l++)
	{
		temp.Format("X%lf Y%lf Z%lf A%lf\r\n",d1[l],d2[l],d3[l],A[l]);
		str+=temp;
	}
	str+="G91 Z-30";
	str+="\r\n";
	str+="G04 P1.0";
	str+="\r\n";
	str+="M25";
	str+="\r\n";
	str+="G04 P1.0";
	str+="\r\n";
	tempfile.WriteString(str);
	tempfile.Close();
}

⌨️ 快捷键说明

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