Skip to content

Commit

Permalink
3 -> 4 (#866)
Browse files Browse the repository at this point in the history
Signed-off-by: Louise Poubel <[email protected]>
  • Loading branch information
chapulina committed Jun 22, 2021
2 parents a1ebffa + 483684f commit f6a1a84
Show file tree
Hide file tree
Showing 30 changed files with 754 additions and 956 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ endif()
# Search for project-specific dependencies
#============================================================================

ign_find_package(sdformat10 REQUIRED VERSION 10.3)
ign_find_package(sdformat10 REQUIRED VERSION 10.5)
set(SDF_VER ${sdformat10_VERSION_MAJOR})

#--------------------------------------
Expand Down Expand Up @@ -75,7 +75,7 @@ set(IGN_FUEL_TOOLS_VER ${ignition-fuel_tools5_VERSION_MAJOR})

#--------------------------------------
# Find ignition-gui
ign_find_package(ignition-gui4 REQUIRED VERSION 4.1.1)
ign_find_package(ignition-gui4 REQUIRED VERSION 4.4)
set(IGN_GUI_VER ${ignition-gui4_VERSION_MAJOR})
ign_find_package (Qt5
COMPONENTS
Expand Down Expand Up @@ -114,12 +114,12 @@ set(IGN_SENSORS_VER ${ignition-sensors4_VERSION_MAJOR})

#--------------------------------------
# Find ignition-rendering
ign_find_package(ignition-rendering4 REQUIRED VERSION 4.7.0)
ign_find_package(ignition-rendering4 REQUIRED VERSION 4.8)
set(IGN_RENDERING_VER ${ignition-rendering4_VERSION_MAJOR})

#--------------------------------------
# Find ignition-math
ign_find_package(ignition-math6 REQUIRED COMPONENTS eigen3 VERSION 6.6)
ign_find_package(ignition-math6 REQUIRED COMPONENTS eigen3 VERSION 6.8)
set(IGN_MATH_VER ${ignition-math6_VERSION_MAJOR})

#--------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions examples/standalone/external_ecm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)

find_package(ignition-gazebo4 REQUIRED)

add_executable(external_ecm external_ecm.cc)
target_link_libraries(external_ecm
ignition-gazebo4::core)

93 changes: 93 additions & 0 deletions examples/standalone/external_ecm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# External ECM

Example showing how to get a snapshot of all entities and components in a
running simulation from an external program using the state message.

## Build

From the root of the `ign-gazebo` repository, do the following to build the example:

~~~
cd ign-gazebo/examples/standalone/external_ecm
mkdir build
cd build
cmake ..
make
~~~

This will generate the `external_ecm` executable under `build`.

## Run

Start a simulation, for example:

ign gazebo shapes.sdf

On another terminal, run the `external_ecm` executable, passing the name of the
running world you want to inspect:

cd ign-gazebo/examples/standalone/external_ecm
./external_ecm shapes

You should see something like this:

```
$ ./external_ecm shapes
Requesting state for world [shapes] on service [/world/shapes/state]...
Entity [1]
- Name: shapes
- Parent:
Entity [4]
- Name: ground_plane
- Parent: shapes [1]
Entity [5]
- Name: link
- Parent: ground_plane [4]
Entity [6]
- Name: visual
- Parent: link [5]
Entity [7]
- Name: collision
- Parent: link [5]
Entity [8]
- Name: box
- Parent: shapes [1]
Entity [9]
- Name: box_link
- Parent: box [8]
Entity [10]
- Name: box_visual
- Parent: box_link [9]
Entity [11]
- Name: box_collision
- Parent: box_link [9]
Entity [12]
- Name: cylinder
- Parent: shapes [1]
Entity [13]
- Name: cylinder_link
- Parent: cylinder [12]
Entity [14]
- Name: cylinder_visual
- Parent: cylinder_link [13]
Entity [15]
- Name: cylinder_collision
- Parent: cylinder_link [13]
Entity [16]
- Name: sphere
- Parent: shapes [1]
Entity [17]
- Name: sphere_link
- Parent: sphere [16]
Entity [18]
- Name: sphere_visual
- Parent: sphere_link [17]
Entity [19]
- Name: sphere_collision
- Parent: sphere_link [17]
Entity [20]
- Name: sun
- Parent: shapes [1]
```
98 changes: 98 additions & 0 deletions examples/standalone/external_ecm/external_ecm.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* 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 <iostream>
#include <ignition/gazebo/EntityComponentManager.hh>
#include <ignition/gazebo/components/Name.hh>
#include <ignition/gazebo/components/ParentEntity.hh>
#include <ignition/msgs/serialized.pb.h>
#include <ignition/transport/Node.hh>

//////////////////////////////////////////////////
int main(int argc, char **argv)
{
if (argc < 2)
{
std::cout << "Usage: `./external_ecm <world name>`" << std::endl;
return -1;
}

// Get arguments
std::string world = argv[1];

// Create a transport node.
ignition::transport::Node node;

bool executed{false};
bool result{false};
unsigned int timeout{5000};
std::string service{"/world/" + world + "/state"};

std::cout << std::endl << "Requesting state for world [" << world
<< "] on service [" << service << "]..." << std::endl << std::endl;

// Request and block
ignition::msgs::SerializedStepMap res;
executed = node.Request(service, timeout, res, result);

if (!executed)
{
std::cerr << std::endl << "Service call to [" << service << "] timed out"
<< std::endl;
return -1;
}

if (!result)
{
std::cerr << std::endl << "Service call to [" << service << "] failed"
<< std::endl;
return -1;
}

// Instantiate an ECM and populate with data from message
ignition::gazebo::EntityComponentManager ecm;
ecm.SetState(res.state());

// Print some information
ecm.Each<ignition::gazebo::components::Name>(
[&](const ignition::gazebo::Entity &_entity,
const ignition::gazebo::components::Name *_name) -> bool
{
auto parentComp =
ecm.Component<ignition::gazebo::components::ParentEntity>(_entity);

std::string parentInfo;
if (parentComp)
{
auto parentNameComp =
ecm.Component<ignition::gazebo::components::Name>(
parentComp->Data());

if (parentNameComp)
{
parentInfo += parentNameComp->Data() + " ";
}
parentInfo += "[" + std::to_string(parentComp->Data()) + "]";
}

std::cout << "Entity [" << _entity << "]" << std::endl
<< " - Name: " << _name->Data() << std::endl
<< " - Parent: " << parentInfo << std::endl;

return true;
});
}
1 change: 1 addition & 0 deletions src/gui/gui.config
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<drawer default="false">
</drawer>
</menus>
<dialog_on_exit>true</dialog_on_exit>
</window>

<!-- GUI plugins -->
Expand Down
75 changes: 20 additions & 55 deletions src/gui/plugins/align_tool/AlignTool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,27 @@
#include <queue>
#include <string>
#include <vector>

#include <ignition/common/Console.hh>
#include <ignition/gui/Application.hh>
#include <ignition/gui/MainWindow.hh>
#include <ignition/common/Console.hh>
#include <ignition/plugin/Register.hh>
#include <ignition/transport/Node.hh>
#include <ignition/rendering/Visual.hh>
#include <ignition/rendering/Geometry.hh>
#include <ignition/rendering/Material.hh>
#include <ignition/rendering/RenderEngine.hh>
#include <ignition/rendering/RenderTypes.hh>
#include <ignition/rendering/RenderingIface.hh>
#include <ignition/rendering/RenderEngine.hh>
#include <ignition/rendering/Scene.hh>
#include <ignition/rendering/Visual.hh>
#include <ignition/rendering/WireBox.hh>
#include "ignition/gazebo/components/World.hh"
#include "ignition/gazebo/components/Name.hh"
#include <ignition/transport/Node.hh>

#include "ignition/gazebo/EntityComponentManager.hh"
#include "ignition/gazebo/components/Name.hh"
#include "ignition/gazebo/components/World.hh"
#include "ignition/gazebo/gui/GuiEvents.hh"
#include "ignition/gazebo/rendering/RenderUtil.hh"

#include "AlignTool.hh"

namespace ignition::gazebo
Expand Down Expand Up @@ -87,6 +90,9 @@ namespace ignition::gazebo

/// \brief The map of the original transparency values for the nodes.
public: std::map<std::string, double> originalTransparency;

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

Expand Down Expand Up @@ -340,70 +346,28 @@ void AlignTool::Align()
if (this->dataPtr->currentState == AlignState::NONE)
return;

auto loadedEngNames = rendering::loadedEngines();
if (loadedEngNames.empty())
{
ignerr << "Internal error: engine should be loaded at this point."
<< std::endl;
return;
}

// Assume there is only one engine loaded
auto engineName = loadedEngNames[0];
if (loadedEngNames.size() > 1)
{
ignwarn << "Found more than one loaded engine "
"- using " << engineName << "." << std::endl;
}
auto engine = rendering::engine(engineName);

if (!engine)
{
ignerr << "Internal error: failed to load engine [" << engineName
<< "]. Align tool plugin won't work." << std::endl;
return;
}

if (engine->SceneCount() == 0)
{
ignerr<< "Internal error: no scenes are available with the loaded engine."
<< std::endl;
return;
}
// assume there is only one scene
// load scene
auto scene = engine->SceneByIndex(0);

if (!scene)
{
ignerr << "Internal error: scene is null." << std::endl;
return;
}

if (!scene->IsInitialized() || scene->VisualCount() == 0)
{
ignerr << "Internal error: scene is either not initialized "
"or there are no visuals within it." << std::endl;
return;
}
if (!this->dataPtr->scene)
this->dataPtr->scene = rendering::sceneFromFirstRenderEngine();

// Get current list of selected entities
std::vector<ignition::rendering::VisualPtr> selectedList;
ignition::rendering::VisualPtr relativeVisual;

for (const auto &entityId : this->dataPtr->selectedEntities)
{
for (auto i = 0u; i < scene->VisualCount(); ++i)
for (auto i = 0u; i < this->dataPtr->scene->VisualCount(); ++i)
{
ignition::rendering::VisualPtr vis = scene->VisualByIndex(i);
ignition::rendering::VisualPtr vis =
this->dataPtr->scene->VisualByIndex(i);
if (!vis)
continue;

if (std::get<int>(vis->UserData("gazebo-entity")) ==
static_cast<int>(entityId))
{
// Check here to see if visual is top level or not, continue if not
rendering::VisualPtr topLevelVis = this->TopLevelVisual(scene, vis);
auto topLevelVis = this->TopLevelVisual(this->dataPtr->scene, vis);
if (topLevelVis != vis)
continue;

Expand Down Expand Up @@ -457,7 +421,8 @@ void AlignTool::Align()
ignition::math::Vector3d max = box.Max();

// Check here to see if visual is top level or not, continue if not
rendering::VisualPtr topLevelVis = this->TopLevelVisual(scene, vis);
rendering::VisualPtr topLevelVis = this->TopLevelVisual(
this->dataPtr->scene, vis);
if (topLevelVis != vis)
continue;

Expand Down
2 changes: 1 addition & 1 deletion src/gui/plugins/align_tool/AlignTool.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

#include <memory>

#include <ignition/gui/Plugin.hh>
#include <ignition/gazebo/gui/GuiSystem.hh>
#include <ignition/gui/Plugin.hh>
#include <ignition/rendering/Node.hh>

namespace ignition
Expand Down
Loading

0 comments on commit f6a1a84

Please sign in to comment.