GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_world.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_world.h"
26 #include "glc_structinstance.h"
27 #include "glc_structreference.h"
28 
30 : m_pWorldHandle(new GLC_WorldHandle())
31 , m_pRoot(new GLC_StructOccurence())
32 {
34 }
35 
37 : m_pWorldHandle(new GLC_WorldHandle())
38 , m_pRoot(pOcc)
39 {
41 }
42 
44 : m_pWorldHandle(world.m_pWorldHandle)
45 , m_pRoot(world.m_pRoot)
46 {
47  //qDebug() << "GLC_World::GLC_World() : " << (*m_pNumberOfWorld) << " " << this;
48  // Increment the number of world
50 
51 }
52 
54 {
55  // Decrement the number of world
57  if (m_pWorldHandle->isOrphan())
58  {
59  delete m_pRoot;
60  delete m_pWorldHandle;
61  }
62 }
63 
64 QList<GLC_StructOccurence *> GLC_World::minimumSelectedOccurenceList() const
65 {
66  QSet<GLC_StructOccurence *> selectedOccSet= QSet<GLC_StructOccurence *>::fromList(m_pWorldHandle->selectionSetHandle()->occurencesList());
67  QList<GLC_StructOccurence *> subject;
68  QSet<GLC_StructOccurence *>::ConstIterator iOcc= selectedOccSet.begin();
69  while (iOcc != selectedOccSet.constEnd())
70  {
71  QList<GLC_StructOccurence*> ancestorList= (*iOcc)->ancestorList();
72  const int count= ancestorList.count();
73  bool addOcc= true;
74  for (int i= 0; i < count; ++i)
75  {
76  if (selectedOccSet.contains(ancestorList.at(i)))
77  {
78  addOcc= false;
79  break;
80  }
81  }
82  if (addOcc) subject.append(*iOcc);
83 
84  ++iOcc;
85  }
86 
87  return subject;
88 }
89 
91 {
92  GLC_StructOccurence* pSubject= m_pRoot;
93  pSubject->makeOrphan();
94 
97 
98  return pSubject;
99 }
100 
102 {
103  Q_ASSERT(pOcc->isOrphan());
104  delete m_pRoot;
105  m_pRoot= pOcc;
106  m_pRoot->setWorldHandle(m_pWorldHandle);
107 }
108 
110 {
111  GLC_StructOccurence* pAnotherRoot= anotherWorld.rootOccurence();
112  if (pAnotherRoot->childCount() > 0)
113  {
114  QList<GLC_StructOccurence*> childs= pAnotherRoot->children();
115  const int size= childs.size();
116  for (int i= 0; i < size; ++i)
117  {
118  m_pRoot->addChild(childs.at(i)->clone(m_pWorldHandle, false));
119  }
121  }
122  else
123  {
124  m_pRoot->addChild(anotherWorld.rootOccurence()->clone(m_pWorldHandle, false));
125  }
126 }
127 
129 {
130  if ((this != &world) && (this->m_pWorldHandle != world.m_pWorldHandle))
131  {
132  // Decrement the number of world
134  if (m_pWorldHandle->isOrphan())
135  {
136  delete m_pRoot;
137  delete m_pWorldHandle;
138  }
139  m_pRoot= world.m_pRoot;
142  }
143  return *this;
144 }
145 
146 bool GLC_World::operator ==(const GLC_World &other) const
147 {
148  bool subject= this == &other;
149  subject= (subject || (this->m_pWorldHandle == other.m_pWorldHandle));
150 
151  return subject;
152 }

©2005-2013 Laurent Ribon