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

Use MinimalScene by default #1014

Merged
merged 17 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
8 changes: 8 additions & 0 deletions examples/worlds/minimal_scene.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ Missing for parity with GzScene3D:
</plugin>

<!-- Plugins that add functionality to the scene -->
<plugin filename="EntityContextMenuPlugin" name="Entity context menu">
<ignition-gui>
<property key="state" type="string">floating</property>
<property key="width" type="double">5</property>
<property key="height" type="double">5</property>
<property key="showTitleBar" type="bool">false</property>
</ignition-gui>
</plugin>
<plugin filename="GzSceneManager" name="Scene Manager">
<ignition-gui>
<anchors target="3D View">
Expand Down
79 changes: 74 additions & 5 deletions src/gui/gui.config
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<!-- GUI plugins -->

<!-- 3D scene -->
<plugin filename="GzScene3D" name="3D View">
<plugin filename="MinimalScene" name="3D View">
<ignition-gui>
<title>3D View</title>
<property type="bool" key="showTitleBar">false</property>
Expand All @@ -38,10 +38,77 @@
<scene>scene</scene>
<ambient_light>0.4 0.4 0.4</ambient_light>
<background_color>0.8 0.8 0.8</background_color>
<camera_pose>6 0 6 0 0.5 3.14</camera_pose>
<camera_pose>-6 0 6 0 0.5 0</camera_pose>
</plugin>

<!-- Play / pause / step -->
<!-- Plugins that add functionality to the scene -->
<plugin filename="GzSceneManager" name="Scene Manager">
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
<ignition-gui>
<anchors target="3D View">
<line own="right" target="right"/>
<line own="top" target="top"/>
</anchors>
<property key="resizable" type="bool">false</property>
<property key="width" type="double">5</property>
<property key="height" type="double">5</property>
<property key="state" type="string">floating</property>
<property key="showTitleBar" type="bool">false</property>
</ignition-gui>
</plugin>
<plugin filename="InteractiveViewControl" name="Interactive view control">
<ignition-gui>
<anchors target="3D View">
<line own="right" target="right"/>
<line own="top" target="top"/>
</anchors>
<property key="resizable" type="bool">false</property>
<property key="width" type="double">5</property>
<property key="height" type="double">5</property>
<property key="state" type="string">floating</property>
<property key="showTitleBar" type="bool">false</property>
</ignition-gui>
</plugin>
<plugin filename="CameraTracking" name="Camera Tracking">
<ignition-gui>
<anchors target="3D View">
<line own="right" target="right"/>
<line own="top" target="top"/>
</anchors>
<property key="resizable" type="bool">false</property>
<property key="width" type="double">5</property>
<property key="height" type="double">5</property>
<property key="state" type="string">floating</property>
<property key="showTitleBar" type="bool">false</property>
</ignition-gui>
</plugin>
<plugin filename="MarkerManager" name="Marker manager">
<ignition-gui>
<anchors target="3D View">
<line own="right" target="right"/>
<line own="top" target="top"/>
</anchors>
<property key="resizable" type="bool">false</property>
<property key="width" type="double">5</property>
<property key="height" type="double">5</property>
<property key="state" type="string">floating</property>
<property key="showTitleBar" type="bool">false</property>
</ignition-gui>
</plugin>
<plugin filename="SelectEntities" name="Select Entities">
<ignition-gui>
<anchors target="Select entities">
<line own="right" target="right"/>
<line own="top" target="top"/>
</anchors>
<property key="resizable" type="bool">false</property>
<property key="width" type="double">5</property>
<property key="height" type="double">5</property>
<property key="state" type="string">floating</property>
<property key="showTitleBar" type="bool">false</property>
</ignition-gui>
</plugin>

<!-- World control -->
<plugin filename="WorldControl" name="World control">
<ignition-gui>
<title>World control</title>
Expand All @@ -64,7 +131,7 @@

</plugin>

<!-- Time / RTF -->
<!-- World statistics -->
<plugin filename="WorldStats" name="World stats">
<ignition-gui>
<title>World stats</title>
Expand All @@ -85,7 +152,6 @@
<real_time>true</real_time>
<real_time_factor>true</real_time_factor>
<iterations>true</iterations>

</plugin>

<!-- Insert simple shapes -->
Expand Down Expand Up @@ -128,6 +194,9 @@
<property key="showTitleBar" type="bool">false</property>
<property key="cardBackground" type="string">#777777</property>
</ignition-gui>

<!-- disable legacy features used to connect this plugin to GzScene3D -->
<legacy>false</legacy>
</plugin>

<!-- Screenshot -->
Expand Down
1 change: 1 addition & 0 deletions src/gui/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ add_subdirectory(modules)
add_subdirectory(align_tool)
add_subdirectory(banana_for_scale)
add_subdirectory(component_inspector)
add_subdirectory(entity_context_menu)
add_subdirectory(entity_tree)
add_subdirectory(joint_position_controller)
add_subdirectory(lights)
Expand Down
8 changes: 8 additions & 0 deletions src/gui/plugins/entity_context_menu/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
gz_add_gui_plugin(EntityContextMenuPlugin
SOURCES
EntityContextMenuPlugin.cc
QT_HEADERS
EntityContextMenuPlugin.hh
PUBLIC_LINK_LIBS
${PROJECT_LIBRARY_TARGET_NAME}-rendering
)
213 changes: 213 additions & 0 deletions src/gui/plugins/entity_context_menu/EntityContextMenuPlugin.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
/*
* 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.
*
*/

#include "EntityContextMenuPlugin.hh"

#include <memory>
#include <utility>

#include <QtQml>

#include <ignition/common/Console.hh>
#include <ignition/common/MouseEvent.hh>
jennuine marked this conversation as resolved.
Show resolved Hide resolved

#include <ignition/gui/Application.hh>
#include <ignition/gui/GuiEvents.hh>
#include <ignition/gui/Helpers.hh>
#include <ignition/gui/MainWindow.hh>

#include <ignition/plugin/Register.hh>

#include <ignition/rendering/Camera.hh>
#include <ignition/rendering/RenderingIface.hh>
#include <ignition/rendering/Visual.hh>
#include <ignition/rendering/Scene.hh>

namespace ignition::gazebo
{
class EntityContextMenuPrivate
{
/// \brief Perform operations in the render thread.
public: void OnRender();

/// \brief Pointer to the rendering scene
public: rendering::ScenePtr scene{nullptr};

/// \brief User camera
public: rendering::CameraPtr camera{nullptr};

/// \brief Entity context menu hanlder
public: EntityContextMenuHanlder entityContextMenuHanlder;
};
}

using namespace ignition;
using namespace gazebo;

/////////////////////////////////////////////////
void EntityContextMenuPrivate::OnRender()
{
if (nullptr == this->scene)
{
this->scene = rendering::sceneFromFirstRenderEngine();
if (nullptr == this->scene)
{
return;
jennuine marked this conversation as resolved.
Show resolved Hide resolved
}

for (unsigned int i = 0; i < this->scene->NodeCount(); ++i)
{
auto cam = std::dynamic_pointer_cast<rendering::Camera>(
this->scene->NodeByIndex(i));
if (cam)
{
if (std::get<bool>(cam->UserData("user-camera")))
{
this->camera = cam;

igndbg << "Spawn plugin is using camera ["
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
<< this->camera->Name() << "]" << std::endl;
break;
}
}
}
}
}

/////////////////////////////////////////////////
EntityContextMenu::EntityContextMenu()
: gui::Plugin(), dataPtr(std::make_unique<EntityContextMenuPrivate>())
{
qmlRegisterType<EntityContextMenuItem>(
"RenderWindowOverlay", 1, 0, "RenderWindowOverlay");
}

EntityContextMenu::~EntityContextMenu() = default;

/////////////////////////////////////////////////
void EntityContextMenu::LoadConfig(const tinyxml2::XMLElement *)
{
EntityContextMenuItem *renderWindowOverlay =
this->PluginItem()->findChild<EntityContextMenuItem *>();
if (!renderWindowOverlay)
{
ignerr << "Unable to find Render Window Overlay item. "
<< "Render window overlay will not be created" << std::endl;
return;
}

renderWindowOverlay->SetEntityContextMenuHanlder(
this->dataPtr->entityContextMenuHanlder);

if (this->title.empty())
this->title = "EntityContextMenu";

ignition::gui::App()->findChild
<ignition::gui::MainWindow *>()->installEventFilter(this);
}

////////////////////////////////////////////////
bool EntityContextMenu::eventFilter(QObject *_obj, QEvent *_event)
{
if (_event->type() == ignition::gui::events::Render::kType)
{
this->dataPtr->OnRender();
}
else if (_event->type() == ignition::gui::events::RightClickOnScene::kType)
{
ignition::gui::events::RightClickOnScene *_e =
static_cast<ignition::gui::events::RightClickOnScene*>(_event);
if (_e)
{
this->dataPtr->entityContextMenuHanlder.HandleMouseContextMenu(
_e->Mouse(), this->dataPtr->camera);
}
}

return QObject::eventFilter(_obj, _event);
}


/////////////////////////////////////////////////
EntityContextMenuItem::EntityContextMenuItem(QQuickItem *_parent)
: QQuickItem(_parent)
{
this->setAcceptedMouseButtons(Qt::AllButtons);
this->setFlag(ItemHasContents);
}

/////////////////////////////////////////////////
void EntityContextMenuItem::SetEntityContextMenuHanlder(
EntityContextMenuHanlder &_entityContextMenuHanlder)
{
entityContextMenuHanlder = &_entityContextMenuHanlder;
this->connect(
entityContextMenuHanlder,
&EntityContextMenuHanlder::ContextMenuRequested,
this,
&EntityContextMenuItem::OnContextMenuRequested,
Qt::QueuedConnection);
}

///////////////////////////////////////////////////
void EntityContextMenuItem::OnContextMenuRequested(
QString _entity, int _mouseX, int _mouseY)
{
emit openContextMenu(std::move(_entity), _mouseX, _mouseY);
}

/////////////////////////////////////////////////
EntityContextMenuHanlder::EntityContextMenuHanlder()
{
}

void EntityContextMenuHanlder::HandleMouseContextMenu(
const common::MouseEvent &_mouseEvent, const rendering::CameraPtr &_camera)
{
if (!_mouseEvent.Dragging() &&
_mouseEvent.Type() == common::MouseEvent::RELEASE &&
_mouseEvent.Button() == common::MouseEvent::RIGHT)
{
math::Vector2i dt =
_mouseEvent.PressPos() - _mouseEvent.Pos();

// check for click with some tol for mouse movement
if (dt.Length() > 5.0)
return;

rendering::VisualPtr visual = _camera->Scene()->VisualAt(
_camera,
_mouseEvent.Pos());

if (!visual)
return;

// get model visual
while (visual->HasParent() && visual->Parent() !=
visual->Scene()->RootVisual())
{
visual = std::dynamic_pointer_cast<rendering::Visual>(visual->Parent());
}

emit ContextMenuRequested(
visual->Name().c_str(), _mouseEvent.Pos().X(), _mouseEvent.Pos().Y());
}
}

// Register this plugin
IGNITION_ADD_PLUGIN(ignition::gazebo::EntityContextMenu,
ignition::gui::Plugin)
Loading