Skip to content

Commit

Permalink
World: handle name collisions like Model
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Peters <[email protected]>

Signed-off-by: Steve Peters <[email protected]>
  • Loading branch information
scpeters authored Aug 21, 2023
1 parent 7f63d02 commit 1c92d4f
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions src/World.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,21 +283,35 @@ Errors World::Load(sdf::ElementPtr _sdf, const ParserConfig &_config)
std::string frameName = frame.Name();
if (frameNames.count(frameName) > 0)
{
frameName += "_frame";
int i = 0;
while (frameNames.count(frameName) > 0)
// This frame has a name collision
if (sdfVersion < gz::math::SemanticVersion(1, 7))
{
frameName = frame.Name() + "_frame" + std::to_string(i++);
// This came from an old file, so try to workaround by renaming frame
frameName += "_frame";
int i = 0;
while (frameNames.count(frameName) > 0)
{
frameName = frame.Name() + "_frame" + std::to_string(i++);
}
std::stringstream ss;
ss << "Frame with name [" << frame.Name() << "] "
<< "in world with name [" << this->Name() << "] "
<< "has a name collision, changing frame name to ["
<< frameName << "].";
Error err(ErrorCode::WARNING, ss.str());
enforceConfigurablePolicyCondition(
_config.WarningsPolicy(), err, errors);

frame.SetName(frameName);
}
else
{
std::stringstream ss;
ss << "Frame with name [" << frame.Name() << "] "
<< "in world with name [" << this->Name() << "] "
<< "has a name collision. Please rename this frame.";
errors.push_back({ErrorCode::DUPLICATE_NAME, ss.str()});
}
std::stringstream ss;
ss << "Frame with name [" << frame.Name() << "] "
<< "in world with name [" << this->Name() << "] "
<< "has a name collision, changing frame name to ["
<< frameName << "].\n";
Error err(ErrorCode::WARNING, ss.str());
enforceConfigurablePolicyCondition(
_config.WarningsPolicy(), err, errors);
frame.SetName(frameName);
}
frameNames.insert(frameName);
}
Expand Down

0 comments on commit 1c92d4f

Please sign in to comment.