1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483 |
- #include "ToolDialog.h"
- #include <QImage>
- #include <QFileInfo>
- #include <QFileDialog>
- #include <QElapsedTimer>
- #include <QGridLayout>
- //////////////////////////////////////////////////////////////////////////
- #include "Qsci/qsciapis.h"
- #include "Qsci/qscilexercpp.h"
- #include "Qsci/qscilexercpp.h"
- #include "Qsci/qscilexerlua.h"
- #include "Qsci/qsciscintilla.h"
- //////////////////////////////////////////////////////////////////////////
- ToolDialogImpl::ToolDialogImpl(QWidget *parent, DllTool* pDllTool)
- : DllToolDialog(parent)
- , m_pDllTool(pDllTool)
- {
- ui.setupUi(this);
- this->setWindowFlags(Qt::Dialog | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint /*| Qt::WindowStaysOnTopHint*/);
- // 设置比例
- QList<int> sizes;
- sizes << 1000 << 5000;
- ui.splitter->setSizes(sizes);
- // 显示控件初始化
- hwndUnit = new HWndUnit(this);
- Util::ShowUnitInWidget(ui.Image_widget, hwndUnit);
- hwndUnit->setWndTitle(("WindowHandle"));
- connect(this, SIGNAL(sigUpdateUI()), this, SLOT(on_UpdateUI()));
- ///////////////////////////////>>////////////////
- scriptEdit = new QsciScintilla(ui.widgetEditor);
- scriptEdit->setMarginType(0, QsciScintilla::MarginType:: NumberMargin); //设置编号为0的页边显示行号。
- scriptEdit->setMarginLineNumbers(0, true); //启用行号
- scriptEdit->setMarginWidth(0, 26);
- // QsciLexerCPP* textLexer = new QsciLexerCPP;
- // textLexer = new QsciLexerCPP;
- // textLexer->setColor(QColor("#008000"), QsciLexerCPP::Comment);
- // textLexer->setColor(QColor("#ff0000"), QsciLexerCPP::Number);
- // textLexer->setColor(QColor("#008000"), QsciLexerCPP::CommentLineDoc);
- // textLexer->setColor(QColor("#008000"), QsciLexerCPP::DoubleQuotedString);
- // textLexer->setColor(QColor("#ff00ff"), QsciLexerCPP::SingleQuotedString);
- // textLexer->setColor(QColor("#0055ff"), QsciLexerCPP::Keyword);
- // textLexer->setColor(QColor("#0055ff"), QsciLexerCPP::PreProcessor);
- //
- //
- // textLexer->setDefaultPaper("#464646");
- // scriptEdit->setLexer(textLexer);
-
- //开启自动缩进
- scriptEdit->setAutoIndent(true);
- //设置缩进的显示方式
- //scriptEdit->setIndentationGuides(QsciScintilla::SC_IV_LOOKBOTH);
- //显示选中的行号
- scriptEdit->setCaretLineVisible(true);
- //显示选中行号的背景色
- scriptEdit->setCaretLineBackgroundColor(Qt::lightGray);
- //左侧行号显示的背景色
- scriptEdit->setMarginsBackgroundColor(Qt::gray);
- //设置括号匹配
- scriptEdit->setBraceMatching(QsciScintilla::BraceMatch::SloppyBraceMatch);
- scriptEdit->setFolding(QsciScintilla::FoldStyle::BoxedTreeFoldStyle);//折叠样式
- scriptEdit->setFoldMarginColors(Qt::gray, Qt::lightGray);//折叠栏颜色
- scriptEdit->setAutoCompletionThreshold(3);//设置每输入一个字符就会出现自动补全的提示
- scriptEdit->setFont(QFont("Courier New")); //设置字体
- scriptEdit->SendScintilla(QsciScintilla::SCI_SETCODEPAGE, QsciScintilla::SC_CP_UTF8); //设置编码为UTF-8
- connect(scriptEdit, SIGNAL(textChanged()), this, SLOT(documentWasModified()));
- QVBoxLayout* vLayout = new QVBoxLayout();
- vLayout->setContentsMargins(1, 1, 1, 1);
- vLayout->setObjectName(QStringLiteral("vLayout"));
- vLayout->addWidget(scriptEdit);
- ui.widgetEditor->setLayout(vLayout);
- ////////////////////////////////<<///////////////
- }
- ToolDialogImpl::~ToolDialogImpl()
- {
- if (scriptEdit != nullptr)
- {
- delete scriptEdit;
- scriptEdit = nullptr;
- }
- }
- VPEnum::RETURN_VALUE ToolDialogImpl::Execute()
- {
- //return VPEnum::RETURN_VALUE::Success;
- try
- {
-
- {
- try
- {
- HImage m_Image;
- try
- {
- GetDebugDataPtr()->Clear();
- //绑定
- HDevProcedureCall proc_call_fib(proc_fib);
- for (int i = 0; i < m_HalconScript.Function.size(); i++)
- {
- H_FUNCTION& mFunction = m_HalconScript.Function[i];
- for (int j = 0; j < mFunction.Interfaces_io.size(); j++)
- {
- H_INTERFACE_HOBJECT& h_inf = mFunction.Interfaces_io[j];
- QString strName = h_inf.strName;
- HImage img = mFunction.Interfaces_io[j].ho_Object;
- proc_call_fib.SetInputIconicParamObject(strName.toStdString().c_str(), img);
- // hwndUnit->ShowImage(img);
- // hwndUnit->Refresh();
- }
- for (int j = 0; j < mFunction.Interfaces_ic.size(); j++)
- {
- QString strName = mFunction.Interfaces_ic.at(j).strName;
-
- if (strName == "WindowHandle")
- {
- HTuple hv_WindowHandle = hwndUnit->getHWndCtrl()->getWindowID();
- proc_call_fib.SetInputCtrlParamTuple(strName.toStdString().c_str(), hv_WindowHandle);
- }
- else
- {
- HTuple hv_Tuple = mFunction.Interfaces_ic.at(j).hv_HTuple;
- proc_call_fib.SetInputCtrlParamTuple(strName.toStdString().c_str(), hv_Tuple);
- }
-
- }
- }
-
- //执行
- proc_call_fib.Execute();
-
- for (int i = 0; i < m_HalconScript.Function.size(); i++)
- {
- H_FUNCTION& mFunction = m_HalconScript.Function[i];
- for (int j = 0; j < mFunction.Interfaces_oo.size(); j++)
- {
- H_INTERFACE_HOBJECT& h_Inf = mFunction.Interfaces_oo[j];
- QString strName = h_Inf.strName;
- HObject obj;
- //if (h_Inf.strSem_type == ("object"))
- {
- obj = proc_call_fib.GetOutputIconicParamObject(strName.toStdString().c_str());
- mFunction.Interfaces_oo[j].ho_Object = obj;
- }
-
- GetDebugDataPtr()->addObj(mFunction.Interfaces_oo[j].ho_Object, qRgb(255, 0, 0));
-
- }
- }
- for (int i = 0; i < m_HalconScript.Function.size(); i++)
- {
- H_FUNCTION& mFunction = m_HalconScript.Function[i];
- for (int j = 0; j < mFunction.Interfaces_oc.size(); j++)
- {
- H_INTERFACE_HTUPLE& h_Inf = mFunction.Interfaces_oc[j];
- QString strName = h_Inf.strName;
- HTuple tup;
-
- proc_call_fib.GetOutputCtrlParamTuple(strName.toStdString().c_str(), & tup );
- mFunction.Interfaces_oc[j].hv_HTuple = tup;
- GetDebugDataPtr()->addMsg(tup);
- }
- }
- }
- catch (HException& HDevExpDefaultException)
- {
- HTuple hv_Exception;
- HDevExpDefaultException.ToHTuple(&hv_Exception);
- int nExceptionID = (hv_Exception.D());
- QString strCodeName = HDevExpDefaultException.ProcName().Text();
- QString strErrorMsg = HDevExpDefaultException.ErrorMessage().Text();
- }
- catch (HDevEngineException& hdev_exception)
- {
- string msg = (("### %s %d:%s\n"), hdev_exception.ProgLineName(), hdev_exception.ProgLineNum(),
- hdev_exception.Message());
- QString strError(msg.c_str());
- qWarning() << strError;
- }
- }
- catch (HException& HDevExpDefaultException)
- {
- HTuple hv_Exception;
- HDevExpDefaultException.ToHTuple(&hv_Exception);
- int nExceptionID = (hv_Exception.D());
- QString strCodeName = HDevExpDefaultException.ProcName().Text();
- QString strErrorMsg = HDevExpDefaultException.ErrorMessage().Text();
- }
- catch (HDevEngineException& hdev_exception)
- {
- string msg = (("### %s %d:%s\n"), hdev_exception.ProgLineName(), hdev_exception.ProgLineNum(),
- hdev_exception.Message());
- QString strError(msg.c_str());
- qWarning() << strError;
- }
- }
- // hwndUnit->ShowImage(m_Image);
- //hwndUnit->ShowObj(m_hoBrushObj, qRgb(255, 0, 0), 0.5);
- // hwndUnit->Refresh();
- }
- catch (...)
- {
- qWarning() << "Execute() Error";
- }
-
- emit sigUpdateUI();
- //m_TestClass.SetValue(m_Value3);
- return VPEnum::RETURN_VALUE::Success;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="bRun"></param>
- void ToolDialogImpl::Running(bool bRun)
- {
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="event"></param>
- void ToolDialogImpl::timerEvent(QTimerEvent* event)
- {
-
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="nIndex"></param>
- /// <returns></returns>
- bool ToolDialogImpl::bindValuePtrByName(const QString strName, const int nIndex)
- {
- // 先添加输入端口
- for (int i = 0; i < m_HalconScript.Function.size(); i++)
- {
- H_FUNCTION& mFunction = m_HalconScript.Function[i];
- if (mFunction.strName != "main")
- {
- // 添加输入的图形变量
- for (int i = 0; i < mFunction.Interfaces_io.size(); i++)
- {
- if (strName == mFunction.Interfaces_io[i].strName)
- {
- m_pDllTool->SetValue(nIndex, mFunction.Interfaces_io[i].ho_Object);
- return true;
- }
- }
- // 添加输入的 控制变量
- for (int i = 0; i < mFunction.Interfaces_ic.size(); i++)
- {
- if (mFunction.Interfaces_ic[i].strName != "WindowHandle")
- {
- if (strName == mFunction.Interfaces_ic[i].strName)
- {
- m_pDllTool->SetValue(nIndex, mFunction.Interfaces_ic[i].hv_HTuple);
- return true;
- }
- }
-
- }
- // 添加输出的 图形变量
- for (int i = 0; i < mFunction.Interfaces_oo.size(); i++)
- {
- if (strName == mFunction.Interfaces_oo[i].strName)
- {
- m_pDllTool->SetValue(nIndex, mFunction.Interfaces_oo[i].ho_Object);
- return true;
- }
- }
- // 添加输出的 控制变量
- for (int i = 0; i < mFunction.Interfaces_oc.size(); i++)
- {
- if (strName == mFunction.Interfaces_oc[i].strName)
- {
- m_pDllTool->SetValue(nIndex, mFunction.Interfaces_oc[i].hv_HTuple);
- return true;
- }
-
- }
- }
- }
-
-
- return true;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="ar"></param>
- /// <param name="bIsOut"></param>
- /// <returns></returns>
- bool ToolDialogImpl::Serialized(QDataStream& ar, bool bIsOut)
- {
- int paranum;//参数数量
- if (bIsOut)//保存参数流程
- {
- paranum = 5;
- ar << paranum;//先保存参数数量
- ar << (int)1 << m_strScriptBaseName;
- ar << (int)2 << m_strProcName;
- ar << (int)3 << m_HalconScript.strFileVersion;
- ar << (int)4 << m_HalconScript.strHalconVersion;
- ar << (int)5 << (int)m_HalconScript.Function.size();
- {
- for (int i = 0; i < m_HalconScript.Function.size(); i++)
- {
- H_FUNCTION& mFunction = m_HalconScript.Function[i];
- ar << mFunction.strName;
- ar << mFunction.strFunctionName;
- ar << (int)mFunction.Src.size();
- for (int j = 0; j < mFunction.Src.size(); j++)
- {
- ar << mFunction.Src.at(j);
- }
- ar << (int)mFunction.Interfaces_io.size();
- for (int k = 0; k < mFunction.Interfaces_io.size(); k++)
- {
- H_INTERFACE_HOBJECT& inf = mFunction.Interfaces_io[k];
- ar << inf.strName;
- ar << inf.strBase_type;
- ar << inf.strDimension;
- ar << inf.strSem_type;
- }
- ar << (int)mFunction.Interfaces_oo.size();
- for (int k = 0; k < mFunction.Interfaces_oo.size(); k++)
- {
- H_INTERFACE_HOBJECT& inf = mFunction.Interfaces_oo[k];
- ar << inf.strName;
- ar << inf.strBase_type;
- ar << inf.strDimension;
- ar << inf.strSem_type;
- }
- ar << (int)mFunction.Interfaces_ic.size();
- for (int k = 0; k < mFunction.Interfaces_ic.size(); k++)
- {
- H_INTERFACE_HTUPLE& inf = mFunction.Interfaces_ic[k];
- ar << inf.strName;
- ar << inf.strBase_type;
- ar << inf.strDimension;
- ar << inf.strSem_type;
- }
- ar << (int)mFunction.Interfaces_oc.size();
- for (int k = 0; k < mFunction.Interfaces_oc.size(); k++)
- {
- H_INTERFACE_HTUPLE& inf = mFunction.Interfaces_oc[k];
- ar << inf.strName;
- ar << inf.strBase_type;
- ar << inf.strDimension;
- ar << inf.strSem_type;
- }
- }
- }
-
- }
- else//加载参数流程,参数加载顺序一定要跟保存顺序一致
- {
- int nFumctionNameSize = 0;
- int para;
- ar >> paranum;//读取参数数量
- for (int i = 0; i < paranum; i++)
- {
- ar >> para;
- switch (para)
- {
- case 1: ar >> m_strScriptBaseName; break;
- case 2: ar >> m_strProcName; break;
- case 3: ar >> m_HalconScript.strFileVersion; break;
- case 4: ar >> m_HalconScript.strHalconVersion; break;
- case 5: ar >> nFumctionNameSize; break;
-
- default:
- {
- qWarning() << "Serialized(In) Error" ;
- return false;
- }
- break;
- }
- }
- {
- ui.comboBoxFunction->clear();
- for (int i = 0; i < nFumctionNameSize; i++)
- {
- int nSrcSize = 0;
- int nInterfaces_ioSize = 0;
- int nInterfaces_ooSize = 0;
- int nInterfaces_icSize = 0;
- int nInterfaces_ocSize = 0;
- H_FUNCTION mFunction;
- ar >> mFunction.strName;
- ar >> mFunction.strFunctionName;
- ar >> nSrcSize;
- for (int j = 0; j < nSrcSize; j++)
- {
- QString strSrc;
- ar >> strSrc;
- mFunction.Src.push_back(strSrc);
- }
- ar >> nInterfaces_ioSize;
- for (int k = 0; k < nInterfaces_ioSize; k++)
- {
- H_INTERFACE_HOBJECT inf;
- ar >> inf.strName;
- ar >> inf.strBase_type;
- ar >> inf.strDimension;
- ar >> inf.strSem_type;
- mFunction.Interfaces_io.push_back(inf);
- }
- ar >> nInterfaces_ooSize;
- for (int k = 0; k < nInterfaces_ooSize; k++)
- {
- H_INTERFACE_HOBJECT inf;
- ar >> inf.strName;
- ar >> inf.strBase_type;
- ar >> inf.strDimension;
- ar >> inf.strSem_type;
- mFunction.Interfaces_oo.push_back(inf);
- }
- ar >> nInterfaces_icSize;
- for (int k = 0; k < nInterfaces_icSize; k++)
- {
- H_INTERFACE_HTUPLE inf;
- ar >> inf.strName;
- ar >> inf.strBase_type;
- ar >> inf.strDimension;
- ar >> inf.strSem_type;
- mFunction.Interfaces_ic.push_back(inf);
- }
- ar >> nInterfaces_ocSize;
- for (int k = 0; k < nInterfaces_ocSize; k++)
- {
- H_INTERFACE_HTUPLE inf;
- ar >> inf.strName;
- ar >> inf.strBase_type;
- ar >> inf.strDimension;
- ar >> inf.strSem_type;
- mFunction.Interfaces_oc.push_back(inf);
- }
- m_HalconScript.Function.push_back(mFunction);
- ui.comboBoxFunction->addItem(mFunction.strFunctionName);
- ui.comboBoxFunction->setCurrentIndex(1);
- }
- }
-
- //1 将反序列化的数据,刷新到UI
- UpdateScriptByEdit(m_strFunctionName, true);
- QString strPath = "./TempScript.hdev";
- //更新 编辑器的代码到数据结构
-
- // 编译之前保存脚本到临时文件
- SaveXML(strPath);
- // 编译成功
- if (Compile(strPath))
- {
- };
- //3 添加端口
- //4 完成数据与端口的绑定
- }
- return true;
- }
- void ToolDialogImpl::on_UpdateUI()
- {
- }
- /// <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;
- }
- /// <summary>
- ///
- /// </summary>
- void ToolDialogImpl::on_btnLoad_clicked()
- {
- QString runPath = QCoreApplication::applicationDirPath(); //获取exe路径
- QString OpenFile, OpenFilePath;
- OpenFile = QFileDialog::getOpenFileName(this,
- "please choose an Script file",
- runPath + "//..//Scrtpt",
- "Image Files(*.hdev);");
- if (!OpenFile.isEmpty())
- {
- // 清理端口信息 再开始加载新的脚本
- resetValueToInf();
- if (ParseToolXML(OpenFile))
- {
- qDebug() << "Load Script is " << OpenFile << "ok ";
- }
- QDateTime time = QDateTime::currentDateTime();
- QFileInfo fileInfo(OpenFile);
- m_strScriptBaseName = QString("%1%2%3%4")
- .arg(fileInfo.completeBaseName())
- .arg("<")
- .arg(QString::number(time.toTime_t()))
- .arg(">");
- // 编译脚本
- //更新
- UpdateScriptByEdit(m_strFunctionName, true);
- // 添加端口
- addNewValueToInf();
- }
- }
- /// <summary>
- ///
- /// </summary>
- void ToolDialogImpl::on_btnExport_clicked()
- {
- // 编译之前保存脚本到临时文件
- QString runPath = QCoreApplication::applicationDirPath(); //获取exe路径
- QString strFileName = "Project_" + QDateTime::currentDateTime().toString("[yyyy-MM-dd hh-mm]");
- QString strPath = runPath + "//..//Scrtpt//" + strFileName;
- QString strFilePath = QFileDialog::getSaveFileName
- (
- this,
- "Save As",
- strPath,
- ("VisionPlus Files (*.hdev)")
- );
- // 如果选定了文件名
- if (!strFilePath.isNull())
- {
- SaveXML(strFilePath);
- }
- }
- void ToolDialogImpl::on_btnCompile_clicked()
- {
- if (scriptEdit)
- {
- // QString strSrc = scriptEdit->text();
- QString strPath = "./TempScript.hdev";
- //更新 编辑器的代码到数据结构
- UpdateScriptByEdit(m_strFunctionName, false);
- // 编译之前保存脚本到临时文件
- SaveXML(strPath);
-
- // 编译成功
- if (Compile(strPath))
- {
- };
-
- }
-
- }
- /// <summary>
- ///
- /// </summary>
- void ToolDialogImpl::documentWasModified()
- {
- }
- /// <summary>
- /// ParseToolXML
- /// </summary>
- /// <param name="strPath"></param>
- /// <returns></returns>
- bool ToolDialogImpl::ParseToolXML(QString strPath)
- {
- pugi::xml_document xmlDoc;
- if (!xmlDoc.load_file(strPath.toStdString().c_str() , pugi::parse_default, pugi::encoding_utf8))
- {
- return false;
- }
- m_HalconScript.Reset();
- ui.comboBoxFunction->clear();
- pugi::xml_node nodeHdevelop = xmlDoc.child("hdevelop");
- // 读取hdevelop节
- m_HalconScript.strFileVersion = nodeHdevelop.attribute("file_version").as_string();
- m_HalconScript.strHalconVersion = nodeHdevelop.attribute("halcon_version").as_string();
- // 读取 procedure 节
- pugi::xml_node nodeProcedure = nodeHdevelop.child("procedure");
- for (pugi::xml_node nodePro = nodeProcedure; nodePro; nodePro = nodePro.next_sibling())
- {
- H_FUNCTION mFunction;
- mFunction.Reset();
- int ix = 0;
- QString strName(nodePro.attribute("name").as_string());
- mFunction.strName = strName;
- if (strName != ("main"))
- {
- m_strProcName = mFunction.strName;
- }
- QString strFunction;
- strFunction = mFunction.strName + " ( ";//
- // 读取 interface 节
- pugi::xml_node nodeInterface = nodePro.child("interface");
- // 读取 io 节
- pugi::xml_node nodeIO = nodeInterface.child("io");
- ix = 0;
- for (pugi::xml_node nodeIF = nodeIO.first_child(); nodeIF; nodeIF = nodeIF.next_sibling())
- {
- H_INTERFACE_HOBJECT inf;
- // 读取hdevelop节
- inf.strName = nodeIF.attribute("name").as_string();
- inf.strBase_type = nodeIF.attribute("base_type").as_string();
- inf.strDimension = nodeIF.attribute("dimension").as_string();
- mFunction.Interfaces_io.push_back(inf);
- if (ix > 0)
- {
- strFunction = strFunction + (", ");
- }
- strFunction = strFunction + inf.strName;// Name ( io
- ix++;
- }
- strFunction = strFunction + (" : ");// Name ( io :
- // 读取 oo 节
- pugi::xml_node nodeOO = nodeInterface.child("oo");
- ix = 0;
- for (pugi::xml_node nodeIF = nodeOO.first_child(); nodeIF; nodeIF = nodeIF.next_sibling())
- {
- H_INTERFACE_HOBJECT inf;
- // 读取hdevelop节
- inf.strName = nodeIF.attribute("name").as_string();
- inf.strBase_type = nodeIF.attribute("base_type").as_string();
- inf.strDimension = nodeIF.attribute("dimension").as_string();
-
- mFunction.Interfaces_oo.push_back(inf);
- if (ix > 0)
- {
- strFunction = strFunction + (", ");
- }
- strFunction = strFunction + inf.strName;// Name ( io : oo
- ix++;
- }
- strFunction = strFunction + (" : ");// Name ( io : oo :
- // 读取 ic 节
- pugi::xml_node nodeIC = nodeInterface.child("ic");
- ix = 0;
- for (pugi::xml_node nodeIF = nodeIC.first_child(); nodeIF; nodeIF = nodeIF.next_sibling())
- {
- H_INTERFACE_HTUPLE inf;
- // 读取hdevelop节
- inf.strName = nodeIF.attribute("name").as_string();
- inf.strBase_type = nodeIF.attribute("base_type").as_string();
- inf.strDimension = nodeIF.attribute("dimension").as_string();
- mFunction.Interfaces_ic.push_back(inf);
- if (ix > 0)
- {
- strFunction = strFunction + (", ");
- }
- strFunction = strFunction + inf.strName;// Name ( io : oo : ic
- ix++;
- }
- strFunction = strFunction + (" : ");// Name ( io : oo : ic :
- // 读取 oc 节
- pugi::xml_node nodeOC = nodeInterface.child("oc");
- ix = 0;
- for (pugi::xml_node nodeIF = nodeOC.first_child(); nodeIF; nodeIF = nodeIF.next_sibling())
- {
- H_INTERFACE_HTUPLE inf;
- // 读取hdevelop节
- inf.strName = nodeIF.attribute("name").as_string();
- inf.strBase_type = nodeIF.attribute("base_type").as_string();
- inf.strDimension = nodeIF.attribute("dimension").as_string();
-
- mFunction.Interfaces_oc.push_back(inf);
- if (ix > 0)
- {
- strFunction = strFunction + (", ");
- }
- strFunction = strFunction + inf.strName;// Name ( io : oo : ic : oc
- ix++;
- }
- strFunction = strFunction + " )";// Name ( io : oo : ic : oc )
- mFunction.strFunctionName = strFunction;
- // 读取 body 节
- pugi::xml_node nodeBody = nodePro.child("body");
- //遍历
- for (pugi::xml_node node = nodeBody.first_child(); node != nullptr; node = node.next_sibling())
- {
- QString strSrc = node.child_value();//node.text().as_string()
- if (!strSrc.isEmpty())
- {
- mFunction.Src.push_back(QString(strSrc));
- }
- }
- // 读取 body 节
- pugi::xml_node nodeParameter = nodePro.child("docu").child("parameters")/*.child("parameter")*/;
- for (pugi::xml_node nodeIF = nodeParameter.first_child(); nodeIF; nodeIF = nodeIF.next_sibling())
- {
- QString str = nodeIF.attribute("id").as_string();
- QString strIName(str);
- for (pugi::xml_node node = nodeIF.first_child(); node != nullptr; node = node.next_sibling())
- {
- QString strSem_type = node.child_value();//node.text().as_string()
- for (int i = 0; i < mFunction.Interfaces_io.size(); i++)
- {
- if (strIName == mFunction.Interfaces_io.at(i).strName)
- {
- mFunction.Interfaces_io[i].strSem_type = strSem_type;
- }
- }
- for (int i = 0; i < mFunction.Interfaces_oo.size(); i++)
- {
- if (strIName == mFunction.Interfaces_oo.at(i).strName)
- {
- mFunction.Interfaces_oo[i].strSem_type = strSem_type;
- }
- }
- for (int i = 0; i < mFunction.Interfaces_ic.size(); i++)
- {
- if (strIName == mFunction.Interfaces_ic.at(i).strName)
- {
- mFunction.Interfaces_ic[i].strSem_type = strSem_type;
- }
- }
- for (int i = 0; i < mFunction.Interfaces_oc.size(); i++)
- {
- if (strIName == mFunction.Interfaces_oc.at(i).strName)
- {
- mFunction.Interfaces_oc[i].strSem_type = strSem_type;
- }
- }
- }
- }
- m_HalconScript.Function.push_back(mFunction);
- m_strFunctionName = strFunction;
- ui.comboBoxFunction->addItem(strFunction);
- ui.comboBoxFunction->setCurrentIndex(1);
- }
- return TRUE;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="strPath"></param>
- /// <returns></returns>
- bool ToolDialogImpl::SaveXML(QString strPath)
- {
- //
- //char * p = str);
- pugi::xml_document xmlDoc;
- pugi::xml_node nodeHdevelop = xmlDoc.append_child("hdevelop");
- // 声明
- pugi::xml_node pre = xmlDoc.prepend_child(pugi::node_declaration);
- pre.append_attribute("version") = "1.0";
- pre.append_attribute("encoding") = "UTF-8";
- // 增加hdevelop version 节
- nodeHdevelop.append_attribute("file_version").set_value((m_HalconScript.strFileVersion.toStdString().c_str() ));
- nodeHdevelop.append_attribute("halcon_version").set_value((m_HalconScript.strHalconVersion.toStdString().c_str()));
- for (int i = 0; i < m_HalconScript.Function.size(); i++)
- {
- H_FUNCTION& mFunction = m_HalconScript.Function[i];
- // 增加 procedure 节
- pugi::xml_node nodeProcedure = nodeHdevelop.append_child("procedure");
-
- nodeProcedure.append_attribute("name").set_value(mFunction.strName.toStdString().c_str());
- // 增加 interface 节
- pugi::xml_node nodeInterface = nodeProcedure.append_child("interface");
- if (mFunction.Interfaces_io.size() > 0)
- {
- // 在interface 中 增加 IO 节
- pugi::xml_node nodeIO = nodeInterface.append_child("io");
- for (int32_t i = 0; i < mFunction.Interfaces_io.size(); ++i)
- {
- pugi::xml_node nodePar = nodeIO.append_child("par");
- H_INTERFACE_HOBJECT& inf = mFunction.Interfaces_io[i];
- // 增加属性
- nodePar.append_attribute("name").set_value(inf.strName.toStdString().c_str());
- nodePar.append_attribute("base_type").set_value(inf.strBase_type.toStdString().c_str());
- nodePar.append_attribute("dimension").set_value(inf.strDimension.toStdString().c_str());
- }
- }
- if (mFunction.Interfaces_oo.size() > 0)
- {
- // 在interface 中 增加 OO 节
- pugi::xml_node nodeOO = nodeInterface.append_child("oo");
- for (int32_t i = 0; i < mFunction.Interfaces_oo.size(); ++i)
- {
- pugi::xml_node nodePar = nodeOO.append_child("par");
- H_INTERFACE_HOBJECT& inf = mFunction.Interfaces_oo[i];
- // 增加属性
- nodePar.append_attribute("name").set_value(inf.strName.toStdString().c_str());
- nodePar.append_attribute("base_type").set_value(inf.strBase_type.toStdString().c_str());
- nodePar.append_attribute("dimension").set_value(inf.strDimension.toStdString().c_str());
- }
- }
- if (mFunction.Interfaces_ic.size() > 0)
- {
- // 在interface 中 增加 IC 节
- pugi::xml_node nodeIC = nodeInterface.append_child("ic");
- for (int32_t i = 0; i < mFunction.Interfaces_ic.size(); ++i)
- {
- pugi::xml_node nodePar = nodeIC.append_child("par");
- H_INTERFACE_HTUPLE& inf = mFunction.Interfaces_ic[i];
- //
- nodePar.append_attribute("name").set_value(inf.strName.toStdString().c_str());
- nodePar.append_attribute("base_type").set_value(inf.strBase_type.toStdString().c_str());
- nodePar.append_attribute("dimension").set_value(inf.strDimension.toStdString().c_str());
- }
- }
- if (mFunction.Interfaces_oc.size() > 0)
- {
- // 在interface 中 增加 OC 节
- pugi::xml_node nodeOC = nodeInterface.append_child("oc");
- for (int32_t i = 0; i < mFunction.Interfaces_oc.size(); ++i)
- {
- pugi::xml_node nodePar = nodeOC.append_child("par");
- H_INTERFACE_HTUPLE& inf = mFunction.Interfaces_oc[i];
- // 增加属性
- nodePar.append_attribute("name").set_value(inf.strName.toStdString().c_str());
- nodePar.append_attribute("base_type").set_value(inf.strBase_type.toStdString().c_str());
- nodePar.append_attribute("dimension").set_value(inf.strDimension.toStdString().c_str());
- }
- }
- // 增加 body 节
- pugi::xml_node nodeBody = nodeProcedure.append_child("body");
- // 在body 中 增加 l 节
- for (size_t i = 0; i < mFunction.Src.size(); i++)
- {
- pugi::xml_node node1 = nodeBody.append_child("l");
- pugi::xml_node nodeScr1 = node1.append_child(pugi::node_pcdata);
-
- QString strSrc = mFunction.Src.at(i);
- if (!strSrc.isEmpty() )
- {
- strSrc = strSrc.trimmed();
- }
- nodeScr1.set_value(mFunction.Src.at(i).toStdString().c_str());
- }
- // 增加 docu 节
- pugi::xml_node nodeDocu = nodeProcedure.append_child("docu");
- nodeDocu.append_attribute("id").set_value(mFunction.strName.toStdString().c_str());
- // 在docu 中 增加 short 节
- pugi::xml_node nodeShort = nodeDocu.append_child("short");
- nodeShort.append_attribute("lang").set_value("en_US");
- pugi::xml_node nodeCommentBooks4 = nodeShort.append_child(pugi::node_pcdata);
- nodeCommentBooks4.set_value(mFunction.strName.toStdString().c_str());
- // 在docu 中 增加 parameters 节
- pugi::xml_node nodeParameters = nodeDocu.append_child("parameters");
- for (int32_t i = 0; i < mFunction.Interfaces_io.size(); ++i)
- {
- H_INTERFACE_HOBJECT& inf = mFunction.Interfaces_io[i];
- pugi::xml_node nodeBook = nodeParameters.append_child("parameter");
- // 增加属性
-
- nodeBook.append_attribute("id").set_value(inf.strName.toStdString().c_str());
- if (!inf.strSem_type.isEmpty())
- {
- pugi::xml_node nodeSem_type = nodeBook.append_child("sem_type");
- pugi::xml_node nodeType = nodeSem_type.append_child(pugi::node_pcdata);
- nodeType.set_value(inf.strSem_type.toStdString().c_str());
- }
- }
- for (int32_t i = 0; i < mFunction.Interfaces_oo.size(); ++i)
- {
- H_INTERFACE_HOBJECT& inf = mFunction.Interfaces_oo[i];
- pugi::xml_node nodeBook = nodeParameters.append_child("parameter");
- // 增加属性
-
- nodeBook.append_attribute("id").set_value(inf.strName.toStdString().c_str());
- if (!inf.strSem_type.isEmpty())
- {
- pugi::xml_node nodeSem_type = nodeBook.append_child("sem_type");
- pugi::xml_node nodeType = nodeSem_type.append_child(pugi::node_pcdata);
- nodeType.set_value(inf.strSem_type.toStdString().c_str());
- }
- }
- for (int32_t i = 0; i < mFunction.Interfaces_ic.size(); ++i)
- {
- H_INTERFACE_HTUPLE& inf = mFunction.Interfaces_ic[i];
- pugi::xml_node nodeBook = nodeParameters.append_child("parameter");
- // 增加属性
-
- nodeBook.append_attribute("id").set_value(inf.strName.toStdString().c_str());
- if (!inf.strSem_type.isEmpty())
- {
- pugi::xml_node nodeSem_type = nodeBook.append_child("sem_type");
- pugi::xml_node nodeType = nodeSem_type.append_child(pugi::node_pcdata);
- nodeType.set_value(inf.strSem_type.toStdString().c_str());
- }
- }
- for (int32_t i = 0; i < mFunction.Interfaces_oc.size(); ++i)
- {
- H_INTERFACE_HTUPLE& inf = mFunction.Interfaces_oc[i];
- pugi::xml_node nodeBook = nodeParameters.append_child("parameter");
- // 增加属性
-
- nodeBook.append_attribute("id").set_value(inf.strName.toStdString().c_str());
- if (!inf.strSem_type.isEmpty())
- {
- pugi::xml_node nodeSem_type = nodeBook.append_child("sem_type");
- pugi::xml_node nodeType = nodeSem_type.append_child(pugi::node_pcdata);
- nodeType.set_value(inf.strSem_type.toStdString().c_str());
- }
- }
- }
- xmlDoc.save_file(strPath.toStdString().c_str(), "\t", 1U, pugi::encoding_utf8);
- return TRUE;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="FunctionName"></param>
- void ToolDialogImpl::UpdateScriptByEdit(QString FunctionName, bool isLoad)
- {
- if (isLoad)
- {
- for (int i = 0; i < m_HalconScript.Function.size(); i++)
- {
- H_FUNCTION& mFunction = m_HalconScript.Function[i];
- if (mFunction.strName != ("main"))
- {
- //m_strProcName = mFunction.strName;
- QString strSrc;
- for (int i = 0; i < mFunction.Src.size(); i++)
- {
- QString src = mFunction.Src[i] + ("\r\n");
- strSrc = strSrc + src;
- }
- scriptEdit->setText(strSrc);
- }
- }
- }
- else
- {
- QString veQString = scriptEdit->text();
- QStringList listSrc = veQString.split('\r');
- for (int i = 0; i < m_HalconScript.Function.size(); i++)
- {
- H_FUNCTION& mFunction = m_HalconScript.Function[i];
- if (mFunction.strName != ("main"))
- {
- //if (mFunction.strFunctionName == FunctionName)
- {
- m_HalconScript.Function[i].Src.clear();
- for (int j= 0;j < listSrc.size() ;j++)
- {
- QString str = listSrc[j];
- m_HalconScript.Function[i].Src.push_back(str);
- }
-
- }
- }
- }
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="strPath"></param>
- bool ToolDialogImpl::Compile(QString strPath)
- {
- // TODO: 在此添加控件通知处理程序代码
- try
- {
- QString str;
- //m_wndBindingFunction.GetLBText(m_wndBindingFunction.GetCurSel(), str);
- QString ComName = str;
- //指定脚本路径
- if (m_strProcName.isEmpty())
- {
- ui.textOutput->append("Compile Error ProcName.isEmpty !" );
- return false;
- }
- my_program.LoadProgram(strPath.toStdString().c_str() );
- proc_fib.LoadProcedure(my_program, m_strProcName.toStdString().c_str() );
- //显式编译
- if (1)
- {
- proc_fib.CompileUsedProcedures();
- }
- ui.textOutput->append("Compile OK !");
- QFile::remove(strPath);
-
- return true;
- }
- catch (HDevEngineException& hdev_exception)
- {
- hdev_exception = hdev_exception; // suppress warning
- string msg = (("### %s %d:%s"), hdev_exception.ProgLineName(), hdev_exception.ProgLineNum(),
- hdev_exception.Message());
- QString strError(msg.c_str());
- //qWarning() << strError;
- ui.textOutput->append(strError);
- return false;
- }
- return false;
- }
- void ToolDialogImpl::on_checkBoxEnableDebug_stateChanged(int arg1)
- {
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- bool ToolDialogImpl::addNewValueToInf()
- {
- // 通知exe端添加对应的接口数据结构
- QList<DLL_INF> dynInfs;
- // 先添加输入端口
- for (int i = 0; i < m_HalconScript.Function.size(); i++)
- {
- H_FUNCTION& mFunction = m_HalconScript.Function.at(i);
- if (mFunction.strName != "main")
- {
- // 添加输入的图形变量
- for (int i = 0; i < mFunction.Interfaces_io.size(); i++)
- {
- H_INTERFACE_HOBJECT& h_inf = mFunction.Interfaces_io[i];
-
- DLL_INF inf;
- inf.strName = h_inf.strName;
- inf.Direction = INF_DIRECTION::INF_DIR_IN;
- inf.value.passMode = VALUE_PASS_MODE::PASS_BY_VALUE;
- if (h_inf.strSem_type == "image")
- {
- inf.value.type = VALUE_TYPE::Type_HImage;
- }
- else
- {
- inf.value.type = VALUE_TYPE::Type_HObject;
- }
-
- inf.value.Ptr = (void**)&mFunction.Interfaces_io[i].ho_Object;
- inf.nIndex = m_pDllTool->GetInterfaceSize();
- // 设置为动态接口
- inf.bDynamic = true;
- // 动态添加
- m_pDllTool->AddInterface(inf);
- // 添加到通知集合中
- dynInfs.push_back(inf);
- }
- // 添加输入的 控制变量
- for (int i = 0; i < mFunction.Interfaces_ic.size(); i++)
- {
- H_INTERFACE_HTUPLE h_inf = mFunction.Interfaces_ic[i];
- // 屏蔽 WindowHandle 端口,此端口为内部端口
- if (h_inf.strName != "WindowHandle")
- {
- DLL_INF inf;
- inf.strName = h_inf.strName;
- inf.Direction = INF_DIRECTION::INF_DIR_IN;
- inf.value.passMode = VALUE_PASS_MODE::PASS_BY_VALUE;
- inf.value.type = VALUE_TYPE::Type_HTuple;
- inf.value.Ptr = (void**)&mFunction.Interfaces_ic[i].hv_HTuple;
- inf.nIndex = m_pDllTool->GetInterfaceSize();
- // 设置为动态接口
- inf.bDynamic = true;
- // 动态添加
- m_pDllTool->AddInterface(inf);
- // 添加到通知集合中
- dynInfs.push_back(inf);
- }
- }
- // 添加输出的 图形变量
- for (int i = 0; i < mFunction.Interfaces_oo.size(); i++)
- {
- H_INTERFACE_HOBJECT& h_inf = mFunction.Interfaces_oo[i];
- DLL_INF inf;
- inf.strName = h_inf.strName;
- inf.Direction = INF_DIRECTION::INF_DIR_OUT;
- inf.value.passMode = VALUE_PASS_MODE::PASS_BY_VALUE;
- inf.value.type = VALUE_TYPE::Type_HObject;
- inf.value.Ptr = (void**)&mFunction.Interfaces_oo[i].ho_Object;
- inf.nIndex = m_pDllTool->GetInterfaceSize();
- // 设置为动态接口
- inf.bDynamic = true;
- // 动态添加
- m_pDllTool->AddInterface(inf);
- // 添加到通知集合中
- dynInfs.push_back(inf);
- }
- // 添加输出的 控制变量
- for (int i = 0; i < mFunction.Interfaces_oc.size(); i++)
- {
- H_INTERFACE_HTUPLE& h_inf = mFunction.Interfaces_oc[i];
- DLL_INF inf;
- inf.strName = h_inf.strName;
- inf.Direction = INF_DIRECTION::INF_DIR_OUT;
- inf.value.passMode = VALUE_PASS_MODE::PASS_BY_VALUE;
- inf.value.type = VALUE_TYPE::Type_HTuple;
- inf.value.Ptr = (void**)&mFunction.Interfaces_oc[i].hv_HTuple;
- inf.nIndex = m_pDllTool->GetInterfaceSize();
- // 设置为动态接口
- inf.bDynamic = true;
- // 动态添加
- m_pDllTool->AddInterface(inf);
-
- // 添加到通知集合中
- dynInfs.push_back(inf);
- }
- }
- }
- // 发送同步动态端口的通知
- this->syncInterfacesToPou(dynInfs, true);
- return true;
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- bool ToolDialogImpl::resetValueToInf()
- {
- // 通知exe端添加对应的接口数据结构
- QList<DLL_INF> dynInfs;
- // 要删除的接口名字
- DLL_INF inf;
- // 删除输入端口
- for (int i = 0; i < m_HalconScript.Function.size(); i++)
- {
- H_FUNCTION& mFunction = m_HalconScript.Function[i];
- if (mFunction.strName != "main")
- {
- // 删除输入的图形变量
- for (int j = 0; j < mFunction.Interfaces_io.size(); j++)
- {
- H_INTERFACE_HOBJECT h_inf = mFunction.Interfaces_io[j];
- inf.strName = h_inf.strName;
- bool bRet = m_pDllTool->DelInterface(inf.strName);// 动态删除
- if (bRet)// 如果删除成功,则添加到通知集合中
- {
- dynInfs.push_back(inf);// 添加到通知集合中
- }
- inf.reset();
- }
- // 删除输入的 控制变量
- for (int j = 0; j < mFunction.Interfaces_ic.size(); j++)
- {
- H_INTERFACE_HTUPLE& h_inf = mFunction.Interfaces_ic[j];
- // 屏蔽 WindowHandle 端口,此端口为内部端口
- if (h_inf.strName != "WindowHandle")
- {
- inf.strName = h_inf.strName;
- bool bRet = m_pDllTool->DelInterface(inf.strName);// 动态删除
- if (bRet)// 如果删除成功,则添加到通知集合中
- {
- dynInfs.push_back(inf);// 添加到通知集合中
- }
- inf.reset();
- }
- }
- // 删除输出的 图形变量
- for (int j = 0; j < mFunction.Interfaces_oo.size(); j++)
- {
- H_INTERFACE_HOBJECT& h_inf = mFunction.Interfaces_oo[j];
- inf.strName = h_inf.strName;
- bool bRet = m_pDllTool->DelInterface(inf.strName);// 动态删除
- if (bRet)// 如果删除成功,则添加到通知集合中
- {
- dynInfs.push_back(inf);// 添加到通知集合中
- }
- inf.reset();
- }
- // 删除输出的 控制变量
- for (int j = 0; j < mFunction.Interfaces_oc.size(); j++)
- {
- H_INTERFACE_HTUPLE& h_inf = mFunction.Interfaces_oc[j];
- inf.strName = h_inf.strName;
- bool bRet = m_pDllTool->DelInterface(inf.strName);// 动态删除
- if (bRet)// 如果删除成功,则添加到通知集合中
- {
- dynInfs.push_back(inf);// 添加到通知集合中
- }
- inf.reset();
- }
- }
- }
- // 发送同步动态端口的通知
- if (dynInfs.size() > 0)
- {
- this->syncInterfacesToPou(dynInfs, false);
- }
- return true;
- }
- /// <summary>
- /// 2022-3-8 向exe中的同步最新的接口变动(一个或多个)
- /// </summary>
- /// <param name="pInfs"></param>
- void ToolDialogImpl::syncInterfacesToPou(QList<DLL_INF> pInfs, bool bAdd)
- {
- SyncInterfaceEvent infEvent;// = new SyncInterfaceEvent();
- // 携带需要同步的多个接口
- infEvent.setSyncValues(pInfs);
- // 设置要本工具的实例名称
- infEvent.m_strInstanceName = this->m_strInstanceName;
- // 增加端口
- infEvent.m_bAdd = bAdd;
- // post数值同步消息
- QCoreApplication::sendEvent(this->m_pPouTarget, &infEvent);
- // 获取事件执行状态
- bool bRet = infEvent.m_bSuccess;
- if (!bRet)
- {
- qWarning() << m_strInstanceName << " add interface error, reason: " << infEvent.m_strReason;
- }
- }
|