Skip to content

Commit

Permalink
[iss-259]
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit a14a244
Author: joaquin.f.fernandez <joaquin.f.fernandez@gmail.com>
Date:   Tue Aug 27 10:14:34 2024 -0300

    Updated vs code config file.

commit 4f636ec
Author: joaquin.f.fernandez <joaquin.f.fernandez@gmail.com>
Date:   Tue Aug 27 10:14:04 2024 -0300

    Refactor/add new annotations to model editor.

commit 36b2c46
Author: joaquin.f.fernandez <joaquin.f.fernandez@gmail.com>
Date:   Tue Aug 27 10:13:37 2024 -0300

    Refactor/improve utils methods.

commit 24dce96
Author: joaquin.f.fernandez <joaquin.f.fernandez@gmail.com>
Date:   Tue Aug 27 10:13:03 2024 -0300

    Added new annotations to highlighter.
  • Loading branch information
joaquinffernandez committed Aug 27, 2024
1 parent 62796da commit bfd0786
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 216 deletions.
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"sonarlint.pathToCompileCommands": "${workspaceFolder}/src/engine/compile_commands.json"
"sonarlint.pathToCompileCommands": "${workspaceFolder}/src/engine/compile_commands.json",
"files.associations": {
"patoh.h": "c",
"scotch.h": "c",
"utils.h": "c"
}
}
2 changes: 2 additions & 0 deletions src/gui/mmohighlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ MmoHighlighter::MmoHighlighter(QTextDocument *parent, h_type file) : QSyntaxHigh
<< "\\bMMO_SZ\\b"
<< "\\bMMO_Event_Id\\b"
<< "\\bMMO_RandomSeed\\b"
<< "\\bMMO_XOutput\\b"
<< "\\bMMO_CVODEMaxOrder\\b"
<< "\\bderivative\\b";

foreach (const QString &pattern, keywordPatterns) {
Expand Down
8 changes: 2 additions & 6 deletions src/gui/mmohighlight.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
******************************************************************************/

#ifndef MMOHIGHLIGHTER_H_
#define MMOHIGHLIGHTER_H_

#include <QSyntaxHighlighter>
#pragma once

#include <QHash>
#include <QSyntaxHighlighter>
#include <QTextCharFormat>

class MmoHighlighter : public QSyntaxHighlighter {
Expand Down Expand Up @@ -50,5 +48,3 @@ class MmoHighlighter : public QSyntaxHighlighter {
QTextCharFormat multiLineCommentFormat;
QTextCharFormat quotationFormat;
};

#endif /* MMOHIGHLIGHTER_H_ */
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
Loading

0 comments on commit bfd0786

Please sign in to comment.