diff --git a/src/libslic3r/Format/OBJ.cpp b/src/libslic3r/Format/OBJ.cpp index 3b05bb5741..4e621e5f78 100644 --- a/src/libslic3r/Format/OBJ.cpp +++ b/src/libslic3r/Format/OBJ.cpp @@ -15,9 +15,13 @@ #define DIR_SEPARATOR '/' #endif +//Translation +#include "I18N.hpp" +#define _L(s) Slic3r::I18N::translate(s) + namespace Slic3r { -bool load_obj(const char *path, TriangleMesh *meshptr) +bool load_obj(const char *path, TriangleMesh *meshptr, std::string &message) { if (meshptr == nullptr) return false; @@ -26,6 +30,7 @@ bool load_obj(const char *path, TriangleMesh *meshptr) ObjParser::ObjData data; if (! ObjParser::objparse(path, data)) { BOOST_LOG_TRIVIAL(error) << "load_obj: failed to parse " << path; + message = _L("load_obj: failed to parse"); return false; } @@ -40,10 +45,12 @@ bool load_obj(const char *path, TriangleMesh *meshptr) if (num_face_vertices > 4) { // Non-triangular and non-quad faces are not supported as of now. BOOST_LOG_TRIVIAL(error) << "load_obj: failed to parse " << path << ". The file contains polygons with more than 4 vertices."; + message = _L("The file contains polygons with more than 4 vertices."); return false; } else if (num_face_vertices < 3) { // Non-triangular and non-quad faces are not supported as of now. BOOST_LOG_TRIVIAL(error) << "load_obj: failed to parse " << path << ". The file contains polygons with less than 2 vertices."; + message = _L("The file contains polygons with less than 2 vertices."); return false; } if (num_face_vertices == 4) @@ -75,6 +82,7 @@ bool load_obj(const char *path, TriangleMesh *meshptr) assert(cnt < 4); if (vertex.coordIdx < 0 || vertex.coordIdx >= int(its.vertices.size())) { BOOST_LOG_TRIVIAL(error) << "load_obj: failed to parse " << path << ". The file contains invalid vertex index."; + message = _L("The file contains invalid vertex index."); return false; } indices[cnt ++] = vertex.coordIdx; @@ -91,6 +99,7 @@ bool load_obj(const char *path, TriangleMesh *meshptr) *meshptr = TriangleMesh(std::move(its)); if (meshptr->empty()) { BOOST_LOG_TRIVIAL(error) << "load_obj: This OBJ file couldn't be read because it's empty. " << path; + message = _L("This OBJ file couldn't be read because it's empty."); return false; } if (meshptr->volume() < 0) @@ -98,11 +107,11 @@ bool load_obj(const char *path, TriangleMesh *meshptr) return true; } -bool load_obj(const char *path, Model *model, const char *object_name_in) +bool load_obj(const char *path, Model *model, std::string &message, const char *object_name_in) { TriangleMesh mesh; - bool ret = load_obj(path, &mesh); + bool ret = load_obj(path, &mesh, message); if (ret) { std::string object_name; diff --git a/src/libslic3r/Format/OBJ.hpp b/src/libslic3r/Format/OBJ.hpp index 3eb8b41393..e9a3817e43 100644 --- a/src/libslic3r/Format/OBJ.hpp +++ b/src/libslic3r/Format/OBJ.hpp @@ -8,8 +8,8 @@ class Model; class ModelObject; // Load an OBJ file into a provided model. -extern bool load_obj(const char *path, TriangleMesh *mesh); -extern bool load_obj(const char *path, Model *model, const char *object_name = nullptr); +extern bool load_obj(const char *path, TriangleMesh *mesh, std::string &message); +extern bool load_obj(const char *path, Model *model, std::string &message, const char *object_name = nullptr); extern bool store_obj(const char *path, TriangleMesh *mesh); extern bool store_obj(const char *path, ModelObject *model); diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 9d2c664d26..f691f9ff65 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -181,7 +181,7 @@ Model Model::read_from_file(const std::string& input_file, DynamicPrintConfig* c else if (boost::algorithm::iends_with(input_file, ".stl")) result = load_stl(input_file.c_str(), &model, nullptr, stlFn); else if (boost::algorithm::iends_with(input_file, ".obj")) - result = load_obj(input_file.c_str(), &model); + result = load_obj(input_file.c_str(), &model, message); else if (boost::algorithm::iends_with(input_file, ".svg")) result = load_svg(input_file.c_str(), &model, message); //BBS: remove the old .amf.xml files