Skip to content

Commit

Permalink
Refs #9051. Update plotting code to use the new option
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbekasov committed Mar 6, 2014
1 parent 4b41215 commit 8df6af6
Showing 1 changed file with 46 additions and 16 deletions.
62 changes: 46 additions & 16 deletions Code/Mantid/MantidQt/CustomInterfaces/src/MuonAnalysis.cpp
Expand Up @@ -2043,28 +2043,58 @@ QStringList MuonAnalysis::getPeriodLabels() const
*/
void MuonAnalysis::plotSpectrum(const QString& wsName, bool logScale)
{
// Get plotting params
const QMap<QString, QString>& params = getPlotStyleParams(wsName);
// List of script lines which acquire a window for plotting. The window is placed to Python
// variable named 'w';'
QStringList acquireWindowScript;

NewPlotPolicy policy = newPlotPolicy();

if ( policy == PreviousWindow )
{
QStringList& s = acquireWindowScript; // To keep short

s << "ew = graph('%WSNAME%-1')";
s << "if '%WSNAME%' != '%PREV%' and ew != None:";
s << " ew.close()";

s << "pw = graph('%PREV%-1')";
s << "if pw == None:";
s << " pw = newGraph('%WSNAME%-1', 0)";

s << "w = plotSpectrum('%WSNAME%', 0, %ERRORS%, %CONNECT%, window = pw, clearWindow = True)";
s << "w.setName('%WSNAME%-1')";
s << "w.setObjectName('%WSNAME%')";
s << "w.show()";
s << "w.setFocus()";
}
else if ( policy == NewWindow )
{
QStringList& s = acquireWindowScript; // To keep short

s << "w = graph('%WSNAME%-1')";
s << "if w == None:";
s << " w = plotSpectrum('%WSNAME%', 0, %ERRORS%, %CONNECT%)";
s << " w.setObjectName('%WSNAME%')";
s << "else:";
s << " plotSpectrum('%WSNAME%', 0, %ERRORS%, %CONNECT%, window = w, clearWindow = True)";
s << " w.show()";
s << " w.setFocus()";
}

QString pyS;

// Try to find existing graph window
pyS = "w = graph('%1-1')\n";
// Add line separators
pyS += acquireWindowScript.join("\n") + "\n";

// If doesn't exist - plot it
pyS += "if w == None:\n"
" w = plotSpectrum('%1', 0, %2, %3)\n"
" w.setObjectName('%1')\n";
// Get plotting params
const QMap<QString, QString>& params = getPlotStyleParams(wsName);

// If plot does exist already, it should've just been updated automatically, so we just
// need to make sure it is visible
pyS += "else:\n"
" plotSpectrum('%1', 0, %2, %3, window = w, clearWindow = True)\n"
" w.show()\n"
" w.setFocus()\n";
// Insert real values
pyS.replace("%WSNAME%", wsName);
pyS.replace("%PREV%", m_currentDataName);
pyS.replace("%ERRORS%", params["ShowErrors"]);
pyS.replace("%CONNECT%", params["ConnectType"]);

pyS = pyS.arg(wsName).arg(params["ShowErrors"]).arg(params["ConnectType"]);

// Update titles
pyS += "l = w.activeLayer()\n"
"l.setCurveTitle(0, '%1')\n"
Expand Down

0 comments on commit 8df6af6

Please sign in to comment.