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, packaged on July 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 Lesser General Public License as published by 00011 the Free Software Foundation; either version 3 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 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser 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 00026 00027 #include "glc_structreference.h" 00028 #include "glc_structoccurence.h" 00029 00030 // Default constructor 00031 GLC_StructReference::GLC_StructReference(const QString& name) 00032 : m_SetOfInstance() 00033 , m_pRepresentation(NULL) 00034 , m_Name(name) 00035 , m_pAttributes(NULL) 00036 { 00037 00038 00039 } 00040 00041 // Create reference with representation 00042 GLC_StructReference::GLC_StructReference(GLC_Rep* pRep) 00043 : m_SetOfInstance() 00044 , m_pRepresentation(pRep) 00045 , m_Name(m_pRepresentation->name()) 00046 , m_pAttributes(NULL) 00047 { 00048 00049 } 00050 00051 // Copy constructor 00052 GLC_StructReference::GLC_StructReference(const GLC_StructReference& ref) 00053 : m_SetOfInstance() 00054 , m_pRepresentation(NULL) 00055 , m_Name(ref.m_Name) 00056 , m_pAttributes(new GLC_Attributes(*(ref.m_pAttributes))) 00057 { 00058 if (NULL != ref.m_pRepresentation) 00059 { 00060 m_pRepresentation= ref.m_pRepresentation->clone(); 00061 } 00062 } 00063 00065 GLC_StructReference& GLC_StructReference::operator=(const GLC_StructReference& ref) 00066 { 00067 if (this != &ref) 00068 { 00069 m_SetOfInstance.clear(); 00070 delete m_pAttributes; 00071 m_pAttributes= NULL; 00072 00073 m_Name= ref.m_Name; 00074 m_pAttributes= new GLC_Attributes(*(ref.m_pAttributes)); 00075 00076 if (NULL != ref.m_pRepresentation) 00077 { 00078 m_pRepresentation= ref.m_pRepresentation->clone(); 00079 } 00080 } 00081 return *this; 00082 } 00083 00084 GLC_StructReference::~GLC_StructReference() 00085 { 00086 delete m_pRepresentation; 00087 delete m_pAttributes; 00088 } 00089 00090 00092 // Get Functions 00094 00095 // Return the list of occurence of this reference 00096 QList<GLC_StructOccurence*> GLC_StructReference::listOfStructOccurence() const 00097 { 00098 QList<GLC_StructInstance*> instanceList= listOfStructInstances(); 00099 QSet<GLC_StructOccurence*> occurenceSet; 00100 const int size= instanceList.size(); 00101 for (int i= 0; i < size; ++i) 00102 { 00103 QList<GLC_StructOccurence*> occurenceList= instanceList.at(i)->listOfStructOccurences(); 00104 const int occurenceSize= occurenceList.size(); 00105 for (int occIndex= 0; occIndex < occurenceSize; ++occIndex) 00106 { 00107 occurenceSet.insert(occurenceList.at(occIndex)); 00108 } 00109 } 00110 return occurenceSet.toList(); 00111 } 00112 00114 // Set Functions 00116 // Set the reference representation 00117 void GLC_StructReference::setRepresentation(const GLC_3DRep& rep) 00118 { 00119 Q_ASSERT(NULL == m_pRepresentation); 00120 m_pRepresentation= new GLC_3DRep(rep); 00121 00122 // Update all occurence of this reference if exist 00123 if (hasStructInstance()) 00124 { 00125 GLC_StructInstance* pInstance= firstInstanceHandle(); 00126 if (pInstance->hasStructOccurence()) 00127 { 00128 QList<GLC_StructOccurence*> occurenceList= pInstance->listOfStructOccurences(); 00129 const int size= occurenceList.size(); 00130 for (int i= 0; i < size; ++i) 00131 { 00132 occurenceList[i]->checkForRepresentation(); 00133 } 00134 } 00135 } 00136 } 00137