swift
simulatorplugincommon.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2018 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
7 #include "gui/guiapplication.h"
9 
10 using namespace swift::gui;
11 using namespace swift::gui::components;
12 using namespace swift::core;
13 using namespace swift::misc;
14 using namespace swift::misc::network;
15 using namespace swift::misc::simulation;
16 
17 namespace swift::simplugin::common
18 {
19  CSimulatorPluginCommon::CSimulatorPluginCommon(const CSimulatorPluginInfo &info,
20  IOwnAircraftProvider *ownAircraftProvider,
21  IRemoteAircraftProvider *renderedAircraftProvider,
22  IClientProvider *clientProvider, QObject *parent)
23  : ISimulator(info, ownAircraftProvider, renderedAircraftProvider, clientProvider, parent)
24  {
26  }
27 
28  CSimulatorPluginCommon::~CSimulatorPluginCommon() { this->deleteInterpolationDisplay(); }
29 
30  void CSimulatorPluginCommon::deleteInterpolationDisplay()
31  {
32  if (m_interpolationDisplayDialog)
33  {
34  // if there is no parent widget, we clean dialog up
35  // otherwise the parent is supposed to clean up
36  CInterpolationLogDisplayDialog *dialog = m_interpolationDisplayDialog;
37  m_interpolationDisplayDialog = nullptr;
38  dialog->close();
39  delete dialog;
40  }
41  }
42 
43  void CSimulatorPluginCommon::showInterpolationDisplay()
44  {
45  if (!m_interpolationDisplayDialog)
46  {
47  QWidget *parentWidget = sGui ? sGui->mainApplicationWidget() : nullptr;
48  CInterpolationLogDisplayDialog *dialog = new CInterpolationLogDisplayDialog(this, nullptr, parentWidget);
49  m_interpolationDisplayDialog = dialog;
50  m_interpolationDisplayDialog->setModal(false);
51  }
52 
53  if (m_interpolationDisplayDialog) { m_interpolationDisplayDialog->show(); }
54  }
55 
57  {
58  // .driver fsuipc on|off
59  if (parser.matchesPart(1, "intdisplay"))
60  {
61  this->showInterpolationDisplay();
62  return true;
63  }
64  return false;
65  }
66 
68  {
69  this->deleteInterpolationDisplay();
70  ISimulator::unload();
71  }
72 
74  {
75  this->deleteInterpolationDisplay();
76  return ISimulator::disconnectFrom();
77  }
78 
80  {
81  if (CSimpleCommandParser::registered("swift::simplugin::common::CSimulatorPluginCommon")) { return; }
82  CSimpleCommandParser::registerCommand({ ".drv intdisplay", "interpolation display" });
83  }
84 } // namespace swift::simplugin::common
Interface to a simulator.
Definition: simulator.h:59
static QWidget * mainApplicationWidget()
Main application window widget.
Utility methods for simple line parsing used with the command line.
bool matchesPart(int index, const QString &toMatch, Qt::CaseSensitivity cs=Qt::CaseInsensitive) const
Matches given part.
Direct in memory access to client (network client) data.
Direct threadsafe in memory access to own aircraft.
Direct thread safe in memory access to remote aircraft.
virtual bool disconnectFrom()
Disconnect from simulator.
virtual void unload()
Driver will be unloaded.
virtual bool parseDetails(const swift::misc::CSimpleCommandParser &parser)
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.
Definition: aboutdialog.cpp:13
GUI related classes.
Free functions in swift::misc.