123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- #include "ToolDialog.h"
- #include <QImage>
- #include <QFileInfo>
- #include <QFileDialog>
- #include <QElapsedTimer>
- #include <QGridLayout>
- #include <QCloseEvent>
- ToolDialogImpl::ToolDialogImpl(QWidget* parent)
- : DllToolDialog(parent)
- {
- ui.setupUi(this);
- this->setWindowFlags(Qt::Dialog | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint /*| Qt::WindowStaysOnTopHint*/);
- connect(this, SIGNAL(sigUpdateUI()), this, SLOT(on_UpdateUI()));
- // 显示控件初始化
- hwndUnit = new HWndUnit(this);
- Util::ShowUnitInWidget(ui.Image_widget, hwndUnit);
- hwndUnit->getHWndCtrl()->useROIController(&m_RoiController);
- connect(&m_RoiController, SIGNAL(ROIChange(const ViewMessage)), this, SLOT(on_ROIChange(const ViewMessage)));
- connect(ui.spinBox_H, SIGNAL(valueChanged(int)), this, SLOT(on_setValue(int)));
- connect(ui.spinBox_W, SIGNAL(valueChanged(int)), this, SLOT(on_setValue(int)));
- ROIPoint* pRoiPoint = new ROIPoint();
- pRoiPoint->setTitle("Brush");
- pRoiPoint->setHandleWidth(100);
- //m_pRoiController->setROISign(ROIOperation::Negative);
- m_RoiController.setROIShape(pRoiPoint);
- m_RoiController.mouseDownAction(500, 400);
-
- m_nROI_W = 512;
- m_nROI_H = 512;
- }
- ToolDialogImpl::~ToolDialogImpl()
- {
- }
- VPEnum::RETURN_VALUE ToolDialogImpl::Execute()
- {
- m_nROI_W = ui.spinBox_W->value();
- m_nROI_H = ui.spinBox_H->value();
- try
- {
- GenRectangle2(&m_hoROI, hv_roiDate[0], hv_roiDate[1], 0, m_nROI_W, m_nROI_H);
- hwndUnit->ShowImage(m_Image);
- hwndUnit->ShowObj(m_hoROI, QColor(128, 222, 0));
- ReduceDomain(m_Image, m_hoROI, &m_OutImage);
- m_CroppingImage = m_OutImage.CropDomain();
-
- hwndUnit->Refresh();
-
- }
- catch (HException& exception)
- {
- char m_szMsg[2048] = "";
- snprintf(m_szMsg, sizeof(m_szMsg),"Error #%u in %s: %s\n", exception.ErrorCode(),
- exception.ProcName().TextA(),
- exception.ErrorMessage().TextA());
- qWarning() << "Execute() Error";
- }
- emit sigUpdateUI();
- return VPEnum::RETURN_VALUE::Success;
- }
- void ToolDialogImpl::on_ROIChange(const ViewMessage& sign)
- {
- switch (sign)
- {
- case ViewMessage::MovingROI:
- {
- }break;
- case ViewMessage::UpdateROI:
- {
- ROI* roi = m_RoiController.getActiveROI();
- if (roi == nullptr)
- {
- return;
- }
- hv_roiDate = roi->getROIData();
- try
- {
- GenRectangle2(&m_hoROI, hv_roiDate[0], hv_roiDate[1], 0, m_nROI_W, m_nROI_H);
- }
- catch (...)
- {
- }
- Execute();
- }
- break;
- case ViewMessage::CreatedROI:
- {
- ROI* roi = m_RoiController.getActiveROI();
- if (roi == nullptr)
- {
- return;
- }
- hv_roiDate = roi->getROIData();
- try
- {
- GenRectangle2(&m_hoROI, hv_roiDate[0], hv_roiDate[1], 0, m_nROI_W, m_nROI_H);
- }
- catch (...)
- {
- }
- }
- break;
- default:
- break;
- }
- }
- void ToolDialogImpl::Running(bool bRun)
- {
- }
- void ToolDialogImpl::timerEvent(QTimerEvent* event)
- {
- }
- bool ToolDialogImpl::Serialized(QDataStream& ar, bool bIsOut)
- {
- int paranum;//参数数量
- if (bIsOut)//保存参数流程
- {
- paranum = 5;
- ar << paranum;//先保存参数数量
- ar << (int)1 << hv_roiDate;
- ar << (int)2 << m_RoiController;
- ar << (int)3 << m_hoROI;
- ar << (int)4 << (int)ui.spinBox_W->value();
- ar << (int)5 << (int)ui.spinBox_H->value();
- }
- else//加载参数流程,参数加载顺序一定要跟保存顺序一致
- {
- int nSize1 = 0;
- int para;
- ar >> paranum;//读取参数数量
- for (int i = 0; i < paranum; i++)
- {
- ar >> para;
- switch (para)
- {
- case 1: ar >> hv_roiDate; break;
- case 2: ar >> m_RoiController; break;
- case 3: ar >> m_hoROI; break;
- case 4: ar >> m_nROI_W; break;
- case 5: ar >> m_nROI_H; break;
- default:
- {
- qWarning() << "Serialized(In) Error";
- return false;
- }
- break;
- }
- }
- on_UpdateUI();
- }
- return true;
- }
- void ToolDialogImpl::on_UpdateUI()
- {
- int x = hv_roiDate[1].D();
- int y = hv_roiDate[0].D();
-
- ui.spinBox_X->setValue(x);
- ui.spinBox_Y->setValue(y);
- ui.spinBox_W->setValue(m_nROI_W);
- ui.spinBox_H->setValue(m_nROI_H);
- }
- /// <summary>
- /// 确定
- /// </summary>
- void ToolDialogImpl::on_btnOK_clicked()
- {
- this->hide();
- }
- /// <summary>
- /// 取消按钮
- /// </summary>
- void ToolDialogImpl::on_btnCancel_clicked()
- {
- // 将本工具的恢复到打开工具之前的状态
- RecoverData();
- }
- /// <summary>
- /// 测试按钮
- /// </summary>
- void ToolDialogImpl::on_btnExecute_clicked()
- {
- QElapsedTimer toolTimer;
- toolTimer.start();
- // 发送事件
- ToolEvent* pToolEvent = new ToolEvent(m_strPouName, m_strInstanceName, TOOL_EVENT_TYPE::TOOL_TRIGGER);
- QCoreApplication::sendEvent(m_pEventTarget, pToolEvent);
- // 统计返回值
- VPEnum::RETURN_VALUE ret = pToolEvent->ret;
- double nExecTime = toolTimer.elapsed();
- QString str;
- str = QString("耗时: %1 ms").arg(nExecTime, 0, 'G', 5);
- ui.label_time->setText(str);
- str = QString("状态: %1 ").arg(QMetaEnum::fromType<VPEnum::RETURN_VALUE>().key((short)ret));
- ui.label_state->setText(str);
- delete pToolEvent;
- }
- void ToolDialogImpl::on_setValue(int)
- {
- if (this->isVisible())
- {
- Execute();
- }
-
- }
|