Skip to content

Commit

Permalink
Fix formatting of error messages with large mesh file names (#1654)
Browse files Browse the repository at this point in the history
Large mesh file names creates ugly error message
by overflow. This commit fixes this.

Signed-off-by: Onur Berk Tore <[email protected]>
Signed-off-by: Addisu Z. Taddese <[email protected]>
Co-authored-by: Onur Berk Tore <[email protected]>
Co-authored-by: Addisu Z. Taddese <[email protected]>
  • Loading branch information
3 people authored Mar 7, 2023
1 parent d2475ff commit 3b8ccd6
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/gui/plugins/spawn/Spawn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ namespace gz::sim

/// \brief Text for popup error message
public: QString errorPopupText;

/// \brief Adds new line after each nChar.
public: std::string AddNewLine(const std::string &_str, int _nChar);
};
}

Expand Down Expand Up @@ -188,6 +191,22 @@ void Spawn::LoadConfig(const tinyxml2::XMLElement *)
<gz::gui::MainWindow *>()->installEventFilter(this);
}

/////////////////////////////////////////////////
std::string SpawnPrivate::AddNewLine(const std::string &_str, int _nChar)
{
std::string out;
out.reserve(_str.size() + _str.size() / _nChar);
for (std::string::size_type i = 0; i < _str.size(); i++)
{
if (!(i % _nChar) && i)
{
out.append("-\n");
}
out.push_back(_str[i]);
}
return out;
}

/////////////////////////////////////////////////
void SpawnPrivate::HandlePlacement()
{
Expand Down Expand Up @@ -581,10 +600,12 @@ void Spawn::OnDropped(const gz::gui::events::DropOnScene *_event)

if (!common::MeshManager::Instance()->IsValidFilename(dropStr))
{
QString errTxt = QString::fromStdString("Invalid URI: " + dropStr +
"\nOnly Fuel URLs or mesh file types DAE, FBX, GLTF, OBJ, and STL are "
+ "supported.");
this->SetErrorPopupText(errTxt);
std::string fixedDropStr = this->dataPtr->AddNewLine(dropStr, 55);
std::string errTxt = "Invalid URI: " + fixedDropStr +
"\nOnly Fuel URLs or mesh file types DAE, FBX, GLTF, OBJ, and STL\n"
"are supported.";
QString QErrTxt = QString::fromStdString(errTxt);
this->SetErrorPopupText(QErrTxt);
return;
}

Expand Down

0 comments on commit 3b8ccd6

Please sign in to comment.