code_production/app/HGProductionTool/mainwindow.cpp

796 lines
23 KiB
C++
Raw Normal View History

#include "mainwindow.h"
2022-12-14 06:39:22 +00:00
#include "ui_mainwindow.h"
#include <QVBoxLayout>
2022-12-22 02:48:06 +00:00
#include <QTimer>
2022-12-14 06:39:22 +00:00
#include "base/HGBase.h"
#include "huagao/brand.h"
#include "huagao/hgscanner_error.h"
2022-12-14 06:39:22 +00:00
#include "HGUIGlobal.h"
2023-09-12 03:02:45 +00:00
#include "app_cfg.h"
2022-12-14 06:39:22 +00:00
#include "dialog_login.h"
#include "dialog_changepwd.h"
#include "dialog_accountmanage.h"
2022-12-14 12:28:25 +00:00
#include "dialog_uploadcfgfile.h"
2022-12-16 11:01:30 +00:00
#include "dialog_inputserialnum.h"
2023-01-10 03:56:10 +00:00
#include "dialog_hgmessagebox.h"
2022-12-14 06:39:22 +00:00
MainWindow::MainWindow(const QString &accountName, Dialog_logIn::DeviceType deviceType, const QString &deviceConfig,
Dialog_logIn::LogInType loginType, QWidget *parent)
2022-12-14 06:39:22 +00:00
: QMainWindow(parent)
, ui(new Ui::MainWindow)
2022-12-26 10:38:34 +00:00
, m_lock(nullptr)
, m_testingRef(0)
, m_accountName(accountName)
, m_deviceType(deviceType)
, m_deviceConfig(deviceConfig)
, m_loginType(loginType)
2023-01-04 06:28:44 +00:00
, m_formBurnMode(nullptr)
2022-12-14 06:39:22 +00:00
, m_top_splitter(nullptr)
, m_bot_splitter(nullptr)
, m_isLogOut(false)
, m_burnDlg(nullptr)
, m_burnForm(nullptr)
2023-01-06 05:39:49 +00:00
, m_inputSnDlg(nullptr)
, m_tmpDevType("")
2022-12-14 06:39:22 +00:00
{
ui->setupUi(this);
2022-12-28 06:57:00 +00:00
ui->act_newDevice->setVisible(false);
ui->act_close->setVisible(false);
ui->act_manage->setVisible(false);
ui->act_export->setVisible(false);
2023-08-31 02:50:43 +00:00
ui->act_upload->setVisible(false);
2023-09-12 03:02:45 +00:00
ui->act_openLog->setVisible(false);
2023-09-01 10:42:28 +00:00
2023-09-12 03:02:45 +00:00
if (m_accountName == "admin")
ui->act_openLog->setVisible(true);
2023-02-08 10:56:36 +00:00
ui->act_refreshDevice->setShortcut(QKeySequence("F5"));
2022-12-28 06:57:00 +00:00
QFont ft;
ft.setPointSize(15);
this->setFont(ft);
2022-12-14 06:39:22 +00:00
setWindowIcon(QIcon(":image/image_rsc/logo/logo.ico"));
2022-12-26 10:38:34 +00:00
HGBase_CreateLock(&m_lock);
2022-12-15 07:00:12 +00:00
connect(this, SIGNAL(sane_dev_arrive(QString)), this, SLOT(on_sane_dev_arrive(QString)), Qt::QueuedConnection);
connect(this, SIGNAL(sane_dev_remove(QString)), this, SLOT(on_sane_dev_remove(QString)), Qt::QueuedConnection);
connect(this, &MainWindow::sane_create_interface, this, &MainWindow::on_sane_create_interface, Qt::QueuedConnection);
2022-12-14 06:39:22 +00:00
if ((m_deviceType == Dialog_logIn::DeviceType_G300 || m_deviceType == Dialog_logIn::DeviceType_G400)
&& m_loginType == Dialog_logIn::LogInType_Station1)
2023-01-04 06:28:44 +00:00
{
m_formBurnMode = new Form_BurnMode(this, this);
2022-12-14 06:39:22 +00:00
2023-01-04 06:28:44 +00:00
QVBoxLayout *vLayout = new QVBoxLayout;
vLayout->addWidget(m_formBurnMode);
this->centralWidget()->setLayout(vLayout);
show();
}
else
{
m_top_splitter = new QSplitter(Qt::Horizontal);
m_bot_splitter = new QSplitter(Qt::Horizontal);
m_top_splitter->setMinimumWidth(600);
m_bot_splitter->setMinimumWidth(600);
m_top_splitter->setChildrenCollapsible(false);
m_bot_splitter->setChildrenCollapsible(false);
QVBoxLayout *vLayout = new QVBoxLayout;
vLayout->addWidget(m_top_splitter);
vLayout->addWidget(m_bot_splitter);
vLayout->setStretch(0, 0);
vLayout->setStretch(1, 0);
this->centralWidget()->setLayout(vLayout);
showMaximized();
}
2022-12-15 09:27:35 +00:00
if (m_deviceType == Dialog_logIn::DeviceType_G300 || m_deviceType == Dialog_logIn::DeviceType_G400)
{
if (m_loginType == Dialog_logIn::LogInType_Station1)
setWindowTitle(tr("production tool-burn station"));
else if (m_loginType == Dialog_logIn::LogInType_Station2)
setWindowTitle(tr("production tool-init test station"));
else if (m_loginType == Dialog_logIn::LogInType_Station3)
setWindowTitle(tr("production tool-image test station"));
}
else
{
if (m_loginType == Dialog_logIn::LogInType_Station1)
setWindowTitle(tr("production tool-init test station"));
else if (m_loginType == Dialog_logIn::LogInType_Station2)
setWindowTitle(tr("production tool-image test station"));
else if (m_loginType == Dialog_logIn::LogInType_Station3)
setWindowTitle(tr("production tool-finish test station"));
}
2022-12-23 02:42:46 +00:00
SANE_Int v = 0;
sane_init_ex(&v, sane_ex_callback, this);
2022-12-15 09:27:35 +00:00
}
2022-12-22 02:48:06 +00:00
MainWindow::~MainWindow()
2022-12-15 09:27:35 +00:00
{
//HGBase_EnterLock(m_lock);
2023-01-04 06:28:44 +00:00
if (m_top_splitter != nullptr)
2022-12-22 02:48:06 +00:00
{
2023-01-04 06:28:44 +00:00
while (0 != m_top_splitter->count())
{
Form_mainInterface * mainInterface = (Form_mainInterface *)m_top_splitter->widget(0);
delete mainInterface;
}
2022-12-22 02:48:06 +00:00
}
2023-01-04 06:28:44 +00:00
if (m_top_splitter != nullptr)
2022-12-22 02:48:06 +00:00
{
2023-01-04 06:28:44 +00:00
while (0 != m_bot_splitter->count())
{
Form_mainInterface * mainInterface = (Form_mainInterface *)m_bot_splitter->widget(0);
delete mainInterface;
}
2022-12-22 02:48:06 +00:00
}
2023-01-04 06:28:44 +00:00
//HGBase_LeaveLock(m_lock);
2022-12-22 02:48:06 +00:00
2022-12-23 10:32:57 +00:00
sane_exit();
2022-12-15 09:27:35 +00:00
2023-01-04 06:28:44 +00:00
delete m_formBurnMode;
m_formBurnMode = nullptr;
2022-12-26 10:38:34 +00:00
HGBase_DestroyLock(m_lock);
m_lock = nullptr;
2022-12-22 02:48:06 +00:00
delete ui;
}
2022-12-14 06:39:22 +00:00
bool MainWindow::isExitApp()
{
return !m_isLogOut;
}
2022-12-16 11:01:30 +00:00
void MainWindow::updateSplitter()
{
if (0 != m_top_splitter->count() && 0 == m_bot_splitter->count())
{
reinterpret_cast<QVBoxLayout*>(this->centralWidget()->layout())->setStretch(0, 1);
reinterpret_cast<QVBoxLayout*>(this->centralWidget()->layout())->setStretch(1, 0);
}
else if (0 == m_top_splitter->count() && 0 != m_bot_splitter->count())
{
reinterpret_cast<QVBoxLayout*>(this->centralWidget()->layout())->setStretch(0, 0);
reinterpret_cast<QVBoxLayout*>(this->centralWidget()->layout())->setStretch(1, 1);
}
else if (0 != m_top_splitter->count() && 0 != m_bot_splitter->count())
{
reinterpret_cast<QVBoxLayout*>(this->centralWidget()->layout())->setStretch(0, 1);
reinterpret_cast<QVBoxLayout*>(this->centralWidget()->layout())->setStretch(1, 1);
}
else
{
reinterpret_cast<QVBoxLayout*>(this->centralWidget()->layout())->setStretch(0, 0);
reinterpret_cast<QVBoxLayout*>(this->centralWidget()->layout())->setStretch(1, 0);
}
}
Form_mainInterface* MainWindow::FindInterface(const QString &sn)
{
for (int i = 0; i < m_top_splitter->count(); ++i)
{
2023-01-04 06:28:44 +00:00
Form_mainInterface * mainInterface = (Form_mainInterface *)m_top_splitter->widget(i);
if (sn == mainInterface->getSn())
2022-12-16 11:01:30 +00:00
{
2023-01-04 06:28:44 +00:00
return mainInterface;
2022-12-16 11:01:30 +00:00
}
}
for (int i = 0; i < m_bot_splitter->count(); ++i)
{
2023-01-04 06:28:44 +00:00
Form_mainInterface * mainInterface = (Form_mainInterface *)m_bot_splitter->widget(i);
if (sn == mainInterface->getSn())
2022-12-16 11:01:30 +00:00
{
2023-01-04 06:28:44 +00:00
return mainInterface;
2022-12-16 11:01:30 +00:00
}
}
return nullptr;
}
2022-12-23 10:32:57 +00:00
Form_mainInterface *MainWindow::FindInterfaceByDevName(const QString &devName)
{
for (int i = 0; i < m_top_splitter->count(); ++i)
{
2023-01-04 06:28:44 +00:00
Form_mainInterface * mainInterface = (Form_mainInterface *)m_top_splitter->widget(i);
if (devName == mainInterface->getDevName())
2022-12-23 10:32:57 +00:00
{
2023-01-04 06:28:44 +00:00
return mainInterface;
2022-12-23 10:32:57 +00:00
}
}
for (int i = 0; i < m_bot_splitter->count(); ++i)
{
2023-01-04 06:28:44 +00:00
Form_mainInterface * mainInterface = (Form_mainInterface *)m_bot_splitter->widget(i);
if (devName == mainInterface->getDevName())
2022-12-23 10:32:57 +00:00
{
2023-01-04 06:28:44 +00:00
return mainInterface;
2022-12-23 10:32:57 +00:00
}
}
return nullptr;
}
2022-12-26 10:38:34 +00:00
Form_mainInterface* MainWindow::FindInterface(SANE_Handle handle)
{
Form_mainInterface *form = nullptr;
for (int i = 0; i < m_top_splitter->count(); ++i)
{
2023-01-04 06:28:44 +00:00
Form_mainInterface * mainInterface = (Form_mainInterface *)m_top_splitter->widget(i);
if (handle == mainInterface->getDevHandle())
2022-12-26 10:38:34 +00:00
{
2023-01-04 06:28:44 +00:00
form = mainInterface;
2022-12-26 10:38:34 +00:00
break;
}
}
if (nullptr == form)
{
for (int i = 0; i < m_bot_splitter->count(); ++i)
{
2023-01-04 06:28:44 +00:00
Form_mainInterface * mainInterface = (Form_mainInterface *)m_bot_splitter->widget(i);
if (handle == mainInterface->getDevHandle())
2022-12-26 10:38:34 +00:00
{
2023-01-04 06:28:44 +00:00
form = mainInterface;
2022-12-26 10:38:34 +00:00
break;
}
}
}
return form;
}
2023-01-04 06:28:44 +00:00
bool MainWindow::AddInterface(Form_mainInterface * mainInterface)
2022-12-16 11:01:30 +00:00
{
2023-01-04 06:28:44 +00:00
assert(nullptr != mainInterface);
2022-12-16 11:01:30 +00:00
//HGBase_EnterLock(m_lock);
2022-12-16 11:01:30 +00:00
bool ret = false;
if (m_top_splitter->count() < 2)
{
2023-01-04 06:28:44 +00:00
m_top_splitter->addWidget(mainInterface);
2022-12-16 11:01:30 +00:00
ret = true;
}
else if (m_bot_splitter->count() < 2)
{
2023-01-04 06:28:44 +00:00
m_bot_splitter->addWidget(mainInterface);
2022-12-16 11:01:30 +00:00
ret = true;
}
//HGBase_LeaveLock(m_lock);
2022-12-16 11:01:30 +00:00
updateSplitter();
return ret;
}
2023-01-04 06:28:44 +00:00
bool MainWindow::RemoveInterface(Form_mainInterface * mainInterface)
2022-12-16 11:01:30 +00:00
{
2023-01-04 06:28:44 +00:00
assert(nullptr != mainInterface);
//HGBase_EnterLock(m_lock);
2023-01-04 06:28:44 +00:00
delete mainInterface;
mainInterface = nullptr;
m_testingRef = 0;
updateActionStatus(true);
//HGBase_LeaveLock(m_lock);
2022-12-16 11:01:30 +00:00
updateSplitter();
return true;
}
void MainWindow::updateActionStatus(bool enable)
{
ui->act_refreshDevice->setEnabled(enable);
ui->act_close->setEnabled(enable);
ui->act_manage->setEnabled(enable);
ui->act_logOut->setEnabled(enable);
ui->act_changePwd->setEnabled(enable);
ui->act_export->setEnabled(enable);
ui->act_upload->setEnabled(enable);
}
void MainWindow::addTestingRef()
{
++m_testingRef;
updateActionStatus(false);
}
void MainWindow::releaseTesting()
{
--m_testingRef;
if (0 == m_testingRef)
{
updateActionStatus(true);
}
}
bool MainWindow::isTesting()
{
return (m_testingRef != 0);
}
void MainWindow::closeEvent(QCloseEvent *event)
{
if (isTesting())
{
QMessageBox::information(this, tr("tips"), tr("Is testing, do not close!"));
event->ignore();
}
}
2022-12-15 07:00:12 +00:00
int MainWindow::sane_ex_callback(SANE_Handle hdev, int code, void *data, unsigned int *len, void *param)
{
2022-12-26 08:24:20 +00:00
MainWindow* p = (MainWindow*)param;
2022-12-26 10:38:34 +00:00
if (SANE_EVENT_DEVICE_ARRIVED == code)
2022-12-26 08:24:20 +00:00
{
SANE_Device_Ex* sane_dev = (SANE_Device_Ex*)data;
2023-01-10 02:07:37 +00:00
2022-12-26 08:24:20 +00:00
emit p->sane_dev_arrive(sane_dev->name);
}
2022-12-26 10:38:34 +00:00
else if (SANE_EVENT_DEVICE_LEFT == code)
2022-12-26 08:24:20 +00:00
{
SANE_Device* sane_dev = (SANE_Device*)data;
emit p->sane_dev_remove(sane_dev->name);
}
2023-12-21 06:54:03 +00:00
else if (SANE_EVENT_IMAGE_OK == code)
{
if (nullptr == p->m_formBurnMode)
2023-12-21 06:54:03 +00:00
{
Form_mainInterface* mainInterface = p->FindInterface(hdev);
if (nullptr != mainInterface)
{
if (nullptr != mainInterface->getScanner() && nullptr != mainInterface->getScanner()->cb_)
mainInterface->getScanner()->cb_(hdev, code, data, len, mainInterface->getScanner());
}
}
}
else if (code == SANE_EVENT_SCAN_FINISHED || code == SANE_EVENT_ERROR || code == SANE_EVENT_STATUS)
2022-12-26 08:24:20 +00:00
{
SaneParams *saneParams = new SaneParams;
saneParams->hdev = hdev;
saneParams->code = code;
2023-12-21 06:54:03 +00:00
char *content = new char[strlen((char*)data) + 1];
memcpy(content, data, strlen((char*)data) + 1);
saneParams->data = content;
saneParams->len = *len;
emit p->sane_create_interface(saneParams);
2022-12-26 10:38:34 +00:00
}
2022-12-26 08:24:20 +00:00
return 0;
2022-12-15 07:00:12 +00:00
}
std::vector<std::string> MainWindow::getDevices()
2022-12-15 03:00:46 +00:00
{
std::vector<std::string> name;
const SANE_Device** devs_list;
SANE_Status status = SANE_STATUS_GOOD;
if ((status = sane_get_devices(&devs_list, SANE_TRUE)) != SANE_STATUS_GOOD)
{
name.push_back("");
return name;
}
name.clear();
while (*devs_list != NULL)
{
name.push_back((*devs_list)->name);
devs_list++;
}
return name;
}
2022-12-16 11:01:30 +00:00
QString MainWindow::getDevSn(SANE_Handle handle)
{
std::string serialNum;
unsigned int serialNumLen = 0;
if(SANE_STATUS_NO_MEM == sane_io_control(handle, IO_CTRL_CODE_GET_SERIAL, nullptr, &serialNumLen) && serialNumLen)
{
serialNum.resize(serialNumLen);
sane_io_control(handle, IO_CTRL_CODE_GET_SERIAL, &serialNum[0], &serialNumLen);
}
return QString::fromStdString(serialNum.c_str());
}
QString MainWindow::getDevType(SANE_Handle handle)
{
std::string firmWareNum;
unsigned int firmWareNumLen = 0;
if(SANE_STATUS_NO_MEM == sane_io_control(handle, IO_CTRL_CODE_GET_HARDWARE_VERSION, nullptr, &firmWareNumLen) && firmWareNumLen)
{
firmWareNum.resize(firmWareNumLen);
sane_io_control(handle, IO_CTRL_CODE_GET_HARDWARE_VERSION, &firmWareNum[0], &firmWareNumLen);
}
QString str = QString::fromStdString(firmWareNum.c_str());
return str.left(2) + "00";
}
2022-12-23 10:32:57 +00:00
QString MainWindow::getDevFwNum(SANE_Handle handle)
{
std::string firmWareNum;
unsigned int firmWareNumLen = 0;
if(SANE_STATUS_NO_MEM == sane_io_control(handle, IO_CTRL_CODE_GET_HARDWARE_VERSION, nullptr, &firmWareNumLen) && firmWareNumLen)
{
firmWareNum.resize(firmWareNumLen);
sane_io_control(handle, IO_CTRL_CODE_GET_HARDWARE_VERSION, &firmWareNum[0], &firmWareNumLen);
}
return QString::fromStdString(firmWareNum.c_str());
}
2022-12-15 07:00:12 +00:00
void MainWindow::on_sane_dev_arrive(QString devName)
2022-12-15 03:00:46 +00:00
{
2022-12-15 07:00:12 +00:00
}
void MainWindow::on_sane_dev_remove(QString devName)
{
if (nullptr != m_formBurnMode)
2022-12-23 10:32:57 +00:00
{
2023-01-04 06:28:44 +00:00
m_formBurnMode->deleteDevice(devName);
}
else
{
if (nullptr != m_burnForm)
{
m_burnForm->deleteDevice(devName);
}
2023-01-06 05:39:49 +00:00
if (nullptr != m_inputSnDlg)
{
m_inputSnDlg->Invalid(devName);
}
2023-01-04 06:28:44 +00:00
Form_mainInterface * mainInterface = FindInterfaceByDevName(devName);
if (mainInterface != nullptr)
2022-12-31 04:43:02 +00:00
{
2023-01-04 06:28:44 +00:00
mainInterface->setDevDisconnect();
//if (!mainInterface->isTesting())
2023-01-04 06:28:44 +00:00
{
RemoveInterface(mainInterface);
}
2022-12-31 04:43:02 +00:00
}
2022-12-23 10:32:57 +00:00
}
2022-12-15 03:00:46 +00:00
}
2022-12-15 07:00:12 +00:00
void MainWindow::on_sane_create_interface(SaneParams *saneParams)
{
if (nullptr == m_formBurnMode)
{
Form_mainInterface* mainInterface = FindInterface(saneParams->hdev);
if (nullptr != mainInterface)
{
if (nullptr != mainInterface->getScanner() && nullptr != mainInterface->getScanner()->cb_)
{
QString info = QString::fromStdString((char*)saneParams->data);
if (info == QString(STATU_DESC_SCANNER_ERR_IMAGE_CORRECTION_FINISHED))
{
int type = 0;
func_test_correct(true, &type);
}
else if (info == QString(STATU_DESC_SCANNER_ERR_IMAGE_CORRECTION_FAIL))
{
int type = 0;
func_test_correct(false, &type);
if (type > 0)
{
mainInterface->checkWrongCorrectItem(type);
}
}
func_test_distortion();
2023-12-21 06:54:03 +00:00
mainInterface->getScanner()->cb_(saneParams->hdev, saneParams->code, saneParams->data, &saneParams->len, mainInterface->getScanner());
}
}
}
2023-12-21 06:54:03 +00:00
delete[] (char*)saneParams->data;
delete saneParams;
saneParams = nullptr;
}
void MainWindow::on_burnmode_refresh_clicked()
2022-12-14 06:39:22 +00:00
{
if (nullptr != m_burnForm)
2022-12-14 06:39:22 +00:00
{
std::vector<std::string> name;
name = getDevices();
m_burnForm->clearDevice();
2022-12-14 06:39:22 +00:00
for (int i = 0; i < name.size(); ++i)
2022-12-16 11:01:30 +00:00
{
SANE_Handle devHandle = nullptr;
sane_open(name[i].c_str(), &devHandle);
if (nullptr != devHandle)
{
DeviceManager *devManager = new DeviceManager(this, m_burnForm, devHandle, m_deviceConfig, name[i].c_str(), getDevSn(devHandle));
m_burnForm->addDevice(devManager);
}
2022-12-16 11:01:30 +00:00
}
2022-12-14 06:39:22 +00:00
}
}
2022-12-14 06:39:22 +00:00
void MainWindow::on_burnmode_ok_clicked()
{
if (nullptr != m_burnDlg)
m_burnDlg->accept();
2023-01-06 05:39:49 +00:00
}
2022-12-14 06:39:22 +00:00
void MainWindow::on_act_manage_triggered()
{
2023-08-31 02:50:43 +00:00
Dialog_accountManage dlg(this);
2022-12-14 06:39:22 +00:00
dlg.exec();
}
void MainWindow::on_act_changePwd_triggered()
{
2023-08-31 02:50:43 +00:00
Dialog_changePwd dlg(m_accountName, this);
2022-12-14 06:39:22 +00:00
dlg.exec();
}
void MainWindow::on_act_logOut_triggered()
{
if (isTesting())
{
QMessageBox::information(this, tr("tips"), tr("Is testing, do not close!"));
return;
}
2022-12-14 06:39:22 +00:00
m_isLogOut = true;
close();
}
void MainWindow::on_act_close_triggered()
{
if (isTesting())
{
QMessageBox::information(this, tr("tips"), tr("Is testing, do not close!"));
return;
}
2022-12-14 06:39:22 +00:00
close();
}
2022-12-16 11:01:30 +00:00
void MainWindow::on_act_upload_triggered()
{
2023-08-31 02:50:43 +00:00
Dialog_uploadCfgFile dlg(this);
2022-12-16 11:01:30 +00:00
dlg.exec();
}
2023-01-05 11:16:17 +00:00
void MainWindow::on_act_refreshDevice_triggered()
{
std::vector<std::string> name;
name = getDevices();
if (nullptr != m_formBurnMode)
{
m_formBurnMode->clearDevice();
for (int i = 0; i < name.size(); ++i)
{
SANE_Handle devHandle = nullptr;
sane_open(name[i].c_str(), &devHandle);
if (nullptr != devHandle)
{
DeviceManager *devManager = new DeviceManager(this, m_formBurnMode, devHandle, m_deviceConfig, name[i].c_str(), getDevSn(devHandle));
m_formBurnMode->addDevice(devManager);
}
}
return;
}
if (m_top_splitter->count() > 0 || m_bot_splitter->count() > 0)
{
return;
}
// G100和G200的初检工位
if (m_loginType == Dialog_logIn::LogInType_Station1)
{
m_burnDlg = new QDialog(this);
m_burnDlg->setWindowTitle(tr("burn mode"));
m_burnDlg->setFixedSize(800, 600);
m_burnDlg->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
QFont ft;
ft.setPointSize(15);
m_burnDlg->setFont(ft);
QVBoxLayout *vLayout = new QVBoxLayout(m_burnDlg);
m_burnForm = new Form_BurnMode(this, m_burnDlg);
vLayout->addWidget(m_burnForm);
QHBoxLayout *hLayout = new QHBoxLayout(m_burnDlg);
hLayout->addStretch();
QPushButton *refreshBtn = new QPushButton(tr("Refresh(F5)"));
refreshBtn->setFixedSize(186, 35);
refreshBtn->setShortcut(QKeySequence("F5"));
connect(refreshBtn, &QPushButton::clicked, this, &MainWindow::on_burnmode_refresh_clicked);
QPushButton *okBtn = new QPushButton(tr("Start Init Test"));
okBtn->setFixedSize(186, 35);
connect(okBtn, &QPushButton::clicked, this, &MainWindow::on_burnmode_ok_clicked);
hLayout->addWidget(refreshBtn);
hLayout->addWidget(okBtn);
vLayout->addLayout(hLayout);
m_burnDlg->setLayout(vLayout);
for (int i = 0; i < name.size(); ++i)
{
SANE_Handle devHandle = nullptr;
sane_open(name[i].c_str(), &devHandle);
if (nullptr != devHandle)
{
DeviceManager *devManager = new DeviceManager(this, m_burnForm, devHandle, m_deviceConfig, name[i].c_str(), getDevSn(devHandle));
m_burnForm->addDevice(devManager);
}
}
bool ok = true;
if (!m_burnDlg->exec())
ok = false;
delete m_burnForm;
m_burnForm = nullptr;
delete m_burnDlg;
m_burnDlg = nullptr;
if (!ok)
{
return;
}
}
2023-01-05 11:16:17 +00:00
for (int i = 0; i < name.size(); ++i)
{
SANE_Handle devHandle = nullptr;
sane_open(name[i].c_str(), &devHandle);
if (nullptr != devHandle)
{
bool canSetSN = false;
if (m_deviceType == Dialog_logIn::DeviceType_G300 || m_deviceType == Dialog_logIn::DeviceType_G400)
{
if (m_loginType == Dialog_logIn::LogInType_Station2)
canSetSN = true;
}
else
{
if (m_loginType == Dialog_logIn::LogInType_Station1)
canSetSN = true;
}
m_inputSnDlg = new Dialog_InputSerialNum(this, name[i].c_str(), m_deviceConfig, m_accountName,
devHandle, getDevSn(devHandle), getDevType(devHandle), canSetSN);
2023-01-06 05:39:49 +00:00
if (m_inputSnDlg->exec())
2023-01-05 11:16:17 +00:00
{
QString logInTypeStr;
if (m_deviceType == Dialog_logIn::DeviceType_G300 || m_deviceType == Dialog_logIn::DeviceType_G400)
{
if (m_loginType == Dialog_logIn::LogInType_Station1)
logInTypeStr = QStringLiteral("烧录工位");
else if (m_loginType == Dialog_logIn::LogInType_Station2)
logInTypeStr = QStringLiteral("初检工位");
else if (m_loginType == Dialog_logIn::LogInType_Station3)
logInTypeStr = QStringLiteral("图像测试工位");
}
else
{
if (m_loginType == Dialog_logIn::LogInType_Station1)
logInTypeStr = QStringLiteral("初检工位");
else if (m_loginType == Dialog_logIn::LogInType_Station2)
logInTypeStr = QStringLiteral("图像测试工位");
else if (m_loginType == Dialog_logIn::LogInType_Station3)
logInTypeStr = QStringLiteral("成品检验工位");
}
2023-01-05 11:16:17 +00:00
Form_mainInterface *mainInterface = new Form_mainInterface(this, m_deviceConfig, m_accountName, devHandle,
m_inputSnDlg->GetSn(), m_inputSnDlg->GetDevType(), name[i].c_str(), getDevFwNum(devHandle), logInTypeStr);
2023-01-05 11:16:17 +00:00
if (!AddInterface(mainInterface))
{
QMessageBox::information(this, tr("tips"), tr("cannot create more table"));
delete mainInterface;
}
m_tmpDevType = getDevType(devHandle);
2023-01-05 11:16:17 +00:00
}
else
{
sane_close(devHandle);
}
2023-01-06 05:39:49 +00:00
delete m_inputSnDlg;
m_inputSnDlg = nullptr;
2023-01-05 11:16:17 +00:00
}
}
}
void MainWindow::on_act_openLog_triggered()
{
HGChar logPath[512];
HGBase_GetDocumentsPath(logPath, 512);
HGChar procName[512];
HGBase_GetProcessName(procName, 512);
strcat(logPath, procName);
strcat(logPath, "/Test_Log/");
2023-09-12 03:02:45 +00:00
QString defaultFileName = logPath + m_accountName + ".log";
QString fileName = getCfgValue(m_tmpDevType.toStdString().c_str(), "logPath", defaultFileName);
QFileInfo fileInfo(getStdFileName(fileName));
auto pathDir = fileInfo.path();
QString strFilePath = "file:///" + pathDir;
QDesktopServices::openUrl(QUrl(strFilePath));
}
static bool isLeap(int year)
{
if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))
return true;
return false;
}
static int getDays(int year, int month)
{
if (2 == month)
{
if (isLeap(year))
return 29;
else
return 28;
}
if (4 == month || 6 == month || 9 == month || 11 == month)
{
return 30;
}
return 31;
}
static int getPatchVersion()
{
const char *buildDate = __DATE__;
QDate date = QLocale(QLocale::English).toDate(QString(buildDate).replace(" ", " 0"), "MMM dd yyyy");
int year = date.year();
int day = date.day();
int month = date.month();
int ret = year % 100;
ret *= 1000;
for (int i = 1; i < month; ++i)
{
ret += getDays(year, i);
}
ret += day;
return ret;
}
void MainWindow::on_act_about_triggered()
{
int mainVersion = VERSION_MAIN;
int subVersion = VERSION_SUB;
int buildVersion = 10000;
int patchVersion = 0;
patchVersion = getPatchVersion();
HGChar version[32] = { 0 };
sprintf(version, "%d.%d.%d.%d", mainVersion, subVersion, buildVersion, patchVersion);
QString title = tr("about %1").arg(tr("Production tool"));
QString content;
content += tr("<p>DriverVer: %1</p>").arg(QString::fromLocal8Bit(version));
QMessageBox::about(this, title, content);
}