Skip to content

Commit

Permalink
- You must compile OMPlotLib first.
Browse files Browse the repository at this point in the history
- Type in plot API in the cells and evaluate to see the embedded plot.
- You cannot save and reopen the embedded plots at the moment.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11199 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Feb 24, 2012
1 parent 1f1b1f1 commit 622864f
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 11 deletions.
18 changes: 12 additions & 6 deletions OMNotebook/OMNotebookGUI/OMNotebookGUI.pro
Expand Up @@ -4,7 +4,7 @@
# Adrian Pop [adrpo@ida.liu.se] 2008-10-02
# Adeel Asghar [adrpo@ida.liu.se] 2011-03-05

QT += network core gui xml
QT += network core gui xml svg

TARGET = OMNotebook
TEMPLATE = app
Expand Down Expand Up @@ -61,7 +61,8 @@ SOURCES += \
../OMSketch/Draw_Ellipse.cpp \
../OMSketch/Draw_Arrow.cpp \
../OMSketch/Draw_Arc.cpp \
../OMSketch/CustomDailog.cpp
../OMSketch/CustomDailog.cpp \
../../OMEdit/OMEditGUI/StringHandler.cpp

HEADERS += \
omc_communication.h \
Expand Down Expand Up @@ -140,7 +141,8 @@ HEADERS += \
../OMSketch/Draw_Arrow.h \
../OMSketch/Draw_Arc.h \
../OMSketch/CustomDialog.h \
../OMSketch/basic.h
../OMSketch/basic.h \
../../OMEdit/OMEditGUI/StringHandler.h

FORMS += ImageSizeDlg.ui \
OtherDlg.ui \
Expand All @@ -155,14 +157,20 @@ win32 {
CORBAINC = $$(OMDEV)/lib/omniORB-4.1.4-mingw/include
CORBALIBS = -L$$(OMDEV)/lib/omniORB-4.1.4-mingw/lib/x86_win32 -lomniORB414_rt -lomnithread34_rt
USE_CORBA = USE_OMNIORB
PLOTLIBS = -L$$(OMDEV)/lib/qwt-5.2.1-mingw/lib -lqwt5 \
-L../../OMPlot/bin -lOMPlot
PLOTINC = $$(OMDEV)/lib/qwt-5.2.1-mingw/include \
../../OMPlot/OMPlotGUI
} else {
include(OMNotebook.config)
}
#---------End OMNIorb

DEFINES += $${USE_CORBA}
LIBS += $${CORBALIBS}
LIBS += $${CORBALIBS} \
$${PLOTLIBS}
INCLUDEPATH += $${CORBAINC} \
$${PLOTINC} \
../OMSketch \
../../

Expand All @@ -181,5 +189,3 @@ MOC_DIR = ../generatedfiles/moc
RCC_DIR = ../generatedfiles/rcc

CONFIG += warn_off


100 changes: 96 additions & 4 deletions OMNotebook/OMNotebookGUI/graphcell.cpp
Expand Up @@ -75,6 +75,9 @@
#include "indent.h"

#include "evalthread.h"
#include "../../OMEdit/OMEditGUI/StringHandler.h"

using namespace OMPlot;

namespace IAEX {
/*!
Expand Down Expand Up @@ -504,7 +507,7 @@ namespace IAEX {
*/
GraphCell::GraphCell(Document *doc, QWidget *parent) :
Cell(parent), evaluated_(false), closed_(true), delegate_(0),
oldHeight_( 0 ), document_(doc)
oldHeight_( 0 ), document_(doc), mpPlotWindow(0)
{
QWidget *main = new QWidget(this);
setMainWidget(main);
Expand All @@ -520,6 +523,7 @@ namespace IAEX {

createGraphCell();
createOutputCell();
createPlotWindow();

connect(input_, SIGNAL(showVariableButton(bool)), this, SLOT(showVariableButton(bool)));

Expand Down Expand Up @@ -555,6 +559,7 @@ namespace IAEX {
break;
}

delete mpPlotWindow;
delete input_;
delete output_;
if(imageFile)
Expand Down Expand Up @@ -678,6 +683,14 @@ namespace IAEX {
output_->hide();
}

void GraphCell::createPlotWindow()
{
mpPlotWindow = new PlotWindow();
mpPlotWindow->setMinimumHeight(400);
layout_->addWidget( mpPlotWindow, 3, 1 /*, Qt::AlignHCenter*/);
mpPlotWindow->hide();
}

bool MyTextEdit2::lessIndented(QString s)
{
QRegExp l("\\b(equation|algorithm|public|protected|else|elseif)\\b");
Expand Down Expand Up @@ -1238,6 +1251,11 @@ namespace IAEX {
height += outHeight;
}

if(mpPlotWindow && mpPlotWindow->isVisible())
{
height += mpPlotWindow->height();
}

setHeight( height );
emit textChanged();

Expand Down Expand Up @@ -1308,7 +1326,26 @@ namespace IAEX {
return true;
else
return false;
}
}

QString GraphCell::getQtPlot(QString text)
{
QRegExp exp("plot[ ]*\\(.*\\)|plotParametric[ ]*\\(.*\\)|plotAll[ ]*\\(.*\\)" );

if( text.isNull() )
{
if( 0 <= input_->toPlainText().indexOf( exp, 0 ) )
return exp.cap(0);
else
return "";
}
else
{
if( 0 <= text.indexOf( exp, 0 ) )
return exp.cap(0);
else
return "";
}
}

Expand Down Expand Up @@ -1339,6 +1376,26 @@ namespace IAEX {
}
}

void GraphCell::plotVariables(QStringList lst)
{
try
{
// clear any curves if we have.
foreach (PlotCurve *pPlotCurve, mpPlotWindow->getPlot()->getPlotCurvesList())
{
mpPlotWindow->getPlot()->removeCurve(pPlotCurve);
pPlotCurve->detach();
}
mpPlotWindow->initializePlot(lst);
mpPlotWindow->fitInView();
mpPlotWindow->getPlot()->getPlotZoomer()->setZoomBase(false);
}
catch (PlotException &e)
{
QMessageBox::warning( 0, "Error", e.what(), "OK" );
}
}

/*!
* \author Ingemar Axelsson and Anders Fernström
* \date 2006-04-18 (update)
Expand Down Expand Up @@ -1417,8 +1474,19 @@ namespace IAEX {

if(newPlot)
{
mpPlotWindow->show();
setClosed(false);
}
// make the plot command silent i.e don't pop-up the OMPlot window.
QString plotCmd = getQtPlot(input_->toPlainText());
QString plotArgs = plotCmd.mid(plotCmd.indexOf("(")+1);
plotArgs = plotArgs.left(plotArgs.lastIndexOf(")"));
QString newPlotCmd = plotCmd.left(plotCmd.lastIndexOf(")"));
if (plotArgs.trimmed().length() > 0)
newPlotCmd = newPlotCmd.append(",silent=true)");
else
newPlotCmd = newPlotCmd.append("silent=true)");
expr.replace(plotCmd, newPlotCmd, Qt::CaseInsensitive);
}

// 2006-02-02 AF, Added try-catch
QString res, error;
Expand All @@ -1441,7 +1509,7 @@ namespace IAEX {
// they appear in the notebook, otherwise a simulate command
// might finish later than a plot!
EvalThread* et = new EvalThread(getDelegate(), expr);
connect(et, SIGNAL(finished()), this, SLOT(delegateFinished()));
connect(et, SIGNAL(finished()), this, SLOT(delegateFinished()));
et->start();
if (!newPlot) { et->wait(); }
}
Expand All @@ -1467,8 +1535,32 @@ namespace IAEX {
QString error = et->getError();

delete sender();

guard->unlock();
// if the result is one the plot commands output.
QStringList resLst = StringHandler::unparseStrings(res);
if (resLst.size() > 0)
{
if (resLst.at(0).compare("_omc_PlotResult") == 0)
{
plotVariables(resLst);
res = tr("");
}
}
// if user has mixed plot command with other OMC commands.
// we must extract the plot command result.
else if (res.contains("_omc_PlotResult"))
{
QString plotResult = res.mid(res.indexOf("_omc_PlotResult"));
plotResult.prepend("{\"");
QStringList resLst = StringHandler::unparseStrings(plotResult);
if (resLst.size() > 0)
{
if (resLst.at(0).compare("_omc_PlotResult") == 0)
{
plotVariables(resLst);
}
}
}

if( res.isEmpty() && (error.isEmpty() || error.size() == 0) )
{
Expand Down
6 changes: 5 additions & 1 deletion OMNotebook/OMNotebookGUI/graphcell.h
Expand Up @@ -52,6 +52,7 @@
//#include "highlighter.h"
#include "document.h"
//#include <QToolBar>
#include "PlotWindow.h"

class IndentationState;

Expand Down Expand Up @@ -87,8 +88,10 @@ namespace IAEX
virtual bool isEditable();
virtual bool isEvaluated(); // Added 2005-11-23 AF
virtual bool isQtPlot(QString text = QString::null);
virtual QString getQtPlot(QString text = QString::null);
virtual bool isVisualize(QString text = QString::null);

void plotVariables(QStringList lst);

signals:
void heightChanged();
Expand Down Expand Up @@ -144,8 +147,8 @@ namespace IAEX
private:
void createGraphCell();
void createOutputCell();
void createPlotWindow();

void createCompoundWidget();
void createChapterCounter();
void exceptionInEval(exception &e); // Added 2006-02-02 AF
void setOutputStyle(); // Added 2006-04-21 AF
Expand All @@ -166,6 +169,7 @@ namespace IAEX
Document *document_;

public:
OMPlot::PlotWindow *mpPlotWindow;
QPushButton* variableButton;
QTemporaryFile* imageFile;
};
Expand Down

0 comments on commit 622864f

Please sign in to comment.