CLI: Fixed load of the model, when input file isn't project file

This commit is contained in:
YuSanka 2025-01-15 13:47:40 +01:00 committed by Lukas Matena
parent c264a216c0
commit f51611c83e
3 changed files with 12 additions and 5 deletions

View File

@ -129,7 +129,7 @@ static bool process_input_files(std::vector<Model>& models, DynamicPrintConfig&
Model model; Model model;
try { try {
if (has_full_config_from_profiles(cli)) { if (has_full_config_from_profiles(cli) || !FileReader::is_project_file(file)) {
// we have full banch of options from profiles set // we have full banch of options from profiles set
// so, just load a geometry // so, just load a geometry
model = FileReader::load_model(file); model = FileReader::load_model(file);
@ -154,7 +154,7 @@ static bool process_input_files(std::vector<Model>& models, DynamicPrintConfig&
} }
// If model for slicing is loaded from 3mf file, then its geometry has to be used and arrange couldn't be apply for this model. // If model for slicing is loaded from 3mf file, then its geometry has to be used and arrange couldn't be apply for this model.
if ((boost::algorithm::iends_with(file, ".3mf") || boost::algorithm::iends_with(file, ".zip")) && if (FileReader::is_project_file(file) &&
(!cli.transform_config.has("dont_arrange") || !cli.transform_config.opt_bool("dont_arrange"))) { (!cli.transform_config.has("dont_arrange") || !cli.transform_config.opt_bool("dont_arrange"))) {
//So, check a state of "dont_arrange" parameter and set it to true, if its value is false. //So, check a state of "dont_arrange" parameter and set it to true, if its value is false.
cli.transform_config.set_key_value("dont_arrange", new ConfigOptionBool(true)); cli.transform_config.set_key_value("dont_arrange", new ConfigOptionBool(true));

View File

@ -30,6 +30,12 @@
namespace Slic3r::FileReader namespace Slic3r::FileReader
{ {
bool is_project_file(const std::string& input_file)
{
return boost::algorithm::iends_with(input_file, ".3mf") || boost::algorithm::iends_with(input_file, ".zip");
}
// Loading model from a file, it may be a simple geometry file as STL or OBJ, however it may be a project file as well. // Loading model from a file, it may be a simple geometry file as STL or OBJ, however it may be a project file as well.
static Model read_model_from_file(const std::string& input_file, LoadAttributes options) static Model read_model_from_file(const std::string& input_file, LoadAttributes options)
{ {
@ -83,15 +89,14 @@ static Model read_all_from_file(const std::string& input_file,
boost::optional<Semver> &prusaslicer_generator_version, boost::optional<Semver> &prusaslicer_generator_version,
LoadAttributes options) LoadAttributes options)
{ {
const bool is_project_file = boost::algorithm::iends_with(input_file, ".3mf") || boost::algorithm::iends_with(input_file, ".zip"); assert(is_project_file(input_file));
assert(is_project_file);
assert(config != nullptr); assert(config != nullptr);
assert(config_substitutions != nullptr); assert(config_substitutions != nullptr);
Model model; Model model;
bool result = false; bool result = false;
if (is_project_file) if (is_project_file(input_file))
result = load_3mf(input_file.c_str(), *config, *config_substitutions, &model, options & LoadAttribute::CheckVersion, prusaslicer_generator_version); result = load_3mf(input_file.c_str(), *config, *config_substitutions, &model, options & LoadAttribute::CheckVersion, prusaslicer_generator_version);
else else
throw Slic3r::RuntimeError(L("Unknown file format. Input file must have .3mf extension.")); throw Slic3r::RuntimeError(L("Unknown file format. Input file must have .3mf extension."));

View File

@ -35,6 +35,8 @@ namespace FileReader
bool looks_like_multipart_object { false }; bool looks_like_multipart_object { false };
}; };
bool is_project_file(const std::string& input_file);
// Load model from input file and return the its mesh. // Load model from input file and return the its mesh.
// Throw RuntimeError if some problem was detected during model loading // Throw RuntimeError if some problem was detected during model loading
TriangleMesh load_mesh(const std::string& input_file); TriangleMesh load_mesh(const std::string& input_file);