2015-07-29 07:19:43 -05:00
|
|
|
//##################################################################################################
|
|
|
|
//
|
|
|
|
// Custom Visualization Core library
|
|
|
|
// Copyright (C) 2011-2013 Ceetron AS
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//##################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
#include "cafCmdAddItemExec.h"
|
|
|
|
|
|
|
|
#include "cafCmdAddItemExecData.h"
|
|
|
|
|
|
|
|
#include "cafNotificationCenter.h"
|
|
|
|
#include "cafPdmReferenceHelper.h"
|
|
|
|
#include "cafSelectionManager.h"
|
|
|
|
|
|
|
|
#include "cafPdmChildArrayField.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace caf
|
|
|
|
{
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QString CmdAddItemExec::name()
|
|
|
|
{
|
|
|
|
PdmFieldHandle* field = PdmReferenceHelper::fieldFromReference(m_commandData->m_rootObject, m_commandData->m_pathToField);
|
|
|
|
|
|
|
|
QString containedObjectType = "object";
|
|
|
|
|
|
|
|
PdmChildArrayFieldHandle* listField = dynamic_cast<PdmChildArrayFieldHandle*>(field);
|
|
|
|
if (listField)
|
|
|
|
{
|
2015-08-20 08:24:49 -05:00
|
|
|
PdmXmlFieldHandle* xfh = listField->xmlCapability();
|
2015-07-29 07:19:43 -05:00
|
|
|
containedObjectType = xfh->childClassKeyword();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QString("Create new '%1'").arg(containedObjectType);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void CmdAddItemExec::redo()
|
|
|
|
{
|
|
|
|
PdmFieldHandle* field = PdmReferenceHelper::fieldFromReference(m_commandData->m_rootObject, m_commandData->m_pathToField);
|
|
|
|
|
|
|
|
PdmChildArrayFieldHandle* listField = dynamic_cast<PdmChildArrayFieldHandle*>(field);
|
2015-08-05 05:34:07 -05:00
|
|
|
if (listField && field->xmlCapability())
|
2015-07-29 07:19:43 -05:00
|
|
|
{
|
2015-10-23 08:21:23 -05:00
|
|
|
QString classKeyword = field->xmlCapability()->childClassKeyword();
|
2015-07-29 07:19:43 -05:00
|
|
|
|
|
|
|
if (classKeyword.isEmpty()) return;
|
|
|
|
|
|
|
|
caf::PdmObjectHandle* obj = PdmDefaultObjectFactory::instance()->create(classKeyword);
|
|
|
|
|
|
|
|
if (!obj) return;
|
|
|
|
|
|
|
|
listField->insertAt(m_commandData->m_indexAfter, obj);
|
|
|
|
|
|
|
|
if (m_commandData->m_indexAfter == -1)
|
|
|
|
{
|
|
|
|
m_commandData->m_createdItemIndex = static_cast<int>(listField->size() - 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_commandData->m_createdItemIndex = m_commandData->m_indexAfter;
|
|
|
|
}
|
|
|
|
|
2015-10-06 08:26:22 -05:00
|
|
|
if (m_notificationCenter) m_notificationCenter->notifyObserversOfDataChange(obj);
|
|
|
|
|
2015-08-20 03:26:16 -05:00
|
|
|
listField->uiCapability()->updateConnectedEditors();
|
2015-07-29 07:19:43 -05:00
|
|
|
|
|
|
|
if (listField->ownerObject())
|
|
|
|
{
|
2015-10-06 08:26:22 -05:00
|
|
|
caf::PdmUiObjectHandle* ownerUiObject = uiObj(listField->ownerObject());
|
|
|
|
if (ownerUiObject)
|
|
|
|
{
|
|
|
|
ownerUiObject->fieldChangedByUi(listField, QVariant(), QVariant());
|
|
|
|
}
|
2015-07-29 07:19:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void CmdAddItemExec::undo()
|
|
|
|
{
|
|
|
|
PdmFieldHandle* field = PdmReferenceHelper::fieldFromReference(m_commandData->m_rootObject, m_commandData->m_pathToField);
|
|
|
|
|
|
|
|
PdmChildArrayFieldHandle* listField = dynamic_cast<PdmChildArrayFieldHandle*>(field);
|
|
|
|
if (listField && m_commandData->m_createdItemIndex >= 0)
|
|
|
|
{
|
|
|
|
std::vector<caf::PdmObjectHandle*> children;
|
|
|
|
listField->childObjects(&children);
|
|
|
|
|
|
|
|
caf::PdmObjectHandle* obj = children[m_commandData->m_createdItemIndex];
|
|
|
|
|
|
|
|
caf::SelectionManager::instance()->removeObjectFromAllSelections(obj);
|
|
|
|
|
|
|
|
listField->erase(m_commandData->m_createdItemIndex);
|
2015-08-26 07:32:49 -05:00
|
|
|
listField->uiCapability()->updateConnectedEditors();
|
2015-07-29 07:19:43 -05:00
|
|
|
|
2015-10-06 08:26:22 -05:00
|
|
|
if (m_notificationCenter) m_notificationCenter->notifyObservers();
|
|
|
|
|
2015-07-29 07:19:43 -05:00
|
|
|
if (listField->ownerObject())
|
|
|
|
{
|
2015-10-06 08:26:22 -05:00
|
|
|
caf::PdmUiObjectHandle* ownerUiObject = uiObj(listField->ownerObject());
|
|
|
|
if (ownerUiObject)
|
|
|
|
{
|
|
|
|
ownerUiObject->fieldChangedByUi(listField, QVariant(), QVariant());
|
|
|
|
}
|
2015-07-29 07:19:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
delete obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
CmdAddItemExec::CmdAddItemExec(NotificationCenter* notificationCenter)
|
|
|
|
: CmdExecuteCommand(notificationCenter)
|
|
|
|
{
|
|
|
|
m_commandData = new CmdAddItemExecData;
|
|
|
|
}
|
|
|
|
|
2015-08-13 04:48:35 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
CmdAddItemExec::~CmdAddItemExec()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-29 07:19:43 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
CmdAddItemExecData* CmdAddItemExec::commandData()
|
|
|
|
{
|
|
|
|
return m_commandData;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace caf
|