Moved duplicated code from spicefile.cpp and spicelibcomp.cpp into spicecompat namespace

This commit is contained in:
Vadim Kuznetzov 2016-03-09 11:46:45 +03:00
parent be62437c86
commit e1428544c4
6 changed files with 39 additions and 63 deletions

View File

@ -588,39 +588,14 @@ QString SpiceFile::getSubcktName()
return s;
}
QStringList SpiceFile::getSubcktPorts()
{
QStringList lst;
lst.clear();
QFile sub_file(getSubcircuitFile());
if (sub_file.open(QIODevice::ReadOnly)) {
QStringList lst1 = QString(sub_file.readAll()).split("\n");
foreach (QString str, lst1) {
QRegExp subckt_header("^\\s*\\.(S|s)(U|u)(B|b)(C|c)(K|k)(T|t)\\s.*");
if (subckt_header.exactMatch(str)) {
QRegExp sep("\\s");
QStringList lst2 = str.split(sep,QString::SkipEmptyParts);
lst2.removeFirst();
lst2.removeFirst();
foreach (QString s1, lst2) {
if (!s1.contains('=')) lst.append(s1);
}
break;
}
}
sub_file.close();
}
return lst;
}
QString SpiceFile::spice_netlist(bool)
{
QStringList ports_lst = Props.at(1)->Value.split(",");
for (QStringList::iterator it = ports_lst.begin();it != ports_lst.end();it++) {
if (it->startsWith("_net")) (*it).remove(0,4);
}
QStringList nod_lst = getSubcktPorts();
QStringList nod_lst;
spicecompat::getPins(getSubcircuitFile(),getSubcktName(),nod_lst);
QList<int> seq;
seq.clear();

View File

@ -54,7 +54,6 @@ protected:
QString netlist();
void createSymbol();
QString getSubcktName();
QStringList getSubcktPorts();
QString spice_netlist(bool isXyce);
private slots:

View File

@ -226,3 +226,38 @@ QString spicecompat::convert_relative_filename(QString filename)
if (inf.exists()) return s;
else return filename;
}
int spicecompat::getPins(const QString &file, const QString &compname, QStringList &pin_names)
{
int r = 0;
QString content;
QString LibName = spicecompat::convert_relative_filename(file);
QFile f(LibName);
if (f.open(QIODevice::ReadOnly)) {
QTextStream ts(&f);
content = ts.readAll();
f.close();
} else return 0;
QTextStream stream(&content,QIODevice::ReadOnly);
while (!stream.atEnd()) {
QString lin = stream.readLine();
QRegExp subckt_header("^\\s*\\.(S|s)(U|u)(B|b)(C|c)(K|k)(T|t)\\s.*");
if (subckt_header.exactMatch(lin)) {
QRegExp sep("\\s");
QStringList lst2 = lin.split(sep,QString::SkipEmptyParts);
QString name = lin.section(sep,1,1,QString::SectionSkipEmpty).toLower();
QString refname = compname.toLower();
if (name != refname) continue;
lst2.removeFirst();
lst2.removeFirst();
foreach (QString s1, lst2) {
if (!s1.contains('=')) pin_names.append(s1);
}
r = pin_names.count();
break;
}
}
return r;
}

View File

@ -19,6 +19,7 @@ namespace spicecompat {
void convertNodeNames(QStringList &tokens, QString &sim);
QString normalize_node_name(QString nod);
QString convert_relative_filename(QString filename);
int getPins(const QString &file, const QString &compname, QStringList &pin_names);
enum Simulator {simNgspice = 0, simXyceSer = 1, simXycePar = 2, simSpiceOpus = 3, simQucsator = 4, simNotSpecified=10};
}

View File

@ -102,7 +102,7 @@ void SpiceLibComp::createSymbol()
}
else {
QStringList pins;
No = getPins(pins);
No = spicecompat::getPins(Props.at(0)->Value,Props.at(1)->Value,pins);
Ports.clear();
remakeSymbol(No,pins); // no symbol was found -> create standard symbol
}
@ -212,40 +212,7 @@ QString SpiceLibComp::getSpiceModel()
return s;
}
int SpiceLibComp::getPins(QStringList &pin_names)
{
int r = 0;
QString content;
QString LibName = spicecompat::convert_relative_filename(Props.at(0)->Value);
QFile f(LibName);
if (f.open(QIODevice::ReadOnly)) {
QTextStream ts(&f);
content = ts.readAll();
f.close();
} else return 0;
QTextStream stream(&content,QIODevice::ReadOnly);
while (!stream.atEnd()) {
QString lin = stream.readLine();
QRegExp subckt_header("^\\s*\\.(S|s)(U|u)(B|b)(C|c)(K|k)(T|t)\\s.*");
if (subckt_header.exactMatch(lin)) {
QRegExp sep("\\s");
QStringList lst2 = lin.split(sep,QString::SkipEmptyParts);
QString name = lin.section(sep,1,1,QString::SectionSkipEmpty).toLower();
QString refname = Props.at(1)->Value.toLower();
if (name != refname) continue;
lst2.removeFirst();
lst2.removeFirst();
foreach (QString s1, lst2) {
if (!s1.contains('=')) pin_names.append(s1);
}
r = pin_names.count();
break;
}
}
return r;
}
void SpiceLibComp::getSymbolPatternsList(QStringList &symbols)
{

View File

@ -35,7 +35,6 @@ protected:
void remakeSymbol(int No, QStringList &pin_names);
int loadSymbol(const QString&);
private:
int getPins(QStringList &pin_names);
void getSymbolPatternsList(QStringList &symbols);
};