DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
LaserScanningSpectroscopy.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/Laser.h"
13#include "../../Instruments/InterModuleCommunicator.h"
14
15#include "CommonModuleEvents.h"
16
17#include <QWidget>
18
19namespace Ui
20{
21 class LaserScanningSpectroscopy;
22}
23
25{
26 class LaserScanningSpectroscopy;
27 class LaserScanningSpectroscopyData;
28
34
36
38 {
39 Q_OBJECT
40
41 public:
44
45 bool AllowResize() const noexcept override final { return true; }
46 const auto GetUI() const noexcept { return ui.get(); }
47 bool GetUIInitialized() const noexcept { return UIInitialized; }
48
50
51 private:
52 std::unique_ptr<Ui::LaserScanningSpectroscopy> ui;
53
54 bool UIInitialized = false;
55
56 private slots:
58 };
59
61 {
62 public:
64 virtual ~LaserScanningSpectroscopyData() = default;
65
68 auto& GetLaser() { return Laser; }
69
70 std::string_view GetUIMessage() const noexcept { return UIMessage; }
71 void SetInvalidStartupStateMessage() { UIMessage = "Laser can not be in Startup state during data capturing."; }
72 void ClearUIMessage() { UIMessage = ""; }
73
80 double StepSize;
88 std::filesystem::path FileSavePath;
91
94
95 private:
96 void ResetImpl(dispatch_tag<QModuleDataBase>) override final;
98
99 void Init();
100
104
105 std::string UIMessage;
106 };
107
109 {
110 public:
113
114 virtual const char* GetParamClassTag() const noexcept override { return "LaserScanningSpectroscopyParams"; }
115
116 Param<DynExp::ObjectLink<DynExpInstr::Laser>> Laser = { *this, GetCore().GetInstrumentManager(),
117 "Laser", "Laser", "Laser instrument to perform spectroscopy with by scanning its frequency", DynExpUI::Icons::Instrument };
119 "PLEInterModuleCommunicator", "PLE inter-module communicator", "Inter-module communicator to control data acquisition", DynExpUI::Icons::Instrument, true };
121 "WFInterModuleCommunicator", "WF inter-module communicator", "Inter-module communicator to communicate with widefield microscope module", DynExpUI::Icons::Instrument, true };
123 "Capturing time difference (ms)", "Time difference between capturing events in continuous scan mode",
124 false, 500, 1};
125
126 private:
128 };
129
131 {
132 public:
135
138
139 private:
140 virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore& Core) const override final { return DynExp::MakeParams<LaserScanningSpectroscopyConfigurator>(ID, Core); }
141 };
142
144 {
145 public:
149
150 constexpr static auto Name() noexcept { return "Laser Scanning Spectroscopy"; }
151 constexpr static auto Category() noexcept { return "Experiments"; }
152
154 virtual ~LaserScanningSpectroscopy() = default;
155
156 virtual std::string GetName() const override { return Name(); }
157 virtual std::string GetCategory() const override { return Category(); }
158
159 std::chrono::milliseconds GetMainLoopDelay() const override final { return std::chrono::milliseconds(50); }
160
161 private:
163
164 void ResetImpl(dispatch_tag<QModuleBase>) override final;
165
166 std::unique_ptr<DynExp::QModuleWidget> MakeUIWidget() override final;
167 void UpdateUIChild(const ModuleBase::ModuleDataGetterType& ModuleDataGetter) override final;
168
169 // Helper functions
170 bool IsReadyState() const noexcept;
171 bool IsSettingFrequencyState() const noexcept;
172 bool IsCapturingState() const noexcept;
173 void FrequencyStep(DynExp::ModuleInstance* Instance) const;
174 std::filesystem::path BuildFilename(Util::SynchronizedPointer<ModuleDataType>& ModuleData, std::string_view FilenameSuffix) const;
175
176 // Events, run in module thread
177 void OnInit(DynExp::ModuleInstance* Instance) const override final;
178 void OnExit(DynExp::ModuleInstance* Instance) const override final;
179 void OnStart(DynExp::ModuleInstance* Instance) const;
180 void OnStartClicked(DynExp::ModuleInstance* Instance, bool) const;
181 void OnStop(DynExp::ModuleInstance* Instance) const;
182 void OnStopClicked(DynExp::ModuleInstance* Instance, bool) const;
183 void OnLowerFrequencyLimitChanged(DynExp::ModuleInstance* Instance, double LowerFrequencyLimit) const;
184 void OnUpperFrequencyLimitChanged(DynExp::ModuleInstance* Instance, double UpperFrequencyLimit) const;
185 void OnFrequencyRangeChanged(DynExp::ModuleInstance* Instance, double FrequencyRange) const;
186 void OnCenterFrequencyChanged(DynExp::ModuleInstance* Instance, double CenterFrequency) const;
187 void OnStepSizeChanged(DynExp::ModuleInstance* Instance, double StepSize) const;
188 void OnNumberOfStepsChanged(DynExp::ModuleInstance* Instance, int NumberOfSteps) const;
189 void OnNumberOfRepetitionsChanged(DynExp::ModuleInstance* Instance, int NumberOfRepetitions) const;
190 void OnScanBackAndForthToggled(DynExp::ModuleInstance* Instance, bool Checked) const;
191 void OnStartAtToggled(DynExp::ModuleInstance* Instance, bool) const;
192 void OnPathChanged(DynExp::ModuleInstance* Instance, const std::string& SaveFilename) const;
193 void OnPathChanged(DynExp::ModuleInstance* Instance, const QString SaveFilename) const;
194 void OnFinishedCapturing(DynExp::ModuleInstance* Instance) const;
195
196 // State functions for state machine
197 StateType ReadyStateFunc(DynExp::ModuleInstance& Instance);
198 StateType WaitForSettingFrequencyStateFunc(DynExp::ModuleInstance& Instance);
199 StateType WaitForCapturingStateFunc(DynExp::ModuleInstance& Instance);
200
201 // States for state machine
202 static constexpr auto ReadyState = Util::StateMachineState(StateType::Ready,
204 static constexpr auto WaitForSettingFrequencyState = Util::StateMachineState(StateType::WaitForSettingFrequency,
205 &LaserScanningSpectroscopy::WaitForSettingFrequencyStateFunc, "Laser stabilizes at target Frequency...");
206 static constexpr auto WaitForCapturingState = Util::StateMachineState(StateType::WaitForCapturing,
208
209 // Logical const-ness: allow events to set the state machine's current state.
211
212 // Indicates waiting time within measurements.
213 mutable std::chrono::system_clock::time_point WaitingEndTimePoint;
214
216 };
217}
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.
LaserStateType
Possible laser states.
Definition Laser.h:71
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...
DynExp::LinkedObjectWrapperContainer< DynExpInstr::Laser > Laser
virtual void ResetImpl(dispatch_tag< LaserScanningSpectroscopyData >)
DynExp::LinkedObjectWrapperContainer< DynExpInstr::InterModuleCommunicator > PLECommunicator
DynExp::LinkedObjectWrapperContainer< DynExpInstr::InterModuleCommunicator > WFCommunicator
Param< DynExp::ObjectLink< DynExpInstr::InterModuleCommunicator > > PLECommunicator
Param< DynExp::ObjectLink< DynExpInstr::InterModuleCommunicator > > WFCommunicator
void ConfigureParamsImpl(dispatch_tag< QModuleParamsBase >) override final
LaserScanningSpectroscopyParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
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 InitializeUI(Util::SynchronizedPointer< LaserScanningSpectroscopyData > &ModuleData)
bool AllowResize() const noexcept override final
Indicates the resizing behavior of the user interface window. Override to adjust.
virtual std::string GetName() const override
Returns the name of this Object type.
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...
std::chrono::milliseconds GetMainLoopDelay() const override final
Specifies in which time intervals the module's event queue runs to handle pending events.
void OnStartAtToggled(DynExp::ModuleInstance *Instance, bool) const
void OnNumberOfRepetitionsChanged(DynExp::ModuleInstance *Instance, int NumberOfRepetitions) 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...
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...
virtual std::string GetCategory() const override
Returns the category of this Object type.
std::filesystem::path BuildFilename(Util::SynchronizedPointer< ModuleDataType > &ModuleData, std::string_view FilenameSuffix) const
void OnStepSizeChanged(DynExp::ModuleInstance *Instance, double StepSize) const
void OnExit(DynExp::ModuleInstance *Instance) const override final
This event is triggered right before the module thread terminates (not due to an exception,...
void OnLowerFrequencyLimitChanged(DynExp::ModuleInstance *Instance, double LowerFrequencyLimit) const
void OnPathChanged(DynExp::ModuleInstance *Instance, const std::string &SaveFilename) const
void OnNumberOfStepsChanged(DynExp::ModuleInstance *Instance, int NumberOfSteps) const
void OnUpperFrequencyLimitChanged(DynExp::ModuleInstance *Instance, double UpperFrequencyLimit) const
void UpdateUIChild(const ModuleBase::ModuleDataGetterType &ModuleDataGetter) override final
void OnScanBackAndForthToggled(DynExp::ModuleInstance *Instance, bool Checked) const
void OnFrequencyRangeChanged(DynExp::ModuleInstance *Instance, double FrequencyRange) const
void OnCenterFrequencyChanged(DynExp::ModuleInstance *Instance, double CenterFrequency) 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:3176
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:625
const std::unique_ptr< ModuleDataType > ModuleData
Module data belonging to this ModuleBase instance.
Definition Module.h:789
ModuleBase(const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params)
Constructs a ModuleBase instance.
Definition Module.cpp:206
Refer to ParamsBase::dispatch_tag.
Definition Module.h:192
Defines data for a thread belonging to a ModuleBase instance. Refer to RunnableInstance.
Definition Module.h:841
const std::thread::id OwnerThreadID
Thread id of the thread which has constructed (and owns) this Object instance.
Definition Object.h:2310
const ParamsBasePtrType Params
Pointer to the parameter class instance belonging to this Object instance.
Definition Object.h:2311
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:1668
Configurator class for QModuleBase.
Definition Module.h:1654
Data class for QModuleBase.
Definition Module.h:1544
Parameter class for QModuleBase.
Definition Module.h:1630
QModuleParamsBase(ItemIDType ID, const DynExpCore &Core)
Constructs the parameters for a QModuleBase instance.
Definition Module.h:1636
Window class for Qt-based user interfaces belonging to DynExp modules. User interface Qt window class...
Definition Module.h:1396
QModuleBase & Owner
Module owning this user interface window (reference, because it should never change nor be nullptr).
Definition Module.h:1486
QModuleWidget(QModuleBase &Owner, QWidget *Parent=nullptr)
Constructs a QModuleWidget instance.
Definition Module.cpp:451
State machine state as used by class StateMachine. A state mainly wraps a state function of the membe...
Definition Util.h:1363
Pointer to lock a class derived from ISynchronizedPointerLockable for synchronizing between threads....
Definition Util.h:171
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.