glc_worldhandle.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "glc_worldhandle.h"
00024 #include "glc_structreference.h"
00025 #include <QSet>
00026
00027 GLC_WorldHandle::GLC_WorldHandle()
00028 : m_Collection()
00029 , m_NumberOfWorld(1)
00030 , m_OccurenceHash()
00031 , m_UpVector(glc::Z_AXIS)
00032 , m_SelectionSet(this)
00033 {
00034
00035 }
00036
00037 GLC_WorldHandle::~GLC_WorldHandle()
00038 {
00039
00040 }
00041
00042
00043 QList<GLC_StructInstance*> GLC_WorldHandle::instances() const
00044 {
00045 QSet<GLC_StructInstance*> instancesSet;
00046 QHash<GLC_uint, GLC_StructOccurence*>::const_iterator iOccurence= m_OccurenceHash.constBegin();
00047 while (iOccurence != m_OccurenceHash.constEnd())
00048 {
00049 instancesSet.insert(iOccurence.value()->structInstance());
00050 ++iOccurence;
00051 }
00052 return instancesSet.toList();
00053 }
00054
00055
00056 QList<GLC_StructReference*> GLC_WorldHandle::references() const
00057 {
00058 QSet<GLC_StructReference*> referencesSet;
00059 QHash<GLC_uint, GLC_StructOccurence*>::const_iterator iOccurence= m_OccurenceHash.constBegin();
00060 while (iOccurence != m_OccurenceHash.constEnd())
00061 {
00062 referencesSet.insert(iOccurence.value()->structReference());
00063 ++iOccurence;
00064 }
00065 return referencesSet.toList();
00066 }
00067
00068
00069 int GLC_WorldHandle::numberOfBody() const
00070 {
00071 QList<GLC_StructReference*> referenceList(references());
00072 const int size= referenceList.size();
00073 int numberOfBody= 0;
00074 for (int i= 0; i < size; ++i)
00075 {
00076 numberOfBody+= referenceList.at(i)->numberOfBody();
00077 }
00078 return numberOfBody;
00079 }
00080
00081 int GLC_WorldHandle::representationCount() const
00082 {
00083 QList<GLC_StructReference*> referenceList(references());
00084 const int size= referenceList.size();
00085 int count= 0;
00086 for (int i= 0; i < size; ++i)
00087 {
00088 if (referenceList.at(i)->hasRepresentation()) ++count;
00089 }
00090 return count;
00091
00092 }
00093
00094
00095 void GLC_WorldHandle::addOccurence(GLC_StructOccurence* pOccurence, bool isSelected, GLuint shaderId)
00096 {
00097 Q_ASSERT(!m_OccurenceHash.contains(pOccurence->id()));
00098 m_OccurenceHash.insert(pOccurence->id(), pOccurence);
00099 GLC_StructReference* pRef= pOccurence->structReference();
00100 Q_ASSERT(NULL != pRef);
00101
00102
00103 if (pOccurence->useAutomatic3DViewInstanceCreation() && pRef->representationIsLoaded())
00104 {
00105
00106 GLC_3DRep* p3DRep= dynamic_cast<GLC_3DRep*>(pRef->representationHandle());
00107 GLC_3DViewInstance representation(*p3DRep);
00108
00109 representation.setId(pOccurence->id());
00110
00111 representation.setName(pOccurence->name());
00112 if (0 != shaderId) m_Collection.bindShader(shaderId);
00113 m_Collection.add(representation, shaderId);
00114 if (isSelected)
00115 {
00116
00117 m_Collection.select(pOccurence->id());
00118 }
00119 }
00120 }
00121
00122
00123 void GLC_WorldHandle::removeOccurence(GLC_StructOccurence* pOccurence)
00124 {
00125 Q_ASSERT(m_OccurenceHash.contains(pOccurence->id()));
00126
00127 m_SelectionSet.remove(pOccurence);
00128
00129 m_OccurenceHash.remove(pOccurence->id());
00130
00131 m_Collection.remove(pOccurence->id());
00132 }
00133
00134 void GLC_WorldHandle::select(GLC_uint occurenceId, bool propagate)
00135 {
00136 Q_ASSERT(m_OccurenceHash.contains(occurenceId));
00137 m_SelectionSet.insert(occurenceId);
00138 m_Collection.select(occurenceId);
00139
00140 const GLC_StructOccurence* pSelectedOccurence= m_OccurenceHash.value(occurenceId);
00141 if (propagate && pSelectedOccurence->hasChild())
00142 {
00143 QList<GLC_StructOccurence*> subOccurenceList= pSelectedOccurence->subOccurenceList();
00144 const int subOccurenceCount= subOccurenceList.size();
00145 for (int i= 0; i < subOccurenceCount; ++i)
00146 {
00147 const GLC_uint currentOccurenceId= subOccurenceList.at(i)->id();
00148 if (m_Collection.contains(currentOccurenceId))
00149 {
00150 m_Collection.select(currentOccurenceId);
00151 }
00152 }
00153 }
00154 }
00155
00156 void GLC_WorldHandle::unselect(GLC_uint occurenceId, bool propagate)
00157 {
00158 Q_ASSERT(m_OccurenceHash.contains(occurenceId));
00159 m_SelectionSet.remove(occurenceId);
00160 m_Collection.unselect(occurenceId);
00161
00162 const GLC_StructOccurence* pSelectedOccurence= m_OccurenceHash.value(occurenceId);
00163 if (propagate && pSelectedOccurence->hasChild())
00164 {
00165 QList<GLC_StructOccurence*> subOccurenceList= pSelectedOccurence->subOccurenceList();
00166 const int subOccurenceCount= subOccurenceList.size();
00167 for (int i= 0; i < subOccurenceCount; ++i)
00168 {
00169 const GLC_uint currentOccurenceId= subOccurenceList.at(i)->id();
00170 m_Collection.unselect(currentOccurenceId);
00171 }
00172 }
00173 }
00174
00175 void GLC_WorldHandle::selectAllWith3DViewInstance(bool allShowState)
00176 {
00177 m_Collection.selectAll(allShowState);
00178 QList<GLC_uint> selectedId= m_Collection.selection()->keys();
00179 m_SelectionSet.clear();
00180 const int selectionCount= selectedId.count();
00181 for (int i= 0; i < selectionCount; ++i)
00182 {
00183 m_SelectionSet.insert(selectedId.at(i));
00184 }
00185 }
00186
00187 void GLC_WorldHandle::unselectAll()
00188 {
00189 m_SelectionSet.clear();
00190 m_Collection.unselectAll();
00191 }
00192
00193 void GLC_WorldHandle::showHideSelected3DViewInstance()
00194 {
00195 QList<GLC_3DViewInstance*> selected3dviewInstance= m_Collection.selection()->values();
00196 const int instanceCount= selected3dviewInstance.count();
00197 for(int i= 0; i < instanceCount; ++i)
00198 {
00199 GLC_3DViewInstance* pCurrentInstance= selected3dviewInstance.at(i);
00200 pCurrentInstance->setVisibility(!pCurrentInstance->isVisible());
00201 }
00202 }
00203
00204 void GLC_WorldHandle::setSelected3DViewInstanceVisibility(bool isVisible)
00205 {
00206 QList<GLC_3DViewInstance*> selected3dviewInstance= m_Collection.selection()->values();
00207 const int instanceCount= selected3dviewInstance.count();
00208 for(int i= 0; i < instanceCount; ++i)
00209 {
00210 GLC_3DViewInstance* pCurrentInstance= selected3dviewInstance.at(i);
00211 pCurrentInstance->setVisibility(isVisible);
00212 }
00213 }
00214