1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993 |
-
- #include "DataStructure.h"
- #include "Utility.h"
- #include "DllToolCommon.h"
- ////========================================================
- ////
- //// VALUE
- ////
- ////========================================================
- VALUE::VALUE()
- {
- type = VALUE_TYPE::Type_Unknown;
- passMode = VALUE_PASS_MODE::PASS_BY_VALUE;
- Ptr = nullptr;
- }
- /// <summary>
- /// 重载 =
- /// </summary>
- /// <param name="v"></param>
- /// <returns></returns>
- VALUE& VALUE::operator = (const VALUE& v)
- {
- if (this != &v)
- {
- this->type = v.type;
- this->passMode = v.passMode;
- this->Ptr = v.Ptr;
- // this->strValueString = v.strValueString;
- }
- return *this;
- }
- /// <summary>
- /// 重载 ==
- /// </summary>
- /// <param name="other"></param>
- /// <returns></returns>
- bool VALUE::operator == (const VALUE& other) const
- {
- return (
- this->type == other.type
- && this->toString() == other.toString()
- );
- }
- /// <summary>
- /// 是否是基础数据类型(目前只支持5种)
- /// </summary>
- /// <returns></returns>
- bool VALUE::isBaseType() const
- {
- if (this->type == VALUE_TYPE::Type_Int
- || this->type == VALUE_TYPE::Type_String
- || this->type == VALUE_TYPE::Type_Bool
- || this->type == VALUE_TYPE::Type_Float
- || this->type == VALUE_TYPE::Type_Double
- // || this->Type == VALUE_TYPE::Type_CharP
- // || this->Type == VALUE_TYPE::Type_StdString
- )
- {
- return true;
- }
- return false;
- }
- /// <summary>
- /// 是否是基础的数值类型(int float double)
- /// </summary>
- /// <returns></returns>
- bool VALUE::isBaseValueType() const
- {
- if (this->type == VALUE_TYPE::Type_Int
- || this->type == VALUE_TYPE::Type_Float
- || this->type == VALUE_TYPE::Type_Double
- )
- {
- return true;
- }
- return false;
- }
- /// <summary>
- /// 设置数值(按类型字符串)
- /// </summary>
- /// <param name="strValue"></param>
- void VALUE::setValue(const QString& strValue)
- {
- // Value
- if (this->type == VALUE_TYPE::Type_Int)
- {
- this->setValue<int>(strValue.toInt());
- }
- else if (this->type == VALUE_TYPE::Type_String)
- {
- this->setValue<QString>(strValue);
- }
- else if (this->type == VALUE_TYPE::Type_Bool)
- {
- if (strValue == "true" || strValue == "1")
- {
- this->setValue<bool>(true);
- }
- else
- {
- this->setValue<bool>(false);
- }
- }
- else if (this->type == VALUE_TYPE::Type_Float)
- {
- this->setValue<float>(strValue.toFloat());
- }
- else if (this->type == VALUE_TYPE::Type_Double)
- {
- this->setValue<double>(strValue.toDouble());
- }
- else if (this->type == VALUE_TYPE::Type_String)
- {
- QString value;
- this->setValue<QString>(value);
- }
- else if (this->type == VALUE_TYPE::Type_StdString)
- {
- std::string value;
- this->setValue<std::string>(value);
- }
- else if (this->type == VALUE_TYPE::Type_QImage)
- {
- QImage value;
- this->setValue<QImage>(value);
- }
- else if (this->type == VALUE_TYPE::Type_Mat)
- {
- Mat value;
- this->setValue<Mat>(value);
- }
- else if (this->type == VALUE_TYPE::Type_HTuple)
- {
- HTuple value;
- this->setValue<HTuple>(value);
- }
- else if (this->type == VALUE_TYPE::Type_HObject)
- {
- HObject value;
- this->setValue<HObject>(value);
- }
- else if (this->type == VALUE_TYPE::Type_HImage)
- {
- HImage value;
- this->setValue<HImage>(value);
- }
- else if (this->type == VALUE_TYPE::Type_ST_Pos)
- {
- ST_POS value;
- this->setValue<ST_POS>(value);
- }
- else if (this->type == VALUE_TYPE::Type_ST_HomMat2D)
- {
- qWarning() << "setValue Type not supported < VALUE_TYPE::Type_ST_HomMat2D >";
- }
- else if (this->type == VALUE_TYPE::Type_ST_Point)
- {
- qWarning() << "setValue Type not supported < VALUE_TYPE::Type_ST_Point >";
- }
- else if (this->type == VALUE_TYPE::Type_ST_Line)
- {
- qWarning() << "setValue Type not supported < VALUE_TYPE::Type_ST_Line >";
- }
- else if (this->type == VALUE_TYPE::Type_ST_Circle)
- {
- qWarning() << "setValue Type not supported < VALUE_TYPE::Type_ST_Circle >";
- }
- else if (this->type == VALUE_TYPE::Type_ST_Disp)
- {
- qWarning() << "setValue Type not supported < VALUE_TYPE::Type_ST_Disp >";
- }
- else if (this->type == VALUE_TYPE::Type_ST_Window)
- {
- qWarning() << "setValue Type not supported < VALUE_TYPE::Type_ST_Window >";
- }
- else if (this->type == VALUE_TYPE::Type_ST_Ncc_Modle)
- {
- qWarning() << "setValue Type not supported " << static_cast<short>(this->type);
- }
- else if (this->type == VALUE_TYPE::Type_ST_Shape_Modle)
- {
- qWarning() << "setValue Type not supported < VALUE_TYPE::Type_ST_Shape_Modle >";
- }
- else if (this->type == VALUE_TYPE::Type_ST_Calibration)
- {
- qWarning() << "setValue Type not supported < VALUE_TYPE::Type_ST_Calibration >";
- }
- else if (this->type == VALUE_TYPE::Type_ST_CamParam_PoseCalib)
- {
- qWarning() << "setValue Type not supported < VALUE_TYPE::Type_ST_CamParam_PoseCalib >";
- }
- else if (this->type == VALUE_TYPE::Type_pIBaseCamera)
- {
- IBaseCamera* value = nullptr;
- this->setValue<IBaseCamera* >(value);
- }
- else if (this->type == VALUE_TYPE::Type_pIpImage)
- {
- qWarning() << "setValue Type not supported < VALUE_TYPE::Type_pIpImage >";
- }
- else if (this->type == VALUE_TYPE::Type_pISocket)
- {
- qWarning() << "setValue Type not supported < VALUE_TYPE::Type_pISocket >";
- }
- else if (this->type == VALUE_TYPE::Type_pArrayIn)
- {
- qWarning() << "setValue Type not supported < VALUE_TYPE::Type_pArrayIn >";
- }
- else if (this->type == VALUE_TYPE::Type_pArrayOut)
- {
- qWarning() << "setValue Type not supported < VALUE_TYPE::Type_pArrayOut >";
- }
- else if (this->type == VALUE_TYPE::Type_pArrayRobotPos)
- {
- qWarning() << "setValue Type not supported < VALUE_TYPE::Type_pArrayRobotPos >";
- }
- else
- {
- qWarning() << "setValue Type not supported " << static_cast<short>(this->type);
- }
- // 继续补充其他类型
- }
- /// <summary>
- /// 2022-2-23 重置数值(根据不同类型分别处理)
- /// </summary>
- void VALUE::resetValue()
- {
- this->setValue("");
- }
- /// <summary>
- /// 2022-3-25 清空Value
- /// </summary>
- void VALUE::clear()
- {
- this->passMode = VALUE_PASS_MODE::PASS_BY_VALUE;
- this->type = VALUE_TYPE::Type_Unknown;
- this->Ptr = nullptr;
- }
- /// <summary>
- /// 转换至 QString 类型
- /// </summary>
- /// <returns></returns>
- QString VALUE::toString() const
- {
- QString strRet;
- if (this->type == VALUE_TYPE::Type_Int)
- {
- strRet = QString::number(*(int*)this->Ptr);
- }
- else if (this->type == VALUE_TYPE::Type_Float)
- {
- strRet = QString("%1").arg(*(float*)this->Ptr);
- }
- else if (this->type == VALUE_TYPE::Type_Double)
- {
- strRet = QString("%1").arg(*(double*)this->Ptr);
- }
- else if (this->type == VALUE_TYPE::Type_Bool)
- {
- // strRet = QString("%1").arg(*(bool*)this->Ptr);
- // 2022-9-25 修改了bool变量显示的值字符串
- if (*(bool*)this->Ptr == true)
- {
- strRet = "true";
- }
- else
- {
- strRet = "false";
- }
- }
- else if (this->type == VALUE_TYPE::Type_String)
- {
- return (*(QString*)this->Ptr);
- }
- return strRet;
- }
- /// <summary>
- /// 转换至 int 类型
- /// </summary>
- /// <returns></returns>
- int VALUE::toInt() const
- {
- int nRet = 0;
- if (this->type == VALUE_TYPE::Type_Int)
- {
- return (*(int*)this->Ptr);
- }
- else if (this->type == VALUE_TYPE::Type_Float)
- {
- nRet = static_cast<int>(*(float*)this->Ptr);
- }
- else if (this->type == VALUE_TYPE::Type_Double)
- {
- nRet = static_cast<int>(*(double*)this->Ptr);
- }
- else if (this->type == VALUE_TYPE::Type_Bool)
- {
- nRet = static_cast<int>(*(bool*)this->Ptr);
- }
- else if (this->type == VALUE_TYPE::Type_String)
- {
- nRet = (*(QString*)this->Ptr).toInt();
- }
- return nRet;
- }
- /// <summary>
- /// 转换至 float 类型
- /// </summary>
- /// <returns></returns>
- float VALUE::toFloat() const
- {
- float fRet = 0.0;
- if (this->type == VALUE_TYPE::Type_Int)
- {
- fRet = static_cast<float>(*(int*)this->Ptr);
- }
- else if (this->type == VALUE_TYPE::Type_Float)
- {
- return (*(float*)this->Ptr);
- }
- else if (this->type == VALUE_TYPE::Type_Double)
- {
- fRet = static_cast<float>(*(double*)this->Ptr);
- }
- else if (this->type == VALUE_TYPE::Type_Bool)
- {
- fRet = static_cast<float>(*(bool*)this->Ptr);
- }
- else if (this->type == VALUE_TYPE::Type_String)
- {
- fRet = (*(QString*)this->Ptr).toFloat();
- }
- return fRet;
- }
- /// <summary>
- /// 转换至 double 类型
- /// </summary>
- /// <returns></returns>
- double VALUE::toDouble() const
- {
- double dRet = 0.0;
- if (this->type == VALUE_TYPE::Type_Int)
- {
- dRet = static_cast<float>(*(int*)this->Ptr);
- }
- else if (this->type == VALUE_TYPE::Type_Float)
- {
- dRet = static_cast<double>(*(float*)this->Ptr);
- }
- else if (this->type == VALUE_TYPE::Type_Double)
- {
- return (*(double*)this->Ptr);
- }
- else if (this->type == VALUE_TYPE::Type_Bool)
- {
- dRet = static_cast<double>(*(bool*)this->Ptr);
- }
- else if (this->type == VALUE_TYPE::Type_String)
- {
- dRet = (*(QString*)this->Ptr).toDouble();
- }
- return dRet;
- }
- /// <summary>
- /// 转换至 bool 类型
- /// </summary>
- /// <returns></returns>
- bool VALUE::toBool() const
- {
- bool bRet = false;
- if (this->type == VALUE_TYPE::Type_Int)
- {
- bRet = static_cast<bool>(*(int*)this->Ptr);
- }
- else if (this->type == VALUE_TYPE::Type_Float)
- {
- bRet = static_cast<bool>(*(float*)this->Ptr);
- }
- else if (this->type == VALUE_TYPE::Type_Double)
- {
- bRet = static_cast<bool>(*(double*)this->Ptr);
- }
- else if (this->type == VALUE_TYPE::Type_Bool)
- {
- return (*(bool*)this->Ptr);
- }
- else if (this->type == VALUE_TYPE::Type_String)
- {
- QString strValue = (*(QString*)this->Ptr);
- if (strValue == "true" || strValue == "1")
- {
- bRet = true;
- }
- else
- {
- bRet = false;
- }
- }
- return bRet;
- }
- /// <summary>
- /// VALUE序列化
- /// </summary>
- /// <param name="out"></param>
- /// <param name="w"></param>
- /// <returns></returns>
- QDataStream& operator<<(QDataStream& out, const VALUE& v)
- {
- out << v.passMode;
- out << v.type;
- // 2022-9-27 加入了对Ptr为nullptr时的处理
- if (v.Ptr == nullptr)
- {
- out << 0;
- return out;
- }
- else
- {
- out << 1;
- }
- // 根据不同类型写入不同的值
- if (v.type == VALUE_TYPE::Type_Int)
- {
- out << *(int*)v.Ptr;
- }
- else if (v.type == VALUE_TYPE::Type_String)
- {
- out << *((QString*)v.Ptr);
- }
- else if (v.type == VALUE_TYPE::Type_Bool)
- {
- out << *(bool*)v.Ptr;
- }
- else if (v.type == VALUE_TYPE::Type_Float)
- {
- out << *(float*)v.Ptr;
- }
- else if (v.type == VALUE_TYPE::Type_Double)
- {
- out << *(double*)v.Ptr;
- }
- //else if (v.Type == VALUE_TYPE::Type_CharP)
- //{
- // out << QString(*(char*)v.Ptr);
- //}
- else
- {
- }
- return out;
- }
- /// <summary>
- /// VALUE反序列化
- /// </summary>
- /// <param name="in"></param>
- /// <param name="w"></param>
- /// <returns></returns>
- QDataStream& operator>>(QDataStream& in, VALUE& v)
- {
- in >> v.passMode;
- in >> v.type;
- // 2022-9-27,读取是否有值的标志
- int nValueExist = 0;
- in >> nValueExist;
- if (nValueExist == 0)
- {
- v.Ptr = nullptr;
- return in;
- }
- // 根据不同类型读入不同的值
- if (v.type == VALUE_TYPE::Type_Int)
- {
- int newValue = 0;
- in >> newValue;
- v.setValue<int>(newValue);
- }
- else if (v.type == VALUE_TYPE::Type_String)
- {
- QString newValue;
- in >> newValue;
- v.setValue<QString>(newValue);
- }
- else if (v.type == VALUE_TYPE::Type_Bool)
- {
- bool newValue;
- in >> newValue;
- v.setValue<bool>(newValue);
- }
- else if (v.type == VALUE_TYPE::Type_Float)
- {
- float newValue;
- in >> newValue;
- v.setValue<float>(newValue);
- }
- else if (v.type == VALUE_TYPE::Type_Double)
- {
- double newValue;
- in >> newValue;
- v.setValue<double>(newValue);
- }
- //else if (v.Type == VALUE_TYPE::Type_CharP)
- //{
- // out << QString(*(char*)v.Ptr);
- //}
- else
- {
- }
- return in;
- }
- //========================================================
- //
- // _INTERFACE
- //
- //========================================================
- _INTERFACE::_INTERFACE(TOOL* pParent, INF_TYPE type)
- {
- this->Type = type;
- pParentTool = pParent;
- // pOriginalTool = pParent;
- pUpLinkInterface = nullptr;
- pBindInterface = nullptr;
- bWatch = false;
- bSerialized = true;
- bDataLink = false;
- bComplexLinkIndex = false;
- accessMode = VPEnum::GVL_ACCESS_MODE::All;
- bShow = true;
- eventTrigger = nullptr;
- nRefCount = 0;
- // 如果本接口属于ToolStart接口,那么把数值类型也同时设置为 Tool 类型
- if (type == INF_TYPE::INF_TYPE_TOOL)
- {
- this->value.type = VALUE_TYPE::Type_Tool;
- this->bShowName = false; // ToolStart接口不显示名字
- //// TODO:如果以后要改成Tool之间直接连接的话,此处方向不能是输入了
- //this->Direction = INF_DIRECTION::INF_DIR_IN; // 输入接口
- }
- }
- /// <summary>
- /// 根据用户的输入构造一个变量(仅变量类型接口专用)
- /// </summary>
- /// <param name="bSerialized"></param>
- /// <param name="strName"></param>
- /// <param name="strType"></param>
- /// <param name="strValue"></param>
- /// <param name="strComment"></param>
- _INTERFACE::_INTERFACE(
- const QString& strGroup,
- bool bSerialized,
- const QString& strName,
- const QString& strType,
- const QString& strValue,
- const QString& strComment,
- int nIndex,
- bool bShow,
- bool bTrigger /* = false */,
- const QString& strCommAddress /* = "" */,
- VPEnum::GVL_ACCESS_MODE mode /* = GVL_ACCESS_MODE::All*/
- )
- {
- // this->setValue(strGroup, bSerialized, strName, strType, strValue, strComment);
- // 赋值Value属性
- this->value.type = Utility::getTypeByString(strType);
- this->value.setValue(strValue);
- this->value.passMode = VALUE_PASS_MODE::PASS_BY_ADDRESS;
- // 赋值接口属性
- this->bSerialized = bSerialized;
- this->bShow = bShow;
- this->strName = strName;
- this->strFullName = strGroup + "." + strName;
- this->strComment = strComment;
- this->strNameWithType = this->strName + " <" + Utility::getTypeString(this->value.type) + ">";
- // 所有的变量类型都是双向接口
- this->Direction = INF_DIRECTION::INF_DIR_BOTH;
- this->Type = INF_TYPE::INF_TYPE_VALUE;
- this->nIndex = nIndex;
- this->bEnable = true;
- pParentTool = nullptr;
- // pOriginalTool = nullptr;
- pUpLinkInterface = nullptr;
- pBindInterface = nullptr;
- bWatch = false;
- bDataLink = false;
- bComplexLinkIndex = false;
- nRefCount = 0;
- this->strCommAddress = strCommAddress;
- accessMode = mode;
- // 2022-9-1增加,如果支持变量触发,则创建一个触发事件
- if (bTrigger)
- {
- eventTrigger = new ToolEvent(strGroup, this->strName, TOOL_EVENT_TYPE::TASK_TRIGGER);
- }
- else
- {
- eventTrigger = nullptr;
- }
- }
- ///// <summary>
- ///// 构造一个空的接口
- ///// </summary>
- //_INTERFACE::_INTERFACE()
- //{
- // // 所有的变量类型都是双向接口
- // this->Direction = INF_DIRECTION::INF_DIR_BOTH;
- // this->Type = INF_TYPE::INF_TYPE_VALUE;
- // this->nIndex = 0;
- // this->bEnable = true;
- //
- // pParentTool = nullptr;
- // pOriginalTool = nullptr;
- // pUpLinkInterface = nullptr;
- //
- // bWatch = false;
- // bDataLink = false;
- // bComplexLinkIndex = false;
- // nRefCount = 0;
- //}
- /// <summary>
- /// 从基础接口信息中扩展运行时信息
- /// </summary>
- /// <param name="inf"></param>
- void _INTERFACE::basedFrom(const STATIC_INTERFACE& inf)
- {
- this->strName = inf.strName;
- this->Direction = inf.Direction;
- // 2022-6-10 复制接口的是否废弃的状态
- this->Discard = inf.Discard;
- this->Type = inf.Type;
- this->value = inf.value;
- this->nIndex = inf.nIndex;
- this->bEnable = inf.bEnable;
- this->strNameWithType = this->strName + " <" + Utility::getTypeString(this->value.type) + ">";
- // 2022-3-12 复制动态接口状态
- this->bDynamic = inf.bDynamic;
- // 2022-4-8 复制接口名字显示设置
- this->bShowName = inf.bShowName;
- //// 2022-9-19,如果是Event类型接口,要把eventTrigger复制进来
- //this->eventTrigger = (ToolEvent*)inf.value.Ptr;
- }
- ///// <summary>
- ///// 从Dll的接口中拷贝
- ///// </summary>
- ///// <param name="dllInf"></param>
- //void _INTERFACE::copyFrom(const DLL_INF& dllInf)
- //{
- // this->strName = dllInf.strName;
- // this->Direction = dllInf.Direction;
- // this->Type = dllInf.Type;
- // this->value = dllInf.value;
- // this->bEnable = dllInf.bEnable;
- // this->strNameWithType = this->strName + " <" + Utility::getTypeString(this->value.type) + ">";
- //}
- /// <summary>
- /// 是否和指定的接口方向相同
- /// </summary>
- /// <param name="pInf"></param>
- /// <returns></returns>
- bool _INTERFACE::isSameDirectionTo(const _INTERFACE* pInf) const
- {
- return this->Direction == pInf->Direction;
- }
- /// <summary>
- /// 是否和指定的接口方向相反
- /// </summary>
- /// <param name="pInf"></param>
- /// <returns></returns>
- bool _INTERFACE::isRevDirectionTo(const _INTERFACE* pInf) const
- {
- if (this->Direction == INF_DIRECTION::INF_DIR_IN
- && pInf->Direction == INF_DIRECTION::INF_DIR_OUT
- )
- {
- return true;
- }
- if (this->Direction == INF_DIRECTION::INF_DIR_OUT
- && pInf->Direction == INF_DIRECTION::INF_DIR_IN
- )
- {
- return true;
- }
- return false;
- }
- /// <summary>
- /// 是否是相同类型(2021-8-24修改,加入了基础数据类型判断)
- /// </summary>
- /// <param name="pInf"></param>
- /// <param name="ignoreBaseType">是否忽略基础类型(基础类型统一算作是相同类型)</param>
- /// <returns></returns>
- bool _INTERFACE::isSameTypeTo(const _INTERFACE* pInf, bool ignoreBaseType) const
- {
- // 2021-8-24 增加,基础类型算作是相同类型(为了进行接口的强制转换)
- if (ignoreBaseType
- && (this->value.isBaseType() && pInf->value.isBaseType())
- )
- {
- return true;
- }
- return (this->value.type == pInf->value.type);
- }
- /// <summary>
- /// 2022-6-7,父工具是否是相同类型(用于检查ToolInterface之间的连接)
- /// </summary>
- /// <param name="pInf"></param>
- /// <returns></returns>
- bool _INTERFACE::isParentSameTypeTo(const _INTERFACE* pInf) const
- {
- if (this->parent() == nullptr || pInf->parent() == nullptr)
- {
- return false;
- }
- return (this->parent()->Type == pInf->parent()->Type);
- }
- /// <summary>
- /// 是否是基础类型(目前只支持5种)
- /// </summary>
- /// <returns></returns>
- bool _INTERFACE::isBaseType() const
- {
- return this->value.isBaseType();
- }
- /// <summary>
- /// 是否是基础的数值类型(int float double)
- /// </summary>
- /// <returns></returns>
- bool _INTERFACE::isBaseValueType() const
- {
- return this->value.isBaseValueType();
- }
- /// <summary>
- /// 是否是输入接口(包括输入和双向两种)
- /// </summary>
- /// <returns></returns>
- bool _INTERFACE::isDirInput() const
- {
- return (
- this->Direction == INF_DIRECTION::INF_DIR_IN
- || this->Direction == INF_DIRECTION::INF_DIR_BOTH
- );
- }
- /// <summary>
- /// 是否是输出接口(包括输出和双向两种)
- /// </summary>
- /// <returns></returns>
- bool _INTERFACE::isDirOutput() const
- {
- return (
- this->Direction == INF_DIRECTION::INF_DIR_OUT
- || this->Direction == INF_DIRECTION::INF_DIR_BOTH
- );
- }
- /// <summary>
- /// 本接口是否被绑定(Goto或者Port工具等等)
- /// </summary>
- /// <returns></returns>
- bool _INTERFACE::isBinded() const
- {
- // return (this->pOriginalTool != this->pParentTool);
- return (this->pBindInterface != nullptr);
- }
- /// <summary>
- /// 是否是Goto的ToolEnd接口
- /// </summary>
- /// <returns></returns>
- bool _INTERFACE::isGotoToolEnd() const
- {
- return (
- this->pParentTool != nullptr
- && this->pParentTool->isGotoTool()
- && this->Direction == INF_DIRECTION::INF_DIR_OUT
- && this->Type == INF_TYPE::INF_TYPE_TOOL
- );
- }
- /// <summary>
- /// 是否是Parallel的ToolStart接口
- /// </summary>
- /// <returns></returns>
- bool _INTERFACE::isParallelToolStart() const
- {
- return (
- this->pParentTool != nullptr
- && this->pParentTool->isParallelTool()
- && this->Direction == INF_DIRECTION::INF_DIR_IN
- && this->Type == INF_TYPE::INF_TYPE_TOOL
- );
- }
- /// <summary>
- /// 是否是Parallel的ToolEnd接口
- /// </summary>
- /// <returns></returns>
- bool _INTERFACE::isParallelToolEnd() const
- {
- return (
- this->pParentTool != nullptr
- && this->pParentTool->isParallelTool()
- && this->Direction == INF_DIRECTION::INF_DIR_OUT
- && this->Type == INF_TYPE::INF_TYPE_TOOL
- );
- }
- /// <summary>
- /// 是否是ForLoop的ToolEnd接口
- /// </summary>
- /// <returns></returns>
- bool _INTERFACE::isForLoopToolEnd() const
- {
- return (
- this->pParentTool != nullptr
- && this->pParentTool->isForloopTool()
- && this->Direction == INF_DIRECTION::INF_DIR_OUT
- && this->Type == INF_TYPE::INF_TYPE_TOOL
- );
- }
- /// <summary>
- /// 是否是标注标准工具的ToolStart接口
- /// </summary>
- /// <returns></returns>
- bool _INTERFACE::isStandardToolStart() const
- {
- return (
- this->pParentTool != nullptr
- && this->pParentTool->Type == TOOL_TYPE::TOOL_TYPE_STANDARD
- && this->Direction == INF_DIRECTION::INF_DIR_IN
- && this->Type == INF_TYPE::INF_TYPE_TOOL
- );
- }
- /// <summary>
- /// 是否是Tool类型的输入接口(ToolStart)
- /// </summary>
- /// <returns></returns>
- bool _INTERFACE::isToolStart() const
- {
- return (
- this->Direction == INF_DIRECTION::INF_DIR_IN
- && this->Type == INF_TYPE::INF_TYPE_TOOL
- );
- }
- /// <summary>
- /// 是否是Tool类型的输出接口(ToolEnd)
- /// </summary>
- /// <returns></returns>
- bool _INTERFACE::isToolEnd() const
- {
- return (
- this->Direction == INF_DIRECTION::INF_DIR_OUT
- && this->Type == INF_TYPE::INF_TYPE_TOOL
- );
- }
- /// <summary>
- /// 是否是ToolInterface(Start、End)
- /// </summary>
- /// <returns></returns>
- bool _INTERFACE::isToolInterface() const
- {
- return (
- (this->Direction == INF_DIRECTION::INF_DIR_IN
- || this->Direction == INF_DIRECTION::INF_DIR_OUT
- ) && this->Type == INF_TYPE::INF_TYPE_TOOL
- );
- }
- /// <summary>
- /// 获取绑定接口的Parent(而非自身Parent)
- /// </summary>
- /// <returns></returns>
- TOOL* _INTERFACE::bindedParent() const
- {
- if (this->pBindInterface != nullptr)
- {
- return (this->pBindInterface->pParentTool);
- }
- return nullptr;
- }
- /// <summary>
- /// 设置Parent
- /// </summary>
- /// <param name="pParent"></param>
- void _INTERFACE::setParent(TOOL* pParent)
- {
- this->pParentTool = pParent;
- }
- /// <summary>
- /// 设置数值(按类型字符串,模板特化)
- /// </summary>
- /// <param name="strValue"></param>
- void _INTERFACE::setValue(const QString& strValue)
- {
- this->value.setValue(strValue);
- }
- /// <summary>
- /// 获取Dll中的Value指针(因为exe本身不保存dll工具的值、仅保存全局和局部变量的)
- /// </summary>
- /// <returns></returns>
- void** _INTERFACE::getValuePtr() const
- {
- // -- 如果是变量或者全局变量数值类型
- if (this->value.Ptr != nullptr)
- {
- return this->value.Ptr;
- }
- // -- 如果是dll中的数值类型
- if (pParentTool == nullptr || pParentTool->pDllPtr == nullptr || this->nIndex == -1)
- {
- return nullptr;
- }
- if (pParentTool->pDllPtr->GetInterfaceSize() <= this->nIndex)
- {
- return nullptr;
- }
- return pParentTool->pDllPtr->Interface(this->nIndex).value.Ptr;
- }
- /// <summary>
- /// 设置数值对应的字符串
- /// </summary>
- void _INTERFACE::setValueString(const QString& strValue)
- {
- this->valueString = strValue;
- }
- // 获取数值对应的字符串(For debug)
- QString _INTERFACE::getValueString() const
- {
- // 2022-8-24 增加,如果是Tool接口的话,直接返回Tool相关字符串
- if (this->Type == INF_TYPE::INF_TYPE_TOOL)
- {
- if (this->Direction == INF_DIRECTION::INF_DIR_IN)
- {
- return "Tool.Start";
- }
- else
- {
- return "Tool.End";
- }
- }
- // -- 如果是变量或者全局变量数值类型
- if (this->value.Ptr != nullptr)
- {
- return Utility::getValueString(this->value.Ptr, value.type);
- }
- // -- 如果是dll中的数值类型
- if (pParentTool == nullptr || pParentTool->pDllPtr == nullptr)
- {
- return "nullptr";
- }
- if (pParentTool->GetInterfaceSize() <= this->nIndex)
- {
- return "InterfaceSize Error";
- }
- if (pParentTool->pDllPtr->GetInterfaceSize() <= this->nIndex)
- {
- return "Dll InterfaceSize Error";
- }
- if (pParentTool->Interfaces[nIndex]->Discard != INF_DISCARD::INF_DEFAULT)
- {
- QString str;
- switch (pParentTool->Interfaces[nIndex]->Discard)
- {
- case INF_DISCARD::INF_MARK_DELETE:
- str = "Error Inf is Delete";
- break;
- case INF_DISCARD::INF_MARK_CHANGE:
- str = "Error Inf is Change";
- break;
- case INF_DISCARD::INF_MARK_DISCARD:
- str = "Error Inf is Discard";
- break;
- default:
- str = "Error";
- break;
- }
- return str;
- }
- if (pParentTool->Interfaces[nIndex]->strName == pParentTool->pDllPtr->Interface(this->nIndex).strName
- && pParentTool->Interfaces[nIndex]->value.type == pParentTool->pDllPtr->Interface(this->nIndex).value.type
- )
- {
- void** pDllValue = pParentTool->pDllPtr->Interface(this->nIndex).value.Ptr;
- if (*pDllValue != nullptr)
- {
- QString strValue = "";
- strValue = Utility::getValueString(pDllValue, value.type);
- return strValue;
- }
- else
- {
- return "nullptr";
- }
- }
- return "Interface Error";
- }
- /// <summary>
- /// 2022-3-23 获取真实的ParentTool(因为Port绑定的关系,接口的Parent需要转换一下)
- /// </summary>
- /// <returns></returns>
- TOOL* _INTERFACE::realParent() const
- {
- if (!this->isBinded())
- {
- return this->pParentTool;
- }
- else
- {
- return this->pBindInterface->pParentTool;
- }
- }
- /// <summary>
- /// 获取本身的parent
- /// </summary>
- /// <returns></returns>
- TOOL* _INTERFACE::parent() const
- {
- return this->pParentTool;
- }
- ////========================================================
- ////
- //// TOOL_BASE_INFO
- ////
- ////========================================================
- TOOL_BASE_INFO::TOOL_BASE_INFO()
- {
- Type = TOOL_TYPE::TOOL_TYPE_UNKNOWN;
- }
- TOOL_BASE_INFO::TOOL_BASE_INFO(
- TOOL_TYPE type,
- QString name,
- QString aliasName,
- QString instanceName,
- QString category,
- QString version,
- QString info,
- QString comment
- )
- {
- this->Type = type;
- this->strName = name;
- this->strAliasName = aliasName;
- this->strInstanceName = instanceName;
- this->strCategory = category;
- this->strVersion = version;
- this->strInfo = info;
- this->strComment = comment;
- }
- /// <summary>
- /// 是否是Standard类型工具
- /// </summary>
- /// <returns></returns>
- bool TOOL_BASE_INFO::isStandardTool() const
- {
- return (this->Type == TOOL_TYPE::TOOL_TYPE_STANDARD);
- }
- /// <summary>
- /// 是否是Port类型的工具
- /// </summary>
- /// <returns></returns>
- bool TOOL_BASE_INFO::isPortTool() const
- {
- return (this->Type == TOOL_TYPE::TOOL_TYPE_PORT_INPUT
- || this->Type == TOOL_TYPE::TOOL_TYPE_PORT_OUTPUT
- );
- }
- /// <summary>
- /// 是否是硬件类型的工具
- /// </summary>
- /// <returns></returns>
- bool TOOL_BASE_INFO::isHardwareTool() const
- {
- return (this->strPouName == GROUP_NAME_HARDWARE);
- }
- /// <summary>
- /// 是否是Goto类型的工具
- /// </summary>
- /// <returns></returns>
- bool TOOL_BASE_INFO::isGotoTool() const
- {
- return (this->Type == TOOL_TYPE::TOOL_TYPE_GOTO);
- }
- /// <summary>
- /// 是否是Comment类型的工具
- /// </summary>
- /// <returns></returns>
- bool TOOL_BASE_INFO::isCommentTool() const
- {
- return (this->Type == TOOL_TYPE::TOOL_TYPE_COMMENT);
- }
- /// <summary>
- /// 是否是Parallel并行工具组
- /// </summary>
- /// <returns></returns>
- bool TOOL_BASE_INFO::isParallelTool() const
- {
- return (this->Type == TOOL_TYPE::TOOL_TYPE_PARALLEL);
- }
- /// <summary>
- /// 是否是For循环工具
- /// </summary>
- /// <returns></returns>
- bool TOOL_BASE_INFO::isForloopTool() const
- {
- return (this->Type == TOOL_TYPE::TOOL_TYPE_FORLOOP);
- }
- /// <summary>
- /// 2022-9-2 是否是Wait工具
- /// </summary>
- /// <returns></returns>
- bool TOOL_BASE_INFO::isWaitTool() const
- {
- return (this->Type == TOOL_TYPE::TOOL_TYPE_WAIT);
- }
- /// <summary>
- /// 2022-8-21 是否是具备Tool接口的工具(例如标准工具、Parallel工具、For工具等等)
- /// </summary>
- /// <returns></returns>
- bool TOOL_BASE_INFO::isHaveToolInterfaces() const
- {
- return (
- this->Type == TOOL_TYPE::TOOL_TYPE_STANDARD
- || this->Type == TOOL_TYPE::TOOL_TYPE_PARALLEL
- || this->Type == TOOL_TYPE::TOOL_TYPE_FORLOOP
- || this->Type == TOOL_TYPE::TOOL_TYPE_WAIT
- );
- }
- /// <summary>
- /// 2022-8-25 是否是具备索引序号的工具
- /// </summary>
- /// <returns></returns>
- bool TOOL_BASE_INFO::isIndexedTool() const
- {
- return (
- this->Type == TOOL_TYPE::TOOL_TYPE_STANDARD
- || this->Type == TOOL_TYPE::TOOL_TYPE_GOTO
- || this->Type == TOOL_TYPE::TOOL_TYPE_PARALLEL
- || this->Type == TOOL_TYPE::TOOL_TYPE_FORLOOP
- || this->Type == TOOL_TYPE::TOOL_TYPE_WAIT
- );
- }
- /// <summary>
- /// 2022-3-8 是否是默认值变量组
- /// </summary>
- /// <returns></returns>
- bool TOOL_BASE_INFO::isDefaultValueGroup() const
- {
- return (this->strPouName == GROUP_NAME_DEFAULVALUE);
- }
- ///// <summary>
- ///// 生成基础类型信息
- ///// </summary>
- ///// <returns></returns>
- //TOOL_BASE_INFO TOOL_BASE_INFO::baseInfo() const
- //{
- // return TOOL_BASE_INFO(
- // this->Type,
- // this->strName,
- // this->strAliasName,
- // this->strInstanceName,
- // this->strCategory,
- // this->strVersion,
- // this->strInfo
- // );
- //}
- /// <summary>
- /// 重载 =
- /// </summary>
- /// <param name="v"></param>
- /// <returns></returns>
- TOOL_BASE_INFO& TOOL_BASE_INFO::operator =(const TOOL_BASE_INFO& v)
- {
- if (this != &v)
- {
- this->Type = v.Type;
- this->strName = v.strName;
- this->strAliasName = v.strAliasName;
- this->strInstanceName = v.strInstanceName;
- this->strCategory = v.strCategory;
- this->strVersion = v.strVersion;
- this->strInfo = v.strInfo;
- this->strPouName = v.strPouName;
- this->strComment = v.strComment;
- }
- return *this;
- }
- ///// <summary>
- ///// 2022-10-1,编写拷贝构造函数,完成工具原始信息的深度拷贝(目前用于Undo结构中)
- ///// </summary>
- ///// <param name="toolInfo"></param>
- //STATIC_TOOL::STATIC_TOOL(const STATIC_TOOL& toolInfo)
- //{
- // vDebug() << "STATIC_TOOL copy constructor()";
- //}
- //
- //
- //
- //STATIC_TOOL& STATIC_TOOL::operator=(const STATIC_TOOL& toolInfo)
- //{
- // vDebug() << "STATIC_TOOL::operator=";
- //
- // return *this;
- //}
- /// <summary>
- /// 2022-10-14,从TOOL中提取基础信息生成STATIC_TOOL(目前用于Undo体系中记录工具原始信息)
- /// </summary>
- STATIC_TOOL::STATIC_TOOL(const TOOL* tool)
- {
- this->Type = tool->Type;
- this->strName = tool->strName;
- this->strAliasName = tool->strAliasName;
- this->strInstanceName = tool->strInstanceName;
- this->strCategory = tool->strCategory;
- this->strVersion = tool->strVersion;
- this->strInfo = tool->strInfo;
- this->strPouName = tool->strPouName;
- this->strComment = tool->strComment;
- // 如果是标准工具,需要复制DllPath信息
- if (tool->isStandardTool())
- {
- this->strDllPath = tool->pDllPtr->m_strFullPath;
- }
- // 复制接口信息
- for (int i = 0; i < tool->Interfaces.size(); i++)
- {
- const _INTERFACE* toolInf = tool->Interfaces[i];
- STATIC_INTERFACE newStaticInf;
- newStaticInf.strName = toolInf->strName;
- newStaticInf.Direction = toolInf->Direction;
- newStaticInf.Discard = toolInf->Discard;
- newStaticInf.Type = toolInf->Type;
- newStaticInf.value.passMode = toolInf->value.passMode;
- newStaticInf.value.type = toolInf->value.type;
- newStaticInf.nIndex = toolInf->nIndex;
- newStaticInf.bEnable = toolInf->bEnable;
- newStaticInf.bDynamic = toolInf->bDynamic;
- newStaticInf.bShowName = toolInf->bShowName;
- this->staticInterfaces.push_back(newStaticInf);
- }
- }
- ////========================================================
- ////
- //// TOOL
- ////
- ////========================================================
- // 为了GVL增加的构造函数
- TOOL::TOOL(const QString& strName, TOOL_TYPE varType, GVL_MODE gvlMode)
- {
- // 设置为变量类型
- this->Type = varType;
- this->strName = strName;
- // 2021-8-24 增加,修正了port绑定了变量状态下序列化出现的错误
- this->strPouName = strName;
- // 2022-3-2 增加了 GVL的模式
- this->gvlMode = gvlMode;
- bEnable = true;
- bEnableBreakPoint = false;
- // bParallelized = false;
- nIndex = 0;
- parentTool = nullptr;
- pDllPtr = nullptr;
- // 如果是标准类型、Parallel类型、For类型的工具,则需要初始化Tool接口(但是这里是GVL的构造函数,应该不会执行到这里)
- if (this->isHaveToolInterfaces())
- {
- //this->startInterface = new _INTERFACE(this, INF_TYPE::INF_TYPE_TOOLSTART);
- //this->endInterface = new _INTERFACE(this, INF_TYPE::INF_TYPE_TOOLEND);
- for (int i = 0; i < (int)TOOL_INTERFACE_COUNT; i++)
- {
- _INTERFACE* newInf = new _INTERFACE(this, INF_TYPE::INF_TYPE_TOOL);
- this->ToolInterfaces.push_back(newInf);
- }
- this->ToolInterfaces[INF_START]->Direction = INF_DIRECTION::INF_DIR_IN;
- this->ToolInterfaces[INF_END]->Direction = INF_DIRECTION::INF_DIR_OUT;
- }
- //else
- //{
- // this->startInterface = nullptr;
- // this->endInterface = nullptr;
- //}
- }
- TOOL::TOOL(const STATIC_TOOL* pTool)
- {
- this->basedFrom(pTool);
- parentTool = nullptr;
- pDllPtr = nullptr;
- bEnable = true;
- bEnableBreakPoint = false;
- // bParallelized = false;
- nIndex = 0;
- gvlMode = GVL_MODE::GVL_BASIC;
- // 如果是标准类型、Parallel类型、For类型的工具,则需要初始化Tool接口
- if (this->isHaveToolInterfaces())
- {
- for (int i = 0; i < (int)TOOL_INTERFACE_COUNT; i++)
- {
- _INTERFACE* newInf = new _INTERFACE(this, INF_TYPE::INF_TYPE_TOOL);
- this->ToolInterfaces.push_back(newInf);
- }
- this->ToolInterfaces[INF_START]->Direction = INF_DIRECTION::INF_DIR_IN;
- this->ToolInterfaces[INF_END]->Direction = INF_DIRECTION::INF_DIR_OUT;
- }
- //else
- //{
- // this->startInterface = nullptr;
- // this->endInterface = nullptr;
- //}
- }
- /// <summary>
- /// 构造一个空的工具(用于反序列化写入)
- /// </summary>
- TOOL::TOOL()
- {
- this->Type = TOOL_TYPE::TOOL_TYPE_STANDARD;
- parentTool = nullptr;
- pDllPtr = nullptr;
- bEnable = true;
- bEnableBreakPoint = false;
- // bParallelized = false;
- nIndex = 0;
- gvlMode = GVL_MODE::GVL_BASIC;
- //// 直接置空,用于反序列化后写入
- //this->startInterface = nullptr;
- //this->endInterface = nullptr;
- }
- ///// <summary>
- ///// 2022-10-1,编写拷贝构造函数,完成Tool的深度拷贝
- ///// </summary>
- ///// <param name="tool"></param>
- //TOOL::TOOL(const TOOL& tool)
- //{
- // vDebug() << "Tool copy constructor";
- //}
- /// <summary>
- /// 从指定的静态Tool信息中扩展
- /// </summary>
- void TOOL::basedFrom(const STATIC_TOOL* pTool)
- {
- this->Type = pTool->Type;
- this->strName = pTool->strName;
- this->strAliasName = pTool->strAliasName;
- //this->strInstanceName = pTool->strName;
- this->strCategory = pTool->strCategory;
- this->strVersion = pTool->strVersion;
- // this->strDllPath = pTool->strDllPath;
- this->strInfo = pTool->strInfo;
- this->strComment = pTool->strComment;
- for (const STATIC_INTERFACE& pStaticInf : pTool->staticInterfaces)
- {
- _INTERFACE* newInf = new _INTERFACE(this);
- newInf->basedFrom(pStaticInf);
- // newInf->strFullName = this->strInstanceName + "." + newInf->strName;
- this->Interfaces.push_back(newInf);
- }
- }
- /// <summary>
- /// 更新实例名字
- /// </summary>
- void TOOL::updateInstanceName(const QString& strInsName)
- {
- if (this->strInstanceName.isEmpty())
- {
- this->strInstanceName = strInsName;
- }
- for (_INTERFACE* pInf : Interfaces)
- {
- pInf->strFullName = this->strInstanceName + "." + pInf->strName;
- }
- }
- /// <summary>
- /// 根据名字获取指定接口
- /// </summary>
- /// <param name="strInfName"></param>
- /// <returns></returns>
- _INTERFACE* TOOL::getInterfaceByName(const QString& strInfName)
- {
- for (_INTERFACE* pInf : this->Interfaces)
- {
- if (pInf->strName == strInfName)
- {
- return pInf;
- }
- }
- return nullptr;
- }
- /// <summary>
- /// 动态增加接口
- /// </summary>
- /// <param name="newInf"></param>
- /// <returns></returns>
- void TOOL::addInterface(_INTERFACE* newInf)
- {
- Interfaces.push_back(newInf);
- }
- /// <summary>
- /// 根据名字动态删除接口
- /// (因为接口一般动态接口都加在后面,所有从后往前找效率比较高)
- /// </summary>
- /// <param name="strName"></param>
- /// <returns></returns>
- bool TOOL::delInterfaceByName(const QString& strName)
- {
- QVector<_INTERFACE*>::iterator itr = Interfaces.begin();
- for (; itr != Interfaces.end();)
- {
- if ((*itr)->strName == strName)
- {
- itr = Interfaces.erase(itr);
- return true;
- }
- else
- {
- itr++;
- }
- }
- return false;
- }
- /// <summary>
- /// 检查是否已经存在此接口了(按名称)
- /// </summary>
- /// <param name="strName"></param>
- /// <returns></returns>
- bool TOOL::contains(const QString& strName)
- {
- for (_INTERFACE* pInf : this->Interfaces)
- {
- if (pInf->strName == strName)
- {
- return true;
- }
- }
- return false;
- }
- /// <summary>
- /// 2022-3-2 根据全名获取指定接口
- /// </summary>
- /// <param name="strInfFullName"></param>
- /// <returns></returns>
- _INTERFACE* TOOL::getInterfaceByFullName(const QString& strInfFullName)
- {
- for (_INTERFACE* pInf : this->Interfaces)
- {
- if (pInf->strFullName == strInfFullName)
- {
- return pInf;
- }
- }
- return nullptr;
- }
- /// <summary>
- /// 2022-3-23 绑定一个Port接口(仅Port工具使用)
- /// </summary>
- /// <param name="pSourceInf"></param>
- void TOOL::bindPortInterface(_INTERFACE* pSourceInf)
- {
- this->Interfaces[0]->pBindInterface = pSourceInf;
- }
- /// <summary>
- /// 2022-3-23 获取本Port工具绑定的源接口(仅Port工具使用)
- /// </summary>
- /// <returns></returns>
- _INTERFACE* TOOL::bindedInterface()
- {
- if (this->Type == TOOL_TYPE::TOOL_TYPE_PORT_INPUT
- || this->Type == TOOL_TYPE::TOOL_TYPE_PORT_OUTPUT)
- {
- // Port工具目前只用到了0号接口
- return this->Interfaces[0]->pBindInterface;
- }
- return nullptr;
- }
- /// <summary>
- /// 本Port工具是否绑定了接口(仅Port工具使用)
- /// </summary>
- /// <returns></returns>
- bool TOOL::isBinded() const
- {
- if (this->Type == TOOL_TYPE::TOOL_TYPE_PORT_INPUT
- || this->Type == TOOL_TYPE::TOOL_TYPE_PORT_OUTPUT)
- {
- return (this->Interfaces[0]->pBindInterface != nullptr);
- }
- return false;
- }
- /// <summary>
- /// 重置本Port工具状态(仅Port工具使用)
- /// </summary>
- void TOOL::resetPort()
- {
- if (this->Type == TOOL_TYPE::TOOL_TYPE_PORT_INPUT
- || this->Type == TOOL_TYPE::TOOL_TYPE_PORT_OUTPUT)
- {
- _INTERFACE* inf = this->Interfaces[0];
- inf->pBindInterface = nullptr;
- inf->nRefCount = 0;
- inf->strFullName.clear();
- inf->strName.clear();
- inf->Direction = INF_DIRECTION::INF_DIR_OUT;
- inf->Type = INF_TYPE::INF_TYPE_UNKNOWN;
- inf->value.clear();
- }
- }
- /// <summary>
- /// 设置本Port工具状态(仅Port工具使用)
- /// </summary>
- void TOOL::setPortError()
- {
- if (this->Type == TOOL_TYPE::TOOL_TYPE_PORT_INPUT
- || this->Type == TOOL_TYPE::TOOL_TYPE_PORT_OUTPUT)
- {
- this->execParams.nRetValue = VPEnum::RETURN_VALUE::Error;
- }
- }
- /// <summary>
- /// 获取ToolStart接口绑定的上级工具
- /// </summary>
- /// <returns></returns>
- TOOL* TOOL::toolStartUpTool()
- {
- // pStardardBlock->m_toolInfo->TopInterface->pUpLinkInterface->parent();
- if (this->ToolInterfaces.size() <= 0
- || this->ToolInterfaces[INF_START]->pUpLinkInterface == nullptr)
- {
- return nullptr;
- }
- return this->ToolInterfaces[INF_START]->pUpLinkInterface->parent();
- }
- /// <summary>
- /// 2022-8-28 本工具是否加入了并行组(判定规则为ToolStart的上级工具是否为并行工具)
- /// </summary>
- /// <returns></returns>
- bool TOOL::isParallelSubTool()
- {
- TOOL* pUpTool = this->toolStartUpTool();
- if (pUpTool != nullptr && pUpTool->isParallelTool())
- {
- return true;
- }
- return false;
- }
- /// <summary>
- /// 2022-8-28 本工具是否加入了For循环
- /// </summary>
- /// <returns></returns>
- bool TOOL::isForloopSubTool()
- {
- TOOL* pUpTool = this->toolStartUpTool();
- if (pUpTool != nullptr && pUpTool->isForloopTool())
- {
- return true;
- }
- return false;
- }
- /// <summary>
- /// 获取接口的数量
- /// </summary>
- /// <returns></returns>
- int TOOL::GetInterfaceSize()
- {
- return Interfaces.size();
- }
- /// <summary>
- /// 2022-9-5 工具等待触发执行
- /// </summary>
- /// <returns></returns>
- VPEnum::RETURN_VALUE TOOL::waitForExecution(unsigned long timeOut /* = ULONG_MAX */)
- {
- this->mutex.lock();
- if (this->activator.wait(&this->mutex, timeOut) == false)
- {
- this->mutex.unlock();
- return VPEnum::RETURN_VALUE::Error;
- }
- this->mutex.unlock();
- return VPEnum::RETURN_VALUE::Success;
- }
- ///// <summary>
- ///// 2022-4-30 本工具是否并行化(加入了并行组)
- ///// </summary>
- ///// <returns></returns>
- //bool TOOL::isParallelized()
- //{
- // // 2022-5-4 注释,此处的判断虽然正确,但是无法用于反序列化的场景,所以暂时不用了
- // //return (
- // // this->TopInterface != nullptr
- // // && this->TopInterface->pUpLinkInterface != nullptr
- // // && this->TopInterface->pUpLinkInterface->parent()->Type == TOOL_TYPE::TOOL_TYPE_PARALLEL
- // // );
- //}
- ///// <summary>
- ///// 2022-4-27 ToolStart接口是否已连接
- ///// </summary>
- ///// <returns></returns>
- //bool TOOL::isTopLinked() const
- //{
- // return (
- // this->TopInterface != nullptr
- // && this->TopInterface->pUpLinkInterface != nullptr
- // );
- //}
- ///// <summary>
- ///// TOOL序列化
- ///// </summary>
- ///// <param name="out"></param>
- ///// <param name="w"></param>
- ///// <returns></returns>
- //QDataStream& operator<<(QDataStream& out, const TOOL& tool)
- //{
- //
- // int nParanum = 11;//参数数量
- // out << nParanum;//先保存参数数量
- //
- // out << (int)1 << tool.Type;
- // out << (int)2 << tool.strPouName;
- // out << (int)3 << tool.strName;
- // out << (int)4 << tool.strAliasName;
- // out << (int)5 << tool.strInstanceName;
- // out << (int)6 << tool.strInfo;
- // out << (int)7 << tool.strVersion;
- // out << (int)8 << tool.bEnable;
- // out << (int)9 << tool.nIndex;
- // out << (int)10 << tool.strComment;
- // out << (int)11 << tool.bParallelized;
- //
- // // 写入接口数量
- // out << tool.Interfaces.size();
- // // 继续遍历接口
- // for (_INTERFACE* pInf : tool.Interfaces)
- // {
- // out << *pInf;
- // }
- //
- // // 如果是具备ToolStart接口的,还需要额外保存一下ToolStart接口信息
- // if (tool.TopInterface != nullptr)
- // {
- // out << *tool.TopInterface;
- // }
- //
- // return out;
- //}
- ///// <summary>
- ///// TOOL反序列化(暂未使用)
- ///// </summary>
- ///// <param name="in"></param>
- ///// <param name="w"></param>
- ///// <returns></returns>
- //QDataStream& operator>>(QDataStream& in, TOOL& tool)
- //{
- // Q_UNUSED(tool);
- //
- // return in;
- //}
- ////========================================================
- ////
- //// PORT
- ////
- ////========================================================
- PORT::PORT(const STATIC_TOOL* pTool)
- {
- pBindInterface = nullptr;
- // Interface = nullptr;
- this->basedFrom(pTool);
- }
- /// <summary>
- /// 从指定的静态Tool信息中扩展
- /// </summary>
- /// <param name="pTool"></param>
- void PORT::basedFrom(const STATIC_TOOL* pTool)
- {
- this->Type = pTool->Type;
- this->strName = pTool->strName;
- this->strAliasName = pTool->strAliasName;
- this->strInfo = pTool->strInfo;
- this->strVersion = pTool->strVersion;
- _INTERFACE* newInf = new _INTERFACE((TOOL*)this);
- newInf->basedFrom(pTool->staticInterfaces[0]);
- newInf->strFullName = this->strName + "." + newInf->strName;
- Interfaces.push_back(newInf);
- }
- //============================================================
- //
- // Other
- //
- //============================================================
- QEvent::Type SyncControlEvent::m_EventType = QEvent::None;
- QEvent::Type SyncValueEvent::m_EventType = QEvent::None;
- QEvent::Type SyncHdValueEvent::m_EventType = QEvent::None;
- QEvent::Type SyncInterfaceEvent::m_EventType = QEvent::None;
|