From c12c22eac788a16ec3c608af695bd148d7bc6bda Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Sun, 5 Jan 2025 11:14:18 +0100 Subject: [PATCH] ui: onroad skeleton (#521) * onroad init * init model renderer * Add default virtual destructors to HudRenderer and AnnotatedCameraWidget This ensures proper cleanup of derived classes if they override these destructors. Adding default destructors promotes better memory safety and adheres to modern C++ best practices. --------- Co-authored-by: Jason Wen --- selfdrive/ui/qt/onroad/annotated_camera.h | 10 +++++++-- selfdrive/ui/qt/onroad/hud.h | 12 ++++++++--- selfdrive/ui/qt/onroad/onroad_home.h | 5 ++++- selfdrive/ui/sunnypilot/SConscript | 3 +++ .../sunnypilot/qt/onroad/annotated_camera.cc | 16 ++++++++++++++ .../sunnypilot/qt/onroad/annotated_camera.h | 18 ++++++++++++++++ selfdrive/ui/sunnypilot/qt/onroad/hud.cc | 18 ++++++++++++++++ selfdrive/ui/sunnypilot/qt/onroad/hud.h | 21 +++++++++++++++++++ selfdrive/ui/sunnypilot/qt/onroad/model.cc | 8 +++++++ selfdrive/ui/sunnypilot/qt/onroad/model.h | 15 +++++++++++++ 10 files changed, 120 insertions(+), 6 deletions(-) create mode 100644 selfdrive/ui/sunnypilot/qt/onroad/annotated_camera.cc create mode 100644 selfdrive/ui/sunnypilot/qt/onroad/annotated_camera.h create mode 100644 selfdrive/ui/sunnypilot/qt/onroad/hud.cc create mode 100644 selfdrive/ui/sunnypilot/qt/onroad/hud.h create mode 100644 selfdrive/ui/sunnypilot/qt/onroad/model.cc create mode 100644 selfdrive/ui/sunnypilot/qt/onroad/model.h diff --git a/selfdrive/ui/qt/onroad/annotated_camera.h b/selfdrive/ui/qt/onroad/annotated_camera.h index d205579f6..a161b89ee 100644 --- a/selfdrive/ui/qt/onroad/annotated_camera.h +++ b/selfdrive/ui/qt/onroad/annotated_camera.h @@ -2,18 +2,24 @@ #include #include -#include "selfdrive/ui/qt/onroad/hud.h" #include "selfdrive/ui/qt/onroad/buttons.h" #include "selfdrive/ui/qt/onroad/driver_monitoring.h" #include "selfdrive/ui/qt/onroad/model.h" #include "selfdrive/ui/qt/widgets/cameraview.h" +#ifdef SUNNYPILOT +#include "selfdrive/ui/sunnypilot/qt/onroad/hud.h" +#else +#include "selfdrive/ui/qt/onroad/hud.h" +#endif + class AnnotatedCameraWidget : public CameraWidget { Q_OBJECT public: explicit AnnotatedCameraWidget(VisionStreamType type, QWidget* parent = 0); - void updateState(const UIState &s); + virtual ~AnnotatedCameraWidget() = default; + virtual void updateState(const UIState &s); private: QVBoxLayout *main_layout; diff --git a/selfdrive/ui/qt/onroad/hud.h b/selfdrive/ui/qt/onroad/hud.h index 0b1220a27..893a9133f 100644 --- a/selfdrive/ui/qt/onroad/hud.h +++ b/selfdrive/ui/qt/onroad/hud.h @@ -1,17 +1,23 @@ #pragma once #include + +#ifdef SUNNYPILOT +#include "selfdrive/ui/sunnypilot/ui.h" +#else #include "selfdrive/ui/ui.h" +#endif class HudRenderer : public QObject { Q_OBJECT public: HudRenderer(); - void updateState(const UIState &s); - void draw(QPainter &p, const QRect &surface_rect); + virtual ~HudRenderer() = default; + virtual void updateState(const UIState &s); + virtual void draw(QPainter &p, const QRect &surface_rect); -private: +protected: void drawSetSpeed(QPainter &p, const QRect &surface_rect); void drawCurrentSpeed(QPainter &p, const QRect &surface_rect); void drawText(QPainter &p, int x, int y, const QString &text, int alpha = 255); diff --git a/selfdrive/ui/qt/onroad/onroad_home.h b/selfdrive/ui/qt/onroad/onroad_home.h index 2224ede32..9b51bb62e 100644 --- a/selfdrive/ui/qt/onroad/onroad_home.h +++ b/selfdrive/ui/qt/onroad/onroad_home.h @@ -1,10 +1,13 @@ #pragma once #include "selfdrive/ui/qt/onroad/alerts.h" -#include "selfdrive/ui/qt/onroad/annotated_camera.h" #ifdef SUNNYPILOT +#include "selfdrive/ui/sunnypilot/qt/onroad/annotated_camera.h" #define UIState UIStateSP +#define AnnotatedCameraWidget AnnotatedCameraWidgetSP +#else +#include "selfdrive/ui/qt/onroad/annotated_camera.h" #endif class OnroadWindow : public QWidget { diff --git a/selfdrive/ui/sunnypilot/SConscript b/selfdrive/ui/sunnypilot/SConscript index 0a5016d58..f1fb707c5 100644 --- a/selfdrive/ui/sunnypilot/SConscript +++ b/selfdrive/ui/sunnypilot/SConscript @@ -17,6 +17,9 @@ qt_src = [ "sunnypilot/qt/offroad/settings/software_panel.cc", "sunnypilot/qt/offroad/settings/sunnylink_panel.cc", "sunnypilot/qt/offroad/settings/sunnypilot_panel.cc", + "sunnypilot/qt/onroad/annotated_camera.cc", + "sunnypilot/qt/onroad/hud.cc", + "sunnypilot/qt/onroad/model.cc", "sunnypilot/qt/onroad/onroad_home.cc", ] diff --git a/selfdrive/ui/sunnypilot/qt/onroad/annotated_camera.cc b/selfdrive/ui/sunnypilot/qt/onroad/annotated_camera.cc new file mode 100644 index 000000000..3721a3d19 --- /dev/null +++ b/selfdrive/ui/sunnypilot/qt/onroad/annotated_camera.cc @@ -0,0 +1,16 @@ +/** + * Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + * + * This file is part of sunnypilot and is licensed under the MIT License. + * See the LICENSE.md file in the root directory for more details. + */ + +#include "selfdrive/ui/sunnypilot/qt/onroad/annotated_camera.h" + +AnnotatedCameraWidgetSP::AnnotatedCameraWidgetSP(VisionStreamType type, QWidget *parent) + : AnnotatedCameraWidget(type, parent) { +} + +void AnnotatedCameraWidgetSP::updateState(const UIState &s) { + AnnotatedCameraWidget::updateState(s); +} diff --git a/selfdrive/ui/sunnypilot/qt/onroad/annotated_camera.h b/selfdrive/ui/sunnypilot/qt/onroad/annotated_camera.h new file mode 100644 index 000000000..46ce7d4be --- /dev/null +++ b/selfdrive/ui/sunnypilot/qt/onroad/annotated_camera.h @@ -0,0 +1,18 @@ +/** + * Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + * + * This file is part of sunnypilot and is licensed under the MIT License. + * See the LICENSE.md file in the root directory for more details. + */ + +#pragma once + +#include "selfdrive/ui/qt/onroad/annotated_camera.h" + +class AnnotatedCameraWidgetSP : public AnnotatedCameraWidget { + Q_OBJECT + +public: + explicit AnnotatedCameraWidgetSP(VisionStreamType type, QWidget *parent = nullptr); + void updateState(const UIState &s) override; +}; diff --git a/selfdrive/ui/sunnypilot/qt/onroad/hud.cc b/selfdrive/ui/sunnypilot/qt/onroad/hud.cc new file mode 100644 index 000000000..233ca59f9 --- /dev/null +++ b/selfdrive/ui/sunnypilot/qt/onroad/hud.cc @@ -0,0 +1,18 @@ +/** + * Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + * + * This file is part of sunnypilot and is licensed under the MIT License. + * See the LICENSE.md file in the root directory for more details. + */ + +#include "selfdrive/ui/sunnypilot/qt/onroad/hud.h" + +HudRendererSP::HudRendererSP() {} + +void HudRendererSP::updateState(const UIState &s) { + HudRenderer::updateState(s); +} + +void HudRendererSP::draw(QPainter &p, const QRect &surface_rect) { + HudRenderer::draw(p, surface_rect); +} diff --git a/selfdrive/ui/sunnypilot/qt/onroad/hud.h b/selfdrive/ui/sunnypilot/qt/onroad/hud.h new file mode 100644 index 000000000..1e98cd3a5 --- /dev/null +++ b/selfdrive/ui/sunnypilot/qt/onroad/hud.h @@ -0,0 +1,21 @@ +/** + * Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + * + * This file is part of sunnypilot and is licensed under the MIT License. + * See the LICENSE.md file in the root directory for more details. + */ + +#pragma once + +#include + +#include "selfdrive/ui/qt/onroad/hud.h" + +class HudRendererSP : public HudRenderer { + Q_OBJECT + +public: + HudRendererSP(); + void updateState(const UIState &s) override; + void draw(QPainter &p, const QRect &surface_rect) override; +}; diff --git a/selfdrive/ui/sunnypilot/qt/onroad/model.cc b/selfdrive/ui/sunnypilot/qt/onroad/model.cc new file mode 100644 index 000000000..617b64f58 --- /dev/null +++ b/selfdrive/ui/sunnypilot/qt/onroad/model.cc @@ -0,0 +1,8 @@ +/** + * Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + * + * This file is part of sunnypilot and is licensed under the MIT License. + * See the LICENSE.md file in the root directory for more details. + */ + +#include "selfdrive/ui/sunnypilot/qt/onroad/model.h" diff --git a/selfdrive/ui/sunnypilot/qt/onroad/model.h b/selfdrive/ui/sunnypilot/qt/onroad/model.h new file mode 100644 index 000000000..e8594629c --- /dev/null +++ b/selfdrive/ui/sunnypilot/qt/onroad/model.h @@ -0,0 +1,15 @@ +/** + * Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + * + * This file is part of sunnypilot and is licensed under the MIT License. + * See the LICENSE.md file in the root directory for more details. + */ + +#pragma once + +#include "selfdrive/ui/qt/onroad/model.h" + +class ModelRendererSP : public ModelRenderer { +public: + ModelRendererSP() {} +};