Add RimFieldReference

This commit is contained in:
Magne Sjaastad 2024-10-10 10:26:08 +02:00
parent 5526ed1a82
commit c56cd59080
5 changed files with 161 additions and 29 deletions

View File

@ -135,6 +135,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RimCameraPosition.h
${CMAKE_CURRENT_LIST_DIR}/RimWellTargetCandidatesGenerator.h
${CMAKE_CURRENT_LIST_DIR}/RimFieldQuickAccess.h
${CMAKE_CURRENT_LIST_DIR}/RimFieldReference.h
${CMAKE_CURRENT_LIST_DIR}/RimPinnedFieldCollection.h
)
@ -271,6 +272,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RimCameraPosition.cpp
${CMAKE_CURRENT_LIST_DIR}/RimWellTargetCandidatesGenerator.cpp
${CMAKE_CURRENT_LIST_DIR}/RimFieldQuickAccess.cpp
${CMAKE_CURRENT_LIST_DIR}/RimFieldReference.cpp
${CMAKE_CURRENT_LIST_DIR}/RimPinnedFieldCollection.cpp
)

View File

@ -18,19 +18,21 @@
#include "RimFieldQuickAccess.h"
#include "RimFieldReference.h"
#include "Riu3DMainWindowTools.h"
#include "cafPdmUiToolButtonEditor.h"
CAF_PDM_SOURCE_INIT( RimFieldQuickAccess, "RimFieldReference" );
CAF_PDM_SOURCE_INIT( RimFieldQuickAccess, "RimFieldQuickAccess" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimFieldQuickAccess::RimFieldQuickAccess()
{
CAF_PDM_InitFieldNoDefault( &m_object, "Object", "Object" );
CAF_PDM_InitFieldNoDefault( &m_fieldName, "FieldName", "FieldName" );
CAF_PDM_InitFieldNoDefault( &m_fieldReference, "FieldReference", "FieldReference" );
m_fieldReference = new RimFieldReference();
CAF_PDM_InitField( &m_selectObjectButton, "SelectObject", false, "...", ":/Bullet.png", "Select Object in Property Editor" );
m_selectObjectButton.uiCapability()->setUiEditorTypeName( caf::PdmUiToolButtonEditor::uiEditorTypeName() );
@ -42,12 +44,9 @@ RimFieldQuickAccess::RimFieldQuickAccess()
//--------------------------------------------------------------------------------------------------
void RimFieldQuickAccess::setField( caf::PdmFieldHandle* field )
{
if ( !field ) return;
if ( !m_fieldReference() ) return;
auto ownerObject = field->ownerObject();
if ( !ownerObject ) return;
setField( field->ownerObject(), field->keyword() );
m_fieldReference->setField( field );
}
//--------------------------------------------------------------------------------------------------
@ -55,9 +54,9 @@ void RimFieldQuickAccess::setField( caf::PdmFieldHandle* field )
//--------------------------------------------------------------------------------------------------
void RimFieldQuickAccess::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
{
if ( field() )
if ( m_fieldReference() && m_fieldReference()->field() )
{
uiOrdering.add( field() );
uiOrdering.add( m_fieldReference()->field() );
}
uiOrdering.add( &m_selectObjectButton );
@ -70,9 +69,9 @@ void RimFieldQuickAccess::defineUiOrdering( QString uiConfigName, caf::PdmUiOrde
//--------------------------------------------------------------------------------------------------
caf::PdmFieldHandle* RimFieldQuickAccess::field() const
{
if ( !m_object() ) return nullptr;
if ( !m_fieldReference() ) return nullptr;
return m_object->findField( m_fieldName() );
return m_fieldReference->field();
}
//--------------------------------------------------------------------------------------------------
@ -92,18 +91,12 @@ void RimFieldQuickAccess::fieldChangedByUi( const caf::PdmFieldHandle* changedFi
{
m_selectObjectButton = false;
if ( auto pdmObj = dynamic_cast<caf::PdmObject*>( m_object() ) )
if ( m_fieldReference() )
{
Riu3DMainWindowTools::selectAsCurrentItem( pdmObj );
if ( auto pdmObj = dynamic_cast<caf::PdmObject*>( m_fieldReference->object() ) )
{
Riu3DMainWindowTools::selectAsCurrentItem( pdmObj );
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFieldQuickAccess::setField( caf::PdmObjectHandle* object, const QString& fieldName )
{
m_object = object;
m_fieldName = fieldName;
}

View File

@ -18,9 +18,11 @@
#pragma once
#include "cafPdmChildField.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "cafPdmPtrField.h"
class RimFieldReference;
//==================================================================================================
///
@ -46,10 +48,7 @@ private:
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
void setField( caf::PdmObjectHandle* object, const QString& fieldName );
caf::PdmChildField<RimFieldReference*> m_fieldReference;
private:
caf::PdmPtrField<caf::PdmObjectHandle*> m_object;
caf::PdmField<QString> m_fieldName;
caf::PdmField<bool> m_selectObjectButton;
caf::PdmField<bool> m_selectObjectButton;
};

View File

@ -0,0 +1,85 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RimFieldReference.h"
#include "cafPdmUiToolButtonEditor.h"
CAF_PDM_SOURCE_INIT( RimFieldReference, "RimFieldReference" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimFieldReference::RimFieldReference()
{
CAF_PDM_InitFieldNoDefault( &m_object, "Object", "Object" );
CAF_PDM_InitFieldNoDefault( &m_fieldName, "FieldName", "FieldName" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFieldReference::setField( caf::PdmFieldHandle* field )
{
if ( !field ) return;
auto ownerObject = field->ownerObject();
if ( !ownerObject ) return;
setField( field->ownerObject(), field->keyword() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFieldReference::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
{
if ( field() )
{
uiOrdering.add( field() );
}
uiOrdering.skipRemainingFields();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmFieldHandle* RimFieldReference::field() const
{
if ( !m_object() ) return nullptr;
return m_object->findField( m_fieldName() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmObjectHandle* RimFieldReference::object() const
{
return m_object;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFieldReference::setField( caf::PdmObjectHandle* object, const QString& fieldName )
{
m_object = object;
m_fieldName = fieldName;
}

View File

@ -0,0 +1,53 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "cafPdmPtrField.h"
//==================================================================================================
///
/// This class is used to store a reference to a field in a PdmObject, and is similar to caf::PdmPtrField<caf::PdmObjectHandle*> that is
/// used for a non-owning reference to an object. Consider creating a caf::PdmPtrField<caf::PdmFieldHandle*> instead of this class.
///
/// Investigate if PdmFieldCapability::attributes can be used to store the field name for a caf::PdmPtrField<caf::PdmObjectHandle*>
///
//==================================================================================================
class RimFieldReference : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimFieldReference();
void setField( caf::PdmFieldHandle* field );
caf::PdmFieldHandle* field() const;
caf::PdmObjectHandle* object() const;
private:
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
void setField( caf::PdmObjectHandle* object, const QString& fieldName );
private:
caf::PdmPtrField<caf::PdmObjectHandle*> m_object;
caf::PdmField<QString> m_fieldName;
};