2014-11-22 11:32:12 +08:00
|
|
|
|
#include "elementhashtable.h"
|
2014-11-22 16:27:22 +08:00
|
|
|
|
#include <iostream>
|
2014-11-22 11:32:12 +08:00
|
|
|
|
ElementHashtable::ElementHashtable(QObject *parent) :
|
2014-12-06 21:48:07 +08:00
|
|
|
|
QObject(parent),currentHT(NULL)
|
2014-11-22 11:32:12 +08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ElementHashtable::child(QXmlStreamReader &reader)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QStringRef elementName;
|
|
|
|
|
|
elementName=reader.name();
|
2014-11-24 22:01:30 +08:00
|
|
|
|
QString id;
|
|
|
|
|
|
if(reader.attributes().hasAttribute("rdf:ID"))
|
|
|
|
|
|
{
|
|
|
|
|
|
id=reader.attributes().value("rdf:ID").toString();
|
|
|
|
|
|
}
|
2014-11-22 11:32:12 +08:00
|
|
|
|
BasicElementInfo *pointer=NULL;
|
2014-11-22 22:18:18 +08:00
|
|
|
|
if(elementName=="BusbarSection")
|
|
|
|
|
|
{
|
2014-11-24 22:01:30 +08:00
|
|
|
|
pointer=new BusbarSection(this);
|
2014-11-22 22:18:18 +08:00
|
|
|
|
pointer->parse(reader);
|
|
|
|
|
|
}
|
|
|
|
|
|
if(elementName=="Terminal")
|
|
|
|
|
|
{
|
2014-11-24 22:01:30 +08:00
|
|
|
|
pointer=new Terminal(this);
|
2014-11-22 22:18:18 +08:00
|
|
|
|
pointer->parse(reader);
|
|
|
|
|
|
}
|
|
|
|
|
|
if(elementName=="ACLineSegment")
|
|
|
|
|
|
{
|
2014-11-24 22:01:30 +08:00
|
|
|
|
pointer=new ACLineSegment(this);
|
2014-11-22 22:18:18 +08:00
|
|
|
|
pointer->parse(reader);
|
|
|
|
|
|
}
|
|
|
|
|
|
if(elementName=="Breaker")
|
|
|
|
|
|
{
|
2014-11-24 22:01:30 +08:00
|
|
|
|
pointer=new Breaker(this);
|
2014-11-22 22:18:18 +08:00
|
|
|
|
pointer->parse(reader);
|
|
|
|
|
|
}
|
2014-12-25 11:44:46 +08:00
|
|
|
|
if(elementName=="Substation")
|
|
|
|
|
|
{
|
|
|
|
|
|
pointer=new Substation(this);
|
|
|
|
|
|
pointer->parse(reader);
|
|
|
|
|
|
}
|
2014-12-12 16:24:27 +08:00
|
|
|
|
// if(elementName=="Compensator")
|
|
|
|
|
|
// {
|
|
|
|
|
|
// pointer=new Compensator(this);
|
|
|
|
|
|
// pointer->parse(reader);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if(elementName=="Disconnector")
|
|
|
|
|
|
// {
|
|
|
|
|
|
// pointer=new Disconnector(this);
|
|
|
|
|
|
// pointer->parse(reader);
|
|
|
|
|
|
// }
|
2014-11-22 22:18:18 +08:00
|
|
|
|
if(elementName=="PowerTransformer")
|
|
|
|
|
|
{
|
2014-11-24 22:01:30 +08:00
|
|
|
|
pointer=new PowerTransformer(this);
|
2014-11-22 22:18:18 +08:00
|
|
|
|
pointer->parse(reader);
|
|
|
|
|
|
}
|
2014-12-12 16:24:27 +08:00
|
|
|
|
// if(elementName=="SynchronousMachine")
|
|
|
|
|
|
// {
|
|
|
|
|
|
// pointer=new SynchronousMachine(this);
|
|
|
|
|
|
// pointer->parse(reader);
|
|
|
|
|
|
// }
|
2014-11-22 22:18:18 +08:00
|
|
|
|
|
2014-11-24 22:01:30 +08:00
|
|
|
|
if(pointer && id!="")
|
|
|
|
|
|
{
|
2014-12-06 21:48:07 +08:00
|
|
|
|
QHash<QString,BasicElementInfo *> *hash=this->currentHT;
|
|
|
|
|
|
(*hash)[id]=pointer;
|
2014-11-24 22:01:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2014-11-22 11:32:12 +08:00
|
|
|
|
|
2014-12-06 21:48:07 +08:00
|
|
|
|
bool ElementHashtable::GoPath()
|
2014-11-24 22:01:30 +08:00
|
|
|
|
{
|
2014-12-06 21:48:07 +08:00
|
|
|
|
const QHash<QString,BasicElementInfo*> &zwht=this->eleHT;//从配网开始找
|
2014-11-24 22:01:30 +08:00
|
|
|
|
QList<QString> keys;
|
2014-12-06 21:48:07 +08:00
|
|
|
|
keys=zwht.keys();
|
2014-11-24 22:01:30 +08:00
|
|
|
|
std::cout<<keys.length()<<std::endl;
|
|
|
|
|
|
for(QList<QString>::Iterator ite=keys.begin();
|
|
|
|
|
|
ite!=keys.end();
|
|
|
|
|
|
ite++)
|
2014-11-22 11:32:12 +08:00
|
|
|
|
{
|
2014-12-06 21:48:07 +08:00
|
|
|
|
BasicElementInfo *p=zwht[*ite];
|
|
|
|
|
|
// if(p->getName()=="ACLineSegment"){
|
|
|
|
|
|
// std::cout<<p->getID().toStdString()<<std::endl;
|
|
|
|
|
|
// }
|
2014-12-25 21:35:06 +08:00
|
|
|
|
if(p->getName()=="ACLineSegment" && p->getID()=="AC-591827")
|
2014-11-24 22:01:30 +08:00
|
|
|
|
{
|
2014-12-06 21:48:07 +08:00
|
|
|
|
ACLineSegment *ac=static_cast<ACLineSegment *>(p);//BusbarSection也就是线路头节点
|
|
|
|
|
|
QString acTerminal=ac->getTerminalB();
|
2014-11-26 17:09:37 +08:00
|
|
|
|
//找Terminal的东西
|
2014-12-06 21:48:07 +08:00
|
|
|
|
Terminal *acTerminalP=static_cast<Terminal *>(zwht[acTerminal]);
|
|
|
|
|
|
std::cout<<acTerminalP->getID().toStdString()<<std::endl;
|
2014-11-26 20:49:33 +08:00
|
|
|
|
QString node;
|
2014-12-06 21:48:07 +08:00
|
|
|
|
node=acTerminalP->getConnectivityNode();
|
|
|
|
|
|
if(node=="")
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;//有些Terminal是没有Node的
|
|
|
|
|
|
}
|
2014-11-26 20:49:33 +08:00
|
|
|
|
std::cout<<node.toStdString()<<std::endl;
|
2014-12-06 21:48:07 +08:00
|
|
|
|
TopologyRecorder tpRecorder(this->eleHT);
|
|
|
|
|
|
tpRecorder.startWithNode(node);
|
2014-11-24 22:01:30 +08:00
|
|
|
|
}
|
2014-11-22 11:32:12 +08:00
|
|
|
|
}
|
2014-12-06 21:48:07 +08:00
|
|
|
|
|
2014-11-22 11:32:12 +08:00
|
|
|
|
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++;
|
2014-11-24 22:01:30 +08:00
|
|
|
|
if(loop>600000){
|
2014-11-22 16:27:22 +08:00
|
|
|
|
// break;
|
2014-11-22 11:32:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
if(reader.hasError())
|
|
|
|
|
|
{
|
|
|
|
|
|
qDebug()<<reader.errorString()<<"\n";
|
|
|
|
|
|
qDebug()<<"line number "<<reader.lineNumber()<<"\n";
|
|
|
|
|
|
}
|
|
|
|
|
|
xmlFile.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2014-12-06 21:48:07 +08:00
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|