Skip to content

Commit

Permalink
OMEdit: handle equations also for Model_info.json files
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23301 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Nov 10, 2014
1 parent 3a65f95 commit e486297
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 20 deletions.
60 changes: 50 additions & 10 deletions OMEdit/OMEditGUI/TransformationalDebugger/TransformationsWidget.cpp
Expand Up @@ -749,17 +749,21 @@ TransformationsWidget::TransformationsWidget(QString infoXMLFullFileName, MainWi
}
}

static QStringList variantListToStringList(const QVariantList lst)
{
QStringList strs;
foreach(QVariant v, lst){
QString s = v.toString();
strs << v.toString().trimmed();
}
return strs;
}

static OMOperation* variantToOperationPtr(QVariantMap var)
{
QString op = var["op"].toString();
QString display = var["display"].toString();
QStringList dataStrings;
foreach(QVariant v, var["data"].toList()){
QString s = v.toString();
if (s != "") {
dataStrings << v.toString().trimmed();
}
}
QStringList dataStrings = variantListToStringList(var["data"].toList());

if (op == "before-after") {
return new OMOperationBeforeAfter(display != "" ? display : op, dataStrings);
Expand Down Expand Up @@ -834,9 +838,45 @@ void TransformationsWidget::loadTransformations()
mVariables[iter.key()] = *var;
}
mpTVariablesTreeModel->insertTVariablesItems(mVariables);
for (int i=0; i<eqs.size(); i++) {
mEquations << new OMEquation();
}
for (int i=0; i<eqs.size(); i++) {
QVariantMap veq = eqs[i].toMap();
OMEquation *eq = new OMEquation();
OMEquation *eq = mEquations[i];
eq->section = veq["section"].toString();
if (veq["eqIndex"].toInt() != i) {
QMessageBox::critical(this, QString(Helper::applicationName).append(" - ").append(Helper::parsingFailedJson), Helper::parsingFailedJson + QString(": got index ") + veq["eqIndex"].toString() + QString(" expected ") + QString::number(i), Helper::ok);
return;
}
eq->index = i;
eq->profileBlock = -1;
if (veq.find("parent") != veq.end()) {
eq->parent = veq["parent"].toInt();
mEquations[eq->parent]->eqs << eq->index;
} else {
eq->parent = 0;
}
if (veq.find("defines") != veq.end()) {
eq->defines = variantListToStringList(veq["defines"].toList());
foreach (QString v, eq->defines) {
mVariables[v].definedIn << eq->index;
}
}
if (veq.find("uses") != veq.end()) {
eq->depends = variantListToStringList(veq["uses"].toList());
foreach (QString v, eq->depends) {
mVariables[v].usedIn << eq->index;
}
}
eq->text = variantListToStringList(veq["equation"].toList());
eq->tag = veq["tag"].toString();
if (veq.find("display") != veq.end()) {
eq->display = veq["display"].toString();
} else {
eq->display = eq->tag;
}
variantToSource(veq["source"].toMap(), eq->info, eq->types, eq->ops);
}
parseProfiling(mProfJSONFullFileName);
fetchEquations();
Expand Down Expand Up @@ -928,7 +968,7 @@ QTreeWidgetItem* TransformationsWidget::makeEquationTreeWidgetItem(int equationI
<< equation->section
<< equation->toString();
if (equation->profileBlock >= 0) {
values << QString::number(equation->ncall)
values << QString::number(equation->ncall)
<< QString::number(equation->maxTime, 'g', 3)
<< QString::number(equation->time, 'g', 3)
<< QString::number(100 * equation->fraction, 'g', 3) + "%";
Expand Down Expand Up @@ -1081,7 +1121,7 @@ void TransformationsWidget::fetchOperations(OMEquation *equation)
/* Clear the operations tree. */
clearTreeWidgetItems(mpEquationOperationsTreeWidget);
/* add operations */
if (mpInfoXMLFileHandler->hasOperationsEnabled)
if (hasOperationsEnabled)
{
foreach (OMOperation *op, equation->ops)
{
Expand Down
24 changes: 14 additions & 10 deletions OMEdit/OMEditGUI/Util/OMDumpXML.cpp
Expand Up @@ -245,18 +245,22 @@ OMEquation::~OMEquation() {

QString OMEquation::toString()
{
if (text.size() < 1) {
return "(dummy equation)";
} else if (text[0] == "assign") {
return QString("(assignment) %1 = %2").arg(defines[0]).arg(text[1]);
} else if (text[0] == "statement") {
return "(statement) " + text[1];
} else if (text[0] == "nonlinear") {
if (tag == "dummy") {
return "";
} else if (tag == "assign") {
return QString("%1 := %2").arg(defines[0]).arg(text[0]);
} else if (tag == "statement" || tag == "algorithm") {
return text.join("\n");
} else if (tag == "container") {
return QString("%1, size %2").arg(display).arg(eqs.size());
} else if (tag == "nonlinear") {
return QString("nonlinear, size %1").arg(eqs.size());
} else if (text[0] == "linear") {
} else if (tag == "linear") {
return QString("linear, size %1").arg(defines.size());
} else if (tag == "residual") {
return text[0] + " (residual)";
} else {
return "(" + text.join(",") + ")";
return "(" + display + "): " + text.join(",");
}
}

Expand Down Expand Up @@ -391,7 +395,7 @@ bool MyHandler::endElement( const QString & namespaceURI, const QString & localN
}
} else if (equationTags.contains(qName)) {
currentEquation->text = texts;
currentEquation->text.prepend(qName);
currentEquation->tag = qName;
texts.clear();
} else if (qName == "simplify") {
operations.append(new OMOperationSimplify(texts));
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Util/OMDumpXML.h
Expand Up @@ -176,8 +176,10 @@ struct OMEquation {
QString section;
int index,profileBlock,parent,ncall;
double time,maxTime,fraction;
QString tag, display;
QStringList text;
OMInfo info;
QStringList types;
QStringList defines;
QStringList depends;
QList<OMOperation*> ops;
Expand Down

0 comments on commit e486297

Please sign in to comment.