2024-10-09 14:58:17 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// 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.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2024-10-10 10:06:57 +02:00
|
|
|
#include "RimFieldQuickAccess.h"
|
2024-10-09 14:58:17 +02:00
|
|
|
|
2024-10-10 10:26:08 +02:00
|
|
|
#include "RimFieldReference.h"
|
|
|
|
|
|
2024-10-09 14:58:17 +02:00
|
|
|
#include "Riu3DMainWindowTools.h"
|
|
|
|
|
|
|
|
|
|
#include "cafPdmUiToolButtonEditor.h"
|
|
|
|
|
|
2024-10-10 10:26:08 +02:00
|
|
|
CAF_PDM_SOURCE_INIT( RimFieldQuickAccess, "RimFieldQuickAccess" );
|
2024-10-09 14:58:17 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2024-10-10 10:06:57 +02:00
|
|
|
RimFieldQuickAccess::RimFieldQuickAccess()
|
2024-10-09 14:58:17 +02:00
|
|
|
{
|
2024-10-10 10:26:08 +02:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_fieldReference, "FieldReference", "FieldReference" );
|
|
|
|
|
m_fieldReference = new RimFieldReference();
|
2024-10-09 14:58:17 +02:00
|
|
|
|
|
|
|
|
CAF_PDM_InitField( &m_selectObjectButton, "SelectObject", false, "...", ":/Bullet.png", "Select Object in Property Editor" );
|
|
|
|
|
m_selectObjectButton.uiCapability()->setUiEditorTypeName( caf::PdmUiToolButtonEditor::uiEditorTypeName() );
|
|
|
|
|
m_selectObjectButton.xmlCapability()->disableIO();
|
2024-10-11 11:58:25 +02:00
|
|
|
|
|
|
|
|
CAF_PDM_InitField( &m_removeObjectButton, "RemoveObject", false, "...", ":/Erase.svg", "Remove Item" );
|
|
|
|
|
m_removeObjectButton.uiCapability()->setUiEditorTypeName( caf::PdmUiToolButtonEditor::uiEditorTypeName() );
|
|
|
|
|
m_removeObjectButton.xmlCapability()->disableIO();
|
|
|
|
|
|
|
|
|
|
m_toBeDeleted = false;
|
2024-10-09 14:58:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2024-10-10 10:06:57 +02:00
|
|
|
void RimFieldQuickAccess::setField( caf::PdmFieldHandle* field )
|
2024-10-09 14:58:17 +02:00
|
|
|
{
|
2024-10-10 10:26:08 +02:00
|
|
|
if ( !m_fieldReference() ) return;
|
2024-10-09 14:58:17 +02:00
|
|
|
|
2024-10-10 10:26:08 +02:00
|
|
|
m_fieldReference->setField( field );
|
2024-10-09 14:58:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2024-10-10 10:06:57 +02:00
|
|
|
void RimFieldQuickAccess::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
2024-10-09 14:58:17 +02:00
|
|
|
{
|
2024-10-10 10:26:08 +02:00
|
|
|
if ( m_fieldReference() && m_fieldReference()->field() )
|
2024-10-09 14:58:17 +02:00
|
|
|
{
|
2024-10-10 10:26:08 +02:00
|
|
|
uiOrdering.add( m_fieldReference()->field() );
|
2024-10-09 14:58:17 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-11 11:58:25 +02:00
|
|
|
uiOrdering.add( &m_selectObjectButton, { .newRow = false } );
|
|
|
|
|
uiOrdering.add( &m_removeObjectButton, { .newRow = false } );
|
2024-10-09 14:58:17 +02:00
|
|
|
|
|
|
|
|
uiOrdering.skipRemainingFields();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2024-10-10 10:06:57 +02:00
|
|
|
caf::PdmFieldHandle* RimFieldQuickAccess::field() const
|
2024-10-09 14:58:17 +02:00
|
|
|
{
|
2024-10-10 10:26:08 +02:00
|
|
|
if ( !m_fieldReference() ) return nullptr;
|
2024-10-09 14:58:17 +02:00
|
|
|
|
2024-10-10 10:26:08 +02:00
|
|
|
return m_fieldReference->field();
|
2024-10-09 14:58:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2024-10-11 11:58:25 +02:00
|
|
|
bool RimFieldQuickAccess::toBeDeleted() const
|
2024-10-09 14:58:17 +02:00
|
|
|
{
|
2024-10-11 11:58:25 +02:00
|
|
|
return m_toBeDeleted;
|
2024-10-09 14:58:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2024-10-10 10:06:57 +02:00
|
|
|
void RimFieldQuickAccess::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
|
2024-10-09 14:58:17 +02:00
|
|
|
{
|
|
|
|
|
if ( changedField == &m_selectObjectButton )
|
|
|
|
|
{
|
|
|
|
|
m_selectObjectButton = false;
|
|
|
|
|
|
2024-10-10 10:26:08 +02:00
|
|
|
if ( m_fieldReference() )
|
2024-10-09 14:58:17 +02:00
|
|
|
{
|
2024-10-10 10:26:08 +02:00
|
|
|
if ( auto pdmObj = dynamic_cast<caf::PdmObject*>( m_fieldReference->object() ) )
|
|
|
|
|
{
|
|
|
|
|
Riu3DMainWindowTools::selectAsCurrentItem( pdmObj );
|
|
|
|
|
}
|
2024-10-09 14:58:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
2024-10-11 11:58:25 +02:00
|
|
|
|
|
|
|
|
if ( changedField == &m_removeObjectButton )
|
|
|
|
|
{
|
|
|
|
|
m_removeObjectButton = false;
|
|
|
|
|
|
|
|
|
|
m_toBeDeleted = true;
|
|
|
|
|
}
|
2024-10-09 14:58:17 +02:00
|
|
|
}
|