2014-12-26 21:21:58 +08:00
|
|
|
#include "cimexporter.h"
|
2014-12-28 17:49:16 +08:00
|
|
|
#include <iostream>
|
2015-01-20 13:19:28 +08:00
|
|
|
CIMExporter::CIMExporter(const QHash<QString, BasicElementInfo *> &eleHT, const QString &loadDir):loadDir(loadDir),eleHT(eleHT)
|
2014-12-26 21:21:58 +08:00
|
|
|
{
|
|
|
|
|
}
|
2014-12-28 16:40:57 +08:00
|
|
|
|
|
|
|
|
void CIMExporter::add(const QPair<QString,QString>& fromTo,Line* line)
|
|
|
|
|
{
|
2015-01-20 20:59:47 +08:00
|
|
|
LineStru lineStru;
|
2014-12-28 16:40:57 +08:00
|
|
|
lineStru.line=line;
|
|
|
|
|
lineStru.fromID=fromTo.first;
|
|
|
|
|
lineStru.toID=fromTo.second;
|
2015-01-20 21:24:33 +08:00
|
|
|
lineStru.id=line->ac->getID();
|
2015-01-21 22:05:19 +08:00
|
|
|
lineStru.isZeroBranch=std::fabs(line->length)<1e-5;
|
2015-01-20 22:46:26 +08:00
|
|
|
lineStru.dispose=false;
|
2014-12-28 17:16:29 +08:00
|
|
|
this->line.push_back(lineStru);
|
2014-12-28 16:40:57 +08:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
void CIMExporter::add(const QPair<QString,QString>& fromTo,Switch* sw)
|
|
|
|
|
{
|
2015-01-20 20:59:47 +08:00
|
|
|
SwitchStru switchStru;
|
2014-12-28 16:40:57 +08:00
|
|
|
switchStru.sw=sw;
|
|
|
|
|
switchStru.fromID=fromTo.first;
|
|
|
|
|
switchStru.toID=fromTo.second;
|
2015-01-20 21:24:33 +08:00
|
|
|
switchStru.id=sw->id;
|
2015-01-20 22:46:26 +08:00
|
|
|
switchStru.isZeroBranch=true;
|
|
|
|
|
switchStru.dispose=false;
|
2014-12-28 17:16:29 +08:00
|
|
|
this->sw.push_back(switchStru);
|
2014-12-28 16:40:57 +08:00
|
|
|
}
|
|
|
|
|
void CIMExporter::add(const QPair<QString,QString>& fromTo,Transformer* tf)
|
|
|
|
|
{
|
2015-01-20 20:59:47 +08:00
|
|
|
TransformerStru tfStru;
|
2014-12-28 16:40:57 +08:00
|
|
|
tfStru.tf=tf;
|
|
|
|
|
tfStru.fromID=fromTo.first;
|
|
|
|
|
tfStru.toID=fromTo.second;
|
2015-01-20 22:46:26 +08:00
|
|
|
tfStru.isZeroBranch=false;
|
|
|
|
|
tfStru.dispose=false;
|
2015-01-21 14:03:07 +08:00
|
|
|
tfStru.id=tf->getTF()->getID();
|
2014-12-28 17:16:29 +08:00
|
|
|
this->tf.push_back(tfStru);
|
2014-12-28 16:40:57 +08:00
|
|
|
}
|
2014-12-28 16:56:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
void CIMExporter::exportTo(const QString& path)
|
|
|
|
|
{
|
2015-01-20 20:50:38 +08:00
|
|
|
|
|
|
|
|
|
2015-01-20 15:56:30 +08:00
|
|
|
//输出到文件
|
|
|
|
|
QFile fd(path);
|
|
|
|
|
if(fd.open(QFile::WriteOnly))
|
2014-12-28 17:49:16 +08:00
|
|
|
{
|
2015-01-20 22:46:26 +08:00
|
|
|
//消减元件
|
|
|
|
|
QList<BranchStruc*> elements;
|
|
|
|
|
for(int i=0;i<this->line.length();i++)
|
|
|
|
|
{
|
|
|
|
|
elements.push_back( &(this->line[i]) );
|
|
|
|
|
}
|
|
|
|
|
for(int i=0;i<this->sw.length();i++)
|
|
|
|
|
{
|
|
|
|
|
elements.push_back( &(this->sw[i]) );
|
|
|
|
|
}
|
|
|
|
|
for(int i=0;i<this->tf.length();i++)
|
|
|
|
|
{
|
|
|
|
|
elements.push_back( &(this->tf[i]) );
|
|
|
|
|
}
|
|
|
|
|
ElementReduction elementReduction(elements);
|
|
|
|
|
elementReduction.doIt();
|
2015-01-20 15:56:30 +08:00
|
|
|
//先给所有节点都编号
|
|
|
|
|
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");
|
2015-01-20 20:59:47 +08:00
|
|
|
for(QList<LineStru>::iterator ite=this->line.begin();
|
2015-01-20 15:56:30 +08:00
|
|
|
ite!=this->line.end();
|
|
|
|
|
ite++)
|
|
|
|
|
{
|
|
|
|
|
LineStru l=*ite;
|
2015-01-21 14:03:07 +08:00
|
|
|
if(l.dispose)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-01-20 15:56:30 +08:00
|
|
|
writer<<l.fromNum<<"\t";
|
|
|
|
|
writer<<l.toNum<<"\t";
|
|
|
|
|
writer<<"type"<<"\t";
|
2015-01-21 22:05:19 +08:00
|
|
|
// writer<<l.id<<"\t";
|
2015-01-20 15:56:30 +08:00
|
|
|
writer<<l.line->length<<"\r\n";
|
|
|
|
|
}
|
|
|
|
|
//输出刀闸
|
2015-01-20 20:59:47 +08:00
|
|
|
for(QList<SwitchStru>::iterator ite=this->sw.begin();
|
2015-01-20 15:56:30 +08:00
|
|
|
ite!=this->sw.end();
|
|
|
|
|
ite++)
|
|
|
|
|
{
|
2015-01-21 14:03:07 +08:00
|
|
|
if(ite->dispose)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-01-20 15:56:30 +08:00
|
|
|
writer<<ite->fromNum<<"\t";
|
|
|
|
|
writer<<ite->toNum<<"\t";
|
|
|
|
|
writer<<"type"<<"\t";
|
2015-01-21 22:05:19 +08:00
|
|
|
// writer<<ite->id<<"\t";
|
2015-01-20 15:56:30 +08:00
|
|
|
writer<<0<<"\r\n";
|
|
|
|
|
}
|
|
|
|
|
//输出负荷
|
|
|
|
|
RecurseDir recurseDir;
|
|
|
|
|
recurseDir.setDir(this->loadDir);
|
|
|
|
|
QStringList files;
|
|
|
|
|
files=recurseDir.getFiles();
|
|
|
|
|
//只取文件名
|
|
|
|
|
QStringList baseNames;
|
|
|
|
|
foreach(QString file,files)
|
2015-01-20 13:19:28 +08:00
|
|
|
{
|
2015-01-20 15:56:30 +08:00
|
|
|
QFileInfo fileInfo(file);
|
|
|
|
|
baseNames<<fileInfo.baseName();
|
2015-01-20 13:19:28 +08:00
|
|
|
}
|
2015-01-20 15:56:30 +08:00
|
|
|
writer<<QStringLiteral("变压器")<<"\r\n";
|
|
|
|
|
writer<<QStringLiteral("节点号")<<"\t"<<QStringLiteral("节点号")<<"\t"<<QStringLiteral("型号")<<"\t"<<QStringLiteral("容量(MVA)")<<"\r\n";
|
|
|
|
|
QStringList usedLoad;
|
2015-01-20 20:59:47 +08:00
|
|
|
for(QList<TransformerStru>::iterator ite=this->tf.begin();
|
2015-01-20 15:56:30 +08:00
|
|
|
ite!=this->tf.end();
|
|
|
|
|
ite++)
|
2015-01-20 13:19:28 +08:00
|
|
|
{
|
2015-01-21 14:03:07 +08:00
|
|
|
if(ite->dispose)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-01-20 15:56:30 +08:00
|
|
|
PowerTransformer *tf=ite->tf->getTF();
|
|
|
|
|
QString subID=tf->getEquipmentMemberOf_EquipmentContainer();//所属Substation的ID
|
|
|
|
|
Substation *sub=static_cast<Substation *>(this->eleHT[subID]);
|
|
|
|
|
if(!sub)
|
2015-01-20 13:19:28 +08:00
|
|
|
{
|
2015-01-20 15:56:30 +08:00
|
|
|
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";
|
2015-01-21 22:05:19 +08:00
|
|
|
// writer<<ite->id<<"\t";
|
2015-01-20 15:56:30 +08:00
|
|
|
writer<<tf->getMVA()<<"\r\n";
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-01-20 13:19:28 +08:00
|
|
|
}
|
|
|
|
|
|
2015-01-20 15:56:30 +08:00
|
|
|
}
|
|
|
|
|
//列出没有用的负荷文件
|
|
|
|
|
foreach(QString name, baseNames)
|
2015-01-20 13:19:28 +08:00
|
|
|
{
|
2015-01-20 15:56:30 +08:00
|
|
|
if(!usedLoad.contains(name))
|
|
|
|
|
{
|
2015-01-22 11:00:39 +08:00
|
|
|
LoadMatchException except;
|
|
|
|
|
if(!except.contains(name))
|
|
|
|
|
{
|
|
|
|
|
std::cout<<name.toLocal8Bit().data()<<"not used"<<std::endl;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
std::cout<<name.toLocal8Bit().data()<<"not used but excepted."<<std::endl;
|
|
|
|
|
}
|
2015-01-20 15:56:30 +08:00
|
|
|
}
|
2015-01-20 13:19:28 +08:00
|
|
|
}
|
2015-01-20 20:50:38 +08:00
|
|
|
this->topologyTest();
|
2015-01-20 15:56:30 +08:00
|
|
|
fd.close();
|
2015-01-20 13:19:28 +08:00
|
|
|
}
|
2014-12-28 16:56:45 +08:00
|
|
|
|
2014-12-28 17:16:29 +08:00
|
|
|
|
2015-01-20 15:56:30 +08:00
|
|
|
|
|
|
|
|
|
2014-12-28 17:16:29 +08:00
|
|
|
}
|
2015-01-15 17:19:06 +08:00
|
|
|
|
2014-12-28 17:16:29 +08:00
|
|
|
template<typename T>
|
|
|
|
|
void CIMExporter::idToNumber(QList<T> &s)//把所有元件的标识进行编号
|
|
|
|
|
{
|
|
|
|
|
for(typename QList<T>::iterator ite=s.begin();
|
|
|
|
|
ite!=s.end();
|
|
|
|
|
ite++
|
|
|
|
|
)
|
|
|
|
|
{
|
2015-01-21 21:52:18 +08:00
|
|
|
if(ite->dispose)
|
|
|
|
|
{
|
|
|
|
|
std::cout<<ite->id.toStdString()<<" dispose"<<std::endl;
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
}
|
2014-12-28 17:16:29 +08:00
|
|
|
T _t=*ite;
|
|
|
|
|
_t.fromNum=this->numberIt(_t.fromID);
|
|
|
|
|
_t.toNum=this->numberIt(_t.toID);
|
|
|
|
|
*ite=_t;
|
|
|
|
|
}
|
2014-12-28 16:56:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CIMExporter::numberIt(const QString& id)
|
|
|
|
|
{
|
|
|
|
|
if(this->number.contains(id))
|
|
|
|
|
{
|
|
|
|
|
return this->number.value(id);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-01-20 15:56:30 +08:00
|
|
|
int n=this->number.keys().length()+1;
|
2014-12-28 16:56:45 +08:00
|
|
|
this->number[id]=n;
|
2015-01-21 22:05:19 +08:00
|
|
|
// std::cout<<id.toStdString()<<" "<<n<<std::endl;
|
2014-12-28 16:56:45 +08:00
|
|
|
return n;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-20 20:50:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CIMExporter::topologyTest()
|
|
|
|
|
{
|
|
|
|
|
//检查一下拓扑关系
|
|
|
|
|
QList<QPair<int,int> > linkage;
|
2015-01-20 20:59:47 +08:00
|
|
|
for(QList<LineStru>::iterator ite=this->line.begin();
|
2015-01-20 20:50:38 +08:00
|
|
|
ite!=this->line.end();
|
|
|
|
|
ite++)
|
|
|
|
|
{
|
2015-01-21 14:03:07 +08:00
|
|
|
if(ite->dispose)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-01-20 20:50:38 +08:00
|
|
|
linkage.push_back(QPair<int,int>(ite->fromNum,ite->toNum));
|
|
|
|
|
}
|
2015-01-20 20:59:47 +08:00
|
|
|
for(QList<SwitchStru>::iterator ite=this->sw.begin();
|
2015-01-20 20:50:38 +08:00
|
|
|
ite!=this->sw.end();
|
|
|
|
|
ite++)
|
|
|
|
|
{
|
2015-01-21 14:03:07 +08:00
|
|
|
if(ite->dispose)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-01-20 20:50:38 +08:00
|
|
|
linkage.push_back(QPair<int,int>(ite->fromNum,ite->toNum));
|
|
|
|
|
}
|
2015-01-20 20:59:47 +08:00
|
|
|
for(QList<TransformerStru>::iterator ite=this->tf.begin();
|
2015-01-20 20:50:38 +08:00
|
|
|
ite!=this->tf.end();
|
|
|
|
|
ite++)
|
|
|
|
|
{
|
2015-01-21 14:03:07 +08:00
|
|
|
if(ite->dispose)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-01-20 20:50:38 +08:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|