glc_structreference.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
00024
00025 #include "glc_structreference.h"
00026 #include "glc_structoccurence.h"
00027
00028
00029 GLC_StructReference::GLC_StructReference(const QString& name)
00030 : m_SetOfInstance()
00031 , m_pRepresentation(NULL)
00032 , m_Name(name)
00033 , m_pAttributes(NULL)
00034 {
00035
00036
00037 }
00038
00039
00040 GLC_StructReference::GLC_StructReference(GLC_Rep* pRep)
00041 : m_SetOfInstance()
00042 , m_pRepresentation(pRep)
00043 , m_Name(m_pRepresentation->name())
00044 , m_pAttributes(NULL)
00045 {
00046
00047 }
00048
00049
00050 GLC_StructReference::GLC_StructReference(const GLC_StructReference& ref)
00051 : m_SetOfInstance()
00052 , m_pRepresentation(NULL)
00053 , m_Name(ref.m_Name)
00054 , m_pAttributes(new GLC_Attributes(*(ref.m_pAttributes)))
00055 {
00056 if (NULL != ref.m_pRepresentation)
00057 {
00058 m_pRepresentation= ref.m_pRepresentation->clone();
00059 }
00060 }
00061
00063 GLC_StructReference& GLC_StructReference::operator=(const GLC_StructReference& ref)
00064 {
00065 if (this != &ref)
00066 {
00067 m_SetOfInstance.clear();
00068 delete m_pAttributes;
00069 m_pAttributes= NULL;
00070
00071 m_Name= ref.m_Name;
00072 m_pAttributes= new GLC_Attributes(*(ref.m_pAttributes));
00073
00074 if (NULL != ref.m_pRepresentation)
00075 {
00076 m_pRepresentation= ref.m_pRepresentation->clone();
00077 }
00078 }
00079 return *this;
00080 }
00081
00082 GLC_StructReference::~GLC_StructReference()
00083 {
00084 delete m_pRepresentation;
00085 delete m_pAttributes;
00086 }
00087
00088
00090
00092
00093 QSet<GLC_StructOccurence*> GLC_StructReference::setOfStructOccurence() const
00094 {
00095 QList<GLC_StructInstance*> instanceList= listOfStructInstances();
00096 QSet<GLC_StructOccurence*> occurenceSet;
00097 const int size= instanceList.size();
00098 for (int i= 0; i < size; ++i)
00099 {
00100 QList<GLC_StructOccurence*> occurenceList= instanceList.at(i)->listOfStructOccurences();
00101 const int occurenceSize= occurenceList.size();
00102 for (int occIndex= 0; occIndex < occurenceSize; ++occIndex)
00103 {
00104 occurenceSet.insert(occurenceList.at(occIndex));
00105 }
00106 }
00107 return occurenceSet;
00108 }
00109
00111
00113
00114 void GLC_StructReference::setRepresentation(const GLC_3DRep& rep)
00115 {
00116
00117 {
00118 QSet<GLC_StructOccurence*> structOccurenceSet= this->setOfStructOccurence();
00119 QSet<GLC_StructOccurence*>::iterator iOcc= structOccurenceSet.begin();
00120 while (structOccurenceSet.constEnd() != iOcc)
00121 {
00122 (*iOcc)->remove3DViewInstance();
00123 ++iOcc;
00124 }
00125 }
00126
00127 if(NULL == m_pRepresentation)
00128 {
00129 m_pRepresentation= new GLC_3DRep(rep);
00130 }
00131 else
00132 {
00133 *(m_pRepresentation)= rep;
00134 }
00135
00136 if (m_pRepresentation->isLoaded())
00137 {
00138 QSet<GLC_StructOccurence*> structOccurenceSet= this->setOfStructOccurence();
00139 QSet<GLC_StructOccurence*>::iterator iOcc= structOccurenceSet.begin();
00140 while (structOccurenceSet.constEnd() != iOcc)
00141 {
00142 GLC_StructOccurence* pOccurence= *iOcc;
00143 Q_ASSERT(!pOccurence->has3DViewInstance());
00144 if (pOccurence->useAutomatic3DViewInstanceCreation())
00145 {
00146 pOccurence->create3DViewInstance();
00147 }
00148 ++iOcc;
00149 }
00150 }
00151 }
00152
00153 GLC_Rep* GLC_StructReference::representationHandle() const
00154 {
00155 Q_ASSERT(NULL != m_pRepresentation);
00156 return m_pRepresentation;
00157 }
00158
00159 QString GLC_StructReference::representationName() const
00160 {
00161 if (NULL != m_pRepresentation)
00162 {
00163 return m_pRepresentation->name();
00164 }
00165 else return QString();
00166 }
00167
00168 bool GLC_StructReference::representationIsLoaded() const
00169 {
00170 if (NULL != m_pRepresentation)
00171 {
00172 return m_pRepresentation->isLoaded();
00173 }
00174 else return false;
00175
00176 }
00177
00178 QString GLC_StructReference::representationFileName() const
00179 {
00180 if (NULL != m_pRepresentation)
00181 {
00182 return m_pRepresentation->fileName();
00183 }
00184 else return QString();
00185 }
00186
00187 bool GLC_StructReference::representationIsEmpty() const
00188 {
00189 if (NULL != m_pRepresentation)
00190 {
00191 return m_pRepresentation->isEmpty();
00192 }
00193 else return true;
00194
00195 }
00196
00197 void GLC_StructReference::setRepresentationName(const QString& representationName)
00198 {
00199 if (NULL != m_pRepresentation)
00200 {
00201 m_pRepresentation->setName(representationName);
00202 }
00203 }
00204
00205 bool GLC_StructReference::loadRepresentation()
00206 {
00207 Q_ASSERT(NULL != m_pRepresentation);
00208 if (m_pRepresentation->load())
00209 {
00210 QSet<GLC_StructOccurence*> structOccurenceSet= this->setOfStructOccurence();
00211 QSet<GLC_StructOccurence*>::iterator iOcc= structOccurenceSet.begin();
00212 while (structOccurenceSet.constEnd() != iOcc)
00213 {
00214 GLC_StructOccurence* pOccurence= *iOcc;
00215 Q_ASSERT(!pOccurence->has3DViewInstance());
00216 if (pOccurence->useAutomatic3DViewInstanceCreation())
00217 {
00218 pOccurence->create3DViewInstance();
00219 }
00220 ++iOcc;
00221 }
00222 return true;
00223 }
00224 else return false;
00225 }
00226
00227 bool GLC_StructReference::unloadRepresentation()
00228 {
00229 Q_ASSERT(NULL != m_pRepresentation);
00230 if (m_pRepresentation->unload())
00231 {
00232 QSet<GLC_StructOccurence*> structOccurenceSet= this->setOfStructOccurence();
00233 QSet<GLC_StructOccurence*>::iterator iOcc= structOccurenceSet.begin();
00234 while (structOccurenceSet.constEnd() != iOcc)
00235 {
00236 (*iOcc)->remove3DViewInstance();
00237 ++iOcc;
00238 }
00239 return true;
00240 }
00241 else return false;
00242 }
00243
00244 bool GLC_StructReference::addChild(GLC_StructOccurence* pOccurence)
00245 {
00246 if (hasStructInstance() && firstInstanceHandle()->hasStructOccurence())
00247 {
00248 GLC_StructOccurence* pCurrentChildOccurence= pOccurence;
00249
00250 QSet<GLC_StructInstance*>::iterator iInstance= m_SetOfInstance.begin();
00251 while (m_SetOfInstance.constEnd() != iInstance)
00252 {
00253 GLC_StructInstance* pCurrentInstance= *iInstance;
00254 QList<GLC_StructOccurence*> occurenceList= pCurrentInstance->listOfStructOccurences();
00255 const int occurenceCount= occurenceList.count();
00256 for (int i= 0; i < occurenceCount; ++i)
00257 {
00258 GLC_StructOccurence* pCurrentOccurence= occurenceList.at(i);
00259
00260 if ((i != 0) || (NULL == pCurrentChildOccurence))
00261 {
00262 pCurrentChildOccurence= pOccurence->clone(pCurrentOccurence->worldHandle(), true);
00263 }
00264
00265 pCurrentOccurence->addChild(pCurrentChildOccurence);
00266 }
00267 pCurrentChildOccurence= NULL;
00268 ++iInstance;
00269 }
00270 return true;
00271 }
00272 else
00273 {
00274 return false;
00275 }
00276 }
00277