21#include <Qt3DCore/QEntity>
25QgsChunkNode::QgsChunkNode(
const QgsChunkNodeId &nodeId,
const QgsBox3D &box3D,
float error, QgsChunkNode *parent )
32QgsChunkNode::~QgsChunkNode()
34 Q_ASSERT( mState == Skeleton );
35 Q_ASSERT( !mLoaderQueueEntry );
36 Q_ASSERT( !mReplacementQueueEntry );
39 qDeleteAll( mChildren );
42bool QgsChunkNode::allChildChunksResident( QTime currentTime )
const
44 Q_ASSERT( mChildrenPopulated );
45 for (
int i = 0; i < childCount(); ++i )
47 if ( mChildren[i]->mHasData && !mChildren[i]->mEntity )
49 Q_UNUSED( currentTime )
56void QgsChunkNode::populateChildren(
const QVector<QgsChunkNode *> &children )
58 Q_ASSERT( !mChildrenPopulated );
59 mChildrenPopulated =
true;
61 mCreatingChildren =
false;
64int QgsChunkNode::level()
const
67 QgsChunkNode *p = mParent;
76QList<QgsChunkNode *> QgsChunkNode::descendants()
78 QList<QgsChunkNode *> lst;
81 for (
int i = 0; i < childCount(); ++i )
83 lst << mChildren[i]->descendants();
89void QgsChunkNode::setQueuedForLoad( QgsChunkListEntry *entry )
91 Q_ASSERT( mState == Skeleton );
92 Q_ASSERT( !mLoaderQueueEntry );
93 Q_ASSERT( !mLoaderJob );
95 mState = QgsChunkNode::QueuedForLoad;
96 mLoaderQueueEntry = entry;
99void QgsChunkNode::cancelQueuedForLoad()
101 Q_ASSERT( mState == QueuedForLoad );
102 Q_ASSERT( mLoaderQueueEntry );
104 delete mLoaderQueueEntry;
105 mLoaderQueueEntry =
nullptr;
107 mState = QgsChunkNode::Skeleton;
110void QgsChunkNode::setLoading( QgsChunkQueueJob &job )
112 Q_ASSERT( mState == QueuedForLoad );
113 Q_ASSERT( !mLoaderJob );
114 Q_ASSERT( mLoaderQueueEntry );
118 mLoaderQueueEntry =
nullptr;
121void QgsChunkNode::cancelLoading()
123 Q_ASSERT( mState == QgsChunkNode::Loading );
124 Q_ASSERT( mLoaderJob );
125 Q_ASSERT( !mLoaderQueueEntry );
126 Q_ASSERT( !mEntity );
127 Q_ASSERT( !mReplacementQueueEntry );
129 mLoaderJob =
nullptr;
131 mState = QgsChunkNode::Skeleton;
134void QgsChunkNode::setLoaded( Qt3DCore::QEntity *newEntity )
136 Q_ASSERT( mState == QgsChunkNode::Loading );
137 Q_ASSERT( mLoaderJob );
138 Q_ASSERT( !mLoaderQueueEntry );
139 Q_ASSERT( !mReplacementQueueEntry );
142 mEntityCreatedTime = QTime::currentTime();
144 mLoaderJob =
nullptr;
146 mState = QgsChunkNode::Loaded;
147 mReplacementQueueEntry =
new QgsChunkListEntry(
this );
150void QgsChunkNode::unloadChunk()
152 Q_ASSERT( mState == QgsChunkNode::Loaded );
154 Q_ASSERT( mReplacementQueueEntry );
159 delete mReplacementQueueEntry;
160 mReplacementQueueEntry =
nullptr;
161 mState = QgsChunkNode::Skeleton;
164void QgsChunkNode::setQueuedForUpdate( QgsChunkListEntry *entry )
166 Q_ASSERT( mState == QgsChunkNode::Loaded );
168 Q_ASSERT( mReplacementQueueEntry );
169 Q_ASSERT( !mLoaderQueueEntry );
170 Q_ASSERT( !mUpdateJob );
172 mState = QueuedForUpdate;
173 mLoaderQueueEntry = entry;
176void QgsChunkNode::cancelQueuedForUpdate()
178 Q_ASSERT( mState == QueuedForUpdate );
180 Q_ASSERT( mLoaderQueueEntry );
181 Q_ASSERT( !mUpdateJob );
185 delete mLoaderQueueEntry;
186 mLoaderQueueEntry =
nullptr;
189void QgsChunkNode::setUpdating( QgsChunkQueueJob &job )
191 Q_ASSERT( mState == QgsChunkNode::QueuedForUpdate );
193 Q_ASSERT( mReplacementQueueEntry );
194 Q_ASSERT( mLoaderQueueEntry );
195 Q_ASSERT( !mUpdateJob );
199 mLoaderQueueEntry =
nullptr;
202void QgsChunkNode::cancelUpdating()
204 Q_ASSERT( mState == QgsChunkNode::Updating );
205 Q_ASSERT( mUpdateJob );
206 Q_ASSERT( !mLoaderQueueEntry );
208 mUpdateJob =
nullptr;
213void QgsChunkNode::setUpdated()
215 Q_ASSERT( mState == QgsChunkNode::Updating );
216 Q_ASSERT( mUpdateJob );
217 Q_ASSERT( !mLoaderQueueEntry );
218 Q_ASSERT( mReplacementQueueEntry );
220 mUpdateJob =
nullptr;
222 mState = QgsChunkNode::Loaded;
225bool QgsChunkNode::creatingChildren()
const
227 return mCreatingChildren;
230void QgsChunkNode::setCreatingChildren(
bool val )
232 mCreatingChildren = val;
235void QgsChunkNode::replaceEntity( Qt3DCore::QEntity *newEntity )
237 Q_ASSERT( mState == QgsChunkNode::Updating );
238 Q_ASSERT( mUpdateJob );
240 Q_ASSERT( newEntity );
242 mEntity->deleteLater();
246void QgsChunkNode::setExactBox3D(
const QgsBox3D &box3D )
253void QgsChunkNode::updateParentBoundingBoxesRecursively()
const
255 QgsChunkNode *currentNode = parent();
256 while ( currentNode )
258 QgsChunkNode *
const *currentNodeChildren = currentNode->children();
259 double xMin = std::numeric_limits<double>::max();
260 double xMax = -std::numeric_limits<double>::max();
261 double yMin = std::numeric_limits<double>::max();
262 double yMax = -std::numeric_limits<double>::max();
263 double zMin = std::numeric_limits<double>::max();
264 double zMax = -std::numeric_limits<double>::max();
266 for (
int i = 0; i < currentNode->childCount(); ++i )
268 const QgsBox3D childBox3D = currentNodeChildren[i]->box3D();
290 const QgsBox3D currentNodeBox3D = xMin > xMax || yMin > yMax || zMin > zMax ?
QgsBox3D() :
QgsBox3D( xMin, yMin, zMin, xMax, yMax, zMax );
292 currentNode->setExactBox3D( currentNodeBox3D );
293 currentNode = currentNode->parent();
A 3-dimensional box composed of x, y, z coordinates.
double yMaximum() const
Returns the maximum y value.
double xMinimum() const
Returns the minimum x value.
double zMaximum() const
Returns the maximum z value.
double xMaximum() const
Returns the maximum x value.
double zMinimum() const
Returns the minimum z value.
double yMinimum() const
Returns the minimum y value.
bool isEmpty() const
Returns true if the box is empty.