From 3b973e01dd3c893116d80ba79cb8f06ff023cce5 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Fri, 1 Feb 2019 11:44:08 +0100 Subject: [PATCH] Get name of both the G-code and project file from the 1st printable object's name or file path. Fixed some compilation warnings. --- src/libslic3r/GCode/SpiralVase.hpp | 2 +- src/libslic3r/GCodeReader.hpp | 2 +- src/libslic3r/Model.cpp | 13 ++++++++++--- src/libslic3r/PrintBase.cpp | 15 ++------------- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/libslic3r/GCode/SpiralVase.hpp b/src/libslic3r/GCode/SpiralVase.hpp index 60aa668d8..7872b1d3c 100644 --- a/src/libslic3r/GCode/SpiralVase.hpp +++ b/src/libslic3r/GCode/SpiralVase.hpp @@ -13,7 +13,7 @@ class SpiralVase { SpiralVase(const PrintConfig &config) : enable(false), _config(&config) { - this->_reader.z() = this->_config->z_offset; + this->_reader.z() = (float)this->_config->z_offset; this->_reader.apply_config(*this->_config); }; std::string process_layer(const std::string &gcode); diff --git a/src/libslic3r/GCodeReader.hpp b/src/libslic3r/GCodeReader.hpp index 13f9e7dd7..f64605a9c 100644 --- a/src/libslic3r/GCodeReader.hpp +++ b/src/libslic3r/GCodeReader.hpp @@ -43,7 +43,7 @@ public: } bool cmd_is(const char *cmd_test) const { const char *cmd = GCodeReader::skip_whitespaces(m_raw.c_str()); - int len = strlen(cmd_test); + size_t len = strlen(cmd_test); return strncmp(cmd, cmd_test, len) == 0 && GCodeReader::is_end_of_word(cmd[len]); } bool extruding(const GCodeReader &reader) const { return this->cmd_is("G1") && this->dist_E(reader) > 0; } diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index a88bdd991..968a3e234 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -549,11 +549,18 @@ void Model::reset_auto_extruder_id() std::string Model::propose_export_file_name() const { + std::string input_file; for (const ModelObject *model_object : this->objects) for (ModelInstance *model_instance : model_object->instances) - if (model_instance->is_printable()) - return model_object->name.empty() ? model_object->input_file : model_object->name; - return std::string(); + if (model_instance->is_printable()) { + input_file = model_object->name.empty() ? model_object->input_file : model_object->name; + if (! input_file.empty()) + goto end; + // Other instances will produce the same name, skip them. + break; + } +end: + return input_file; } ModelObject::~ModelObject() diff --git a/src/libslic3r/PrintBase.cpp b/src/libslic3r/PrintBase.cpp index 1d078da30..48e991b8d 100644 --- a/src/libslic3r/PrintBase.cpp +++ b/src/libslic3r/PrintBase.cpp @@ -67,20 +67,9 @@ std::string PrintBase::output_filename(const std::string &format, const std::str std::string PrintBase::output_filepath(const std::string &path) const { // if we were supplied no path, generate an automatic one based on our first object's input file - if (path.empty()) { + if (path.empty()) // get the first input file name - std::string input_file; - for (const ModelObject *model_object : m_model.objects) { - for (ModelInstance *model_instance : model_object->instances) - if (model_instance->is_printable()) { - input_file = model_object->input_file; - break; - } - if (! input_file.empty()) - break; - } - return (boost::filesystem::path(input_file).parent_path() / this->output_filename()).make_preferred().string(); - } + return (boost::filesystem::path(m_model.propose_export_file_name()).parent_path() / this->output_filename()).make_preferred().string(); // if we were supplied a directory, use it and append our automatically generated filename boost::filesystem::path p(path);