diff --git a/ApplicationCode/Commands/ViewLink/RicDeleteAllLinkedViewsFeature.cpp b/ApplicationCode/Commands/ViewLink/RicDeleteAllLinkedViewsFeature.cpp index a0f781173e..27f7ba8e11 100644 --- a/ApplicationCode/Commands/ViewLink/RicDeleteAllLinkedViewsFeature.cpp +++ b/ApplicationCode/Commands/ViewLink/RicDeleteAllLinkedViewsFeature.cpp @@ -42,11 +42,17 @@ bool RicDeleteAllLinkedViewsFeature::isCommandEnabled() void RicDeleteAllLinkedViewsFeature::onActionTriggered(bool isChecked) { RimProject* proj = RiaApplication::instance()->project(); - if (proj->viewLinkerCollection()->viewLinker()) + + RimViewLinker* viewLinker = proj->viewLinkerCollection()->viewLinker(); + if (viewLinker) { - delete proj->viewLinkerCollection()->viewLinker(); + // Remove the view linker object from the view linker collection + // viewLinkerCollection->viewLinker is a PdmChildField containing one RimViewLinker child object + proj->viewLinkerCollection->viewLinker.removeChildObject(viewLinker); + + viewLinker->applyRangeFilterCollectionByUserChoice(); - proj->viewLinkerCollection()->viewLinker = NULL; + delete viewLinker; proj->uiCapability()->updateConnectedEditors(); } diff --git a/ApplicationCode/Commands/ViewLink/RicSetMasterViewFeature.cpp b/ApplicationCode/Commands/ViewLink/RicSetMasterViewFeature.cpp index c3597598ff..5f5609da7a 100644 --- a/ApplicationCode/Commands/ViewLink/RicSetMasterViewFeature.cpp +++ b/ApplicationCode/Commands/ViewLink/RicSetMasterViewFeature.cpp @@ -68,13 +68,14 @@ void RicSetMasterViewFeature::onActionTriggered(bool isChecked) RimProject* proj = RiaApplication::instance()->project(); RimViewLinker* viewLinker = proj->viewLinkerCollection()->viewLinker(); + viewLinker->applyRangeFilterCollectionByUserChoice(); + RimView* previousMasterView = viewLinker->masterView(); viewLinker->setMasterView(activeView); viewLinker->updateDependentViews(); viewLinker->addDependentView(previousMasterView); - proj->viewLinkerCollection.uiCapability()->updateConnectedEditors(); proj->updateConnectedEditors(); diff --git a/ApplicationCode/Commands/ViewLink/RicUnLinkViewFeature.cpp b/ApplicationCode/Commands/ViewLink/RicUnLinkViewFeature.cpp index f7978677e1..a3bbaa6f09 100644 --- a/ApplicationCode/Commands/ViewLink/RicUnLinkViewFeature.cpp +++ b/ApplicationCode/Commands/ViewLink/RicUnLinkViewFeature.cpp @@ -60,8 +60,9 @@ void RicUnLinkViewFeature::onActionTriggered(bool isChecked) if (!activeView) return; RimViewController* viewController = activeView->viewController(); - caf::SelectionManager::instance()->setSelectedItem(viewController); + viewController->applyRangeFilterCollectionByUserChoice(); + caf::SelectionManager::instance()->setSelectedItem(viewController); caf::CmdFeature* feature = caf::CmdFeatureManager::instance()->getCommandFeature("RicDeleteItemFeature"); if (feature) { diff --git a/ApplicationCode/ProjectDataModel/RimView.cpp b/ApplicationCode/ProjectDataModel/RimView.cpp index 3757273236..a8a848c9d7 100644 --- a/ApplicationCode/ProjectDataModel/RimView.cpp +++ b/ApplicationCode/ProjectDataModel/RimView.cpp @@ -705,3 +705,26 @@ RimCellRangeFilterCollection* RimView::overrideRangeFilterCollection() return m_overrideRangeFilterCollection(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimView::replaceRangeFilterCollectionWithOverride() +{ + RimCellRangeFilterCollection* overrideRfc = m_overrideRangeFilterCollection; + CVF_ASSERT(overrideRfc); + + RimCellRangeFilterCollection* currentRfc = m_rangeFilterCollection; + if (currentRfc) + { + delete currentRfc; + } + + // Must call removeChildObject() to make sure the object has no parent + // No parent is required when assigning a object into a field + m_overrideRangeFilterCollection.removeChildObject(overrideRfc); + + m_rangeFilterCollection = overrideRfc; + + this->uiCapability()->updateConnectedEditors(); +} + diff --git a/ApplicationCode/ProjectDataModel/RimView.h b/ApplicationCode/ProjectDataModel/RimView.h index be5d5c2edf..ec84420a08 100644 --- a/ApplicationCode/ProjectDataModel/RimView.h +++ b/ApplicationCode/ProjectDataModel/RimView.h @@ -81,6 +81,7 @@ class RimView : public caf::PdmObject RimCellRangeFilterCollection* overrideRangeFilterCollection(); void setOverrideRangeFilterCollection(RimCellRangeFilterCollection* rfc); + void replaceRangeFilterCollectionWithOverride(); caf::PdmField< std::vector > windowGeometry; diff --git a/ApplicationCode/ProjectDataModel/RimViewController.cpp b/ApplicationCode/ProjectDataModel/RimViewController.cpp index 2c5533142b..cc5eb87f78 100644 --- a/ApplicationCode/ProjectDataModel/RimViewController.cpp +++ b/ApplicationCode/ProjectDataModel/RimViewController.cpp @@ -46,6 +46,8 @@ #include "cafPdmUiTreeOrdering.h" #include "RigCaseToCaseRangeFilterMapper.h" +#include + CAF_PDM_SOURCE_INIT(RimViewController, "ViewController"); //-------------------------------------------------------------------------------------------------- /// @@ -148,6 +150,11 @@ void RimViewController::fieldChangedByUi(const caf::PdmFieldHandle* changedField { if (changedField == &m_isActive) { + if (!m_isActive) + { + applyRangeFilterCollectionByUserChoice(); + } + updateOverrides(); updateResultColorsControl(); updateCameraLink(); @@ -176,6 +183,10 @@ void RimViewController::fieldChangedByUi(const caf::PdmFieldHandle* changedField } else if (changedField == &m_syncRangeFilters) { + if (!m_syncRangeFilters) + { + applyRangeFilterCollectionByUserChoice(); + } updateOverrides(); } else if (changedField == &m_syncPropertyFilters) @@ -478,7 +489,6 @@ RimViewLinker* RimViewController::ownerViewLinker() { RimViewLinker* viewLinker = NULL; this->firstAnchestorOrThisOfType(viewLinker); - CVF_ASSERT(viewLinker); return viewLinker; } @@ -812,3 +822,52 @@ void RimViewController::updateRangeFilterOverrides(RimCellRangeFilter* changedRa } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimViewController::applyRangeFilterCollectionByUserChoice() +{ + if (!m_managedView->overrideRangeFilterCollection()) + { + return; + } + + bool restoreOriginal = askUserToRestoreOriginalRangeFilterCollection(m_managedView->name); + if (restoreOriginal) + { + m_managedView->setOverrideRangeFilterCollection(NULL); + } + else + { + m_managedView->replaceRangeFilterCollectionWithOverride(); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimViewController::askUserToRestoreOriginalRangeFilterCollection(const QString& viewName) +{ + RimView* activeView = RiaApplication::instance()->activeReservoirView(); + + QMessageBox msgBox(activeView->viewer()->layoutWidget()); + msgBox.setIcon(QMessageBox::Question); + + QString questionText; + questionText = QString("The linked view named \"%1\" is about to be unlinked. The range filters can either restore the original or keep the current range filters based on the master view.").arg(viewName); + + msgBox.setText(questionText); + msgBox.setInformativeText("Do you want to restore the original range filters?"); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + + int ret = msgBox.exec(); + if (ret == QMessageBox::Yes) + { + return true; + } + else + { + return false; + } +} + diff --git a/ApplicationCode/ProjectDataModel/RimViewController.h b/ApplicationCode/ProjectDataModel/RimViewController.h index f206b45b7c..32f31fdfce 100644 --- a/ApplicationCode/ProjectDataModel/RimViewController.h +++ b/ApplicationCode/ProjectDataModel/RimViewController.h @@ -74,6 +74,8 @@ class RimViewController : public caf::PdmObject void updateDisplayNameAndIcon(); void updateRangeFilterOverrides(RimCellRangeFilter* changedRangeFilter); + void applyRangeFilterCollectionByUserChoice(); + protected: // Pdm overridden methods virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue); @@ -98,6 +100,8 @@ class RimViewController : public caf::PdmObject RimGeoMechView* managedGeoView(); static void removeOverrides(RimView* view); + static bool askUserToRestoreOriginalRangeFilterCollection(const QString& viewName); + private: caf::PdmField m_name; caf::PdmPtrField m_managedView; diff --git a/ApplicationCode/ProjectDataModel/RimViewLinker.cpp b/ApplicationCode/ProjectDataModel/RimViewLinker.cpp index 417871c61c..b8239c3944 100644 --- a/ApplicationCode/ProjectDataModel/RimViewLinker.cpp +++ b/ApplicationCode/ProjectDataModel/RimViewLinker.cpp @@ -372,6 +372,14 @@ bool RimViewLinker::isActive() RimViewLinkerCollection* viewLinkerCollection = NULL; this->firstAnchestorOrThisOfType(viewLinkerCollection); + if (!viewLinkerCollection) + { + // This will happen when the all linked views are about to be deleted + // The viewLinker is taken out of the viewLinkerCollection, and no parent can be found + // See RicDeleteAllLinkedViewsFeature + return false; + } + return viewLinkerCollection->isActive(); } @@ -614,3 +622,22 @@ void RimViewLinker::addViewControllers(caf::PdmUiTreeOrdering& uiTreeOrdering) } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimViewLinker::applyRangeFilterCollectionByUserChoice() +{ + for (size_t j = 0; j < m_viewControllers.size(); j++) + { + m_viewControllers[j]->applyRangeFilterCollectionByUserChoice(); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimViewLinker::removeViewController(RimViewController* viewController) +{ + m_viewControllers.removeChildObject(viewController); +} + diff --git a/ApplicationCode/ProjectDataModel/RimViewLinker.h b/ApplicationCode/ProjectDataModel/RimViewLinker.h index a43f690cae..12246263d4 100644 --- a/ApplicationCode/ProjectDataModel/RimViewLinker.h +++ b/ApplicationCode/ProjectDataModel/RimViewLinker.h @@ -57,6 +57,7 @@ class RimViewLinker : public caf::PdmObject void addDependentView(RimView* view); void updateDependentViews(); + void removeViewController(RimViewController* viewController); void updateCamera(RimView* sourceView); void updateTimeStep(RimView* sourceView, int timeStep); @@ -64,6 +65,7 @@ class RimViewLinker : public caf::PdmObject void updateCellResult(); void updateRangeFilters(RimCellRangeFilter* changedRangeFilter); + void applyRangeFilterCollectionByUserChoice(); void scheduleGeometryRegenForDepViews(RivCellSetEnum geometryType); void scheduleCreateDisplayModelAndRedrawForDependentViews(); diff --git a/ApplicationCode/ProjectDataModel/RimViewLinkerCollection.cpp b/ApplicationCode/ProjectDataModel/RimViewLinkerCollection.cpp index 5f6ec52636..ece9c7a518 100644 --- a/ApplicationCode/ProjectDataModel/RimViewLinkerCollection.cpp +++ b/ApplicationCode/ProjectDataModel/RimViewLinkerCollection.cpp @@ -74,6 +74,11 @@ void RimViewLinkerCollection::fieldChangedByUi(const caf::PdmFieldHandle* change { if (viewLinker()) { + if (!isActive) + { + viewLinker()->applyRangeFilterCollectionByUserChoice(); + } + viewLinker()->updateDependentViews(); } } diff --git a/ApplicationCode/UserInterface/RiuViewer.cpp b/ApplicationCode/UserInterface/RiuViewer.cpp index cd83c8d651..6ea2cabd47 100644 --- a/ApplicationCode/UserInterface/RiuViewer.cpp +++ b/ApplicationCode/UserInterface/RiuViewer.cpp @@ -231,6 +231,7 @@ void RiuViewer::mouseReleaseEvent(QMouseEvent* event) return; } + event->accept(); m_viewerCommands->displayContextMenu(event); return; } diff --git a/ApplicationCode/UserInterface/RiuViewerCommands.cpp b/ApplicationCode/UserInterface/RiuViewerCommands.cpp index 78f41f260b..bc0cbcf3ea 100644 --- a/ApplicationCode/UserInterface/RiuViewerCommands.cpp +++ b/ApplicationCode/UserInterface/RiuViewerCommands.cpp @@ -264,7 +264,17 @@ void RiuViewerCommands::displayContextMenu(QMouseEvent* event) } } - menu.exec(event->globalPos()); + if (menu.actions().size() > 0) + { +// event->accept(); + QAction* act = menu.exec(event->globalPos()); +/* + if (act) + { + cvf::Trace::show("Jadda"); + } +*/ + } } //--------------------------------------------------------------------------------------------------