diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.cpp index 589bb83c20..556d1aaabc 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.cpp +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.cpp @@ -790,7 +790,7 @@ void RicSummaryCurveCreator::syncCurvesFromUiSelection() for (const auto& curve : currentCurvesInPlot) { std::pair curveDef = std::make_pair(curve->summaryCase(), curve->summaryAddress()); - if (deleteCurveDefs.count(curveDef)) + if (deleteCurveDefs.count(curveDef) > 0) deleteCurves.insert(curve); } } @@ -999,23 +999,72 @@ void RicSummaryCurveCreator::populateCurveCreator(const RimSummaryPlot& sourceSu } // Copy curve object to the preview plot - copyCurveAndAddToPlot(curve, m_previewPlot); + copyCurveAndAddToPlot(curve, m_previewPlot, true); } m_previewPlot->updateConnectedEditors(); } //-------------------------------------------------------------------------------------------------- /// Copy curves from preview plot to target plot -// Todo: Do not copy curves already in target plot (?) //-------------------------------------------------------------------------------------------------- void RicSummaryCurveCreator::updateTargetPlot() { if (m_targetPlot == nullptr) m_targetPlot = new RimSummaryPlot(); - + + std::set> targetCurveDefs; + std::set> editedCurveDefs; + for (const auto& curve : m_targetPlot->summaryCurves()) + { + targetCurveDefs.insert(std::make_pair(curve->summaryCase(), curve->summaryAddress())); + } for (const auto& curve : m_previewPlot->summaryCurves()) { - copyCurveAndAddToPlot(curve, m_targetPlot); + if (curve->isCurveVisible()) + { + editedCurveDefs.insert(std::make_pair(curve->summaryCase(), curve->summaryAddress())); + } + } + + // First delete target plot curves that have been deleted or unchecked in the preview plot + std::set> deleteCurveDefs; + std::set_difference(targetCurveDefs.begin(), targetCurveDefs.end(), + editedCurveDefs.begin(), editedCurveDefs.end(), + std::inserter(deleteCurveDefs, deleteCurveDefs.end())); + + if (deleteCurveDefs.size() > 0) + { + for (const auto& curve : m_targetPlot->summaryCurves()) + { + std::pair curveDef = std::make_pair(curve->summaryCase(), curve->summaryAddress()); + if (deleteCurveDefs.count(curveDef) > 0) + m_targetPlot->deleteCurve(curve); + } + } + + // Add edited curves to target plot, skipping curves that already exists in the plot + for (const auto& editedCurve : m_previewPlot->summaryCurves()) + { + if (!editedCurve->isCurveVisible()) + { + continue; + } + + // Avoid duplicate curves in target plot + bool curveExistsInTargetPlot = false; + for (const auto& existingCurve : m_targetPlot->summaryCurves()) + { + if (existingCurve->summaryCase() == editedCurve->summaryCase() && + existingCurve->summaryAddress() == editedCurve->summaryAddress()) + { + curveExistsInTargetPlot = true; + break; + } + } + if (!curveExistsInTargetPlot) + { + copyCurveAndAddToPlot(editedCurve, m_targetPlot); + } } m_targetPlot->updateConnectedEditors(); } @@ -1023,11 +1072,13 @@ void RicSummaryCurveCreator::updateTargetPlot() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RicSummaryCurveCreator::copyCurveAndAddToPlot(const RimSummaryCurve *curve, RimSummaryPlot *plot) +void RicSummaryCurveCreator::copyCurveAndAddToPlot(const RimSummaryCurve *curve, RimSummaryPlot *plot, bool forceVisible) { RimSummaryCurve* curveCopy = dynamic_cast(curve->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance())); CVF_ASSERT(curveCopy); + if (forceVisible) + curveCopy->setCurveVisiblity(true); plot->addCurve(curveCopy); // Resolve references after object has been inserted into the project data model diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.h b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.h index 2022931ab3..15000f3ef1 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.h +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.h @@ -111,7 +111,7 @@ private: void populateCurveCreator(const RimSummaryPlot& sourceSummaryPlot); void updateTargetPlot(); - void copyCurveAndAddToPlot(const RimSummaryCurve *curve, RimSummaryPlot *plot); + void copyCurveAndAddToPlot(const RimSummaryCurve *curve, RimSummaryPlot *plot, bool forceVisible = false); void resetAllFields(); diff --git a/ApplicationCode/FileInterface/RifEclipseSummaryAddress.cpp b/ApplicationCode/FileInterface/RifEclipseSummaryAddress.cpp index 7e159dfd09..670135f1ee 100644 --- a/ApplicationCode/FileInterface/RifEclipseSummaryAddress.cpp +++ b/ApplicationCode/FileInterface/RifEclipseSummaryAddress.cpp @@ -191,6 +191,9 @@ std::string RifEclipseSummaryAddress::uiText(RifEclipseSummaryAddress::SummaryId return ""; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- std::string RifEclipseSummaryAddress::formatUiTextIJK() const { return std::to_string(this->cellI()) + ", " @@ -198,7 +201,9 @@ std::string RifEclipseSummaryAddress::formatUiTextIJK() const + std::to_string(this->cellK()); } -// todo: Make class member +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- std::tuple RifEclipseSummaryAddress::ijkTupleFromUiText(const std::string &s) { auto firstSep = s.find(','); diff --git a/ApplicationCode/ProjectDataModel/RimPlotCurve.cpp b/ApplicationCode/ProjectDataModel/RimPlotCurve.cpp index 8197fad21c..2cac582692 100644 --- a/ApplicationCode/ProjectDataModel/RimPlotCurve.cpp +++ b/ApplicationCode/ProjectDataModel/RimPlotCurve.cpp @@ -272,6 +272,14 @@ bool RimPlotCurve::isCurveVisible() const return m_showCurve; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPlotCurve::setCurveVisiblity(bool visible) +{ + m_showCurve = visible; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimPlotCurve.h b/ApplicationCode/ProjectDataModel/RimPlotCurve.h index e8a41f28fb..b4d6235ccd 100644 --- a/ApplicationCode/ProjectDataModel/RimPlotCurve.h +++ b/ApplicationCode/ProjectDataModel/RimPlotCurve.h @@ -82,7 +82,8 @@ public: void setLineThickness(int thickness); bool isCurveVisible() const; - + void setCurveVisiblity(bool visible); + void updateCurveName(); QString curveName() const { return m_curveName; }