Linked Views: Refactoring ViewController

Consolidating update responsibilities.
Renaming
This commit is contained in:
Jacob Støren 2015-09-24 17:40:45 +02:00
parent d83d9e967b
commit efe5951222
4 changed files with 140 additions and 107 deletions

View File

@ -151,7 +151,7 @@ void RimViewController::fieldChangedByUi(const caf::PdmFieldHandle* changedField
if (syncCamera()) doSyncCamera();
if (syncTimeStep()) doSyncTimeStep();
if (syncCellResult()) doSyncCellResult();
configureOverrides();
updateOverrides();
}
else if (changedField == &syncCamera && syncCamera())
{
@ -181,15 +181,15 @@ void RimViewController::fieldChangedByUi(const caf::PdmFieldHandle* changedField
}
else if (changedField == &syncRangeFilters)
{
configureOverrides();
updateOverrides();
}
else if (changedField == &syncPropertyFilters)
{
configureOverrides();
updateOverrides();
}
else if (changedField == &m_managedView)
{
configureOverrides();
updateOverrides();
if (m_managedView)
{
@ -234,7 +234,7 @@ void RimViewController::fieldChangedByUi(const caf::PdmFieldHandle* changedField
else if (&m_syncVisibleCells == changedField)
{
updateOptionSensitivity();
configureOverrides();
updateOverrides();
}
}
@ -243,7 +243,7 @@ void RimViewController::fieldChangedByUi(const caf::PdmFieldHandle* changedField
//--------------------------------------------------------------------------------------------------
void RimViewController::initAfterRead()
{
configureOverrides();
updateOverrides();
updateDisplayNameAndIcon();
updateOptionSensitivity();
}
@ -271,20 +271,20 @@ RimGeoMechView* RimViewController::managedGeoView()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimViewController::configureOverrides()
void RimViewController::updateOverrides()
{
RimViewLinkerCollection* viewLinkerColl = NULL;
this->firstAnchestorOrThisOfType(viewLinkerColl);
if (!viewLinkerColl->isActive()) return;
RimViewLinker* viewLinker = NULL;
this->firstAnchestorOrThisOfType(viewLinker);
RimViewLinker* viewLinker = ownerViewLinker();
if (!viewLinker->isActive() || !isActive)
{
removeOverrides();
return;
}
RimView* masterView = viewLinker->masterView();
CVF_ASSERT(masterView);
if (!masterView) return;
if (m_managedView)
{
RimEclipseView* manEclView = managedEclipseView();
@ -300,18 +300,12 @@ void RimViewController::configureOverrides()
manEclView->updateIconStateForFilterCollections();
}
if (!isActive)
if (syncVisibleCells())
{
m_managedView->setOverrideRangeFilterCollection(NULL);
if (manEclView) manEclView->setOverridePropertyFilterCollection(NULL);
if (manGeoView) manGeoView->setOverridePropertyFilterCollection(NULL);
}
else if (syncVisibleCells())
{
m_managedView->setOverrideRangeFilterCollection(NULL);
if (manEclView) manEclView->setOverridePropertyFilterCollection(NULL);
if (manGeoView) manGeoView->setOverridePropertyFilterCollection(NULL);
m_managedView->scheduleGeometryRegen(OVERRIDDEN_CELL_VISIBILITY);
}
else
{
@ -360,6 +354,21 @@ void RimViewController::configureOverrides()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimViewController::removeOverrides()
{
if (m_managedView)
{
RimEclipseView* manEclView = managedEclipseView();
RimGeoMechView* manGeoView = managedGeoView();
m_managedView->setOverrideRangeFilterCollection(NULL);
if (manEclView) manEclView->setOverridePropertyFilterCollection(NULL);
if (manGeoView) manGeoView->setOverridePropertyFilterCollection(NULL);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -402,7 +411,7 @@ void RimViewController::updateOptionSensitivity()
this->syncPropertyFilters.uiCapability()->setUiReadOnly(false);
}
m_syncVisibleCells.uiCapability()->setUiReadOnly(!this->isVisibleCellsSyncPossible());
m_syncVisibleCells.uiCapability()->setUiReadOnly(!this->isMasterAndDepViewDifferentType());
}
//--------------------------------------------------------------------------------------------------
@ -419,6 +428,10 @@ RimView* RimViewController::managedView()
void RimViewController::setManagedView(RimView* view)
{
m_managedView = view;
this->initAfterReadRecursively();
this->updateOptionSensitivity();
this->updateDisplayNameAndIcon();
}
//--------------------------------------------------------------------------------------------------
@ -441,20 +454,6 @@ void RimViewController::defineUiOrdering(QString uiConfigName, caf::PdmUiOrderin
visibleCells->add(&syncPropertyFilters);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimViewController::removeOverrides()
{
if (m_managedView)
{
RimEclipseView* manEclView = managedEclipseView();
RimGeoMechView* manGeoView = managedGeoView();
m_managedView->setOverrideRangeFilterCollection(NULL);
if (manEclView) manEclView->setOverridePropertyFilterCollection(NULL);
if (manGeoView) manGeoView->setOverridePropertyFilterCollection(NULL);
}
}
//--------------------------------------------------------------------------------------------------
///
@ -607,7 +606,7 @@ RimView* RimViewController::masterView()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimViewController::isVisibleCellsSyncPossible()
bool RimViewController::isMasterAndDepViewDifferentType()
{
RimEclipseView* eclipseMasterView = dynamic_cast<RimEclipseView*>(masterView());
RimGeoMechView* geoMasterView = dynamic_cast<RimGeoMechView*>(masterView());
@ -630,9 +629,16 @@ bool RimViewController::isVisibleCellsSyncPossible()
//--------------------------------------------------------------------------------------------------
bool RimViewController::syncVisibleCells()
{
if (isVisibleCellsSyncPossible())
if (isMasterAndDepViewDifferentType())
{
return m_syncVisibleCells();
if (ownerViewLinker()->isActive() && this->isActive())
{
return m_syncVisibleCells();
}
else
{
return false;
}
}
else
{
@ -640,3 +646,46 @@ bool RimViewController::syncVisibleCells()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimViewController::scheduleCreateDisplayModelAndRedrawForDependentView()
{
if (!this->isActive) return;
if (this->syncVisibleCells()
|| this->syncPropertyFilters()
|| this->syncRangeFilters()
)
{
if (this->managedView())
{
this->managedView()->scheduleCreateDisplayModelAndRedraw();
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimViewController::scheduleGeometryRegenForDepViews(RivCellSetEnum geometryType)
{
if (!this->isActive) return;
if (this->syncVisibleCells()
|| this->syncPropertyFilters()
|| this->syncRangeFilters()
)
{
if (this->managedView())
{
if (this->syncVisibleCells()) {
this->managedView()->scheduleGeometryRegen(OVERRIDDEN_CELL_VISIBILITY);
}
else{
this->managedView()->scheduleGeometryRegen(geometryType);
}
}
}
}

View File

@ -26,6 +26,8 @@
#include "cvfBase.h"
#include "cvfObject.h"
#include "RivCellSetEnum.h"
class RimView;
class RimEclipseView;
class RimGeoMechView;
@ -44,54 +46,60 @@ public:
RimViewController(void);
virtual ~RimViewController(void);
caf::PdmField<bool> isActive;
caf::PdmField<QString> name;
caf::PdmField<bool> isActive;
RimView* managedView();
void setManagedView(RimView* view);
RimView* masterView();
RimViewLinker* ownerViewLinker();
RimView* managedView();
void setManagedView(RimView* view);
const RigCaseToCaseCellMapper* cellMapper();
RimView* masterView();
RimViewLinker* ownerViewLinker();
const RigCaseToCaseCellMapper* cellMapper();
// Linked (both ways) properties
caf::PdmField<bool> syncCamera;
caf::PdmField<bool> syncTimeStep;
caf::PdmField<bool> syncCamera;
caf::PdmField<bool> syncTimeStep;
// Overridden properties
caf::PdmField<bool> syncCellResult;
bool syncVisibleCells();
caf::PdmField<bool> syncRangeFilters;
caf::PdmField<bool> syncPropertyFilters;
caf::PdmField<bool> syncCellResult;
bool syncVisibleCells();
caf::PdmField<bool> syncRangeFilters;
caf::PdmField<bool> syncPropertyFilters;
void configureOverrides();
void updateOptionSensitivity();
void removeOverrides();
void scheduleCreateDisplayModelAndRedrawForDependentView();
void scheduleGeometryRegenForDepViews(RivCellSetEnum geometryType);
void updateOverrides();
void updateOptionSensitivity();
void removeOverrides();
void updateDisplayNameAndIcon();
void updateDisplayNameAndIcon();
protected:
protected: // Pdm overridden methods
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
virtual QList<caf::PdmOptionItemInfo> calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly);
virtual void defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "");
virtual void initAfterRead();
virtual caf::PdmFieldHandle* userDescriptionField() { return &name; }
virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering);
virtual void initAfterRead();
virtual caf::PdmFieldHandle* userDescriptionField() { return &name; }
virtual caf::PdmFieldHandle* objectToggleField() { return &isActive; }
private:
void doSyncCamera();
void doSyncTimeStep();
void doSyncCellResult();
void doSyncCamera();
void doSyncTimeStep();
void doSyncCellResult();
bool isVisibleCellsSyncPossible();
bool isMasterAndDepViewDifferentType();
RimEclipseView* managedEclipseView();
RimGeoMechView* managedGeoView();
RimEclipseView* managedEclipseView();
RimGeoMechView* managedGeoView();
caf::PdmPtrField<RimView*> m_managedView;
QIcon m_originalIcon;
cvf::ref<RigCaseToCaseCellMapper> m_caseToCaseCellMapper;
caf::PdmField<bool> m_syncVisibleCells;
private:
caf::PdmField<QString> name;
caf::PdmPtrField<RimView*> m_managedView;
caf::PdmField<bool> m_syncVisibleCells;
QIcon m_originalIcon;
cvf::ref<RigCaseToCaseCellMapper> m_caseToCaseCellMapper;
};

View File

@ -90,7 +90,7 @@ void RimViewLinker::updateTimeStep(RimView* sourceView, int timeStep)
if (masterView() != sourceView)
{
RimViewController* sourceViewLink = viewLinkForView(sourceView);
RimViewController* sourceViewLink = sourceView->controllingViewLink();
CVF_ASSERT(sourceViewLink);
if (!sourceViewLink->isActive() || !sourceViewLink->syncTimeStep())
@ -201,7 +201,7 @@ void RimViewLinker::updateOverrides()
RimViewController* viewLink = viewLinks[i];
if (isViewlinkerActive && viewLink->isActive)
{
viewLink->configureOverrides();
viewLink->updateOverrides();
}
else
{
@ -238,9 +238,12 @@ void RimViewLinker::allViewsForCameraSync(RimView* source, std::vector<RimView*>
for (size_t i = 0; i < viewLinks.size(); i++)
{
if (viewLinks[i]->isActive() && viewLinks[i]->syncCamera && viewLinks[i]->managedView() && source != viewLinks[i]->managedView())
if (viewLinks[i]->managedView() && source != viewLinks[i]->managedView())
{
views.push_back(viewLinks[i]->managedView());
if (viewLinks[i]->isActive() && viewLinks[i]->syncCamera())
{
views.push_back(viewLinks[i]->managedView());
}
}
}
}
@ -404,22 +407,7 @@ void RimViewLinker::scheduleGeometryRegenForDepViews(RivCellSetEnum geometryType
{
for (size_t i = 0; i < viewLinks.size(); i++)
{
if (!viewLinks[i]->isActive) continue;
if ( viewLinks[i]->syncVisibleCells()
|| viewLinks[i]->syncPropertyFilters()
|| viewLinks[i]->syncRangeFilters()
)
{
if (viewLinks[i]->managedView())
{
if (viewLinks[i]->syncVisibleCells()) {
viewLinks[i]->managedView()->scheduleGeometryRegen(OVERRIDDEN_CELL_VISIBILITY);
}else{
viewLinks[i]->managedView()->scheduleGeometryRegen(geometryType);
}
}
}
viewLinks[i]->scheduleGeometryRegenForDepViews(geometryType);
}
}
@ -430,18 +418,7 @@ void RimViewLinker::scheduleCreateDisplayModelAndRedrawForDependentViews()
{
for (size_t i = 0; i < viewLinks.size(); i++)
{
if (!viewLinks[i]->isActive) continue;
if (viewLinks[i]->syncVisibleCells()
|| viewLinks[i]->syncPropertyFilters()
|| viewLinks[i]->syncRangeFilters()
)
{
if (viewLinks[i]->managedView())
{
viewLinks[i]->managedView()->scheduleCreateDisplayModelAndRedraw();
}
}
viewLinks[i]->scheduleCreateDisplayModelAndRedrawForDependentView();
}
}
@ -675,9 +652,7 @@ void RimViewLinker::addDependentView(RimView* view)
viewLink->setManagedView(view);
viewLink->initAfterReadRecursively();
viewLink->updateOptionSensitivity();
viewLink->updateDisplayNameAndIcon();
}
//--------------------------------------------------------------------------------------------------

View File

@ -48,6 +48,8 @@ class RimViewLinker : public caf::PdmObject
public:
RimViewLinker(void);
virtual ~RimViewLinker(void);
bool isActive();
void setMasterView(RimView* view);
RimView* masterView();
@ -91,7 +93,6 @@ private:
void updateOverrides();
void removeOverrides();
bool isActive();
static bool isBoundingBoxesOverlappingOrClose(const cvf::BoundingBox& sourceBB, const cvf::BoundingBox& destBB);
private: