code_production/app/HGProductionTool/form_maininterface.cpp

831 lines
27 KiB
C++
Raw Normal View History

2022-12-14 06:39:22 +00:00
#include "form_maininterface.h"
#include "ui_form_maininterface.h"
#include <QPainter>
2022-12-16 11:01:30 +00:00
#include <QMessageBox>
#include <QInputDialog>
#include "base/HGBase.h"
2022-12-14 06:39:22 +00:00
#include "imgfmt/HGImgFmt.h"
#include "HGUIGlobal.h"
2022-12-27 08:25:47 +00:00
#include "HGString.h"
2022-12-14 06:39:22 +00:00
#include "form_texttips.h"
2022-12-14 12:28:25 +00:00
#include "test_base.h"
2022-12-16 11:01:30 +00:00
#include "hgscanner.h"
#include "mainwindow.h"
#include "dialog_excepdesc.h"
2022-12-30 02:43:17 +00:00
#include "huagao/hgscanner_error.h"
2022-12-14 06:39:22 +00:00
2023-01-04 12:48:53 +00:00
Form_mainInterface::Form_mainInterface(class MainWindow *mainwnd, Dialog_logIn::LogInType logInType, SANE_Handle handle, HGPdtToolDbUserMgr pdtToolDbuserMgr, HGPdtToolDbDevice pdtToolDbDevice,
2022-12-23 10:32:57 +00:00
const QString &serialNum, const QString &devType, const QString &devName, const QString &devFwNum)
2022-12-16 11:01:30 +00:00
: QWidget(mainwnd)
2022-12-14 06:39:22 +00:00
, ui(new Ui::Form_mainInterface)
2022-12-16 11:01:30 +00:00
, m_mainwnd(mainwnd)
2023-01-04 12:48:53 +00:00
, m_logInType(logInType)
2022-12-26 10:38:34 +00:00
, m_hg(nullptr)
2022-12-16 11:01:30 +00:00
, m_handle(handle)
2022-12-31 04:43:02 +00:00
, m_disconnect(false)
2022-12-17 05:48:03 +00:00
, m_pdtToolDbuserMgr(pdtToolDbuserMgr)
2022-12-16 11:01:30 +00:00
, m_pdtToolDbDevice(pdtToolDbDevice)
, m_serialNum(serialNum)
, m_devType(devType)
2022-12-23 10:32:57 +00:00
, m_devName(devName)
, m_devFwNum(devFwNum)
, m_curItemName("")
, m_isTesting(false)
2023-03-06 09:44:08 +00:00
, m_isCorrectNormal(true)
2023-01-05 10:38:10 +00:00
, m_multiIndex(-1)
, m_curNameIndex(1)
, m_curDpi(0)
, m_distortion_200dpi(0.0)
, m_distortion_300dpi(0.0)
2023-02-28 07:07:31 +00:00
, m_distortion_600dpi(0.0)
2022-12-14 06:39:22 +00:00
{
ui->setupUi(this);
ui->pbtn_showImg->setVisible(false);
2023-01-06 08:18:57 +00:00
ui->pbtn_leftRotate->setVisible(false);
ui->pbtn_rightRotate->setVisible(false);
ui->pbtn_prePage->setVisible(false);
ui->pbtn_nextPage->setVisible(false);
2022-12-28 06:57:00 +00:00
QFont ft;
ft.setPointSize(15);
this->setFont(ft);
2022-12-27 08:25:47 +00:00
connect(this, SIGNAL(testResult(QString)), this, SLOT(on_testResult(QString)), Qt::QueuedConnection);
connect(this, SIGNAL(testResultImg(void*)), this, SLOT(on_testResultImg(void*)), Qt::QueuedConnection);
2023-01-09 10:48:00 +00:00
connect(this, &Form_mainInterface::testDistortion, this, &Form_mainInterface::on_testDistortion);
connect(this, SIGNAL(testCorrectInfo(QString)), this, SLOT(on_testCorrectInfo(QString)), Qt::QueuedConnection);
connect(this, SIGNAL(testGetDevCfgInfo(int,int,int,int,QString,QString)), this, SLOT(on_testGetDevCfgInfo(int,int,int,int,QString,QString)), Qt::QueuedConnection);
connect(this, SIGNAL(testOpenCacheFile(QString)), this, SLOT(on_testOpenCacheFile(QString)), Qt::QueuedConnection);
2022-12-27 08:25:47 +00:00
2022-12-23 10:32:57 +00:00
if (m_handle)
2023-01-03 10:42:08 +00:00
{
m_hg = new hgscanner(this, nullptr, nullptr, m_handle);
2023-01-03 10:42:08 +00:00
}
ui->label_devInfo->setText(tr("Device type:") + m_devType + tr(" SerialNum:") + m_serialNum + " " + tr("FirmwareNum:") + m_devFwNum);
2022-12-23 10:32:57 +00:00
ui->label_speedMode->setText(tr(" speed mode:") + getSpeedMode());
ui->label_sleepTime->setText(tr(" sleep time:") + getSleepTime());
2023-01-06 08:18:57 +00:00
ui->label_vidpid->setText(tr(" VID:") + getDevVid() + tr(" PID:") + getDevPid());
2023-01-06 05:39:49 +00:00
2023-01-05 12:37:01 +00:00
ui->label_imgInfo->setVisible(false);
ui->label_destortionInfo_200dpi->setVisible(false);
ui->label_destortionInfo_300dpi->setVisible(false);
2023-01-05 12:37:01 +00:00
2022-12-23 10:32:57 +00:00
setMinimumWidth(500);
ui->tableWidget->setMinimumWidth(450);
ui->tableWidget->setMaximumWidth(450);
2022-12-14 12:28:25 +00:00
m_textTips = new Form_textTips();
m_view = new HGImgView();
ui->stackedWidget->addWidget(m_textTips);
ui->stackedWidget->addWidget(m_view);
ui->pbtn_showImg->setToolTip(tr("load last image which uploaded last time"));
2022-12-14 12:28:25 +00:00
connect(m_view, SIGNAL(doubleClicked()), this, SLOT(on_viewerDblClick()));
2022-12-23 02:42:46 +00:00
initTableWidgetUi();
2022-12-23 10:32:57 +00:00
if(!m_devType.isEmpty())
HGPdtToolDb_SetDeviceType(m_pdtToolDbDevice, m_devType.toStdString().c_str());
if(!m_devFwNum.isEmpty())
HGPdtToolDb_SetDeviceVersion(m_pdtToolDbDevice, m_devFwNum.toStdString().c_str());
if(!m_devName.isEmpty())
HGPdtToolDb_SetDeviceName(m_pdtToolDbDevice, m_devName.toStdString().c_str());
2022-12-14 06:39:22 +00:00
}
Form_mainInterface::~Form_mainInterface()
{
2023-01-05 10:38:10 +00:00
m_multiIndex = -1;
m_curNameIndex = 1;
2023-01-05 10:38:10 +00:00
m_list_images.clear();
QDir dir(getCachePath());
if (dir.exists())
dir.removeRecursively();
2022-12-26 10:38:34 +00:00
delete m_hg;
m_hg = nullptr;
2022-12-23 10:32:57 +00:00
sane_close(m_handle);
2022-12-26 10:38:34 +00:00
m_handle = nullptr;
2022-12-16 11:01:30 +00:00
HGPdtToolDb_CloseDevice(m_pdtToolDbDevice);
2022-12-26 10:38:34 +00:00
m_pdtToolDbDevice = nullptr;
2022-12-16 11:01:30 +00:00
2022-12-14 06:39:22 +00:00
delete ui;
}
bool Form_mainInterface::isTesting()
{
return m_isTesting;
}
2022-12-16 11:01:30 +00:00
QString Form_mainInterface::getSn()
{
return m_serialNum;
}
2022-12-23 10:32:57 +00:00
QString Form_mainInterface::getDevName()
{
return m_devName;
}
2022-12-26 10:38:34 +00:00
SANE_Handle Form_mainInterface::getDevHandle()
{
return m_handle;
}
hgscanner *Form_mainInterface::getScanner()
{
return m_hg;
}
2022-12-31 04:43:02 +00:00
void Form_mainInterface::setDevDisconnect()
{
m_disconnect = true;
}
2022-12-14 06:39:22 +00:00
void Form_mainInterface::paintEvent(QPaintEvent *event)
{
(void)event;
QPainter p(this);
2023-01-05 10:38:10 +00:00
p.fillRect(0, 0, this->width(), this->height(), qRgb(230, 230, 230));
2022-12-14 06:39:22 +00:00
p.setPen(QColor("gray"));
p.drawRect(0, 0, width() -1, height() -1);
}
2022-12-27 08:25:47 +00:00
void Form_mainInterface::on_testResult(QString text)
{
2023-03-06 09:44:08 +00:00
if (!m_isCorrectNormal)
text += (tr(",but correct information is abnormal"));
if (!text.isEmpty())
QMessageBox::information(this, tr("tips"), text);
updateUiEnabled(true);
m_isTesting = false;
m_mainwnd->releaseTesting();
2022-12-31 04:43:02 +00:00
if (m_disconnect)
{
m_mainwnd->RemoveInterface(this);
}
2022-12-27 08:25:47 +00:00
}
void Form_mainInterface::on_testResultImg(void *img)
{
HGImage image = (HGImage)img;
2023-01-05 10:38:10 +00:00
QString filename = getCacheFileName();
HGImgFmt_SaveImage(image, 0, 0, getStdString(filename).c_str());
2023-01-05 10:38:10 +00:00
m_list_images.push_back(filename);
2023-01-05 10:38:10 +00:00
m_multiIndex = m_list_images.size() - 1;
2022-12-27 08:25:47 +00:00
ui->stackedWidget->setCurrentWidget(m_view);
m_view->addImage(image);
2022-12-28 06:57:00 +00:00
ui->pbtn_leftRotate->setVisible(true);
ui->pbtn_rightRotate->setVisible(true);
ui->pbtn_prePage->setVisible(true);
ui->pbtn_nextPage->setVisible(true);
2022-12-27 08:25:47 +00:00
HGBase_DestroyImage(image);
}
2023-01-09 10:48:00 +00:00
void Form_mainInterface::on_testDistortion(SANE_DISTORTION_VAL data)
2022-12-28 06:57:00 +00:00
{
2023-01-09 10:48:00 +00:00
ui->label_imgInfo->setVisible(true);
ui->label_destortionInfo_200dpi->setVisible(true);
ui->label_destortionInfo_300dpi->setVisible(true);
2023-01-09 10:48:00 +00:00
2023-02-28 07:07:31 +00:00
ui->label_imgInfo->setText(tr("image pixel: ") + QString::number((data.w > 0 && data.w < 9999) ? data.w : 0.0, 'f') +
" * " + QString::number((data.h > 0 && data.h < 9999) ? data.h : 0.0, 'f'));
if (200 == m_curDpi)
{
m_distortion_200dpi = data.scaleXY > 0 ? data.scaleXY : 0;
ui->label_destortionInfo_200dpi->setText(" 200dpi" + tr("destortion value: ") + QString::number(m_distortion_200dpi, 'f'));
2023-01-09 08:45:22 +00:00
if (m_hg != nullptr)
{
m_hg->setDistortValue(m_distortion_200dpi);
}
}
else if (300 == m_curDpi)
{
m_distortion_300dpi = data.scaleXY > 0 ? data.scaleXY : 0;
ui->label_destortionInfo_300dpi->setText(" 300dpi" + tr("destortion value: ") + QString::number(m_distortion_300dpi, 'f'));
if (m_hg != nullptr)
{
m_hg->setDistortValue(m_distortion_300dpi);
}
}
2023-02-28 07:07:31 +00:00
else if (600 == m_curDpi)
{
m_distortion_600dpi = data.scaleXY > 0 ? data.scaleXY : 0;
ui->label_destortionInfo_600dpi->setText(" 600dpi" + tr("destortion value: ") + QString::number(m_distortion_600dpi, 'f'));
if (m_hg != nullptr)
{
m_hg->setDistortValue(m_distortion_600dpi);
}
}
2023-01-09 08:45:22 +00:00
// updateImgPixelInfo();
2022-12-31 04:43:02 +00:00
2023-01-05 12:37:01 +00:00
updateUiEnabled(true);
m_isTesting = false;
m_mainwnd->releaseTesting();
if (m_disconnect)
{
m_mainwnd->RemoveInterface(this);
}
}
void Form_mainInterface::on_testCorrectInfo(QString info)
{
2023-03-06 09:44:08 +00:00
if (info.contains("异常"))
{
m_isCorrectNormal = false;
m_textTips->addContent(info, false);
}
else
{
m_textTips->addContent(info, true);
}
}
void Form_mainInterface::on_testGetDevCfgInfo(int vid, int pid, int sleepTime, int speedMode, QString devSn, QString devFw)
{
char buf[10];
sprintf(buf, "%x", vid);
char buf2[10];
sprintf(buf2, "%x", pid);
QString str = (tr("please verify the configuration of the device:") + "\n\t");
str.append(tr("vid:%1\n\t").arg(QString::fromStdString(buf)));
str.append(tr("pid:%1\n\t").arg(QString::fromStdString(buf2)));
str.append(tr("sleep time:%1minute\n\t").arg(QString::number(sleepTime)));
str.append(tr("speed mode:%1PPM\n\t").arg(QString::number(speedMode)));
str.append(tr("device serial number:%1\n\t").arg(devSn));
str.append(tr("device firmware number:%1").arg(devFw));
m_textTips->setViewContent(str);
}
void Form_mainInterface::on_testOpenCacheFile(QString name)
{
if (name == HGPDTTOOLDB_NAME_IMAGE_GRAY_QUALITY && m_curDpi == 600)
{
if (m_view != nullptr)
{
m_view->doubleClicked();
}
}
}
void Form_mainInterface::on_viewerDblClick()
{
if (m_multiIndex != -1)
{
// QString strFileName = m_list_images[m_multiIndex];
QString cacheFilePath = getCachePath();
QFileInfo fileInfo(cacheFilePath);
auto pathDir = fileInfo.path();
QString strFilePath = "file:///" + pathDir;
QDesktopServices::openUrl(QUrl(strFilePath));
}
}
2022-12-23 02:42:46 +00:00
void Form_mainInterface::on_pbtn_preStep_clicked()
2022-12-14 06:39:22 +00:00
{
2022-12-23 02:42:46 +00:00
int row = ui->tableWidget->currentRow();
if (row > 0)
2022-12-14 06:39:22 +00:00
{
2022-12-23 02:42:46 +00:00
ui->tableWidget->selectRow(row - 1);
2022-12-14 06:39:22 +00:00
}
}
void Form_mainInterface::on_pbtn_nextStep_clicked()
{
2022-12-23 02:42:46 +00:00
int row = ui->tableWidget->currentRow();
if (row < ui->tableWidget->rowCount() - 1)
{
ui->tableWidget->selectRow(row + 1);
}
2022-12-14 06:39:22 +00:00
}
void Form_mainInterface::on_pbtn_fail_clicked()
{
2022-12-23 02:42:46 +00:00
int row = ui->tableWidget->currentRow();
QTableWidgetItem *item = ui->tableWidget->item(row, 1);
2023-01-06 01:47:28 +00:00
if (item != nullptr)
{
2023-01-06 01:47:28 +00:00
QString title = item->text();
2022-12-23 02:42:46 +00:00
2023-01-06 01:47:28 +00:00
Dialog_ExcepDesc dlg(this);
if (dlg.exec())
{
ui->tableWidget->setItem(row, 2, new QTableWidgetItem(getItemStatusStr(HGPDTTOOLDB_ENTRYSTATUS_NOTPASS)));
ui->tableWidget->item(row, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui->tableWidget->item(row, 2)->setBackgroundColor(QColor(255,0,0));
2023-01-06 01:47:28 +00:00
QString str = dlg.getExcepDesc();
std::string name = m_map_title_name.value(title).name.toStdString();
HGPdtToolDb_SetDeviceEntryStatus(m_pdtToolDbDevice, name.c_str(), HGPDTTOOLDB_ENTRYSTATUS_NOTPASS);
HGPdtToolDb_SetDeviceEntryExcepDesc(m_pdtToolDbDevice, name.c_str(), str.toStdString().c_str());
QTableWidgetItem *item2 = ui->tableWidget->item(row, 2);
item2->setToolTip(str);
}
}
2022-12-14 06:39:22 +00:00
}
void Form_mainInterface::on_pbtn_pass_clicked()
{
2022-12-23 02:42:46 +00:00
int row = ui->tableWidget->currentRow();
QTableWidgetItem *item = ui->tableWidget->item(row, 1);
2023-01-06 01:47:28 +00:00
if (item != nullptr)
{
QString title = item->text();
std::string name = m_map_title_name.value(title).name.toStdString();
HGPdtToolDb_SetDeviceEntryStatus(m_pdtToolDbDevice, name.c_str(), HGPDTTOOLDB_ENTRYSTATUS_PASS);
HGPdtToolDb_SetDeviceEntryExcepDesc(m_pdtToolDbDevice, name.c_str(), "");
ui->tableWidget->setItem(row, 2, new QTableWidgetItem(getItemStatusStr(HGPDTTOOLDB_ENTRYSTATUS_PASS)));
ui->tableWidget->item(row, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui->tableWidget->item(row, 2)->setBackgroundColor(QColor(0,255,0));
2022-12-23 02:42:46 +00:00
2023-01-06 01:47:28 +00:00
QTableWidgetItem *item2 = ui->tableWidget->item(row, 2);
item2->setToolTip("");
}
2022-12-23 02:42:46 +00:00
// HGImage img = nullptr;
// m_view->getImage(&img);
// if (img != nullptr)
// {
// QString fileName = getCacheFileName();
// HGResult ret = HGImgFmt_SaveImage(img, 0, 0, getStdString(fileName).c_str());
// if(ret == HGBASE_ERR_OK)
// {
// int row = ui->tableWidget->currentRow();
// QTableWidgetItem *item = ui->tableWidget->item(row, 1);
// QString title = item->text();
// std::string name = m_map_title_name.value(title).name.toStdString();
// HGPdtToolDb_ClearDeviceEntryImage(m_pdtToolDbDevice, name.c_str());
// HGPdtToolDb_UploadDeviceEntryImage(m_pdtToolDbDevice, name.c_str(), m_mainwnd->m_ftpHost.toStdString().c_str(),
// m_mainwnd->m_ftpPort, fileName.toStdString().c_str());
// QFile file(fileName);
// file.remove();
// }
// }
2022-12-28 13:03:01 +00:00
2022-12-14 12:28:25 +00:00
on_pbtn_nextStep_clicked();
2022-12-14 06:39:22 +00:00
}
2022-12-23 02:42:46 +00:00
void Form_mainInterface::on_pbtn_stop_clicked()
2022-12-16 11:01:30 +00:00
{
2022-12-23 02:42:46 +00:00
m_mainwnd->RemoveInterface(this);
}
void Form_mainInterface::initTableWidgetUi()
{
ui->tableWidget->resizeRowsToContents();
ui->tableWidget->setColumnCount(3);
ui->tableWidget->horizontalHeader()->setDefaultSectionSize(200);
ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
QStringList header;
header<< tr("ID") << tr("Test items") << tr("status");
ui->tableWidget->setHorizontalHeaderLabels(header);
QFont font = ui->tableWidget->horizontalHeader()->font();
font.setBold(true);
ui->tableWidget->horizontalHeader()->setFont(font);
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
ui->tableWidget->verticalHeader()->setDefaultSectionSize(10);
ui->tableWidget->setFrameShape(QFrame::NoFrame);
ui->tableWidget->setShowGrid(true);
ui->tableWidget->verticalHeader()->setVisible(false);
ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableWidget->horizontalHeader()->setFixedHeight(30);
ui->tableWidget->clearContents();
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableWidget->setStyleSheet("selection-background-color:rgb(193,210,240)");
2022-12-17 05:48:03 +00:00
HGChar cfgPath[512] = {0};
HGBase_GetConfigPath(cfgPath, 512);
HGBase_CreateDir(cfgPath);
strcat(cfgPath, m_devType.toStdString().c_str());
strcat(cfgPath, ".json");
2022-12-31 09:14:20 +00:00
HGPdtToolDb_DownloadFile(m_pdtToolDbuserMgr, m_devType.toStdString().c_str(), cfgPath);
2022-12-23 02:42:46 +00:00
2022-12-31 09:14:20 +00:00
AnalysisJson analysisJson(QString::fromStdString(cfgPath));
2022-12-23 02:42:46 +00:00
2023-01-04 12:48:53 +00:00
const QString stationStr[] = {"烧录工位", "初检工位", "图像测试工位", "压力测试工位"};
2022-12-23 02:42:46 +00:00
2022-12-31 09:14:20 +00:00
std::vector<AnalysisJson::json_node> list_jsonNode = analysisJson.GetNode();
int count = list_jsonNode.size();
ui->tableWidget->setRowCount(count);
2023-01-04 12:48:53 +00:00
int index = 0;
2022-12-31 09:14:20 +00:00
for(int i = 0; i < count; ++i)
{
AnalysisJson::json_node node = list_jsonNode[i];
m_map_title_name.insert(node.title, node);
2023-01-04 12:48:53 +00:00
if (stationStr[m_logInType] == node.station)
2022-12-31 09:14:20 +00:00
{
2023-01-04 12:48:53 +00:00
HGPdtToolDb_SetEntryNameCnStr(m_pdtToolDbuserMgr, node.name.toStdString().c_str(), node.title.toStdString().c_str());
ui->tableWidget->setItem(index, 0, new QTableWidgetItem(QString::number(index+1)));
ui->tableWidget->item(index, 0)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui->tableWidget->setItem(index, 1, new QTableWidgetItem(node.title));
ui->tableWidget->item(index, 1)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
std::string name = node.name.toStdString();
HGUInt status = 0;
HGPdtToolDb_GetDeviceEntryStatus(m_pdtToolDbDevice, name.c_str(), &status);
QString statusStr = getItemStatusStr(status);
ui->tableWidget->setItem(index, 2, new QTableWidgetItem(statusStr));
ui->tableWidget->item(index, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
if (HGPDTTOOLDB_ENTRYSTATUS_NOTPASS == status)
{
ui->tableWidget->item(index, 2)->setBackgroundColor(QColor(255,0,0));
}
else if (HGPDTTOOLDB_ENTRYSTATUS_NOTSUPP == status)
{
ui->tableWidget->item(index, 2)->setBackgroundColor(QColor(255,255,0));
}
else if (HGPDTTOOLDB_ENTRYSTATUS_PASS == status)
{
ui->tableWidget->item(index, 2)->setBackgroundColor(QColor(0,255,0));
}
HGChar desc[512] = {0};
HGPdtToolDb_GetDeviceEntryExcepDesc(m_pdtToolDbDevice, name.c_str(), desc, 512);
QTableWidgetItem *item = ui->tableWidget->item(index, 2);
item->setToolTip(desc);
++index;
2022-12-23 10:32:57 +00:00
}
2022-12-22 02:48:06 +00:00
}
2022-12-31 09:14:20 +00:00
ui->tableWidget->selectRow(0);
2022-12-16 11:01:30 +00:00
}
2022-12-23 02:42:46 +00:00
QString Form_mainInterface::getItemStatusStr(HGUInt status)
{
static const QString statusStr[] = {tr("not test"), tr("not pass"), tr("not support"), tr("pass") };
return statusStr[status];
}
2022-12-17 05:48:03 +00:00
2022-12-27 08:25:47 +00:00
QString Form_mainInterface::getCachePath()
{
HGChar cachePath[512];
HGBase_GetDocumentsPath(cachePath, 512);
HGChar procName[512];
HGBase_GetProcessName(procName, 512);
strcat(cachePath, procName);
2022-12-27 08:25:47 +00:00
strcat(cachePath, "/Cache/");
return getStdFileName(StdStringToUtf8(cachePath).c_str());
}
QString Form_mainInterface::getCacheFileName()
{
QString cachePath = getCachePath();
cachePath.append(m_serialNum);
cachePath.append("/");
cachePath.append(m_curItemName);
cachePath.append("/");
HGBase_CreateDir(getStdString(getStdFileName(cachePath)).c_str());
2022-12-27 08:25:47 +00:00
QString suffix = ".jpg";
QString fileName = getStdFileName(cachePath + QString::number(m_curNameIndex++) + suffix);
2022-12-27 08:25:47 +00:00
return fileName;
}
QString Form_mainInterface::getCurItemName()
{
return m_curItemName;
}
void Form_mainInterface::updateUiEnabled(bool enable)
{
ui->tableWidget->setEnabled(enable);
ui->pbtn_preStep->setEnabled(enable);
ui->pbtn_nextStep->setEnabled(enable);
ui->pbtn_pass->setEnabled(enable);
ui->pbtn_fail->setEnabled(enable);
ui->pbtn_start->setEnabled(enable);
// ui->pbtn_showImg->setEnabled(enable);
ui->pbtn_leftRotate->setEnabled(enable);
ui->pbtn_rightRotate->setEnabled(enable);
ui->pbtn_stop->setEnabled(enable);
2023-01-05 12:37:01 +00:00
ui->pbtn_prePage->setEnabled(enable);
ui->pbtn_nextPage->setEnabled(enable);
}
void Form_mainInterface::updateImgPixelInfo()
{
ui->label_imgInfo->setVisible(true);
ui->label_destortionInfo_200dpi->setVisible(true);
ui->label_destortionInfo_300dpi->setVisible(true);
2023-01-05 12:37:01 +00:00
HGImage image = NULL;
m_view->getImage(&image);
HGImageInfo imgInfo;
memset(&imgInfo, 0, sizeof(imgInfo));
HGBase_GetImageInfo(image, &imgInfo);
int imgWidth = imgInfo.width;
int imgHeight = imgInfo.height;
if (imgWidth > 0 && imgHeight > 0)
ui->label_imgInfo->setText(tr("image pixel: ") + QString::number(imgWidth) + " * " + QString::number(imgHeight) + " ");
}
QString Form_mainInterface::getSpeedMode()
2023-01-06 05:39:49 +00:00
{
SANE_Int speedMode = 0;
unsigned int len = sizeof(SANE_Int);
sane_io_control(m_handle, IO_CTRL_CODE_GET_SPEED_MODE, &speedMode, &len);
2023-01-06 05:39:49 +00:00
const wchar_t G100[6] = { 70,80,90,110 };
const wchar_t G200[6] = { 100,110,120,130 };
const wchar_t G300[6] = { 40,50,60,70 };
const wchar_t G400[6] = { 40,50,60,70,80 };
int speed = 0;
if (m_devType == "G100")
speed = G100[(int)speedMode - 1];
2023-01-06 05:39:49 +00:00
else if (m_devType == "G200")
speed = G200[(int)speedMode - 1];
2023-01-06 05:39:49 +00:00
else if (m_devType == "G300")
speed = G300[(int)speedMode - 1];
2023-01-06 05:39:49 +00:00
else if (m_devType == "G400")
speed = G400[(int)speedMode - 1];
2023-01-06 05:39:49 +00:00
return QString::number(speed) + "PPM";
}
QString Form_mainInterface::getSleepTime()
2023-01-06 05:39:49 +00:00
{
int sleepTime = SANE_POWER_FIRST;
unsigned int len2 = sizeof(int);
sane_io_control(m_handle, IO_CTRL_CODE_GET_POWER_LEVEL, &sleepTime, &len2);
2023-01-06 05:39:49 +00:00
if (sleepTime > 99999 || sleepTime == -1)
return QString::number(0);
return QString::number(sleepTime / 60) + tr(" minute");
}
QString Form_mainInterface::getDevVid()
2023-01-06 08:18:57 +00:00
{
VIDPID vidpid;
int vidpid_val;
unsigned int len = sizeof(int);
sane_io_control(m_handle, IO_CTRL_CODE_GET_VIDPID, &vidpid_val, &len);
vidpid.Value = vidpid_val;
int vid = vidpid.VID;
char buf[10];
sprintf(buf, "%x", vid);
return QString::fromStdString(buf);
}
QString Form_mainInterface::getDevPid()
{
VIDPID vidpid;
int vidpid_val;
unsigned int len = sizeof(int);
sane_io_control(m_handle, IO_CTRL_CODE_GET_VIDPID, &vidpid_val, &len);
vidpid.Value = vidpid_val;
int pid = vidpid.PID;
char buf[10];
sprintf(buf, "%x", pid);
return QString::fromStdString(buf);
}
int Form_mainInterface::getRollerNum()
{
SANE_Int rollCount = 0;
unsigned int rollCountSize = sizeof(SANE_Int);
SANE_Status ret = sane_io_control(m_handle, IO_CTRL_CODE_GET_ROLLER_NUM, &rollCount, &rollCountSize);
if (ret == SANE_STATUS_GOOD)
return rollCount >= 0 ? rollCount : -1;
else
return -1;
2023-01-06 08:18:57 +00:00
}
int Form_mainInterface::getHistoryCount()
{
SANE_Int historyCount = 0;
unsigned int historyCountSize = sizeof(SANE_Int);
SANE_Status ret = sane_io_control(m_handle, IO_CTRL_CODE_GET_HISTORY_SCAN_NUM, &historyCount, &historyCountSize);
if (ret == SANE_STATUS_GOOD)
return historyCount >= 0 ? historyCount : -1;
else
return -1;
}
2022-12-23 02:42:46 +00:00
void Form_mainInterface::on_tableWidget_currentItemChanged(QTableWidgetItem *current, QTableWidgetItem *previous)
{
2022-12-26 08:24:20 +00:00
(void)previous;
2023-01-05 10:38:10 +00:00
if (current != nullptr)
2023-01-03 10:42:08 +00:00
{
// ui->pbtn_showImg->setVisible(false);
2023-01-05 10:38:10 +00:00
ui->pbtn_leftRotate->setVisible(false);
ui->pbtn_rightRotate->setVisible(false);
2023-01-05 12:37:01 +00:00
ui->pbtn_prePage->setVisible(false);
ui->pbtn_nextPage->setVisible(false);
2023-01-05 10:38:10 +00:00
int row = current->row();
int count = ui->tableWidget->rowCount();
ui->pbtn_preStep->setEnabled(row != 0);
ui->pbtn_nextStep->setEnabled(row != count- 1);
QTableWidgetItem *item2 = ui->tableWidget->item(row, 1);
QString title = item2->text();
m_curItemName = title;
2023-01-05 10:38:10 +00:00
if (nullptr == m_handle)
{
ui->pbtn_start->setVisible(false);
}
else
{
bool man = m_map_title_name.value(title).is_man;
ui->pbtn_start->setEnabled(!man);
}
2022-12-26 08:24:20 +00:00
2023-01-05 10:38:10 +00:00
m_textTips->setViewContent(m_map_title_name.value(title).desc);
ui->stackedWidget->setCurrentWidget(m_textTips);
m_view->clearImage();
QString name = m_map_title_name.value(title).name;
2023-01-05 10:38:10 +00:00
HGUInt imageCount = 0;
HGPdtToolDb_GetDeviceEntryImageCount(m_pdtToolDbDevice, name.toStdString().c_str(), &imageCount);
2023-01-05 10:38:10 +00:00
if (imageCount > 0)
{
// ui->pbtn_showImg->setVisible(true);
2023-01-05 10:38:10 +00:00
}
2023-01-06 01:47:28 +00:00
// m_multiIndex = -1;
// m_curNameIndex = 1;
// m_list_images.clear();
// QDir dir(getCachePath());
// if (dir.exists())
// dir.removeRecursively();
if (name.toStdWString() == HGPDTTOOLDB_NAME_CLEAR_ROLLER_COUNT)
{
QString str(tr("device roller count:") + QString::number(getRollerNum()));
m_textTips->setViewContent(str);
}
if (name.toStdWString() == HGPDTTOOLDB_NAME_CLEAR_HISTORY_COUNT)
{
QString str(tr("device history scan count:") + QString::number(getHistoryCount()));
m_textTips->setViewContent(str);
}
}
2022-12-26 08:24:20 +00:00
}
2022-12-17 05:48:03 +00:00
2022-12-26 08:24:20 +00:00
void Form_mainInterface::on_pbtn_start_clicked()
{
2023-03-06 09:44:08 +00:00
m_isCorrectNormal = true;
2023-01-05 10:38:10 +00:00
m_multiIndex = -1;
m_curNameIndex = 1;
2023-01-05 10:38:10 +00:00
m_list_images.clear();
QString cachePath = getCachePath();
cachePath.append(m_serialNum);
cachePath.append("/");
cachePath.append(m_curItemName);
cachePath.append("/");
QDir dir(getStdString(getStdFileName(cachePath)).c_str());
2023-01-05 10:38:10 +00:00
if (dir.exists())
dir.removeRecursively();
2022-12-26 08:24:20 +00:00
int row = ui->tableWidget->currentRow();
QTableWidgetItem *item = ui->tableWidget->item(row, 1);
2023-01-06 01:47:28 +00:00
if (item != nullptr)
{
QString title = item->text();
QString name = m_map_title_name.value(title).name;
int correct_value = m_map_title_name.value(title).correct_value;
2023-01-09 08:45:22 +00:00
int dpi = m_map_title_name.value(title).resolution;
2023-01-09 10:48:00 +00:00
wchar_t buf[5] = {0};
if (dpi > 0)
{
m_curDpi = dpi;
2023-01-09 10:48:00 +00:00
swprintf(buf, L"%d", dpi);
}
else if (correct_value > -1 && correct_value < 7)
{
swprintf(buf, L"%d", correct_value);
}
2023-01-09 10:48:00 +00:00
2023-01-06 01:47:28 +00:00
if (m_hg != nullptr)
2023-01-06 09:24:49 +00:00
{
updateUiEnabled(false);
m_isTesting = true;
m_mainwnd->addTestingRef();
if (buf != nullptr && (dpi > 0 || (correct_value > -1 && correct_value < 7)))
2023-01-09 10:48:00 +00:00
func_test_go(name.toStdWString().c_str(), (const wchar_t*)buf, m_hg);
2023-01-09 08:45:22 +00:00
else
func_test_go(name.toStdWString().c_str(), L"null", m_hg);
2023-01-06 09:24:49 +00:00
}
if (name == HGPDTTOOLDB_NAME_CLEAR_ROLLER_COUNT)
{
QString str(tr("device roller count:") + QString::number(getRollerNum()));
m_textTips->setViewContent(str);
}
if (name == HGPDTTOOLDB_NAME_CLEAR_HISTORY_COUNT)
{
QString str(tr("device history scan count:") + QString::number(getHistoryCount()));
m_textTips->setViewContent(str);
}
2023-01-06 01:47:28 +00:00
}
2022-12-23 02:42:46 +00:00
}
void Form_mainInterface::on_pbtn_showImg_clicked()
{
// QString fileName = getCacheFileName();
// int row = ui->tableWidget->currentRow();
// QTableWidgetItem *item = ui->tableWidget->item(row, 1);
// QString title = item->text();
// std::string name = m_map_title_name.value(title).name.toStdString();
// HGResult ret = HGPdtToolDb_DownloadDeviceEntryImage(m_pdtToolDbDevice, name.c_str(), m_mainwnd->m_ftpHost.toStdString().c_str(),
// m_mainwnd->m_ftpPort, 0, fileName.toStdString().c_str());
// if(ret == HGBASE_ERR_OK)
// {
// m_list_images.push_back(fileName);
// ui->pbtn_leftRotate->setVisible(true);
// ui->pbtn_rightRotate->setVisible(true);
// ui->pbtn_prePage->setVisible(true);
// ui->pbtn_nextPage->setVisible(true);
// ui->stackedWidget->setCurrentWidget(m_view);
// HGImage img = nullptr;
// HGImgFmt_LoadImage(fileName.toStdString().c_str(), 0, 0, 0, 0, &img);
// m_view->addImage(img);
// m_multiIndex++;
// }
// else
// {
// QMessageBox::information(this, tr("tips"), tr("no image"));
// }
}
2022-12-28 06:57:00 +00:00
void Form_mainInterface::on_pbtn_leftRotate_clicked()
{
m_view->rotateLeft();
}
void Form_mainInterface::on_pbtn_rightRotate_clicked()
{
m_view->rotateRight();
}
2023-01-05 10:38:10 +00:00
void Form_mainInterface::on_pbtn_prePage_clicked()
{
if (m_multiIndex > 0)
--m_multiIndex;
HGImage img = nullptr;
QString filename = m_list_images.at(m_multiIndex);
HGImgFmt_LoadImage(getStdString(filename).c_str(), 0, 0, 0, 0, &img);
2023-01-05 10:38:10 +00:00
if (nullptr != img)
{
m_view->addImage(img);
HGBase_DestroyImage(img);
}
}
void Form_mainInterface::on_pbtn_nextPage_clicked()
{
if (m_multiIndex < m_list_images.size() - 1)
++m_multiIndex;
HGImage img = nullptr;
QString filename = m_list_images.at(m_multiIndex);
HGImgFmt_LoadImage(getStdString(filename).c_str(), 0, 0, 0, 0, &img);
2023-01-05 10:38:10 +00:00
if (nullptr != img)
{
m_view->addImage(img);
HGBase_DestroyImage(img);
}
}