You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1746 lines
46 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "MainFrame.h"
#include "ui_MainFrame.h"
#include "colossusbase.h"
#include <QHeaderView>
#pragma execution_character_set("utf-8")
QString showVariant(const AlgoParamType type, const QVariant &var) {
switch (type)
{
case LP_INT:
{
return QString::number(var.toInt());
break;
}
case LP_BOOLEAN:
case LP_STRING:
{
return var.toString();
break;
}
case LP_DOUBLE:
{
return QString::number(var.toDouble());
break;
}
case LP_IMAGE:
{
if (!var.isNull())
{
QImage img = var.value<QImage>();
if (!img.isNull())
{
return QString("[%1*%2]").arg(img.width()).arg(img.height());
}
}
break;
}
case LP_POINTF:
{
QPointF pt = var.toPointF();
QString str = "(%1,%2)"; str = str.arg(pt.x()).arg(pt.y());
return str;
break;
}
case LP_POINT:
{
QPoint pt = var.toPoint();
QString str = "(%1,%2)"; str = str.arg(pt.x()).arg(pt.y());
return str;
break;
}
case LP_MAT:
{
cv::Mat matResult = var.value<cv::Mat>();
return QString("[%1*%2]").arg(matResult.cols).arg(matResult.rows);
break;
}
case LP_ROI:
{
LP_DETECTOR_ROI_DATA roi = var.value<LP_DETECTOR_ROI_DATA>();
int nCount = roi.records.size();
if (nCount > 0)
{
for (int i = 0; i < nCount; i++)
{
Item_List record = roi.records.at(i);
int nItemCount = record.size();
for (int j = 0; j < nItemCount; j++)
{
Feature_List item = record.at(j);
switch (item.first)
{
case RECTANGLE:
case ELLIPSE:
{
QString strResult = "(%1,%2,%3,%4)";
strResult = strResult.arg(item.second.at(0)).arg(item.second.at(1)).arg(item.second.at(2)).arg(item.second.at(3));
return strResult;
break;
}
case CIRCLE:
{
QString strResult = "(%1,%2,%3)";
strResult = strResult.arg(item.second.at(0)).arg(item.second.at(1)).arg(item.second.at(2));
return strResult;
break;
}
case POLY:
{
break;
}
default:
break;
}
}
}
}
break;
}
default:
break;
}
return var.toString();
}
CMainFrame::CMainFrame(QWidget *parent)
{
m_pDE = NULL;
m_pSolutionMgr = NULL;
m_pCurrentSolution = NULL;
m_pCurrentTask = NULL;
m_pCurrentAlgo = NULL;
m_pSrcItem = NULL;
ui = new Ui::MainFrame;
ui->setupUi(this);
setContextMenuPolicy(Qt::NoContextMenu);
setWindowIcon(QIcon(":/img/resource/app.png"));
connect(ui->treeWidget, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(OnTreeItemClick()));
ui->treeWidget->setStyleSheet("QTreeWidget::item{height:30px}");
ui->tableWidget_2->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->tableWidget_2, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(OnParamPopMenu(const QPoint&)));
connect(ui->tableWidget_2, SIGNAL(cellDoubleClicked(int, int)), this, SLOT(OnRunAlgo()));
connect(ui->tableWidget_2, SIGNAL(cellClicked(int, int)), this, SLOT(OnInitCurrentAlgoParam()));
ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->tableWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(OnParamListPopMenu(const QPoint&)));
connect(ui->tableWidget, SIGNAL(cellChanged(int, int)), this, SLOT(OnCellChanged(int, int)));
connect(ui->tableWidget, SIGNAL(cellClicked(int, int)), this, SLOT(OnCellClicked(int, int)));
// connect(ui->listWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(OnListItemClick()));
// connect(ui->listWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(OnListItemDoubleClick()));
// ui->listWidget->setContextMenuPolicy(Qt::CustomContextMenu);
// connect(ui->listWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(OnListWidgetPopMenu(const QPoint&)));
ui->gv_input->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->gv_input, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(OnGvInputWidgetPopMenu(const QPoint&)));
connect(ui->pushButton_5, SIGNAL(clicked()), this, SLOT(OnClearResult()));
connect(ui->m_pbLoadImage, SIGNAL(clicked()), this, SLOT(onLoadImage()));
//connect(ui->menubar, SIGNAL(triggered(QAction *)), this, SLOT(OnMainMenuTrigger(QAction*)));
connect(ui->m_pbSaveBtn, SIGNAL(clicked()), this, SLOT(OnTrigger()));
connect(this, SIGNAL(sgShowStatus(QString)), this, SLOT(OnShowStatus(QString)));
ui->gv_input->setInfoLabel(ui->label_pixel_info);
connect(ui->gv_input, SIGNAL(imgScaled(QTransform, QPointF)), ui->gv_output, SLOT(scaleImg(QTransform, QPointF)));
connect(ui->gv_input, SIGNAL(imgMoved(QPointF)), ui->gv_output, SLOT(moveImg(QPointF)));
connect(ui->gv_output, SIGNAL(imgScaled(QTransform, QPointF)), ui->gv_input, SLOT(scaleImg(QTransform, QPointF)));
connect(ui->gv_output, SIGNAL(imgMoved(QPointF)), ui->gv_input, SLOT(moveImg(QPointF)));
connect(ui->gv_output, SIGNAL(pixelSelected(QPoint)), ui->gv_input, SLOT(selectPixel(QPoint)));
connect(this, SIGNAL(sgShowCameraImage(QImage)), this, SLOT(OnShowCameraImage(QImage)));
m_plablStatus = new QLabel(this);
ui->statusBar->addWidget(m_plablStatus);
_pSaveStatus = ui->label_SaveStatus;
}
CMainFrame::~CMainFrame()
{
if (m_plablStatus)
{
delete m_plablStatus;
m_plablStatus = NULL;
}
if (ui)
{
delete ui;
ui = NULL;
}
}
bool CMainFrame::OnMainMenuTrigger(QAction* pAction)
{
if (pAction)
{
QString strName = pAction->objectName();
if ("action_save" == strName)
{
if (_pOldTask){
if (!oldMat.empty())
_pOldTask->GetTaskInfo()->templateImg = oldMat;
}
return false;
}
}
return false;
}
void CMainFrame::OnTrigger()
{
QString strObj = sender()->objectName();
if ("m_pbSaveBtn" == strObj)
{
if (_pOldTask){
if (!oldMat.empty())
_pOldTask->GetTaskInfo()->templateImg = oldMat;
}
if (m_pDE && m_pSolutionMgr->SaveByNames(m_TaskChangeList))
{
if (_pSaveStatus)
{
_pSaveStatus->setText(QObject::tr(" 标定数据保存完成!"));
QTimer::singleShot(1500, [&](){
_pSaveStatus->setText("");
update();
});
m_TaskChangeList.clear();
SystemStateInfo::bParamStateFlag = false;
}
}
else
{
if (_pSaveStatus)
{
_pSaveStatus->setText(QObject::tr(" 保存失败!"));
QTimer::singleShot(2000, [&](){_pSaveStatus->setText(""); });
update();
}
}
}
}
bool CMainFrame::Initialize(IDetectorEngine* lpDE)
{
if (!lpDE)
return false;
m_pDE = lpDE;
m_pSolutionMgr = m_pDE->getSolutionMgr();
if (!m_pSolutionMgr)
return false;
return true;
}
bool CMainFrame::InitGraphView()
{
if (!m_pSolutionMgr)
return false;
if (!ui->treeWidget)
return false;
_pOldTask = nullptr;
ui->treeWidget->clear();
ui->treeWidget->setCurrentItem(NULL);
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
ui->tableWidget->verticalHeader()->setHidden(true);
ui->tableWidget_2->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableWidget_2->setSelectionMode(QAbstractItemView::SingleSelection);
ui->tableWidget_2->verticalHeader()->setHidden(true);
ui->tableWidget_2->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableWidget_2->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
ui->tableWidget_2->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
ui->tableWidget_2->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
ui->textEdit->setWordWrapMode(QTextOption::NoWrap);
{ /*获取所有的solution*/
QMap<QString, IDetectorSolution*> tmp = m_pSolutionMgr->GetAllSolutions();
for (QMap<QString, IDetectorSolution*>::iterator it = tmp.begin(); it!= tmp.end(); ++it)
{
IDetectorSolution* tmpSolution = *it;
if (tmpSolution != nullptr)
{
PLP_DETECTOR_SOLUTION pSolutionInfo = tmpSolution->GetSolutionInfo();
QTreeWidgetItem *solutionItem = NULL;
QString strText = pSolutionInfo->strName;// +tr("(√)");
solutionItem = new QTreeWidgetItem(ui->treeWidget, QStringList(strText));
solutionItem->setData(0, Qt::UserRole, tmpSolution->GetID());
solutionItem->setData(1, Qt::UserRole, SOLUTION);
solutionItem->setData(2, Qt::UserRole, it.key());
QMap<QString, IDetectorTask*> mItemMap = tmpSolution->GetAllTasks();
/*设置template模板在最前面*/
QMap<QString, IDetectorTask*>::iterator it = mItemMap.find("template");
if (it != mItemMap.end())
{
int nID = (*it)->GetTaskInfo()->nID;
QString strName = (*it)->GetTaskInfo()->strName;
QTreeWidgetItem *TaskItem = new QTreeWidgetItem(solutionItem, QStringList(strName));
TaskItem->setData(0, Qt::UserRole, nID);
TaskItem->setData(1, Qt::UserRole, Task);
solutionItem->addChild(TaskItem);
}
for (QMap<QString, IDetectorTask*>::iterator its = mItemMap.begin(); its != mItemMap.end(); ++its)
{
int nID = (*its)->GetTaskInfo()->nID;
QString strName = (*its)->GetTaskInfo()->strName;
if(strName.contains("template")||strName == "template")
continue;
QTreeWidgetItem *TaskItem = new QTreeWidgetItem(solutionItem, QStringList(strName));
TaskItem->setData(0, Qt::UserRole, nID);
TaskItem->setData(1, Qt::UserRole, Task);
solutionItem->addChild(TaskItem);
}
ui->treeWidget->expandItem(solutionItem);
ui->treeWidget->setCurrentItem(solutionItem);
}
}
}
m_TaskChangeList.clear();
if (!InitCurrentTask())
return true;
return true;
}
bool CMainFrame::InitCurrentTask()
{
if (!InitCurrentNode())
return false;
ui->tableWidget->setRowCount(0);
ui->tableWidget->clearContents();
ui->tableWidget_2->setRowCount(0);
ui->tableWidget_2->clearContents();
ui->gv_input->clear();
ui->gv_output->clear();
ui->textEdit->clear();
IDetectorTask* ptask = currentTask();
if (ptask)
{
if (_pOldTask==nullptr)
{
_pOldTask = ptask;
oldMat = ptask->GetTaskInfo()->templateImg;
}
if (_pOldTask != ptask){
_pOldTask->GetTaskInfo()->templateImg = oldMat;
_pOldTask = ptask;
oldMat = ptask->GetTaskInfo()->templateImg;
}
QMap<int, IDetectorAlgorithm*> mAlg = m_pCurrentTask->GetAllAlgorithms();
int nIndex = 0;
for (QMap<int, IDetectorAlgorithm*>::iterator it = mAlg.begin();it!=mAlg.end();it++)
{
IDetectorAlgorithm* pAlg = *it;
if (pAlg)
{
ui->tableWidget_2->setRowCount(nIndex + 1);
QTableWidgetItem* pItem = NULL;
if (m_pCurrentTask->GetRunAlgo() && pAlg->GetID() == m_pCurrentTask->GetRunAlgo()->GetID())
{
QString strText = QString::number(pAlg->GetID()) + tr("(√)");
pItem = new QTableWidgetItem(strText);
pItem->setData(Qt::UserRole, pAlg->GetID());
ui->tableWidget_2->setItem(nIndex, 0, pItem);
}
else
{
pItem = new QTableWidgetItem(QString::number(pAlg->GetID()));
pItem->setData(Qt::UserRole, pAlg->GetID());
ui->tableWidget_2->setItem(nIndex, 0, pItem);
}
ui->tableWidget_2->setItem(nIndex, 1, new QTableWidgetItem(QObject::tr(pAlg->GetAlgorithmInfo()->strName.toStdString().c_str())));
ui->tableWidget_2->setItem(nIndex, 2, new QTableWidgetItem(QString::number(pAlg->GetAlgorithmInfo()->nRoiID)));
if (nIndex == 0)
{
ui->tableWidget_2->setCurrentCell(0, QItemSelectionModel::Select);
}
}
nIndex++;
}
if (m_pCurrentTask->GetTaskInfo()->templateImg.data == NULL)
{
QString strExePath = QCoreApplication::applicationDirPath();
QString strImagePath = strExePath + LP_DETECTOR_BUSSINESS_IMAGE_DIR;
QString strImageName = strImagePath + QString::number(m_pCurrentSolution->GetID()) + "_" + QString::number(m_pCurrentTask->GetID()) + ".bmp";
std::string strPath = strImageName.toLocal8Bit().toStdString();
m_pCurrentTask->GetTaskInfo()->templateImg = cv::imread(strPath, CV_LOAD_IMAGE_GRAYSCALE);
}
ColossusBase::showImage(m_pCurrentTask->GetTaskInfo()->templateImg, ui->gv_input);
}
return true;
}
bool CMainFrame::InitCurrentSolution(QTreeWidgetItem* pItem, IDetectorSolution* pSolution)
{
if (!pSolution || !pItem)
return false;
pItem->takeChildren();
QStringList strKey = pSolution->GetAllTaskNames();
for (int n = 0; n < strKey.size(); n++)
{
IDetectorTask* pTask = pSolution->GetTaskByName(strKey[n]);
if (pTask)
{
PLP_DETECTOR_TASK pTaskInfo = pTask->GetTaskInfo();
QTreeWidgetItem *TaskItem = new QTreeWidgetItem(pItem, QStringList(pTaskInfo->strName));
TaskItem->setData(0, Qt::UserRole, pTask->GetID());
TaskItem->setData(1, Qt::UserRole, Task);
pItem->addChild(TaskItem);
}
}
return true;
}
bool CMainFrame::OnSetRunSolution()
{
if (!currentSolution())
return false;
if ((NodeType)ui->treeWidget->currentItem()->data(1, Qt::UserRole).toInt() == SOLUTION)
{
IDetectorSolution* pRunSolution = m_pSolutionMgr->GetRunSolution();
if (pRunSolution)
{
if (pRunSolution->GetID() == m_pCurrentSolution->GetID())
{
QString strName = pRunSolution->GetSolutionName();
m_pSolutionMgr->SetRunSolution(strName);
ui->treeWidget->currentItem()->setText(0, m_pCurrentSolution->GetSolutionInfo()->strName);
return true;
}
else
{
int nItemCount = ui->treeWidget->topLevelItemCount();
for (int i = 0; i < nItemCount; i++)
{
QTreeWidgetItem* pItem = ui->treeWidget->topLevelItem(i);
if (pItem->data(0, Qt::UserRole).toString() == pRunSolution->GetSolutionName())
{
pItem->setText(0, pRunSolution->GetSolutionInfo()->strName);
break;
}
}
m_pSolutionMgr->SetRunSolution(m_pCurrentSolution->GetSolutionName());
QString strText = m_pCurrentSolution->GetSolutionInfo()->strName + tr("(√)");
ui->treeWidget->currentItem()->setText(0, strText);
return true;
}
}
else
{
m_pSolutionMgr->SetRunSolution(m_pCurrentSolution->GetSolutionName());
QString strText = m_pCurrentSolution->GetSolutionInfo()->strName + tr("(√)");
ui->treeWidget->currentItem()->setText(0, strText);
return true;
}
}
return false;
}
bool CMainFrame::OnBatchLoadImage(bool bReLoad)
{
if (!currentTask())
return false;
QString strDefaultDirPath = m_pCurrentTask->GetTaskInfo()->strDirPath;
QStringList strFileNamesList = QFileDialog::getOpenFileNames(this, "open file", strDefaultDirPath, "Images (*.bmp *.png *.xpm *.jpg)");
if (strFileNamesList.size() <= 0)
{
return false;
}
// ui->listWidget->clear();
// ui->listWidget->setSpacing(12);
// ui->listWidget->setMovement(QListView::Static);
// ui->listWidget->setViewMode(QListView::IconMode);
// ui->listWidget->setWrapping(false);
// ui->listWidget->setFlow(QListView::LeftToRight);
// for (int i = 0; i < strFileNamesList.size(); i++)
// {
// QListWidgetItem* item = new QListWidgetItem("Test", ui->listWidget);
// item->setData(Qt::UserRole, strFileNamesList.at(i));
// item->setText(strFileNamesList.at(i).split("/").last());
// ui->listWidget->addItem(item);
// }
QString strFileName = strFileNamesList[0];
std::string strpath = strFileName.toLocal8Bit().toStdString();//中文路径支持
//cv::Mat m_img = cv::imread(strpath, CV_LOAD_IMAGE_UNCHANGED);
m_pCurrentTask->GetTaskInfo()->templateImg = cv::imread(strpath, CV_LOAD_IMAGE_GRAYSCALE);
oldMat = m_pCurrentTask->GetTaskInfo()->templateImg;
if (ColossusBase::showImage(m_pCurrentTask->GetTaskInfo()->templateImg, ui->gv_input))
{
m_pCurrentTask->GetTaskInfo()->strImageName = strFileName.split("/").last();
}
return true;
}
bool CMainFrame::OnCopyFileTitle()
{
// QListWidgetItem* item = ui->listWidget->currentItem();
// if (item)
// {
// QClipboard *clipboard = QApplication::clipboard();
// clipboard->setText(item->text());
// }
return true;
}
void CMainFrame::OnShowCameraImage(QImage img)
{
m_pCurrentTask->GetTaskInfo()->templateImg = ColossusBase::QImage2cvMat(img).clone();
if (ColossusBase::showImage(img, ui->gv_input))
{
return;
}
}
void __stdcall ImageEventHandler(void * callBackOwner, QImage& img, int nDeviceID)
{
CMainFrame* p = (CMainFrame*)(callBackOwner);
emit p->sgShowCameraImage(img);
}
bool CMainFrame::OnSnapImage()
{
// if (!currentTask())
// return false;
//
// DeviceType type;
// IDetectorCameraDevice* pCamera = (IDetectorCameraDevice*)m_pDeviceMgr->GetDevice(m_pCurrentTask->GetTaskInfo()->nCameraID, type);
// if (!pCamera && type != CAMERA)
// return false;
//
// pCamera->SnapImage(this, ImageEventHandler);
return true;
}
bool CMainFrame::InitCurrentNode()
{
if (!m_pSolutionMgr)
return false;
QTreeWidgetItem *currentItem = ui->treeWidget->currentItem();
if (currentItem)
{
if (currentItem->data(1, Qt::UserRole).toInt() == SOLUTION)
{
if (m_pCurrentSolution)
m_pCurrentSolution->ClearUserParamValue();
QString nSolutionID = currentItem->data(0, Qt::UserRole).toString();
m_pCurrentSolution = m_pSolutionMgr->GetSolutionByID(nSolutionID);
if (!m_pCurrentSolution)
return false;
m_pCurrentSolution->LoadUserParamValue();
m_pCurrentTask = NULL;
}
else if (currentItem->data(1, Qt::UserRole).toInt() == Task)
{
if (currentItem->parent())
{
QString nSolutionID = currentItem->parent()->data(2, Qt::UserRole).toString();
m_pCurrentSolution = m_pSolutionMgr->GetSolutionByID(nSolutionID);
if (!m_pCurrentSolution)
return false;
QString strName = currentItem->data(0,Qt::DisplayRole).toString();
int nTaskID = currentItem->data(0, Qt::UserRole).toInt();
m_pCurrentTask = m_pCurrentSolution->GetTaskByName(strName);
if (!m_pCurrentTask)
return false;
}
}
return true;
}
return true;
}
bool CMainFrame::OnTreeItemClick()
{
if (!InitCurrentTask())
return false;
return true;
}
bool CMainFrame::OnParamPopMenu(const QPoint& points)
{
QMenu menu(this);
QAction *runAction = menu.addAction(QObject::tr("运行"));
runAction->setObjectName("runAction");
menu.addSeparator();
// QAction *addAlgoAction = menu.addAction(QStringLiteral("添加算法"));
// addAlgoAction->setObjectName("addAlgoAction");
// menu.addSeparator();
QAction *selectAlgoAction = menu.addAction(QObject::tr("选择算法"));
selectAlgoAction->setObjectName("selectAlgoAction");
QAction *editAction = menu.addAction(QObject::tr("编辑"));
editAction->setObjectName("editAction");
// QAction *deleteAction = menu.addAction(QStringLiteral("删除"));
// deleteAction->setObjectName("deleteAction");
// menu.addSeparator();
QAction *setAction = menu.addAction(QObject::tr("输入参数设置"));
setAction->setObjectName("setAction");
QAction *outParamAction = menu.addAction(QObject::tr("输出参数设置"));
outParamAction->setObjectName("outParamAction");
// QAction *importParamAciton = menu.addAction(QStringLiteral("导入参数"));
// QAction *exportParamAciton = menu.addAction(QStringLiteral("导出参数"));
// QAction *importOutParamAciton = menu.addAction(QStringLiteral("导入输出参数"));
// QAction *exportOutParamAciton = menu.addAction(QStringLiteral("导出输出参数"));
QAction *updateRelyOnAlgoAciton = menu.addAction(QObject::tr("更新关联算法参数"));
updateRelyOnAlgoAciton->setObjectName("updateRelyOnAlgoAciton");
QAction *selectedAction = menu.exec(QCursor::pos());
if (!selectedAction)
{
menu.clear();
return false;
}
QString strObj = selectedAction->objectName();
if (strObj == "editAction")
{
OnEditAlgo();
}
else if (strObj == "deleteAction")
{
OnDeleteAlgo();
}
else if (strObj == "setAction")
{
OnSetAlgo();
}
else if (strObj == "outParamAction")
{
OnSetOutParam();
}
else if (strObj == "addAlgoAction")
{
OnAddAlgo();
}
else if (strObj == "runAction")
{
OnRunAlgo();
}
else if (strObj == "selectAlgoAction")
{
OnSelectAlgo();
}
else if (strObj == "importParamAciton")
{
OnImportParam();
}
else if (strObj == "exportParamAciton")
{
OnExportParam();
}
else if (strObj == "importOutParamAciton")
{
OnImportOutParam();
}
else if (strObj == "exportOutParamAciton")
{
OnExportOutParam();
}
else if (strObj == "updateRelyOnAlgoAciton")
{
bool bupdate = OnUpdateRelyOnAlgo();
if (m_plablStatus){
if (bupdate)
m_plablStatus->setText(QObject::tr("更新关联完成"));
else
m_plablStatus->setText(QObject::tr("Error更新关联失败"));
QTimer::singleShot(1000,[&](){m_plablStatus->setText(""); });
}
}
menu.clear();
return true;
}
bool CMainFrame::OnAddAlgo()
{
if (!m_tAlgoDlg.Initialize(m_pDE, m_pCurrentTask))
return false;
m_tAlgoDlg.setParent(this);
m_tAlgoDlg.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
m_tAlgoDlg.setWindowIcon(QIcon(":/image/leaper"));
m_tAlgoDlg.setWindowModality(Qt::ApplicationModal);
m_tAlgoDlg.setAttribute(Qt::WA_ShowModal, true);
IDetectorAlgorithm* pAlgo = m_tAlgoDlg.ShowAlgoDlg(NULL);
if (pAlgo)
{
int nRowCount = ui->tableWidget_2->rowCount();
ui->tableWidget_2->setRowCount(nRowCount + 1);
QTableWidgetItem* pItem = new QTableWidgetItem(QString::number(pAlgo->GetID()));
pItem->setData(Qt::UserRole, pAlgo->GetID());
ui->tableWidget_2->setItem(nRowCount, 0, pItem);
ui->tableWidget_2->setItem(nRowCount, 1, new QTableWidgetItem(QObject::tr(pAlgo->GetAlgorithmInfo()->strName.toStdString().c_str())));
//ui->tableWidget_2->setItem(nRowCount, 2, new QTableWidgetItem(pAlgo->GetAlgorithmInfo()->strDescription));
ui->tableWidget_2->setItem(nRowCount, 2, new QTableWidgetItem(QString::number(pAlgo->GetAlgorithmInfo()->nRoiID)));
ui->tableWidget_2->setCurrentCell(nRowCount, QItemSelectionModel::Select);
OnInitCurrentAlgoParam();
}
return true;
}
bool CMainFrame::OnEditAlgo()
{
if (!currentTask())
return false;
int nRowIndex = ui->tableWidget_2->currentRow();
if (nRowIndex != -1)
{
QList<QTableWidgetItem*>items = ui->tableWidget_2->selectedItems();
QTableWidgetItem*item = items.at(0);
if (item)
{
int nCurrentID = item->data(Qt::UserRole).toInt();
IDetectorAlgorithm* pAlgo = m_pCurrentTask->GetAlgorithm(nCurrentID);
if (!pAlgo)
return false;
if (!m_tAlgoDlg.Initialize(m_pDE, m_pCurrentTask))
return false;
m_tAlgoDlg.setParent(this);
m_tAlgoDlg.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
m_tAlgoDlg.setWindowIcon(QIcon(":/image/leaper"));
m_tAlgoDlg.setWindowModality(Qt::ApplicationModal);
m_tAlgoDlg.setAttribute(Qt::WA_ShowModal, true);
pAlgo = m_tAlgoDlg.ShowAlgoDlg(pAlgo);
if (items.size()>1)
items.at(1)->setText(QObject::tr(pAlgo->GetAlgorithmInfo()->strName.toStdString().c_str()));
if (items.size()>3)
items.at(2)->setText(QString::number(pAlgo->GetAlgorithmInfo()->nRoiID));
// if (items.size()>2)
// items.at(2)->setText(pAlgo->GetAlgorithmInfo()->strDescription);
// if (items.size()>3)
// items.at(3)->setText(QString::number(pAlgo->GetAlgorithmInfo()->nRoiID));
OnInitCurrentAlgoParam();
return true;
}
}
return false;
}
bool CMainFrame::OnDeleteAlgo()
{
if (!currentTask())
return false;
int nRowIndex = ui->tableWidget_2->currentRow();
if (nRowIndex != -1)
{
QList<QTableWidgetItem*>items = ui->tableWidget_2->selectedItems();
QTableWidgetItem*item = items.at(0);
if (item)
{
int nCurrentID = item->data(Qt::UserRole).toInt();
IDetectorAlgorithm* pAlgo = m_pCurrentTask->GetAlgorithm(nCurrentID);
if (!pAlgo)
return false;
if (m_pCurrentTask->DeleteAlgorithm(pAlgo->GetID()))
{
ui->tableWidget_2->removeRow(nRowIndex);
OnInitCurrentAlgoParam();
return true;
}
}
}
return false;
}
bool CMainFrame::OnSetAlgo()
{
if (!currentTask())
return false;
int nRowIndex = ui->tableWidget_2->currentRow();
if (nRowIndex != -1)
{
QList<QTableWidgetItem*>items = ui->tableWidget_2->selectedItems();
QTableWidgetItem*item = items.at(0);
if (item)
{
int nCurrentID = item->data(Qt::UserRole).toInt();
IDetectorAlgorithm* pAlgo = m_pCurrentTask->GetAlgorithm(nCurrentID);
if (!pAlgo)
return false;
//CDsgAlgorithmParamMgrDlg m_tParamMgrDlg;
if (!m_tParamMgrDlg.Initialize(m_pDE, m_pCurrentTask, pAlgo,PARAM_IN))
return false;
m_tParamMgrDlg.setParent(this);
m_tParamMgrDlg.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
m_tParamMgrDlg.setWindowIcon(QIcon(":/image/leaper"));
m_tParamMgrDlg.setWindowModality(Qt::ApplicationModal);
m_tParamMgrDlg.setAttribute(Qt::WA_ShowModal, true);
m_tParamMgrDlg.ShowParamMgrDlg(pAlgo);
//m_tParamMgrDlg.exec();
}
}
return true;
}
bool CMainFrame::OnSetOutParam()
{
if (!currentTask())
return false;
int nRowIndex = ui->tableWidget_2->currentRow();
if (nRowIndex != -1)
{
QList<QTableWidgetItem*>items = ui->tableWidget_2->selectedItems();
QTableWidgetItem*item = items.at(0);
if (item)
{
int nCurrentID = item->data(Qt::UserRole).toInt();
IDetectorAlgorithm* pAlgo = m_pCurrentTask->GetAlgorithm(nCurrentID);
if (!pAlgo)
return false;
//CDsgAlgorithmParamMgrDlg m_tParamMgrDlg;
if (!m_tParamMgrDlg.Initialize(m_pDE, m_pCurrentTask, pAlgo,PARAM_OUT))
return false;
m_tParamMgrDlg.setParent(this);
m_tParamMgrDlg.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
m_tParamMgrDlg.setWindowIcon(QIcon(":/image/leaper"));
m_tParamMgrDlg.setWindowModality(Qt::ApplicationModal);
m_tParamMgrDlg.setAttribute(Qt::WA_ShowModal, true);
m_tParamMgrDlg.ShowParamMgrDlg(pAlgo);
//m_tParamMgrDlg.exec();
}
}
return true;
}
bool CMainFrame::OnRunAlgo()
{
if (!currentTask())
return false;
int nRowIndex = ui->tableWidget_2->currentRow();
if (nRowIndex != -1)
{
QList<QTableWidgetItem*>items = ui->tableWidget_2->selectedItems();
QTableWidgetItem*item = items.at(0);
if (item)
{
int nCurrentID = item->data(Qt::UserRole).toInt();
IDetectorAlgorithm* pAlgo = m_pCurrentTask->GetAlgorithm(nCurrentID);
if (!pAlgo)
return false;
m_pCurrentTask->GetTaskInfo()->detectImg = m_pCurrentTask->GetTaskInfo()->templateImg;
//QString strHeader = "";
//strHeader += "<span style='font-size:15px;color:#ff0000;font-weight:bold;'>";
//strHeader += pAlgo->GetAlgorithmInfo()->strName;
//if (pCurrentTask->GetTaskInfo()->strImageName.size() > 0)
//{
// strHeader += "->";
// strHeader += pCurrentTask->GetTaskInfo()->strImageName;
//}
//strHeader += ":";
//ui->textEdit->append(strHeader);
if (pAlgo->Exec())
{
QString strResult = "";
strResult += "<span style='font-size:10px;font-weight:bold;'>";
strResult += QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
strResult += " ";
strResult += "</span>";
strResult += "<span style='font-size:10px;font-weight:bold;'>";
strResult += QObject::tr("算法名称:");
strResult += "</span>";
strResult += "<span style='font-size:10px;color:#ff0000;'>";
strResult += QObject::tr(pAlgo->GetAlgorithmInfo()->strName.toStdString().c_str());
strResult += "</span>";
strResult += ",";
if (m_pCurrentTask->GetTaskInfo()->strImageName.size() > 0)
{
strResult += "<span style='font-size:10px;font-weight:bold;'>";
strResult += QObject::tr("图片名称:");
strResult += "</span>";
strResult += "<span style='font-size:10px;color:#ff0000;'>";
strResult += m_pCurrentTask->GetTaskInfo()->strImageName;
strResult += "</span>";
strResult += ",";
}
QMap<QString, PLP_ALGORITHM_PARAM> mOutParam = pAlgo->GetAllOutParams();
for (QMap<QString, PLP_ALGORITHM_PARAM>::iterator it = mOutParam.begin();it!=mOutParam.end();it++)
{
PLP_ALGORITHM_PARAM pOutParam = *it;
if (pOutParam)
{
strResult += "<span style='font-size:10px;font-weight:bold;'>";
strResult += pOutParam->strName + ":";
strResult += "</span>";
strResult += "<span style='font-size:10px;color:#ff0000;'>";
switch (pOutParam->type)
{
case LP_INT:
{
strResult += QString::number(pOutParam->value.toInt());
break;
}
case LP_BOOLEAN:
{
strResult += showVariant(pOutParam->type, pOutParam->value);// lppOutParam[i]->value.toString();
break;
}
case LP_STRING:
{
strResult += showVariant(pOutParam->type, pOutParam->value); //lppOutParam[i]->value.toString();
break;
}
case LP_DOUBLE:
{
strResult += QString::number(pOutParam->value.toDouble());
break;
}
case LP_IMAGE:
{
if (!pOutParam->value.isNull())
{
QImage img = pOutParam->value.value<QImage>();
if (!img.isNull())
{
ColossusBase::showImage(img, ui->gv_output);
}
}
break;
}
case LP_POINTF:
{
QPointF pt = pOutParam->value.toPointF();
QString str = "(%1,%2)"; str = str.arg(pt.x()).arg(pt.y());
strResult += str;
break;
}
case LP_POINT:
{
QPoint pt = pOutParam->value.toPoint();
QString str = "(%1,%2)"; str = str.arg(pt.x()).arg(pt.y());
strResult += str;
break;
}
default:
break;
}
strResult += "</span>";
strResult += ",";
}
}
if (strResult.length() > 0)
{
strResult = strResult.left(strResult.length() - 1);
ui->textEdit->append(strResult);
}
}
else
{
QString strResult = "";
strResult += "<span style='font-size:10px;color:#ff0000;'>";
strResult += QObject::tr("加载算法失败,请检查是否配置相应的算法库");
strResult += "</span>";
ui->textEdit->append(strResult);
return false;
}
}
}
return true;
}
bool CMainFrame::OnSelectAlgo()
{
if (!currentTask())
return false;
int nRowIndex = ui->tableWidget_2->currentRow();
if (nRowIndex != -1)
{
QList<QTableWidgetItem*>items = ui->tableWidget_2->selectedItems();
QTableWidgetItem* item = items.at(0);
if (item)
{
int nCurrentID = item->data(Qt::UserRole).toInt();
IDetectorAlgorithm* pAlgo = m_pCurrentTask->GetAlgorithm(nCurrentID);
if (!pAlgo)
return false;
IDetectorAlgorithm* pRunAlgo = m_pCurrentTask->GetRunAlgo();
if (pRunAlgo)
{
if (pRunAlgo->GetID() == pAlgo->GetID())
{
m_pCurrentTask->SetRunAlgo(LP_DETECTOR_INVALID_ID);
item->setText(QString::number(pAlgo->GetID()));
return true;
}
else
{
int nCount = ui->tableWidget_2->rowCount();
for (int i = 0; i < nCount; i++)
{
QTableWidgetItem* pIDItem = ui->tableWidget_2->item(i, 0);
if (pIDItem->data(Qt::UserRole).toInt() == pRunAlgo->GetID())
{
pIDItem->setText(QString::number(pRunAlgo->GetID()));
break;
}
}
m_pCurrentTask->SetRunAlgo(pAlgo->GetID());
QString strText = QString::number(pAlgo->GetID()) + tr("(√)");
item->setText(strText);
return true;
}
}
else
{
m_pCurrentTask->SetRunAlgo(pAlgo->GetID());
QString strText = QString::number(pAlgo->GetID()) + tr("(√)");
item->setText(strText);
return true;
}
}
}
return true;
}
bool CMainFrame::OnListWidgetPopMenu(const QPoint&)
{
QMenu menu;
QAction *batchLoadImgAction = menu.addAction(QObject::tr("加载标定图片"));
//QAction *copyTitleAction = menu.addAction(QStringLiteral("复制图片名称"));
//QAction *deleteAction = menu.addAction(QStringLiteral("删除"));
QAction *selectedAction = menu.exec(QCursor::pos());
if (!selectedAction)
{
menu.clear();
return false;
}
if (selectedAction == batchLoadImgAction)
{
OnBatchLoadImage();
}
menu.clear();
return true;
}
bool CMainFrame::OnGvInputWidgetPopMenu(const QPoint&)
{
if (!m_pCurrentTask || m_pCurrentTask->GetTaskInfo()->templateImg.empty())
{
return true;
}
QMenu menu;
QAction *saveImgAction = menu.addAction(QObject::tr("设置当前为标定图"));
QAction *selectedAction = menu.exec(QCursor::pos());
if (!selectedAction)
{
menu.clear();
return false;
}
if (selectedAction == saveImgAction)
{
if (_pOldTask){
oldMat = _pOldTask->GetTaskInfo()->templateImg;
}
QString strName = m_pCurrentTask->GetTaskInfo()->strName;
if (!m_TaskChangeList.contains(strName))
{
m_TaskChangeList.append(strName);
}
// QString fileName = QFileDialog::getSaveFileName(this, tr("save image"), qApp->applicationDirPath(), tr("Image (*.bmp)"));
//
// if (!fileName.isNull())
// {
// std::string strpath = fileName.toLocal8Bit().toStdString();
// if (!cv::imwrite(strpath, m_pCurrentTask->GetTaskInfo()->img))
// return false;
// }
}
menu.clear();
return true;
}
bool CMainFrame::OnListItemDoubleClick()
{
return OnRunAlgo();
}
bool CMainFrame::OnListItemClick()
{
// if (m_pCurrentTask)
// {
// QListWidgetItem* item = ui->listWidget->currentItem();
//
// if (item)
// {
// QString strFilePath = item->data(Qt::UserRole).toString();
// std::string strpath = strFilePath.toLocal8Bit().toStdString();
// m_pCurrentTask->GetTaskInfo()->templateImg = cv::imread(strpath, 0);
//
// if (ColossusBase::showImage(m_pCurrentTask->GetTaskInfo()->templateImg, ui->gv_input))
// {
// m_pCurrentTask->GetTaskInfo()->strImageName = strFilePath.split("/").last();
// }
// }
//
// return true;
// }
return false;
}
void CMainFrame::OnClearResult()
{
ui->textEdit->clear();
}
bool CMainFrame::OnInitCurrentAlgoParam()
{
if (!ui->tableWidget)
return false;
ui->tableWidget->setRowCount(0);
ui->tableWidget->clearContents();
//ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
ui->tableWidget->verticalHeader()->setHidden(true);
ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
if (!m_pCurrentTask)
return false;
int nRowIndex = ui->tableWidget_2->currentRow();
if (nRowIndex != -1)
{
QList<QTableWidgetItem*>items = ui->tableWidget_2->selectedItems();
QTableWidgetItem*item = items.at(0);
if (item)
{
int nCurrentID = item->data(Qt::UserRole).toInt();
m_pCurrentAlgo = m_pCurrentTask->GetAlgorithm(nCurrentID);
if (!m_pCurrentAlgo)
return false;
if (!m_tParamDlg.Initialize(m_pDE, m_pCurrentTask, m_pCurrentAlgo, PARAM_IN))
return false;
QMap<QString, PLP_ALGORITHM_PARAM> mParam = m_pCurrentAlgo->GetAllParams();
int nIndex = 0;
for (QMap<QString, PLP_ALGORITHM_PARAM>::iterator its = mParam.begin(); its != mParam.end(); ++its){
ui->tableWidget->setRowCount(nIndex + 1);
ui->tableWidget->setItem(nIndex, 0, new QTableWidgetItem(QString::number(nIndex + 1)));
ui->tableWidget->setItem(nIndex, 1, new QTableWidgetItem((*its)->strName));
ui->tableWidget->setItem(nIndex, 2, new QTableWidgetItem(GetParamTypeStr((*its)->type)));
ui->tableWidget->setItem(nIndex, 3, new QTableWidgetItem(showVariant((*its)->type, (*its)->value)));
//ui->tableWidget->setItem(nIndex, 4, new QTableWidgetItem((*its)->strDescription));
nIndex++;
}
}
}
return true;
}
bool CMainFrame::OnParamListPopMenu(const QPoint&)
{
QMenu menu;
// QAction *addParamAction = menu.addAction(QStringLiteral("添加"));
// addParamAction->setObjectName("addParamAction");
QAction *editParamAction = menu.addAction(QObject::tr("编辑"));
editParamAction->setObjectName("editParamAction");
// QAction *deleteParamAction = menu.addAction(QStringLiteral("删除"));
// deleteParamAction->setObjectName("deleteParamAction");
QAction *selectedAction = menu.exec(QCursor::pos());
if (!selectedAction)
{
menu.clear();
return false;
}
QString strObj = selectedAction->objectName();
//if (selectedAction == addParamAction)
if (strObj == "addParamAction")
{
OnAddParam();
}
//else if (selectedAction == editParamAction)
else if (strObj == "editParamAction")
{
OnEditParam();
}
//else if (selectedAction == deleteParamAction)
else if (strObj == "deleteParamAction")
{
OnDeleteParam();
}
menu.clear();
return true;
}
bool CMainFrame::OnAddParam()
{
if (!currentAlgorithm())
return false;
if (!m_tParamDlg.InitGraphView())
return false;
m_tParamDlg.setParent(this);
m_tParamDlg.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
m_tParamDlg.setWindowIcon(QIcon(":/image/leaper"));
m_tParamDlg.setWindowModality(Qt::ApplicationModal);
m_tParamDlg.setAttribute(Qt::WA_ShowModal, true);
PLP_ALGORITHM_PARAM pParam = m_tParamDlg.ShowParamDlg(NULL);
if (pParam)
{
int nRowCount = ui->tableWidget->rowCount();
ui->tableWidget->setRowCount(nRowCount + 1);
ui->tableWidget->setItem(nRowCount, 0, new QTableWidgetItem(QString::number(pParam->nID)));
ui->tableWidget->setItem(nRowCount, 1, new QTableWidgetItem(pParam->strName));
ui->tableWidget->setItem(nRowCount, 2, new QTableWidgetItem(GetParamTypeStr(pParam->type)));
ui->tableWidget->setItem(nRowCount, 3, new QTableWidgetItem(showVariant(pParam->type, pParam->value)));
ui->tableWidget->setItem(nRowCount, 4, new QTableWidgetItem(pParam->strDescription));
return true;
}
return false;
}
bool CMainFrame::OnDeleteParam()
{
if (!currentAlgorithm())
return false;
int nRowIndex = ui->tableWidget->currentRow();
if (nRowIndex != -1)
{
QList<QTableWidgetItem*>items = ui->tableWidget->selectedItems();
QTableWidgetItem*item = items.at(0);
if (item)
{
int nCurrentID = item->text().toInt();
m_pCurrentAlgo->DeleteParam(nCurrentID);
ui->tableWidget->removeRow(nRowIndex);
return true;
}
}
return false;
}
bool CMainFrame::OnEditParam()
{
if (!currentAlgorithm())
return false;
int nRowIndex = ui->tableWidget->currentRow();
if (nRowIndex != -1)
{
QList<QTableWidgetItem*>items;//= ui->tableWidget->selectedItems();
for (int i = 0; i < ui->tableWidget->colorCount(); i++)
{
items.push_back(ui->tableWidget->item(nRowIndex, i));
}
QTableWidgetItem*item = items.at(1);
if (item)
{
if (_pOldTask){
if (!oldMat.empty())
_pOldTask->GetTaskInfo()->templateImg = oldMat;
}
//int nCurrentID = item->text().toInt();
QString strParaName = item->text();
AlgoParamType type;
PLP_ALGORITHM_PARAM pParam = NULL;
pParam = m_pCurrentAlgo->GetParamByName(strParaName);
//pParam = m_pCurrentAlgo->GetParam(nCurrentID);
if (pParam)
{
if (!m_tParamDlg.InitGraphView())
return false;
// m_tParamDlg.show();
m_tParamDlg.setParent(this);
m_tParamDlg.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
m_tParamDlg.setWindowIcon(QIcon(":/image/leaper"));
m_tParamDlg.setWindowModality(Qt::ApplicationModal);
m_tParamDlg.setAttribute(Qt::WA_ShowModal, true);
m_tParamDlg.ShowParamDlg(pParam);
// items.at(1)->setText(pParam->strName);
// items.at(2)->setText(GetParamTypeStr(pParam->type));
// items.at(3)->setText(showVariant(pParam->type,pParam->value));
//items.at(4)->setText(pParam->strDescription);
QString st = _pOldTask->GetTaskInfo()->strName;
if (!m_TaskChangeList.contains(st))
{
m_TaskChangeList.append(st);
}
return true;
}
}
}
return false;
}
bool CMainFrame::OnImportParam()
{
QString strFileName = QFileDialog::getOpenFileName(this, "open file", "", "File (*.json)");
if (strFileName.length() > 0)
{
int nRowIndex = ui->tableWidget_2->currentRow();
if (nRowIndex != -1)
{
QList<QTableWidgetItem*>items = ui->tableWidget_2->selectedItems();
QTableWidgetItem*item = items.at(0);
if (item)
{
int nCurrentID = item->data(Qt::UserRole).toInt();
IDetectorAlgorithm* pAlgo = m_pCurrentTask->GetAlgorithm(nCurrentID);
if (!pAlgo)
return false;
QFile file(strFileName);
QByteArray byteArray;
if (!file.open(QIODevice::ReadOnly))
{
return false;
}
byteArray = file.readAll();
if (byteArray.size() == 0)
return true;
QJsonParseError parse_error;
QJsonDocument document = QJsonDocument::fromJson(byteArray, &parse_error);
if (parse_error.error == QJsonParseError::NoError)
{
if (!document.isEmpty() && !document.isNull())
{
if (document.isArray())
{
QJsonArray paramArray = document.array();
pAlgo->ImportParam(paramArray);
return true;
}
}
}
}
}
}
return true;
}
bool CMainFrame::OnExportParam()
{
QString fileName = QFileDialog::getSaveFileName(this,"Open Param","","Param File (*.json)");
if (!fileName.isNull())
{
int nRowIndex = ui->tableWidget_2->currentRow();
if (nRowIndex != -1)
{
QList<QTableWidgetItem*>items = ui->tableWidget_2->selectedItems();
QTableWidgetItem*item = items.at(0);
if (item)
{
int nCurrentID = item->data(Qt::UserRole).toInt();
IDetectorAlgorithm* pAlgo = m_pCurrentTask->GetAlgorithm(nCurrentID);
if (!pAlgo)
return false;
QByteArray byteArray;
byteArray = pAlgo->ExportParam();
QFile file(fileName);
if (file.open(QFile::WriteOnly))
{
file.write(byteArray);
return true;
}
}
}
}
return true;
}
bool CMainFrame::OnImportOutParam()
{
QString strFileName = QFileDialog::getOpenFileName(this, "open file", "", "File (*.json)");
if (strFileName.length() > 0)
{
int nRowIndex = ui->tableWidget_2->currentRow();
if (nRowIndex != -1)
{
QList<QTableWidgetItem*>items = ui->tableWidget_2->selectedItems();
QTableWidgetItem*item = items.at(0);
if (item)
{
int nCurrentID = item->data(Qt::UserRole).toInt();
IDetectorAlgorithm* pAlgo = m_pCurrentTask->GetAlgorithm(nCurrentID);
if (!pAlgo)
return false;
QFile file(strFileName);
QByteArray byteArray;
if (!file.open(QIODevice::ReadOnly))
{
return false;
}
byteArray = file.readAll();
if (byteArray.size() == 0)
return true;
QJsonParseError parse_error;
QJsonDocument document = QJsonDocument::fromJson(byteArray, &parse_error);
if (parse_error.error == QJsonParseError::NoError)
{
if (!document.isEmpty() && !document.isNull())
{
if (document.isArray())
{
QJsonArray paramArray = document.array();
pAlgo->ImportOutParam(paramArray);
return true;
}
}
}
}
}
}
return true;
}
bool CMainFrame::OnExportOutParam()
{
QString fileName = QFileDialog::getSaveFileName(this, "Open Param", "", tr("Param File (*.json)"));
if (!fileName.isNull())
{
int nRowIndex = ui->tableWidget_2->currentRow();
if (nRowIndex != -1)
{
QList<QTableWidgetItem*>items = ui->tableWidget_2->selectedItems();
QTableWidgetItem*item = items.at(0);
if (item)
{
int nCurrentID = item->data(Qt::UserRole).toInt();
IDetectorAlgorithm* pAlgo = m_pCurrentTask->GetAlgorithm(nCurrentID);
if (!pAlgo)
return false;
QByteArray byteArray;
byteArray = pAlgo->ExportOutParam();
QFile file(fileName);
if (file.open(QFile::WriteOnly))
{
file.write(byteArray);
return true;
}
}
}
}
return true;
}
bool CMainFrame::OnUpdateRelyOnAlgo()
{
int nRowIndex = ui->tableWidget_2->currentRow();
if (nRowIndex != -1)
{
QList<QTableWidgetItem*>items = ui->tableWidget_2->selectedItems();
QTableWidgetItem*item = items.at(0);
if (item)
{
int nCurrentID = item->data(Qt::UserRole).toInt();
IDetectorAlgorithm* pAlgo = m_pCurrentTask->GetAlgorithm(nCurrentID);
if (!pAlgo)
return false;
QString strName = m_pCurrentTask->GetTaskInfo()->strName;
QList<int> rltList = pAlgo->UpdateRelyOnAlgo();
if (rltList.size() <= 0)
return false;
if (!m_TaskChangeList.contains(strName))
{
m_TaskChangeList.append(strName);
}
return true;
}
}
return false;
}
QString CMainFrame::GetParamTypeStr(AlgoParamType type)
{
QString strType;
return AlgoParamName[type];
switch (type)
{
case LP_INT:
{
strType = "INT";
break;
}
case LP_BOOLEAN:
{
strType = "BOOLEAN";
break;
}
case LP_STRING:
{
strType = "STRING";
break;
}
case LP_DOUBLE:
{
strType = "DOUBLE";
break;
}
case LP_IMAGE:
{
strType = "IMAGE";
break;
}
default:
break;
}
return strType;
}
void CMainFrame::OnCellChanged(int row, int column)
{
QString str = sender()->objectName();
int a = 1;
}
bool CMainFrame::OnNextBtnClick()
{
// int index = ui->listWidget->currentRow();
// int maxindex = ui->listWidget->count()-1;
//
// if (index < maxindex)
// {
// ui->listWidget->setCurrentRow(index + 1);
// OnListItemClick();
// }
return OnRunAlgo();
}
void CMainFrame::OnCellClicked(int row, int column)
{
return;
QTableWidgetItem *pWidget = ui->tableWidget->item(row, column);
if (2 == column)
{
QComboBox *pCombox = new QComboBox(ui->tableWidget);
for (int i = 0; i < LP_MAX_ALGO_PARAM_NUM; i++)
{
pCombox->insertItem(i, AlgoParamName[i]);
}
pCombox->setEditable(false);
ui->tableWidget->setCellWidget(row, column, pCombox);
connect(pCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(OnComboxSelect(int)));
}
else if (3 == column)
{
}
}
IDetectorSolution * CMainFrame::currentSolution()
{
if (!m_pCurrentSolution) {
//emit sgShowStatus("current solution not exist");
return NULL;
}
//emit sgShowStatus("current solution exist");
return m_pCurrentSolution;
}
IDetectorTask * CMainFrame::currentTask()
{
if (!m_pCurrentTask) {
//emit sgShowStatus("current task not exist");
return NULL;
}
//emit sgShowStatus("current task exist");
return m_pCurrentTask;
}
IDetectorAlgorithm * CMainFrame::currentAlgorithm()
{
if (!m_pCurrentAlgo) {
//emit sgShowStatus("current algo not exist");
return NULL;
}
//emit sgShowStatus("current algo exist");
return m_pCurrentAlgo;
}
void CMainFrame::OnShowStatus(QString strMess)
{
QStatusBar *p = statusBar();
p->showMessage(strMess);
}
QString CMainFrame::genInfo()
{
//<! solution xx:, task xx:, algo: xx;
QString strMess = "";
return true;
}
void CMainFrame::closeEvent(QCloseEvent *event)
{
return QMainWindow::closeEvent(event);;
if (_pOldTask){
if (!oldMat.empty())
_pOldTask->GetTaskInfo()->templateImg = oldMat;
}
if (SystemStateInfo::bParamStateFlag)
{
QMessageBox msgBox(QMessageBox::Warning, QObject::tr("提示"), QObject::tr("配置已修改过,是否保存相关参数到文件中?"), 0, this);
msgBox.addButton(QObject::tr(""), QMessageBox::AcceptRole);
msgBox.addButton(QObject::tr(""), QMessageBox::RejectRole);
if (msgBox.exec() == QMessageBox::AcceptRole)
{
//m_pDE->Save();
}
SystemStateInfo::bParamStateFlag = false;
}
if (m_pSolutionMgr && m_pSolutionMgr->GetRunSolution()) {
m_pSolutionMgr->SetRunSolution(m_pSolutionMgr->GetRunSolution()->GetSolutionName());
}
//OnManualTrigger();
QMainWindow::closeEvent(event);
}
Q_SLOT void CMainFrame::onLoadImage()
{
if (!currentTask())
return ;
QString strDefaultDirPath = m_pCurrentTask->GetTaskInfo()->strDirPath;
QStringList strFileNamesList = QFileDialog::getOpenFileNames(this, "open file", strDefaultDirPath, "Images (*.bmp *.png *.xpm *.jpg)");
if (strFileNamesList.size() <= 0)
{
return ;
}
QString strFileName = strFileNamesList[0];
std::string strpath = strFileName.toLocal8Bit().toStdString();//中文路径支持
m_pCurrentTask->GetTaskInfo()->templateImg = cv::imread(strpath, CV_LOAD_IMAGE_GRAYSCALE);
oldMat = m_pCurrentTask->GetTaskInfo()->templateImg;
if (ColossusBase::showImage(m_pCurrentTask->GetTaskInfo()->templateImg, ui->gv_input))
{
m_pCurrentTask->GetTaskInfo()->strImageName = strFileName.split("/").last();
}
}