Skip to content

Commit

Permalink
Change transformation uses/deps to use QList and equation kind to sim…
Browse files Browse the repository at this point in the history
…ply be a string

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23296 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Nov 10, 2014
1 parent 8afa180 commit 3a65f95
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 75 deletions.
50 changes: 25 additions & 25 deletions OMEdit/OMEditGUI/TransformationalDebugger/TransformationsWidget.cpp
Expand Up @@ -834,6 +834,12 @@ void TransformationsWidget::loadTransformations()
mVariables[iter.key()] = *var;
}
mpTVariablesTreeModel->insertTVariablesItems(mVariables);
for (int i=0; i<eqs.size(); i++) {
QVariantMap veq = eqs[i].toMap();
OMEquation *eq = new OMEquation();
}
parseProfiling(mProfJSONFullFileName);
fetchEquations();
} else {
mpInfoXMLFileHandler = new MyHandler(file,mVariables,mEquations);
mpTVariablesTreeModel->insertTVariablesItems(mVariables);
Expand All @@ -849,19 +855,16 @@ void TransformationsWidget::fetchDefinedInEquations(const OMVariable &variable)
/* Clear the defined in tree. */
clearTreeWidgetItems(mpDefinedInEquationsTreeWidget);
/* add defined in equations */
for (int i = 0; i < equationTypeSize; i++)
for (int i=0; i<variable.definedIn.size(); i++)
{
if (variable.definedIn[i])
{
OMEquation *equation = getOMEquation(mEquations, variable.definedIn[i]);
QStringList values;
values << QString::number(variable.definedIn[i]) << OMEquationTypeToString(equation->kind) << equation->toString();
QTreeWidgetItem *pDefinedInTreeItem = new IntegerTreeWidgetItem(values, mpDefinedInEquationsTreeWidget);
pDefinedInTreeItem->setToolTip(0, values[0]);
pDefinedInTreeItem->setToolTip(1, values[1]);
pDefinedInTreeItem->setToolTip(2, values[2]);
mpDefinedInEquationsTreeWidget->addTopLevelItem(pDefinedInTreeItem);
}
OMEquation *equation = getOMEquation(mEquations, variable.definedIn[i]);
QStringList values;
values << QString::number(variable.definedIn[i]) << equation->section << equation->toString();
QTreeWidgetItem *pDefinedInTreeItem = new IntegerTreeWidgetItem(values, mpDefinedInEquationsTreeWidget);
pDefinedInTreeItem->setToolTip(0, values[0]);
pDefinedInTreeItem->setToolTip(1, values[1]);
pDefinedInTreeItem->setToolTip(2, values[2]);
mpDefinedInEquationsTreeWidget->addTopLevelItem(pDefinedInTreeItem);
}
}

Expand All @@ -870,19 +873,16 @@ void TransformationsWidget::fetchUsedInEquations(const OMVariable &variable)
/* Clear the used in tree. */
clearTreeWidgetItems(mpUsedInEquationsTreeWidget);
/* add used in equations */
for (int i = 0; i < equationTypeSize; i++)
foreach (int index, variable.usedIn)
{
foreach (int index, variable.usedIn[i])
{
OMEquation *equation = getOMEquation(mEquations, index);
QStringList values;
values << QString::number(index) << OMEquationTypeToString(equation->kind) << equation->toString();
QTreeWidgetItem *pUsedInTreeItem = new IntegerTreeWidgetItem(values, mpUsedInEquationsTreeWidget);
pUsedInTreeItem->setToolTip(0, values[0]);
pUsedInTreeItem->setToolTip(1, values[1]);
pUsedInTreeItem->setToolTip(2, values[2]);
mpUsedInEquationsTreeWidget->addTopLevelItem(pUsedInTreeItem);
}
OMEquation *equation = getOMEquation(mEquations, index);
QStringList values;
values << QString::number(index) << equation->section << equation->toString();
QTreeWidgetItem *pUsedInTreeItem = new IntegerTreeWidgetItem(values, mpUsedInEquationsTreeWidget);
pUsedInTreeItem->setToolTip(0, values[0]);
pUsedInTreeItem->setToolTip(1, values[1]);
pUsedInTreeItem->setToolTip(2, values[2]);
mpUsedInEquationsTreeWidget->addTopLevelItem(pUsedInTreeItem);
}
}

Expand Down Expand Up @@ -925,7 +925,7 @@ QTreeWidgetItem* TransformationsWidget::makeEquationTreeWidgetItem(int equationI
}
QStringList values;
values << QString::number(equation->index)
<< OMEquationTypeToString(equation->kind)
<< equation->section
<< equation->toString();
if (equation->profileBlock >= 0) {
values << QString::number(equation->ncall)
Expand Down
52 changes: 16 additions & 36 deletions OMEdit/OMEditGUI/Util/OMDumpXML.cpp
Expand Up @@ -42,12 +42,6 @@
#include "OMDumpXML.h"
#include "diff_match_patch.h"

const char* OMEquationTypeToString(int t)
{
static const char *kindToString[equationTypeSize] = {"start","parameter","initial","regular"};
return kindToString[t];
}

QString OMOperation::toString()
{
return "unknown operation";
Expand Down Expand Up @@ -191,9 +185,6 @@ QString OMInfo::toString() {

OMVariable::OMVariable()
{
for (int i=0; i<equationTypeSize; i++) {
definedIn[i] = 0;
}
}

OMVariable::OMVariable(const OMVariable &var)
Expand All @@ -202,10 +193,8 @@ OMVariable::OMVariable(const OMVariable &var)
comment = var.comment;
info = var.info;
types = var.types;
for (int i = 0; i < equationTypeSize ; i++) {
definedIn[i] = var.definedIn[i];
usedIn[i] = var.usedIn[i];
}
definedIn = var.definedIn;
usedIn = var.usedIn;
foreach (OMOperation *op, var.ops) {
qDebug() << "dynamic_cast op: " << op->toString();
if (dynamic_cast<OMOperationSimplify*>(op))
Expand Down Expand Up @@ -299,7 +288,7 @@ bool MyHandler::startDocument()
equations.clear();
/* use index from 1; add dummy element 0 */
equations.append(new OMEquation());
currentKind = start;
currentSection = "unknown section";
return true;
}

Expand All @@ -320,10 +309,8 @@ bool MyHandler::startElement( const QString & namespaceURI, const QString & loca
if (qName == "variable") {
currentVariable.name = atts.value("name");
currentVariable.comment = atts.value("comment");
memset(currentVariable.definedIn,0,sizeof(currentVariable.definedIn));
for (int i=0; i<equationTypeSize; i++) {
currentVariable.usedIn[i].clear();
}
currentVariable.definedIn.clear();
currentVariable.usedIn.clear();
currentVariable.types.clear();
currentInfo = OMInfo();
} else if (qName == "info") {
Expand All @@ -337,20 +324,17 @@ bool MyHandler::startElement( const QString & namespaceURI, const QString & loca
currentEquation = new OMEquation();
currentEquation->index = atts.value("index").toLong();
currentEquation->parent = atts.value("parent").toLong(); // Returns 0 on failure, which suits us
currentEquation->kind = currentKind;
currentEquation->section = currentSection;
nestedEquations.clear();
currentInfo = OMInfo();
} else if (qName == "eq") {
nestedEquations.append(atts.value("index").toLong());
} else if (qName == "equations" ||
qName == "jacobian-equations") {
currentKind = regular;
} else if (qName == "initial-equations") {
currentKind = initial;
} else if (qName == "parameter-equations") {
currentKind = parameter;
} else if (qName == "start-equations") {
currentKind = start;
qName == "jacobian-equations" ||
qName == "initial-equations" ||
qName == "parameter-equations" ||
qName == "start-equations") {
currentSection = qName;
} else if (qName == "defines") {
currentEquation->defines.append(atts.value("name"));
} else if (qName == "depends") {
Expand Down Expand Up @@ -396,18 +380,14 @@ bool MyHandler::endElement( const QString & namespaceURI, const QString & localN
qDebug() << "Defines " << def << " not found in variables.";
continue;
}
int prev = variables[def].definedIn[currentEquation->kind];
if (prev) {
qDebug() << "failing: multiple define of " << def << ": " << prev << " and " << currentEquation->index << " for kind: " << currentEquation->kind;
return false;
}
variables[def].definedIn[currentEquation->kind] = currentEquation->index;
variables[def].definedIn.append(currentEquation->index);
}
foreach (QString def, currentEquation->depends) {
if (variables.contains(def))
variables[def].usedIn[currentEquation->kind].append(currentEquation->index);
else
if (variables.contains(def)) {
variables[def].usedIn.append(currentEquation->index);
} else {
qDebug() << "Depends " << def << " not found in variables.";
}
}
} else if (equationTags.contains(qName)) {
currentEquation->text = texts;
Expand Down
18 changes: 4 additions & 14 deletions OMEdit/OMEditGUI/Util/OMDumpXML.h
Expand Up @@ -43,16 +43,6 @@
#include <QXmlDefaultHandler>
#include <QHash>

enum OMEquationType {
start = 0,
parameter,
initial,
regular,
equationTypeSize
};

const char* OMEquationTypeToString(int);

class OMOperation {
public:
virtual QString toString();
Expand Down Expand Up @@ -174,16 +164,16 @@ struct OMVariable {
QString comment;
OMInfo info;
QStringList types;
int definedIn[equationTypeSize];
QList<int> usedIn[equationTypeSize];
QList<int> definedIn;
QList<int> usedIn;
QList<OMOperation*> ops;
OMVariable();
OMVariable(const OMVariable& var);
~OMVariable();
};

struct OMEquation {
OMEquationType kind;
QString section;
int index,profileBlock,parent,ncall;
double time,maxTime,fraction;
QStringList text;
Expand All @@ -209,7 +199,7 @@ class MyHandler : private QXmlDefaultHandler {
OMEquation *currentEquation;
QList<int> nestedEquations;
OMInfo currentInfo;
OMEquationType currentKind;
QString currentSection;
QString currentText;
QStringList texts;
QList<OMOperation*> operations;
Expand Down

0 comments on commit 3a65f95

Please sign in to comment.