GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_structreference.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21 *****************************************************************************/
22 
24 
25 #include "glc_structreference.h"
26 #include "glc_structoccurence.h"
27 
28 // Default constructor
30 : m_SetOfInstance()
31 , m_pRepresentation(NULL)
32 , m_Name(name)
33 , m_pAttributes(NULL)
34 {
35 
36 
37 }
38 
39 // Create reference with representation
41 : m_SetOfInstance()
42 , m_pRepresentation(pRep)
43 , m_Name(m_pRepresentation->name())
44 , m_pAttributes(NULL)
45 {
46 
47 }
48 
49 // Copy constructor
51 : m_SetOfInstance()
52 , m_pRepresentation(NULL)
53 , m_Name(ref.m_Name)
54 , m_pAttributes(new GLC_Attributes(*(ref.m_pAttributes)))
55 {
56  if (NULL != ref.m_pRepresentation)
57  {
59  }
60 }
61 
64 {
65  if (this != &ref)
66  {
67  m_SetOfInstance.clear();
68  delete m_pAttributes;
69  m_pAttributes= NULL;
70 
71  m_Name= ref.m_Name;
73 
74  if (NULL != ref.m_pRepresentation)
75  {
77  }
78  }
79  return *this;
80 }
81 
83 {
84  delete m_pRepresentation;
85  delete m_pAttributes;
86 }
87 
88 
90 // Get Functions
92 
93 QSet<GLC_StructOccurence*> GLC_StructReference::setOfStructOccurence() const
94 {
95  QList<GLC_StructInstance*> instanceList= listOfStructInstances();
96  QSet<GLC_StructOccurence*> occurenceSet;
97  const int size= instanceList.size();
98  for (int i= 0; i < size; ++i)
99  {
100  QList<GLC_StructOccurence*> occurenceList= instanceList.at(i)->listOfStructOccurences();
101  const int occurenceSize= occurenceList.size();
102  for (int occIndex= 0; occIndex < occurenceSize; ++occIndex)
103  {
104  occurenceSet.insert(occurenceList.at(occIndex));
105  }
106  }
107  return occurenceSet;
108 }
109 
111 // Set Functions
113 // Set the reference representation
115 {
116  // Unload occurence representation
117  {
118  QSet<GLC_StructOccurence*> structOccurenceSet= this->setOfStructOccurence();
119  QSet<GLC_StructOccurence*>::iterator iOcc= structOccurenceSet.begin();
120  while (structOccurenceSet.constEnd() != iOcc)
121  {
122  (*iOcc)->remove3DViewInstance();
123  ++iOcc;
124  }
125  }
126 
127  if(NULL == m_pRepresentation)
128  {
129  m_pRepresentation= new GLC_3DRep(rep);
130  }
131  else
132  {
133  *(m_pRepresentation)= rep;
134  }
135 
137  {
138  QSet<GLC_StructOccurence*> structOccurenceSet= this->setOfStructOccurence();
139  QSet<GLC_StructOccurence*>::iterator iOcc= structOccurenceSet.begin();
140  while (structOccurenceSet.constEnd() != iOcc)
141  {
142  GLC_StructOccurence* pOccurence= *iOcc;
143  Q_ASSERT(!pOccurence->has3DViewInstance());
144  if (pOccurence->useAutomatic3DViewInstanceCreation())
145  {
146  pOccurence->create3DViewInstance();
147  }
148  ++iOcc;
149  }
150  }
151 }
152 
154 {
155  Q_ASSERT(NULL != m_pRepresentation);
156  return m_pRepresentation;
157 }
158 
160 {
161  if (NULL != m_pRepresentation)
162  {
163  return m_pRepresentation->name();
164  }
165  else return QString();
166 }
167 
169 {
170  if (NULL != m_pRepresentation)
171  {
172  return m_pRepresentation->isLoaded();
173  }
174  else return false;
175 
176 }
177 
179 {
180  if (NULL != m_pRepresentation)
181  {
182  return m_pRepresentation->fileName();
183  }
184  else return QString();
185 }
186 
188 {
189  if (NULL != m_pRepresentation)
190  {
191  return m_pRepresentation->isEmpty();
192  }
193  else return true;
194 
195 }
196 
197 void GLC_StructReference::setRepresentationName(const QString& representationName)
198 {
199  if (NULL != m_pRepresentation)
200  {
201  m_pRepresentation->setName(representationName);
202  }
203 }
204 
206 {
207  Q_ASSERT(NULL != m_pRepresentation);
208  if (m_pRepresentation->load())
209  {
210  QSet<GLC_StructOccurence*> structOccurenceSet= this->setOfStructOccurence();
211  QSet<GLC_StructOccurence*>::iterator iOcc= structOccurenceSet.begin();
212  while (structOccurenceSet.constEnd() != iOcc)
213  {
214  GLC_StructOccurence* pOccurence= *iOcc;
215  Q_ASSERT(!pOccurence->has3DViewInstance());
216  if (pOccurence->useAutomatic3DViewInstanceCreation())
217  {
218  pOccurence->create3DViewInstance();
219  }
220  ++iOcc;
221  }
222  return true;
223  }
224  else return false;
225 }
226 
228 {
229  Q_ASSERT(NULL != m_pRepresentation);
230  if (m_pRepresentation->unload())
231  {
232  QSet<GLC_StructOccurence*> structOccurenceSet= this->setOfStructOccurence();
233  QSet<GLC_StructOccurence*>::iterator iOcc= structOccurenceSet.begin();
234  while (structOccurenceSet.constEnd() != iOcc)
235  {
236  (*iOcc)->remove3DViewInstance();
237  ++iOcc;
238  }
239  return true;
240  }
241  else return false;
242 }
243 
244 QList<GLC_StructOccurence*> GLC_StructReference::addChild(GLC_StructOccurence* pOccurence)
245 {
246  QList<GLC_StructOccurence*> subject;
247  if (hasStructInstance() && firstInstanceHandle()->hasStructOccurence())
248  {
249  QList<GLC_StructOccurence*> parentOccurences= listOfStructOccurence();
250  const int parentCount= parentOccurences.count();
251  GLC_StructInstance* pNewInstance= NULL;
252  for (int i= 0; i < parentCount; ++i)
253  {
254  GLC_StructOccurence* pCurrentParent= parentOccurences.at(i);
255  GLC_StructOccurence* pNewChild= NULL;
256  if (NULL == pNewInstance)
257  {
258  pNewChild= pOccurence;
259  pNewInstance= pNewChild->structInstance();
260  pCurrentParent->addChild(pNewChild);
261  }
262  else
263  {
264  pNewChild= pCurrentParent->addChild(pNewInstance);
265  }
266  subject.append(pNewChild);
267  }
268  }
269 
270  return subject;
271 }
272 

©2005-2013 Laurent Ribon