Small refactoring

This commit is contained in:
Enrico Turri 2019-07-18 15:03:05 +02:00
parent f61d43de07
commit 1c5ff3c72d
2 changed files with 6 additions and 10 deletions

View file

@ -292,8 +292,7 @@ bool Bed3D::set_shape(const Pointfs& shape, const std::string& custom_texture)
std::string cst_texture(custom_texture); std::string cst_texture(custom_texture);
if (!cst_texture.empty()) if (!cst_texture.empty())
{ {
std::string ext = boost::filesystem::path(cst_texture).extension().string(); if ((!boost::algorithm::iends_with(custom_texture, ".png") && !boost::algorithm::iends_with(custom_texture, ".svg")) || !boost::filesystem::exists(custom_texture))
if ((!boost::iequals(ext.c_str(), ".png") && !boost::iequals(ext.c_str(), ".svg")) || !boost::filesystem::exists(custom_texture))
cst_texture = ""; cst_texture = "";
} }
@ -520,8 +519,7 @@ void Bed3D::render_prusa(GLCanvas3D* canvas, const std::string &key, bool bottom
if ((m_texture.get_id() == 0) || (m_texture.get_source() != filename)) if ((m_texture.get_id() == 0) || (m_texture.get_source() != filename))
{ {
std::string ext = boost::filesystem::path(filename).extension().string(); if (boost::algorithm::iends_with(filename, ".svg"))
if (boost::iequals(ext.c_str(), ".svg"))
{ {
// generate a temporary lower resolution texture to show while no main texture levels have been compressed // generate a temporary lower resolution texture to show while no main texture levels have been compressed
if (!m_temp_texture.load_from_svg_file(filename, false, false, false, max_tex_size / 8)) if (!m_temp_texture.load_from_svg_file(filename, false, false, false, max_tex_size / 8))
@ -537,7 +535,7 @@ void Bed3D::render_prusa(GLCanvas3D* canvas, const std::string &key, bool bottom
return; return;
} }
} }
else if (boost::iequals(ext.c_str(), ".png")) else if (boost::algorithm::iends_with(filename, ".png"))
{ {
std::cout << "texture: " << filename << std::endl; std::cout << "texture: " << filename << std::endl;
render_custom(); render_custom();

View file

@ -449,7 +449,7 @@ void BedShapePanel::load_stl()
return; return;
std::string file_name = dialog.GetPath().ToUTF8().data(); std::string file_name = dialog.GetPath().ToUTF8().data();
if (!boost::iequals(boost::filesystem::path(file_name).extension().string().c_str(), ".stl")) if (!boost::algorithm::iends_with(file_name, ".stl"))
{ {
show_error(this, _(L("Invalid file format."))); show_error(this, _(L("Invalid file format.")));
return; return;
@ -498,9 +498,7 @@ void BedShapePanel::load_texture()
m_custom_texture = NONE; m_custom_texture = NONE;
std::string file_name = dialog.GetPath().ToUTF8().data(); std::string file_name = dialog.GetPath().ToUTF8().data();
std::string file_ext = boost::filesystem::path(file_name).extension().string(); if (!boost::algorithm::iends_with(file_name, ".png") && !boost::algorithm::iends_with(file_name, ".svg"))
if (!boost::iequals(file_ext.c_str(), ".png") && !boost::iequals(file_ext.c_str(), ".svg"))
{ {
show_error(this, _(L("Invalid file format."))); show_error(this, _(L("Invalid file format.")));
return; return;
@ -523,7 +521,7 @@ void BedShapePanel::load_model()
m_custom_model = NONE; m_custom_model = NONE;
std::string file_name = dialog.GetPath().ToUTF8().data(); std::string file_name = dialog.GetPath().ToUTF8().data();
if (!boost::iequals(boost::filesystem::path(file_name).extension().string().c_str(), ".stl")) if (!boost::algorithm::iends_with(file_name, ".stl"))
{ {
show_error(this, _(L("Invalid file format."))); show_error(this, _(L("Invalid file format.")));
return; return;