swift
aircraftmodelloaderprovider.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include <QDir>
7 #include <QMap>
8 #include <Qt>
9 #include <QtGlobal>
10 
11 #include "misc/directoryutils.h"
12 #include "misc/logmessage.h"
14 #include "misc/simulation/flightgear/aircraftmodelloaderflightgear.h"
18 
19 using namespace swift::misc;
20 using namespace swift::misc::simulation::data;
21 using namespace swift::misc::simulation::settings;
22 using namespace swift::misc::simulation::fscommon;
23 using namespace swift::misc::simulation::flightgear;
24 using namespace swift::misc::simulation::xplane;
25 
26 namespace swift::misc::simulation
27 {
29  QObject *parent)
30  {
31  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Single simulator");
32  if (simulator.isXPlane()) { return new CAircraftModelLoaderXPlane(parent); }
33  if (simulator.isFG()) { return new CAircraftModelLoaderFlightgear(parent); }
34  return CAircraftCfgParser::createModelLoader(simulator, parent);
35  }
36 
38  {
39  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
40  switch (simulator.getSimulator())
41  {
42  case CSimulatorInfo::P3D:
43  {
44  if (!m_loaderP3D) { m_loaderP3D = this->initLoader(CSimulatorInfo::p3d()); }
45  return m_loaderP3D;
46  }
47  case CSimulatorInfo::XPLANE:
48  {
49  if (!m_loaderXP) { m_loaderXP = this->initLoader(CSimulatorInfo::xplane()); }
50  return m_loaderXP;
51  }
52  case CSimulatorInfo::FG:
53  {
54  if (!m_loaderFG) { m_loaderFG = this->initLoader(CSimulatorInfo::fg()); }
55  return m_loaderFG;
56  }
57  case CSimulatorInfo::MSFS:
58  {
59  if (!m_loaderMsfs) { m_loaderMsfs = this->initLoader(CSimulatorInfo::msfs()); }
60  return m_loaderMsfs;
61  }
62  case CSimulatorInfo::MSFS2024:
63  {
64  if (!m_loaderMsfs2024) { m_loaderMsfs2024 = this->initLoader(CSimulatorInfo::msfs2024()); }
65  return m_loaderMsfs2024;
66  }
67  default: Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator"); break;
68  }
69  return nullptr;
70  }
71 
73  {
75  return loader;
76  }
77 
78  IAircraftModelLoader *CMultiAircraftModelLoaderProvider::initLoader(const CSimulatorInfo &simulator)
79  {
80  // in some cases the loading progress signal was not send properly
81  // changing to Qt::QueuedConnection has solved the issues (Ref T529)
82  IAircraftModelLoader *loader = createModelLoader(simulator, this);
83  bool c = connect(loader, &IAircraftModelLoader::loadingFinished, this,
85  Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
86  c = connect(loader, &IAircraftModelLoader::diskLoadingStarted, this,
88  Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
91  Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
92  c = connect(loader, &IAircraftModelLoader::loadingProgress, this,
94  Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
95  return loader;
96  }
97 } // namespace swift::misc::simulation
Single instances of all model loaders (lazy init)
static IAircraftModelLoader * createModelLoader(const CSimulatorInfo &simulator, QObject *parent=nullptr)
Create a loader and synchronize caches.
IAircraftModelLoader * loaderInstance(const CSimulatorInfo &simulator)
Loader instance.
void diskLoadingStarted(const CSimulatorInfo &simulator, IAircraftModelLoader::LoadMode mode)
Disk loading started.
void cacheChanged(const CSimulatorInfo &simulator)
Relayed from centralized caches.
void loadingFinished(const swift::misc::CStatusMessageList &status, const CSimulatorInfo &simulator, IAircraftModelLoader::LoadFinishedInfo info)
Parsing is finished or cache has been loaded.
static CMultiAircraftModelLoaderProvider & multiModelLoaderInstance()
Singleton.
void loadingProgress(const CSimulatorInfo &simulator, const QString &message, int progressPercentage)
Loading progress, normally from disk.
Simple hardcoded info about the corresponding simulator.
Definition: simulatorinfo.h:41
bool isSingleSimulator() const
Single simulator selected.
Simulator getSimulator() const
Simulator.
static const CSimulatorInfo & msfs()
Const simulator info objects.
static const CSimulatorInfo & p3d()
Const simulator info objects.
static const CSimulatorInfo & xplane()
Const simulator info objects.
static const CSimulatorInfo & msfs2024()
Const simulator info objects.
static const CSimulatorInfo & fg()
Const simulator info objects.
Load the aircraft for a simulator.
void loadingProgress(const CSimulatorInfo &simulator, const QString &message, int progressPercentage)
Loading progress, normally from disk.
void cacheChanged(const CSimulatorInfo &simulator)
Relayed from centralized caches.
void loadingFinished(const CStatusMessageList &status, const CSimulatorInfo &simulator, IAircraftModelLoader::LoadFinishedInfo info)
Parsing is finished or cache has been loaded.
void diskLoadingStarted(const CSimulatorInfo &simulator, IAircraftModelLoader::LoadMode loadMode)
Disk loading started.
Free functions in swift::misc.
QueuedConnection