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#include "ui_SignalPlotter.h"
16
17namespace DynExpModule
18{
19 class SignalPlotter;
20
22 {
23 Q_OBJECT
24
25 public:
27 {
29
30 void Reset();
31 QString GetMultiplierLabel() const;
32
33 QList<QPointF> Points;
34 QPointF MinValues;
35 QPointF MaxValues;
36 unsigned int Multiplier = 0;
37 };
38
41
42 bool AllowResize() const noexcept override final { return true; }
43
44 auto* GetAutoscalePlotAction() noexcept { return PlotAutoscaleAction; }
46 auto* GetClearPlotAction() const noexcept { return PlotClearAction; }
47
48 void UpdateUI(bool IsRunning);
49 void SetAxes(QValueAxis* XAxis, QValueAxis* YAxis);
50 void SetData(const SampleDataType& SampleData);
51
52 auto GetXAxis() noexcept { return XAxis; }
53 auto GetYAxis() noexcept { return YAxis; }
54 auto GetMultiplier() noexcept { return Multiplier; }
55
56 Ui::SignalPlotter ui;
57
58 private:
59 void FinishedSavingData() noexcept { IsSavingData = false; }
61
66
67 QXYSeries* DataSeries;
68 QChart* DataChart;
69 QValueAxis* XAxis;
70 QValueAxis* YAxis;
71
76
77 // If data is currently being saved to file, do not update internal data.
78 std::atomic_bool IsSavingData = false;
79
80 private slots:
81 void OnPlotContextMenuRequested(const QPoint& Position);
82 void OnSaveCSVClicked();
83 };
84
86 {
87 public:
89 virtual ~SignalPlotterData() = default;
90
93
94 void SetCurrentSourceIndex(int Index);
96 const auto& GetDataStreamInstrLabels() const noexcept { return DataStreamInstr.GetLabels(); }
97 std::string_view GetDataStreamInstrIconPath() const { return DataStreamInstr.GetIconPath(); }
98
99 bool IsUIInitialized() const noexcept { return UIInitialized; }
100 void SetUIInitialized() noexcept { UIInitialized = true; }
101
108
110
111 private:
112 void ResetImpl(dispatch_tag<QModuleDataBase>) override final;
114
115 void Init();
116
119
121 };
122
124 {
125 public:
127 virtual ~SignalPlotterParams() = default;
128
129 virtual const char* GetParamClassTag() const noexcept override { return "SignalPlotterParams"; }
130
132 "DataStreamInstr", "Data stream instrument(s)", "Underlying data stream instrument(s) to be used as a data source(s)", DynExpUI::Icons::Instrument };
133
134 Param<bool> Autoscale = { *this, "Autoscale", true };
135 Param<bool> RollingView = { *this, "RollingView", false };
136
137 private:
139 };
140
142 {
143 public:
146
148 virtual ~SignalPlotterConfigurator() = default;
149
150 private:
151 virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore& Core) const override final { return DynExp::MakeParams<SignalPlotterConfigurator>(ID, Core); }
152 };
153
155 {
156 public:
160
161 constexpr static auto Name() noexcept { return "Signal Plotter"; }
162 constexpr static auto Category() noexcept { return "I/O"; }
163
166 virtual ~SignalPlotter() = default;
167
168 virtual std::string GetName() const override { return Name(); }
169 virtual std::string GetCategory() const override { return Category(); }
170
171 std::chrono::milliseconds GetMainLoopDelay() const override final { return std::chrono::milliseconds(50); }
172
173 private:
175
176 void ResetImpl(dispatch_tag<QModuleBase>) override final;
177
178 std::unique_ptr<DynExp::QModuleWidget> MakeUIWidget() override final;
179 void UpdateUIChild(const ModuleBase::ModuleDataGetterType& ModuleDataGetter) override final;
180
189 bool ProcessBasicSamples(std::vector<DynExpInstr::BasicSample>&& BasicSamples, bool IsBasicSampleTimeUsed);
190
191 // Events, run in module thread
192 void OnInit(DynExp::ModuleInstance* Instance) const override final;
193 void OnExit(DynExp::ModuleInstance* Instance) const override final;
194 void OnRunClicked(DynExp::ModuleInstance* Instance, bool Checked) const;
195 void OnSourceChanged(DynExp::ModuleInstance* Instance, int Index) const;
196 void OnPlotAutoscaleClicked(DynExp::ModuleInstance* Instance, bool Checked) const;
197 void OnPlotRollingViewClicked(DynExp::ModuleInstance* Instance, bool Checked) const;
198 void OnClearStream(DynExp::ModuleInstance* Instance, bool) const;
199
201 };
202}
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
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:3303
const auto & GetLabels() const noexcept
Returns ObjectLabels.
Definition Object.h:3316
std::string_view GetIconPath() const
Returns IconPath.
Definition Object.h:3317
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:587
ModuleBase(const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params)
Constructs a ModuleBase instance.
Definition Module.cpp:189
Refer to ParamsBase::dispatch_tag.
Definition Module.h:189
Defines data for a thread belonging to a ModuleBase instance. Refer to RunnableInstance.
Definition Module.h:793
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:1344
QModuleBase(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
Constructs a QModuleBase instance.
Definition Module.cpp:557
Configurator class for QModuleBase.
Definition Module.h:1330
Data class for QModuleBase.
Definition Module.h:1220
Parameter class for QModuleBase.
Definition Module.h:1306
QModuleParamsBase(ItemIDType ID, const DynExpCore &Core)
Constructs the parameters for a QModuleBase instance.
Definition Module.h:1312
Window class for Qt-based user interfaces belonging to DynExp modules. User interface Qt window class...
Definition Module.h:1079
QModuleBase & Owner
Module owning this user interface window (reference, because it should never change nor be nullptr).
Definition Module.h:1162
QModuleWidget(QModuleBase &Owner, QWidget *Parent=nullptr)
Constructs a QModuleWidget instance.
Definition Module.cpp:417
void UnlockObject(LinkedObjectWrapperContainer< ObjectT > &ObjectWrapperContainer)
Unlocks an Object instance stored in the LinkedObjectWrapperContainer ObjectWrapperContainer....
Definition Object.h:3570
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:3554
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.