SWMMVis  6.0.0-alpha.4
Qt6/C++ GIS-based graphical user interface for the SWMMVis engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
animationcontroller.h
Go to the documentation of this file.
1
22#ifndef ANIMATIONCONTROLLER_H
23#define ANIMATIONCONTROLLER_H
24
25#include <QDateTime>
26#include <QList>
27#include <QObject>
28#include <QPointer>
29
30// QPointer<SWMM2DResultsLayer> in the private section requires the
31// inheritance chain to be visible; include the layer header instead of just
32// forward-declaring.
34
35class QTimer;
37
42class AnimationController : public QObject
43{
44 Q_OBJECT
45
46public:
47 explicit AnimationController(QObject *parent = nullptr);
48 ~AnimationController() override;
49
50 // ----- Primary layer -------------------------------------------------
51
60 [[nodiscard]] SWMMResultsLayer *primaryLayer() const;
61
62 // ----- 2D fallback layer (Slice CF.MVP-fix.1) -----------------------
63 //
64 // When no 1D primary is set, the controller drives a SWMM2DResultsLayer
65 // directly so 2D-only runs (no .out results loaded) still animate.
66 // When a 1D primary becomes available the fallback is silently demoted;
67 // the 2D layer keeps following via the QDateTime fan-out in
68 // SWMMVis::onAnimationCurrentTimeChanged.
70 [[nodiscard]] SWMM2DResultsLayer *fallback2DLayer() const { return m_fallback2D; }
71
72 // ----- Secondary layers ----------------------------------------------
73
77
79 [[nodiscard]] QList<SWMMResultsLayer *> allLayers() const;
80
81 // ----- State query ---------------------------------------------------
82
83 [[nodiscard]] bool isPlaying() const { return m_playing; }
84 [[nodiscard]] double speed() const { return m_speed; }
85
86 // ----- Sync window (causal "as-of within timespan") ------------------
87 //
88 // Non-driver outputs display the latest frame at or before the cursor
89 // (causal floor). The window is the look-back span [t - w, t] used by the
90 // range-slider UI and to classify an output as fresh/stale; under the
91 // hold-last policy it does not change which frame shows.
92 [[nodiscard]] qint64 windowMs() const { return m_windowMs; }
93
96 [[nodiscard]] QDateTime driverStartTime() const;
97 [[nodiscard]] QDateTime driverEndTime() const;
99 [[nodiscard]] QDateTime currentDateTime() const;
100
101 // ----- Speed ---------------------------------------------------------
102
107 void setSpeed(double speed);
108
111 void setWindowMs(qint64 ms);
112 void setWindowSec(double sec) { setWindowMs(static_cast<qint64>(sec * 1000.0)); }
113
114 // ----- Looping (toolbar "Cycle" checkbox) ----------------------------
115
119 void setLooping(bool on) { m_loop = on; }
120 [[nodiscard]] bool looping() const { return m_loop; }
121
122public slots:
123 void play();
124 void pause();
125 void stop();
126 void stepForward();
127 void stepBackward();
128 void seekToFirst();
129 void seekToLast();
130 void seekToPeriod(int period);
133 void seekToTime(const QDateTime &dt);
134
135signals:
136 void currentTimeChanged(const QDateTime &dt);
137 void currentPeriodChanged(int period);
138 void playStateChanged(bool playing);
139 void totalPeriodsChanged(int total);
142
143private slots:
144 void onTimerTick();
145 void onPrimaryPeriodChanged(int step);
146 void onPrimaryTotalStepsChanged(int total);
147
148 // 2D fallback re-emit slots (mirror the 1D ones).
149 void onFallback2DPeriodChanged(int step);
150 void onFallback2DTimeChanged(const QDateTime &dt);
151 void onFallback2DRangeChanged(int lo, int hi);
152
153private:
154 void updateTimerInterval();
155 void connectPrimary();
156 void disconnectPrimary();
157 void connectFallback2D();
158 void disconnectFallback2D();
159
160 // Returns true when either a 1D primary or a 2D fallback is set.
161 [[nodiscard]] bool hasDriver() const;
162 // Total step count from whichever driver is active (1D primary preferred).
163 [[nodiscard]] int driverTotalSteps() const;
164 // Current step index from whichever driver is active.
165 [[nodiscard]] int driverCurrentStep() const;
166 // Advance whichever driver is active to \p step.
167 void driverSetStep(int step);
172 [[nodiscard]] bool driverIsLive() const;
173
180 void effectiveStepRange(int &outMin, int &outMax) const;
181
182 QPointer<SWMMResultsLayer> m_primaryLayer;
183 QList<QPointer<SWMMResultsLayer>> m_secondaryLayers;
184 QPointer<SWMM2DResultsLayer> m_fallback2D;
185 QTimer *m_timer = nullptr;
186 bool m_playing = false;
187 bool m_loop = true;
188 double m_speed = 1.0;
189 qint64 m_windowMs = 0;
190
196 int m_stepsPerTick = 1;
197
202 int m_direction = 1;
203
204 static constexpr int kMinIntervalMs = 50;
205 static constexpr int kDefaultStepMs = 200; // fallback when primary has no report step
206};
207
208#endif // ANIMATIONCONTROLLER_H
Central coordinator for result-layer time-stepping and playback.
Definition animationcontroller.h:43
void setPrimaryLayer(SWMMResultsLayer *layer)
Set the primary (authoritative) results layer.
Definition animationcontroller.cpp:37
void pause()
Definition animationcontroller.cpp:356
void currentPeriodChanged(int period)
void setWindowMs(qint64 ms)
Definition animationcontroller.cpp:245
void play()
Definition animationcontroller.cpp:331
QDateTime driverEndTime() const
Definition animationcontroller.cpp:227
bool looping() const
Definition animationcontroller.h:120
void seekToLast()
Definition animationcontroller.cpp:400
void windowChanged(qint64 windowMs)
void setFallback2DLayer(SWMM2DResultsLayer *layer)
Definition animationcontroller.cpp:113
void seekToPeriod(int period)
Definition animationcontroller.cpp:407
void seekToTime(const QDateTime &dt)
Definition animationcontroller.cpp:414
SWMM2DResultsLayer * fallback2DLayer() const
Definition animationcontroller.h:70
void playStateChanged(bool playing)
qint64 windowMs() const
Definition animationcontroller.h:92
bool isPlaying() const
Definition animationcontroller.h:83
void setSpeed(double speed)
Set playback speed multiplier (0.25 / 0.5 / 1 / 2 / 4 / 8).
Definition animationcontroller.cpp:286
QDateTime driverStartTime() const
Definition animationcontroller.cpp:214
void stepForward()
Definition animationcontroller.cpp:372
void setLooping(bool on)
Definition animationcontroller.h:119
QList< SWMMResultsLayer * > allLayers() const
Definition animationcontroller.cpp:273
void stop()
Definition animationcontroller.cpp:366
void setWindowSec(double sec)
Definition animationcontroller.h:112
void currentTimeChanged(const QDateTime &dt)
~AnimationController() override
Definition animationcontroller.cpp:28
QDateTime currentDateTime() const
Definition animationcontroller.cpp:237
double speed() const
Definition animationcontroller.h:84
SWMMResultsLayer * primaryLayer() const
Definition animationcontroller.cpp:65
void primaryLayerChanged(SWMMResultsLayer *layer)
void stepBackward()
Definition animationcontroller.cpp:385
void removeSecondaryLayer(SWMMResultsLayer *layer)
Definition animationcontroller.cpp:263
void seekToFirst()
Definition animationcontroller.cpp:393
void totalPeriodsChanged(int total)
void addSecondaryLayer(SWMMResultsLayer *layer)
Definition animationcontroller.cpp:257
void clearSecondaryLayers()
Definition animationcontroller.cpp:268
Definition swmm2dresultslayer.h:550
Overlays time-stepped simulation results on the SWMM network geometry.
Definition swmmresultslayer.h:96
double step
Definition meshcellparams.cpp:28
QVector< int > parent
union-find
Definition pslgminsize.cpp:176