#2975 Ensemble Curve Set: Call updateConnectedEditors on collection

This commit is contained in:
Magne Sjaastad
2018-06-01 15:38:48 +02:00
parent ea7c5b6a76
commit 58ba0b2882
2 changed files with 57 additions and 44 deletions

View File

@@ -1,17 +1,17 @@
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2016- Statoil ASA // Copyright (C) 2016- Statoil ASA
// //
// ResInsight is free software: you can redistribute it and/or modify // ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY // ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or // WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. // FITNESS FOR A PARTICULAR PURPOSE.
// //
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html> // See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details. // for more details.
// //
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
@@ -24,10 +24,7 @@
#include "RimEnsembleCurveSet.h" #include "RimEnsembleCurveSet.h"
#include "RimEnsembleCurveSetCollection.h" #include "RimEnsembleCurveSetCollection.h"
//#include "RimSummaryCurve.h"
//#include "RimSummaryCurveFilter.h"
#include "RimSummaryPlot.h" #include "RimSummaryPlot.h"
//#include "RimSummaryCrossPlot.h"
#include "cafPdmDefaultObjectFactory.h" #include "cafPdmDefaultObjectFactory.h"
#include "cafPdmDocument.h" #include "cafPdmDocument.h"
@@ -38,73 +35,89 @@
#include <QAction> #include <QAction>
CAF_CMD_SOURCE_INIT(RicPasteEnsembleCurveSetFeature, "RicPasteEnsembleCurveSetFeature"); CAF_CMD_SOURCE_INIT(RicPasteEnsembleCurveSetFeature, "RicPasteEnsembleCurveSetFeature");
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
RimEnsembleCurveSet* RicPasteEnsembleCurveSetFeature::copyCurveSetAndAddToCollection(RimEnsembleCurveSet *sourceCurveSet) RimEnsembleCurveSet*
RicPasteEnsembleCurveSetFeature::copyCurveSetAndAddToCollection(RimEnsembleCurveSetCollection* curveSetCollection,
const RimEnsembleCurveSet* sourceCurveSet)
{ {
RimSummaryPlot* plot = caf::firstAncestorOfTypeFromSelectedObject<RimSummaryPlot*>(); CVF_ASSERT(curveSetCollection);
RimEnsembleCurveSetCollection* coll = caf::firstAncestorOfTypeFromSelectedObject<RimEnsembleCurveSetCollection*>();
RimEnsembleCurveSet* newCurveSet = dynamic_cast<RimEnsembleCurveSet*>(sourceCurveSet->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance())); RimEnsembleCurveSet* newCurveSet = dynamic_cast<RimEnsembleCurveSet*>(
sourceCurveSet->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance()));
CVF_ASSERT(newCurveSet); CVF_ASSERT(newCurveSet);
if (!coll) coll = plot->ensembleCurveSetCollection(); curveSetCollection->addCurveSet(newCurveSet);
coll->addCurveSet(newCurveSet);
// Resolve references after object has been inserted into the project data model // Resolve references after object has been inserted into the project data model
newCurveSet->resolveReferencesRecursively(); newCurveSet->resolveReferencesRecursively();
newCurveSet->initAfterReadRecursively(); newCurveSet->initAfterReadRecursively();
newCurveSet->loadDataAndUpdate(true); newCurveSet->loadDataAndUpdate(false);
newCurveSet->updateConnectedEditors(); newCurveSet->updateConnectedEditors();
coll->updateConnectedEditors();
return newCurveSet; return newCurveSet;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool RicPasteEnsembleCurveSetFeature::isCommandEnabled() bool RicPasteEnsembleCurveSetFeature::isCommandEnabled()
{ {
caf::PdmObject* destinationObject = dynamic_cast<caf::PdmObject*>(caf::SelectionManager::instance()->selectedItem()); caf::PdmObject* destinationObject = dynamic_cast<caf::PdmObject*>(caf::SelectionManager::instance()->selectedItem());
RimSummaryPlot* plot; RimSummaryPlot* plot = nullptr;
RimEnsembleCurveSetCollection* coll = nullptr; RimEnsembleCurveSetCollection* coll = nullptr;
destinationObject->firstAncestorOrThisOfType(plot); destinationObject->firstAncestorOrThisOfType(plot);
destinationObject->firstAncestorOrThisOfType(coll); destinationObject->firstAncestorOrThisOfType(coll);
if(!coll && !plot) if (!coll && !plot)
{ {
return false; return false;
} }
if (ensembleCurveSetsOnClipboard().size() == 0) if (ensembleCurveSetsOnClipboard().empty())
{ {
return false; return false;
} }
return true; return true;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicPasteEnsembleCurveSetFeature::onActionTriggered(bool isChecked) void RicPasteEnsembleCurveSetFeature::onActionTriggered(bool isChecked)
{ {
std::vector<caf::PdmPointer<RimEnsembleCurveSet> > sourceObjects = RicPasteEnsembleCurveSetFeature::ensembleCurveSetsOnClipboard(); std::vector<caf::PdmPointer<RimEnsembleCurveSet>> sourceObjects =
RicPasteEnsembleCurveSetFeature::ensembleCurveSetsOnClipboard();
if (sourceObjects.empty()) return;
for (size_t i = 0; i < sourceObjects.size(); i++) RimSummaryPlot* plot = caf::firstAncestorOfTypeFromSelectedObject<RimSummaryPlot*>();
RimEnsembleCurveSetCollection* coll = caf::firstAncestorOfTypeFromSelectedObject<RimEnsembleCurveSetCollection*>();
if (!coll && plot)
{ {
copyCurveSetAndAddToCollection(sourceObjects[i]); coll = plot->ensembleCurveSetCollection();
} }
if (!coll) return;
for (const auto& sourceObject : sourceObjects)
{
copyCurveSetAndAddToCollection(coll, sourceObject);
}
if (plot)
{
plot->updateAll();
}
coll->updateConnectedEditors();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicPasteEnsembleCurveSetFeature::setupActionLook(QAction* actionToSetup) void RicPasteEnsembleCurveSetFeature::setupActionLook(QAction* actionToSetup)
{ {
@@ -114,14 +127,14 @@ void RicPasteEnsembleCurveSetFeature::setupActionLook(QAction* actionToSetup)
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
std::vector<caf::PdmPointer<RimEnsembleCurveSet> > RicPasteEnsembleCurveSetFeature::ensembleCurveSetsOnClipboard() std::vector<caf::PdmPointer<RimEnsembleCurveSet>> RicPasteEnsembleCurveSetFeature::ensembleCurveSetsOnClipboard()
{ {
caf::PdmObjectGroup objectGroup; caf::PdmObjectGroup objectGroup;
RicPasteFeatureImpl::findObjectsFromClipboardRefs(&objectGroup); RicPasteFeatureImpl::findObjectsFromClipboardRefs(&objectGroup);
std::vector<caf::PdmPointer<RimEnsembleCurveSet> > typedObjects; std::vector<caf::PdmPointer<RimEnsembleCurveSet>> typedObjects;
objectGroup.objectsByType(&typedObjects); objectGroup.objectsByType(&typedObjects);
return typedObjects; return typedObjects;

View File

@@ -1,17 +1,17 @@
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2016- Statoil ASA // Copyright (C) 2016- Statoil ASA
// //
// ResInsight is free software: you can redistribute it and/or modify // ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY // ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or // WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. // FITNESS FOR A PARTICULAR PURPOSE.
// //
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html> // See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details. // for more details.
// //
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
@@ -24,22 +24,22 @@
#include <vector> #include <vector>
class RimEnsembleCurveSet; class RimEnsembleCurveSet;
class RimEnsembleCurveSetCollection;
//================================================================================================== //==================================================================================================
/// ///
//================================================================================================== //==================================================================================================
class RicPasteEnsembleCurveSetFeature : public caf::CmdFeature class RicPasteEnsembleCurveSetFeature : public caf::CmdFeature
{ {
CAF_CMD_HEADER_INIT; CAF_CMD_HEADER_INIT;
public: private:
static RimEnsembleCurveSet* copyCurveSetAndAddToCollection(RimEnsembleCurveSet *sourceCurveSet); bool isCommandEnabled() override;
void onActionTriggered(bool isChecked) override;
void setupActionLook(QAction* actionToSetup) override;
protected: static RimEnsembleCurveSet* copyCurveSetAndAddToCollection(RimEnsembleCurveSetCollection* coll,
// Overrides const RimEnsembleCurveSet* sourceCurveSet);
virtual bool isCommandEnabled() override;
virtual void onActionTriggered( bool isChecked ) override;
virtual void setupActionLook(QAction* actionToSetup) override;
static std::vector<caf::PdmPointer<RimEnsembleCurveSet> > ensembleCurveSetsOnClipboard(); static std::vector<caf::PdmPointer<RimEnsembleCurveSet>> ensembleCurveSetsOnClipboard();
}; };