swift
Loading...
Searching...
No Matches
cockpitcomcomponent.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include <QDoubleSpinBox>
7#include <QLabel>
8#include <QPushButton>
9#include <QString>
10#include <QtGlobal>
11
12#include "ui_cockpitcomcomponent.h"
13
21#include "gui/guiapplication.h"
22#include "gui/led.h"
28#include "misc/logmessage.h"
29#include "misc/pq/frequency.h"
30#include "misc/pq/units.h"
31#include "misc/sequence.h"
32#include "misc/verify.h"
33
34using namespace swift::gui;
35using namespace swift::gui::editors;
36using namespace swift::core;
37using namespace swift::core::context;
38using namespace swift::misc;
39using namespace swift::misc::audio;
40using namespace swift::misc::aviation;
41using namespace swift::misc::simulation;
42using namespace swift::misc::physical_quantities;
43
45{
47 : QFrame(parent), CIdentifiable(this), ui(new Ui::CCockpitComComponent)
48 {
49 ui->setupUi(this);
50
51 // init from aircraft
52 this->forceCockpitUpdateFromOwnAircraftContext();
53
54 // COM form
55 connect(ui->editor_Com, &CCockpitComForm::testSelcal, this, &CCockpitComComponent::testSelcal);
57 &CCockpitComComponent::updateOwnCockpitInContext);
58 connect(ui->editor_Com, &CCockpitComForm::changedSelcal, this, &CCockpitComComponent::updateSelcalInContext);
63
64 // Relay COM form signals
69
70 // hook up with changes from own aircraft context
71 if (sGui)
72 {
73 // own aircraft
74 connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this,
75 &CCockpitComComponent::updateCockpitFromContext, Qt::QueuedConnection);
76 connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedSelcal, this,
77 &CCockpitComComponent::updateSelcalFromContext, Qt::QueuedConnection);
78
79 // hook up with audio context
80 // connect(sGui->getIContextAudio(), &IContextAudio::changedVoiceRooms, this,
81 // &CCockpitComComponent::updateVoiceRoomStatusFromContext, Qt::QueuedConnection);
82
84 QTimer::singleShot(10 * 1000, this, [=, this] {
85 if (!sGui || sGui->isShuttingDown() || !myself)
86 {
87 return;
88 }
89 const CSimulatedAircraft aircraft = sGui->getIContextOwnAircraft()->getOwnAircraft();
90 this->updateCockpitFromContext(aircraft, CIdentifier::fake());
91 });
92 }
93 }
94
96
97 void CCockpitComComponent::setTransponderModeStateIdent() { ui->editor_Com->setTransponderModeStateIdent(); }
98
104
105 void CCockpitComComponent::updateCockpitFromContext(const CSimulatedAircraft &ownAircraft,
106 const CIdentifier &originator)
107 {
108 if (isMyIdentifier(originator))
109 {
110 return;
111 } // comes from myself
112
113 // update GUI elements
114 // avoid unnecessary change events as far as possible
115 const CComSystem com1 = ownAircraft.getCom1System(); // aircraft just updated or set from context
116 const CComSystem com2 = ownAircraft.getCom2System();
117 const CTransponder transponder = ownAircraft.getTransponder();
118
119 // update the frequencies
120 ui->editor_Com->setFrequencies(com1, com2);
121
122 // update transponder
123 ui->editor_Com->setTransponder(transponder);
124 }
125
126 void CCockpitComComponent::testSelcal()
127 {
128 Q_ASSERT_X(sGui, Q_FUNC_INFO, "Need sGui");
129 const CSelcal selcal = ui->editor_Com->getSelcal();
130 if (!selcal.isValid())
131 {
132 CLogMessage().validationWarning(u"Invalid SELCAL code");
133 }
134 else if (sGui->getCContextAudioBase())
135 {
136 sGui->getCContextAudioBase()->playSelcalTone(selcal);
137 }
138 else
139 {
140 CLogMessage().validationWarning(u"No audio available");
141 }
142 }
143
144 void CCockpitComComponent::updateSelcalFromContext(const CSelcal &selcal, const CIdentifier &originator)
145 {
146 if (isMyIdentifier(originator))
147 {
148 return;
149 } // comes from myself
150 ui->editor_Com->setSelcal(selcal);
151 }
152
153 CSimulatedAircraft CCockpitComComponent::getOwnAircraft() const
154 {
155 // unavailable context during shutdown possible
156 // mostly when client runs with DBus, but DBus is down
158 {
159 return {};
160 }
162 }
163
164 bool CCockpitComComponent::updateOwnCockpitInContext(const CSimulatedAircraft &ownAircraft)
165 {
166 // unavailable context during shutdown possible
167 // mostly when client runs with DBus, but DBus is down
169 {
170 return false;
171 }
172 return sGui->getIContextOwnAircraft()->updateCockpit(ownAircraft.getCom1System(), ownAircraft.getCom2System(),
173 ownAircraft.getTransponder(), identifier());
174 }
175
176 void CCockpitComComponent::forceCockpitUpdateFromOwnAircraftContext()
177 {
178 if (!sGui || sGui->isShuttingDown())
179 {
180 return;
181 }
182 const CSimulatedAircraft ownAircraft = this->getOwnAircraft();
183 this->updateCockpitFromContext(ownAircraft,
184 CIdentifier("dummyInitialValues")); // intentionally different name here
185 }
186
187 void CCockpitComComponent::updateSelcalInContext(const CSelcal &selcal)
188 {
190 {
191 return;
192 }
194 }
195} // namespace swift::gui::components
const context::IContextOwnAircraft * getIContextOwnAircraft() const
Direct access to contexts if a CCoreFacade has been initialized.
bool isShuttingDown() const
Is application shutting down?
void changedAircraftCockpit(const swift::misc::simulation::CSimulatedAircraft &aircraft, const swift::misc::CIdentifier &originator)
Aircraft cockpit update.
virtual bool updateSelcal(const swift::misc::aviation::CSelcal &selcal, const swift::misc::CIdentifier &originator)=0
Own SELCAL code.
virtual swift::misc::simulation::CSimulatedAircraft getOwnAircraft() const =0
Get own aircraft.
void changedSelcal(const swift::misc::aviation::CSelcal &selcal, const swift::misc::CIdentifier &originator)
Changed SELCAL code.
virtual bool updateCockpit(const swift::misc::aviation::CComSystem &com1, const swift::misc::aviation::CComSystem &com2, const swift::misc::aviation::CTransponder &transponder, const swift::misc::CIdentifier &originator)=0
Update own cockpit.
static bool useStyleSheetInDerivedWidget(QWidget *derivedWidget, QStyle::PrimitiveElement element=QStyle::PE_Widget)
Use style sheets in derived widgets.
CCockpitComComponent(QWidget *parent=nullptr)
Constructor.
void requestCom1TextMessage()
Request COM text messages.
void transponderModeChanged(swift::misc::aviation::CTransponder::TransponderMode newMode)
Mode / state has been changed.
void setTransponderModeStateIdent()
Set to swift::misc::aviation::CTransponder::StateIdent.
void requestCom2TextMessage()
Request COM text messages.
void transponderStateIdentEnded()
Ident phase ended.
void transponderStateIdentEnded()
Ident phase ended.
void requestCom2TextMessage()
Request COM text messages.
void requestCom1TextMessage()
Request COM text messages.
void transponderModeChanged(swift::misc::aviation::CTransponder::TransponderMode newMode)
Mode / state has been changed.
void changedCockpitValues(const swift::misc::simulation::CSimulatedAircraft &aircraft)
GUI values changed.
void testSelcal()
Request to test SELCAL.
void changedSelcal(const swift::misc::aviation::CSelcal &selcal)
SELCAL value changed.
bool isMyIdentifier(const CIdentifier &otherIdentifier) const
My identifier?
CIdentifiable(const QString &objectName)
Use literal based object name.
const CIdentifier & identifier() const
Get identifier.
Value object encapsulating information identifying a component of a modular distributed swift process...
Definition identifier.h:29
static const CIdentifier & fake()
Returns a fake identifier.
Class for emitting a log message.
Definition logmessage.h:27
Derived & validationWarning(const char16_t(&format)[N])
Set the severity to warning, providing a format string, and adding the validation category.
COM system (aka "radio").
Definition comsystem.h:37
Value object for SELCAL.
Definition selcal.h:31
bool isValid() const
Is valid?
Definition selcal.h:43
Comprehensive information of an aircraft.
const aviation::CComSystem & getCom2System() const
Get COM2 system.
const aviation::CComSystem & getCom1System() const
Get COM1 system.
const aviation::CTransponder & getTransponder() const
Get transponder.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
Backend services of the swift project, like dealing with the network or the simulators.
Definition actionbind.cpp:7
High level reusable GUI components.
GUI related classes.
Free functions in swift::misc.
QFrame(QWidget *parent, Qt::WindowFlags f)
virtual bool event(QEvent *e) override
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
QueuedConnection
QWidget(QWidget *parent, Qt::WindowFlags f)