Skip to content

Commit

Permalink
Fix for bug #1705 #1706
Browse files Browse the repository at this point in the history
- Added the flag to set plot silent +plotSilent=true (if true then outputs the data instead of showing the OMPlot).
- Some fixes for OMNotebook plotting.
- Fixed the file saving issue.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11266 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Mar 2, 2012
1 parent cea7ec0 commit fb7c682
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 98 deletions.
3 changes: 3 additions & 0 deletions OMNotebook/OMNotebookGUI/cellapplication.cpp
Expand Up @@ -125,6 +125,9 @@ namespace IAEX
//Create a commandCenter.
cmdCenter_ = new CellCommandCenter(this);

// set the plot command silent in OMC
OmcInteractiveEnvironment::setPlotSilent(tr("true"));

// 2006-04-10 AF, use environment variable to find xml files
QString openmodelica = OmcInteractiveEnvironment::OpenModelicaHome();

Expand Down
92 changes: 5 additions & 87 deletions OMNotebook/OMNotebookGUI/graphcell.cpp
Expand Up @@ -1307,79 +1307,18 @@ namespace IAEX {
bool GraphCell::isEvaluated()
{
return evaluated_;
}

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

if( text.isNull() )
{
if( 0 <= input_->toPlainText().indexOf( exp, 0 ) )
return true;
else
return false;
}
else
{
if( 0 <= text.indexOf( exp, 0 ) )
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 "";
}
}
}

void GraphCell::setExpr(QString expr)
{
input_->setPlainText(expr);
}

bool GraphCell::isVisualize(QString text)
{
QRegExp exp( "visualize[ ]*\\((.*)" );


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

}
}

void GraphCell::plotVariables(QStringList lst)
{
try
{
mpPlotWindow->show();
// clear any curves if we have.
foreach (PlotCurve *pPlotCurve, mpPlotWindow->getPlot()->getPlotCurvesList())
{
Expand Down Expand Up @@ -1468,29 +1407,6 @@ namespace IAEX {
output_->update();
QCoreApplication::processEvents();

// remove plot.png if it already exist, don't want any
// old plot.
bool newPlot = isQtPlot(input_->toPlainText());

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;

// 2005-11-24 AF, added check to see if the user wants to quit
if( 0 == expr.indexOf( "quit()", 0, Qt::CaseSensitive ))
{
Expand All @@ -1511,7 +1427,6 @@ namespace IAEX {
EvalThread* et = new EvalThread(getDelegate(), expr);
connect(et, SIGNAL(finished()), this, SLOT(delegateFinished()));
et->start();
if (!newPlot) { et->wait(); }
}
catch( exception &e )
{
Expand Down Expand Up @@ -1545,6 +1460,7 @@ namespace IAEX {
plotVariables(resLst);
res = tr("");
}
else { mpPlotWindow->hide(); }
}
// if user has mixed plot command with other OMC commands.
// we must extract the plot command result.
Expand All @@ -1559,8 +1475,10 @@ namespace IAEX {
{
plotVariables(resLst);
}
else { mpPlotWindow->hide(); }
}
}
else { mpPlotWindow->hide(); }

if( res.isEmpty() && (error.isEmpty() || error.size() == 0) )
{
Expand Down
3 changes: 0 additions & 3 deletions OMNotebook/OMNotebookGUI/graphcell.h
Expand Up @@ -87,9 +87,6 @@ namespace IAEX
virtual bool isClosed(); // Added 2006-01-17 AF
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);

Expand Down
2 changes: 1 addition & 1 deletion OMNotebook/OMNotebookGUI/notebook.cpp
Expand Up @@ -2865,7 +2865,7 @@ void NotebookWindow::saveas()
//window->insertImage(filename);
//window->SaveSketchImage(filename);

QMessageBox::about(this,"entered ","image witten ");
//QMessageBox::about(this,"entered ","image witten ");

statusBar()->showMessage("Saving file");
application()->commandCenter()->executeCommand(new SaveDocumentCommand(subject_, filename));
Expand Down
4 changes: 2 additions & 2 deletions OMNotebook/OMNotebookGUI/notebookcommands.h
Expand Up @@ -179,8 +179,8 @@ namespace IAEX
file.fileName().toStdString();
throw runtime_error( msg.c_str() );
}
if(file.exists() && (fileInfo.permission(QFile::WriteUser) != true))

if(file.exists() && (file.permissions().testFlag(QFile::WriteUser) != true))
{
string msg = "The file for saving the document is not writable: " +
file.fileName().toStdString() + "\nPlease use Save As.";
Expand Down
11 changes: 11 additions & 0 deletions OMNotebook/OMNotebookGUI/omcinteractiveenvironment.cpp
Expand Up @@ -280,6 +280,17 @@ namespace IAEX
return version;
}

bool OmcInteractiveEnvironment::setPlotSilent(QString silent)
{
OmcInteractiveEnvironment *env = OmcInteractiveEnvironment::getInstance();
env->evalExpression(QString("setPlotSilent("+silent+")"));
QString result = env->getResult();
if (result.toLower().compare("true") == 0)
return true;
else
return false;
}

QString OmcInteractiveEnvironment::OpenModelicaHome()
{
OmcInteractiveEnvironment *env = OmcInteractiveEnvironment::getInstance();
Expand Down
1 change: 1 addition & 0 deletions OMNotebook/OMNotebookGUI/omcinteractiveenvironment.h
Expand Up @@ -56,6 +56,7 @@ namespace IAEX
virtual bool startDelegate();
static bool startOMC();
static QString OMCVersion();
static bool setPlotSilent(QString silent);
static QString OpenModelicaHome();
static QString TmpPath();

Expand Down
6 changes: 1 addition & 5 deletions OMNotebook/OMNotebookGUI/xmlparser.cpp
Expand Up @@ -572,11 +572,7 @@ namespace IAEX
else if( e.tagName() == XML_OUTPUTPART )
{
GraphCell *iCell = dynamic_cast<GraphCell*>(graphcell);

if( iCell->isQtPlot() )
iCell->setTextOutputHtml( e.text() );
else
iCell->setTextOutput( e.text() );
iCell->setTextOutput( e.text() );
}
else if( e.tagName() == XML_IMAGE )
{
Expand Down

0 comments on commit fb7c682

Please sign in to comment.