Kstars

simclock.h
1/*
2 SPDX-FileCopyrightText: 2002 Mark Hollomon <mhh@mindspring.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "kstarsdatetime.h"
10
11#include <QTime>
12#include <QElapsedTimer>
13#include <QTimer>
14#include <qtdbusglobal.h>
15
16/** @class SimClock
17 *@short kstars simulation clock
18 *@author Mark Hollomon
19 *@version 1.0
20 */
21
22class SimClock : public QObject
23{
25 Q_CLASSINFO("D-Bus Interface", "org.kde.kstars.SimClock")
26 public:
27 /**
28 * Constructor
29 * @param parent parent object for the clock
30 * @param when the date/time to which the SimClock should be initialized in UTC
31 */
33
34 /** @return const reference to the current simulation Universal Time. */
35 const KStarsDateTime &utc() const
36 {
37 return m_UTC;
38 }
39
40 /** Whether the clock is active or not is a bit complicated by the
41 *introduction of "manual mode". In manual mode, SimClock's internal timer
42 *is stopped, because the clock is ticked manually when the current update
43 *has finished. So, if ManualMode is true, then isActive() checks
44 *whether ManualActive is true. Otherwise, it checks whether the timer is
45 *running.
46 *@returns true if the Simulation clock is actively running.
47 */
48 Q_INVOKABLE bool isActive();
49
50 /** @returns the current timestep setting */
51 double scale() const
52 {
53 return m_Scale;
54 }
55
56 /** Manual Mode is a new (04/2002) addition to the SimClock. It is
57 *intended to be activated for large timesteps, when we want each frame
58 *drawn to the screen to be precisely Scale seconds later than the
59 *previous frame. (i.e., if the timescale is 1 year, then each successive
60 *frame should be 1 year later than the previous frame). ManualMode
61 *accomplishes this by stopping the internal timer and allowing the clock
62 *to be advanced manually (the manualTick() slot is called at the end of each
63 *KStars::updateTime()).
64 *@returns whether Manual Mode is active.
65 */
66 bool isManualMode() const
67 {
68 return m_ManualMode;
69 }
70
71 /**Sets Manual Mode on/off according to the bool argument. */
72 void setManualMode(bool on = true);
73
74 public Q_SLOTS:
75#ifndef KSTARS_LITE
76 /** DBUS function to stop the SimClock. */
77 Q_SCRIPTABLE Q_NOREPLY void stop();
78
79 /** DBUS function to start the SimClock. */
80 Q_SCRIPTABLE Q_NOREPLY void start();
81
82 /** DBUS function to set the time of the SimClock. */
83 Q_SCRIPTABLE Q_NOREPLY void setUTC(const KStarsDateTime &newtime);
84
85 /** DBUS function to set the current time of the SimClock. */
90
91 /** DBUS function to set scale of simclock. */
92 /**
93 * @brief setClockScale Set simulation clock scale per second.
94 * @param scale Scale per second. 1 means normal scale, each 1 simulation
95 * second equals 1 real second. Value less than one *slows* the simulation clock,
96 * while values over 1 speeds it up. A scale of 0.5 makes the simulation clock ticks
97 * once every 2 actual seconds (or half-ticks per one actual second),
98 * while a value of 60 make the simulation clock ticks 60 simulation seconds (1 simulation minute)
99 * for every 1 actual second.
100 */
101 Q_SCRIPTABLE Q_NOREPLY void setClockScale(double scale);
102#else
103 // Define non-DBUS versions of functions above for use within KStarsLite
104 /** Function to stop the SimClock. */
105 void stop();
106
107 /** Function to start the SimClock. */
108 void start();
109
110 /** Function to set the time of the SimClock. */
111 void setUTC(const KStarsDateTime &newtime);
112
113 /** Function to set scale of simclock. */
114 void setClockScale(float s);
115#endif
116
117 /** Respond to the QTimer::timeout signal */
118 void tick();
119
120 /** Equivalent of tick() for manual mode.
121 * If ManualActive is true, add Scale seconds to the SimClock time.
122 * (we may want to modify this slightly...e.g., the number of seconds in a
123 * year is not constant (leap years), so it is better to increment the
124 * year, instead of adding 31 million seconds.
125 * set backward to true to reverse sign of Scale value
126 */
127
128 void manualTick(bool force = false, bool backward = false);
129
130 signals:
131 /** The time has changed (emitted by setUTC() ) */
133
134 /** The clock has ticked (emitted by tick() )*/
136
137 /** The timestep has changed*/
138 void scaleChanged(float);
139
140 /** This is an signal that is called on either clock start or
141 clock stop with an appropriate boolean argument. Required so
142 that we can bind it to KToggleAction::slotToggled(bool) */
143 void clockToggled(bool);
144
145 private:
146 long double m_JulianMark { 0 };
147 KStarsDateTime m_UTC;
148 QTimer m_InternalTimer;
149 double m_Scale { 1 };
150 QElapsedTimer m_SystemMark;
151 int m_LastElapsed { 0 };
152 bool m_ManualMode { false };
153 bool m_ManualActive { false };
154
155 // used to generate names for dcop interfaces
156 //static int idgen;
157 // how often to update
158 static int TimerInterval;
159
160 // Disallow copying
161 SimClock(const SimClock &);
162 SimClock &operator=(const SimClock &);
163};
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
static KStarsDateTime currentDateTimeUtc()
kstars simulation clock
Definition simclock.h:23
void clockToggled(bool)
This is an signal that is called on either clock start or clock stop with an appropriate boolean argu...
void timeAdvanced()
The clock has ticked (emitted by tick() )
double scale() const
Definition simclock.h:51
void timeChanged()
The time has changed (emitted by setUTC() )
Q_INVOKABLE bool isActive()
Whether the clock is active or not is a bit complicated by the introduction of "manual mode".
Definition simclock.cpp:96
void setManualMode(bool on=true)
Sets Manual Mode on/off according to the bool argument.
Definition simclock.cpp:61
void scaleChanged(float)
The timestep has changed.
Q_SCRIPTABLE Q_NOREPLY void setNow()
DBUS function to set the current time of the SimClock.
Definition simclock.h:86
Q_SCRIPTABLE Q_NOREPLY void setClockScale(double scale)
DBUS function to set scale of simclock.
Definition simclock.cpp:169
const KStarsDateTime & utc() const
Definition simclock.h:35
Q_SCRIPTABLE Q_NOREPLY void start()
DBUS function to start the SimClock.
Definition simclock.cpp:120
void tick()
Respond to the QTimer::timeout signal.
Definition simclock.cpp:32
Q_SCRIPTABLE Q_NOREPLY void setUTC(const KStarsDateTime &newtime)
DBUS function to set the time of the SimClock.
Definition simclock.cpp:143
SimClock(QObject *parent=nullptr, const KStarsDateTime &when=KStarsDateTime::currentDateTimeUtc())
Constructor.
Definition simclock.cpp:18
bool isManualMode() const
Manual Mode is a new (04/2002) addition to the SimClock.
Definition simclock.h:66
Q_SCRIPTABLE Q_NOREPLY void stop()
DBUS function to stop the SimClock.
Definition simclock.cpp:104
void manualTick(bool force=false, bool backward=false)
Equivalent of tick() for manual mode.
Definition simclock.cpp:83
Q_CLASSINFO(Name, Value)
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 10 2024 11:50:59 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.