201 lines
6.0 KiB
C++
201 lines
6.0 KiB
C++
#include "cimexporter.h"
|
|
#include <iostream>
|
|
CIMExporter::CIMExporter(const QHash<QString, BasicElementInfo *> &eleHT, const QString &loadDir):loadDir(loadDir),eleHT(eleHT)
|
|
{
|
|
}
|
|
|
|
void CIMExporter::add(const QPair<QString,QString>& fromTo,Line* line)
|
|
{
|
|
LineStru lineStru;
|
|
lineStru.line=line;
|
|
lineStru.fromID=fromTo.first;
|
|
lineStru.toID=fromTo.second;
|
|
this->line.push_back(lineStru);
|
|
|
|
}
|
|
void CIMExporter::add(const QPair<QString,QString>& fromTo,Switch* sw)
|
|
{
|
|
SwitchStru switchStru;
|
|
switchStru.sw=sw;
|
|
switchStru.fromID=fromTo.first;
|
|
switchStru.toID=fromTo.second;
|
|
this->sw.push_back(switchStru);
|
|
}
|
|
void CIMExporter::add(const QPair<QString,QString>& fromTo,Transformer* tf)
|
|
{
|
|
TransformerStru tfStru;
|
|
tfStru.tf=tf;
|
|
tfStru.fromID=fromTo.first;
|
|
tfStru.toID=fromTo.second;
|
|
this->tf.push_back(tfStru);
|
|
}
|
|
|
|
|
|
void CIMExporter::exportTo(const QString& path)
|
|
{
|
|
|
|
|
|
//输出到文件
|
|
QFile fd(path);
|
|
if(fd.open(QFile::WriteOnly))
|
|
{
|
|
//先给所有节点都编号
|
|
this->idToNumber(this->line);
|
|
this->idToNumber(this->sw);
|
|
this->idToNumber(this->tf);
|
|
//开始按要求输出
|
|
//先输出线路
|
|
QTextStream writer(&fd);
|
|
writer<<QStringLiteral("线路")<<QStringLiteral("\r\n");
|
|
writer<<QStringLiteral("节点号")<<QStringLiteral("\t")<<QStringLiteral("节点号")<<QStringLiteral("\t")<<QStringLiteral("型号")<<QStringLiteral("\t")<<QStringLiteral("长度(m)")<<QStringLiteral("\r\n");
|
|
for(QList<LineStru>::iterator ite=this->line.begin();
|
|
ite!=this->line.end();
|
|
ite++)
|
|
{
|
|
LineStru l=*ite;
|
|
writer<<l.fromNum<<"\t";
|
|
writer<<l.toNum<<"\t";
|
|
writer<<"type"<<"\t";
|
|
writer<<l.line->length<<"\r\n";
|
|
}
|
|
//输出刀闸
|
|
for(QList<SwitchStru>::iterator ite=this->sw.begin();
|
|
ite!=this->sw.end();
|
|
ite++)
|
|
{
|
|
writer<<ite->fromNum<<"\t";
|
|
writer<<ite->toNum<<"\t";
|
|
writer<<"type"<<"\t";
|
|
writer<<0<<"\r\n";
|
|
}
|
|
//输出负荷
|
|
RecurseDir recurseDir;
|
|
recurseDir.setDir(this->loadDir);
|
|
QStringList files;
|
|
files=recurseDir.getFiles();
|
|
//只取文件名
|
|
QStringList baseNames;
|
|
foreach(QString file,files)
|
|
{
|
|
QFileInfo fileInfo(file);
|
|
baseNames<<fileInfo.baseName();
|
|
}
|
|
writer<<QStringLiteral("变压器")<<"\r\n";
|
|
writer<<QStringLiteral("节点号")<<"\t"<<QStringLiteral("节点号")<<"\t"<<QStringLiteral("型号")<<"\t"<<QStringLiteral("容量(MVA)")<<"\r\n";
|
|
QStringList usedLoad;
|
|
for(QList<TransformerStru>::iterator ite=this->tf.begin();
|
|
ite!=this->tf.end();
|
|
ite++)
|
|
{
|
|
PowerTransformer *tf=ite->tf->getTF();
|
|
QString subID=tf->getEquipmentMemberOf_EquipmentContainer();//所属Substation的ID
|
|
Substation *sub=static_cast<Substation *>(this->eleHT[subID]);
|
|
if(!sub)
|
|
{
|
|
std::cout<<"CIMExporter:: can not substation of "<<subID.toStdString()<<std::endl;
|
|
continue;
|
|
}
|
|
LoadMapping loadMapping;
|
|
QVector<QSharedPointer<LoadInfo> > vecLoadInfo=loadMapping.getSubstationLoad(sub->getID());
|
|
foreach(QSharedPointer<LoadInfo> p,vecLoadInfo)
|
|
{
|
|
QFileInfo targetBasename(p->getLoadPath());
|
|
// std::cout<<targetBasename.baseName().toLocal8Bit().data()<<std::endl;
|
|
if( baseNames.contains( targetBasename.baseName()) and !usedLoad.contains(targetBasename.baseName()))
|
|
{
|
|
// std::cout<<"match "<<targetBasename.baseName().toLocal8Bit().data()<<std::endl;
|
|
usedLoad<<targetBasename.baseName();
|
|
// p->updateByTime(QTime(3,45,0));
|
|
// std::cout<<this->numberIt(ite->toID)<<" "<< p->getPA()<<std::endl;
|
|
writer<<ite->fromNum<<"\t";
|
|
writer<<ite->toNum<<"\t";
|
|
writer<<"type"<<"\t";
|
|
writer<<tf->getMVA()<<"\r\n";
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
//列出没有用的负荷文件
|
|
foreach(QString name, baseNames)
|
|
{
|
|
if(!usedLoad.contains(name))
|
|
{
|
|
std::cout<<name.toLocal8Bit().data()<<"not used"<<std::endl;
|
|
}
|
|
}
|
|
this->topologyTest();
|
|
fd.close();
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
template<typename T>
|
|
void CIMExporter::idToNumber(QList<T> &s)//把所有元件的标识进行编号
|
|
{
|
|
for(typename QList<T>::iterator ite=s.begin();
|
|
ite!=s.end();
|
|
ite++
|
|
)
|
|
{
|
|
T _t=*ite;
|
|
_t.fromNum=this->numberIt(_t.fromID);
|
|
_t.toNum=this->numberIt(_t.toID);
|
|
*ite=_t;
|
|
}
|
|
}
|
|
|
|
int CIMExporter::numberIt(const QString& id)
|
|
{
|
|
if(this->number.contains(id))
|
|
{
|
|
return this->number.value(id);
|
|
}
|
|
else
|
|
{
|
|
int n=this->number.keys().length()+1;
|
|
this->number[id]=n;
|
|
return n;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
bool CIMExporter::topologyTest()
|
|
{
|
|
//检查一下拓扑关系
|
|
QList<QPair<int,int> > linkage;
|
|
for(QList<LineStru>::iterator ite=this->line.begin();
|
|
ite!=this->line.end();
|
|
ite++)
|
|
{
|
|
linkage.push_back(QPair<int,int>(ite->fromNum,ite->toNum));
|
|
}
|
|
for(QList<SwitchStru>::iterator ite=this->sw.begin();
|
|
ite!=this->sw.end();
|
|
ite++)
|
|
{
|
|
linkage.push_back(QPair<int,int>(ite->fromNum,ite->toNum));
|
|
}
|
|
for(QList<TransformerStru>::iterator ite=this->tf.begin();
|
|
ite!=this->tf.end();
|
|
ite++)
|
|
{
|
|
linkage.push_back(QPair<int,int>(ite->fromNum,ite->toNum));
|
|
}
|
|
|
|
TopologyTest tpTest(this->number.keys().length());
|
|
if(tpTest.start(linkage))
|
|
{
|
|
std::cout<<"topoloty ok!"<<std::endl;
|
|
return true;
|
|
}else
|
|
{
|
|
std::cout<<"not ok topology"<<std::endl;
|
|
return false;
|
|
}
|
|
}
|