PunchHMI/mctype/mainwidgetfunction.cpp
huahaiyan b9438b59c4 20240219
1、修改配置文件名称;
2、修改花样文件夹路径,并删除fcg文件;
3、合并任晴的代码;
2024-02-19 11:33:47 +08:00

5510 lines
174 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "mainwidgetfunction.h"
MainWidgetFunction::MainWidgetFunction(QObject *parent) :
QObject(parent),
m_pPromptDlg(NULL),
m_pSystemManageDlg(NULL),
m_pBrokenLineDialog(NULL)
{
initialize();
initializeLotData();//初始化物联网数据
m_pPromptDlg = new PromptDialog();
m_pPromptDlg->hide();
connect(m_pPromptDlg, SIGNAL(siUpdataCancel()),g_pMachine, SLOT(breakFileTrans()));
connect(g_pMachine, SIGNAL(siTransProgress(u8,int,int)),this, SLOT(slotTransProgress(u8,int,int)));//升级主控进度条
// connect(g_pLotMachine,SIGNAL(siConnectToMqtt()),this,SLOT(slotSendJsonToMqtt()));
connect(g_pLotMachine,SIGNAL(siRunLotDataAction(QString)),this,SLOT(slotRunLotDataAction(QString)));
//机器信息改变
connect(g_pMachine, SIGNAL(siMcInfoChange()), this, SLOT(slotMCInfoChange()));
//接收物联数据
//connect(g_pMachine, SIGNAL(siReceiveLotData()), this, SLOT(slotReceiveLotData()));
m_pSystemManageDlg = new SystemManageDialog();
connect(m_pSystemManageDlg,SIGNAL(siClearProductStatis()),this,SLOT(slotClearProductStatis()));
connect(m_pSystemManageDlg,SIGNAL(siCsvExport(int)),this,SLOT(slotCsvExport(int)));
connect(m_pSystemManageDlg,SIGNAL(siCsvChangeErro( )),this,SLOT(slotJournalError()));
connect(m_pSystemManageDlg,SIGNAL(siCsvChangeBrea( )),this,SLOT(slotJournalBreakage()));
connect(m_pSystemManageDlg,SIGNAL(siClearJournal()),this,SLOT(slotClearJournal()));
connect(m_pSystemManageDlg,SIGNAL(siRefreshWifiList()),this,SLOT(slotRefreshWifiList()));
connect(m_pSystemManageDlg,SIGNAL(siSetDynamicIP(QString)),this,SLOT(slotSetDynamicIP(QString)));
connect(m_pSystemManageDlg,SIGNAL(siSetStaticIP(QString,QString,QString)),this,SLOT(slotSetStaticIP(QString,QString,QString)));
m_pSystemManageDlg->hide();
m_pBrokenLineDialog = new BrokenLineDialog();
m_pBrokenLineDialog->hide();
m_pTipsTimer = new QTimer(this);
m_pTipsTimer->setInterval(14400000);//设置定时器时间间隔 4小时
connect(m_pTipsTimer, SIGNAL(timeout()), this, SLOT(onTipsTimer()));
// 测试物联网用
// connect(&timer, SIGNAL(timeout()), this, SLOT(slotReceiveLotData()));
// timer.setInterval(1000);
// timer.start();
#if(IFOPENGATEWAY)
//物联网
m_pLotTimer = new QTimer(this);
connect(m_pLotTimer, SIGNAL(timeout()), this, SLOT(slotSendLotData()));
m_pLotTimer->setInterval(5000);
m_pLotTimer->start();
#endif
}
MainWidgetFunction::~MainWidgetFunction()
{
if(m_pPromptDlg != NULL)
{
delete m_pPromptDlg;
}
if(m_pSystemManageDlg != NULL)
{
delete m_pSystemManageDlg;
}
if(m_pBrokenLineDialog != NULL)
{
delete m_pBrokenLineDialog;
}
}
void MainWidgetFunction::initialize()
{
//读取配置文件,初始化机头断线次数
memset(&m_headBreakLine,0,sizeof(HeadBreakLine));
for(u16 i = 0; i < sizeof(m_headBreakLine.headBreakLineNum)/sizeof(s32); i++)
//for(u16 i = 0; i < sizeof(HeadBreakLine)/sizeof(s32); i++)
{
int breakLineNum = 0;
breakLineNum = g_pSettings->readFromIniFile("HeadBreakLineNum/head"+QString::number(i+1)).toInt();
m_headBreakLine.headBreakLineNum[i] = breakLineNum;
//xcy 0314 机头针位断线
for(int j = 0; j < 15; j++)
{
int needelBreakLineNum = 0;
needelBreakLineNum = g_pSettings->readFromIniFile("Head" + QString::number(i+1) + "NeedleBreakLine/needle" + QString::number(j+1)).toInt();
m_headBreakLine.headNeedleBreakLine[i][j] = needelBreakLineNum;
//qDebug() <<"m_headBreakLine.headNeedleBreakLine[" << i << "]["<< j << "]=" <<m_headBreakLine.headNeedleBreakLine[i][j] ;
}
}
memset(&m_mcStatus,0,sizeof(MCStatus));
m_curFileID = 1;// 当前文件ID
m_beginX = 0;
m_beginY = 0;
m_filePath.clear();
m_fileName.clear();
m_getScore = 0;
m_totalScore = 0;
initializeLotInfo();
}
void MainWidgetFunction::initializeLotInfo()
{
QDir apppath(qApp->applicationDirPath());
QString iniPath = apppath.path() + apppath.separator() + "config.ini";
QSettings setting(iniPath, QSettings::IniFormat); //QSettings能记录一些程序中的信息下次再打开时可以读取出来
m_getScore = setting.value("Progress/getScore").toInt();
QString path = apppath.path() + apppath.separator() + CSV_PROGRESS;
QFile file(path);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << "Open CSV file failed!";
return;
}
QStringList strlist;
strlist.clear();
QTextStream out(&file);
out.setCodec("GB2312"); //支持读取中文信息
//遍历行
for(int i = 0; !out.atEnd(); i++)
{
QString strLine = out.readLine();
if(strLine.size() <= 0)
{
continue;
}
m_csvFileStrList.append(strLine);
strlist = strLine.split(",", QString::SkipEmptyParts); //根据","分隔开每行的列
if(i > 0) //第一行不执行操作
{
if (strlist.size() > COLUMN_SCORE)
{
int score = strlist.at(COLUMN_SCORE).toInt();
m_totalScore += score;
}
}
}
file.close();//关闭文件
}
//初始化物联网数据
void MainWidgetFunction::initializeLotData()
{
memset(&m_mcLotData,0,sizeof(McLotData));
memset(&m_HMILotData,0,sizeof(HMILotData));
QString verStr = getVersionStr();
memcpy(m_HMILotData.HMIVerStr, verStr.data(), verStr.length()); // 版本号
u32 rackNum = g_pSettings->readFromIniFile("IOT/rackNumber").toInt();//机架号
m_HMILotData.machineNumber = rackNum; // 机架号
u16 dProgress = g_pSettings->readFromIniFile("IOT/debugProgress").toInt();//调试进度
m_HMILotData.debugProgress = dProgress; //调试进度
QString deliveryTime = g_pSettings->readFromIniFile("IOT/deliveryTime").toString();//工厂预计交货时间
QByteArray arr = deliveryTime.toLocal8Bit();
memcpy(m_HMILotData.deliveryTime, arr.data(), arr.size()); //交货日期
//电机总数-先固定写为4个如果后续变动较大可把电机个数写为全局变量或从其他cpp中传参
m_HMILotData.motorNum = 4;
QString fileName = m_fileName;
memcpy(m_HMILotData.fileName, fileName.data(), fileName.length()); // 文件名称
}
//优盘检测
QString MainWidgetFunction::detectUsb()
{
QString usbPath = "";
#ifdef Q_OS_LINUX
QDir dir(LINUXUSBPATH);
if(!dir.exists())
{
usbPath = "";
}
else
{
usbPath = LINUXUSBPATH;
}
#endif
#ifdef Q_OS_WIN
QFileInfoList list = QDir::drives();
for(int i = 0; i<list.count(); i++)
{
UINT ret = GetDriveType((WCHAR *) list.at(i).filePath().utf16());
if(ret == DRIVE_REMOVABLE)
{
usbPath = list.at(i).filePath();
break;
}
}
#endif
return usbPath;
}
s16 MainWidgetFunction::detectWifiConnect()
{
s16 value = -1;
#ifdef Q_OS_LINUX
QProcess cmd;
QString cmdStr;
cmdStr.clear();
QString strCmdOut;
strCmdOut.clear();
QStringList lineStrList;
lineStrList.clear();
cmdStr = "wpa_cli -i wlan0 status";//查询wifi连接状态
cmd.start(cmdStr);
cmd.waitForStarted();
cmd.waitForFinished();
strCmdOut=QString::fromLocal8Bit(cmd.readAllStandardOutput());
//qDebug()<<"strCmdOut"<<strCmdOut;
lineStrList = strCmdOut.split("\n", QString::SkipEmptyParts); //换行符
//qDebug()<<"lineStrList.size()"<<lineStrList.size();
for(int i = 0; i < lineStrList.size(); i++)
{
QStringList lineStr = lineStrList[i].split("=", QString::SkipEmptyParts);
if(lineStr.size() >= 2)
{
QString str1 = lineStr[0];
//qDebug()<<lineStrList[i];
if(str1.indexOf("wpa_state") != -1)
{
QString str2 = lineStr[1];
//qDebug()<<str2;
if(str2.indexOf("COMPLETED") == -1)
{
cmd.close();
value = -1;
}
}
if(str1.indexOf("ip_address") != -1)
{
cmd.close();
value = 1;
break;
}
}
}
cmd.close();
#endif
return value;
}
void MainWidgetFunction::systemUpgrade(int type, u8 protocol, u8 nodeid, u8 nodeType)
{
QString usbPath = detectUsb();
if(usbPath.length() <= 0)
{
//优盘不存在
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("USB flash drive is not detected!");//未检测到优盘!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
QDir apppath(qApp->applicationDirPath());
QString targetDir = apppath.absolutePath() + apppath.separator();
QDir dir (usbPath);
dir.setFilter(QDir::Files | QDir::NoSymLinks); // 设置类型过滤器,只为文件格式
QFileInfoList fileList = dir.entryInfoList();
if(type == HMI_UPDATA)//界面升级
{
qDebug()<<"update 1";
//界面文件、语言文件、RCC资源文件、打包的AUT文件
for (int var = 0; var < fileList.size(); var++)
{
#ifdef Q_OS_WIN
if((fileList.at(var).fileName().toUpper().indexOf(APPNAME) != -1 &&
fileList.at(var).suffix().toUpper() == "EXE") ||
fileList.at(var).fileName().toUpper().indexOf(".QM") != -1 ||
fileList.at(var).fileName().toUpper().indexOf(".RCC") != -1 ||
fileList.at(var).fileName().toUpper().indexOf(".AUT") != -1)
{
m_pSystemManageDlg->addItem(fileList.at(var).fileName());
}
#endif
#ifdef Q_OS_LINUX
if((fileList.at(var).fileName().toUpper().indexOf(APPNAME) != -1 &&
fileList.at(var).suffix().toUpper().length() == 0) ||
fileList.at(var).fileName().toUpper().indexOf(".QM") != -1 ||
fileList.at(var).fileName().toUpper().indexOf(".RCC") != -1 ||
fileList.at(var).fileName().toUpper().indexOf(".AUT") != -1)
{
m_pSystemManageDlg->addItem(fileList.at(var).fileName());
}
#endif
}
qDebug()<<"update 2";
}
else if(type == MC_UPDATA)//主控升级
{
for (int var = 0; var < fileList.size(); var++)
{
if( fileList.at(var).suffix().toUpper() == "RNPU")
{
m_pSystemManageDlg->addItem(fileList.at(var).fileName());
}
}
qDebug()<<"update 3";
}
else if(type == EXBOARD_UPDATA)//外围板升级
{
for (int var = 0; var < fileList.size(); var++)
{
if( fileList.at(var).suffix().toUpper() == "RNPU")
{
m_pSystemManageDlg->addItem(fileList.at(var).fileName());
}
}
qDebug()<<"update 5";
}
else if(type == PARA_IMPORT ||
type == WKPARA_IMPORT)//参数导入或工作参数导入
{
for (int var = 0; var < fileList.size(); var++)
{
if( fileList.at(var).suffix().toUpper() == "PARADAT")
{
m_pSystemManageDlg->addItem(fileList.at(var).fileName());
}
}
qDebug()<<"update 4";
}
else if(type == FRAMEPARA_IMPORT)//动框参数导入
{
for (int var = 0; var < fileList.size(); var++)
{
if( fileList.at(var).suffix().toUpper() == "FRAMEPARADAT")
{
m_pSystemManageDlg->addItem(fileList.at(var).fileName());
}
}
}
//点击了确认按钮
if(m_pSystemManageDlg->exec(type) == 1)
{
QString fileName = m_pSystemManageDlg->getCurFile();
if(type == HMI_UPDATA)//界面升级
{
QString sPath,tPath;
#ifdef Q_OS_WIN
if(fileName.toUpper().indexOf(APPNAME) != -1 &&
fileName.toUpper().indexOf(".EXE") != -1)
{
sPath = usbPath + fileName;
tPath = targetDir + WIN_APPNAME;
qDebug()<<"HMI Update";
qDebug()<<"sPath"<<sPath;
qDebug()<<"tPath"<<tPath;
QFile::remove(tPath);
QFile::copy( sPath , tPath);
qApp->exit();
}
#endif
#ifdef Q_OS_LINUX
if(fileName.toUpper().indexOf(APPNAME) != -1 &&
fileName.toUpper().indexOf(".EXE") == -1 &&
fileName.toUpper().indexOf(".AUT") == -1)//非aut打包文件
{
sPath = usbPath + fileName;
tPath = targetDir + LINUX_APPNAME;
qDebug()<<"HMI Update";
qDebug()<<"sPath"<<sPath;
qDebug()<<"tPath"<<tPath;
QFile::remove(tPath);
system("sync");
QFile::copy( sPath , tPath);
system("sync");
system("reboot");
qDebug()<<"reboot";
}
#endif
else if(fileName.toUpper().indexOf(".QM") != -1 )
{
//增加语言包选择日期
QString tPath;// 目标文件
if(fileName.toUpper().indexOf("LAG-ZH") != -1 ) //中文语言包 //XPlatForm-SEW-RP-LAG-ZH-V220511.qm
{
tPath = targetDir + "chinese.qm"; // 目标文件
}
else if(fileName.toUpper().indexOf("LAG-EN") != -1 ) // 英语
{
tPath = targetDir + "english.qm";
}
else if(fileName.toUpper().indexOf("LAG-ES") != -1 ) // 西班牙语
{
tPath = targetDir + "spanish.qm";
}
else if(fileName.toUpper().indexOf("LAG-TK") != -1 ) // 土耳其语
{
tPath = targetDir + "turkey.qm";
}
else if(fileName.toUpper().indexOf("LAG-RQ") != -1 ) // 葡萄牙语
{
tPath = targetDir + "portugal.qm";
}
else
{
tPath = targetDir + fileName ;
}
QString sPath = usbPath + fileName ;//源文件
QString tPath1 = targetDir + "language.qm";
qDebug()<<"Language Update";
qDebug()<<"sPath"<<sPath; //sPath "F:/chinese.qm"
qDebug()<<"tPath"<<tPath; //tPath "D:/work/workQT/XPlatform/Windows/debug\\chinese.qm"
qDebug()<<"tPath1"<<tPath1; //tPath1 "D:/work/workQT/XPlatform/Windows/debug\\language.qm"
QFile::remove(tPath);
QFile::remove(tPath1);
#ifdef Q_OS_LINUX
system("sync");
#endif
QFile::copy(sPath , tPath);//sPath复制到tPath
QFile::copy(sPath , tPath1);
#ifdef Q_OS_WIN
qApp->exit();
#endif
#ifdef Q_OS_LINUX
system("sync");
system("reboot");
#endif
}
else if(fileName.toUpper().indexOf(".RCC") != -1 )
{
QString sPath = usbPath + fileName ;
QString tPath = targetDir + "nxcui.rcc";
qDebug()<<"RCC Update";
qDebug()<<"sPath"<<sPath;
qDebug()<<"tPath"<<tPath;
QFile::remove(tPath );
#ifdef Q_OS_LINUX
system("sync");
#endif
QFile::copy(sPath , tPath);
#ifdef Q_OS_WIN
qApp->exit();
#endif
#ifdef Q_OS_LINUX
system("sync");
system("reboot");
#endif
}
else if(fileName.toUpper().indexOf(".AUT") != -1)//界面打包文件(包括升级文件、语言包、RCC等)
{
QString strFile = usbPath + fileName;
QFile file(strFile);
file.open(QIODevice::ReadOnly);
QByteArray AllData = file.readAll();
HMIFileHead *fhead = (HMIFileHead*)(AllData.data());
int filenum = fhead->fileNum;
int bSize = 0;
for(int j = 0; j < filenum; j++)
{
int cSize = j*sizeof(HMIItemFileHead) + sizeof(HMIFileHead) + bSize;
HMIItemFileHead *ahead;
ahead = (HMIItemFileHead*)(AllData.data() + cSize);
QString fName = ahead->fileName;
int fileSize = ahead->fileSize;
if(fileSize <= 0)
{
return;
}
int sDataCheck = ahead->dataCheck;
cSize = cSize + sizeof(HMIItemFileHead);
QByteArray buf = AllData.mid(cSize,fileSize);
int tDataCheck = calcCheckSum32((u8*)buf.data(),fileSize);
bSize = bSize + fileSize;
//校验相同,查找相同的文件替换
if(sDataCheck == tDataCheck)
{
QString uFileName = targetDir + fName;
QFile uFile(uFileName);
QString cName = fName;
if(uFile.exists())//执行目录中存在U盘中的文件fileName
{
QString targetPath;
targetPath.clear();
#ifdef Q_OS_WIN
if(fName.toUpper().indexOf(APPNAME) != -1 &&
fName.toUpper().indexOf(".EXE") != -1)
{
targetPath = targetDir + WIN_APPNAME;
}
#endif
#ifdef Q_OS_LINUX
if(fName.toUpper().indexOf(APPNAME) != -1 &&
fName.toUpper().indexOf(".EXE") == -1)
{
targetPath = targetDir + LINUX_APPNAME;
cName = LINUX_APPNAME;
}
#endif
#if(0)
if(fName.toUpper().indexOf(APPNAME) != -1)
{
#ifdef Q_OS_WIN
targetPath = targetDir + WIN_APPNAME;
#endif
#ifdef Q_OS_LINUX
targetPath = targetDir + LINUX_APPNAME;
cName = LINUX_APPNAME;
#endif
}
#endif
else//其他文件
{
targetPath = uFileName;
}
QFile::remove(targetPath);
QFile tFile(targetPath);
if(tFile.open(QIODevice::WriteOnly) == false)
{
return;
}
tFile.write(buf);
qDebug()<<"AUT Update";
qDebug()<<"targetPath"<<targetPath;
#ifdef Q_OS_LINUX
QString str = "chmod 777 " + cName;
system(str.toLatin1());
#endif
}
else//不存在
{
QString targetPath;
targetPath.clear();
#ifdef Q_OS_WIN
if(fName.toUpper().indexOf(APPNAME) != -1 &&
fName.toUpper().indexOf(".EXE") != -1)
{
targetPath = targetDir + WIN_APPNAME;
}
#endif
#ifdef Q_OS_LINUX
if(fName.toUpper().indexOf(APPNAME) != -1 &&
fName.toUpper().indexOf(".EXE") == -1)
{
targetPath = targetDir + LINUX_APPNAME;
cName = LINUX_APPNAME;
}
#endif
#if(0)
if(fName.toUpper().indexOf(APPNAME) != -1)
{
#ifdef Q_OS_WIN
targetPath = targetDir + WIN_APPNAME;
#endif
#ifdef Q_OS_LINUX
targetPath = targetDir + LINUX_APPNAME;
cName = LINUX_APPNAME;
#endif
}
#endif
else//其他文件
{
#ifdef Q_OS_WIN
if(fName.toUpper().indexOf(APPNAME) != -1 &&
fName.toUpper().indexOf(".EXE") == -1)
{
continue;
}
#endif
#ifdef Q_OS_LINUX
if(fName.toUpper().indexOf(APPNAME) != -1 &&
fName.toUpper().indexOf(".EXE") != -1)
{
continue;
}
#endif
targetPath = uFileName;
}
QFile tFile(targetPath);
if(tFile.open(QIODevice::WriteOnly) == false)
{
return;
}
tFile.write(buf);
qDebug()<<"not exist"<<cName;
qDebug()<<"targetPath"<<targetPath;
#ifdef Q_OS_LINUX
QString str = "chmod 777 " + cName;
system(str.toLatin1());
#endif
}
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("The program is corrupted, please re-upgrade after replacing the program!")); //程序已损坏,请更换程序后重新升级!
m_pPromptDlg->exec();
return;
}
}
file.close();
#ifdef Q_OS_LINUX
qDebug()<<"reboot before";
system("sync");
system("reboot");
qDebug()<<"reboot end";
#endif
//需放在linux重启命令后面
#ifdef Q_OS_WIN
qDebug()<<"qApp->exit()";
qApp->exit();
#endif
}
else
{
//所选文件非升级文件
//文件格式错误,请重新选择!
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("The file format is wrong, please select again!");//文件格式错误,请重新选择!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
}
}
else if(type == MC_UPDATA)//主控升级
{
if(fileName.toUpper().indexOf(".RNPU") != -1)
{
QString uPath = usbPath + fileName;
qDebug()<<"RNPU update";
qDebug()<<"uPath"<<uPath;
AppFileHead appHead ;
memset(&appHead , 0 , sizeof(appHead));
QFile file(uPath);
u8 * pBuff = (u8 *) malloc(file.size());
qDebug() << "file.size()" << file.size();
if(file.size() <= 0)
{
//文件格式错误,请重新选择!
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("File bytes are 0, please check the file!");//文件字节为0请检查文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
file.open(QIODevice::ReadOnly);
file.read( (char *)pBuff , file.size()) ;
file.close();
int nameSize = uPath.toUtf8().size() ;
if( nameSize > 32 )
{
nameSize = 32;
}
memcpy(appHead.fileName , uPath.toUtf8().data() , nameSize);
appHead.dataSize = file.size();
appHead.dataChecksum = calcCheckSum32(pBuff , file.size());
static int nID = 0;
if( g_pMachine->isConnected() == 3)
{
g_pMachine->sendAPPFileProc(FILE_TYPE_PGM,
0,
nID++,
appHead ,
pBuff
);
}
free(pBuff);
}
}
else if(type == EXBOARD_UPDATA)//外围板升级
{
if(fileName.toUpper().indexOf(".RNPU") != -1)
{
QString uPath = usbPath + fileName;
qDebug()<<"RNPU update";
qDebug()<<"uPath"<<uPath;
BoardFileHead boardHead ;
memset(&boardHead , 0 , sizeof(boardHead));
QFile file(uPath);
u8 * pBuff = (u8 *) malloc( file.size());
qDebug() << "file.size()" << file.size();
file.open(QIODevice::ReadOnly);
file.read( (char *)pBuff , file.size()) ;
file.close();
int nameSize = uPath.toUtf8().size() ;
if( nameSize > 32 )
{
nameSize = 32;
}
memcpy(boardHead.fileName , uPath.toUtf8().data() , nameSize);
boardHead.dataSize = file.size();
boardHead.dataChecksum = calcCheckSum32(pBuff , file.size());
boardHead.protocol = protocol;
boardHead.nodeid = nodeid;
boardHead.nodeType = nodeType;
boardHead.fileType = FILE_TYPE_PGM;
static int eID = 0;
if( g_pMachine->isConnected() == 3)
{
g_pMachine->sendBoardFileProc(FILE_TYPE_BOARD,
0,
eID++,
boardHead,
pBuff
);
}
free(pBuff);
}
}
else if(type == PARA_IMPORT)//参数导入
{
QString uPath = usbPath + fileName;
qDebug()<<"Para Import";
qDebug()<<"uPath"<<uPath;
QFile paraFile(uPath);
if(!paraFile.exists())
{
return;
}
paraFile.open(QIODevice::ReadOnly);
if(paraFile.size() != 0)
{
// 将文件 读取成结构体
ParaFile paraFileStruct;
memset(&paraFileStruct,0,sizeof(ParaFile));
int readSize = paraFile.read((char*)&paraFileStruct,sizeof(ParaFile));
paraFile.close();
if(readSize != paraFile.size())
{
//文件大小不匹配,无效的参数文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("File size not match, invalid file!"));//文件大小不匹配,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
if( readSize != sizeof(ParaFile) )
{
//文件大小不匹配,无效的参数文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("File size not match, invalid file!"));//文件大小不匹配,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
// 参数被正确的读取
if(
( paraFileStruct.s_head[0] == 'P' )
&& ( paraFileStruct.s_head[1] == 'A' )
&& ( paraFileStruct.s_head[2] == 'R' )
&& ( paraFileStruct.s_head[3] == 'A' )
&& ( paraFileStruct.s_type == 0 )
&& ( paraFileStruct.s_len == 4096 )
)
{
unsigned short i_crc = calcCrc16( (unsigned char *) paraFileStruct.s_para_buff , paraFileStruct.s_len);
if( paraFileStruct.s_crc != i_crc )
{
//数据校验错误,无效的参数文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("Data check error, invalid file!"));//数据校验错误,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
//将 一个文件 拆分成两个 缓冲区
unsigned char mac_config [1024] ;
unsigned char work_config [1024] ;
unsigned char pre_mac_config [1024] ;
unsigned char pre_work_config [1024] ;
// 清空
memset( mac_config , 0 , 1024 ) ;
memset( work_config , 0 , 1024 ) ;
memset( pre_mac_config , 0 , 1024 ) ;
memset( pre_work_config , 0 , 1024 ) ;
memcpy( work_config , paraFileStruct.s_para_buff , 1024 ) ;
memcpy( mac_config , ((char*)paraFileStruct.s_para_buff) + 1024 , 1024 ) ;
memcpy( pre_mac_config , ((char*)paraFileStruct.s_para_buff) + 2048 , 1024 ) ;
memcpy( pre_work_config , ((char*)paraFileStruct.s_para_buff) + 3072 , 1024 ) ;
QString str;
g_pMachine->setMcPara((ParaStruct *) mac_config);
g_pMachine->setWkPara((ParaStruct *) work_config);
g_pMachine->setMcPrePara((ParaStruct *) pre_mac_config);
g_pMachine->setWkPrePara((ParaStruct *) pre_work_config);
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
str = (tr("Parameters imported successfully!"));//参数导入成功!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
else
{
//文件头不匹配,无效的参数文件!
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("File head not match, invalid file!"));//文件头不匹配,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
}
}
else if (type == WKPARA_IMPORT) //工作参数导入
{
QString uPath = usbPath + fileName;
QFile paraFile(uPath);
if(!paraFile.exists())
{
return;
}
paraFile.open(QIODevice::ReadOnly);
if(paraFile.size() != 0)
{
// 将文件 读取成结构体
ParaFile paraFileStruct;
memset(&paraFileStruct,0,sizeof(ParaFile));
int readSize = paraFile.read((char*)&paraFileStruct,sizeof(ParaFile));
paraFile.close();
if(readSize != paraFile.size())
{
//文件大小不匹配,无效的参数文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("File size not match, invalid file!"));//文件大小不匹配,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
if( readSize != sizeof(ParaFile) )
{
//文件大小不匹配,无效的参数文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("File size not match, invalid file!"));//文件大小不匹配,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
// 参数被正确的读取
if( ( paraFileStruct.s_head[0] == 'P' )
&& ( paraFileStruct.s_head[1] == 'A' )
&& ( paraFileStruct.s_head[2] == 'R' )
&& ( paraFileStruct.s_head[3] == 'A' )
&& ( paraFileStruct.s_type == 0 )
&& ( paraFileStruct.s_len == 4096 )
)
{
unsigned short i_crc = calcCrc16( (unsigned char *) paraFileStruct.s_para_buff , paraFileStruct.s_len);
if( paraFileStruct.s_crc != i_crc )
{
//数据校验错误,无效的参数文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("Data check error, invalid file!"));//数据校验错误,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
//将 一个文件 拆分成两个 缓冲区
unsigned char mac_config [1024] ;
unsigned char work_config [1024] ;
unsigned char pre_mac_config [1024] ;
unsigned char pre_work_config [1024] ;
// 清空
memset( mac_config , 0 , 1024 ) ;
memset( work_config , 0 , 1024 ) ;
memset( pre_mac_config , 0 , 1024 ) ;
memset( pre_work_config , 0 , 1024 ) ;
memcpy( work_config , paraFileStruct.s_para_buff , 1024 ) ;
memcpy( mac_config , ((char*)paraFileStruct.s_para_buff) + 1024 , 1024 ) ;
memcpy( pre_mac_config , ((char*)paraFileStruct.s_para_buff) + 2048 , 1024 ) ;
memcpy( pre_work_config , ((char*)paraFileStruct.s_para_buff) + 3072 , 1024 ) ;
QString str;
g_pMachine->setWkPara((ParaStruct *) work_config);
str = (tr("Work parameters imported fail!"));//工作参数导入失败!
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
str = (tr("Work parameters imported successfully!"));//工作参数导入成功!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
else
{
//文件头不匹配,无效的参数文件!
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("File head not match, invalid file!"));//文件头不匹配,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
}
}
else if(type == FRAMEPARA_IMPORT)//动框参数导入
{
QString uPath = usbPath + fileName;
QFile paraFile(uPath);
if(!paraFile.exists())
{
return;
}
paraFile.open(QIODevice::ReadOnly);
if(paraFile.size() != 0)
{
// 将文件 读取成结构体
ParaFile paraFileStruct;
memset(&paraFileStruct,0,sizeof(ParaFile));
int readSize = paraFile.read((char*)&paraFileStruct,sizeof(ParaFile));
paraFile.close();
if(readSize != paraFile.size())
{
//文件大小不匹配,无效的参数文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("File size not match, invalid file!"));//文件大小不匹配,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
if( readSize != sizeof(ParaFile) )
{
//文件大小不匹配,无效的参数文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("File size not match, invalid file!"));//文件大小不匹配,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
// 参数被正确的读取
if(
( paraFileStruct.s_head[0] == 'P' )
&& ( paraFileStruct.s_head[1] == 'A' )
&& ( paraFileStruct.s_head[2] == 'R' )
&& ( paraFileStruct.s_head[3] == 'A' )
&& ( paraFileStruct.s_type == 0 )
&& ( paraFileStruct.s_len == 4096 )
)
{
unsigned short i_crc = calcCrc16( (unsigned char *) paraFileStruct.s_para_buff , paraFileStruct.s_len);
if( paraFileStruct.s_crc != i_crc )
{
//数据校验错误,无效的参数文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("Data check error, invalid file!"));//数据校验错误,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
//将 一个文件 拆分成两个 缓冲区
unsigned char frame1_config [1024] ;
//unsigned char frame2_config [1024] ;
unsigned char pre_frame1_config [1024] ;
// unsigned char pre_frame2_config [1024] ;
// 清空
memset( frame1_config , 0 , 1024 ) ;
//memset( frame2_config , 0 , 1024 ) ;
memset( pre_frame1_config , 0 , 1024 ) ;
//memset( pre_frame2_config , 0 , 1024 ) ;
memcpy( frame1_config , paraFileStruct.s_para_buff , 1024 ) ;
// memcpy( frame2_config , ((char*)paraFileStruct.s_para_buff) + 1024 , 1024 ) ;
memcpy( pre_frame1_config , ((char*)paraFileStruct.s_para_buff) + 1024 , 1024 ) ;
//memcpy( pre_frame2_config , ((char*)paraFileStruct.s_para_buff) + 3072 , 1024 ) ;
QString str;
g_pMachine->setFrameAnglePara((EmbMvAng *) frame1_config);
g_pMachine->setFrameAnglePara((EmbMvAng *) pre_frame1_config);
str = (tr("Frame parameters imported fail!"));//动框参数导入失败!
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
str = (tr("Frame parameters imported successfully!"));//动框参数导入成功!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
else
{
//文件头不匹配,无效的参数文件!
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("File head not match, invalid file!"));//文件头不匹配,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
}
}
}
}
s16 MainWidgetFunction::refreshWifiList(QStringList &wifiStrList,s16 scan)
{
if(scan == 0){}//为了去掉编译警告
wifiStrList.clear();
QProcess cmd;
QString cmdStr;
cmdStr.clear();
QString strCmdOut;
strCmdOut.clear();
QStringList lineStrList;
lineStrList.clear();
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
#ifdef Q_OS_LINUX
cmdStr = "ifconfig";//查看wlan0初始化是否成功
cmd.start(cmdStr);
cmd.waitForStarted();
cmd.waitForFinished();
strCmdOut=QString::fromLocal8Bit(cmd.readAllStandardOutput());
lineStrList = strCmdOut.split("\n", QString::SkipEmptyParts); //换行符
int initFlag = 0;
for(int i = 0; i < lineStrList.size(); i++)
{
QString lineStr = lineStrList[i];
if(lineStr.indexOf("wlan0") != -1)
{
initFlag = 1;
break;
}
}
if(initFlag == 0)
{
m_pPromptDlg->setContentStr(tr("Failed to initialize wlan0!"));//初始化wlan0失败
m_pPromptDlg->exec();
return -1;
}
if(scan != 0)
{
cmdStr = "wpa_cli -i wlan0 scan";//搜索可见wifi
cmd.start(cmdStr);
cmd.waitForStarted();
cmd.waitForFinished();
strCmdOut=QString::fromLocal8Bit(cmd.readAllStandardOutput());
int flag = 0;
while(strCmdOut.toUpper().indexOf("OK") == -1)
{
cmdStr = "wpa_cli -i wlan0 scan";//搜索可见wifi
cmd.start(cmdStr);
cmd.waitForStarted();
cmd.waitForFinished();
strCmdOut=QString::fromLocal8Bit(cmd.readAllStandardOutput());
flag++;
if(flag >= 100)
{
break;
}
}
}
cmdStr = "wpa_cli -i wlan0 scan_result";//获取搜索结果
cmd.start(cmdStr);
cmd.waitForStarted();
cmd.waitForFinished();
strCmdOut=QString::fromLocal8Bit(cmd.readAllStandardOutput());
lineStrList = strCmdOut.split("\n", QString::SkipEmptyParts);//换行符
for(int i = 0; i < lineStrList.size(); i++)
{
//qDebug()<<i<<lineStrList[i];
QStringList lineStr = lineStrList[i].split("\t", QString::SkipEmptyParts);//tap
if(lineStr.size() >= 2 && lineStr[lineStr.size()-1].indexOf("]") == -1)
{
QString str = lineStr[lineStr.size()-1].remove(QRegExp("^ +\\s*"));//正则表达式去掉空格
s16 ifExist = 0;
for(s16 m = 0; m < wifiStrList.size(); m++)
{
if(wifiStrList[m] == str)
{
ifExist = 1;
break;
}
}
if(ifExist == 0)
{
wifiStrList.append(str);
}
}
}
if(wifiStrList.size() <= 0)
{
m_pPromptDlg->setContentStr(tr("Failed to search for WiFi list. Please try again later!"));//搜索wifi列表失败请稍后重试
m_pPromptDlg->exec();
return -1;
}
#endif
return 1;
}
QString MainWidgetFunction::getIpSegment(bool bl)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString ipStr;
ipStr.clear();
if(bl == true){}//为了去掉编译警告
//linux下查询wifi连接状态
#ifdef Q_OS_LINUX
s16 value = -1;
QProcess cmd;
QString cmdStr;
cmdStr.clear();
QString strCmdOut;
strCmdOut.clear();
QStringList lineStrList;
lineStrList.clear();
cmdStr = "wpa_cli -i wlan0 status";//查询wifi连接状态
cmd.start(cmdStr);
cmd.waitForStarted();
cmd.waitForFinished();
strCmdOut=QString::fromLocal8Bit(cmd.readAllStandardOutput());
//qDebug()<<"strCmdOut"<<strCmdOut;
lineStrList = strCmdOut.split("\n", QString::SkipEmptyParts); //换行符
//qDebug()<<"lineStrList.size()"<<lineStrList.size();
for(int i = 0; i < lineStrList.size(); i++)
{
QStringList lineStr = lineStrList[i].split("=", QString::SkipEmptyParts);
if(lineStr.size() >= 2)
{
QString str1 = lineStr[0];
//qDebug()<<lineStrList[i];
if(str1.indexOf("wpa_state") != -1)
{
QString str2 = lineStr[1];
//qDebug()<<str2;
if(str2.indexOf("COMPLETED") == -1)
{
cmd.close();
}
}
if(str1.indexOf("ip_address") != -1)
{
ipStr = lineStr[1].remove(QRegExp("^ +\\s*"));//正则表达式去掉空格-IP
cmd.close();
value = 1;
break;
}
}
}
cmd.close();
if(value >= 0)
{
QString modeStr;
modeStr.clear();
if(bl == false)
{
modeStr = tr("dynamic");//动态
}
else if(bl == true)
{
modeStr = tr("static");//静态
}
ipStr = ipStr + "(" + modeStr + ")";
}
else
{
if(bl == true)
{
m_pPromptDlg->setContentStr(tr("Failed to obtain IP. Please check the settings!"));//获取IP失败请检查设置
m_pPromptDlg->exec();
}
}
#endif
return ipStr;
}
//工作参数导入
void MainWidgetFunction::funImportWkParameter(QString tStyle)
{
m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("WkParameter Import"));
m_pSystemManageDlg->setSubTitle(tr("Auxiliary Function > WkParameter Import"));
m_pSystemManageDlg->initDialog();
systemUpgrade(WKPARA_IMPORT);
}
//参数导入
void MainWidgetFunction::funImportParameter(QString tStyle)
{
m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("Parameter Import"));
m_pSystemManageDlg->setSubTitle(tr("Auxiliary Function > Parameter Import"));
m_pSystemManageDlg->initDialog();
systemUpgrade(PARA_IMPORT);
}
//主控升级
void MainWidgetFunction::funMCUpgrade(QString tStyle)
{
m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("MC Upgrade"));
m_pSystemManageDlg->setSubTitle(tr("Auxiliary Function > MC Upgrade"));
m_pSystemManageDlg->initDialog();
systemUpgrade(MC_UPDATA);
}
//界面升级
void MainWidgetFunction::funHMIUpgrade(QString tStyle)
{
m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("HMI Upgrade"));
m_pSystemManageDlg->setSubTitle(tr("Auxiliary Function > HMI Upgrade"));
m_pSystemManageDlg->initDialog();
systemUpgrade(HMI_UPDATA);
}
void MainWidgetFunction::funWIFI(QString tStyle)
{
QStringList wifiStrList;
wifiStrList.clear();
s16 rel = refreshWifiList(wifiStrList);
if(rel > 0)
{
m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("WIFI"));
m_pSystemManageDlg->setSubTitle(tr("Auxiliary Function > WIFI"));
bool mode = false;//动态获取IP方式
QString iniPath = WIFIINIPATH;
QSettings setting(iniPath,QSettings::IniFormat);
QString wifiName = QByteArray::fromBase64(setting.value("WIFI/default_ssid").toByteArray());
QString wifiPass = QByteArray::fromBase64(setting.value("WIFI/default_passwd").toByteArray());
mode = setting.value("WIFI/static_mode").toBool();
QString ip = getIpSegment(mode);
if(ip.length() > 0)//已连接
{
m_pSystemManageDlg->setWifiInfo(ip,wifiName,wifiPass,mode);
m_pSystemManageDlg->initDialog(1);
for(s16 i = 0; i < wifiStrList.size(); i++)
{
m_pSystemManageDlg->addItem(wifiStrList.at(i));
}
emit siWifiState(true);
}
else//未连接
{
m_pSystemManageDlg->initDialog(1);
for(s16 i = 0; i < wifiStrList.size(); i++)
{
m_pSystemManageDlg->addItem(wifiStrList.at(i));
}
emit siWifiState(false);
}
m_pSystemManageDlg->exec();
}
}
//参数导出
void MainWidgetFunction::funExportParameter()
{
QString usbPath = detectUsb();
if(usbPath.length() <= 0)
{
//优盘不存在
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("USB flash drive is not detected!");//未检测到优盘!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
//导出参数文件时文件名自动生成
QString i_para = "Ppara_";
QString paradat = ".paradat";
QString i_time = QDateTime::currentDateTime().toString("_yyMMdd_hhmmss");//时间日期
QString strName = i_para + i_time + paradat;
QString paraFileName = usbPath + strName;
QFile::remove (paraFileName) ;
#ifdef Q_OS_LINUX
system("sync");
#endif
char para_mc [ 1024 ];
char para_wk [ 1024 ];
char pre_para_mc [ 1024 ];
char pre_para_wk [ 1024 ];
memcpy(para_mc , (u8*) (&(g_pMachine->getMcPara())) , 1024 );
memcpy(para_wk , (u8*) (&(g_pMachine->getWkPara())) , 1024 );
memcpy(pre_para_mc , (u8*) (&(g_pMachine->getPreMcPara())) , 1024 );
memcpy(pre_para_wk , (u8*) (&(g_pMachine->getPreWkPara())) , 1024 );
//两个缓冲区,输出成一个参数文件
// 转换结构体 开始
ParaFile paraFileStruct ;
memset(&paraFileStruct,0,sizeof(ParaFile)) ;
paraFileStruct.s_head[0] = 'P';
paraFileStruct.s_head[1] = 'A';
paraFileStruct.s_head[2] = 'R';
paraFileStruct.s_head[3] = 'A';
paraFileStruct.s_type = 0 ;
paraFileStruct.s_len = 4096 ;
memcpy( paraFileStruct.s_para_buff , para_wk , 1024 );
memcpy( (char *) (paraFileStruct.s_para_buff) + 1024 , para_mc , 1024 );
memcpy( (char *) (paraFileStruct.s_para_buff) + 2048 , pre_para_mc , 1024 );
memcpy( (char *) (paraFileStruct.s_para_buff) + 3072 , pre_para_wk , 1024 );
paraFileStruct.s_crc = calcCrc16( (u8 * ) paraFileStruct.s_para_buff , 4096 ) ;
// 转换结构体 结束
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
// 保存文件 开始
QFile file(paraFileName);
bool bl = file.open(QIODevice::ReadWrite | QIODevice::Truncate);
if(bl == false)
{
//参数导出失败!
str = tr("Parameters exported failed!");//参数导出失败!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
file.close();
return;
}
bl = file.write((char*)&paraFileStruct,sizeof(ParaFile));
if(bl == false)
{
//参数导出失败!
str = tr("Parameters exported failed!");//参数导出失败!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
file.close();
return;
}
file.flush();
file.close();
// 保存文件 结束
#ifdef Q_OS_LINUX
system("sync");
#endif
//参数导出成功
str = tr("Parameters exported successfully!");//参数导出成功!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
//动框参数导出
void MainWidgetFunction::funExportFrameParameter()
{
QString usbPath = detectUsb();
if(usbPath.length() <= 0)
{
//优盘不存在
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("USB flash drive is not detected!");//未检测到优盘!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
//导出参数文件时文件名自动生成
MCInfo info1 = g_pMachine->getMcInfo();
QString software_ver;
software_ver.sprintf("%s",info1.softwareVerStr);
QStringList i_sof = software_ver.split(" ");//读取空格之前的版本信息
QString i_info = i_sof[0] ;
QString i_para = "FrameEpara_";
QString paradat = ".frameparadat";
QString i_time = QDateTime::currentDateTime().toString("_yyMMdd_hhmmss");//时间日期
QString strName = i_para + i_info + i_time + paradat;
QString paraFileName = usbPath + strName;
QFile::remove (paraFileName) ;
#ifdef Q_OS_LINUX
system("sync");
#endif
char para_frame1 [ 1024 ];
//char para_frame2 [ 1024 ];
char pre_para_frame1 [ 1024 ];
// char pre_para_frame2 [ 1024 ];
memcpy(para_frame1 , (u8*) (&(g_pMachine->getFrameAnglePara())) , 1024 );
memcpy(pre_para_frame1 , (u8*) (&(g_pMachine->getFrameAnglePara())) , 1024 );
//两个缓冲区,输出成一个参数文件
// 转换结构体 开始
ParaFile paraFileStruct ;
memset(&paraFileStruct,0,sizeof(ParaFile)) ;
paraFileStruct.s_head[0] = 'P';
paraFileStruct.s_head[1] = 'A';
paraFileStruct.s_head[2] = 'R';
paraFileStruct.s_head[3] = 'A';
paraFileStruct.s_type = 0 ;
paraFileStruct.s_len = 4096 ;
memcpy( paraFileStruct.s_para_buff , para_frame1 , 1024 );
memcpy( (char *) (paraFileStruct.s_para_buff) + 1024 , pre_para_frame1 , 1024 );
paraFileStruct.s_crc = calcCrc16( (u8 * ) paraFileStruct.s_para_buff , 4096 ) ;
// 转换结构体 结束
// 保存文件 开始
QFile file(paraFileName);
file.open(QIODevice::ReadWrite | QIODevice::Truncate);
file.write((char*)&paraFileStruct,sizeof(ParaFile));
file.flush();
file.close();
// 保存文件 结束
#ifdef Q_OS_LINUX
system("sync");
#endif
//参数导出成功
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("Frame parameters exported successfully!");//动框参数导出成功!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
//全部归零
void MainWidgetFunction::funAllToZero()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("All to zero"));//全部归零
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->allToZero();
}
}
}
//主轴点动
void MainWidgetFunction::funSpindleJog()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Spindle jog"));//主轴点动
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->spindleJog();
}
}
}
void MainWidgetFunction::funPunchMsSeverOn()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Punch spindle enable"));//冲孔主轴使能
QString str;
str = tr("Is the punching spindle enabled?");//冲孔主轴是否使能?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->punchMsServoOn();
}
}
}
void MainWidgetFunction::funPunchMsSeverOff()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Punch spindle enable"));//冲孔主轴失能
QString str;
str = tr("Is the punching spindle disabled?");//冲孔主轴是否失能?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->punchMsServoOff();
}
}
}
void MainWidgetFunction::funPunchMsRun()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Punch spindle run"));//冲孔主轴研车
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->punchMsRun();
}
}
}
void MainWidgetFunction::funSewMsRun()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Sew spindle run"));//缝纫主轴研车
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1) // 界面点击确认按钮要执行下面的问题
{
if(g_pMachine != NULL)
{
g_pMachine->sewingMsRun();
}
}
}
void MainWidgetFunction::funEmbMsRun()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("embroidered spindle run"));//平绣主轴研车
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->embMsRun();
}
}
}
void MainWidgetFunction::funPunchSpindleJog()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Punch spindle jog"));//冲孔主轴点动
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->punchJog();
}
}
}
void MainWidgetFunction::funSewSpindleJog()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Sew spindle jog"));//缝纫主轴点动
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->sewJog();
}
}
}
void MainWidgetFunction::funEmbSpindleJog()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("embroidered spindle jog"));//平绣主轴点动
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->embJog();
}
}
}
void MainWidgetFunction::funToHookPosition()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Hook position"));//缝纫主轴去勾线位
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->hookPos();
}
}
}
void MainWidgetFunction::funEmbToHookPosition()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Emb hook position"));//平绣主轴去勾线位
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->embHookPos();
}
}
}
//缝纫旋转校对
void MainWidgetFunction::funRotateProofread()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Rotate proofread"));//缝纫旋转校对
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->rotateProofread();
}
}
}
void MainWidgetFunction::funSewheadUpDown()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Sewing machine head lifting"));//缝纫机头升降
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->sewHeadLift();
}
}
}
void MainWidgetFunction::switchMachineHead(int nNum)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
if(nNum == 1)
{
m_pPromptDlg->setTitleStr(tr("Change to the sew head"));//切换缝纫机头
}
else if(nNum == 2)
{
m_pPromptDlg->setTitleStr(tr("Change to the punch head"));//切换冲孔机头
}
else if(nNum == 3)
{
m_pPromptDlg->setTitleStr(tr("Change to the embroidered head"));//切换平绣机头
}
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->headSwitch(nNum);
}
}
}
void MainWidgetFunction::funNeedleContrast(int step)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
if(step == 0)
{
m_pPromptDlg->setTitleStr(tr("Needle shuttle proofreading"));//针梭校对
}
else if(step == 2)
{
m_pPromptDlg->setTitleStr(tr("Shuttle zero"));//梭归零
}
else if(step == 3)
{
m_pPromptDlg->setTitleStr(tr("Needle zero"));//针归零
}
else if(step == 4)
{
m_pPromptDlg->setTitleStr(tr("Needle shuttle reset"));//针梭复位
}
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->msAdjust(step);
}
}
}
//回换梭位
void MainWidgetFunction::funBackShuttlePos()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Replacing shuttle positions"));//回换梭位
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->gotoShuttlePos();
}
}
}
//缝纫旋转
void MainWidgetFunction::funSewRotate(int flag)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
if(flag == 1)
{
m_pPromptDlg->setTitleStr(tr("Sew rotate up"));//缝纫旋转+
}
else if(flag == 2)
{
m_pPromptDlg->setTitleStr(tr("Sew rotate down"));//缝纫旋转-
}
QString str;
str = tr("Whether to change the steering!");//是否改变转向!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
if(flag == 1)
{
g_pMachine->moveRotByHand('p',2);
}
else if(flag == 2)
{
g_pMachine->moveRotByHand('n',2);
}
}
}
}
//定偏移点
void MainWidgetFunction::funSetOffsetPoint()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Set offset point"));//定偏移点
QString str;
str = tr("Whether to set the current point as the offset point?");//是否将当前点设置为偏移点?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->setOffsetPos();
}
}
}
//回偏移点
void MainWidgetFunction::funBackOffsetPoint()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Back offset point"));//回偏移点
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->gotoOffsetPos();
}
}
}
void MainWidgetFunction::funPunchRotToZero()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Punch rot to zero"));//冲孔旋转去零位
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->punchRotToZero();
}
}
}
//回工作点
void MainWidgetFunction::funBackWorkPoint()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Back work point"));//回工作点
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->gotoWorkPos();
}
}
}
//回定位点
void MainWidgetFunction::funBackAnchorPoint()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Back anchor point"));//回定位点
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->gotoAnchorPos();
}
}
}
//回穿线点
void MainWidgetFunction::funBackThreadPoint()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Back thread point"));//回穿线点
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->gotoWorkPos();
}
}
}
//回原点
void MainWidgetFunction::funBackToOrigin()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Back to origin"));//回原点
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->gotoZeroPos();
}
}
}
void MainWidgetFunction::funBackCenterPoint()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Back center point"));//回中心点
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->gotoCenterPos();
}
}
}
//第一机头定起始点
void MainWidgetFunction::funFirstHeadSetStartPoint(QString filePath)
{
if(filePath.length() <= 0)
{
return;
}
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
if(g_emMacType == MACHINE_PUNCH_SEW || g_emMacType == MACHINE_PUNCH_SEW_EMB)
{
m_pPromptDlg->setTitleStr(tr("Sew head set start point"));//缝纫头定起始点
}
else
{
m_pPromptDlg->setTitleStr(tr("Set start point"));//定起始点
}
QString str = tr("Whether to set the current point as the start point?");//是否将当前点设置为起始点?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
s32 x,y;
x = y = 0;
if(g_pMachine != NULL)
{
m_mcStatus = g_pMachine->getMcStatus();
x = m_mcStatus.xPos;
y = m_mcStatus.yPos;
}
int oldBeginX, oldBeginY;
oldBeginX = oldBeginY = 0;
if(g_pCurEmbData != NULL)
{
oldBeginX = g_pCurEmbData->getBeginX();
oldBeginY = g_pCurEmbData->getBeginY();
g_pCurEmbData->setStartPosition(x,y);
//改变中间数据ds16的头文件
}
sendPatternHead(filePath);//发送花样ds16头文件
//每次点击选择花样的时候才会生成ds16数据其他时候就是给下位机发头文件
//dsr,dst整个文件->中间数据->ds16
//冲孔机起始点-保存到fcg不改变源文件
//垫板冲孔机-自动定起始点
//压胶机-保存到fcg不改变源文件
//冲缝机-保存到源文件
//将新的起始点写回到dstdsr源文件中
if(g_emMacType == MACHINE_PUNCH || g_emMacType == MACHINE_PUNCH_SEW || g_emMacType == MACHINE_PUNCH_SEW_EMB)//等于冲缝机
{
int wx = x - oldBeginX - g_pCurEmbData->getAnchorX();
int wy = y - oldBeginY - g_pCurEmbData->getAnchorY();
writePonitToFile(filePath,wx,wy);
}
//等于压胶机或冲孔机
if(g_emMacType == MACHINE_ADHESIVE || g_emMacType == MACHINE_PUNCH_SEW ||
g_emMacType == MACHINE_PUNCH || g_emMacType == MACHINE_PUNCH_SEW_EMB)
{
DataFileHead fileHead;
getPatternHeadConfig(filePath,fileHead);
fileHead.beginX = x;
fileHead.beginY = y;
setPatternHeadConfig(filePath,fileHead);
}
m_beginX = x;
m_beginY = y;
//流程复位
g_pMachine->allToReset();
}
}
//主机头设置定位点(冲缝机时主机头为缝纫机头)
void MainWidgetFunction::funFirstHeadSetAnchorPoint(QString filePath)
{
if(filePath.length() <= 0)
{
return;
}
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
if(g_emMacType == MACHINE_PUNCH_SEW_EMB)
{
m_pPromptDlg->setTitleStr(tr("Sew head set anchor point"));//缝纫头定定位点
}
else
{
m_pPromptDlg->setTitleStr(tr("Set anchor point"));//定定位点
}
QString str = tr("Whether to set the current point as the anchor point?");//是否将当前点设置为定位点?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
s32 x,y;
x = y = 0;
if(g_pMachine != NULL)
{
m_mcStatus = g_pMachine->getMcStatus();
x = m_mcStatus.xPos;
y = m_mcStatus.yPos;
}
if(g_pCurEmbData != NULL)
{
g_pCurEmbData->setStartPosition(x,y);
g_pCurEmbData->setAnchorPosition(x,y);
//改变中间数据ds16的头文件
}
sendPatternHead(filePath);//发送花样ds16头文件
//每次点击选择花样的时候才会生成ds16数据其他时候就是给下位机发头文件
//将新的起始点写回到dstdsr源文件中
//等于冲缝机或冲缝绣
if(g_emMacType == MACHINE_PUNCH_SEW || g_emMacType == MACHINE_PUNCH_SEW_EMB )
{
writePonitToFile(filePath,x,y,1);
}
//等于压胶机或冲孔机
if(g_emMacType == MACHINE_ADHESIVE || g_emMacType == MACHINE_PUNCH_SEW ||
g_emMacType == MACHINE_PUNCH || g_emMacType == MACHINE_PUNCH_SEW_EMB)
{
DataFileHead fileHead;
getPatternHeadConfig(filePath,fileHead);
fileHead.anchorX = x;
fileHead.anchorY = y;
setPatternHeadConfig(filePath,fileHead);
}
}
}
//第二机头设置起始点(冲缝机时次机头为冲孔机头)
void MainWidgetFunction::funSecHeadSetStartPoint(QString filePath)
{
if(filePath.length() <= 0)
{
return;
}
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
if(g_emMacType == MACHINE_PUNCH_SEW || g_emMacType == MACHINE_PUNCH_SEW_EMB)
{
m_pPromptDlg->setTitleStr(tr("Punch head set start point"));//冲孔头定起始点
}
else
{
m_pPromptDlg->setTitleStr(tr("Set start point"));//定起始点
}
QString str = tr("Whether to set the current point as the start point?");//是否将当前点设置为起始点?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
s32 x,y;
x = y = 0;
if(g_pMachine != NULL)
{
m_mcStatus = g_pMachine->getMcStatus();
x = m_mcStatus.xPos - g_pMachine->getMcPara().buf[82];
y = m_mcStatus.yPos - g_pMachine->getMcPara().buf[83];
}
int oldBeginX,oldBeginY;
oldBeginX = oldBeginY = 0;
if(g_pCurEmbData != NULL)
{
oldBeginX = g_pCurEmbData->getBeginX();
oldBeginY = g_pCurEmbData->getBeginY();
g_pCurEmbData->setStartPosition(x,y);
//改变中间数据ds16的头文件
}
sendPatternHead(filePath);//发送花样ds16头文件
//每次点击选择花样的时候才会生成ds16数据其他时候就是给下位机发头文件
//dsr,dst整个文件->中间数据->ds16
//冲孔机起始点-保存到fcg不改变源文件
//垫板冲孔机-自动定起始点
//压胶机-保存到fcg不改变源文件
//冲缝机-保存到源文件
//将新的起始点写回到dstdsr源文件中
if(g_emMacType == MACHINE_PUNCH_SEW || g_emMacType == MACHINE_PUNCH_SEW_EMB)//等于冲缝机
{
int wx = x - oldBeginX - g_pCurEmbData->getAnchorX();
int wy = y - oldBeginY - g_pCurEmbData->getAnchorY();
writePonitToFile(filePath,wx,wy);
}
//冲缝绣
if(g_emMacType == MACHINE_PUNCH_SEW || g_emMacType == MACHINE_PUNCH_SEW_EMB)
{
DataFileHead fileHead;
getPatternHeadConfig(filePath,fileHead);
fileHead.beginX = x;
fileHead.beginY = y;
setPatternHeadConfig(filePath,fileHead);
}
m_beginX = x;
m_beginY = y;
//流程复位
g_pMachine->allToReset();
}
}
//次机头设置定位点(冲缝机时次机头为冲孔机头)
void MainWidgetFunction::funSecHeadSetAnchorPoint(QString filePath)
{
if(filePath.length() <= 0)
{
return;
}
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
if(g_emMacType == MACHINE_PUNCH_SEW_EMB)
{
m_pPromptDlg->setTitleStr(tr("Punch head set anchor point"));//冲孔头定定位点
}
else
{
m_pPromptDlg->setTitleStr(tr("Set anchor point"));//定定位点
}
QString str = tr("Whether to set the current point as the anchor point?");//是否将当前点设置为定位点?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
s32 x,y;
x = y = 0;
if(g_pMachine != NULL)
{
m_mcStatus = g_pMachine->getMcStatus();
x = m_mcStatus.xPos - g_pMachine->getMcPara().buf[82];
y = m_mcStatus.yPos - g_pMachine->getMcPara().buf[83];
}
if(g_pCurEmbData != NULL)
{
g_pCurEmbData->setStartPosition(x,y);
g_pCurEmbData->setAnchorPosition(x,y);
//改变中间数据ds16的头文件
}
sendPatternHead(filePath);//发送花样ds16头文件
//每次点击选择花样的时候才会生成ds16数据其他时候就是给下位机发头文件
//将新的起始点写回到dstdsr源文件中
//等于冲缝机或冲缝绣
if(g_emMacType == MACHINE_PUNCH_SEW || g_emMacType == MACHINE_PUNCH_SEW_EMB )
{
writePonitToFile(filePath,x,y,1);
}
//等于压胶机或冲孔机
if(g_emMacType == MACHINE_ADHESIVE || g_emMacType == MACHINE_PUNCH_SEW ||
g_emMacType == MACHINE_PUNCH || g_emMacType == MACHINE_PUNCH_SEW_EMB)
{
DataFileHead fileHead;
getPatternHeadConfig(filePath,fileHead);
fileHead.anchorX = x;
fileHead.anchorY = y;
setPatternHeadConfig(filePath,fileHead);
}
}
}
//第三机头设置起始点(冲绣缝时三机头为绣花机头)
void MainWidgetFunction::funThrHeadSetStartPoint(QString filePath)
{
if(filePath.length() <= 0)
{
return;
}
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
if(g_emMacType == MACHINE_PUNCH_SEW_EMB)
{
m_pPromptDlg->setTitleStr(tr("Emb head set start point"));//绣花头定起始点
}
else
{
m_pPromptDlg->setTitleStr(tr("Set start point"));//定起始点
}
QString str = tr("Whether to set the current point as the start point?");//是否将当前点设置为起始点?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
s32 x,y;
x = y = 0;
if(g_pMachine != NULL)
{
m_mcStatus = g_pMachine->getMcStatus();
x = m_mcStatus.xPos - g_pMachine->getMcPara().buf[150];
y = m_mcStatus.yPos - g_pMachine->getMcPara().buf[151];
}
int oldBeginX,oldBeginY;
oldBeginX = oldBeginY = 0;
if(g_pCurEmbData != NULL)
{
oldBeginX = g_pCurEmbData->getBeginX();
oldBeginY = g_pCurEmbData->getBeginY();
g_pCurEmbData->setStartPosition(x,y);
//改变中间数据ds16的头文件
}
sendPatternHead(filePath);//发送花样ds16头文件
//每次点击选择花样的时候才会生成ds16数据其他时候就是给下位机发头文件
//dsr,dst整个文件->中间数据->ds16
//冲孔机起始点-保存到fcg不改变源文件
//冲绣缝起始点-保存到fcg不改变源文件
//垫板冲孔机-自动定起始点
//压胶机-保存到fcg不改变源文件
//冲缝机-保存到源文件
//将新的起始点写回到dstdsr源文件中
if(g_emMacType == MACHINE_PUNCH_SEW || g_emMacType == MACHINE_PUNCH_SEW_EMB)//等于冲缝机
{
int wx = x - oldBeginX - g_pCurEmbData->getAnchorX();
int wy = y - oldBeginY - g_pCurEmbData->getAnchorY();
writePonitToFile(filePath,wx,wy);
}
if(g_emMacType == MACHINE_PUNCH_SEW_EMB)
{
DataFileHead fileHead;
getPatternHeadConfig(filePath,fileHead);
fileHead.beginX = x;
fileHead.beginY = y;
setPatternHeadConfig(filePath,fileHead);
}
m_beginX = x;
m_beginY = y;
//流程复位
g_pMachine->allToReset();
}
}
//三机头设置定位点(冲绣缝时三机头为平绣机头)
void MainWidgetFunction::funThrHeadSetAnchorPoint(QString filePath)
{
if(filePath.length() <= 0)
{
return;
}
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
if(g_emMacType == MACHINE_PUNCH_SEW_EMB)
{
m_pPromptDlg->setTitleStr(tr("Emb head set anchor point"));//绣花头定定位点
}
else
{
m_pPromptDlg->setTitleStr(tr("Set anchor point"));//定定位点
}
QString str = tr("Whether to set the current point as the anchor point?");//是否将当前点设置为定位点?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
s32 x,y;
x = y = 0;
if(g_pMachine != NULL)
{
m_mcStatus = g_pMachine->getMcStatus();
x = m_mcStatus.xPos - g_pMachine->getMcPara().buf[150];
y = m_mcStatus.yPos - g_pMachine->getMcPara().buf[151];
}
if(g_pCurEmbData != NULL)
{
g_pCurEmbData->setAnchorPosition(x,y);
//改变中间数据ds16的头文件
}
sendPatternHead(filePath);//发送花样ds16头文件
//每次点击选择花样的时候才会生成ds16数据其他时候就是给下位机发头文件
//将新的起始点写回到dstdsr源文件中
//等于冲缝机或冲缝绣
if(g_emMacType == MACHINE_PUNCH_SEW || g_emMacType == MACHINE_PUNCH_SEW_EMB )
{
writePonitToFile(filePath,x,y,1);
}
}
}
//边框检查超限后重新自动设置起始点
void MainWidgetFunction::funResetStartPoint(QString filePath,DataFilePos pos)
{
if(filePath.length() <= 0)
{
return;
}
s32 beginX,beginY;
beginX = beginY = 0;
beginX = pos.beginX;
beginY = pos.beginY;
if(g_pCurEmbData != NULL)
{
g_pCurEmbData->setStartPosition(beginX,beginY);
}
//边框检查后自动定起始点总是不成功(数据发送失败),所以加了延时已临时解决
QDateTime oldTime = QDateTime::currentDateTime();
while(1)
{
QDateTime curTime = QDateTime::currentDateTime();
if(oldTime.msecsTo(curTime) > 200)
{
break;
}
}
sendPatternHead(filePath);
m_beginX = beginX;
m_beginY = beginY;
//流程复位
g_pMachine->allToReset();
}
void MainWidgetFunction::funSetStartPoint(QString filePath, s32 x, s32 y)
{
if(filePath.length() <= 0)
{
return;
}
int oldBeginX, oldBeginY;
oldBeginX = oldBeginY = 0;
if(g_pCurEmbData != NULL)
{
oldBeginX = g_pCurEmbData->getBeginX();
oldBeginY = g_pCurEmbData->getBeginY();
g_pCurEmbData->setStartPosition(x,y);
}
//将新的起始点写回到文件中
//非定位冲时写入
if(g_emMacType != MACHINE_PUNCH_AUTOPOS)
{
int wx = x - oldBeginX - g_pCurEmbData->getAnchorX();//数据起始点坐标-数据起始点坐标-数据定位点坐标
int wy = y - oldBeginY - g_pCurEmbData->getAnchorY();
writePonitToFile(filePath,wx,wy);
}
m_beginX = x;
m_beginY = y;
#ifdef Q_OS_LINUX
system("sync");
#endif
}
void MainWidgetFunction::funSetAnchorPoint(QString filePath, s32 x, s32 y)
{
if(filePath.length() <= 0)
{
return;
}
if(g_pCurEmbData != NULL)
{
g_pCurEmbData->setAnchorPosition(x,y);
}
//将新的定位点写回到文件中
//等于冲缝绣或冲缝机
if(g_emMacType == MACHINE_PUNCH_SEW_EMB)
{
writePonitToFile(filePath,x,y,1);
}
#ifdef Q_OS_LINUX
system("sync");
#endif
}
//回起始点
void MainWidgetFunction::funBackStartPoint()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Back start point"));//回起始点
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->gotoStartPos();
}
}
}
//边框检查
void MainWidgetFunction::funBorderCheck()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Border check"));//边框检查
int punchXN,punchXP,punchYN,punchYP;
punchXN = punchXP = punchYN = punchYP = 0;
if(g_pMachine != NULL)
{
ParaStruct mcParaValues;
mcParaValues = g_pMachine->getMcPara();
//等于冲缝机或压胶机
if(g_emMacType == MACHINE_ADHESIVE || g_emMacType == MACHINE_PUNCH_SEW || g_emMacType == MACHINE_PUNCH_SEW_EMB)
{
punchXN = mcParaValues.buf[84]; // x可缝纫区域负边界(X-)
punchXP = mcParaValues.buf[85]; // x可缝纫区域正边界(X+)
punchYN = mcParaValues.buf[86]; // y可缝纫区域负边界(Y-)
punchYP = mcParaValues.buf[87]; // y可缝纫区域正边界(Y+)
}
//等于冲孔机或垫板冲孔机
if(g_emMacType == MACHINE_PUNCH || g_emMacType == MACHINE_PUNCH_AUTOPOS)
{
// punchXN = 0; // x可冲孔区域负边界(X-)
// punchXP = 90000; // x可冲孔区域正边界(X+)
// punchYN = 0; // y可冲孔区域负边界(Y-)
// punchYP = 60000; // y可冲孔区域正边界(Y+)
punchXN = mcParaValues.buf[88]; // x可冲孔区域负边界(X-)
punchXP = mcParaValues.buf[89]; // x可冲孔区域正边界(X+)
punchYN = mcParaValues.buf[90]; // y可冲孔区域负边界(Y-)
punchYP = mcParaValues.buf[91]; // y可冲孔区域正边界(Y+)
}
}
QString str1,str2,str3,str4;
if((g_pCurEmbData->getMaxX() / 100) > punchXP / 100) //x+
{
//左边界超限
str1 = tr("Left side out of frame ") + QString::number(g_pCurEmbData->getMaxX() / 100 - punchXP / 100) + " mm"; // 原为m_maxX
}
else
{
str1 = tr("Left side is ok");//左边界正常
}
if((g_pCurEmbData->getMinX() / 100) < punchXN / 100) //x-
{
//右边界超限
str2 = tr("Right side out of frame ") + QString::number(punchXN / 100 - g_pCurEmbData->getMinX() / 100) + " mm"; // yuanwei m_minX
}
else
{
str2 = tr("Right side is ok");//右边界正常
}
if((g_pCurEmbData->getMaxY() / 100) > punchYP / 100) //y+
{
//下边界超限
str3 = tr("Lower side out of frame ") + QString::number(g_pCurEmbData->getMaxY() / 100 - punchYP / 100) + " mm"; // 原为m_maxY
}
else
{
str3 = tr("Lower side is ok");//下边界正常
}
if((g_pCurEmbData->getMinY() / 100) < punchYN / 100) //y- m_minY
{
//上边界超限
str4 = tr("Upper side out of frame ") + QString::number(punchYN / 100 - g_pCurEmbData->getMinY() / 100) + " mm"; // 原为m_minY上面那句也一样
}
else
{
str4 = tr("Upper side is ok");//上边界正常
}
QString str;
str = str1 + "\n" + str2 + "\n" + str3 + "\n"+ str4 + "\n"; // 原为"\n\n",lxs20220627改为\n
//点击确定按钮机器将进行边框检查的动作,点击取消按钮机器不会动作并退出此界面!
str += tr("Click OK button machine will make a frame check, click the Cancel button machine will not move and exit this interface!");
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if((m_mcStatus.workStatus & WORK_STA_BUSY) != 0) // 下位机在执行动作
{
return;
}
g_pMachine->checkFrame(); // 发给下位机,边框检查
}
}
void MainWidgetFunction::funSewHeadCutLine(int nNum)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Sewing machine head thread cutting"));//缝纫机头剪线
QString str;
str = tr("The machine is about to cut the thread, please pay attention to safety!");//机器即将剪线,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->sewCutThread(nNum);
}
}
}
void MainWidgetFunction::funEmbHeadCutLine()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Embroidered machine head thread cutting"));//绣花机头剪线
QString str;
str = tr("The machine is about to cut the thread, please pay attention to safety!");//机器即将剪线,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->embCutThread();
}
}
}
//手动剪线-剪上线
void MainWidgetFunction::funManualTrimUp()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Cutting thread up"));//剪上线
QString str;
str = tr("The machine is about to cut the thread, please pay attention to safety!");//机器即将剪线,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->cutThreadUp();
}
}
}
//手动剪线-剪下线
void MainWidgetFunction::funManualTrimDn()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Cutting thread down"));//剪下线
QString str;
str = tr("The machine is about to cut the thread, please pay attention to safety!");//机器即将剪线,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->cutThreadDn();
}
}
}
//剪刀开合
void MainWidgetFunction::funCutterOpenAndClose()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Upper cutter"));//上剪线
QString str;
str = tr("The scissors are about to move, please pay attention to safety!");//剪刀即将动作,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->manualAction(OT_CUT_UP);
}
}
}
//冲孔换杆归零
void MainWidgetFunction::funPunchRodZero()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Punch rod zero"));//冲孔换杆归零
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->manualAction(PUNCH_CHANGE_ZERO);
}
}
}
void MainWidgetFunction::funPunchManualChangeColor()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_M_C_C);
m_pPromptDlg->setTitleStr(tr("Manual change color"));
m_pPromptDlg->setCurNeedleStrVisible(true);//当前针杆label是否可见 -rq
m_pPromptDlg->initNeedleBar(MACHINE_PUNCH);
if (m_pPromptDlg->exec() == 1)
{
s32 val = m_pPromptDlg->getNeedleSelectIdx();
if(g_pMachine != NULL)
{
g_pMachine->punchSwitchNeedle(val);
}
}
}
void MainWidgetFunction::funEmbManualChangeColor()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_M_C_C);
m_pPromptDlg->setTitleStr(tr("embroidered Manual change color"));
m_pPromptDlg->setCurNeedleStrVisible(true);//当前针杆label是否可见 -rq
m_pPromptDlg->initNeedleBar(MACHINE_PUNCH_SEW_EMB);
if (m_pPromptDlg->exec() == 1)
{
s32 val = m_pPromptDlg->getNeedleSelectIdx();
if(g_pMachine != NULL)
{
g_pMachine->embSwitchNeedle(val);
}
}
}
void MainWidgetFunction::funSinglePunch()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Single punch"));//单次冲孔
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->singlePunch();
}
}
}
void MainWidgetFunction::funWorkPause()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Work Pause"));//暂停工作
QString str;
str = tr("Do you want to suspend machine operation?");//是否暂停机器工作?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->pauseWork();
}
}
}
//空走边框
void MainWidgetFunction::funSimulateFrame()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Simulate frame"));//空走边框
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if((m_mcStatus.workStatus & WORK_STA_BUSY) != 0) // 下位机在执行动作
{
return;
}
g_pMachine->simulateFrame(); // 发给下位机,空走边框
}
}
void MainWidgetFunction::funProcessReset()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Process reset"));//流程复位
QString str;
str = tr("The machine is about to reset, please pay attention to safety!");//机器即将流程复位,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->allToReset();
}
}
}
//框架归零
void MainWidgetFunction::funGotoZeroPos()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Goto zero pos"));//框架归零
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->gotoZeroPos();
}
}
}
//回角点 1、右上2、右下3、左上4、左下
void MainWidgetFunction::funGotoGorner(int nNum)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Goto gorner"));//回角点
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->gotoGorner(nNum);
}
}
}
//定工作范围
void MainWidgetFunction::funSetWorkRange()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Set work range"));//定工作范围
QString str;
str = tr("If automatically set work range?");//是否自动定工作范围?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->autoSetWorkRange();
}
}
}
void MainWidgetFunction::funTestADC()
{
if(g_pMachine != NULL)
{
g_pMachine->testADC(2);
}
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Test adc"));//测试电位器
m_pPromptDlg->setADCContentStr();
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine!=NULL)
{
g_pMachine->testADC(0);
}
}
}
void MainWidgetFunction::funPunchMsDown()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Punch ms down"));//冲头停下位
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->punchMsDown();
}
}
}
void MainWidgetFunction::funDrawOutline()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Draw outline"));//画轮廓线
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->punchDrawOutline();
}
}
}
//自动设置起始点-只有垫板冲孔机(自动定位冲孔机)有这个功能
void MainWidgetFunction::funAutoSetStartPoint(QString filePath)
{
s32 x,y;
x = y = 0;
//等于垫板冲孔机
if(g_emMacType == MACHINE_PUNCH_AUTOPOS)
{
DataFileHead fileHead;
getPatternHeadConfig(filePath,fileHead);
x = fileHead.beginX ;
y = fileHead.beginY ;
}
int oldBeginX, oldBeginY;
oldBeginX = oldBeginY = 0;
if(g_pCurEmbData != NULL)
{
oldBeginX = g_pCurEmbData->getBeginX();
oldBeginY = g_pCurEmbData->getBeginY();
g_pCurEmbData->setStartPosition(x,y);
}
sendPatternHead(filePath);
//将新的起始点写回到文件中
if(g_emMacType == MACHINE_PUNCH_SEW || g_emMacType == MACHINE_PUNCH_SEW_EMB)//等于冲缝机
{
int wx = x - oldBeginX - g_pCurEmbData->getAnchorX();
int wy = y - oldBeginY - g_pCurEmbData->getAnchorY();
writePonitToFile(filePath,wx,wy);
}
m_beginX = x;
m_beginY = y;
//流程复位
if(g_pMachine != NULL)
{
g_pMachine->allToReset();
}
}
void MainWidgetFunction::funContinuousOilSupply()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Continuous oil supply"));//连续供油
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->continuousOilSupply();
}
}
}
//手动加油
void MainWidgetFunction::funManualOil(int nNum)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Manual oil"));//手动加油
QString str;
str = tr("If manual oil?");//是否手动加油?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->manualOil(nNum);
}
}
}
void MainWidgetFunction::sendPatternHead(QString filePath)
{
if(DATA_FORMATE == DATA_DS16)
{
//获取文件头并重新发送文件头
DataDs16FileHead *pDs16Head = g_pCurEmbData->getDsDatHead();
g_pMachine->setFilePara(0, m_curFileID, (DataFilePara&)*pDs16Head);
}
else if(DATA_FORMATE == DATA_DS8)
{
QString ds8FilePath = filePath + ".ds8";
QFile file(ds8FilePath);
if(file.exists())//存在ds8文件
{
if(!file.open(QIODevice::ReadOnly))
{
qDebug() << "open file fail when read";
return;
}
QByteArray ary = file.readAll();
DataDs16FileHead *pDs8Head = (DataDs16FileHead *)(ary.data());
DataDs16FileHead *pDs16Head = g_pCurEmbData->getDsDatHead();
pDs8Head->anchorX = pDs16Head->anchorX;
pDs8Head->anchorY = pDs16Head->anchorY;
pDs8Head->beginX = pDs16Head->beginX;
pDs8Head->beginY = pDs16Head->beginY;
pDs8Head->beginR = pDs16Head->beginR;
//pDs8Head->combineMode = pDs16Head->combineMode;
pDs8Head->maxX = pDs16Head->maxX;
pDs8Head->maxY = pDs16Head->maxY;
pDs8Head->minX = pDs16Head->minX;
pDs8Head->minY = pDs16Head->minY;
memcpy(pDs8Head->switchTable,pDs16Head->switchTable,sizeof(pDs8Head->switchTable));
g_pMachine->setFilePara(0, m_curFileID, (DataFilePara&)*pDs8Head);
file.close();
}
else
{
QByteArray ds16dat = g_pCurEmbData->getDsDat();//获得ds16数据
QByteArray ds8dat;
ds8dat.clear();
// ds16数据
int size = ds16dat.size();
if (size <= (int)sizeof(DataDs16FileHead))
{
qDebug("data less then head size");
return;
}
DataDs16FileHead * pDs16Head = (DataDs16FileHead *)(ds16dat.data());
ds8dat.append((char*)pDs16Head,sizeof(DataDs16FileHead));
int datasize = size - sizeof(DataDs16FileHead);
if (datasize <= 0)
{
qDebug("ds16 dataBegin err");
return;
}
int stepsize = datasize/sizeof(Ds16Item);
if (stepsize <= 0)
{
qDebug("ds16 data size err");
return;
}
Ds16Item *pData = (Ds16Item *)(ds16dat.data() + sizeof(DataDs16FileHead));
Ds16Item * dataPtr = pData;
u8 ctrl,attr;
s16 dx,dy,dr;
Ds8Item ds8Item;
for (int i = 0; i < stepsize; i++)
{
ctrl = dataPtr->ctrl;
attr = dataPtr->attr;
dx = dataPtr->dx;
dy = dataPtr->dy;
dr = dataPtr->dr;
ds8Item.ctrl = ctrl;
ds8Item.attr = attr;
ds8Item.dx = dx;
ds8Item.dy = dy;
ds8Item.dr = dr;
ds8dat.append((char*)&ds8Item,sizeof(Ds8Item));
dataPtr++;
}
//发送ds8数据
DataDs16FileHead * pDs8Head = (DataDs16FileHead *)(ds8dat.data());
Ds8Item *tData = (Ds8Item *)(ds8dat.data() + sizeof(DataDs16FileHead));
//重新生成文件头
pDs8Head->dataSize = pDs8Head->itemNums*sizeof(Ds8Item); // 数据字节数
pDs8Head->bytesPerItem = sizeof(Ds8Item); // 每项占的字节数
pDs8Head->dataChecksum = calcCheckSum32((u8 *)(tData) , pDs8Head->dataSize);; // 数据累加校验和
pDs8Head->checkCrc = calcCrc16((u8 *)(pDs8Head), HEAD_FIX_INFO_LEN); // 前面6个字段的CRC校验6个字段分别为文件名称字节数项个数每项字节数每块字节数数据累加和的CRC校验值
g_pMachine->setFilePara(0, m_curFileID, (DataFilePara&)*pDs8Head);
}
}
}
//选择花样后发送数据并显示大图
void MainWidgetFunction::sendPatternData(QString filePath,int type)
{
m_filePath = filePath;
//保存最后一次的花样路径到配置文件中
if(g_pSettings != NULL)
{
g_pSettings->writeToIniFile("Pattern/name",filePath);
}
if(DATA_FORMATE == DATA_DS16)
{
sendDs16PatternData(type);//发送ds16数据
}
else if(DATA_FORMATE == DATA_DS8)
{
convertDs16ToDs8AndSend(filePath,type);//将ds16数据转换为ds8数据并发送
}
}
void MainWidgetFunction::funFaceDetect()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_FACE);
m_pPromptDlg->setTitleStr(tr("Face line detection"));//面线检测
m_pPromptDlg->setContentStr(tr("Face line detection"));
m_pPromptDlg->exec();
}
void MainWidgetFunction::funExitRoot()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
g_emUser = operate;
m_pPromptDlg->setContentStr(tr("Exit successfully!"));//成功退出!
m_pPromptDlg->exec();
}
void MainWidgetFunction::funGetMCVersionInfo()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("System info"));
m_pPromptDlg->setContentInfoShow();
m_pPromptDlg->exec();
}
void MainWidgetFunction::funProductStatistics(QString tStyle,QString filePath,int patternBreakLineNum)
{
m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("Production statistics"));//生产统计
m_pSystemManageDlg->setSubTitle(tr("Auxiliary Function > Production statistics"));//辅助功能 > 生产统计
m_pSystemManageDlg->initDialog();
m_filePath = filePath;
QFileInfo file(m_filePath);
QString fileName = file.fileName();
m_fileName = fileName;
addProductStatisInfo(patternBreakLineNum);
m_pSystemManageDlg->exec(PRODUCTSTATIS);
}
//错误日志
void MainWidgetFunction::slotJournalError()
{
//m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("Error Log"));//错误日志
m_pSystemManageDlg->setSubTitle(tr("Auxiliary Function > Error Log"));//辅助功能 > 错误日志
m_pSystemManageDlg->initDialog();
addJournalInfoError();
//m_pSystemManageDlg->exec(JOURNALERROR);//显示窗体
}
//断线日志
void MainWidgetFunction::slotJournalBreakage()
{
//m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("Breakage Log"));//断线日志
m_pSystemManageDlg->setSubTitle(tr("Auxiliary Function > Breakage Log"));//辅助功能 > 断线日志
m_pSystemManageDlg->initDialog();
addJournalInfoBreakage();
//m_pSystemManageDlg->exec(JOURNALBREAKAGE);//显示窗体
}
void MainWidgetFunction::slotSpindleTest()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Spindle Gear Ratio Test"));//主轴齿轮比测试
QString str;
str = tr("Whether to test the gear ratio of the spindle?");//是否测试齿轮比?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->spindleTest(0,0);
}
}
}
//错误日志
void MainWidgetFunction::funJournalError(QString tStyle)
{
m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("ErrorLog"));//错误日志
m_pSystemManageDlg->setSubTitle(tr("Auxiliary Function > ErrorLog"));//辅助功能 > 错误日志
m_pSystemManageDlg->initDialog();
addJournalInfoError();
m_pSystemManageDlg->exec(JOURNAL);//显示窗体
}
void MainWidgetFunction::funSoftwareAuthor()
{
if (g_pMachine != NULL)
{
if(g_pMachine->isConnected() == 3)
{
g_pMachine->getInfoFromMachine();
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("No connection"));
m_pPromptDlg->exec();
return;
}
}
// 设置板卡ID值的显示
m_pPromptDlg->initDialog(PromptDialog::BTN_WARRANT);
m_pPromptDlg->setTitleStr(tr("Warrant"));
m_pPromptDlg->setContentWarrantShow();
m_pPromptDlg->exec();
}
//报错信息
int MainWidgetFunction::funErrorPrompt(u32 errcode,QString info)
{
int ret = 0;
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
//QString errInfo= errcode+info;
m_pPromptDlg->setContentStr(info);
if(m_pPromptDlg->exec() == 1)
{
if(errcode == ERR_CHANGE_BOBBIN)
{
g_pMachine->resetBobbinCounter();// 底线计数复位
}
g_pMachine->cleanError();
}
return ret;
}
void MainWidgetFunction::funSetPromptDlgVisibleFalse()
{
if(m_pPromptDlg->isVisible())
{
m_pPromptDlg->done(1);
}
if(m_pBrokenLineDialog->isVisible())//断线检测弹窗消失
{
m_pBrokenLineDialog->hide();
}
}
//底线计数复位
void MainWidgetFunction::funBottomLineCountReset()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("Is the bottom line count reset?")); //是否底线计数复位?
if(m_pPromptDlg->exec() == 1)
{
g_pMachine->resetBobbinCounter(); // 底线计数复位
}
}
void MainWidgetFunction::funResetAll()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Reset all"));//全部复位
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->resetAll();
}
}
}
void MainWidgetFunction::funMotorZeroing()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Motor zeroing"));//电机归零
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->motorZeroing();
}
}
}
void MainWidgetFunction::funStationGluing(int idx)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
if(idx == 1)
{
m_pPromptDlg->setTitleStr(tr("Station 1 gluing"));//工位1涂胶
}
else if(idx == 2)
{
m_pPromptDlg->setTitleStr(tr("Station 2 gluing"));//工位2涂胶
}
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
if(idx == 1)
{
g_pMachine->station1Gluing();
}
else if(idx == 2)
{
g_pMachine->station2Gluing();
}
}
}
}
void MainWidgetFunction::funHeadUpDown()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("head Up Down"));//机头升降
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->headUpDown();
}
}
}
void MainWidgetFunction::funToStationApos(int idx)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
if(idx == 1)
{
m_pPromptDlg->setTitleStr(tr("to Station 1 Apos"));//回工位1起始点
}
else if(idx == 2)
{
m_pPromptDlg->setTitleStr(tr("to Station 2 Apos"));//回工位2起始点
}
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
if(idx == 1)
{
g_pMachine->toStation1Apos();
}
else if(idx == 2)
{
g_pMachine->toStation2Apos();
}
}
}
}
void MainWidgetFunction::funToWaittingPos()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Return to material waiting point"));//回等料点
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->toWaittingPos();
}
}
}
void MainWidgetFunction::funToRemoveGluePos()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Backflow glue point"));//回排胶点
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->toRemoveGluePos();
}
}
}
void MainWidgetFunction::funRemoveGlueOnce()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Discharge glue once"));//排一次胶
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->removeGlueOnce();
}
}
}
void MainWidgetFunction::funAdjustGlueHeight()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Adjust glue height"));//校准胶管高度
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->adjustGlueHeight();
}
}
}
//手自动工作状态切换 0:手动 1:自动
void MainWidgetFunction::funManualOrAutoSwitch(s16 val)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));
if(val == 0)
{
m_pPromptDlg->setContentStr(tr("Are you sure to ManualSwitch?")); //是否手动工作状态切换?
if(m_pPromptDlg->exec() == 1)
{
g_pMachine->setToManualWork();
}
}
else if( val ==1)
{
m_pPromptDlg->setContentStr(tr("Are you sure to AutoSwitch?")); //是否自动工作状态切换?
if(m_pPromptDlg->exec() == 1)
{
g_pMachine->setToAutoWork();
}
}
}
void MainWidgetFunction::getPatternHeadConfig(QString path,DataFileHead & head)
{
memset(&head,0,sizeof(DataFileHead));
QString filePath = path + ".fcg";
QFile file(filePath);
if(file.exists())//存在fcg文件
{
if(file.open(QIODevice::ReadOnly))
{
QByteArray ary = file.readAll();
if((u32)ary.size() >= sizeof(DataFileHead))
{
memcpy(&head,ary.data(),sizeof(DataFileHead));
}
}
file.close();
}
}
void MainWidgetFunction::slotCalMachineProgress(s16 csvCode,s16 type)
{
int per = 0;
int ifPress = 0;
for(int i = 1; i < m_csvFileStrList.size(); i++)
{
QStringList strlist = m_csvFileStrList[i].split(",", QString::SkipEmptyParts); //根据","分隔开每行的列
if(strlist.size() > 0)
{
QString code = strlist.at(COLUMN_CODE);
QStringList strlist1 = code.split("_", QString::SkipEmptyParts); //根据"_"分隔开每行的列
int infoCode = 0;
int csvType = 0;
if(strlist1.size() >= 2)
{
char *bufCode = strdup(strlist1[2].toLatin1().data());
sscanf (bufCode, "%x", &infoCode);
char *bufType = strdup(strlist1[1].toLatin1().data());
sscanf (bufType, "%x", &csvType);
}
if(infoCode == csvCode && type == csvType)
{
QStringList strlist2 = m_csvFileStrList[i].split(",", QString::SkipEmptyParts); //根据","分隔开每行的列
if(COLUMN_PRESSNUM < strlist2.size())
{
ifPress = strlist2.at(COLUMN_PRESSNUM).toInt()+1;
strlist2[COLUMN_PRESSNUM] = QString::number(ifPress);
QString str;
for(int m = 0; m < strlist2.size(); m++)
{
str.append(strlist2[m]);
if(m != strlist2.size() - 1)
{
str.append(",");
}
}
m_csvFileStrList[i] = str;
//如果按钮没被点击过就加入百分比的计算
if(ifPress == 1)
{
per += strlist2.at(COLUMN_SCORE).toInt();
}
}
m_getScore += per;
if(per != 0)
{
if(m_totalScore == 0)
{
m_totalScore = 1;
}
sendDataToGateway(csvCode,type);
}
break;
}
}
}
if(ifPress == 1)
{
QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
QByteArray array;
array.clear();
for(int j = 0; j < m_csvFileStrList.size(); j++)
{
QString str = m_csvFileStrList[j];
array.append(str.toLocal8Bit());
if(j != m_csvFileStrList.size() - 1)
{
array.append('\n');
}
}
QDir apppath(qApp->applicationDirPath());
QString path = apppath.path() + apppath.separator() + CSV_PROGRESS;
QFile file(path);
if (file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
{
file.write(array);
#ifdef Q_OS_LINUX
system("sync");
#endif
}
file.close();
QString iniPath = apppath.path() + apppath.separator() + "config.ini";
QSettings setting(iniPath, QSettings::IniFormat); //QSettings能记录一些程序中的信息下次再打开时可以读取出来
setting.setValue("Progress/getScore",m_getScore); //记录路径到QSetting中保存
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
}
}
void MainWidgetFunction::setPatternHeadConfig(QString path, DataFileHead head)
{
QFile patternFile(path);//花样文件
if(patternFile.exists() == false)//花样文件不存在
{
return;
}
QByteArray fileAry;
fileAry.resize(sizeof(DataFileHead));//数组大小
memset(fileAry.data(),0,fileAry.length());//清空数组
QFile file(path+".fcg");//path当前选择的花样路径//创建 QFile 对象,同时指定要操作的文件
if(file.exists())//存在fcg文件
{
if(file.open(QIODevice::ReadOnly))//只能对文件进行读操作
{
QByteArray ary = file.readAll();
memcpy(fileAry.data(),ary.data(),ary.length());
}
file.close();
}
DataFileHead wHead;
memcpy(&wHead,&head,sizeof(wHead));
//WriteOnly:只能对文件进行写操作,如果目标文件不存在,会自行创建一个新文件。
//Truncate:以重写模式打开,写入的数据会将原有数据全部清除。注意,此打开方式不能单独使用,通常会和 ReadOnly 或 WriteOnly 搭配。
if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
{
qDebug() << "open file fail when wirte, path =" << path;//文件打开失败
return;
}
else
{
memcpy(fileAry.data(),(char*)&wHead,sizeof(DataFileHead));
file.write(fileAry.data(),fileAry.length());
file.close();
}
}
//发送ds16花样数据
void MainWidgetFunction::sendDs16PatternData(int type)
{
QByteArray & ds16dat = g_pCurEmbData->getDsDat();
// ds16数据转换的
int size = ds16dat.size();
if (size <= (int)sizeof(DataDs16FileHead))
{
qDebug("data less then head size");
return;
}
DataDs16FileHead * pDs16Head = (DataDs16FileHead *)(ds16dat.data());
qDebug()<<"fileid 2"<<pDs16Head->fileid;
int datasize = size - sizeof(DataDs16FileHead);
if (datasize <= 0)
{
qDebug("ds16 dataBegin err");
return;
}
int stepsize = datasize/sizeof(Ds16Item);
if (stepsize <= 0)
{
qDebug("ds16 data size err");
return;
}
Ds16Item *pData = (Ds16Item *)(ds16dat.data() + sizeof(DataDs16FileHead));
#if(0)
Ds16Item item;
item.dx = pData->dx;
item.dy = pData->dy;
item.dr = pData->dr;
if(item.dx == 0 && item.dy == 0)
{
ds16dat.remove(0,sizeof(Ds16Item));
pData = (Ds16Item *)(ds16dat.data() + sizeof(DataDs16FileHead));
}
#endif
//发送ds16数据
m_curFileID++;
if ((m_curFileID & 0xffff) == 0)
{
m_curFileID = 1;
}
if(g_pMachine != NULL)
{
g_pMachine->sendFileProc(type, 0, m_curFileID, pDs16Head, (u8*)pData);
}
m_beginX = pDs16Head->beginX;
m_beginY = pDs16Head->beginY;
}
//将ds16数据转换为ds8数据并发送
void MainWidgetFunction::convertDs16ToDs8AndSend(QString filePath,int type)
{
QByteArray ds16dat = g_pCurEmbData->getDsDat();//获得ds16数据
QByteArray ds8dat;
ds8dat.clear();
// ds16数据
int size = ds16dat.size();
if (size <= (int)sizeof(DataDs16FileHead))
{
qDebug("data less then head size");
return;
}
DataDs16FileHead * pDs16Head = (DataDs16FileHead *)(ds16dat.data());
ds8dat.append((char*)pDs16Head,sizeof(DataDs16FileHead));
int datasize = size - sizeof(DataDs16FileHead);
if (datasize <= 0)
{
qDebug("ds16 dataBegin err");
return;
}
int stepsize = datasize/sizeof(Ds16Item);
if (stepsize <= 0)
{
qDebug("ds16 data size err");
return;
}
Ds16Item *pData = (Ds16Item *)(ds16dat.data() + sizeof(DataDs16FileHead));
Ds16Item * dataPtr = pData;
u8 ctrl,attr;
s16 dx,dy,dr;
Ds8Item ds8Item;
for (int i = 0; i < stepsize; i++)
{
ctrl = dataPtr->ctrl;
attr = dataPtr->attr;
dx = dataPtr->dx;
dy = dataPtr->dy;
dr = dataPtr->dr;
ds8Item.ctrl = ctrl;
ds8Item.attr = attr;
ds8Item.dx = dx;
ds8Item.dy = dy;
ds8Item.dr = dr;
ds8dat.append((char*)&ds8Item,sizeof(Ds8Item));
dataPtr++;
}
#if(1)
//保存成ds8文件
QString ds8FilePath = filePath + ".ds8";
QFile file(ds8FilePath);
//边框刺绣不保存ds8数据避免边框刺绣完成后自动加载花样获得ds8文件头不对(还是边框刺绣的文件头)
if(type != FILE_TYPE_FRAME)
{
if(file.exists())//存在ds8文件
{
QFile::remove(ds8FilePath);
}
}
#endif
//发送ds8数据
DataDs16FileHead * pDs8Head = (DataDs16FileHead *)(ds8dat.data());
Ds8Item *tData = (Ds8Item *)(ds8dat.data() + sizeof(DataDs16FileHead));
//重新生成文件头
pDs8Head->dataSize = pDs8Head->itemNums*sizeof(Ds8Item); // 数据字节数
pDs8Head->bytesPerItem = sizeof(Ds8Item); // 每项占的字节数
pDs8Head->dataChecksum = calcCheckSum32((u8 *)(tData) , pDs8Head->dataSize);; // 数据累加校验和
pDs8Head->checkCrc = calcCrc16((u8 *)(pDs8Head), HEAD_FIX_INFO_LEN); // 前面6个字段的CRC校验6个字段分别为文件名称字节数项个数每项字节数每块字节数数据累加和的CRC校验值
m_curFileID++;
if ((m_curFileID & 0xffff) == 0)
{
m_curFileID = 1;
}
g_pMachine->sendFileProc(type, 0, m_curFileID, pDs8Head, (u8*)tData);
m_beginX = pDs8Head->beginX;
m_beginY = pDs8Head->beginY;
#if(1)
//边框刺绣不保存ds8数据避免边框刺绣完成后自动加载花样获得ds8文件头不对(还是边框刺绣的文件头)
if(type != FILE_TYPE_FRAME)
{
if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
{
qDebug() << "open file fail when wirte, path =" << filePath;
return;
}
else
{
file.write(ds8dat);
file.close();
}
}
#endif
}
void MainWidgetFunction::addProductStatisInfo(int patternBreakLineNum)
{
//刷新生产统计信息
m_pSystemManageDlg->initDialog();
QString itemStr = tr("Total number of patterns processed: ") + QString::number(m_mcStatus.outCounter);//总共加工花样数量:
m_pSystemManageDlg->addItem(itemStr);
itemStr = tr("Total punchs: ") + QString::number(m_mcStatus.embNeedleNum);//总冲孔数:
m_pSystemManageDlg->addItem(itemStr);
itemStr = tr("Pattern name: ") + m_fileName;//花样名称:
m_pSystemManageDlg->addItem(itemStr);
itemStr = tr("Pattern break line num: ") + QString::number(patternBreakLineNum);//花样断线次数:
m_pSystemManageDlg->addItem(itemStr);
ParaStruct mcParaValues;
mcParaValues = g_pMachine->getMcPara();
int headNum = mcParaValues.buf[HEADNUMBERIDX];//机头个数
for(int i= 0; i < headNum; i++)
{
//机头断线次数:
itemStr = tr("Head ") + QString::number(i+1) + tr(" break line num: ") + QString::number(m_headBreakLine.headBreakLineNum[i]);// 机头断线次数:
m_pSystemManageDlg->addItem(itemStr);
}
}
void MainWidgetFunction::addJournalInfoError()
{
//刷新信息
m_pSystemManageDlg->initDialog();
m_pSystemManageDlg->addListError();//读取csv列表
}
void MainWidgetFunction::addJournalInfoBreakage()
{
//刷新信息
m_pSystemManageDlg->initDialog();
m_pSystemManageDlg->addListBreakage();//读取csv列表
}
QString MainWidgetFunction::getCompileDateTime()
{
const char *pMonth[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
const char date[12] = __DATE__; // 取编译日期
int i;
int month, year, day;
month = year = day = 0;
for(i = 0; i < 12; i++)
{
if(memcmp(date, pMonth[i], 3) == 0)
{
month = i + 1;
break;
}
}
year = (unsigned char)atoi(date + 9); // date[9]为2位年份, date[7]为完整年份
day = (unsigned char)atoi(date + 4); // 日期
QString str;
str.sprintf("%02d%02d%02d", year, month, day);
return str;
}
//组成json键值对
QString MainWidgetFunction::compositionJson(QString key, QString value)
{
QString mStr="\"";//引号的字符串
QString str = mStr + key + mStr + ":" + mStr + value + mStr + ",";
return str;
}
HMILotData MainWidgetFunction::getHMILotData()
{
HMILotData lotFata;
memset(&lotFata, 0, sizeof(HMILotData));
memcpy(lotFata.HMIVerStr, getVersionStr().data(), getVersionStr().length()); // 版本信息
memcpy(lotFata.fileName, m_fileName.data(), m_fileName.length()); // 文件名称
u32 rackNum = g_pSettings->readFromIniFile("IOT/rackNumber").toInt();//机架号
lotFata.machineNumber = rackNum; // 机架号
QString deliveryTime = g_pSettings->readFromIniFile("IOT/deliveryTime").toString();//工厂预计交货时间
QByteArray arr = deliveryTime.toLocal8Bit();
memcpy(lotFata.deliveryTime, arr.data(), arr.size()); //交货日期
u16 debugProgress = g_pSettings->readFromIniFile("IOT/debugProgress").toInt();//调试进度
lotFata.debugProgress = debugProgress; //调试进度
//电机总数-先固定写为4个如果后续变动较大可把电机个数写为全局变量或从其他cpp中传参
lotFata.motorNum = 4;
return lotFata;
}
void MainWidgetFunction::sendDataToGateway(s16 code,s16 type)
{
QString mStr="\"";//引号的字符串
QString mcType = mStr+U00016+mStr+":"+mStr+"Emb"+mStr+",";
QString mcStr1;
mcStr1.clear();
QString mcStr2;
mcStr2.clear();
if(code == 0 || type == 0){}
QString sensorMotorStr;
sensorMotorStr.clear();
QString timeStr;
timeStr.clear();
#ifdef Q_OS_LINUX
timeStr = QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch() - 28800000);//mcgs下时间差8个小时
#endif
#ifdef Q_OS_WIN
timeStr = QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch());
#endif
QString lotStr;
lotStr.clear();
lotStr = "{" + mStr + QString::number(m_HMILotData.machineNumber) + "#" + mStr + ":[{" +
mStr + "ts" + mStr + ":" + timeStr + "," +
mStr + "values" + mStr + ":{\"timestamp" + mStr + ":" + timeStr + ",\"RackNumber\":\"" + QString::number(m_HMILotData.machineNumber) + "#\"" + ","
+ mcType + mcStr1 + mcStr2 + sensorMotorStr;
lotStr.chop(1);
lotStr += "}}]}";
//qDebug()<<lotStr;
g_pLotMachine->sendLotDataToGateway(lotStr);
}
void MainWidgetFunction::setErrorCodeAndStateList(QList<ErrorCodeStateItem> list)
{
m_errorCodeAndStateItemList.clear();
m_errorCodeAndStateItemList.append(list);
}
//上电计算 关机时间 并发送给主控
void MainWidgetFunction::setShutDownTime()
{
int oldSecond = g_pSettings->readFromIniFile("DateTime/second").toInt();//上次上电的系统时间
QDateTime dateTime = QDateTime::currentDateTime(); //当前时间
int curSecond = dateTime.toTime_t();//单位为秒 //新的时间
int diff = curSecond - oldSecond;//关机秒数
if (diff >= 0)
{
}
else//小于0
{
diff = 5000*3600;
}
qDebug()<<"shutdown second"<<diff;
if(g_pMachine != NULL && oldSecond != 0)
{
g_pMachine->setShutDownTime(0, diff);//可能这个diff太大了
}
}
//设置机器状态
void MainWidgetFunction::setMcStates(MCStatus mcStatus)
{
memset((char*)&m_mcStatus,0,sizeof(MCStatus));
memcpy((char*)&m_mcStatus,(char*)&mcStatus,sizeof(MCStatus));
u32 potval = m_mcStatus.potVal;
float potValue = potval*0.01;
QString potValueStr;
potValueStr.sprintf("%.2f",potValue);
m_pPromptDlg->setPosValueStr(potValueStr);//电位器值
m_pPromptDlg->setCurNeedleStr(QString("%1").arg(m_mcStatus.needleIdx));//当前针杆
}
QString MainWidgetFunction::getVersionStr()
{
QString str;
str.sprintf("RPCE-ALL-XPlatformP-LAUTO-V");
str += getCompileDateTime();
return str;
}
//将起始点或定位点写回到文件中
void MainWidgetFunction::writePonitToFile(QString filePath,int x, int y,int flag)
{
QFileInfo fileInfo(filePath);
QString suffix = fileInfo.suffix().toUpper();//后缀大写
if(suffix == "DST")
{
DataFileDst dst;
dst.initFile(filePath);
dst.loadFile();
dst.writePointToFile(x,y,flag);
}
else if(suffix == "DSR")
{
DataFileDsr dsr;
dsr.initFile(filePath);
dsr.loadFile();
dsr.writePointToFile(x,y,flag);
}
}
//机器信息改变
void MainWidgetFunction::slotMCInfoChange()
{
static int fID = 0;
m_mcStatus = g_pMachine->getMcStatus();
//可使用时长
int workTime = m_mcStatus.workableTimer;
if( workTime > 0 && workTime < INT_MAX )
{
QString strTime;
QString strDay;
QString strHour;
QString strSec;
int day = workTime/(60 *24);
//使用时长不足5天就主动提示用户
if(day < 5 && fID == 0)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
strDay = QString::number(workTime/(60 *24) , 10);
strHour = QString::number((workTime%(60 *24))/60 , 10) ;
strSec = QString::number(workTime%60 , 10);
strTime = strDay + " " + tr("Day") + " " + strHour + " " + tr("Hour") + " " + strSec + " " + tr("Minutes") ; // 天 小时 分钟
//机器剩余可用时间为
str = tr("The remaining available time of the machine is ") + strTime;
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
//开启一个定时器隔4个小时就发一次查询机器状态
m_pTipsTimer->start();
fID++;
}
}
}
//给主控发查询机器信息
void MainWidgetFunction::onTipsTimer()
{
if (g_pMachine != NULL)
{
g_pMachine->getInfoFromMachine();
}
m_pTipsTimer->stop(); //关定时器
}
void MainWidgetFunction::slotSetDynamicIP(QString ssid)
{
if(ssid.length() <= 0)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("ssid is empty!"));//ssid为空
m_pPromptDlg->exec();
return;
}
WordsInputDialog wordInputDlg;
wordInputDlg.wifiClean();
wordInputDlg.setTitleStr(tr("Password input"));//密码输入
wordInputDlg.setOldWordsStr("");
if(wordInputDlg.exec() == 1)
{
#ifdef Q_OS_LINUX
QString psd = wordInputDlg.getInputStr();
//密码不能小于8位(一般密码不允许少于8位)如果写入小于8位的密码系统文件会写入失败造成文件内容丢失会造成wifi列表获取失败
//wifi不需要密码登录的时候也可以点击确认按钮连接wifi
if(psd.length() < 8 && psd.length() > 0)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("The password cannot be less than 8 digits, please check!");//密码不能小于8位请检查
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
//base64解密
//向配置文件写入加密结果设置动态IP
QString iniPath = WIFIINIPATH;
QSettings setting(iniPath,QSettings::IniFormat);
setting.beginGroup("WIFI");
setting.setValue("default_passwd",psd.toLatin1().toBase64());
setting.setValue("default_ssid",ssid.toLatin1().toBase64());
setting.setValue("static_ip","");
setting.setValue("static_mask","");
setting.setValue("static_mode","false");
setting.endGroup();
system("sync");
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("Settings require screen restart to take effect!");//设置需要重启屏幕才生效!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
system("reboot");
}
#endif
}
}
void MainWidgetFunction::slotSetStaticIP(QString ssid, QString psd,QString dnip)
{
if(ssid.length() <= 0)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("ssid is empty!"));//ssid为空
m_pPromptDlg->exec();
return;
}
if(psd.length() <= 0){}//为了去掉编译警告
PassWordDialog passWordDlg;
QString ip;
ip.clear();
passWordDlg.setTitleStr(tr("IP input"),-1);//IP输入
passWordDlg.setShowIfVisible(true);
passWordDlg.setIpStr(dnip);
int rslt = passWordDlg.exec();
if(rslt == 1)
{
ip = passWordDlg.getInputStr();
}
#ifdef Q_OS_LINUX
if(ip.length() <= 0)
{
return;
}
//base64解密
//向配置文件写入加密结果设置静态IP
QString iniPath = WIFIINIPATH;
QSettings setting(iniPath,QSettings::IniFormat);
setting.beginGroup("WIFI");
setting.setValue("default_passwd",psd.toLatin1().toBase64());
setting.setValue("default_ssid",ssid.toLatin1().toBase64());
setting.setValue("static_ip",ip);
setting.setValue("static_mask","255.255.255.0");
setting.setValue("static_mode","true");
setting.endGroup();
system("sync");
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("Settings require screen restart to take effect!");//设置需要重启屏幕才生效!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
system("reboot");
}
return;
#endif
}
void MainWidgetFunction::slotDebugMode()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str;
if (g_emDebugMode == nodebugMode)
{
str = tr("Whether to enter debug mode?");//是否进入调试模式?
}
else
{
str = tr("whether to exit debug mode?");//是否退出调试模式?
}
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if (g_emDebugMode == nodebugMode)
{
g_emDebugMode = debugMode;
}
else //退出了调试模式
{
g_emDebugMode = nodebugMode;//全局的
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str2;
str2 = tr("Please log in to super user again!");//请重新登录超级用户!
m_pPromptDlg->setContentStr(str2);
if(m_pPromptDlg->exec() == 1) //退出超级用户界面
{
emit siCloseRootPara();//关闭超级用户参数界面
}
}
g_pSettings->writeToIniFile("HMI/debugMode",g_emDebugMode);//写入配置文件
emit siDebugState();//主界面接收信号,调试模式时,界面不需要密码,界面标题变红
}
}
void MainWidgetFunction::slotParaReadPrompt(s16 type, s16 value)
{
if(type == PARA_TYPE_HEADPARAMETER && value == 0)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str2;
str2 = tr("read parameter...");//读取参数中...
m_pPromptDlg->setContentStr(str2);
m_pPromptDlg->exec();
}
else if(type == PARA_TYPE_HEADPARAMETER && value != 0)
{
if(m_pPromptDlg->isVisible())
{
m_pPromptDlg->done(1);
}
}
}
//接收到主板的物联网数据
void MainWidgetFunction::slotSendLotData()
{
QString mStr="\"";//引号的字符串
QString lotStr;
lotStr.clear();
QString timeStr;
timeStr.clear();
#ifdef Q_OS_LINUX
//imeStr = QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch() - 28800000);//mcgs下时间差8个小时
timeStr = QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch());
#endif
#ifdef Q_OS_WIN
timeStr = QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch());
#endif
lotStr.clear();
lotStr = "{" + mStr + QString::number(m_HMILotData.machineNumber) + mStr + ":[{" +
mStr + "ts" + mStr + ":" + timeStr + "," +
mStr + "values" + mStr + ":{\"RackNumber\":\"" + QString::number(m_HMILotData.machineNumber) + "\"" + ",";
QString keyStr;
keyStr.clear();
if(g_pLotMachine != NULL)
{
if(g_pMachine == NULL)
{
return;
}
if(m_HMILotData.workState == S0505)
{
m_HMILotData.workState = S0507;
qint64 time = 0;
#ifdef Q_OS_LINUX
time = QDateTime::currentDateTime().toMSecsSinceEpoch() - 28800000;//mcgs下时间差8个小时
#endif
#ifdef Q_OS_WIN
time = QDateTime::currentDateTime().toMSecsSinceEpoch();
#endif
m_HMILotData.endTime = time;
m_HMILotData.startTime = time;
}
if((m_mcStatus.workStatus & WORK_STA_WORKING) == WORK_STA_WORKING)
{
if(m_HMILotData.workState != S0506)
{
qint64 time = 0;
#ifdef Q_OS_LINUX
time = QDateTime::currentDateTime().toMSecsSinceEpoch() - 28800000;//mcgs下时间差8个小时
#endif
#ifdef Q_OS_WIN
time = QDateTime::currentDateTime().toMSecsSinceEpoch();
#endif
m_HMILotData.workState = S0506;
m_HMILotData.startTime = time;
}
keyStr = compositionJson(U00048, QString::number(S0506)); //设备状态
lotStr += keyStr;
}
else
{
if(m_HMILotData.workState != S0507)
{
qint64 time = 0;
#ifdef Q_OS_LINUX
time = QDateTime::currentDateTime().toMSecsSinceEpoch() - 28800000;//mcgs下时间差8个小时
#endif
#ifdef Q_OS_WIN
time = QDateTime::currentDateTime().toMSecsSinceEpoch();
#endif
m_HMILotData.endTime = time;
m_HMILotData.workState = S0507;
}
keyStr = compositionJson(U00049, QString::number(m_HMILotData.startTime)); //开始时间
lotStr += keyStr;
keyStr = compositionJson(U00050, QString::number(m_HMILotData.endTime)); //结束时间
lotStr += keyStr;
int pins = m_HMILotData.endPins - m_HMILotData.startPins;
keyStr = compositionJson(U00051, QString::number(pins)); //区间针数
lotStr += keyStr;
keyStr = compositionJson(U00048, QString::number(S0507)); //设备状态
lotStr += keyStr;
keyStr = compositionJson(U00052, QString::number(m_mcStatus.outCounter)); //产量统计
lotStr += keyStr;
}
keyStr = compositionJson("ts", timeStr); //时间戳
lotStr += keyStr;
if(lotStr.at(lotStr.length()-1) == ',')//去除最后一个逗号
{
lotStr.chop(1); //删除字符串右边n个字符
}
lotStr += "}}]}";
//qDebug()<<lotStr;
//发送物联数据到网关
g_pLotMachine->sendLotDataToGateway(lotStr);
}
}
//执行网关数据动作
void MainWidgetFunction::slotRunLotDataAction(QString str)
{
int cmd = str.toInt();
if(cmd == 1)//点动
{
funSpindleJog();
}
else if(cmd == 2)//剪线
{
funManualTrimUp();
}
}
#if(0)
//当界面与网关建立连接时需要向网关发送固定的键值对
void MainWidgetFunction::slotSendJsonToMqtt()
{
QString mStr="\"";//引号的字符串
QString lotStr;
lotStr.clear();
lotStr += "{" + mStr + "device" + mStr + ":" + mStr + QString::number(m_HMILotData.machineNumber) + "#" + mStr + "}";
if(g_pLotMachine != NULL)
{
g_pLotMachine->sendLotDataToGateway(lotStr);
}
}
#endif
void MainWidgetFunction::slotTransProgress(u8 fileType, int send, int total)
{
int csend = 0;
int ctotal = 0;
if(fileType == FILE_TYPE_PGM)//主控升级文件
{
csend += g_pMachine->getTotalSendNum();
ctotal += g_pMachine->getTotalPacketNum();
if (csend < 0 && ctotal < 0)
{
// 失败
m_pPromptDlg->initDialog(PromptDialog::BTN_UCANCEL);
m_pPromptDlg->setTitleStr(tr("MC Upgrade"));//主控升级
//m_pPromptDlg->setButtonUCancelStr(tr("Close"));//关闭
m_pPromptDlg->setContentProcessStr(tr("Failed to upgrade the main control system!")); //主控系统升级失败!
}
else if (csend == 0 && ctotal == 0)
{
// 成功
m_pPromptDlg->initDialog(PromptDialog::BTN_RESTART);
m_pPromptDlg->setTitleStr(tr("MC Upgrade"));//主控升级
m_pPromptDlg->setContentProcessStr(tr("The main control system has been successed, waiting until machine restart"));
int seconds = 10;//界面重启时间改成10秒
for(int i = 0; i < seconds; i++)
{
QString str = QString(tr("System will restart %1 s later")).arg(seconds-i);//系统将在 %1 秒后重启
m_pPromptDlg->setContentProcessStr(str);
g_pMachine->sleep(1);
}
#ifdef Q_OS_WIN
qApp->exit();
#endif
#ifdef Q_OS_LINUX
system("reboot");
#endif
m_pPromptDlg->hide();
}
else if(csend >= 0 && csend <= ctotal)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_UCANCEL);
m_pPromptDlg->setTitleStr(tr("MC Upgrade"));//主控升级
m_pPromptDlg->setContentProcessStr(tr("Main control system is being upgraded...")); //主控系统升级中...
//m_pPromptDlg->setButtonUCancelStr(tr("Cancel"));//取消
m_pPromptDlg->setRange(0, total);
m_pPromptDlg->setValue(send);
m_pPromptDlg->show();
QCoreApplication::processEvents(QEventLoop::AllEvents);
}
else
{
m_pPromptDlg->hide();
}
}
else
{
if (send < 0 && total < 0)
{
// 失败
m_pPromptDlg->initDialog(PromptDialog::BTN_UCANCEL);
if(fileType == FILE_TYPE_BOARD)//外围板升级文件
{
m_pPromptDlg->setTitleStr(tr("EXB Upgrade"));//外围板升级
//m_pPromptDlg->setButtonUCancelStr(tr("Close"));//关闭
m_pPromptDlg->setContentProcessStr(tr("Perparalboard system upgrade failed!")); //外围板系统升级失败!
}
else if(fileType == FILE_TYPE_DAT || fileType == FILE_TYPE_FRAME)//花样数据文件(边框刺绣文件)
{
m_pPromptDlg->setTitleStr(tr("Prompt"));
//m_pPromptDlg->setButtonUCancelStr(tr("Close"));//关闭
m_pPromptDlg->setContentStr(tr("Failed to send data file!")); //发送数据文件失败!
}
}
else if (send == 0 && total == 0)
{
if(fileType == FILE_TYPE_BOARD)//外围板升级文件
{
// 成功
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("EXB Upgrade"));//外围板升级
//外围板系统升级成功!
m_pPromptDlg->setContentProcessStr(tr("The external board system is upgraded!"));
}
else if(fileType == FILE_TYPE_DAT || fileType == FILE_TYPE_FRAME)//花样数据文件(边框刺绣文件)
{
// 成功
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));//主控升级
m_pPromptDlg->setContentProcessStr(tr("The data file is send successfully!")); //数据文件发送成功!
}
m_pPromptDlg->hide();
}
else if(send >= 0 && send <= total)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_UCANCEL);
if(fileType == FILE_TYPE_BOARD)//外围板升级文件
{
m_pPromptDlg->setTitleStr(tr("EXB Upgrade"));//外围板升级
m_pPromptDlg->setContentProcessStr(tr("The external board system upgrade...")); //外围板系统升级中...
}
else if(fileType == FILE_TYPE_DAT || fileType == FILE_TYPE_FRAME)//花样数据文件(边框刺绣文件)
{
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentProcessStr(tr("Data file sending...")); //数据文件发送中...
}
//m_pPromptDlg->setButtonUCancelStr(tr("Cancel"));//取消
m_pPromptDlg->setRange(0, total);
m_pPromptDlg->setValue(send);
m_pPromptDlg->show();
QCoreApplication::processEvents(QEventLoop::AllEvents);
}
else
{
m_pPromptDlg->hide();
}
}
}
//导出csv文件到U盘
void MainWidgetFunction::slotCsvExport(int logType)
{
QString usbPath = detectUsb();//U盘路径
if(usbPath.length() <= 0)
{
//优盘不存在
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("USB flash drive is not detected!");//未检测到优盘!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
QDir apppath(qApp->applicationDirPath());//D:/work/workQT/XPlatform/Windows/debug
QString newName = usbPath + apppath.separator();//G
QString timeStr = QDateTime::currentDateTime().toString("_yyMMdd_hhmmss");//时间日期 _230215_144121
QString astr;
if(logType == TYPE_ERROR)
{
astr = "error";
}
else if(logType == TYPE_BREAK)
{
astr = "break";
}
QString newFileName = newName+astr+timeStr+".csv";
//csv文件路径
QString csvfile;
if(logType == TYPE_ERROR)
{
csvfile = apppath.path() + apppath.separator() + CSV_ERROR;
}
else if(logType == TYPE_BREAK)
{
csvfile = apppath.path() + apppath.separator() + CSV_BREAK;
}
QString csvfilePath = QDir(csvfile).absolutePath();//为了将"\"变为"/"
bool bl = QFile::copy(csvfilePath,newFileName);
//强制写入
//linux下写入文件或者拷贝、删除文件的情况
#ifdef Q_OS_LINUX
system("sync");
#endif
QString str;
if(bl == true)
{
str = tr("Journal exported successfully!");//文件日志导出成功!
}
else
{
str = tr("Journal exported failed!");//文件日志导出失败!
}
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
str = tr("Journal exported successfully!");//文件日志导出成功!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
void MainWidgetFunction::slotClearJournal()
{
QDir apppath(qApp->applicationDirPath());
QString csvfile = apppath.path() + apppath.separator();
g_pSettings->fileClear(csvfile+CSV_BREAK);//清空文件日志内容,但文件还在
memset(&m_headBreakLine,0,sizeof(HeadBreakLine));
// 刷新文件日志界面信息
m_pSystemManageDlg->initDialog();
m_pSystemManageDlg->exec(JOURNAL);//显示窗体
}
void MainWidgetFunction::slotRefreshWifiList()
{
QStringList wifiStrList;
wifiStrList.clear();
s16 rel = refreshWifiList(wifiStrList,1);
if(rel > 0)
{
m_pSystemManageDlg->setItemList(wifiStrList);
}
}
//清空产量统计
void MainWidgetFunction::slotClearProductStatis()
{
if(g_pMachine != NULL)
{
g_pMachine->resetOutput();//清除产量统计(主控计数)
}
//清空花版断线计数和机头断线计数(花版参数文件.fcg和config.ini中的机头断线次数)
//读取配置文件,初始化机头断线次数
memset(&m_headBreakLine,0,sizeof(HeadBreakLine));
for(u16 i = 0; i < sizeof(m_headBreakLine.headBreakLineNum)/sizeof(s32); i++)
//for(u16 i = 0; i < sizeof(HeadBreakLine)/sizeof(s32); i++)
{
g_pSettings->writeToIniFile(("HeadBreakLineNum/head"+QString::number(i+1)),0);
}
emit siClearPatternBreakLineNum();
addProductStatisInfo(0);//花版断线次数清零
m_pSystemManageDlg->refreshUi();
}
//用户登录
void MainWidgetFunction::slotUserLogin(s16 user)
{
// QTextCodec *cod = QTextCodec::codecForLocale();
PassWordDialog passWordDlg;
QString str("");
if(user == repair)
{
passWordDlg.setTitleStr(tr("Password input *"));//密码输入
}
else if(user == factory)
{
passWordDlg.setTitleStr(tr("Password input **"));//密码输入
}
else if(user == root)
{
passWordDlg.setTitleStr(tr("Password input ***"));//密码输入
}
else if(user == resetpara)
{
passWordDlg.setTitleStr(tr("Password input ****"));//密码输入
}
int rslt = passWordDlg.exec();
if(rslt == 1)
{
str = passWordDlg.getInputStr();
if(user == repair)
{
if (str == g_passwordOne)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
g_emUser = repair;
m_pPromptDlg->setContentStr(tr("Primary password successfully logged in!"));//一级密码成功登入!
m_pPromptDlg->exec();
emit siSetButtonUserLogo(1);
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("The password is wrong,please re-enter!"));//密码错误,请重新输入密码!
m_pPromptDlg->exec();
return;
}
}
else if(user == factory)
{
if (str == PASSWORD_TWO)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
g_emUser = factory;
m_pPromptDlg->setContentStr(tr("Root successfully logged in!"));//超级用户成功登入!
m_pPromptDlg->exec();
emit siSetButtonUserLogo(2);
}
else if (str == PASSWORD_THREE)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
g_emUser = root;
m_pPromptDlg->setContentStr(tr("Three-level password successfully logged in!"));//三级密码成功登入!
m_pPromptDlg->exec();
emit siSetButtonUserLogo(2);
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("The password is wrong,please re-enter!"));//密码错误,请重新输入密码!
m_pPromptDlg->exec();
return;
}
}
else if(user == resetpara)
{
if (str == PASSWORD_RESETPARA)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
g_emUser = resetpara;
m_pPromptDlg->setContentStr(tr("reset parameters password successfully logged in!"));//重置参数密码成功登入!
m_pPromptDlg->exec();
emit siSetButtonUserLogo(2);
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("The password is wrong,please re-enter!"));//密码错误,请重新输入密码!
m_pPromptDlg->exec();
return;
}
}
}
}
//界面解密
void MainWidgetFunction::slotHMIDecrypt(QString id)
{
// 获取网卡号并输入序列号
m_pPromptDlg->initDialog(PromptDialog::BTN_HMI_DECRYPT);
m_pPromptDlg->setTitleStr(tr("HMI decrypt"));
m_pPromptDlg->setContentHMIDecryptShow(id);
if(m_pPromptDlg->exec() == 1)
{
QString inputStr = m_pPromptDlg->getInputPassword();
QByteArray inputAry = inputStr.toLatin1();
QString idStr = m_pPromptDlg->getNetworkCardID();
QByteArray idAry = idStr.toLatin1();
char inputBuf[20]; //输入的注册码
u8 idBuf[12]; //id号16进制字符串
memset(inputBuf,0,sizeof(inputBuf));
memset(idBuf,0,sizeof(idBuf));
memcpy(inputBuf,inputAry.data(),inputStr.toLatin1().length());
memcpy(idBuf,idAry.data(),idStr.toLatin1().length());
char outputBuf[20]; //生成的注册码
int num,i;
u8 anBuf[16],chanBuf[16];
memset(anBuf,0,sizeof(anBuf));
memset(chanBuf,0,sizeof(chanBuf));
memset(outputBuf,0,sizeof(outputBuf));
for(i = 0; i < 4; i++)
{
if((inputBuf[i] >= '0') && (inputBuf[i] <= '9'))
anBuf[i]=inputBuf[i] - '0';
else if((inputBuf[i] >= 'a') && (inputBuf[i] <= 'f'))
anBuf[i]=inputBuf[i] - 'a' + 10;
else if((inputBuf[i] >= 'A') && (inputBuf[i] <= 'F'))
anBuf[i]=inputBuf[i] - 'A' + 10;
else
break;
}
for(u16 i = 0; i < sizeof(idBuf);)
{
if((idBuf[i] >= '0') && (idBuf[i] <= '9'))
idBuf[i]=idBuf[i] - '0';
else if((idBuf[i] >= 'a') && (idBuf[i] <= 'f'))
idBuf[i]=idBuf[i] - 'a' + 10;
else if((idBuf[i] >= 'A') && (idBuf[i] <= 'F'))
idBuf[i]=idBuf[i] - 'A' + 10;
if((idBuf[i+1] >= '0') && (idBuf[i+1] <= '9'))
idBuf[i+1]=idBuf[i+1] - '0';
else if((idBuf[i+1] >= 'a') && (idBuf[i+1] <= 'f'))
idBuf[i+1]=idBuf[i+1] - 'a' + 10;
else if((idBuf[i+1] >= 'A') && (idBuf[i+1] <= 'F'))
idBuf[i+1]=idBuf[i+1] - 'A' + 10;
i += 2;
}
num=((u8)(anBuf[0]*16 + anBuf[1]))*256 + (u8)(anBuf[2]*16 + anBuf[3]);
anBuf[4]=(u8)(((idBuf[0] << 4) | idBuf[1]) + num) >> 4;
anBuf[5]=(u8)(((idBuf[0] << 4) | idBuf[1]) + num) & 0x0f;
anBuf[6]=(u8)(((idBuf[2] << 4) | idBuf[3]) + num) >> 4;
anBuf[7]=(u8)(((idBuf[2] << 4) | idBuf[3]) + num) & 0x0f;
anBuf[8]=(u8)(((idBuf[4] << 4) | idBuf[5]) + num) >> 4;
anBuf[9]=(u8)(((idBuf[4] << 4) | idBuf[5]) + num) & 0x0f;
anBuf[10]=(u8)(((idBuf[6] << 4) | idBuf[7]) + num) >> 4;
anBuf[11]=(u8)(((idBuf[6] << 4) | idBuf[7]) + num) & 0x0f;
anBuf[12]=(u8)(((idBuf[8] << 4) | idBuf[9]) + num) >> 4;
anBuf[13]=(u8)(((idBuf[8] << 4) | idBuf[9]) + num) & 0x0f;
anBuf[14]=(u8)(((idBuf[10] << 4) | idBuf[11]) + num) >> 4;
anBuf[15]=(u8)(((idBuf[10] << 4) | idBuf[11]) + num) & 0x0f;
chanBuf[0]=(u8)(anBuf[0]*16 + anBuf[1]);
chanBuf[1]=(u8)(anBuf[2]*16 + anBuf[3]);
chanBuf[2]=(u8)(anBuf[7]*16 + anBuf[9]);
chanBuf[3]=(u8)(anBuf[6]*16 + anBuf[8]);
chanBuf[4]=(u8)(anBuf[10]*16 + anBuf[15]);
chanBuf[5]=(u8)(anBuf[5]*16 + anBuf[11]);
chanBuf[6]=(u8)(anBuf[13]*16 + anBuf[4]);
chanBuf[7]=(u8)(anBuf[14]*16 + anBuf[12]);
//id号长度大于12以此类推
//chanbuf[8]=(u8)(anbuf[17]*16 + anbuf[16]);
//chanbuf[9]=(u8)(anbuf[19]*16 + anbuf[18]);
//chanbuf[10]=(u8)(anbuf[21]*16 + anbuf[20]);
sprintf(outputBuf,"%02x%02x%02x%02x%02x%02x%02x%02x",chanBuf[0],
chanBuf[1],chanBuf[2],chanBuf[3],chanBuf[4],chanBuf[5],chanBuf[6],chanBuf[7]);
QDir apppath(qApp->applicationDirPath());
QString HMIDecryptConfigfile;
HMIDecryptConfigfile = apppath.path() + apppath.separator() + "HMIDecryptConfig.ini";
QSettings iniSetting(HMIDecryptConfigfile, QSettings::IniFormat);
if( 0 == memcmp(inputBuf, outputBuf, sizeof(inputBuf)) ) // 比较两个缓存区内容是否相同(等于0相等)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("The interface program is licensed, and then take effect after restarting, please restart manually!");//界面程序授权成功,重启后生效,请手动重启!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
iniSetting.setValue("HMIDecrypt/ifdecrypt",1);
return;
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("Password error, interface program authorization failed!");//密码错误,界面程序授权失败!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
//iniSetting.setValue("HMIDecrypt/ifdecrypt",0);
return;
}
}
}
void MainWidgetFunction::slotStrokeCorrection()
{
if(g_pMachine->isConnected() == Connected)//已连接
{
int punchXS = 0;
if(g_pMachine != NULL)
{
ParaStruct mcParaValues;
mcParaValues = g_pMachine->getMcPara();
punchXS = mcParaValues.buf[89]; //x可冲孔区域正边界(X+) 0920 异形旋转冲
}
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("The settings take effect after restarting the interface!");//重启界面后设置生效!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(punchXS != 0)
g_pSettings->writeToIniFile("AUFUS/zeroXcoordinate",punchXS);//归零x坐标
#ifdef Q_OS_WIN
qApp->exit();
#endif
#ifdef Q_OS_LINUX
system("sync");
system("reboot");
#endif
}
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Network error"));
m_pPromptDlg->setContentStr(tr("No connection"));
m_pPromptDlg->exec();
}
}
//自动定软限位
void MainWidgetFunction::slotAutoSetSoftLimit()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Auto set softlimit"));//自动定软限位
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->autoSetSoftLimit();
}
}
}
//动框参数导入
void MainWidgetFunction::slotFrameParaImport()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Moving frame parameter import"));//动框参数导入
QString str;
str = tr("Whether to import movable frame parameters?");//是否动框参数导入?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
m_pSystemManageDlg->setTypeLogo("");
m_pSystemManageDlg->setMainTitle(tr("Frame parameter Import"));
m_pSystemManageDlg->setSubTitle(tr("Root > Frame Parameter Import"));
m_pSystemManageDlg->initDialog();
systemUpgrade(FRAMEPARA_IMPORT);
}
}
//动框参数导出
void MainWidgetFunction::slotFrameParaExport()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Moving frame parameter export"));//动框参数导出
QString str;
str = tr("Whether to export moving frame parameters?");//是否动框参数导出?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
funExportFrameParameter();
}
}
//超级用户退出程序
void MainWidgetFunction::slotExitApp()
{
//是否退出程序
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str;
str = tr("Whether to exit the program?");//是否退出程序?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
QApplication* app;
app->exit(0);
}
}
//超级用户版本恢复
void MainWidgetFunction::slotVerRecovery()
{
//是否版本恢复
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str;
str = tr("Is the version restored?");//是否版本恢复?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
}
}
//删除执行目录下的config.ini
void MainWidgetFunction::slotDeleteIni()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str;
str = tr("Do you delete the configuration file?");//是否删除配置文件?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
QDir apppath(qApp->applicationDirPath());
//配置文件路径
QString configfile;
configfile = apppath.path() + apppath.separator() + "config.ini";
QFile::remove(configfile);
QString HMIConfigfile;
HMIConfigfile = apppath.path() + apppath.separator() + "HMIConfig.ini";
QFile::remove(HMIConfigfile);
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("The settings take effect after restarting the interface!");//重启界面后设置生效!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
#ifdef Q_OS_WIN
qApp->exit();
#endif
#ifdef Q_OS_LINUX
system("reboot");
#endif
}
}
}
//导入csv文件
void MainWidgetFunction::slotImportCSV()
{
QString usbPath = detectUsb();
if(usbPath.length() <= 0)
{
//优盘不存在
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("USB flash drive is not detected!");//未检测到优盘!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
QString sPath = usbPath + CSV_PROGRESS;
QDir apppath(qApp->applicationDirPath());
QString tPath= apppath.absolutePath() + apppath.separator() + CSV_PROGRESS;
QFile::remove(tPath);
QFile::copy(sPath,tPath);
#ifdef Q_OS_LINUX
system("sync");
#endif
//成功导入csv文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("Import csv file successful!");//成功导入csv文件
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
}
//删除csv文件
void MainWidgetFunction::slotDeleteCSV()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str;
str = tr("Do you delete the csv file?");//是否删除csv文件
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
QDir apppath(qApp->applicationDirPath());
//配置文件路径
QString csvfile;
csvfile = apppath.path() + apppath.separator() + CSV_PROGRESS;
QFile::remove(csvfile);
#ifdef Q_OS_LINUX
system("sync");
#endif
}
}
//重置csv文件
void MainWidgetFunction::slotResetCSV()
{
m_csvFileStrList.clear();
QDir apppath(qApp->applicationDirPath());
QString path = apppath.path() + apppath.separator() + CSV_PROGRESS;
QFile file(path);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << "Open file failed!";
return;
}
QTextStream out(&file);
out.setCodec("GB2312"); //支持读取中文信息
//遍历行
for(int i = 0; !out.atEnd(); i++)
{
QString strLine = out.readLine();
if(strLine.size() <= 0)
{
continue;
}
QStringList strlist = strLine.split(",", QString::SkipEmptyParts); //根据","分隔开每行的列
if(COLUMN_PRESSNUM < strlist.size())
{
if(i != 0)
{
strlist[COLUMN_PRESSNUM] = "0";
}
QString str;
for(int m = 0; m < strlist.size(); m++)
{
str.append(strlist[m]);
if(m != strlist.size() - 1)
{
str.append(",");
}
}
m_csvFileStrList.append(str);
}
}
file.close();
QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
QByteArray array;
array.clear();
for(int j = 0; j < m_csvFileStrList.size(); j++)
{
QString str = m_csvFileStrList[j];
array.append(str.toLocal8Bit());
if(j != m_csvFileStrList.size() - 1)
{
array.append('\n');
}
}
QFile wfile(path);
if (wfile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
{
wfile.write(array);
#ifdef Q_OS_LINUX
system("sync");
#endif
}
wfile.close();
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
QString iniPath = apppath.path() + apppath.separator() + "config.ini";
QSettings setting(iniPath, QSettings::IniFormat);
setting.setValue("Progress/getScore",0);
m_getScore = 0;
//成功导入csv文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("Reset succeeded!");//重置成功!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
}
//超级用户花样总清
void MainWidgetFunction::slotPatternClear()
{
//是否花样总清
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str;
str = tr("Is the pattern clear?");//是否花样总清?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{ //删除文件
QDir apppath(qApp->applicationDirPath());
QString targetDir = apppath.absolutePath() + apppath.separator();
QString tPath = targetDir + PATTERNPATH;
deleteDir(tPath);
}
}
void MainWidgetFunction:: deleteDir(QString tPath)
{
QDir dir(tPath);//项目中所保存的路径
dir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);//设置过滤
QFileInfoList fileList = dir.entryInfoList();// 获取所有的文件信息
foreach (QFileInfo file,fileList)//遍历文件信息
{
if (file.isFile()) //是文件,删除,文件夹也要删除
{
file.dir().remove(file.fileName());
}
else //递归删除
{
deleteDir(file.absoluteFilePath());
}
}
dir.rmpath(dir.absolutePath());
//检测是否删除
QDir dir1(tPath);
dir1.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);//设置过滤
QFileInfoList fileList_1 = dir1.entryInfoList();//获取所有的文件信息
if(fileList_1.size() == 0)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("Delete complete!"));//删除完成!
m_pPromptDlg->exec();
emit siClearPattern();//清空当前选择的花样
return;
}
else
{
deleteDir(tPath);
// m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
// m_pPromptDlg->setTitleStr(tr("Prompt"));
// m_pPromptDlg->setContentStr(tr("Not cleaned up!"));//未清理完成!
// m_pPromptDlg->exec();
// return;
}
}
void MainWidgetFunction::slotPatternFcgClear()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str;
str = tr("Is the pattern Fcg clear?");//是否删除花样fcg文件
m_pPromptDlg->setContentStr(str);
//清除所有的fcg花样参数点了确认按钮才会生成新的fcg文件没有fcg文件时花样参数是默认值
if(m_pPromptDlg->exec() == 1)
{
//删除文件
QDir apppath(qApp->applicationDirPath());
QString targetDir = apppath.absolutePath() + apppath.separator();
QString tPath = targetDir + PATTERNPATH;
QDir dir(tPath);//项目中所保存的路径
dir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);//设置过滤
QFileInfoList fileList = dir.entryInfoList(QStringList()<<"*.fcg");// 获取.fcg的文件列表
foreach (QFileInfo file,fileList)//遍历文件信息
{
if (file.isFile()) //是文件,删除
{
file.dir().remove(file.fileName());
}
else //递归删除
{
// deleteDir(file.absoluteFilePath());
}
}
//检测是否删除
QDir dir1(tPath);
dir1.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);//设置过滤
QFileInfoList fileList_1 = dir1.entryInfoList(QStringList()<<"*.fcg");//获取.fcg的文件信息
if(fileList_1.size() == 0)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("Delete complete,please reselect the file!"));//删除完成,请重新选择文件!
m_pPromptDlg->exec();
emit siClearPatternFcg();//清空当前选择的花样
return;
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("Not cleaned up!"));//未清理完成!
m_pPromptDlg->exec();
return;
}
}
}
void MainWidgetFunction::slotPatternFcgClearFileid()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str;
str = tr("If reset the pattern Fcg data?");//是否重置花样fcg文件数据
m_pPromptDlg->setContentStr(str);
//重置所有的fcg数据
if(m_pPromptDlg->exec() == 1)
{
QDir apppath(qApp->applicationDirPath());
QString targetDir = apppath.absolutePath() + apppath.separator();
QString tPath = targetDir + PATTERNPATH;
QDir dir(tPath);//项目中所保存的路径
dir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);//设置过滤
QFileInfoList fileList = dir.entryInfoList(QStringList()<<"*.fcg");// 获取.fcg的文件列表
foreach (QFileInfo file,fileList)//遍历文件信息
{
if (file.isFile()) //是文件,重置
{
//优化不删除将影响fileid的属性置为默认
qDebug() <<"fileList=" <<file.filePath();
QString getTemp_filePath = file.filePath().left(file.filePath().length() - 4);
QString setTemp_filePath = file.filePath().left(file.filePath().length() - 4);
{
//xcy 20230223
DataFileHead temp_fileHead;
getPatternHeadConfig(getTemp_filePath,temp_fileHead);
temp_fileHead.rotateStyle = 0;
temp_fileHead.horizontalStyle = 0;
temp_fileHead.verticalStyle = 0;
temp_fileHead.rotateAngle = 0;
temp_fileHead.xZoom = 100;
temp_fileHead.yZoom = 100;
temp_fileHead.lockNeedlesNum = 2;
temp_fileHead.lockNeedlesStepNum = 1;
temp_fileHead.lockNeedlesStepLength = 100;
setPatternHeadConfig(setTemp_filePath,temp_fileHead);
}
}
else //递归删除
{
// deleteDir(file.absoluteFilePath());
}
}
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("Reset complete,please reselect the file!"));//重置完成,请重新选择文件!
m_pPromptDlg->exec();
emit siAfterDeleteFileid();//清空当前选择的花样
return;
}
}
//win下关机按钮
void MainWidgetFunction::funShutDown()
{
//是否关闭计算机
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str;
str = tr("Whether to shut down the computer?");//是否关闭计算机?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
system("shutdown -s -t 00");//电脑关机
}
}