From 0ee3cfdc22393029c847c87692db32e982012722 Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Mon, 12 Jun 2023 20:28:20 +0000 Subject: [PATCH] Garden bazel Signed-off-by: Michael Carroll --- BUILD.bazel | 495 ++++++++++++++++++ gz_gui_plugin.bzl | 43 ++ src/Application.cc | 20 +- src/MainWindow.cc | 21 +- src/main.cc | 67 +++ .../image_display/ImageDisplay_TEST.cc | 1 - 6 files changed, 635 insertions(+), 12 deletions(-) create mode 100644 BUILD.bazel create mode 100644 gz_gui_plugin.bzl create mode 100644 src/main.cc diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 000000000..83d1d2462 --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,495 @@ +load( + "@gz//bazel/skylark:build_defs.bzl", + "GZ_FEATURES", + "GZ_ROOT", + "GZ_VISIBILITY", + "gz_configure_header", + "gz_export_header", + "gz_include_header", +) +load("@com_justbuchanan_rules_qt//:qt.bzl", "gencpp", "genqrc", "qt_cc_library", "qt_ui_library") +load("gz_gui_plugin.bzl", "gz_gui_plugin") + +package( + default_visibility = GZ_VISIBILITY, + features = GZ_FEATURES, +) + +licenses(["notice"]) # Apache-2.0 + +exports_files(["LICENSE"]) + +gz_configure_header( + name = "gui_config_hh", + src = "include/gz/gui/config.hh.in", + cmakelists = ["CMakeLists.txt"], + package = "gui", +) + +gz_export_header( + name = "include/gz/gui/Export.hh", + export_base = "GZ_GUI", + lib_name = "gz-gui", + visibility = ["//visibility:private"], +) + +public_headers_no_gen = glob([ + "include/gz/gui/*.hh", + "include/gz/gui/*.h", +]) + +sources = glob( + [ + "src/*.cc", + "src/*.hh", + ], + exclude = [ + "src/main.cc", + "src/gz.cc", + "src/*_TEST.cc", + ], +) + +gz_include_header( + name = "gui_hh_genrule", + out = "include/gz/gui.hh", + hdrs = public_headers_no_gen + [ + "include/gz/gui/config.hh", + "include/gz/gui/Export.hh", + ], +) + +public_headers = public_headers_no_gen + [ + "include/gz/gui/config.hh", + "include/gz/gui/Export.hh", +] + +gencpp( + name = "gui_resources_gen", + cpp = "gui_resources.cpp", + files = glob([ + "include/gz/gui/qtquickcontrols2.conf", + "include/gz/gui/qml/*.qml", + "include/gz/gui/qml/images/*.*", + "include/gz/gui/qml/qmldir", + "include/gz/gui/qml/qmldir_deprecated", + ]), + qrc = "include/gz/gui/resources.qrc", + resource_name = "resources", +) + +qt_cc_library( + name = "gui", + srcs = sources + ["gui_resources.cpp"], + hdrs = [ + "include/gz/gui/Application.hh", + "include/gz/gui/Dialog.hh", + "include/gz/gui/MainWindow.hh", + "include/gz/gui/PlottingInterface.hh", + "include/gz/gui/Plugin.hh", + ], + includes = ["include"], + normal_hdrs = [ + "include/gz/gui/qt.h", + "include/gz/gui/Conversions.hh", + "include/gz/gui/DragDropModel.hh", + "include/gz/gui/GuiEvents.hh", + "include/gz/gui/Enums.hh", + "include/gz/gui/config.hh", + "include/gz/gui/Export.hh", + "include/gz/gui/Helpers.hh", + "include/gz/gui/SearchModel.hh", + ], + deps = [ + GZ_ROOT + "common/events", + GZ_ROOT + "msgs", + GZ_ROOT + "transport", + GZ_ROOT + "plugin:loader", + "@qt//:qt_core", + "@qt//:qt_gui", + "@qt//:qt_qml", + "@qt//:qt_quick", + "@qt//:qt_quickcontrols2", + "@qt//:qt_widgets", + ], + alwayslink = 1, +) + +gz_gui_plugin( + name = "camera_fps", + srcs = ["src/plugins/camera_fps/CameraFps.cc"], + hdrs = ["src/plugins/camera_fps/CameraFps.hh"], + qrc_file = "src/plugins/camera_fps/CameraFps.qrc", + qrc_resources = ["src/plugins/camera_fps/CameraFps.qml"], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "common/profiler", + GZ_ROOT + "plugin:register", + GZ_ROOT + "rendering", + ":gui", + ], +) + +gz_gui_plugin( + name = "camera_tracking", + srcs = ["src/plugins/camera_tracking/CameraTracking.cc"], + hdrs = ["src/plugins/camera_tracking/CameraTracking.hh"], + qrc_file = "src/plugins/camera_tracking/CameraTracking.qrc", + qrc_resources = ["src/plugins/camera_tracking/CameraTracking.qml"], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "common/profiler", + GZ_ROOT + "plugin:register", + GZ_ROOT + "rendering", + ":gui", + ], +) + +gz_gui_plugin( + name = "grid_config", + srcs = ["src/plugins/grid_config/GridConfig.cc"], + hdrs = ["src/plugins/grid_config/GridConfig.hh"], + qrc_file = "src/plugins/grid_config/GridConfig.qrc", + qrc_resources = ["src/plugins/grid_config/GridConfig.qml"], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "common/profiler", + GZ_ROOT + "plugin:register", + GZ_ROOT + "rendering", + ":gui", + ], +) + +gz_gui_plugin( + name = "image_display", + srcs = ["src/plugins/image_display/ImageDisplay.cc"], + hdrs = ["src/plugins/image_display/ImageDisplay.hh"], + qrc_file = "src/plugins/image_display/ImageDisplay.qrc", + qrc_resources = ["src/plugins/image_display/ImageDisplay.qml"], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "plugin:register", + GZ_ROOT + "rendering", + ":gui", + ], +) + +gz_gui_plugin( + name = "interactive_view_control", + srcs = ["src/plugins/interactive_view_control/InteractiveViewControl.cc"], + hdrs = ["src/plugins/interactive_view_control/InteractiveViewControl.hh"], + qrc_file = "src/plugins/interactive_view_control/InteractiveViewControl.qrc", + qrc_resources = ["src/plugins/interactive_view_control/InteractiveViewControl.qml"], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "plugin:register", + GZ_ROOT + "rendering", + ":gui", + ], +) + +gz_gui_plugin( + name = "key_publisher", + srcs = ["src/plugins/key_publisher/KeyPublisher.cc"], + hdrs = ["src/plugins/key_publisher/KeyPublisher.hh"], + qrc_file = "src/plugins/key_publisher/KeyPublisher.qrc", + qrc_resources = ["src/plugins/key_publisher/KeyPublisher.qml"], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "plugin:register", + ":gui", + ], +) + +gz_gui_plugin( + name = "marker_manager", + srcs = ["src/plugins/marker_manager/MarkerManager.cc"], + hdrs = ["src/plugins/marker_manager/MarkerManager.hh"], + qrc_file = "src/plugins/marker_manager/MarkerManager.qrc", + qrc_resources = ["src/plugins/marker_manager/MarkerManager.qml"], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "common/profiler", + GZ_ROOT + "plugin:register", + GZ_ROOT + "rendering", + ":gui", + ], +) + +gz_gui_plugin( + name = "minimal_scene", + srcs = [ + "src/plugins/minimal_scene/MinimalScene.cc", + "src/plugins/minimal_scene/MinimalSceneRhi.cc", + "src/plugins/minimal_scene/MinimalSceneRhiOpenGL.cc", + ], + hdrs = [ + "src/plugins/minimal_scene/MinimalScene.hh", + ], + normal_headers = [ + "src/plugins/minimal_scene/MinimalSceneRhi.hh", + "src/plugins/minimal_scene/MinimalSceneRhiMetal.hh", + "src/plugins/minimal_scene/MinimalSceneRhiOpenGL.hh", + ], + qrc_file = "src/plugins/minimal_scene/MinimalScene.qrc", + qrc_resources = ["src/plugins/minimal_scene/MinimalScene.qml"], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "plugin:register", + GZ_ROOT + "rendering", + ":gui", + ], +) + +gz_gui_plugin( + name = "navsat_map", + srcs = ["src/plugins/navsat_map/NavSatMap.cc"], + hdrs = ["src/plugins/navsat_map/NavSatMap.hh"], + qrc_file = "src/plugins/navsat_map/NavSatMap.qrc", + qrc_resources = ["src/plugins/navsat_map/NavSatMap.qml"], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "plugin:register", + GZ_ROOT + "rendering", + ":gui", + ], +) + +gz_gui_plugin( + name = "plotting", + srcs = ["src/plugins/plotting/TransportPlotting.cc"], + hdrs = ["src/plugins/plotting/TransportPlotting.hh"], + qrc_file = "src/plugins/plotting/TransportPlotting.qrc", + qrc_resources = ["src/plugins/plotting/TransportPlotting.qml"], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "plugin:register", + ":gui", + ], +) + +gz_gui_plugin( + name = "point_cloud", + srcs = ["src/plugins/point_cloud/PointCloud.cc"], + hdrs = ["src/plugins/point_cloud/PointCloud.hh"], + qrc_file = "src/plugins/point_cloud/PointCloud.qrc", + qrc_resources = ["src/plugins/point_cloud/PointCloud.qml"], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "common/profiler", + GZ_ROOT + "plugin:register", + ":gui", + ], +) + +gz_gui_plugin( + name = "publisher", + srcs = ["src/plugins/publisher/Publisher.cc"], + hdrs = ["src/plugins/publisher/Publisher.hh"], + qrc_file = "src/plugins/publisher/Publisher.qrc", + qrc_resources = ["src/plugins/publisher/Publisher.qml"], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "plugin:register", + ":gui", + ], +) + +gz_gui_plugin( + name = "screenshot", + srcs = ["src/plugins/screenshot/Screenshot.cc"], + hdrs = ["src/plugins/screenshot/Screenshot.hh"], + qrc_file = "src/plugins/screenshot/Screenshot.qrc", + qrc_resources = [ + "src/plugins/screenshot/folder.png", + "src/plugins/screenshot/Screenshot.qml", + "src/plugins/screenshot/screenshot.png", + ], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "common/graphics", + GZ_ROOT + "plugin:register", + GZ_ROOT + "rendering", + ":gui", + ], +) + +gz_gui_plugin( + name = "shutdown_button", + srcs = ["src/plugins/shutdown_button/ShutdownButton.cc"], + hdrs = ["src/plugins/shutdown_button/ShutdownButton.hh"], + qrc_file = "src/plugins/shutdown_button/ShutdownButton.qrc", + qrc_resources = ["src/plugins/shutdown_button/ShutdownButton.qml"], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "plugin:register", + ":gui", + ], +) + +gz_gui_plugin( + name = "tape_measure", + srcs = ["src/plugins/tape_measure/TapeMeasure.cc"], + hdrs = ["src/plugins/tape_measure/TapeMeasure.hh"], + qrc_file = "src/plugins/tape_measure/TapeMeasure.qrc", + qrc_resources = [ + "src/plugins/tape_measure/tape_measure.png", + "src/plugins/tape_measure/TapeMeasure.qml", + "src/plugins/tape_measure/trashcan.png", + ], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "plugin:register", + GZ_ROOT + "rendering", + ":gui", + ], +) + +gz_gui_plugin( + name = "teleop", + srcs = ["src/plugins/teleop/Teleop.cc"], + hdrs = ["src/plugins/teleop/Teleop.hh"], + qrc_file = "src/plugins/teleop/Teleop.qrc", + qrc_resources = ["src/plugins/teleop/Teleop.qml"], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "plugin:register", + ":gui", + ], +) + +gz_gui_plugin( + name = "topic_echo", + srcs = ["src/plugins/topic_echo/TopicEcho.cc"], + hdrs = ["src/plugins/topic_echo/TopicEcho.hh"], + qrc_file = "src/plugins/topic_echo/TopicEcho.qrc", + qrc_resources = ["src/plugins/topic_echo/TopicEcho.qml"], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "plugin:register", + ":gui", + ], +) + +gz_gui_plugin( + name = "topic_viewer", + srcs = ["src/plugins/topic_viewer/TopicViewer.cc"], + hdrs = ["src/plugins/topic_viewer/TopicViewer.hh"], + qrc_file = "src/plugins/topic_viewer/TopicViewer.qrc", + qrc_resources = [ + "src/plugins/topic_viewer/minus.png", + "src/plugins/topic_viewer/plottable_icon.svg", + "src/plugins/topic_viewer/plus.png", + "src/plugins/topic_viewer/TopicViewer.qml", + ], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "plugin:register", + ":gui", + ], +) + +gz_gui_plugin( + name = "transport_scene_manager", + srcs = ["src/plugins/transport_scene_manager/TransportSceneManager.cc"], + hdrs = ["src/plugins/transport_scene_manager/TransportSceneManager.hh"], + qrc_file = "src/plugins/transport_scene_manager/TransportSceneManager.qrc", + qrc_resources = ["src/plugins/transport_scene_manager/TransportSceneManager.qml"], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "common/graphics", + GZ_ROOT + "plugin:register", + GZ_ROOT + "rendering", + ":gui", + ], +) + +gz_gui_plugin( + name = "world_control", + srcs = [ + "src/plugins/world_control/WorldControl.cc", + "src/plugins/world_control/WorldControlEventListener.cc", + ], + hdrs = [ + "src/plugins/world_control/WorldControl.hh", + "src/plugins/world_control/WorldControlEventListener.hh", + ], + qrc_file = "src/plugins/world_control/WorldControl.qrc", + qrc_resources = ["src/plugins/world_control/WorldControl.qml"], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "plugin:register", + ":gui", + ], +) + +gz_gui_plugin( + name = "world_stats", + srcs = ["src/plugins/world_stats/WorldStats.cc"], + hdrs = ["src/plugins/world_stats/WorldStats.hh"], + qrc_file = "src/plugins/world_stats/WorldStats.qrc", + qrc_resources = ["src/plugins/world_stats/WorldStats.qml"], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "plugin:register", + ":gui", + ], +) + +cc_library( + name = "plugins", + deps = [ + ":camera_fps", + ":camera_tracking", + ":grid_config", + ":image_display", + ":interactive_view_control", + ":key_publisher", + ":marker_manager", + ":minimal_scene", + ":navsat_map", + ":plotting", + ":point_cloud", + ":publisher", + ":screenshot", + ":shutdown_button", + ":tape_measure", + ":teleop", + ":topic_echo", + ":topic_viewer", + ":transport_scene_manager", + ":world_control", + ":world_stats", + ], +) + +cc_binary( + name = "main", + srcs = ["src/main.cc"], + defines = [ + "GZ_PLUGIN_STATIC_ONLY=1", + ], + deps = [ + ":gui", + ":plugins", + ], +) + +test_sources = glob( + #include = ["src/*_TEST.cc"], +) + +[cc_test( + name = src.replace("/", "_").replace(".cc", "").replace("src_", ""), + srcs = [src], + env = { + "GZ_BAZEL": "1", + "GZ_BAZEL_PATH": "gui", + }, + deps = [ + ":gui", + GZ_ROOT + "common/testing", + "@gtest", + "@gtest//:gtest_main", + ], +) for src in test_sources] diff --git a/gz_gui_plugin.bzl b/gz_gui_plugin.bzl new file mode 100644 index 000000000..4b9e95877 --- /dev/null +++ b/gz_gui_plugin.bzl @@ -0,0 +1,43 @@ +load("@com_justbuchanan_rules_qt//:qt.bzl", "gencpp", "genqrc", "qt_cc_library", "qt_ui_library") +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") + +def gz_gui_plugin( + name, + srcs, + hdrs, + qrc_file, + qrc_resources, + normal_headers = [], + deps = [], + test_srcs = [], + test_deps = []): + gencpp( + name = name + "_resources", + resource_name = name, + qrc = qrc_file, + files = qrc_resources, + cpp = name + "_resources.cpp", + ) + + qt_cc_library( + name = name, + srcs = srcs + [name + "_resources.cpp"], + hdrs = hdrs, + normal_hdrs = normal_headers, + deps = deps, + alwayslink = 1, + defines = [ + "GZ_PLUGIN_STATIC_ONLY=1", + ], + ) + + if len(test_srcs): + cc_test( + name = "%s_TEST" % name, + srcs = test_srcs, + deps = deps + test_deps + [ + "@gtest", + "@gtest//:gtest_main", + ":" + name, + ], + ) diff --git a/src/Application.cc b/src/Application.cc index eb63208b9..b367aa110 100644 --- a/src/Application.cc +++ b/src/Application.cc @@ -467,13 +467,14 @@ bool Application::LoadPlugin(const std::string &_filename, // Add default folder and install folder std::string home; common::env(GZ_HOMEDIR, home); - systemPaths.AddPluginPaths(home + "/.gz/gui/plugins:" + - GZ_GUI_PLUGIN_INSTALL_DIR); + //systemPaths.AddPluginPaths(home + "/.gz/gui/plugins:" + + // GZ_GUI_PLUGIN_INSTALL_DIR); // TODO(CH3): Deprecated. Remove on tock. - systemPaths.AddPluginPaths(home + "/.ignition/gui/plugins:" + - GZ_GUI_PLUGIN_INSTALL_DIR); + //systemPaths.AddPluginPaths(home + "/.ignition/gui/plugins:" + + //GZ_GUI_PLUGIN_INSTALL_DIR); + std::cout << "_filename: " << _filename << std::endl; auto pathToLib = systemPaths.FindSharedLibrary(_filename); if (pathToLib.empty()) @@ -782,7 +783,7 @@ std::vector>> paths.push_back(home + "/.ignition/gui/plugins"); // 4. Install path - paths.push_back(GZ_GUI_PLUGIN_INSTALL_DIR); + //paths.push_back(GZ_GUI_PLUGIN_INSTALL_DIR); // Populate map std::vector>> plugins; @@ -807,6 +808,15 @@ std::vector>> plugins.push_back(std::make_pair(path, ps)); } + gz::plugin::Loader loader; + auto loader_plugins = loader.AllPlugins(); + std::vector ps; + for (auto & plugin : loader_plugins) + { + ps.push_back(plugin); + } + plugins.push_back(std::make_pair("static", ps)); + return plugins; } diff --git a/src/MainWindow.cc b/src/MainWindow.cc index c90d09a7a..8752aa315 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -133,14 +133,23 @@ QStringList MainWindow::PluginListModel() const auto plugins = App()->PluginList(); for (auto const &path : plugins) { + for (auto const &plugin : path.second) { - // Remove lib and .so - auto pluginName = plugin.substr(3, plugin.find(".") - 3); + std::string pluginName; + if (path.first != "static") + { + // Remove lib and .so + pluginName = plugin.substr(3, plugin.find(".") - 3); - // Split WWWCamelCase3D -> WWW Camel Case 3D - std::regex reg("(\\B[A-Z][a-z])|(\\B[0-9])"); - pluginName = std::regex_replace(pluginName, reg, " $&"); + // Split WWWCamelCase3D -> WWW Camel Case 3D + std::regex reg("(\\B[A-Z][a-z])|(\\B[0-9])"); + pluginName = std::regex_replace(pluginName, reg, " $&"); + } + else + { + pluginName = plugin; + } // Show? if (this->dataPtr->windowConfig.pluginsFromPaths || @@ -267,7 +276,7 @@ void MainWindow::OnAddPlugin(QString _plugin) // Remove spaces plugin.erase(remove_if(plugin.begin(), plugin.end(), isspace), plugin.end()); - gzlog << "Add [" << plugin << "] via menu" << std::endl; + gzmsg << "Add [" << plugin << "] via menu" << std::endl; App()->LoadPlugin(plugin); } diff --git a/src/main.cc b/src/main.cc new file mode 100644 index 000000000..7222c7ecf --- /dev/null +++ b/src/main.cc @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2017 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + +#include + +#include + +#include + +#include "gz/gui/Application.hh" +#include "gz/gui/config.hh" +#include "gz/gui/Export.hh" +#include "gz/gui/MainWindow.hh" + +int g_argc = 1; +char* g_argv[] = +{ + reinterpret_cast(const_cast("./ignition")), +}; + +////////////////////////////////////////////////// +int main(int argc, char** argv) +{ + gz::common::Console::SetVerbosity(4); + + QDirIterator it(":", QDirIterator::Subdirectories); + while (it.hasNext()) { + qDebug() << it.next(); + } + + gz::gui::Application app(g_argc, g_argv); + + auto pluginsList = app.PluginList(); + for (auto const &path : pluginsList) + { + std::cout << path.first << std::endl; + + for (unsigned int i = 0; i < path.second.size(); ++i) + { + if (i == path.second.size() - 1) + std::cout << "└── " << path.second[i] << std::endl; + else + std::cout << "├── " << path.second[i] << std::endl; + } + + if (path.second.empty()) + std::cout << "└── No plugins" << std::endl; + } + + app.exec(); + + +} diff --git a/src/plugins/image_display/ImageDisplay_TEST.cc b/src/plugins/image_display/ImageDisplay_TEST.cc index 4d75636f4..aefe1d67c 100644 --- a/src/plugins/image_display/ImageDisplay_TEST.cc +++ b/src/plugins/image_display/ImageDisplay_TEST.cc @@ -27,7 +27,6 @@ #include "gz/gui/Application.hh" #include "gz/gui/MainWindow.hh" #include "gz/gui/Plugin.hh" -#include "test_config.hh" // NOLINT(build/include) #include "ImageDisplay.hh" int g_argc = 1;