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

View File

@ -6,11 +6,26 @@ project (CeeApp)
find_package (Qt4 COMPONENTS QtCore QtGui QtMain QtOpenGl REQUIRED)
include (${QT_USE_FILE})
#libraries
add_subdirectory (cafProjectDataModel/cafPdmCore)
add_subdirectory (cafProjectDataModel/cafPdmUiCore)
add_subdirectory (cafProjectDataModel/cafPdmXml)
add_subdirectory(cafProjectDataModel)
add_subdirectory(cafCommand)
add_subdirectory(cafUserInterface)
#executables
add_subdirectory(cafTests/cafProjectDataModel_UnitTests)
add_subdirectory(cafTests/cafTestApplication)
add_subdirectory (cafProjectDataModel/cafPdmCore/cafPdmCore_UnitTests)
add_subdirectory (cafProjectDataModel/cafPdmXml/cafPdmXml_UnitTests)
# Organize sub-projects into folders on Visual Studio
# Turn on using solution folders
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(TARGET cafPdmCore cafPdmCore_UnitTests cafPdmXml cafPdmXml_UnitTests cafPdmUiCore PROPERTY FOLDER "PdmCore")

View File

@ -2,6 +2,23 @@ cmake_minimum_required (VERSION 2.8)
project (CommonCode)
# Qt
find_package ( Qt4 COMPONENTS QtCore QtGui QtMain QtOpenGl )
include (${QT_USE_FILE})
# Open GL
find_package( OpenGL )
include_directories(
${LibCore_SOURCE_DIR}
${LibGeometry_SOURCE_DIR}
${LibGuiQt_SOURCE_DIR}
${LibRender_SOURCE_DIR}
${LibViewing_SOURCE_DIR}
${cafPdmCore_SOURCE_DIR}
)
# These headers need to go through Qt's MOC compiler
set( QOBJECT_HEADERS
cafMessagePanel.h

View File

@ -154,18 +154,28 @@ EffectGenerator::RenderingModeType EffectGenerator::renderingMode()
return sm_renderingMode;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::Effect> EffectGenerator::generateEffectFromCache() const
{
cvf::ref<cvf::Effect> eff = caf::EffectCache::instance()->findEffect(this);
if (eff.notNull()) return eff.p();
eff = generateEffect();
caf::EffectCache::instance()->addEffect(this, eff.p());
return eff;
}
//--------------------------------------------------------------------------------------------------
/// Creates a new effect using the settings in the inherited generator.
/// Creates a new effect and calls the correct update-Effect method dep. on the effect type (software/shader)
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::Effect> EffectGenerator::generateEffect() const
{
cvf::ref<cvf::Effect> eff = caf::EffectCache::instance()->findEffect(this);
if (eff.notNull()) return eff.p();
eff = new cvf::Effect;
cvf::ref<cvf::Effect> eff = new cvf::Effect;
if (sm_renderingMode == SHADER_BASED)
{
@ -176,11 +186,11 @@ cvf::ref<cvf::Effect> EffectGenerator::generateEffect() const
updateForFixedFunctionRendering(eff.p());
}
caf::EffectCache::instance()->addEffect(this, eff.p());
return eff;
}
//--------------------------------------------------------------------------------------------------
/// Updates the effect to the state defined by the inherited effect generator.
/// This can be used to update an effect used several places in the scene.
@ -781,6 +791,7 @@ EffectGenerator* ScalarMapperMeshEffectGenerator::copy() const
MeshEffectGenerator::MeshEffectGenerator(const cvf::Color3f& color)
{
m_color = color;
m_lineStipple = false;
}
//--------------------------------------------------------------------------------------------------
@ -798,7 +809,12 @@ void MeshEffectGenerator::updateForShaderBasedRendering(cvf::Effect* effect) con
cvf::ref<cvf::Effect> eff = effect;
eff->setShaderProgram(shaderProg.p());
eff->setUniform(new cvf::UniformFloat("u_color", cvf::Color4f(m_color, 1.0)));
if (m_lineStipple)
{
// MODTODO
//eff->setRenderState(new cvf::RenderStateLineStipple_FF);
}
}
//--------------------------------------------------------------------------------------------------
@ -813,6 +829,11 @@ void MeshEffectGenerator::updateForFixedFunctionRendering(cvf::Effect* effect) c
eff->setRenderState(new cvf::RenderStateDepth(true, cvf::RenderStateDepth::LEQUAL));
eff->setRenderState(new cvf::RenderStateLighting_FF(false));
if (m_lineStipple)
{
// MODTODO
//eff->setRenderState(new cvf::RenderStateLineStipple_FF);
}
}
//--------------------------------------------------------------------------------------------------
@ -824,10 +845,17 @@ bool MeshEffectGenerator::isEqual(const EffectGenerator* other) const
if (otherMesh)
{
if (m_color == otherMesh->m_color)
if (m_color != otherMesh->m_color)
{
return true;
return false;
}
if (m_lineStipple != otherMesh->m_lineStipple)
{
return false;
}
return true;
}
return false;
@ -838,7 +866,10 @@ bool MeshEffectGenerator::isEqual(const EffectGenerator* other) const
//--------------------------------------------------------------------------------------------------
EffectGenerator* MeshEffectGenerator::copy() const
{
return new MeshEffectGenerator(m_color);
MeshEffectGenerator* effGen = new MeshEffectGenerator(m_color);
effGen->setLineStipple(m_lineStipple);
return effGen;
}

View File

@ -46,6 +46,11 @@
#include "cvfString.h"
#include "cvfRenderStatePolygonOffset.h"
namespace cvf
{
class RenderStatePolygonOffset;
}
namespace caf {
class CommonShaderSources
@ -89,6 +94,7 @@ public:
virtual ~EffectGenerator() {}
cvf::ref<cvf::Effect> generateEffect() const;
cvf::ref<cvf::Effect> generateEffectFromCache() const;
void updateEffect(cvf::Effect* effect) const;
static void setRenderingMode(RenderingModeType effectType);
@ -230,6 +236,7 @@ class MeshEffectGenerator : public EffectGenerator
{
public:
MeshEffectGenerator(const cvf::Color3f& color);
void setLineStipple(bool enable) { m_lineStipple = enable; }
protected:
virtual bool isEqual(const EffectGenerator* other) const;
@ -240,6 +247,7 @@ protected:
private:
cvf::Color3f m_color;
bool m_lineStipple;
};

View File

@ -41,7 +41,7 @@
#include "cvfObject.h"
#include "cvfVector3.h"
#include "../cafProjectDataModel/cafAppEnum.h"
#include "cafAppEnum.h"

View File

@ -2,6 +2,10 @@ cmake_minimum_required (VERSION 2.8)
project (cafAnimControl)
# Qt
find_package ( Qt4 COMPONENTS QtCore QtGui QtMain )
include (${QT_USE_FILE})
set( QOBJECT_HEADERS
cafFrameAnimationControl.h
cafAnimationToolBar.h

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})

View File

@ -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

View File

@ -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

View File

@ -37,62 +37,50 @@
#pragma once
#include <vector>
#include <QString>
#include "cafPdmUiItem.h"
#include "cafUiTreeItem.h"
#include "cafPdmPointer.h"
class QUndoStack;
class QString;
namespace caf
{
class PdmObject;
class PdmFieldHandle;
class PdmUiTreeOrdering;
typedef UiTreeItem<PdmUiTreeOrdering* > PdmUiTreeItem;
class CmdExecuteCommand;
class CmdUiCommandSystemImpl;
//==================================================================================================
/// Class storing a tree structure representation of some PdmObject hierarchy to be used for tree views in the Gui
///
//==================================================================================================
class PdmUiTreeOrdering : public UiTreeItem< PdmUiTreeOrdering* >
class CmdExecCommandManager
{
public:
PdmUiTreeOrdering(PdmUiTreeOrdering* parent = NULL, int position = -1, PdmObject* dataObject = NULL);
~PdmUiTreeOrdering();
static CmdExecCommandManager* instance();
void add(PdmFieldHandle * field);
void add(PdmObject* object);
PdmUiTreeOrdering* add(const QString & title, const QString& iconResourceName );
// 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();
/// If the rest of the fields containing children is supposed to be omitted, setForgetRemainingFileds to true.
void setForgetRemainingFields(bool val) { m_forgetRemainingFields = val; }
/// To stop the tree generation at this level, setSubTreeDefined to true
void setIgnoreSubTree(bool doIgnoreSubTree ) { m_isToIgnoreSubTree = doIgnoreSubTree; }
// 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();
PdmObject* object() const { return m_object; }
PdmFieldHandle* field() const { return m_field; }
PdmUiItem* uiItem() const { return m_uiItem; }
// 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:
friend class PdmObject;
bool forgetRemainingFields() const { return m_forgetRemainingFields; }
bool ignoreSubTree() const { return m_isToIgnoreSubTree; }
bool containsField(const PdmFieldHandle* field);
bool containsObject(const PdmObject* object);
CmdExecCommandManager();
private:
PdmPointer<PdmObject> m_object;
PdmFieldHandle* m_field;
PdmUiItem* m_uiItem;
QUndoStack* m_undoStack;
bool m_forgetRemainingFields;
bool m_isToIgnoreSubTree;
CmdUiCommandSystemImpl* m_commandFeatureInterface;
};
} // End of namespace caf
} // end namespace caf

View File

@ -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

View File

@ -1,7 +1,7 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
// 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:
@ -34,12 +34,15 @@
//
//##################################################################################################
#include "cafCmdFeature.h"
#include "cafPdmSettings.h"
#include "cafPdmField.h"
#include "cafCmdExecCommandManager.h"
#include "cafCmdFeatureManager.h"
#include <assert.h>
#include <QAction>
namespace caf
{
@ -48,69 +51,66 @@ namespace caf
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Settings::readFieldsFromApplicationStore(caf::PdmObject* object)
QAction* CmdFeature::action()
{
// Qt doc :
//
// Constructs a QSettings object for accessing settings of the application and organization
// set previously with a call to QCoreApplication::setOrganizationName(),
// QCoreApplication::setOrganizationDomain(), and QCoreApplication::setApplicationName().
QSettings settings;
return this->action(QString(""));
}
QString prefix = object->classKeyword();
if (!prefix.isEmpty())
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QAction* CmdFeature::action(QString customText)
{
std::map<QString, QAction*>::iterator it;
it = m_customTextToActionMap.find(customText);
if (it != m_customTextToActionMap.end() && it->second != NULL)
{
prefix += "/";
return it->second;
}
std::vector<caf::PdmFieldHandle*> fields;
object->fields(fields);
size_t i;
for (i = 0; i < fields.size(); i++)
else
{
caf::PdmFieldHandle* fieldHandle = fields[i];
QString keywordWithPrefix = prefix + fieldHandle->keyword();
if (settings.contains(keywordWithPrefix))
QAction* action = new QAction(this);
this->setupActionLook(action);
if (!customText.isEmpty())
{
QVariant val = settings.value(keywordWithPrefix);
fieldHandle->setValueFromUi(val);
action->setText(customText);
}
connect(action, SIGNAL(triggered(bool)), SLOT(actionTriggered(bool)));
m_customTextToActionMap[customText]= action;
return action;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Settings::writeFieldsToApplicationStore(caf::PdmObject* object)
void CmdFeature::refreshEnabledState()
{
assert(object);
std::map<QString, QAction*>::iterator it;
bool isEnabled = this->isCommandEnabled();
// Qt doc :
//
// Constructs a QSettings object for accessing settings of the application and organization
// set previously with a call to QCoreApplication::setOrganizationName(),
// QCoreApplication::setOrganizationDomain(), and QCoreApplication::setApplicationName().
QSettings settings;
QString prefix = object->classKeyword();
if (!prefix.isEmpty())
for (it = m_customTextToActionMap.begin(); it != m_customTextToActionMap.end(); ++it)
{
prefix += "/";
}
std::vector<caf::PdmFieldHandle*> fields;
object->fields(fields);
size_t i;
for (i = 0; i < fields.size(); i++)
{
caf::PdmFieldHandle* fieldHandle = fields[i];
QString keywordWithPrefix = prefix + fieldHandle->keyword();
settings.setValue(keywordWithPrefix, fieldHandle->uiValue());
it->second->setEnabled(isEnabled);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdFeature::refreshCheckedState()
{
std::map<QString, QAction*>::iterator it;
bool isChecked = this->isCommandChecked();
} // namespace caf
for (it = m_customTextToActionMap.begin(); it != m_customTextToActionMap.end(); ++it)
{
QAction* act = it->second;
if (act->isCheckable())
{
it->second->setChecked(isChecked);
}
}
}
} // end namespace caf

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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -37,34 +37,32 @@
#pragma once
#include <QDialog>
#include "cafCmdExecuteCommand.h"
namespace caf
namespace caf
{
class PdmObject;
class PdmUiPropertyView;
class PdmChildArrayFieldHandle;
class CmdAddItemExecData;
//==================================================================================================
//
//
//
///
//==================================================================================================
class PdmUiPropertyDialog : public QDialog
class CmdAddItemExec : public CmdExecuteCommand
{
Q_OBJECT
public:
PdmUiPropertyDialog(QWidget* parent, caf::PdmObject* object, const QString& windowTitle);
CmdAddItemExec(NotificationCenter* notificationCenter);
CmdAddItemExecData* commandData();
virtual QString name();
virtual void redo();
virtual void undo();
private:
void setupUi();
private:
QString m_windowTitle;
caf::PdmObject* m_pdmObject;
caf::PdmUiPropertyView* m_pdmUiPropertyView;
CmdAddItemExecData* m_commandData;
};
} // end namespace caf

View File

@ -35,21 +35,12 @@
//##################################################################################################
#pragma once
#include "cafCmdAddItemExecData.h"
#include <QSettings>
namespace caf
{
class PdmObject;
class Settings
{
public:
static void readFieldsFromApplicationStore(caf::PdmObject* object);
static void writeFieldsToApplicationStore(caf::PdmObject* object);
};
CAF_PDM_SOURCE_INIT(CmdAddItemExecData, "CmdAddItemExecData");
} // end namespace caf

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -2,15 +2,39 @@ cmake_minimum_required (VERSION 2.8)
project (cafPdmCvf)
# Qt
find_package ( Qt4 COMPONENTS QtCore QtGui QtMain )
include (${QT_USE_FILE})
include_directories(
${LibCore_SOURCE_DIR}
${cafProjectDataModel_SOURCE_DIR}
${cafUserInterface_SOURCE_DIR}
${cafPdmCore_SOURCE_DIR}
${cafPdmUiCore_SOURCE_DIR}
)
add_library( ${PROJECT_NAME}
cafPdmFieldCvfColor.cpp
cafPdmCoreColor3f.h
cafPdmUiCoreColor3f.cpp
cafPdmUiCoreColor3f.h
cafPdmXmlColor3f.cpp
cafPdmXmlColor3f.h
cafPdmFieldCvfColor.h
cafPdmFieldCvfMat4d.cpp
cafPdmCoreVec3d.h
cafPdmUiCoreVec3d.cpp
cafPdmUiCoreVec3d.h
cafPdmXmlVec3d.cpp
cafPdmXmlVec3d.h
cafPdmFieldCvfVec3d.h
cafPdmCoreMat4d.h
# cafPdmUiCoreVec3d.cpp no special editor for matrix is created yet
cafPdmUiCoreMat4d.h
cafPdmXmlMat4d.cpp
cafPdmXmlMat4d.h
cafPdmFieldCvfMat4d.h
)

View File

@ -0,0 +1,82 @@
//##################################################################################################
//
// 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 "cvfBase.h"
#include "cvfColor3.h"
#include "cafInternalPdmValueFieldSpecializations.h"
#include <QColor>
namespace caf
{
//==================================================================================================
/// Partial specialization for PdmValueFieldSpecialization< cvf::Color3f >
//==================================================================================================
template <>
class PdmValueFieldSpecialization<cvf::Color3f>
{
public:
static QVariant convert(const cvf::Color3f& value)
{
QColor col;
col.setRgbF(value.r(), value.g(), value.b());
return col;
}
static void setFromVariant(const QVariant& variantValue, cvf::Color3f& value)
{
QColor col = variantValue.value<QColor>();
value.set(col.redF(), col.greenF(), col.blueF());
}
static bool isEqual(const QVariant& variantValue, const QVariant& variantValue2)
{
return variantValue == variantValue2;
}
};
} // end namespace caf

View File

@ -0,0 +1,83 @@
//##################################################################################################
//
// 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 "cvfBase.h"
#include "cvfMatrix4.h"
#include "cafInternalPdmValueFieldSpecializations.h"
#include "cafPdmXmlMat4d.h"
namespace caf
{
template <>
class PdmValueFieldSpecialization < cvf::Mat4d >
{
public:
/// Convert the field value into a QVariant
static QVariant convert(const cvf::Mat4d& value)
{
QString str;
QTextStream textStream(&str);
textStream << value;
return QVariant(str);
}
/// Set the field value from a QVariant
static void setFromVariant(const QVariant& variantValue, cvf::Mat4d& value)
{
QString str = variantValue.toString();
QTextStream textStream(&str);
textStream >> value;
}
static bool isEqual(const QVariant& variantValue, const QVariant& variantValue2)
{
return variantValue == variantValue2;
}
};
} // end namespace caf

View File

@ -0,0 +1,84 @@
//##################################################################################################
//
// 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 "cvfBase.h"
#include "cvfVector3.h"
#include "cafInternalPdmValueFieldSpecializations.h"
#include "cafPdmXmlVec3d.h"
namespace caf
{
template <>
class PdmValueFieldSpecialization < cvf::Vec3d >
{
public:
/// Convert the field value into a QVariant
static QVariant convert(const cvf::Vec3d& value)
{
QString str;
QTextStream textStream(&str);
textStream << value;
return QVariant(str);
}
/// Set the field value from a QVariant
static void setFromVariant(const QVariant& variantValue, cvf::Vec3d& value)
{
QString str = variantValue.toString();
QTextStream textStream(&str);
textStream >> value;
}
static bool isEqual(const QVariant& variantValue, const QVariant& variantValue2)
{
return variantValue == variantValue2;
}
};
} // end namespace caf

View File

@ -36,63 +36,8 @@
#pragma once
#include <QVariant>
#include <QList>
#include <QTextStream>
#include "cafPdmFieldImpl.h"
#include "cvfBase.h"
#include "cvfColor3.h"
#include "cafPdmCoreColor3f.h"
#include "cafPdmXmlColor3f.h"
#include "cafPdmUiCoreColor3f.h"
namespace caf
{
// Forward declarations
template <typename T> class PdmField;
//==================================================================================================
/// Partial specialization for PdmField< cvf::Color3f >
//==================================================================================================
template <>
class PdmFieldTypeSpecialization < cvf::Color3f >
{
public:
/// Convert the field value into a QVariant
static QVariant convert(const cvf::Color3f& value)
{
QColor col;
col.setRgbF(value.r(), value.g(), value.b());
return col;
}
/// Set the field value from a QVariant
static void setFromVariant(const QVariant& variantValue, cvf::Color3f& value)
{
QColor col = variantValue.value<QColor>();
value.set(col.redF(), col.greenF(), col.blueF());
}
/// Methods to get a list of options for a field
static QList<PdmOptionItemInfo> valueOptions( bool* useOptionsOnly, const cvf::Color3f& )
{
return QList<PdmOptionItemInfo>();
}
/// Methods to retrieve the possible PdmObject pointed to by a field
static void childObjects(const PdmField< cvf::Color3f >& field, std::vector<PdmObject*>* objects)
{ }
};
}
//==================================================================================================
/// QTextStream Stream operator for cvf::Color3f
//==================================================================================================
void operator >> (QTextStream& str, cvf::Color3f& value);
void operator << (QTextStream& str, const cvf::Color3f& value);

View File

@ -34,66 +34,8 @@
//
//##################################################################################################
#pragma once
#include <QVariant>
#include <QList>
//#include <QStringList>
//#include <QXmlStreamReader>
//#include <QXmlStreamWriter>
#include <QTextStream>
//#include "cafPdmUiItem.h"
//#include "cafPdmObjectFactory.h"
#include "cafPdmFieldImpl.h"
#include "cvfAssert.h"
#include "cvfMatrix4.h"
namespace caf
{
// Forward declarations
template <typename T> class PdmField;
//==================================================================================================
/// Partial specialization for PdmField< cvf::Mat4d >
//==================================================================================================
template <>
class PdmFieldTypeSpecialization < cvf::Mat4d >
{
public:
/// Convert the field value into a QVariant
static QVariant convert(const cvf::Mat4d& value)
{
return QVariant();
}
/// Set the field value from a QVariant
static void setFromVariant(const QVariant& variantValue, cvf::Mat4d& value)
{
}
/// Methods to get a list of options for a field
static QList<PdmOptionItemInfo> valueOptions( bool* useOptionsOnly, const cvf::Mat4d& )
{
return QList<PdmOptionItemInfo>();
}
/// Methods to retrieve the possible PdmObject pointed to by a field
static void childObjects(const PdmField< cvf::Mat4d >& field, std::vector<PdmObject*>* objects)
{ }
};
}
//==================================================================================================
/// QTextStream Stream operator for cvf::Color3f
//==================================================================================================
void operator >> (QTextStream& str, cvf::Mat4d& value);
void operator << (QTextStream& str, const cvf::Mat4d& value);
#include "cafPdmCoreMat4d.h"
#include "cafPdmXmlMat4d.h"
#include "cafPdmUiCoreMat4d.h"

View File

@ -0,0 +1,42 @@
//##################################################################################################
//
// 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.
//
//##################################################################################################
#pragma once
#include "cafPdmCoreVec3d.h"
#include "cafPdmXmlVec3d.h"
#include "cafPdmUiCoreVec3d.h"

View File

@ -0,0 +1,43 @@
//##################################################################################################
//
// 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 "cafPdmUiCoreColor3f.h"
#include "cafPdmField.h"
#include "cafPdmProxyValueField.h"
#include "cafPdmUiColorEditor.h"
CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(caf::PdmUiColorEditor, cvf::Color3f);

View File

@ -0,0 +1,87 @@
//##################################################################################################
//
// 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 "cvfBase.h"
#include "cvfColor3.h"
#include "cafInternalPdmValueFieldSpecializations.h"
#include "cafPdmUiFieldSpecialization.h"
#include "cafPdmUiItem.h"
#include "cafPdmCoreColor3f.h"
namespace caf
{
template <>
class PdmUiFieldSpecialization < cvf::Color3f >
{
public:
/// Convert the field value into a QVariant
static QVariant convert(const cvf::Color3f& value)
{
return PdmValueFieldSpecialization< cvf::Color3f >::convert(value);
}
/// Set the field value from a QVariant
static void setFromVariant(const QVariant& variantValue, cvf::Color3f& value)
{
PdmValueFieldSpecialization< cvf::Color3f >::setFromVariant(variantValue, value);
}
static bool isEqual(const QVariant& variantValue, const QVariant& variantValue2)
{
return PdmValueFieldSpecialization< cvf::Color3f >::isEqual(variantValue, variantValue2);
}
/// Methods to get a list of options for a field, specialized for AppEnum
static QList<PdmOptionItemInfo> valueOptions(bool* useOptionsOnly, const cvf::Color3f&)
{
return QList<PdmOptionItemInfo>();
}
/// Methods to retrieve the possible PdmObject pointed to by a field
static void childObjects(const PdmDataValueField< cvf::Color3f >&, std::vector<PdmObjectHandle*>*)
{ }
};
} // end namespace caf

View File

@ -0,0 +1,87 @@
//##################################################################################################
//
// 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 "cvfBase.h"
#include "cvfMatrix4.h"
#include "cafInternalPdmValueFieldSpecializations.h"
#include "cafPdmUiFieldSpecialization.h"
#include "cafPdmUiItem.h"
#include "cafPdmCoreMat4d.h"
namespace caf
{
template <>
class PdmUiFieldSpecialization < cvf::Mat4d >
{
public:
/// Convert the field value into a QVariant
static QVariant convert(const cvf::Mat4d& value)
{
return PdmValueFieldSpecialization< cvf::Mat4d >::convert(value);
}
/// Set the field value from a QVariant
static void setFromVariant(const QVariant& variantValue, cvf::Mat4d& value)
{
PdmValueFieldSpecialization< cvf::Mat4d >::setFromVariant(variantValue, value);
}
static bool isEqual(const QVariant& variantValue, const QVariant& variantValue2)
{
return PdmValueFieldSpecialization< cvf::Mat4d >::isEqual(variantValue, variantValue2);
}
/// Methods to get a list of options for a field, specialized for AppEnum
static QList<PdmOptionItemInfo> valueOptions(bool* useOptionsOnly, const cvf::Mat4d&)
{
return QList<PdmOptionItemInfo>();
}
/// Methods to retrieve the possible PdmObject pointed to by a field
static void childObjects(const PdmDataValueField< cvf::Mat4d >&, std::vector<PdmObjectHandle*>*)
{ }
};
} // end namespace caf

View File

@ -0,0 +1,45 @@
//##################################################################################################
//
// 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 "cafPdmUiCoreVec3d.h"
#include "cafPdmField.h"
#include "cafPdmProxyValueField.h"
#include "cafPdmUiLineEditor.h"
// TODO: This macro is never run, because this compile unit is never touched
// See RPM EvcSplitElementUi where it is needed to set up an editor for a cvf::Vec3d
CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(caf::PdmUiLineEditor, cvf::Vec3d);

View File

@ -0,0 +1,87 @@
//##################################################################################################
//
// 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 "cvfBase.h"
#include "cvfVector3.h"
#include "cafInternalPdmValueFieldSpecializations.h"
#include "cafPdmUiFieldSpecialization.h"
#include "cafPdmUiItem.h"
#include "cafPdmCoreVec3d.h"
namespace caf
{
template <>
class PdmUiFieldSpecialization < cvf::Vec3d >
{
public:
/// Convert the field value into a QVariant
static QVariant convert(const cvf::Vec3d& value)
{
return PdmValueFieldSpecialization< cvf::Vec3d >::convert(value);
}
/// Set the field value from a QVariant
static void setFromVariant(const QVariant& variantValue, cvf::Vec3d& value)
{
PdmValueFieldSpecialization< cvf::Vec3d >::setFromVariant(variantValue, value);
}
static bool isEqual(const QVariant& variantValue, const QVariant& variantValue2)
{
return PdmValueFieldSpecialization< cvf::Vec3d >::isEqual(variantValue, variantValue2);
}
/// Methods to get a list of options for a field, specialized for AppEnum
static QList<PdmOptionItemInfo> valueOptions(bool* useOptionsOnly, const cvf::Vec3d&)
{
return QList<PdmOptionItemInfo>();
}
/// Methods to retrieve the possible PdmObject pointed to by a field
static void childObjects(const PdmDataValueField< cvf::Vec3d >&, std::vector<PdmObjectHandle*>*)
{ }
};
} // end namespace caf

View File

@ -34,18 +34,11 @@
//
//##################################################################################################
#include "cafPdmXmlColor3f.h"
#include <QTextStream>
#include "cvfBase.h"
// Includes needed for field editor registration
#include "cvfColor3.h"
#include "cafPdmUiColorEditor.h"
#include "cafPdmField.h"
CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(caf::PdmUiColorEditor, cvf::Color3f);
void operator >> (QTextStream& str, cvf::Color3f& value)
{
QString text;

View File

@ -0,0 +1,50 @@
//##################################################################################################
//
// 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 "cvfBase.h"
#include "cvfColor3.h"
class QTextStream;
//==================================================================================================
/// QTextStream Stream operator for cvf::Color3f
//==================================================================================================
void operator >> (QTextStream& str, cvf::Color3f& value);
void operator << (QTextStream& str, const cvf::Color3f& value);

View File

@ -34,23 +34,16 @@
//
//##################################################################################################
#include "cafPdmXmlMat4d.h"
#include <QTextStream>
// Includes needed for field editor registration
#include "cvfAssert.h"
#include "cvfMatrix4.h"
//#include "cafPdmUiMatrixEditor.h"
//#include "cafPdmField.h"
//CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(caf::PdmUiMatrixEditor, cvf::Mat4d);
void operator >> (QTextStream& str, cvf::Mat4d& value)
{
for (int r = 0; r < 4 ; ++r)
for (int r = 0; r < 4; ++r)
{
for (int c = 0; c < 4 ; ++c)
for (int c = 0; c < 4; ++c)
{
str >> value(r, c);
}
@ -59,13 +52,11 @@ void operator >> (QTextStream& str, cvf::Mat4d& value)
void operator << (QTextStream& str, const cvf::Mat4d& value)
{
for (int r = 0; r < 4 ; ++r)
for (int r = 0; r < 4; ++r)
{
for (int c = 0; c < 4 ; ++c)
for (int c = 0; c < 4; ++c)
{
str << value(r, c) << " " ;
str << value(r, c) << " ";
}
}
}

View File

@ -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.
//
//##################################################################################################
#pragma once
#include "cvfBase.h"
#include "cvfMatrix4.h"
class QTextStream;
void operator >> (QTextStream& str, cvf::Mat4d& value);
void operator << (QTextStream& str, const cvf::Mat4d& value);

View File

@ -0,0 +1,71 @@
//##################################################################################################
//
// 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 "cafPdmXmlVec3d.h"
#include <QTextStream>
void operator >> (QTextStream& str, cvf::Vec3d& value)
{
bool streamStatusOk = true;
cvf::Vec3d tmp;
for (int r = 0; r < 3; ++r)
{
str >> tmp[r];
if (str.status() != QTextStream::Ok)
{
streamStatusOk = false;
}
}
if (streamStatusOk)
{
value = tmp;
}
}
void operator << (QTextStream& str, const cvf::Vec3d& value)
{
for (int r = 0; r < 3; ++r)
{
str << value[r];
if (r < 2) str << " ";
}
}

View File

@ -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.
//
//##################################################################################################
#pragma once
#include "cvfBase.h"
#include "cvfVector3.h"
class QTextStream;
void operator >> (QTextStream& str, cvf::Vec3d& value);
void operator << (QTextStream& str, const cvf::Vec3d& value);

View File

@ -2,35 +2,30 @@ cmake_minimum_required (VERSION 2.8)
project (cafProjectDataModel)
add_library( ${PROJECT_NAME}
cafAppEnum.h
# Qt
find_package ( Qt4 COMPONENTS QtCore QtGui )
include (${QT_USE_FILE})
include_directories (
${cafPdmCore_SOURCE_DIR}
${cafPdmUiCore_SOURCE_DIR}
${cafPdmXml_SOURCE_DIR}
)
set( PROJECT_FILES
cafFactory.h
cafFixedArray.h
cafOmpMutex.h
cafUiTreeItem.h
cafPdmDocument.cpp
cafPdmDocument.h
cafPdmField.cpp
cafPdmField.h
cafPdmField.inl
cafPdmFieldImpl.h
cafPdmObject.cpp
cafPdmObjectGroup.cpp
cafPdmObjectGroup.h
cafPdmObject.h
cafPdmObjectFactory.h
cafPdmPointer.cpp
cafPdmPointer.h
cafPdmUiEditorHandle.cpp
cafPdmUiEditorHandle.h
cafPdmUiFieldEditorHandle.cpp
cafPdmUiFieldEditorHandle.h
cafPdmUiItem.cpp
cafPdmUiItem.h
cafPdmUiObjectEditorHandle.cpp
cafPdmUiObjectEditorHandle.h
cafPdmUiOrdering.cpp
cafPdmUiOrdering.h
cafPdmUiTreeOrdering.cpp
cafPdmUiTreeOrdering.h
cafPdmUiTreeEditorHandle.h
cafPdmUiTreeEditorHandle.cpp
cafPdmField.h
)
add_library( ${PROJECT_NAME}
${PROJECT_FILES}
)
source_group("" FILES ${PROJECT_FILES})

View File

@ -0,0 +1,166 @@
@startuml
class PdmObject {
name()
fields();
referencingFields();
parentField();
template<T> capability()
void addCapability()
---
std::vector<PdmFieldHandle> m_fields;
std::vector<PdmObjectCapability*> m_capabilities;
}
PdmObject --* "n" PdmObjectCapability
class PdmUiItem{
}
PdmObjectCapability <|- PdmUiObject
PdmUiItem <|- PdmUiObject
class PdmUiObject{
uiOrdering() = ?;
uiTreeOrdering() = ? ;
editorAttribute() = ?;
objectEditorAttribute() = ? ;
userDescriptionField();
objectToggleField()
calculateValueOptions() = ?;
fieldChangedByUi() = 0;
---
m_descriptionField;
m_objectToggleField;
}
PdmUiObject <|-- PdmCompleteObject
PdmObject <|-- PdmCompleteObject
PdmXmlSerializable <|-- PdmCompleteObject
class PdmXmlSerializable {
classKeyword() = 0;
readFields ();
writeFields();
}
PdmObjectCapability <|- PdmXmlSerializable
package FieldHandle{
PdmObject --> "n" PdmFieldHandle
class PdmFieldHandle{
name()
setOwnerObject();
ownerObject();
hasChildObjects() = 0;
childObjects( ) = 0;
---
std::vector<PdmFieldCapability*> m_attributes;
}
PdmFieldHandle --* "n" PdmFieldCapability
class PdmUiFieldHandle{
uiValue()
setValueFromUi()
valueOptions( ) = 0;
}
PdmFieldCapability <|- PdmUiFieldHandle
PdmUiItem <|- PdmUiFieldHandle
class PdmXmlFieldHandle {
setKeyword();
keyword();
readFieldData() = 0;
writeFieldData() = 0;
isIOReadable()
isIOWritable()
setIOWritable()
setIOReadable()
---
bool m_isReadable;
bool m_isWritable;
}
PdmFieldCapability <|- PdmXmlFieldHandle
PdmFieldHandle <|-- PdmCompleteFieldHandle
PdmUiFieldHandle <|-- PdmCompleteFieldHandle
PdmXmlFieldHandle <|-- PdmCompleteFieldHandle
}
package ToDoFields{
class "PdmFieldXmlCap<PdmPtrField<T>>"{
}
}
package SplittedFields{
PdmFieldHandle <|--- "PdmField<T>"
"PdmField<T>" --> "PdmFieldUiCap<FieldT>"
"PdmField<T>" --> "PdmFieldXmlCap<FieldT>"
PdmFieldHandle <|--- "PdmProxyField<T>"
"PdmProxyField<T>" --> "PdmFieldUiCap<FieldT>"
"PdmProxyField<T>" --> "PdmFieldXmlCap<FieldT>"
PdmUiFieldHandle <|--- "PdmFieldUiCap<FieldT>"
PdmXmlFieldHandle <|--- "PdmFieldXmlCap<FieldT>"
PdmFieldHandle <|--- "PdmPtrField<T*>"
"PdmPtrField<T*>" --> "PdmFieldUiCap<FieldT>"
"PdmPtrField<T*>" --> "PdmFieldXmlCap<FieldT>"
"PdmPtrField<T*>" ..> "Todo" "PdmFieldXmlCap<PdmPtrField<T>>"
PdmFieldHandle <|--- "PdmChildField<T*>"
"PdmChildField<T*>"--> "PdmFieldUiCap<PdmField<T*>>"
"PdmChildField<T*>"--> "PdmFieldXmlCap<PdmField<T*>>"
PdmFieldHandle <|--- "PdmChildArrayField<T*>"
"PdmChildArrayField<T*>"--> "PdmFieldUiCap<PdmPointersField<T*>>"
"PdmChildArrayField<T*>"--> "PdmFieldXmlCap<PdmPointersField<T*>>"
}
package ToDoFields{
PdmFieldHandle <|-- "PdmProxyPtrField<T>"
"PdmProxyPtrField<T>" --> "PdmFieldUiCap<FieldT>"
"PdmProxyPtrField<T>" ..> "Todo" "PdmFieldXmlCap<PdmPtrField<T>>"
PdmFieldHandle <|-- "PdmProxyChildField<T*>"
"PdmProxyChildField<T*>"--> "PdmFieldUiCap<PdmField<T*>>"
"PdmProxyChildField<T*>"--> "PdmFieldXmlCap<PdmField<T*>>"
PdmFieldHandle <|-- "PdmProxyChildArrayField<T*>"
"PdmProxyChildArrayField<T*>"--> "PdmFieldUiCap<PdmPointersField<T*>>"
"PdmProxyChildArrayField<T*>"--> "PdmFieldXmlCap<PdmPointersField<T*>>"
}
@enduml

View File

@ -0,0 +1,163 @@
@startuml
class PdmObjectHandle {
name()
fields();
referencingFields();
parentField();
template<T> capability()
void addCapability()
---
std::vector<PdmFieldHandle> m_fields;
std::vector<PdmObjectCapability*> m_capabilities;
}
PdmObjectHandle --* "n" PdmObjectCapability
class PdmUiItem{
}
PdmObjectCapability <|- PdmUiObjectHandle
PdmUiItem <|- PdmUiObjectHandle
class PdmUiObjectHandle {
uiOrdering() = ?;
uiTreeOrdering() = ? ;
editorAttribute() = ?;
objectEditorAttribute() = ? ;
userDescriptionField();
objectToggleField()
calculateValueOptions() = ?;
fieldChangedByUi() = 0;
---
m_descriptionField;
m_objectToggleField;
}
PdmUiObjectHandle <|-- PdmObject
PdmObjectHandle <|-- PdmObject
PdmXmlObjectHandle <|-- PdmObject
class PdmXmlObjectHandle {
classKeyword() = 0;
readFields ();
writeFields();
}
PdmObjectCapability <|- PdmXmlObjectHandle
package FieldHandle{
PdmObjectHandle --> "n" PdmFieldHandle
class PdmFieldHandle{
name()
setOwnerObject();
ownerObject();
hasChildObjects() = 0;
childObjects( ) = 0;
---
std::vector<PdmFieldCapability*> m_attributes;
}
PdmFieldHandle --* "n" PdmFieldCapability
class PdmUiFieldHandle{
uiValue()
setValueFromUi()
valueOptions( ) = 0;
}
PdmFieldCapability <|- PdmUiFieldHandle
PdmUiItem <|- PdmUiFieldHandle
class PdmXmlFieldHandle {
setKeyword();
keyword();
readFieldData() = 0;
writeFieldData() = 0;
isIOReadable()
isIOWritable()
setIOWritable()
setIOReadable()
---
bool m_isReadable;
bool m_isWritable;
}
PdmFieldCapability <|- PdmXmlFieldHandle
}
package ToDoFields{
class "InternalPdmXmlFieldCapability<PdmPtrField<T>>"{
}
}
package SplittedFields{
PdmFieldHandle <|--- "PdmField<T>"
"PdmField<T>" --> "InternalPdmUiFieldCapability<FieldT>"
"PdmField<T>" --> "InternalPdmXmlFieldCapability<FieldT>"
PdmFieldHandle <|--- "PdmProxyField<T>"
"PdmProxyField<T>" --> "InternalPdmUiFieldCapability<FieldT>"
"PdmProxyField<T>" --> "InternalPdmXmlFieldCapability<FieldT>"
PdmUiFieldHandle <|--- "InternalPdmUiFieldCapability<FieldT>"
PdmXmlFieldHandle <|--- "InternalPdmXmlFieldCapability<FieldT>"
PdmFieldHandle <|--- "PdmPtrField<T*>"
"PdmPtrField<T*>" --> "InternalPdmUiFieldCapability<FieldT>"
"PdmPtrField<T*>" --> "InternalPdmXmlFieldCapability<FieldT>"
"PdmPtrField<T*>" ..> "Todo" "InternalPdmXmlFieldCapability<PdmPtrField<T>>"
PdmFieldHandle <|--- "PdmChildField<T*>"
"PdmChildField<T*>"--> "InternalPdmUiFieldCapability<PdmField<T*>>"
"PdmChildField<T*>"--> "InternalPdmXmlFieldCapability<PdmField<T*>>"
PdmFieldHandle <|--- "PdmChildArrayField<T*>"
"PdmChildArrayField<T*>"--> "InternalPdmUiFieldCapability<PdmPointersField<T*>>"
"PdmChildArrayField<T*>"--> "InternalPdmXmlFieldCapability<PdmPointersField<T*>>"
}
package ToDoFields{
PdmFieldHandle <|-- "PdmProxyPtrField<T>"
"PdmProxyPtrField<T>" --> "InternalPdmUiFieldCapability<FieldT>"
"PdmProxyPtrField<T>" ..> "Todo" "InternalPdmXmlFieldCapability<PdmPtrField<T>>"
PdmFieldHandle <|-- "PdmProxyChildField<T*>"
"PdmProxyChildField<T*>"--> "InternalPdmUiFieldCapability<PdmField<T*>>"
"PdmProxyChildField<T*>"--> "InternalPdmXmlFieldCapability<PdmField<T*>>"
PdmFieldHandle <|-- "PdmProxyChildArrayField<T*>"
"PdmProxyChildArrayField<T*>"--> "InternalPdmUiFieldCapability<PdmPointersField<T*>>"
"PdmProxyChildArrayField<T*>"--> "InternalPdmXmlFieldCapability<PdmPointersField<T*>>"
}
@enduml

View File

@ -39,6 +39,25 @@
#include <assert.h>
#include <map>
#include <cstddef>
// Taken from gtest.h
//
// Due to C++ preprocessor weirdness, we need double indirection to
// concatenate two tokens when one of them is __LINE__. Writing
//
// foo ## __LINE__
//
// will result in the token foo__LINE__, instead of foo followed by
// the current line number. For more details, see
// http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6
#define CAF_FACTORY_CONCATENATE_STRINGS(foo, bar) CAF_FACTORY_CONCATENATE_STRINGS_IMPL_(foo, bar)
#define CAF_FACTORY_CONCATENATE_STRINGS_IMPL_(foo, bar) foo ## bar
#define CAF_UNIQUE_COMPILE_UNIT_VAR_NAME CAF_FACTORY_CONCATENATE_STRINGS(caf_factory_init_, __LINE__)
#define CAF_FACTORY_REGISTER(BaseType, TypeToCreate, KeyType, key) \
static bool CAF_UNIQUE_COMPILE_UNIT_VAR_NAME = caf::Factory<BaseType, KeyType>::instance()->registerCreator<TypeToCreate>(key)
namespace caf
{
@ -56,6 +75,8 @@ namespace caf
///
/// static bool uniqueVarname = caf::Factory<BaseType, KeyType>::instance()->registerCreator<TypeToCreate>(key);
///
/// You can also use the macro CAF_FACTORY_REGISTER(BaseType, TypeToCreate, KeyType, key)
///
/// See also cafPdmUiFieldEditorHandle.h for an advanced example.
///
/// When you need an object:

View File

@ -55,8 +55,8 @@ public:
FixedArray<T, size>& operator=(const T* ptr) { for (size_t i = 0; i < size ; ++i) m_array[i] = ptr[i]; return *this;}
template<typename IndexType> T& operator[](const IndexType& index) { return m_array[index]; }
template<typename IndexType> const T& operator[](const IndexType& index) const { return m_array[index]; }
template<typename IndexType> T& operator[](const IndexType& index) { CVF_TIGHT_ASSERT(static_cast<size_t>(index) < size); return m_array[index]; }
template<typename IndexType> const T& operator[](const IndexType& index) const { CVF_TIGHT_ASSERT(static_cast<size_t>(index) < size); return m_array[index]; }
};
typedef FixedArray<int, 3> IntArray3;

View File

@ -0,0 +1,47 @@
cmake_minimum_required (VERSION 2.8)
project (cafPdmCore)
# Qt
find_package ( Qt4 COMPONENTS QtCore )
include (${QT_USE_FILE})
include_directories (
)
set( PROJECT_FILES
cafAppEnum.h
cafClassTypeName.h
cafPdmBase.h
cafPdmChildArrayField.h
cafPdmChildArrayField.inl
cafPdmChildArrayFieldHandle.cpp
cafPdmChildField.h
cafPdmChildField.inl
cafPdmDataValueField.h
cafPdmFieldCapability.h
cafPdmFieldHandle.cpp
cafPdmFieldHandle.h
cafPdmObjectCapability.h
cafPdmObjectHandle.cpp
cafPdmObjectHandle.h
cafPdmPointer.cpp
cafPdmPointer.h
cafPdmProxyValueField.h
cafPdmPtrField.h
cafPdmPtrField.inl
cafPdmReferenceHelper.cpp
cafPdmReferenceHelper.h
cafPdmValueField.h
cafNotificationCenter.cpp
cafNotificationCenter.h
)
add_library( ${PROJECT_NAME}
${PROJECT_FILES}
)
source_group("" FILES ${PROJECT_FILES})

View File

@ -170,13 +170,14 @@ private:
static EnumMapper * instance()
{
static EnumMapper * storedInstance = 0;
if (!storedInstance)
static EnumMapper storedInstance;
static bool isInitialized = false;
if (!isInitialized)
{
storedInstance = new EnumMapper;
isInitialized = true;
AppEnum<T>::setUp();
}
return storedInstance;
return &storedInstance;
}
void setDefault(T defaultEnumValue)

View File

@ -0,0 +1,43 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 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.
//
//##################################################################################################
#pragma once
#include <typeinfo>
/// Create a QString based on a typename
#define qStringTypeName(TypeName) QString(typeid(TypeName).name())

View File

@ -0,0 +1,118 @@
#pragma once
#include <QVariant>
namespace caf
{
//==================================================================================================
/// A proxy class that implements the generic QVariant interface for a field
///
/// This class collects methods that need specialization when introducing a new type in a PdmField.
/// Having those methods in a separate class makes it possible to "partially specialize" the methods
/// for container classes etc. since partial specialization of template functions is not C++ as of yet.
///
/// When introducing a new type in a PdmField, you might need to implement a (partial)specialization
/// of this class.
//==================================================================================================
template <typename T>
class PdmValueFieldSpecialization
{
public:
/// Convert the field value into a QVariant
static QVariant convert(const T& value)
{
return QVariant::fromValue(value);
}
/// Set the field value from a QVariant
static void setFromVariant(const QVariant& variantValue, T& value)
{
value = variantValue.value<T>();
}
/// Check equality between QVariants that carries a Field Value.
/// The == operator will normally work, but does not support custom types in the QVariant
/// See http://qt-project.org/doc/qt-4.8/qvariant.html#operator-eq-eq-64
static bool isEqual(const QVariant& variantValue, const QVariant& variantValue2)
{
return variantValue == variantValue2;
}
};
} // End of namespace caf
#include "cafAppEnum.h"
namespace caf
{
template <typename T>
class PdmValueFieldSpecialization<caf::AppEnum<T> >
{
public:
static QVariant convert(const caf::AppEnum<T>& value)
{
T enumValue = value;
return QVariant(enumValue);
}
static void setFromVariant(const QVariant& variantValue, caf::AppEnum<T>& value)
{
value = (T)variantValue.toInt();
}
static bool isEqual(const QVariant& variantValue, const QVariant& variantValue2)
{
return variantValue == variantValue2;
}
};
} // End of namespace caf
#include <vector>
namespace caf
{
template <typename T>
class PdmValueFieldSpecialization<std::vector<T> >
{
public:
static QVariant convert(const std::vector<T>& value)
{
QList<QVariant> returnList;
typename std::vector<T>::const_iterator it;
for (it = value.begin(); it != value.end() ; ++it)
{
returnList.push_back(QVariant::fromValue(*it));
}
return returnList;
}
static void setFromVariant(const QVariant& variantValue, std::vector<T>& value)
{
if (variantValue.canConvert< QList<QVariant> >())
{
value.clear();
QList<QVariant> lst = variantValue.toList();
for (int i = 0; i < lst.size(); ++i)
{
value.push_back(lst[i].value<T>());
}
}
}
static bool isEqual(const QVariant& variantValue, const QVariant& variantValue2)
{
return variantValue == variantValue2;
}
};
} // End of namespace caf

View File

@ -0,0 +1,116 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2014 Ceetron Solutions AS
//
// <APPLICATION_NAME> 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.
//
// <APPLICATION_NAME> 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.
//
/////////////////////////////////////////////////////////////////////////////////
#include "cafNotificationCenter.h"
#include <QtGlobal>
#include <assert.h>
#include <algorithm>
namespace caf
{
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
NotificationCenter::NotificationCenter()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
NotificationCenter::~NotificationCenter()
{
assert(m_observers.size() == 0);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void NotificationCenter::registerObserver(DataModelObserver* observer)
{
std::vector<DataModelObserver*>::iterator it = std::find(m_observers.begin(), m_observers.end(), observer);
if (it == m_observers.end())
{
m_observers.push_back(observer);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void NotificationCenter::removeObserver(DataModelObserver* observer)
{
std::vector<DataModelObserver*>::iterator it = std::find(m_observers.begin(), m_observers.end(), observer);
if (it != m_observers.end())
{
m_observers.erase(it);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void NotificationCenter::notifyObserversOfDataChange(caf::PdmObjectHandle* itemThatChanged)
{
assert(itemThatChanged);
foreach(DataModelObserver* o, m_observers)
{
o->handleModelNotification(itemThatChanged);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void NotificationCenter::notifyObservers()
{
foreach(DataModelObserver* o, m_observers)
{
o->handleModelNotification(NULL);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void NotificationCenter::notifyObserversOfSelectionChange()
{
foreach(DataModelObserver* o, m_observers)
{
o->handleModelSelectionChange();
}
}
} // end namespace caf

View File

@ -0,0 +1,66 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2014 Ceetron Solutions AS
//
// <APPLICATION_NAME> 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.
//
// <APPLICATION_NAME> 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <vector>
namespace caf
{
class PdmObjectHandle;
//==================================================================================================
//
//
//
//==================================================================================================
class DataModelObserver
{
public:
virtual void handleModelNotification(caf::PdmObjectHandle* itemThatChanged) = 0;
virtual void handleModelSelectionChange() = 0;
};
//==================================================================================================
//
//
//
//==================================================================================================
class NotificationCenter
{
public:
NotificationCenter();
~NotificationCenter();
void registerObserver(DataModelObserver* observer);
void removeObserver(DataModelObserver* observer);
void notifyObservers();
void notifyObserversOfDataChange(caf::PdmObjectHandle* itemThatChanged);
void notifyObserversOfSelectionChange();
private:
std::vector<DataModelObserver*> m_observers;
};
} // end namespace caf

View File

@ -0,0 +1,12 @@
#pragma once
// Brings in size_t and definition of NULL
#include <cstddef>
// Macro to disable the copy constructor and assignment operator
// Should be used in the private section of a class
#define PDM_DISABLE_COPY_AND_ASSIGN(CLASS_NAME) \
CLASS_NAME(const CLASS_NAME&); \
void operator=(const CLASS_NAME&)

View File

@ -0,0 +1,99 @@
#pragma once
#include "cafPdmFieldHandle.h"
#include "cafPdmPointer.h"
#include <assert.h>
namespace caf
{
template <typename T> class PdmFieldXmlCap;
//==================================================================================================
///
///
///
//==================================================================================================
class PdmChildArrayFieldHandle : public PdmFieldHandle
{
public:
PdmChildArrayFieldHandle() {}
virtual ~PdmChildArrayFieldHandle() {}
virtual size_t size() const = 0;
virtual bool empty() const = 0;
virtual void clear() = 0;
virtual void insertAt(size_t indexAfter, PdmObjectHandle* obj) = 0;
virtual void erase(size_t index) = 0;
virtual void deleteAllChildObjects() = 0;
bool hasSameFieldCountForAllObjects();
};
//==================================================================================================
/// PdmFieldClass to handle a collection of PdmObject derived pointers
/// The reasons for this class is to add itself as parentField into the objects being pointed to.
/// The interface is made similar to std::vector<>, and the complexity of the methods is similar too.
//==================================================================================================
template<typename DataType>
class PdmChildArrayField : public PdmFieldHandle
{
public:
PdmChildArrayField()
{
bool doNotUsePdmPointersFieldForAnythingButPointersToPdmObject = false; assert(doNotUsePdmPointersFieldForAnythingButPointersToPdmObject);
}
};
template<typename DataType>
class PdmChildArrayField<DataType*> : public PdmChildArrayFieldHandle
{
typedef DataType* DataTypePtr;
public:
PdmChildArrayField() { }
virtual ~PdmChildArrayField();
PdmChildArrayField& operator() () { return *this; }
// Reimplementation of PdmPointersFieldHandle methods
virtual size_t size() const { return m_pointers.size(); }
virtual bool empty() const { return m_pointers.empty(); }
virtual void clear();
virtual void deleteAllChildObjects();
virtual void insertAt(size_t indexAfter, PdmObjectHandle* obj);
// std::vector-like access
DataType* operator[] (size_t index) const;
void push_back(DataType* pointer);
void set(size_t index, DataType* pointer);
void insert(size_t indexAfter, DataType* pointer);
void insert(size_t indexAfter, const std::vector<PdmPointer<DataType> >& objects);
size_t count(const DataType* pointer) const;
void erase(size_t index);
// Child objects
virtual void childObjects(std::vector<PdmObjectHandle*>* objects);
virtual void removeChildObject(PdmObjectHandle* object);
private: //To be disabled
PDM_DISABLE_COPY_AND_ASSIGN(PdmChildArrayField);
private:
void removeThisAsParentField();
void addThisAsParentField();
private:
friend class PdmFieldXmlCap< PdmChildArrayField<DataType*> >;
std::vector< PdmPointer<DataType> > m_pointers;
};
} // End of namespace caf
#include "cafPdmChildArrayField.inl"

View File

@ -0,0 +1,244 @@
#include "cafClassTypeName.h"
#include "cafPdmObjectHandle.h"
namespace caf
{
//==================================================================================================
/// Implementation of PdmPointersField<>
//==================================================================================================
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType>
PdmChildArrayField<DataType*>::~PdmChildArrayField()
{
this->removeThisAsParentField();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType>
DataType* PdmChildArrayField<DataType*>::operator[](size_t index) const
{
return m_pointers[index];
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmChildArrayField<DataType*>::push_back(DataType* pointer)
{
m_pointers.push_back(pointer);
if (pointer) pointer->setAsParentField(this);
}
//--------------------------------------------------------------------------------------------------
/// Set the value at position index to pointer, overwriting any pointer already present at that
/// position without deleting the object pointed to.
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmChildArrayField<DataType*>::set(size_t index, DataType* pointer)
{
if (m_pointers[index]) m_pointers[index]->removeAsParentField(this);
m_pointers[index] = pointer;
if (m_pointers[index]) pointer->setAsParentField(this);
}
//--------------------------------------------------------------------------------------------------
/// Insert pointer at position index, pushing the value previously at that position and all
/// the preceding values backwards
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmChildArrayField<DataType*>::insert(size_t index, DataType* pointer)
{
m_pointers.insert(m_pointers.begin()+index, pointer);
if (pointer) pointer->setAsParentField(this);
}
//--------------------------------------------------------------------------------------------------
/// Insert the pointers at position index, pushing the value previously at that position and all
/// the preceding values backwards
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmChildArrayField<DataType*>::insert(size_t index, const std::vector<PdmPointer<DataType> >& objects)
{
m_pointers.insert(m_pointers.begin()+index, objects.begin(), objects.end());
typename std::vector< PdmPointer< DataType > >::iterator it;
for (it = m_pointers.begin()+index; it != m_pointers.end(); ++it)
{
if (!it->isNull())
{
(*it)->setAsParentField(this);
}
}
}
//--------------------------------------------------------------------------------------------------
/// Returns the number of times pointer is referenced from the container.
//--------------------------------------------------------------------------------------------------
template<typename DataType>
size_t PdmChildArrayField<DataType*>::count(const DataType* pointer) const
{
size_t itemCount = 0;
typename std::vector< PdmPointer< DataType > >::const_iterator it;
for (it = m_pointers.begin(); it != m_pointers.end(); ++it)
{
if (*it == pointer)
{
itemCount++;
}
}
return itemCount;
}
//--------------------------------------------------------------------------------------------------
/// Empty the container without deleting the objects pointed to.
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmChildArrayField<DataType*>::clear()
{
this->removeThisAsParentField();
m_pointers.clear();
}
//--------------------------------------------------------------------------------------------------
/// Deletes all the objects pointed to by the field, then clears the container.
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmChildArrayField<DataType*>::deleteAllChildObjects()
{
size_t index;
for (index = 0; index < m_pointers.size(); ++index)
{
delete(m_pointers[index].rawPtr());
}
m_pointers.clear();
}
//--------------------------------------------------------------------------------------------------
/// Removes the pointer at index from the container. Does not delete the object pointed to.
/// Todo: This implementation can't be necessary in the new regime. Should be to just remove
/// the item at index (shrinking the array)
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmChildArrayField<DataType*>::erase(size_t index)
{
PdmObjectHandle* obj = m_pointers[index].rawPtr();
if (obj)
{
removeChildObject(obj);
}
}
//--------------------------------------------------------------------------------------------------
/// Removes all instances of object pointer from the container without deleting the object.
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmChildArrayField<DataType*>::removeChildObject(PdmObjectHandle* object)
{
std::vector< PdmPointer<DataType> > tempPointers;
tempPointers = m_pointers;
m_pointers.clear();
for (size_t index = 0; index < tempPointers.size(); ++index)
{
if (tempPointers[index].rawPtr() != object)
{
m_pointers.push_back(tempPointers[index]);
}
else
{
if (tempPointers[index].rawPtr())
{
tempPointers[index].rawPtr()->removeAsParentField(this);
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmChildArrayField<DataType*>::childObjects(std::vector<PdmObjectHandle*>* objects)
{
if (!objects) return;
size_t i;
for (i = 0; i < m_pointers.size(); ++i)
{
objects->push_back(m_pointers[i].rawPtr());
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmChildArrayField<DataType*>::insertAt(size_t indexAfter, PdmObjectHandle* obj)
{
// This method should assert if obj to insert is not castable to the container type, but since this
// is a virtual method, its implementation is always created and that makes a dyn_cast add the need for
// #include of the header file "everywhere"
typename std::vector< PdmPointer<DataType> >::iterator it;
if (indexAfter == -1)
{
m_pointers.push_back(PdmPointer<DataType>());
it = m_pointers.end() - 1;
}
else
{
m_pointers.insert(m_pointers.begin() + indexAfter, PdmPointer<DataType>());
it = m_pointers.begin() + indexAfter;
}
it->setRawPtr(obj);
obj->setAsParentField(this);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmChildArrayField<DataType*>::removeThisAsParentField()
{
typename std::vector< PdmPointer< DataType > >::iterator it;
for (it = m_pointers.begin(); it != m_pointers.end(); ++it)
{
if (!it->isNull())
{
it->rawPtr()->removeAsParentField(this);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmChildArrayField<DataType*>::addThisAsParentField()
{
typename std::vector< PdmPointer< DataType > >::iterator it;
for (it = m_pointers.begin(); it != m_pointers.end(); ++it)
{
if (!it->isNull())
{
(*it)->setAsParentField(this);
}
}
}
} //End of namespace caf

View File

@ -0,0 +1,40 @@
#include "cafPdmChildArrayField.h"
#include "cafPdmFieldHandle.h"
#include "cafPdmObjectHandle.h"
namespace caf
{
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool PdmChildArrayFieldHandle::hasSameFieldCountForAllObjects()
{
std::vector<PdmObjectHandle*> listObjects;
this->childObjects(&listObjects);
if (listObjects.size() == 0)
{
return true;
}
size_t fieldCount = 0;
for (size_t i = 0; i < listObjects.size(); i++)
{
std::vector<PdmFieldHandle*> fields;
listObjects[i]->fields(fields);
if (i == 0)
{
fieldCount = fields.size();
}
else if (fieldCount != fields.size())
{
return false;
}
}
return true;
}
} // End of namespace caf

View File

@ -0,0 +1,69 @@
#pragma once
#include "cafPdmPointer.h"
#include "cafPdmFieldHandle.h"
#include <assert.h>
namespace caf
{
template< typename T> class PdmFieldXmlCap;
//==================================================================================================
/// Specialization for pointers, but only applicable to PdmObject derived objects.
/// The pointer is guarded, meaning that it will be set to NULL if the object pointed to
/// is deleted. The referenced object will be printed in place in the xml-file
/// This is supposed to be renamed to PdmChildField
//==================================================================================================
template<typename DataType>
class PdmChildField : public PdmFieldHandle
{
public:
PdmChildField()
{
bool doNotUsePdmPtrFieldForAnythingButPointersToPdmObject = false; assert(doNotUsePdmPtrFieldForAnythingButPointersToPdmObject);
}
};
template<typename DataType >
class PdmChildField <DataType*> : public PdmFieldHandle
{
typedef DataType* DataTypePtr;
public:
PdmChildField() { }
explicit PdmChildField(const DataTypePtr& fieldValue);
virtual ~PdmChildField();
// Assignment
PdmChildField& operator= (const DataTypePtr & fieldValue);
// Basic access
DataType* value() const { return m_fieldValue; }
void setValue(const DataTypePtr& fieldValue);
// Access operators
/*Conversion*/ operator DataType* () const { return m_fieldValue; }
DataType* operator->() const { return m_fieldValue; }
const PdmPointer<DataType>& operator()() const { return m_fieldValue; }
const PdmPointer<DataType>& v() const { return m_fieldValue; }
// Child objects
virtual void childObjects(std::vector<PdmObjectHandle*>* objects);
virtual void removeChildObject(PdmObjectHandle* object);
private:
PDM_DISABLE_COPY_AND_ASSIGN(PdmChildField);
friend class PdmFieldXmlCap< PdmChildField <DataType*> >;
PdmPointer<DataType> m_fieldValue;
};
} // End of namespace caf
#include "cafPdmChildField.inl"

View File

@ -0,0 +1,73 @@
#include <vector>
#include <iostream>
#include <assert.h>
namespace caf
{
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
void caf::PdmChildField<DataType*>::childObjects(std::vector<PdmObjectHandle*>* objects)
{
assert(objects);
PdmObjectHandle* obj = m_fieldValue.rawPtr();
if (obj)
{
objects->push_back(obj);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
void caf::PdmChildField<DataType*>::removeChildObject(PdmObjectHandle* object)
{
if (m_fieldValue.rawPtr() != NULL && m_fieldValue.rawPtr() == object)
{
m_fieldValue.rawPtr()->removeAsParentField(this);
m_fieldValue.setRawPtr(NULL);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
caf::PdmChildField<DataType*>::PdmChildField(const DataTypePtr& fieldValue)
{
if (m_fieldValue) m_fieldValue->removeAsParentField(this);
m_fieldValue = fieldValue;
if (m_fieldValue != NULL) m_fieldValue->setAsParentField(this);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
caf::PdmChildField<DataType*>::~PdmChildField()
{
if (!m_fieldValue.isNull()) m_fieldValue.rawPtr()->removeAsParentField(this);
m_fieldValue.setRawPtr(NULL);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
caf::PdmChildField<DataType*>& PdmChildField<DataType*>::operator=(const DataTypePtr & fieldValue)
{
if (m_fieldValue) m_fieldValue->removeAsParentField(this);
m_fieldValue = fieldValue;
if (m_fieldValue != NULL) m_fieldValue->setAsParentField(this);
return *this;
}
} //End of namespace caf

View File

@ -0,0 +1,54 @@
cmake_minimum_required (VERSION 2.8)
find_package ( Qt4 COMPONENTS QtCore )
include (${QT_USE_FILE})
project ( cafPdmCore_UnitTests )
include_directories (
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/..
)
set( PROJECT_FILES
cafPdmCore_UnitTests.cpp
gtest/gtest-all.cpp
cafPdmCoreBasicTest.cpp
Child.cpp
Child.h
Parent.cpp
Parent.h
TestObj.cpp
TestObj.h
)
# add the executable
add_executable (${PROJECT_NAME}
${PROJECT_FILES}
)
source_group("" FILES ${PROJECT_FILES})
message(STATUS ${PROJECT_NAME}" - Qt includes : " ${QT_LIBRARIES})
target_link_libraries ( ${PROJECT_NAME}
cafPdmCore
${QT_LIBRARIES}
)
# Copy Qt Dlls
if (MSVC)
set (QTLIBLIST QtCore )
foreach (qtlib ${QTLIBLIST})
# Debug
execute_process(COMMAND cmake -E copy_if_different ${QT_BINARY_DIR}/${qtlib}d4.dll ${CMAKE_CURRENT_BINARY_DIR}/Debug/${qtlib}d4.dll)
# Release
execute_process(COMMAND cmake -E copy_if_different ${QT_BINARY_DIR}/${qtlib}4.dll ${CMAKE_CURRENT_BINARY_DIR}/Release/${qtlib}4.dll)
endforeach( qtlib )
endif(MSVC)

View File

@ -0,0 +1,11 @@
#include "Child.h"
#include "TestObj.h"
Child::Child()
{
this->addField(&m_testObj, "Numbers");
}
Child::~Child()
{
}

View File

@ -0,0 +1,19 @@
#pragma once
#include "cafPdmChildField.h"
#include "cafPdmPointer.h"
#include "cafPdmObjectHandle.h"
class TestObj;
class Child: public caf::PdmObjectHandle
{
public:
Child();
~Child();
caf::PdmChildField<TestObj*> m_testObj;
};

View File

@ -0,0 +1,31 @@
#include "Parent.h"
#include "Child.h"
Parent::Parent()
{
this->addField(&m_simpleObjectsField, "SimpleObjects");
this->addField(&m_simpleObjectF, "SimpleObject");
}
Parent::~Parent()
{
}
void Parent::doSome()
{
size_t i = m_simpleObjectsField.size();
if (i){
//Child* c = m_simpleObjectsField[0];
//TestObj* to = c->m_testObj();
}
}
#include <gtest/gtest.h>
TEST(IncludeTest, Basic)
{
Parent* p = new Parent;
delete(p);
}

View File

@ -0,0 +1,19 @@
#pragma once
#include "cafPdmObjectHandle.h"
#include "cafPdmChildArrayField.h"
#include "cafPdmChildField.h"
class Child;
class Parent : public caf::PdmObjectHandle
{
public:
Parent();
~Parent();
void doSome();
caf::PdmChildArrayField<Child*> m_simpleObjectsField;
caf::PdmChildField<Child*> m_simpleObjectF;
};

View File

@ -0,0 +1,9 @@
#include "TestObj.h"
TestObj::TestObj()
{
this->addField(&m_position, "Position");
}
TestObj::~TestObj() {}

View File

@ -0,0 +1,14 @@
#pragma once
#include "cafPdmPointer.h"
#include "cafPdmDataValueField.h"
#include "cafPdmObjectHandle.h"
class TestObj : public caf::PdmObjectHandle
{
public:
TestObj();
~TestObj();
caf::PdmDataValueField<double> m_position;
};

View File

@ -0,0 +1,574 @@
#include "gtest/gtest.h"
#include "cafPdmChildArrayField.h"
#include "cafPdmChildField.h"
#include "cafPdmDataValueField.h"
#include "cafPdmObjectHandle.h"
#include "cafPdmProxyValueField.h"
#include "cafPdmValueField.h"
#include "Parent.h"
#include "cafPdmPtrField.h"
class DemoPdmObject: public caf::PdmObjectHandle
{
public:
DemoPdmObject()
{
this->addField(&m_proxyDoubleField, "m_proxyDoubleField");
m_proxyDoubleField.registerSetMethod(this, &DemoPdmObject::setDoubleMember);
m_proxyDoubleField.registerGetMethod(this, &DemoPdmObject::doubleMember);
this->addField(&m_proxyIntField, "m_proxyIntField");
m_proxyIntField.registerSetMethod(this, &DemoPdmObject::setIntMember);
m_proxyIntField.registerGetMethod(this, &DemoPdmObject::intMember);
this->addField(&m_proxyStringField, "m_proxyStringField");
m_proxyStringField.registerSetMethod(this, &DemoPdmObject::setStringMember);
m_proxyStringField.registerGetMethod(this, &DemoPdmObject::stringMember);
this->addField(&m_memberDoubleField, "m_memberDoubleField");
this->addField(&m_memberIntField, "m_memberIntField");
this->addField(&m_memberStringField, "m_memberStringField");
// Default values
m_doubleMember = 2.1;
m_intMember = 7;
m_stringMember = "abba";
m_memberDoubleField = 0.0;
m_memberIntField = 0;
m_memberStringField = "";
}
~DemoPdmObject()
{
}
// Fields
caf::PdmProxyValueField<double> m_proxyDoubleField;
caf::PdmProxyValueField<int> m_proxyIntField;
caf::PdmProxyValueField<QString> m_proxyStringField;
caf::PdmDataValueField<double> m_memberDoubleField;
caf::PdmDataValueField<int> m_memberIntField;
caf::PdmDataValueField<QString> m_memberStringField;
// Internal class members accessed by proxy fields
double doubleMember() const { std::cout << "doubleMember" << std::endl; return m_doubleMember; }
void setDoubleMember(const double& d) { m_doubleMember = d; std::cout << "setDoubleMember" << std::endl; }
int intMember() const { return m_intMember; }
void setIntMember(const int& val) { m_intMember = val; }
QString stringMember() const { return m_stringMember; }
void setStringMember(const QString& val) { m_stringMember = val; }
private:
double m_doubleMember;
int m_intMember;
QString m_stringMember;
};
class InheritedDemoObj : public DemoPdmObject
{
public:
InheritedDemoObj()
{
this->addField(&m_texts, "Texts");
this->addField(&m_childArrayField, "DemoPdmObjectects");
this->addField(&m_ptrField, "m_ptrField");
}
caf::PdmDataValueField<QString > m_texts;
caf::PdmChildArrayField<DemoPdmObject*> m_childArrayField;
caf::PdmPtrField<InheritedDemoObj*> m_ptrField;
};
TEST(BaseTest, Delete)
{
DemoPdmObject* s2 = new DemoPdmObject;
delete s2;
}
//--------------------------------------------------------------------------------------------------
/// TestPdmDataValueField
//--------------------------------------------------------------------------------------------------
TEST(BaseTest, TestPdmDataValueField)
{
DemoPdmObject* a = new DemoPdmObject;
ASSERT_DOUBLE_EQ(0.0, a->m_memberDoubleField.value());
a->m_memberDoubleField.setValue(1.2);
ASSERT_DOUBLE_EQ(1.2, a->m_memberDoubleField.value());
ASSERT_EQ(0, a->m_memberIntField.value());
a->m_memberIntField.setValue(11);
ASSERT_EQ(11, a->m_memberIntField.value());
ASSERT_TRUE(a->m_memberStringField.value().isEmpty());
a->m_memberStringField.setValue("123");
ASSERT_TRUE(a->m_memberStringField.value() == "123");
}
//--------------------------------------------------------------------------------------------------
/// TestPdmProxyValueField
//--------------------------------------------------------------------------------------------------
TEST(BaseTest, TestPdmProxyValueField)
{
DemoPdmObject* a = new DemoPdmObject;
ASSERT_DOUBLE_EQ(2.1, a->m_proxyDoubleField.value());
a->m_proxyDoubleField.setValue(1.2);
ASSERT_DOUBLE_EQ(1.2, a->m_proxyDoubleField.value());
ASSERT_EQ(7, a->m_proxyIntField.value());
a->m_proxyIntField.setValue(11);
ASSERT_EQ(11, a->m_proxyIntField.value());
ASSERT_TRUE(a->m_proxyStringField.value() == "abba");
a->m_proxyStringField.setValue("123");
ASSERT_TRUE(a->m_proxyStringField.value() == "123");
}
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
TEST(BaseTest, TestPdmValueFieldInterface)
{
DemoPdmObject* a = new DemoPdmObject;
{
caf::PdmValueField* valField = dynamic_cast<caf::PdmValueField*>(a->findField("m_proxyDoubleField"));
QVariant newVal = 3.4;
valField->setFromQVariant(newVal);
QVariant var = valField->toQVariant();
ASSERT_TRUE(newVal == var);
}
{
caf::PdmValueField* valField = dynamic_cast<caf::PdmValueField*>(a->findField("m_proxyIntField"));
QVariant newVal = 3;
valField->setFromQVariant(newVal);
QVariant var = valField->toQVariant();
ASSERT_TRUE(newVal == var);
}
{
caf::PdmValueField* valField = dynamic_cast<caf::PdmValueField*>(a->findField("m_proxyStringField"));
QVariant newVal = "test";
valField->setFromQVariant(newVal);
QVariant var = valField->toQVariant();
ASSERT_TRUE(newVal == var);
}
{
caf::PdmValueField* valField = dynamic_cast<caf::PdmValueField*>(a->findField("m_memberDoubleField"));
QVariant newVal = 3.4;
valField->setFromQVariant(newVal);
QVariant var = valField->toQVariant();
ASSERT_TRUE(newVal == var);
}
{
caf::PdmValueField* valField = dynamic_cast<caf::PdmValueField*>(a->findField("m_memberIntField"));
QVariant newVal = 3;
valField->setFromQVariant(newVal);
QVariant var = valField->toQVariant();
ASSERT_TRUE(newVal == var);
}
{
caf::PdmValueField* valField = dynamic_cast<caf::PdmValueField*>(a->findField("m_memberStringField"));
QVariant newVal = "test";
valField->setFromQVariant(newVal);
QVariant var = valField->toQVariant();
ASSERT_TRUE(newVal == var);
}
}
//--------------------------------------------------------------------------------------------------
/// Test of PdmDataValueField operations
//--------------------------------------------------------------------------------------------------
TEST(BaseTest, NormalPdmField)
{
class A
{
public:
A(const std::vector<double>& testValue) : field2(testValue), field3(field2) {}
caf::PdmDataValueField<std::vector<double> > field1;
caf::PdmDataValueField<std::vector<double> > field2;
caf::PdmDataValueField<std::vector<double> > field3;
};
std::vector<double> testValue;
testValue.push_back(1.1);
testValue.push_back(1.2);
testValue.push_back(1.3);
std::vector<double> testValue2;
testValue2.push_back(2.1);
testValue2.push_back(2.2);
testValue2.push_back(2.3);
// Constructors
A a(testValue);
EXPECT_EQ(1.3, a.field2.v()[2]);
EXPECT_EQ(1.3, a.field3.v()[2]);
EXPECT_EQ(size_t(0), a.field1().size());
// Operators
// ==
EXPECT_FALSE(a.field1 == a.field3);
// = field to field
a.field1 = a.field2;
// ()
EXPECT_EQ(1.3, a.field1()[2]);
// = value to field
a.field1 = testValue2;
// v()
EXPECT_EQ(2.3, a.field1.v()[2]);
// ==
a.field3 = a.field1;
EXPECT_TRUE(a.field1 == a.field3);
}
//--------------------------------------------------------------------------------------------------
/// Test of PdmChildArrayField operations
//--------------------------------------------------------------------------------------------------
TEST(BaseTest, PdmChildArrayField)
{
InheritedDemoObj* ihd1 = new InheritedDemoObj;
caf::PdmPointer<DemoPdmObject> s1 = new DemoPdmObject;
caf::PdmPointer<DemoPdmObject> s2 = new DemoPdmObject;
caf::PdmPointer<DemoPdmObject> s3 = new DemoPdmObject;
// empty() number 1
EXPECT_TRUE(ihd1->m_childArrayField.empty());
EXPECT_EQ(size_t(0), ihd1->m_childArrayField.size());
// push_back()
ihd1->m_childArrayField.push_back(s1);
ihd1->m_childArrayField.push_back(s2);
ihd1->m_childArrayField.push_back(s3);
// Parent field
EXPECT_EQ(s1->parentField(), &(ihd1->m_childArrayField));
// size()
EXPECT_EQ(size_t(3), ihd1->m_childArrayField.size());
EXPECT_EQ(size_t(3), ihd1->m_childArrayField.size());
// operator[]
EXPECT_EQ(s2, ihd1->m_childArrayField[1]);
EXPECT_EQ(s3, ihd1->m_childArrayField[2]);
// childObjects
std::vector<caf::PdmObjectHandle*> objects;
ihd1->m_childArrayField.childObjects(&objects);
EXPECT_EQ(size_t(3), objects.size());
// set()
ihd1->m_childArrayField.set(1, NULL);
EXPECT_TRUE(NULL == ihd1->m_childArrayField[1]);
EXPECT_TRUE(s2->parentField() == NULL);
ihd1->m_childArrayField.removeChildObject(NULL);
EXPECT_EQ(size_t(2), ihd1->m_childArrayField.size());
EXPECT_EQ(s3, ihd1->m_childArrayField[1]);
EXPECT_EQ(s1, ihd1->m_childArrayField[0]);
// insert()
ihd1->m_childArrayField.insert(1, s2);
EXPECT_EQ(s1, ihd1->m_childArrayField[0]);
EXPECT_EQ(s2, ihd1->m_childArrayField[1]);
EXPECT_EQ(s3, ihd1->m_childArrayField[2]);
EXPECT_TRUE(s2->parentField() == &(ihd1->m_childArrayField));
// erase (index)
ihd1->m_childArrayField.erase(1);
EXPECT_EQ(size_t(2), ihd1->m_childArrayField.size());
EXPECT_EQ(s3, ihd1->m_childArrayField[1]);
EXPECT_EQ(s1, ihd1->m_childArrayField[0]);
EXPECT_TRUE(s2->parentField() == NULL);
// clear()
ihd1->m_childArrayField.clear();
EXPECT_EQ(size_t(0), ihd1->m_childArrayField.size());
EXPECT_TRUE(s1->parentField() == NULL);
ihd1->m_childArrayField.push_back(s1);
ihd1->m_childArrayField.push_back(s2);
ihd1->m_childArrayField.push_back(s3);
ihd1->m_childArrayField.deleteAllChildObjects();
EXPECT_EQ(size_t(0), ihd1->m_childArrayField.size());
EXPECT_TRUE(s1 == NULL);
EXPECT_TRUE(s2 == NULL);
EXPECT_TRUE(s3 == NULL);
}
TEST(BaseTest, PdmChildArrayParentField)
{
// Test of instanciating a class with forward declare of object used in PdmChildArrayField and PdmChildField
Parent* parentObj = new Parent;
delete parentObj;
}
#include "Child.h"
TEST(BaseTest, PdmPointersFieldInsertVector)
{
Parent* ihd1 = new Parent;
Child* s1 = new Child;
Child* s2 = new Child;
Child* s3 = new Child;
std::vector<caf::PdmPointer<Child> > typedObjects;
typedObjects.push_back(s1);
typedObjects.push_back(s2);
typedObjects.push_back(s3);
ihd1->m_simpleObjectsField.push_back(new Child);
ihd1->m_simpleObjectsField.insert(ihd1->m_simpleObjectsField.size(), typedObjects);
EXPECT_EQ(size_t(4), ihd1->m_simpleObjectsField.size());
EXPECT_EQ(ihd1->m_simpleObjectsField[3], s3);
delete ihd1;
}
//--------------------------------------------------------------------------------------------------
/// PdmChildArrayFieldHandle
//--------------------------------------------------------------------------------------------------
TEST(BaseTest, PdmChildArrayFieldHandle)
{
// virtual size_t size() const = 0;
// virtual bool empty() const = 0;
// virtual void clear() = 0;
// virtual PdmObject* createAppendObject(int indexAfter) = 0;
// virtual void erase(size_t index) = 0;
// virtual void deleteAllChildObjects() = 0;
//
// virtual PdmObject* at(size_t index) = 0;
//
// bool hasSameFieldCountForAllObjects();
DemoPdmObject* s0 = new DemoPdmObject;
s0->m_memberDoubleField = 1000;
DemoPdmObject* s1 = new DemoPdmObject;
s1->m_memberDoubleField = 1000;
DemoPdmObject* s2 = new DemoPdmObject;
s2->m_memberDoubleField = 2000;
DemoPdmObject* s3 = new DemoPdmObject;
s3->m_memberDoubleField = 3000;
InheritedDemoObj* ihd1 = new InheritedDemoObj;
caf::PdmChildArrayFieldHandle* listField = &(ihd1->m_childArrayField);
EXPECT_EQ(0, listField->size());
EXPECT_TRUE(listField->hasSameFieldCountForAllObjects());
EXPECT_TRUE(listField->empty());
listField->insertAt(0, s0);
EXPECT_EQ(1, listField->size());
EXPECT_TRUE(listField->hasSameFieldCountForAllObjects());
EXPECT_FALSE(listField->empty());
ihd1->m_childArrayField.push_back(s1);
ihd1->m_childArrayField.push_back(s2);
ihd1->m_childArrayField.push_back(s3);
EXPECT_EQ(4, listField->size());
EXPECT_TRUE(listField->hasSameFieldCountForAllObjects());
EXPECT_FALSE(listField->empty());
listField->erase(0);
EXPECT_EQ(3, listField->size());
EXPECT_TRUE(listField->hasSameFieldCountForAllObjects());
EXPECT_FALSE(listField->empty());
listField->deleteAllChildObjects();
EXPECT_EQ(0, listField->size());
EXPECT_TRUE(listField->hasSameFieldCountForAllObjects());
EXPECT_TRUE(listField->empty());
}
//--------------------------------------------------------------------------------------------------
/// Test of PdmChildField
//--------------------------------------------------------------------------------------------------
TEST(BaseTest, PdmChildField)
{
class A {
public:
A(Child* a) :field2(a) {}
caf::PdmChildField<Child*> field2;
int b;
};
{
Parent* parent = new Parent;
Child* testValue = new Child;
// Constructor assignment
A a(testValue);
EXPECT_EQ(testValue, a.field2.v());
// Guarded
delete testValue;
EXPECT_EQ((Child*)0, a.field2);
}
{
A a(NULL);
Child* c2 = new Child;
// Assign
a.field2 = c2;
// Access
EXPECT_EQ(c2, a.field2.v());
EXPECT_EQ(c2, a.field2);
EXPECT_EQ(c2, a.field2.value());
EXPECT_TRUE(c2 == a.field2);
std::vector<caf::PdmObjectHandle*> objects;
a.field2.childObjects(&objects);
EXPECT_EQ((size_t)1, objects.size());
EXPECT_EQ(c2, objects[0]);
}
}
TEST(BaseTest, PdmPtrField)
{
InheritedDemoObj* ihd1 = new InheritedDemoObj;
InheritedDemoObj* ihd2 = new InheritedDemoObj;
// Direct access
EXPECT_EQ((InheritedDemoObj*)NULL, ihd1->m_ptrField);
InheritedDemoObj* accessedIhd = NULL;
// Assignment
ihd1->m_ptrField = ihd1;
accessedIhd = ihd1->m_ptrField;
EXPECT_EQ(ihd1, accessedIhd);
ihd1->m_ptrField = caf::PdmPointer<InheritedDemoObj>(ihd2);
accessedIhd = ihd1->m_ptrField;
EXPECT_EQ(ihd2, accessedIhd);
// Access
accessedIhd = ihd1->m_ptrField; // Conversion
EXPECT_EQ(ihd2, accessedIhd);
accessedIhd = ihd1->m_ptrField.value();
EXPECT_EQ(ihd2, accessedIhd);
accessedIhd = ihd1->m_ptrField.v();
caf::PdmPointer<InheritedDemoObj> accessedPdmPtr;
EXPECT_EQ(ihd2, accessedIhd);
accessedPdmPtr = ihd1->m_ptrField.v();
EXPECT_EQ(ihd2, accessedPdmPtr.p());
accessedPdmPtr = ihd1->m_ptrField();
EXPECT_EQ(ihd2, accessedPdmPtr.p());
// Operator ==
EXPECT_TRUE(ihd1->m_ptrField == ihd2);
EXPECT_FALSE(ihd1->m_ptrField == ihd1);
EXPECT_TRUE(ihd1->m_ptrField == caf::PdmPointer<InheritedDemoObj>(ihd2));
// Generic access
std::vector<caf::PdmObjectHandle*> objects;
ihd1->m_ptrField.ptrReferencedObjects(&objects);
EXPECT_EQ(1, objects.size());
EXPECT_EQ(ihd2, objects[0]);
// Operator ->
ihd1->m_ptrField->m_texts = "Hei PtrField";
EXPECT_TRUE(ihd1->m_ptrField->m_texts == "Hei PtrField");
// Refrencing system
std::vector<caf::PdmFieldHandle*> ptrFields;
ihd2->referringPtrFields(ptrFields);
EXPECT_EQ(1, ptrFields.size());
EXPECT_EQ(&(ihd1->m_ptrField), ptrFields[0]);
objects.clear();
ihd2->objectsWithReferringPtrFields(objects);
EXPECT_EQ(1, objects.size());
EXPECT_EQ(ihd1, objects[0]);
delete ihd1;
delete ihd2;
}
//--------------------------------------------------------------------------------------------------
/// Tests the features of PdmPointer
//--------------------------------------------------------------------------------------------------
TEST(BaseTest, PdmPointer)
{
InheritedDemoObj * d = new InheritedDemoObj;
{
caf::PdmPointer<InheritedDemoObj> p;
EXPECT_TRUE(p == NULL);
}
{
caf::PdmPointer<InheritedDemoObj> p(d);
caf::PdmPointer<InheritedDemoObj> p2(p);
EXPECT_TRUE(p == d && p2 == d);
EXPECT_TRUE(p.p() == d);
p = 0;
EXPECT_TRUE(p == NULL);
EXPECT_TRUE(p.isNull());
EXPECT_TRUE(p2 == d);
p = p2;
EXPECT_TRUE(p == d);
delete d;
EXPECT_TRUE(p.isNull() && p2.isNull());
}
caf::PdmPointer<DemoPdmObject> p3(new DemoPdmObject());
delete p3;
}

View File

@ -0,0 +1,56 @@
//##################################################################################################
//
// 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 "gtest/gtest.h"
#include <stdio.h>
#include <iostream>
#include <string>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
int result = RUN_ALL_TESTS();
char text[5];
std::cin.getline(text, 5);
return result;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,108 @@
//##################################################################################################
//
// 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.
//
//##################################################################################################
#ifndef CAF_IS_DEFINING_PDM_FIELD
#pragma once
#endif
#include "cafPdmValueField.h"
#include "cafInternalPdmValueFieldSpecializations.h"
#include <vector>
#include <QVariant>
namespace caf
{
class PdmObjectHandle;
//==================================================================================================
/// Field class encapsulating data with input and output of this data to/from a QXmlStream
/// read/write-FieldData is supposed to be specialized for types needing specialization
//==================================================================================================
template<typename DataType >
class PdmDataValueField : public PdmValueField
{
public:
typedef DataType FieldDataType;
PdmDataValueField() {}
PdmDataValueField(const PdmDataValueField& other) { m_fieldValue = other.m_fieldValue; }
explicit PdmDataValueField(const DataType& fieldValue) { m_fieldValue = fieldValue; }
virtual ~PdmDataValueField() {}
// Assignment
PdmDataValueField& operator= (const PdmDataValueField& other) { m_fieldValue = other.m_fieldValue; return *this; }
PdmDataValueField& operator= (const DataType& fieldValue) { m_fieldValue = fieldValue; return *this; }
// Basic access
DataType value() const { return m_fieldValue; }
void setValue(const DataType& fieldValue) { m_fieldValue = fieldValue; }
// Implementation of PdmValueField interface
virtual QVariant toQVariant() const { return PdmValueFieldSpecialization<DataType>::convert(m_fieldValue); }
virtual void setFromQVariant(const QVariant& variant) { PdmValueFieldSpecialization<DataType>::setFromVariant(variant, m_fieldValue); }
virtual bool isReadOnly() const { return false; }
// Access operators
/*Conversion */ operator DataType () const { return m_fieldValue; }
const DataType& operator()() const { return m_fieldValue; }
DataType& v() { return m_fieldValue; } // This one breaches encapsulation. Remove ?
const DataType& v() const { return m_fieldValue; }
bool operator== (const DataType& fieldValue) const { return m_fieldValue == fieldValue; }
protected:
DataType m_fieldValue;
// Default value stuff.
//
// This is not used enough. Remove when dust has settled.
// ResInsight uses at one point to find whether the value is changed by the user
public:
const DataType& defaultValue() const { return m_defaultFieldValue; }
void setDefaultValue(const DataType& val) { m_defaultFieldValue = val; }
protected:
DataType m_defaultFieldValue;
};
} // End of namespace caf

View File

@ -0,0 +1,14 @@
#pragma once
namespace caf
{
class PdmFieldCapability
{
public:
PdmFieldCapability() {}
virtual ~PdmFieldCapability() {}
};
} // End of namespace caf

View File

@ -0,0 +1,72 @@
#include "cafPdmFieldHandle.h"
#include "cafPdmFieldCapability.h"
#include <assert.h>
namespace caf
{
#if 0
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool PdmFieldHandle::assertValid() const
{
if (m_keyword == "UNDEFINED")
{
std::cout << "PdmField: Detected use of non-initialized field. Did you forget to do CAF_PDM_InitField() on this field ?\n";
return false;
}
if (!PdmXmlSerializable::isValidXmlElementName(m_keyword))
{
std::cout << "PdmField: The supplied keyword: \"" << m_keyword.toStdString() << "\" is an invalid XML element name, and will break your file format!\n";
return false;
}
return true;
}
#endif
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmFieldHandle::setKeyword(const QString& keyword)
{
m_keyword = keyword;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool PdmFieldHandle::hasChildObjects()
{
std::vector<PdmObjectHandle*> children;
this->childObjects(&children);
return (children.size() > 0);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmFieldHandle::~PdmFieldHandle()
{
for (size_t i = 0; i < m_capabilities.size(); ++i)
{
if (m_capabilities[i].second) delete m_capabilities[i].first;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool PdmFieldHandle::hasPtrReferencedObjects()
{
std::vector<PdmObjectHandle*> ptrReffedObjs;
this->ptrReferencedObjects(&ptrReffedObjs);
return (ptrReffedObjs.size() > 0);
}
} // End of namespace caf

View File

@ -0,0 +1,69 @@
#pragma once
#include "cafPdmBase.h"
#include <QString>
#include <vector>
namespace caf
{
class PdmObjectHandle;
//==================================================================================================
/// Base class for all fields, making it possible to handle them generically
//==================================================================================================
class PdmFieldCapability;
class PdmFieldHandle
{
public:
PdmFieldHandle() { m_ownerObject = NULL; }
virtual ~PdmFieldHandle();
QString keyword() const { return m_keyword; }
PdmObjectHandle* ownerObject() { return m_ownerObject; }
// Child objects
bool hasChildObjects();
virtual void childObjects(std::vector<PdmObjectHandle*>*) { }
virtual void removeChildObject(PdmObjectHandle*) { }
// Ptr referenced objects
bool hasPtrReferencedObjects();
virtual void ptrReferencedObjects(std::vector<PdmObjectHandle*>*) { }
// Capabilities
void addCapability(PdmFieldCapability* capability, bool takeOwnership) { m_capabilities.push_back(std::make_pair(capability, takeOwnership)); }
template <typename CapabilityType>
CapabilityType* capability();
private:
PDM_DISABLE_COPY_AND_ASSIGN(PdmFieldHandle);
friend class PdmObjectHandle; // Give access to m_ownerObject and set Keyword
void setKeyword(const QString& keyword);
PdmObjectHandle* m_ownerObject;
QString m_keyword;
std::vector<std::pair<PdmFieldCapability*, bool> > m_capabilities;
};
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template <typename CapabilityType>
CapabilityType* PdmFieldHandle::capability()
{
for (size_t i = 0; i < m_capabilities.size(); ++i)
{
CapabilityType* capability = dynamic_cast<CapabilityType*>(m_capabilities[i].first);
if (capability) return capability;
}
return NULL;
}
} // End of namespace caf

View File

@ -0,0 +1,14 @@
#pragma once
namespace caf
{
class PdmObjectCapability
{
public:
PdmObjectCapability() {}
virtual ~PdmObjectCapability() {}
};
} // End namespace caf

View File

@ -0,0 +1,149 @@
#include "cafPdmObjectHandle.h"
#include "cafPdmFieldHandle.h"
#include "cafPdmObjectCapability.h"
#include <assert.h>
namespace caf
{
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmObjectHandle::~PdmObjectHandle()
{
for (size_t i = 0; i < m_capabilities.size(); ++i)
{
if (m_capabilities[i].second) delete m_capabilities[i].first;
}
// Set all guarded pointers pointing to this to NULL
std::set<PdmObjectHandle**>::iterator it;
for (it = m_pointersReferencingMe.begin(); it != m_pointersReferencingMe.end() ; ++it)
{
(**it) = NULL;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmObjectHandle::fields(std::vector<PdmFieldHandle*>& fields) const
{
fields = m_fields;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmObjectHandle::setAsParentField(PdmFieldHandle* parentField)
{
assert(m_parentField == NULL);
m_parentField = parentField;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmObjectHandle::removeAsParentField(PdmFieldHandle* parentField)
{
assert(m_parentField == parentField);
m_parentField = NULL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmObjectHandle::addReferencingPtrField(PdmFieldHandle* fieldReferringToMe)
{
if (fieldReferringToMe != NULL) m_referencingPtrFields.insert(fieldReferringToMe);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmObjectHandle::removeReferencingPtrField(PdmFieldHandle* fieldReferringToMe)
{
if (fieldReferringToMe != NULL) m_referencingPtrFields.erase(fieldReferringToMe);
}
//--------------------------------------------------------------------------------------------------
/// Appends pointers to all the PdmPtrFields containing a pointer to this object.
/// As the PdmPtrArrayFields can hold several pointers to the same object, the returned vector can
/// contain multiple pointers to the same field.
//--------------------------------------------------------------------------------------------------
void PdmObjectHandle::referringPtrFields(std::vector<PdmFieldHandle*>& fieldsReferringToMe) const
{
std::multiset<PdmFieldHandle*>::const_iterator it;
for (it = m_referencingPtrFields.begin(); it != m_referencingPtrFields.end(); ++it)
{
fieldsReferringToMe.push_back(*it);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmObjectHandle::objectsWithReferringPtrFields(std::vector<PdmObjectHandle*>& objects) const
{
std::vector<caf::PdmFieldHandle*> parentFields;
this->referringPtrFields(parentFields);
size_t i;
for (i = 0; i < parentFields.size(); i++)
{
objects.push_back(parentFields[i]->ownerObject());
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmObjectHandle::addField(PdmFieldHandle* field, const QString& keyword)
{
field->m_ownerObject = this;
assert(!keyword.isEmpty());
assert(this->findField(keyword) == NULL);
field->setKeyword(keyword);
m_fields.push_back(field);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmFieldHandle* PdmObjectHandle::findField(const QString& keyword)
{
std::vector<PdmFieldHandle*> fields;
this->fields(fields);
for (size_t it = 0; it < fields.size(); it++)
{
PdmFieldHandle* field = fields[it];
if (field->keyword() == keyword)
{
return field;
}
}
return NULL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmFieldHandle* PdmObjectHandle::parentField() const
{
return m_parentField;
}
} // End namespace caf

View File

@ -0,0 +1,93 @@
#pragma once
#include "cafPdmBase.h"
class QString;
#include <vector>
#include <set>
namespace caf
{
class PdmObjectCapability;
class PdmFieldHandle;
//==================================================================================================
/// The base class of all objects
//==================================================================================================
class PdmObjectHandle
{
public:
PdmObjectHandle() { m_parentField = NULL; }
virtual ~PdmObjectHandle();
/// The registered fields contained in this PdmObject.
void fields(std::vector<PdmFieldHandle*>& fields) const;
PdmFieldHandle* findField(const QString& keyword);
/// The field referencing this object as a child
PdmFieldHandle* parentField() const;
// PtrReferences
/// The PdmPtrField's containing pointers to this PdmObjecthandle
/// Use ownerObject() on the fieldHandle to get the PdmObjectHandle
void referringPtrFields(std::vector<PdmFieldHandle*>& fieldsReferringToMe) const;
/// Convenience method to get the objects pointing to this field
void objectsWithReferringPtrFields(std::vector<PdmObjectHandle*>& objects) const;
// Object capabilities
void addCapability(PdmObjectCapability* capability, bool takeOwnership) { m_capabilities.push_back(std::make_pair(capability, takeOwnership)); }
template <typename CapabilityType>
CapabilityType* capability()
{
for (size_t i = 0; i < m_capabilities.size(); ++i)
{
CapabilityType* capability = dynamic_cast<CapabilityType*>(m_capabilities[i].first);
if (capability) return capability;
}
return NULL;
}
protected:
void addField(PdmFieldHandle* field, const QString& keyword);
private:
PDM_DISABLE_COPY_AND_ASSIGN(PdmObjectHandle);
// Fields
std::vector<PdmFieldHandle*> m_fields;
// Capabilities
std::vector<std::pair<PdmObjectCapability*, bool> > m_capabilities;
// Child/Parent Relationships
void setAsParentField(PdmFieldHandle* parentField);
void removeAsParentField(PdmFieldHandle* parentField);
PdmFieldHandle* m_parentField;
// PtrReferences
void addReferencingPtrField(PdmFieldHandle* fieldReferringToMe);
void removeReferencingPtrField(PdmFieldHandle* fieldReferringToMe);
std::multiset<PdmFieldHandle*> m_referencingPtrFields;
// Give access to set/removeAsParentField
template < class T > friend class PdmChildArrayField;
template < class T > friend class PdmChildField;
template < class T > friend class PdmPtrField;
template < class T > friend class PdmField; // For backwards compatibility layer
template < class T > friend class PdmFieldXmlCap;
static const char* classKeywordStatic() { return "PdmObjectHandle";} // For PdmXmlFieldCap to be able to handle fields of PdmObjectHandle directly
// Support system for PdmPointer
friend class PdmPointerImpl;
std::set<PdmObjectHandle**> m_pointersReferencingMe;
};
} // End of namespace caf

View File

@ -34,7 +34,7 @@
//
//##################################################################################################
#include "cafPdmObject.h"
#include "cafPdmObjectHandle.h"
#include "cafPdmPointer.h"
namespace caf
@ -44,7 +44,7 @@ namespace caf
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmPointerImpl::addReference(PdmObject ** addressToObjectPointer)
void PdmPointerImpl::addReference(PdmObjectHandle ** addressToObjectPointer)
{
if (*addressToObjectPointer) (*addressToObjectPointer)->m_pointersReferencingMe.insert(addressToObjectPointer);
}
@ -52,7 +52,7 @@ void PdmPointerImpl::addReference(PdmObject ** addressToObjectPointer)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmPointerImpl::removeReference(PdmObject ** addressToObjectPointer)
void PdmPointerImpl::removeReference(PdmObjectHandle ** addressToObjectPointer)
{
if (*addressToObjectPointer) (*addressToObjectPointer)->m_pointersReferencingMe.erase(addressToObjectPointer);
}

View File

@ -37,11 +37,13 @@
#pragma once
#include <cstddef>
namespace caf
{
class PdmObject;
class PdmObjectHandle;
//==================================================================================================
/// Helper class for the PdmPointer class
@ -58,8 +60,8 @@ class PdmPointerImpl
{
private:
template < class T > friend class PdmPointer;
static void addReference(PdmObject ** addressToObjectPointer);
static void removeReference(PdmObject ** addressToObjectPointer);
static void addReference(PdmObjectHandle ** addressToObjectPointer);
static void removeReference(PdmObjectHandle ** addressToObjectPointer);
};
//==================================================================================================
@ -74,7 +76,7 @@ private:
template < class T >
class PdmPointer
{
PdmObject* m_object;
PdmObjectHandle* m_object;
public :
inline PdmPointer () : m_object(NULL) { }
inline PdmPointer ( T * p ) : m_object(p) { PdmPointerImpl::addReference(&m_object); }
@ -82,18 +84,21 @@ public :
{ PdmPointerImpl::addReference(&m_object); }
inline ~PdmPointer () { PdmPointerImpl::removeReference(&m_object); }
T* p() const { return static_cast<T*>(const_cast<PdmObject*>(m_object)); }
T* p() const { return static_cast<T*>(const_cast<PdmObjectHandle*>(m_object)); }
bool isNull() const { return !m_object; }
bool notNull() const { return !isNull(); }
operator T* () const { return static_cast<T*>(const_cast<PdmObject*>(m_object)); }
T& operator* () const { return *static_cast<T*>(const_cast<PdmObject*>(m_object)); }
T* operator->() const { return static_cast<T*>(const_cast<PdmObject*>(m_object)); }
operator T* () const { return static_cast<T*>(const_cast<PdmObjectHandle*>(m_object)); }
T& operator* () const { return *static_cast<T*>(const_cast<PdmObjectHandle*>(m_object)); }
T* operator->() const { return static_cast<T*>(const_cast<PdmObjectHandle*>(m_object)); }
PdmPointer<T> & operator= ( const PdmPointer<T>& p ) { if (this != &p) PdmPointerImpl::removeReference(&m_object); m_object = p.m_object; PdmPointerImpl::addReference(&m_object); return *this; }
PdmPointer<T> & operator= ( T* p ) { if (m_object != p) PdmPointerImpl::removeReference(&m_object); m_object = p; PdmPointerImpl::addReference(&m_object); return *this; }
// Private methods used by PdmField<T*> and PdmPointersField<T*>. Do not use unless you mean it !
PdmObject* rawPtr() const { return m_object; }
void setRawPtr( PdmObject* p) { if (m_object != p) PdmPointerImpl::removeReference(&m_object); m_object = p; PdmPointerImpl::addReference(&m_object); }
PdmObjectHandle* rawPtr() const { return m_object; }
void setRawPtr( PdmObjectHandle* p) { if (m_object != p) PdmPointerImpl::removeReference(&m_object); m_object = p; PdmPointerImpl::addReference(&m_object); }
};
} // End of namespace caf

View File

@ -0,0 +1,137 @@
#pragma once
#include "cafPdmFieldHandle.h"
#include "cafPdmPointer.h"
#include "cafPdmValueField.h"
#include "cafInternalPdmValueFieldSpecializations.h"
#include <QVariant>
#include <assert.h>
namespace caf
{
//==================================================================================================
/// Field class encapsulating data access through object setter/getter with input and output of this
/// data to/from a QXmlStream
/// read/write-FieldData is supposed to be specialized for types needing specialization
//==================================================================================================
template<typename DataType >
class PdmProxyValueField : public PdmValueField
{
public:
typedef DataType FieldDataType;
PdmProxyValueField() { m_valueSetter = NULL; m_valueGetter = NULL; }
virtual ~PdmProxyValueField() { if (m_valueSetter) delete m_valueSetter; if (m_valueGetter) delete m_valueGetter; }
// Assignment
PdmProxyValueField& operator= (const DataType& newFieldValue) { setValue(newFieldValue); return *this; }
// Basic access
void setValue(const DataType& fieldValue) { if (m_valueSetter) m_valueSetter->setValue(fieldValue); }
DataType value() const { assert(m_valueGetter); return m_valueGetter->getValue(); }
// Implementation of PdmValueField interface
virtual QVariant toQVariant() const { DataType val = value(); return PdmValueFieldSpecialization<DataType>::convert(val); }
virtual void setFromQVariant(const QVariant& variant) { DataType val; PdmValueFieldSpecialization<DataType>::setFromVariant(variant, val); setValue(val); }
virtual bool isReadOnly() const { if (!m_valueSetter) { return true; } else { return false; } }
// Access operators
DataType operator()() const { return value(); }
DataType v() const { return value(); }
bool operator== (const DataType& otherValue) const { return value() == otherValue; }
private:
PDM_DISABLE_COPY_AND_ASSIGN(PdmProxyValueField);
// Proxy Field stuff to handle the method pointers
// The public registering methods must be written below the private classes
// For some reason. Forward declaration did some weirdness.
private:
class SetValueInterface
{
public:
virtual ~SetValueInterface() {}
virtual void setValue(const DataType& value) = 0;
};
template <typename ObjectType>
class SetterMethodCB : public SetValueInterface
{
public:
typedef void (ObjectType::*SetterMethodType)(const DataType& value);
SetterMethodCB(ObjectType* obj, SetterMethodType setterMethod)
{
m_setterMethod = setterMethod;
m_obj = obj;
}
void setValue(const DataType& value)
{
(m_obj->*m_setterMethod)(value);
}
private:
SetterMethodType m_setterMethod;
PdmPointer<ObjectType> m_obj;
};
class GetValueInterface
{
public:
virtual ~GetValueInterface() {}
virtual DataType getValue() const = 0;
};
template <typename ObjectType>
class GetterMethodCB : public GetValueInterface
{
public:
typedef DataType (ObjectType::*GetterMethodType)() const;
GetterMethodCB(ObjectType* obj, GetterMethodType setterMethod)
{
m_getterMethod = setterMethod;
m_obj = obj;
}
DataType getValue() const
{
return (m_obj->*m_getterMethod)();
}
private:
GetterMethodType m_getterMethod;
PdmPointer< ObjectType> m_obj;
};
public:
template <typename OwnerObjectType>
void registerSetMethod(OwnerObjectType* obj, typename SetterMethodCB< OwnerObjectType>::SetterMethodType setterMethod)
{
if (m_valueSetter) delete m_valueSetter;
m_valueSetter = new SetterMethodCB<OwnerObjectType>(obj, setterMethod);
}
template <typename OwnerObjectType>
void registerGetMethod(OwnerObjectType* obj, typename GetterMethodCB< OwnerObjectType>::GetterMethodType getterMethod)
{
if (m_valueGetter) delete m_valueGetter;
m_valueGetter = new GetterMethodCB<OwnerObjectType>(obj, getterMethod);
}
private:
SetValueInterface* m_valueSetter;
GetValueInterface* m_valueGetter;
};
} // End of namespace caf

View File

@ -0,0 +1,81 @@
#pragma once
#include "cafPdmPointer.h"
#include "cafPdmFieldHandle.h"
#include <assert.h>
namespace caf
{
template< typename T> class PdmFieldXmlCap;
//==================================================================================================
/// A field that contains a pointer to a PdmObjectHandle derived object.
/// The referenced object will not be printed in the XML-output yet, but
/// it is intended to be written as a reference (by path from common root)
/// This field has nothing to do with ownership at all, and is not a part of the
/// parent-child relations induced by the other PdmChildField<PdmPtrType*> PdmChildArrayField<PdmPtrType*>
/// The pointer is guarded, meaning that it will be set to NULL if the object pointed to
/// is deleted.
//==================================================================================================
template<typename DataType>
class PdmPtrField : public PdmFieldHandle
{
public:
PdmPtrField()
{
bool doNotUsePdmPtrFieldForAnythingButPointersToPdmObject = false; assert(doNotUsePdmPtrFieldForAnythingButPointersToPdmObject);
}
};
template<typename DataType >
class PdmPtrField <DataType*> : public PdmFieldHandle
{
typedef DataType* DataTypePtr;
public:
typedef PdmPointer<DataType> FieldDataType;
PdmPtrField() { }
explicit PdmPtrField(const DataTypePtr& fieldValue);
virtual ~PdmPtrField();
// Assignment
PdmPtrField& operator= (const DataTypePtr & fieldValue);
PdmPtrField& operator= (const FieldDataType & fieldValue);
// Basic access
DataType* value() const { return m_fieldValue; }
void setValue(const DataTypePtr& fieldValue);
// Access operators
/*Conversion*/ operator DataType* () const { return m_fieldValue; }
DataType* operator->() const { return m_fieldValue; }
const PdmPointer<DataType>& operator()() const { return m_fieldValue; }
const PdmPointer<DataType>& v() const { return m_fieldValue; }
bool operator==(const DataTypePtr& fieldValue) { return m_fieldValue == fieldValue; }
// Ptr referenced objects
virtual void ptrReferencedObjects(std::vector<PdmObjectHandle*>* objectsToFill);
private:
PDM_DISABLE_COPY_AND_ASSIGN(PdmPtrField);
friend class PdmFieldXmlCap< PdmPtrField <DataType*> >;
void setRawPtr(PdmObjectHandle* obj);
PdmPointer<DataType> m_fieldValue;
};
} // End of namespace caf
#include "cafPdmPtrField.inl"
#include <QMetaType>
Q_DECLARE_METATYPE(caf::PdmPointer<caf::PdmObjectHandle>);

View File

@ -0,0 +1,88 @@
namespace caf
{
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
caf::PdmPtrField<DataType*>::PdmPtrField(const DataTypePtr& fieldValue)
{
m_fieldValue = fieldValue;
if (m_fieldValue != NULL) m_fieldValue->addReferencingPtrField(this);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
caf::PdmPtrField<DataType*>::~PdmPtrField()
{
if (!m_fieldValue.isNull()) m_fieldValue.rawPtr()->removeReferencingPtrField(this);
m_fieldValue.setRawPtr(NULL);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
void PdmPtrField<DataType*>::setValue(const DataTypePtr& fieldValue)
{
if (m_fieldValue) m_fieldValue->removeReferencingPtrField(this);
m_fieldValue = fieldValue;
if (m_fieldValue != NULL) m_fieldValue->addReferencingPtrField(this);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
void PdmPtrField<DataType*>::setRawPtr(PdmObjectHandle* obj)
{
if (m_fieldValue.notNull()) m_fieldValue.rawPtr()->removeReferencingPtrField(this);
m_fieldValue.setRawPtr(obj);
if (m_fieldValue.notNull()) m_fieldValue.rawPtr()->addReferencingPtrField(this);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
caf::PdmPtrField<DataType*>& PdmPtrField<DataType*>::operator=(const DataTypePtr & fieldValue)
{
if (m_fieldValue) m_fieldValue->removeReferencingPtrField(this);
m_fieldValue = fieldValue;
if (m_fieldValue != NULL) m_fieldValue->addReferencingPtrField(this);
return *this;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
caf::PdmPtrField<DataType*>& PdmPtrField<DataType*>::operator=(const FieldDataType & fieldValue)
{
if (m_fieldValue) m_fieldValue->removeReferencingPtrField(this);
m_fieldValue = fieldValue;
if (m_fieldValue != NULL) m_fieldValue->addReferencingPtrField(this);
return *this;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
void PdmPtrField<DataType*>::ptrReferencedObjects(std::vector<PdmObjectHandle*>* objectsToFill)
{
if (m_fieldValue.rawPtr())
{
objectsToFill->push_back(m_fieldValue.rawPtr());
}
}
} // End of namespace caf

View File

@ -0,0 +1,354 @@
//##################################################################################################
//
// 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 "cafPdmReferenceHelper.h"
#include "cafPdmFieldHandle.h"
#include <QStringList>
#include <assert.h>
#include <algorithm>
namespace caf
{
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString PdmReferenceHelper::referenceFromRootToObject(PdmObjectHandle* root, PdmObjectHandle* obj)
{
QStringList objectNames = referenceFromRootToObjectAsStringList(root, obj);
QString completeReference = objectNames.join(" ");
return completeReference;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString PdmReferenceHelper::referenceFromRootToField(PdmObjectHandle* root, PdmFieldHandle* field)
{
if (field == NULL || root == NULL) return QString();
PdmObjectHandle* owner = field->ownerObject();
if (!owner) return QString(); // Should be assert ?
QStringList refFromRootToField;
refFromRootToField = referenceFromRootToObjectAsStringList(root, owner);
refFromRootToField.push_front(field->keyword());
QString completeReference = refFromRootToField.join(" ");
return completeReference;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmObjectHandle* PdmReferenceHelper::objectFromReference(PdmObjectHandle* root, const QString& reference)
{
QStringList decodedReference = reference.split(" ");
return objectFromReferenceStringList(root, decodedReference);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmFieldHandle* PdmReferenceHelper::findField(PdmObjectHandle* object, const QString& fieldKeyword)
{
if (object == NULL) return NULL;
std::vector<PdmFieldHandle*> fields;
object->fields(fields);
for (size_t i = 0; i < fields.size(); i++)
{
if (fields[i]->keyword() == fieldKeyword)
{
return fields[i];
}
}
return NULL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QStringList PdmReferenceHelper::referenceFromRootToObjectAsStringList(PdmObjectHandle* root, PdmObjectHandle* obj)
{
QStringList objectNames;
if (obj != NULL && root)
{
if (obj == root) return objectNames;
PdmObjectHandle* currentObject = obj;
bool continueParsing = true;
while (continueParsing)
{
caf::PdmFieldHandle* parentField = currentObject->parentField();
assert(parentField);
std::vector<PdmObjectHandle*> childObjects;
parentField->childObjects(&childObjects);
if (childObjects.size() > 0)
{
int index = -1;
for (size_t i = 0; i < childObjects.size(); i++)
{
if (childObjects[i] == currentObject)
{
index = static_cast<int>(i);
}
}
objectNames.push_front(QString::number(index));
objectNames.push_front(parentField->keyword());
}
else
{
continueParsing = false;
continue;
}
PdmObjectHandle* ownerObject = parentField->ownerObject();
assert(ownerObject);
if (ownerObject == root)
{
continueParsing = false;
continue;
}
currentObject = ownerObject;
}
}
return objectNames;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmFieldHandle* PdmReferenceHelper::fieldFromReference(PdmObjectHandle* root, const QString& reference)
{
QStringList decodedReference = reference.split(" ");
QString fieldKeyword = decodedReference[0];
decodedReference.pop_front();
PdmObjectHandle* parentObject = objectFromReferenceStringList(root, decodedReference);
return findField(parentObject, fieldKeyword);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmObjectHandle* PdmReferenceHelper::objectFromReferenceStringList(PdmObjectHandle* root, const QStringList& reference)
{
PdmObjectHandle* currentObject = root;
int i = 0;
while (i < reference.size())
{
QString fieldKeyword = reference.at(i++);
PdmFieldHandle* field = findField(currentObject, fieldKeyword);
if (field)
{
std::vector<PdmObjectHandle*> childObjects;
field->childObjects(&childObjects);
if (childObjects.size() > 0)
{
QString fieldIndex = reference.at(i++);
bool conversionOk = true;
int index = fieldIndex.toInt(&conversionOk);
if (!conversionOk)
{
index = -1;
}
if (index > -1)
{
PdmObjectHandle* listObject = childObjects[index];
currentObject = listObject;
}
else
{
return NULL;
}
}
else
{
return NULL;
}
}
}
return currentObject;
}
std::vector<PdmObjectHandle*> findPathToObjectFromRoot(PdmObjectHandle* obj)
{
std::vector<PdmObjectHandle*> objPath;
PdmObjectHandle* currentObj = obj;
while (currentObj)
{
objPath.push_back(currentObj);
if (currentObj->parentField())
{
currentObj = currentObj->parentField()->ownerObject();
}
else
{
currentObj = NULL;
}
}
std::reverse(objPath.begin(), objPath.end());
return objPath;
}
QString PdmReferenceHelper::referenceFromFieldToObject(PdmFieldHandle* fromField, PdmObjectHandle* toObj)
{
assert(fromField);
if (toObj == NULL) return "";
PdmObjectHandle* fromObj = fromField->ownerObject();
std::vector<PdmObjectHandle*> fromObjPath = findPathToObjectFromRoot(fromObj);
std::vector<PdmObjectHandle*> toObjPath = findPathToObjectFromRoot(toObj);
// Make sure the objects actually have at least one common ancestor
assert(fromObjPath.front() == toObjPath.front());
bool anchestorIsEqual = true;
size_t idxToLastCommonAnchestor = 0;
while (anchestorIsEqual)
{
++idxToLastCommonAnchestor;
if ( idxToLastCommonAnchestor >= fromObjPath.size()
|| idxToLastCommonAnchestor >= toObjPath.size()
|| fromObjPath[idxToLastCommonAnchestor] != toObjPath[idxToLastCommonAnchestor])
{
anchestorIsEqual = false;
idxToLastCommonAnchestor -= 1;
}
}
size_t levelCountToCommonAnchestor = (fromObjPath.size() - 1) - idxToLastCommonAnchestor;
PdmObjectHandle* lastCommonAnchestor = fromObjPath[idxToLastCommonAnchestor];
QStringList referenceList = referenceFromRootToObjectAsStringList(lastCommonAnchestor, toObj);
for (size_t i = 0; i < levelCountToCommonAnchestor; ++i)
{
referenceList.push_front("..");
}
QString completeReference = referenceList.join(" ");
return completeReference;
}
PdmObjectHandle* PdmReferenceHelper::objectFromFieldReference(PdmFieldHandle* fromField, const QString& reference)
{
if (reference.isEmpty()) return NULL;
assert(fromField);
QStringList decodedReference = reference.split(" ");
PdmObjectHandle* lastCommonAnchestor = fromField->ownerObject();
assert(lastCommonAnchestor);
assert(decodedReference.size());
while (decodedReference.front() == "..")
{
PdmFieldHandle* parentField = lastCommonAnchestor->parentField();
if (!parentField)
{
// Error: Relative object reference has an invalid number of parent levels
return NULL;
}
lastCommonAnchestor = parentField->ownerObject();
assert(lastCommonAnchestor);
decodedReference.pop_front();
}
return objectFromReferenceStringList(lastCommonAnchestor, decodedReference);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmObjectHandle* PdmReferenceHelper::findRoot(PdmObjectHandle* obj)
{
std::vector<PdmObjectHandle*> path = findPathToObjectFromRoot(obj);
if (path.size()) return path[0];
else return NULL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmObjectHandle* PdmReferenceHelper::findRoot(PdmFieldHandle* field)
{
if (field)
{
PdmObjectHandle* ownerObject = field->ownerObject();
return findRoot(ownerObject);
}
return NULL;
}
} // end namespace caf

View File

@ -0,0 +1,75 @@
//##################################################################################################
//
// 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 "cafPdmObjectHandle.h"
#include "cafPdmPointer.h"
class QStringList;
namespace caf
{
//==================================================================================================
///
//==================================================================================================
class PdmReferenceHelper
{
public:
static PdmObjectHandle* findRoot(PdmObjectHandle* obj);
static PdmObjectHandle* findRoot(PdmFieldHandle* field);
static QString referenceFromRootToField(PdmObjectHandle* root, PdmFieldHandle* field);
static QString referenceFromRootToObject(PdmObjectHandle* root, PdmObjectHandle* obj);
static PdmObjectHandle* objectFromReference(PdmObjectHandle* root, const QString& reference);
static PdmFieldHandle* fieldFromReference(PdmObjectHandle* root, const QString& reference);
static QString referenceFromFieldToObject(PdmFieldHandle* fromField, PdmObjectHandle* toObj);
static PdmObjectHandle* objectFromFieldReference(PdmFieldHandle* fromField, const QString& reference);
private:
static QStringList referenceFromRootToObjectAsStringList(PdmObjectHandle* root, PdmObjectHandle* obj);
static PdmObjectHandle* objectFromReferenceStringList(PdmObjectHandle* root, const QStringList& reference);
static PdmFieldHandle* findField(PdmObjectHandle* object, const QString& fieldKeyword);
};
} // end namespace caf

View File

@ -0,0 +1,66 @@
//##################################################################################################
//
// 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 "cafPdmFieldHandle.h"
class QVariant;
namespace caf
{
class PdmValueField : public PdmFieldHandle
{
public:
virtual QVariant toQVariant() const = 0;
virtual void setFromQVariant(const QVariant& variant) = 0;
virtual bool isReadOnly() const = 0;
};
// class PdmProxyValueField : public PdmValueField
// {
// DataType value() const { assert(m_valueGetter); return m_valueGetter->getValue(); }
// void setValue(const DataType& fieldValue) { if (m_valueSetter) m_valueSetter->setValue(fieldValue); }
// }
} // End of namespace caf

View File

@ -38,69 +38,20 @@
#include "cafPdmDocument.h"
#include <QFile>
#include <QXmlStreamReader>
namespace caf
{
CAF_PDM_SOURCE_INIT(PdmObjectGroup, "PdmObjectGroup");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmObjectGroup::PdmObjectGroup()
{
CAF_PDM_InitObject("Object Group", "", "", "");
CAF_PDM_InitFieldNoDefault(&objects, "PdmObjects","", "", "", "")
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmObjectGroup::~PdmObjectGroup()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmObjectGroup::deleteObjects()
{
size_t it;
for (it = 0; it != objects.size(); ++it)
{
delete objects[it];
}
removeNullPtrs();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmObjectGroup::removeNullPtrs()
{
objects.removeChildObject(NULL);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmObjectGroup::addObject(PdmObject * obj)
{
objects.push_back(obj);
}
CAF_PDM_SOURCE_INIT(PdmDocument, "PdmDocument");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmDocument::PdmDocument()
PdmDocument::PdmDocument()
{
CAF_PDM_InitObject("File", "", "", "");
CAF_PDM_InitField(&fileName, "DocumentFileName", QString(""), "File Name", "", "", "");
CAF_PDM_InitFieldNoDefault(&fileName, "DocumentFileName", "File Name", "", "", "");
}
//--------------------------------------------------------------------------------------------------
@ -133,7 +84,7 @@ void PdmDocument::readFile(QIODevice* xmlFile)
// Error: This is not a Ceetron Pdm based xml document
return;
}
readFields(xmlStream);
readFields(xmlStream, PdmDefaultObjectFactory::instance());
}
}
@ -141,7 +92,6 @@ void PdmDocument::readFile(QIODevice* xmlFile)
// after everything is read from file
PdmDocument::initAfterReadTraversal(this);
PdmDocument::updateUiIconStateRecursively(this);
}
//--------------------------------------------------------------------------------------------------
@ -177,17 +127,15 @@ void PdmDocument::writeFile(QIODevice* xmlFile)
xmlStream.writeEndDocument();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmDocument::setupBeforeSaveTraversal(PdmObject * object)
void PdmDocument::setupBeforeSaveTraversal(PdmObjectHandle * object)
{
if (object == NULL) return;
std::vector<PdmFieldHandle*> fields;
object->fields(fields);
std::vector<PdmObject*> children;
std::vector<PdmObjectHandle*> children;
size_t fIdx;
for (fIdx = 0; fIdx < fields.size(); ++fIdx)
{
@ -200,20 +148,24 @@ void PdmDocument::setupBeforeSaveTraversal(PdmObject * object)
PdmDocument::setupBeforeSaveTraversal(children[cIdx]);
}
object->setupBeforeSave();
PdmXmlObjectHandle* xmlObject = xmlObj(object);
if (xmlObject)
{
xmlObject->setupBeforeSave();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmDocument::initAfterReadTraversal(PdmObject* object)
void PdmDocument::initAfterReadTraversal(PdmObjectHandle* object)
{
if (object == NULL) return;
std::vector<PdmFieldHandle*> fields;
object->fields(fields);
std::vector<PdmObject*> children;
std::vector<PdmObjectHandle*> children;
size_t fIdx;
for (fIdx = 0; fIdx < fields.size(); ++fIdx)
{
@ -226,20 +178,24 @@ void PdmDocument::initAfterReadTraversal(PdmObject* object)
PdmDocument::initAfterReadTraversal(children[cIdx]);
}
object->initAfterRead();
PdmXmlObjectHandle* xmlObject = xmlObj(object);
if (xmlObject)
{
xmlObject->initAfterRead();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmDocument::updateUiIconStateRecursively(PdmObject* object)
void PdmDocument::updateUiIconStateRecursively(PdmObjectHandle* object)
{
if (object == NULL) return;
std::vector<PdmFieldHandle*> fields;
object->fields(fields);
std::vector<PdmObject*> children;
std::vector<PdmObjectHandle*> children;
size_t fIdx;
for (fIdx = 0; fIdx < fields.size(); ++fIdx)
{
@ -252,8 +208,13 @@ void PdmDocument::updateUiIconStateRecursively(PdmObject* object)
PdmDocument::updateUiIconStateRecursively(children[cIdx]);
}
object->updateUiIconFromToggleField();
PdmUiObjectHandle* uiObjectHandle = uiObj(object);
if (uiObjectHandle)
{
uiObjectHandle->updateUiIconFromToggleField();
}
}
} //End of namespace caf

View File

@ -39,45 +39,11 @@
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "cafPdmPointer.h"
#include "cafPdmObjectGroup.h"
namespace caf
{
//==================================================================================================
/// The PdmObjectGroup serves as a container of unknown PdmObjects, and is inherited by
/// PdmDocument. Can be used to create sub assemblies.
/// This class should possibly be merged with PdmDocument. It is not clear whether it really has
/// a reusable value on its own.
//==================================================================================================
class PdmObjectGroup : public PdmObject
{
CAF_PDM_HEADER_INIT;
public:
PdmObjectGroup();
~PdmObjectGroup();
PdmPointersField<PdmObject*> objects;
void deleteObjects();
void removeNullPtrs();
void addObject(PdmObject * obj);
template <typename T>
void objectsByType(std::vector<PdmPointer<T> >* typedObjects ) const
{
if (!typedObjects) return;
size_t it;
for (it = 0; it != objects.size(); ++it)
{
T* obj = dynamic_cast<T*>(objects[it]);
if (obj) typedObjects->push_back(obj);
}
}
template <typename T>
void createCopyByType(std::vector<PdmPointer<T> >* copyOfTypedObjects) const;
};
//==================================================================================================
/// The PdmDocument class is the main class to do file based IO,
/// and is also supposed to act as the overall container of the objects read.
@ -96,52 +62,13 @@ class PdmDocument: public PdmObjectGroup
void readFile(QIODevice* device);
void writeFile(QIODevice* device);
static void updateUiIconStateRecursively(PdmObject * root);
static void initAfterReadTraversal(PdmObject * root);
static void setupBeforeSaveTraversal(PdmObject * root);
private:
static void updateUiIconStateRecursively(PdmObjectHandle* root);
static void initAfterReadTraversal(PdmObjectHandle* root);
static void setupBeforeSaveTraversal(PdmObjectHandle * root);
};
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template <typename T>
void PdmObjectGroup::createCopyByType(std::vector<PdmPointer<T> >* copyOfTypedObjects) const
{
std::vector<PdmPointer<T> > sourceTypedObjects;
objectsByType(&sourceTypedObjects);
QString encodedXml;
{
// Write original objects to XML file
PdmObjectGroup typedObjectGroup;
for (size_t i = 0; i < sourceTypedObjects.size(); i++)
{
typedObjectGroup.addObject(sourceTypedObjects[i]);
PdmDocument::setupBeforeSaveTraversal(sourceTypedObjects[i]);
}
QXmlStreamWriter xmlStream(&encodedXml);
xmlStream.setAutoFormatting(true);
typedObjectGroup.writeFields(xmlStream);
}
// Read back XML into object group, factory methods will be called that will create new objects
PdmObjectGroup destinationObjectGroup;
QXmlStreamReader xmlStream(encodedXml);
destinationObjectGroup.readFields(xmlStream);
for (size_t it = 0; it < destinationObjectGroup.objects.size(); it++)
{
T* obj = dynamic_cast<T*>(destinationObjectGroup.objects[it]);
if (obj) copyOfTypedObjects->push_back(obj);
}
}
} // End of namespace caf

View File

@ -1,267 +1,23 @@
//##################################################################################################
//
// 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
#define CAF_IS_DEFINING_PDM_FIELD
#define PdmDataValueField PdmField
#include "cafPdmDataValueField.h"
#undef PdmDataValueField
#undef CAF_IS_DEFINING_PDM_FIELD
#pragma once
#include "cafPdmUiItem.h"
#include "cafPdmFieldImpl.h"
#include <set>
#include <assert.h>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include <QTextStream>
namespace caf
namespace caf
{
class PdmObject;
template <class T> class PdmPointer;
class PdmUiFieldEditorHandle;
// Specialization to create compiler errors to help finding the PdmField's to rename
//==================================================================================================
/// Base class for all fields, making it possible to handle them generically
//==================================================================================================
#ifdef WIN32
class PdmFieldHandle : public PdmUiItem
{
public:
PdmFieldHandle() : m_isIOReadable(true), m_isIOWritable(true) { m_ownerObject = NULL; m_keyword = "UNDEFINED"; }
virtual ~PdmFieldHandle() { }
template<typename DataType >
class PdmField <DataType*> : public Rename_PdmField_of_pointer_to_PdmChildField // You must rename PdmField<T*> to PdmChildField<T*>
{
};
virtual void resetToDefaultValue() { };
#endif
virtual void readFieldData(QXmlStreamReader& xmlStream) = 0;
virtual void writeFieldData(QXmlStreamWriter& xmlStream) = 0;
bool isIOReadable() { return m_isIOReadable; }
bool isIOWritable() { return m_isIOWritable; }
void setIOWritable(bool isWritable) { m_isIOWritable = isWritable; }
void setIOReadable(bool isReadable) { m_isIOReadable = isReadable; }
void setKeyword(const QString& keyword);
QString keyword() const { return m_keyword; }
void setOwnerObject(PdmObject * owner) { m_ownerObject = owner; }
PdmObject* ownerObject() { return m_ownerObject; }
// Generalized access methods for User interface
// The QVariant encapsulates the real value, or an index into the valueOptions
//
virtual QVariant uiValue() const { return QVariant(); }
virtual void setValueFromUi(const QVariant& ) { }
virtual bool hasChildObjects();
virtual void childObjects(std::vector<PdmObject*>* ) { }
virtual void removeChildObject(PdmObject* ) { }
virtual QList<PdmOptionItemInfo>
valueOptions( bool* useOptionsOnly) { return QList<PdmOptionItemInfo>(); }
protected:
bool assertValid() const;
protected:
PdmObject* m_ownerObject;
private:
QString m_keyword;
bool m_isIOReadable;
bool m_isIOWritable;
};
//==================================================================================================
/// Field class encapsulating data with input and output of this data to/from a QXmlStream
/// read/write-FieldData is supposed to be specialized for types needing specialization
//==================================================================================================
template <typename T> struct PdmFieldWriter;
template <typename T> struct PdmFieldReader;
template<typename DataType >
class PdmField : public PdmFieldHandle
{
public:
PdmField() {}
virtual ~PdmField() {}
// Copy and assignment must ignore the default value.
PdmField(const PdmField& other) : PdmFieldHandle() { assertValid(); m_fieldValue = other.m_fieldValue; }
PdmField(const DataType& fieldValue) : PdmFieldHandle() { assertValid(); m_fieldValue = fieldValue; }
PdmField& operator= (const PdmField& other) { assertValid(); m_fieldValue = other.m_fieldValue; return *this; }
PdmField& operator= (const DataType& fieldValue) { assertValid(); m_fieldValue = fieldValue; return *this; }
operator DataType () const { return m_fieldValue; }
// DataType& operator()() { assertValid(); return m_fieldValue; }
const DataType& operator()() const { return m_fieldValue; }
DataType& v() { assertValid(); return m_fieldValue; }
const DataType& v() const { return m_fieldValue; }
bool operator== (const DataType& fieldValue) const { return m_fieldValue == fieldValue; }
// readFieldData assumes that the xmlStream points to first token of field content.
// After reading, the xmlStream is supposed to point to the first token after the field content.
// (typically an "endElement")
virtual void readFieldData(QXmlStreamReader& xmlStream) { PdmFieldReader<DataType>::readFieldData(*this, xmlStream); }
virtual void writeFieldData(QXmlStreamWriter& xmlStream) { PdmFieldWriter<DataType>::writeFieldData(*this, xmlStream);}
const DataType& defaultValue() const { return m_defaultFieldValue; }
void setDefaultValue(const DataType& val) { m_defaultFieldValue = val; }
virtual void resetToDefaultValue() { m_fieldValue = m_defaultFieldValue; }
// Gui generalized interface
virtual QVariant uiValue() const;
virtual void setValueFromUi(const QVariant& uiValue);
virtual QList<PdmOptionItemInfo> valueOptions( bool* useOptionsOnly);
virtual void childObjects(std::vector<PdmObject*>* objects) { PdmFieldTypeSpecialization<DataType>::childObjects(*this, objects); }
protected:
DataType m_fieldValue;
DataType m_defaultFieldValue;
QList<PdmOptionItemInfo> m_optionEntryCache;
};
//==================================================================================================
/// Specialization for pointers, but only applicable to PdmObject derived objects.
/// The pointer is guarded, meaning that it will be set to NULL if the object pointed to
/// is deleted. The referenced object will be printed in place in the xml-file
//==================================================================================================
template<typename DataType >
class PdmField <DataType*> : public PdmFieldHandle
{
typedef DataType* DataTypePtr;
public:
PdmField() : PdmFieldHandle() { }
PdmField(const PdmField& other);
PdmField(const DataTypePtr& fieldValue);
virtual ~PdmField();
PdmField& operator= (const PdmField& other);
PdmField& operator= (const DataTypePtr & fieldValue);
operator DataType* () const { return m_fieldValue; }
DataType* operator->() const { return m_fieldValue; }
const PdmPointer<DataType>& operator()() const { return m_fieldValue; }
const PdmPointer<DataType>& v() const { return m_fieldValue; }
bool operator==(const DataTypePtr& fieldValue) { return m_fieldValue == fieldValue; }
// readFieldData assumes that the xmlStream points to first token of field content.
// After reading, the xmlStream is supposed to point to the first token after the field content.
// (typically an "endElement")
virtual void readFieldData(QXmlStreamReader& xmlStream);
virtual void writeFieldData(QXmlStreamWriter& xmlStream);
const DataTypePtr& defaultValue() const { return NULL; }
void setDefaultValue(const DataTypePtr& ) { }
// Gui generalized methods
virtual QVariant uiValue() const { return QVariant();}
virtual void childObjects(std::vector<PdmObject*>* objects);
protected:
PdmPointer<DataType> m_fieldValue;
};
//==================================================================================================
/// PdmFieldClass to handle a collection of PdmObject derived pointers
/// The reasons for this class is to add itself as parentField into the objects being pointed to.
/// The interface is made similar to std::vector<>, and the complexity of the methods is similar too.
//==================================================================================================
template<typename DataType>
class PdmPointersField : public PdmFieldHandle
{
public:
PdmPointersField()
{ bool doNotUsePdmPointersFieldForAnythingButPointersToPdmObject = false; assert(doNotUsePdmPointersFieldForAnythingButPointersToPdmObject); }
};
template<typename DataType>
class PdmPointersField<DataType*> : public PdmFieldHandle
{
typedef DataType* DataTypePtr;
public:
PdmPointersField() { }
PdmPointersField(const PdmPointersField& other);
virtual ~PdmPointersField();
PdmPointersField& operator= (const PdmPointersField& other);
bool operator==(const PdmPointersField& other) { return m_pointers == other.m_pointers; }
PdmPointersField& operator() () { return *this; }
size_t size() const { return m_pointers.size(); }
bool empty() const { return m_pointers.empty(); }
DataType* operator[] (size_t index) const;
void push_back(DataType* pointer);
void set(size_t index, DataType* pointer);
void insert(size_t indexAfter, DataType* pointer);
void insert(size_t indexAfter, const std::vector<PdmPointer<DataType> >& objects);
size_t count(const DataType* pointer) const;
void clear();
void erase(size_t index);
void deleteAllChildObjects();
// Reimplementation of PdmFieldhandle methods
virtual void readFieldData(QXmlStreamReader& xmlStream);
virtual void writeFieldData(QXmlStreamWriter& xmlStream);
// Gui generalized methods
virtual void childObjects(std::vector<PdmObject*>* objects);
virtual void removeChildObject(PdmObject* object);
private:
void removeThisAsParentField();
void addThisAsParentField();
private:
std::vector< PdmPointer<DataType> > m_pointers;
};
} // End of namespace caf
#include "cafPdmField.inl"
}

View File

@ -1,746 +0,0 @@
//##################################################################################################
//
// 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 "cafPdmObject.h"
#include <vector>
#include <iostream>
#include "cafPdmUiFieldEditorHandle.h"
namespace caf
{
//==================================================================================================
/// Implementation of PdmField<T> methods
//==================================================================================================
//--------------------------------------------------------------------------------------------------
/// This method is supposed to be the interface for the implementation of UI editors to set values into
/// the field. The data to set must be encapsulated in a QVariant.
/// This method triggers PdmObject::fieldChangedByUi() and PdmObject::updateConnectedEditors(), an thus
/// makes the application and the UI aware of the change.
///
/// Note : If the field has optionValues the interface is _index-based_. The QVariant must contain
/// an UInt representing the index to the option selected by the user interface.
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
void caf::PdmField<DataType>::setValueFromUi(const QVariant& uiValue)
{
QVariant oldValue = PdmFieldTypeSpecialization<DataType>::convert(m_fieldValue);
// Check whether we are handling selections of values or actual values
if (m_optionEntryCache.size())
{
// This has an option based GUI, the uiValue is only indexes into the m_optionEntryCache
if (uiValue.type() == QVariant::UInt)
{
assert(uiValue.toUInt() < static_cast<unsigned int>(m_optionEntryCache.size()));
PdmFieldTypeSpecialization<DataType>::setFromVariant(m_optionEntryCache[uiValue.toUInt()].value, m_fieldValue);
}
else if (uiValue.type() == QVariant::List)
{
QList<QVariant> selectedIndexes = uiValue.toList();
QList<QVariant> valuesToSetInField;
if (selectedIndexes.isEmpty())
{
PdmFieldTypeSpecialization<DataType>::setFromVariant(valuesToSetInField, m_fieldValue);
}
else
{
if (selectedIndexes.front().type() == QVariant::UInt)
{
for (int i = 0; i < selectedIndexes.size(); ++i)
{
unsigned int opIdx = selectedIndexes[i].toUInt();
if (opIdx < static_cast<unsigned int>(m_optionEntryCache.size()))
{
valuesToSetInField.push_back(m_optionEntryCache[opIdx].value);
}
}
PdmFieldTypeSpecialization<DataType>::setFromVariant(valuesToSetInField, m_fieldValue);
}
else
{
// We are not getting indexes as expected from the UI. For now assert, to catch this condition
// but it should possibly be handled as setting the values explicitly. The code for that is below the assert
assert(false);
PdmFieldTypeSpecialization<DataType>::setFromVariant(uiValue, m_fieldValue);
m_optionEntryCache.clear();
}
}
}
else
{
// We are not getting indexes as expected from the UI. For now assert, to catch this condition
// but it should possibly be handled as setting the values explicitly. The code for that is below the assert
assert(false);
PdmFieldTypeSpecialization<DataType>::setFromVariant(uiValue, m_fieldValue);
m_optionEntryCache.clear();
}
}
else
{ // Not an option based GUI, the uiValue is a real field value
PdmFieldTypeSpecialization<DataType>::setFromVariant(uiValue, m_fieldValue);
}
QVariant newValue = PdmFieldTypeSpecialization<DataType>::convert(m_fieldValue);
// Call changed methods if field value has changed
if (newValue != oldValue)
{
assert(m_ownerObject != NULL);
m_ownerObject->fieldChangedByUi(this, oldValue, newValue);
// This assumes that all field editors are updated by an instance of PdmUiObjectEditorHandle
m_ownerObject->updateConnectedEditors();
}
}
//--------------------------------------------------------------------------------------------------
/// Returns the option values that is to be displayed in the UI for this field.
/// This method calls the virtual PdmObject::calculateValueOptions to get the list provided from the
/// application, then possibly adds the current field value(s) to the list, to
/// make sure the actual values are shown
///
/// Note: This method is missing the uiConfigName concept. This is a Todo. The m_optionEntryCache
/// then needs to be stored pr. uiConfigName.
//--------------------------------------------------------------------------------------------------
template<typename DataType >
QList<PdmOptionItemInfo> caf::PdmField<DataType>::valueOptions(bool* useOptionsOnly)
{
// First check if the owner PdmObject has a value options specification.
// if it has, use it.
if (m_ownerObject)
{
m_optionEntryCache = m_ownerObject->calculateValueOptions(this, useOptionsOnly);
if (m_optionEntryCache.size())
{
// Make sure the options contain the field values, event though they not necessarily
// is supplied as possible options by the application. This is a convenience making sure
// the actual data in the pdmObject is shown correctly in the UI, and to prevent accidental
// changes of the field values
// Find the field value(s) in the list if present
QVariant convertedFieldValue = PdmFieldTypeSpecialization<DataType>::convert(m_fieldValue);
std::vector<unsigned int> foundIndexes;
bool foundAllFieldValues = PdmOptionItemInfo::findValues(m_optionEntryCache, convertedFieldValue, foundIndexes);
// If not all are found, we have to add the missing to the list, to be able to show it
if (!foundAllFieldValues)
{
if (convertedFieldValue.type() != QVariant::List) // Single value field
{
if (!convertedFieldValue.toString().isEmpty())
{
m_optionEntryCache.push_front(PdmOptionItemInfo(convertedFieldValue.toString(), convertedFieldValue, true, QIcon()));
}
}
else // The field value is a list of values
{
QList<QVariant> valuesSelectedInField = convertedFieldValue.toList();
for (int i= 0 ; i < valuesSelectedInField.size(); ++i)
{
bool isFound = false;
for (unsigned int opIdx = 0; opIdx < static_cast<unsigned int>(m_optionEntryCache.size()); ++opIdx)
{
if (valuesSelectedInField[i] == m_optionEntryCache[opIdx].value) isFound = true;
}
if (!isFound && !valuesSelectedInField[i].toString().isEmpty())
{
m_optionEntryCache.push_front(PdmOptionItemInfo(valuesSelectedInField[i].toString(), valuesSelectedInField[i], true, QIcon()));
}
}
}
}
return m_optionEntryCache;
}
}
// If we have no options, use the options defined by the type. Normally only caf::AppEnum type
#if 0
m_optionEntryCache = PdmFieldTypeSpecialization<DataType>::valueOptions(useOptionsOnly, m_fieldValue);
return m_optionEntryCache;
#else
return PdmFieldTypeSpecialization<DataType>::valueOptions(useOptionsOnly, m_fieldValue);
#endif
}
//--------------------------------------------------------------------------------------------------
/// Extracts a QVariant representation of the data in the field to be used in the UI.
///
/// Note : For fields with a none-empty valueOptions list, the returned QVariant contains the
/// _indexes_ to the selected options rather than the actual values, if they can be found.
///
/// If this is a multivalue field, and we cant find all of the field values among the options,
/// the method asserts (For now), forcing the valueOptions to always contain the field values.
/// Single value fields will return -1 if the option is not found, allowing the concept of "nothing selected"
//--------------------------------------------------------------------------------------------------
template<typename DataType >
QVariant caf::PdmField<DataType>::uiValue() const
{
if (m_optionEntryCache.size())
{
QVariant convertedFieldValue = PdmFieldTypeSpecialization<DataType>::convert(m_fieldValue);
std::vector<unsigned int> indexesToFoundOptions;
PdmOptionItemInfo::findValues(m_optionEntryCache, convertedFieldValue, indexesToFoundOptions);
if (convertedFieldValue.type() == QVariant::List)
{
if (indexesToFoundOptions.size() == static_cast<size_t>(convertedFieldValue.toList().size()))
{
QList<QVariant> returnList;
for(size_t i = 0; i < indexesToFoundOptions.size(); ++i)
{
returnList.push_back(QVariant(indexesToFoundOptions[i]));
}
return QVariant(returnList);
}
assert(false); // Did not find all the field values among the options available.
}
else
{
if (indexesToFoundOptions.size() == 1) return QVariant(indexesToFoundOptions.front());
else return QVariant(-1); // Return -1 if not found instead of assert. Should result in clearing the selection
}
assert(false);
return convertedFieldValue;
}
else
{
return PdmFieldTypeSpecialization<DataType>::convert(m_fieldValue);
}
}
//==================================================================================================
/// Implementation of PdmField<T*> methods
/// (Partial specialization for pointers)
//==================================================================================================
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
void caf::PdmField<DataType*>::readFieldData(QXmlStreamReader& xmlStream)
{
PdmFieldIOHelper::skipCharactersAndComments(xmlStream);
if (!xmlStream.isStartElement())
{
return; // This happens when the field is "shortcut" empty (written like: <ElementName/>)
}
QString className = xmlStream.name().toString();
PdmObject* obj = NULL;
// Create an object if needed
if (m_fieldValue.isNull())
{
obj = caf::PdmObjectFactory::instance()->create(className);
if (obj == NULL)
{
std::cout << "Line " << xmlStream.lineNumber() << ": Warning: Unknown object type with class name: " << className.toLatin1().data() << " found while reading the field : " << this->keyword().toLatin1().data() << std::endl;
xmlStream.skipCurrentElement(); // Skip to the endelement of the object we was supposed to read
xmlStream.skipCurrentElement(); // Skip to the endelement of this field
return;
}
else
{
if (obj->classKeyword() != className)
{
assert(false); // Inconsistency in the factory. It creates objects of wrong type from the ClassKeyword
xmlStream.skipCurrentElement(); // Skip to the endelement of the object we was supposed to read
xmlStream.skipCurrentElement(); // Skip to the endelement of this field
return;
}
m_fieldValue.setRawPtr(obj);
obj->addParentField(this);
}
}
else
{
obj = m_fieldValue.rawPtr();
}
if (className != obj->classKeyword())
{
// Error: Field contains different class type than on file
std::cout << "Line " << xmlStream.lineNumber() << ": Warning: Unknown object type with class name: " << className.toLatin1().data() << " found while reading the field : " << this->keyword().toLatin1().data() << std::endl;
std::cout << " Expected class name: " << obj->classKeyword().toLatin1().data() << std::endl;
xmlStream.skipCurrentElement(); // Skip to the endelement of the object we was supposed to read
xmlStream.skipCurrentElement(); // Skip to the endelement of this field
return;
}
// Everything seems ok, so read the contents of the object:
obj->readFields(xmlStream);
// Make stream point to endElement of this field
QXmlStreamReader::TokenType type;
type = xmlStream.readNext();
PdmFieldIOHelper::skipCharactersAndComments(xmlStream);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
void caf::PdmField<DataType*>::writeFieldData(QXmlStreamWriter& xmlStream)
{
if (m_fieldValue.rawPtr() == NULL) return;
QString className = m_fieldValue.rawPtr()->classKeyword();
xmlStream.writeStartElement("", className);
m_fieldValue.rawPtr()->writeFields(xmlStream);
xmlStream.writeEndElement();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
void caf::PdmField<DataType*>::childObjects(std::vector<PdmObject*>* objects)
{
assert (objects);
PdmObject* obj = m_fieldValue.rawPtr();
if (obj)
{
objects->push_back(obj);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
caf::PdmField<DataType*>::PdmField(const PdmField& other)
: PdmFieldHandle()
{
if (m_fieldValue) m_fieldValue.rawPtr()->removeParentField(this);
m_fieldValue = other.m_fieldValue;
if (m_fieldValue != NULL) m_fieldValue.rawPtr()->addParentField(this);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
caf::PdmField<DataType*>::PdmField(const DataTypePtr& fieldValue)
{
if (m_fieldValue) m_fieldValue->removeParentField(this);
m_fieldValue = fieldValue;
if (m_fieldValue != NULL) m_fieldValue->addParentField(this);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
caf::PdmField<DataType*>::~PdmField()
{
if (!m_fieldValue.isNull()) m_fieldValue.rawPtr()->removeParentField(this);
m_fieldValue.setRawPtr(NULL);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
caf::PdmField<DataType*>& PdmField<DataType*>::operator=(const PdmField& other)
{
if (m_fieldValue) m_fieldValue->removeParentField(this);
m_fieldValue = other.m_fieldValue;
if (m_fieldValue != NULL) m_fieldValue->addParentField(this);
return *this;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
caf::PdmField<DataType*>& PdmField<DataType*>::operator=(const DataTypePtr & fieldValue)
{
if (m_fieldValue) m_fieldValue->removeParentField(this);
m_fieldValue = fieldValue;
if (m_fieldValue != NULL) m_fieldValue->addParentField(this);
return *this;
}
//==================================================================================================
/// Implementation of PdmPointersField<>
//==================================================================================================
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType>
PdmPointersField<DataType*>::PdmPointersField(const PdmPointersField& other)
{
this->removeThisAsParentField();
m_pointers = other.m_pointers;
this->addThisAsParentField();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType>
PdmPointersField<DataType*>::~PdmPointersField()
{
this->removeThisAsParentField();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType>
caf::PdmPointersField<DataType*>& PdmPointersField<DataType*>::operator=(const PdmPointersField& other)
{
this->removeThisAsParentField();
m_pointers = other.m_pointers;
this->addThisAsParentField();
return *this;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType>
DataType* PdmPointersField<DataType*>::operator[](size_t index) const
{
return m_pointers[index];
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmPointersField<DataType*>::push_back(DataType* pointer)
{
m_pointers.push_back(pointer);
if (pointer) pointer->addParentField(this);
}
//--------------------------------------------------------------------------------------------------
/// Set the value at position index to pointer, overwriting any pointer already present at that
/// position without deleting the object pointed to.
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmPointersField<DataType*>::set(size_t index, DataType* pointer)
{
if (m_pointers[index]) m_pointers[index]->removeParentField(this);
m_pointers[index] = pointer;
if (m_pointers[index]) pointer->addParentField(this);
}
//--------------------------------------------------------------------------------------------------
/// Insert pointer at position index, pushing the value previously at that position and all
/// the preceding values backwards
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmPointersField<DataType*>::insert(size_t index, DataType* pointer)
{
m_pointers.insert(m_pointers.begin()+index, pointer);
if (pointer) pointer->addParentField(this);
}
//--------------------------------------------------------------------------------------------------
/// Insert the pointers at position index, pushing the value previously at that position and all
/// the preceding values backwards
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmPointersField<DataType*>::insert(size_t index, const std::vector<PdmPointer<DataType> >& objects)
{
m_pointers.insert(m_pointers.begin()+index, objects.begin(), objects.end());
typename std::vector< PdmPointer< DataType > >::iterator it;
for (it = m_pointers.begin()+index; it != m_pointers.end(); ++it)
{
if (!it->isNull())
{
(*it)->addParentField(this);
}
}
}
//--------------------------------------------------------------------------------------------------
/// Returns the number of times pointer is referenced from the container.
//--------------------------------------------------------------------------------------------------
template<typename DataType>
size_t PdmPointersField<DataType*>::count(const DataType* pointer) const
{
size_t itemCount = 0;
typename std::vector< PdmPointer< DataType > >::const_iterator it;
for (it = m_pointers.begin(); it != m_pointers.end(); ++it)
{
if (*it == pointer)
{
itemCount++;
}
}
return itemCount;
}
//--------------------------------------------------------------------------------------------------
/// Empty the container without deleting the objects pointed to.
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmPointersField<DataType*>::clear()
{
this->removeThisAsParentField();
m_pointers.clear();
}
//--------------------------------------------------------------------------------------------------
/// Deletes all the objects pointed to by the field, then clears the container.
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmPointersField<DataType*>::deleteAllChildObjects()
{
size_t index;
for (index = 0; index < m_pointers.size(); ++index)
{
delete(m_pointers[index].rawPtr());
}
m_pointers.clear();
}
//--------------------------------------------------------------------------------------------------
/// Removes the pointer at index from the container. Does not delete the object pointed to.
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmPointersField<DataType*>::erase(size_t index)
{
if (m_pointers[index])
{
m_pointers[index]->removeParentField(this);
}
m_pointers.erase(m_pointers.begin() + index);
}
//--------------------------------------------------------------------------------------------------
/// Removes all instances of object pointer from the container without deleting the object.
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmPointersField<DataType*>::removeChildObject(PdmObject* object)
{
std::vector< PdmPointer<DataType> > tempPointers;
tempPointers = m_pointers;
m_pointers.clear();
for (size_t index = 0; index < tempPointers.size(); ++index)
{
if (tempPointers[index].rawPtr() != object)
{
m_pointers.push_back(tempPointers[index]);
}
else
{
if (tempPointers[index].rawPtr())
{
tempPointers[index].rawPtr()->removeParentField(this);
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmPointersField<DataType*>::writeFieldData( QXmlStreamWriter& xmlStream)
{
typename std::vector< PdmPointer<DataType> >::iterator it;
for (it = m_pointers.begin(); it != m_pointers.end(); ++it)
{
if (it->rawPtr() == NULL) continue;
QString className = it->rawPtr()->classKeyword();
xmlStream.writeStartElement("", className);
it->rawPtr()->writeFields(xmlStream);
xmlStream.writeEndElement();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmPointersField<DataType*>::readFieldData(QXmlStreamReader& xmlStream)
{
DataType * currentObject = NULL;
this->deleteAllChildObjects();
PdmFieldIOHelper::skipCharactersAndComments(xmlStream);
while (xmlStream.isStartElement())
{
QString className = xmlStream.name().toString();
PdmObject * obj = PdmObjectFactory::instance()->create(className);
if (obj == NULL)
{
// Warning: Unknown className read
// Skip to corresponding end element
std::cout << "Line " << xmlStream.lineNumber() << ": Warning: Unknown object type with class name: " << className.toLatin1().data() << " found while reading the field : " << this->keyword().toLatin1().data() << std::endl;
// Skip to EndElement of the object
xmlStream.skipCurrentElement();
// Jump off the end element, and head for next start element (or the final EndElement of the field)
QXmlStreamReader::TokenType type;
type = xmlStream.readNext();
PdmFieldIOHelper::skipCharactersAndComments(xmlStream);
continue;
}
if (obj->classKeyword() != className)
{
assert(false); // There is an inconsistency in the factory. It creates objects of type not matching the ClassKeyword
// Skip to EndElement of the object
xmlStream.skipCurrentElement();
// Jump off the end element, and head for next start element (or the final EndElement of the field)
QXmlStreamReader::TokenType type;
type = xmlStream.readNext();
PdmFieldIOHelper::skipCharactersAndComments(xmlStream);
continue;
}
obj->readFields(xmlStream);
m_pointers.push_back(PdmPointer<DataType>());
m_pointers.back().setRawPtr(obj);
obj->addParentField(this);
// Jump off the end element, and head for next start element (or the final EndElement of the field)
// Qt reports a character token between EndElements and StartElements so skip it
QXmlStreamReader::TokenType type;
type = xmlStream.readNext();
PdmFieldIOHelper::skipCharactersAndComments(xmlStream);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmPointersField<DataType*>::childObjects(std::vector<PdmObject*>* objects)
{
if (!objects) return;
size_t i;
for (i = 0; i < m_pointers.size(); ++i)
{
objects->push_back(m_pointers[i].rawPtr());
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmPointersField<DataType*>::removeThisAsParentField()
{
typename std::vector< PdmPointer< DataType > >::iterator it;
for (it = m_pointers.begin(); it != m_pointers.end(); ++it)
{
if (!it->isNull())
{
it->rawPtr()->removeParentField(this);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType>
void PdmPointersField<DataType*>::addThisAsParentField()
{
typename std::vector< PdmPointer< DataType > >::iterator it;
for (it = m_pointers.begin(); it != m_pointers.end(); ++it)
{
if (!it->isNull())
{
(*it)->addParentField(this);
}
}
}
} //End of namespace caf

Some files were not shown because too many files have changed in this diff Show More