DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
SignalPlotter.h
Go to the documentation of this file.
1// This file is part of DynExp.
2
8#pragma once
9
10#include "stdafx.h"
11#include "DynExpCore.h"
12#include "../MetaInstruments/DataStreamInstrument.h"
13
14#include <QWidget>
15
16namespace Ui
17{
18 class SignalPlotter;
19}
20
21namespace DynExpModule
22{
23 class SignalPlotter;
24
26 {
27 Q_OBJECT
28
29 public:
31 {
33
34 void Reset();
35 QString GetMultiplierLabel() const;
36
37 QList<QPointF> Points;
38 QPointF MinValues;
39 QPointF MaxValues;
40 unsigned int Multiplier = 0;
41 };
42
45
46 bool AllowResize() const noexcept override final { return true; }
47
48 auto* GetAutoscalePlotAction() noexcept { return PlotAutoscaleAction; }
50 auto* GetClearPlotAction() const noexcept { return PlotClearAction; }
51
52 void UpdateUI(bool IsRunning);
53 void SetAxes(QValueAxis* XAxis, QValueAxis* YAxis);
54 void SetData(const SampleDataType& SampleData);
55
56 auto GetXAxis() noexcept { return XAxis; }
57 auto GetYAxis() noexcept { return YAxis; }
58 auto GetMultiplier() noexcept { return Multiplier; }
59
60 std::unique_ptr<Ui::SignalPlotter> ui;
61
62 private:
63 void FinishedSavingData() noexcept { IsSavingData = false; }
65
70
71 QXYSeries* DataSeries;
72 QChart* DataChart;
73 QValueAxis* XAxis;
74 QValueAxis* YAxis;
75
80
81 // If data is currently being saved to file, do not update internal data.
82 std::atomic_bool IsSavingData = false;
83
84 private slots:
85 void OnPlotContextMenuRequested(const QPoint& Position);
86 void OnSaveCSVClicked();
87 };
88
90 {
91 public:
93 virtual ~SignalPlotterData() = default;
94
97
98 void SetCurrentSourceIndex(int Index);
100 const auto& GetDataStreamInstrLabels() const noexcept { return DataStreamInstr.GetLabels(); }
101 std::string_view GetDataStreamInstrIconPath() const { return DataStreamInstr.GetIconPath(); }
102
103 bool IsUIInitialized() const noexcept { return UIInitialized; }
104 void SetUIInitialized() noexcept { UIInitialized = true; }
105
112
114
115 private:
116 void ResetImpl(dispatch_tag<QModuleDataBase>) override final;
118
119 void Init();
120
123
125 };
126
128 {
129 public:
131 virtual ~SignalPlotterParams() = default;
132
133 virtual const char* GetParamClassTag() const noexcept override { return "SignalPlotterParams"; }
134
136 "DataStreamInstr", "Data stream instrument(s)", "Underlying data stream instrument(s) to be used as a data source(s)", DynExpUI::Icons::Instrument };
137
138 Param<bool> Autoscale = { *this, "Autoscale", true };
139 Param<bool> RollingView = { *this, "RollingView", false };
140
141 private:
143 };
144
146 {
147 public:
150
152 virtual ~SignalPlotterConfigurator() = default;
153
154 private:
155 virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore& Core) const override final { return DynExp::MakeParams<SignalPlotterConfigurator>(ID, Core); }
156 };
157
159 {
160 public:
164
165 constexpr static auto Name() noexcept { return "Signal Plotter"; }
166 constexpr static auto Category() noexcept { return "I/O"; }
167
170 virtual ~SignalPlotter() = default;
171
172 virtual std::string GetName() const override { return Name(); }
173 virtual std::string GetCategory() const override { return Category(); }
174
175 std::chrono::milliseconds GetMainLoopDelay() const override final { return std::chrono::milliseconds(50); }
176
177 private:
179
180 void ResetImpl(dispatch_tag<QModuleBase>) override final;
181
182 std::unique_ptr<DynExp::QModuleWidget> MakeUIWidget() override final;
183 void UpdateUIChild(const ModuleBase::ModuleDataGetterType& ModuleDataGetter) override final;
184
193 bool ProcessBasicSamples(std::vector<DynExpInstr::BasicSample>&& BasicSamples, bool IsBasicSampleTimeUsed);
194
195 // Events, run in module thread
196 void OnInit(DynExp::ModuleInstance* Instance) const override final;
197 void OnExit(DynExp::ModuleInstance* Instance) const override final;
198 void OnRunClicked(DynExp::ModuleInstance* Instance, bool Checked) const;
199 void OnSourceChanged(DynExp::ModuleInstance* Instance, int Index) const;
200 void OnPlotAutoscaleClicked(DynExp::ModuleInstance* Instance, bool Checked) const;
201 void OnPlotRollingViewClicked(DynExp::ModuleInstance* Instance, bool Checked) const;
202 void OnClearStream(DynExp::ModuleInstance* Instance, bool) const;
203
205 };
206}
Defines DynExp's core module as an interface between the UI and DynExp objects.
UnitType
Units which can be used for data stream instruments.
virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core) const override final
Override to make derived classes call DynExp::MakeParams with the correct configurator type derived f...
void ResetImpl(dispatch_tag< QModuleDataBase >) override final
void UnlockInstruments(DynExp::ModuleInstance *Instance)
DynExp::LinkedObjectWrapperContainerList< DynExpInstr::DataStreamInstrument > DataStreamInstr
virtual void ResetImpl(dispatch_tag< SignalPlotterData >)
virtual ~SignalPlotterData()=default
void LockInstruments(DynExp::ModuleInstance *Instance, const DynExp::ParamsBase::ListParam< DynExp::ObjectLink< DynExpInstr::DataStreamInstrument > > &InstrParam)
const auto & GetDataStreamInstrLabels() const noexcept
SignalPlotterWidget::SampleDataType SampleData
bool IsUIInitialized() const noexcept
DynExpInstr::DataStreamInstrumentData::UnitType ValueUnit
std::string_view GetDataStreamInstrIconPath() const
SignalPlotterParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
ListParam< DynExp::ObjectLink< DynExpInstr::DataStreamInstrument > > DataStreamInstr
virtual const char * GetParamClassTag() const noexcept override
This function is intended to be overridden once in each derived class returning the name of the respe...
void ConfigureParamsImpl(dispatch_tag< QModuleParamsBase >) override final
virtual ~SignalPlotterParams()=default
void OnPlotContextMenuRequested(const QPoint &Position)
auto * GetAutoscalePlotAction() noexcept
decltype(SampleDataType::Multiplier) Multiplier
Describes the factor 10^Multiplier the displayed data has been multiplied with for better x-label rea...
auto * GetClearPlotAction() const noexcept
auto * GetRollingViewPlotAction() noexcept
std::unique_ptr< Ui::SignalPlotter > ui
void SetAxes(QValueAxis *XAxis, QValueAxis *YAxis)
bool AllowResize() const noexcept override final
Indicates the resizing behavior of the user interface window. Override to adjust.
void SetData(const SampleDataType &SampleData)
std::chrono::milliseconds GetMainLoopDelay() const override final
Specifies in which time intervals the module's event queue runs to handle pending events.
virtual std::string GetName() const override
Returns the name of this Object type.
virtual std::string GetCategory() const override
Returns the category of this Object type.
Util::DynExpErrorCodes::DynExpErrorCodes ModuleMainLoop(DynExp::ModuleInstance &Instance) override final
Module main loop. The function is executed periodically by the module thread. Also refer to GetMainLo...
void OnExit(DynExp::ModuleInstance *Instance) const override final
This event is triggered right before the module thread terminates (not due to an exception,...
void OnPlotRollingViewClicked(DynExp::ModuleInstance *Instance, bool Checked) const
SignalPlotter(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
void OnRunClicked(DynExp::ModuleInstance *Instance, bool Checked) const
void ResetImpl(dispatch_tag< QModuleBase >) override final
static constexpr auto Name() noexcept
void OnSourceChanged(DynExp::ModuleInstance *Instance, int Index) const
bool ProcessBasicSamples(std::vector< DynExpInstr::BasicSample > &&BasicSamples, bool IsBasicSampleTimeUsed)
Converts BasicSamples to displayable format.
std::unique_ptr< DynExp::QModuleWidget > MakeUIWidget() override final
Used by InitUI() as a factory function for the module's user interface widget. Create the widget here...
static constexpr auto Category() noexcept
void OnInit(DynExp::ModuleInstance *Instance) const override final
This event is triggered right before the module thread starts. Override it to lock instruments this m...
void OnPlotAutoscaleClicked(DynExp::ModuleInstance *Instance, bool Checked) const
void OnClearStream(DynExp::ModuleInstance *Instance, bool) const
virtual ~SignalPlotter()=default
void UpdateUIChild(const ModuleBase::ModuleDataGetterType &ModuleDataGetter) override final
DynExp's core class acts as the interface between the user interface and DynExp's internal data like ...
Definition DynExpCore.h:127
This class defines a list of LinkedObjectWrapperContainer instances. The list owns the contained Link...
Definition Object.h:3311
const auto & GetLabels() const noexcept
Returns ObjectLabels.
Definition Object.h:3324
std::string_view GetIconPath() const
Returns IconPath.
Definition Object.h:3325
Util::CallableMemberWrapper< ModuleBase, ModuleDataTypeSyncPtrType(ModuleBase::*)(const std::chrono::milliseconds)> ModuleDataGetterType
Invoking an instance of this alias is supposed to call ModuleBase::GetModuleData() of the instance th...
Definition Module.h:624
ModuleBase(const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params)
Constructs a ModuleBase instance.
Definition Module.cpp:206
Refer to ParamsBase::dispatch_tag.
Definition Module.h:191
Defines data for a thread belonging to a ModuleBase instance. Refer to RunnableInstance.
Definition Module.h:840
const std::thread::id OwnerThreadID
Thread id of the thread which has constructed (and owns) this Object instance.
Definition Object.h:2302
const ParamsBasePtrType Params
Pointer to the parameter class instance belonging to this Object instance.
Definition Object.h:2303
const auto & GetCore() const noexcept
Returns a reference to DynExp's core.
Definition Object.h:1677
const ItemIDType ID
ID of the Object this parameter class instance belongs to.
Definition Object.h:1779
const DynExpCore & Core
Reference to DynExp's core.
Definition Object.h:1780
Tag for function dispatching mechanism within this class used when derived classes are not intended t...
Definition Object.h:349
Base class for modules with a Qt-based user interface. Derive from this class to implement modules wi...
Definition Module.h:1660
QModuleBase(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
Constructs a QModuleBase instance.
Definition Module.cpp:591
Configurator class for QModuleBase.
Definition Module.h:1646
Data class for QModuleBase.
Definition Module.h:1536
Parameter class for QModuleBase.
Definition Module.h:1622
QModuleParamsBase(ItemIDType ID, const DynExpCore &Core)
Constructs the parameters for a QModuleBase instance.
Definition Module.h:1628
Window class for Qt-based user interfaces belonging to DynExp modules. User interface Qt window class...
Definition Module.h:1395
QModuleBase & Owner
Module owning this user interface window (reference, because it should never change nor be nullptr).
Definition Module.h:1478
QModuleWidget(QModuleBase &Owner, QWidget *Parent=nullptr)
Constructs a QModuleWidget instance.
Definition Module.cpp:451
void UnlockObject(LinkedObjectWrapperContainer< ObjectT > &ObjectWrapperContainer)
Unlocks an Object instance stored in the LinkedObjectWrapperContainer ObjectWrapperContainer....
Definition Object.h:3609
void LockObject(const ParamsBase::Param< ObjectLink< ObjectT > > &LinkParam, LinkedObjectWrapperContainer< ObjectT > &ObjectWrapperContainer, std::chrono::milliseconds Timeout=ObjectLinkBase::LockObjectTimeoutDefault)
Locks an Object instance referenced by a parameter LinkParam of type ParamsBase::Param< ObjectLink< O...
Definition Object.h:3593
Holds a CallableMemberWrapper and invokes its callable when being destroyed.
Definition Util.h:494
DynExp's instrument namespace contains the implementation of DynExp instruments which extend DynExp's...
DynExp's module namespace contains the implementation of DynExp modules which extend DynExp's core fu...
constexpr auto Instrument
DynExp's main namespace contains the implementation of DynExp including classes to manage resources (...
std::unique_ptr< ParamsBase > ParamsBasePtrType
Alias for a pointer to the parameter system base class ParamsBase.
Definition Object.h:1807
size_t ItemIDType
ID type of objects/items managed by DynExp.
DynExpErrorCodes
DynExp's error codes
Definition Exception.h:22
Accumulates include statements to provide a precompiled header.