277 lines
9.9 KiB
C++
277 lines
9.9 KiB
C++
#include "topologyrecorder.h"
|
|
#include <iostream>
|
|
#include <QList>
|
|
TopologyRecorder::TopologyRecorder(const QHash<QString,BasicElementInfo *>& elementHT, const QVector<QString> &FDSet, QObject *parent):eleHT(elementHT),FDSet(FDSet)
|
|
{
|
|
}
|
|
|
|
TopologyRecorder::~TopologyRecorder()
|
|
{
|
|
const QHash<QString,BasicElementInfo*> &ht=this->eleHT;
|
|
std::cout<<"total tf"<<this->tfs.length()<<std::endl;
|
|
//统计一下每个Container下有多少个变压器
|
|
QHash<QString,QVector<QString> > s;
|
|
for(QVector<QString>::iterator ite=this->tfs.begin();
|
|
ite!=this->tfs.end();
|
|
ite++)
|
|
{
|
|
PowerTransformer *pf=static_cast<PowerTransformer *>(ht[*ite]);
|
|
QString container;
|
|
container=pf->getEquipmentMemberOf_EquipmentContainer();
|
|
s[container].push_back(*ite);
|
|
}
|
|
std::cout<<"container "<<s.keys().length()<<std::endl;
|
|
QList<QString> keys=s.keys();
|
|
for(QList<QString>::iterator ite=keys.begin();
|
|
ite!=keys.end();
|
|
ite++)
|
|
{
|
|
QString k=*ite;
|
|
std::cout<<k.toStdString();
|
|
Substation *sb=static_cast<Substation *>(ht[k]);
|
|
std::cout<<", "<<sb->getNamingDescription().toStdString();
|
|
QVector<QString> v=s[k];
|
|
foreach (QString n, v) {
|
|
std::cout<<", "<<n.toStdString();
|
|
PowerTransformer *pf=static_cast<PowerTransformer *>(ht[n]);
|
|
std::cout<<"("<<pf->getNamingDescription().toStdString()<<")";
|
|
}
|
|
std::cout<<std::endl;
|
|
}
|
|
}
|
|
|
|
bool TopologyRecorder::isEquipmentNeeded(const QString& substatinID)
|
|
{
|
|
const QHash<QString,BasicElementInfo*> &ht=this->eleHT;
|
|
Substation *sfd=static_cast<Substation *>(ht[substatinID]);
|
|
if(sfd==NULL)
|
|
{
|
|
std::cout<<"can not find"<<substatinID.toStdString()<<std::endl;
|
|
}
|
|
else
|
|
{
|
|
QString feederID=sfd->getSubstationMemberOf_Feeder();
|
|
return this->FDSet.contains(feederID) ||sfd->getNamingDescription()=="V馈线站";
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void TopologyRecorder::exportTo(const QString& path)
|
|
{
|
|
this->cimExporter.exportTo(path);
|
|
}
|
|
|
|
bool TopologyRecorder::startWithNode(const QString& node)
|
|
{
|
|
if(node=="")
|
|
{
|
|
return true;
|
|
}
|
|
const QHash<QString,BasicElementInfo*> &ht=this->eleHT;
|
|
QString anotherTerminal;
|
|
QVector<QString> anotherTerminalVector;
|
|
anotherTerminalVector=this->nodeToTerminal.value(node);//一个Node可以找到多个与之相连的Terminal
|
|
for(int atI=0;atI<anotherTerminalVector.length();atI++)
|
|
{
|
|
TopologyRecorder::Type::EleType typ;
|
|
BasicElementInfo *foundEle=NULL;
|
|
// bool foundCate=false;
|
|
anotherTerminal=anotherTerminalVector.at(atI);
|
|
if(this->reachedTerminal.contains(anotherTerminal))
|
|
{
|
|
continue;
|
|
}
|
|
this->reachedTerminal[anotherTerminal]=0;
|
|
Terminal *anotherTerminalP=static_cast<Terminal *>(ht[anotherTerminal]);
|
|
QString ce;
|
|
ce=anotherTerminalP->getConductingEquipment();
|
|
QPair<QString,QString> fromTo;
|
|
QString terminalA;
|
|
QString terminalB;
|
|
//通过ACSegmentLine的ID来找Terminal。下同。
|
|
if(ce.startsWith("AC"))
|
|
{
|
|
QString acID=ce;
|
|
fromTo.first=node;
|
|
fromTo.second=acID;
|
|
ACLineSegment *AC=static_cast<ACLineSegment *>(ht[acID]);
|
|
if(!AC)
|
|
{
|
|
continue;
|
|
}
|
|
terminalA=AC->getTerminalA();
|
|
terminalB=AC->getTerminalB();
|
|
std::cout<<"find"<<AC->getID().toStdString()<<std::endl;
|
|
std::cout<<AC->getNamingDescription().toStdString()<<std::endl;
|
|
//把线路长度也输出来看一下
|
|
std::cout<<AC->getLength()<<std::endl;
|
|
foundEle=AC;
|
|
typ=TopologyRecorder::Type::AC;
|
|
}
|
|
if(ce.startsWith("SW"))
|
|
{
|
|
BasicElementInfo *bi=ht[ce];
|
|
if(bi!=NULL)
|
|
{
|
|
|
|
if(bi->getName()=="Breaker")
|
|
{
|
|
std::cout<<bi->getName().toStdString()<<std::endl;
|
|
QString swID=ce;
|
|
fromTo.first=node;
|
|
fromTo.second=swID;
|
|
Breaker *SW=static_cast<Breaker *>(ht[swID]);
|
|
if(!SW)
|
|
{
|
|
continue;
|
|
}
|
|
//显示开关状态
|
|
if(SW->getOpenState()==true)
|
|
{
|
|
std::cout<<"sw "<<SW->getNamingDescription().toStdString()<<"is open"<<std::endl;
|
|
}
|
|
else
|
|
{
|
|
std::cout<<"sw "<<SW->getNamingDescription().toStdString()<<"is close"<<std::endl;
|
|
}
|
|
terminalA=SW->getTerminalA();
|
|
terminalB=SW->getTerminalB();
|
|
std::cout<<"find"<<SW->getID().toStdString()<<std::endl;
|
|
foundEle=SW;
|
|
typ=TopologyRecorder::Type::BREAKER;
|
|
}
|
|
if(bi->getName()=="Disconnector")
|
|
{
|
|
std::cout<<bi->getName().toStdString()<<std::endl;
|
|
QString disConID=ce;
|
|
Disconnector *Dis=static_cast<Disconnector *>(ht[disConID]);
|
|
//先判断一下是不是需要的Disconnector
|
|
QString container=Dis->getEquipmentMemberOf_EquipmentContainer();
|
|
if(!this->isEquipmentNeeded(container))
|
|
{
|
|
std::cout<<"Dissw not belong "<<disConID.toStdString()<<std::endl;
|
|
continue;
|
|
}
|
|
fromTo.first=node;
|
|
fromTo.second=disConID;
|
|
|
|
if(!Dis)
|
|
{
|
|
continue;
|
|
}
|
|
//显示开关状态
|
|
if(Dis->getOpenState()==true)
|
|
{
|
|
std::cout<<"Dissw "<<Dis->getNamingDescription().toStdString()<<"is open"<<std::endl;
|
|
}
|
|
else
|
|
{
|
|
std::cout<<"Dissw "<<Dis->getNamingDescription().toStdString()<<"is close"<<std::endl;
|
|
}
|
|
terminalA=Dis->getTerminalA();
|
|
terminalB=Dis->getTerminalB();
|
|
std::cout<<"find"<<Dis->getID().toStdString()<<std::endl;
|
|
foundEle=Dis;
|
|
typ=TopologyRecorder::Type::DISCONNECTOR;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
continue;
|
|
}
|
|
|
|
|
|
}
|
|
if(ce.startsWith("BS"))
|
|
{
|
|
//看找到那个Substation了
|
|
BusbarSection *bs=static_cast<BusbarSection *>(ht[ce]);
|
|
if(bs==NULL)
|
|
{
|
|
std::cout<<"not find bussection"<<ce.toStdString()<<std::endl;
|
|
}
|
|
else
|
|
{
|
|
QString container=bs->getEquipmentMemberOf_EquipmentContainer();
|
|
Substation *sfd=static_cast<Substation *>(ht[container]);
|
|
if(sfd==NULL)
|
|
{
|
|
std::cout<<"can not find"<<container.toStdString()<<std::endl;
|
|
}
|
|
else
|
|
{
|
|
std::cout<<"encounter "<<sfd->getNamingDescription().toStdString()<<std::endl;
|
|
if(!this->isEquipmentNeeded(container))
|
|
{
|
|
std::cout<<"not belong"<<std::endl;
|
|
}
|
|
}
|
|
}
|
|
continue;
|
|
}
|
|
if(ce.startsWith("TF"))
|
|
{
|
|
QString tfID=ce;
|
|
PowerTransformer *tf=static_cast<PowerTransformer *>(ht[tfID]);
|
|
std::cout<<"TF"<<tf->getNamingDescription().toStdString()<<std::endl;
|
|
//判断一下这个变压器是不是我们需要的
|
|
QString equipmentContainer;
|
|
equipmentContainer=tf->getEquipmentMemberOf_EquipmentContainer();
|
|
if(this->isEquipmentNeeded(equipmentContainer))
|
|
{
|
|
this->tfs.push_back(tfID);
|
|
fromTo.first=node;
|
|
fromTo.second=tfID;
|
|
foundEle=tf;
|
|
}
|
|
else
|
|
{
|
|
std::cout<<tf->getNamingDescription().toStdString()<<"not belong"<<std::endl;
|
|
}
|
|
typ=TopologyRecorder::Type::TF;
|
|
|
|
}
|
|
if(foundEle)
|
|
{
|
|
Branch *branch=NULL;
|
|
switch(typ)
|
|
{
|
|
case TopologyRecorder::Type::AC:
|
|
branch=new Line(fromTo,static_cast<ACLineSegment *>(foundEle),this);
|
|
this->cimExporter.add(fromTo,static_cast<Line *>(branch));
|
|
break;
|
|
case TopologyRecorder::Type::BREAKER:
|
|
branch=new Switch(fromTo,this);
|
|
this->cimExporter.add(fromTo,static_cast<Switch *>(branch));
|
|
break;
|
|
case TopologyRecorder::Type::DISCONNECTOR:
|
|
branch=new Switch(fromTo,this);
|
|
this->cimExporter.add(fromTo,static_cast<Switch *>(branch));
|
|
break;
|
|
case TopologyRecorder::Type::TF:
|
|
branch=new Transformer(fromTo,static_cast<PowerTransformer *>(foundEle),this);
|
|
this->cimExporter.add(fromTo,static_cast<Transformer *>(branch));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
QString nextTerminal;
|
|
nextTerminal=(terminalA==anotherTerminal)?terminalB:terminalA;
|
|
Terminal *nextTerminalP=static_cast<Terminal *>(ht[nextTerminal]);
|
|
if(!nextTerminalP)
|
|
{
|
|
continue;
|
|
}
|
|
QString nextNode=nextTerminalP->getConnectivityNode();
|
|
this->startWithNode(nextNode);
|
|
}
|
|
else
|
|
{
|
|
std::cout<<"not found cate "<<ce.toStdString()<<std::endl;
|
|
continue;
|
|
}
|
|
|
|
}
|
|
return true;
|
|
}
|