Copied in RPM/Fwk/AppFwk

Commented out use of stipple line, as VizFwk is not update yet
This commit is contained in:
Magne Sjaastad
2015-07-29 14:19:43 +02:00
parent 81cf711036
commit 58149cbdb9
283 changed files with 72838 additions and 4741 deletions
+72
View File
@@ -0,0 +1,72 @@
cmake_minimum_required (VERSION 2.8)
# Qt
find_package ( Qt4 COMPONENTS QtCore QtGui QtMain )
include (${QT_USE_FILE})
project (cafCommand)
include_directories(
${cafProjectDataModel_SOURCE_DIR}
)
include_directories (
${cafPdmCore_SOURCE_DIR}
${cafPdmUiCore_SOURCE_DIR}
${cafPdmXml_SOURCE_DIR}
.
)
# These headers need to go through Qt's MOC compiler
set( QOBJECT_HEADERS
cafCmdFeature.h
cafCmdFeatureManager.h
)
if ( (${CMAKE_VERSION} VERSION_LESS 2.8.6) OR (NOT CMAKE_AUTOMOC) )
qt4_wrap_cpp( MOC_FILES_CPP ${QOBJECT_HEADERS} )
endif()
set( PROJECT_FILES
cafCmdExecCommandManager.cpp
cafCmdExecCommandManager.h
cafCmdExecuteCommand.h
cafCmdUiCommandSystemImpl.h
cafCmdUiCommandSystemImpl.cpp
# Default features
defaultfeatures/cafCmdAddItemExec.cpp
defaultfeatures/cafCmdAddItemExec.h
defaultfeatures/cafCmdAddItemExecData.cpp
defaultfeatures/cafCmdAddItemExecData.h
defaultfeatures/cafCmdAddItemFeature.cpp
defaultfeatures/cafCmdAddItemFeature.h
defaultfeatures/cafCmdDeleteItemExec.cpp
defaultfeatures/cafCmdDeleteItemExec.h
defaultfeatures/cafCmdDeleteItemExecData.cpp
defaultfeatures/cafCmdDeleteItemExecData.h
defaultfeatures/cafCmdDeleteItemFeature.cpp
defaultfeatures/cafCmdDeleteItemFeature.h
cafCmdFieldChangeExec.cpp
cafCmdFieldChangeExec.h
cafCmdSelectionHelper.cpp
cafCmdSelectionHelper.h
cafCmdSelectionChangeExec.cpp
cafCmdSelectionChangeExec.h
cafCmdFeature.cpp
cafCmdFeature.h
cafCmdFeatureManager.cpp
cafCmdFeatureManager.h
)
add_library( ${PROJECT_NAME}
${PROJECT_FILES}
${MOC_FILES_CPP}
)
source_group("" FILES ${PROJECT_FILES})
@@ -0,0 +1,165 @@
@startuml
scale 1200 width
class PdmUiTableEditor{
QMenu * buildDefaultContextMenu()
enableDefaultContextMenu(bool );
}
PdmUiTableEditor ---> CmdFeatureManager :"GetQAction(id)"
PdmUiTableEditor --* QTableView
QTableView --> NodeTableMenuCreator : signal CustomContextMenu(QMenu*)
NodeTableMenuCreator .. SelectionManager
NodeTableMenuCreator ---> CmdFeatureManager :"GetQAction(id)"
class MainWindow{
refreshAllVisibleToolbars()
}
MainWindow --> CmdFeatureManager: refreshEnabledState()
class SelectionManager{
SelectionStack
CurrentTempSelection
---
CurrentItem ?
PreHighlightSelection ?
---
activePdmCommandFeature
}
class CmdFeatureManager{
QAction* action(commandId)
void refreshEnabledState([commandIdList])
void refreshCheckedState([commandIdList])
void refreshStates([commandIdList])
CmdFeature* getCommandFeature(const std::string& commandId)
}
CmdFeatureManager ----* "n" CmdFeature
CmdFeatureManager --> "get new" CmdFeatureFactory
class CmdFeature{
QAction* action()
QAction* action(QString customText);
void refreshEnabledState();
void refreshCheckedState();
--
slot:
void actionTriggered(bool isChecked)
}
CmdFeature <|-- CmdAddItemFeature
SelectionManager <----> CmdAddItemFeature
CmdAddItemFeature --> "create" CmdAddItemExec
CmdAddItemFeature -l-> "processExecuteCommand()" CmdExecCommandManager
CmdFeature -l-> CmdFeatureFactory :"register"
CmdFeature ..> "create" CmdExecuteCommand
CmdFeature ..> "processExecuteCommand()" CmdExecCommandManager
CmdFeature .> "Thought" CommandUserProcess
CommandUserProcess .> "Thought" CommandUi
class CmdExecuteCommand{
virtual redo()
virtual undo()
}
CmdExecuteCommand <|--- CmdFieldChangeExec
CmdFieldChangeExec --* CmdFieldChangeExecData
PdmObject <|- CmdFieldChangeExecData
CmdExecuteCommand <|--- CmdAddItemExec
CmdAddItemExec --* CmdAddItemExecData
PdmObject <|- CmdAddItemExecData
class CmdExecCommandManager{
void activateCommandSystem();
void enableUndoCommandSystem(bool enable);
QUndoStack* undoStack();
void processExecuteCommand( CmdExecuteCommand* cmd)
void processExecuteCommandsAsMacro(const QString& macroName,
std::vector<CmdExecuteCommand*>& commands);
}
CmdExecCommandManager --* "n" CmdExecuteCommand
package "Project Data Model UI" {
class PdmUiFieldEditorHandle
PdmUiFieldEditorHandle -> PdmUiCommandSystemProxy : setUiValueToField()
class PdmUiCommandSystemProxy
note right
If the commandinterface object is set,
delegate handling of field changed events to this object
If no commandinterface,
perform basic field change on a single field
end note
class PdmUiCommandSystemProxy{
void setCommandInterface(PdmUiCommandFeatureInterface* undoCommandInterface);
void setUiValueToField(PdmUiFieldHandle* uiFieldHandle, const QVariant& newUiValue);
void populateMenu(const QString& uiConfigName, QMenu* menu);
}
PdmUiCommandSystemProxy "Process Ui requests" ..> PdmUiCommandFeatureInterface
}
class PdmUiCommandFeatureInterface{
virtual void fieldChangedCommand(PdmFieldHandle* field, const QVariant& newUiValue) = 0;
virtual void populateMenu(const QString& uiConfigName, QMenu* menu) = 0;
}
CmdFieldChangeExec --> CmdExecCommandManager
CmdExecCommandManager "Registers command interface" .> PdmUiCommandSystemProxy
PdmUiCommandFeatureInterface <|- CmdUiCommandSystemImpl
class CmdUiCommandSystemImpl
note bottom
fieldChangedCommand interacts with selection system
to find all selected fields with same keyword as being edited
creates N CmdFieldChangeExec commands, and insert into undo stack if needed
populateMenu creates the UI menu for default commands (add item/delete item)
end note
class CmdUiCommandSystemImpl{
virtual void fieldChangedCommand(PdmFieldHandle* field, const QVariant& newUiValue);
virtual void populateMenu(const QString& uiConfigName, QMenu* menu);
virtual bool isUndoEnabled();
}
CmdUiCommandSystemImpl ----* "n" CmdFieldChangeExec
@enduml
@@ -0,0 +1,194 @@
//##################################################################################################
//
// 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 "cafCmdExecCommandManager.h"
#include "cafCmdExecuteCommand.h"
#include "cafCmdUiCommandSystemImpl.h"
#include "cafPdmUiCommandSystemProxy.h"
#include <QUndoCommand>
//--------------------------------------------------------------------------------------------------
/// Classed used to take over ownership of an execute command and wrap it in a QUndoCommand
//--------------------------------------------------------------------------------------------------
class UndoRedoWrapper : public QUndoCommand
{
public:
UndoRedoWrapper(caf::CmdExecuteCommand* executeCommand)
{
m_executeCommand = executeCommand;
setText(m_executeCommand->name());
}
~UndoRedoWrapper()
{
delete m_executeCommand;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
virtual void undo()
{
m_executeCommand->undo();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
virtual void redo()
{
m_executeCommand->redo();
}
private:
caf::CmdExecuteCommand* m_executeCommand;
};
namespace caf
{
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CmdExecCommandManager::CmdExecCommandManager()
{
m_commandFeatureInterface = NULL;
m_undoStack = new QUndoStack();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CmdExecCommandManager* CmdExecCommandManager::instance()
{
static CmdExecCommandManager* singleton = new CmdExecCommandManager;
return singleton;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdExecCommandManager::activateCommandSystem()
{
if (!m_commandFeatureInterface)
{
m_commandFeatureInterface = new CmdUiCommandSystemImpl;
PdmUiCommandSystemProxy::instance()->setCommandInterface(m_commandFeatureInterface);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdExecCommandManager::enableUndoCommandSystem(bool enable)
{
this->activateCommandSystem();
m_commandFeatureInterface->enableUndoFeature(enable);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QUndoStack* CmdExecCommandManager::undoStack()
{
return m_undoStack;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdExecCommandManager::processExecuteCommand(CmdExecuteCommand* executeCommand)
{
if (m_commandFeatureInterface && m_commandFeatureInterface->isUndoEnabled())
{
// Transfer ownership of execute command to wrapper object
UndoRedoWrapper* undoRedoWrapper = new UndoRedoWrapper(executeCommand);
m_undoStack->push(undoRedoWrapper);
}
else
{
// Execute command and delete the execute command
executeCommand->redo();
delete executeCommand;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdExecCommandManager::processExecuteCommandsAsMacro(const QString& macroName, std::vector<CmdExecuteCommand*>& commands)
{
if (commands.size() == 0)
{
return;
}
if (m_commandFeatureInterface && m_commandFeatureInterface->isUndoEnabled())
{
m_undoStack->beginMacro(macroName);
for (size_t i = 0; i < commands.size(); i++)
{
UndoRedoWrapper* undoRedoWrapper = new UndoRedoWrapper(commands[i]);
m_undoStack->push(undoRedoWrapper);
}
m_undoStack->endMacro();
}
else
{
for (size_t i = 0; i < commands.size(); i++)
{
CmdExecuteCommand* executeCommand = commands[i];
if (executeCommand)
{
executeCommand->redo();
delete executeCommand;
}
}
}
}
} // end namespace caf
@@ -0,0 +1,86 @@
//##################################################################################################
//
// 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.
//
//##################################################################################################
#pragma once
#include <vector>
class QUndoStack;
class QString;
namespace caf
{
class CmdExecuteCommand;
class CmdUiCommandSystemImpl;
//==================================================================================================
///
//==================================================================================================
class CmdExecCommandManager
{
public:
static CmdExecCommandManager* instance();
// Creates the object (CmdUiCommandSystemImpl) used to communicate from UI editors to advanced parts of the command system
// This includes support for undo system and default command features for add/delete of items in PdmChildArrayFieldHandle
// and creation of field changed commands so a change in an editor can be put into undo/redo
// CmdUiCommandSystemImpl is a requirement for using the undo system
void activateCommandSystem();
// When the undoFeature is enabled, execute commands are inserted in the undo stack
// The application can use the QUndoStack to display/modify execute commands wrapped in QUndoCommand objects
void enableUndoCommandSystem(bool enable);
QUndoStack* undoStack();
// If undo system is enabled, the PdmExecuteCommand is wrapped in a QUndoCommand and inserted in the QUndoStack.
// If undo is not possible (undo system not enabled, or pdm object has disabled undo),
// the PdmExecuteCommand is executed and deleted
void processExecuteCommand(CmdExecuteCommand* executeCommand);
void processExecuteCommandsAsMacro(const QString& macroName, std::vector<CmdExecuteCommand*>& commands);
private:
CmdExecCommandManager();
private:
QUndoStack* m_undoStack;
CmdUiCommandSystemImpl* m_commandFeatureInterface;
};
} // end namespace caf
@@ -0,0 +1,70 @@
//##################################################################################################
//
// 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.
//
//##################################################################################################
#pragma once
#include <QString>
#include <assert.h>
namespace caf
{
class NotificationCenter;
class PdmObjectHandle;
//==================================================================================================
///
//==================================================================================================
class CmdExecuteCommand
{
public:
CmdExecuteCommand(NotificationCenter* notificationCenter)
{
m_notificationCenter = notificationCenter;
}
virtual QString name() = 0;
virtual void redo() = 0;
virtual void undo() = 0;
protected:
NotificationCenter* m_notificationCenter;
};
} // end namespace caf
+116
View File
@@ -0,0 +1,116 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2014 Ceetron Solutions 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 "cafCmdFeature.h"
#include "cafCmdExecCommandManager.h"
#include "cafCmdFeatureManager.h"
#include <assert.h>
#include <QAction>
namespace caf
{
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QAction* CmdFeature::action()
{
return this->action(QString(""));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QAction* CmdFeature::action(QString customText)
{
std::map<QString, QAction*>::iterator it;
it = m_customTextToActionMap.find(customText);
if (it != m_customTextToActionMap.end() && it->second != NULL)
{
return it->second;
}
else
{
QAction* action = new QAction(this);
this->setupActionLook(action);
if (!customText.isEmpty())
{
action->setText(customText);
}
connect(action, SIGNAL(triggered(bool)), SLOT(actionTriggered(bool)));
m_customTextToActionMap[customText]= action;
return action;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdFeature::refreshEnabledState()
{
std::map<QString, QAction*>::iterator it;
bool isEnabled = this->isCommandEnabled();
for (it = m_customTextToActionMap.begin(); it != m_customTextToActionMap.end(); ++it)
{
it->second->setEnabled(isEnabled);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdFeature::refreshCheckedState()
{
std::map<QString, QAction*>::iterator it;
bool isChecked = this->isCommandChecked();
for (it = m_customTextToActionMap.begin(); it != m_customTextToActionMap.end(); ++it)
{
QAction* act = it->second;
if (act->isCheckable())
{
it->second->setChecked(isChecked);
}
}
}
} // end namespace caf
+99
View File
@@ -0,0 +1,99 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2014 Ceetron Solution 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.
//
//##################################################################################################
#pragma once
#include "cafFactory.h"
#include <map>
#include <string>
#include <QObject>
class QAction;
class QIcon;
class QString;
#define CAF_CMD_HEADER_INIT \
public: \
static const std::string& idNameStatic()
#define CAF_CMD_SOURCE_INIT(ClassName, CommandIdName)\
const std::string& ClassName::idNameStatic() { static std::string id = CommandIdName; return id;} \
CAF_FACTORY_REGISTER(caf::CmdFeature, ClassName, std::string, ClassName::idNameStatic())
namespace caf
{
class CmdExecuteCommand;
//==================================================================================================
/// 1. If a direct command with no UI is requested, create an ExecuteCommand object and execute command
/// 2. If UI is required, create a CommandUI object and display to user. When user accepts data input,
/// create an ExecuteCommand object and fill in the data provided by the user
/// 3. If a user process is required, create start an CommandUserProcess. When the process is complete,
/// create an ExecuteCommand object and fill in the data provided by the user
//==================================================================================================
class CmdFeature : public QObject
{
Q_OBJECT
public:
CmdFeature() {}
virtual ~CmdFeature() {}
QAction* action();
QAction* action(QString customText);
void refreshEnabledState();
void refreshCheckedState();
public slots:
void actionTriggered(bool isChecked) { this->onActionTriggered(isChecked); }
protected:
virtual void onActionTriggered(bool isChecked) = 0;
virtual void setupActionLook(QAction* actionToSetup) = 0;
virtual bool isCommandEnabled() = 0;
virtual bool isCommandChecked() { return false; }
private:
std::map<QString, QAction*> m_customTextToActionMap;
};
} // end namespace caf
@@ -0,0 +1,252 @@
//##################################################################################################
//
// 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 "cafCmdFeatureManager.h"
#include "cafCmdFeature.h"
#include "cafCmdSelectionHelper.h"
#include "cafFactory.h"
#include "defaultfeatures/cafCmdDeleteItemFeature.h"
#include "defaultfeatures/cafCmdAddItemFeature.h"
#include <QAction>
#include <assert.h>
namespace caf
{
typedef Factory<CmdFeature, std::string> CommandFeatureFactory;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CmdFeatureManager::CmdFeatureManager()
{
CmdDeleteItemFeature::idNameStatic();
CmdAddItemFeature::idNameStatic();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CmdFeatureManager::~CmdFeatureManager()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CmdFeatureManager* CmdFeatureManager::instance()
{
static CmdFeatureManager* singleton = new CmdFeatureManager;
return singleton;
}
//--------------------------------------------------------------------------------------------------
/// Get action for the specified command.
/// The action is owned by the PdmCommandItemManager
//--------------------------------------------------------------------------------------------------
QAction* CmdFeatureManager::action(const QString& commandId)
{
std::pair<CmdFeature*, size_t> featurePair = createFeature(commandId.toStdString());
QAction* act = featurePair.first->action();
m_actionToFeatureIdxMap[act] = featurePair.second;
return act;
}
//--------------------------------------------------------------------------------------------------
/// Get action for the specified command, with custom action text
/// The action is owned by the PdmCommandItemManager
//--------------------------------------------------------------------------------------------------
QAction* CmdFeatureManager::action(const QString& commandId, const QString& customActionText)
{
std::pair<CmdFeature*, size_t> featurePair = createFeature(commandId.toStdString());
QAction* act = featurePair.first->action(customActionText);
m_actionToFeatureIdxMap[act] = featurePair.second;
return act;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::pair<CmdFeature*, size_t> CmdFeatureManager::createFeature(const std::string& commandId)
{
std::pair<CmdFeature*, size_t> featurePair = this->findExistingCmdFeature(commandId);
if (featurePair.first)
{
return featurePair;
}
CmdFeature* feature = CommandFeatureFactory::instance()->create(commandId);
assert(feature); // The command ID is not known in the factory
feature->setParent(this);
size_t index = m_commandFeatures.size();
m_commandFeatures.push_back(feature);
m_commandIdToFeatureIdxMap[commandId] = index;
return std::make_pair(feature, index);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::pair<CmdFeature*, size_t> CmdFeatureManager::findExistingCmdFeature(const std::string& commandId)
{
std::map<std::string, size_t>::const_iterator it;
it = m_commandIdToFeatureIdxMap.find(commandId);
if (it != m_commandIdToFeatureIdxMap.end())
{
size_t itemIndex = it->second;
CmdFeature* item = m_commandFeatures[itemIndex];
item->refreshEnabledState();
return std::make_pair(item, itemIndex);
}
else
{
return std::make_pair(static_cast<CmdFeature*>(NULL), -1);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdFeatureManager::refreshStates(const QStringList& commandIdList)
{
if (commandIdList.size() == 0)
{
for (int i = 0; i < m_commandFeatures.size(); i++)
{
CmdFeature* cmdFeature = m_commandFeatures[i];
if (cmdFeature)
{
cmdFeature->refreshEnabledState();
cmdFeature->refreshCheckedState();
}
}
}
else
{
for (int i = 0; i < commandIdList.size(); i++)
{
std::pair<CmdFeature*, size_t> featurePair = findExistingCmdFeature(commandIdList.at(i).toStdString());
if (featurePair.first)
{
featurePair.first->refreshEnabledState();
featurePair.first->refreshCheckedState();
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdFeatureManager::refreshEnabledState(const QStringList& commandIdList)
{
if (commandIdList.size() == 0)
{
for (int i = 0; i < m_commandFeatures.size(); i++)
{
m_commandFeatures[i]->refreshEnabledState();
}
}
else
{
for (int i = 0; i < commandIdList.size(); i++)
{
std::pair<CmdFeature*, size_t> featurePair = findExistingCmdFeature(commandIdList.at(i).toStdString());
if (featurePair.first)
{
featurePair.first->refreshEnabledState();
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdFeatureManager::refreshCheckedState(const QStringList& commandIdList)
{
if (commandIdList.size() == 0)
{
for (int i = 0; i < m_commandFeatures.size(); i++)
{
m_commandFeatures[i]->refreshCheckedState();
}
}
else
{
for (int i = 0; i < commandIdList.size(); i++)
{
std::pair<CmdFeature*, size_t> featurePair = findExistingCmdFeature(commandIdList.at(i).toStdString());
if (featurePair.first)
{
featurePair.first->refreshCheckedState();
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CmdFeature* CmdFeatureManager::getCommandFeature(const std::string& commandId)
{
std::pair<CmdFeature*, size_t> featurePair = createFeature(commandId);
return featurePair.first;
}
} // end namespace caf
@@ -0,0 +1,88 @@
//##################################################################################################
//
// 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.
//
//##################################################################################################
#pragma once
#include <vector>
#include <map>
#include <set>
#include <QObject>
#include <QStringList>
class QAction;
namespace caf
{
class CmdFeature;
//==================================================================================================
///
//==================================================================================================
class CmdFeatureManager : public QObject
{
Q_OBJECT
public:
static CmdFeatureManager* instance();
virtual ~CmdFeatureManager();
QAction* action(const QString& commandId);
QAction* action(const QString& commandId, const QString& actionText);
void refreshStates(const QStringList& commandIdList = QStringList());
void refreshEnabledState(const QStringList& commandIdList = QStringList());
void refreshCheckedState(const QStringList& commandIdList = QStringList());
CmdFeature* getCommandFeature(const std::string& commandId);
private:
CmdFeatureManager();
std::pair<CmdFeature*, size_t> createFeature(const std::string& commandId);
std::pair<CmdFeature*, size_t> findExistingCmdFeature(const std::string& commandId);
std::vector<CmdFeature*> m_commandFeatures;
std::map<std::string , size_t > m_commandIdToFeatureIdxMap;
std::map<QAction*, size_t > m_actionToFeatureIdxMap;
};
} // end namespace caf
@@ -0,0 +1,207 @@
//##################################################################################################
//
// 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 "cafCmdFieldChangeExec.h"
#include "cafPdmReferenceHelper.h"
#include "cafNotificationCenter.h"
namespace caf
{
CAF_PDM_SOURCE_INIT(CmdFieldChangeExecData, "CmdFieldChangeExecData");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString CmdFieldChangeExec::name()
{
PdmFieldHandle* field = PdmReferenceHelper::fieldFromReference(m_commandData->m_rootObject, m_commandData->m_pathToField);
if (field)
{
QString fieldText;
PdmUiFieldHandle* uiFieldHandle = uiField(field);
if (uiFieldHandle)
{
fieldText = QString("Change field '%1'").arg(uiFieldHandle->uiName());
}
if (field->ownerObject())
{
PdmUiObjectHandle* uiObjHandle = uiObj(field->ownerObject());
if (uiObjHandle)
{
fieldText += QString(" in '%1'").arg(uiObjHandle->uiName());
}
}
return fieldText;
}
else
{
return m_commandData->classKeyword();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdFieldChangeExec::redo()
{
PdmFieldHandle* field = PdmReferenceHelper::fieldFromReference(m_commandData->m_rootObject, m_commandData->m_pathToField);
if (!field)
{
assert(false);
return;
}
PdmUiFieldHandle* uiFieldHandle = uiField(field);
PdmXmlFieldHandle* xmlFieldHandle = xmlField(field);
if (uiFieldHandle && xmlFieldHandle)
{
if (m_commandData->m_redoFieldValueSerialized.isEmpty())
{
{
QXmlStreamWriter xmlStream(&m_commandData->m_undoFieldValueSerialized);
writeFieldDataToValidXmlDocument(xmlStream, xmlFieldHandle);
}
// This function will notify field change, no need to explicitly call notification
uiFieldHandle->setValueFromUi(m_commandData->m_newUiValue);
{
QXmlStreamWriter xmlStream(&m_commandData->m_redoFieldValueSerialized);
writeFieldDataToValidXmlDocument(xmlStream, xmlFieldHandle);
}
}
else
{
QVariant oldFieldData = uiFieldHandle->toUiBasedQVariant();
QXmlStreamReader xmlStream(m_commandData->m_redoFieldValueSerialized);
readFieldValueFromValidXmlDocument(xmlStream, xmlFieldHandle);
QVariant newFieldData = uiFieldHandle->toUiBasedQVariant();
// New data is present in field, notify data changed
uiFieldHandle->notifyFieldChanged(oldFieldData, newFieldData);
}
}
if (m_notificationCenter) m_notificationCenter->notifyObserversOfDataChange(field->ownerObject());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdFieldChangeExec::undo()
{
PdmFieldHandle* field = PdmReferenceHelper::fieldFromReference(m_commandData->m_rootObject, m_commandData->m_pathToField);
if (!field)
{
assert(false);
return;
}
PdmUiFieldHandle* uiFieldHandle = uiField(field);
PdmXmlFieldHandle* xmlFieldHandle = xmlField(field);
if (uiFieldHandle && xmlFieldHandle)
{
QXmlStreamReader xmlStream(m_commandData->m_undoFieldValueSerialized);
QVariant oldFieldData = uiFieldHandle->toUiBasedQVariant();
readFieldValueFromValidXmlDocument(xmlStream, xmlFieldHandle);
QVariant newFieldData = uiFieldHandle->toUiBasedQVariant();
// New data is present in field, notify data changed
uiFieldHandle->notifyFieldChanged(oldFieldData, newFieldData);
}
if (m_notificationCenter) m_notificationCenter->notifyObserversOfDataChange(field->ownerObject());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CmdFieldChangeExec::CmdFieldChangeExec(NotificationCenter* notificationCenter)
: CmdExecuteCommand(notificationCenter)
{
m_commandData = new CmdFieldChangeExecData;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CmdFieldChangeExecData* CmdFieldChangeExec::commandData()
{
return m_commandData;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdFieldChangeExec::writeFieldDataToValidXmlDocument(QXmlStreamWriter &xmlStream, PdmXmlFieldHandle* xmlFieldHandle)
{
xmlStream.setAutoFormatting(true);
xmlStream.writeStartDocument();
xmlStream.writeStartElement("", "d");
xmlFieldHandle->writeFieldData(xmlStream);
xmlStream.writeEndElement();
xmlStream.writeEndDocument();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdFieldChangeExec::readFieldValueFromValidXmlDocument(QXmlStreamReader &xmlStream, PdmXmlFieldHandle* xmlFieldHandle)
{
// See PdmObject::readFields and friends to match token count for reading field values
// The stream is supposed to be pointing at the first token of field content when calling readFieldData()
QXmlStreamReader::TokenType tt;
int tokenCount = 3;
for (int i = 0; i < tokenCount; i++)
{
tt = xmlStream.readNext();
}
xmlFieldHandle->readFieldData(xmlStream, PdmDefaultObjectFactory::instance());
}
} // end namespace caf
@@ -0,0 +1,97 @@
//##################################################################################################
//
// 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.
//
//##################################################################################################
#pragma once
#include "cafCmdExecuteCommand.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
namespace caf
{
class PdmChildArrayFieldHandle;
//==================================================================================================
///
//==================================================================================================
class CmdFieldChangeExecData : public PdmObject
{
CAF_PDM_HEADER_INIT;
public:
CmdFieldChangeExecData()
{
CAF_PDM_InitObject("CmdFieldChangeExecData uiName", "", "CmdFieldChangeExecData tooltip", "CmdFieldChangeExecData whatsthis");
CAF_PDM_InitField(&m_pathToField, "PathToField", QString(), "PathToField", "", "PathToField tooltip", "PathToField whatsthis");
}
caf::PdmPointer<PdmObjectHandle> m_rootObject;
PdmField<QString> m_pathToField;
QVariant m_newUiValue; // QVariant coming from the UI
QString m_undoFieldValueSerialized;
QString m_redoFieldValueSerialized;
};
//==================================================================================================
///
//==================================================================================================
class CmdFieldChangeExec : public CmdExecuteCommand
{
public:
CmdFieldChangeExec(NotificationCenter* notificationCenter);
CmdFieldChangeExecData* commandData();
virtual QString name();
virtual void redo();
virtual void undo();
private:
void readFieldValueFromValidXmlDocument(QXmlStreamReader& xmlStream, PdmXmlFieldHandle* xmlFieldHandle);
void writeFieldDataToValidXmlDocument(QXmlStreamWriter& xmlStream, PdmXmlFieldHandle* xmlFieldHandle);
private:
CmdFieldChangeExecData* m_commandData;
};
} // end namespace caf
@@ -0,0 +1,100 @@
//##################################################################################################
//
// 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 "cafCmdSelectionChangeExec.h"
#include "cafPdmReferenceHelper.h"
namespace caf
{
template<>
void AppEnum<SelectionManager::SelectionRole>::setUp()
{
addItem(SelectionManager::APPLICATION_GLOBAL, "APPLICATION_GLOBAL", "APPLICATION_GLOBAL");
addItem(SelectionManager::CURRENT, "CURRENT", "CURRENT");
addItem(SelectionManager::UNDEFINED, "UNDEFINED", "UNDEFINED");
setDefault(SelectionManager::UNDEFINED);
}
CAF_PDM_SOURCE_INIT(CmdSelectionChangeExecData, "CmdSelectionChangeExecData");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString CmdSelectionChangeExec::name()
{
return m_commandData->classKeyword();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdSelectionChangeExec::redo()
{
SelectionManager::instance()->setSelectionFromReferences(m_commandData->m_newSelection.v(), m_commandData->m_selectionRole.v());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdSelectionChangeExec::undo()
{
SelectionManager::instance()->setSelectionFromReferences(m_commandData->m_previousSelection.v(), m_commandData->m_selectionRole.v());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CmdSelectionChangeExec::CmdSelectionChangeExec(NotificationCenter* notificationCenter)
: CmdExecuteCommand(notificationCenter)
{
m_commandData = new CmdSelectionChangeExecData;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CmdSelectionChangeExecData* CmdSelectionChangeExec::commandData()
{
return m_commandData;
}
} // end namespace caf
@@ -0,0 +1,95 @@
//##################################################################################################
//
// 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.
//
//##################################################################################################
#pragma once
#include "cafCmdExecuteCommand.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "cafSelectionManager.h"
#include "cafAppEnum.h"
namespace caf
{
//==================================================================================================
///
//==================================================================================================
class CmdSelectionChangeExecData : public PdmObject
{
CAF_PDM_HEADER_INIT;
public:
CmdSelectionChangeExecData()
{
CAF_PDM_InitObject("CmdSelectionChangeExecData uiName", "", "CmdSelectionChangeExecData tooltip", "CmdSelectionChangeExecData whatsthis");
CAF_PDM_InitFieldNoDefault(&m_selectionRole, "selectionRole", "selectionRole", "", "", "");
CAF_PDM_InitField(&m_previousSelection, "previousSelection", std::vector<QString>(), "previousSelection", "", "", "");
CAF_PDM_InitField(&m_newSelection, "newSelection", std::vector<QString>(), "newSelection", "", "", "");
}
PdmField< AppEnum<SelectionManager::SelectionRole> > m_selectionRole;
PdmField< std::vector<QString> > m_previousSelection;
PdmField< std::vector<QString> > m_newSelection;
};
//==================================================================================================
///
//==================================================================================================
class CmdSelectionChangeExec : public CmdExecuteCommand
{
public:
CmdSelectionChangeExec(NotificationCenter* notificationCenter);
CmdSelectionChangeExecData* commandData();
virtual QString name();
virtual void redo();
virtual void undo();
private:
CmdSelectionChangeExecData* m_commandData;
};
} // end namespace caf
@@ -0,0 +1,76 @@
//##################################################################################################
//
// 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 "cafCmdSelectionHelper.h"
#include "cafCmdExecCommandManager.h"
#include "cafCmdSelectionChangeExec.h"
namespace caf
{
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdSelectionHelper::executeSelectionCommand(std::vector<PdmObjectHandle*> selection, SelectionManager::SelectionRole role)
{
CmdSelectionChangeExec* selectionChangeExec = createSelectionCommand(selection, role);
CmdExecCommandManager::instance()->processExecuteCommand(selectionChangeExec);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CmdSelectionChangeExec* CmdSelectionHelper::createSelectionCommand(const std::vector<PdmObjectHandle*>& selection, SelectionManager::SelectionRole role)
{
CmdSelectionChangeExec* selectionChangeExec = new CmdSelectionChangeExec(SelectionManager::instance()->notificationCenter());
selectionChangeExec->commandData()->m_selectionRole.v() = role;
SelectionManager::instance()->selectionAsReferences(selectionChangeExec->commandData()->m_previousSelection.v(), role);
for (size_t i = 0; i < selection.size(); i++)
{
QString itemRef = PdmReferenceHelper::referenceFromRootToObject(PdmReferenceHelper::findRoot(selection[i]), selection[i]);
selectionChangeExec->commandData()->m_newSelection.v().push_back(itemRef);
}
return selectionChangeExec;
}
} // end namespace caf
@@ -0,0 +1,58 @@
//##################################################################################################
//
// 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.
//
//##################################################################################################
#pragma once
#include "cafSelectionManager.h"
#include <vector>
namespace caf
{
class CmdSelectionChangeExec;
class CmdSelectionHelper
{
public:
static void executeSelectionCommand(std::vector<PdmObjectHandle*> selection, SelectionManager::SelectionRole role);
static CmdSelectionChangeExec* createSelectionCommand(const std::vector<PdmObjectHandle*>& selection, SelectionManager::SelectionRole role);
};
} // end namespace caf
@@ -0,0 +1,199 @@
//##################################################################################################
//
// 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 "cafCmdUiCommandSystemImpl.h"
#include "cafCmdExecCommandManager.h"
#include "cafCmdExecuteCommand.h"
#include "cafCmdFieldChangeExec.h"
#include "cafCmdFeatureManager.h"
#include "cafPdmFieldHandle.h"
#include "cafPdmUiObjectHandle.h"
#include "cafSelectionManager.h"
#include <QMenu>
#include <vector>
namespace caf
{
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CmdUiCommandSystemImpl::CmdUiCommandSystemImpl()
{
m_undoFeatureEnabled = false;
m_disableUndoFeatureOverride = false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdUiCommandSystemImpl::fieldChangedCommand(PdmFieldHandle* editorField, const QVariant& newUiValue)
{
std::vector<PdmFieldHandle*> fieldsToUpdate;
fieldsToUpdate.push_back(editorField);
// For current selection, find all fields with same keyword
{
std::vector<PdmUiItem*> items;
SelectionManager::instance()->selectedItems(items, SelectionManager::CURRENT);
for (int i = 0; i < items.size(); i++)
{
PdmObjectHandle* objectHandle = dynamic_cast<PdmObjectHandle*>(items[i]);
if (objectHandle)
{
// An object is selected, find field with same keyword as the current field being edited
PdmFieldHandle* fieldHandle = objectHandle->findField(editorField->keyword());
if (fieldHandle && fieldHandle != editorField)
{
fieldsToUpdate.push_back(fieldHandle);
}
}
else
{
// A field is selected, check if keywords are identical
PdmUiFieldHandle* uiFieldHandle = dynamic_cast<PdmUiFieldHandle*>(items[i]);
if (uiFieldHandle)
{
PdmFieldHandle* field = uiFieldHandle->fieldHandle();
if (field && field != editorField && field->keyword() == editorField->keyword())
{
fieldsToUpdate.push_back(field);
}
}
}
}
}
std::vector<CmdExecuteCommand*> commands;
for (int i = 0; i < fieldsToUpdate.size(); i++)
{
PdmFieldHandle* field = fieldsToUpdate[i];
PdmUiFieldHandle* uiFieldHandle = uiField(field);
if (uiFieldHandle)
{
QVariant fieldCurrentUiValue = uiFieldHandle->uiValue();
if (fieldCurrentUiValue != newUiValue)
{
PdmObjectHandle* rootObjHandle = PdmReferenceHelper::findRoot(field);
QString reference = PdmReferenceHelper::referenceFromRootToField(rootObjHandle, field);
if (reference.isEmpty())
{
assert(false);
return;
}
CmdFieldChangeExec* fieldChangeExec = new CmdFieldChangeExec(SelectionManager::instance()->notificationCenter());
fieldChangeExec->commandData()->m_newUiValue = newUiValue;
fieldChangeExec->commandData()->m_pathToField = reference;
fieldChangeExec->commandData()->m_rootObject = rootObjHandle;
commands.push_back(fieldChangeExec);
}
}
}
caf::PdmUiObjectHandle* uiOwnerObjectHandle = uiObj(editorField->ownerObject());
if (uiOwnerObjectHandle && !uiOwnerObjectHandle->useUndoRedoFramework())
{
// Temporarily disable undo framework as requested by the PdmUiObjectHandle
m_disableUndoFeatureOverride = true;
}
if (commands.size() == 1)
{
CmdExecCommandManager::instance()->processExecuteCommand(commands[0]);
}
else
{
CmdExecCommandManager::instance()->processExecuteCommandsAsMacro("Multiple Field Change", commands);
}
if (uiOwnerObjectHandle && !uiOwnerObjectHandle->useUndoRedoFramework())
{
// Restore undo feature to normal operation
m_disableUndoFeatureOverride = false;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdUiCommandSystemImpl::populateMenuWithDefaultCommands(const QString& uiConfigName, QMenu* menu)
{
if (uiConfigName == "PdmUiTreeViewEditor" ||
uiConfigName == "PdmUiTableViewEditor")
{
caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance();
menu->addAction(commandManager->action("PdmListField_AddItem"));
menu->addAction(commandManager->action("PdmListField_DeleteItem"));
QStringList commandIdList;
commandIdList << "PdmListField_AddItem" << "PdmListField_DeleteItem";
commandManager->refreshStates(commandIdList);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool CmdUiCommandSystemImpl::isUndoEnabled()
{
if (m_disableUndoFeatureOverride) return false;
return m_undoFeatureEnabled;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdUiCommandSystemImpl::enableUndoFeature(bool enable)
{
m_undoFeatureEnabled = enable;
}
} // end namespace caf
@@ -0,0 +1,65 @@
//##################################################################################################
//
// 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.
//
//##################################################################################################
#pragma once
#include "cafInternalPdmUiCommandSystemInterface.h"
namespace caf
{
class PdmFieldHandle;
class CmdUiCommandSystemImpl : public PdmUiCommandSystemInterface
{
public:
CmdUiCommandSystemImpl();
virtual void fieldChangedCommand(PdmFieldHandle* field, const QVariant& newUiValue);
virtual void populateMenuWithDefaultCommands(const QString& uiConfigName, QMenu* menu);
bool isUndoEnabled();
void enableUndoFeature(bool enable);
private:
bool m_undoFeatureEnabled;
bool m_disableUndoFeatureOverride;
};
} // end namespace caf
@@ -0,0 +1,169 @@
//##################################################################################################
//
// 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)
{
PdmXmlFieldHandle* xfh = listField->capability<PdmXmlFieldHandle>();
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);
if (listField && xmlField(field))
{
QString classKeyword = xmlField(field)->childClassKeyword();
if (classKeyword.isEmpty()) return;
caf::PdmObjectHandle* obj = PdmDefaultObjectFactory::instance()->create(classKeyword);
if (!obj) return;
listField->insertAt(m_commandData->m_indexAfter, obj);
caf::PdmUiObjectHandle* uiObject = uiObj(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;
}
if (m_notificationCenter) m_notificationCenter->notifyObserversOfDataChange(obj);
caf::PdmUiFieldHandle::updateConnectedUiEditors(listField);
if (listField->ownerObject())
{
caf::PdmUiObjectHandle* ownerUiObject = uiObj(listField->ownerObject());
if (ownerUiObject)
{
ownerUiObject->fieldChangedByUi(listField, QVariant(), QVariant());
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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);
caf::PdmUiFieldHandle::updateConnectedUiEditors(listField);
if (m_notificationCenter) m_notificationCenter->notifyObservers();
if (listField->ownerObject())
{
caf::PdmUiObjectHandle* ownerUiObject = uiObj(listField->ownerObject());
if (ownerUiObject)
{
ownerUiObject->fieldChangedByUi(listField, QVariant(), QVariant());
}
}
delete obj;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CmdAddItemExec::CmdAddItemExec(NotificationCenter* notificationCenter)
: CmdExecuteCommand(notificationCenter)
{
m_commandData = new CmdAddItemExecData;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CmdAddItemExecData* CmdAddItemExec::commandData()
{
return m_commandData;
}
} // end namespace caf
@@ -0,0 +1,68 @@
//##################################################################################################
//
// 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.
//
//##################################################################################################
#pragma once
#include "cafCmdExecuteCommand.h"
namespace caf
{
class PdmChildArrayFieldHandle;
class CmdAddItemExecData;
//==================================================================================================
///
//==================================================================================================
class CmdAddItemExec : public CmdExecuteCommand
{
public:
CmdAddItemExec(NotificationCenter* notificationCenter);
CmdAddItemExecData* commandData();
virtual QString name();
virtual void redo();
virtual void undo();
private:
CmdAddItemExecData* m_commandData;
};
} // end namespace caf
@@ -0,0 +1,46 @@
//##################################################################################################
//
// 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 "cafCmdAddItemExecData.h"
namespace caf
{
CAF_PDM_SOURCE_INIT(CmdAddItemExecData, "CmdAddItemExecData");
} // end namespace caf
@@ -0,0 +1,73 @@
//##################################################################################################
//
// 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.
//
//##################################################################################################
#pragma once
#include "cafPdmObject.h"
#include "cafPdmField.h"
namespace caf
{
//==================================================================================================
///
//==================================================================================================
class CmdAddItemExecData : public PdmObject
{
CAF_PDM_HEADER_INIT;
public:
CmdAddItemExecData()
{
CAF_PDM_InitObject("CmdAddItemExecData uiName", "", "CmdAddItemExecData tooltip", "CmdAddItemExecData whatsthis");
CAF_PDM_InitField(&m_pathToField, "PathToField", QString(), "PathToField", "", "PathToField tooltip", "PathToField whatsthis");
CAF_PDM_InitField(&m_indexAfter, "indexAfter", -1, "indexAfter", "", "indexAfter tooltip", "indexAfter whatsthis");
CAF_PDM_InitField(&m_createdItemIndex, "createdItemIndex", -1, "createdItemIndex", "", "createdItemIndex tooltip", "createdItemIndex whatsthis");
}
caf::PdmPointer<PdmObjectHandle> m_rootObject;
caf::PdmField<QString> m_pathToField;
caf::PdmField<int> m_indexAfter;
caf::PdmField<int> m_createdItemIndex;
};
} // end namespace caf
@@ -0,0 +1,123 @@
//##################################################################################################
//
// 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 "cafCmdAddItemFeature.h"
#include "cafCmdAddItemExec.h"
#include "cafCmdAddItemExecData.h"
#include "cafCmdFeatureManager.h"
#include "cafCmdSelectionHelper.h"
#include "cafPdmReferenceHelper.h"
#include "cafSelectionManager.h"
#include "cafCmdExecCommandManager.h"
#include "cafPdmChildArrayField.h"
#include "cafPdmField.h"
#include <QAction>
namespace caf
{
CAF_CMD_SOURCE_INIT(CmdAddItemFeature, "PdmListField_AddItem");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CmdExecuteCommand* CmdAddItemFeature::createExecuteCommand()
{
caf::PdmChildArrayFieldHandle* childArrayFieldHandle = SelectionManager::instance()->activeChildArrayFieldHandle();
if (!childArrayFieldHandle) return NULL;
int indexAfter = -1;
CmdAddItemExec* addItemExec = new CmdAddItemExec(SelectionManager::instance()->notificationCenter());
CmdAddItemExecData* data = addItemExec->commandData();
data->m_rootObject = PdmReferenceHelper::findRoot(childArrayFieldHandle);
data->m_pathToField = PdmReferenceHelper::referenceFromRootToField(data->m_rootObject, childArrayFieldHandle);
data->m_indexAfter = indexAfter;
return addItemExec;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool CmdAddItemFeature::isCommandEnabled()
{
caf::PdmChildArrayFieldHandle* childArrayFieldHandle = SelectionManager::instance()->activeChildArrayFieldHandle();
if (childArrayFieldHandle)
{
return true;
}
else
{
return false;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdAddItemFeature::onActionTriggered(bool isChecked)
{
if (isCommandEnabled())
{
CmdExecuteCommand* exeCmd = createExecuteCommand();
if (exeCmd)
{
CmdExecCommandManager::instance()->processExecuteCommand(exeCmd);
}
else
{
assert(0);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdAddItemFeature::setupActionLook(QAction* actionToSetup)
{
actionToSetup->setText("Add new object");
}
} // end namespace caf
@@ -0,0 +1,64 @@
//##################################################################################################
//
// 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.
//
//##################################################################################################
#pragma once
#include "cafCmdFeature.h"
namespace caf
{
class CmdExecuteCommand;
//==================================================================================================
///
//==================================================================================================
class CmdAddItemFeature : public CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
CmdExecuteCommand* createExecuteCommand();
virtual bool isCommandEnabled();
virtual void onActionTriggered( bool isChecked );
virtual void setupActionLook( QAction* actionToSetup );
};
} // end namespace caf
@@ -0,0 +1,150 @@
//##################################################################################################
//
// 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 "cafCmdDeleteItemExec.h"
#include "cafCmdDeleteItemExecData.h"
#include "cafPdmChildArrayField.h"
#include "cafPdmReferenceHelper.h"
#include "cafPdmUiFieldHandle.h"
#include "cafNotificationCenter.h"
#include "cafSelectionManager.h"
namespace caf
{
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString CmdDeleteItemExec::name()
{
return m_commandData->classKeyword();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdDeleteItemExec::redo()
{
PdmFieldHandle* field = PdmReferenceHelper::fieldFromReference(m_commandData->m_rootObject, m_commandData->m_pathToField);
PdmChildArrayFieldHandle* listField = dynamic_cast<PdmChildArrayFieldHandle*>(field);
if (listField)
{
std::vector<PdmObjectHandle*> children;
listField->childObjects(&children);
PdmObjectHandle* obj = children[m_commandData->m_indexToObject];
caf::SelectionManager::instance()->removeObjectFromAllSelections(obj);
if (m_commandData->m_deletedObjectAsXml().isEmpty())
{
QString encodedXml;
{
m_commandData->m_deletedObjectAsXml = xmlObj(obj)->writeObjectToXmlString();
}
}
listField->erase(m_commandData->m_indexToObject);
// TODO: The notification here could possibly be changed to
// PdmUiFieldHandle::notifyDataChange() similar to void CmdFieldChangeExec::redo()
caf::PdmUiObjectHandle* ownerUiObject = uiObj(listField->ownerObject());
if (ownerUiObject)
{
ownerUiObject->fieldChangedByUi(field, QVariant(), QVariant());
}
caf::PdmUiFieldHandle::updateConnectedUiEditors(listField);
if (m_notificationCenter) m_notificationCenter->notifyObservers();
delete obj;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdDeleteItemExec::undo()
{
PdmFieldHandle* field = PdmReferenceHelper::fieldFromReference(m_commandData->m_rootObject, m_commandData->m_pathToField);
PdmChildArrayFieldHandle* listField = dynamic_cast<PdmChildArrayFieldHandle*>(field);
if (listField)
{
PdmObjectHandle* obj = PdmXmlObjectHandle::readUnknownObjectFromXmlString(m_commandData->m_deletedObjectAsXml(), PdmDefaultObjectFactory::instance());
listField->insertAt(m_commandData->m_indexToObject, obj);
// TODO: The notification here could possibly be changed to
// PdmUiFieldHandle::notifyDataChange() similar to void CmdFieldChangeExec::redo()
caf::PdmUiObjectHandle* ownerUiObject = uiObj(listField->ownerObject());
if (ownerUiObject)
{
ownerUiObject->fieldChangedByUi(field, QVariant(), QVariant());
}
caf::PdmUiFieldHandle::updateConnectedUiEditors(listField);
if (m_notificationCenter) m_notificationCenter->notifyObservers();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CmdDeleteItemExec::CmdDeleteItemExec(NotificationCenter* notificationCenter)
: CmdExecuteCommand(notificationCenter)
{
m_commandData = new CmdDeleteItemExecData;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CmdDeleteItemExecData* CmdDeleteItemExec::commandData()
{
return m_commandData;
}
} // end namespace caf
@@ -0,0 +1,68 @@
//##################################################################################################
//
// 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.
//
//##################################################################################################
#pragma once
#include "cafCmdExecuteCommand.h"
namespace caf
{
class PdmChildArrayFieldHandle;
class CmdDeleteItemExecData;
//==================================================================================================
///
//==================================================================================================
class CmdDeleteItemExec : public CmdExecuteCommand
{
public:
CmdDeleteItemExec(NotificationCenter* notificationCenter);
CmdDeleteItemExecData* commandData();
virtual QString name();
virtual void redo();
virtual void undo();
private:
CmdDeleteItemExecData* m_commandData;
};
} // end namespace caf
@@ -0,0 +1,46 @@
//##################################################################################################
//
// 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 "cafCmdDeleteItemExecData.h"
namespace caf
{
CAF_PDM_SOURCE_INIT(CmdDeleteItemExecData, "CmdDeleteItemExecData");
} // end namespace caf
@@ -0,0 +1,73 @@
//##################################################################################################
//
// 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.
//
//##################################################################################################
#pragma once
#include "cafPdmObject.h"
#include "cafPdmField.h"
namespace caf
{
//==================================================================================================
///
//==================================================================================================
class CmdDeleteItemExecData : public PdmObject
{
CAF_PDM_HEADER_INIT;
public:
CmdDeleteItemExecData()
{
CAF_PDM_InitObject("CmdDeleteItemExecData uiName", "", "CmdDeleteItemExecData tooltip", "CmdDeleteItemExecData whatsthis");
CAF_PDM_InitField(&m_pathToField, "PathToField", QString(), "PathToField", "", "PathToField tooltip", "PathToField whatsthis");
CAF_PDM_InitField(&m_indexToObject, "indexToObject", -1, "indexToObject", "", "indexToObject tooltip", "indexToObject whatsthis");
CAF_PDM_InitField(&m_deletedObjectAsXml, "deletedObjectAsXml", QString(), "deletedObjectAsXml", "", "deletedObjectAsXml tooltip", "deletedObjectAsXml whatsthis");
}
caf::PdmPointer<PdmObjectHandle> m_rootObject;
caf::PdmField<QString> m_pathToField;
caf::PdmField<int> m_indexToObject;
caf::PdmField<QString> m_deletedObjectAsXml;
};
} // end namespace caf
@@ -0,0 +1,145 @@
//##################################################################################################
//
// 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 "cafCmdDeleteItemFeature.h"
#include "cafCmdExecCommandManager.h"
#include "cafCmdDeleteItemExec.h"
#include "cafCmdDeleteItemExecData.h"
#include "cafCmdSelectionHelper.h"
#include "cafPdmReferenceHelper.h"
#include "cafSelectionManager.h"
#include "cafPdmChildArrayField.h"
#include "cafPdmField.h"
#include <QAction>
namespace caf
{
CAF_CMD_SOURCE_INIT(CmdDeleteItemFeature, "PdmListField_DeleteItem");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CmdExecuteCommand* CmdDeleteItemFeature::createExecuteCommand()
{
std::vector<PdmUiItem*> items;
SelectionManager::instance()->selectedItems(items, SelectionManager::CURRENT);
caf::PdmChildArrayFieldHandle* childArrayFieldHandle = caf::SelectionManager::instance()->activeChildArrayFieldHandle();
if (!childArrayFieldHandle) return NULL;
caf::PdmObjectHandle* currentPdmObject = NULL;
for (size_t i = 0; i < items.size(); i++)
{
if (dynamic_cast<caf::PdmUiObjectHandle*>(items[i]))
{
currentPdmObject = dynamic_cast<caf::PdmUiObjectHandle*>(items[i])->owner();
}
}
if (!currentPdmObject) return NULL;
int indexAfter = -1;
std::vector<PdmObjectHandle*> childObjects;
childArrayFieldHandle->childObjects(&childObjects);
for (size_t i = 0; i < childObjects.size(); i++)
{
if (childObjects[i] == currentPdmObject)
{
indexAfter = static_cast<int>(i);
}
}
// Did not find currently selected pdm object in the current list field
assert(indexAfter != -1);
CmdDeleteItemExec* executeCmd = new CmdDeleteItemExec(SelectionManager::instance()->notificationCenter());
CmdDeleteItemExecData* data = executeCmd->commandData();
data->m_rootObject = PdmReferenceHelper::findRoot(childArrayFieldHandle);
data->m_pathToField = PdmReferenceHelper::referenceFromRootToField(data->m_rootObject, childArrayFieldHandle);
data->m_indexToObject = indexAfter;
return executeCmd;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool CmdDeleteItemFeature::isCommandEnabled()
{
caf::PdmObject* currentPdmObject = dynamic_cast<caf::PdmObject*>(caf::SelectionManager::instance()->selectedItem(caf::SelectionManager::CURRENT));
if (!currentPdmObject) return false;
caf::PdmChildArrayFieldHandle* childArrayFieldHandle = caf::SelectionManager::instance()->activeChildArrayFieldHandle();
if (!childArrayFieldHandle) return false;
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdDeleteItemFeature::onActionTriggered(bool isChecked)
{
if (isCommandEnabled())
{
CmdExecuteCommand* exeCmd = createExecuteCommand();
if (exeCmd)
{
CmdExecCommandManager::instance()->processExecuteCommand(exeCmd);
}
else
{
assert(0);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdDeleteItemFeature::setupActionLook(QAction* actionToSetup)
{
actionToSetup->setText("Delete object");
}
} // end namespace caf
@@ -0,0 +1,62 @@
//##################################################################################################
//
// 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.
//
//##################################################################################################
#pragma once
#include "cafCmdFeature.h"
namespace caf
{
//==================================================================================================
///
//==================================================================================================
class CmdDeleteItemFeature : public CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
CmdExecuteCommand* createExecuteCommand();
// Overrides
virtual bool isCommandEnabled();
virtual void onActionTriggered( bool isChecked );
virtual void setupActionLook( QAction* actionToSetup );
};
} // end namespace caf