2524 lines
72 KiB
C++
2524 lines
72 KiB
C++
#include "datafilequix.h"
|
||
|
||
|
||
DataFileQuix::DataFileQuix()
|
||
{
|
||
clear();
|
||
}
|
||
|
||
DataFileQuix::DataFileQuix(const QString &fullPathName)
|
||
{
|
||
initFile(fullPathName);
|
||
loadFile();
|
||
convertDataToEmbAbs();
|
||
}
|
||
|
||
void DataFileQuix::writeLeftFrontToFileDoubleHead(QString filePath,int left,int front)
|
||
{
|
||
QFile rdfile(filePath);
|
||
if(!rdfile.open(QIODevice::ReadOnly))
|
||
{
|
||
return;
|
||
}
|
||
|
||
QByteArray fileData = rdfile.readAll();
|
||
rdfile.close();
|
||
|
||
if(fileData.size() <= 0)
|
||
{
|
||
return;
|
||
}
|
||
|
||
QuixFileHead * head = (QuixFileHead *)(fileData.data());//头文件的结构体
|
||
head->left = left;
|
||
head->front = front;
|
||
|
||
QFile wfile(filePath);
|
||
if(!wfile.open(QIODevice::WriteOnly | QIODevice::Truncate))
|
||
{
|
||
return;
|
||
}
|
||
|
||
wfile.write(fileData);
|
||
wfile.close();
|
||
|
||
#ifdef Q_OS_LINUX
|
||
system("sync");
|
||
#endif
|
||
}
|
||
|
||
void DataFileQuix::convertDataToEmbAbs(s16 flag)
|
||
{
|
||
m_absData.clear();
|
||
getQuixMinMax();
|
||
|
||
QuixFileHead head;
|
||
|
||
// 图形数据
|
||
u32 i, datasize, idx;
|
||
unsigned char ctrl, tmpls;
|
||
|
||
u8 c1, c2, c3, c4;
|
||
u32 lsdata;
|
||
double deltx1, delty1, deltx2, delty2;
|
||
double threex[4], threey[4];
|
||
s16 nmstep;
|
||
|
||
double factorx, factory, unitmuti;
|
||
memcpy(&head, m_fileData.data(), sizeof(QuixFileHead));
|
||
unitmuti = getMutiUnit(0);
|
||
|
||
double scanx = head.scanX * unitmuti; // 宽度
|
||
double scany = head.scanY * unitmuti; // 长度
|
||
|
||
if (scanx < 1)
|
||
{
|
||
scanx = 1;
|
||
}
|
||
if (scany < 1)
|
||
{
|
||
scany = 1;
|
||
}
|
||
|
||
// 计算缩放系数
|
||
factorx = (double)((m_maxX-m_minX) / (scanx));
|
||
factory = (double)((m_maxY-m_minY) / (scany));
|
||
|
||
if(factorx == 0){factorx = 1;}
|
||
if(factory == 0){factory = 1;}
|
||
// factorx = 1;
|
||
// factory = 1;
|
||
|
||
if(flag != 1)
|
||
{
|
||
factorx = 1;
|
||
factory = 1;
|
||
}
|
||
|
||
nmstep = head.normalStep * unitmuti;
|
||
if(nmstep == 0)
|
||
{
|
||
nmstep = 200; //单位0.01mm(2mm)
|
||
}
|
||
|
||
i = sizeof(QuixFileHead);
|
||
datasize = m_fileData.size();
|
||
|
||
DsAbsItem absItem;
|
||
memset(&absItem,0,sizeof(DsAbsItem));
|
||
|
||
//将第一个点加进来
|
||
// absItem.ctrl = m_firstPoint.ctrl;
|
||
// absItem.ax = m_firstPoint.x / factorx;
|
||
// absItem.ay = m_firstPoint.y / factory;
|
||
// m_absData.append((char*)&absItem,sizeof(DsAbsItem));
|
||
|
||
while(i < datasize)
|
||
{
|
||
// 功能控制字
|
||
if (i >= datasize){break;}
|
||
ctrl = m_fileData.at(i++);
|
||
|
||
// 图元类型
|
||
if (i >= datasize){break;}
|
||
tmpls = m_fileData.at(i++);
|
||
|
||
// 附加控制字
|
||
if (i >= datasize){break;}
|
||
m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
m_fileData.at(i++);
|
||
|
||
if(ctrl == 0x00) // 结束
|
||
{
|
||
break;
|
||
}
|
||
|
||
switch(tmpls)
|
||
{
|
||
case QUI_TYPE_LINE: // 直线
|
||
case QUI_TYPE_STEP: // 跨步
|
||
case QUI_TYPE_HSTEP: // 翻头跨步
|
||
{
|
||
//增加剪线
|
||
if(tmpls == QUI_TYPE_STEP || tmpls == QUI_TYPE_HSTEP)
|
||
{
|
||
if((u32)m_absData.size() >= sizeof(DsAbsItem))
|
||
{
|
||
memcpy((char*)&absItem,m_absData.data()+m_absData.size()-sizeof(DsAbsItem),sizeof(DsAbsItem));
|
||
absItem.ctrl = DATA_CUTTRD;
|
||
m_absData.append((char*)&absItem,sizeof(DsAbsItem));
|
||
}
|
||
}
|
||
|
||
// 点个数
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
lsdata = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
|
||
if (lsdata > 1)
|
||
{
|
||
// 第一个点
|
||
//点x
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double x = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
deltx2 = x/factorx;
|
||
|
||
//点y
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double y = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
delty2 = y/factory;
|
||
|
||
for(idx = 1; idx < lsdata; idx++) // 其余的点
|
||
{
|
||
deltx1 = deltx2;
|
||
delty1 = delty2;
|
||
|
||
//点x
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
x = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
deltx2 = x/factorx;
|
||
|
||
//点y
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
y = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
delty2 = y/factory;
|
||
|
||
// 处理直线
|
||
calcLine(deltx1, delty1, deltx2, delty2, nmstep, m_absData, tmpls);
|
||
}
|
||
|
||
if (idx != lsdata)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
case QUI_TYPE_ARC: // 三点圆弧
|
||
{
|
||
// 点个数
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
lsdata = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
if(lsdata != 3)
|
||
{
|
||
break;
|
||
}
|
||
|
||
for (idx = 0; idx < lsdata; idx++)
|
||
{
|
||
//点x
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double x = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
threex[idx] = x/factorx;
|
||
|
||
//点y
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double y = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
threey[idx] = y/factory;
|
||
}
|
||
|
||
calcCurve(threex, threey, nmstep, m_absData);
|
||
|
||
if (idx != 3)
|
||
{
|
||
break;
|
||
}
|
||
break;
|
||
}
|
||
case QUI_TYPE_BES: // 贝塞尔曲线
|
||
{
|
||
// 点个数
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
lsdata = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
if(lsdata != 4)
|
||
{
|
||
break;
|
||
}
|
||
|
||
for (idx = 0; idx < lsdata; idx++)
|
||
{
|
||
//点x
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double x = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
threex[idx] = x/factorx;
|
||
|
||
//点y
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double y = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
threey[idx] = y/factory;
|
||
}
|
||
|
||
// 处理贝塞尔曲线
|
||
QList<QPointF> splineListXY;//拟合后的点
|
||
splineListXY.clear();
|
||
getBezierPointList(threex, threey, nmstep,splineListXY);
|
||
|
||
QList<QPointF> splitListXY;//均分后的点
|
||
splitListXY.clear();
|
||
if(splineListXY.size() > 0)
|
||
{
|
||
getCurvePointFillLine(splineListXY,nmstep,splitListXY,0,OBJECT_STITCHLEN_NEW_SAMALL);
|
||
}
|
||
|
||
//添加贝塞尔曲线数据点
|
||
for(int i = 0; i < splitListXY.size(); i++)
|
||
{
|
||
memset(&absItem,0,sizeof(DsAbsItem));
|
||
|
||
deltx1 = splitListXY[i].x();
|
||
delty1 = splitListXY[i].y();
|
||
|
||
absItem.ctrl = DATA_SEWING;
|
||
absItem.ax = deltx1;
|
||
absItem.ay = delty1;
|
||
m_absData.append((char*)&absItem,sizeof(DsAbsItem));
|
||
}
|
||
//calcBezier(threex, threey, nmstep, m_absData);
|
||
|
||
if (idx != 4)
|
||
{
|
||
break;
|
||
}
|
||
break;
|
||
}
|
||
case QUI_TYPE_SPLINE: // 样条
|
||
{
|
||
QList<QPointF> quiListPoint;//样条拟合前的点集合
|
||
quiListPoint.clear();
|
||
|
||
// 点个数
|
||
if (i >= datasize){break;}
|
||
unsigned char c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
unsigned char c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
unsigned char c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
unsigned char c4 = m_fileData.at(i++);
|
||
lsdata = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
|
||
for(idx = 0; idx < lsdata; idx++) // 点
|
||
{
|
||
//点x
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double x = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
deltx1 = x/factorx;
|
||
|
||
//点y
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double y = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
delty1 = y/factory;
|
||
|
||
QPointF point(deltx1,delty1);
|
||
quiListPoint.append(point);
|
||
}
|
||
|
||
QList<QPointF> splineListXY;//拟合后的点
|
||
splineListXY.clear();
|
||
if(quiListPoint.size() <= 0)
|
||
{
|
||
break;
|
||
}
|
||
getSplineNew(quiListPoint,splineListXY);
|
||
|
||
// 均分
|
||
QList<QPointF> splitListXY;//均分后的点
|
||
splitListXY.clear();
|
||
if(splineListXY.size() > 0)
|
||
{
|
||
getCurvePointFillLine(splineListXY,nmstep,splitListXY,0,OBJECT_STITCHLEN_NEW_SAMALL);
|
||
}
|
||
|
||
//添加样条曲线数据点
|
||
for(int i = 0; i < splitListXY.size(); i++)
|
||
{
|
||
memset(&absItem,0,sizeof(DsAbsItem));
|
||
|
||
deltx1 = splitListXY[i].x();
|
||
delty1 = splitListXY[i].y();
|
||
|
||
absItem.ctrl = DATA_SEWING;
|
||
absItem.ax = deltx1;
|
||
absItem.ay = delty1;
|
||
m_absData.append((char*)&absItem,sizeof(DsAbsItem));
|
||
}
|
||
|
||
if(idx != lsdata)
|
||
{
|
||
break;
|
||
}
|
||
break;
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
//生成绝对坐标数据的文件头
|
||
creatAbsHeadAndAr();
|
||
}
|
||
|
||
void DataFileQuix::creatAbsHeadAndAr()
|
||
{
|
||
DataDs16FileHead dhead;
|
||
memset(&dhead, 0, sizeof(DataDs16FileHead));
|
||
|
||
int stepSize = m_absData.size()/sizeof(DsAbsItem);
|
||
if(stepSize <= 0)
|
||
{
|
||
return;
|
||
}
|
||
|
||
DsAbsItem * absDataPtr = (DsAbsItem *)(m_absData.data());
|
||
|
||
double minX, maxX, minY, maxY;
|
||
minX = S32_MAX;
|
||
maxX = S32_MIN;
|
||
minY = S32_MAX;
|
||
maxY = S32_MIN;
|
||
|
||
double curx,cury,dx,dy,ar;
|
||
curx = cury = dx = dy = ar = 0;
|
||
|
||
//取反并求最大最小值
|
||
for (int i = 0; i < stepSize; i++)
|
||
{
|
||
absDataPtr->ax *= QUIX_DATADIRX;
|
||
absDataPtr->ay *= QUIX_DATADIRY;
|
||
|
||
curx = absDataPtr->ax;
|
||
cury = absDataPtr->ay;
|
||
|
||
if(curx > maxX)
|
||
{
|
||
maxX = curx;
|
||
}
|
||
if(curx < minX)
|
||
{
|
||
minX = curx;
|
||
}
|
||
|
||
if(cury > maxY)
|
||
{
|
||
maxY = cury;
|
||
}
|
||
if(cury < minY)
|
||
{
|
||
minY = cury;
|
||
}
|
||
|
||
absDataPtr++;
|
||
}
|
||
|
||
absDataPtr = (DsAbsItem *)(m_absData.data());
|
||
double begX = absDataPtr->ax;//起始点
|
||
double begY = absDataPtr->ay;
|
||
int begR = 0;
|
||
|
||
m_firstPoint.x = begX;
|
||
m_firstPoint.y = begY;
|
||
m_firstPoint.ctrl = absDataPtr->ctrl;
|
||
|
||
//增加结束码
|
||
if((u32)m_absData.size() >= sizeof(DsAbsItem))
|
||
{
|
||
DsAbsItem absItem;
|
||
memset(&absItem,0,sizeof(DsAbsItem));
|
||
memcpy((char*)&absItem,m_absData.data()+m_absData.size()-sizeof(DsAbsItem),sizeof(DsAbsItem));
|
||
absItem.ctrl = DATA_END;
|
||
m_absData.append((char*)&absItem,sizeof(DsAbsItem));
|
||
stepSize++;
|
||
}
|
||
|
||
m_maxX = maxX;
|
||
m_minX = minX;
|
||
m_maxY = maxY;
|
||
m_minY = minY;
|
||
|
||
//生成文件头
|
||
dhead.maxX = maxX;
|
||
dhead.maxY = maxY;
|
||
dhead.minX = minX;
|
||
dhead.minY = minY;
|
||
dhead.beginX = begX;
|
||
dhead.beginY = begY;
|
||
dhead.beginR = begR;
|
||
dhead.anchorX = 0;
|
||
dhead.anchorY = 0;
|
||
dhead.itemNums = stepSize;
|
||
dhead.dataSize = stepSize*sizeof(DsAbsItem); // 数据字节数
|
||
dhead.bytesPerItem = sizeof(DsAbsItem); // 每项占的字节数
|
||
dhead.dataChecksum = calcCheckSum32((u8 *)(m_absData.data()) , dhead.dataSize);; // 数据累加校验和
|
||
dhead.checkCrc = calcCrc16((u8 *)(&dhead), HEAD_FIX_INFO_LEN); // 前面6个字段的CRC校验,(6个字段分别为:文件名称,字节数,项个数,每项字节数,每块字节数,数据累加和的CRC校验值)
|
||
dhead.fileid = dhead.checkCrc;
|
||
m_absData.insert(0,(char*)&dhead,sizeof(DataDs16FileHead));
|
||
}
|
||
|
||
void DataFileQuix::getQuixMinMax()
|
||
{
|
||
QuixFileHead head;
|
||
memcpy(&head, m_fileData.data(), sizeof(QuixFileHead));
|
||
|
||
u32 i, idx, datasize;
|
||
unsigned char ctrl, tmpls;
|
||
u8 c1, c2, c3, c4;
|
||
u32 lsdata;
|
||
double deltx, delty;
|
||
double threex[4], threey[4];
|
||
|
||
int first = 0;
|
||
double minx, maxx, miny, maxy;
|
||
|
||
minx = S32_MAX;
|
||
maxx = S32_MIN;
|
||
miny = S32_MAX;
|
||
maxy = S32_MIN;
|
||
|
||
i = sizeof(QuixFileHead);
|
||
datasize = m_fileData.size();
|
||
while(i < datasize)
|
||
{
|
||
// 功能控制字
|
||
if (i >= datasize){break;}
|
||
ctrl = m_fileData.at(i++);
|
||
|
||
// 图元类型
|
||
if (i >= datasize){break;}
|
||
tmpls = m_fileData.at(i++);
|
||
|
||
// 附加控制字1和2
|
||
if (i >= datasize){break;}
|
||
m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
m_fileData.at(i++);
|
||
|
||
if(ctrl == 0x00) // 结束
|
||
{
|
||
break;
|
||
}
|
||
|
||
switch(tmpls)
|
||
{
|
||
case QUI_TYPE_LINE: // 直线(折线)
|
||
case QUI_TYPE_STEP: // 跨步
|
||
case QUI_TYPE_HSTEP: // 翻头跨步
|
||
{
|
||
// 点个数
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
lsdata = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
|
||
if (lsdata > 1)
|
||
{
|
||
for(idx = 0; idx < lsdata; idx++) // 点
|
||
{
|
||
//点x
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
deltx = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
|
||
//点y
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
delty = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
|
||
if (first == 0)
|
||
{
|
||
m_firstPoint.x = deltx;
|
||
m_firstPoint.y = delty;
|
||
m_firstPoint.ctrl = ctrl;
|
||
first = 1;
|
||
}
|
||
|
||
if(deltx > maxx)
|
||
{
|
||
maxx = deltx;
|
||
}
|
||
if(deltx < minx)
|
||
{
|
||
minx = deltx;
|
||
}
|
||
|
||
if(delty > maxy)
|
||
{
|
||
maxy = delty;
|
||
}
|
||
if(delty < miny)
|
||
{
|
||
miny = delty;
|
||
}
|
||
}
|
||
|
||
if (idx != lsdata)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case QUI_TYPE_ARC: // 三点圆弧
|
||
{
|
||
// 点个数
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
lsdata = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
|
||
if(lsdata != 3)
|
||
{
|
||
break;
|
||
}
|
||
|
||
for (idx = 0; idx < lsdata; idx++)
|
||
{
|
||
//点x
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
threex[idx] = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
|
||
//点y
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
threey[idx] = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
|
||
if (first == 0)
|
||
{
|
||
m_firstPoint.x = threex[0];
|
||
m_firstPoint.y = threey[0];
|
||
m_firstPoint.ctrl = ctrl;
|
||
first = 1;
|
||
}
|
||
}
|
||
if (idx != 3)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
break;
|
||
case QUI_TYPE_BES: // 贝塞尔曲线
|
||
{
|
||
// 点个数
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
lsdata = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
|
||
if(lsdata != 4)
|
||
{
|
||
break;
|
||
}
|
||
|
||
for (idx = 0; idx < lsdata; idx++)
|
||
{
|
||
//点x
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
threex[idx] = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
|
||
//点y
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
threey[idx] = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
|
||
if (first == 0)
|
||
{
|
||
m_firstPoint.x = threex[0];
|
||
m_firstPoint.y = threey[0];
|
||
m_firstPoint.ctrl = ctrl;
|
||
first = 1;
|
||
}
|
||
}
|
||
if (idx != 4)
|
||
{
|
||
break;
|
||
}
|
||
|
||
getBezierMinMax(threex, threey, &minx, &maxx, &miny, &maxy);
|
||
}
|
||
break;
|
||
case QUI_TYPE_SPLINE: // 样条
|
||
{
|
||
QList<QPointF> quiListPoint;//样条拟合前的点集合
|
||
quiListPoint.clear();
|
||
|
||
// 点个数
|
||
if (i >= datasize){break;}
|
||
unsigned char c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
unsigned char c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
unsigned char c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
unsigned char c4 = m_fileData.at(i++);
|
||
lsdata = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
|
||
for(idx = 0; idx < lsdata; idx++) // 点
|
||
{
|
||
//点x
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
deltx = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
|
||
//点y
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
delty = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
|
||
QPointF point(deltx,delty);
|
||
quiListPoint.append(point);
|
||
|
||
if (first == 0)
|
||
{
|
||
m_firstPoint.x = deltx;
|
||
m_firstPoint.y = delty;
|
||
m_firstPoint.ctrl = ctrl;
|
||
first = 1;
|
||
}
|
||
}
|
||
getSplineMinMax(quiListPoint, &minx, &maxx, &miny, &maxy);
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (first == 0)
|
||
{
|
||
minx = 0;
|
||
maxx = 0;
|
||
miny = 0;
|
||
maxy = 0;
|
||
|
||
m_firstPoint.x = 0;
|
||
m_firstPoint.y = 0;
|
||
m_firstPoint.ctrl = 0;
|
||
}
|
||
|
||
m_minX = minx;
|
||
m_maxX = maxx;
|
||
m_minY = miny;
|
||
m_maxY = maxy;
|
||
|
||
return;
|
||
}
|
||
|
||
const QPoint DataFileQuix::getFirstPoint()
|
||
{
|
||
QPoint p(m_firstPoint.x,m_firstPoint.y);
|
||
return p;
|
||
}
|
||
|
||
int DataFileQuix::checkFileHead()
|
||
{
|
||
if (m_fileData.size() >= (int)sizeof(QuixFileHead))
|
||
{
|
||
QuixFileHead * pHead;
|
||
pHead = (QuixFileHead *)(m_fileData.data());
|
||
|
||
if (pHead->normalStep < 1)
|
||
{
|
||
pHead->normalStep = 40;
|
||
}
|
||
|
||
if (pHead->scanX < 1)
|
||
{
|
||
pHead->scanX = m_maxX - m_minX;
|
||
}
|
||
|
||
if (pHead->scanY < 1)
|
||
{
|
||
pHead->scanY = m_maxY - m_minY;
|
||
}
|
||
|
||
QFile wrfile(m_fileFullPathName);
|
||
if(!wrfile.open(QIODevice::WriteOnly | QIODevice::Truncate))
|
||
{
|
||
return -1;
|
||
}
|
||
else
|
||
{
|
||
wrfile.write(m_fileData);
|
||
wrfile.close();
|
||
}
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
|
||
double DataFileQuix::getMutiUnit(int unit)
|
||
{
|
||
double unitmuti;
|
||
if (unit == 0x00) // 0x00: 0.1mm;
|
||
{
|
||
unitmuti = 10;
|
||
}
|
||
else if (unit == 0x01) // 0x01: 1/1000inch;
|
||
{
|
||
unitmuti = 2.54;
|
||
}
|
||
else if (unit == 0x02) // 0x02: 0.04mm
|
||
{
|
||
unitmuti = 10;
|
||
}
|
||
else
|
||
{
|
||
unitmuti = 1;
|
||
}
|
||
return unitmuti;
|
||
}
|
||
|
||
void DataFileQuix::initFile(const QString &fullPathName)
|
||
{
|
||
clear();
|
||
QFileInfo file(fullPathName);
|
||
if (file.exists() && file.isFile())
|
||
{
|
||
m_fileFullPathName = fullPathName;
|
||
}
|
||
else
|
||
{
|
||
qDebug() << "Init file failed path =" << m_fileFullPathName;
|
||
}
|
||
loadFile();
|
||
}
|
||
|
||
void DataFileQuix::clear()
|
||
{
|
||
m_firstPoint.x = 0;
|
||
m_firstPoint.y = 0;
|
||
m_firstPoint.ctrl = 0;
|
||
|
||
m_firstPointLeft.x = 0;
|
||
m_firstPointLeft.y = 0;
|
||
m_firstPointLeft.ctrl = 0;
|
||
|
||
m_firstPointRight.x = 0;
|
||
m_firstPointRight.y = 0;
|
||
m_firstPointRight.ctrl = 0;
|
||
|
||
m_minX = INT32_MAX;
|
||
m_maxX = INT32_MIN;
|
||
m_minY = INT32_MAX;
|
||
m_maxY = INT32_MIN;
|
||
|
||
m_fileFullPathName.clear(); // 文件路径
|
||
m_fileData.clear(); // 文件数据内容
|
||
m_absData.clear(); // 转换后的数据
|
||
}
|
||
|
||
void DataFileQuix::loadFile()
|
||
{
|
||
QFile rdfile(m_fileFullPathName);
|
||
if(!rdfile.open(QIODevice::ReadOnly))
|
||
{
|
||
qDebug() << "open file fail when read, path =" << m_fileFullPathName;
|
||
return;
|
||
}
|
||
|
||
m_fileData = rdfile.readAll();
|
||
rdfile.close();
|
||
}
|
||
|
||
int DataFileQuix::createPreviewImage(QImage *pImg, int saveflag, int penwidth, int reDraw)
|
||
{
|
||
#if(1)
|
||
s16 existFlag = 1;
|
||
|
||
if(reDraw == 0)//图片存在则不重画
|
||
{
|
||
existFlag = 0;
|
||
// 图片是否存在,存在则返回
|
||
QString previewPath = getFileFullPathName() + ".preview.png";
|
||
QFile imageFile(previewPath);
|
||
if (imageFile.exists())
|
||
{
|
||
return 1;
|
||
}
|
||
}
|
||
#endif
|
||
|
||
int newimgflag = 0;
|
||
QImage * pImage;
|
||
int width, height;
|
||
if (pImg == NULL)
|
||
{
|
||
width = QUIX_PREVIEW_WIDTH;
|
||
height = QUIX_PREVIEW_HEIGHT;
|
||
pImage = new QImage(width, height, IMAGE_TYPE);
|
||
newimgflag = 1;
|
||
}
|
||
else
|
||
{
|
||
pImage = pImg;
|
||
}
|
||
|
||
width = pImage->width();
|
||
height = pImage->height();
|
||
if (width <= QUIX_PREVIEW_SIDE*2 || height <= QUIX_PREVIEW_SIDE*2)
|
||
{
|
||
if (pImage != NULL && newimgflag == 1)
|
||
{
|
||
delete pImage;
|
||
}
|
||
qDebug("preview img too small");
|
||
return -1;
|
||
}
|
||
|
||
memset(pImage->bits(), 0x00, pImage->byteCount());
|
||
|
||
QPainter painter(pImage);
|
||
QColor backcolor(255, 255, 255, 0); // 透明背景
|
||
// 背景
|
||
QPen pen;
|
||
pen.setWidth(penwidth);
|
||
pen.setColor(backcolor);
|
||
painter.setPen(pen);
|
||
painter.setBrush(backcolor);
|
||
painter.drawRect(0, 0, width, height);
|
||
|
||
// 图形
|
||
//qDebug()<<"convertDataToAbs defore";
|
||
convertDataToEmbAbs(existFlag); // 转换为绝对坐标数据
|
||
//qDebug()<<"convertDataToAbs end";
|
||
|
||
// absdat数据
|
||
int size = m_absData.size();
|
||
if (size <= (int)sizeof(DataDs16FileHead))
|
||
{
|
||
qDebug("2 data less then head size");
|
||
return -1;
|
||
}
|
||
DataDs16FileHead * pAbsHead = (DataDs16FileHead *)(m_absData.data());
|
||
int datasize = size - sizeof(DataDs16FileHead);
|
||
if (datasize <= 0)
|
||
{
|
||
qDebug("absdat dataBegin err");
|
||
return -1;
|
||
}
|
||
int stepsize = datasize/sizeof(DsAbsItem);
|
||
if (stepsize <= 0)
|
||
{
|
||
qDebug("absdat data size err");
|
||
return -1;
|
||
}
|
||
DsAbsItem * pData = (DsAbsItem *)(m_absData.data() + sizeof(DataDs16FileHead));
|
||
DsAbsItem * absDataPtr = pData;
|
||
//--------
|
||
|
||
// 图形显示区域
|
||
int dpminx = QUIX_PREVIEW_SIDE;
|
||
int dpmaxx = width - QUIX_PREVIEW_SIDE;
|
||
int dpminy = QUIX_PREVIEW_SIDE;
|
||
int dpmaxy = height - QUIX_PREVIEW_SIDE;
|
||
|
||
// 计算缩放系数
|
||
double factor, temp;
|
||
if ((dpmaxx - dpminx) <= 0 || (dpmaxy - dpminy) <= 0)
|
||
{
|
||
return -1;
|
||
}
|
||
|
||
factor = (double)(fabs(m_maxX - m_minX)) / (dpmaxx - dpminx); // 按x计算的缩放系数
|
||
temp = (double)(fabs(m_maxY - m_minY)) / (dpmaxy - dpminy); // 按x计算的缩放系数
|
||
|
||
if (temp >= factor) // 使用较大的缩放系数
|
||
{
|
||
factor = temp;
|
||
}
|
||
|
||
// 计算显示参数,按照图形的实际位置显示(数据坐标零点对应图形中心)
|
||
double dpx = (double)((dpminx+dpmaxx)/2 - ((m_maxX+m_minX)/factor)/2);
|
||
double dpy = (double)((dpminy+dpmaxy)/2 - ((m_maxY+m_minY)/factor)/2);
|
||
|
||
// 显示花样图形
|
||
u8 ctrlByte;
|
||
double dx;
|
||
double dy;
|
||
|
||
double datposx, datposy;
|
||
datposx = datposy = 0.;
|
||
double curx, cury, prex, prey;
|
||
curx = cury = prex = prey = 0;
|
||
|
||
datposx = pAbsHead->beginX;
|
||
datposy = pAbsHead->beginY;
|
||
|
||
curx = (datposx) / factor + dpx;
|
||
cury = (datposy) / factor + dpy;
|
||
|
||
if (QUIX_SHOWDIRX == -1)
|
||
{
|
||
curx = (width)-curx;
|
||
}
|
||
if (QUIX_SHOWDIRY == -1)
|
||
{
|
||
cury = (height)-cury;
|
||
}
|
||
|
||
absDataPtr = pData;
|
||
|
||
QColor color = QColor(Qt::green);
|
||
pen.setColor(color);
|
||
painter.setPen(pen);
|
||
|
||
for (int i = 0; i < stepsize; i++)
|
||
{
|
||
// 读入一个针步数据
|
||
ctrlByte = absDataPtr->ctrl;
|
||
|
||
prex = curx;
|
||
prey = cury;
|
||
|
||
dx = absDataPtr->ax;
|
||
dy = absDataPtr->ay;
|
||
|
||
datposx = dx;
|
||
datposy = dy;
|
||
|
||
curx = (datposx) / factor + dpx;
|
||
cury = (datposy) / factor + dpy;
|
||
|
||
if (QUIX_SHOWDIRX == -1)
|
||
{
|
||
curx = (width)-curx;
|
||
}
|
||
if (QUIX_SHOWDIRY == -1)
|
||
{
|
||
cury = (height)-cury;
|
||
}
|
||
|
||
if(i == 0)
|
||
{
|
||
absDataPtr++;
|
||
continue;
|
||
}
|
||
|
||
if (ctrlByte == DATA_SEWING)
|
||
{
|
||
QPointF p1(prex, prey);
|
||
QPointF p2(curx, cury);
|
||
painter.drawLine(p1, p2);
|
||
}
|
||
else
|
||
{
|
||
//painter.drawLine(prex, prey, curx, cury);
|
||
//qDebug("other type=0x%x", ctrlByte);
|
||
}
|
||
|
||
absDataPtr++;
|
||
}
|
||
|
||
// 保存成文件
|
||
QString preview = getFileFullPathName();
|
||
if (saveflag != 0 && preview.isEmpty() == false)
|
||
{
|
||
#if (1)
|
||
preview += ".preview.png";
|
||
pImage->save(preview, "png");
|
||
#endif
|
||
}
|
||
|
||
if (pImage != NULL && newimgflag == 1)
|
||
{
|
||
delete pImage;
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
|
||
QuixFileHead *DataFileQuix::getQuixHead()
|
||
{
|
||
if(m_fileData.size() <= 0)
|
||
{
|
||
loadFile();
|
||
}
|
||
|
||
QuixFileHead *head = NULL;
|
||
|
||
int size = m_fileData.size();
|
||
if (size <= (int)(sizeof(QuixFileHead)))
|
||
{
|
||
head = new QuixFileHead;
|
||
memset(head,0,sizeof(QuixFileHead));
|
||
return head;
|
||
}
|
||
|
||
head = (QuixFileHead *)(m_fileData.data());
|
||
return head;
|
||
}
|
||
|
||
void DataFileQuix::writePatternParaToFile(QuixFileHead *head)
|
||
{
|
||
if(m_fileData.size() <= 0)
|
||
{
|
||
return;
|
||
}
|
||
|
||
memcpy(m_fileData.data(),(char*)head,sizeof(QuixFileHead));
|
||
|
||
QFile wfile(m_fileFullPathName);
|
||
if(!wfile.open(QIODevice::WriteOnly | QIODevice::Truncate))
|
||
{
|
||
qDebug() << "open file fail when read, path =" << m_fileFullPathName;
|
||
return;
|
||
}
|
||
|
||
wfile.write(m_fileData);
|
||
wfile.close();
|
||
}
|
||
|
||
void DataFileQuix::moveDataBeginPonit(s32 left, s32 front)
|
||
{
|
||
if((u32)m_absData.size() > sizeof(DataDs16FileHead))
|
||
{
|
||
DataDs16FileHead *dhead = (DataDs16FileHead *)( m_absData.data());
|
||
dhead->beginX += left;
|
||
dhead->beginY += front;
|
||
dhead->maxX += left;
|
||
dhead->minX += left;
|
||
dhead->maxY += front;
|
||
dhead->minY += front;
|
||
}
|
||
}
|
||
|
||
int DataFileQuix::doubleHeadCreatePreviewImage(QImage *pImg, int saveflag, int penwidth, int reDraw)
|
||
{
|
||
#if(1)
|
||
if(reDraw == 0)//图片存在则不重画
|
||
{
|
||
// 图片是否存在,存在则返回
|
||
QString previewPath = getFileFullPathName() + ".preview.png";
|
||
QFile imageFile(previewPath);
|
||
if (imageFile.exists())
|
||
{
|
||
return 1;
|
||
}
|
||
}
|
||
#endif
|
||
|
||
int newimgflag = 0;
|
||
QImage * pImage;
|
||
double width, height;
|
||
if (pImg == NULL)
|
||
{
|
||
width = QUIX_PREVIEW_WIDTH;
|
||
height = QUIX_PREVIEW_HEIGHT;
|
||
pImage = new QImage(width, height, IMAGE_TYPE);
|
||
newimgflag = 1;
|
||
}
|
||
else
|
||
{
|
||
pImage = pImg;
|
||
}
|
||
|
||
width = pImage->width();
|
||
height = pImage->height();
|
||
if (width <= QUIX_PREVIEW_SIDE*2 || height <= QUIX_PREVIEW_SIDE*2)
|
||
{
|
||
if (pImage != NULL && newimgflag == 1)
|
||
{
|
||
delete pImage;
|
||
}
|
||
qDebug("preview img too small");
|
||
return -1;
|
||
}
|
||
|
||
memset(pImage->bits(), 0x00, pImage->byteCount());
|
||
|
||
QPainter painter(pImage);
|
||
QColor backcolor(255, 255, 255, 0); // 透明背景
|
||
// 背景
|
||
QPen pen;
|
||
pen.setWidth(penwidth);
|
||
pen.setColor(backcolor);
|
||
painter.setPen(pen);
|
||
painter.setBrush(backcolor);
|
||
painter.drawRect(0, 0, width, height);
|
||
|
||
// 图形
|
||
//qDebug()<<"convertDataToAbs defore";
|
||
doubleHeadConvertDataToEmbAbs(0); // 转换为绝对坐标数据
|
||
//qDebug()<<"convertDataToAbs end";
|
||
|
||
// absdat数据
|
||
int size = m_absData.size();
|
||
if (size <= (int)sizeof(DataDs16FileHead))
|
||
{
|
||
qDebug("2 data less then head size");
|
||
return -1;
|
||
}
|
||
//DataDs16FileHead * pAbsHead = (DataDs16FileHead *)(m_absData.data());
|
||
int datasize = size - sizeof(DataDs16FileHead);
|
||
if (datasize <= 0)
|
||
{
|
||
qDebug("absdat dataBegin err");
|
||
return -1;
|
||
}
|
||
int stepsize = datasize/sizeof(DsAbsItem);
|
||
if (stepsize <= 0)
|
||
{
|
||
qDebug("absdat data size err");
|
||
return -1;
|
||
}
|
||
DsAbsItem * pData = (DsAbsItem *)(m_absData.data() + sizeof(DataDs16FileHead));
|
||
DsAbsItem * absDataPtr = pData;
|
||
//--------
|
||
|
||
// 图形显示区域
|
||
int dpminx = QUIX_PREVIEW_SIDE;
|
||
int dpmaxx = width - QUIX_PREVIEW_SIDE;
|
||
int dpminy = QUIX_PREVIEW_SIDE;
|
||
int dpmaxy = height - QUIX_PREVIEW_SIDE;
|
||
|
||
// 计算缩放系数
|
||
double factor, temp;
|
||
if ((dpmaxx - dpminx) <= 0 || (dpmaxy - dpminy) <= 0)
|
||
{
|
||
return -1;
|
||
}
|
||
|
||
factor = (double)(fabs(m_maxX - m_minX)) / (dpmaxx - dpminx); // 按x计算的缩放系数
|
||
temp = (double)(fabs(m_maxY - m_minY)) / (dpmaxy - dpminy); // 按x计算的缩放系数
|
||
|
||
if (temp >= factor) // 使用较大的缩放系数
|
||
{
|
||
factor = temp;
|
||
}
|
||
|
||
// 计算显示参数,按照图形的实际位置显示(数据坐标零点对应图形中心)
|
||
double dpx = (double)((dpminx+dpmaxx)/2 - ((m_maxX+m_minX)/factor)/2);
|
||
double dpy = (double)((dpminy+dpmaxy)/2 - ((m_maxY+m_minY)/factor)/2);
|
||
|
||
// 显示花样图形
|
||
u8 ctrlByte;
|
||
double dx;
|
||
double dy;
|
||
|
||
double firOftX = m_firstPointLeft.x - m_firstAbsPoint.x();
|
||
double firOftY = 0 - (m_firstPointLeft.y - m_firstAbsPoint.y());
|
||
|
||
double secOftX = m_firstPointRight.x - m_firstPointLeft.x;
|
||
double secOftY = 0 - (m_firstPointRight.y - m_firstPointLeft.y);//因为中间数据y向取反了,所以这里用0减
|
||
|
||
double datposx1, datposy1, datposx2, datposy2;
|
||
datposx1 = datposy1 = datposx2 = datposy2 = 0.;
|
||
double curx1, cury1, prex1, prey1;
|
||
curx1 = cury1 = prex1 = prey1 = 0;
|
||
double curx2, cury2, prex2, prey2;
|
||
curx2 = cury2 = prex2 = prey2 = 0;
|
||
|
||
//判断数据是否为第二机头开始
|
||
if(absDataPtr->ctrl == DATA_OFFSET_SEC || absDataPtr->ctrl == DATA_SEWING_R)
|
||
{
|
||
datposx2 = 0;
|
||
datposy2 = 0;
|
||
|
||
datposx1 = 0 - secOftX;
|
||
datposy1 = 0 - secOftY;
|
||
}
|
||
else
|
||
{
|
||
datposx1 = 0;
|
||
datposy1 = 0;
|
||
|
||
datposx2 = secOftX;
|
||
datposy2 = secOftY;
|
||
}
|
||
|
||
curx1 = (datposx1) / factor + dpx;
|
||
cury1 = (datposy1) / factor + dpy;
|
||
|
||
int showDirX = QUIX_SHOWDIRX;
|
||
int showDirY = QUIX_SHOWDIRY;
|
||
|
||
if (showDirX == -1)
|
||
{
|
||
curx1 = (width)-curx1;
|
||
}
|
||
if (showDirY == -1)
|
||
{
|
||
cury1 = (height)-cury1;
|
||
}
|
||
|
||
curx2 = (datposx2) / factor + dpx;
|
||
cury2 = (datposy2) / factor + dpy;
|
||
|
||
if (showDirX == -1)
|
||
{
|
||
curx2 = (width)-curx2;
|
||
}
|
||
if (showDirY == -1)
|
||
{
|
||
cury2 = (height)-cury2;
|
||
}
|
||
|
||
absDataPtr = pData;
|
||
|
||
QColor color = QColor(Qt::green);
|
||
pen.setColor(color);
|
||
painter.setPen(pen);
|
||
|
||
for (int i = 0; i < stepsize; i++)
|
||
{
|
||
// 读入一个针步数据
|
||
ctrlByte = absDataPtr->ctrl;
|
||
|
||
if(ctrlByte == QUIX_OFFSET)
|
||
{
|
||
firOftX = absDataPtr->ax;
|
||
firOftY = absDataPtr->ay;
|
||
}
|
||
|
||
if(ctrlByte == QUIX_OFFSET_SEC)
|
||
{
|
||
secOftX = absDataPtr->ax - firOftX;
|
||
secOftY = absDataPtr->ay - firOftY;
|
||
}
|
||
|
||
if(ctrlByte == QUIX_SEWING || ctrlByte == QUIX_OFFSET ||
|
||
ctrlByte == QUIX_SYNC_OFFSET || ctrlByte == QUIX_MIRROR_SEC ||
|
||
ctrlByte == QUIX_MIRROR_OFT_SEC || ctrlByte == QUIX_SYNC_SEWING)//左机头
|
||
{
|
||
//左机头
|
||
prex1 = curx1;
|
||
prey1 = cury1;
|
||
|
||
dx = absDataPtr->ax;
|
||
dy = absDataPtr->ay;
|
||
|
||
datposx1 = dx;
|
||
datposy1 = dy;
|
||
|
||
curx1 = (datposx1) / factor + dpx;
|
||
cury1 = (datposy1) / factor + dpy;
|
||
|
||
if (showDirX == -1)
|
||
{
|
||
curx1 = (width)-curx1;
|
||
}
|
||
if (showDirY == -1)
|
||
{
|
||
cury1 = (height)-cury1;
|
||
}
|
||
|
||
if (ctrlByte == QUIX_OFFSET || ctrlByte == QUIX_SYNC_OFFSET || ctrlByte == QUIX_MIRROR_OFT_SEC || ctrlByte == DATA_NULL)
|
||
{
|
||
//偏移数据和j结束不绘制
|
||
//painter.drawLine(QLineF(prex1, prey1, curx1, cury1));
|
||
}
|
||
else
|
||
{
|
||
painter.drawLine(QLineF(prex1, prey1, curx1, cury1));
|
||
//qDebug()<<"1"<<i<<prex1<<curx1<<" "<<prey1<<cury1;
|
||
}
|
||
}
|
||
|
||
if(ctrlByte == QUIX_SEWING_SEC || ctrlByte == QUIX_OFFSET_SEC ||
|
||
ctrlByte == QUIX_SYNC_OFFSET || ctrlByte == QUIX_MIRROR_SEC ||
|
||
ctrlByte == QUIX_MIRROR_OFT_SEC || ctrlByte == QUIX_SYNC_SEWING)//右机头
|
||
{
|
||
//右机头
|
||
prex2 = curx2;
|
||
prey2 = cury2;
|
||
|
||
if(ctrlByte == QUIX_OFFSET_SEC || ctrlByte == QUIX_SEWING_SEC)
|
||
{
|
||
dx = absDataPtr->ax;
|
||
dy = absDataPtr->ay;
|
||
}
|
||
else
|
||
{
|
||
dx = absDataPtr->ax + secOftX;
|
||
dy = absDataPtr->ay + secOftY;
|
||
}
|
||
|
||
if(ctrlByte == QUIX_MIRROR_SEC || ctrlByte == QUIX_MIRROR_OFT_SEC)
|
||
{
|
||
dx = secOftX + (firOftX - absDataPtr->ax) + firOftX;
|
||
}
|
||
|
||
datposx2 = dx;
|
||
datposy2 = dy;
|
||
|
||
curx2 = (datposx2) / factor + dpx;
|
||
cury2 = (datposy2) / factor + dpy;
|
||
|
||
if (showDirX == -1)
|
||
{
|
||
curx2 = (width)-curx2;
|
||
}
|
||
if (showDirY == -1)
|
||
{
|
||
cury2 = (height)-cury2;
|
||
}
|
||
|
||
if (ctrlByte == QUIX_OFFSET_SEC || ctrlByte == QUIX_SYNC_OFFSET || ctrlByte == QUIX_MIRROR_OFT_SEC || ctrlByte == DATA_NULL)
|
||
{
|
||
//偏移数据和j结束不绘制
|
||
//painter.drawLine(QLineF(prex2, prey2, curx2, cury2));
|
||
}
|
||
else
|
||
{
|
||
painter.drawLine(prex2, prey2, curx2, cury2);
|
||
//qDebug()<<"2"<<i<<prex2<<curx2<<" "<<prey2<<cury2;
|
||
}
|
||
}
|
||
|
||
if(i == 0)
|
||
{
|
||
absDataPtr++;
|
||
continue;
|
||
}
|
||
|
||
absDataPtr++;
|
||
}
|
||
|
||
// 保存成文件
|
||
QString preview = getFileFullPathName();
|
||
if (saveflag != 0 && preview.isEmpty() == false)
|
||
{
|
||
#if (1)
|
||
preview += ".preview.png";
|
||
pImage->save(preview, "png");
|
||
#endif
|
||
}
|
||
|
||
if (pImage != NULL && newimgflag == 1)
|
||
{
|
||
delete pImage;
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
|
||
void DataFileQuix::doubleHeadConvertDataToEmbAbs(s16 flag)
|
||
{
|
||
if(flag == 0){}//去掉编译警告
|
||
m_absData.clear();
|
||
|
||
// 图形数据
|
||
u32 i, datasize, idx;
|
||
unsigned char ctrl, tmpls;
|
||
|
||
u8 c1, c2, c3, c4;
|
||
u32 lsdata;
|
||
double deltx, delty, deltx1, delty1, deltx2, delty2;
|
||
double threex[4], threey[4];
|
||
s16 nmstep;
|
||
|
||
double factorx, factory, unitmuti;
|
||
factorx = factory = unitmuti = 1;
|
||
QuixFileHead * head = (QuixFileHead *)(m_fileData.data());//头文件的结构体
|
||
|
||
nmstep = head->normalStep * 10;
|
||
if(nmstep == 0)
|
||
{
|
||
nmstep = 200; //单位0.01mm(2mm)
|
||
}
|
||
|
||
i = sizeof(QuixFileHead);
|
||
datasize = m_fileData.size();
|
||
|
||
DsAbsItem absItem;
|
||
memset(&absItem,0,sizeof(DsAbsItem));
|
||
|
||
int firstLeftOft = 0;//左机头第一个偏移点,要记作左机头的起始点,双头组合机型
|
||
int firstRightOft = 0;//右机头第一个偏移点,要记作右机头的起始点,双头组合机型
|
||
|
||
while(i < datasize)
|
||
{
|
||
#if(0)
|
||
int stepSize = m_absData.size()/sizeof(DsAbsItem);
|
||
if(stepSize >= 2700)
|
||
{
|
||
int a = 0;
|
||
a = 1;
|
||
}
|
||
#endif
|
||
// 功能控制字
|
||
if (i >= datasize){break;}
|
||
ctrl = m_fileData.at(i++);
|
||
|
||
// 图元类型
|
||
if (i >= datasize){break;}
|
||
tmpls = m_fileData.at(i++);
|
||
|
||
// 附加控制字
|
||
if (i >= datasize){break;}
|
||
m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
m_fileData.at(i++);
|
||
|
||
if(ctrl == 0x00) // 结束
|
||
{
|
||
break;
|
||
}
|
||
|
||
//如果为剪线,直接向后加12(点个数1和xy坐标值,共12字节),且将剪线码添加到m_absData中,坐标与前一坐标值相同
|
||
if(ctrl == QUIX_CUTTER || ctrl == QUIX_SYNC_CUTTER || ctrl == QUIX_CUTTER_SEC)
|
||
{
|
||
i += 12;
|
||
if (i >= datasize){break;}
|
||
memcpy((char*)&absItem,m_absData.data()+m_absData.size()-sizeof(DsAbsItem),sizeof(DsAbsItem));
|
||
if(ctrl == QUIX_CUTTER)
|
||
{
|
||
ctrl = DATA_CUTTRD;
|
||
}
|
||
else if(ctrl == QUIX_CUTTER_SEC)
|
||
{
|
||
ctrl = DATA_CUTTER_SEC;
|
||
}
|
||
else if(ctrl == QUIX_SYNC_CUTTER)
|
||
{
|
||
ctrl = DATA_SYNC_CUTTER;
|
||
}
|
||
absItem.ctrl = ctrl;
|
||
m_absData.append((char*)&absItem,sizeof(DsAbsItem));
|
||
continue;
|
||
}
|
||
|
||
switch(tmpls)
|
||
{
|
||
case QUI_TYPE_LINE: // 直线
|
||
case QUI_TYPE_STEP: // 跨步
|
||
case QUI_TYPE_HSTEP: // 翻头跨步
|
||
{
|
||
//增加剪线
|
||
if(tmpls == QUI_TYPE_STEP || tmpls == QUI_TYPE_HSTEP)
|
||
{
|
||
if((u32)m_absData.size() >= sizeof(DsAbsItem))
|
||
{
|
||
memcpy((char*)&absItem,m_absData.data()+m_absData.size()-sizeof(DsAbsItem),sizeof(DsAbsItem));
|
||
absItem.ctrl = DATA_CUTTRD;
|
||
m_absData.append((char*)&absItem,sizeof(DsAbsItem));
|
||
}
|
||
}
|
||
|
||
// 点个数
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
lsdata = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
|
||
if(lsdata == 1)
|
||
{
|
||
//点x
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double x = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
deltx = x/factorx;
|
||
|
||
//点y
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double y = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
delty = y/factory;
|
||
|
||
//非起始点偏移,加到m_absData中
|
||
memset(&absItem,0,sizeof(DsAbsItem));
|
||
absItem.ax = deltx;
|
||
absItem.ay = delty;
|
||
//if((firstLeftOft == 1 && ctrl == QUIX_OFFSET) || (firstRightOft == 1 && ctrl == QUIX_OFFSET_SEC))
|
||
//if(ctrl == QUIX_OFFSET || ctrl == QUIX_OFFSET_SEC)
|
||
{
|
||
absItem.ctrl = ctrl;
|
||
m_absData.append((char*)&absItem,sizeof(DsAbsItem));
|
||
}
|
||
}
|
||
else if (lsdata > 1)
|
||
{
|
||
// 第一个点
|
||
//点x
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double x = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
deltx2 = x/factorx;
|
||
|
||
//点y
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double y = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
delty2 = y/factory;
|
||
|
||
for(idx = 1; idx < lsdata; idx++) // 其余的点
|
||
{
|
||
deltx1 = deltx2;
|
||
delty1 = delty2;
|
||
|
||
//点x
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
x = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
deltx2 = x/factorx;
|
||
|
||
//点y
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
y = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
delty2 = y/factory;
|
||
|
||
// 处理直线
|
||
calcLine(deltx1, delty1, deltx2, delty2, nmstep, m_absData, tmpls, ctrl);
|
||
}
|
||
|
||
if (idx != lsdata)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
|
||
//双头组合机型每个图元起始都会有一个偏移点
|
||
if(firstLeftOft == 0 && lsdata == 1 && ctrl == QUIX_OFFSET)
|
||
{
|
||
firstLeftOft = 1;
|
||
m_firstPointLeft.x = deltx;
|
||
m_firstPointLeft.y = delty;
|
||
m_firstPointLeft.ctrl = ctrl;
|
||
}
|
||
if(firstRightOft == 0 && lsdata == 1 && ctrl == QUIX_OFFSET_SEC)
|
||
{
|
||
firstRightOft = 1;
|
||
m_firstPointRight.x = deltx;
|
||
m_firstPointRight.y = delty;
|
||
m_firstPointRight.ctrl = ctrl;
|
||
}
|
||
|
||
break;
|
||
}
|
||
case QUI_TYPE_ARC: // 三点圆弧
|
||
{
|
||
// 点个数
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
lsdata = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
|
||
if(lsdata == 1)
|
||
{
|
||
//点x
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double x = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
deltx = x/factorx;
|
||
|
||
//点y
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double y = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
delty = y/factory;
|
||
|
||
//非起始点偏移,加到m_absData中
|
||
memset(&absItem,0,sizeof(DsAbsItem));
|
||
absItem.ax = deltx;
|
||
absItem.ay = delty;
|
||
//if((firstLeftOft == 1 && ctrl == QUIX_OFFSET) || (firstRightOft == 1 && ctrl == QUIX_OFFSET_SEC))
|
||
//if(ctrl == QUIX_OFFSET || ctrl == QUIX_OFFSET_SEC)
|
||
{
|
||
absItem.ctrl = ctrl;
|
||
m_absData.append((char*)&absItem,sizeof(DsAbsItem));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(lsdata != 3)
|
||
{
|
||
break;
|
||
}
|
||
|
||
for (idx = 0; idx < lsdata; idx++)
|
||
{
|
||
//点x
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double x = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
threex[idx] = x/factorx;
|
||
|
||
//点y
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double y = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
threey[idx] = y/factory;
|
||
}
|
||
|
||
//添加圆弧第一个点
|
||
memset(&absItem,0,sizeof(DsAbsItem));
|
||
absItem.ax = threex[0];
|
||
absItem.ay = threey[0];
|
||
absItem.ctrl = ctrl;
|
||
m_absData.append((char*)&absItem,sizeof(DsAbsItem));
|
||
calcCurve(threex, threey, nmstep, m_absData, ctrl);
|
||
|
||
if (idx != 3)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
|
||
//双头组合机型每个图元起始都会有一个偏移点
|
||
if(firstLeftOft == 0 && lsdata == 1 && ctrl == QUIX_OFFSET)
|
||
{
|
||
firstLeftOft = 1;
|
||
m_firstPointLeft.x = deltx;
|
||
m_firstPointLeft.y = delty;
|
||
m_firstPointLeft.ctrl = ctrl;
|
||
}
|
||
if(firstRightOft == 0 && lsdata == 1 && ctrl == QUIX_OFFSET_SEC)
|
||
{
|
||
firstRightOft = 1;
|
||
m_firstPointRight.x = deltx;
|
||
m_firstPointRight.y = delty;
|
||
m_firstPointRight.ctrl = ctrl;
|
||
}
|
||
break;
|
||
}
|
||
case QUI_TYPE_BES: // 贝塞尔曲线
|
||
{
|
||
// 点个数
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
lsdata = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
if(lsdata == 1)
|
||
{
|
||
//点x
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double x = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
deltx = x/factorx;
|
||
|
||
//点y
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double y = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
delty = y/factory;
|
||
|
||
//非起始点偏移,加到m_absData中
|
||
memset(&absItem,0,sizeof(DsAbsItem));
|
||
absItem.ax = deltx;
|
||
absItem.ay = delty;
|
||
//if((firstLeftOft == 1 && ctrl == QUIX_OFFSET) || (firstRightOft == 1 && ctrl == QUIX_OFFSET_SEC))
|
||
//if(ctrl == QUIX_OFFSET || ctrl == QUIX_OFFSET_SEC)
|
||
{
|
||
absItem.ctrl = ctrl;
|
||
m_absData.append((char*)&absItem,sizeof(DsAbsItem));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(lsdata != 4)
|
||
{
|
||
break;
|
||
}
|
||
|
||
for (idx = 0; idx < lsdata; idx++)
|
||
{
|
||
//点x
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double x = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
threex[idx] = x/factorx;
|
||
|
||
//点y
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double y = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
threey[idx] = y/factory;
|
||
}
|
||
|
||
// 处理贝塞尔曲线
|
||
QList<QPointF> splineListXY;//拟合后的点
|
||
splineListXY.clear();
|
||
getBezierPointList(threex, threey, nmstep,splineListXY);
|
||
|
||
QList<QPointF> splitListXY;//均分后的点
|
||
splitListXY.clear();
|
||
if(splineListXY.size() > 0)
|
||
{
|
||
getCurvePointFillLine(splineListXY,nmstep,splitListXY,0,OBJECT_STITCHLEN_NEW_SAMALL);
|
||
}
|
||
|
||
//添加贝塞尔曲线数据点
|
||
for(int i = 0; i < splitListXY.size(); i++)
|
||
{
|
||
memset(&absItem,0,sizeof(DsAbsItem));
|
||
|
||
deltx1 = splitListXY[i].x();
|
||
delty1 = splitListXY[i].y();
|
||
|
||
absItem.ctrl = ctrl;
|
||
absItem.ax = deltx1;
|
||
absItem.ay = delty1;
|
||
m_absData.append((char*)&absItem,sizeof(DsAbsItem));
|
||
}
|
||
//calcBezier(threex, threey, nmstep, m_absData);
|
||
if (idx != 4)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
|
||
//双头组合机型每个图元起始都会有一个偏移点
|
||
if(firstLeftOft == 0 && lsdata == 1 && ctrl == QUIX_OFFSET)
|
||
{
|
||
firstLeftOft = 1;
|
||
m_firstPointLeft.x = deltx;
|
||
m_firstPointLeft.y = delty;
|
||
m_firstPointLeft.ctrl = ctrl;
|
||
}
|
||
if(firstRightOft == 0 && lsdata == 1 && ctrl == QUIX_OFFSET_SEC)
|
||
{
|
||
firstRightOft = 1;
|
||
m_firstPointRight.x = deltx;
|
||
m_firstPointRight.y = delty;
|
||
m_firstPointRight.ctrl = ctrl;
|
||
}
|
||
|
||
break;
|
||
}
|
||
case QUI_TYPE_SPLINE: // 样条
|
||
{
|
||
QList<QPointF> quiListPoint;//样条拟合前的点集合
|
||
quiListPoint.clear();
|
||
|
||
// 点个数
|
||
if (i >= datasize){break;}
|
||
unsigned char c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
unsigned char c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
unsigned char c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
unsigned char c4 = m_fileData.at(i++);
|
||
lsdata = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
|
||
if(lsdata == 1)
|
||
{
|
||
//点x
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double x = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
deltx = x/factorx;
|
||
|
||
//点y
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double y = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
delty = y/factory;
|
||
|
||
//非起始点偏移,加到m_absData中
|
||
memset(&absItem,0,sizeof(DsAbsItem));
|
||
absItem.ax = deltx;
|
||
absItem.ay = delty;
|
||
//if((firstLeftOft == 1 && ctrl == QUIX_OFFSET) || (firstRightOft == 1 && ctrl == QUIX_OFFSET_SEC))
|
||
//if(ctrl == QUIX_OFFSET || ctrl == QUIX_OFFSET_SEC)
|
||
{
|
||
absItem.ctrl = ctrl;
|
||
m_absData.append((char*)&absItem,sizeof(DsAbsItem));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
for(idx = 0; idx < lsdata; idx++) // 点
|
||
{
|
||
//点x
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double x = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
deltx1 = x/factorx;
|
||
|
||
//点y
|
||
if (i >= datasize){break;}
|
||
c1 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c2 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c3 = m_fileData.at(i++);
|
||
if (i >= datasize){break;}
|
||
c4 = m_fileData.at(i++);
|
||
double y = (c4 << 24) + (c3 << 16) + (c2 << 8) + (c1);
|
||
delty1 = y/factory;
|
||
|
||
QPointF point(deltx1,delty1);
|
||
quiListPoint.append(point);
|
||
}
|
||
|
||
QList<QPointF> splineListXY;//拟合后的点
|
||
splineListXY.clear();
|
||
if(quiListPoint.size() <= 0)
|
||
{
|
||
break;
|
||
}
|
||
getSplineNew(quiListPoint,splineListXY);
|
||
|
||
// 均分
|
||
QList<QPointF> splitListXY;//均分后的点
|
||
splitListXY.clear();
|
||
if(splineListXY.size() > 0)
|
||
{
|
||
getCurvePointFillLine(splineListXY,nmstep,splitListXY,0,OBJECT_STITCHLEN_NEW_SAMALL);
|
||
}
|
||
|
||
//添加样条曲线数据点
|
||
for(int i = 0; i < splitListXY.size(); i++)
|
||
{
|
||
memset(&absItem,0,sizeof(DsAbsItem));
|
||
|
||
deltx1 = splitListXY[i].x();
|
||
delty1 = splitListXY[i].y();
|
||
|
||
absItem.ctrl = ctrl;
|
||
absItem.ax = deltx1;
|
||
absItem.ay = delty1;
|
||
m_absData.append((char*)&absItem,sizeof(DsAbsItem));
|
||
}
|
||
|
||
if(idx != lsdata)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
|
||
//双头组合机型每个图元起始都会有一个偏移点
|
||
if(firstLeftOft == 0 && lsdata == 1 && ctrl == QUIX_OFFSET)
|
||
{
|
||
firstLeftOft = 1;
|
||
m_firstPointLeft.x = deltx;
|
||
m_firstPointLeft.y = delty;
|
||
m_firstPointLeft.ctrl = ctrl;
|
||
}
|
||
if(firstRightOft == 0 && lsdata == 1 && ctrl == QUIX_OFFSET_SEC)
|
||
{
|
||
firstRightOft = 1;
|
||
m_firstPointRight.x = deltx;
|
||
m_firstPointRight.y = delty;
|
||
m_firstPointRight.ctrl = ctrl;
|
||
}
|
||
break;
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
//生成绝对坐标数据的文件头
|
||
DataDs16FileHead dhead;
|
||
memset(&dhead, 0, sizeof(DataDs16FileHead));
|
||
|
||
int stepSize = m_absData.size()/sizeof(DsAbsItem);
|
||
if(stepSize <= 0)
|
||
{
|
||
return;
|
||
}
|
||
|
||
DsAbsItem * absDataPtr = (DsAbsItem *)(m_absData.data());
|
||
double firstX = absDataPtr->ax;
|
||
double firstY = absDataPtr->ay;
|
||
m_firstAbsPoint.setX(firstX);
|
||
m_firstAbsPoint.setY(firstY);
|
||
|
||
double minX, maxX, minY, maxY;
|
||
minX = S32_MAX;
|
||
maxX = S32_MIN;
|
||
minY = S32_MAX;
|
||
maxY = S32_MIN;
|
||
|
||
int dataDirY = QUIX_DATADIRY*-1;
|
||
|
||
double prex,prey,curx,cury,dx,dy,ar;
|
||
prex = prey = curx = cury = dx = dy = ar = 0;
|
||
double curx2,cury2;
|
||
curx2 = cury2 = 0;
|
||
|
||
double firOftX = 0;
|
||
double firOftY = 0;
|
||
|
||
double secOftX = m_firstPointRight.x - m_firstPointLeft.x;
|
||
double secOftY = m_firstPointRight.y - m_firstPointLeft.y;
|
||
|
||
//将absDataPtr的每个点都减去起始点,并求最大最小值(包括左机头和右机头),将起点看作零
|
||
for (int i = 0; i < stepSize; i++)
|
||
{
|
||
ctrl = absDataPtr->ctrl;
|
||
|
||
#if(0)
|
||
if(ctrl == DATA_CUTTRD || ctrl == DATA_CUTTER_SEC || ctrl == DATA_SYNC_CUTTER || i >= 25)
|
||
{
|
||
int a = 0;
|
||
a = 1;
|
||
}
|
||
#endif
|
||
|
||
absDataPtr->ax -= firstX;
|
||
absDataPtr->ay -= firstY;
|
||
|
||
absDataPtr->ax *= QUIX_DATADIRX;
|
||
absDataPtr->ay *= dataDirY;
|
||
|
||
if(ctrl == QUIX_OFFSET)
|
||
{
|
||
firOftX = absDataPtr->ax;
|
||
firOftY = absDataPtr->ay;
|
||
}
|
||
|
||
if(ctrl == QUIX_OFFSET_SEC)
|
||
{
|
||
secOftX = absDataPtr->ax - firOftX;
|
||
secOftY = absDataPtr->ay - firOftY;
|
||
}
|
||
|
||
curx = absDataPtr->ax;
|
||
cury = absDataPtr->ay;
|
||
|
||
if(ctrl == QUIX_OFFSET_SEC || ctrl == QUIX_SEWING_SEC)
|
||
{
|
||
curx2 = absDataPtr->ax;
|
||
cury2 = absDataPtr->ay;
|
||
}
|
||
else
|
||
{
|
||
if(ctrl != QUIX_OFFSET && ctrl != QUIX_SEWING)
|
||
{
|
||
curx2 = curx + secOftX;
|
||
cury2 = cury - secOftY;//因为y方向取反了,所以这里用减法,如果不取反,应该用加法
|
||
}
|
||
}
|
||
|
||
if(ctrl == QUIX_MIRROR_SEC)
|
||
{
|
||
curx2 = secOftX + (firOftX - curx) + firOftX;
|
||
}
|
||
|
||
if(curx > maxX)
|
||
{
|
||
maxX = curx;
|
||
}
|
||
if(curx < minX)
|
||
{
|
||
minX = curx;
|
||
}
|
||
|
||
if(cury > maxY)
|
||
{
|
||
maxY = cury;
|
||
}
|
||
if(cury < minY)
|
||
{
|
||
minY = cury;
|
||
}
|
||
|
||
if(curx2 > maxX)
|
||
{
|
||
maxX = curx2;
|
||
}
|
||
if(curx2 < minX)
|
||
{
|
||
minX = curx2;
|
||
}
|
||
|
||
if(cury2 > maxY)
|
||
{
|
||
maxY = cury2;
|
||
}
|
||
if(cury2 < minY)
|
||
{
|
||
minY = cury2;
|
||
}
|
||
|
||
absDataPtr++;
|
||
}
|
||
|
||
absDataPtr = (DsAbsItem *)(m_absData.data());
|
||
double btar = atan2(m_firstPointLeft.y,m_firstPointLeft.x);
|
||
double begR = (btar*10000+0.5*(btar>0?1:-1));
|
||
|
||
btar = atan2(m_firstPointRight.y,m_firstPointRight.x);
|
||
double begR2 = (btar*10000+0.5*(btar>0?1:-1));
|
||
|
||
prex = 0;//等于起始点,这里以左机头计算角度,因为左右机头轨迹相同
|
||
prey = 0;
|
||
|
||
//缩放并求dr
|
||
m_maxX = maxX;
|
||
m_minX = minX;
|
||
m_maxY = maxY;
|
||
m_minY = minY;
|
||
|
||
unitmuti = getMutiUnit(0);
|
||
unitmuti = 1;
|
||
|
||
double scanx = head->scanX * unitmuti; // 宽度
|
||
double scany = head->scanY * unitmuti; // 长度
|
||
|
||
if (scanx < 1)
|
||
{
|
||
scanx = m_maxX-m_minX;
|
||
}
|
||
if (scany < 1)
|
||
{
|
||
scany = m_maxY-m_minY;
|
||
}
|
||
|
||
// 计算缩放系数
|
||
factorx = (double)((m_maxX-m_minX) / (scanx));
|
||
factory = (double)((m_maxY-m_minY) / (scany));
|
||
|
||
if(factorx == 0){factorx = 1;}
|
||
if(factory == 0){factory = 1;}
|
||
|
||
// if(flag == 1)//双头组合机型注释掉
|
||
// {
|
||
// factorx = 1;
|
||
// factory = 1;
|
||
// }
|
||
|
||
for (int i = 0; i < stepSize; i++)
|
||
{
|
||
absDataPtr->ax /= factorx;
|
||
absDataPtr->ay /= factory;
|
||
|
||
curx = absDataPtr->ax;
|
||
cury = absDataPtr->ay;
|
||
|
||
dx = curx - prex;
|
||
dy = cury - prey;
|
||
|
||
double tar = atan2(dy,dx);
|
||
ar = (tar*10000+0.5*(tar>0?1:-1));
|
||
absDataPtr->ar = ar;
|
||
|
||
prex = curx;
|
||
prey = cury;
|
||
|
||
absDataPtr++;
|
||
}
|
||
|
||
//增加结束码
|
||
if((u32)m_absData.size() >= sizeof(DsAbsItem))
|
||
{
|
||
DsAbsItem absItem;
|
||
memset(&absItem,0,sizeof(DsAbsItem));
|
||
memcpy((char*)&absItem,m_absData.data()+m_absData.size()-sizeof(DsAbsItem),sizeof(DsAbsItem));
|
||
absItem.ctrl = DATA_END;
|
||
m_absData.append((char*)&absItem,sizeof(DsAbsItem));
|
||
stepSize++;
|
||
}
|
||
|
||
maxX /= factorx;
|
||
maxY /= factory;
|
||
minX /= factorx;
|
||
minY /= factory;
|
||
|
||
m_maxX = maxX;
|
||
m_minX = minX;
|
||
m_maxY = maxY;
|
||
m_minY = minY;
|
||
|
||
m_firstPointLeft.x /= factorx;
|
||
m_firstPointLeft.y /= factory;
|
||
m_firstPointRight.x /= factorx;
|
||
m_firstPointRight.y /= factory;
|
||
|
||
//生成文件头
|
||
dhead.maxX = maxX;
|
||
dhead.maxY = maxY;
|
||
dhead.minX = minX;
|
||
dhead.minY = minY;
|
||
dhead.beginX = m_firstPointLeft.x;
|
||
dhead.beginY = m_firstPointLeft.y;
|
||
dhead.beginR = begR;
|
||
dhead.beginX2 = m_firstPointRight.x;
|
||
dhead.beginY2 = m_firstPointRight.y;
|
||
dhead.beginR2 = begR2;
|
||
dhead.anchorX = 0;
|
||
dhead.anchorY = 0;
|
||
dhead.itemNums = stepSize;
|
||
dhead.dataSize = stepSize*sizeof(DsAbsItem); // 数据字节数
|
||
dhead.bytesPerItem = sizeof(DsAbsItem); // 每项占的字节数
|
||
dhead.dataChecksum = calcCheckSum32((u8 *)(m_absData.data()) , dhead.dataSize);; // 数据累加校验和
|
||
dhead.checkCrc = calcCrc16((u8 *)(&dhead), HEAD_FIX_INFO_LEN); // 前面6个字段的CRC校验,(6个字段分别为:文件名称,字节数,项个数,每项字节数,每块字节数,数据累加和的CRC校验值)
|
||
dhead.fileid = dhead.checkCrc;
|
||
m_absData.insert(0,(char*)&dhead,sizeof(DataDs16FileHead));
|
||
}
|
||
|
||
void DataFileQuix::writeFileLL(int left, int front, int startX, int startY)
|
||
{
|
||
QuixFileHead *pQuixHead = getQuixHead();
|
||
|
||
if(left < 0)
|
||
{
|
||
left = 0;
|
||
}
|
||
if(front < 0)
|
||
{
|
||
front = 0;
|
||
}
|
||
|
||
pQuixHead->left = left;
|
||
pQuixHead->front = front;
|
||
|
||
pQuixHead->startX = startX;
|
||
pQuixHead->startY = startY;
|
||
|
||
QFile wfile(m_fileFullPathName);
|
||
if(!wfile.open(QIODevice::WriteOnly | QIODevice::Truncate))
|
||
{
|
||
qDebug() << "open file fail when read, path =" << m_fileFullPathName;
|
||
return;
|
||
}
|
||
|
||
wfile.write(m_fileData);
|
||
wfile.close();
|
||
|
||
#ifdef Q_OS_LINUX
|
||
system("sync");
|
||
#endif
|
||
}
|
||
|
||
int DataFileQuix::getStitchNums()
|
||
{
|
||
if(m_absData.size() <= 0)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
DataDs16FileHead * pHead = (DataDs16FileHead *)((m_absData.data()));
|
||
return pHead->itemNums;
|
||
}
|
||
|
||
int DataFileQuix::getDatWidth()
|
||
{
|
||
if(m_absData.size() <= 0)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
DataDs16FileHead * pHead = (DataDs16FileHead *)((m_absData.data()));
|
||
return (pHead->maxX - pHead->minX);
|
||
}
|
||
|
||
int DataFileQuix::getDatHeight()
|
||
{
|
||
if(m_absData.size() <= 0)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
DataDs16FileHead * pHead = (DataDs16FileHead *)((m_absData.data()));
|
||
return (pHead->maxY - pHead->minY);
|
||
}
|
||
|
||
int DataFileQuix::getMaxX()
|
||
{
|
||
if(m_absData.size() <= 0)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
DataDs16FileHead * pHead = (DataDs16FileHead *)((m_absData.data()));
|
||
return pHead->maxX;
|
||
}
|
||
|
||
int DataFileQuix::getMinX()
|
||
{
|
||
if(m_absData.size() <= 0)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
DataDs16FileHead * pHead = (DataDs16FileHead *)((m_absData.data()));
|
||
return pHead->minX;
|
||
}
|
||
|
||
int DataFileQuix::getMaxY()
|
||
{
|
||
if(m_absData.size() <= 0)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
DataDs16FileHead * pHead = (DataDs16FileHead *)((m_absData.data()));
|
||
return pHead->maxY;
|
||
}
|
||
|
||
int DataFileQuix::getMinY()
|
||
{
|
||
if(m_absData.size() <= 0)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
DataDs16FileHead * pHead = (DataDs16FileHead *)((m_absData.data()));
|
||
return pHead->minY;
|
||
}
|