git-svn-id: svn://db.shs.com.ru/libs@105 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2016-07-24 14:03:59 +00:00
parent 1f71f140eb
commit 9fc412f646
9 changed files with 145 additions and 50 deletions

View File

@@ -55,7 +55,7 @@ private:
static const char app_config[], pult_config[]; static const char app_config[], pult_config[];
PIConnection connection; PIConnection connection;
PIMap<int, PIMap<int, KSection> > k_sections; // [enum KSection][index] = CDUtils::KSection
}; };

View File

@@ -1,11 +1,15 @@
#include "cdutils_k.h" #include "cdutils_k.h"
#include "cdutils_core.h" #include "cdutils_core.h"
#include "piconfig.h"
#include "pifile.h"
using namespace CDUtils; using namespace CDUtils;
KInterface::KInterface() { KInterface::KInterface() {
core = Core::instance(); core = Core::instance();
k_file = PIStringAscii("k.dat");
k_file_size = 0;
CONNECTU(core, K_Sended, this, sended); CONNECTU(core, K_Sended, this, sended);
CONNECTU(core, K_Received, this, received); CONNECTU(core, K_Received, this, received);
} }
@@ -41,6 +45,11 @@ const KSection & KInterface::root() const {
} }
int KInterface::count(bool recursive) const {
return core->k_.count(recursive);
}
void KInterface::send() { void KInterface::send() {
core->K_Send(); core->K_Send();
} }
@@ -50,6 +59,15 @@ void KInterface::request() {
} }
bool KInterface::configure(const PIString & config, const PIString & sect) {
PIConfig conf(config, PIIODevice::ReadOnly);
PIConfig::Entry & e(conf.getValue(sect));
bool ret = false;
k_file = e.getValue("file", "k.dat", &ret);
return ret;
}
void KInterface::write(PIIODevice * d) { void KInterface::write(PIIODevice * d) {
core->k_write(d); core->k_write(d);
} }
@@ -68,3 +86,20 @@ void KInterface::parse(PIIODevice * d) {
void KInterface::update(PIIODevice * d) { void KInterface::update(PIIODevice * d) {
core->k_update(d); core->k_update(d);
} }
void KInterface::readFile() {
if (k_file.isEmpty()) return;
PIFile f(k_file, PIIODevice::ReadOnly);
read(&f);
k_file_size = f.size();
}
void KInterface::writeFile() {
if (k_file.isEmpty()) return;
PIFile f(k_file, PIIODevice::ReadWrite);
f.clear();
write(&f);
k_file_size = f.size();
}

View File

@@ -23,16 +23,27 @@ public:
const KSection section(int v) const; const KSection section(int v) const;
const KSection & root() const; const KSection & root() const;
int count(bool recursive = true) const;
const PIString file() const {return k_file;}
int fileSize() const {return k_file_size;}
EVENT(sended) EVENT(sended)
EVENT(received) EVENT(received)
EVENT_HANDLER(void, send); EVENT_HANDLER(void, send);
EVENT_HANDLER(void, request); EVENT_HANDLER(void, request);
bool configure(const PIString & config, const PIString & sect = PIStringAscii("k"));
void write(PIIODevice * d); void write(PIIODevice * d);
void read(PIIODevice * d); void read(PIIODevice * d);
void parse(PIIODevice * d); void parse(PIIODevice * d);
void update(PIIODevice * d); void update(PIIODevice * d);
void readFile();
void writeFile();
private: private:
Core * core; Core * core;
PIString k_file;
int k_file_size;
}; };

View File

@@ -18,17 +18,21 @@ enum Phase {
}; };
void removeComment(PIString & line, PIString * comment = 0) { void removeComment(PIString & line, PIString * type, PIString * comment) {
int ci = line.find("//"); int ci = line.find("//");
if (ci >= 0) { if (ci >= 0) {
if (comment) *comment = line.right(line.size_s() - ci - 2).trim(); if (comment) *comment = line.right(line.size_s() - ci - 2).trim();
line.cutRight(line.size_s() - ci).trim(); line.cutRight(line.size_s() - ci).trim();
if (type && comment && !line.isEmpty()) {
*type = comment->takeLeft(1);
comment->trim();
}
} }
} }
void parseEnumLine(PIString & line, int * value, PIString * comment = 0) { void parseEnumLine(PIString & line, int * value, PIString * type, PIString * comment) {
removeComment(line, comment); removeComment(line, type, comment);
int ci = line.find("="); int ci = line.find("=");
if (ci >= 0) { if (ci >= 0) {
if (value) *value = line.right(line.size_s() - ci - 1).trim().toInt(); if (value) *value = line.right(line.size_s() - ci - 1).trim().toInt();
@@ -54,15 +58,19 @@ void parseInsert(PIString line, PIString & alias, PIStringList & out) {
} }
PIVector<int> enumValues(const PIString & e, const PIMap<PIString, KSection> & sections) { PIVector<int> enumValues(const PIString & e, const PIMap<PIString, KSection> & sections, PIStringList & enames) {
PIVector<int> ret; PIVector<int> ret;
enames.clear();
if (sections.contains(e)) { if (sections.contains(e)) {
ret = sections[e].indexes(); ret = sections[e].indexes();
enames = sections[e].index_names();
} else { } else {
int v = e.toInt(); int v = e.toInt();
if (v < 2) return ret; if (v < 2) return ret;
for (int i = 0; i < v; ++i) for (int i = 0; i < v; ++i) {
ret << i; ret << i;
enames << PIString::fromNumber(i);
}
} }
return ret; return ret;
} }
@@ -75,9 +83,13 @@ KSection KParser::parse(PIIODevice * d) {
KType ck; KType ck;
PIMap<PIString, KSection> sections; PIMap<PIString, KSection> sections;
PIMap<PIString, int> enum_values, cevalues; PIMap<PIString, int> enum_values, cevalues;
PIString content, line, alias, comment; PIString content, line, alias, type, comment;
PIStringList iarr; PIStringList iarr;
if (PIStringAscii(d->className()) == PIStringAscii("PIFile")) content = ((PIFile*)d)->readAll(); if (PIStringAscii(d->className()) == PIStringAscii("PIFile")) {
PIByteArray c = ((PIFile*)d)->readAll();
c << uchar(0);
content = PIString::fromUTF8((const char *)c.data());
}
if (PIStringAscii(d->className()) == PIStringAscii("PIIOString")) content = *(((PIIOString*)d)->string()); if (PIStringAscii(d->className()) == PIStringAscii("PIIOString")) content = *(((PIIOString*)d)->string());
PIIOString ios(&content); PIIOString ios(&content);
//int phase = 0; //int phase = 0;
@@ -85,14 +97,15 @@ KSection KParser::parse(PIIODevice * d) {
while ((cind = content.find("enum", cind)) >= 0) { while ((cind = content.find("enum", cind)) >= 0) {
ios.seek(cind); ios.seek(cind);
line = ios.readLine().trim(); line = ios.readLine().trim();
type.clear();
comment.clear(); comment.clear();
removeComment(line, &comment); removeComment(line, &type, &comment);
if (line.find("{") < 0) { if (line.find("{") < 0) {
cind += 4; cind += 4;
continue; continue;
} }
line.cutLeft(line.find("enum") + 4).trim(); line.cutLeft(line.find("enum") + 4).trim();
line.cutRight(line.size_s() - line.find("{")).trim(); line.cutRight(line.size_s() - line.find("{")).trim();
if (line.isEmpty()) { if (line.isEmpty()) {
cind += 4; cind += 4;
continue; continue;
@@ -105,7 +118,7 @@ KSection KParser::parse(PIIODevice * d) {
while (!ios.isEnd()) { while (!ios.isEnd()) {
line = ios.readLine().trim(); line = ios.readLine().trim();
comment.clear(); comment.clear();
removeComment(line, &comment); removeComment(line, &type, &comment);
if (line.find("}") >= 0) break; if (line.find("}") >= 0) break;
if (line.isEmpty()) { if (line.isEmpty()) {
if (comment.find("=") >= 0) { if (comment.find("=") >= 0) {
@@ -124,12 +137,15 @@ KSection KParser::parse(PIIODevice * d) {
KSection is = sections.value(iarr.take_front()), ts; KSection is = sections.value(iarr.take_front()), ts;
int ibpos = is.name.size_s(); int ibpos = is.name.size_s();
piForeachRC (PIString & a, iarr) { piForeachRC (PIString & a, iarr) {
PIVector<int> evals = enumValues(a, sections); PIStringList enames;
PIVector<int> evals = enumValues(a, sections, enames);
//piCout << a << evals; //piCout << a << evals;
piForeachC (int e, evals) for (int i = 0; i < evals.size_s(); ++i) {
ts.section(e) = is; ts.section(evals[i]) = is;
ts.section(evals[i]).index_name = enames[i];
}
ts.name = is.name; ts.name = is.name;
ts.name.insert(ibpos, PIString("[") << evals.size_s() << "]"); ts.name.insert(ibpos, PIString("[") << a << "]");
is = ts; is = ts;
ts = KSection(); ts = KSection();
} }
@@ -137,9 +153,9 @@ KSection KParser::parse(PIIODevice * d) {
} }
} }
} else { } else {
parseEnumLine(line, &cev, &comment); parseEnumLine(line, &cev, &type, &comment);
//piCout << line << "=" << cev << "//" << comment; piCout << line << "=" << cev << "//" << type << comment;
ck = KType(cev, line, "", "", comment); ck = KType(cev, line, type, "", "", comment);
cs[cev] = ck; cs[cev] = ck;
cevalues[line] = cev; cevalues[line] = cev;
++cev; ++cev;

View File

@@ -12,9 +12,10 @@ KType::KType() {
} }
KType::KType(int i, const PIString & n, const PIString & v, const PIString & f, const PIString & c) { KType::KType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c) {
index_ = i; index_ = i;
name_ = n; name_ = n;
type_ = t;
value_s = v; value_s = v;
formula_ = f; formula_ = f;
comment_ = c; comment_ = c;
@@ -24,6 +25,26 @@ KType::KType(int i, const PIString & n, const PIString & v, const PIString & f,
} }
int KSection::count(bool recursive) const {
int ret = k.size_s();
if (recursive) {
PIMap<int, KSection>::const_iterator i;
for (i = s.begin(); i != s.end(); ++i)
ret += i->second.count(recursive);
}
return ret;
}
PIStringList KSection::index_names() const {
PIStringList ret;
PIMap<int, KType>::iterator i;
for (i = k.begin(); i != k.end(); ++i)
ret << i.value().name();
return ret;
}
void KSection::write(PIIODevice * d, const PIString & prefix) { void KSection::write(PIIODevice * d, const PIString & prefix) {
if (!d) return; if (!d) return;
if (k.isEmpty() && s.isEmpty()) return; if (k.isEmpty() && s.isEmpty()) return;
@@ -32,14 +53,14 @@ void KSection::write(PIIODevice * d, const PIString & prefix) {
if (prefix.isEmpty()) l = "[k]"; if (prefix.isEmpty()) l = "[k]";
else l = "[" + prefix + ".k]"; else l = "[" + prefix + ".k]";
l += "\n"; l += "\n";
d->write(l.toByteArray()); d->write(l.toUTF8());
PIMap<int, KType>::iterator i; PIMap<int, KType>::iterator i;
for (i = k.begin(); i != k.end(); ++i) { for (i = k.begin(); i != k.end(); ++i) {
KType & ck(i.value()); KType & ck(i.value());
l.clear(); l.clear();
l << ck.index() << ".f = " << ck.formula() << " #s " << ck.comment() << "\n"; l << ck.index() << ".f = " << ck.formula() << " #s " << ck.comment() << "\n";
l << ck.index() << ".v = " << ck.value() << " #s " << ck.name() << "\n"; l << ck.index() << ".v = " << ck.value() << " #s " << ck.type() << " " << ck.name() << "\n";
d->write(l.toByteArray()); d->write(l.toUTF8());
} }
} }
if (!s.isEmpty()) { if (!s.isEmpty()) {
@@ -52,7 +73,7 @@ void KSection::write(PIIODevice * d, const PIString & prefix) {
} }
if (prefix.isEmpty()) { if (prefix.isEmpty()) {
l = "[]\n"; l = "[]\n";
d->write(l.toByteArray()); d->write(l.toUTF8());
} }
} }
@@ -65,7 +86,9 @@ void KSection::read(const void * ep) {
for (int i = 0; i < kl.childCount(); ++i) { for (int i = 0; i < kl.childCount(); ++i) {
const PIConfig::Entry * ke(kl.child(i)); const PIConfig::Entry * ke(kl.child(i));
int kid = ke->name().toInt(); int kid = ke->name().toInt();
k[kid] = KType(kid, ke->getValue("v").comment(), ke->getValue("v").value(), ke->getValue("f").value(), ke->getValue("f").comment()); PIString n = ke->getValue("v").comment();
PIString t = n.takeLeft(1);
k[kid] = KType(kid, n.trim(), t, ke->getValue("v").value(), ke->getValue("f").value(), ke->getValue("f").comment());
} }
PIConfig::Entry & sl = e.getValue("s"); PIConfig::Entry & sl = e.getValue("s");
for (int i = 0; i < sl.childCount(); ++i) { for (int i = 0; i < sl.childCount(); ++i) {

View File

@@ -16,9 +16,10 @@ class KType {
friend class ::CD_Pult; friend class ::CD_Pult;
public: public:
KType(); KType();
KType(int i, const PIString & n, const PIString & v, const PIString & f, const PIString & c); KType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c);
int index() const {return index_;} int index() const {return index_;}
PIString name() const {return name_;} PIString name() const {return name_;}
PIString type() const {return type_;}
PIString value() const {return value_s;} PIString value() const {return value_s;}
PIString formula() const {return formula_;} PIString formula() const {return formula_;}
PIString comment() const {return comment_;} PIString comment() const {return comment_;}
@@ -31,7 +32,7 @@ public:
private: private:
int index_; int index_;
PIString name_; PIString name_, type_;
PIString value_s, formula_, comment_; PIString value_s, formula_, comment_;
double value_d; double value_d;
int value_i; int value_i;
@@ -54,9 +55,12 @@ public:
const KSection section(int v) const {return s[v];} const KSection section(int v) const {return s[v];}
bool isEmpty() const {return k.isEmpty() && s.isEmpty();} bool isEmpty() const {return k.isEmpty() && s.isEmpty();}
int count(bool recursive = true) const;
PIVector<int> indexes() const {return k.keys();} PIVector<int> indexes() const {return k.keys();}
PIStringList index_names() const;
PIString name; PIString name;
PIString index_name;
private: private:
KSection(PIMap<int, KType> k_, PIMap<int, KSection> s_) { KSection(PIMap<int, KType> k_, PIMap<int, KSection> s_) {
@@ -68,7 +72,7 @@ private:
void update(KSection & v, bool keep_names); void update(KSection & v, bool keep_names);
bool isSameStructure(KSection & v); bool isSameStructure(KSection & v);
PIMap<int, KType> k; mutable PIMap<int, KType> k;
PIMap<int, KSection> s; PIMap<int, KSection> s;
}; };

View File

@@ -58,6 +58,8 @@ config(piqt(config_), QIODevice::ReadWrite) {
connect(ui->checkKHideExpressions, SIGNAL(toggled(bool)), this, SLOT(filterTree())); connect(ui->checkKHideExpressions, SIGNAL(toggled(bool)), this, SLOT(filterTree()));
connect(ui->lineKSearch, SIGNAL(textChanged(QString)), this, SLOT(filterTree())); connect(ui->lineKSearch, SIGNAL(textChanged(QString)), this, SLOT(filterTree()));
session.load(); session.load();
K.configure(config_);
K.readFile();
updateKDesc(); updateKDesc();
updateCDesc(); updateCDesc();
timer_diag.start(40); timer_diag.start(40);
@@ -70,14 +72,14 @@ CD_Pult::~CD_Pult() {
void CD_Pult::loading(QPIConfig & conf) { void CD_Pult::loading(QPIConfig & conf) {
kdesc_file = conf.getValue("kdesc_file").stringValue(); kdesc_file = Q2PIString(conf.getValue("kdesc_file").stringValue());
cdesc_file = conf.getValue("cdesc_file").stringValue(); cdesc_file = Q2PIString(conf.getValue("cdesc_file").stringValue());
} }
void CD_Pult::saving(QPIConfig & conf) { void CD_Pult::saving(QPIConfig & conf) {
conf.setValue("kdesc_file", kdesc_file); conf.setValue("kdesc_file", PI2QString(kdesc_file));
conf.setValue("cdesc_file", cdesc_file); conf.setValue("cdesc_file", PI2QString(cdesc_file));
} }
@@ -206,15 +208,19 @@ void CD_Pult::makeTreeSection(KSection & ks, QTreeWidgetItem * pi) {
const KType & ck(ki.value()); const KType & ck(ki.value());
ti->setText(0, QString::number(ck.index())); ti->setText(0, QString::number(ck.index()));
ti->setText(1, PI2QString(ck.name())); ti->setText(1, PI2QString(ck.name()));
ti->setText(2, PI2QString(ck.formula())); ti->setText(2, typeName(PI2QString(ck.type())));
ti->setText(4, PI2QString(ck.comment())); ti->setText(3, PI2QString(ck.formula()));
ti->setText(5, PI2QString(ck.comment()));
} }
PIMap<int, KSection>::iterator si; PIMap<int, KSection>::iterator si;
for (si = ks.s.begin(); si != ks.s.end(); ++si) { for (si = ks.s.begin(); si != ks.s.end(); ++si) {
QTreeWidgetItem * ti = new QTreeWidgetItem(pi); QTreeWidgetItem * ti = new QTreeWidgetItem(pi);
const KSection & cs(si.value()); const KSection & cs(si.value());
ti->setText(0, QString("[%1]").arg(si.key())); QString sn("[%1]");
ti->setText(1, PI2QString(cs.name)); if (cs.index_name.isEmpty()) sn = sn.arg(si.key());
else sn = sn.arg(PI2QString(cs.index_name));
ti->setText(0, sn);
ti->setText(2, PI2QString(cs.name));
makeTreeSection(const_cast<KSection&>(cs), ti); makeTreeSection(const_cast<KSection&>(cs), ti);
} }
} }
@@ -273,32 +279,32 @@ void CD_Pult::on_buttonHideAll_clicked() {
void CD_Pult::on_buttonRead_clicked() { void CD_Pult::on_buttonRead_clicked() {
//coeffs.readCoeffs(); K.readFile();
//addToList(trUtf8("Read K file \"%1\": %2 coeffs, %3 bytes").arg(PI2QString(coeffs.fileName())).arg(K.size_s()).arg(coeffs.k_content.size_s()), Qt::darkMagenta); addToList(trUtf8("Readed K file \"%1\": %2 coeffs, %3 bytes").arg(PI2QString(K.file())).arg(K.count()).arg(K.fileSize()), Qt::darkMagenta);
updateTree(); updateTree();
} }
void CD_Pult::on_buttonWrite_clicked() { void CD_Pult::on_buttonWrite_clicked() {
//coeffs.writeCoeffs(); K.writeFile();
//addToList(trUtf8("Write K file \"%1\": %2 coeffs, %3 bytes").arg(PI2QString(coeffs.fileName())).arg(K.size_s()).arg(coeffs.k_content.size_s()), Qt::darkMagenta); addToList(trUtf8("Written K file \"%1\": %2 coeffs, %3 bytes").arg(PI2QString(K.file())).arg(K.count()).arg(K.fileSize()), Qt::darkMagenta);
} }
void CD_Pult::on_buttonSetKDesc_clicked() { void CD_Pult::on_buttonSetKDesc_clicked() {
QString ret = QFileDialog::getOpenFileName(this, trUtf8("Select *.h file with K description"), kdesc_file, "C/C++ header files(*.h *.hpp);;All files(*)"); QString ret = QFileDialog::getOpenFileName(this, trUtf8("Select *.h file with K description"), PI2QString(kdesc_file), "C/C++ header files(*.h *.hpp);;All files(*)");
if (ret.isEmpty()) return; if (ret.isEmpty()) return;
kdesc_file = QDir::current().relativeFilePath(ret); kdesc_file = Q2PIString(QDir::current().relativeFilePath(ret));
PIFile f(Q2PIString(kdesc_file), PIIODevice::ReadOnly); PIFile f(kdesc_file, PIIODevice::ReadOnly);
K.update(&f); K.update(&f);
updateKDesc(true); updateKDesc(true);
} }
void CD_Pult::on_buttonSetCDesc_clicked() { void CD_Pult::on_buttonSetCDesc_clicked() {
QString ret = QFileDialog::getOpenFileName(this, trUtf8("Select *.h file with C description"), cdesc_file, "C/C++ header files(*.h *.hpp);;All files(*)"); QString ret = QFileDialog::getOpenFileName(this, trUtf8("Select *.h file with C description"), PI2QString(cdesc_file), "C/C++ header files(*.h *.hpp);;All files(*)");
if (ret.isEmpty()) return; if (ret.isEmpty()) return;
cdesc_file = QDir::current().relativeFilePath(ret); cdesc_file = Q2PIString(QDir::current().relativeFilePath(ret));
updateCDesc(); updateCDesc();
} }

View File

@@ -60,7 +60,7 @@ private:
Ui::CD_Pult * ui; Ui::CD_Pult * ui;
PIString config_, name_x, name_c; PIString config_, name_x, name_c;
QString kdesc_file, cdesc_file, xdesc_file; PIString kdesc_file, cdesc_file, xdesc_file;
QMenu log_menu; QMenu log_menu;
QTime tm, ctm; QTime tm, ctm;
QTimer timer_diag; QTimer timer_diag;

View File

@@ -321,6 +321,11 @@
<string>Name</string> <string>Name</string>
</property> </property>
</column> </column>
<column>
<property name="text">
<string>Type</string>
</property>
</column>
<column> <column>
<property name="text"> <property name="text">
<string>Expression</string> <string>Expression</string>
@@ -331,11 +336,6 @@
<string>Calculated</string> <string>Calculated</string>
</property> </property>
</column> </column>
<column>
<property name="text">
<string>Type</string>
</property>
</column>
<column> <column>
<property name="text"> <property name="text">
<string>Comment</string> <string>Comment</string>