#include "form_maininterface.h" #include "ui_form_maininterface.h" #include #include #include #include "base/HGBase.h" #include "base/HGInfo.h" #include "imgfmt/HGImgFmt.h" #include "HGUIGlobal.h" #include "HGString.h" #include "form_texttips.h" #include "test_base.h" #include "app_cfg.h" #include "hgscanner.h" #include "mainwindow.h" #include "dialog_excepdesc.h" #include "huagao/hgscanner_error.h" Form_mainInterface::Form_mainInterface(class MainWindow *mainwnd, Dialog_logIn::LogInType logInType, const QString &profileName, const QString &accountName, SANE_Handle handle, const QString &serialNum, const QString &devType, const QString &devName, const QString &devFwNum) : QWidget(mainwnd) , ui(new Ui::Form_mainInterface) , m_mainwnd(mainwnd) , m_logInType(logInType) , m_accountName(accountName) , m_profileName(profileName) , m_hg(nullptr) , m_handle(handle) , m_disconnect(false) , m_serialNum(serialNum) , m_devType(devType) , m_devName(devName) , m_devFwNum(devFwNum) , m_curItemName("") , m_isTesting(false) , m_isCorrectNormal(true) , m_multiIndex(-1) , m_curNameIndex(1) , m_curDpi(0) , m_distortion_200dpi(0.0) , m_distortion_300dpi(0.0) , m_distortion_600dpi(0.0) { ui->setupUi(this); ui->pbtn_showImg->setVisible(false); ui->pbtn_leftRotate->setVisible(false); ui->pbtn_rightRotate->setVisible(false); ui->pbtn_prePage->setVisible(false); ui->pbtn_nextPage->setVisible(false); QFont ft; ft.setPointSize(15); this->setFont(ft); connect(this, SIGNAL(testResult(QString)), this, SLOT(on_testResult(QString)), Qt::QueuedConnection); connect(this, SIGNAL(testResultImg(void*)), this, SLOT(on_testResultImg(void*)), Qt::QueuedConnection); 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,QString)), this, SLOT(on_testGetDevCfgInfo(int,int,int,int,QString,QString,QString)), Qt::QueuedConnection); connect(this, SIGNAL(testOpenCacheFile(QString)), this, SLOT(on_testOpenCacheFile(QString)), Qt::QueuedConnection); connect(this, SIGNAL(testGetDevCpuDisk(QString,QString)), this, SLOT(on_testGetDevCpuDisk(QString,QString)), Qt::QueuedConnection); if (m_handle) { m_hg = new hgscanner(this, nullptr, nullptr, m_handle); } ui->label_devInfo->setText(tr("Device type:") + m_devType + tr(" SerialNum:") + m_serialNum + " " + tr("FirmwareNum:") + m_devFwNum); ui->label_speedMode->setText(tr(" speed mode:") + getSpeedMode()); ui->label_sleepTime->setText(tr(" sleep time:") + getSleepTime()); ui->label_vidpid->setText(tr(" VID:") + getDevVid() + tr(" PID:") + getDevPid()); ui->label_imgInfo->setVisible(false); ui->label_destortionInfo_200dpi->setVisible(false); ui->label_destortionInfo_300dpi->setVisible(false); setMinimumWidth(500); ui->tableWidget->setMinimumWidth(450); ui->tableWidget->setMaximumWidth(450); 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")); connect(m_view, SIGNAL(doubleClicked()), this, SLOT(on_viewerDblClick())); initTableWidgetUi(); // 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()); } Form_mainInterface::~Form_mainInterface() { m_multiIndex = -1; m_curNameIndex = 1; m_list_images.clear(); QDir dir(getCachePath()); if (dir.exists()) dir.removeRecursively(); delete m_hg; m_hg = nullptr; sane_close(m_handle); m_handle = nullptr; //HGPdtToolDb_CloseDevice(m_pdtToolDbDevice); //m_pdtToolDbDevice = nullptr; delete ui; } bool Form_mainInterface::isTesting() { return m_isTesting; } QString Form_mainInterface::getSn() { return m_serialNum; } QString Form_mainInterface::getDevName() { return m_devName; } SANE_Handle Form_mainInterface::getDevHandle() { return m_handle; } hgscanner *Form_mainInterface::getScanner() { return m_hg; } void Form_mainInterface::setDevDisconnect() { m_disconnect = true; } void Form_mainInterface::paintEvent(QPaintEvent *event) { (void)event; QPainter p(this); p.fillRect(0, 0, this->width(), this->height(), qRgb(230, 230, 230)); p.setPen(QColor("gray")); p.drawRect(0, 0, width() -1, height() -1); } void Form_mainInterface::on_testResult(QString text) { 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(); if (m_disconnect) { m_mainwnd->RemoveInterface(this); } } void Form_mainInterface::on_testResultImg(void *img) { HGImage image = (HGImage)img; QString filename = getCacheFileName(); HGImgFmt_SaveImage(image, 0, 0, getStdString(filename).c_str()); m_list_images.push_back(filename); m_multiIndex = m_list_images.size() - 1; ui->stackedWidget->setCurrentWidget(m_view); m_view->addImage(image); ui->pbtn_leftRotate->setVisible(true); ui->pbtn_rightRotate->setVisible(true); ui->pbtn_prePage->setVisible(true); ui->pbtn_nextPage->setVisible(true); HGBase_DestroyImage(image); } void Form_mainInterface::on_testDistortion(SANE_DISTORTION_VAL data) { ui->label_imgInfo->setVisible(true); ui->label_destortionInfo_200dpi->setVisible(true); ui->label_destortionInfo_300dpi->setVisible(true); 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')); 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); } } 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); } } // updateImgPixelInfo(); updateUiEnabled(true); m_isTesting = false; m_mainwnd->releaseTesting(); if (m_disconnect) { m_mainwnd->RemoveInterface(this); } } void Form_mainInterface::on_testCorrectInfo(QString info) { 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, QString devModel) { 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(sleepTime > 0 ? tr("sleep time:%1minute\n\t").arg(QString::number(sleepTime)) : tr("sleep time:%1\n\t").arg(tr("Not sleeping"))); 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\n\t").arg(devFw)); if (!devModel.isEmpty()) str.append(tr("device model:%1").arg(devModel)); m_textTips->setViewContent(str); } void Form_mainInterface::on_testGetDevCpuDisk(QString cpu, QString disk) { AnalysisJson analysisJson(m_profileName); AnalysisJson::json_global jsonGlobal = analysisJson.GetGlobal(); QString cpu_size = jsonGlobal.cpu_size; QString disk_size = jsonGlobal.disk_size; QString str = (tr("please verify the size of the device's cpu and disk:") + "\n\n\t"); str.append(tr("Target cpu size:%1").arg(cpu_size) + "\n\t"); str.append(tr("Target disk size:%1").arg(disk_size) + "\n\n\t"); str.append(tr("Actual pu size:%1").arg(cpu) + "\n\t"); str.append(tr("Actual disk size:%1").arg(disk) + "\n\t"); m_textTips->setViewContent(str); } void Form_mainInterface::on_testOpenCacheFile(QString name) { if (name == HGPDTTOOLDB_NAME_IMAGE_GRAY_QUALITY && m_curDpi == 600) { if (m_multiIndex != -1) { QString cacheFilePath = getCachePath(); QFileInfo fileInfo(cacheFilePath); auto pathDir = fileInfo.path(); QString strFilePath = "file:///" + pathDir; QDesktopServices::openUrl(QUrl(strFilePath)); } } } void Form_mainInterface::on_viewerDblClick() { if (m_multiIndex != -1) { QString strFileName = m_list_images[m_multiIndex]; QFileInfo fileInfo(strFileName); auto pathDir = fileInfo.path(); QString strFilePath = "file:///" + pathDir; QDesktopServices::openUrl(QUrl(strFilePath)); } } void Form_mainInterface::on_pbtn_preStep_clicked() { int row = ui->tableWidget->currentRow(); if (row > 0) { ui->tableWidget->selectRow(row - 1); } } void Form_mainInterface::on_pbtn_nextStep_clicked() { int row = ui->tableWidget->currentRow(); if (row < ui->tableWidget->rowCount() - 1) { ui->tableWidget->selectRow(row + 1); } } void Form_mainInterface::on_pbtn_fail_clicked() { int row = ui->tableWidget->currentRow(); QTableWidgetItem *item = ui->tableWidget->item(row, 1); if (item != nullptr) { QString title = item->text(); 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)); ui->tableWidget->item(row, 2)->setText(tr("not pass")); 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); writeTestLog(tr("Tester: %1, Test item: %2, Test result: Failed! Reason: %3") .arg(m_accountName).arg(title).arg(str)); } } } void Form_mainInterface::on_pbtn_pass_clicked() { int row = ui->tableWidget->currentRow(); QTableWidgetItem *item = ui->tableWidget->item(row, 1); 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)); ui->tableWidget->item(row, 2)->setText(tr("pass")); QTableWidgetItem *item2 = ui->tableWidget->item(row, 2); item2->setToolTip(""); writeTestLog(tr("Tester: %1, Test item: %2, Test result: Pass!") .arg(m_accountName).arg(title)); on_pbtn_nextStep_clicked(); } // 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(); // } // } } void Form_mainInterface::on_pbtn_stop_clicked() { 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)"); //HGPdtToolDb_DownloadFile(m_pdtToolDbuserMgr, m_devType.toStdString().c_str(), cfgPath); AnalysisJson analysisJson(m_profileName); const QString stationStr[] = {"烧录工位", "初检工位", "图像测试工位", "压力测试工位"}; std::vector list_jsonNode = analysisJson.GetNode(); int count = list_jsonNode.size(); ui->tableWidget->setRowCount(count); int index = 0; for(int i = 0; i < count; ++i) { AnalysisJson::json_node node = list_jsonNode[i]; m_map_title_name.insert(node.title, node); if (stationStr[m_logInType] == node.station) { //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; } } ui->tableWidget->selectRow(0); } QString Form_mainInterface::getItemStatusStr(HGUInt status) { static const QString statusStr[] = {tr("not test"), tr("not pass"), tr("not support"), tr("pass") }; return statusStr[status]; } QString Form_mainInterface::getCachePath() { HGChar cachePath[512]; HGBase_GetDocumentsPath(cachePath, 512); HGChar procName[512]; HGBase_GetProcessName(procName, 512); strcat(cachePath, procName); 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()); QString suffix = ".jpg"; QString fileName = getStdFileName(cachePath + QString::number(m_curNameIndex++) + suffix); 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); 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); 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() { SANE_Int speedMode = 0; unsigned int len = sizeof(SANE_Int); sane_io_control(m_handle, IO_CTRL_CODE_GET_SPEED_MODE, &speedMode, &len); 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,80,90 }; const wchar_t G400[6] = { 40,50,60,70,80,90 }; int speed = 0; if ((int)speedMode >= 40) speed = (int)speedMode; else { if (m_devType == "G100") speed = G100[(int)speedMode - 1]; else if (m_devType == "G200") speed = G200[(int)speedMode - 1]; else if (m_devType == "G300") speed = G300[(int)speedMode - 1]; else if (m_devType == "G400") speed = G400[(int)speedMode - 1]; } return QString::number(speed) + "PPM"; } QString Form_mainInterface::getSleepTime() { int sleepTime = SANE_POWER_FIRST; unsigned int len2 = sizeof(int); sane_io_control(m_handle, IO_CTRL_CODE_GET_POWER_LEVEL, &sleepTime, &len2); if (sleepTime > 99999 || sleepTime == -1) return tr("Not sleeping"); return QString::number(sleepTime / 60) + tr(" minute"); } QString Form_mainInterface::getDevVid() { 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; } 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; } void Form_mainInterface::getLogInfo(int ret) { if (ret == SANE_STATUS_NO_DOCS) { QMessageBox::information(this, tr("Prompt"), tr("No paper")); } else if (ret == SCANNER_ERR_DEVICE_SLEEPING) { QMessageBox::information(this, tr("Prompt"), tr("Device is sleeping")); } else if (ret == SCANNER_ERR_DEVICE_COUNT_MODE) { QMessageBox::information(this, tr("Prompt"), tr("Counting mode")); } else { QMessageBox::information(this, tr("Prompt"), tr("Other error")); } } QString Form_mainInterface::getLogPath() { HGChar logPath[512]; HGBase_GetDocumentsPath(logPath, 512); HGChar procName[512]; HGBase_GetProcessName(procName, 512); strcat(logPath, procName); strcat(logPath, "/Test_Log/"); strcat(logPath, m_devType.toStdString().c_str()); strcat(logPath, "/"); return getCfgValue(m_devType.toStdString().c_str(), "logPath", getStdFileName(StdStringToUtf8(logPath).c_str())); } void Form_mainInterface::writeTestLog(QString logContent) { QString logPath = getLogPath(); HGBase_CreateDir(getStdString(logPath).c_str()); QString fileName = logPath + m_serialNum + ".log"; QFile file(fileName); if(!file.open(QIODevice::ReadWrite | QIODevice::Append)) { return; } QDateTime dateTime= QDateTime::currentDateTime(); QString curTime = dateTime .toString("yyyy-MM-dd hh:mm:ss"); QString content = "[" + curTime + "] "; content += logContent; QTextStream txtOutput(&file); txtOutput << content << endl; file.close(); } void Form_mainInterface::on_tableWidget_currentItemChanged(QTableWidgetItem *current, QTableWidgetItem *previous) { (void)previous; if (current != nullptr) { // ui->pbtn_showImg->setVisible(false); ui->pbtn_leftRotate->setVisible(false); ui->pbtn_rightRotate->setVisible(false); ui->pbtn_prePage->setVisible(false); ui->pbtn_nextPage->setVisible(false); 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; 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); } 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; HGUInt imageCount = 0; //HGPdtToolDb_GetDeviceEntryImageCount(m_pdtToolDbDevice, name.toStdString().c_str(), &imageCount); if (imageCount > 0) { // ui->pbtn_showImg->setVisible(true); } // 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); } } } void Form_mainInterface::on_pbtn_start_clicked() { m_isCorrectNormal = true; m_multiIndex = -1; m_curNameIndex = 1; 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()); if (dir.exists()) dir.removeRecursively(); int row = ui->tableWidget->currentRow(); QTableWidgetItem *item = ui->tableWidget->item(row, 1); 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; int dpi = m_map_title_name.value(title).resolution; wchar_t buf[5] = {0}; if (dpi > 0) { m_curDpi = dpi; swprintf(buf, L"%d", dpi); } else if (correct_value > -1 && correct_value < 7) { swprintf(buf, L"%d", correct_value); } if (m_hg != nullptr) { updateUiEnabled(false); m_isTesting = true; m_mainwnd->addTestingRef(); int ret = 0; if (buf != nullptr && (dpi > 0 || (correct_value > -1 && correct_value < 7))) ret = func_test_go(name.toStdWString().c_str(), (const wchar_t*)buf, m_hg); else ret = func_test_go(name.toStdWString().c_str(), L"null", m_hg); if (ret > SANE_STATUS_GOOD) { getLogInfo(ret); updateUiEnabled(true); m_isTesting = false; m_mainwnd->releaseTesting(); return; } } 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); } } } 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")); // } } void Form_mainInterface::on_pbtn_leftRotate_clicked() { m_view->rotateLeft(); } void Form_mainInterface::on_pbtn_rightRotate_clicked() { m_view->rotateRight(); } 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); 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); if (nullptr != img) { m_view->addImage(img); HGBase_DestroyImage(img); } }