Skip to content

Commit

Permalink
Re #6162. Sorted out the shapes transformations.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Jan 3, 2013
1 parent 45f3601 commit e9551b5
Show file tree
Hide file tree
Showing 19 changed files with 135 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,14 @@ void InstrumentActor::initMaskHelper() const
}
}

/**
* Checks if the actor has a mask workspace attached.
*/
bool InstrumentActor::hasMaskWorkspace() const
{
return m_maskWorkspace ? true : false;
}

/**
* Find a rotation from one orthonormal basis set (Xfrom,Yfrom,Zfrom) to
* another orthonormal basis set (Xto,Yto,Zto). Both sets must be right-handed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class InstrumentActor: public QObject, public GLActor
/* Masking */

void initMaskHelper() const;
bool hasMaskWorkspace() const;
signals:
void colorMapChanged();
protected:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ void InstrumentWindow::tabChanged(int)
auto surface = getSurface();
if ( !surface ) return;
setInfoText(surface->getInfoText());
updateInstrumentView();
//updateInstrumentView();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ void InstrumentWindowMaskTab::initSurface()
connect(m_instrWindow->getSurface().get(),SIGNAL(shapeSelected()),this,SLOT(shapeSelected()));
connect(m_instrWindow->getSurface().get(),SIGNAL(shapesDeselected()),this,SLOT(shapesDeselected()));
connect(m_instrWindow->getSurface().get(),SIGNAL(shapeChanged()),this,SLOT(shapeChanged()));
enableApply( m_instrWindow->getSurface()->hasMasks() );
bool hasMasks = m_instrWindow->getSurface()->hasMasks();
enableApply( hasMasks );
enableClear( hasMasks || m_instrWindow->getInstrumentActor()->hasMaskWorkspace() );
}

void InstrumentWindowMaskTab::setActivity()
Expand Down Expand Up @@ -222,6 +224,7 @@ void InstrumentWindowMaskTab::shapeCreated()
{
setSelectActivity();
enableApply(true);
enableClear(true);
}

void InstrumentWindowMaskTab::shapeSelected()
Expand All @@ -240,9 +243,9 @@ void InstrumentWindowMaskTab::shapeChanged()
m_userEditing = false; // this prevents resetting shape proeprties by doubleChanged(...)
RectF rect = m_instrWindow->getSurface()->getCurrentBoundingRect();
m_doubleManager->setValue(m_left,rect.x0());
m_doubleManager->setValue(m_top,rect.y0());
m_doubleManager->setValue(m_top,rect.y1());
m_doubleManager->setValue(m_right,rect.x1());
m_doubleManager->setValue(m_bottom,rect.y1());
m_doubleManager->setValue(m_bottom,rect.y0());
for(QMap<QtProperty *,QString>::iterator it = m_doublePropertyMap.begin(); it != m_doublePropertyMap.end(); ++it)
{
m_doubleManager->setValue(it.key(),m_instrWindow->getSurface()->getCurrentDouble(it.value()));
Expand Down Expand Up @@ -271,7 +274,9 @@ void InstrumentWindowMaskTab::showEvent (QShowEvent *)
{
setActivity();
m_instrWindow->setMouseTracking(true);
enableApply( m_instrWindow->getSurface()->hasMasks() );
bool hasMasks = m_instrWindow->getSurface()->hasMasks();
enableApply( hasMasks );
enableClear( hasMasks || m_instrWindow->getInstrumentActor()->hasMaskWorkspace() );
}

void InstrumentWindowMaskTab::clearProperties()
Expand Down Expand Up @@ -371,6 +376,7 @@ void InstrumentWindowMaskTab::applyMask()
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
m_instrWindow->getInstrumentActor()->applyMaskWorkspace();
enableApply(false);
enableClear(false);
QApplication::restoreOverrideCursor();
}

Expand All @@ -383,6 +389,7 @@ void InstrumentWindowMaskTab::clearMask()
m_instrWindow->getInstrumentActor()->clearMaskWorkspace();
m_instrWindow->updateInstrumentView();
enableApply(false);
enableClear(false);
}

/**
Expand Down Expand Up @@ -522,12 +529,19 @@ std::string InstrumentWindowMaskTab::generateMaskWorkspaceName(bool temp) const

/**
* Sets the m_hasMaskToApply flag and
* enables/disables the Apply and ClearAll buttons.
* enables/disables the Apply button.
*/
void InstrumentWindowMaskTab::enableApply(bool on)
{
m_hasMaskToApply = on;
m_apply->setEnabled(on);
}

/**
* Enables/disables the ClearAll button.
*/
void InstrumentWindowMaskTab::enableClear(bool on)
{
m_clear_all->setEnabled(on);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ protected slots:
void saveMaskingToFile(bool invertMask = false);
std::string generateMaskWorkspaceName(bool temp = false) const;
void enableApply(bool on);
void enableClear(bool on);
void setSelectActivity();

/// Is it used?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ void InstrumentWindowPickTab::setSelectionType()
if ( surface )
{
surface->setInteractionMode( surfaceMode );
m_instrWindow->updateInstrumentView();
//m_instrWindow->updateInstrumentView();
}
m_plot->clearAll();
m_plot->replot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "InstrumentWindowTreeTab.h"
#include "InstrumentTreeWidget.h"
#include "InstrumentActor.h"
#include "ProjectionSurface.h"

InstrumentWindowTreeTab::InstrumentWindowTreeTab(InstrumentWindow* instrWindow):
InstrumentWindowTab(instrWindow)
Expand Down Expand Up @@ -47,6 +48,8 @@ void InstrumentWindowTreeTab::hideEvent(QHideEvent *)
if ( actor )
{
actor->accept(SetAllVisibleVisitor());
getSurface()->updateView();
getSurface()->requestRedraw();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ void MantidGLWidget::componentSelected(Mantid::Geometry::ComponentID id)
{
m_surface->componentSelected(id);
m_surface->updateView();
repaint();
update();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ m_row(-1)
m_boundingRect = RectF(centre - QPointF((qreal)m_markerSize/2,(qreal)m_markerSize/2),
QSizeF((qreal)m_markerSize,(qreal)m_markerSize));
setScalable(false);
std::cerr << "Centre " << centre.x() << ' ' << centre.y() << std::endl;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ void PeakOverlay::draw(QPainter& painter) const
if (!marker) continue;

QPointF p0 = marker->origin();
std::cerr << p0.x() << ' ' << p0.y() << std::endl;
QPointF p1 = m_transform.map(p0);
QRectF rect = marker->getLabelRect();
QPointF dp = rect.topLeft() - p0;
Expand Down Expand Up @@ -246,7 +245,7 @@ void PeakOverlay::draw(QPainter& painter) const
{
PeakHKL& hkl = m_labels[i];
hkl.draw(painter,m_precision);
hkl.print();
//hkl.print();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ void Projection3D::drawSurface(MantidGLWidget*,bool picking)const

QApplication::setOverrideCursor(Qt::WaitCursor);

if (m_viewChanged)
{
m_viewChanged = false;
}
m_instrActor->draw(picking);
OpenGLError::check("GL3DWidget::draw3D()[scene draw] ");

Expand Down Expand Up @@ -415,7 +411,7 @@ void Projection3D::translate(int x, int y)
{
m_trackball->generateTranslationTo( x, y );
m_trackball->initTranslateFrom( x, y );
m_viewChanged = true;
updateView();
}

/**
Expand All @@ -437,7 +433,7 @@ void Projection3D::zoom(int x, int y)
{
m_trackball->generateZoomTo( x, y );
m_trackball->initZoomFrom( x, y );
m_viewChanged = true;
updateView();
}

/**
Expand All @@ -449,7 +445,7 @@ void Projection3D::wheelZoom(int x, int y, int d)
{
m_trackball->initZoomFrom( x, y );
m_trackball->generateZoomTo( x, y - d );
m_viewChanged = true;
updateView();
}

/**
Expand All @@ -471,7 +467,7 @@ void Projection3D::rotate(int x, int y)
{
m_trackball->generateRotationTo( x, y );
m_trackball->initRotationFrom( x, y );
m_viewChanged = true;
updateView();
}

RectF Projection3D::getSurfaceBounds()const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ ProjectionSurface::ProjectionSurface(const InstrumentActor* rootActor,const Mant
m_zaxis(axis),
m_viewImage(NULL),
m_pickImage(NULL),
m_viewChanged(true),
m_viewRect(),
m_selectRect(),
m_interactionMode(MoveMode),
m_peakLabelPrecision(6),
m_peakShapesStyle(0)
m_peakShapesStyle(0),
m_viewChanged(true)
{
connect(rootActor,SIGNAL(colorMapChanged()),this,SLOT(colorMapChanged()));
connect(&m_maskShapes,SIGNAL(shapeCreated()),this,SLOT(catchShapeCreated()));
Expand Down Expand Up @@ -126,21 +126,14 @@ void ProjectionSurface::clear()
*/
void ProjectionSurface::draw(MantidGLWidget *widget)const
{
if (getInteractionMode() == PickMode)
if ( m_viewChanged )
{
bool changed = m_viewChanged;
draw(widget,true);
m_viewChanged = changed;
draw(widget,false);
draw(widget,true);
}
else
draw(widget,false);
if ( m_viewChanged )
{
draw(widget,false);
if (m_pickImage)
{
delete m_pickImage;
m_pickImage = NULL;
}
m_viewChanged = false;
}
}

Expand Down Expand Up @@ -182,8 +175,6 @@ void ProjectionSurface::draw(MantidGLWidget *widget,bool picking)const
}
painter.end();
}
m_viewChanged = false;

}
else if (!picking)
{
Expand Down Expand Up @@ -226,24 +217,12 @@ void ProjectionSurface::drawSimple(QWidget* widget)const
{
if ( m_viewImage ) delete m_viewImage;
m_viewImage = new QImage(widget->width(), widget->height(),QImage::Format_RGB32);
}

if (getInteractionMode() == MoveMode)
{
drawSimpleToImage(m_viewImage,false);
if (m_pickImage)
{
delete m_pickImage;
m_pickImage = NULL;
}
}
else
{
if (m_pickImage) delete m_pickImage;
m_pickImage = new QImage(widget->width(), widget->height(),QImage::Format_RGB32);
drawSimpleToImage(m_pickImage,true);
drawSimpleToImage(m_viewImage,false);
}

drawSimpleToImage(m_pickImage,true);
drawSimpleToImage(m_viewImage,false);
m_viewChanged = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ protected slots:
Mantid::Kernel::V3D m_yaxis; ///< The y axis
mutable QImage* m_viewImage; ///< storage for view image
mutable QImage* m_pickImage; ///< storage for picking image
mutable bool m_viewChanged; ///< set when the image must be redrawn
QColor m_backgroundColor; ///< The background colour
RectF m_viewRect; ///< Keeps the physical dimensions of the surface
QRect m_selectRect;
Expand All @@ -260,7 +259,10 @@ protected slots:
private:
/// Get the current input controller
InputController* getController() const;

QMap<int,InputController*> m_inputControllers; ///< controllers for mouse and keyboard input
/// Set when the image must be redrawn
mutable bool m_viewChanged;
};

typedef boost::shared_ptr<ProjectionSurface> ProjectionSurface_sptr;
Expand Down
3 changes: 1 addition & 2 deletions Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/RectF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ void RectF::findTransform(QTransform& trans, const QRectF& rect)
double m11 = rect.width() / xSpan();
double m22 = -rect.height() / ySpan();
trans.reset();
trans.translate(rect.left(), rect.bottom());
trans.translate(rect.left() - m11 * x0(), rect.bottom() - m22 * y0());
trans.scale(m11, m22);
trans = trans.inverted();
}

void RectF::include(const QPointF &p)
Expand Down

0 comments on commit e9551b5

Please sign in to comment.