101 lines
3.0 KiB
C
101 lines
3.0 KiB
C
|
|
#ifndef POWERENTITY_H
|
|||
|
|
#define POWERENTITY_H
|
|||
|
|
/****************************
|
|||
|
|
* 电力实体类,实现拓扑层级的建立 grid-zone-station-diagram
|
|||
|
|
* *************************/
|
|||
|
|
#include <QString>
|
|||
|
|
#include <QList>
|
|||
|
|
#include "global.h"
|
|||
|
|
|
|||
|
|
class PowerTerminal;
|
|||
|
|
|
|||
|
|
// 所有实体的基类(组合模式核心)
|
|||
|
|
class PowerEntity :public QObject{
|
|||
|
|
Q_OBJECT
|
|||
|
|
public:
|
|||
|
|
PowerEntity(EntityType type, const QString& id, const QString& name)
|
|||
|
|
: m_type(type), m_id(id), m_name(name) {}
|
|||
|
|
|
|||
|
|
virtual ~PowerEntity() {
|
|||
|
|
qDeleteAll(m_children);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 添加/删除子元素
|
|||
|
|
void addChild(PowerEntity* child) {
|
|||
|
|
if (child == this || getAllDescendants().contains(this)) {
|
|||
|
|
qCritical() << "Detected cyclic parent-child relationship!";
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
if (child && !m_children.contains(child)) {
|
|||
|
|
m_children.append(child);
|
|||
|
|
child->m_parent = this;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void removeChild(PowerEntity* child) {
|
|||
|
|
if (child && m_children.removeOne(child)) {
|
|||
|
|
child->m_parent = nullptr;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 获取属性
|
|||
|
|
EntityType type() const { return m_type; }
|
|||
|
|
QString id() const { return m_id; }
|
|||
|
|
QString name() const { return m_name; }
|
|||
|
|
QList<PowerEntity*> children() const { return m_children; }
|
|||
|
|
PowerEntity* parent() const { return m_parent; }
|
|||
|
|
|
|||
|
|
// 递归查找
|
|||
|
|
QList<PowerEntity*> getAllDescendants() const {
|
|||
|
|
QList<PowerEntity*> descendants;
|
|||
|
|
for (PowerEntity* child : m_children) {
|
|||
|
|
descendants.append(child);
|
|||
|
|
descendants.append(child->getAllDescendants());
|
|||
|
|
}
|
|||
|
|
return descendants;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
virtual QJsonObject toJson() const;
|
|||
|
|
public:
|
|||
|
|
// 接线点管理
|
|||
|
|
void addTerminal(PowerTerminal* terminal);
|
|||
|
|
void removeTerminal(const QString& terminalId);
|
|||
|
|
QList<PowerTerminal*> terminals() const { return m_terminals; }
|
|||
|
|
PowerTerminal* findTerminal(const QString& terminalId) const;
|
|||
|
|
signals:
|
|||
|
|
void terminalAdded(PowerTerminal* terminal);
|
|||
|
|
void terminalRemoved(const QString& terminalId);
|
|||
|
|
protected:
|
|||
|
|
QList<PowerTerminal*> m_terminals;
|
|||
|
|
private:
|
|||
|
|
EntityType m_type;
|
|||
|
|
QString m_id; // 唯一标识符(可用UUID生成)
|
|||
|
|
QString m_name;
|
|||
|
|
PowerEntity* m_parent = nullptr;
|
|||
|
|
QList<PowerEntity*> m_children;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// 组态图特殊属性(继承自PowerEntity)
|
|||
|
|
class ConfigurationDiagram : public PowerEntity {
|
|||
|
|
public:
|
|||
|
|
ConfigurationDiagram(const QString& id, const QString& name)
|
|||
|
|
: PowerEntity(EntityType::ConfigurationDiagram, id, name) {}
|
|||
|
|
|
|||
|
|
// 可扩展图特有属性(如版本、创建时间等)
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
//电网区域划分 grid-zone-station
|
|||
|
|
class PowerDivision : public PowerEntity {
|
|||
|
|
public:
|
|||
|
|
PowerDivision(EntityType type,const QString& id, const QString& name)
|
|||
|
|
: PowerEntity(type, id, name) {}
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
//电力元件(拓扑)
|
|||
|
|
class PowerComponent : public PowerEntity {
|
|||
|
|
public:
|
|||
|
|
PowerComponent(EntityType type,const QString& id, const QString& name)
|
|||
|
|
: PowerEntity(type, id, name) {}
|
|||
|
|
};
|
|||
|
|
#endif
|