2025-04-22 10:10:55 +08:00
|
|
|
|
#ifndef TOPOLOGYMANAGER_H
|
|
|
|
|
|
#define TOPOLOGYMANAGER_H
|
|
|
|
|
|
/****************************
|
|
|
|
|
|
* 拓扑关系管理类
|
|
|
|
|
|
* *************************/
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
|
#include <QList>
|
|
|
|
|
|
#include "powerConnection.h"
|
|
|
|
|
|
#include "powerTerminal.h"
|
|
|
|
|
|
#include "global.h"
|
|
|
|
|
|
|
|
|
|
|
|
class PowerEntity;
|
2025-05-09 19:36:32 +08:00
|
|
|
|
class BaseProperty;
|
2025-04-22 10:10:55 +08:00
|
|
|
|
|
|
|
|
|
|
class TopologyManager : public QObject {
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
public:
|
|
|
|
|
|
static TopologyManager& instance();
|
|
|
|
|
|
|
|
|
|
|
|
// 实体管理
|
2025-08-25 12:02:15 +08:00
|
|
|
|
PowerEntity* createEntity(EntityType type,const QString& uuid,const QString& name,ModelFunctionType tpe = ModelFunctionType::ProjectModel,const QString& block = QString());
|
2025-06-13 19:00:05 +08:00
|
|
|
|
PowerEntity* findEntity(const QString& id,ModelFunctionType = ModelFunctionType::ProjectModel) const;
|
|
|
|
|
|
bool deleteEntity(const QString& id,ModelFunctionType = ModelFunctionType::ProjectModel);
|
2025-08-25 12:02:15 +08:00
|
|
|
|
QList<PowerEntity*> getEntitiesByBlock(const QString&); //通过名称返回entity中的实体(blockEditor中)
|
2025-04-22 10:10:55 +08:00
|
|
|
|
|
|
|
|
|
|
// 连接管理
|
2025-06-13 19:00:05 +08:00
|
|
|
|
PowerConnection* createConnection(const QString& uuid,const QString& fromTerId, const QString& toTerId,const QString& fromId,const QString& toId,ModelFunctionType tpe = ModelFunctionType::ProjectModel);
|
|
|
|
|
|
QList<PowerConnection*> getConnectionsForTerminal(const QString& terminalId,ModelFunctionType tpe = ModelFunctionType::ProjectModel) const;
|
|
|
|
|
|
void removeConnection(const QString& connId,ModelFunctionType = ModelFunctionType::ProjectModel);
|
|
|
|
|
|
bool validateConnection(const QString& fromTermId, const QString& toTermId,ModelFunctionType = ModelFunctionType::ProjectModel) const;
|
2025-04-22 10:10:55 +08:00
|
|
|
|
|
|
|
|
|
|
// 连接查询接口
|
2025-06-13 19:00:05 +08:00
|
|
|
|
QList<PowerConnection*> getConnectionsFor(const QString& entityId,ModelFunctionType tpe = ModelFunctionType::ProjectModel) const;
|
|
|
|
|
|
PowerConnection* connection(const QString& conId,ModelFunctionType tpe = ModelFunctionType::ProjectModel) const;
|
|
|
|
|
|
PowerConnection* connection(const QString& fromPin,const QString& toPin,ModelFunctionType tpe = ModelFunctionType::ProjectModel);
|
|
|
|
|
|
QHash<QString,PowerConnection*> getAllConnections(ModelFunctionType tpe = ModelFunctionType::ProjectModel);
|
2025-04-22 10:10:55 +08:00
|
|
|
|
|
2025-06-13 19:00:05 +08:00
|
|
|
|
PowerEntity* getEntity(const QString& id,ModelFunctionType tpe = ModelFunctionType::ProjectModel) const;
|
|
|
|
|
|
QList<PowerEntity*> findEntitiesByName(const QString& name,ModelFunctionType tpe = ModelFunctionType::ProjectModel) const;
|
2025-04-22 10:10:55 +08:00
|
|
|
|
|
2025-05-09 19:36:32 +08:00
|
|
|
|
//==========================组态图拓扑相关===================================
|
2025-06-13 19:00:05 +08:00
|
|
|
|
PowerEntity* createDiagram(const QString& id,const QString& name,ModelFunctionType tpe = ModelFunctionType::ProjectModel); //单独创建组态图
|
|
|
|
|
|
PowerEntity* findDiagram(const QString& id,ModelFunctionType tpe = ModelFunctionType::ProjectModel) const;
|
|
|
|
|
|
bool deleteDiagram(const QString& id,ModelFunctionType tpe = ModelFunctionType::ProjectModel);
|
2025-05-09 19:36:32 +08:00
|
|
|
|
|
2025-04-22 10:10:55 +08:00
|
|
|
|
public:
|
|
|
|
|
|
// 接线点管理
|
|
|
|
|
|
PowerTerminal* createTerminal(const QString& parentEntityId,
|
|
|
|
|
|
TerminalType type,
|
|
|
|
|
|
const QString& name,
|
2025-04-30 16:29:17 +08:00
|
|
|
|
const QPointF& relPos = QPointF(),
|
2025-06-13 19:00:05 +08:00
|
|
|
|
const QString& uuid = "",
|
|
|
|
|
|
ModelFunctionType tpe = ModelFunctionType::ProjectModel);
|
|
|
|
|
|
bool deleteTerminal(const QString& terminalId,ModelFunctionType tpe = ModelFunctionType::ProjectModel);
|
|
|
|
|
|
PowerTerminal* getTerminal(const QString& terminalId,ModelFunctionType tpe = ModelFunctionType::ProjectModel) const;
|
|
|
|
|
|
QList<PowerTerminal*> getTerminalsForEntity(const QString& entityId,ModelFunctionType tpe = ModelFunctionType::ProjectModel) const;
|
|
|
|
|
|
PowerEntity* getEntityByTerminal(const QString& terminalId,ModelFunctionType tpe = ModelFunctionType::ProjectModel) const; //返回terminal所在的entity实体
|
|
|
|
|
|
PowerConnection* getConnectionContainsTerminal(const QString& terminalId,ModelFunctionType tpe = ModelFunctionType::ProjectModel) const; //返回包含terminal的connection
|
2025-04-22 10:10:55 +08:00
|
|
|
|
signals:
|
|
|
|
|
|
void entityCreated(const QString&);
|
|
|
|
|
|
void entityDeleted(const QString&);
|
|
|
|
|
|
void connectionCreated(const QString&);
|
|
|
|
|
|
void connectionRemoved(const QString&);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
explicit TopologyManager(QObject* parent = nullptr);
|
|
|
|
|
|
~TopologyManager();
|
|
|
|
|
|
void clearAllData();
|
|
|
|
|
|
QHash<QString, PowerEntity*> m_entities; // ID到实体映射
|
|
|
|
|
|
|
2025-05-09 19:36:32 +08:00
|
|
|
|
QHash<QString, PowerEntity*> m_diagrams; // 组态图拓扑结构
|
2025-04-22 10:10:55 +08:00
|
|
|
|
// 连接存储
|
|
|
|
|
|
QHash<QString,PowerConnection*> m_connections;
|
2025-04-30 16:29:17 +08:00
|
|
|
|
QMultiHash<QString,PowerConnection*> m_connectionIndex; // 接线点ID到连接的映射
|
2025-06-13 19:00:05 +08:00
|
|
|
|
|
2025-04-22 10:10:55 +08:00
|
|
|
|
QHash<QString, PowerTerminal*> m_allTerminals; // ID到接线点映射
|
|
|
|
|
|
QHash<QString, QList<PowerTerminal*>> m_terminalsByEntity; // 实体ID到接线点列表
|
2025-04-30 16:29:17 +08:00
|
|
|
|
|
|
|
|
|
|
QHash<QString, QSet<QString>> m_entityConnections; // <entityId, Set<connectionId>>
|
2025-06-13 19:00:05 +08:00
|
|
|
|
private:
|
|
|
|
|
|
QHash<QString, PowerEntity*> m_baseEntities; // ID到实体映射(基模)
|
|
|
|
|
|
QHash<QString, PowerEntity*> m_baseDiagrams; // 组态图拓扑结构(基模)
|
|
|
|
|
|
// 连接存储
|
|
|
|
|
|
QHash<QString,PowerConnection*> m_baseConnections;
|
|
|
|
|
|
QMultiHash<QString,PowerConnection*> m_baseConnectionIndex; // 接线点ID到连接的映射(基模)
|
|
|
|
|
|
|
|
|
|
|
|
QHash<QString, PowerTerminal*> m_baseAllTerminals; // ID到接线点映射(基模)
|
|
|
|
|
|
QHash<QString, QList<PowerTerminal*>> m_baseTerminalsByEntity; // 实体ID到接线点列表(基模)
|
|
|
|
|
|
|
|
|
|
|
|
QHash<QString, QSet<QString>> m_baseEntityConnections; // <entityId, Set<connectionId>>(基模)
|
2025-08-25 12:02:15 +08:00
|
|
|
|
private:
|
|
|
|
|
|
QHash<QString, PowerEntity*> m_editorEntities; // ID到实体映射(编辑器)
|
|
|
|
|
|
// 连接存储
|
|
|
|
|
|
QHash<QString,PowerConnection*> m_editorConnections;
|
|
|
|
|
|
QMultiHash<QString,PowerConnection*> m_editorConnectionIndex; // 接线点ID到连接的映射(编辑器)
|
|
|
|
|
|
|
|
|
|
|
|
QHash<QString, PowerTerminal*> m_editorAllTerminals; // ID到接线点映射(编辑器)
|
|
|
|
|
|
QHash<QString, QList<PowerTerminal*>> m_editorTerminalsByEntity; // 实体ID到接线点列表(编辑器)
|
|
|
|
|
|
|
|
|
|
|
|
QHash<QString, QSet<QString>> m_editorEntityConnections; // <entityId, Set<connectionId>>(编辑器)
|
|
|
|
|
|
private:
|
|
|
|
|
|
QHash<QString, PowerEntity*> m_blockEntities; // ID到实体映射(模块编辑)
|
|
|
|
|
|
// 连接存储
|
|
|
|
|
|
QHash<QString,PowerConnection*> m_blockConnections;
|
|
|
|
|
|
QMultiHash<QString,PowerConnection*> m_blockConnectionIndex; // 接线点ID到连接的映射(模块编辑)
|
|
|
|
|
|
|
|
|
|
|
|
QHash<QString, PowerTerminal*> m_blockAllTerminals; // ID到接线点映射(模块编辑)
|
|
|
|
|
|
QHash<QString, QList<PowerTerminal*>> m_blockTerminalsByEntity; // 实体ID到接线点列表(模块编辑)
|
|
|
|
|
|
|
|
|
|
|
|
QHash<QString, QSet<QString>> m_blockEntityConnections; // <entityId, Set<connectionId>>(模块编辑)
|
2025-06-13 19:00:05 +08:00
|
|
|
|
|
2025-04-22 10:10:55 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|