Commit 72284d1f authored by Samuel Jackson's avatar Samuel Jackson
Browse files

Refs #18120 Refactor and fix selection bug

parent ce07e6ed
...@@ -349,10 +349,9 @@ protected: ...@@ -349,10 +349,9 @@ protected:
bool m_showPeakRelativeIntensity; ///< flag to show peak hkl labels bool m_showPeakRelativeIntensity; ///< flag to show peak hkl labels
mutable int m_peakShapesStyle; ///< index of a default PeakMarker2D style to mutable int m_peakShapesStyle; ///< index of a default PeakMarker2D style to
std::vector<Mantid::Kernel::V3D> m_selectedAlignmentPlane; std::vector<std::pair<Mantid::Kernel::V3D, QPointF>> m_selectedAlignmentPlane;
std::vector<QPointF> m_selectedAlignmentMarkers; std::pair<Mantid::Geometry::IPeak *, QPointF> m_selectedAlignmentPeak;
Mantid::Geometry::IPeak *m_selectedAlignmentPeak;
QPointF m_selectedAlignmentPeakPosition;
std::pair<std::vector<Mantid::Geometry::IPeak *>, std::pair<std::vector<Mantid::Geometry::IPeak *>,
std::vector<Mantid::Geometry::IPeak *>> m_selectedPeaks; std::vector<Mantid::Geometry::IPeak *>> m_selectedPeaks;
std::pair<QPointF, QPointF> m_selectedMarkers; std::pair<QPointF, QPointF> m_selectedMarkers;
......
...@@ -57,6 +57,7 @@ public: ...@@ -57,6 +57,7 @@ public:
bool selectAtXY(int x, int y, bool edit = true); bool selectAtXY(int x, int y, bool edit = true);
bool selectAtXY(const QPointF &point, bool edit = true); bool selectAtXY(const QPointF &point, bool edit = true);
void deselectAtXY(int x, int y); void deselectAtXY(int x, int y);
void deselectAtXY(const QPointF &point);
bool selectIn(const QRect &rect); bool selectIn(const QRect &rect);
void removeCurrentShape(); void removeCurrentShape();
bool isEmpty() const { return m_shapes.isEmpty(); } bool isEmpty() const { return m_shapes.isEmpty(); }
......
...@@ -40,8 +40,7 @@ ProjectionSurface::ProjectionSurface(const InstrumentActor *rootActor) ...@@ -40,8 +40,7 @@ ProjectionSurface::ProjectionSurface(const InstrumentActor *rootActor)
m_viewRect(), m_selectRect(), m_interactionMode(MoveMode), m_viewRect(), m_selectRect(), m_interactionMode(MoveMode),
m_isLightingOn(false), m_peakLabelPrecision(2), m_showPeakRows(false), m_isLightingOn(false), m_peakLabelPrecision(2), m_showPeakRows(false),
m_showPeakLabels(false), m_showPeakRelativeIntensity(false), m_showPeakLabels(false), m_showPeakRelativeIntensity(false),
m_peakShapesStyle(0), m_selectedAlignmentPeak(nullptr), m_peakShapesStyle(0), m_viewChanged(true), m_redrawPicking(true) {
m_viewChanged(true), m_redrawPicking(true) {
connect(rootActor, SIGNAL(colorMapChanged()), this, SLOT(colorMapChanged())); connect(rootActor, SIGNAL(colorMapChanged()), this, SLOT(colorMapChanged()));
connect(&m_maskShapes, SIGNAL(shapeCreated()), this, SIGNAL(shapeCreated())); connect(&m_maskShapes, SIGNAL(shapeCreated()), this, SIGNAL(shapeCreated()));
connect(&m_maskShapes, SIGNAL(shapeSelected()), this, connect(&m_maskShapes, SIGNAL(shapeSelected()), this,
...@@ -545,6 +544,7 @@ bool ProjectionSurface::peakVisibleAtPoint(const QPointF &point) const { ...@@ -545,6 +544,7 @@ bool ProjectionSurface::peakVisibleAtPoint(const QPointF &point) const {
for (const auto po : m_peakShapes) { for (const auto po : m_peakShapes) {
po->selectAtXY(point); po->selectAtXY(point);
auto markers = po->getSelectedPeakMarkers(); auto markers = po->getSelectedPeakMarkers();
po->deselectAtXY(point);
visible = visible =
std::any_of(markers.begin(), markers.end(), std::any_of(markers.begin(), markers.end(),
[](PeakMarker2D *marker) { return marker->isVisible(); }); [](PeakMarker2D *marker) { return marker->isVisible(); });
...@@ -626,18 +626,20 @@ void ProjectionSurface::drawPeakAlignmentMarkers(QPainter &painter) const { ...@@ -626,18 +626,20 @@ void ProjectionSurface::drawPeakAlignmentMarkers(QPainter &painter) const {
auto windowRect = getSurfaceBounds(); auto windowRect = getSurfaceBounds();
windowRect.findTransform(transform, painter.viewport()); windowRect.findTransform(transform, painter.viewport());
auto outOfPlanePoint = m_selectedAlignmentPeak.second;
// draw the 4th peak in a different colour // draw the 4th peak in a different colour
if (!m_selectedAlignmentPeakPosition.isNull()) { if (!outOfPlanePoint.isNull()) {
painter.setPen(Qt::green); painter.setPen(Qt::green);
auto point = transform.map(m_selectedAlignmentPeakPosition); auto point = transform.map(outOfPlanePoint);
painter.drawEllipse(point, 8, 8); painter.drawEllipse(point, 8, 8);
} }
// draw highlight around the first three peaks // draw highlight around the first three peaks
QPolygonF poly; QPolygonF poly;
painter.setPen(Qt::blue); painter.setPen(Qt::blue);
for (auto &origin : m_selectedAlignmentMarkers) { for (auto &item : m_selectedAlignmentPlane) {
if(origin != m_selectedAlignmentPeakPosition) { auto origin = item.second;
if (origin != outOfPlanePoint) {
auto point = transform.map(origin); auto point = transform.map(origin);
painter.drawEllipse(point, 8, 8); painter.drawEllipse(point, 8, 8);
} }
...@@ -751,9 +753,7 @@ void ProjectionSurface::clearPeakOverlays() { ...@@ -751,9 +753,7 @@ void ProjectionSurface::clearPeakOverlays() {
*/ */
void ProjectionSurface::clearAlignmentPlane() { void ProjectionSurface::clearAlignmentPlane() {
m_selectedAlignmentPlane.clear(); m_selectedAlignmentPlane.clear();
m_selectedAlignmentMarkers.clear(); m_selectedAlignmentPeak = std::make_pair(nullptr, QPointF());
m_selectedAlignmentPeak = nullptr;
m_selectedAlignmentPeakPosition = QPointF();
} }
/** /**
...@@ -867,9 +867,16 @@ void ProjectionSurface::erasePeaks(const QRect &rect) { ...@@ -867,9 +867,16 @@ void ProjectionSurface::erasePeaks(const QRect &rect) {
(!m_selectedPeaks.second.empty() && m_selectedPeaks.second.front() == peak)) { (!m_selectedPeaks.second.empty() && m_selectedPeaks.second.front() == peak)) {
clearComparisonPeaks(); clearComparisonPeaks();
} }
if (std::find(m_selectedAlignmentPlane.cbegin(), m_selectedAlignmentPlane.cend(), peak->getQSampleFrame()) != m_selectedAlignmentPlane.cend()) { // check if erased peak matches one of our alignment peaks
clearAlignmentPlane(); auto result = std::find_if(m_selectedAlignmentPlane.cbegin(),
m_selectedAlignmentPlane.cend(),
[peak](const std::pair<V3D, QPointF> &item) {
return item.first == peak->getQLabFrame();
});
if (result != m_selectedAlignmentPlane.cend()) {
clearAlignmentPlane();
} }
} }
...@@ -925,8 +932,9 @@ void ProjectionSurface::comparePeaks(const QRect &rect) { ...@@ -925,8 +932,9 @@ void ProjectionSurface::comparePeaks(const QRect &rect) {
} }
void ProjectionSurface::alignPeaks(const QRect &rect) { void ProjectionSurface::alignPeaks(const QRect &rect) {
using Mantid::Geometry::IPeak;
PeakMarker2D *marker = nullptr; PeakMarker2D *marker = nullptr;
Mantid::Geometry::IPeak *peak = nullptr; IPeak *peak = nullptr;
QPointF origin; QPointF origin;
for (auto po : m_peakShapes) { for (auto po : m_peakShapes) {
...@@ -945,23 +953,31 @@ void ProjectionSurface::alignPeaks(const QRect &rect) { ...@@ -945,23 +953,31 @@ void ProjectionSurface::alignPeaks(const QRect &rect) {
return; return;
if (m_selectedAlignmentPlane.size() < 3) { if (m_selectedAlignmentPlane.size() < 3) {
auto qsample = peak->getQSampleFrame();
auto planeBegin = m_selectedAlignmentPlane.cbegin();
auto planeEnd = m_selectedAlignmentPlane.cend();
// check Q value is not already in the plane list // check Q value is not already in the plane list
// We only want unique vectors to define the plane // We only want unique vectors to define the plane
if(std::find(planeBegin, planeEnd, qsample) == planeEnd) { const auto result = std::find_if(
m_selectedAlignmentPlane.push_back(peak->getQSampleFrame()); m_selectedAlignmentPlane.cbegin(), m_selectedAlignmentPlane.cend(),
m_selectedAlignmentMarkers.push_back(origin); [peak](const std::pair<V3D, QPointF> &item) {
return item.first == peak->getQLabFrame();
});
if (result == m_selectedAlignmentPlane.cend()) {
m_selectedAlignmentPlane.push_back(
std::make_pair(peak->getQSampleFrame(), origin));
} }
} else { } else {
m_selectedAlignmentPeak = peak; m_selectedAlignmentPeak = std::make_pair(peak, origin);
m_selectedAlignmentPeakPosition = origin;
} }
if (m_selectedAlignmentPlane.size() >= 3 && m_selectedAlignmentPeak) if (m_selectedAlignmentPlane.size() >= 3 && m_selectedAlignmentPeak.first) {
emit alignPeaks(m_selectedAlignmentPlane, m_selectedAlignmentPeak); // create vector V3Ds for the plane
std::vector<Mantid::Kernel::V3D> qValues;
std::transform(
m_selectedAlignmentPlane.begin(), m_selectedAlignmentPlane.end(),
std::back_inserter(qValues),
[](const std::pair<V3D, QPointF> &item) { return item.first; });
emit alignPeaks(qValues, m_selectedAlignmentPeak.first);
}
} }
/** /**
...@@ -1010,11 +1026,17 @@ void ProjectionSurface::loadFromProject(const std::string &lines) { ...@@ -1010,11 +1026,17 @@ void ProjectionSurface::loadFromProject(const std::string &lines) {
return Mantid::Kernel::V3D(x, y, z); return Mantid::Kernel::V3D(x, y, z);
}; };
alignmentInfo.parseLines("Marker", m_selectedAlignmentMarkers); std::vector<QPointF> alignmentPoints;
alignmentInfo.parseLines("Qlab", m_selectedAlignmentPlane, parseV3D); std::vector<Mantid::Kernel::V3D> qValues;
alignmentInfo.parseLines("Marker", alignmentPoints);
if (m_selectedAlignmentPlane.size() >= 3 && m_selectedAlignmentPeak) alignmentInfo.parseLines("Qlab", qValues, parseV3D);
emit alignPeaks(m_selectedAlignmentPlane, m_selectedAlignmentPeak);
// make vector of pairs <V3D, QPointF>
std::transform(qValues.begin(), qValues.end(), alignmentPoints.begin(),
std::back_inserter(m_selectedAlignmentPlane),
[](Mantid::Kernel::V3D qValue, QPointF origin) {
return std::make_pair(qValue, origin);
});
} }
} }
...@@ -1027,12 +1049,10 @@ std::string ProjectionSurface::saveToProject() const { ...@@ -1027,12 +1049,10 @@ std::string ProjectionSurface::saveToProject() const {
tsv.writeSection("shapes", m_maskShapes.saveToProject()); tsv.writeSection("shapes", m_maskShapes.saveToProject());
API::TSVSerialiser alignmentInfo; API::TSVSerialiser alignmentInfo;
for (auto origin : m_selectedAlignmentMarkers) { for (const auto &item : m_selectedAlignmentPlane) {
alignmentInfo.writeLine("Marker") << origin; const auto qLab = item.first;
}
for (auto qLab : m_selectedAlignmentPlane) {
alignmentInfo.writeLine("Qlab") << qLab.X() << qLab.Y() << qLab.Z(); alignmentInfo.writeLine("Qlab") << qLab.X() << qLab.Y() << qLab.Z();
alignmentInfo.writeLine("Marker") << item.second;
} }
tsv.writeSection("AlignmentInfo", alignmentInfo.outputLines()); tsv.writeSection("AlignmentInfo", alignmentInfo.outputLines());
......
...@@ -332,9 +332,17 @@ bool Shape2DCollection::selectAtXY(const QPointF &point, bool edit) { ...@@ -332,9 +332,17 @@ bool Shape2DCollection::selectAtXY(const QPointF &point, bool edit) {
* @param y :: Mouse y coordinate. * @param y :: Mouse y coordinate.
*/ */
void Shape2DCollection::deselectAtXY(int x, int y) { void Shape2DCollection::deselectAtXY(int x, int y) {
QPointF p = m_transform.inverted().map(QPointF(x, y)); const QPointF p = m_transform.inverted().map(QPointF(x, y));
deselectAtXY(p);
}
/**
* Deselect a shape under the cursor.
* @param point :: point where peaks should be deselected
*/
void Shape2DCollection::deselectAtXY(const QPointF &point) {
foreach (Shape2D *shape, m_shapes) { foreach (Shape2D *shape, m_shapes) {
bool picked = shape->selectAt(p); bool picked = shape->selectAt(point);
if (picked) { if (picked) {
removeFromSelection(shape); removeFromSelection(shape);
return; return;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment