Skip to content

Commit

Permalink
Added new command line option --Debug=[true|false]. Draws widgets hel…
Browse files Browse the repository at this point in the history
…pful for development.
  • Loading branch information
adeas31 committed Nov 17, 2015
1 parent da9489d commit ffbc45f
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 60 deletions.
22 changes: 11 additions & 11 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -45,8 +45,8 @@
#include "FetchInterfaceDataDialog.h"
#include "TLMCoSimulationOutputWidget.h"

MainWindow::MainWindow(QSplashScreen *pSplashScreen, QWidget *parent)
: QMainWindow(parent), mExitApplicationStatus(false)
MainWindow::MainWindow(QSplashScreen *pSplashScreen, bool debug, QWidget *parent)
: QMainWindow(parent), mDebug(debug), mExitApplicationStatus(false)
{
// This is a very convoluted way of asking for the default system font in Qt
QFont systmFont("Monospace");
Expand Down Expand Up @@ -2531,12 +2531,12 @@ void MainWindow::createActions()
mpShowOMCLoggerWidgetAction = new QAction(QIcon(":/Resources/icons/console.svg"), Helper::OpenModelicaCompilerCLI, this);
mpShowOMCLoggerWidgetAction->setStatusTip(tr("Shows OpenModelica Compiler CLI"));
connect(mpShowOMCLoggerWidgetAction, SIGNAL(triggered()), mpOMCProxy, SLOT(openOMCLoggerWidget()));
#ifdef QT_DEBUG
// show OMC Diff widget action
mpShowOMCDiffWidgetAction = new QAction(QIcon(":/Resources/icons/console.svg"), tr("OpenModelica Compiler Diff"), this);
mpShowOMCDiffWidgetAction->setStatusTip(tr("Shows OpenModelica Compiler Diff"));
connect(mpShowOMCDiffWidgetAction, SIGNAL(triggered()), mpOMCProxy, SLOT(openOMCDiffWidget()));
#endif
if (isDebug()) {
// show OMC Diff widget action
mpShowOMCDiffWidgetAction = new QAction(QIcon(":/Resources/icons/console.svg"), tr("OpenModelica Compiler Diff"), this);
mpShowOMCDiffWidgetAction->setStatusTip(tr("Shows OpenModelica Compiler Diff"));
connect(mpShowOMCDiffWidgetAction, SIGNAL(triggered()), mpOMCProxy, SLOT(openOMCDiffWidget()));
}
// export to OMNotebook action
mpExportToOMNotebookAction = new QAction(QIcon(":/Resources/icons/export-omnotebook.svg"), Helper::exportToOMNotebook, this);
mpExportToOMNotebookAction->setStatusTip(Helper::exportToOMNotebookTip);
Expand Down Expand Up @@ -2817,9 +2817,9 @@ void MainWindow::createMenus()
pToolsMenu->setTitle(tr("&Tools"));
// add actions to Tools menu
pToolsMenu->addAction(mpShowOMCLoggerWidgetAction);
#ifdef QT_DEBUG
pToolsMenu->addAction(mpShowOMCDiffWidgetAction);
#endif
if (isDebug()) {
pToolsMenu->addAction(mpShowOMCDiffWidgetAction);
}
pToolsMenu->addSeparator();
pToolsMenu->addAction(mpExportToOMNotebookAction);
pToolsMenu->addAction(mpImportFromOMNotebookAction);
Expand Down
6 changes: 3 additions & 3 deletions OMEdit/OMEditGUI/MainWindow.h
Expand Up @@ -97,7 +97,8 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
enum { MaxRecentFiles = 8 };
MainWindow(QSplashScreen *pSplashScreen, QWidget *parent = 0);
MainWindow(QSplashScreen *pSplashScreen, bool debug, QWidget *parent = 0);
bool isDebug() {return mDebug;}
OMCProxy* getOMCProxy();
void setExitApplicationStatus(bool status);
bool getExitApplicationStatus();
Expand Down Expand Up @@ -185,6 +186,7 @@ class MainWindow : public QMainWindow
const char* curveStyle, const char* legendPosition, const char* footer, const char* autoScale,
const char* variables);
private:
bool mDebug;
OMCProxy *mpOMCProxy;
bool mExitApplicationStatus;
OptionsDialog *mpOptionsDialog;
Expand Down Expand Up @@ -271,9 +273,7 @@ class MainWindow : public QMainWindow
QAction *mpExportFigaroAction;
// Tools Menu
QAction *mpShowOMCLoggerWidgetAction;
#ifdef QT_DEBUG
QAction *mpShowOMCDiffWidgetAction;
#endif
QAction *mpExportToOMNotebookAction;
QAction *mpImportFromOMNotebookAction;
QAction *mpImportNgspiceNetlistAction;
Expand Down
22 changes: 17 additions & 5 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -2250,7 +2250,9 @@ ModelWidget::ModelWidget(LibraryTreeItem* pLibraryTreeItem, ModelWidgetContainer
mpUndoStack = new QUndoStack;
connect(mpUndoStack, SIGNAL(canUndoChanged(bool)), SLOT(handleCanUndoChanged(bool)));
connect(mpUndoStack, SIGNAL(canRedoChanged(bool)), SLOT(handleCanRedoChanged(bool)));
mpUndoView = new QUndoView(mpUndoStack);
if (mpModelWidgetContainer->getMainWindow()->isDebug()) {
mpUndoView = new QUndoView(mpUndoStack);
}
getModelInheritedClasses(mpLibraryTreeItem);
drawModelInheritedClasses();
getModelIconDiagramShapes();
Expand All @@ -2268,7 +2270,9 @@ ModelWidget::ModelWidget(LibraryTreeItem* pLibraryTreeItem, ModelWidgetContainer
mpDiagramGraphicsView = 0;
// undo stack for model
mpUndoStack = 0;
mpUndoView = 0;
if (mpModelWidgetContainer->getMainWindow()->isDebug()) {
mpUndoView = 0;
}
mpEditor = 0;
}
// store the text of LibraryTreeItem::Text
Expand Down Expand Up @@ -2546,7 +2550,9 @@ void ModelWidget::createModelWidgetComponents()
mpModelStatusBar->addPermanentWidget(mpCursorPositionLabel, 0);
mpModelStatusBar->addPermanentWidget(mpFileLockToolButton, 0);
// set layout
pMainLayout->addWidget(mpUndoView);
if (mpModelWidgetContainer->getMainWindow()->isDebug()) {
pMainLayout->addWidget(mpUndoView);
}
pMainLayout->addWidget(mpDiagramGraphicsView, 1);
pMainLayout->addWidget(mpIconGraphicsView, 1);
mpUndoStack->clear();
Expand Down Expand Up @@ -2580,7 +2586,9 @@ void ModelWidget::createModelWidgetComponents()
mpUndoStack = new QUndoStack;
connect(mpUndoStack, SIGNAL(canUndoChanged(bool)), SLOT(handleCanUndoChanged(bool)));
connect(mpUndoStack, SIGNAL(canRedoChanged(bool)), SLOT(handleCanRedoChanged(bool)));
mpUndoView = new QUndoView(mpUndoStack);
if (mpModelWidgetContainer->getMainWindow()->isDebug()) {
mpUndoView = new QUndoView(mpUndoStack);
}
// create an xml editor for TLM
mpEditor = new TLMEditor(this);
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(mpEditor);
Expand Down Expand Up @@ -2621,7 +2629,9 @@ void ModelWidget::createModelWidgetComponents()
mpModelStatusBar->addPermanentWidget(mpFileLockToolButton, 0);
// set layout
pMainLayout->addWidget(mpModelStatusBar);
pMainLayout->addWidget(mpUndoView);
if (mpModelWidgetContainer->getMainWindow()->isDebug()) {
pMainLayout->addWidget(mpUndoView);
}
pMainLayout->addWidget(mpDiagramGraphicsView, 1);
mpUndoStack->clear();
}
Expand Down Expand Up @@ -3394,6 +3404,7 @@ void ModelWidget::showIconView(bool checked)
mpDiagramGraphicsView->hide();
mpEditor->hide();
mpIconGraphicsView->show();
mpIconGraphicsView->setFocus();
mpModelWidgetContainer->setPreviousViewType(StringHandler::Icon);
updateUndoRedoActions();
}
Expand Down Expand Up @@ -3424,6 +3435,7 @@ void ModelWidget::showDiagramView(bool checked)
mpIconGraphicsView->hide();
mpEditor->hide();
mpDiagramGraphicsView->show();
mpDiagramGraphicsView->setFocus();
mpModelWidgetContainer->setPreviousViewType(StringHandler::Diagram);
updateUndoRedoActions();
}
Expand Down
74 changes: 37 additions & 37 deletions OMEdit/OMEditGUI/OMC/OMCProxy.cpp
Expand Up @@ -123,28 +123,28 @@ OMCProxy::OMCProxy(MainWindow *pMainWindow)
pVerticalalLayout->addLayout(pHorizontalLayout);
pVerticalalLayout->addWidget(mpOMCLoggerEnableHintLabel);
mpOMCLoggerWidget->setLayout(pVerticalalLayout);
#ifdef QT_DEBUG
// OMC Diff widget
mpOMCDiffWidget = new QWidget;
mpOMCDiffWidget->resize(640, 480);
mpOMCDiffWidget->setWindowIcon(QIcon(":/Resources/icons/console.svg"));
mpOMCDiffWidget->setWindowTitle(QString(Helper::applicationName).append(" - ").append(tr("OMC Diff")));
mpOMCDiffBeforeLabel = new Label(tr("Before"));
mpOMCDiffBeforeTextBox = new QPlainTextEdit;
mpOMCDiffAfterLabel = new Label(tr("After"));
mpOMCDiffAfterTextBox = new QPlainTextEdit;
mpOMCDiffMergedLabel = new Label(tr("Merged"));
mpOMCDiffMergedTextBox = new QPlainTextEdit;
// Set the OMC Diff widget Layout
QGridLayout *pOMCDiffWidgetLayout = new QGridLayout;
pOMCDiffWidgetLayout->addWidget(mpOMCDiffBeforeLabel, 0, 0);
pOMCDiffWidgetLayout->addWidget(mpOMCDiffAfterLabel, 0, 1);
pOMCDiffWidgetLayout->addWidget(mpOMCDiffBeforeTextBox, 1, 0);
pOMCDiffWidgetLayout->addWidget(mpOMCDiffAfterTextBox, 1, 1);
pOMCDiffWidgetLayout->addWidget(mpOMCDiffMergedLabel, 2, 0, 1, 2);
pOMCDiffWidgetLayout->addWidget(mpOMCDiffMergedTextBox, 3, 0, 1, 2);
mpOMCDiffWidget->setLayout(pOMCDiffWidgetLayout);
#endif
if (mpMainWindow->isDebug()) {
// OMC Diff widget
mpOMCDiffWidget = new QWidget;
mpOMCDiffWidget->resize(640, 480);
mpOMCDiffWidget->setWindowIcon(QIcon(":/Resources/icons/console.svg"));
mpOMCDiffWidget->setWindowTitle(QString(Helper::applicationName).append(" - ").append(tr("OMC Diff")));
mpOMCDiffBeforeLabel = new Label(tr("Before"));
mpOMCDiffBeforeTextBox = new QPlainTextEdit;
mpOMCDiffAfterLabel = new Label(tr("After"));
mpOMCDiffAfterTextBox = new QPlainTextEdit;
mpOMCDiffMergedLabel = new Label(tr("Merged"));
mpOMCDiffMergedTextBox = new QPlainTextEdit;
// Set the OMC Diff widget Layout
QGridLayout *pOMCDiffWidgetLayout = new QGridLayout;
pOMCDiffWidgetLayout->addWidget(mpOMCDiffBeforeLabel, 0, 0);
pOMCDiffWidgetLayout->addWidget(mpOMCDiffAfterLabel, 0, 1);
pOMCDiffWidgetLayout->addWidget(mpOMCDiffBeforeTextBox, 1, 0);
pOMCDiffWidgetLayout->addWidget(mpOMCDiffAfterTextBox, 1, 1);
pOMCDiffWidgetLayout->addWidget(mpOMCDiffMergedLabel, 2, 0, 1, 2);
pOMCDiffWidgetLayout->addWidget(mpOMCDiffMergedTextBox, 3, 0, 1, 2);
mpOMCDiffWidget->setLayout(pOMCDiffWidgetLayout);
}
//start the server
if(!initializeOMC()) // if we are unable to start OMC. Exit the application.
{
Expand All @@ -156,9 +156,9 @@ OMCProxy::OMCProxy(MainWindow *pMainWindow)
OMCProxy::~OMCProxy()
{
delete mpOMCLoggerWidget;
#ifdef QT_DEBUG
delete mpOMCDiffWidget;
#endif
if (mpMainWindow->isDebug()) {
delete mpOMCDiffWidget;
}
}

/*!
Expand Down Expand Up @@ -457,20 +457,20 @@ void OMCProxy::sendCustomExpression()
mpExpressionTextBox->setText("");
}

#ifdef QT_DEBUG
/*!
* \brief OMCProxy::openOMCDiffWidget
* Opens the OMC Diff widget.
*/
void OMCProxy::openOMCDiffWidget()
{
mpOMCDiffBeforeTextBox->setFocus(Qt::ActiveWindowFocusReason);
mpOMCDiffWidget->show();
mpOMCDiffWidget->raise();
mpOMCDiffWidget->activateWindow();
mpOMCDiffWidget->setWindowState(mpOMCDiffWidget->windowState() & (~Qt::WindowMinimized | Qt::WindowActive));
if (mpMainWindow->isDebug()) {
mpOMCDiffBeforeTextBox->setFocus(Qt::ActiveWindowFocusReason);
mpOMCDiffWidget->show();
mpOMCDiffWidget->raise();
mpOMCDiffWidget->activateWindow();
mpOMCDiffWidget->setWindowState(mpOMCDiffWidget->windowState() & (~Qt::WindowMinimized | Qt::WindowActive));
}
}
#endif

/*!
Removes the CORBA IOR file. We only call this method when we are unable to connect to OMC.\n
Expand Down Expand Up @@ -1588,11 +1588,11 @@ QString OMCProxy::diffModelicaFileListings(QString before, QString after)
QString escapedAfter = StringHandler::escapeString(after);
sendCommand("diffModelicaFileListings(\"" + escapedBefore + "\", \"" + escapedAfter + "\", OpenModelica.Scripting.DiffFormat.plain)");
QString result = StringHandler::unparse(getResult());
#ifdef QT_DEBUG
mpOMCDiffBeforeTextBox->setPlainText(before);
mpOMCDiffAfterTextBox->setPlainText(after);
mpOMCDiffMergedTextBox->setPlainText(result);
#endif
if (mpMainWindow->isDebug()) {
mpOMCDiffBeforeTextBox->setPlainText(before);
mpOMCDiffAfterTextBox->setPlainText(after);
mpOMCDiffMergedTextBox->setPlainText(result);
}
return result;
}

Expand Down
2 changes: 0 additions & 2 deletions OMEdit/OMEditGUI/OMC/OMCProxy.h
Expand Up @@ -231,9 +231,7 @@ public slots:
void showException(QString exception);
void openOMCLoggerWidget();
void sendCustomExpression();
#ifdef QT_DEBUG
void openOMCDiffWidget();
#endif
};

class CustomExpressionBox : public QLineEdit
Expand Down
19 changes: 17 additions & 2 deletions OMEdit/OMEditGUI/main.cpp
Expand Up @@ -41,6 +41,11 @@
Source code documentation. Provides brief information about the classes used.
\section contributors_section Contributors
\subsection year_2015_subsection 2015
- Adeel Asghar - <a href="mailto:adeel.asghar@liu.se">adeel.asghar@liu.se</a>
- Martin Sjölund - <a href="mailto:martin.sjolund@liu.se">martin.sjolund@liu.se</a>
- Alachew Shitahun - <a href="mailto:alachew.mengist@liu.se">alachew.mengist@liu.se</a>
\subsection year_2014_subsection 2014
- Adeel Asghar - <a href="mailto:adeel.asghar@liu.se">adeel.asghar@liu.se</a>
- Martin Sjölund - <a href="mailto:martin.sjolund@liu.se">martin.sjolund@liu.se</a>
Expand Down Expand Up @@ -195,8 +200,9 @@ LONG WINAPI exceptionFilter(LPEXCEPTION_POINTERS info)

void printOMEditUsage()
{
printf("Usage: OMEdit [--OMCLogger=true|false] [files]\n");
printf("Usage: OMEdit [--OMCLogger=true|false] --Debug=true|false] [files]\n");
printf(" --OMCLogger=[true|false] Allows sending OMC commands from OMCLogger. Default is false.\n");
printf(" --Debug=[true|false] Enables the debugging features like QUndoView, diffModelicaFileListings view. Default is false.\n");
printf(" files List of Modelica files(*.mo) to open.\n");
}

Expand Down Expand Up @@ -281,6 +287,7 @@ int main(int argc, char *argv[])
setlocale(LC_NUMERIC, "C");
// if user has requested to open the file by passing it in argument then,
bool OMCLogger = false;
bool debug = false;
QString fileName = "";
QStringList fileNames;
if (a.arguments().size() > 1) {
Expand All @@ -293,6 +300,14 @@ int main(int argc, char *argv[])
} else {
OMCLogger = false;
}
} else if (strncmp(a.arguments().at(i).toStdString().c_str(), "--Debug=",8) == 0) {
QString debugArg = a.arguments().at(i);
debugArg.remove("--Debug=");
if (0 == strcmp("true", debugArg.toStdString().c_str())) {
debug = true;
} else {
debug = false;
}
} else {
fileName = a.arguments().at(i);
if (!fileName.isEmpty()) {
Expand All @@ -308,7 +323,7 @@ int main(int argc, char *argv[])
}
}
// MainWindow Initialization
MainWindow mainwindow(&splashScreen);
MainWindow mainwindow(&splashScreen, debug);
if (mainwindow.getExitApplicationStatus()) { // if there is some issue in running the application.
a.quit();
exit(1);
Expand Down

0 comments on commit ffbc45f

Please sign in to comment.