DiagramDesigner/common/include/global.h

747 lines
17 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef GLOBAL_H
#define GLOBAL_H
#include <QGraphicsItem>
#include <QtCore/QMetaObject>
#include <QtSwap>
#include <QHash>
#include <QUuid>
#include <QJsonObject>
#include <QWidget>
#include <QStandardItemModel>
const double g_dGriaphicsScene_Width = 800;
const double g_dGriaphicsScene_Height = 600;
const int g_dEditorItem_Width = 150;
const int g_dEditorItem_Height = 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_baseBus = QGraphicsItem::UserType + 200,
GIT_baseLine = QGraphicsItem::UserType + 201,
GIT_baseBreaker = QGraphicsItem::UserType + 202
};
enum AbstractItemType //工程模关联的对象类型
{
AIT_motor = 1,
AIT_bus
};
enum class ModelFunctionType //模型函数的类型
{
ProjectModel = 0,
BaseModel
};
class corresbondItem //类型关联函数
{
public:
static QMap<AbstractItemType,GraphicsItemType> linkType;
};
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 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; //基础属性
QStandardItemModel* pSelect; //已选择属性
FormerName formerMeta; //曾用元模名
FormerName formerProject; //曾用工程模名
QMap<QString,projectManager> dataInfo; //存放数据库内容
};
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; //长度限制
};
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; //编辑窗口对象
};
//==================组态拓扑结构======================
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;
};*/
//===================组态编辑器使用================
struct DiagramEditorWizardInfo //组态编辑向导信息
{
int bus_220_num = 0;
int bus_220_division = 1;
int bus_220_circuit = 0;
int bus_110_num = 0;
int bus_110_division = 1;
int bus_110_circuit = 0;
int bus_35_num = 0;
int bus_35_division = 1;
int bus_35_circuit = 0;
};
enum class DiagramEditorStructType
{
bus, //母线
rowData //母线对应的一行数据
};
//==================组态图使用=====================
enum HandleType
{
T_none = 0,
T_resize, //调整大小
T_rotate, //旋转
T_editShape, //编辑形状
T_text, //文本
T_lineIn, //入线口
T_lineOut, //出线口
T_lineInOut //双端线
};
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;
}
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 ((obj.nSrcNodeId == nSrcNodeId)&&(obj.nSrcPortId == nSrcPortId)&&(obj.srcType == srcType)&&(obj.nDestNodeId == nDestNodeId)&&(obj.nDestPortId == nDestPortId)&&(obj.destType == 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使用uuidload数据使用数据库自增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 transRatio; //变比
QString accuracyClass; //精度等级
QString secondaryLoadCapacity; //二次负载容量
QString windingConnectionMethod; //绕组接法
};
struct CtExtraInfo
{
int id;
QString transRatio; //变比
QString accuracyClass; //精度等级
QString secondaryLoadCapacity; //二次负载容量
};
//==================================================
struct baseComponentInfo //基模图元数据
{
int id = 0;
QUuid uuid;
QString name;
QString tag;
int typeId = 0;
QJsonObject context;
QString metaMmodel;
QString projectModel;
};
//==================================================
struct componentInfo //工程模图元数据
{
int id = 0;
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 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 busStability
{
int componentId = 0;
double resistance = 0;
bool anchor_v = false;
double uv_alarm = 0;
double ov_alarm = 0;
bool anchor_i = false;
double ui_alarm = 0;
double oi_alarm = 0;
};*/
//Q_ENUM_NS(GraphicsItemType)
/**
* 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