1.加了一个历遍所有子目录的类
2.加了读入所有匹配数据的功能。 Signed-off-by: dmy@lab <dmy@lab.lab>
This commit is contained in:
parent
9259da0e93
commit
214c17dd10
|
|
@ -38,6 +38,7 @@ void CIMExporter::exportTo(const QString& path)
|
||||||
this->idToNumber(this->sw);
|
this->idToNumber(this->sw);
|
||||||
this->idToNumber(this->tf);
|
this->idToNumber(this->tf);
|
||||||
//开始按要求输出
|
//开始按要求输出
|
||||||
|
//先输出线路
|
||||||
for(QList<CIMExporter::LineStru>::iterator ite=this->line.begin();
|
for(QList<CIMExporter::LineStru>::iterator ite=this->line.begin();
|
||||||
ite!=this->line.end();
|
ite!=this->line.end();
|
||||||
ite++)
|
ite++)
|
||||||
|
|
@ -45,7 +46,10 @@ void CIMExporter::exportTo(const QString& path)
|
||||||
LineStru l=*ite;
|
LineStru l=*ite;
|
||||||
std::cout<<l.fromID.toStdString()<<" "<<l.fromNum<<" ";
|
std::cout<<l.fromID.toStdString()<<" "<<l.fromNum<<" ";
|
||||||
std::cout<<l.toID.toStdString()<<" "<<l.toNum<<std::endl;
|
std::cout<<l.toID.toStdString()<<" "<<l.toNum<<std::endl;
|
||||||
|
std::cout<<l.line->r<<","<<l.line->x<<","<<l.line->g1<<","<<l.line->g2<<std::endl;
|
||||||
}
|
}
|
||||||
|
//输出负荷
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ class Branch:public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Branch(const QString& from, const QString& to,QObject* parent=0);
|
Branch(const QString& from, const QString& to,QObject* parent=0);
|
||||||
protected:
|
public:
|
||||||
double r;
|
double r;
|
||||||
double x;
|
double x;
|
||||||
QString from;
|
QString from;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
#include "loadmapping.h"
|
||||||
|
|
||||||
|
|
||||||
|
QHash<QString,QVector<double> > *LoadMapping::ht=NULL;
|
||||||
|
LoadMapping::LoadMapping()
|
||||||
|
{
|
||||||
|
if(!LoadMapping::ht)
|
||||||
|
{
|
||||||
|
LoadMapping::ht=new QHash<QString,QVector<double> >;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LoadMapping::~LoadMapping()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LoadMapping::load(const QString &dir)
|
||||||
|
{
|
||||||
|
if(LoadMapping::ht->keys().length()>0)
|
||||||
|
{
|
||||||
|
return true;//只执行一次
|
||||||
|
}
|
||||||
|
if(!QFileInfo::exists(dir))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
RecurseDir recurseDir;
|
||||||
|
recurseDir.setDir((dir));
|
||||||
|
QStringList filePathList=recurseDir.getFiles();
|
||||||
|
foreach(QString filePath,filePathList)
|
||||||
|
{
|
||||||
|
QFileInfo fileInfo(filePath);
|
||||||
|
if(!fileInfo.exists())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
QString fileName;
|
||||||
|
QString suffix;
|
||||||
|
suffix=fileInfo.suffix();
|
||||||
|
if(suffix.toLower()!="csv")
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
fileName=fileInfo.baseName();
|
||||||
|
QFile file(filePath);
|
||||||
|
QString line;
|
||||||
|
QStringList sep;
|
||||||
|
if(file.open(QFile::ReadOnly))
|
||||||
|
{
|
||||||
|
QTextStream reader(&file);
|
||||||
|
while(!reader.atEnd())
|
||||||
|
{
|
||||||
|
line=reader.readLine().trimmed();
|
||||||
|
sep=line.split(',');
|
||||||
|
if(sep.length()<2)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
QString SFDid;
|
||||||
|
SFDid=sep.at(0);
|
||||||
|
QVector<QString> loads;
|
||||||
|
for(int i=1;i<sep.length();i++)
|
||||||
|
{
|
||||||
|
loads.push_back(sep.at(i));
|
||||||
|
}
|
||||||
|
this->loads[SFDid]=loads;
|
||||||
|
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
#ifndef LOADMAPPING_H
|
||||||
|
#define LOADMAPPING_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QHash>
|
||||||
|
#include <QVector>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include "recursedir.h"
|
||||||
|
//这是一个单例
|
||||||
|
class LoadMapping
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LoadMapping();
|
||||||
|
~LoadMapping();
|
||||||
|
bool load(const QString& dir);
|
||||||
|
private:
|
||||||
|
class CG // 它的唯一工作就是在析构函数中删除CSingleton的实例
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
~CG()
|
||||||
|
{
|
||||||
|
if (LoadMapping::ht)
|
||||||
|
delete LoadMapping::ht;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
static CG Garbo; // 定义一个静态成员,在程序结束时,系统会调用它的析构函数
|
||||||
|
static QHash<QString,QVector<double> > *ht;
|
||||||
|
QHash<QString,QVector<QString> > loads;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LOADMAPPING_H
|
||||||
|
|
@ -3,14 +3,18 @@
|
||||||
#include "regexextract.h"
|
#include "regexextract.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "loadmapping.h"
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QCoreApplication a(argc, argv);
|
QCoreApplication a(argc, argv);
|
||||||
|
LoadMapping lm;
|
||||||
|
lm.load("D:/Project/佛山项目/数据/匹配的数据");
|
||||||
|
|
||||||
// ReadWrite aa;
|
// ReadWrite aa;
|
||||||
// RegexExtract re;
|
// RegexExtract re;
|
||||||
// re.extract("D:/Project/佛山项目/数据/df8003/df8600/exportfiles/exportmodel_pw.xml");
|
// re.extract("D:/Project/佛山项目/数据/df8003/df8600/exportfiles/exportmodel_pw.xml");
|
||||||
// re.exportBlocks("./a");
|
// re.exportBlocks("./a");
|
||||||
// return a.exec();
|
return a.exec();
|
||||||
ElementHashtable eleReader;
|
ElementHashtable eleReader;
|
||||||
eleReader.Parse("D:/Project/佛山项目/数据/df8003/df8600/exportfiles/exportmodel_pw.xml","D:/Project/佛山项目/佛山收资/exportmodel_zwyth20141204/exportmodel_zwyth.xml");
|
eleReader.Parse("D:/Project/佛山项目/数据/df8003/df8600/exportfiles/exportmodel_pw.xml","D:/Project/佛山项目/佛山收资/exportmodel_zwyth20141204/exportmodel_zwyth.xml");
|
||||||
// eleReader.GoPath();
|
// eleReader.GoPath();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
#include "recursedir.h"
|
||||||
|
|
||||||
|
RecurseDir::RecurseDir()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
RecurseDir::~RecurseDir()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList RecurseDir::getFiles()
|
||||||
|
{
|
||||||
|
return this->filePathList;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RecurseDir::lsDir(const QString& dir)
|
||||||
|
{
|
||||||
|
QDir _dir(dir);
|
||||||
|
QStringList nameFilter;
|
||||||
|
nameFilter<<"*";
|
||||||
|
QStringList fileList=_dir.entryList(nameFilter,QDir::NoDotAndDotDot|QDir::AllEntries);
|
||||||
|
for(QStringList::iterator ite=fileList.begin();
|
||||||
|
ite!=fileList.end();
|
||||||
|
ite++)
|
||||||
|
{
|
||||||
|
QString absPath=dir+'/'+*ite;
|
||||||
|
if(QFileInfo(absPath).isDir())
|
||||||
|
{
|
||||||
|
if(!this->lsDir(absPath))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->filePathList.push_back(absPath);//只保存文件
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RecurseDir::setDir(const QString& dir)
|
||||||
|
{
|
||||||
|
return this->lsDir(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
#ifndef RECURSEDIR_H
|
||||||
|
#define RECURSEDIR_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
class RecurseDir
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RecurseDir();
|
||||||
|
~RecurseDir();
|
||||||
|
QStringList getFiles();
|
||||||
|
bool setDir(const QString& dir);
|
||||||
|
private:
|
||||||
|
bool lsDir(const QString& dir);
|
||||||
|
private:
|
||||||
|
QStringList filePathList;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // RECURSEDIR_H
|
||||||
|
|
@ -37,7 +37,9 @@ SOURCES += main.cpp \
|
||||||
element/line.cpp \
|
element/line.cpp \
|
||||||
element/transformer.cpp \
|
element/transformer.cpp \
|
||||||
element/switch.cpp \
|
element/switch.cpp \
|
||||||
task.cpp
|
task.cpp \
|
||||||
|
loadmapping.cpp \
|
||||||
|
recursedir.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
elementhashtable.h \
|
elementhashtable.h \
|
||||||
|
|
@ -60,7 +62,9 @@ HEADERS += \
|
||||||
element/line.h \
|
element/line.h \
|
||||||
element/transformer.h \
|
element/transformer.h \
|
||||||
element/switch.h \
|
element/switch.h \
|
||||||
task.h
|
task.h \
|
||||||
|
loadmapping.h \
|
||||||
|
recursedir.h
|
||||||
|
|
||||||
#release{
|
#release{
|
||||||
DEFINES += QT_NO_DEBUG_OUTPUT
|
DEFINES += QT_NO_DEBUG_OUTPUT
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue