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
...@@ -12,12 +12,12 @@ ...@@ -12,12 +12,12 @@
// it under the terms of the GNU Lesser General Public License as published by // it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// OpenFlipper is distributed in the hope that it will be useful, // OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details. // GNU Lesser General Public License for more details.
// //
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>. // along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
// //
...@@ -168,39 +168,39 @@ bool get_target_identifiers( std::vector<int>& _identifiers ) { ...@@ -168,39 +168,39 @@ bool get_target_identifiers( std::vector<int>& _identifiers ) {
// =============================================================================== // ===============================================================================
bool get_object( int _identifier , BaseObject*& _object ) { bool get_object( int _identifier , BaseObject*& _object ) {
if ( _identifier == -1 ) if ( _identifier == -1 )
return false; return false;
_object = objectRoot_->childExists( _identifier ); _object = objectRoot_->childExists( _identifier );
return ( _object != 0 ); return ( _object != 0 );
} }
bool get_object( int _identifier , BaseObjectData*& _object ) { bool get_object( int _identifier , BaseObjectData*& _object ) {
if ( _identifier == -1 ) if ( _identifier == -1 )
return false; return false;
BaseObject* object = objectRoot_->childExists( _identifier ); BaseObject* object = objectRoot_->childExists( _identifier );
_object = dynamic_cast< BaseObjectData* >(object); _object = dynamic_cast< BaseObjectData* >(object);
return ( _object != 0 ); return ( _object != 0 );
} }
bool get_object( int _identifier , TriMeshObject*& _object ) { bool get_object( int _identifier , TriMeshObject*& _object ) {
if ( _identifier == -1 ) if ( _identifier == -1 )
return false; return false;
BaseObject* object = objectRoot_->childExists( _identifier ); BaseObject* object = objectRoot_->childExists( _identifier );
_object = dynamic_cast< TriMeshObject* >(object); _object = dynamic_cast< TriMeshObject* >(object);
return ( _object != 0 ); return ( _object != 0 );
} }
bool get_object( int _identifier , PolyMeshObject*& _object ) { bool get_object( int _identifier , PolyMeshObject*& _object ) {
if ( _identifier == -1 ) if ( _identifier == -1 )
return false; return false;
BaseObject* object = objectRoot_->childExists( _identifier ); BaseObject* object = objectRoot_->childExists( _identifier );
_object = dynamic_cast< PolyMeshObject* >(object); _object = dynamic_cast< PolyMeshObject* >(object);
return ( _object != 0 ); return ( _object != 0 );
...@@ -211,10 +211,10 @@ bool get_object( int _identifier , PolyMeshObject*& _object ) { ...@@ -211,10 +211,10 @@ bool get_object( int _identifier , PolyMeshObject*& _object ) {
bool get_mesh( int _identifier , TriMesh*& _mesh ) { bool get_mesh( int _identifier , TriMesh*& _mesh ) {
if ( _identifier == -1 ) if ( _identifier == -1 )
return false; return false;
BaseObject* object = objectRoot_->childExists( _identifier ); BaseObject* object = objectRoot_->childExists( _identifier );
// Unable to find object // Unable to find object
...@@ -232,10 +232,10 @@ bool get_mesh( int _identifier , TriMesh*& _mesh ) { ...@@ -232,10 +232,10 @@ bool get_mesh( int _identifier , TriMesh*& _mesh ) {
} }
bool get_mesh( int _identifier , PolyMesh*& _mesh ) { bool get_mesh( int _identifier , PolyMesh*& _mesh ) {
if ( _identifier == -1 ) if ( _identifier == -1 )
return false; return false;
BaseObject* object = objectRoot_->childExists( _identifier ); BaseObject* object = objectRoot_->childExists( _identifier );
// Unable to find object // Unable to find object
...@@ -253,7 +253,7 @@ bool get_mesh( int _identifier , PolyMesh*& _mesh ) { ...@@ -253,7 +253,7 @@ bool get_mesh( int _identifier , PolyMesh*& _mesh ) {
} }
bool deleteObject( int _id ) { bool deleteObject( int _id ) {
if ( _id == -1 ) if ( _id == -1 )
return false; return false;
...@@ -281,12 +281,40 @@ void deleteAll( ) { ...@@ -281,12 +281,40 @@ void deleteAll( ) {
objectRoot()->deleteSubtree(); 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 ) { bool object_exists( int _identifier ) {
if ( _identifier == -1 ) if ( _identifier == -1 )
return false; return false;
BaseObject* object = objectRoot_->childExists( _identifier ); BaseObject* object = objectRoot_->childExists( _identifier );
return ( object != 0 ); return ( object != 0 );
} }
...@@ -421,8 +449,8 @@ void translate( const ACG::Vec3d &_vector ) { ...@@ -421,8 +449,8 @@ void translate( const ACG::Vec3d &_vector ) {
examiner_widget_->translate(_vector); examiner_widget_->translate(_vector);
} }
void rotate(const ACG::Vec3d& _axis, void rotate(const ACG::Vec3d& _axis,
double _angle, double _angle,
const ACG::Vec3d& _center) const ACG::Vec3d& _center)
{ {
examiner_widget_->rotate(_axis,_angle,_center); examiner_widget_->rotate(_axis,_angle,_center);
...@@ -437,11 +465,11 @@ void viewAll() { ...@@ -437,11 +465,11 @@ void viewAll() {
} }
ACG::Vec3d viewingDirection() { ACG::Vec3d viewingDirection() {
return examiner_widget_->glState().viewing_direction(); return examiner_widget_->glState().viewing_direction();
} }
ACG::Vec3d eyePos() { ACG::Vec3d eyePos() {
return examiner_widget_->glState().eye(); return examiner_widget_->glState().eye();
} }
ACG::Vec3d upVector() { ACG::Vec3d upVector() {
...@@ -694,14 +722,14 @@ ObjectIterator objects_end() { ...@@ -694,14 +722,14 @@ ObjectIterator objects_end() {
BaseObjectData* baseObjectData( BaseObject* _object ){ BaseObjectData* baseObjectData( BaseObject* _object ){
if ( _object == 0 ) if ( _object == 0 )
return 0; return 0;
return dynamic_cast< BaseObjectData* >(_object); return dynamic_cast< BaseObjectData* >(_object);
} }
TriMesh* triMesh( BaseObjectData* _object ) { TriMesh* triMesh( BaseObjectData* _object ) {
if ( _object == 0 ) if ( _object == 0 )
return 0; return 0;
if ( _object->dataType(DATA_TRIANGLE_MESH) ) { if ( _object->dataType(DATA_TRIANGLE_MESH) ) {
TriMeshObject* object = dynamic_cast< TriMeshObject* >(_object); TriMeshObject* object = dynamic_cast< TriMeshObject* >(_object);
return object->mesh(); return object->mesh();
...@@ -712,7 +740,7 @@ TriMesh* triMesh( BaseObjectData* _object ) { ...@@ -712,7 +740,7 @@ TriMesh* triMesh( BaseObjectData* _object ) {
PolyMesh* polyMesh( BaseObjectData* _object ) { PolyMesh* polyMesh( BaseObjectData* _object ) {
if ( _object == 0 ) if ( _object == 0 )
return 0; return 0;
if ( _object->dataType(DATA_POLY_MESH) ) { if ( _object->dataType(DATA_POLY_MESH) ) {
PolyMeshObject* object = dynamic_cast< PolyMeshObject* >(_object); PolyMeshObject* object = dynamic_cast< PolyMeshObject* >(_object);
return object->mesh(); return object->mesh();
...@@ -723,7 +751,7 @@ PolyMesh* polyMesh( BaseObjectData* _object ) { ...@@ -723,7 +751,7 @@ PolyMesh* polyMesh( BaseObjectData* _object ) {
TriMeshObject* triMeshObject( BaseObjectData* _object ) { TriMeshObject* triMeshObject( BaseObjectData* _object ) {
if ( _object == 0 ) if ( _object == 0 )
return 0; return 0;
if ( ! _object->dataType(DATA_TRIANGLE_MESH) ) if ( ! _object->dataType(DATA_TRIANGLE_MESH) )
return NULL; return NULL;
return dynamic_cast< TriMeshObject* >( _object ); return dynamic_cast< TriMeshObject* >( _object );
...@@ -732,7 +760,7 @@ TriMeshObject* triMeshObject( BaseObjectData* _object ) { ...@@ -732,7 +760,7 @@ TriMeshObject* triMeshObject( BaseObjectData* _object ) {
PolyMeshObject* polyMeshObject( BaseObjectData* _object ) { PolyMeshObject* polyMeshObject( BaseObjectData* _object ) {
if ( _object == 0 ) if ( _object == 0 )
return 0; return 0;
if ( ! _object->dataType(DATA_POLY_MESH) ) if ( ! _object->dataType(DATA_POLY_MESH) )
return NULL; return NULL;
return dynamic_cast< PolyMeshObject* >( _object ); return dynamic_cast< PolyMeshObject* >( _object );
......
...@@ -123,6 +123,16 @@ bool deleteObject( int _id ); ...@@ -123,6 +123,16 @@ bool deleteObject( int _id );
DLLEXPORT DLLEXPORT
void deleteAll( ); 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 @@ ...@@ -54,6 +54,21 @@
*/ */
static int idGenerator = 1; 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) : BaseObject::BaseObject(BaseObject* _parent) :
id_(-1), id_(-1),
...@@ -533,6 +548,11 @@ void BaseObject::dumpTree() { ...@@ -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 // per Object data functions
......
...@@ -78,6 +78,12 @@ class DLLEXPORT BaseObject { ...@@ -78,6 +78,12 @@ class DLLEXPORT BaseObject {
friend class BaseObjectData; friend class BaseObjectData;
public : 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); BaseObject( BaseObject *_parent = 0);
virtual ~BaseObject(); virtual ~BaseObject();
...@@ -239,6 +245,9 @@ class DLLEXPORT BaseObject { ...@@ -239,6 +245,9 @@ class DLLEXPORT BaseObject {
/// Debugging function, writing the subtree to output /// Debugging function, writing the subtree to output
void dumpTree(); void dumpTree();
/// Returns a full copy of the object
virtual BaseObject* copy();
/** @} */ /** @} */
......
...@@ -48,6 +48,18 @@ ...@@ -48,6 +48,18 @@
//== CLASS DEFINITION ========================================================= //== 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 ) : BaseObjectData::BaseObjectData( SeparatorNode* _rootNode ) :
BaseObject(), BaseObject(),
path_("."), path_("."),
......
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
#else #else
#define DLLEXPORT #define DLLEXPORT
#endif #endif
#endif #endif
//== INCLUDES ================================================================= //== INCLUDES =================================================================
...@@ -87,6 +87,13 @@ typedef ACG::SceneGraph::BaseNode BaseNode; ...@@ -87,6 +87,13 @@ typedef ACG::SceneGraph::BaseNode BaseNode;
class DLLEXPORT BaseObjectData : public BaseObject class DLLEXPORT BaseObjectData : public BaseObject
{ {
public: public:
/** \brief copy constructor
*
* Create new basic scenegraph nodes for this object
*/
BaseObjectData(const BaseObjectData& _object);
/// constructor /// constructor
BaseObjectData(SeparatorNode* _rootNode); BaseObjectData(SeparatorNode* _rootNode);
......
...@@ -12,12 +12,12 @@ ...@@ -12,12 +12,12 @@
// it under the terms of the GNU Lesser General Public License as published by // it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// OpenFlipper is distributed in the hope that it will be useful, // OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details. // GNU Lesser General Public License for more details.
// //
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>. // along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
// //
...@@ -49,6 +49,13 @@ ...@@ -49,6 +49,13 @@
//== CLASS DEFINITION ========================================================= //== CLASS DEFINITION =========================================================
GroupObject::GroupObject(const GroupObject& _object ):
BaseObject(_object)
{
setDataType(DATA_GROUP);
setName(name());
}
GroupObject::GroupObject( QString _groupName , GroupObject *_parent) : GroupObject::GroupObject( QString _groupName , GroupObject *_parent) :
BaseObject(_parent) BaseObject(_parent)
{ {
...@@ -60,5 +67,10 @@ GroupObject::~GroupObject() { ...@@ -60,5 +67,10 @@ GroupObject::~GroupObject() {
} }
BaseObject* GroupObject::copy() {
GroupObject* copy = new GroupObject(*this);
return dynamic_cast< BaseObject* > (copy);
}
//============================================================================= //=============================================================================
...@@ -12,12 +12,12 @@ ...@@ -12,12 +12,12 @@
// it under the terms of the GNU Lesser General Public License as published by // it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// OpenFlipper is distributed in the hope that it will be useful, // OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details. // GNU Lesser General Public License for more details.
// //
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>. // along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
// //
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
//============================================================================= //=============================================================================
/** /**
* \file Types.hh * \file Types.hh
* This File contains the basic available datatypes in the Framework. * This File contains the basic available datatypes in the Framework.
*/ */
...@@ -47,21 +47,21 @@ ...@@ -47,21 +47,21 @@
#ifndef GROUPOBJECT_HH #ifndef GROUPOBJECT_HH
#define GROUPOBJECT_HH #define GROUPOBJECT_HH
#ifndef DLLEXPORT #ifndef DLLEXPORT
#ifdef WIN32 #ifdef WIN32
#define DLLEXPORT __declspec(dllexport) #define DLLEXPORT __declspec(dllexport)
#else #else
#define DLLEXPORT #define DLLEXPORT
#endif #endif
#endif #endif
//== INCLUDES ================================================================= //== INCLUDES =================================================================
#include <QList> #include <QList>
//== TYPEDEFS ================================================================= //== TYPEDEFS =================================================================
//== CLASS DEFINITION ========================================================= //== CLASS DEFINITION =========================================================
...@@ -70,20 +70,32 @@ ...@@ -70,20 +70,32 @@
*/ */
class DLLEXPORT GroupObject : public BaseObject { class DLLEXPORT GroupObject : public BaseObject {
public: public:
/** copy constructor
*
*/
GroupObject(const GroupObject& _object );
/** constructor /** constructor
* *
* @param _groupName Name of the new Group object * @param _groupName Name of the new Group object
*/ */
GroupObject(QString _groupName = "Group" , GroupObject *parent = 0 ); GroupObject(QString _groupName = "Group" , GroupObject *parent = 0 );
/// destructor /// destructor
virtual ~GroupObject(); 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();
/** @} */
}; };
//============================================================================= //=============================================================================
#endif // GROUPOBJECT_HH defined #endif // GROUPOBJECT_HH defined
//============================================================================= //=============================================================================
...@@ -52,6 +52,22 @@ ...@@ -52,6 +52,22 @@
//== CLASS DEFINITION ========================================================= //== 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 /** 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 * 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 * and all nodes for visualization will be added below the scenegraph node.\n
...@@ -144,8 +160,12 @@ ...@@ -144,8 +160,12 @@
* the mesh and requests all required properties for the mesh. * the mesh and requests all required properties for the mesh.
*/ */
template < class MeshT , DataType objectDataType > template < class MeshT , DataType objectDataType >
void MeshObject< MeshT , objectDataType >::init() { void MeshObject< MeshT , objectDataType >::init(MeshT* _mesh) {
mesh_ = new MeshT();
if ( _mesh == 0 )
mesh_ = new MeshT();
else
mesh_ = new MeshT(*_mesh);
mesh_->request_vertex_normals(); mesh_->request_vertex_normals();
mesh_->request_face_normals(); mesh_->request_face_normals();
...@@ -307,6 +327,13 @@ ...@@ -307,6 +327,13 @@
handleNode_->update_cache(); 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);
}
// ===============================================================================