2024-02-06 06:19:53 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QtConcurrent>
|
|
|
|
|
|
|
|
#define _IN_MAIN_CPP
|
|
|
|
#include "main.h"
|
|
|
|
#include "mainwindow.h"
|
|
|
|
|
2024-03-08 08:33:05 +00:00
|
|
|
QString switchLanguage(int language,QDir appPath)
|
|
|
|
{
|
|
|
|
QString languagePath;
|
|
|
|
switch (language)
|
|
|
|
{
|
|
|
|
case chinese://中文
|
|
|
|
languagePath = appPath.path() + appPath.separator() + "chinese.qm";
|
|
|
|
break;
|
|
|
|
case english://英文
|
|
|
|
languagePath = appPath.path() + appPath.separator() + "english.qm";
|
|
|
|
break;
|
|
|
|
default://中文
|
|
|
|
languagePath = appPath.path() + appPath.separator() + "chinese.qm";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return languagePath;
|
|
|
|
}
|
|
|
|
|
2024-02-06 06:19:53 +00:00
|
|
|
int main(int argc,char *argv[])
|
|
|
|
{
|
|
|
|
QApplication app(argc, argv);
|
|
|
|
|
|
|
|
//支持中文编码
|
|
|
|
QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
|
|
|
|
|
|
|
|
//下位机通讯
|
|
|
|
//上次所连接机器的IP
|
|
|
|
QDir apppath(qApp->applicationDirPath());
|
|
|
|
QString configfile;
|
|
|
|
configfile = apppath.path() + apppath.separator() + "config.ini";
|
|
|
|
QSettings settings(configfile, QSettings::IniFormat);
|
|
|
|
|
|
|
|
QString localIp = "192.168.16.41";
|
|
|
|
quint16 localPort = 5001;
|
|
|
|
|
|
|
|
QFile iniFile(configfile);
|
|
|
|
if(!iniFile.exists())//配置文件不存在
|
|
|
|
{
|
|
|
|
settings.setValue("Local/ip","192.168.16.41");
|
|
|
|
settings.setValue("Local/port",5001);
|
2024-03-08 08:33:05 +00:00
|
|
|
|
|
|
|
settings.setValue("DrawSet/rotate90",0);//是否正向旋转90度
|
|
|
|
settings.setValue("DrawSet/vecfont",0);//是否使用矢量字体
|
|
|
|
settings.setValue("DrawSet/linewidth",2);//线宽
|
|
|
|
settings.setValue("DrawSet/paperwidth",2400);//纸张宽度
|
|
|
|
settings.setValue("DrawSet/rightmargin",0);//右边距
|
|
|
|
settings.setValue("DrawSet/markmargin",20);//马克间距
|
|
|
|
settings.setValue("DrawSet/buttmargin",100);//对接符间距
|
2024-02-06 06:19:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//本地IP和端口
|
|
|
|
localIp = settings.value("Local/ip").toString();
|
|
|
|
localPort = settings.value("Local/port").toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
g_machineList.clear();
|
|
|
|
|
|
|
|
int num = 0;
|
|
|
|
for(int i = 1; i <= MACHINE_NUM; i++)
|
|
|
|
{
|
|
|
|
QString str = "MachineNo" + QString::number(i);
|
|
|
|
QString strKey = str + "/name";
|
|
|
|
bool bl = settings.contains(strKey);
|
|
|
|
if(bl == true)
|
|
|
|
{
|
|
|
|
num++;
|
|
|
|
//建立连接
|
|
|
|
QString mcIp = settings.value(str+"/ip").toString();
|
|
|
|
quint16 mcPort = settings.value(str+"/port").toInt();
|
|
|
|
QString mcName = settings.value(str+"/name").toString();
|
|
|
|
|
|
|
|
Machine *pMachine = new Machine(); //建立连接
|
|
|
|
pMachine->setIpAndPort(mcName,mcIp,mcPort,localIp,localPort);//设置IP和端口
|
|
|
|
pMachine->startCommunication();
|
|
|
|
McPrintInfo mcf;
|
|
|
|
mcf.m_mcNum = num;
|
|
|
|
mcf.m_mcName = mcName;
|
|
|
|
mcf.m_ip = mcIp;
|
|
|
|
mcf.m_port = mcPort;
|
|
|
|
pMachine->m_mcPrintInfo = mcf;
|
|
|
|
g_machineList.append(pMachine);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-08 08:33:05 +00:00
|
|
|
//多语言翻译
|
|
|
|
int language = 0;
|
|
|
|
language = settings.value("HMI/language").toInt();
|
|
|
|
QString languageFile = switchLanguage(language,apppath);
|
|
|
|
g_pTranslator = new QTranslator();
|
|
|
|
g_pTranslator->load(languageFile);
|
|
|
|
qApp->installTranslator(g_pTranslator);
|
|
|
|
|
2024-02-06 06:19:53 +00:00
|
|
|
MainWindow mainWi;
|
|
|
|
mainWi.initAllWinForm();
|
|
|
|
mainWi.show();
|
|
|
|
|
|
|
|
#if(0)
|
|
|
|
#if(1)
|
|
|
|
//有机器连接时才加载自动绘图目录
|
|
|
|
if(machineList.size() > 0)
|
|
|
|
{
|
|
|
|
mainWi.loadAutoPrintDirFiles();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if(machineList.size() > 0)
|
|
|
|
{
|
|
|
|
QtConcurrent::run(&mainWi, &MainWindow::loadAutoPrintDirFiles);//并发线程的使用,为了避免同时加载窗体和加载文件时的窗体卡顿
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
app.exec();
|
|
|
|
return 0;
|
|
|
|
}
|