GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_worldhandle.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 
23 #include "glc_worldhandle.h"
24 #include "glc_structreference.h"
25 #include <QSet>
26 
28 : m_Collection()
29 , m_NumberOfWorld(1)
30 , m_OccurenceHash()
31 , m_UpVector(glc::Z_AXIS)
32 , m_SelectionSet(this)
33 {
34 
35 }
36 
38 {
39 
40 }
41 
42 // Return the list of instance
43 QList<GLC_StructInstance*> GLC_WorldHandle::instances() const
44 {
45  QSet<GLC_StructInstance*> instancesSet;
46  QHash<GLC_uint, GLC_StructOccurence*>::const_iterator iOccurence= m_OccurenceHash.constBegin();
47  while (iOccurence != m_OccurenceHash.constEnd())
48  {
49  instancesSet.insert(iOccurence.value()->structInstance());
50  ++iOccurence;
51  }
52  return instancesSet.toList();
53 }
54 
55 // Return the list of Reference
56 QList<GLC_StructReference*> GLC_WorldHandle::references() const
57 {
58  QSet<GLC_StructReference*> referencesSet;
59  QHash<GLC_uint, GLC_StructOccurence*>::const_iterator iOccurence= m_OccurenceHash.constBegin();
60  while (iOccurence != m_OccurenceHash.constEnd())
61  {
62  referencesSet.insert(iOccurence.value()->structReference());
63  ++iOccurence;
64  }
65  return referencesSet.toList();
66 }
67 
68 // Return the number of body
70 {
71  QList<GLC_StructReference*> referenceList(references());
72  const int size= referenceList.size();
73  int numberOfBody= 0;
74  for (int i= 0; i < size; ++i)
75  {
76  numberOfBody+= referenceList.at(i)->numberOfBody();
77  }
78  return numberOfBody;
79 }
80 
82 {
83  QList<GLC_StructReference*> referenceList(references());
84  const int size= referenceList.size();
85  int count= 0;
86  for (int i= 0; i < size; ++i)
87  {
88  if (referenceList.at(i)->hasRepresentation()) ++count;
89  }
90  return count;
91 
92 }
93 
94 // An Occurence has been added
95 void GLC_WorldHandle::addOccurence(GLC_StructOccurence* pOccurence, bool isSelected, GLuint shaderId)
96 {
97  Q_ASSERT(!m_OccurenceHash.contains(pOccurence->id()));
98  m_OccurenceHash.insert(pOccurence->id(), pOccurence);
99  GLC_StructReference* pRef= pOccurence->structReference();
100  Q_ASSERT(NULL != pRef);
101 
102  // Add instance representation in the collection
103  if (pOccurence->useAutomatic3DViewInstanceCreation() && pRef->representationIsLoaded())
104  {
105  pOccurence->create3DViewInstance(shaderId);
106  if (isSelected) select(pOccurence->id());
107  }
108 }
109 
110 // An Occurence has been removed
112 {
113  Q_ASSERT(m_OccurenceHash.contains(pOccurence->id()));
114  // Remove the occurence from the selection set
115  m_SelectionSet.remove(pOccurence);
116  // Remove the occurence from the main occurence hash table
117  m_OccurenceHash.remove(pOccurence->id());
118  // Remove instance representation from the collection
119  m_Collection.remove(pOccurence->id());
120 }
121 
123 {
124  Q_ASSERT(m_OccurenceHash.contains(occurenceId));
125  m_SelectionSet.insert(occurenceId);
126  m_Collection.select(occurenceId);
127 
128  const GLC_StructOccurence* pSelectedOccurence= m_OccurenceHash.value(occurenceId);
129  if (pSelectedOccurence->hasChild())
130  {
131  QList<GLC_StructOccurence*> subOccurenceList= pSelectedOccurence->subOccurenceList();
132  const int subOccurenceCount= subOccurenceList.size();
133  for (int i= 0; i < subOccurenceCount; ++i)
134  {
135  const GLC_uint currentOccurenceId= subOccurenceList.at(i)->id();
136  if (m_Collection.contains(currentOccurenceId))
137  {
138  m_Collection.select(currentOccurenceId);
139  }
140  }
141  }
142 }
143 
144 void GLC_WorldHandle::unselect(GLC_uint occurenceId, bool propagate)
145 {
146  Q_ASSERT(m_OccurenceHash.contains(occurenceId));
147  m_SelectionSet.remove(occurenceId);
148  m_Collection.unselect(occurenceId);
149 
150  const GLC_StructOccurence* pSelectedOccurence= m_OccurenceHash.value(occurenceId);
151  if (propagate && pSelectedOccurence->hasChild())
152  {
153  QList<GLC_StructOccurence*> subOccurenceList= pSelectedOccurence->subOccurenceList();
154  const int subOccurenceCount= subOccurenceList.size();
155  for (int i= 0; i < subOccurenceCount; ++i)
156  {
157  const GLC_uint currentOccurenceId= subOccurenceList.at(i)->id();
158  m_Collection.unselect(currentOccurenceId);
159  }
160  }
161 }
162 
164 {
165  m_Collection.selectAll(allShowState);
166  QList<GLC_uint> selectedId= m_Collection.selection()->keys();
168  const int selectionCount= selectedId.count();
169  for (int i= 0; i < selectionCount; ++i)
170  {
171  m_SelectionSet.insert(selectedId.at(i));
172  }
173 }
174 
176 {
179 }
180 
182 {
183  QList<GLC_3DViewInstance*> selected3dviewInstance= m_Collection.selection()->values();
184  const int instanceCount= selected3dviewInstance.count();
185  for(int i= 0; i < instanceCount; ++i)
186  {
187  GLC_3DViewInstance* pCurrentInstance= selected3dviewInstance.at(i);
188  pCurrentInstance->setVisibility(!pCurrentInstance->isVisible());
189  }
190 }
191 
193 {
194  QList<GLC_3DViewInstance*> selected3dviewInstance= m_Collection.selection()->values();
195  const int instanceCount= selected3dviewInstance.count();
196  for(int i= 0; i < instanceCount; ++i)
197  {
198  GLC_3DViewInstance* pCurrentInstance= selected3dviewInstance.at(i);
199  pCurrentInstance->setVisibility(isVisible);
200  }
201 }
202 

©2005-2013 Laurent Ribon