glc_worldhandle.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  Version 2.0.0 Beta 1, packaged on April 2010.
00006 
00007  http://glc-lib.sourceforge.net
00008 
00009  GLC-lib is free software; you can redistribute it and/or modify
00010  it under the terms of the GNU General Public License as published by
00011  the Free Software Foundation; either version 2 of the License, or
00012  (at your option) any later version.
00013 
00014  GLC-lib is distributed in the hope that it will be useful,
00015  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  GNU General Public License for more details.
00018 
00019  You should have received a copy of the GNU General Public License
00020  along with GLC-lib; if not, write to the Free Software
00021  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023  *****************************************************************************/
00024 
00025 #include "glc_worldhandle.h"
00026 #include "glc_structreference.h"
00027 #include <QSet>
00028 
00029 GLC_WorldHandle::GLC_WorldHandle()
00030 : m_Collection()
00031 , m_NumberOfWorld(1)
00032 , m_OccurenceHash()
00033 , m_UpVector(glc::Z_AXIS)
00034 {
00035 
00036 }
00037 
00038 GLC_WorldHandle::~GLC_WorldHandle()
00039 {
00040 
00041 }
00042 
00043 // Return the list of instance
00044 QList<GLC_StructInstance*> GLC_WorldHandle::instances() const
00045 {
00046         QSet<GLC_StructInstance*> instancesSet;
00047         QHash<GLC_uint, GLC_StructOccurence*>::const_iterator iOccurence= m_OccurenceHash.constBegin();
00048         while (iOccurence != m_OccurenceHash.constEnd())
00049         {
00050                 instancesSet.insert(iOccurence.value()->structInstance());
00051                 ++iOccurence;
00052         }
00053         return instancesSet.toList();
00054 }
00055 
00056 // Return the list of Reference
00057 QList<GLC_StructReference*> GLC_WorldHandle::references() const
00058 {
00059         QSet<GLC_StructReference*> referencesSet;
00060         QHash<GLC_uint, GLC_StructOccurence*>::const_iterator iOccurence= m_OccurenceHash.constBegin();
00061         while (iOccurence != m_OccurenceHash.constEnd())
00062         {
00063                 referencesSet.insert(iOccurence.value()->structReference());
00064                 ++iOccurence;
00065         }
00066         return referencesSet.toList();
00067 }
00068 
00069 // Return the number of body
00070 int GLC_WorldHandle::numberOfBody() const
00071 {
00072         QList<GLC_StructReference*> referenceList(references());
00073         const int size= referenceList.size();
00074         int numberOfBody= 0;
00075         for (int i= 0; i < size; ++i)
00076         {
00077                 numberOfBody+= referenceList.at(i)->numberOfBody();
00078         }
00079         return numberOfBody;
00080 }
00081 
00082 
00083 // An Occurence has been added
00084 void GLC_WorldHandle::addOccurence(GLC_StructOccurence* pOccurence, bool isSelected, GLuint shaderId)
00085 {
00086         Q_ASSERT(!m_OccurenceHash.contains(pOccurence->id()));
00087         m_OccurenceHash.insert(pOccurence->id(), pOccurence);
00088 
00089         // Add instance representation in the collection
00090         if (pOccurence->hasRepresentation())
00091         {
00092                 GLC_3DRep* p3DRep= dynamic_cast<GLC_3DRep*>(pOccurence->structReference()->representationHandle());
00093                 GLC_3DViewInstance representation(*p3DRep);
00094                 // Force instance representation id
00095                 representation.setId(pOccurence->id());
00096                 // Force instance representation name
00097                 representation.setName(pOccurence->name());
00098                 if (0 != shaderId) m_Collection.bindShader(shaderId);
00099                 m_Collection.add(representation, shaderId);
00100                 if (isSelected)
00101                 {
00102                         qDebug() << pOccurence->name() << "selected";
00103                         m_Collection.select(pOccurence->id());
00104                 }
00105         }
00106 }
00107 
00108 // An Occurence has been removed
00109 void GLC_WorldHandle::removeOccurence(GLC_StructOccurence* pOccurence)
00110 {
00111         Q_ASSERT(m_OccurenceHash.contains(pOccurence->id()));
00112         m_OccurenceHash.remove(pOccurence->id());
00113         // Remove instance representation from the collection
00114         if (pOccurence->hasRepresentation())
00115         {
00116                 m_Collection.remove(pOccurence->id());
00117         }
00118 }

SourceForge.net Logo

©2005 Laurent Ribon