Skip to content

Commit

Permalink
fixes after more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
adrpo committed May 8, 2024
1 parent b6222af commit ec35509
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 31 deletions.
3 changes: 2 additions & 1 deletion OMEdit/OMEditLIB/CRML/CRMLTranslateAsDialog.cpp
Expand Up @@ -61,10 +61,11 @@ CRMLTranslateAsDialog::CRMLTranslateAsDialog(QWidget *pParent)
{
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(QString("%1 - %2").arg(Helper::applicationName).arg(Helper::translateAsCRML));
setMinimumWidth(400);
setMinimumWidth(1000);
// Create the output directory label
mpOutputDirectoryLabel = new Label(tr("Select the output directory:"));
mpOutputDirectoryTextBox = new QLineEdit;
mpOutputDirectoryTextBox->setText(StringHandler::getLastOpenDirectory());
mpOutputDirectoryBrowseButton = new QPushButton(Helper::browse);
mpOutputDirectoryBrowseButton->setAutoDefault(false);
connect(mpOutputDirectoryBrowseButton, SIGNAL(clicked()), SLOT(browseOutputDirectory()));
Expand Down
4 changes: 4 additions & 0 deletions OMEdit/OMEditLIB/CRML/CRMLTranslateAsDialog.h
Expand Up @@ -51,6 +51,7 @@
#include "Modeling/ModelicaClassDialog.h"

class Label;
class LibraryTreeItem;

class CRMLTranslateAsDialog : public QDialog
{
Expand All @@ -59,6 +60,8 @@ class CRMLTranslateAsDialog : public QDialog
CRMLTranslateAsDialog(QWidget *pParent = 0);
QLineEdit* getParentClassTextBox() {return mpParentClassTextBox;}
QLineEdit* getOutputDirectoryTextBox() {return mpOutputDirectoryTextBox;}
void setLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem) {mpLibraryTreeItem = pLibraryTreeItem;};
LibraryTreeItem *getLibraryTreeItem() {return mpLibraryTreeItem;};
private:
Label *mpOutputDirectoryLabel;
QLineEdit *mpOutputDirectoryTextBox;
Expand All @@ -69,6 +72,7 @@ class CRMLTranslateAsDialog : public QDialog
QPushButton *mpOkButton;
QPushButton *mpCancelButton;
QDialogButtonBox *mpButtonBox;
LibraryTreeItem *mpLibraryTreeItem;
private slots:
void browseOutputDirectory();
void browseParentClass();
Expand Down
78 changes: 61 additions & 17 deletions OMEdit/OMEditLIB/CRML/CRMLTranslatorOutputWidget.cpp
Expand Up @@ -61,12 +61,14 @@ CRMLTranslatorOutputWidget::CRMLTranslatorOutputWidget(CRMLTranslatorOptions sim
{
// progress label
mpProgressLabel = new Label;
mpProgressLabel->setWordWrap(true);
mpProgressLabel->setElideMode(Qt::ElideMiddle);
mpCancelButton = new QPushButton(tr("Cancel"));
mpCancelButton->setEnabled(false);
connect(mpCancelButton, SIGNAL(clicked()), SLOT(cancelCompilation()));
mpProgressBar = new QProgressBar;
mpProgressBar->setAlignment(Qt::AlignHCenter);

// Generated Files tab widget
mpGeneratedFilesTabWidget = new QTabWidget;
mpGeneratedFilesTabWidget->setDocumentMode(true);
Expand All @@ -81,9 +83,9 @@ CRMLTranslatorOutputWidget::CRMLTranslatorOutputWidget(CRMLTranslatorOptions sim
QGridLayout *pMainLayout = new QGridLayout;
pMainLayout->setContentsMargins(5, 5, 5, 5);
pMainLayout->addWidget(mpProgressLabel, 0, 0);
pMainLayout->addWidget(mpProgressBar, 1, 1);
pMainLayout->addWidget(mpCancelButton, 1, 2);
pMainLayout->addWidget(mpGeneratedFilesTabWidget, 2, 0, 1, 5);
pMainLayout->addWidget(mpProgressBar, 2, 0);
pMainLayout->addWidget(mpCancelButton, 2, 1);
pMainLayout->addWidget(mpGeneratedFilesTabWidget, 3, 0, 1, 5);
setLayout(pMainLayout);
mpCompilationProcess = 0;
setCompilationProcessKilled(false);
Expand Down Expand Up @@ -212,7 +214,7 @@ void loadModelicaLibs(LibraryWidget *pLibraryWidget) {
void CRMLTranslatorOutputWidget::compilationProcessFinishedHelper(int exitCode, QProcess::ExitStatus exitStatus)
{
QString progressStr;
mpProgressBar->setRange(0, 1);
mpProgressBar->setRange(0, 2);
mpCancelButton->setEnabled(false);
if (exitStatus == QProcess::NormalExit && exitCode == 0) {
LibraryWidget *pLibraryWidget = MainWindow::instance()->getLibraryWidget();
Expand All @@ -232,28 +234,33 @@ void CRMLTranslatorOutputWidget::compilationProcessFinishedHelper(int exitCode,
MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, GUIMessages::getMessage(GUIMessages::UNABLE_TO_OPEN_FILE).arg(file),
Helper::scriptingKind, Helper::errorLevel));
}
mpProgressBar->setValue(2);
} else if (mCRMLTranslatorOptions.getMode().compare("translate") == 0) {
progressStr = tr("Translation of CRML file %1 finished.").arg(mCRMLTranslatorOptions.getCRMLFile());
progressStr = tr("Translation of CRML file %1 finished. Now loading specified CRML Modelica libraries...").arg(mCRMLTranslatorOptions.getCRMLFile());
mpProgressLabel->setText(progressStr);
updateMessageTab(progressStr);

QFileInfo fi = QFileInfo(mCRMLTranslatorOptions.getCRMLFile());

loadModelicaLibs(pLibraryWidget);

QString fileName = fi.absoluteDir().absolutePath() + QDir::separator() + "generated" + QDir::separator() + fi.fileName();
fileName = fileName.remove(fileName.lastIndexOf(".crml"), 5);
fileName += ".mo";
QString fileName = fi.absoluteDir().absolutePath() + QDir::separator() + "generated" +
QDir::separator() + fi.baseName() + QDir::separator() + fi.baseName() + ".mo";
fileName = fileName.replace("\\", "/");
pLibraryWidget->openFile(fileName, Helper::utf8, false, true);
// now open it if we can find it in the tree!
LibraryTreeItem *pMOLibraryTreeItem = pLibraryWidget->getLibraryTreeModel()->getLibraryTreeItemFromFile(fileName, 1);
if (pMOLibraryTreeItem) {
pLibraryWidget->getLibraryTreeModel()->showModelWidget(pMOLibraryTreeItem);
}
mpProgressBar->setValue(2);
} else if (mCRMLTranslatorOptions.getMode().compare("translateAs") == 0) {
progressStr = tr("Translation of CRML file %1 with output directory %2 and within %3 finished.").
progressStr = tr("Translation of CRML file [%1] with output directory [%2] and within [%3] finished. Now loading specified CRML Modelica libraries...").
arg(mCRMLTranslatorOptions.getCRMLFile(),
mCRMLTranslatorOptions.getOutputDirectory(),
mCRMLTranslatorOptions.getModelicaWithin());
mpProgressLabel->setText(progressStr);
updateMessageTab(progressStr);

loadModelicaLibs(pLibraryWidget);

Expand All @@ -268,6 +275,7 @@ void CRMLTranslatorOutputWidget::compilationProcessFinishedHelper(int exitCode,
if (pMOLibraryTreeItem) {
pLibraryWidget->getLibraryTreeModel()->showModelWidget(pMOLibraryTreeItem);
}
mpProgressBar->setValue(2);
} else {
// TODO fixme, error!
}
Expand Down Expand Up @@ -303,8 +311,20 @@ void CRMLTranslatorOutputWidget::cancelCompilation()
setCompilationProcessKilled(true);
mpCompilationProcess->kill();
mIsCompilationProcessRunning = false;
progressStr = tr("Testsuite run in directory %1 is cancelled.").arg(mCRMLTranslatorOptions.getRepositoryDirectory());
mpProgressBar->setRange(0, 1);
if (mCRMLTranslatorOptions.getMode().compare("testsuite") == 0) {
progressStr = tr("Testsuite run in directory %1 failed.").arg(mCRMLTranslatorOptions.getRepositoryDirectory());
} else if (mCRMLTranslatorOptions.getMode().compare("translate") == 0) {
progressStr = tr("Translation of the CRML %1 file failed.").arg(mCRMLTranslatorOptions.getCRMLFile());
} else if (mCRMLTranslatorOptions.getMode().compare("translateAs") == 0) {
progressStr = tr("Translation of the CRML file %1 with output directory %2 and within %3 failed.").
arg(mCRMLTranslatorOptions.getCRMLFile(),
mCRMLTranslatorOptions.getOutputDirectory(),
mCRMLTranslatorOptions.getModelicaWithin()
);
} else {
progressStr = tr("CRML tool run failed.");
}
mpProgressBar->setRange(0, 2);
mpProgressBar->setValue(0);
mpCancelButton->setEnabled(false);
}
Expand All @@ -314,15 +334,15 @@ void CRMLTranslatorOutputWidget::cancelCompilation()

/*!
* \brief CRMLTranslatorOutputWidget::compilationProcessStarted
* Slot activated when mpCompilationProcess started signal is raised.\n
* Slot activated when mpCompilationProcess started signal is raised.\n
* Updates the progress label, bar and button controls.
*/
void CRMLTranslatorOutputWidget::compilationProcessStarted()
{
mIsCompilationProcessRunning = true;
const QString progressStr = tr("CRML compiler is running. Please wait for a while.");
mpProgressLabel->setText(progressStr);
mpProgressBar->setRange(0, 0);
mpProgressBar->setRange(0, 2);
mpProgressBar->setTextVisible(false);
updateMessageTab(progressStr);
mpCancelButton->setText(tr("Cancel"));
Expand Down Expand Up @@ -374,15 +394,39 @@ void CRMLTranslatorOutputWidget::compilationProcessError(QProcess::ProcessError
void CRMLTranslatorOutputWidget::compilationProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
mIsCompilationProcessRunning = false;
QString exitCodeStr = tr("Testsuite run process failed. Exited with code %1.").arg(Utilities::formatExitCode(exitCode));
QString messageFailed = "";
QString messageSuccess = "";
if (mCRMLTranslatorOptions.getMode().compare("testsuite") == 0) {
messageFailed = tr("Testsuite run in directory %1 failed. Exit code %2.").
arg(mCRMLTranslatorOptions.getRepositoryDirectory(), Utilities::formatExitCode(exitCode));
messageSuccess = tr("Testsuite run in directory %1 finished.").
arg(mCRMLTranslatorOptions.getRepositoryDirectory());;
} else if (mCRMLTranslatorOptions.getMode().compare("translate") == 0) {
messageFailed = tr("Translation of the CRML %1 file failed. Exit code %2").
arg(mCRMLTranslatorOptions.getCRMLFile(), Utilities::formatExitCode(exitCode));
messageSuccess = tr("Translation of CRML file %1 finished. Now loading specified CRML Modelica libraries...").arg(mCRMLTranslatorOptions.getCRMLFile());
} else if (mCRMLTranslatorOptions.getMode().compare("translateAs") == 0) {
messageFailed = tr("Translation of the CRML file %1 with output directory %2 and within %3 failed. Exit code %4.").
arg(mCRMLTranslatorOptions.getCRMLFile(),
mCRMLTranslatorOptions.getOutputDirectory(),
mCRMLTranslatorOptions.getModelicaWithin(),
Utilities::formatExitCode(exitCode)
);
messageSuccess = tr("Translation of CRML file [%1] with output directory [%2] and within [%3] finished. Now loading specified CRML Modelica libraries...").
arg(mCRMLTranslatorOptions.getCRMLFile(),
mCRMLTranslatorOptions.getOutputDirectory(),
mCRMLTranslatorOptions.getModelicaWithin());
} else {
messageFailed = tr("CRML tool run failed.");
}
if (exitStatus == QProcess::NormalExit && exitCode == 0) {
writeCompilationOutput(tr("Testsuite run process finished successfully.\n"), Qt::blue);
writeCompilationOutput(messageSuccess, Qt::blue);
compilationProcessFinishedHelper(exitCode, exitStatus);
} else if (mpCompilationProcess->error() == QProcess::UnknownError) {
writeCompilationOutput(exitCodeStr, Qt::red);
writeCompilationOutput(messageFailed, Qt::red);
compilationProcessFinishedHelper(exitCode, exitStatus);
} else {
writeCompilationOutput(mpCompilationProcess->errorString() + "\n" + exitCodeStr, Qt::red);
writeCompilationOutput(mpCompilationProcess->errorString() + "\n" + messageFailed, Qt::red);
compilationProcessFinishedHelper(exitCode, exitStatus);
}
}
Expand Down
40 changes: 27 additions & 13 deletions OMEdit/OMEditLIB/MainWindow.cpp
Expand Up @@ -145,6 +145,7 @@ MainWindow::MainWindow(QWidget *parent)
setWindowIcon(QIcon(":/Resources/icons/modeling.png"));
setMinimumSize(400, 300);
setContentsMargins(1, 1, 1, 1);
mpCRMLTranslateAsDialog = NULL;
}

MainWindow *MainWindow::mpInstance = 0;
Expand Down Expand Up @@ -1100,27 +1101,24 @@ void MainWindow::translateCRML(LibraryTreeItem *pLibraryTreeItem)

CRMLTranslatorOutputWidget *pCRMLTranslatorOutputWidget = new CRMLTranslatorOutputWidget(crmlTranslatorOptions);
MessagesWidget::instance()->addSimulationOutputTab(pCRMLTranslatorOutputWidget,
QString("%1 %2").arg(Helper::translateCRML, pLibraryTreeItem->getNameStructure()));
QString("%1 %2").arg(Helper::translateCRML, fi.fileName()));
pCRMLTranslatorOutputWidget->start();

}

void MainWindow::translateAsCRML(LibraryTreeItem *pLibraryTreeItem)
void MainWindow::runCRMLTranslateAs(int result)
{
/* if the CRML text is changed manually by user then validate it before saving. */
if (pLibraryTreeItem->getModelWidget()) {
if (!pLibraryTreeItem->getModelWidget()->validateText(&pLibraryTreeItem)) {
return;
}
}

LibraryTreeItem *pLibraryTreeItem = mpCRMLTranslateAsDialog->getLibraryTreeItem();
QString outputDirectory = mpCRMLTranslateAsDialog->getOutputDirectoryTextBox()->text();
QString modelicaWithin = mpCRMLTranslateAsDialog->getParentClassTextBox()->text();
QFileInfo fi = QFileInfo(pLibraryTreeItem->getFileName());

CRMLTranslateAsDialog *pCRMLTranslateAsDialog = new CRMLTranslateAsDialog(this);
pCRMLTranslateAsDialog->exec();
delete(mpCRMLTranslateAsDialog);
mpCRMLTranslateAsDialog = NULL;

QString outputDirectory = pCRMLTranslateAsDialog->getOutputDirectoryTextBox()->text();
QString modelicaWithin = pCRMLTranslateAsDialog->getParentClassTextBox()->text();
if (result == QDialog::Rejected)
return;

CRMLTranslatorOptions crmlTranslatorOptions;
CRMLPage *ep = OptionsDialog::instance()->getCRMLPage();
Expand All @@ -1141,9 +1139,25 @@ void MainWindow::translateAsCRML(LibraryTreeItem *pLibraryTreeItem)

CRMLTranslatorOutputWidget *pCRMLTranslatorOutputWidget = new CRMLTranslatorOutputWidget(crmlTranslatorOptions);
MessagesWidget::instance()->addSimulationOutputTab(pCRMLTranslatorOutputWidget,
QString("%1 %2").arg(Helper::translateAsCRML, pLibraryTreeItem->getNameStructure()));
QString("%1 %2").arg(Helper::translateAsCRML, fi.fileName()));
pCRMLTranslatorOutputWidget->start();
}

void MainWindow::translateAsCRML(LibraryTreeItem *pLibraryTreeItem)
{
/* if the CRML text is changed manually by user then validate it before saving. */
if (pLibraryTreeItem->getModelWidget()) {
if (!pLibraryTreeItem->getModelWidget()->validateText(&pLibraryTreeItem)) {
return;
}
}

if (!mpCRMLTranslateAsDialog) {
mpCRMLTranslateAsDialog = new CRMLTranslateAsDialog(this);
connect(mpCRMLTranslateAsDialog, SIGNAL(finished(int)), this, SLOT(runCRMLTranslateAs(int)));
}
mpCRMLTranslateAsDialog->setLibraryTreeItem(pLibraryTreeItem);
mpCRMLTranslateAsDialog->open();
}

void MainWindow::runScript(LibraryTreeItem *pLibraryTreeItem)
Expand Down
3 changes: 3 additions & 0 deletions OMEdit/OMEditLIB/MainWindow.h
Expand Up @@ -94,6 +94,7 @@ class StatusBar;
class TraceabilityGraphViewWidget;
class SearchWidget;
class MessageTab;
class CRMLTranslateAsDialog;

class MainWindow : public QMainWindow
{
Expand Down Expand Up @@ -320,6 +321,7 @@ class MainWindow : public QMainWindow
QObject *mpOMSensPlugin;
GitCommands *mpGitCommands;
CommitChangesDialog *mpCommitChangesDialog;
CRMLTranslateAsDialog* mpCRMLTranslateAsDialog;
TraceabilityInformationURI *mpTraceabilityInformationURI;
QStackedWidget *mpCentralStackedWidget;
QTabWidget *mpMessagesTabWidget;
Expand Down Expand Up @@ -610,6 +612,7 @@ public slots:
void toggleAutoSave();
void readInterfaceData(LibraryTreeItem *pLibraryTreeItem);
void enableReSimulationToolbar(bool visible);
void runCRMLTranslateAs(int result);
private slots:
void perspectiveTabChanged(int tabIndex);
void documentationDockWidgetVisibilityChanged(bool visible);
Expand Down

0 comments on commit ec35509

Please sign in to comment.