1497 lines
44 KiB
C++
1497 lines
44 KiB
C++
#ifndef GLOBAL_H
|
||
#define GLOBAL_H
|
||
|
||
#include <QGraphicsItem>
|
||
#include <QtCore/QMetaObject>
|
||
#include <QtSwap>
|
||
#include <QHash>
|
||
#include <QUuid>
|
||
#include <QJsonObject>
|
||
#include <QJsonArray>
|
||
#include <QWidget>
|
||
#include <QStandardItemModel>
|
||
#include "tools.h"
|
||
|
||
const double g_dGriaphicsScene_Width = 800;
|
||
const double g_dGriaphicsScene_Height = 600;
|
||
|
||
const int g_dEditorItem_Width = 150;
|
||
const int g_dEditorItem_Height = 80;
|
||
|
||
const int g_nEditorBus_Height = 10;
|
||
|
||
const int g_nVDiagramSpacing = 80;
|
||
const int g_nHDiagramSpacing = 80;
|
||
|
||
//Q_NAMESPACE
|
||
enum GraphicsItemType
|
||
{
|
||
GIT_base = QGraphicsItem::UserType + 1,
|
||
GIT_line = QGraphicsItem::UserType + 2,
|
||
GIT_rect = QGraphicsItem::UserType + 3,
|
||
GIT_roundRect = QGraphicsItem::UserType + 4,
|
||
GIT_ellipse = QGraphicsItem::UserType + 5,
|
||
GIT_polygon = QGraphicsItem::UserType + 6,
|
||
//======================================
|
||
GIT_bus = QGraphicsItem::UserType + 50,
|
||
GIT_itemRect = QGraphicsItem::UserType + 51,
|
||
GIT_itemTri = QGraphicsItem::UserType + 52,
|
||
GIT_link= QGraphicsItem::UserType + 53,
|
||
GIT_ctItem= QGraphicsItem::UserType + 54,
|
||
GIT_ctGroup= QGraphicsItem::UserType + 55,
|
||
GIT_ptItem= QGraphicsItem::UserType + 56,
|
||
GIT_ptGroup= QGraphicsItem::UserType + 57,
|
||
GIT_ES= QGraphicsItem::UserType + 58,
|
||
GIT_DS= QGraphicsItem::UserType + 59,
|
||
GIT_FES= QGraphicsItem::UserType + 60,
|
||
GIT_DTEDS= QGraphicsItem::UserType + 61,
|
||
GIT_PI= QGraphicsItem::UserType + 62,
|
||
GIT_LA= QGraphicsItem::UserType + 63,
|
||
GIT_cableTer= QGraphicsItem::UserType + 64,
|
||
GIT_cableEnd= QGraphicsItem::UserType + 65,
|
||
GIT_2wTransformer= QGraphicsItem::UserType + 66,
|
||
GIT_3wTransformer= QGraphicsItem::UserType + 67,
|
||
GIT_node= QGraphicsItem::UserType + 79,
|
||
GIT_bay= QGraphicsItem::UserType + 80, //间隔
|
||
//======================================
|
||
GIT_baseNode = QGraphicsItem::UserType + 199,
|
||
GIT_baseBus = QGraphicsItem::UserType + 200,
|
||
GIT_baseLine = QGraphicsItem::UserType + 201,
|
||
GIT_baseBreaker = QGraphicsItem::UserType + 202,
|
||
GIT_baseCT = QGraphicsItem::UserType + 203,
|
||
GIT_basePT = QGraphicsItem::UserType + 204,
|
||
GIT_baseDS = QGraphicsItem::UserType + 205, //隔离开关
|
||
GIT_baseES = QGraphicsItem::UserType + 206, //接地开关
|
||
GIT_baseFES = QGraphicsItem::UserType + 207, //快速接地
|
||
GIT_baseDTEDS = QGraphicsItem::UserType + 208, //双掷接地隔离开关
|
||
GIT_basePI = QGraphicsItem::UserType + 209, //带电指示器
|
||
GIT_baseLightningArrester = QGraphicsItem::UserType + 210, //避雷器
|
||
GIT_baseCableTer = QGraphicsItem::UserType + 211, //电缆出线套筒
|
||
GIT_baseCableEnd = QGraphicsItem::UserType + 212,
|
||
GIT_base2wTransformer = QGraphicsItem::UserType + 213, //两绕阻变压器
|
||
GIT_base3wTransformer = QGraphicsItem::UserType + 214, //三绕组变压器
|
||
};
|
||
|
||
enum AbstractItemType //工程模关联的对象类型
|
||
{
|
||
AIT_motor = 1,
|
||
AIT_bus
|
||
};
|
||
|
||
enum class ModelFunctionType //模型函数的类型
|
||
{
|
||
ProjectModel = 0,
|
||
BaseModel,
|
||
EditorModel,
|
||
BlockEditorModel, //模块划分时的连接关系
|
||
RuntimeModel //运行时
|
||
};
|
||
|
||
|
||
extern const QMap<AbstractItemType,GraphicsItemType> linkType;
|
||
//类型转换
|
||
extern const QMap<int,GraphicsItemType> typeToProGraphic;
|
||
|
||
enum DiagramMode //组态图模式
|
||
{
|
||
DM_edit = 0,
|
||
DM_run,
|
||
DM_academic,
|
||
DM_baseModel
|
||
};
|
||
|
||
enum VariantIcon //变种图
|
||
{
|
||
VI_thumbnail = 0,
|
||
VI_normal_1,
|
||
VI_normal_2,
|
||
VI_normal_3,
|
||
VI_normal_4,
|
||
VI_normal_5
|
||
};
|
||
|
||
enum Attribute //元模属性字段对照
|
||
{
|
||
Id = Qt::UserRole + 1,
|
||
Attribute = Qt::UserRole + 2,
|
||
AttributeName = Qt::UserRole + 3,
|
||
DataType = Qt::UserRole + 4,
|
||
LengthPrecision = Qt::UserRole + 5,
|
||
Scale = Qt::UserRole + 6,
|
||
IsNotNull = Qt::UserRole + 7,
|
||
DefaultValue = Qt::UserRole + 8,
|
||
ValueRange = Qt::UserRole + 9,
|
||
IsVisible = Qt::UserRole + 10
|
||
};
|
||
|
||
enum TableDelegateContent //代理内容
|
||
{
|
||
TD_ProjectModel = 0, //工程模
|
||
TD_MetaModel, //基模
|
||
TD_ComponentType //元件类型
|
||
};
|
||
|
||
enum SelectorDialogType //选择dialog类型
|
||
{
|
||
ST_MetaModel = 0, //元模对话框
|
||
ST_ComponentType //元件选择
|
||
};
|
||
|
||
enum TableItemState //工程模table操作的对象状态
|
||
{
|
||
TS_create = 1,
|
||
TS_select = 2,
|
||
TS_edit = 4
|
||
};
|
||
|
||
enum class AlertInfo //警告提示信息
|
||
{
|
||
success = 1,
|
||
fail = 2,
|
||
exist = 4
|
||
};
|
||
|
||
struct attributeGroup //属性组(元模)
|
||
{
|
||
int id = 0;
|
||
QString groupType;
|
||
QString groupName;
|
||
int ispublic = -1;
|
||
QString remark;
|
||
};
|
||
|
||
struct dataType //数据类型(元模)
|
||
{
|
||
int id = 0;
|
||
QString dataType;
|
||
QString databaseType;
|
||
};
|
||
|
||
struct modelType //模型类型
|
||
{
|
||
int id = 0;
|
||
QString modelType;
|
||
QString modelName;
|
||
int graphicEelement; //类型
|
||
QByteArray icon; //图片
|
||
QString remark;
|
||
};
|
||
|
||
struct modelGroup
|
||
{
|
||
int id = 0;
|
||
qint64 modelTypeId = 0;
|
||
qint64 attributeGroupId = 0;
|
||
};
|
||
|
||
struct attribute //属性表(元模属性字段)
|
||
{
|
||
int id = 0;
|
||
QString attribute; //属性名
|
||
QString attributeName; //别名(中文名)
|
||
qint64 dataTypeId = 0; //数据类型id
|
||
int lengthPrecision=0; //长度限制(varchar)
|
||
int scale=0; //小数点位数
|
||
int isNotNull=0; //是否非空
|
||
QString defaultValue; //默认值
|
||
QString valueRange; //数值范围
|
||
int isVisible = 1;
|
||
};
|
||
|
||
struct modelAttribute //模型属性表(所有模型属性的索引)
|
||
{
|
||
int id = 0;
|
||
qint64 modelTypeId = 0;
|
||
qint64 attributeGroupId = 0;
|
||
qint64 attributeId = 0;
|
||
};
|
||
|
||
struct modelAttributePublic //公共属性表
|
||
{
|
||
int id = 0;
|
||
qint64 attributeGroupId = 0;
|
||
qint64 attributeId = 0;
|
||
};
|
||
|
||
struct modelConnectivity //模型连接性表(元模是否可以连接)
|
||
{
|
||
int id = 0;
|
||
QString fromModel; //属性名
|
||
QString toModel;
|
||
int connectivity=0; //是否可连
|
||
};
|
||
|
||
//=====================================
|
||
struct projectManager //工程模管理类
|
||
{
|
||
int id = 0;
|
||
QString name; //工程模表名
|
||
QString tag; //工程模名称
|
||
QString metaModel; //元模名
|
||
QString groupName; //属性组名
|
||
int linkType; //图元链接类型
|
||
QJsonObject checkState; //属性选择状态
|
||
};
|
||
|
||
struct projectModelSetting //工程模设定类,如图标
|
||
{
|
||
QString modelName; //工程模名
|
||
QMap<QString,QByteArray> mapSvg; //存放选择的svg图片
|
||
QMap<QString,QByteArray> mapUsedSvg; //存放使用的svg
|
||
};
|
||
|
||
/*struct baseModelSelectManger
|
||
{
|
||
int id = 0;
|
||
QUuid componentId;
|
||
QString componentTag;
|
||
int pageId;
|
||
int version;
|
||
QJsonObject checkState;
|
||
};*/
|
||
|
||
enum projectState
|
||
{
|
||
Err = -1,
|
||
NotExist = 0,
|
||
Exist,
|
||
Changed
|
||
};
|
||
|
||
struct FormerName //曾用名,记录修改前名称
|
||
{
|
||
QString sName;
|
||
bool bChanged = false; //是否改变过
|
||
};
|
||
|
||
struct PropertyState //每个属性的状态
|
||
{
|
||
bool checkState = false;
|
||
QString dataType;
|
||
bool editable = true; //可勾选状态
|
||
};
|
||
|
||
struct PropertyPage //属性信息
|
||
{
|
||
QMap<QString,PropertyState> mCheckState; //属性选择状态
|
||
bool isPublic = false;
|
||
};
|
||
|
||
typedef QMap<QString,PropertyPage> MapProperty; //属性组
|
||
struct PropertyModel //工程模
|
||
{
|
||
MapProperty mapProperty;
|
||
int nType = 0; //工程模类型,选择图标后确定
|
||
QStandardItemModel* pBase = nullptr; //基础属性
|
||
QStandardItemModel* pSelect = nullptr; //已选择属性
|
||
FormerName formerMeta; //曾用元模名
|
||
FormerName formerProject; //曾用工程模名
|
||
QMap<QString,projectManager> dataInfo; //存放数据库内容
|
||
projectModelSetting modelSetting;
|
||
PropertyModel deepCopy() //深拷贝
|
||
{
|
||
PropertyModel copy;
|
||
copy.mapProperty = mapProperty;
|
||
copy.nType = nType;
|
||
copy.pBase = deepCloneModel(pBase);
|
||
copy.pSelect = deepCloneModel(pSelect);
|
||
copy.formerMeta = formerMeta;
|
||
copy.formerProject = formerProject;
|
||
copy.dataInfo = dataInfo;
|
||
copy.modelSetting = modelSetting;
|
||
return copy;
|
||
}
|
||
void release()
|
||
{
|
||
delete pBase;
|
||
delete pSelect;
|
||
pBase = nullptr;
|
||
pSelect = nullptr;
|
||
}
|
||
};
|
||
typedef QMap<QString,PropertyModel> MapProject; //str为工程名,PropertyModel为工程属性
|
||
typedef QMap<QString,MapProject> MapMeta; //str为元模名,PropertyModel为工程模集
|
||
|
||
//=====================================
|
||
struct propertyGroupState //模型属性组信息
|
||
{
|
||
QString groupName; //属性组名称
|
||
QString tableName; //属性组表名
|
||
QJsonObject propertyState; //属性状态信息
|
||
};
|
||
|
||
//================工程模使用======================
|
||
|
||
struct propertyStateInfo //属性
|
||
{
|
||
QString name; //属性名
|
||
QString tagName; //别名
|
||
QString type; //属性类型
|
||
QVariant defaultValue; //默认值
|
||
int lengthPrecision = 999; //长度限制
|
||
int isVisibe = 1; //是否可见(0:不可见,1:可见,2:特殊项)
|
||
bool lock = false; //值手动改变时置true,下次保存时恢复
|
||
};
|
||
|
||
Q_DECLARE_METATYPE(propertyStateInfo);
|
||
|
||
typedef QMap<QString,propertyStateInfo> PropertyValueInfo;
|
||
|
||
struct groupStateInfo //属性组(结构信息)
|
||
{
|
||
QString groupName; //组名
|
||
QString tableName; //表名
|
||
bool isPublic = false;;
|
||
PropertyValueInfo info; //属性信息
|
||
};
|
||
|
||
struct groupStateValue //属性组(实时数据)
|
||
{
|
||
QString groupName; //组名
|
||
QString tableName; //表名
|
||
QMap<QUuid,PropertyValueInfo> mapInfo;
|
||
};
|
||
|
||
struct modelStateInfo //模型结构信息
|
||
{
|
||
QString modelName;
|
||
int modelType;
|
||
QWidget* _PropertyDlg = NULL; //属性设置界面,每个模型维护一种界面
|
||
QMap<QString,groupStateInfo> groupInfo; //属性组信息
|
||
void release()
|
||
{
|
||
if(_PropertyDlg)
|
||
delete _PropertyDlg;
|
||
}
|
||
};
|
||
|
||
struct modelDataInfo //模型数据信息
|
||
{
|
||
QString modelName;
|
||
int modelType;
|
||
QMap<QString,groupStateValue> groupInfo; //属性组实时信息
|
||
};
|
||
|
||
struct propertyContentInfo //单个属性结构
|
||
{
|
||
QString proName; //名称
|
||
QString proType; //类型
|
||
QWidget* proEditer = NULL; //编辑窗口对象
|
||
};
|
||
|
||
struct measureAttributeType //量测可用属性类型(从基模获取的占位符变量)
|
||
{
|
||
QString tag;
|
||
QString name;
|
||
};
|
||
//==================组态拓扑结构======================
|
||
enum class DataState
|
||
{
|
||
unchanged = 0,
|
||
changed,
|
||
prepareDelete
|
||
};
|
||
/*struct diagramInfo
|
||
{
|
||
QString name;
|
||
QString uuid;
|
||
QMap<QString,diagramInfo> childMap;
|
||
};
|
||
|
||
struct stationInfo
|
||
{
|
||
QString stationName;
|
||
QString uuid;
|
||
QMap<QString,diagramInfo> diagramMap;
|
||
};
|
||
|
||
struct zoneInfo
|
||
{
|
||
QString zoneName;
|
||
QString uuid;
|
||
QMap<QString,stationInfo> stationMap;
|
||
};
|
||
|
||
struct gridInfo //grid
|
||
{
|
||
QString gridName;
|
||
QString uuid;
|
||
QMap<QString,zoneInfo> zoneMap;
|
||
};*/
|
||
//===================组态编辑器使用================
|
||
const int g_transformerLevel = 999; //层级结构中变压器所处层级
|
||
|
||
struct DiagramEditorWizardBusInfo //组态编辑母线信息
|
||
{
|
||
int nIndex = 0;
|
||
double dVoltage = 0; //电压等级
|
||
int nLineType = 1; //1单母线,2双母线
|
||
int nNum1 = 0; //1母
|
||
int nNum2 = 0; //2母
|
||
int connectType = 0; //接线方式,1为分段连接
|
||
int nState = 0; //母线状态位 0已保存1新建2修改
|
||
|
||
friend QDataStream &operator<<(QDataStream &out, const DiagramEditorWizardBusInfo &data) {
|
||
out << data.nIndex << data.dVoltage << data.nLineType << data.nNum1 << data.nNum2 << data.connectType << data.nState;
|
||
return out;
|
||
}
|
||
friend QDataStream &operator>>(QDataStream &in, DiagramEditorWizardBusInfo &data) {
|
||
in >> data.nIndex >> data.dVoltage >> data.nLineType >> data.nNum1 >> data.nNum2 >> data.connectType >> data.nState;
|
||
return in;
|
||
}
|
||
};
|
||
|
||
enum class TransformerType //变压器类型
|
||
{
|
||
twoWinding = 0, //两绕组
|
||
threeWinding //三绕组
|
||
};
|
||
|
||
enum class BayType //间隔类型
|
||
{
|
||
busSectionBay = 0, //分段
|
||
busCouplerBay, //母联
|
||
ptBay, //pt
|
||
incomingBay, //进线
|
||
outcomingBay, //出线
|
||
compensationBay, //无功补偿
|
||
bypassBay, //旁路
|
||
mainTransformerBay //主变
|
||
};
|
||
|
||
enum class EditorItemType //组态编辑中的图形项类型
|
||
{
|
||
bus = 1, //母线
|
||
bay, //间隔
|
||
trans, //变压器
|
||
line, //连接线
|
||
none //空白占位图
|
||
};
|
||
|
||
struct EditorTransConnection //组态变压器连接信息
|
||
{
|
||
QString sName;
|
||
int nPara = 0; //012,高中低侧
|
||
};
|
||
|
||
struct DiagramEditorWizardTransformerInfo //组态变压器信息
|
||
{
|
||
QString sName;
|
||
TransformerType nType;
|
||
QList<EditorTransConnection> lstBindObj; //连接的对象
|
||
};
|
||
|
||
struct DiagramEditorWizardBayInfo //组态间隔信息
|
||
{
|
||
QString sName;
|
||
BayType nType;
|
||
QList<QString> lstBindObj; //连接的对象
|
||
};
|
||
|
||
struct DiagramEditorComponentInfo //组态设备信息
|
||
{
|
||
int nCategory = 0; //分类 0电气设备1连接关系
|
||
QString sName;
|
||
int nType = 0; //类型 1母线2异步电动机3断路器4电缆5电流互感器6电压互感器7隔离开关8接地开关9快速接地开关10双掷接地隔离开关11带电指示器12避雷器13电缆出线套筒14电缆端
|
||
QString sBindObj; //所关联的实体名 (母线block,间隔block,变压器高中低端子)
|
||
int nBindType = 0; //关联实体的类型 1母线2间隔3变压器
|
||
int nBindPara = 0; //关联额外参数,关联变压器时为(0高1中2低)
|
||
QString sBindParent; //关联父item名,关联变压器时为变压器名
|
||
QStringList sUsedRoute; //使用设备的线路名
|
||
int nUsedDirection = 0; //被占用的方向 8421 上下左右
|
||
QPoint deltaPos = QPoint(0,0); //相对坐标(相对间隔)
|
||
QUuid uid;
|
||
int nFlag = 0; //标志0未使用1新建2修改
|
||
int nRotate = 0; //旋转角
|
||
|
||
bool operator ==(const DiagramEditorComponentInfo& obj) const {
|
||
if(nCategory == obj.nCategory && sName == obj.sName && nType == obj.nType && sBindObj == obj.sBindObj && nBindType == obj.nBindType &&
|
||
sUsedRoute == obj.sUsedRoute && nUsedDirection == obj.nUsedDirection && deltaPos == obj.deltaPos && uid == obj.uid && nFlag == obj.nFlag && nRotate == obj.nRotate)
|
||
return true;
|
||
else
|
||
return false;
|
||
}
|
||
|
||
friend QDataStream &operator<<(QDataStream &out, const DiagramEditorComponentInfo &data) {
|
||
out << data.nCategory << data.sName << data.nType << data.sBindObj << data.nBindType << data.nBindPara << data.sBindParent << data.sUsedRoute << data.nUsedDirection << data.deltaPos << data.uid << data.nFlag << data.nRotate;
|
||
return out;
|
||
}
|
||
friend QDataStream &operator>>(QDataStream &in, DiagramEditorComponentInfo &data) {
|
||
in >> data.nCategory >> data.sName >> data.nType >> data.sBindObj >> data.nBindType >> data.nBindPara >> data.sBindParent >> data.sUsedRoute >> data.nUsedDirection >> data.deltaPos >> data.uid >> data.nFlag >> data.nRotate;
|
||
return in;
|
||
}
|
||
};
|
||
|
||
inline uint qHash(const DiagramEditorComponentInfo &key, uint seed = 0) {
|
||
return qHash(key.uid, seed);
|
||
}
|
||
|
||
struct DiagramEditorRouteInfo //间隔中单条线路信息
|
||
{
|
||
QString sRouteName;
|
||
bool bMainRoute = false; //主线路(包含设备最多的线路,决定整体布局)
|
||
QList<DiagramEditorComponentInfo> lstCompo;
|
||
QList<DiagramEditorComponentInfo> lstOrder; //线路顺序容器(计算用)
|
||
QList<DiagramEditorComponentInfo> lstReverse; //逆序容器(计算用)
|
||
|
||
friend QDataStream &operator<<(QDataStream &out, const DiagramEditorRouteInfo &data) {
|
||
out << data.sRouteName << data.bMainRoute << data.lstCompo << data.lstOrder << data.lstReverse;
|
||
return out;
|
||
}
|
||
friend QDataStream &operator>>(QDataStream &in, DiagramEditorRouteInfo &data) {
|
||
in >> data.sRouteName >> data.bMainRoute >> data.lstCompo >> data.lstOrder >> data.lstReverse;
|
||
return in;
|
||
}
|
||
};
|
||
|
||
struct DiagramEditorBayInfo //组态编辑间隔信息
|
||
{
|
||
QString name; //间隔名
|
||
int nLayout; //布局 0纵向1横向
|
||
QList<QUuid> lstFrom; //起始
|
||
QList<QUuid> lstTo; //结束
|
||
QMap<QString,DiagramEditorRouteInfo> mapRoute; //线路信息
|
||
QMap<QString,DiagramEditorComponentInfo> mapComponent; //设备信息
|
||
|
||
friend QDataStream &operator<<(QDataStream &out, const DiagramEditorBayInfo &data) {
|
||
out << data.name << data.nLayout << data.lstFrom << data.lstTo << data.mapRoute << data.mapComponent;
|
||
return out;
|
||
}
|
||
friend QDataStream &operator>>(QDataStream &in, DiagramEditorBayInfo &data) {
|
||
in >> data.name >> data.nLayout >> data.lstFrom >> data.lstTo >> data.mapRoute >> data.mapComponent;
|
||
return in;
|
||
}
|
||
};
|
||
|
||
struct DiagramEditorTransNeutralInfo //组态编辑变压器中性点信息
|
||
{
|
||
QString name; //中性点名
|
||
int nType = 0; //中性点类型 0高1中2低
|
||
QPointF delPoint; //相对变压器偏移量
|
||
QMap<QString,DiagramEditorRouteInfo> mapRoute; //中性点对应的线路结构
|
||
|
||
friend QDataStream &operator<<(QDataStream &out, const DiagramEditorTransNeutralInfo &data) {
|
||
out << data.name << data.nType << data.delPoint << data.mapRoute;
|
||
return out;
|
||
}
|
||
friend QDataStream &operator>>(QDataStream &in, DiagramEditorTransNeutralInfo &data) {
|
||
in >> data.name >> data.nType >> data.delPoint >> data.mapRoute;
|
||
return in;
|
||
}
|
||
};
|
||
|
||
struct DiagramEditorTransInfo //组态编辑变压器信息
|
||
{
|
||
QString name; //变压器名
|
||
QMap<int,DiagramEditorTransNeutralInfo> mapNeutral; //中性点结构
|
||
QMap<QString,DiagramEditorComponentInfo> mapComponent; //设备信息
|
||
|
||
friend QDataStream &operator<<(QDataStream &out, const DiagramEditorTransInfo &data) {
|
||
out << data.name << data.mapNeutral << data.mapComponent;
|
||
return out;
|
||
}
|
||
friend QDataStream &operator>>(QDataStream &in, DiagramEditorTransInfo &data) {
|
||
in >> data.name >> data.mapNeutral >> data.mapComponent;
|
||
return in;
|
||
}
|
||
};
|
||
|
||
enum class DiagramEditorStructType
|
||
{
|
||
block = 0, //模块(母线段、间隔、变压器)
|
||
blockContainer, //模块容器(包含若干模块)
|
||
rowData //行数据(包含若干容器)
|
||
};
|
||
|
||
struct DiagramEditorConnectType //组态编辑连接信息
|
||
{
|
||
QString sName;
|
||
int nType = 0; //1母线,2间隔,3变压器
|
||
|
||
friend QDataStream &operator<<(QDataStream &out, const DiagramEditorConnectType &data) {
|
||
out << data.sName << data.nType;
|
||
return out;
|
||
}
|
||
friend QDataStream &operator>>(QDataStream &in, DiagramEditorConnectType &data) {
|
||
in >> data.sName >> data.nType;
|
||
return in;
|
||
}
|
||
};
|
||
|
||
struct DiagramEditorBriefConnect //组态编辑时连接信息
|
||
{
|
||
QUuid uid;
|
||
DiagramEditorConnectType con1;
|
||
DiagramEditorConnectType con2;
|
||
int nPara = 0; //万用参数(变压器中表示连接位置,0高压侧,1中压侧,2低压侧)
|
||
|
||
bool operator==(const DiagramEditorBriefConnect& obj)
|
||
{
|
||
if(this == &obj)
|
||
return false;
|
||
if((con1.sName == obj.con1.sName && con2.sName == obj.con2.sName)||(con1.sName == obj.con2.sName && con2.sName == obj.con1.sName))
|
||
return true;
|
||
else
|
||
return false;
|
||
}
|
||
|
||
friend QDataStream &operator<<(QDataStream &out, const DiagramEditorBriefConnect &data) {
|
||
out << data.uid << data.con1 << data.con2 << data.nPara;
|
||
return out;
|
||
}
|
||
friend QDataStream &operator>>(QDataStream &in, DiagramEditorBriefConnect &data) {
|
||
in >> data.uid >> data.con1 >> data.con2 >> data.nPara;
|
||
return in;
|
||
}
|
||
|
||
DiagramEditorConnectType getOpposite(const QString& s){ //获取另一端名称
|
||
if(con1.sName == s)
|
||
return con2;
|
||
else if(con2.sName == s)
|
||
return con1;
|
||
return DiagramEditorConnectType();
|
||
}
|
||
};
|
||
|
||
struct DiagramEditorBlockInfo //组态编辑block信息
|
||
{
|
||
QString sName;
|
||
QString sContainerId; //所属的容器id
|
||
int nType; //1母线,2间隔,3变压器
|
||
int nContainerLevel; //所处容器的层级 0,1,2,3
|
||
QUuid uid;
|
||
QList<QUuid> _lstCon; //连接信息
|
||
QList<QPair<int,QUuid>> _lstSub; //子对象列表(非拓扑计算使用) 如母线子对象为间隔,间隔子对象为item,电动机子对象为item <类型,uid> 类型:0设备1间隔
|
||
QRectF recSize; //当前大小(根据内容确定)
|
||
QPointF sceneDelta; //block中心相对位移(计算布局位置
|
||
bool bEditState; //详细编辑状态
|
||
|
||
//bus
|
||
float fVoltage; //母线电压
|
||
int nBusType; //0无前缀,1:Ⅰ母,2Ⅱ母
|
||
int nIndex; //第几段,1A,2B,3C,4D,5E,6F,7G,8H
|
||
//bay
|
||
BayType nBayType;
|
||
DiagramEditorBayInfo bayInfo; //间隔信息
|
||
//transformer
|
||
TransformerType nTransType;
|
||
DiagramEditorTransInfo transInfo;
|
||
|
||
friend QDataStream &operator<<(QDataStream &out, const DiagramEditorBlockInfo &data) {
|
||
out << data.sName << data.sContainerId << data.nType << data.nContainerLevel << data.uid << data._lstCon << data.recSize << data.sceneDelta
|
||
<< data.bEditState << data.fVoltage << data.nBusType << data.nIndex << data.nBayType << data.bayInfo << data.nTransType << data.transInfo;
|
||
return out;
|
||
}
|
||
friend QDataStream &operator>>(QDataStream &in, DiagramEditorBlockInfo &data) {
|
||
in >> data.sName >> data.sContainerId >> data.nType >> data.nContainerLevel >> data.uid >> data._lstCon >> data.recSize >> data.sceneDelta
|
||
>> data.bEditState >> data.fVoltage >> data.nBusType >> data.nIndex >> data.nBayType >> data.bayInfo >> data.nTransType >> data.transInfo;
|
||
return in;
|
||
}
|
||
};
|
||
|
||
|
||
struct DiagramEditorContainerInfo //组态编辑容器信息
|
||
{
|
||
QString sId;
|
||
double dMidUpY; //1母上边界
|
||
double dMidDownY; //2母下边界
|
||
double dStartX; //起始x
|
||
double dStartY; //起始y
|
||
double dWidth; //宽度
|
||
double dHeight;
|
||
double dMaxUpH; //上方最大高度(1母线到上边界)
|
||
double dMaxDownH; //下方最大高度(2母线到下边界)
|
||
QMap<int,QList<DiagramEditorBlockInfo>> mapBlockInfo;
|
||
|
||
friend QDataStream &operator<<(QDataStream &out, const DiagramEditorContainerInfo &data) {
|
||
out << data.sId << data.dMidUpY << data.dMidDownY << data.dStartX << data.dStartY << data.dWidth << data.dHeight << data.dMaxUpH << data.dMaxDownH << data.mapBlockInfo;
|
||
return out;
|
||
}
|
||
friend QDataStream &operator>>(QDataStream &in, DiagramEditorContainerInfo &data) {
|
||
in >> data.sId >> data.dMidUpY >> data.dMidDownY >> data.dStartX >> data.dStartY >> data.dWidth >> data.dHeight >> data.dMaxUpH >> data.dMaxDownH >> data.mapBlockInfo;
|
||
return in;
|
||
}
|
||
};
|
||
|
||
struct DiagramEditorProjectInfo //editor工程信息
|
||
{
|
||
QString sName;
|
||
QUuid uid;
|
||
QMap<int,DiagramEditorWizardBusInfo> mapBus;
|
||
QMap<int,QList<DiagramEditorContainerInfo>> mapSturctContainer;
|
||
QMap<QUuid,DiagramEditorBriefConnect> mapConnect;
|
||
|
||
friend QDataStream &operator<<(QDataStream &out, const DiagramEditorProjectInfo &data) {
|
||
out << data.sName << data.uid << data.mapBus << data.mapSturctContainer << data.mapConnect;
|
||
return out;
|
||
}
|
||
friend QDataStream &operator>>(QDataStream &in, DiagramEditorProjectInfo &data) {
|
||
in >> data.sName >> data.uid >> data.mapBus >> data.mapSturctContainer >> data.mapConnect;
|
||
return in;
|
||
}
|
||
};
|
||
|
||
//==================组态图使用=====================
|
||
enum HandleType
|
||
{
|
||
T_none = 0,
|
||
T_resize, //调整大小
|
||
T_rotate, //旋转
|
||
T_editShape, //编辑形状
|
||
T_text, //文本
|
||
T_lineIn, //入线口
|
||
T_lineOut, //出线口
|
||
T_lineInOut, //双端线
|
||
T_newTral //中性点
|
||
};
|
||
|
||
enum HandleTag
|
||
{
|
||
H_none = 0,
|
||
H_leftTop,
|
||
H_top,
|
||
H_rightTop,
|
||
H_right,
|
||
H_rightBottom,
|
||
H_bottom,
|
||
H_leftBottom,
|
||
H_left, //8
|
||
H_rotate_leftTop,
|
||
H_rotate_rightTop,
|
||
H_rotate_rightBottom,
|
||
H_rotate_leftBottom, //12
|
||
H_edit,
|
||
H_textCaption = 40, //标题文本
|
||
H_textCurrent, //电流
|
||
h_textVoltage, //电压
|
||
H_connect = 50 //连接操作点从50开始,前面预留
|
||
};
|
||
|
||
enum PortPos
|
||
{
|
||
P_top = 0,
|
||
P_down,
|
||
P_left,
|
||
P_right
|
||
};
|
||
|
||
struct Connection
|
||
{
|
||
QUuid nSrcNodeId;
|
||
QUuid nSrcPortId;
|
||
HandleType srcType;
|
||
PortPos srcPos;
|
||
QUuid nDestNodeId;
|
||
QUuid nDestPortId;
|
||
HandleType destType;
|
||
PortPos destPos;
|
||
|
||
Connection()
|
||
{
|
||
srcType = T_none;
|
||
srcPos = P_top;
|
||
destType = T_none;
|
||
destPos = P_top;
|
||
nSrcNodeId = QUuid();
|
||
nSrcPortId = QUuid();
|
||
nDestNodeId = QUuid();
|
||
nDestPortId = QUuid();
|
||
}
|
||
|
||
Connection(const Connection& obj)
|
||
{
|
||
nSrcNodeId = obj.nSrcNodeId;
|
||
nSrcPortId = obj.nSrcPortId;
|
||
srcType = obj.srcType;
|
||
srcPos = obj.srcPos;
|
||
nDestNodeId = obj.nDestNodeId;
|
||
nDestPortId = obj.nDestPortId;
|
||
destType = obj.destType;
|
||
destPos = obj.destPos;
|
||
}
|
||
|
||
Connection(QUuid nSNI,QUuid nSPI,HandleType sT,PortPos sPOS,QUuid nDNI,QUuid nDPI,HandleType dT,PortPos dPOS)
|
||
{
|
||
nSrcNodeId = nSNI;
|
||
nSrcPortId = nSPI;
|
||
srcType = sT;
|
||
srcPos = sPOS;
|
||
nDestNodeId = nDNI;
|
||
nDestPortId = nDPI;
|
||
destType = dT;
|
||
destPos = dPOS;
|
||
}
|
||
bool operator==(const Connection& obj)
|
||
{
|
||
return ((nSrcNodeId == obj.nSrcNodeId)&&(nSrcPortId == obj.nSrcPortId)&&(srcType == obj.srcType)&&(nDestNodeId == obj.nDestNodeId)&&(nDestPortId == obj.nDestPortId)&&(destType == obj.destType));
|
||
}
|
||
|
||
Connection& operator=(const Connection& obj)
|
||
{
|
||
if(this == &obj)
|
||
return *this;
|
||
nSrcNodeId = obj.nSrcNodeId;
|
||
nSrcPortId = obj.nSrcPortId;
|
||
srcType = obj.srcType;
|
||
srcPos = obj.srcPos;
|
||
nDestNodeId = obj.nDestNodeId;
|
||
nDestPortId = obj.nDestPortId;
|
||
destType = obj.destType;
|
||
destPos = obj.destPos;
|
||
return *this;
|
||
}
|
||
};
|
||
|
||
// 基础实体类型(电力元素或组态图)
|
||
enum class EntityType {
|
||
Grid,
|
||
Zone,
|
||
Station,
|
||
ConfigurationDiagram,
|
||
Component };
|
||
|
||
struct EntityInfo
|
||
{
|
||
QString sName;
|
||
QString sUuid;
|
||
QString sParentId;
|
||
EntityType eType;
|
||
};
|
||
|
||
struct DiagramInfo //组态图结构信息
|
||
{
|
||
QVariant id; //临时id使用uuid,load数据使用数据库自增id
|
||
QString sName;
|
||
QString sTag;
|
||
QVariant parentId;
|
||
QString sBasePageName; //基模组态图名称
|
||
};
|
||
|
||
struct DiagramContent {
|
||
QString diagramId; // 对应的PowerEntity ID
|
||
|
||
// 元素位置信息 <元素ID, 位置>
|
||
QHash<QString, QPointF> elementPositions;
|
||
//QHash<QString, QColor> connectionColors; // <连接ID, 显示颜色>
|
||
QHash<QString, QList<QPointF>> connectionPaths; // 自定义路径点
|
||
};
|
||
|
||
struct PtExtraInfo
|
||
{
|
||
int id;
|
||
QString minTransRatio; //最小变比
|
||
QString maxTransRatio; //最大变比
|
||
QString transRatio; //变比
|
||
QString accuracyClass; //精度等级
|
||
QString secondaryLoadCapacity; //二次负载容量
|
||
QString windingConnectionMethod; //绕组接法
|
||
};
|
||
|
||
struct CtExtraInfo
|
||
{
|
||
int id;
|
||
QString transRatio; //变比
|
||
QString minTransRatio; //最小变比
|
||
QString maxTransRatio; //最大变比
|
||
QString accuracyClass; //精度等级
|
||
QString secondaryLoadCapacity; //二次负载容量
|
||
};
|
||
|
||
struct MeasurementInfo //量测
|
||
{
|
||
QString tag; //量测tag
|
||
QString name; //量测名称
|
||
QString equipment; //设备名称
|
||
QString channel; //设备端子
|
||
int type; //量测类型 0:遥测 1:遥信 2:遥控
|
||
int size; //量测size
|
||
QUuid bayUuid; //所属间隔
|
||
QUuid componentUuid; //所属设备
|
||
|
||
//通讯
|
||
int nSource; //数据来源 1:cl3611 2:104
|
||
QString sStation; //子站名称
|
||
QString sChannel; //通道名(cl3611) 遥测:TMx(1-8); P; Q; S; PF; F; deltaF; UAB; UBC; UCA; 遥信: TSxx(01-10); 遥控: TCx;
|
||
int nPacket; //包号(104)
|
||
int nOffset; //偏移量(104)
|
||
//事件
|
||
bool bEnable = false; //"enable"开启标志
|
||
QMap<QString,double> mapTE; //遥测"cause" key:upup,up,down,downdown可选,val:0-100
|
||
QString sEdge; //遥信"cause:edge" raising, falling 字符串单选
|
||
QString sCommand; //"action:command" info, warning, error, critical, exception 字符串单选
|
||
QStringList lstParameter; //"action:parameters" 字符串数组
|
||
};
|
||
|
||
//==================================================
|
||
struct baseComponentInfo //基模图元数据
|
||
{
|
||
int id = 0;
|
||
QUuid uuid;
|
||
QString name;
|
||
QString tag;
|
||
int typeId = 0;
|
||
QJsonObject context;
|
||
QString metaMmodel;
|
||
QString projectModel;
|
||
};
|
||
|
||
struct editorProjectInfo //editor工程数据
|
||
{
|
||
int id = 0;
|
||
QUuid uuid;
|
||
QString name;
|
||
QString tag;
|
||
};
|
||
|
||
struct editorBaseSettingInfo //editor基础设置
|
||
{
|
||
int id = 0;
|
||
QUuid uuid;
|
||
QString projectName; //所属工程名
|
||
QString autor; //作者
|
||
QByteArray context; //内容
|
||
QUuid generateUid; //生成的图uuid
|
||
QString ts; //时间戳
|
||
};
|
||
|
||
//==================================================
|
||
|
||
struct componentInfo //工程模图元数据
|
||
{
|
||
QUuid uuid;
|
||
QString modelName;
|
||
QString nspath;
|
||
QString tag;
|
||
QString name;
|
||
QString description;
|
||
QString grid;
|
||
QString zone;
|
||
QString station;
|
||
int type = 0;
|
||
bool inService = true;
|
||
int state = 0;
|
||
QJsonObject connected_bus;
|
||
QJsonObject label;
|
||
QJsonObject context;
|
||
int op = 0;
|
||
};
|
||
|
||
struct componentTypeInfo //元件类型
|
||
{
|
||
int id = 0;
|
||
QString type;
|
||
QString name;
|
||
QJsonObject config;
|
||
};
|
||
|
||
struct topologicInfo
|
||
{
|
||
int id = -1;
|
||
QUuid uuid_from;
|
||
QUuid uuid_to;
|
||
QJsonObject context;
|
||
int flag;
|
||
QString description;
|
||
int op;
|
||
};
|
||
|
||
struct pageInfo
|
||
{
|
||
int id = -1;
|
||
QString tag;
|
||
QString name;
|
||
QJsonObject label;
|
||
QJsonObject context;
|
||
QString description;
|
||
int op;
|
||
};
|
||
|
||
struct monitorPageInfo //运行时page
|
||
{
|
||
int id = -1;
|
||
QUuid uid;
|
||
QString tag;
|
||
QString name;
|
||
QString parent;
|
||
QJsonObject context;
|
||
QString ts;
|
||
};
|
||
|
||
struct gridInfo
|
||
{
|
||
int id = -1;
|
||
QString name;
|
||
QString description;
|
||
};
|
||
|
||
struct zoneInfo
|
||
{
|
||
int id = -1;
|
||
int grid_id = -1;
|
||
QString name;
|
||
QString description;
|
||
};
|
||
|
||
struct stationInfo
|
||
{
|
||
int id = -1;
|
||
int zone_id = -1;
|
||
QString name;
|
||
QString description;
|
||
bool is_local = true;
|
||
};
|
||
|
||
struct bayInfo
|
||
{
|
||
QUuid uuid;
|
||
QString name;
|
||
QString tag;
|
||
QString type;
|
||
double unom;
|
||
double fla;
|
||
double capacity;
|
||
QString description;
|
||
bool inService;
|
||
int nState;
|
||
QString grid;
|
||
QString zone;
|
||
QString station;
|
||
QJsonObject business;
|
||
QJsonObject fromUuid;
|
||
QJsonObject toUuid;
|
||
QJsonObject protect;
|
||
QJsonObject faultRec;
|
||
QJsonObject status;
|
||
QJsonObject dynSense;
|
||
QJsonObject instruct;
|
||
QJsonObject etc;
|
||
QJsonObject context;
|
||
QList<QUuid> components;
|
||
};
|
||
|
||
struct itemPageInfo //page中保存的item信息(大小,位置etc)
|
||
{
|
||
QPointF pos;
|
||
double dWidth = 0.0;
|
||
double dHeight = 0.0;
|
||
double dRotate = 0.0;
|
||
};
|
||
|
||
/*********************运行时************************/
|
||
struct monitorRelationSturctItem //监控关系结构item
|
||
{
|
||
int nCategory; //类型 0设备1间隔
|
||
int nEquipType; //设备类别
|
||
QString sName; //名称
|
||
QUuid uid; //id
|
||
|
||
QJsonObject toJson() const {
|
||
QJsonObject obj;
|
||
obj["nCategory"] = nCategory;
|
||
obj["nEquipType"] = nEquipType;
|
||
obj["sName"] = sName;
|
||
obj["uid"] = uid.toString();
|
||
return obj;
|
||
}
|
||
|
||
// 从JSON对象解析
|
||
void fromJson(const QJsonObject& json) {
|
||
nCategory = json["nCategory"].toInt();
|
||
nEquipType = json["nEquipType"].toInt();
|
||
sName = json["sName"].toString();
|
||
uid = QUuid::fromString(json["uid"].toString());
|
||
}
|
||
|
||
// 检查有效性
|
||
bool isValid() const {
|
||
return !uid.isNull() && !sName.isEmpty();
|
||
}
|
||
|
||
// 重载相等运算符
|
||
bool operator==(const monitorRelationSturctItem& other) const {
|
||
return uid == other.uid &&
|
||
sName == other.sName &&
|
||
nCategory == other.nCategory;
|
||
}
|
||
};
|
||
|
||
struct monitorRelationItem //监控关系item
|
||
{
|
||
monitorRelationSturctItem parent;
|
||
monitorRelationSturctItem item;
|
||
QList<monitorRelationSturctItem> subList;
|
||
|
||
QJsonObject toJson() const {
|
||
QJsonObject obj;
|
||
obj["parent"] = parent.toJson();
|
||
obj["item"] = item.toJson();
|
||
|
||
// 序列化子列表
|
||
QJsonArray subArray;
|
||
for (const auto& subItem : subList) {
|
||
subArray.append(subItem.toJson());
|
||
}
|
||
obj["subList"] = subArray;
|
||
obj["subCount"] = subList.size();
|
||
|
||
return obj;
|
||
}
|
||
|
||
// 从JSON对象解析
|
||
void fromJson(const QJsonObject& json) {
|
||
parent.fromJson(json["parent"].toObject());
|
||
item.fromJson(json["item"].toObject());
|
||
|
||
// 解析子列表
|
||
subList.clear();
|
||
QJsonArray subArray = json["subList"].toArray();
|
||
for (const QJsonValue& subValue : subArray) {
|
||
monitorRelationSturctItem sub;
|
||
sub.fromJson(subValue.toObject());
|
||
subList.append(sub);
|
||
}
|
||
}
|
||
|
||
// 检查有效性
|
||
bool isValid() const {
|
||
return parent.isValid() && item.isValid();
|
||
}
|
||
|
||
// 添加子项
|
||
void addSubItem(const monitorRelationSturctItem& subItem) {
|
||
subList.append(subItem);
|
||
}
|
||
|
||
// 移除子项
|
||
bool removeSubItem(const QUuid& subUid) {
|
||
for (int i = 0; i < subList.size(); ++i) {
|
||
if (subList[i].uid == subUid) {
|
||
subList.removeAt(i);
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
// 查找子项
|
||
monitorRelationSturctItem* findSubItem(const QUuid& subUid) {
|
||
for (auto& sub : subList) {
|
||
if (sub.uid == subUid) {
|
||
return ⊂
|
||
}
|
||
}
|
||
return nullptr;
|
||
}
|
||
};
|
||
|
||
struct monitorItemAttributeInfo //单个监控item属性
|
||
{
|
||
QString sGroup; //所属组别
|
||
QString sTag; //索引名
|
||
QString sName; //显示名
|
||
int nConnectType = 0; //关联数据类别 0字段 1量测
|
||
QString sConnectPara; //查询参数(参数服务使用)
|
||
int nShowType = 0; //显示类别 0字符 1图表
|
||
bool bShowDiagram = false; //显示到组态中
|
||
int nGraphType = 0; //图表类型 0折线1柱状
|
||
QString sTimeRange; //时间范围(分)
|
||
QString sValue; //属性值
|
||
bool bSelected = false;
|
||
|
||
// 转换为JSON对象
|
||
QJsonObject toJson() const {
|
||
QJsonObject obj;
|
||
obj["sGroup"] = sGroup;
|
||
obj["sTag"] = sTag;
|
||
obj["sName"] = sName;
|
||
obj["nConnectType"] = nConnectType;
|
||
obj["sConnectPara"] = sConnectPara;
|
||
obj["nShowType"] = nShowType;
|
||
obj["bShowDiagram"] = bShowDiagram;
|
||
obj["nGraphType"] = nGraphType;
|
||
obj["sTimeRange"] = sTimeRange;
|
||
obj["sValue"] = sValue;
|
||
obj["bSelected"] = bSelected;
|
||
return obj;
|
||
}
|
||
|
||
// 从JSON对象解析
|
||
void fromJson(const QJsonObject& json) {
|
||
sGroup = json["sGroup"].toString();
|
||
sTag = json["sTag"].toString();
|
||
sName = json["sName"].toString();
|
||
nConnectType = json["nConnectType"].toInt();
|
||
sConnectPara = json["sConnectPara"].toString();
|
||
nShowType = json["nShowType"].toInt();
|
||
bShowDiagram = json["bShowDiagram"].toBool();
|
||
nGraphType = json["nGraphType"].toInt();
|
||
sTimeRange = json["sTimeRange"].toString();
|
||
sValue = json["sValue"].toString();
|
||
bSelected = json["bSelected"].toBool();
|
||
}
|
||
|
||
// 检查有效性
|
||
bool isValid() const {
|
||
return !sTag.isEmpty() && !sName.isEmpty();
|
||
}
|
||
|
||
// 重载相等运算符
|
||
bool operator==(const monitorItemAttributeInfo& other) const {
|
||
return sTag == other.sTag &&
|
||
sName == other.sName &&
|
||
sGroup == other.sGroup;
|
||
}
|
||
};
|
||
|
||
enum class monitorItemState{ //监控item的状态
|
||
Normal = 0, //正常
|
||
Closing, //合闸
|
||
Opening, //分闸
|
||
AccidentTrip, //事故跳闸
|
||
StatusFault, //状态故障
|
||
Energized, //带电
|
||
DeEnergized, //失电
|
||
Grounding, //接地
|
||
Running, //运行
|
||
ShutDown, //停运
|
||
Alarm, //告警
|
||
LineBreak, //断线
|
||
MeasureMentOutLimit //量测越限
|
||
};
|
||
|
||
struct monitorItemDisplayInfo //监控模式显示信息
|
||
{
|
||
int nItemType; //设备类型
|
||
QString sStateName; //状态名
|
||
bool bEnable = false;
|
||
QString sColor;
|
||
QByteArray bytPicture; //存储二进制数据
|
||
int nWidth;
|
||
int nHeight;
|
||
QString sMeta; //元模型名
|
||
QString sModel; //工程模名
|
||
|
||
QJsonObject toJson() const {
|
||
QJsonObject obj;
|
||
obj["nItemType"] = nItemType;
|
||
obj["sStateName"] = sStateName;
|
||
obj["bEnable"] = bEnable;
|
||
obj["sColor"] = sColor;
|
||
obj["bytPicture"] = QString(bytPicture.toBase64());
|
||
obj["nWidth"] = nWidth;
|
||
obj["nHeight"] = nHeight;
|
||
obj["sMeta"] = sMeta;
|
||
obj["sModel"] = sModel;
|
||
return obj;
|
||
}
|
||
|
||
// 从JSON对象解析 - 成员函数
|
||
void fromJson(const QJsonObject& json) {
|
||
nItemType = json["nItemType"].toInt();
|
||
sStateName = json["sStateName"].toString();
|
||
bEnable = json["bEnable"].toBool();
|
||
sColor = json["sColor"].toString();
|
||
|
||
QString pictureBase64 = json["bytPicture"].toString();
|
||
bytPicture = QByteArray::fromBase64(pictureBase64.toUtf8());
|
||
|
||
nWidth = json["nWidth"].toInt();
|
||
nHeight = json["nHeight"].toInt();
|
||
sMeta = json["sMeta"].toString();
|
||
sModel = json["sModel"].toString();
|
||
}
|
||
};
|
||
|
||
struct monitorItemTypeStruct //监控设备类型
|
||
{
|
||
QString sTag;
|
||
QString sName;
|
||
|
||
bool isValid() const {
|
||
return !sTag.isEmpty() && !sName.isEmpty();
|
||
}
|
||
|
||
bool operator==(const monitorItemTypeStruct& other) const {
|
||
return sTag == other.sTag && sName == other.sName;
|
||
}
|
||
|
||
bool operator<(const monitorItemTypeStruct& other) const {
|
||
return sTag < other.sTag || (sTag == other.sTag && sName < other.sName);
|
||
}
|
||
|
||
// 转换为JSON对象 - 成员函数
|
||
QJsonObject toJson() const {
|
||
QJsonObject obj;
|
||
obj["sTag"] = sTag;
|
||
obj["sName"] = sName;
|
||
return obj;
|
||
}
|
||
|
||
// 从JSON对象解析 - 成员函数
|
||
void fromJson(const QJsonObject& json) {
|
||
sTag = json["sTag"].toString();
|
||
sName = json["sName"].toString();
|
||
}
|
||
};
|
||
|
||
struct monitorItemStateStruct //监控设备状态
|
||
{
|
||
QString sState;
|
||
monitorItemState eState;
|
||
|
||
bool isValid() const {
|
||
return !sState.isEmpty();
|
||
}
|
||
|
||
bool operator==(const monitorItemStateStruct& other) const {
|
||
return sState == other.sState && eState == other.eState;
|
||
}
|
||
|
||
bool operator<(const monitorItemStateStruct& other) const {
|
||
return sState < other.sState || (sState == other.sState && eState < other.eState);
|
||
}
|
||
|
||
// 转换为JSON对象 - 成员函数
|
||
QJsonObject toJson() const {
|
||
QJsonObject obj;
|
||
obj["sState"] = sState;
|
||
obj["eState"] = static_cast<int>(eState);
|
||
return obj;
|
||
}
|
||
|
||
// 从JSON对象解析 - 成员函数
|
||
void fromJson(const QJsonObject& json) {
|
||
sState = json["sState"].toString();
|
||
eState = static_cast<monitorItemState>(json["eState"].toInt());
|
||
}
|
||
};
|
||
|
||
struct ModelTypeInfo{ //类型临时信息
|
||
int nType;
|
||
QString sType;
|
||
QString sName;
|
||
QString sMeta; //该类型元模名
|
||
QString sModel; //该类型工程模名
|
||
};
|
||
/**
|
||
* Constants used for fetching QVariant data from GraphModel.
|
||
*/
|
||
enum class NodeRole {
|
||
Type = 0, ///< Type of the current node, usually a string.
|
||
Position = 1, ///< `QPointF` positon of the node on the scene.
|
||
Size = 2, ///< `QSize` for resizable nodes.
|
||
CaptionVisible = 3, ///< `bool` for caption visibility.
|
||
Caption = 4, ///< `QString` for node caption.
|
||
Style = 5, ///< Custom NodeStyle as QJsonDocument
|
||
InternalData = 6, ///< Node-stecific user data as QJsonObject
|
||
InPortCount = 7, ///< `unsigned int`
|
||
OutPortCount = 9, ///< `unsigned int`
|
||
Widget = 10, ///< Optional `QWidget*` or `nullptr`
|
||
};
|
||
//Q_ENUM_NS(NodeRole)
|
||
|
||
/**
|
||
* Specific flags regulating node features and appeaarence.
|
||
*/
|
||
enum NodeFlag {
|
||
NoFlags = 0x0, ///< Default NodeFlag
|
||
Resizable = 0x1, ///< Lets the node be resizable
|
||
Locked = 0x2
|
||
};
|
||
|
||
Q_DECLARE_FLAGS(NodeFlags, NodeFlag)
|
||
//Q_FLAG_NS(NodeFlags)
|
||
Q_DECLARE_OPERATORS_FOR_FLAGS(NodeFlags)
|
||
|
||
/**
|
||
* Constants for fetching port-related information from the GraphModel.
|
||
*/
|
||
enum class PortRole {
|
||
Data = 0, ///< `std::shared_ptr<NodeData>`.
|
||
DataType = 1, ///< `QString` describing the port data type.
|
||
ConnectionPolicyRole = 2, ///< `enum` ConnectionPolicyRole
|
||
CaptionVisible = 3, ///< `bool` for caption visibility.
|
||
Caption = 4, ///< `QString` for port caption.
|
||
};
|
||
//Q_ENUM_NS(PortRole)
|
||
|
||
/**
|
||
* Defines how many connections are possible to attach to ports. The
|
||
* values are fetched using PortRole::ConnectionPolicy.
|
||
*/
|
||
enum class ConnectionPolicy {
|
||
One, ///< Just one connection for each port.
|
||
Many, ///< Any number of connections possible for the port.
|
||
};
|
||
//Q_ENUM_NS(ConnectionPolicy)
|
||
|
||
/**
|
||
* Used for distinguishing input and output node ports.
|
||
*/
|
||
enum class PortType {
|
||
In = 0, ///< Input node port (from the left).
|
||
Out = 1, ///< Output node port (from the right).
|
||
None = 2
|
||
};
|
||
//Q_ENUM_NS(PortType)
|
||
|
||
enum PortState
|
||
{
|
||
P_const = 0, //固定端口
|
||
p_movable, //移动端口
|
||
};
|
||
|
||
using PortCount = int;
|
||
|
||
/// ports are consecutively numbered starting from zero.
|
||
using PortIndex = int;
|
||
|
||
const PortIndex InvalidPortIndex = -1;
|
||
|
||
/// Unique Id associated with each node in the GraphModel.
|
||
using NodeId = int;
|
||
|
||
const NodeId InvalidNodeId = -1;
|
||
|
||
/**
|
||
* A unique connection identificator that stores
|
||
* out `NodeId`, out `PortIndex`, in `NodeId`, in `PortIndex`
|
||
*/
|
||
struct ConnectionId
|
||
{
|
||
int conId;
|
||
NodeId outNodeId;
|
||
PortIndex outPortIndex;
|
||
NodeId inNodeId;
|
||
PortIndex inPortIndex;
|
||
};
|
||
|
||
inline uint qHash(const ConnectionId &data, uint seed){
|
||
|
||
return data.conId;
|
||
}
|
||
|
||
inline bool operator<(ConnectionId const &a, ConnectionId const &b)
|
||
{
|
||
return a.conId<b.conId;
|
||
}
|
||
|
||
inline bool operator==(ConnectionId const &a, ConnectionId const &b)
|
||
{
|
||
return a.outNodeId == b.outNodeId && a.outPortIndex == b.outPortIndex
|
||
&& a.inNodeId == b.inNodeId && a.inPortIndex == b.inPortIndex;
|
||
}
|
||
|
||
inline bool operator!=(ConnectionId const &a, ConnectionId const &b)
|
||
{
|
||
return !(a == b);
|
||
}
|
||
|
||
inline void invertConnection(ConnectionId &id)
|
||
{
|
||
qSwap(id.outNodeId, id.inNodeId);
|
||
qSwap(id.outPortIndex, id.inPortIndex);
|
||
}
|
||
|
||
#endif
|