414 lines
10 KiB
C
414 lines
10 KiB
C
#ifndef TOPOLOGY_H
|
|
#define TOPOLOGY_H
|
|
/*********拓扑相关结构********/
|
|
#include <QString>
|
|
#include <QUuid>
|
|
#include <QJsonObject>
|
|
#include <QList>
|
|
#include <QMap>
|
|
#include <QJsonArray>
|
|
|
|
// 数据状态
|
|
enum class DataState {
|
|
Unchanged = 0,
|
|
Changed,
|
|
PrepareDelete
|
|
};
|
|
|
|
// 端口位置
|
|
enum PortPos {
|
|
P_top = 0,
|
|
P_down,
|
|
P_left,
|
|
P_right
|
|
};
|
|
|
|
enum HandleType
|
|
{
|
|
T_none = 0,
|
|
T_resize, //调整大小
|
|
T_rotate, //旋转
|
|
T_editShape, //编辑形状
|
|
T_text, //文本
|
|
T_lineIn, //入线口
|
|
T_lineOut, //出线口
|
|
T_lineInOut, //双端线
|
|
T_newTral //中性点
|
|
};
|
|
|
|
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;
|
|
}
|
|
};
|
|
|
|
// 拓扑连接信息
|
|
struct TopologyInfo
|
|
{
|
|
int id = -1;
|
|
QUuid uuid_from;
|
|
QUuid uuid_to;
|
|
QJsonObject context;
|
|
int flag;
|
|
QString description;
|
|
int op;
|
|
};
|
|
|
|
// 电网信息
|
|
struct GridInfo
|
|
{
|
|
int id = -1;
|
|
QString tagname;
|
|
QString name;
|
|
QString description;
|
|
};
|
|
|
|
// 区域信息
|
|
struct ZoneInfo
|
|
{
|
|
int id = -1;
|
|
int grid_id = -1;
|
|
QString tagname;
|
|
QString name;
|
|
QString description;
|
|
};
|
|
|
|
// 电站信息
|
|
struct StationInfo
|
|
{
|
|
int id = -1;
|
|
int zone_id = -1;
|
|
QString tagname;
|
|
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 HierarchyStructItem {
|
|
QString sVoltageLevel;
|
|
int nCategory; //类型 0设备1间隔
|
|
int nEquipType; //设备类别
|
|
QString sName; //名称
|
|
QUuid uid; //id
|
|
QString grid; //电网
|
|
QString zone; //区域
|
|
QString station; //电站
|
|
|
|
QJsonObject toJson() const {
|
|
QJsonObject obj;
|
|
obj["sVoltageLevel"] = sVoltageLevel;
|
|
obj["nCategory"] = nCategory;
|
|
obj["nEquipType"] = nEquipType;
|
|
obj["sName"] = sName;
|
|
obj["uid"] = uid.toString();
|
|
obj["grid"] = grid;
|
|
obj["zone"] = zone;
|
|
obj["station"] = station;
|
|
return obj;
|
|
}
|
|
|
|
// 从JSON对象解析
|
|
void fromJson(const QJsonObject& json) {
|
|
sVoltageLevel = json["sVoltageLevel"].toString();
|
|
nCategory = json["nCategory"].toInt();
|
|
nEquipType = json["nEquipType"].toInt();
|
|
sName = json["sName"].toString();
|
|
uid = QUuid::fromString(json["uid"].toString());
|
|
grid = json["grid"].toString();
|
|
zone = json["zone"].toString();
|
|
station = json["station"].toString();
|
|
}
|
|
|
|
// 检查有效性
|
|
bool isValid() const {
|
|
return !uid.isNull() && !sName.isEmpty();
|
|
}
|
|
|
|
// 重载相等运算符
|
|
bool operator==(const HierarchyStructItem& other) const {
|
|
return uid == other.uid &&
|
|
sName == other.sName &&
|
|
nCategory == other.nCategory;
|
|
}
|
|
};
|
|
|
|
// 层级关系项
|
|
struct HierarchyItem {
|
|
HierarchyStructItem parent;
|
|
HierarchyStructItem item;
|
|
QList<HierarchyStructItem> 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) {
|
|
HierarchyStructItem sub;
|
|
sub.fromJson(subValue.toObject());
|
|
subList.append(sub);
|
|
}
|
|
}
|
|
|
|
// 检查有效性
|
|
bool isValid() const {
|
|
return parent.isValid() && item.isValid();
|
|
}
|
|
|
|
// 添加子项
|
|
void addSubItem(const HierarchyStructItem& 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;
|
|
}
|
|
|
|
// 查找子项
|
|
HierarchyStructItem* findSubItem(const QUuid& subUid) {
|
|
for (auto& sub : subList) {
|
|
if (sub.uid == subUid) {
|
|
return ⊂
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
};
|
|
|
|
//属性其他参数与层级关系
|
|
struct ExtraProperty
|
|
{
|
|
int id = 0;
|
|
QString code; // 唯一编码(拼接字符串)
|
|
QString tag; // 属性tag
|
|
QString name; // 显示名称
|
|
QString connect_para; // 连接参数
|
|
|
|
// 层级名称
|
|
QString grid_name;
|
|
QString zone_name;
|
|
QString station_name;
|
|
QString currentLevel;
|
|
QString bay_name;
|
|
QString component_name;
|
|
QString group_name;
|
|
QString type_name;
|
|
|
|
//层级索引
|
|
QString grid_tag;
|
|
QString zone_tag;
|
|
QString station_tag;
|
|
QString page_tag;
|
|
QString bay_tag;
|
|
QUuid component_uuid;
|
|
QString component_tag;
|
|
QString group_tag;
|
|
QString type_tag;
|
|
|
|
// 数据源配置
|
|
QString sourceType; // "property", "measurement"
|
|
QVariantMap sourceConfig;
|
|
|
|
bool bDataChanged = false; //数据改变标志(临时)
|
|
// 获取完整路径
|
|
QString getFullName() const {
|
|
QStringList parts = {grid_name, zone_name, station_name, currentLevel, bay_name, component_name, group_name, name};
|
|
parts.removeAll("");
|
|
return parts.join(".");
|
|
}
|
|
|
|
//获取完整索引
|
|
QString getFullTag() const {
|
|
QStringList parts = {grid_tag, zone_tag, station_tag, page_tag, currentLevel, bay_tag, component_uuid.toString(), group_tag, tag};
|
|
parts.removeAll("");
|
|
return parts.join(".");
|
|
}
|
|
|
|
// 检查是否匹配过滤条件
|
|
bool matches(const QVariantMap& filter,const QString& type) const {
|
|
for (auto it = filter.begin(); it != filter.end(); ++it) {
|
|
QString field = it.key();
|
|
QString filterValue = it.value().toString();
|
|
QString fieldValue;
|
|
if(type == "name"){
|
|
fieldValue = getFieldName(field);
|
|
}
|
|
else if(type == "tag"){
|
|
fieldValue = getFieldTag(field);
|
|
}
|
|
|
|
if (!filterValue.isEmpty() && fieldValue != filterValue) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
QString getFieldName(const QString& field) const {
|
|
if (field == "grid") return grid_name;
|
|
if (field == "zone") return zone_name;
|
|
if (field == "station") return station_name;
|
|
if (field == "currentLevel") return currentLevel;
|
|
if (field == "bay") return bay_name;
|
|
if (field == "component") return component_name;
|
|
if (field == "group") return group_name;
|
|
if (field == "property") return name;
|
|
return "";
|
|
}
|
|
|
|
QString getFieldTag(const QString& field) const {
|
|
if (field == "grid") return grid_tag;
|
|
if (field == "zone") return zone_tag;
|
|
if (field == "station") return station_tag;
|
|
if (field == "page") return page_tag;
|
|
if (field == "currentLevel") return currentLevel;
|
|
if (field == "bay") return bay_tag;
|
|
if (field == "component") return component_name;
|
|
if (field == "group") return component_uuid.toString();
|
|
if (field == "tag") return name;
|
|
return "";
|
|
}
|
|
};
|
|
|
|
struct ExtraPropertyLevelInfo { //层级关系item信息
|
|
QString displayText; // 显示文本
|
|
QString nameValue; // 名称值
|
|
QString tagValue; // 标签值
|
|
bool isRequired; // 是否必填
|
|
QString placeholder; // 缺省占位符
|
|
};
|
|
|
|
// 基础实体类型
|
|
enum class EntityType {
|
|
Grid,
|
|
Zone,
|
|
Station,
|
|
ConfigurationDiagram,
|
|
Component
|
|
};
|
|
|
|
struct EntityInfo {
|
|
QString sName;
|
|
QString sUuid;
|
|
QString sParentId;
|
|
EntityType eType;
|
|
};
|
|
#endif // TOPOLOGY_H
|