Skip to content

Commit

Permalink
UTMSP: Convert to Singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey committed Nov 22, 2024
1 parent fb11f31 commit d40f658
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 106 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ list(APPEND QGC_RESOURCES
)

if(QGC_UTM_ADAPTER)
add_definitions(-DQGC_UTM_ADAPTER)
list(APPEND QGC_RESOURCES ${CMAKE_SOURCE_DIR}/src/UTMSP/utmsp.qrc)
else()
list(APPEND QGC_RESOURCES ${CMAKE_SOURCE_DIR}/src/UTMSP/dummy/utmsp_dummy.qrc)
Expand Down
4 changes: 0 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ qt_add_library(QGC STATIC
QGCToolbox.h
)

if(QGC_UTM_ADAPTER)
add_definitions(-DQGC_UTM_ADAPTER)
endif()

add_subdirectory(ADSB)
add_subdirectory(AnalyzeView)
add_subdirectory(API)
Expand Down
4 changes: 1 addition & 3 deletions src/MissionManager/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
find_package(Qt6 REQUIRED COMPONENTS Core Gui Positioning Qml Xml)
if(QGC_UTM_ADAPTER)
add_definitions(-DQGC_UTM_ADAPTER)
endif()

qt_add_library(MissionManager STATIC
BlankPlanCreator.cc
Expand Down Expand Up @@ -98,6 +95,7 @@ target_link_libraries(MissionManager
Settings
Terrain
Utilities
UTMSP
Vehicle
)

Expand Down
4 changes: 0 additions & 4 deletions src/PlanView/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ find_package(Qt6 REQUIRED COMPONENTS Core Qml)

qt_add_library(PlanView STATIC)

if(QGC_UTM_ADAPTER)
add_definitions(-DQGC_UTM_ADAPTER)
endif()

file(GLOB QML_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.qml)
qt_add_qml_module(PlanView
URI QGroundControl.PlanView
Expand Down
9 changes: 0 additions & 9 deletions src/QGCToolbox.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
#include "QGCCorePlugin.h"
#include "SettingsManager.h"
#include "QGCApplication.h"
#ifdef QGC_UTM_ADAPTER
#include "UTMSPManager.h"
#endif

#if defined(QGC_CUSTOM_BUILD)
#include CUSTOMHEADER
Expand All @@ -35,9 +32,6 @@ QGCToolbox::QGCToolbox(QGCApplication* app)
_mavlinkProtocol = new MAVLinkProtocol (app, this);
_multiVehicleManager = new MultiVehicleManager (app, this);
_videoManager = new VideoManager (app, this);
#ifdef QGC_UTM_ADAPTER
_utmspManager = new UTMSPManager (app, this);
#endif
}

void QGCToolbox::setChildToolboxes(void)
Expand All @@ -50,9 +44,6 @@ void QGCToolbox::setChildToolboxes(void)
_mavlinkProtocol->setToolbox(this);
_multiVehicleManager->setToolbox(this);
_videoManager->setToolbox(this);
#ifdef QGC_UTM_ADAPTER
_utmspManager->setToolbox(this);
#endif
}

void QGCToolbox::_scanAndLoadPlugins(QGCApplication* app)
Expand Down
9 changes: 0 additions & 9 deletions src/QGCToolbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class QGCApplication;
class VideoManager;
class QGCCorePlugin;
class SettingsManager;
#ifdef QGC_UTM_ADAPTER
class UTMSPManager;
#endif

/// This is used to manage all of our top level services/tools
class QGCToolbox : public QObject {
Expand All @@ -37,9 +34,6 @@ class QGCToolbox : public QObject {
VideoManager* videoManager () { return _videoManager; }
QGCCorePlugin* corePlugin () { return _corePlugin; }
SettingsManager* settingsManager () { return _settingsManager; }
#ifdef QGC_UTM_ADAPTER
UTMSPManager* utmspManager () { return _utmspManager; }
#endif

private:
void setChildToolboxes(void);
Expand All @@ -51,9 +45,6 @@ class QGCToolbox : public QObject {
VideoManager* _videoManager = nullptr;
QGCCorePlugin* _corePlugin = nullptr;
SettingsManager* _settingsManager = nullptr;
#ifdef QGC_UTM_ADAPTER
UTMSPManager* _utmspManager = nullptr;
#endif
friend class QGCApplication;
};

Expand Down
4 changes: 0 additions & 4 deletions src/QmlControls/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
find_package(Qt6 REQUIRED COMPONENTS Concurrent Core Gui Location Positioning Qml QmlIntegration Quick Widgets)

if(QGC_UTM_ADAPTER)
add_definitions(-DQGC_UTM_ADAPTER)
endif()

qt_add_library(QmlControls STATIC
AppMessages.cc
AppMessages.h
Expand Down
9 changes: 6 additions & 3 deletions src/QmlControls/QGroundControlQmlGlobal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#ifndef QGC_AIRLINK_DISABLED
#include "AirLinkManager.h"
#endif
#ifdef QGC_UTM_ADAPTER
#include "UTMSPManager.h"
#endif

#include <QtCore/QSettings>
#include <QtCore/QLineF>
Expand All @@ -46,6 +49,9 @@ QGroundControlQmlGlobal::QGroundControlQmlGlobal(QGCApplication* app, QGCToolbox
#ifndef QGC_AIRLINK_DISABLED
, _airlinkManager(AirLinkManager::instance())
#endif
#ifdef QGC_UTM_ADAPTER
, _utmspManager(UTMSPManager::instance())
#endif
{
// We clear the parent on this object since we run into shutdown problems caused by hybrid qml app. Instead we let it leak on shutdown.
// setParent(nullptr);
Expand Down Expand Up @@ -95,9 +101,6 @@ void QGroundControlQmlGlobal::setToolbox(QGCToolbox* toolbox)
_gpsRtkFactGroup = GPSManager::instance()->gpsRtk()->gpsRtkFactGroup();
#endif
_globalPalette = new QGCPalette(this);
#ifdef QGC_UTM_ADAPTER
_utmspManager = toolbox->utmspManager();
#endif
}

void QGroundControlQmlGlobal::saveGlobalSetting (const QString& key, const QString& value)
Expand Down
15 changes: 6 additions & 9 deletions src/QmlControls/QGroundControlQmlGlobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,6 @@ class QGroundControlQmlGlobal : public QGCTool
bool airlinkSupported () { return false; }
#endif

#ifdef QGC_UTM_ADAPTER
UTMSPManager* utmspManager () {return _utmspManager;}
#endif

qreal zOrderTopMost () { return 1000; }
qreal zOrderWidgets () { return 100; }
qreal zOrderMapItems () { return 50; }
Expand Down Expand Up @@ -236,9 +232,10 @@ class QGroundControlQmlGlobal : public QGCTool
QString qgcVersion (void) const;

#ifdef QGC_UTM_ADAPTER
bool utmspSupported() { return true; }
UTMSPManager* utmspManager() {return _utmspManager;}
bool utmspSupported() { return true; }
#else
bool utmspSupported() { return false; }
bool utmspSupported() { return false; }
#endif

// Overrides from QGCTool
Expand All @@ -260,6 +257,9 @@ class QGroundControlQmlGlobal : public QGCTool
#ifndef QGC_AIRLINK_DISABLED
AirLinkManager* _airlinkManager = nullptr;
#endif
#ifdef QGC_UTM_ADAPTER
UTMSPManager* _utmspManager;
#endif

double _flightMapInitialZoom = 17.0;
LinkManager* _linkManager = nullptr;
Expand All @@ -272,9 +272,6 @@ class QGroundControlQmlGlobal : public QGCTool
#endif
QGCPalette* _globalPalette = nullptr;
QmlUnitsConversion _unitsConversion;
#ifdef QGC_UTM_ADAPTER
UTMSPManager* _utmspManager;
#endif

bool _skipSetupPage = false;
QStringList _altitudeModeEnumString;
Expand Down
27 changes: 13 additions & 14 deletions src/UTMSP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ qt_add_library(UTMSP STATIC)

if(QGC_UTM_ADAPTER)
message(STATUS "UTMSP is Initialized")
add_definitions(-DQGC_UTM_ADAPTER)

if(NOT nlohmann_json_FOUND)
message(STATUS "UTMSP: Fetching nlohmann/json")
include(FetchContent)
FetchContent_Declare(json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.3
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(json)
endif()
# if(NOT TARGET nlohmann_json)
# message(STATUS "UTMSP: Fetching nlohmann/json")
# include(FetchContent)
# FetchContent_Declare(json
# GIT_REPOSITORY https://github.com/nlohmann/json.git
# GIT_TAG v3.11.3
# GIT_SHALLOW TRUE
# )
# FetchContent_MakeAvailable(json)
# endif()

find_package(Qt6 REQUIRED COMPONENTS Network Positioning Qml)
find_package(Threads REQUIRED)
Expand Down Expand Up @@ -52,14 +51,14 @@ if(QGC_UTM_ADAPTER)

target_link_libraries(UTMSP
PRIVATE
nlohmann_json
Threads::Threads
Qt6::Network
Comms
Vehicle
PUBLIC
# nlohmann_json
Qt6::Core
Qt6::Positioning
QGC
)

target_include_directories(UTMSP
Expand All @@ -69,7 +68,7 @@ if(QGC_UTM_ADAPTER)
${CMAKE_CURRENT_SOURCE_DIR}
)

target_compile_definitions(UTMSP PUBLIC CONFIG_UTM_ADAPTER)
target_compile_definitions(UTMSP PUBLIC QGC_UTM_ADAPTER)

# qt_add_qml_module(UTMSP
# URI QGroundControl.UTMSP
Expand Down
3 changes: 2 additions & 1 deletion src/UTMSP/UTMSPAuthorization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
*
****************************************************************************/

#include <nlohmann/json.hpp>
// #include <nlohmann/json.hpp>
#include <string>
#include <QByteArray>
#include <QBitArray>
#include <QString>

#include "UTMSPLogger.h"
#include "UTMSPAuthorization.h"
#include "parse/nlohmann/json.hpp"

using json = nlohmann::ordered_json;

Expand Down
3 changes: 2 additions & 1 deletion src/UTMSP/UTMSPFlightPlanManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
#pragma once

#include <string>
#include <nlohmann/json.hpp>
// #include <nlohmann/json_fwd.hpp>

#include "UTMSPBlenderRestInterface.h"
#include "parse/nlohmann/json.hpp"

using json = nlohmann::ordered_json;

Expand Down
46 changes: 28 additions & 18 deletions src/UTMSP/UTMSPManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,56 @@
*
****************************************************************************/


#include "UTMSPManager.h"
#include "UTMSPLogger.h"
#include "UTMSPVehicle.h"

#include "services/dispatcher.h"
#include "Vehicle.h"
#include "qqml.h"
#include <QtQml/qqml.h>
#include <QtCore/qapplicationstatic.h>

Q_APPLICATION_STATIC(UTMSPManager, _UTMSPManagerInstance);

UTMSPManager::UTMSPManager(QGCApplication* app, QGCToolbox* toolbox) :
QGCTool(app, toolbox),
_dispatcher(std::make_shared<Dispatcher>())
UTMSPManager::UTMSPManager(QObject *parent)
: QObject(parent)
, _utmspAuthorization(new UTMSPAuthorization(this))
, _dispatcher(std::make_shared<Dispatcher>())
{
_utmspAuthorization = new UTMSPAuthorization();
qmlRegisterUncreatableType<UTMSPManager> ("QGroundControl.UTMSP", 1, 0, "UTMSPManager", "Reference only");
qmlRegisterUncreatableType<UTMSPVehicle> ("QGroundControl.UTMSP", 1, 0, "UTMSPVehicle", "Reference only");
qmlRegisterUncreatableType<UTMSPAuthorization> ("QGroundControl.UTMSP", 1, 0, "UTMSPAuthorization", "Reference only");
(void) qmlRegisterUncreatableType<UTMSPManager>("QGroundControl.UTMSP", 1, 0, "UTMSPManager", "Reference only");
(void) qmlRegisterUncreatableType<UTMSPVehicle>("QGroundControl.UTMSP", 1, 0, "UTMSPVehicle", "Reference only");
(void) qmlRegisterUncreatableType<UTMSPAuthorization>("QGroundControl.UTMSP", 1, 0, "UTMSPAuthorization", "Reference only");
}

UTMSPManager::~UTMSPManager()
{
UTMSP_LOG_DEBUG() << "UTMSPManager: Destructor called";
delete _utmspAuthorization;
_utmspAuthorization = nullptr;
}

void UTMSPManager::setToolbox(QGCToolbox* toolbox)
UTMSPManager *UTMSPManager::instance()
{
UTMSP_LOG_INFO() << "UTMSPManager: ToolBox Set" ;
QGCTool::setToolbox(toolbox);
return _UTMSPManagerInstance();
}

UTMSPVehicle* UTMSPManager::instantiateVehicle(const Vehicle& vehicle)
UTMSPAuthorization *UTMSPManager::utmspAuthorization()
{
// TODO: Investigate safe deletion of pointer in this modification of having a member pointer
_vehicle = new UTMSPVehicle(_dispatcher,vehicle);
return _utmspAuthorization;
}

UTMSPVehicle *UTMSPManager::utmspVehicle()
{
return _vehicle;
}

UTMSPAuthorization* UTMSPManager::instantiateUTMSPAuthorization(){
UTMSPVehicle* UTMSPManager::instantiateVehicle(const Vehicle &vehicle)
{
// TODO: Investigate safe deletion of pointer in this modification of having a member pointer
_vehicle = new UTMSPVehicle(_dispatcher, vehicle);

return _vehicle;
}

UTMSPAuthorization* UTMSPManager::instantiateUTMSPAuthorization()
{
return _utmspAuthorization;
}
Loading

0 comments on commit d40f658

Please sign in to comment.