#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;
}
///
/// 重载 =
///
///
///
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;
}
///
/// 重载 ==
///
///
///
bool VALUE::operator == (const VALUE& other) const
{
return (
this->type == other.type
&& this->toString() == other.toString()
);
}
///
/// 是否是基础数据类型(目前只支持5种)
///
///
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;
}
///
/// 是否是基础的数值类型(int float double)
///
///
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;
}
///
/// 设置数值(按类型字符串)
///
///
void VALUE::setValue(const QString& strValue)
{
// Value
if (this->type == VALUE_TYPE::Type_Int)
{
this->setValue(strValue.toInt());
}
else if (this->type == VALUE_TYPE::Type_String)
{
this->setValue(strValue);
}
else if (this->type == VALUE_TYPE::Type_Bool)
{
if (strValue == "true" || strValue == "1")
{
this->setValue(true);
}
else
{
this->setValue(false);
}
}
else if (this->type == VALUE_TYPE::Type_Float)
{
this->setValue(strValue.toFloat());
}
else if (this->type == VALUE_TYPE::Type_Double)
{
this->setValue(strValue.toDouble());
}
else if (this->type == VALUE_TYPE::Type_String)
{
QString value;
this->setValue(value);
}
else if (this->type == VALUE_TYPE::Type_StdString)
{
std::string value;
this->setValue(value);
}
else if (this->type == VALUE_TYPE::Type_QImage)
{
QImage value;
this->setValue(value);
}
else if (this->type == VALUE_TYPE::Type_Mat)
{
Mat value;
this->setValue(value);
}
else if (this->type == VALUE_TYPE::Type_HTuple)
{
HTuple value;
this->setValue(value);
}
else if (this->type == VALUE_TYPE::Type_HObject)
{
HObject value;
this->setValue(value);
}
else if (this->type == VALUE_TYPE::Type_HImage)
{
HImage value;
this->setValue(value);
}
else if (this->type == VALUE_TYPE::Type_ST_Pos)
{
ST_POS value;
this->setValue(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(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(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(this->type);
}
// 继续补充其他类型
}
///
/// 2022-2-23 重置数值(根据不同类型分别处理)
///
void VALUE::resetValue()
{
this->setValue("");
}
///
/// 2022-3-25 清空Value
///
void VALUE::clear()
{
this->passMode = VALUE_PASS_MODE::PASS_BY_VALUE;
this->type = VALUE_TYPE::Type_Unknown;
this->Ptr = nullptr;
}
///
/// 转换至 QString 类型
///
///
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;
}
///
/// 转换至 int 类型
///
///
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(*(float*)this->Ptr);
}
else if (this->type == VALUE_TYPE::Type_Double)
{
nRet = static_cast(*(double*)this->Ptr);
}
else if (this->type == VALUE_TYPE::Type_Bool)
{
nRet = static_cast(*(bool*)this->Ptr);
}
else if (this->type == VALUE_TYPE::Type_String)
{
nRet = (*(QString*)this->Ptr).toInt();
}
return nRet;
}
///
/// 转换至 float 类型
///
///
float VALUE::toFloat() const
{
float fRet = 0.0;
if (this->type == VALUE_TYPE::Type_Int)
{
fRet = static_cast(*(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(*(double*)this->Ptr);
}
else if (this->type == VALUE_TYPE::Type_Bool)
{
fRet = static_cast(*(bool*)this->Ptr);
}
else if (this->type == VALUE_TYPE::Type_String)
{
fRet = (*(QString*)this->Ptr).toFloat();
}
return fRet;
}
///
/// 转换至 double 类型
///
///
double VALUE::toDouble() const
{
double dRet = 0.0;
if (this->type == VALUE_TYPE::Type_Int)
{
dRet = static_cast(*(int*)this->Ptr);
}
else if (this->type == VALUE_TYPE::Type_Float)
{
dRet = static_cast(*(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(*(bool*)this->Ptr);
}
else if (this->type == VALUE_TYPE::Type_String)
{
dRet = (*(QString*)this->Ptr).toDouble();
}
return dRet;
}
///
/// 转换至 bool 类型
///
///
bool VALUE::toBool() const
{
bool bRet = false;
if (this->type == VALUE_TYPE::Type_Int)
{
bRet = static_cast(*(int*)this->Ptr);
}
else if (this->type == VALUE_TYPE::Type_Float)
{
bRet = static_cast(*(float*)this->Ptr);
}
else if (this->type == VALUE_TYPE::Type_Double)
{
bRet = static_cast(*(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;
}
///
/// VALUE序列化
///
///
///
///
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;
}
///
/// VALUE反序列化
///
///
///
///
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(newValue);
}
else if (v.type == VALUE_TYPE::Type_String)
{
QString newValue;
in >> newValue;
v.setValue(newValue);
}
else if (v.type == VALUE_TYPE::Type_Bool)
{
bool newValue;
in >> newValue;
v.setValue(newValue);
}
else if (v.type == VALUE_TYPE::Type_Float)
{
float newValue;
in >> newValue;
v.setValue(newValue);
}
else if (v.type == VALUE_TYPE::Type_Double)
{
double newValue;
in >> newValue;
v.setValue(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; // 输入接口
}
}
///
/// 根据用户的输入构造一个变量(仅变量类型接口专用)
///
///
///
///
///
///
_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;
}
}
/////
///// 构造一个空的接口
/////
//_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;
//}
///
/// 从基础接口信息中扩展运行时信息
///
///
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;
}
/////
///// 从Dll的接口中拷贝
/////
/////
//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) + ">";
//}
///
/// 是否和指定的接口方向相同
///
///
///
bool _INTERFACE::isSameDirectionTo(const _INTERFACE* pInf) const
{
return this->Direction == pInf->Direction;
}
///
/// 是否和指定的接口方向相反
///
///
///
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;
}
///
/// 是否是相同类型(2021-8-24修改,加入了基础数据类型判断)
///
///
/// 是否忽略基础类型(基础类型统一算作是相同类型)
///
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);
}
///
/// 2022-6-7,父工具是否是相同类型(用于检查ToolInterface之间的连接)
///
///
///
bool _INTERFACE::isParentSameTypeTo(const _INTERFACE* pInf) const
{
if (this->parent() == nullptr || pInf->parent() == nullptr)
{
return false;
}
return (this->parent()->Type == pInf->parent()->Type);
}
///
/// 是否是基础类型(目前只支持5种)
///
///
bool _INTERFACE::isBaseType() const
{
return this->value.isBaseType();
}
///
/// 是否是基础的数值类型(int float double)
///
///
bool _INTERFACE::isBaseValueType() const
{
return this->value.isBaseValueType();
}
///
/// 是否是输入接口(包括输入和双向两种)
///
///
bool _INTERFACE::isDirInput() const
{
return (
this->Direction == INF_DIRECTION::INF_DIR_IN
|| this->Direction == INF_DIRECTION::INF_DIR_BOTH
);
}
///
/// 是否是输出接口(包括输出和双向两种)
///
///
bool _INTERFACE::isDirOutput() const
{
return (
this->Direction == INF_DIRECTION::INF_DIR_OUT
|| this->Direction == INF_DIRECTION::INF_DIR_BOTH
);
}
///
/// 本接口是否被绑定(Goto或者Port工具等等)
///
///
bool _INTERFACE::isBinded() const
{
// return (this->pOriginalTool != this->pParentTool);
return (this->pBindInterface != nullptr);
}
///
/// 是否是Goto的ToolEnd接口
///
///
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
);
}
///
/// 是否是Parallel的ToolStart接口
///
///
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
);
}
///
/// 是否是Parallel的ToolEnd接口
///
///
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
);
}
///
/// 是否是ForLoop的ToolEnd接口
///
///
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
);
}
///
/// 是否是标注标准工具的ToolStart接口
///
///
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
);
}
///
/// 是否是Tool类型的输入接口(ToolStart)
///
///
bool _INTERFACE::isToolStart() const
{
return (
this->Direction == INF_DIRECTION::INF_DIR_IN
&& this->Type == INF_TYPE::INF_TYPE_TOOL
);
}
///
/// 是否是Tool类型的输出接口(ToolEnd)
///
///
bool _INTERFACE::isToolEnd() const
{
return (
this->Direction == INF_DIRECTION::INF_DIR_OUT
&& this->Type == INF_TYPE::INF_TYPE_TOOL
);
}
///
/// 是否是ToolInterface(Start、End)
///
///
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
);
}
///
/// 获取绑定接口的Parent(而非自身Parent)
///
///
TOOL* _INTERFACE::bindedParent() const
{
if (this->pBindInterface != nullptr)
{
return (this->pBindInterface->pParentTool);
}
return nullptr;
}
///
/// 设置Parent
///
///
void _INTERFACE::setParent(TOOL* pParent)
{
this->pParentTool = pParent;
}
///
/// 设置数值(按类型字符串,模板特化)
///
///
void _INTERFACE::setValue(const QString& strValue)
{
this->value.setValue(strValue);
}
///
/// 获取Dll中的Value指针(因为exe本身不保存dll工具的值、仅保存全局和局部变量的)
///
///
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;
}
///
/// 设置数值对应的字符串
///
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";
}
///
/// 2022-3-23 获取真实的ParentTool(因为Port绑定的关系,接口的Parent需要转换一下)
///
///
TOOL* _INTERFACE::realParent() const
{
if (!this->isBinded())
{
return this->pParentTool;
}
else
{
return this->pBindInterface->pParentTool;
}
}
///
/// 获取本身的parent
///
///
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;
}
///
/// 是否是Standard类型工具
///
///
bool TOOL_BASE_INFO::isStandardTool() const
{
return (this->Type == TOOL_TYPE::TOOL_TYPE_STANDARD);
}
///
/// 是否是Port类型的工具
///
///
bool TOOL_BASE_INFO::isPortTool() const
{
return (this->Type == TOOL_TYPE::TOOL_TYPE_PORT_INPUT
|| this->Type == TOOL_TYPE::TOOL_TYPE_PORT_OUTPUT
);
}
///
/// 是否是硬件类型的工具
///
///
bool TOOL_BASE_INFO::isHardwareTool() const
{
return (this->strPouName == GROUP_NAME_HARDWARE);
}
///
/// 是否是Goto类型的工具
///
///
bool TOOL_BASE_INFO::isGotoTool() const
{
return (this->Type == TOOL_TYPE::TOOL_TYPE_GOTO);
}
///
/// 是否是Comment类型的工具
///
///
bool TOOL_BASE_INFO::isCommentTool() const
{
return (this->Type == TOOL_TYPE::TOOL_TYPE_COMMENT);
}
///
/// 是否是Parallel并行工具组
///
///
bool TOOL_BASE_INFO::isParallelTool() const
{
return (this->Type == TOOL_TYPE::TOOL_TYPE_PARALLEL);
}
///
/// 是否是For循环工具
///
///
bool TOOL_BASE_INFO::isForloopTool() const
{
return (this->Type == TOOL_TYPE::TOOL_TYPE_FORLOOP);
}
///
/// 2022-9-2 是否是Wait工具
///
///
bool TOOL_BASE_INFO::isWaitTool() const
{
return (this->Type == TOOL_TYPE::TOOL_TYPE_WAIT);
}
///
/// 2022-8-21 是否是具备Tool接口的工具(例如标准工具、Parallel工具、For工具等等)
///
///
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
);
}
///
/// 2022-8-25 是否是具备索引序号的工具
///
///
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
);
}
///
/// 2022-3-8 是否是默认值变量组
///
///
bool TOOL_BASE_INFO::isDefaultValueGroup() const
{
return (this->strPouName == GROUP_NAME_DEFAULVALUE);
}
/////
///// 生成基础类型信息
/////
/////
//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
// );
//}
///
/// 重载 =
///
///
///
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;
}
/////
///// 2022-10-1,编写拷贝构造函数,完成工具原始信息的深度拷贝(目前用于Undo结构中)
/////
/////
//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;
//}
///
/// 2022-10-14,从TOOL中提取基础信息生成STATIC_TOOL(目前用于Undo体系中记录工具原始信息)
///
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;
//}
}
///
/// 构造一个空的工具(用于反序列化写入)
///
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;
}
/////
///// 2022-10-1,编写拷贝构造函数,完成Tool的深度拷贝
/////
/////
//TOOL::TOOL(const TOOL& tool)
//{
// vDebug() << "Tool copy constructor";
//}
///
/// 从指定的静态Tool信息中扩展
///
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);
}
}
///
/// 更新实例名字
///
void TOOL::updateInstanceName(const QString& strInsName)
{
if (this->strInstanceName.isEmpty())
{
this->strInstanceName = strInsName;
}
for (_INTERFACE* pInf : Interfaces)
{
pInf->strFullName = this->strInstanceName + "." + pInf->strName;
}
}
///
/// 根据名字获取指定接口
///
///
///
_INTERFACE* TOOL::getInterfaceByName(const QString& strInfName)
{
for (_INTERFACE* pInf : this->Interfaces)
{
if (pInf->strName == strInfName)
{
return pInf;
}
}
return nullptr;
}
///
/// 动态增加接口
///
///
///
void TOOL::addInterface(_INTERFACE* newInf)
{
Interfaces.push_back(newInf);
}
///
/// 根据名字动态删除接口
/// (因为接口一般动态接口都加在后面,所有从后往前找效率比较高)
///
///
///
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;
}
///
/// 检查是否已经存在此接口了(按名称)
///
///
///
bool TOOL::contains(const QString& strName)
{
for (_INTERFACE* pInf : this->Interfaces)
{
if (pInf->strName == strName)
{
return true;
}
}
return false;
}
///
/// 2022-3-2 根据全名获取指定接口
///
///
///
_INTERFACE* TOOL::getInterfaceByFullName(const QString& strInfFullName)
{
for (_INTERFACE* pInf : this->Interfaces)
{
if (pInf->strFullName == strInfFullName)
{
return pInf;
}
}
return nullptr;
}
///
/// 2022-3-23 绑定一个Port接口(仅Port工具使用)
///
///
void TOOL::bindPortInterface(_INTERFACE* pSourceInf)
{
this->Interfaces[0]->pBindInterface = pSourceInf;
}
///
/// 2022-3-23 获取本Port工具绑定的源接口(仅Port工具使用)
///
///
_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;
}
///
/// 本Port工具是否绑定了接口(仅Port工具使用)
///
///
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;
}
///
/// 重置本Port工具状态(仅Port工具使用)
///
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();
}
}
///
/// 设置本Port工具状态(仅Port工具使用)
///
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;
}
}
///
/// 获取ToolStart接口绑定的上级工具
///
///
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();
}
///
/// 2022-8-28 本工具是否加入了并行组(判定规则为ToolStart的上级工具是否为并行工具)
///
///
bool TOOL::isParallelSubTool()
{
TOOL* pUpTool = this->toolStartUpTool();
if (pUpTool != nullptr && pUpTool->isParallelTool())
{
return true;
}
return false;
}
///
/// 2022-8-28 本工具是否加入了For循环
///
///
bool TOOL::isForloopSubTool()
{
TOOL* pUpTool = this->toolStartUpTool();
if (pUpTool != nullptr && pUpTool->isForloopTool())
{
return true;
}
return false;
}
///
/// 获取接口的数量
///
///
int TOOL::GetInterfaceSize()
{
return Interfaces.size();
}
///
/// 2022-9-5 工具等待触发执行
///
///
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;
}
/////
///// 2022-4-30 本工具是否并行化(加入了并行组)
/////
/////
//bool TOOL::isParallelized()
//{
// // 2022-5-4 注释,此处的判断虽然正确,但是无法用于反序列化的场景,所以暂时不用了
// //return (
// // this->TopInterface != nullptr
// // && this->TopInterface->pUpLinkInterface != nullptr
// // && this->TopInterface->pUpLinkInterface->parent()->Type == TOOL_TYPE::TOOL_TYPE_PARALLEL
// // );
//}
/////
///// 2022-4-27 ToolStart接口是否已连接
/////
/////
//bool TOOL::isTopLinked() const
//{
// return (
// this->TopInterface != nullptr
// && this->TopInterface->pUpLinkInterface != nullptr
// );
//}
/////
///// TOOL序列化
/////
/////
/////
/////
//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;
//}
/////
///// TOOL反序列化(暂未使用)
/////
/////
/////
/////
//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);
}
///
/// 从指定的静态Tool信息中扩展
///
///
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;