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

Particle system - Part2 #562

Merged
merged 16 commits into from
Feb 18, 2021
39 changes: 38 additions & 1 deletion src/systems/particle_emitter/ParticleEmitter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,47 @@ void ParticleEmitter::Configure(const Entity &/*_entity*/,
return;
}

// allow_renaming
bool allowRenaming = false;
if (_sdf->HasElement("allow_renaming"))
allowRenaming = _sdf->Get<bool>("allow_renaming");

// Name.
std::string name = "particle_emitter_entity_" + std::to_string(entity);
if (_sdf->HasElement("emitter_name"))
name = _sdf->Get<std::string>("emitter_name");
{
std::set<std::string> emitterNames;
std::string emitterName = _sdf->Get<std::string>("emitter_name");

// check to see if name is already taken
_ecm.Each<components::Name, components::ParticleEmitter>(
[&emitterNames](const Entity &, const components::Name *_name,
const components::ParticleEmitter *)
{
emitterNames.insert(_name->Data());
return true;
});

name = emitterName;

// rename emitter if needed
if (emitterNames.find(emitterName) != emitterNames.end())
{
if (!allowRenaming)
{
ignwarn << "Entity named [" << name
<< "] already exists and "
<< "[allow_renaming] is false. Entity not spawned."
<< std::endl;
return;
}
int counter = 0;
while (emitterNames.find(name) != emitterNames.end())
{
name = emitterName + "_" + std::to_string(++counter);
}
iche033 marked this conversation as resolved.
Show resolved Hide resolved
}
}
this->dataPtr->emitter.set_name(name);

// Type. The default type is point.
Expand Down
2 changes: 2 additions & 0 deletions src/systems/particle_emitter/ParticleEmitter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ namespace systems
///
/// `<emitter_name>`: Unique name for the particle emitter. The name will be
/// automatically generated if this parameter is not set.
/// `<allow_renaming>`: Rename the particle emitter if one with the same name
/// already exists
iche033 marked this conversation as resolved.
Show resolved Hide resolved
/// `<type>`: The emitter type (point, box, cylinder, ellipsoid).
/// Default value is point.
/// `<pose>`: The pose of the emitter. Default value is {0, 0, 0, 0, 0, 0}.
Expand Down
4 changes: 0 additions & 4 deletions test/integration/particle_emitter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "ignition/gazebo/test_config.hh"

#include "helpers/Relay.hh"
#include "helpers/UniqueTestDirectoryEnv.hh"

using namespace ignition;
using namespace gazebo;
Expand All @@ -47,7 +46,6 @@ class ParticleEmitterTest : public ::testing::Test
}
public: void LoadWorld(const std::string &_path, bool _useLevels = false)
{
this->serverConfig.SetResourceCache(test::UniqueTestDirectoryEnv::Path());
this->serverConfig.SetSdfFile(
common::joinPaths(PROJECT_SOURCE_PATH, _path));
this->serverConfig.SetUseLevels(_useLevels);
Expand Down Expand Up @@ -165,7 +163,5 @@ TEST_F(ParticleEmitterTest, SDFLoad)
int main(int _argc, char **_argv)
{
::testing::InitGoogleTest(&_argc, _argv);
::testing::AddGlobalTestEnvironment(
new test::UniqueTestDirectoryEnv("particle_emitter_test_cache"));
return RUN_ALL_TESTS();
}