197 lines
5.1 KiB
C++
197 lines
5.1 KiB
C++
#include "elementhashtable.h"
|
||
#include <iostream>
|
||
ElementHashtable::ElementHashtable(QObject *parent) :
|
||
QObject(parent),currentHT(NULL),tpRecorder(NULL)
|
||
{
|
||
}
|
||
|
||
bool ElementHashtable::child(QXmlStreamReader &reader)
|
||
{
|
||
|
||
|
||
QStringRef elementName;
|
||
elementName=reader.name();
|
||
QString id;
|
||
if(reader.attributes().hasAttribute("rdf:ID"))
|
||
{
|
||
id=reader.attributes().value("rdf:ID").toString();
|
||
}
|
||
BasicElementInfo *pointer=NULL;
|
||
if(elementName=="BusbarSection")
|
||
{
|
||
pointer=new BusbarSection(this);
|
||
pointer->parse(reader);
|
||
}
|
||
if(elementName=="Terminal")
|
||
{
|
||
pointer=new Terminal(this);
|
||
pointer->parse(reader);
|
||
}
|
||
if(elementName=="ACLineSegment")
|
||
{
|
||
pointer=new ACLineSegment(this);
|
||
pointer->parse(reader);
|
||
}
|
||
if(elementName=="Breaker")
|
||
{
|
||
pointer=new Breaker(this);
|
||
pointer->parse(reader);
|
||
}
|
||
if(elementName=="Substation")
|
||
{
|
||
pointer=new Substation(this);
|
||
pointer->parse(reader);
|
||
}
|
||
// if(elementName=="Compensator")
|
||
// {
|
||
// pointer=new Compensator(this);
|
||
// pointer->parse(reader);
|
||
// }
|
||
if(elementName=="Disconnector")
|
||
{
|
||
pointer=new Disconnector(this);
|
||
pointer->parse(reader);
|
||
}
|
||
if(elementName=="PowerTransformer")
|
||
{
|
||
pointer=new PowerTransformer(this);
|
||
pointer->parse(reader);
|
||
}
|
||
if(elementName=="SynchronousMachine")
|
||
{
|
||
pointer=new SynchronousMachine(this);
|
||
pointer->parse(reader);
|
||
}
|
||
|
||
if(pointer && id!="")
|
||
{
|
||
QHash<QString,BasicElementInfo *> *hash=this->currentHT;
|
||
(*hash)[id]=pointer;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
|
||
|
||
bool ElementHashtable::GoPath()
|
||
{
|
||
const QHash<QString,BasicElementInfo*> &zwht=this->eleHT;//从配网开始找
|
||
QList<QString> keys;
|
||
keys=zwht.keys();
|
||
// std::cout<<keys.length()<<std::endl;
|
||
for(QList<QString>::Iterator ite=keys.begin();
|
||
ite!=keys.end();
|
||
ite++)
|
||
{
|
||
BasicElementInfo *p=zwht[*ite];
|
||
if(p->getName()=="ACLineSegment" && p->getID()==this->lineID)
|
||
{
|
||
ACLineSegment *ac=static_cast<ACLineSegment *>(p);//BusbarSection也就是线路头节点
|
||
QString acTerminal=ac->getTerminalB();
|
||
//找Terminal的东西
|
||
Terminal *acTerminalP=static_cast<Terminal *>(zwht[acTerminal]);
|
||
// std::cout<<acTerminalP->getID().toStdString()<<std::endl;
|
||
QString node;
|
||
node=acTerminalP->getConnectivityNode();
|
||
if(node=="")
|
||
{
|
||
continue;//有些Terminal是没有Node的
|
||
}
|
||
// std::cout<<node.toStdString()<<std::endl;
|
||
if(this->tpRecorder!=NULL)
|
||
{
|
||
delete this->tpRecorder;
|
||
this->tpRecorder=NULL;
|
||
}
|
||
this->tpRecorder=new TopologyRecorder(this->eleHT,this->FDSet,this->loadFilePath);
|
||
this->tpRecorder->startWithNode(node);
|
||
// this->tpRecorder->exportTo("");
|
||
break;
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
bool ElementHashtable::parse(const QString& xmlPath)
|
||
{
|
||
QFile xmlFile(xmlPath);
|
||
|
||
int loop=0;
|
||
if(xmlFile.open(QFile::ReadOnly))
|
||
{
|
||
QXmlStreamReader reader(&xmlFile);
|
||
while(!reader.atEnd() && !reader.hasError())
|
||
{
|
||
reader.readNext();
|
||
if(reader.isStartElement())
|
||
{
|
||
if(reader.name()=="RDF")//不要读<rdf:RDF xmlns:rdf="http://www.w3.org/1999/ …… 这样一堆东西
|
||
{
|
||
continue;
|
||
}
|
||
this->child(reader);//处理根元素下的第一级子元素,也就是Substation这一类。
|
||
}
|
||
loop++;
|
||
// if(loop>600000){
|
||
// break;
|
||
// }
|
||
|
||
}
|
||
if(reader.hasError())
|
||
{
|
||
qDebug()<<reader.errorString()<<"\n";
|
||
qDebug()<<"line number "<<reader.lineNumber()<<"\n";
|
||
}
|
||
xmlFile.close();
|
||
}
|
||
return true;
|
||
}
|
||
|
||
bool ElementHashtable::setCurrentHashTable(QHash<QString,BasicElementInfo *> *t)
|
||
{
|
||
this->currentHT=t;
|
||
return true;
|
||
}
|
||
|
||
bool ElementHashtable::Parse(const QString& xmlPWPath,const QString& xmlZWPath){
|
||
this->setCurrentHashTable(&this->eleHT);
|
||
this->parse(xmlPWPath);
|
||
// this->setCurrentHashTable(&this->mainStationHT);
|
||
// this->parse(xmlZWPath);
|
||
return true;
|
||
}
|
||
|
||
|
||
|
||
void ElementHashtable::SetACLineID(const QString &id)//寻找的线路ID
|
||
{
|
||
this->lineID=id;
|
||
}
|
||
void ElementHashtable::SetFDSet(const QVector<QString> &FDSet)//FeeDer集合
|
||
{
|
||
this->FDSet=FDSet;
|
||
}
|
||
|
||
void ElementHashtable::ShowContainerInfo(const QString& fileName)
|
||
{
|
||
QString relPath="D:/MyPro/cimforreduceloss/testHasttable/output/";
|
||
relPath+=fileName+".txt";
|
||
QFile file(relPath);
|
||
if(file.open(QFile::WriteOnly|QFile::Text))
|
||
{
|
||
QTextStream stream(&file);
|
||
this->tpRecorder->showContainerInfo(stream);
|
||
file.close();
|
||
}
|
||
else
|
||
{
|
||
std::cerr<<"not open"<<relPath.toStdString()<<std::endl;
|
||
}
|
||
}
|
||
|
||
void ElementHashtable::SetLoadFilePath(const QString &path)
|
||
{
|
||
this->loadFilePath=path;
|
||
}
|