QGIS API Documentation  3.17.0-Master (a035f434f4)
qgschunkedentity_p.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgschunkedentity_p.h
3  --------------------------------------
4  Date : July 2017
5  Copyright : (C) 2017 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSCHUNKEDENTITY_P_H
17 #define QGSCHUNKEDENTITY_P_H
18 
20 
21 //
22 // W A R N I N G
23 // -------------
24 //
25 // This file is not part of the QGIS API. It exists purely as an
26 // implementation detail. This header file may change from version to
27 // version without notice, or even be removed.
28 //
29 
30 #include <Qt3DCore/QEntity>
31 
32 #define SIP_NO_FILE
33 
34 class QgsAABB;
35 class QgsChunkNode;
36 class QgsChunkList;
37 class QgsChunkQueueJob;
38 class QgsChunkLoaderFactory;
39 class QgsChunkBoundsEntity;
40 class QgsChunkQueueJobFactory;
41 
42 #include <QVector3D>
43 #include <QMatrix4x4>
44 
45 #include <QTime>
46 
47 #include "qgsfeatureid.h"
48 #include "qgschunknode_p.h"
49 
50 namespace Qt3DRender
51 {
52  class QPickEvent;
53 }
54 
61 class QgsChunkedEntity : public Qt3DCore::QEntity
62 {
63  Q_OBJECT
64  public:
66  QgsChunkedEntity( float tau, QgsChunkLoaderFactory *loaderFactory, bool ownsFactory, Qt3DCore::QNode *parent = nullptr );
67  ~QgsChunkedEntity() override;
68 
70  struct SceneState
71  {
72  QVector3D cameraPos;
73  float cameraFov;
74  int screenSizePx;
75  QMatrix4x4 viewProjectionMatrix;
76  };
77 
79  void update( const SceneState &state );
80 
82  bool needsUpdate() const { return mNeedsUpdate; }
83 
85  void setShowBoundingBoxes( bool enabled );
86 
88  void updateNodes( const QList<QgsChunkNode *> &nodes, QgsChunkQueueJobFactory *updateJobFactory );
89 
91  QList<QgsChunkNode *> activeNodes() const { return mActiveNodes; }
93  QgsChunkNode *rootNode() const { return mRootNode; }
94 
96  int pendingJobsCount() const;
97 
99  void setPickingEnabled( bool enabled );
101  bool hasPickingEnabled() const { return mPickingEnabled; }
102 
104  void setUsingAdditiveStrategy( bool additive ) { mAdditiveStrategy = additive; }
105 
111  bool usingAditiveStrategy() const { return mAdditiveStrategy; }
112 
113  protected:
115  void cancelActiveJob( QgsChunkQueueJob *job );
116  void cancelActiveJobs();
118  void setNeedsUpdate( bool needsUpdate ) { mNeedsUpdate = needsUpdate; }
119 
120  private:
121  void update( QgsChunkNode *node, const SceneState &state );
122 
124  void requestResidency( QgsChunkNode *node );
125 
126  void startJobs();
127  QgsChunkQueueJob *startJob( QgsChunkNode *node );
128 
129  private slots:
130  void onActiveJobFinished();
131 
132  void onPickEvent( Qt3DRender::QPickEvent *event );
133 
134  signals:
136  void pendingJobsCountChanged();
137 
139  void newEntityCreated( Qt3DCore::QEntity *entity );
140 
142  void pickedObject( Qt3DRender::QPickEvent *pickEvent, QgsFeatureId fid );
143 
144  protected:
146  QgsChunkNode *mRootNode = nullptr;
148  bool mNeedsUpdate = false;
149 
157  float mTau;
159  QgsChunkLoaderFactory *mChunkLoaderFactory = nullptr;
161  bool mOwnsFactory = true;
163  QgsChunkList *mChunkLoaderQueue = nullptr;
165  QgsChunkList *mReplacementQueue = nullptr;
167  QList<QgsChunkNode *> mActiveNodes;
169  int mFrustumCulled = 0;
170 
171  // TODO: max. length for loading queue
172 
173  QTime mCurrentTime;
174 
176  int mMaxLoadedChunks = 512;
177 
179  QgsChunkBoundsEntity *mBboxesEntity = nullptr;
180 
182  QList<QgsChunkQueueJob *> mActiveJobs;
183 
185  bool mPickingEnabled = false;
186 
191  bool mAdditiveStrategy = false;
192 
193  bool mIsValid = true;
194 };
195 
197 
198 #endif // QGSCHUNKEDENTITY_P_H
3 Axis-aligned bounding box - in world coords.
Definition: qgsaabb.h:33
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features ...
Definition: qgsfeatureid.h:28