2015-08-14 02:45:57 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2015- Statoil ASA
|
|
|
|
// Copyright (C) 2015- Ceetron Solutions AS
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2015-08-14 02:45:57 -05:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2015-08-14 02:45:57 -05:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2015-08-14 02:45:57 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
2015-08-11 13:59:05 -05:00
|
|
|
|
|
|
|
#include "RicDeleteItemExec.h"
|
|
|
|
#include "RicDeleteItemExecData.h"
|
|
|
|
|
2015-09-15 06:14:13 -05:00
|
|
|
#include "cafNotificationCenter.h"
|
|
|
|
#include "cafPdmChildArrayField.h"
|
|
|
|
#include "cafPdmDocument.h"
|
|
|
|
#include "cafPdmReferenceHelper.h"
|
|
|
|
#include "cafPdmUiFieldHandle.h"
|
|
|
|
#include "cafSelectionManager.h"
|
2015-08-11 13:59:05 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2015-08-11 13:59:05 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QString RicDeleteItemExec::name()
|
|
|
|
{
|
2021-02-09 06:31:27 -06:00
|
|
|
if ( !m_commandData.m_description().isEmpty() )
|
|
|
|
{
|
|
|
|
return m_commandData.m_description();
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_commandData.classKeyword();
|
2015-08-11 13:59:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2015-08-11 13:59:05 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicDeleteItemExec::redo()
|
|
|
|
{
|
2023-02-26 03:48:40 -06:00
|
|
|
caf::PdmFieldHandle* field = caf::PdmReferenceHelper::fieldFromReference( m_commandData.m_rootObject, m_commandData.m_pathToField );
|
2015-08-11 13:59:05 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::PdmChildArrayFieldHandle* listField = dynamic_cast<caf::PdmChildArrayFieldHandle*>( field );
|
|
|
|
if ( listField )
|
2015-08-11 13:59:05 -05:00
|
|
|
{
|
2023-05-12 14:41:34 -05:00
|
|
|
std::vector<caf::PdmObjectHandle*> children = listField->children();
|
2015-08-11 13:59:05 -05:00
|
|
|
|
2021-02-09 06:31:27 -06:00
|
|
|
caf::PdmObjectHandle* obj = children[m_commandData.m_indexToObject];
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::SelectionManager::instance()->removeObjectFromAllSelections( obj );
|
2015-08-11 13:59:05 -05:00
|
|
|
|
2023-05-12 14:41:34 -05:00
|
|
|
std::vector<caf::PdmObjectHandle*> referringObjects = obj->objectsWithReferringPtrFields();
|
2016-11-04 02:48:38 -05:00
|
|
|
|
2021-02-09 06:31:27 -06:00
|
|
|
if ( m_commandData.m_deletedObjectAsXml().isEmpty() )
|
2015-08-11 13:59:05 -05:00
|
|
|
{
|
2021-02-09 06:31:27 -06:00
|
|
|
m_commandData.m_deletedObjectAsXml = xmlObj( obj )->writeObjectToXmlString();
|
2015-08-11 13:59:05 -05:00
|
|
|
}
|
|
|
|
|
2015-08-13 04:47:43 -05:00
|
|
|
delete obj;
|
2015-08-11 13:59:05 -05:00
|
|
|
|
2021-02-09 06:31:27 -06:00
|
|
|
listField->erase( m_commandData.m_indexToObject );
|
2015-09-25 07:46:45 -05:00
|
|
|
|
2015-08-14 08:20:50 -05:00
|
|
|
caf::PdmObjectHandle* parentObj = listField->ownerObject();
|
2015-08-20 08:24:49 -05:00
|
|
|
parentObj->uiCapability()->updateConnectedEditors();
|
2020-05-18 09:02:27 -05:00
|
|
|
parentObj->onChildDeleted( listField, referringObjects );
|
2015-08-11 13:59:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2015-08-11 13:59:05 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicDeleteItemExec::undo()
|
|
|
|
{
|
2023-02-26 03:48:40 -06:00
|
|
|
caf::PdmFieldHandle* field = caf::PdmReferenceHelper::fieldFromReference( m_commandData.m_rootObject, m_commandData.m_pathToField );
|
2015-08-11 13:59:05 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::PdmChildArrayFieldHandle* listField = dynamic_cast<caf::PdmChildArrayFieldHandle*>( field );
|
|
|
|
if ( listField )
|
2015-08-11 13:59:05 -05:00
|
|
|
{
|
2023-02-26 03:48:40 -06:00
|
|
|
caf::PdmObjectHandle* obj = caf::PdmXmlObjectHandle::readUnknownObjectFromXmlString( m_commandData.m_deletedObjectAsXml(),
|
|
|
|
caf::PdmDefaultObjectFactory::instance(),
|
|
|
|
false );
|
2015-08-11 13:59:05 -05:00
|
|
|
|
2021-02-09 06:31:27 -06:00
|
|
|
listField->insertAt( m_commandData.m_indexToObject, obj );
|
2015-08-11 13:59:05 -05:00
|
|
|
|
2015-08-27 04:56:52 -05:00
|
|
|
obj->xmlCapability()->initAfterReadRecursively();
|
2021-02-09 06:31:27 -06:00
|
|
|
obj->xmlCapability()->resolveReferencesRecursively();
|
2015-08-12 04:10:10 -05:00
|
|
|
|
|
|
|
listField->uiCapability()->updateConnectedEditors();
|
2015-08-20 08:24:49 -05:00
|
|
|
listField->ownerObject()->uiCapability()->updateConnectedEditors();
|
2015-08-12 04:10:10 -05:00
|
|
|
|
2021-02-09 06:31:27 -06:00
|
|
|
caf::PdmObjectHandle* parentObj = listField->ownerObject();
|
|
|
|
if ( parentObj )
|
|
|
|
{
|
|
|
|
std::vector<caf::PdmObjectHandle*> referringObjects;
|
|
|
|
|
|
|
|
// TODO: Here we need a different concept like onChildAdded()
|
|
|
|
parentObj->onChildDeleted( listField, referringObjects );
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( m_notificationCenter ) m_notificationCenter->notifyObservers();
|
2015-08-11 13:59:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2015-08-11 13:59:05 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
RicDeleteItemExec::RicDeleteItemExec( caf::NotificationCenter* notificationCenter )
|
|
|
|
: CmdExecuteCommand( notificationCenter )
|
2015-08-11 13:59:05 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2015-08-11 13:59:05 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-02-09 06:31:27 -06:00
|
|
|
RicDeleteItemExecData& RicDeleteItemExec::commandData()
|
2015-08-11 13:59:05 -05:00
|
|
|
{
|
|
|
|
return m_commandData;
|
|
|
|
}
|