Skip to content

Commit

Permalink
- OMPlot is a MDI application now. You can switch between tabbedview …
Browse files Browse the repository at this point in the history
…and subwindowview through the menu.

- Only one instance of OMPlot is allowed at a time. The active window with in the OMPlot application recieves the new plot commands from omc.
- New icon for OMPlot.
- few more updates as well.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8451 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Apr 1, 2011
1 parent 966471b commit a2ae4e7
Show file tree
Hide file tree
Showing 15 changed files with 434 additions and 80 deletions.
18 changes: 14 additions & 4 deletions OMPlot/OMPlotGUI/OMPlotGUI.pro
Expand Up @@ -18,7 +18,9 @@ SOURCES += main.cpp \
PlotGrid.cpp \
PlotCurve.cpp \
PlotWindow.cpp \
PlotApplication.cpp
PlotApplication.cpp \
PlotWindowContainer.cpp \
PlotMainWindow.cpp

HEADERS += ../../c_runtime/read_matlab4.h \
Plot.h \
Expand All @@ -28,10 +30,17 @@ HEADERS += ../../c_runtime/read_matlab4.h \
PlotGrid.h \
PlotCurve.h \
PlotWindow.h \
PlotApplication.h
PlotApplication.h \
PlotWindowContainer.h \
PlotMainWindow.h

win32 {
CONFIG(debug, debug|release){
LIBS += -L$$(OMDEV)/lib/qwt-5.2.1-mingw/lib -lqwtd5
}
else {
LIBS += -L$$(OMDEV)/lib/qwt-5.2.1-mingw/lib -lqwt5
}
INCLUDEPATH += $$(OMDEV)/lib/qwt-5.2.1-mingw/include
} else {
include(OMPlotGUI.config)
Expand All @@ -49,5 +58,6 @@ MOC_DIR = ../generatedfiles/moc

RCC_DIR = ../generatedfiles/rcc

RESOURCES += \
Resources.qrc
RESOURCES += resource_omplot.qrc

RC_FILE = rc_omplot.rc
18 changes: 13 additions & 5 deletions OMPlot/OMPlotGUI/OMPlotLib.pro
Expand Up @@ -4,7 +4,7 @@
#
#-------------------------------------------------

QT += core gui
QT += core gui

TARGET = OMPlot
TEMPLATE = lib
Expand All @@ -20,7 +20,9 @@ SOURCES += main.cpp \
PlotGrid.cpp \
PlotCurve.cpp \
PlotWindow.cpp \
PlotApplication.cpp
PlotApplication.cpp \
PlotWindowContainer.cpp \
PlotMainWindow.cpp

HEADERS += ../../c_runtime/read_matlab4.h \
Plot.h \
Expand All @@ -30,10 +32,17 @@ HEADERS += ../../c_runtime/read_matlab4.h \
PlotGrid.h \
PlotCurve.h \
PlotWindow.h \
PlotApplication.h
PlotApplication.h \
PlotWindowContainer.h \
PlotMainWindow.h

win32 {
CONFIG(debug, debug|release){
LIBS += -L$$(OMDEV)/lib/qwt-5.2.1-mingw/lib -lqwtd5
}
else {
LIBS += -L$$(OMDEV)/lib/qwt-5.2.1-mingw/lib -lqwt5
}
INCLUDEPATH += $$(OMDEV)/lib/qwt-5.2.1-mingw/include
} else {
include(OMPlotGUI.config)
Expand All @@ -51,5 +60,4 @@ MOC_DIR = ../generatedfiles/moc

RCC_DIR = ../generatedfiles/rcc

RESOURCES += \
Resources.qrc
RESOURCES += resource_omplot.qrc
49 changes: 13 additions & 36 deletions OMPlot/OMPlotGUI/PlotApplication.cpp
Expand Up @@ -34,6 +34,8 @@
#include "PlotApplication.h"
#include <QTimer>

using namespace OMPlot;

PlotApplication::PlotApplication(int &argc, char *argv[], const QString uniqueKey)
: QApplication(argc, argv)
{
Expand All @@ -58,22 +60,18 @@ PlotApplication::PlotApplication(int &argc, char *argv[], const QString uniqueKe
mSharedMemory.unlock();
// start checking for messages of other instances.
mpTimer = new QTimer(this);
startTimer(); // connect the timer to checkForMessage slot
connect(mpTimer, SIGNAL(timeout()), SLOT(checkForMessage()));
mpTimer->start(100); // after every 0.1 second we check the shared memory
}

connect(this, SIGNAL(newApplicationLaunched()), SLOT(stopTimer()));
}

bool PlotApplication::isRunning()
{
return mIsRunning;
}

bool PlotApplication::sendMessage(QStringList arguments)
void PlotApplication::sendMessage(QStringList arguments)
{
if (!mIsRunning)
return false;
QByteArray byteArray("1");
byteArray.append(arguments.join(";").toUtf8());
byteArray.append('\0'); // < should be as char here, not a string!
Expand All @@ -82,44 +80,36 @@ bool PlotApplication::sendMessage(QStringList arguments)
const char *from = byteArray.data();
memcpy(to, from, qMin(mSharedMemory.size(), byteArray.size()));
mSharedMemory.unlock();
return true;
}

void PlotApplication::launchNewApplication()
void PlotApplication::launchNewApplication(QStringList arguments)
{
QByteArray byteArray("1");
byteArray.append(tr("newomplotwindow").toUtf8());
QByteArray byteArray("2");
byteArray.append(arguments.join(";").toUtf8());
byteArray.append('\0'); // < should be as char here, not a string!
mSharedMemory.lock();
char *to = (char*)mSharedMemory.data();
const char *from = byteArray.data();
memcpy(to, from, qMin(mSharedMemory.size(), byteArray.size()));
mSharedMemory.unlock();
// new create timer for new app
mpTimer = new QTimer(this);
startTimer(); // connect the timer to checkForMessage slot
mpTimer->start(100); // after every 0.1 second we check the shared memory
}

void PlotApplication::checkForMessage()
{
qDebug() << "looking for message";
mSharedMemory.lock();
QByteArray byteArray = QByteArray((char*)mSharedMemory.constData(), mSharedMemory.size());
mSharedMemory.unlock();
if (byteArray.left(1) == "0")
return;
char type = byteArray.at(0);
byteArray.remove(0, 1); // remove the one we put at the start of the bytearray while writing to memory
// check if new application is launched or not
if (QString::fromUtf8(byteArray.constData()).compare("newomplotwindow") == 0)
{
emit newApplicationLaunched();
}
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
{
QStringList arguments = QString::fromUtf8(byteArray.constData()).split(";");
emit messageAvailable(arguments);
}
// remove message from shared memory.
byteArray = "0";
mSharedMemory.lock();
Expand All @@ -128,16 +118,3 @@ void PlotApplication::checkForMessage()
memcpy(to, from, qMin(mSharedMemory.size(), byteArray.size()));
mSharedMemory.unlock();
}

void PlotApplication::startTimer()
{
connect(mpTimer, SIGNAL(timeout()), SLOT(checkForMessage()));
}

void PlotApplication::stopTimer()
{
mpTimer->stop();
qDebug() << "stopping timer";
}


11 changes: 6 additions & 5 deletions OMPlot/OMPlotGUI/PlotApplication.h
Expand Up @@ -39,26 +39,27 @@
#include <QStringList>
#include <QDebug>

namespace OMPlot
{
class PlotApplication : public QApplication
{
Q_OBJECT
public:
PlotApplication(int &argc, char *argv[], const QString uniqueKey);

bool isRunning();
bool sendMessage(QStringList arguments);
void launchNewApplication();
void sendMessage(QStringList arguments);
void launchNewApplication(QStringList arguments);
private:
bool mIsRunning;
QSharedMemory mSharedMemory;
QTimer *mpTimer;
public slots:
void checkForMessage();
void startTimer();
void stopTimer();
signals:
void messageAvailable(QStringList arguments);
void newApplicationLaunched();
void newApplicationLaunched(QStringList arguments);
};
}

#endif // PLOTAPPLICATION_H
117 changes: 117 additions & 0 deletions OMPlot/OMPlotGUI/PlotMainWindow.cpp
@@ -0,0 +1,117 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Linkoping University,
* Department of Computer and Information Science,
* SE-58183 Linkoping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3
* AND THIS OSMC PUBLIC LICENSE (OSMC-PL).
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S
* ACCEPTANCE OF THE OSMC PUBLIC LICENSE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from Linkoping University, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS
* OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
* Main Author 2011: Adeel Asghar
*
*/

#include "PlotMainWindow.h"

using namespace OMPlot;

PlotMainWindow::PlotMainWindow(QWidget *pParent)
: QMainWindow(pParent)
{
mpPlotWindowContainer = new PlotWindowContainer(this);

setWindowTitle(tr("OMPlot - OpenModelica Plot"));
setWindowIcon(QIcon(":/Resources/icons/omplot.png"));

createActions();
createMenus();

//Create the Statusbar
mpStatusBar = new QStatusBar();
mpStatusBar->setObjectName("statusBar");
setStatusBar(mpStatusBar);
// set plotwindowcontainer as central widget
setCentralWidget(mpPlotWindowContainer);
}

PlotWindowContainer* PlotMainWindow::getPlotWindowContainer()
{
return mpPlotWindowContainer;
}

void PlotMainWindow::addPlotWindow(QStringList arguments)
{
mpPlotWindowContainer->addPlotWindow(arguments);
}

void PlotMainWindow::createActions()
{
mpCloseAction = new QAction(tr("Close"), this);
mpCloseAction->setShortcut(QKeySequence("Ctrl+q"));
connect(mpCloseAction, SIGNAL(triggered()), SLOT(close()));

mpTabViewAction = new QAction(tr("Tab View"), this);
mpTabViewAction->setCheckable(true);
mpTabViewAction->setChecked(true);
connect(mpTabViewAction, SIGNAL(triggered(bool)), SLOT(switchWindowsView(bool)));
}

void PlotMainWindow::createMenus()
{
//Create the menubar
mpMenuBar = new QMenuBar();
mpMenuBar->setGeometry(QRect(0,0,800,25));
mpMenuBar->setObjectName("menubar");

//Create the File menu
mpMenuFile = new QMenu(mpMenuBar);
mpMenuFile->setObjectName("menuFile");
mpMenuFile->setTitle("&File");
//Add the actions to file menu
mpMenuFile->addAction(mpCloseAction);
// add file menu to menubar
mpMenuBar->addAction(mpMenuFile->menuAction());
//Create the Options menu
mpMenuOptions = new QMenu(mpMenuBar);
mpMenuOptions->setObjectName("menuFile");
mpMenuOptions->setTitle("&Options");
//Add the actions to Options menu
mpMenuOptions->addAction(mpTabViewAction);
// add options menu to menubar
mpMenuBar->addAction(mpMenuOptions->menuAction());
// add menubar to mainwindow
setMenuBar(mpMenuBar);
}

void PlotMainWindow::switchWindowsView(bool mode)
{
if (mode)
{
getPlotWindowContainer()->setViewMode(QMdiArea::TabbedView);
}
else
{
getPlotWindowContainer()->setViewMode(QMdiArea::SubWindowView);
getPlotWindowContainer()->getCurrentWindow()->show();
}
}

0 comments on commit a2ae4e7

Please sign in to comment.