Skip to content

Commit

Permalink
Refactor/add new annotations to model editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquinffernandez committed Aug 27, 2024
1 parent 36b2c46 commit 4f636ec
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
25 changes: 22 additions & 3 deletions src/gui/modeleditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ ModelEditor::ModelEditor(QWidget *parent, QString name)
_BDFPart(),
_BDFPartitionDepth(),
_BDFMaxStep(),
_random_seed(),
_semiStaticPartitioning(false),
_hl(NULL)
{
Expand Down Expand Up @@ -729,10 +728,29 @@ QString ModelEditor::modelName()
return "";
}

void ModelEditor::searchFixedAnnot(QStringList annotations)
{
for (const auto &annotation : annotations) {
QString annot_value = getAnnotations(annotation);
if (!annot_value.isEmpty()) {
_fixed_annotations.insert(annotation, annot_value);
}
}
}

void ModelEditor::addFixedAnnot()
{
for (auto it = _fixed_annotations.begin(); it != _fixed_annotations.end(); ++it) {
setAnnotations(it.key(), it.value(), true);
}
}

void ModelEditor::writeAnnotations()
{
QString mName = modelName();
_random_seed = randomSeed();
// Search and store fixed user annotations to write them back later.
searchFixedAnnot({"MMO_RandomSeed", "MMO_XOutput", "MMO_CVODEMaxOrder"});

deleteAnnotations();
int tab = _model_editor_tab->currentIndex();
CodeEditor *_textEditor = qobject_cast<CodeEditor *>(_model_editor_tab->widget(tab));
Expand Down Expand Up @@ -768,7 +786,7 @@ void ModelEditor::writeAnnotations()
if (!_BDFPart.isEmpty()) setAnnotations("MMO_BDF_Part", _BDFPart, true);
if (!_BDFPartitionDepth.isEmpty()) setAnnotations("MMO_BDF_PDepth", _BDFPartitionDepth, true);
if (!_BDFMaxStep.isEmpty()) setAnnotations("MMO_BDF_Max_Step", _BDFMaxStep, true);
if (!_random_seed.isEmpty()) setAnnotations("MMO_RandomSeed", _random_seed, true);
addFixedAnnot();
setAnnotations("StartTime", _startTime, true);
setAnnotations("StopTime", _stopTime, true);
setAnnotations("Tolerance", _tolerance, true);
Expand Down Expand Up @@ -827,4 +845,5 @@ void ModelEditor::writeAnnotations()
}
}
_annotations.clear();
_fixed_annotations.clear();
}
8 changes: 6 additions & 2 deletions src/gui/modeleditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ class ModelEditor : public QDialog, public Ui::ModelEditorForm {
inline void setBDFPartitionDepth(QString str) { _BDFPartitionDepth = str; };
inline QString BDFMaxStep() { return getAnnotations("MMO_BDF_Max_Step"); };
inline void setBDFMaxStep(QString str) { _BDFMaxStep = str; };
inline QString randomSeed() { return getAnnotations("MMO_RandomSeed"); };

void keyReleaseEvent(QKeyEvent *event);
void save(void);
Expand Down Expand Up @@ -156,6 +155,11 @@ class ModelEditor : public QDialog, public Ui::ModelEditorForm {
void setAnnotations(QString str, QString value, bool separator);
void save(int tab);
int tokenPosition(QString token);
/// Add any annotation that's not required in the run form here.
/// They will be added to the to the generated annotations without any modifications.
void searchFixedAnnot(QStringList annotations);
void addFixedAnnot();

QStringList _annotations;
QMap<QString, QString> _defaultValues;
QString _startTime;
Expand Down Expand Up @@ -190,8 +194,8 @@ class ModelEditor : public QDialog, public Ui::ModelEditorForm {
QString _BDFPart;
QString _BDFPartitionDepth;
QString _BDFMaxStep;
QString _random_seed;
bool _semiStaticPartitioning;
QMap<QString, QString> _fixed_annotations;
QTabWidget *_model_editor_tab;
QList<ModelInfo> *_models;
Utils *_utils;
Expand Down

0 comments on commit 4f636ec

Please sign in to comment.