DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
SpectrumViewer.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/Spectrometer.h"
13#include "../../Instruments/InterModuleCommunicator.h"
14
16
17#include <QWidget>
18#include "ui_SpectrumViewer.h"
19
21{
22 class SpectrumViewer;
23 class SpectrumViewerData;
24
26 {
27 Q_OBJECT
28
29 public:
44
47
48 bool AllowResize() const noexcept override final { return true; }
49
50 const auto& GetUI() const noexcept { return ui; }
51
54 void SetData(SampleDataType&& SampleData, DynExpInstr::SpectrometerData::TimeType ExposureTime);
55
56 private:
57 void FinishedSavingData() noexcept { IsSavingData = false; }
59
60 QXYSeries* DataSeries;
61 QChart* DataChart;
62 QValueAxis* XAxis;
63 QValueAxis* YAxis;
64
65 Ui::SpectrumViewer ui;
66
69
70 // If data is currently being saved to file, do not update internal data.
71 std::atomic_bool IsSavingData = false;
72
73 private slots:
74 void OnSaveCSVClicked();
75 };
76
78 {
79 public:
81 virtual ~SpectrumViewerData() = default;
82
83 bool IsUIInitialized() const noexcept { return UIInitialized; }
84 void SetUIInitialized() noexcept { UIInitialized = true; }
85 auto& GetSpectrometer() { return Spectrometer; }
86 auto& GetCommunicator() { return Communicator; }
87
101 std::string AutoSaveFilename;
102
105
106 private:
107 void ResetImpl(dispatch_tag<QModuleDataBase>) override final;
109
110 void Init();
111
113
116 };
117
119 {
120 public:
122 virtual ~SpectrumViewerParams() = default;
123
124 virtual const char* GetParamClassTag() const noexcept override { return "SpectrumViewerParams"; }
125
127 "Spectrometer", "Spectrometer", "Underlying spectrometer instrument to be used as a data source", DynExpUI::Icons::Instrument };
129 "InterModuleCommunicator", "Inter-module communicator", "Inter-module communicator to control this module with", DynExpUI::Icons::Instrument, true };
130
131 private:
133 };
134
136 {
137 public:
140
142 virtual ~SpectrumViewerConfigurator() = default;
143
144 private:
145 virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore& Core) const override final { return DynExp::MakeParams<SpectrumViewerConfigurator>(ID, Core); }
146 };
147
149 {
150 public:
154
155 constexpr static auto Name() noexcept { return "Spectrum Viewer"; }
156 constexpr static auto Category() noexcept { return "Image Capturing"; }
157
160 virtual ~SpectrumViewer() = default;
161
162 virtual std::string GetName() const override { return Name(); }
163 virtual std::string GetCategory() const override { return Category(); }
164
165 std::chrono::milliseconds GetMainLoopDelay() const override final { return std::chrono::milliseconds(50); }
166
167 private:
169
170 void ResetImpl(dispatch_tag<QModuleBase>) override final;
171
172 std::unique_ptr<DynExp::QModuleWidget> MakeUIWidget() override final;
173 void UpdateUIChild(const ModuleBase::ModuleDataGetterType& ModuleDataGetter) override final;
174
175 SpectrumViewerWidget::SampleDataType ProcessSpectrum(DynExpInstr::SpectrometerData::SpectrumType&& Spectrum,
176 Util::SynchronizedPointer<SpectrumViewerData>& ModuleData);
177 void SaveSpectrum(const SpectrumViewerWidget::SampleDataType& Spectrum,
178 Util::SynchronizedPointer<SpectrumViewerData>& ModuleData);
179
180 // Events, run in module thread
181 void OnInit(DynExp::ModuleInstance* Instance) const override final;
182 void OnExit(DynExp::ModuleInstance* Instance) const override final;
183
184 void OnRunClicked(DynExp::ModuleInstance* Instance, bool) const;
185 void OnStopClicked(DynExp::ModuleInstance* Instance, bool) const;
186 void OnSilentModeToggled(DynExp::ModuleInstance* Instance, bool Checked) const;
187 void OnExposureTimeChanged(DynExp::ModuleInstance* Instance, int Value) const;
188 void OnLowerLimitChanged(DynExp::ModuleInstance* Instance, double Value) const;
189 void OnUpperLimitChanged(DynExp::ModuleInstance* Instance, double Value) const;
190 void OnRecordAndSaveSpectrum(DynExp::ModuleInstance* Instance, std::string SaveDataFilename) const;
191 void OnPauseSpectrumRecording(DynExp::ModuleInstance* Instance) const;
192 void OnResumeSpectrumRecording(DynExp::ModuleInstance* Instance) const;
193
195 };
196}
Defines DynExp's core module as an interface between the UI and DynExp objects.
Events for inter-module communication handled by the DynExpModule::SpectrumViewer::SpectrumViewer mod...
CapturingStateType
Possible spectrometer states.
std::chrono::milliseconds TimeType
Time type describing the spectrometer's times like its exposure time.
FrequencyUnitType
Supported spectrometer frequency units.
IntensityUnitType
Supported spectrometer intensity units.
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...
SpectrumViewerWidget::SampleDataType CurrentSpectrum
DynExpInstr::SpectrometerData::TimeType CurrentExposureTime
DynExpInstr::SpectrometerData::CapturingStateType CapturingState
DynExpInstr::SpectrometerData::TimeType AcquisitionExposureTime
DynExpInstr::SpectrometerData::TimeType MinExposureTime
DynExp::LinkedObjectWrapperContainer< DynExpInstr::InterModuleCommunicator > Communicator
void ResetImpl(dispatch_tag< QModuleDataBase >) override final
DynExpInstr::SpectrometerData::TimeType MaxExposureTime
DynExpInstr::SpectrometerData::FrequencyUnitType FrequencyUnit
virtual void ResetImpl(dispatch_tag< SpectrumViewerData >)
DynExp::LinkedObjectWrapperContainer< DynExpInstr::Spectrometer > Spectrometer
DynExpInstr::SpectrometerData::IntensityUnitType IntensityUnit
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...
Param< DynExp::ObjectLink< DynExpInstr::Spectrometer > > Spectrometer
void ConfigureParamsImpl(dispatch_tag< QModuleParamsBase >) override final
SpectrumViewerParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
Param< DynExp::ObjectLink< DynExpInstr::InterModuleCommunicator > > Communicator
void UpdateUI(Util::SynchronizedPointer< SpectrumViewerData > &ModuleData)
bool AllowResize() const noexcept override final
Indicates the resizing behavior of the user interface window. Override to adjust.
void InitializeUI(Util::SynchronizedPointer< SpectrumViewerData > &ModuleData)
DynExpInstr::SpectrometerData::TimeType CurrentExposureTime
void SetData(SampleDataType &&SampleData, DynExpInstr::SpectrometerData::TimeType ExposureTime)
void OnRunClicked(DynExp::ModuleInstance *Instance, bool) const
void OnExit(DynExp::ModuleInstance *Instance) const override final
This event is triggered right before the module thread terminates (not due to an exception,...
static constexpr auto Category() noexcept
void OnUpperLimitChanged(DynExp::ModuleInstance *Instance, double Value) const
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...
SpectrumViewer(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
void OnStopClicked(DynExp::ModuleInstance *Instance, bool) const
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 OnPauseSpectrumRecording(DynExp::ModuleInstance *Instance) const
void ResetImpl(dispatch_tag< QModuleBase >) override final
void OnLowerLimitChanged(DynExp::ModuleInstance *Instance, double Value) const
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...
void UpdateUIChild(const ModuleBase::ModuleDataGetterType &ModuleDataGetter) override final
virtual std::string GetName() const override
Returns the name of this Object type.
void SaveSpectrum(const SpectrumViewerWidget::SampleDataType &Spectrum, Util::SynchronizedPointer< SpectrumViewerData > &ModuleData)
SpectrumViewerWidget::SampleDataType ProcessSpectrum(DynExpInstr::SpectrometerData::SpectrumType &&Spectrum, Util::SynchronizedPointer< SpectrumViewerData > &ModuleData)
static constexpr auto Name() noexcept
void OnSilentModeToggled(DynExp::ModuleInstance *Instance, bool Checked) const
virtual std::string GetCategory() const override
Returns the category of this Object type.
void OnResumeSpectrumRecording(DynExp::ModuleInstance *Instance) const
void OnRecordAndSaveSpectrum(DynExp::ModuleInstance *Instance, std::string SaveDataFilename) const
std::chrono::milliseconds GetMainLoopDelay() const override final
Specifies in which time intervals the module's event queue runs to handle pending events.
void OnExposureTimeChanged(DynExp::ModuleInstance *Instance, int Value) const
DynExp's core class acts as the interface between the user interface and DynExp's internal data like ...
Definition DynExpCore.h:127
This class holds a pointer (LinkedObjectWrapperPointer) to a LinkedObjectWrapper. Intances of this cl...
Definition Object.h:3160
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
const std::unique_ptr< ModuleDataType > ModuleData
Module data belonging to this ModuleBase instance.
Definition Module.h:743
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
Holds a CallableMemberWrapper and invokes its callable when being destroyed.
Definition Util.h:494
Pointer to lock a class derived from ISynchronizedPointerLockable for synchronizing between threads....
Definition Util.h:170
DynExp's instrument namespace contains the implementation of DynExp instruments which extend DynExp's...
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
DynExp's Util namespace contains commonly used functions and templates as well as extensions to Qt an...
Accumulates include statements to provide a precompiled header.
DynExpInstr::SpectrometerData::IntensityUnitType IntensityUnit
DynExpInstr::SpectrometerData::FrequencyUnitType FrequencyUnit
std::string ToStr(DynExpInstr::SpectrometerData::TimeType ExposureTime) const