Commit ea17af07 authored by Jan Möbius's avatar Jan Möbius

Created copy constructors and copy funtions for objects provided by core (...

Created copy constructors and copy funtions for objects provided by core ( Meshobject,GroupObject, Baseobject and baseobjectdata)

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@3800 383ad7c9-94d9-4d36-a494-682f7c89f535
parent b0ca4887
......@@ -281,6 +281,34 @@ void deleteAll( ) {
objectRoot()->deleteSubtree();
}
int copyObject( int _id ) {
if ( _id == -1 )
return -1;
// get the node
BaseObject* object = objectRoot_->childExists(_id);
if ( !object ) {
std::cerr << "Error while copying object ... not found" << std::endl;
return -1;
}
// remove the whole subtree below this item
BaseObject* copy = object->copy();
if ( copy == 0 ) {
std::cerr << "Unable to create a copy of the object." << std::endl;
}
// Integrate into object tree
copy->setParent( object->parent() );
if ( object->parent() )
object->parent()->appendChild(copy);
else
std::cerr << "Unable to add copy to object list" << std::endl;
return copy->id();
}
bool object_exists( int _identifier ) {
......
......@@ -123,6 +123,16 @@ bool deleteObject( int _id );
DLLEXPORT
void deleteAll( );
/** \brief Create a copy of the object with the given id
*
* Creates a copy of an object. All scenegraph nodes will be created. The object will
* not be part of the object tree. This has to be done by setParent of the object.
* @return Pointer to new object or 0 if failed;
* */
DLLEXPORT
int copyObject( int _id );
/** @} */
......
......@@ -54,6 +54,21 @@
*/
static int idGenerator = 1;
BaseObject::BaseObject(const BaseObject& _object) {
id_ = idGenerator;
++idGenerator;
persistentId_ = _object.persistentId_;
objectType_ = _object.objectType_;
target_ = _object.target_;
source_ = _object.source_;
visible_ = _object.visible_;
parentItem_ = 0;
childItems_.clear();
name_ = "Copy of " + _object.name_;
///@todo Maybe copy per Object Data
dataMap_.clear();
}
BaseObject::BaseObject(BaseObject* _parent) :
id_(-1),
......@@ -533,6 +548,11 @@ void BaseObject::dumpTree() {
}
BaseObject* BaseObject::copy() {
std::cerr << "Copy not supported by this Object" << std::endl;
return 0;
}
// ===============================================================================
// per Object data functions
......
......@@ -78,6 +78,12 @@ class DLLEXPORT BaseObject {
friend class BaseObjectData;
public :
/** Creates a copy of this Object. Currently it will not have any per Object data attached.
* Its also not attached to the object tree. This has to be done by using setParent.
*/
BaseObject(const BaseObject& _object);
BaseObject( BaseObject *_parent = 0);
virtual ~BaseObject();
......@@ -239,6 +245,9 @@ class DLLEXPORT BaseObject {
/// Debugging function, writing the subtree to output
void dumpTree();
/// Returns a full copy of the object
virtual BaseObject* copy();
/** @} */
......
......@@ -48,6 +48,18 @@
//== CLASS DEFINITION =========================================================
BaseObjectData::BaseObjectData(const BaseObjectData& _object)
: BaseObject(_object),
path_("."),
rootNode_(_object.rootNode_),
separatorNode_(0),
manipulatorNode_(0),
materialNode_(0)
{
// We have to create our own visualization nodes as we are a new object
init();
}
BaseObjectData::BaseObjectData( SeparatorNode* _rootNode ) :
BaseObject(),
path_("."),
......
......@@ -87,6 +87,13 @@ typedef ACG::SceneGraph::BaseNode BaseNode;
class DLLEXPORT BaseObjectData : public BaseObject
{
public:
/** \brief copy constructor
*
* Create new basic scenegraph nodes for this object
*/
BaseObjectData(const BaseObjectData& _object);
/// constructor
BaseObjectData(SeparatorNode* _rootNode);
......
......@@ -49,6 +49,13 @@
//== CLASS DEFINITION =========================================================
GroupObject::GroupObject(const GroupObject& _object ):
BaseObject(_object)
{
setDataType(DATA_GROUP);
setName(name());
}
GroupObject::GroupObject( QString _groupName , GroupObject *_parent) :
BaseObject(_parent)
{
......@@ -60,5 +67,10 @@ GroupObject::~GroupObject() {
}
BaseObject* GroupObject::copy() {
GroupObject* copy = new GroupObject(*this);
return dynamic_cast< BaseObject* > (copy);
}
//=============================================================================
......@@ -70,6 +70,13 @@
*/
class DLLEXPORT GroupObject : public BaseObject {
public:
/** copy constructor
*
*/
GroupObject(const GroupObject& _object );
/** constructor
*
* @param _groupName Name of the new Group object
......@@ -79,6 +86,11 @@ class DLLEXPORT GroupObject : public BaseObject {
/// destructor
virtual ~GroupObject();
/** return a full copy of this object. The object will not be a part of the object tree.
* This has to be done with the setParent() function.
*/
BaseObject* copy();
/** @} */
};
......
......@@ -52,6 +52,22 @@
//== CLASS DEFINITION =========================================================
template < class MeshT , DataType objectDataType >
MeshObject< MeshT , objectDataType >::MeshObject(const MeshObject& _object) :
BaseObjectData(_object),
statusNode_(0),
areaNode_(0),
handleNode_(0),
meshNode_(0),
textureNode_(0),
shaderNode_(0),
triangle_bsp_(0)
{
init(_object.mesh_);
setName( name() );
}
/** Constructor for Mesh Objects. This object class gets a Separator Node giving
* the root node to which it should be connected. The mesh is generated internally
* and all nodes for visualization will be added below the scenegraph node.\n
......@@ -144,8 +160,12 @@
* the mesh and requests all required properties for the mesh.
*/
template < class MeshT , DataType objectDataType >
void MeshObject< MeshT , objectDataType >::init() {
void MeshObject< MeshT , objectDataType >::init(MeshT* _mesh) {
if ( _mesh == 0 )
mesh_ = new MeshT();
else
mesh_ = new MeshT(*_mesh);
mesh_->request_vertex_normals();
mesh_->request_face_normals();
......@@ -307,6 +327,13 @@
handleNode_->update_cache();
}
template < class MeshT , DataType objectDataType >
BaseObject* MeshObject< MeshT , objectDataType >::copy() {
MeshObject< MeshT , objectDataType >* object = new MeshObject< MeshT , objectDataType >(*this);
return dynamic_cast< BaseObject* >(object);
}
// ===============================================================================
// Visualization
// ===============================================================================
......
......@@ -99,6 +99,13 @@ typedef ACG::SceneGraph::TextureNode TextureNode;
template < class MeshT, DataType objectDataType >
class DLLEXPORT MeshObject : public BaseObjectData {
public:
/** \brief copy constructor
*
* Create a copy of this object
*/
MeshObject(const MeshObject& _object);
/// constructor
MeshObject(SeparatorNode* _rootNode);
......@@ -111,7 +118,7 @@ class DLLEXPORT MeshObject : public BaseObjectData {
protected:
/// Initialise current object, including all related nodes.
virtual void init();
virtual void init( MeshT* _mesh = 0);
//===========================================================================
/** @name Name and Path handling
......@@ -147,6 +154,11 @@ class DLLEXPORT MeshObject : public BaseObjectData {
/// Update Topology of all data structures
void updateTopology();
/** return a full copy of this object ( All scenegraph nodes will be created )
* but the object will not be a part of the object tree.
*/
BaseObject* copy();
private:
MeshT* mesh_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment