Skip to content

Commit

Permalink
- Fixed exception throw problem. Using QApplication::notify now.
Browse files Browse the repository at this point in the history
- Fixed the shared memory problem.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8556 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Apr 8, 2011
1 parent 76956c4 commit 961ceae
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 17 deletions.
34 changes: 27 additions & 7 deletions OMPlot/OMPlotGUI/PlotApplication.cpp
Expand Up @@ -32,6 +32,7 @@
*/

#include "PlotApplication.h"
#include "PlotWindow.h"
#include <QTimer>

using namespace OMPlot;
Expand All @@ -48,7 +49,7 @@ PlotApplication::PlotApplication(int &argc, char *argv[], const QString uniqueKe
mIsRunning = false;
// attach data to shared memory.
QByteArray byteArray("0"); // default value to note that no message is available.
if (!mSharedMemory.create(byteArray.size()))
if (!mSharedMemory.create(4096))
{
printf("Unable to create shared memory for OMPlot.");
return;
Expand Down Expand Up @@ -94,6 +95,25 @@ void PlotApplication::launchNewApplication(QStringList arguments)
mSharedMemory.unlock();
}

bool PlotApplication::notify(QObject *receiver, QEvent *event)
{
try
{
return QApplication::notify(receiver, event);
}
catch (PlotException &e)
{
QMessageBox *msgBox = new QMessageBox();
msgBox->setWindowTitle(QString("OMPlot - Error"));
msgBox->setIcon(QMessageBox::Warning);
msgBox->setText(QString(e.what()));
msgBox->setStandardButtons(QMessageBox::Ok);
msgBox->setDefaultButton(QMessageBox::Ok);
msgBox->exec();
return true;
}
}

void PlotApplication::checkForMessage()
{
mSharedMemory.lock();
Expand All @@ -104,17 +124,17 @@ void PlotApplication::checkForMessage()
char type = byteArray.at(0);
byteArray.remove(0, 1); // remove the one we put at the start of the bytearray while writing to memory
QStringList arguments = QString::fromUtf8(byteArray.constData()).split(";");
// if type is 1 send message to current tab
// if type is 2 launch a new tab
if (type == '2')
emit newApplicationLaunched(arguments);
else
emit messageAvailable(arguments);
// remove message from shared memory.
byteArray = "0";
mSharedMemory.lock();
char *to = (char*)mSharedMemory.data();
const char *from = byteArray.data();
memcpy(to, from, qMin(mSharedMemory.size(), byteArray.size()));
mSharedMemory.unlock();
// if type is 1 send message to current tab
// if type is 2 launch a new tab
if (type == '2')
emit newApplicationLaunched(arguments);
else
emit messageAvailable(arguments);
}
1 change: 1 addition & 0 deletions OMPlot/OMPlotGUI/PlotApplication.h
Expand Up @@ -50,6 +50,7 @@ class PlotApplication : public QApplication
bool isRunning();
void sendMessage(QStringList arguments);
void launchNewApplication(QStringList arguments);
virtual bool notify(QObject *receiver, QEvent *event);
private:
bool mIsRunning;
QSharedMemory mSharedMemory;
Expand Down
8 changes: 6 additions & 2 deletions OMPlot/OMPlotGUI/PlotWindow.cpp
Expand Up @@ -44,9 +44,11 @@ PlotWindow::PlotWindow(QStringList arguments, QWidget *parent)
setUpWidget();
// initialize plot by reading all parameters passed to it
if (arguments.size() > 1)
{
initializePlot(arguments);
mpPlot->getPlotZoomer()->setZoomBase(false);
}
// set qwtplot the central widget
mpPlot->getPlotZoomer()->setZoomBase(false);
setCentralWidget(getPlot());
}

Expand Down Expand Up @@ -315,7 +317,7 @@ void PlotWindow::plot()
pPlotCurve[i] = new PlotCurve(mpPlot);
pPlotCurve[i]->setFileName(QFileInfo(mFile).fileName());
mpPlot->addPlotCurve(pPlotCurve[i]);
pPlotCurve[i]->setTitle(allVariablesInFile.at(i));
pPlotCurve[i]->setTitle(variablesPlotted.at(i));
}

//Assign Values
Expand Down Expand Up @@ -686,6 +688,8 @@ void PlotWindow::exportDocument()
if (fileName.endsWith(".svg"))
{
QSvgGenerator generator;
generator.setTitle(tr("OMPlot - OpenModelica Plot"));
generator.setDescription(tr("Generated by OpenModelica Plot Tool"));
generator.setFileName(fileName);
generator.setSize(getPlot()->rect().size());
getPlot()->print(generator);
Expand Down
2 changes: 2 additions & 0 deletions OMPlot/OMPlotGUI/PlotWindowContainer.cpp
Expand Up @@ -88,11 +88,13 @@ void PlotWindowContainer::addPlotWindow(QStringList arguments)
pPlotWindow->showMaximized();
else
pPlotWindow->show();
getPlotMainWindow()->activateWindow();
}

void PlotWindowContainer::updateCurrentWindow(QStringList arguments)
{
getCurrentWindow()->receiveMessage(arguments);
getPlotMainWindow()->activateWindow();
}

void PlotWindowContainer::checkSubWindows()
Expand Down
17 changes: 9 additions & 8 deletions OMPlot/OMPlotGUI/main.cpp
Expand Up @@ -63,14 +63,15 @@ int main(int argc, char *argv[])
}
// create the plot application object that is used to check that only one instance of application is running
PlotApplication app(argc, argv, "OMPlot");
// create the plot main window
PlotMainWindow w;
QObject::connect(&app, SIGNAL(messageAvailable(QStringList)),
w.getPlotWindowContainer(), SLOT(updateCurrentWindow(QStringList)));
QObject::connect(&app, SIGNAL(newApplicationLaunched(QStringList)),
w.getPlotWindowContainer(), SLOT(addPlotWindow(QStringList)));
try {
// create the plot main window
PlotMainWindow w;
w.addPlotWindow(arguments);
QObject::connect(&app, SIGNAL(messageAvailable(QStringList)),
w.getPlotWindowContainer(), SLOT(updateCurrentWindow(QStringList)));
QObject::connect(&app, SIGNAL(newApplicationLaunched(QStringList)),
w.getPlotWindowContainer(), SLOT(addPlotWindow(QStringList)));
if (!app.isRunning())
w.addPlotWindow(arguments);
// if there is no exception with plot window then continue
if (app.isRunning())
{
Expand All @@ -85,7 +86,7 @@ int main(int argc, char *argv[])
} catch (PlotException &e)
{
QMessageBox *msgBox = new QMessageBox();
msgBox->setWindowTitle(QString("PlotWidgetGUI"));
msgBox->setWindowTitle(QString("OMPlot - Error"));
msgBox->setIcon(QMessageBox::Warning);
msgBox->setText(QString(e.what()));
msgBox->setStandardButtons(QMessageBox::Ok);
Expand Down

0 comments on commit 961ceae

Please sign in to comment.