00001 /**************************************************************************** 00002 00003 This file is part of the GLC-lib library. 00004 Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net) 00005 http://glc-lib.sourceforge.net 00006 00007 GLC-lib is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU Lesser General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 GLC-lib is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public License 00018 along with GLC-lib; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 00021 *****************************************************************************/ 00022 00024 00025 #include "glc_world.h" 00026 #include "glc_structinstance.h" 00027 #include "glc_structreference.h" 00028 00029 // Default constructor 00030 GLC_World::GLC_World() 00031 : m_pWorldHandle(new GLC_WorldHandle()) 00032 , m_pRoot(new GLC_StructOccurence()) 00033 { 00034 m_pRoot->setWorldHandle(m_pWorldHandle); 00035 //qDebug() << "GLC_World::GLC_World() : " << (*m_pNumberOfWorld) << " " << this; 00036 } 00037 00038 // Copy constructor 00039 GLC_World::GLC_World(const GLC_World& world) 00040 : m_pWorldHandle(world.m_pWorldHandle) 00041 , m_pRoot(world.m_pRoot) 00042 { 00043 //qDebug() << "GLC_World::GLC_World() : " << (*m_pNumberOfWorld) << " " << this; 00044 // Increment the number of world 00045 m_pWorldHandle->increment(); 00046 } 00047 00048 GLC_World::~GLC_World() 00049 { 00050 00051 // Decrement the number of world 00052 m_pWorldHandle->decrement(); 00053 //qDebug() << "GLC_World::GLC_World() : " << (*m_pNumberOfWorld) << " " << this; 00054 if (m_pWorldHandle->isOrphan()) 00055 { 00056 // this is the last World, delete the root product and collection 00057 //m_pWorldHandle->collection()->clear(); // Clear collection first (performance) 00058 delete m_pRoot; 00059 delete m_pWorldHandle; 00060 } 00061 } 00062 00063 // Merge this world with another world 00064 void GLC_World::mergeWithAnotherWorld(GLC_World& anotherWorld) 00065 { 00066 qDebug() << "GLC_World::mergeWithAnotherWorld"; 00067 GLC_StructOccurence* pAnotherRoot= anotherWorld.rootOccurence(); 00068 if (pAnotherRoot->childCount() > 0) 00069 { 00070 QList<GLC_StructOccurence*> childs= pAnotherRoot->children(); 00071 const int size= childs.size(); 00072 for (int i= 0; i < size; ++i) 00073 { 00074 m_pRoot->addChild(childs.at(i)->clone(m_pWorldHandle, false)); 00075 } 00076 m_pRoot->updateChildrenAbsoluteMatrix(); 00077 } 00078 else 00079 { 00080 m_pRoot->addChild(anotherWorld.rootOccurence()->clone(m_pWorldHandle, false)); 00081 } 00082 } 00083 00084 // Assignment operator 00085 GLC_World& GLC_World::operator=(const GLC_World& world) 00086 { 00087 if (this != &world) 00088 { 00089 // Decrement the number of world 00090 m_pWorldHandle->decrement(); 00091 if (m_pWorldHandle->isOrphan()) 00092 { 00093 // this is the last World, delete the root product and collection 00094 //m_pWorldHandle->collection()->clear(); // Clear collection first (performance) 00095 delete m_pRoot; 00096 delete m_pWorldHandle; 00097 } 00098 m_pRoot= world.m_pRoot; 00099 m_pWorldHandle= world.m_pWorldHandle; 00100 m_pWorldHandle->increment(); 00101 } 00102 return *this; 00103 }