From b2f4cd6696507f5bfb3f63db2557eab444eff83f Mon Sep 17 00:00:00 2001 From: Rebecca Cox Date: Mon, 23 Oct 2017 18:29:23 +0200 Subject: [PATCH] #1845 RFT/PLT Plot: Add support for annotation of Qwt plot --- .../UserInterface/CMakeLists_files.cmake | 2 + .../UserInterface/RiuPlotAnnotationTool.cpp | 63 +++++++++++++++++++ .../UserInterface/RiuPlotAnnotationTool.h | 40 ++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 ApplicationCode/UserInterface/RiuPlotAnnotationTool.cpp create mode 100644 ApplicationCode/UserInterface/RiuPlotAnnotationTool.h diff --git a/ApplicationCode/UserInterface/CMakeLists_files.cmake b/ApplicationCode/UserInterface/CMakeLists_files.cmake index 965217a9a1..93336b29b8 100644 --- a/ApplicationCode/UserInterface/CMakeLists_files.cmake +++ b/ApplicationCode/UserInterface/CMakeLists_files.cmake @@ -40,6 +40,7 @@ ${CEE_CURRENT_LIST_DIR}RiuViewer.h ${CEE_CURRENT_LIST_DIR}RiuViewerCommands.h ${CEE_CURRENT_LIST_DIR}RiuWellLogPlot.h ${CEE_CURRENT_LIST_DIR}RiuWellLogTrack.h +${CEE_CURRENT_LIST_DIR}RiuPlotAnnotationTool.h ${CEE_CURRENT_LIST_DIR}RiuGeoMechXfTensorResultAccessor.h ${CEE_CURRENT_LIST_DIR}RiuFemTimeHistoryResultAccessor.h ${CEE_CURRENT_LIST_DIR}RiuEditPerforationCollectionWidget.h @@ -93,6 +94,7 @@ ${CEE_CURRENT_LIST_DIR}RiuViewer.cpp ${CEE_CURRENT_LIST_DIR}RiuViewerCommands.cpp ${CEE_CURRENT_LIST_DIR}RiuWellLogPlot.cpp ${CEE_CURRENT_LIST_DIR}RiuWellLogTrack.cpp +${CEE_CURRENT_LIST_DIR}RiuPlotAnnotationTool.cpp ${CEE_CURRENT_LIST_DIR}RiuGeoMechXfTensorResultAccessor.cpp ${CEE_CURRENT_LIST_DIR}RiuFemTimeHistoryResultAccessor.cpp ${CEE_CURRENT_LIST_DIR}RiuEditPerforationCollectionWidget.cpp diff --git a/ApplicationCode/UserInterface/RiuPlotAnnotationTool.cpp b/ApplicationCode/UserInterface/RiuPlotAnnotationTool.cpp new file mode 100644 index 0000000000..ef0f40c8ad --- /dev/null +++ b/ApplicationCode/UserInterface/RiuPlotAnnotationTool.cpp @@ -0,0 +1,63 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017- Statoil ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RiuPlotAnnotationTool.h" + +#include + +#include "qwt_plot.h" + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuPlotAnnotationTool::attachFormationNames(const std::vector& names, const std::vector yPositions) +{ + if (names.size() != yPositions.size()) return; + + QPen curvePen; + curvePen.setStyle(Qt::DashLine); + curvePen.setColor(Qt::gray); + curvePen.setWidth(1); + + for (size_t i = 0; i < names.size(); i++) + { + std::unique_ptr line(std::make_unique()); + + line->setLineStyle(QwtPlotMarker::HLine); + line->setLinePen(curvePen); + line->setYValue(yPositions[i]); + line->setLabel(names[i]); + line->setLabelAlignment(Qt::AlignLeft | Qt::AlignBottom); + + line->attach(m_plot); + + m_markers.push_back(std::move(line)); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuPlotAnnotationTool::detachAllAnnotations() +{ + for (size_t i = 0; i < m_markers.size(); i++) + { + m_markers[i]->detach(); + } + m_markers.clear(); +} diff --git a/ApplicationCode/UserInterface/RiuPlotAnnotationTool.h b/ApplicationCode/UserInterface/RiuPlotAnnotationTool.h new file mode 100644 index 0000000000..4d46e83ded --- /dev/null +++ b/ApplicationCode/UserInterface/RiuPlotAnnotationTool.h @@ -0,0 +1,40 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017- Statoil ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "qwt_plot_marker.h" + +#include +#include + +class QString; +class QwtPlot; + +class RiuPlotAnnotationTool +{ +public: + RiuPlotAnnotationTool(QwtPlot* plot) : m_plot(plot) {}; + + void attachFormationNames(const std::vector& names, const std::vector yPositions); + void detachAllAnnotations(); + +private: + QwtPlot* m_plot; + std::vector> m_markers; +};