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_structoccurence.h"
00026 #include "glc_3dviewcollection.h"
00027 #include "glc_structreference.h"
00028 #include "glc_worldhandle.h"
00029 #include "../glc_errorlog.h"
00030
00031
00032 GLC_StructOccurence::GLC_StructOccurence()
00033 : m_Uid(glc::GLC_GenID())
00034 , m_pWorldHandle(NULL)
00035 , m_pNumberOfOccurence(new int(1))
00036 , m_pStructInstance(new GLC_StructInstance())
00037 , m_pParent(NULL)
00038 , m_Childs()
00039 , m_AbsoluteMatrix()
00040 , m_OccurenceNumber(0)
00041 , m_IsVisible(true)
00042 , m_pRenderProperties(NULL)
00043 , m_AutomaticCreationOf3DViewInstance(true)
00044 {
00045
00046 m_pStructInstance->structOccurenceCreated(this);
00047 }
00048
00049
00050
00051 GLC_StructOccurence::GLC_StructOccurence(GLC_StructInstance* pStructInstance, GLC_WorldHandle* pWorldHandle, GLuint shaderId)
00052 : m_Uid(glc::GLC_GenID())
00053 , m_pWorldHandle(pWorldHandle)
00054 , m_pNumberOfOccurence(NULL)
00055 , m_pStructInstance(pStructInstance)
00056 , m_pParent(NULL)
00057 , m_Childs()
00058 , m_AbsoluteMatrix()
00059 , m_OccurenceNumber(0)
00060 , m_IsVisible(true)
00061 , m_pRenderProperties(NULL)
00062 , m_AutomaticCreationOf3DViewInstance(true)
00063 {
00064
00065 if (pStructInstance->hasStructOccurence())
00066 {
00067 GLC_StructOccurence* pFirstOccurence= pStructInstance->firstOccurenceHandle();
00068 m_pNumberOfOccurence= pFirstOccurence->m_pNumberOfOccurence;
00069 ++(*m_pNumberOfOccurence);
00070 QList<GLC_StructOccurence*> childs= pFirstOccurence->m_Childs;
00071 const int size= childs.size();
00072 for (int i= 0; i < size; ++i)
00073 {
00074 GLC_StructOccurence* pChild= childs.at(i)->clone(m_pWorldHandle, true);
00075 addChild(pChild);
00076 }
00077 }
00078 else
00079 {
00080 m_pNumberOfOccurence= new int(1);
00081 }
00082
00083 setName(m_pStructInstance->name());
00084
00085
00086 if (NULL != m_pWorldHandle)
00087 {
00088 m_pWorldHandle->addOccurence(this, shaderId);
00089 }
00090
00091
00092 updateAbsoluteMatrix();
00093
00094
00095 m_pStructInstance->structOccurenceCreated(this);
00096 }
00097
00098 GLC_StructOccurence::GLC_StructOccurence(GLC_3DRep* pRep)
00099 : m_Uid(glc::GLC_GenID())
00100 , m_pWorldHandle(NULL)
00101 , m_pNumberOfOccurence(new int(1))
00102 , m_pStructInstance(NULL)
00103 , m_pParent(NULL)
00104 , m_Childs()
00105 , m_AbsoluteMatrix()
00106 , m_OccurenceNumber(0)
00107 , m_IsVisible(true)
00108 , m_pRenderProperties(NULL)
00109 , m_AutomaticCreationOf3DViewInstance(true)
00110 {
00111 m_pStructInstance= new GLC_StructInstance(pRep);
00112 setName(m_pStructInstance->name());
00113
00114
00115 m_pStructInstance->structOccurenceCreated(this);
00116 }
00117
00118
00119 GLC_StructOccurence::GLC_StructOccurence(GLC_WorldHandle* pWorldHandle, const GLC_StructOccurence& structOccurence, bool shareInstance)
00120 : m_Uid(glc::GLC_GenID())
00121 , m_pWorldHandle(pWorldHandle)
00122 , m_pNumberOfOccurence(NULL)
00123 , m_pStructInstance(NULL)
00124 , m_pParent(NULL)
00125 , m_Childs()
00126 , m_AbsoluteMatrix(structOccurence.m_AbsoluteMatrix)
00127 , m_OccurenceNumber(0)
00128 , m_IsVisible(structOccurence.m_IsVisible)
00129 , m_pRenderProperties(NULL)
00130 , m_AutomaticCreationOf3DViewInstance(structOccurence.m_AutomaticCreationOf3DViewInstance)
00131 {
00132 if (shareInstance)
00133 {
00134 m_pStructInstance= structOccurence.m_pStructInstance;
00135 m_pNumberOfOccurence= structOccurence.m_pNumberOfOccurence;
00136 ++(*m_pNumberOfOccurence);
00137 }
00138 else
00139 {
00140 m_pNumberOfOccurence= new int(1);
00141 m_pStructInstance= new GLC_StructInstance(structOccurence.m_pStructInstance);
00142 }
00143
00144
00145
00146 GLuint shaderId= 0;
00147 bool instanceIsSelected= false;
00148 if ((NULL != m_pWorldHandle) && (NULL != structOccurence.m_pWorldHandle) && structOccurence.m_pWorldHandle->collection()->contains(structOccurence.id()))
00149 {
00150 GLC_3DViewInstance* p3DViewInstance= structOccurence.m_pWorldHandle->collection()->instanceHandle(structOccurence.id());
00151
00152 if(structOccurence.m_pWorldHandle->collection()->isInAShadingGroup(structOccurence.id()))
00153 {
00154 shaderId= structOccurence.m_pWorldHandle->collection()->shadingGroup(structOccurence.id());
00155 }
00156
00157 instanceIsSelected= p3DViewInstance->isSelected();
00158
00159 if (! p3DViewInstance->renderPropertiesHandle()->isDefault())
00160 {
00161 m_pRenderProperties= new GLC_RenderProperties(*(p3DViewInstance->renderPropertiesHandle()));
00162 }
00163 }
00164 else if (NULL != structOccurence.m_pRenderProperties)
00165 {
00166 m_pRenderProperties= new GLC_RenderProperties(*(structOccurence.m_pRenderProperties));
00167 }
00168
00169
00170 if (NULL != m_pWorldHandle)
00171 {
00172 m_pWorldHandle->addOccurence(this, instanceIsSelected, shaderId);
00173 if (NULL != m_pRenderProperties)
00174 {
00175 m_pWorldHandle->collection()->instanceHandle(id())->setRenderProperties(*m_pRenderProperties);
00176 delete m_pRenderProperties;
00177 m_pRenderProperties= NULL;
00178 }
00179 }
00180
00181
00182 updateAbsoluteMatrix();
00183
00184
00185
00186 const int size= structOccurence.childCount();
00187 for (int i= 0; i < size; ++i)
00188 {
00189 GLC_StructOccurence* pChild= structOccurence.child(i)->clone(m_pWorldHandle, true);
00190 addChild(pChild);
00191 }
00192 updateChildrenAbsoluteMatrix();
00193
00194 m_pStructInstance->structOccurenceCreated(this);
00195 }
00196
00197
00198 GLC_StructOccurence::~GLC_StructOccurence()
00199 {
00200
00201 Q_ASSERT(m_pNumberOfOccurence != NULL);
00202
00203 if (NULL != m_pWorldHandle)
00204 {
00205 m_pWorldHandle->removeOccurence(this);
00206 }
00207
00208
00209 const int size= m_Childs.size();
00210 for (int i= 0; i < size; ++i)
00211 {
00212 GLC_StructOccurence* pChild= m_Childs.first();
00213 removeChild(pChild);
00214 delete pChild;
00215 }
00216
00217 if ((--(*m_pNumberOfOccurence)) == 0)
00218 {
00219 delete m_pStructInstance;
00220 delete m_pNumberOfOccurence;
00221 }
00222 else
00223 {
00224 m_pStructInstance->structOccurenceDeleted(this);
00225 if (!m_pStructInstance->hasStructOccurence())
00226 {
00227
00228 QStringList errorList;
00229 errorList << "StructOccurence count error";
00230 errorList << ("ref name = " + m_pStructInstance->structReference()->name());
00231 GLC_ErrorLog::addError(errorList);
00232
00233 delete m_pStructInstance;
00234
00235 }
00236 }
00237
00238 delete m_pRenderProperties;
00239 }
00240
00242
00244
00245 bool GLC_StructOccurence::hasRepresentation() const
00246 {
00247 if ((NULL != m_pStructInstance) && (m_pStructInstance->hasStructOccurence()))
00248 {
00249 return this->structReference()->hasRepresentation();
00250 }
00251 else return false;
00252 }
00253
00254 bool GLC_StructOccurence::has3DViewInstance() const
00255 {
00256 if ( NULL != m_pWorldHandle)
00257 {
00258 return m_pWorldHandle->collection()->contains(m_Uid);
00259 }
00260 else return false;
00261 }
00262
00263 bool GLC_StructOccurence::canBeAddedToChildren(GLC_StructOccurence* pOccurence) const
00264 {
00265 bool canBeAdded= false;
00266 if ((NULL != m_pStructInstance) && (m_pStructInstance->hasStructOccurence()) && (NULL != pOccurence->m_pStructInstance) && (NULL != pOccurence->structReference()))
00267 {
00268 if (this->structReference() != pOccurence->structReference())
00269 {
00270 QSet<GLC_StructReference*> thisRefSet= GLC_StructOccurence::parentsReferences(this);
00271 thisRefSet << this->structReference();
00272 QSet<GLC_StructReference*> childRefSet= pOccurence->childrenReferences();
00273
00274 canBeAdded= thisRefSet == (thisRefSet - childRefSet);
00275 }
00276 }
00277 else
00278 {
00279 canBeAdded= true;
00280 }
00281 return canBeAdded;
00282 }
00283
00284 QList<GLC_StructOccurence*> GLC_StructOccurence::subOccurenceList() const
00285 {
00286 QList<GLC_StructOccurence*> subOccurence;
00287 const int childCount= m_Childs.size();
00288 for (int i= 0; i < childCount; ++i)
00289 {
00290 GLC_StructOccurence* pCurrentChild= m_Childs.at(i);
00291 if (pCurrentChild->hasChild())
00292 {
00293 subOccurence.append(pCurrentChild->subOccurenceList());
00294 }
00295 else
00296 {
00297 subOccurence.append(pCurrentChild);
00298 }
00299 }
00300
00301 return subOccurence;
00302 }
00303
00304 unsigned int GLC_StructOccurence::numberOfFaces() const
00305 {
00306 unsigned int result= 0;
00307 if (hasRepresentation())
00308 {
00309 result= structInstance()->structReference()->numberOfFaces();
00310 }
00311
00312 const int size= m_Childs.size();
00313 for (int i= 0; i < size; ++i)
00314 {
00315 result+= m_Childs.at(i)->numberOfFaces();
00316 }
00317
00318 return result;
00319 }
00320
00321 unsigned int GLC_StructOccurence::numberOfVertex() const
00322 {
00323 unsigned int result= 0;
00324 if (hasRepresentation())
00325 {
00326 result= structInstance()->structReference()->numberOfVertex();
00327 }
00328 const int size= m_Childs.size();
00329 for (int i= 0; i < size; ++i)
00330 {
00331 result+= m_Childs.at(i)->numberOfVertex();
00332 }
00333
00334 return result;
00335 }
00336
00337
00338 unsigned int GLC_StructOccurence::numberOfMaterials() const
00339 {
00340 unsigned int result= 0;
00341 QSet<GLC_Material*> materialSet;
00342 if (hasRepresentation())
00343 {
00344 result= structInstance()->structReference()->numberOfMaterials();
00345 }
00346
00347 const int size= m_Childs.size();
00348 for (int i= 0; i < size; ++i)
00349 {
00350 materialSet.unite(m_Childs.at(i)->materialSet());
00351 }
00352 result= static_cast<unsigned int>(materialSet.size());
00353
00354 return result;
00355 }
00356
00357
00358 QSet<GLC_Material*> GLC_StructOccurence::materialSet() const
00359 {
00360 QSet<GLC_Material*> materialSet;
00361 if (hasRepresentation())
00362 {
00363 materialSet= structInstance()->structReference()->materialSet();
00364 }
00365
00366 const int size= m_Childs.size();
00367 for (int i= 0; i < size; ++i)
00368 {
00369 materialSet.unite(m_Childs.at(i)->materialSet());
00370 }
00371
00372 return materialSet;
00373 }
00374
00375
00376 GLC_StructOccurence* GLC_StructOccurence::clone(GLC_WorldHandle* pWorldHandle, bool shareInstance) const
00377 {
00378 return new GLC_StructOccurence(pWorldHandle, *this, shareInstance);
00379 }
00380
00381
00382 bool GLC_StructOccurence::isVisible() const
00383 {
00384 bool isHidden= true;
00385
00386 if ((NULL != m_pWorldHandle) && m_pWorldHandle->collection()->contains(m_Uid))
00387 {
00388 isHidden= !m_pWorldHandle->collection()->instanceHandle(m_Uid)->isVisible();
00389 }
00390 else if (childCount() > 0)
00391 {
00392 const int size= childCount();
00393 int i= 0;
00394 while ((i < size) && isHidden)
00395 {
00396 isHidden= isHidden && !child(i)->isVisible();
00397 ++i;
00398 }
00399 }
00400 else
00401 {
00402 isHidden= !m_IsVisible;
00403 }
00404 return !isHidden;
00405 }
00406
00407
00408 GLC_BoundingBox GLC_StructOccurence::boundingBox() const
00409 {
00410 GLC_BoundingBox boundingBox;
00411
00412 if (NULL != m_pWorldHandle)
00413 {
00414 if (has3DViewInstance())
00415 {
00416 Q_ASSERT(m_pWorldHandle->collection()->contains(id()));
00417 boundingBox= m_pWorldHandle->collection()->instanceHandle(id())->boundingBox();
00418 }
00419 else
00420 {
00421 if (hasChild())
00422 {
00423 QList<GLC_StructOccurence*> childrenList= children();
00424 const int size= childrenList.size();
00425
00426 for (int i= 0; i < size; ++i)
00427 {
00428 boundingBox.combine(childrenList.at(i)->boundingBox());
00429 }
00430 }
00431 }
00432 }
00433
00434 return boundingBox;
00435 }
00436
00437 unsigned int GLC_StructOccurence::nodeCount() const
00438 {
00439 unsigned int result= 1;
00440 const int size= m_Childs.size();
00441 for (int i= 0; i < size; ++i)
00442 {
00443 result+= m_Childs.at(i)->nodeCount();
00444 }
00445 return result;
00446 }
00447
00448 QSet<GLC_StructReference*> GLC_StructOccurence::childrenReferences() const
00449 {
00450 QSet<GLC_StructReference*> refChildrenSet;
00451 const int childCount= m_Childs.size();
00452 for (int i= 0; i < childCount; ++i)
00453 {
00454 GLC_StructOccurence* pCurrentChild= m_Childs.at(i);
00455 if ((NULL != pCurrentChild->structInstance()) && (NULL != pCurrentChild->structReference()))
00456 {
00457 refChildrenSet << pCurrentChild->structReference();
00458 }
00459 }
00460
00461 return refChildrenSet;
00462 }
00463
00464 QSet<GLC_StructReference*> GLC_StructOccurence::parentsReferences(const GLC_StructOccurence* pOccurence)
00465 {
00466 QSet<GLC_StructReference*> parentSet;
00467 GLC_StructOccurence* pParent= pOccurence->parent();
00468 if (NULL != pParent)
00469 {
00470 if ((NULL != pParent->structInstance()) && (NULL != pParent->structReference()))
00471 {
00472 parentSet << pParent->structReference();
00473 parentSet.unite(GLC_StructOccurence::parentsReferences(pParent));
00474 }
00475 }
00476
00477 return parentSet;
00478 }
00479
00481
00483
00484
00485 GLC_StructOccurence* GLC_StructOccurence::updateAbsoluteMatrix()
00486 {
00487 if (NULL != m_pParent)
00488 {
00489 m_AbsoluteMatrix= m_pParent->absoluteMatrix() * m_pStructInstance->relativeMatrix();
00490 }
00491 else
00492 {
00493 m_AbsoluteMatrix= m_pStructInstance->relativeMatrix();
00494 }
00495
00496
00497 if ((NULL != m_pWorldHandle) && m_pWorldHandle->collection()->contains(m_Uid))
00498 {
00499 m_pWorldHandle->collection()->instanceHandle(m_Uid)->setMatrix(m_AbsoluteMatrix);
00500 }
00501 return this;
00502 }
00503
00504
00505 GLC_StructOccurence* GLC_StructOccurence::updateChildrenAbsoluteMatrix()
00506 {
00507 updateAbsoluteMatrix();
00508 const int size= m_Childs.size();
00509 for (int i= 0; i < size; ++i)
00510 {
00511 m_Childs[i]->updateChildrenAbsoluteMatrix();
00512 }
00513 return this;
00514 }
00515
00516
00517 void GLC_StructOccurence::addChild(GLC_StructOccurence* pChild)
00518 {
00519 Q_ASSERT(pChild->isOrphan());
00520 Q_ASSERT((NULL == pChild->m_pWorldHandle) || (m_pWorldHandle == pChild->m_pWorldHandle));
00521
00522
00523
00524
00525 m_Childs.append(pChild);
00526 pChild->m_pParent= this;
00527 if (NULL == pChild->m_pWorldHandle)
00528 {
00529 pChild->setWorldHandle(m_pWorldHandle);
00530 }
00531 pChild->updateChildrenAbsoluteMatrix();
00532 }
00533
00534
00535 GLC_StructOccurence* GLC_StructOccurence::addChild(GLC_StructInstance* pInstance)
00536 {
00537 GLC_StructOccurence* pOccurence;
00538 pOccurence= new GLC_StructOccurence(pInstance, m_pWorldHandle);
00539
00540 addChild(pOccurence);
00541
00542 return pOccurence;
00543 }
00544
00545
00546 void GLC_StructOccurence::makeOrphan()
00547 {
00548
00549
00550 Q_ASSERT(!isOrphan());
00551 m_pParent->removeChild(this);
00552
00553 }
00554
00555
00556 bool GLC_StructOccurence::removeChild(GLC_StructOccurence* pChild)
00557 {
00558 Q_ASSERT(pChild->m_pParent == this);
00559 Q_ASSERT(m_Childs.contains(pChild));
00560 pChild->m_pParent= NULL;
00561 pChild->detach();
00562
00563 return m_Childs.removeOne(pChild);
00564 }
00565
00566
00567 void GLC_StructOccurence::detach()
00568 {
00569 if (NULL != m_pWorldHandle)
00570 {
00571
00572 if (m_pWorldHandle->collection()->contains(m_Uid))
00573 {
00574 GLC_3DViewInstance* pInstance= m_pWorldHandle->collection()->instanceHandle(m_Uid);
00575 if (!pInstance->renderPropertiesHandle()->isDefault())
00576 {
00577 Q_ASSERT(NULL == m_pRenderProperties);
00578 m_pRenderProperties= new GLC_RenderProperties(*(pInstance->renderPropertiesHandle()));
00579 }
00580 }
00581 m_pWorldHandle->removeOccurence(this);
00582 m_pWorldHandle= NULL;
00583 if (!m_Childs.isEmpty())
00584 {
00585 const int size= m_Childs.size();
00586 for (int i= 0; i < size; ++i)
00587 {
00588 m_Childs[i]->detach();
00589 }
00590 }
00591 }
00592 }
00593
00594
00595 void GLC_StructOccurence::reverseNormals()
00596 {
00597 if (has3DViewInstance())
00598 {
00599 m_pWorldHandle->collection()->instanceHandle(id())->reverseGeometriesNormals();
00600 }
00601 }
00602
00603
00604 bool GLC_StructOccurence::create3DViewInstance()
00605 {
00606 bool creationSuccess= false;
00607 if ((NULL != m_pWorldHandle) && hasRepresentation())
00608 {
00609 GLC_3DRep* p3DRep= dynamic_cast<GLC_3DRep*>(structReference()->representationHandle());
00610 if (NULL != p3DRep)
00611 {
00612 GLC_3DViewInstance instance(*p3DRep);
00613 instance.setName(name());
00614
00615 instance.setId(id());
00616 creationSuccess= m_pWorldHandle->collection()->add(instance);
00617 m_pWorldHandle->collection()->setVisibility(m_Uid, m_IsVisible);
00618 }
00619 }
00620 return creationSuccess;
00621 }
00622
00623 bool GLC_StructOccurence::remove3DViewInstance()
00624 {
00625 if (NULL != m_pWorldHandle)
00626 {
00627 return m_pWorldHandle->collection()->remove(m_Uid);
00628 }
00629 else return false;
00630 }
00631
00632
00633 void GLC_StructOccurence::setWorldHandle(GLC_WorldHandle* pWorldHandle)
00634 {
00635
00636 if (m_pWorldHandle == pWorldHandle) return;
00637
00638 if (NULL != m_pWorldHandle)
00639 {
00640 m_pWorldHandle->removeOccurence(this);
00641 }
00642
00643 m_pWorldHandle= pWorldHandle;
00644
00645 if (NULL != m_pWorldHandle)
00646 {
00647 m_pWorldHandle->addOccurence(this);
00648 m_pWorldHandle->collection()->setVisibility(m_Uid, m_IsVisible);
00649
00650 const int size= m_Childs.size();
00651 for (int i= 0; i < size; ++i)
00652 {
00653 m_Childs[i]->setWorldHandle(m_pWorldHandle);
00654 }
00655 }
00656 }
00657
00658
00659 bool GLC_StructOccurence::loadRepresentation()
00660 {
00661 Q_ASSERT(!this->has3DViewInstance());
00662
00663 bool loadSuccess= false;
00664 if (hasRepresentation())
00665 {
00666 GLC_StructReference* pReference= this->structReference();
00667 if (pReference->representationIsLoaded())
00668 {
00669 loadSuccess= create3DViewInstance();
00670 }
00671 else
00672 {
00673 loadSuccess= m_pStructInstance->structReference()->loadRepresentation();
00674 if (loadSuccess && !m_AutomaticCreationOf3DViewInstance)
00675 {
00676 loadSuccess= create3DViewInstance();
00677 }
00678 }
00679 }
00680
00681 return loadSuccess;
00682 }
00683
00684
00685 bool GLC_StructOccurence::unloadRepresentation()
00686 {
00687 bool unloadResult= false;
00688 if (hasRepresentation())
00689 {
00690 GLC_StructReference* pRef= this->structReference();
00691 if (pRef->representationIsLoaded())
00692 {
00693 if (this->has3DViewInstance())
00694 {
00695 unloadResult= m_pWorldHandle->collection()->remove(m_Uid);
00696 QSet<GLC_StructOccurence*> occurenceSet= pRef->setOfStructOccurence();
00697 QSet<GLC_StructOccurence*>::const_iterator iOcc= occurenceSet.constBegin();
00698 bool unloadReferenceRep= true;
00699 while (occurenceSet.constEnd() != iOcc)
00700 {
00701 unloadReferenceRep= unloadReferenceRep && !(*iOcc)->has3DViewInstance();
00702 ++iOcc;
00703 }
00704 if (unloadReferenceRep)
00705 {
00706 pRef->unloadRepresentation();
00707 }
00708 }
00709 }
00710 }
00711 return unloadResult;
00712 }
00713
00714 unsigned int GLC_StructOccurence::updateOccurenceNumber(unsigned int n)
00715 {
00716 m_OccurenceNumber= n++;
00717 const int childCount= m_Childs.size();
00718 for (int i= 0; i < childCount; ++i)
00719 {
00720 n= m_Childs[i]->updateOccurenceNumber(n);
00721 }
00722 return n;
00723 }
00724
00725 void GLC_StructOccurence::setVisibility(bool visibility)
00726 {
00727 m_IsVisible= visibility;
00728 if (has3DViewInstance())
00729 {
00730 m_pWorldHandle->collection()->setVisibility(m_Uid, m_IsVisible);
00731 }
00732 const int childCount= m_Childs.size();
00733 for (int i= 0; i < childCount; ++i)
00734 {
00735 m_Childs[i]->setVisibility(m_IsVisible);
00736 }
00737 }
00738
00739 void GLC_StructOccurence::setRenderProperties(const GLC_RenderProperties& renderProperties)
00740 {
00741 delete m_pRenderProperties;
00742 if (has3DViewInstance())
00743 {
00744 m_pWorldHandle->collection()->instanceHandle(m_Uid)->setRenderProperties(renderProperties);
00745 }
00746 else if (hasChild())
00747 {
00748 const int childCount= m_Childs.size();
00749 for (int i= 0; i < childCount; ++i)
00750 {
00751 m_Childs[i]->setRenderProperties(renderProperties);
00752 }
00753 }
00754 else
00755 {
00756 m_pRenderProperties= new GLC_RenderProperties(renderProperties);
00757 }
00758 }
00759
00760 void GLC_StructOccurence::removeEmptyChildren()
00761 {
00762 QList<GLC_StructOccurence*>::iterator iChild= m_Childs.begin();
00763 while (m_Childs.constEnd() != iChild)
00764 {
00765 if (!((*iChild)->hasChild()) && !((*iChild)->hasRepresentation()))
00766 {
00767 delete *iChild;
00768 iChild= m_Childs.erase(iChild);
00769 }
00770 else
00771 {
00772 (*iChild)->removeEmptyChildren();
00773 ++iChild;
00774 }
00775 }
00776 }
00777
00778 void GLC_StructOccurence::setReference(GLC_StructReference* pRef)
00779 {
00780 Q_ASSERT(m_pStructInstance->structReference() == NULL);
00781 Q_ASSERT((*m_pNumberOfOccurence) == 1);
00782
00783 if (pRef->hasStructInstance())
00784 {
00785 GLC_StructInstance* pExistingInstance= pRef->firstInstanceHandle();
00786 if (pExistingInstance->hasStructOccurence())
00787 {
00788 GLC_StructOccurence* pFirstOccurence= pExistingInstance->firstOccurenceHandle();
00789 QList<GLC_StructOccurence*> childs= pFirstOccurence->m_Childs;
00790 const int size= childs.size();
00791 for (int i= 0; i < size; ++i)
00792 {
00793 GLC_StructOccurence* pChild= childs.at(i)->clone(m_pWorldHandle, true);
00794 addChild(pChild);
00795 }
00796
00797 QList<GLC_StructInstance*> instances= pRef->listOfStructInstances();
00798 const int instanceCount= instances.size();
00799 int i= 0;
00800 bool continu= true;
00801 while (continu && (i < instanceCount))
00802 {
00803 if (m_pStructInstance == instances.at(i))
00804 {
00805 continu= false;
00806 delete m_pNumberOfOccurence;
00807 m_pNumberOfOccurence= instances.at(i)->firstOccurenceHandle()->m_pNumberOfOccurence;
00808 ++(*m_pNumberOfOccurence);
00809 }
00810 ++i;
00811 }
00812 }
00813 }
00814
00815 m_pStructInstance->setReference(pRef);
00816 }