📄 math.cpp
字号:
// Math.cpp: implementation of the CMath class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Jianyang.h"
#include "Math.h"
#include "JianyangView.h"
#include "Last.h"
#include <math.h>
#include <cstdlib>
#include <stdlib.h>
#include <boost/regex.hpp>
#include <string>
#include <iostream>
using namespace std;
using namespace boost;
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#define PI 3.1415926535897932384626433832795
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMath::CMath()
{
// GCodePoint = new CLast;
}
CMath::~CMath()
{
// delete GCodePoint;
}
double CMath::AnalyzeGCode(CString UnitChar, int iFlag)
{
string m_sXPrePoint, m_sYPrePoint, m_sZPrePoint, m_sAPrePoint, m_sBPrePoint, m_sPreFeedrate,
m_sXNextPoint, m_sYNextPoint, m_sZNextPoint, m_sANextPoint, m_sBNextPoint, m_sNextFeedrate;
std::string path = "^(N)(\\d*)(X)(.?)(\\d*)(.?)(\\d*?)(Y)(.?)(\\d*)(.?)(\\d*?)(Z)(.?)(\\d*)(.?)(\\d*?)(A)(.?)(\\d*)(.?)(\\d*?)(B)(.?)(\\d*)(.?)(\\d*?)(F?)(.?)(\\d*?)(.?)(\\d*?)\\*$";
boost::regex re(path);
std::string str = UnitChar;
std::string::const_iterator start, end;
start = str.begin();
end = str.end();
typedef boost::match_results<std::string::const_iterator> match_result_type;
match_result_type what;
boost::match_flag_type flags=boost::match_default;
if(regex_search(start, end, what, re, flags))
{
cout<<what[1]<<what[2]<<endl //N,行号
<<what[3]<<what[4]<<what[5]<<what[6]<<what[7]<<endl //X轴
<<what[8]<<what[9]<<what[10]<<what[11]<<what[12]<<endl //Y轴
<<what[13]<<what[14]<<what[15]<<what[16]<<what[17]<<endl //Z轴
<<what[18]<<what[19]<<what[20]<<what[21]<<what[22]<<endl //A轴
<<what[23]<<what[24]<<what[25]<<what[26]<<what[27]<<endl //B轴
<<what[28]<<what[29]<<what[30]<<what[31]<<what[32]<<endl;//F,进给速度
if(iFlag == 0)
{
m_sXPrePoint = what[4];
m_sXPrePoint += what[5];
m_sXPrePoint += what[6];
m_sXPrePoint += what[7];
// GCodePoint.m_dXPrePoint = atof(m_sXPrePoint.c_str());
m_dXPrePoint = atof(m_sXPrePoint.c_str());
m_sYPrePoint = what[9];
m_sYPrePoint += what[10];
m_sYPrePoint += what[11];
m_sYPrePoint += what[12];
// GCodePoint->m_dYPrePoint = atof(m_sYPrePoint.c_str());
m_dYPrePoint = atof(m_sYPrePoint.c_str());
m_sZPrePoint = what[14];
m_sZPrePoint += what[15];
m_sZPrePoint += what[16];
m_sZPrePoint += what[17];
// GCodePoint->m_dZPrePoint = atof(m_sZPrePoint.c_str());
m_dZPrePoint = atof(m_sZPrePoint.c_str());
m_sAPrePoint = what[19];
m_sAPrePoint += what[20];
m_sAPrePoint += what[21];
m_sAPrePoint += what[22];
// GCodePoint->m_dAPrePoint = atof(m_sAPrePoint.c_str());
m_dAPrePoint = atof(m_sAPrePoint.c_str());
m_sBPrePoint = what[24];
m_sBPrePoint += what[25];
m_sBPrePoint += what[26];
m_sBPrePoint += what[27];
// GCodePoint->m_dBPrePoint = atof(m_sBPrePoint.c_str());
m_dBPrePoint = atof(m_sBPrePoint.c_str());
m_sPreFeedrate = what[29];
m_sPreFeedrate += what[30];
m_sPreFeedrate += what[31];
m_sPreFeedrate += what[32];
// GCodePoint->m_dFeedrate = atof(m_sPreFeedrate.c_str());
m_dFeedrate = atof(m_sPreFeedrate.c_str());
}
else //if(iFlag == 1)
{
m_sXNextPoint = what[4];
m_sXNextPoint += what[5];
m_sXNextPoint += what[6];
m_sXNextPoint += what[7];
// GCodePoint.m_dXNextPoint = atof(m_sXNextPoint.c_str());
m_dXNextPoint = atof(m_sXNextPoint.c_str());
m_sYNextPoint = what[9];
m_sYNextPoint += what[10];
m_sYNextPoint += what[11];
m_sYNextPoint += what[12];
// GCodePoint->m_dYNextPoint = atof(m_sYNextPoint.c_str());
m_dYNextPoint = atof(m_sYNextPoint.c_str());
m_sZNextPoint = what[14];
m_sZNextPoint += what[15];
m_sZNextPoint += what[16];
m_sZNextPoint += what[17];
// GCodePoint->m_dZNextPoint = atof(m_sZNextPoint.c_str());
m_dZNextPoint = atof(m_sZNextPoint.c_str());
m_sANextPoint = what[19];
m_sANextPoint += what[20];
m_sANextPoint += what[21];
m_sANextPoint += what[22];
// GCodePoint->m_dANextPoint = atof(m_sANextPoint.c_str());
m_dANextPoint = atof(m_sANextPoint.c_str()) * PI / 180;
m_sBNextPoint = what[24];
m_sBNextPoint += what[25];
m_sBNextPoint += what[26];
m_sBNextPoint += what[27];
// GCodePoint->m_dBNextPoint = atof(m_sBNextPoint.c_str());
m_dBNextPoint = atof(m_sBNextPoint.c_str()) * PI / 180;
m_sNextFeedrate = what[29];
m_sNextFeedrate += what[30];
m_sNextFeedrate += what[31];
m_sNextFeedrate += what[32];
// GCodePoint->m_dFeedrate = atof(m_sNextFeedrate.c_str());
m_dFeedrate = atof(m_sNextFeedrate.c_str());
}
// GCodePoint->iExecutedTimes ++;
iExecutedTimes ++;
}
ComputeSpeed();
// AfxMessageBox("double CMath::AnalyzeGCode(CString UnitChar, int iFlag) has just been executed successfully!");
return 0;
}
/*
double CMath::ComputeSpeed() //计算时,前一次的m_dXPrePoint或者m_dXNextPoint值已经丢失
{
if((GCodePoint->iExecutedTimes >= 2) && (GCodePoint->iExecutedTimes % 2 == 0))
{
GCodePoint->m_dXPoint = GCodePoint->m_dXNextPoint - GCodePoint->m_dXPrePoint;
GCodePoint->m_dYPoint = GCodePoint->m_dYNextPoint - GCodePoint->m_dYPrePoint;
GCodePoint->m_dZPoint = GCodePoint->m_dZNextPoint - GCodePoint->m_dZPrePoint;
GCodePoint->m_dAPoint = GCodePoint->m_dANextPoint - GCodePoint->m_dAPrePoint;
GCodePoint->m_dBPoint = GCodePoint->m_dBNextPoint - GCodePoint->m_dBPrePoint;
}
else if((GCodePoint->iExecutedTimes >= 2) && (GCodePoint->iExecutedTimes % 2 == 1))
{
GCodePoint->m_dXPoint = GCodePoint->m_dXPrePoint - GCodePoint->m_dXNextPoint;
GCodePoint->m_dYPoint = GCodePoint->m_dYPrePoint - GCodePoint->m_dYNextPoint;
GCodePoint->m_dZPoint = GCodePoint->m_dZPrePoint - GCodePoint->m_dZNextPoint;
GCodePoint->m_dAPoint = GCodePoint->m_dAPrePoint - GCodePoint->m_dANextPoint;
GCodePoint->m_dBPoint = GCodePoint->m_dBPrePoint - GCodePoint->m_dBNextPoint;
}
return 0;
}
*/
double CMath::ComputeSpeed()
{
if(iExecutedTimes == 1)
{
CLast *SaveSpeedData = new CLast;
SaveSpeedData->SpeedDataHeadSave();
SaveSpeedData->AnalyzeSpeedData();
return 0;
}
else //if(iExecutedTimes >= 2)
{
if(iExecutedTimes % 2 == 0)
{
m_dXPoint = m_dXNextPoint - m_dXPrePoint;
m_dYPoint = m_dYNextPoint - m_dYPrePoint;
m_dZPoint = m_dZNextPoint - m_dZPrePoint;
m_dAPoint = m_dANextPoint - m_dAPrePoint;
m_dBPoint = m_dBNextPoint - m_dBPrePoint;
}
else //iExecutedTimes % 2 == 1
{
m_dXPoint = m_dXPrePoint - m_dXNextPoint;
m_dYPoint = m_dYPrePoint - m_dYNextPoint;
m_dZPoint = m_dZPrePoint - m_dZNextPoint;
m_dAPoint = m_dAPrePoint - m_dANextPoint;
m_dBPoint = m_dBPrePoint - m_dBNextPoint;
}
double m_dSquare;
m_dSquare = sqrt( pow(m_dXPoint, 2) + pow(m_dYPoint, 2) + pow(m_dZPoint, 2) + pow(m_dAPoint, 2) + pow(m_dBPoint, 2) );
m_dXSpeed = m_dXPoint * m_dFeedrate / m_dSquare;
m_dYSpeed = m_dYPoint * m_dFeedrate / m_dSquare;
m_dZSpeed = m_dZPoint * m_dFeedrate / m_dSquare;
m_dASpeed = m_dAPoint * m_dFeedrate / m_dSquare;
m_dBSpeed = m_dBPoint * m_dFeedrate / m_dSquare;
CLast *SaveSpeedData = new CLast;
SaveSpeedData->AnalyzeSpeedData();
SaveSpeedData->OnSpeeddataSave();
// AfxMessageBox("double CMath::ComputeSpeed() has just been executed successfully!");
return 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -