调整逻辑

valve_lucas
bobpan 5 years ago
parent bbd891b243
commit 0cf588eda7

@ -20,7 +20,6 @@ public:
virtual QString stationKey() = 0;
virtual QString stationShowName() = 0;
virtual void setCamInfo(int nId, int alg, QString uniqueName, QString showName) = 0;
virtual void setComInfo(QString strName, int nCmd) = 0;
virtual QVariant getVariant(){ return QVariant(); }
virtual void revResult() = 0;
virtual bool trigImage(const QString folder = QString()) = 0;
@ -40,7 +39,7 @@ public:
virtual QString uniqueModel(const QString &model){ return QString(); }
virtual bool sendResult(double ) = 0;
virtual bool setWidget(QString str, QWidget *pWgt) = 0;
virtual bool setView(QWidget *pWgt) = 0;
virtual bool startBatchTest(QString) = 0;
virtual bool IStandard(QString) = 0;
@ -49,6 +48,7 @@ signals:
void sgPrint2Window(QString &);
void sgUpdateLable();
void sgShowImage(const QImage &img);
void sgShowModeName(int, QString);
protected:
ISerialPortTool *m_pPort{ nullptr };
};

@ -11,7 +11,7 @@ class IWfCtrl :public QObject
public:
IWfCtrl(){};
virtual~IWfCtrl(){};
virtual void onInit() = 0;
virtual bool IOnlineMode() { return false; }
virtual void ISetOnlineModel(bool) {};
virtual bool IBatchModel() = 0;

@ -15,16 +15,12 @@
int Station::s_nTrigWaitTimes = 5;
Station::Station(QSqliteWheelHubWf *p1, ICoreCtrl *p2, IWfCtrl * p3)
: m_pView(NULL), m_pLblImage(NULL), m_pLblStationName(NULL),
m_pDbWf(p1)
: m_pView(NULL),m_pDbWf(p1)
{
m_pResultTextShow = NULL;
m_pCoreCtrl = p2;
m_pWfCtrl = p3;
m_pTrigDetector = new CTrigDetector;
connect(m_pTrigDetector, SIGNAL(sgErrorTrig(int)), this, SLOT(onErrTrig(int)));
connect(this, SIGNAL(sgPrint2Window(QString &)), this, SLOT(onAddResult2TextEdit(QString &)));
connect(this, SIGNAL(sgShowImage(const QImage&)), this, SLOT(showImage(const QImage&)));
connect(this, SIGNAL(sgUpdateLable()), this, SLOT(updateAll()));
connect(this, SIGNAL(sgaddTrigCount(int)), m_pTrigDetector, SLOT(addTrigCount(int)));
connect(this, SIGNAL(sgaddRevCount(int)), m_pTrigDetector, SLOT(addRevCount(int)));
@ -155,22 +151,19 @@ bool Station::initCurrentModel()
bool Station::updateCurrentModel2Label()
{
if (m_pLblStationName) {
bool bCali = false;
WfModel *pModel = wfModel(m_strCurrentModel);
if (pModel) {
//bCali = pModel->bCaliState;
bCali = IStandard(m_strCurrentModel);
}
QString strText = "<html><head / ><body><p><span style = '%1'>%2%3 __ %4 __%5< / span>< / p>< / body>< / html>";
strText = strText.arg("color:#ff0000;").arg(QObject::tr("工位"))
.arg(nId).arg(m_strCurrentModel == "" ? "?" : m_strCurrentModel)
.arg(bCali == true ? QObject::tr("已标定") : QObject::tr("未标定"));
m_pLblStationName->setText(strText);
bool bCali = false;
WfModel *pModel = wfModel(m_strCurrentModel);
if (pModel) {
//bCali = pModel->bCaliState;
bCali = IStandard(m_strCurrentModel);
}
QString strText = "<html><head / ><body><p><span style = '%1'>%2%3 __ %4 __%5< / span>< / p>< / body>< / html>";
strText = strText.arg("color:#ff0000;").arg(QObject::tr("工位"))
.arg(nId).arg(m_strCurrentModel == "" ? "?" : m_strCurrentModel)
.arg(bCali == true ? QObject::tr("已标定") : QObject::tr("未标定"));
emit sgShowModeName(nId, strText);
return true;
}
@ -181,14 +174,6 @@ bool Station::updateAll()
return true;
}
bool Station::onAddResult2TextEdit(QString &str)
{
if (!m_pResultTextShow) {
return false;
}
m_pResultTextShow->append(str);
return true;
}
QVariant Station::getVariant()
{
@ -205,12 +190,12 @@ void Station::onErrTrig(int nErrCount)
else if (s_nTrigWaitTimes * 3 == nErrCount) {
qWarning() << "stationid =" << nId << ",nErrCount = " << nErrCount;
QString str = genTimerInfo() + "camera disconnect!";
onAddResult2TextEdit(str);
emit sgPrint2Window(str);
str = genTimerInfo() + "camera count reset, but not trig again!";
onAddResult2TextEdit(str);
emit sgPrint2Window(str);
m_pTrigDetector->correct();
str = genTimerInfo() + "try reopen camera!";
onAddResult2TextEdit(str);
emit sgPrint2Window(str);
m_pCoreCtrl->IStopCamera(szCamKey);
m_pCoreCtrl->ICloseCamera(szCamKey);
if (m_pWfCtrl->IBatchModel()) {
@ -218,7 +203,7 @@ void Station::onErrTrig(int nErrCount)
}
bool bb = m_pCoreCtrl->IOpenCamera(szCamKey);
str = QString("reopen_%1").arg(bb);
onAddResult2TextEdit(str);
emit sgPrint2Window(str);
bool b = m_pCoreCtrl->IStartCamera(szCamKey);
if (b) {
str = genTimerInfo() + "try reopen successful!";
@ -228,7 +213,7 @@ void Station::onErrTrig(int nErrCount)
str = genTimerInfo() + "reopen failed!";
qWarning() << "stationid = " << nId << ", try reopen camera:" << szCamKey << " failed";
}
onAddResult2TextEdit(str);
emit sgPrint2Window(str);
if (m_pWfCtrl->IBatchModel()) {
trigImage();
}
@ -238,9 +223,9 @@ void Station::onErrTrig(int nErrCount)
else if (s_nTrigWaitTimes == nErrCount || s_nTrigWaitTimes * 2 == nErrCount) {
qWarning() << "camera trig failed!";
QString str = genTimerInfo() + "camera trig failed!";
onAddResult2TextEdit(str);
emit sgPrint2Window(str);
str = genTimerInfo() + "try to trig again!";
onAddResult2TextEdit(str);
emit sgPrint2Window(str);
QStringList strList = m_pCoreCtrl->ICameraKeys();
if (strList.contains(szCamKey))
@ -339,31 +324,9 @@ bool Station::trigImage(const QString folder/* = QString()*/)
return true;
}
bool Station::setWidget(QString str, QWidget *pWgt)
{
// if (str.startsWith(_WF_CAM_LISTWIDGET_PREFIX)) {
m_pView = new ModelView(qobject_cast<QTableView*>(pWgt), this);
// }
// else if (str.startsWith(_WF_LABEL_IMAGE_SHOW_PREFIX)) {
// m_pLblImage = qobject_cast<QLabel*>(pWgt);
// }
// else if (str.startsWith(_WF_LABEL_STATION_NAME_PREFIX)) {
// m_pLblStationName = qobject_cast<QLabel*>(pWgt);
// updateCurrentModel2Label();
// }
// else if (str.startsWith(_WF_TEXT_EDIT_RESULT_PREFIX)) {
// m_pResultTextShow = qobject_cast<QTextEdit*>(pWgt);
// if (m_pResultTextShow) {
// m_pResultTextShow->clear();
// QTextDocument *pDoc = m_pResultTextShow->document();
// pDoc->setMaximumBlockCount(200);
// m_pResultTextShow->append(Station::genTimerInfo() + "start successful");
// }
// }
// else {
// return false;
// }
bool Station::setView(QWidget *pWgt)
{
m_pView = new ModelView(qobject_cast<QTableView*>(pWgt), this);
return true;
}
@ -474,49 +437,6 @@ bool Station::sendResult(double angleValue)
return true;
}
void Station::setComInfo(QString strName, int nCmd)
{
m_strComName = strName;
m_nCmd = nCmd;
}
Q_SLOT void Station::showImage(const QImage &img)
{
// if (m_pImgViewer)
// {
// QImage imgShow = img;
// m_pImgViewer->setImg(imgShow);
// return;
// }
if (!m_pLblImage) {
qDebug() << "label image is null";
return;
}
qDebug() << "show image";
//QRect rt = m_pLblImage->rect();
if (img.isNull())
{
QString str = QObject::tr("检测到错误: 模型与图像尺寸不匹配,请重新标定模型!!!");
m_pLblImage->setText(str);
}
else
{
QRect rt = m_pLblImage->rect();
int h = img.height();
int w = img.width();
float d = w*1.0 / h;
if (d > 0)
{
int h2 = rt.width() / d;
rt.setHeight(h2);
}
QImage imgShow = img.scaled(QSize(rt.size()));
m_pLblImage->setPixmap(QPixmap::fromImage(imgShow));
}
}
QString Station::currentSelectModel()
{
if (m_pView) {

@ -29,7 +29,6 @@ public:
virtual QString stationKey();
virtual QString stationShowName();
virtual void setCamInfo(int nId, int alg, QString uniqueName, QString showName);
virtual void setComInfo(QString strName, int nCmd);
virtual QVariant getVariant();
virtual void revResult();
virtual bool trigImage(const QString folder = QString());
@ -48,11 +47,9 @@ public:
virtual bool delModel(QString strModel);
virtual bool sendResult(double);
virtual bool setWidget(QString str, QWidget *pWgt);
virtual bool setView(QWidget *pWgt);
virtual bool IStandard(QString strModel);
Q_SLOT void showImage(const QImage &img);
Q_SLOT bool onAddResult2TextEdit(QString &str);
Q_SLOT void onErrTrig(int);
virtual bool startBatchTest(QString strBasePath);
@ -63,9 +60,6 @@ public:
private:
class CTrigDetector *m_pTrigDetector;
class ModelView *m_pView;
QLabel *m_pLblImage{ NULL };
QLabel *m_pLblStationName;
QTextEdit *m_pResultTextShow;
int nId;
int nAlgorithm;
QString szShow;
@ -82,7 +76,6 @@ private:
QSqliteWheelHubWf *m_pDbWf;
ICoreCtrl *m_pCoreCtrl;
IWfCtrl *m_pWfCtrl;
class LabelManTest4Ui *m_pBatchTest;
public:
QString getModelUnique(const QString &model);
bool updateCurrentModel2Label();

@ -20,8 +20,6 @@ public:
QMap<QString, class WfModel*> allTask();
bool updateModelInfo(QMap<QString, class WfModel*> &info);
// bool getOnlineModel() const;
// void setOnlineModel(bool b);
bool getBatchModel() const;
QStringList allRunningTask();
bool saveTask(QMap<QString, class WfModel*>);

@ -21,10 +21,7 @@ CWfCtrl::CWfCtrl(ICoreCtrl* p1, WfColossus* p3)
readSettingFile();
QString path;
m_pWfDb = new QSqliteWheelHubWf(path + "//user//");
initGolbal();
initStation();
initModel();
initCurrentModel();
QSettings systemIniFile("systemInfo.ini", QSettings::IniFormat);
m_nOnlineMode = systemIniFile.value("OnlineMode").toBool();
{
@ -90,32 +87,10 @@ void CWfCtrl::ISetOnlineModel(bool b)
systemIniFile.setValue("OnlineMode", m_nOnlineMode);
}
void CWfCtrl::initGolbal()
void CWfCtrl::onInit()
{
//m_nOnlineMode = m_pColossus->getOnlineModel();
// get comm name
// QString strConfig = m_pMainBack->IJsonUser().value("config").toString();
// QString strPath = m_pMainBack->IDllPaths().size() == 0 ? ".\\" : m_pMainBack->IDllPaths().first();
// QJsonObject objJson = QZkJsonParser::ReadJsonObject(strPath + "\\" + strConfig + "\\communicate.json");
// if (!objJson.empty()) {
// QJsonValue jValue = objJson["COM"];
// if (jValue.isArray()) {
// QJsonArray jArray = jValue.toArray();
// for (int i = 0; i < jArray.size(); ++i) {
// if (!jArray[i].isObject()) {
// continue;
// }
// QJsonObject objTmp = jArray[i].toObject();
// m_strCommName = objTmp.value("name").toString();
// qDebug() << "comm name is " << m_strCommName;
// break;
// }
// }
// }
// else {
// qWarning() << "can not find communicate.json";
// }
initModel();
initCurrentModel();
}
bool CWfCtrl::IOnlineMode()
@ -164,7 +139,6 @@ bool CWfCtrl::initModel()
bool CWfCtrl::initStation()
{
QStringList camKeys = m_pCoreCtrl->ICameraKeys();
QString strCom = "COM3";
for (QStringList::iterator it = camKeys.begin(); it != camKeys.end(); ++it) {
TP_CAMERA_OPTION camOpt;
if (!m_pCoreCtrl->ICameraOptionByKey(*it, camOpt)) {
@ -172,7 +146,6 @@ bool CWfCtrl::initStation()
}
IStation *pStation = new Station(m_pWfDb, m_pCoreCtrl, this);
pStation->setCamInfo(camOpt.id, camOpt.algorithm, camOpt.uniqueName, camOpt.showName);
pStation->setComInfo(strCom, 0x46 + camOpt.id - 1);
m_pStationMap.insert(camOpt.uniqueName, pStation);
if (camOpt.deviceType != 100)//虚拟相机模式下不开启定时删除图像的模式

@ -16,6 +16,7 @@ class CWfCtrl : public IWfCtrl
public:
CWfCtrl(ICoreCtrl *, WfColossus*);
virtual~CWfCtrl();
virtual void onInit();
virtual bool IOnlineMode();
virtual void ISetOnlineModel(bool);
virtual bool IBatchModel();
@ -38,7 +39,6 @@ public:
virtual void ISetModifyModel(bool bflag);
virtual QString IGetCurrentRuningModel(int);
private:
void initGolbal();
bool initStation();
bool initModel();
bool initCurrentModel();
@ -47,7 +47,6 @@ private:
void writeSettingFile();
private:
bool m_nOnlineMode{ false };
//QString m_strCommName;
class WorkChecker *m_pConnectChecker{ nullptr };
QMap<QString, IStation*> m_pStationMap;
QMap<QString, WfModel*> m_mpModels;

@ -49,28 +49,6 @@ bool WfColossus::addModel(int nIndex, QString strModel)
bCreate = true;
}
// IDetectorTask *pTasks[c_nMaxTask];
// int n = pSolutions->EnumTask(pTasks, c_nMaxTask);
//
// for (int i = 0; i < n; i++) {
// IDetectorTask *pTask = pTasks[i];
// QString str = pTask->GetTaskInfo()->strName;
// QStringList l = str.split("##");
// if (l.size() != 2) {
// continue;
// }
// if (l.first().toInt() == nIndex && l.last() == WF_MODEL_TEMPLATE_NAME) {
// IDetectorTask *pNew = pSolutions->AddAndCopyTask(pTask);
// PLP_DETECTOR_TASK tTsk = pNew->GetTaskInfo();
// tTsk->strName = combineWithSymbol(QString::number(nIndex), strModel);
// tTsk->bIsRun = false;
// pNew->SetTaskInfo(tTsk);
// bCreate = true;
// break;
// }
// }
if (!bCreate) {
LP_DETECTOR_TASK tTsk;
tTsk.strName = combineWithSymbol(QString::number(nIndex), strModel);

@ -51,7 +51,13 @@ CMainWin::CMainWin(QWidget *parent)
m_pColossus = new WfColossus(m_pDetectorEngine);
m_pWfCtrl = new CWfCtrl(m_pCoreCtrl, m_pColossus);
connect(m_pColossus, SIGNAL(sgSetModel(int, QString)), this, SLOT(onShowName(int, QString)));
QStringList strList = m_pWfCtrl->IGetStationKeys();
foreach(QString str , strList) {
IStation *pS = m_pWfCtrl->IGetStationByKey(str);
connect(pS, SIGNAL(sgShowModeName(int, QString)), this, SLOT(onShowName(int, QString)));
}
m_pWfCtrl->onInit();
m_mangeWid.onInitModelList(m_pWfCtrl);
{//用户管理模块加载

@ -7,11 +7,11 @@
<x>0</x>
<y>0</y>
<width>1028</width>
<height>686</height>
<height>705</height>
</rect>
</property>
<property name="windowTitle">
<string>CMainWin</string>
<string>气门芯定位检测系统</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QGridLayout" name="gridLayout">

@ -124,7 +124,6 @@ Q_SLOT bool QModelMangerUI::OnCellDoubleClicked(const QModelIndex &index)
pModel->nIndex = nIndex;
}
}
return true;
}
@ -183,11 +182,11 @@ void QModelMangerUI::onInitModelList(IWfCtrl *pCtrl)
for (int i = 0; i < lst.size(); i++) {
QTableView *pW = new QTableView(ui.tabWidgetStation);
IStation *pStation = m_pCtrl->IGetStationByKey(lst.at(i));
QString strName = "wf_cam_listwidget_" + QString::number(pStation->stationId());
pW->setObjectName(strName);
QString strObjName = "wf_cam_listwidget_" + QString::number(pStation->stationId());
pW->setObjectName(strObjName);
int nIndex = pStation->stationId()-1;
ui.tabWidgetStation->insertTab(nIndex, (QWidget*)pW, pStation->stationShowName());
pStation->setWidget(strName, pW);
pStation->setView(pW);
connect(pW, SIGNAL(doubleClicked(const QModelIndex &)),this, SLOT(OnCellDoubleClicked(const QModelIndex &)));
}
}

@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>QModelMangerUI</string>
<string>型号管理</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">

@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>QTestModeWid</string>
<string>功能测试</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">

Loading…
Cancel
Save