From 5cef22ee66b47b02fc99bb5b912e5642fecfc01e Mon Sep 17 00:00:00 2001 From: SoftFever Date: Fri, 8 Sep 2023 00:01:12 +0800 Subject: [PATCH] klipper object exclusion name fix --- src/libslic3r/GCode.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 32a4c1aede..2472fe45cc 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -2957,12 +2958,25 @@ namespace Skirt { } // namespace Skirt -inline std::string get_instance_name(const PrintObject *object, size_t inst_id) { - auto obj_name = object->model_object()->name; - // replace space in obj_name with '-' - std::replace(obj_name.begin(), obj_name.end(), ' ', '_'); +// Orca: Klipper can't parse object names with spaces and other spetical characters +std::string sanitize_instance_name(const std::string& name) { + // Replace sequences of non-word characters with an underscore + std::string result = std::regex_replace(name, std::regex("[ !@#$%^&*()=+\\[\\]{};:\",']+"), "_"); + // Remove leading and trailing underscores + if (!result.empty() && result.front() == '_') { + result.erase(result.begin()); + } + if (!result.empty() && result.back() == '_') { + result.erase(result.end() - 1); + } - return (boost::format("%1%_id_%2%_copy_%3%") % obj_name % object->get_id() % inst_id).str(); + return result; +} + +inline std::string get_instance_name(const PrintObject *object, size_t inst_id) { + auto obj_name = sanitize_instance_name(object->model_object()->name); + auto name = (boost::format("%1%_id_%2%_copy_%3%") % obj_name % object->get_id() % inst_id).str(); + return sanitize_instance_name(name); } inline std::string get_instance_name(const PrintObject *object, const PrintInstance &inst) {