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
15#include "CommonModuleEvents.h"
17
18#include <QWidget>
19
20namespace Ui
21{
22 class SpectrumViewer;
23}
24
26{
27 class SpectrumViewer;
28 class SpectrumViewerData;
29
31 {
32 Q_OBJECT
33
34 public:
49
52
53 bool AllowResize() const noexcept override final { return true; }
54
55 const auto GetUI() const noexcept { return ui.get(); }
56
59 void SetData(SampleDataType&& SampleData, DynExpInstr::SpectrometerData::TimeType ExposureTime);
60
61 private:
62 void FinishedSavingData() noexcept { IsSavingData = false; }
64
65 std::unique_ptr<Ui::SpectrumViewer> ui;
66
67 QXYSeries* DataSeries;
68 QChart* DataChart;
69 QValueAxis* XAxis;
70 QValueAxis* YAxis;
71
74
75 // If data is currently being saved to file, do not update internal data.
76 std::atomic_bool IsSavingData = false;
77
78 private slots:
79 void OnSaveCSVClicked();
80 };
81
83 {
84 public:
86 virtual ~SpectrumViewerData() = default;
87
88 bool IsUIInitialized() const noexcept { return UIInitialized; }
89 void SetUIInitialized() noexcept { UIInitialized = true; }
90 auto& GetSpectrometer() { return Spectrometer; }
91 auto& GetCommunicator() { return Communicator; }
92
106 std::string AutoSaveFilename;
107
110
111 private:
112 void ResetImpl(dispatch_tag<QModuleDataBase>) override final;
114
115 void Init();
116
118
121 };
122
124 {
125 public:
127 virtual ~SpectrumViewerParams() = default;
128
129 virtual const char* GetParamClassTag() const noexcept override { return "SpectrumViewerParams"; }
130
132 "Spectrometer", "Spectrometer", "Underlying spectrometer instrument to be used as a data source", DynExpUI::Icons::Instrument };
134 "InterModuleCommunicator", "Inter-module communicator", "Inter-module communicator to control this module with", DynExpUI::Icons::Instrument, true };
135
136 private:
138 };
139
141 {
142 public:
145
147 virtual ~SpectrumViewerConfigurator() = default;
148
149 private:
150 virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore& Core) const override final { return DynExp::MakeParams<SpectrumViewerConfigurator>(ID, Core); }
151 };
152
154 {
155 public:
159
160 constexpr static auto Name() noexcept { return "Spectrum Viewer"; }
161 constexpr static auto Category() noexcept { return "Image Capturing"; }
162
165 virtual ~SpectrumViewer() = default;
166
167 virtual std::string GetName() const override { return Name(); }
168 virtual std::string GetCategory() const override { return Category(); }
169
170 std::chrono::milliseconds GetMainLoopDelay() const override final { return std::chrono::milliseconds(50); }
171
172 private:
174
175 void ResetImpl(dispatch_tag<QModuleBase>) override final;
176
177 std::unique_ptr<DynExp::QModuleWidget> MakeUIWidget() override final;
178 void UpdateUIChild(const ModuleBase::ModuleDataGetterType& ModuleDataGetter) override final;
179
180 SpectrumViewerWidget::SampleDataType ProcessSpectrum(DynExpInstr::SpectrometerData::SpectrumType&& Spectrum,
181 Util::SynchronizedPointer<SpectrumViewerData>& ModuleData);
182 void SaveSpectrum(const SpectrumViewerWidget::SampleDataType& Spectrum,
183 Util::SynchronizedPointer<SpectrumViewerData>& ModuleData);
184
185 // Events, run in module thread
186 void OnInit(DynExp::ModuleInstance* Instance) const override final;
187 void OnExit(DynExp::ModuleInstance* Instance) const override final;
188
189 void OnRunClicked(DynExp::ModuleInstance* Instance, bool) const;
190 void OnStopClicked(DynExp::ModuleInstance* Instance, bool) const;
191 void OnSilentModeToggled(DynExp::ModuleInstance* Instance, bool Checked) const;
192 void OnExposureTimeChanged(DynExp::ModuleInstance* Instance, int Value) const;
193 void OnLowerLimitChanged(DynExp::ModuleInstance* Instance, double Value) const;
194 void OnUpperLimitChanged(DynExp::ModuleInstance* Instance, double Value) const;
195 void OnSetFilename(DynExp::ModuleInstance* Instance, const std::string& SaveFilename) const;
196 void OnTrigger(DynExp::ModuleInstance* Instance) const;
197 void OnStop(DynExp::ModuleInstance* Instance) const;
198 void OnPauseSpectrumRecording(DynExp::ModuleInstance* Instance) const;
199 void OnResumeSpectrumRecording(DynExp::ModuleInstance* Instance) const;
200
202 };
203}
Provides common events for inter-module communication. Also refer to DynExp::InterModuleEventBase.
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
std::unique_ptr< Ui::SpectrumViewer > ui
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 OnTrigger(DynExp::ModuleInstance *Instance) const
void OnSetFilename(DynExp::ModuleInstance *Instance, const std::string &SaveFilename) const
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
void OnStop(DynExp::ModuleInstance *Instance) const
virtual std::string GetCategory() const override
Returns the category of this Object type.
void OnResumeSpectrumRecording(DynExp::ModuleInstance *Instance) 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:3168
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
const std::unique_ptr< ModuleDataType > ModuleData
Module data belonging to this ModuleBase instance.
Definition Module.h:788
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
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