2012-06-26 16:10:41 +02:00
|
|
|
//##################################################################################################
|
|
|
|
|
//
|
|
|
|
|
// Custom Visualization Core library
|
2015-07-29 14:19:43 +02:00
|
|
|
// Copyright (C) Ceetron Solutions AS
|
2013-09-20 15:22:29 +02:00
|
|
|
//
|
|
|
|
|
// This library may be used under the terms of either the GNU General Public License or
|
|
|
|
|
// the GNU Lesser General Public License as follows:
|
|
|
|
|
//
|
|
|
|
|
// GNU General Public License Usage
|
|
|
|
|
// This library 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.
|
|
|
|
|
//
|
|
|
|
|
// This library 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.
|
|
|
|
|
//
|
|
|
|
|
// GNU Lesser General Public License Usage
|
|
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
// the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
|
|
|
|
// for more details.
|
2012-06-26 16:10:41 +02:00
|
|
|
//
|
|
|
|
|
//##################################################################################################
|
|
|
|
|
|
2015-07-29 14:19:43 +02:00
|
|
|
#include "cafPdmUiCommandSystemProxy.h"
|
2013-09-20 15:22:29 +02:00
|
|
|
|
2015-07-29 14:19:43 +02:00
|
|
|
#include "cafInternalPdmUiCommandSystemInterface.h"
|
2012-06-26 16:10:41 +02:00
|
|
|
|
2015-07-29 14:19:43 +02:00
|
|
|
#include "cafPdmFieldHandle.h"
|
|
|
|
|
#include "cafPdmObjectHandle.h"
|
|
|
|
|
#include "cafPdmUiFieldHandle.h"
|
|
|
|
|
#include "cafPdmUiObjectHandle.h"
|
2018-06-27 13:13:24 +02:00
|
|
|
#include "cafSelectionManager.h"
|
2012-06-26 16:10:41 +02:00
|
|
|
|
2015-07-29 14:19:43 +02:00
|
|
|
#include <cstddef>
|
|
|
|
|
|
2020-06-19 07:53:59 +02:00
|
|
|
namespace caf
|
|
|
|
|
{
|
2012-06-26 16:10:41 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 07:53:59 +02:00
|
|
|
///
|
2012-06-26 16:10:41 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-07-29 14:19:43 +02:00
|
|
|
PdmUiCommandSystemProxy* PdmUiCommandSystemProxy::instance()
|
2012-06-26 16:10:41 +02:00
|
|
|
{
|
2015-07-29 14:19:43 +02:00
|
|
|
static PdmUiCommandSystemProxy staticInstance;
|
|
|
|
|
|
|
|
|
|
return &staticInstance;
|
2012-06-26 16:10:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 07:53:59 +02:00
|
|
|
///
|
2012-06-26 16:10:41 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-07-29 14:19:43 +02:00
|
|
|
PdmUiCommandSystemProxy::PdmUiCommandSystemProxy()
|
2012-06-26 16:10:41 +02:00
|
|
|
{
|
2018-02-18 18:05:08 +01:00
|
|
|
m_commandInterface = nullptr;
|
2012-06-26 16:10:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 07:53:59 +02:00
|
|
|
///
|
2012-06-26 16:10:41 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 07:53:59 +02:00
|
|
|
void PdmUiCommandSystemProxy::setCommandInterface( PdmUiCommandSystemInterface* commandInterface )
|
2012-06-26 16:10:41 +02:00
|
|
|
{
|
2015-07-29 14:19:43 +02:00
|
|
|
m_commandInterface = commandInterface;
|
2012-06-26 16:10:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 07:53:59 +02:00
|
|
|
///
|
2012-06-26 16:10:41 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 07:53:59 +02:00
|
|
|
void PdmUiCommandSystemProxy::setUiValueToField( PdmUiFieldHandle* uiFieldHandle, const QVariant& newUiValue )
|
2012-06-26 16:10:41 +02:00
|
|
|
{
|
2021-02-15 10:58:51 +01:00
|
|
|
if ( uiFieldHandle && uiFieldHandle->fieldHandle() )
|
2015-07-29 14:19:43 +02:00
|
|
|
{
|
2018-06-27 13:13:24 +02:00
|
|
|
// Handle editing multiple objects when several objects are selected
|
2020-06-19 07:53:59 +02:00
|
|
|
PdmFieldHandle* editorField = uiFieldHandle->fieldHandle();
|
|
|
|
|
const std::type_info& fieldOwnerTypeId = typeid( *editorField->ownerObject() );
|
2018-06-29 16:21:54 +02:00
|
|
|
|
2018-06-27 13:13:24 +02:00
|
|
|
std::vector<PdmFieldHandle*> fieldsToUpdate;
|
2020-06-19 07:53:59 +02:00
|
|
|
fieldsToUpdate.push_back( editorField );
|
2018-06-27 13:13:24 +02:00
|
|
|
|
2021-02-15 10:58:51 +01:00
|
|
|
std::vector<PdmFieldHandle*> otherSelectedFields = fieldsFromSelection( fieldOwnerTypeId, editorField->keyword() );
|
2018-06-27 13:13:24 +02:00
|
|
|
|
2021-02-15 10:58:51 +01:00
|
|
|
// If current edited field is part of the selection, update all fields in selection
|
|
|
|
|
if ( std::find( otherSelectedFields.begin(), otherSelectedFields.end(), editorField ) != otherSelectedFields.end() )
|
|
|
|
|
{
|
|
|
|
|
for ( auto otherField : otherSelectedFields )
|
2018-06-27 13:13:24 +02:00
|
|
|
{
|
2021-02-15 10:58:51 +01:00
|
|
|
if ( otherField != editorField )
|
2018-06-27 13:13:24 +02:00
|
|
|
{
|
2021-02-15 10:58:51 +01:00
|
|
|
fieldsToUpdate.push_back( otherField );
|
2018-06-27 13:13:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-19 07:53:59 +02:00
|
|
|
if ( m_commandInterface )
|
2015-07-29 14:19:43 +02:00
|
|
|
{
|
2021-03-29 08:46:14 +02:00
|
|
|
caf::PdmUiObjectHandle* uiOwnerObjectHandle = uiObj( editorField->ownerObject() );
|
|
|
|
|
if ( uiOwnerObjectHandle && uiOwnerObjectHandle->useUndoRedoForFieldChanged() )
|
2018-06-27 13:13:24 +02:00
|
|
|
{
|
2021-03-29 08:46:14 +02:00
|
|
|
m_commandInterface->fieldChangedCommand( fieldsToUpdate, newUiValue );
|
|
|
|
|
return;
|
2018-06-27 13:13:24 +02:00
|
|
|
}
|
2015-07-29 14:19:43 +02:00
|
|
|
}
|
2021-03-29 08:46:14 +02:00
|
|
|
|
|
|
|
|
for ( auto fieldHandle : fieldsToUpdate )
|
|
|
|
|
{
|
|
|
|
|
fieldHandle->uiCapability()->setValueFromUiEditor( newUiValue );
|
|
|
|
|
}
|
2015-07-29 14:19:43 +02:00
|
|
|
}
|
2012-06-26 16:10:41 +02:00
|
|
|
}
|
|
|
|
|
|
2019-08-29 11:48:43 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 07:53:59 +02:00
|
|
|
///
|
2019-08-29 11:48:43 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 07:53:59 +02:00
|
|
|
void PdmUiCommandSystemProxy::setCurrentContextMenuTargetWidget( QWidget* targetWidget )
|
2019-08-29 11:48:43 +02:00
|
|
|
{
|
2020-06-19 07:53:59 +02:00
|
|
|
if ( m_commandInterface )
|
2019-08-29 11:48:43 +02:00
|
|
|
{
|
2020-06-19 07:53:59 +02:00
|
|
|
m_commandInterface->setCurrentContextMenuTargetWidget( targetWidget );
|
2019-08-29 11:48:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-26 16:10:41 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 07:53:59 +02:00
|
|
|
///
|
2012-06-26 16:10:41 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 07:53:59 +02:00
|
|
|
void PdmUiCommandSystemProxy::populateMenuWithDefaultCommands( const QString& uiConfigName, QMenu* menu )
|
2012-06-26 16:10:41 +02:00
|
|
|
{
|
2020-06-19 07:53:59 +02:00
|
|
|
if ( m_commandInterface )
|
2015-07-29 14:19:43 +02:00
|
|
|
{
|
2020-06-19 07:53:59 +02:00
|
|
|
m_commandInterface->populateMenuWithDefaultCommands( uiConfigName, menu );
|
2015-07-29 14:19:43 +02:00
|
|
|
}
|
2012-06-26 16:10:41 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-15 10:58:51 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
std::vector<PdmFieldHandle*> PdmUiCommandSystemProxy::fieldsFromSelection( const std::type_info& fieldOwnerTypeId,
|
|
|
|
|
const QString& fieldKeyword )
|
|
|
|
|
{
|
|
|
|
|
std::vector<PdmUiItem*> items;
|
|
|
|
|
std::vector<PdmFieldHandle*> additionalFieldsToUpdate;
|
|
|
|
|
|
|
|
|
|
int selectionLevel = 0;
|
|
|
|
|
SelectionManager::instance()->selectedItems( items, selectionLevel );
|
|
|
|
|
|
|
|
|
|
for ( auto& item : items )
|
|
|
|
|
{
|
|
|
|
|
PdmObjectHandle* objectHandle = dynamic_cast<PdmObjectHandle*>( item );
|
|
|
|
|
if ( objectHandle && typeid( *objectHandle ) == fieldOwnerTypeId )
|
|
|
|
|
{
|
|
|
|
|
// An object is selected, find field with same keyword as the current field being edited
|
|
|
|
|
PdmFieldHandle* fieldHandle = objectHandle->findField( fieldKeyword );
|
|
|
|
|
if ( fieldHandle )
|
|
|
|
|
{
|
|
|
|
|
additionalFieldsToUpdate.push_back( fieldHandle );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Todo Remove when dust has settled. Selection manager is not supposed to select single fields
|
|
|
|
|
// A field is selected, check if keywords are identical
|
|
|
|
|
PdmUiFieldHandle* itemFieldHandle = dynamic_cast<PdmUiFieldHandle*>( item );
|
|
|
|
|
if ( itemFieldHandle )
|
|
|
|
|
{
|
|
|
|
|
PdmFieldHandle* field = itemFieldHandle->fieldHandle();
|
|
|
|
|
if ( field && field->keyword() == fieldKeyword )
|
|
|
|
|
{
|
|
|
|
|
additionalFieldsToUpdate.push_back( field );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return additionalFieldsToUpdate;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-29 14:19:43 +02:00
|
|
|
} // end namespace caf
|