/** * @RDE_HEADER@ * Interface for Script Editor Playback Controls * $Id$ * $HeadURL$ * $Author$ * * Created by Mike Wille, SLSE, 2017-04-19 */ #pragma once #include #include #include class QWidget; namespace TopicEditorBase { class ExportNotifier; } namespace TopicReplay { /** * @brief The Interface class handles the playback of the coherent Topic in the Script Player. */ class Interface { public: static QJsonObject timeRange(qint64 start, qint64 end) { return { {QStringLiteral("start"), start}, {QStringLiteral("end"), end} }; } struct SituationReplayTime { int id = 0; // topic start/end time in presentation (relative to presentation start) qint64 topicStart_s = -1; qint64 topicEnd_s = -1; // absolute time of replay start/end qint64 replayStart_ms = -1; qint64 replayEnd_ms = -1; double replaySpeedFactor = 1; QJsonObject toReplayInformation() const { return { {QStringLiteral("id"), id}, {QStringLiteral("timeInPresentation"), timeRange(topicStart_s * 1000, topicEnd_s * 1000)}, }; } QJsonObject toPlaybackTime(double max) const { QJsonObject ret = timeRange(replayStart_ms, std::min(replayEnd_ms * replaySpeedFactor, max)); ret[QStringLiteral("replaySpeedFactor")] = replaySpeedFactor; return ret; } QJsonObject toJson(double maxReplayEndMs) const { return { {QStringLiteral("playbackTime"), toPlaybackTime(maxReplayEndMs)}, {QStringLiteral("replayInformation"), toReplayInformation()}, }; } }; Interface() = default; virtual ~Interface() = default; /** * @brief createWidget * You are still the owner of the widget created by this method. You have to delete it on d_tor. * Do not override if this is a control interface only (using playbackInit/Start/Pause only) * @return */ virtual QWidget *createWidget() { return nullptr; } // Control Ifc: (do not override one of the following if this is a widget interface only (using createWidget only)) /** * @brief playbackInit is called when the Script Player starts the playback of the coherent topic. * @param attributes * @return */ virtual bool playbackInit(const QJsonObject &attributes) { Q_UNUSED(attributes); return true; } /*qint64 startTime, qint64 endTime, const double speed) { (void)startTime; (void)endTime; (void)speed; return false; }*/ // Override only if necessary (that is when your Topic's playback is not controlled by DDS / the Replay Management) Example: Video Playback virtual bool playbackStart(int secondsOffset) { Q_UNUSED(secondsOffset); return true; } virtual bool playbackPause() { return true; } virtual bool playbackStop() { return true; } /* * For TakehomePackage: * Notify about success or failure bei emitting * emit pExportNotifier->signalExportSuccessful(const QString& strFileName); * emit pExportNotifier->signalExportFailed(); * * If your export is time consuming call the following signal regularly * emit pExportNotifier->signalStillAlive(); */ virtual void setExportPlaybackTimes( qint64 startTimeSec, qint64 durationSec, const QVector &sitReplayTimes ) { Q_UNUSED(startTimeSec); Q_UNUSED(durationSec); Q_UNUSED(sitReplayTimes); } virtual bool exportTopic( const QJsonObject &attributes, const QString &strFolderPath, TopicEditorBase::ExportNotifier *pExportNotifier ) = 0; // returns a vector with additional TrackEntries to export (e.g. additional files) virtual QVector additionalTrackEntries(const QJsonObject &attributes) const { Q_UNUSED(attributes); return {}; } virtual QVector additionalTrackEntries(const QJsonObject &attributes, bool &keepOriginalTopic) const { keepOriginalTopic = true; return additionalTrackEntries(attributes); } virtual void setBasePath(const QString &basePath) { Q_UNUSED(basePath); } }; /** * @brief The Factory class handles one Interface at a time so that many widgets in the replay * can be handled separately. */ class Factory { public: virtual ~Factory() = default; virtual Interface *createInterface(TopicEditorBase::TopicType topicType) = 0; }; } // namespace TopicReplay