From 9f472260491bbe8586db8ef69c04e22b53457240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Jensen?= Date: Fri, 15 Sep 2017 13:37:52 +0200 Subject: [PATCH] #1886 Curve creator. Set target plot from edit summary curve command --- .../RicEditSummaryCurves.cpp | 9 +++++ .../RicSummaryCurveCreator.cpp | 35 ++++++++++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicEditSummaryCurves.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicEditSummaryCurves.cpp index 53182bafb9..109e5dab3c 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicEditSummaryCurves.cpp +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicEditSummaryCurves.cpp @@ -29,6 +29,7 @@ #include #include "cvfAssert.h" +#include "cafSelectionManager.h" CAF_CMD_SOURCE_INIT(RicEditSummaryCurves, "RicEditSummaryCurves"); @@ -57,6 +58,14 @@ void RicEditSummaryCurves::onActionTriggered(bool isChecked) if (!m_dialogWithSplitter->isVisible()) m_dialogWithSplitter->show(); + + // Set target plot + std::vector plots; + caf::SelectionManager::instance()->objectsByType(&plots); + if (plots.size() == 1) + { + m_curveCreator->setTargetPlot(plots.front()); + } } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.cpp index cddb4101b4..8fb8e3d8d6 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.cpp +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.cpp @@ -158,6 +158,7 @@ RicSummaryCurveCreator::RicSummaryCurveCreator() : m_identifierFieldsMap( CAF_PDM_InitFieldNoDefault(m_identifierFieldsMap[RifEclipseSummaryAddress::SUMMARY_BLOCK_LGR][2]->pdmField(), "BlockLgrVectors", "Block Vectors", "", "", ""); CAF_PDM_InitFieldNoDefault(&m_previewPlot, "PreviewPlot", "PreviewPlot", "", "", ""); + CAF_PDM_InitFieldNoDefault(&m_targetPlot, "TargetPlot", "TargetPlot", "", "", ""); CAF_PDM_InitField(&m_useAutoAppearanceAssignment, "UseAutoAppearanceAssignment", true, "Auto", "", "", ""); CAF_PDM_InitFieldNoDefault(&m_caseAppearanceType, "CaseAppearanceType", "Case", "", "", ""); @@ -212,7 +213,11 @@ RicSummaryCurveCreator::~RicSummaryCurveCreator() void RicSummaryCurveCreator::setTargetPlot(RimSummaryPlot* targetPlot) { m_targetPlot = targetPlot; - + if (targetPlot != nullptr) + { + populateCurveCreator(*targetPlot); + updateConnectedEditors(); + } } //-------------------------------------------------------------------------------------------------- @@ -847,7 +852,7 @@ void RicSummaryCurveCreator::populateCurveCreator(const RimSummaryPlot& sourceSu for (const auto& curve : sourceSummaryPlot.summaryCurves()) { // Select case if not already selected - if (std::find(m_selectedCases.begin(), m_selectedCases.end(), curve->summaryCase()) != m_selectedCases.end()) + if (std::find(m_selectedCases.begin(), m_selectedCases.end(), curve->summaryCase()) == m_selectedCases.end()) { m_selectedCases.push_back(curve->summaryCase()); } @@ -855,11 +860,31 @@ void RicSummaryCurveCreator::populateCurveCreator(const RimSummaryPlot& sourceSu auto identifierAndFieldList = m_identifierFieldsMap[curve->summaryAddress().category()]; for (const auto& identifierAndField : identifierAndFieldList) { - auto& pdmField = *identifierAndField->pdmField(); - auto currentSelections = pdmField(); - currentSelections.push_back(QString::fromStdString(curve->summaryAddress().uiText(identifierAndField->summaryIdentifier()))); + QString uiText = QString::fromStdString(curve->summaryAddress().uiText(identifierAndField->summaryIdentifier())); + const auto& currentSelectionVector = identifierAndField->pdmField()->v(); + if (std::find(currentSelectionVector.begin(), currentSelectionVector.end(), uiText) == currentSelectionVector.end()) + { + std::vector newSelectionVector(currentSelectionVector.begin(), currentSelectionVector.end()); + newSelectionVector.push_back(uiText); + (*identifierAndField->pdmField()) = newSelectionVector; + } } + + // Copy curve object to the preview plot + RimSummaryCurve* curveCopy = dynamic_cast(curve->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance())); + CVF_ASSERT(curveCopy); + + m_previewPlot->addCurve(curveCopy); + + // Resolve references after object has been inserted into the project data model + curveCopy->resolveReferencesRecursively(); + + // The curve creator is not a descendant of the project, and need to be set manually + curveCopy->setSummaryCase(curve->summaryCase()); + curveCopy->initAfterReadRecursively(); + curveCopy->loadDataAndUpdate(); } + m_previewPlot->updateConnectedEditors(); }