code_production/app/HGProductionTool/hgscanner.cpp

134 lines
3.5 KiB
C++
Raw Normal View History

2022-12-15 06:12:53 +00:00
#include "hgscanner.h"
2022-12-26 08:24:20 +00:00
#include <QMessageBox>
2022-12-26 10:38:34 +00:00
#include "form_maininterface.h"
2022-12-27 08:25:47 +00:00
#include "dialog_userinput.h"
2022-12-28 13:03:01 +00:00
#include <QDebug>
2022-12-15 06:12:53 +00:00
2022-12-26 10:38:34 +00:00
hgscanner::hgscanner(Form_mainInterface *form, SANE_Handle h)
: m_interface(form)
, devHandle_(h)
2022-12-15 06:12:53 +00:00
{
cb_ = nullptr;
2022-12-15 06:12:53 +00:00
}
hgscanner::~hgscanner()
{
}
parameter* hgscanner::get_user_input(data_from from, value_type type, const wchar_t* title, const wchar_t* desc)
{
2022-12-27 08:25:47 +00:00
if (from == DATA_FROM_USER)
{
2022-12-28 13:03:01 +00:00
Dialog_UserInput dlg(type, QString::fromStdWString(title), desc, m_interface);
2022-12-27 08:25:47 +00:00
if (dlg.exec())
{
return dlg.getParam();
}
}
2022-12-15 06:12:53 +00:00
return nullptr;
}
void hgscanner::test_callback(const wchar_t* name, test_event ev, void* data, size_t flag)
{
2022-12-27 08:25:47 +00:00
if (ev == TEST_EVENT_TIPS)
{
2022-12-15 06:12:53 +00:00
}
else if (ev == TEST_EVENT_NOT_FIND_TEST)
{
QString info = QObject::tr("Not find test item");
emit m_interface->testResult(info);
}
else if (ev == TEST_EVENT_IO_FAIL)
{
QString info;
2022-12-30 02:43:17 +00:00
if (data != nullptr)
{
info = QObject::tr("failed: ") + QString::fromStdWString((const wchar_t*)data);
2022-12-30 02:43:17 +00:00
}
emit m_interface->testResult(info);
}
else if (ev == TEST_EVENT_MANUAL_CONFIRMATION)
{
QString info;
if (data != nullptr)
{
info = QString::fromStdWString((const wchar_t*)data);
}
emit m_interface->testResult(info);
2022-12-27 08:25:47 +00:00
}
else if (ev == TEST_EVENT_RESULT)
{
QString info;
2022-12-30 02:43:17 +00:00
if (data != nullptr)
{
if (flag)
info = QObject::tr("success: ") + QString::fromStdWString((const wchar_t*)data);
2022-12-30 02:43:17 +00:00
else
info = QObject::tr("failed: ") + QString::fromStdWString((const wchar_t*)data);
2022-12-30 02:43:17 +00:00
}
emit m_interface->testResult(info);
2022-12-27 08:25:47 +00:00
}
2022-12-28 06:57:00 +00:00
else if (ev == TEST_EVENT_DISTORTION)
{
QString title = QString::fromStdWString(name);
emit m_interface->testDistortion(title, data);
}
2022-12-29 16:07:01 +00:00
else if (ev == TEST_EVENT_FALT_INFO)
{
QString info;
if (data != nullptr)
{
info = QString::fromStdWString((const wchar_t*)data);
emit m_interface->testCorrectInfo(info);
}
2022-12-29 16:07:01 +00:00
}
2022-12-27 08:25:47 +00:00
else if (ev == TEST_EVENT_HAVE_IMAGE)
{
SANE_Image *sane_img = (SANE_Image *)data;
HGUInt imgType = 0;
if (sane_img->header.format == SANE_FRAME_GRAY)
{
if (1 == sane_img->header.depth)
imgType = HGBASE_IMGTYPE_BINARY;
else if (8 == sane_img->header.depth)
imgType = HGBASE_IMGTYPE_GRAY;
}
else if (sane_img->header.format == SANE_FRAME_RGB)
{
imgType = HGBASE_IMGTYPE_RGB;
}
HGByte *imgData = sane_img->data;
HGImageInfo imgInfo = {(HGUInt)sane_img->header.pixels_per_line, (HGUInt)sane_img->header.lines,
imgType, (HGUInt)sane_img->header.bytes_per_line, HGBASE_IMGORIGIN_TOP};
HGImage img = nullptr;
HGBase_CreateImageFromData(imgData, &imgInfo, nullptr, imgType, HGBASE_IMGORIGIN_TOP, &img);
if (nullptr != img)
{
emit m_interface->testResultImg(img);
}
}
2022-12-15 06:12:53 +00:00
}
int hgscanner::register_sane_callback(sane_callback cb, void* param)
{
2022-12-15 11:53:41 +00:00
cb_ = cb;
2022-12-15 06:12:53 +00:00
return 0;
}
int hgscanner::unregister_sane_callback(sane_callback cb)
{
2022-12-15 11:53:41 +00:00
2022-12-15 06:12:53 +00:00
return 0;
}
int hgscanner::io_control(unsigned long code, void* data, unsigned* len)
{
sane_io_control(devHandle_, code, data, len);
return 0;
2022-12-26 08:24:20 +00:00
}