From 07916f55ce5919c415825591d0df96560ff3db27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Wed, 28 Oct 2015 16:49:52 +0100 Subject: [PATCH] (#592) Plots and tracks are now autoscaled on curve drag, drop, delete, toggled --- .../Commands/RicDeleteItemExec.cpp | 2 +- .../RicWellLogPlotTrackFeatureImpl.cpp | 61 +++++++++------ .../RicWellLogPlotTrackFeatureImpl.h | 3 +- .../RimWellLogExtractionCurve.cpp | 2 +- .../ProjectDataModel/RimWellLogFileCurve.cpp | 2 +- .../ProjectDataModel/RimWellLogPlot.cpp | 20 ++--- .../ProjectDataModel/RimWellLogPlotCurve.cpp | 30 ++++++-- .../ProjectDataModel/RimWellLogPlotCurve.h | 4 +- .../ProjectDataModel/RimWellLogPlotTrack.cpp | 76 ++++++++----------- .../ProjectDataModel/RimWellLogPlotTrack.h | 6 +- ApplicationCode/UserInterface/RiuDragDrop.cpp | 2 +- 11 files changed, 115 insertions(+), 93 deletions(-) diff --git a/ApplicationCode/Commands/RicDeleteItemExec.cpp b/ApplicationCode/Commands/RicDeleteItemExec.cpp index 8d633ad64b..c6a7c80657 100644 --- a/ApplicationCode/Commands/RicDeleteItemExec.cpp +++ b/ApplicationCode/Commands/RicDeleteItemExec.cpp @@ -121,7 +121,7 @@ void RicDeleteItemExec::redo() parentObj->firstAnchestorOrThisOfType(wellLogPlotTrack); if (wellLogPlotTrack) { - wellLogPlotTrack->alignDepthZoomToPlotAndZoomAllX(); + wellLogPlotTrack->zoomAllXAndZoomAllDepthOnOwnerPlot(); } RimWellLogPlotCollection* wellLogPlotCollection = NULL; diff --git a/ApplicationCode/Commands/WellLogCommands/RicWellLogPlotTrackFeatureImpl.cpp b/ApplicationCode/Commands/WellLogCommands/RicWellLogPlotTrackFeatureImpl.cpp index 03bb6340a3..2096650f45 100644 --- a/ApplicationCode/Commands/WellLogCommands/RicWellLogPlotTrackFeatureImpl.cpp +++ b/ApplicationCode/Commands/WellLogCommands/RicWellLogPlotTrackFeatureImpl.cpp @@ -30,38 +30,53 @@ //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RicWellLogPlotTrackFeatureImpl::moveCurvesToWellLogPlotTrack(RimWellLogPlotTrack* wellLogPlotTrack, const std::vector& curves) +void RicWellLogPlotTrackFeatureImpl::moveCurvesToWellLogPlotTrack(RimWellLogPlotTrack* destTrack, + const std::vector& curves, + RimWellLogPlotCurve* insertAfterCurve) { - CVF_ASSERT(wellLogPlotTrack); + CVF_ASSERT(destTrack ); + + std::set srcTracks; + std::set srcPlots; for (size_t cIdx = 0; cIdx < curves.size(); cIdx++) { - RimWellLogPlotTrack* oldPlotTrack; - curves[cIdx]->firstAnchestorOrThisOfType(oldPlotTrack); - if (oldPlotTrack) + RimWellLogPlotCurve* curve = curves[cIdx]; + + RimWellLogPlotTrack* wellLogPlotTrack; + curve->firstAnchestorOrThisOfType(wellLogPlotTrack); + if (wellLogPlotTrack) { - oldPlotTrack->removeCurve(curves[cIdx]); - oldPlotTrack->updateConnectedEditors(); + wellLogPlotTrack->removeCurve(curve); + wellLogPlotTrack->updateConnectedEditors(); + srcTracks.insert(wellLogPlotTrack); + RimWellLogPlot* plot; + wellLogPlotTrack->firstAnchestorOrThisOfType(plot); + if (plot) srcPlots.insert(plot); } - - wellLogPlotTrack->insertCurve(curves[cIdx], cIdx); } - wellLogPlotTrack->loadDataAndUpdate(); - wellLogPlotTrack->alignDepthZoomToPlotAndZoomAllX(); - wellLogPlotTrack->updateConnectedEditors(); -} -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicWellLogPlotTrackFeatureImpl::moveCurvesToWellLogPlotTrack(RimWellLogPlotTrack* wellLogPlotTrack, const std::vector& curves, RimWellLogPlotCurve* insertAfterCurve) -{ - CVF_ASSERT(wellLogPlotTrack && insertAfterCurve); + size_t insertionStartIndex = 0; + if (insertAfterCurve) insertionStartIndex = destTrack->curveIndex(insertAfterCurve) + 1; - wellLogPlotTrack->moveCurves(insertAfterCurve, curves); - wellLogPlotTrack->loadDataAndUpdate(); - wellLogPlotTrack->alignDepthZoomToPlotAndZoomAllX(); - wellLogPlotTrack->updateConnectedEditors(); + for (size_t cIdx = 0; cIdx < curves.size(); cIdx++) + { + destTrack->insertCurve(curves[cIdx], insertionStartIndex + cIdx); + } + + for (std::set::iterator pIt = srcPlots.begin(); pIt != srcPlots.end(); ++pIt) + { + (*pIt)->calculateAvailableDepthRange(); + } + + for (std::set::iterator tIt = srcTracks.begin(); tIt != srcTracks.end(); ++tIt) + { + (*tIt)->zoomAllXAndZoomAllDepthOnOwnerPlot(); + } + + destTrack->loadDataAndUpdate(); + destTrack->zoomAllXAndZoomAllDepthOnOwnerPlot(); + destTrack->updateConnectedEditors(); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/WellLogCommands/RicWellLogPlotTrackFeatureImpl.h b/ApplicationCode/Commands/WellLogCommands/RicWellLogPlotTrackFeatureImpl.h index c17a4e9468..808ad3c03d 100644 --- a/ApplicationCode/Commands/WellLogCommands/RicWellLogPlotTrackFeatureImpl.h +++ b/ApplicationCode/Commands/WellLogCommands/RicWellLogPlotTrackFeatureImpl.h @@ -32,8 +32,7 @@ class RicWellLogPlotTrackFeatureImpl { public: - static void moveCurvesToWellLogPlotTrack(RimWellLogPlotTrack* wellLogPlotTrack, const std::vector& curves); - static void moveCurvesToWellLogPlotTrack(RimWellLogPlotTrack* wellLogPlotTrack, const std::vector& curves, RimWellLogPlotCurve* insertAfterCurve); + static void moveCurvesToWellLogPlotTrack(RimWellLogPlotTrack* dstTrack, const std::vector& curves, RimWellLogPlotCurve* insertAfterCurve); static void moveTracksToWellLogPlot(RimWellLogPlot* wellLogPlot, const std::vector& tracks); static void moveTracks(RimWellLogPlotTrack* insertAfterTrack, const std::vector& tracks); }; diff --git a/ApplicationCode/ProjectDataModel/RimWellLogExtractionCurve.cpp b/ApplicationCode/ProjectDataModel/RimWellLogExtractionCurve.cpp index 2c2413de4f..647da20dec 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogExtractionCurve.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogExtractionCurve.cpp @@ -256,7 +256,7 @@ void RimWellLogExtractionCurve::updatePlotData() } m_qwtPlotCurve->setCurveData(m_curveData.p()); - updateTrackAndPlotFromCurveData(); + zoomAllOwnerTrackAndPlot(); if (m_ownerQwtTrack) m_ownerQwtTrack->replot(); } diff --git a/ApplicationCode/ProjectDataModel/RimWellLogFileCurve.cpp b/ApplicationCode/ProjectDataModel/RimWellLogFileCurve.cpp index 0a65cdf63d..80e0af83e4 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogFileCurve.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogFileCurve.cpp @@ -99,7 +99,7 @@ void RimWellLogFileCurve::updatePlotData() m_qwtPlotCurve->setCurveData(m_curveData.p()); - updateTrackAndPlotFromCurveData(); + zoomAllOwnerTrackAndPlot(); if (m_ownerQwtTrack) m_ownerQwtTrack->replot(); } diff --git a/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp b/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp index 4e50053383..6f71a57756 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp @@ -291,18 +291,18 @@ void RimWellLogPlot::calculateAvailableDepthRange() double minTrackDepth = HUGE_VAL; double maxTrackDepth = -HUGE_VAL; - if (m_tracks[tIdx]->availableDepthRange(&minTrackDepth, &maxTrackDepth)) - { - if (minTrackDepth < minDepth) - { - minDepth = minTrackDepth; - } + m_tracks[tIdx]->availableDepthRange(&minTrackDepth, &maxTrackDepth); - if (maxTrackDepth > maxDepth) - { - maxDepth = maxTrackDepth; - } + if (minTrackDepth < minDepth) + { + minDepth = minTrackDepth; } + + if (maxTrackDepth > maxDepth) + { + maxDepth = maxTrackDepth; + } + } m_minAvailableDepth = minDepth; diff --git a/ApplicationCode/ProjectDataModel/RimWellLogPlotCurve.cpp b/ApplicationCode/ProjectDataModel/RimWellLogPlotCurve.cpp index f2c2fdb3b7..04c0895339 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogPlotCurve.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogPlotCurve.cpp @@ -62,9 +62,12 @@ RimWellLogPlotCurve::RimWellLogPlotCurve() RimWellLogPlotCurve::~RimWellLogPlotCurve() { m_qwtPlotCurve->detach(); - if (m_ownerQwtTrack) m_ownerQwtTrack->replot(); - delete m_qwtPlotCurve; + + if (m_ownerQwtTrack) + { + m_ownerQwtTrack->replot(); + } } //-------------------------------------------------------------------------------------------------- @@ -121,6 +124,21 @@ void RimWellLogPlotCurve::updateCurveVisibility() { m_qwtPlotCurve->detach(); } + + RimWellLogPlot* wellLogPlot; + this->firstAnchestorOrThisOfType(wellLogPlot); + if (wellLogPlot) + { + wellLogPlot->calculateAvailableDepthRange(); + } + + RimWellLogPlotTrack* wellLogPlotTrack; + this->firstAnchestorOrThisOfType(wellLogPlotTrack); + if (wellLogPlotTrack) + { + wellLogPlotTrack->zoomAllXAndZoomAllDepthOnOwnerPlot(); + } + } //-------------------------------------------------------------------------------------------------- @@ -164,7 +182,7 @@ bool RimWellLogPlotCurve::depthRange(double* minimumDepth, double* maximumDepth) { CVF_ASSERT(minimumDepth && maximumDepth); CVF_ASSERT(m_qwtPlotCurve); - + if (m_qwtPlotCurve->data()->size() < 1) { return false; @@ -230,7 +248,7 @@ void RimWellLogPlotCurve::updatePlotTitle() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RimWellLogPlotCurve::isCurveVisible() +bool RimWellLogPlotCurve::isCurveVisible() const { return m_showCurve; } @@ -246,7 +264,7 @@ void RimWellLogPlotCurve::initAfterRead() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimWellLogPlotCurve::updateTrackAndPlotFromCurveData() +void RimWellLogPlotCurve::zoomAllOwnerTrackAndPlot() { RimWellLogPlot* wellLogPlot; firstAnchestorOrThisOfType(wellLogPlot); @@ -260,7 +278,7 @@ void RimWellLogPlotCurve::updateTrackAndPlotFromCurveData() firstAnchestorOrThisOfType(plotTrack); if (plotTrack) { - plotTrack->alignDepthZoomToPlotAndZoomAllX(); + plotTrack->zoomAllXAndZoomAllDepthOnOwnerPlot(); } } diff --git a/ApplicationCode/ProjectDataModel/RimWellLogPlotCurve.h b/ApplicationCode/ProjectDataModel/RimWellLogPlotCurve.h index 454b31d241..c5811d5aad 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogPlotCurve.h +++ b/ApplicationCode/ProjectDataModel/RimWellLogPlotCurve.h @@ -52,7 +52,7 @@ public: void setQwtTrack(RiuWellLogTrackPlot* plot); void detachQwtCurve(); - bool isCurveVisible(); + bool isCurveVisible() const; QwtPlotCurve* plotCurve() const; const RigWellLogCurveData* curveData() const; @@ -71,7 +71,7 @@ protected: void updatePlotConfiguration(); void updateCurveVisibility(); - void updateTrackAndPlotFromCurveData(); + void zoomAllOwnerTrackAndPlot(); void updateOptionSensitivity(); // Overridden PDM methods diff --git a/ApplicationCode/ProjectDataModel/RimWellLogPlotTrack.cpp b/ApplicationCode/ProjectDataModel/RimWellLogPlotTrack.cpp index 8eca699c34..0f557c358f 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogPlotTrack.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogPlotTrack.cpp @@ -145,31 +145,6 @@ void RimWellLogPlotTrack::removeCurve(RimWellLogPlotCurve* curve) } } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimWellLogPlotTrack::moveCurves(RimWellLogPlotCurve* insertAfterCurve, const std::vector& curvesToMove) -{ - for (size_t cIdx = 0; cIdx < curvesToMove.size(); cIdx++) - { - RimWellLogPlotCurve* curve = curvesToMove[cIdx]; - - RimWellLogPlotTrack* wellLogPlotTrack; - curve->firstAnchestorOrThisOfType(wellLogPlotTrack); - if (wellLogPlotTrack) - { - wellLogPlotTrack->removeCurve(curve); - wellLogPlotTrack->updateConnectedEditors(); - } - } - - size_t index = curves.index(insertAfterCurve) + 1; - - for (size_t cIdx = 0; cIdx < curvesToMove.size(); cIdx++) - { - insertCurve(curvesToMove[cIdx], index + cIdx); - } -} //-------------------------------------------------------------------------------------------------- /// @@ -182,47 +157,34 @@ RiuWellLogTrackPlot* RimWellLogPlotTrack::viewer() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RimWellLogPlotTrack::availableDepthRange(double* minimumDepth, double* maximumDepth) +void RimWellLogPlotTrack::availableDepthRange(double* minimumDepth, double* maximumDepth) { double minDepth = HUGE_VAL; double maxDepth = -HUGE_VAL; size_t curveCount = curves.size(); - if (curveCount < 1) - { - return false; - } - - bool rangeUpdated = false; for (size_t cIdx = 0; cIdx < curveCount; cIdx++) { double minCurveDepth = HUGE_VAL; double maxCurveDepth = -HUGE_VAL; - if (curves[cIdx]->depthRange(&minCurveDepth, &maxCurveDepth)) + if (curves[cIdx]->isCurveVisible() && curves[cIdx]->depthRange(&minCurveDepth, &maxCurveDepth)) { if (minCurveDepth < minDepth) { minDepth = minCurveDepth; - rangeUpdated = true; } if (maxCurveDepth > maxDepth) { maxDepth = maxCurveDepth; - rangeUpdated = true; } } } - if (rangeUpdated) - { - *minimumDepth = minDepth; - *maximumDepth = maxDepth; - } - - return rangeUpdated; + *minimumDepth = minDepth; + *maximumDepth = maxDepth; } //-------------------------------------------------------------------------------------------------- @@ -272,6 +234,26 @@ void RimWellLogPlotTrack::detachAllCurves() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellLogPlotTrack::zoomAllXAndZoomAllDepthOnOwnerPlot() +{ + if (m_wellLogTrackPlotWidget) + { + RimWellLogPlot* wellLogPlot; + firstAnchestorOrThisOfType(wellLogPlot); + if (wellLogPlot) + { + wellLogPlot->zoomAllDepth(); + } + + zoomAllXAxis(); + + m_wellLogTrackPlotWidget->replot(); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -308,7 +290,7 @@ void RimWellLogPlotTrack::zoomAllXAxis() double minCurveValue = HUGE_VAL; double maxCurveValue = -HUGE_VAL; - if (curves[cIdx]->valueRange(&minCurveValue, &maxCurveValue)) + if (curves[cIdx]->isCurveVisible() && curves[cIdx]->valueRange(&minCurveValue, &maxCurveValue)) { if (minCurveValue < minValue) { @@ -363,3 +345,11 @@ void RimWellLogPlotTrack::defineUiOrdering(QString uiConfigName, caf::PdmUiOrder gridGroup->add(&m_visibleXRangeMin); gridGroup->add(&m_visibleXRangeMax); } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +size_t RimWellLogPlotTrack::curveIndex(RimWellLogPlotCurve* curve) +{ + return curves.index(curve); +} diff --git a/ApplicationCode/ProjectDataModel/RimWellLogPlotTrack.h b/ApplicationCode/ProjectDataModel/RimWellLogPlotTrack.h index 21e9cdb080..b409b53564 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogPlotTrack.h +++ b/ApplicationCode/ProjectDataModel/RimWellLogPlotTrack.h @@ -48,7 +48,7 @@ public: void addCurve(RimWellLogPlotCurve* curve); void insertCurve(RimWellLogPlotCurve* curve, size_t index); void removeCurve(RimWellLogPlotCurve* curve); - void moveCurves(RimWellLogPlotCurve* insertAfterCurve, const std::vector& curvesToMove); + size_t curveIndex(RimWellLogPlotCurve* curve); size_t curveCount() { return curves.size(); } void recreateViewer(); @@ -56,7 +56,8 @@ public: void loadDataAndUpdate(); - bool availableDepthRange(double* minimumDepth, double* maximumDepth); + void availableDepthRange(double* minimumDepth, double* maximumDepth); + void zoomAllXAndZoomAllDepthOnOwnerPlot(); void alignDepthZoomToPlotAndZoomAllX(); RiuWellLogTrackPlot* viewer(); @@ -73,7 +74,6 @@ protected: private: void zoomAllXAxis(); - private: caf::PdmField m_show; caf::PdmField m_userName; diff --git a/ApplicationCode/UserInterface/RiuDragDrop.cpp b/ApplicationCode/UserInterface/RiuDragDrop.cpp index 5b7a80bcfd..212ba79335 100644 --- a/ApplicationCode/UserInterface/RiuDragDrop.cpp +++ b/ApplicationCode/UserInterface/RiuDragDrop.cpp @@ -350,7 +350,7 @@ bool RiuDragDrop::handleWellLogPlotTrackDrop(Qt::DropAction action, caf::PdmObje { if (action == Qt::MoveAction) { - RicWellLogPlotTrackFeatureImpl::moveCurvesToWellLogPlotTrack(wellLogPlotTrack, wellLogPlotCurves); + RicWellLogPlotTrackFeatureImpl::moveCurvesToWellLogPlotTrack(wellLogPlotTrack, wellLogPlotCurves, NULL); return true; } }