Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for MouseDrag GUI plugin #2085

Draft
wants to merge 43 commits into
base: gz-sim7
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
142d5a1
Create MouseDrag GUI plugin
Henrique-BO Jul 1, 2023
9449842
Track mouse position and the clicked link
Henrique-BO Jul 1, 2023
508a0ef
Implement calculation of plane of wrench application and translation …
Henrique-BO Jul 2, 2023
28919d6
Implement translation drag by arbitrary point in object
Henrique-BO Jul 3, 2023
603e949
Implement rotation dragging
Henrique-BO Jul 8, 2023
eeade69
Merge branch 'gazebosim:gz-sim7' into mouse_drag
Henrique-BO Jul 11, 2023
1383635
Improve rotation calculation and implement velocity damping
Henrique-BO Jul 11, 2023
0f68570
Use PID for wrench calculation and implement visualization
Henrique-BO Jul 14, 2023
f1179e8
Merge branch 'gazebosim:gz-sim7' into mouse_drag
Henrique-BO Jul 14, 2023
009cdb2
Merge branch 'mouse_drag' of github.com:Henrique-BO/gz-sim into mouse…
Henrique-BO Jul 14, 2023
a4dcdff
Merge branch 'gazebosim:gz-sim7' into mouse_drag
Henrique-BO Jul 17, 2023
2b36d85
Improve visualization for rotation
Henrique-BO Jul 17, 2023
8086225
Merge branch 'gazebosim:gz-sim7' into mouse_drag
Henrique-BO Jul 19, 2023
54a64c0
Fix rotation mode
Henrique-BO Jul 19, 2023
316f054
Make arrows always visible and minor changes
Henrique-BO Jul 20, 2023
e7f2ef2
Automatically load ApplyLinkWrench system and improve calculations
Henrique-BO Jul 21, 2023
c31bec6
Merge branch 'gazebosim:gz-sim7' into mouse_drag
Henrique-BO Jul 24, 2023
a639f5c
Merge branch 'gazebosim:gz-sim7' into mouse_drag
Henrique-BO Jul 27, 2023
91b1f1a
Configurable stiffnesses in MouseDrag
Henrique-BO Jul 27, 2023
60f788f
Minor fixes
Henrique-BO Jul 31, 2023
965a9e0
Change wrench calculation
Henrique-BO Aug 1, 2023
5d53a17
Merge branch 'mouse_drag' into mouse_drag_config
Henrique-BO Aug 1, 2023
7c81964
Visualizing plane and optimize calculations
Henrique-BO Aug 1, 2023
49de688
Merge branch 'gazebosim:gz-sim7' into mouse_drag
Henrique-BO Aug 3, 2023
896bed1
Merge branch 'gazebosim:gz-sim7' into mouse_drag_config
Henrique-BO Aug 3, 2023
21fcc93
Merge branch 'gazebosim:gz-sim7' into mouse_drag_config
Henrique-BO Aug 7, 2023
9bc7356
Merge branch 'gazebosim:gz-sim7' into mouse_drag
Henrique-BO Aug 7, 2023
06d5a3c
Merge branch 'gazebosim:gz-sim7' into mouse_drag_config
Henrique-BO Aug 10, 2023
e6af6c7
Merge branch 'gazebosim:gz-sim7' into mouse_drag
Henrique-BO Aug 10, 2023
f6920d3
Add mutex
Henrique-BO Aug 10, 2023
d37c517
Merge branch 'mouse_drag' into mouse_drag_config
Henrique-BO Aug 10, 2023
ba95572
Started MouseDrag unit and integration tests
Henrique-BO Aug 10, 2023
ee833a2
Use events to test translation mode in MouseDrag
Henrique-BO Aug 15, 2023
3fbb38f
Merge branch 'gazebosim:gz-sim7' into mouse_drag
Henrique-BO Aug 16, 2023
78f86a5
Refactoring and minor changes
Henrique-BO Aug 16, 2023
b2f1c51
Merge branch 'mouse_drag' into mouse_drag_config
Henrique-BO Aug 16, 2023
9f7bf50
Merge branch 'mouse_drag_config' into plugin_tests
Henrique-BO Aug 16, 2023
61b1c82
Merge branch 'gz-sim7' into mouse_drag_config
Henrique-BO Aug 17, 2023
8c77ba8
Merge branch 'mouse_drag_config' into plugin_tests
Henrique-BO Aug 17, 2023
5caea15
Merge branch 'gz-sim7' into plugin_tests
Henrique-BO Aug 21, 2023
335e1f2
Merge branch 'gazebosim:gz-sim7' into plugin_tests
Henrique-BO Aug 22, 2023
eb1e792
Merge branch 'gazebosim:gz-sim7' into plugin_tests
Henrique-BO Aug 23, 2023
85f4d15
Refactor GuiRelay
Henrique-BO Aug 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/gui/plugins/mouse_drag/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
gz_add_gui_plugin(MouseDrag
SOURCES MouseDrag.cc
QT_HEADERS MouseDrag.hh
TEST_SOURCES MouseDrag_TEST.cc
)
92 changes: 92 additions & 0 deletions src/gui/plugins/mouse_drag/MouseDrag_TEST.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright (C) 2023 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 <gtest/gtest.h>
#ifdef _MSC_VER
#pragma warning(push, 0)
#endif
#include <gz/msgs/double.pb.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#include <gz/gui/Application.hh>
#include <gz/gui/MainWindow.hh>
#include <gz/gui/Plugin.hh>
#include <gz/transport/Node.hh>
#include <gz/utils/ExtraTestMacros.hh>

#include <string>
#include <vector>
#include <algorithm>

#include "test_config.hh"
#include "../../../../test/helpers/EnvTestFixture.hh"

#include "../../GuiRunner.hh"

#include "MouseDrag.hh"

int g_argc = 1;
char **g_argv;

using namespace gz;

/// \brief Tests for the mouse drag GU I plugin
class MouseDragGui : public InternalFixture<::testing::Test>
{
};

/////////////////////////////////////////////////
TEST_F(MouseDragGui, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Load))
{
// Create app
auto app = std::make_unique<gui::Application>(g_argc, g_argv);
ASSERT_NE(nullptr, app);
app->AddPluginPath(
common::joinPaths(std::string(PROJECT_BINARY_PATH), "lib"));

// Create GUI runner to handle sim::gui plugins
auto runner = new sim::GuiRunner("default");
runner->setParent(gui::App());

// Add plugin
EXPECT_TRUE(app->LoadPlugin("MouseDrag"));

// Get main window
auto win = app->findChild<gui::MainWindow *>();
ASSERT_NE(nullptr, win);

// Get plugin
auto plugins = win->findChildren<
sim::MouseDrag *>();
EXPECT_EQ(plugins.size(), 1);

auto plugin = plugins[0];

EXPECT_EQ(plugin->Title(), "Mouse drag");

transport::Node node;
auto topic = transport::TopicUtils::AsValidTopic("/world/default/wrench");
EXPECT_FALSE(topic.empty());

std::vector<std::string> topics;
node.TopicList(topics);
EXPECT_NE(std::find(topics.begin(), topics.end(), topic), topics.end());

// Cleanup
plugins.clear();
}
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include_directories (

add_subdirectory(gtest_vendor)
add_subdirectory(benchmark)
add_subdirectory(helpers)
add_subdirectory(integration)
add_subdirectory(performance)
add_subdirectory(plugins)
Expand Down
15 changes: 15 additions & 0 deletions test/helpers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
find_package(Qt5Test REQUIRED)

set (qt_headers
GuiRelay.hh
)

QT5_WRAP_CPP(headers_MOC ${qt_headers})

add_library(${PROJECT_NAME}_test_helpers SHARED
${headers_MOC}
)
target_link_libraries(${PROJECT_NAME}_test_helpers
PUBLIC
${PROJECT_LIBRARY_TARGET_NAME}
)
85 changes: 85 additions & 0 deletions test/helpers/GuiRelay.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (C) 2021 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.
*
*/
#ifndef GZ_GUI_GUIRELAY_HH_
#define GZ_GUI_GUIRELAY_HH_

#include <gz/gui/Application.hh>
#include <gz/gui/Export.hh>
#include <gz/gui/MainWindow.hh>

namespace gz
{
namespace sim
{
namespace test
{
/// \brief Helper class to be used in internal tests. It allows receiving
/// events emitted in the GUI.
///
/// ## Usage
///
/// // Instantiate the class
/// test::GuiRelay guiRelay;
///
/// // Register callback, for example:
/// guiRelay.OnQEvent([&](QEvent *_event)
/// {
/// if (_event.type() == gz::gui::events::Render::kType)
/// {
/// // Do something
/// }
/// }
///
class GuiRelay : public QObject
{
Q_OBJECT

/// \brief Constructor
public: GuiRelay()
{
gz::gui::App()->findChild<gz::gui::MainWindow *>()->
installEventFilter(this);
}

/// \brief Destructor
public: ~GuiRelay() = default;

/// \brief Wrapper around Qt's event filter
/// \param[in] _cb Function to be called on every received QEvent
public: GuiRelay &OnQEvent(std::function<void (QEvent *)> _cb)
{
this->forwardEvent = std::move(_cb);
return *this;
}

/// \brief Documentation inherited
public: bool eventFilter(QObject *_obj, QEvent *_event) override
{
if (this->forwardEvent)
this->forwardEvent(_event);

// Standard event processing
return QObject::eventFilter(_obj, _event);
}

public: std::function<void (QEvent *)> forwardEvent;
};
}
}
}

#endif
9 changes: 9 additions & 0 deletions test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ set(tests
model.cc
model_photo_shoot_default_joints.cc
model_photo_shoot_random_joints.cc
mouse_drag.cc
multicopter.cc
multiple_servers.cc
navsat_system.cc
Expand Down Expand Up @@ -102,6 +103,7 @@ set(tests_needing_display
distortion_camera.cc
gpu_lidar.cc
mesh_uri.cc
mouse_drag.cc
optical_tactile_plugin.cc
reset_sensors.cc
rgbd_camera.cc
Expand Down Expand Up @@ -210,6 +212,13 @@ if(TARGET INTEGRATION_reset_sensors)
)
endif()

if(TARGET INTEGRATION_mouse_drag)
target_link_libraries(INTEGRATION_mouse_drag
${PROJECT_LIBRARY_TARGET_NAME}-gui
${PROJECT_NAME}_test_helpers
)
endif()

# The default timeout (240s) doesn't seem to be enough for this test.
if(TARGET INTEGRATION_tracked_vehicle_system )
set_tests_properties(INTEGRATION_tracked_vehicle_system PROPERTIES TIMEOUT 300)
Expand Down
Loading