DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
EventSender.cpp
Go to the documentation of this file.
1// This file is part of DynExp.
2
3#include "stdafx.h"
4#include "moc_EventSender.cpp"
5#include "ui_EventSender.h"
6#include "EventSender.h"
7
8namespace DynExpModule
9{
11 : QModuleWidget(Owner, parent),
12 ui(std::make_unique<Ui::EventSender>()),
13 EventID(0)
14 {
15 ui->setupUi(this);
16 }
17
18 void EventSenderWidget::OnEventDoubleClicked(QListWidgetItem* Item)
19 {
20 EventID = Item->data(Qt::UserRole).value<size_t>();
21 }
22
27
29 {
30 UIInitialized = false;
31 EventID = 0;
32 }
33
35 {
36 auto ModuleData = DynExp::dynamic_ModuleData_cast<EventSender>(Instance.ModuleDataGetter());
37
38 if (ModuleData->EventID)
39 {
40 auto Event = DynExp::InterModuleEventLibrary::Get().GetEvents().at(ModuleData->EventID)();
41 ModuleData->Communicator->PostEvent(*this, *Event);
42
43 ModuleData->EventID = 0;
44 }
45
47 }
48
52
53 std::unique_ptr<DynExp::QModuleWidget> EventSender::MakeUIWidget()
54 {
55 auto Widget = std::make_unique<EventSenderWidget>(*this);
56
57 return Widget;
58 }
59
60 void EventSender::UpdateUIChild(const ModuleBase::ModuleDataGetterType& ModuleDataGetter)
61 {
62 auto Widget = GetWidget<EventSenderWidget>();
63 auto ModuleData = DynExp::dynamic_ModuleData_cast<EventSender>(ModuleDataGetter());
64
65 if (!ModuleData->UIInitialized)
66 {
68
69 for (auto& Event : Events)
70 {
71 const auto E = Event.second();
72
73 auto ListItem = new QListWidgetItem(QString::fromStdString(E->GetName()), Widget->ui->LWEvents);
74 ListItem->setToolTip("ID " + QString::number(Event.first));
75 ListItem->setData(Qt::UserRole, QVariant::fromValue(Event.first));
76 }
77
78 ModuleData->UIInitialized = true;
79 }
80
81 if (Widget->EventID)
82 {
83 ModuleData->EventID = Widget->EventID;
84 Widget->EventID = 0;
85
86 ModuleData->RunQueue();
87 }
88 }
89
91 {
92 auto ModuleParams = DynExp::dynamic_Params_cast<EventSender>(Instance->ParamsGetter());
93 auto ModuleData = DynExp::dynamic_ModuleData_cast<EventSender>(Instance->ModuleDataGetter());
94
95 Instance->LockObject(ModuleParams->Communicator, ModuleData->Communicator);
96 }
97
99 {
100 auto ModuleData = DynExp::dynamic_ModuleData_cast<EventSender>(Instance->ModuleDataGetter());
101
102 Instance->UnlockObject(ModuleData->Communicator);
103 }
104}
Implementation of a module to let the user manually issue inter-module events.
void ResetImpl(dispatch_tag< QModuleDataBase >) override final
std::unique_ptr< Ui::EventSender > ui
Definition EventSender.h:37
EventSenderWidget(EventSender &Owner, QModuleWidget *parent=nullptr)
void OnEventDoubleClicked(QListWidgetItem *Item)
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 ResetImpl(dispatch_tag< QModuleBase >) override final
void OnExit(DynExp::ModuleInstance *Instance) const override final
This event is triggered right before the module thread terminates (not due to an exception,...
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 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 UpdateUIChild(const ModuleBase::ModuleDataGetterType &ModuleDataGetter) override final
static InterModuleEventLibrary & Get()
Getter for the singleton instance of InterModuleEventLibrary.
Definition Module.cpp:432
auto & GetEvents() const noexcept
Getter for Events.
Definition Module.h:1349
const std::unique_ptr< ModuleDataType > ModuleData
Module data belonging to this ModuleBase instance.
Definition Module.h:788
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 ModuleBase::ModuleDataGetterType ModuleDataGetter
Getter for module's data. Refer to ModuleBase::ModuleDataGetterType.
Definition Module.h:872
Refer to ParamsBase::dispatch_tag.
Definition Object.h:2018
QModuleWidget * Widget
User interface widget belonging to the module.
Definition Module.h:1807
const Object::ParamsGetterType ParamsGetter
Invoke to obtain the parameters (derived from ParamsBase) of Owner.
Definition Object.h:3710
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
DynExp's module namespace contains the implementation of DynExp modules which extend DynExp's core fu...
DynExpErrorCodes
DynExp's error codes
Definition Exception.h:22
Accumulates include statements to provide a precompiled header.