Skip to content

Commit

Permalink
Re #6162. Fixes the instrument image disapearing
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Nov 28, 2012
1 parent efd2c14 commit 50160e8
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 32 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/MantidPlot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ set ( MANTID_HDRS src/Mantid/AbstractMantidLog.h
src/Mantid/MantidMDCurveDialog.h
src/Mantid/MantidMatrixDialog.h
src/Mantid/MantidMatrix.h
src/Mantid/MantidAlgorithmMetatype.h
src/Mantid/MantidSampleLogDialog.h
src/Mantid/MantidUI.h
src/Mantid/MantidWSIndexDialog.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ InstrumentWindow::InstrumentWindow(const QString& wsName, const QString& label,

tabChanged(0);

connect(this,SIGNAL(needSetIntegrationRange(double,double)),this,SLOT(setIntegrationRange(double,double)));
connect(this,SIGNAL(needSetIntegrationRange(double,double)),this,SLOT(setIntegrationRange(double,double)),Qt::QueuedConnection);
setAcceptDrops(true);

setWindowTitle(QString("Instrument - ") + m_workspaceName);
Expand Down Expand Up @@ -448,6 +448,7 @@ void InstrumentWindow::setSurfaceType(int type)
connect(surface,SIGNAL(singleDetectorTouched(int)),this,SLOT(singleDetectorTouched(int)));
connect(surface,SIGNAL(singleDetectorPicked(int)),this,SLOT(singleDetectorPicked(int)));
connect(surface,SIGNAL(multipleDetectorsSelected(QList<int>&)),this,SLOT(multipleDetectorsSelected(QList<int>&)));
connect(surface,SIGNAL(executeAlgorithm(Mantid::API::IAlgorithm_sptr)),this,SIGNAL(execMantidAlgorithm(Mantid::API::IAlgorithm_sptr)));
QApplication::restoreOverrideCursor();
}
update();
Expand Down Expand Up @@ -493,6 +494,8 @@ void InstrumentWindow::setSurfaceType(const QString& typeStr)
m_renderTab->m_renderMode->blockSignals(true);
m_renderTab->m_renderMode->setCurrentIndex( typeIndex );
m_renderTab->m_renderMode->blockSignals(false);
m_renderTab->showResetView( typeIndex );
m_renderTab->showFlipControl( typeIndex );
}

/**
Expand Down Expand Up @@ -1252,7 +1255,12 @@ void InstrumentWindow::createExcludeGroupingFile()

void InstrumentWindow::executeAlgorithm(const QString& alg_name, const QString& param_list)
{
emit execMantidAlgorithm(alg_name,param_list,this);
emit execMantidAlgorithm(alg_name,param_list,this);
}

void InstrumentWindow::executeAlgorithm(Mantid::API::IAlgorithm_sptr alg)
{
emit execMantidAlgorithm( alg );
}

/**
Expand Down Expand Up @@ -1400,7 +1408,7 @@ void InstrumentWindow::mouseLeftInstrumentDisplay()
void InstrumentWindow::clearPeakOverlays()
{
getSurface()->clearPeakOverlays();
m_InstrumentDisplay->repaint();
updateInstrumentView();
}

/**
Expand All @@ -1410,7 +1418,7 @@ void InstrumentWindow::clearPeakOverlays()
void InstrumentWindow::setPeakLabelPrecision(int n)
{
getSurface()->setPeakLabelPrecision(n);
m_InstrumentDisplay->repaint();
updateInstrumentView();
}

/**
Expand All @@ -1419,7 +1427,7 @@ void InstrumentWindow::setPeakLabelPrecision(int n)
void InstrumentWindow::setShowPeakRowFlag(bool on)
{
getSurface()->setShowPeakRowFlag(on);
m_InstrumentDisplay->repaint();
updateInstrumentView();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
#ifndef INSTRUMENTWINDOW_H_
#define INSTRUMENTWINDOW_H_

#include "../../MdiSubWindow.h"
#include "../MantidAlgorithmMetatype.h"

#include "MantidGLWidget.h"
#include "InstrumentTreeWidget.h"
#include "../../MdiSubWindow.h"
#include "MantidQtAPI/GraphOptions.h"
#include "BinDialog.h"

#include "MantidQtAPI/GraphOptions.h"
#include "MantidQtAPI/WorkspaceObserver.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/AlgorithmObserver.h"

#include <string>
#include <vector>

#include "qwt_scale_widget.h"
#include <Poco/NObserver.h>
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/AlgorithmObserver.h"

class InstrumentActor;
class OneCurvePlot;
Expand Down Expand Up @@ -134,6 +137,7 @@ public slots:
void groupDetectors();
void maskDetectors();
void executeAlgorithm(const QString&, const QString&);
void executeAlgorithm(Mantid::API::IAlgorithm_sptr);

void extractDetsToWorkspace();
void sumDetsToWorkspace();
Expand Down Expand Up @@ -168,6 +172,7 @@ public slots:
void plotSpectra(const QString&,const std::set<int>&);
void createDetectorTable(const QString&,const std::vector<int>&,bool);
void execMantidAlgorithm(const QString&,const QString&,Mantid::API::AlgorithmObserver*);
void execMantidAlgorithm(Mantid::API::IAlgorithm_sptr);
void needSetIntegrationRange(double,double);

private slots:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "CollapsiblePanel.h"
#include "InstrumentActor.h"
#include "ProjectionSurface.h"
#include "UnwrappedSurface.h"
#include "PeakMarker2D.h"

#include "MantidKernel/ConfigService.h"
Expand Down Expand Up @@ -715,6 +716,11 @@ void InstrumentWindowPickTab::addPeak(double x,double y)
tw = Mantid::API::WorkspaceFactory::Instance().createPeaks("PeaksWorkspace");
tw->setInstrument(instr);
Mantid::API::AnalysisDataService::Instance().add(peakTableName,tw);
UnwrappedSurface* surface = dynamic_cast<UnwrappedSurface*>( m_instrWindow->getSurface() );
if ( surface )
{
surface->setPeaksWorkspace(boost::dynamic_pointer_cast<Mantid::API::IPeaksWorkspace>(tw));
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,19 @@ private slots:
TubeXUnits getTubeXUnits(const QString& name) const;
QString getTubeXUnitsName(TubeXUnits unit) const;


/// The parent InstrumentWindow
InstrumentWindow* m_instrWindow;
MantidGLWidget *mInstrumentDisplay;

/* Pick tab controls */
OneCurvePlot* m_plot;
OneCurvePlot* m_plot; ///< Miniplot to display data in the detectors
QLabel *m_activeTool; ///< Displays a tip on which tool is currently selected
QPushButton *m_one; ///< Button switching on single detector selection mode
QPushButton *m_tube; ///< Button switching on detector's parent selection mode
QPushButton *m_box; ///< Button switching on box selection mode
QPushButton *m_peak; ///< Button switching on box selection mode
QPushButton *m_one; ///< Button switching on single detector selection mode
QPushButton *m_tube; ///< Button switching on detector's parent selection mode
QPushButton *m_box; ///< Button switching on box selection mode
QPushButton *m_peak; ///< Button switching on box selection mode
bool m_plotSum;

// Actions to set integration option for the detector's parent selection mode
QAction *m_sumDetectors; ///< Sets summation over detectors (m_plotSum = true)
QAction *m_integrateTimeBins; ///< Sets integration over time bins (m_plotSum = false)
Expand All @@ -104,6 +106,7 @@ private slots:
QActionGroup* m_unitsGroup;
QAction *m_detidUnits,*m_lengthUnits,*m_phiUnits;
QSignalMapper *m_unitsMapper;

// Instrument display context menu actions
QAction *m_storeCurve; ///< add the current curve to the list of permanently displayed curves
QAction *m_savePlotToWorkspace; ///< Save data plotted on the miniplot into a MatrixWorkspace
Expand Down
20 changes: 7 additions & 13 deletions Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/PeakOverlay.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "PeakOverlay.h"
#include "UnwrappedSurface.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/AlgorithmManager.h"

#include <QPainter>
#include <QList>
Expand Down Expand Up @@ -128,29 +128,20 @@ m_showRows(true)
*/
void PeakOverlay::removeShapes(const QList<Shape2D*>& shapeList)
{
std::cerr <<"ws " << m_peaksWorkspace->name() << std::endl;
std::cerr << "deleting:" << std::endl;
// vectors of rows to delete from the peaks workspace.
std::vector<size_t> rows;
foreach(Shape2D* shape, shapeList)
{
PeakMarker2D* marker = dynamic_cast<PeakMarker2D*>(shape);
if ( !marker ) throw std::logic_error("Wrong shape type found.");
int row = marker->getRow();
std::cerr << " " << row << std::endl;
rows.push_back( static_cast<size_t>( row ) );
if ( shape == m_currentShape )
{
m_currentShape = NULL;
}
removeShape( shape );
rows.push_back( static_cast<size_t>( marker->getRow() ) );
}

// Run the DeleteTableRows algorithm to delete the peak.
auto alg = Mantid::API::FrameworkManager::Instance().createAlgorithm("DeleteTableRows");
auto alg = Mantid::API::AlgorithmManager::Instance().create("DeleteTableRows",-1);
alg->setPropertyValue("TableWorkspace", m_peaksWorkspace->name());
alg->setProperty("Rows",rows);
alg->executeAsync();
emit executeAlgorithm(alg);
}

/**---------------------------------------------------------------------
Expand Down Expand Up @@ -181,6 +172,7 @@ void PeakOverlay::addMarker(PeakMarker2D* m)
void PeakOverlay::createMarkers(const PeakMarker2D::Style& style)
{
int nPeaks = getNumberPeaks();
this->clear();
for(int i = 0; i < nPeaks; ++i)
{
Mantid::API::IPeak& peak = getPeak(i);
Expand All @@ -205,6 +197,7 @@ void PeakOverlay::draw(QPainter& painter) const
{
// Draw symbols
Shape2DCollection::draw(painter);

// Sort the labels to avoid overlapping
QColor color(Qt::red);
if ( !m_shapes.isEmpty() )
Expand Down Expand Up @@ -233,6 +226,7 @@ void PeakOverlay::draw(QPainter& painter) const
{
PeakHKL& hkl = m_labels[i];
overlap = hkl.add(marker,rect);
if ( overlap ) break;
}

if (!overlap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "Shape2DCollection.h"
#include "PeakMarker2D.h"
#include "../MantidAlgorithmMetatype.h"

#include "MantidQtAPI/WorkspaceObserver.h"

Expand Down Expand Up @@ -71,6 +72,9 @@ class PeakOverlay: public Shape2DCollection, public MantidQt::API::WorkspaceObse
void setShowRowsFlag(bool yes) {m_showRows = yes;}
static PeakMarker2D::Style getDefaultStyle(int index);

signals:
void executeAlgorithm(Mantid::API::IAlgorithm_sptr);

private:
/// A WorkspaceObserver handle implemented.
virtual void afterReplaceHandle(const std::string& wsName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ void ProjectionSurface::draw(MantidGLWidget *widget,bool picking)const
delete (*image);
}
(*image) = new QImage(widget->grabFrameBuffer());
checkImage( *image );

if (!picking)
{
Expand All @@ -163,7 +162,6 @@ void ProjectionSurface::draw(MantidGLWidget *widget,bool picking)const
{
QPainter painter(widget);
painter.drawImage(0,0,**image);
checkImage( *image );

QRectF windowRect = getSurfaceBounds();
m_maskShapes.setWindow(windowRect,painter.viewport());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "InstrumentActor.h"
#include "Shape2DCollection.h"
#include "PeakOverlay.h"
#include "../MantidAlgorithmMetatype.h"

#include <QImage>
#include <QList>
Expand Down Expand Up @@ -191,9 +192,10 @@ class ProjectionSurface: public QObject
void shapeSelected();
void shapesDeselected();
void shapeChanged();

void redrawRequired();

void executeAlgorithm(Mantid::API::IAlgorithm_sptr);

protected slots:

void colorMapChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class Shape2DCollection: public QObject, public Shape2D
bool isEmpty()const{return m_shapes.isEmpty();}
size_t size()const {return static_cast<size_t>(m_shapes.size());}
void select(int i);
QList<Shape2D*> getSelectedShapes() const;

QRectF getCurrentBoundingRect()const;
void setCurrentBoundingRect(const QRectF& rect);
Expand Down Expand Up @@ -102,6 +101,7 @@ class Shape2DCollection: public QObject, public Shape2D
bool selectControlPointAt(int x,int y);
bool isOverCurrentAt(int x,int y);
void select(Shape2D* shape);
QList<Shape2D*> getSelectedShapes() const;

QList<Shape2D*> m_shapes;
mutable QRectF m_windowRect; // original surface window in "real" coordinates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ void UnwrappedSurface::setPeaksWorkspace(boost::shared_ptr<Mantid::API::IPeaksWo
po->setShowRowsFlag(m_showPeakRow);
m_peakShapes.append(po);
m_startPeakShapes = true;
connect(po,SIGNAL(executeAlgorithm(Mantid::API::IAlgorithm_sptr)),this,SIGNAL(executeAlgorithm(Mantid::API::IAlgorithm_sptr)));
}

//-----------------------------------------------------------------------------
Expand Down
16 changes: 16 additions & 0 deletions Code/Mantid/MantidPlot/src/Mantid/MantidAlgorithmMetatype.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef MANTIDALGORITHMMETATYPE_H
#define MANTIDALGORITHMMETATYPE_H

#include "MantidAPI/Algorithm.h"
#include <QMetaType>

/**
Declare Qt metatype for IAlgorithm_sptr to allow its direct use with signals and slots.
*/

Q_DECLARE_METATYPE(Mantid::API::IAlgorithm_sptr)


#endif /* MANTIDALGORITHMMETATYPE_H */
11 changes: 11 additions & 0 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,15 @@ void MantidUI::executeAlgorithmDlg(QString algName, QMap<QString,QString> paramL
executeAlgorithm(dlg,alg);
}

/**
* Slot for executing an algorithm.
* @param alg :: Shared pointer to an algorithm to execute with all properties already set.
*/
void MantidUI::executeAlgorithm(Mantid::API::IAlgorithm_sptr alg)
{
executeAlgorithmAsync(alg);
}

/**
* Find the first input workspace for an algorithm
* @param algorithm :: A pointer to the algorithm instance
Expand Down Expand Up @@ -1888,6 +1897,8 @@ InstrumentWindow* MantidUI::getInstrumentView(const QString & wsName, int tab)
SLOT(createDetectorTable(const QString&,const std::vector<int>&,bool)));
connect(insWin, SIGNAL(execMantidAlgorithm(const QString&,const QString&,Mantid::API::AlgorithmObserver*)), this,
SLOT(executeAlgorithm(const QString&, const QString&,Mantid::API::AlgorithmObserver*)));
connect(insWin, SIGNAL(execMantidAlgorithm(Mantid::API::IAlgorithm_sptr)), this,
SLOT(executeAlgorithm(Mantid::API::IAlgorithm_sptr)));

QApplication::restoreOverrideCursor();
return insWin;
Expand Down
3 changes: 3 additions & 0 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../ApplicationWindow.h"
#include "../Graph.h"
#include "MantidLog.h"
#include "MantidAlgorithmMetatype.h"

#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/Algorithm.h"
Expand Down Expand Up @@ -380,6 +381,8 @@ public slots:
void executeAlgorithm(QString algName, QMap<QString,QString> paramList,Mantid::API::AlgorithmObserver* obs = NULL);
//Execute an algorithm with the given parameter list
void executeAlgorithmDlg(QString algName, QMap<QString,QString> paramList,Mantid::API::AlgorithmObserver* obs = NULL);
// Execute an algorithm
void executeAlgorithm(Mantid::API::IAlgorithm_sptr alg);
// Find the name of the first input workspace for an algorithm
QString findInputWorkspaceProperty(Mantid::API::IAlgorithm_sptr algorithm) const;
// Show Qt critical error message box
Expand Down

0 comments on commit 50160e8

Please sign in to comment.