From 09530ef7c44f69058bd383cbd8516fece4be2aeb Mon Sep 17 00:00:00 2001 From: HanifKoh <76276251+HanifKoh@users.noreply.github.com> Date: Thu, 8 Oct 2026 13:40:36 +0800 Subject: [PATCH 1/6] Size a Project's Mixed-Colour Metadata to the Filaments in the CLI (#16247) The mixed-colour metadata options are parallel per-slot arrays in the project config. A project saved before they were sized per slot stores a single value for the gradient ones, and one saved before they existed stores none. The GUI sizes all seven to the filament count when it opens a project; the CLI kept the stored arrays and exported one-element defaults for absent ones, so a project it exported carried one-element arrays where the GUI writes one entry per filament. Slicing is unaffected, every reader treats a missing entry as not mixed / no gradient, but the GUI-vs-CLI comparison reported the four gradient keys on every mixed-filament project. The resize helper moves from PresetBundle.cpp, where it was file-local, to PrintConfig.cpp next to set_filament_dev_options(). It creates an option the config lacks before sizing it, a no-op for the bundle's project config where all seven always exist. The CLI calls it with its filament count once the project and loaded filaments are merged, after the check that every mixed slot has a filament of its own. --- src/OrcaSlicer.cpp | 2 ++ src/libslic3r/PresetBundle.cpp | 18 ----------------- src/libslic3r/PrintConfig.cpp | 15 ++++++++++++++ src/libslic3r/PrintConfig.hpp | 4 ++++ .../test_config_variant_expansion.cpp | 20 +++++++++++++++++++ 5 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/OrcaSlicer.cpp b/src/OrcaSlicer.cpp index 7104d1bbcb..b895c25e89 100644 --- a/src/OrcaSlicer.cpp +++ b/src/OrcaSlicer.cpp @@ -4094,6 +4094,8 @@ int CLI::run(int argc, char **argv) flush_and_exit(CLI_MIXED_FILAMENT_INVALID); } } + if (filament_count > 0) + resize_mixed_filament_metadata(m_print_config, size_t(filament_count), size_t(filament_count)); m_print_config.option>("printer_technology", true)->value = printer_technology; diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 0b3d30d5a5..ae8aec1bd3 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -3593,24 +3593,6 @@ void PresetBundle::export_selections(AppConfig &config) BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": printer %1%, print %2%, filaments[0] %3% ")%printers.get_selected_preset_name() % prints.get_selected_preset_name() %filament_presets[0]; } -// Preserve metadata only for existing colour slots; new slots get false/empty defaults. -static void resize_mixed_filament_metadata(DynamicPrintConfig &config, size_t old_slot_count, size_t new_slot_count) -{ - auto resize = [old_slot_count, new_slot_count](auto *opt) { - if (opt) { - opt->values.resize(std::min(old_slot_count, opt->values.size())); - opt->values.resize(new_slot_count); - } - }; - resize(config.option("filament_is_mixed")); - resize(config.option("filament_mixed_components")); - resize(config.option("filament_mixed_sublayer_ratios")); - resize(config.option("filament_mixed_gradient")); - resize(config.option("filament_mixed_gradient_range")); - resize(config.option("filament_mixed_gradient_curve")); - resize(config.option("filament_mixed_gradient_per_part")); -} - void PresetBundle::set_num_filaments(unsigned int n, std::string new_color) { unsigned old_filament_count = this->filament_presets.size(); diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index cd60a8f471..fc534c9686 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -10845,6 +10845,21 @@ void set_filament_dev_options(DynamicPrintConfig &config, const std::vectorvalues.resize(std::min(old_slot_count, opt->values.size())); + opt->values.resize(new_slot_count); + }; + resize(config.option("filament_is_mixed", true)); + resize(config.option("filament_mixed_components", true)); + resize(config.option("filament_mixed_sublayer_ratios", true)); + resize(config.option("filament_mixed_gradient", true)); + resize(config.option("filament_mixed_gradient_range", true)); + resize(config.option("filament_mixed_gradient_curve", true)); + resize(config.option("filament_mixed_gradient_per_part", true)); +} + //used for object/region config //use the smallest of multiple to single diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index beff23933a..0bad9eea86 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -933,6 +933,10 @@ extern std::set filament_dev_options; // filament_configs, one config per filament in slot order, as the filaments' values one after another. void set_filament_dev_options(DynamicPrintConfig &config, const std::vector &filament_configs); +// Orca: sizes the per-slot mixed-colour metadata options to new_slot_count, keeping the first +// old_slot_count values; an option the config lacks is created. +void resize_mixed_filament_metadata(DynamicPrintConfig &config, size_t old_slot_count, size_t new_slot_count); + extern void update_static_print_config_from_dynamic(ConfigBase& config, const DynamicPrintConfig& dest_config, std::vector variant_index, std::set& key_set1, int stride = 1); extern void compute_filament_override_value(const std::string& opt_key, const ConfigOption *opt_old_machine, const ConfigOption *opt_new_machine, const ConfigOption *opt_new_filament, const DynamicPrintConfig& new_full_config, t_config_option_keys& diff_keys, DynamicPrintConfig& filament_overrides, std::vector& f_map_indices); diff --git a/tests/libslic3r/test_config_variant_expansion.cpp b/tests/libslic3r/test_config_variant_expansion.cpp index 40fdce384a..aa1cc1d374 100644 --- a/tests/libslic3r/test_config_variant_expansion.cpp +++ b/tests/libslic3r/test_config_variant_expansion.cpp @@ -863,3 +863,23 @@ TEST_CASE("The device drying options are rebuilt as each filament's values in sl set_filament_dev_options(config, {&two_values, &no_value}); REQUIRE(config.option("filament_dev_ams_drying_ams_limitations")->values == std::vector({"1", "0", ""})); } + +TEST_CASE("The mixed filament metadata is sized to the filament count", "[Config]") +{ + DynamicPrintConfig config; + config.option("filament_is_mixed", true)->values = {false, false, true}; + config.option("filament_mixed_components", true)->values = {"", "", "1,2"}; + config.option("filament_mixed_gradient", true)->values = {false}; + config.option("filament_mixed_gradient_range", true)->values = {""}; + + resize_mixed_filament_metadata(config, 3, 3); + REQUIRE(config.option("filament_is_mixed")->values == std::vector({false, false, true})); + REQUIRE(config.option("filament_mixed_components")->values == std::vector({"", "", "1,2"})); + REQUIRE(config.option("filament_mixed_gradient")->values == std::vector({false, false, false})); + REQUIRE(config.option("filament_mixed_gradient_range")->values == std::vector({"", "", ""})); + REQUIRE(config.option("filament_mixed_gradient_curve")->values == std::vector({"", "", ""})); + + resize_mixed_filament_metadata(config, 2, 4); + REQUIRE(config.option("filament_is_mixed")->values == std::vector({false, false, false, false})); + REQUIRE(config.option("filament_mixed_components")->values == std::vector({"", "", "", ""})); +} From 6cd5feed79880e9c5669197e75a49686160e83cf Mon Sep 17 00:00:00 2001 From: HanifKoh <76276251+HanifKoh@users.noreply.github.com> Date: Thu, 8 Oct 2026 13:51:50 +0800 Subject: [PATCH 2/6] Remove Duplicate Includes and the Dead GCodeSender Sources (#16249) 46 files include the same header twice at file scope, outside any #if, 66 times in all: Model.cpp included Model.hpp twice, Utils.hpp and twice, seven GUI headers and twice. The second include of each is removed. GCodeSender.cpp and GCodeSender.hpp have been commented out of libslic3r/CMakeLists.txt since 2022 and their only two includes are commented out as well. Both files go, with the commented lines, and the CMake entry for SLA/SupportTreeIGL.cpp, a file that no longer exists. --- src/libslic3r/CAD/CadDocument.cpp | 1 - src/libslic3r/CMakeLists.txt | 3 - src/libslic3r/CutSurface.cpp | 1 - src/libslic3r/Emboss.cpp | 1 - src/libslic3r/Format/STEP.cpp | 1 - src/libslic3r/GCode.cpp | 1 - src/libslic3r/GCode/FanMover.cpp | 2 - src/libslic3r/GCodeSender.cpp | 580 ------------------ src/libslic3r/GCodeSender.hpp | 81 --- src/libslic3r/Geometry/MedialAxis.cpp | 1 - src/libslic3r/Model.cpp | 1 - src/libslic3r/Model.hpp | 1 - src/libslic3r/Shape/TextShape.cpp | 1 - src/libslic3r/Utils.hpp | 2 - src/slic3r/GUI/AmsMappingPopup.hpp | 2 - src/slic3r/GUI/AmsWidgets.hpp | 3 - src/slic3r/GUI/Auxiliary.hpp | 3 - src/slic3r/GUI/BBLStatusBar.hpp | 1 - src/slic3r/GUI/BBLStatusBarBind.hpp | 1 - src/slic3r/GUI/BBLStatusBarPrint.hpp | 1 - src/slic3r/GUI/BBLStatusBarSend.hpp | 1 - src/slic3r/GUI/BaseTransparentDPIFrame.cpp | 1 - src/slic3r/GUI/BindDialog.cpp | 1 - src/slic3r/GUI/BonjourDialog.cpp | 1 - src/slic3r/GUI/Calibration.hpp | 2 - src/slic3r/GUI/ConfigManipulation.cpp | 1 - src/slic3r/GUI/DeviceCore/DevFilaSystem.h | 1 - src/slic3r/GUI/DeviceManager.cpp | 1 - src/slic3r/GUI/GLTexture.cpp | 1 - src/slic3r/GUI/GUI.cpp | 1 - src/slic3r/GUI/GUI_App.cpp | 2 - src/slic3r/GUI/HintNotification.cpp | 1 - src/slic3r/GUI/ImGuiWrapper.cpp | 1 - src/slic3r/GUI/MainFrame.cpp | 1 - src/slic3r/GUI/ModelMall.cpp | 1 - src/slic3r/GUI/Monitor.cpp | 1 - src/slic3r/GUI/Monitor.hpp | 3 - src/slic3r/GUI/NetworkTestDialog.cpp | 1 - src/slic3r/GUI/PresetBundleDialog.cpp | 1 - src/slic3r/GUI/PrintHostDialogs.cpp | 1 - src/slic3r/GUI/ProgressStatusBar.hpp | 1 - src/slic3r/GUI/ReleaseNote.hpp | 3 - src/slic3r/GUI/SelectMachine.hpp | 2 - src/slic3r/GUI/SelectMachinePop.hpp | 2 - src/slic3r/GUI/SendToPrinter.hpp | 2 - src/slic3r/GUI/Tab.cpp | 3 - src/slic3r/Utils/CalibUtils.cpp | 2 - src/slic3r/Utils/EmbossStyleManager.cpp | 3 - src/slic3r/Utils/PresetUpdater.cpp | 1 - .../libslic3r/test_preset_bundle_loading.cpp | 1 - 50 files changed, 732 deletions(-) delete mode 100644 src/libslic3r/GCodeSender.cpp delete mode 100644 src/libslic3r/GCodeSender.hpp diff --git a/src/libslic3r/CAD/CadDocument.cpp b/src/libslic3r/CAD/CadDocument.cpp index cec5a3a74e..cb143da9a6 100644 --- a/src/libslic3r/CAD/CadDocument.cpp +++ b/src/libslic3r/CAD/CadDocument.cpp @@ -84,7 +84,6 @@ #include #include #include -#include #include #include #include diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index fa81aceea2..781fd374d4 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -261,8 +261,6 @@ set(lisbslic3r_sources GCode/PreciseSeam.cpp GCode/PreciseSeam.hpp GCode/PreciseSeamInternal.hpp - #GCodeSender.cpp - #GCodeSender.hpp GCode/SmallAreaInfillFlowCompensator.cpp GCode/SmallAreaInfillFlowCompensator.hpp GCode/SpiralVase.cpp @@ -447,7 +445,6 @@ set(lisbslic3r_sources SLA/SupportTreeBuildsteps.hpp SLA/SupportTree.cpp SLA/SupportTree.hpp - #SLA/SupportTreeIGL.cpp SLA/SupportTreeMesher.cpp SLA/SupportTreeMesher.hpp SlicesToTriangleMesh.cpp diff --git a/src/libslic3r/CutSurface.cpp b/src/libslic3r/CutSurface.cpp index 76b87a1e7e..abda122a71 100644 --- a/src/libslic3r/CutSurface.cpp +++ b/src/libslic3r/CutSurface.cpp @@ -2589,7 +2589,6 @@ void priv::create_face_types(FaceTypeMap &map, } #include -#include bool priv::clip_cut(SurfacePatch &cut, CutMesh clipper) { CutMesh& tm = cut.mesh; diff --git a/src/libslic3r/Emboss.cpp b/src/libslic3r/Emboss.cpp index 2506c26f61..3a44ef4407 100644 --- a/src/libslic3r/Emboss.cpp +++ b/src/libslic3r/Emboss.cpp @@ -15,7 +15,6 @@ #include "Emboss.hpp" #include #include -#include #include #include #include diff --git a/src/libslic3r/Format/STEP.cpp b/src/libslic3r/Format/STEP.cpp index 57d8e44157..962c4cffb9 100644 --- a/src/libslic3r/Format/STEP.cpp +++ b/src/libslic3r/Format/STEP.cpp @@ -55,7 +55,6 @@ #include "TDataStd_Name.hxx" #include "BRepBuilderAPI_Transform.hxx" #include "TopExp_Explorer.hxx" -#include "TopExp_Explorer.hxx" #include "BRep_Tool.hxx" #include "BRepTools.hxx" #include diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 7317676240..844ac8da1e 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -43,7 +43,6 @@ #include "Print.hpp" #include "Utils.hpp" #include "ClipperUtils.hpp" -#include "libslic3r.h" #include "LocalesUtils.hpp" #include "libslic3r/format.hpp" #include "Time.hpp" diff --git a/src/libslic3r/GCode/FanMover.cpp b/src/libslic3r/GCode/FanMover.cpp index 3fc85828ec..d303cbbac6 100644 --- a/src/libslic3r/GCode/FanMover.cpp +++ b/src/libslic3r/GCode/FanMover.cpp @@ -27,8 +27,6 @@ #include "../PrintConfig.hpp" #include "../Utils.hpp" #include "Print.hpp" -#include "libslic3r/PrintConfig.hpp" -#include "libslic3r/libslic3r.h" #include #include diff --git a/src/libslic3r/GCodeSender.cpp b/src/libslic3r/GCodeSender.cpp deleted file mode 100644 index 275dd61a79..0000000000 --- a/src/libslic3r/GCodeSender.cpp +++ /dev/null @@ -1,580 +0,0 @@ -#include "GCodeSender.hpp" -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(__APPLE__) || defined(__OpenBSD__) -#include -#endif -#ifdef __APPLE__ -#include -#include -#endif -#ifdef __linux__ -#include -#include -#include "/usr/include/asm-generic/ioctls.h" - -/* The following definitions are kindly borrowed from: - /usr/include/asm-generic/termbits.h - Unfortunately we cannot just include that one because - it would redefine the "struct termios" already defined - the already included by Boost.ASIO. */ -#define K_NCCS 19 -struct termios2 { - tcflag_t c_iflag; - tcflag_t c_oflag; - tcflag_t c_cflag; - tcflag_t c_lflag; - cc_t c_line; - cc_t c_cc[K_NCCS]; - speed_t c_ispeed; - speed_t c_ospeed; -}; -#define BOTHER CBAUDEX - -#endif - -//#define DEBUG_SERIAL -#ifdef DEBUG_SERIAL -#include -#include -std::fstream fs; -#endif - -#define KEEP_SENT 20 - -namespace Slic3r { - -GCodeSender::GCodeSender() - : io(), serial(io), can_send(false), sent(0), open(false), error(false), - connected(false), queue_paused(false) -{ -#ifdef DEBUG_SERIAL - std::srand(std::time(nullptr)); -#endif -} - -GCodeSender::~GCodeSender() -{ - this->disconnect(); -} - -bool -GCodeSender::connect(std::string devname, unsigned int baud_rate) -{ - this->disconnect(); - - this->set_error_status(false); - try { - this->serial.open(devname); - - this->serial.set_option(boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::odd)); - this->serial.set_option(boost::asio::serial_port_base::character_size(boost::asio::serial_port_base::character_size(8))); - this->serial.set_option(boost::asio::serial_port_base::flow_control(boost::asio::serial_port_base::flow_control::none)); - this->serial.set_option(boost::asio::serial_port_base::stop_bits(boost::asio::serial_port_base::stop_bits::one)); - this->set_baud_rate(baud_rate); - - this->serial.close(); - this->serial.open(devname); - this->serial.set_option(boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::none)); - - // set baud rate again because set_option overwrote it - this->set_baud_rate(baud_rate); - this->open = true; - this->reset(); - } catch (boost::system::system_error &) { - this->set_error_status(true); - return false; - } - - // a reset firmware expect line numbers to start again from 1 - this->sent = 0; - this->last_sent.clear(); - - /* Initialize debugger */ -#ifdef DEBUG_SERIAL - fs.open("serial.txt", std::fstream::out | std::fstream::trunc); -#endif - - // this gives some work to the io_service before it is started - // (post() runs the supplied function in its thread) - this->io.post(boost::bind(&GCodeSender::do_read, this)); - - // start reading in the background thread - boost::thread t(boost::bind(&boost::asio::io_service::run, &this->io)); - this->background_thread.swap(t); - - // always send a M105 to check for connection because firmware might be silent on connect - //FIXME Vojtech: This is being sent too early, leading to line number synchronization issues, - // from which the GCodeSender never recovers. - // this->send("M105", true); - - return true; -} - -void -GCodeSender::set_baud_rate(unsigned int baud_rate) -{ - try { - // This does not support speeds > 115200 - this->serial.set_option(boost::asio::serial_port_base::baud_rate(baud_rate)); - } catch (boost::system::system_error &) { - boost::asio::serial_port::native_handle_type handle = this->serial.native_handle(); - -#if __APPLE__ - termios ios; - ::tcgetattr(handle, &ios); - ::cfsetspeed(&ios, baud_rate); - speed_t newSpeed = baud_rate; - ioctl(handle, IOSSIOSPEED, &newSpeed); - ::tcsetattr(handle, TCSANOW, &ios); -#elif __linux__ - termios2 ios; - if (ioctl(handle, TCGETS2, &ios)) - printf("Error in TCGETS2: %s\n", strerror(errno)); - ios.c_ispeed = ios.c_ospeed = baud_rate; - ios.c_cflag &= ~CBAUD; - ios.c_cflag |= BOTHER | CLOCAL | CREAD; - ios.c_cc[VMIN] = 1; // Minimum of characters to read, prevents eof errors when 0 bytes are read - ios.c_cc[VTIME] = 1; - if (ioctl(handle, TCSETS2, &ios)) - printf("Error in TCSETS2: %s\n", strerror(errno)); - -#elif __OpenBSD__ - struct termios ios; - ::tcgetattr(handle, &ios); - ::cfsetspeed(&ios, baud_rate); - if (::tcsetattr(handle, TCSAFLUSH, &ios) != 0) - printf("Failed to set baud rate: %s\n", strerror(errno)); -#else - //throw Slic3r::InvalidArgument("OS does not currently support custom bauds"); -#endif - } -} - -void -GCodeSender::disconnect() -{ - if (!this->open) return; - this->open = false; - this->connected = false; - this->io.post(boost::bind(&GCodeSender::do_close, this)); - this->background_thread.join(); - this->io.reset(); - /* - if (this->error_status()) { - throw(boost::system::system_error(boost::system::error_code(), - "Error while closing the device")); - } - */ - -#ifdef DEBUG_SERIAL - fs << "DISCONNECTED" << std::endl << std::flush; - fs.close(); -#endif -} - -bool -GCodeSender::is_connected() const -{ - return this->connected; -} - -bool -GCodeSender::wait_connected(unsigned int timeout) const -{ - using namespace boost::posix_time; - ptime t0 = second_clock::local_time() + seconds(timeout); - while (!this->connected) { - if (second_clock::local_time() > t0) return false; - boost::this_thread::sleep(boost::posix_time::milliseconds(100)); - } - return true; -} - -size_t -GCodeSender::queue_size() const -{ - boost::lock_guard l(this->queue_mutex); - return this->queue.size(); -} - -void -GCodeSender::pause_queue() -{ - boost::lock_guard l(this->queue_mutex); - this->queue_paused = true; -} - -void -GCodeSender::resume_queue() -{ - { - boost::lock_guard l(this->queue_mutex); - this->queue_paused = false; - } - this->send(); -} - -void -GCodeSender::purge_queue(bool priority) -{ - boost::lock_guard l(this->queue_mutex); - if (priority) { - // clear priority queue - std::list empty; - std::swap(this->priqueue, empty); - } else { - // clear queue - std::queue empty; - std::swap(this->queue, empty); - this->queue_paused = false; - } -} - -// purge log and return its contents -std::vector -GCodeSender::purge_log() -{ - boost::lock_guard l(this->log_mutex); - std::vector retval; - retval.reserve(this->log.size()); - while (!this->log.empty()) { - retval.push_back(this->log.front()); - this->log.pop(); - } - return retval; -} - -std::string -GCodeSender::getT() const -{ - boost::lock_guard l(this->log_mutex); - return this->T; -} - -std::string -GCodeSender::getB() const -{ - boost::lock_guard l(this->log_mutex); - return this->B; -} - -void -GCodeSender::do_close() -{ - this->set_error_status(false); - boost::system::error_code ec; - this->serial.cancel(ec); - if (ec) this->set_error_status(true); - this->serial.close(ec); - if (ec) this->set_error_status(true); -} - -void -GCodeSender::set_error_status(bool e) -{ - boost::lock_guard l(this->error_mutex); - this->error = e; -} - -bool -GCodeSender::error_status() const -{ - boost::lock_guard l(this->error_mutex); - return this->error; -} - -void -GCodeSender::do_read() -{ - // read one line - boost::asio::async_read_until( - this->serial, - this->read_buffer, - '\n', - boost::bind( - &GCodeSender::on_read, - this, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred - ) - ); -} - -void -GCodeSender::on_read(const boost::system::error_code& error, - size_t bytes_transferred) -{ - this->set_error_status(false); - if (error) { - #ifdef __APPLE__ - if (error.value() == 45) { - // OS X bug: http://osdir.com/ml/lib.boost.asio.user/2008-08/msg00004.html - this->do_read(); - return; - } - #endif - - // printf("ERROR: [%d] %s\n", error.value(), error.message().c_str()); - // error can be true even because the serial port was closed. - // In this case it is not a real error, so ignore. - if (this->open) { - this->do_close(); - this->set_error_status(true); - } - return; - } - - std::istream is(&this->read_buffer); - std::string line; - std::getline(is, line); - if (!line.empty()) { -#ifdef DEBUG_SERIAL - fs << "<< " << line << std::endl << std::flush; -#endif - - // note that line might contain \r at its end - // parse incoming line - if (!this->connected - && (boost::starts_with(line, "start") - || boost::starts_with(line, "Grbl ") - || boost::starts_with(line, "ok") - || boost::contains(line, "T:"))) { - this->connected = true; - { - boost::lock_guard l(this->queue_mutex); - this->can_send = true; - } - this->send(); - } else if (boost::starts_with(line, "ok")) { - { - boost::lock_guard l(this->queue_mutex); - this->can_send = true; - } - this->send(); - } else if (boost::istarts_with(line, "resend") // Marlin uses "Resend: " - || boost::istarts_with(line, "rs")) { - // extract the first number from line - boost::algorithm::trim_left_if(line, !boost::algorithm::is_digit()); - size_t toresend = boost::lexical_cast(line.substr(0, line.find_first_not_of("0123456789"))); - -#ifdef DEBUG_SERIAL - fs << "!! line num out of sync: toresend = " << toresend << ", sent = " << sent << ", last_sent.size = " << last_sent.size() << std::endl; -#endif - - if (toresend > this->sent - this->last_sent.size() && toresend <= this->sent) { - { - boost::lock_guard l(this->queue_mutex); - - const auto lines_to_resend = this->sent - toresend + 1; -#ifdef DEBUG_SERIAL - fs << "!! resending " << lines_to_resend << " lines" << std::endl; -#endif - // move the unsent lines to priqueue - this->priqueue.insert( - this->priqueue.begin(), // insert at the beginning - this->last_sent.begin() + this->last_sent.size() - lines_to_resend, - this->last_sent.end() - ); - - // we can empty last_sent because it's not useful anymore - this->last_sent.clear(); - - // start resending with the requested line number - this->sent = toresend - 1; - this->can_send = true; - } - this->send(); - } else { - printf("Cannot resend %zu (oldest we have is %zu)\n", toresend, this->sent - this->last_sent.size()); - } - } else if (boost::starts_with(line, "wait")) { - // ignore - } else { - // push any other line into the log - boost::lock_guard l(this->log_mutex); - this->log.push(line); - } - - // parse temperature info - { - size_t pos = line.find("T:"); - if (pos != std::string::npos && line.size() > pos + 2) { - // we got temperature info - boost::lock_guard l(this->log_mutex); - this->T = line.substr(pos+2, line.find_first_not_of("0123456789.", pos+2) - (pos+2)); - - pos = line.find("B:"); - if (pos != std::string::npos && line.size() > pos + 2) { - // we got bed temperature info - this->B = line.substr(pos+2, line.find_first_not_of("0123456789.", pos+2) - (pos+2)); - } - } - } - } - this->do_read(); -} - -void -GCodeSender::send(const std::vector &lines, bool priority) -{ - // append lines to queue - { - boost::lock_guard l(this->queue_mutex); - for (std::vector::const_iterator line = lines.begin(); line != lines.end(); ++line) { - if (priority) { - this->priqueue.push_back(*line); - } else { - this->queue.push(*line); - } - } - } - this->send(); -} - -void -GCodeSender::send(const std::string &line, bool priority) -{ - // append line to queue - { - boost::lock_guard l(this->queue_mutex); - if (priority) { - this->priqueue.push_back(line); - } else { - this->queue.push(line); - } - } - this->send(); -} - -void -GCodeSender::send() -{ - this->io.post(boost::bind(&GCodeSender::do_send, this)); -} - -void -GCodeSender::do_send() -{ - boost::lock_guard l(this->queue_mutex); - - // printer is not connected or we're still waiting for the previous ack - if (!this->can_send) return; - - std::string line; - while (!this->priqueue.empty() || (!this->queue.empty() && !this->queue_paused)) { - if (!this->priqueue.empty()) { - line = this->priqueue.front(); - this->priqueue.pop_front(); - } else { - line = this->queue.front(); - this->queue.pop(); - } - - // strip comments - size_t comment_pos = line.find_first_of(';'); - if (comment_pos != std::string::npos) - line.erase(comment_pos, std::string::npos); - boost::algorithm::trim(line); - - // if line is not empty, send it - if (!line.empty()) break; - // if line is empty, process next item in queue - } - if (line.empty()) return; - - // compute full line - ++ this->sent; -#ifndef DEBUG_SERIAL - const auto line_num = this->sent; -#else - // In DEBUG_SERIAL mode, test line re-synchronization by sending bad line number 1/4 of the time - const auto line_num = std::rand() < RAND_MAX/4 ? 0 : this->sent; -#endif - std::string full_line = "N" + boost::lexical_cast(line_num) + " " + line; - - // calculate checksum - int cs = 0; - for (std::string::const_iterator it = full_line.begin(); it != full_line.end(); ++it) - cs = cs ^ *it; - - // write line to device - full_line += "*"; - full_line += boost::lexical_cast(cs); - full_line += "\n"; - -#ifdef DEBUG_SERIAL - fs << ">> " << full_line << std::flush; -#endif - - this->last_sent.push_back(line); - this->can_send = false; - - while (this->last_sent.size() > KEEP_SENT) { - this->last_sent.pop_front(); - } - - // we can't supply boost::asio::buffer(full_line) to async_write() because full_line is on the - // stack and the buffer would lose its underlying storage causing memory corruption - std::ostream os(&this->write_buffer); - os << full_line; - boost::asio::async_write(this->serial, this->write_buffer, boost::bind(&GCodeSender::on_write, this, boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred)); -} - -void -GCodeSender::on_write(const boost::system::error_code& error, - size_t bytes_transferred) -{ - this->set_error_status(false); - if (error) { - if (this->open) { - this->do_close(); - this->set_error_status(true); - } - return; - } - - this->do_send(); -} - -void -GCodeSender::set_DTR(bool on) -{ -#if defined(_WIN32) && !defined(__SYMBIAN32__) - boost::asio::serial_port_service::native_handle_type handle = this->serial.native_handle(); - if (on) - EscapeCommFunction(handle, SETDTR); - else - EscapeCommFunction(handle, CLRDTR); -#else - int fd = this->serial.native_handle(); - int status; - ioctl(fd, TIOCMGET, &status); - if (on) - status |= TIOCM_DTR; - else - status &= ~TIOCM_DTR; - ioctl(fd, TIOCMSET, &status); -#endif -} - -void -GCodeSender::reset() -{ - set_DTR(false); - std::this_thread::sleep_for(std::chrono::milliseconds(200)); - set_DTR(true); - std::this_thread::sleep_for(std::chrono::milliseconds(200)); - set_DTR(false); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); -} - -} // namespace Slic3r diff --git a/src/libslic3r/GCodeSender.hpp b/src/libslic3r/GCodeSender.hpp deleted file mode 100644 index e9f97e2a29..0000000000 --- a/src/libslic3r/GCodeSender.hpp +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef slic3r_GCodeSender_hpp_ -#define slic3r_GCodeSender_hpp_ - -#include "libslic3r.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Slic3r { - -namespace asio = boost::asio; - -class GCodeSender : private boost::noncopyable { - public: - GCodeSender(); - ~GCodeSender(); - bool connect(std::string devname, unsigned int baud_rate); - void send(const std::vector &lines, bool priority = false); - void send(const std::string &s, bool priority = false); - void disconnect(); - bool error_status() const; - bool is_connected() const; - bool wait_connected(unsigned int timeout = 3) const; - size_t queue_size() const; - void pause_queue(); - void resume_queue(); - void purge_queue(bool priority = false); - std::vector purge_log(); - std::string getT() const; - std::string getB() const; - void set_DTR(bool on); - void reset(); - - private: - asio::io_service io; - asio::serial_port serial; - boost::thread background_thread; - boost::asio::streambuf read_buffer, write_buffer; - bool open; // whether the serial socket is connected - bool connected; // whether the printer is online - bool error; - mutable boost::mutex error_mutex; - - // this mutex guards queue, priqueue, can_send, queue_paused, sent, last_sent - mutable boost::mutex queue_mutex; - std::queue queue; - std::list priqueue; - bool can_send; - bool queue_paused; - size_t sent; - std::deque last_sent; - - // this mutex guards log, T, B - mutable boost::mutex log_mutex; - std::queue log; - std::string T, B; - - void set_baud_rate(unsigned int baud_rate); - void set_error_status(bool e); - void do_send(); - void on_write(const boost::system::error_code& error, size_t bytes_transferred); - void do_close(); - void do_read(); - void on_read(const boost::system::error_code& error, size_t bytes_transferred); - void send(); -}; - -} // namespace Slic3r - -#endif /* slic3r_GCodeSender_hpp_ */ diff --git a/src/libslic3r/Geometry/MedialAxis.cpp b/src/libslic3r/Geometry/MedialAxis.cpp index 9d05ec9867..6fa22eb336 100644 --- a/src/libslic3r/Geometry/MedialAxis.cpp +++ b/src/libslic3r/Geometry/MedialAxis.cpp @@ -1,7 +1,6 @@ #include #include "MedialAxis.hpp" -#include #include #include #include diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 39993895b0..75c4b65ed1 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -22,7 +22,6 @@ #include "Format/AssimpImport.hpp" #include "ClipperUtils.hpp" #include "Exception.hpp" -#include "Model.hpp" #include "ModelArrange.hpp" #include "Arrange.hpp" #include "Geometry.hpp" diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index 9c6967371c..4bb1794b46 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -18,7 +18,6 @@ #include "TriangleMesh.hpp" #include "CustomGCode.hpp" #include "calib.hpp" -#include "enum_bitmask.hpp" #include "TextConfiguration.hpp" #include "EmbossShape.hpp" #include "TriangleSelector.hpp" diff --git a/src/libslic3r/Shape/TextShape.cpp b/src/libslic3r/Shape/TextShape.cpp index dd7ca3f119..15d6744f45 100644 --- a/src/libslic3r/Shape/TextShape.cpp +++ b/src/libslic3r/Shape/TextShape.cpp @@ -44,7 +44,6 @@ #include "TDataStd_Name.hxx" #include "BRepBuilderAPI_Transform.hxx" #include "TopExp_Explorer.hxx" -#include "TopExp_Explorer.hxx" #include "BRep_Tool.hxx" #include "Font_BRepFont.hxx" #include "Font_BRepTextBuilder.hxx" diff --git a/src/libslic3r/Utils.hpp b/src/libslic3r/Utils.hpp index 29adae1b74..24ebe9a337 100644 --- a/src/libslic3r/Utils.hpp +++ b/src/libslic3r/Utils.hpp @@ -25,8 +25,6 @@ #include #include #include -#include -#include #include #include diff --git a/src/slic3r/GUI/AmsMappingPopup.hpp b/src/slic3r/GUI/AmsMappingPopup.hpp index f86b2a4497..90cf86bf57 100644 --- a/src/slic3r/GUI/AmsMappingPopup.hpp +++ b/src/slic3r/GUI/AmsMappingPopup.hpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -30,7 +29,6 @@ #include #include #include -#include #include #include "GUI_Utils.hpp" diff --git a/src/slic3r/GUI/AmsWidgets.hpp b/src/slic3r/GUI/AmsWidgets.hpp index 24f3f781b2..0c3c726b0c 100644 --- a/src/slic3r/GUI/AmsWidgets.hpp +++ b/src/slic3r/GUI/AmsWidgets.hpp @@ -19,20 +19,17 @@ #include #include #include -#include #include #include #include #include #include #include -#include #include #include #include #include #include -#include #include diff --git a/src/slic3r/GUI/Auxiliary.hpp b/src/slic3r/GUI/Auxiliary.hpp index 4f25aab439..01ad99f648 100644 --- a/src/slic3r/GUI/Auxiliary.hpp +++ b/src/slic3r/GUI/Auxiliary.hpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -36,14 +35,12 @@ #include #include #include -#include #include #include #include #include #include #include -#include #include #include #include diff --git a/src/slic3r/GUI/BBLStatusBar.hpp b/src/slic3r/GUI/BBLStatusBar.hpp index 1ff2fd6f0f..829c7445d7 100644 --- a/src/slic3r/GUI/BBLStatusBar.hpp +++ b/src/slic3r/GUI/BBLStatusBar.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include "Jobs/ProgressIndicator.hpp" diff --git a/src/slic3r/GUI/BBLStatusBarBind.hpp b/src/slic3r/GUI/BBLStatusBarBind.hpp index b1b06b60b6..f9c217b504 100644 --- a/src/slic3r/GUI/BBLStatusBarBind.hpp +++ b/src/slic3r/GUI/BBLStatusBarBind.hpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include "Jobs/ProgressIndicator.hpp" diff --git a/src/slic3r/GUI/BBLStatusBarPrint.hpp b/src/slic3r/GUI/BBLStatusBarPrint.hpp index bc82d80068..9780b7f24a 100644 --- a/src/slic3r/GUI/BBLStatusBarPrint.hpp +++ b/src/slic3r/GUI/BBLStatusBarPrint.hpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include "Jobs/ProgressIndicator.hpp" diff --git a/src/slic3r/GUI/BBLStatusBarSend.hpp b/src/slic3r/GUI/BBLStatusBarSend.hpp index 1c4b267c6f..cedab29e1d 100644 --- a/src/slic3r/GUI/BBLStatusBarSend.hpp +++ b/src/slic3r/GUI/BBLStatusBarSend.hpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include "Jobs/ProgressIndicator.hpp" diff --git a/src/slic3r/GUI/BaseTransparentDPIFrame.cpp b/src/slic3r/GUI/BaseTransparentDPIFrame.cpp index c9e4e4b76e..50fa700ec6 100644 --- a/src/slic3r/GUI/BaseTransparentDPIFrame.cpp +++ b/src/slic3r/GUI/BaseTransparentDPIFrame.cpp @@ -18,7 +18,6 @@ #include #include #include -#include "Widgets/Button.hpp" #include "CapsuleButton.hpp" namespace Slic3r::GUI { struct IntEvent; } diff --git a/src/slic3r/GUI/BindDialog.cpp b/src/slic3r/GUI/BindDialog.cpp index 2f1283b790..60dd64bb57 100644 --- a/src/slic3r/GUI/BindDialog.cpp +++ b/src/slic3r/GUI/BindDialog.cpp @@ -46,7 +46,6 @@ #include "libslic3r/Model.hpp" #include "libslic3r/Polygon.hpp" #include "MainFrame.hpp" -#include "GUI_App.hpp" #include "Plater.hpp" #include "Jobs/BoostThreadWorker.hpp" #include "Jobs/PlaterWorker.hpp" diff --git a/src/slic3r/GUI/BonjourDialog.cpp b/src/slic3r/GUI/BonjourDialog.cpp index 566441c64f..914597fe40 100644 --- a/src/slic3r/GUI/BonjourDialog.cpp +++ b/src/slic3r/GUI/BonjourDialog.cpp @@ -29,7 +29,6 @@ #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/I18N.hpp" #include "slic3r/GUI/format.hpp" -#include "slic3r/Utils/Bonjour.hpp" #include "slic3r/GUI/Widgets/DialogButtons.hpp" diff --git a/src/slic3r/GUI/Calibration.hpp b/src/slic3r/GUI/Calibration.hpp index c5318f818b..cc07b1452d 100644 --- a/src/slic3r/GUI/Calibration.hpp +++ b/src/slic3r/GUI/Calibration.hpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -24,7 +23,6 @@ #include #include #include -#include #include #include "GUI_Utils.hpp" diff --git a/src/slic3r/GUI/ConfigManipulation.cpp b/src/slic3r/GUI/ConfigManipulation.cpp index df00a6a8b5..62ae955ab6 100644 --- a/src/slic3r/GUI/ConfigManipulation.cpp +++ b/src/slic3r/GUI/ConfigManipulation.cpp @@ -1,4 +1,3 @@ -// #include "libslic3r/GCodeSender.hpp" #include "ConfigManipulation.hpp" #include "I18N.hpp" #include "GUI_App.hpp" diff --git a/src/slic3r/GUI/DeviceCore/DevFilaSystem.h b/src/slic3r/GUI/DeviceCore/DevFilaSystem.h index 27dc238e9e..b843eba4b3 100644 --- a/src/slic3r/GUI/DeviceCore/DevFilaSystem.h +++ b/src/slic3r/GUI/DeviceCore/DevFilaSystem.h @@ -15,7 +15,6 @@ #include #include #include -#include #include #include diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index 30e7282c0e..c1c357a2d5 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -11,7 +11,6 @@ #include "GUI_App.hpp" #include "DeviceErrorDialog.hpp" #include "Plater.hpp" -#include "GUI_App.hpp" #include "ReleaseNote.hpp" #include #include diff --git a/src/slic3r/GUI/GLTexture.cpp b/src/slic3r/GUI/GLTexture.cpp index 4cdb17dd28..f83dd1f854 100644 --- a/src/slic3r/GUI/GLTexture.cpp +++ b/src/slic3r/GUI/GLTexture.cpp @@ -46,7 +46,6 @@ #include "nanosvg/nanosvgrast.h" #include "libslic3r/Utils.hpp" -#include "GUI_App.hpp" #include #include #include diff --git a/src/slic3r/GUI/GUI.cpp b/src/slic3r/GUI/GUI.cpp index 7de994960e..e376bfc097 100644 --- a/src/slic3r/GUI/GUI.cpp +++ b/src/slic3r/GUI/GUI.cpp @@ -50,7 +50,6 @@ #include "AboutDialog.hpp" #include "MsgDialog.hpp" #include "Plater.hpp" -#include "format.hpp" #include "WebUserLoginDialog.hpp" diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 11cde7e5f2..66362cf213 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -172,12 +172,10 @@ #include "libslic3r/Utils.hpp" #include "libslic3r/Model.hpp" -#include "libslic3r/I18N.hpp" #include "libslic3r/PresetBundle.hpp" #include "libslic3r/InstanceLock.hpp" #include "libslic3r/Thread.hpp" #include "libslic3r/miniz_extension.hpp" -#include "libslic3r/Utils.hpp" #include "slic3r/plugin/PluginManager.hpp" #include "slic3r/plugin/host/PluginHostUi.hpp" #include "slic3r/plugin/PythonInterpreter.hpp" diff --git a/src/slic3r/GUI/HintNotification.cpp b/src/slic3r/GUI/HintNotification.cpp index 433a829c29..1ad5903dea 100644 --- a/src/slic3r/GUI/HintNotification.cpp +++ b/src/slic3r/GUI/HintNotification.cpp @@ -11,7 +11,6 @@ #include "libslic3r/Config.hpp" #include "libslic3r/PresetBundle.hpp" #include "libslic3r/Preset.hpp" -#include "libslic3r/Config.hpp" #include "libslic3r/PrintConfig.hpp" #include diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 5728ad5697..7def86aaeb 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -66,7 +66,6 @@ #include #include #include "OpenGLManager.hpp" -#include "GUI_App.hpp" namespace Slic3r { namespace GUI { diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index c882667d90..84b702d7e5 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -113,7 +113,6 @@ #include "MsgDialog.hpp" #include "Notebook.hpp" #include "GUI_Factories.hpp" -#include "GUI_ObjectList.hpp" #include "NotificationManager.hpp" #include "MarkdownTip.hpp" #include "NetworkTestDialog.hpp" diff --git a/src/slic3r/GUI/ModelMall.cpp b/src/slic3r/GUI/ModelMall.cpp index e8b08f7e02..f0d708640d 100644 --- a/src/slic3r/GUI/ModelMall.cpp +++ b/src/slic3r/GUI/ModelMall.cpp @@ -21,7 +21,6 @@ #include "wx/evtloop.h" #include "MainFrame.hpp" -#include "GUI_App.hpp" #include "Plater.hpp" using json = nlohmann::json; diff --git a/src/slic3r/GUI/Monitor.cpp b/src/slic3r/GUI/Monitor.cpp index b23c5ab468..4e7bae328d 100644 --- a/src/slic3r/GUI/Monitor.cpp +++ b/src/slic3r/GUI/Monitor.cpp @@ -45,7 +45,6 @@ #include "MainFrame.hpp" #include "MediaPlayCtrl.h" #include "MediaFilePanel.h" -#include "Plater.hpp" #include "BindDialog.hpp" #include "DeviceCore/DevManager.h" diff --git a/src/slic3r/GUI/Monitor.hpp b/src/slic3r/GUI/Monitor.hpp index ce7fcf0570..613a1f1ac7 100644 --- a/src/slic3r/GUI/Monitor.hpp +++ b/src/slic3r/GUI/Monitor.hpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -31,14 +30,12 @@ #include #include #include -#include #include #include #include #include #include #include -#include #include #include #include diff --git a/src/slic3r/GUI/NetworkTestDialog.cpp b/src/slic3r/GUI/NetworkTestDialog.cpp index caff68b39e..54c0f11cf0 100644 --- a/src/slic3r/GUI/NetworkTestDialog.cpp +++ b/src/slic3r/GUI/NetworkTestDialog.cpp @@ -4,7 +4,6 @@ #include "libslic3r/Utils.hpp" #include "GUI.hpp" #include "GUI_App.hpp" -#include "I18N.hpp" #include "libslic3r_version.h" #include "slic3r/Utils/Http.hpp" #include "libslic3r/AppConfig.hpp" diff --git a/src/slic3r/GUI/PresetBundleDialog.cpp b/src/slic3r/GUI/PresetBundleDialog.cpp index c067d99c28..3c97d94525 100644 --- a/src/slic3r/GUI/PresetBundleDialog.cpp +++ b/src/slic3r/GUI/PresetBundleDialog.cpp @@ -30,7 +30,6 @@ #include "MainFrame.hpp" #include #include -#include #include using json = nlohmann::json; diff --git a/src/slic3r/GUI/PrintHostDialogs.cpp b/src/slic3r/GUI/PrintHostDialogs.cpp index 2e8047cf72..fbb803859c 100644 --- a/src/slic3r/GUI/PrintHostDialogs.cpp +++ b/src/slic3r/GUI/PrintHostDialogs.cpp @@ -79,7 +79,6 @@ #include "libslic3r_version.h" #include "wxExtensions.hpp" -#include #include "libslic3r/Preset.hpp" #include "libslic3r/PresetBundle.hpp" #include "slic3r/GUI/Widgets/Button.hpp" diff --git a/src/slic3r/GUI/ProgressStatusBar.hpp b/src/slic3r/GUI/ProgressStatusBar.hpp index 79343d51df..069d2131f1 100644 --- a/src/slic3r/GUI/ProgressStatusBar.hpp +++ b/src/slic3r/GUI/ProgressStatusBar.hpp @@ -4,7 +4,6 @@ #include #include #include -#include #include "Jobs/ProgressIndicator.hpp" diff --git a/src/slic3r/GUI/ReleaseNote.hpp b/src/slic3r/GUI/ReleaseNote.hpp index 1234d59c60..fbb01ac0ee 100644 --- a/src/slic3r/GUI/ReleaseNote.hpp +++ b/src/slic3r/GUI/ReleaseNote.hpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -32,10 +31,8 @@ #include #include #include -#include #include #include -#include #include #include "AmsMappingPopup.hpp" diff --git a/src/slic3r/GUI/SelectMachine.hpp b/src/slic3r/GUI/SelectMachine.hpp index 31ce752a2e..30ca78130c 100644 --- a/src/slic3r/GUI/SelectMachine.hpp +++ b/src/slic3r/GUI/SelectMachine.hpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -38,7 +37,6 @@ #include #include #include -#include #include #include diff --git a/src/slic3r/GUI/SelectMachinePop.hpp b/src/slic3r/GUI/SelectMachinePop.hpp index 37dcd98ac4..bfbed88867 100644 --- a/src/slic3r/GUI/SelectMachinePop.hpp +++ b/src/slic3r/GUI/SelectMachinePop.hpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -29,7 +28,6 @@ #include #include #include -#include #include #include diff --git a/src/slic3r/GUI/SendToPrinter.hpp b/src/slic3r/GUI/SendToPrinter.hpp index fad825713b..4c1e2cf935 100644 --- a/src/slic3r/GUI/SendToPrinter.hpp +++ b/src/slic3r/GUI/SendToPrinter.hpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -33,7 +32,6 @@ #include #include #include -#include #include #include diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 5e5761c6fe..4b94d84543 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1,4 +1,3 @@ -// #include "libslic3r/GCodeSender.hpp" //#include "slic3r/Utils/Serial.hpp" #include "Tab.hpp" #include "PresetHints.hpp" @@ -102,8 +101,6 @@ #include "Widgets/MultiNozzleSync.hpp" #include "Widgets/SwitchButton.hpp" #include "Widgets/TabCtrl.hpp" -#include "Widgets/ComboBox.hpp" -#include "Search.hpp" #include "BedShapeDialog.hpp" #include "libslic3r/GCode/Thumbnails.hpp" #include "WipeTowerDialog.hpp" diff --git a/src/slic3r/Utils/CalibUtils.cpp b/src/slic3r/Utils/CalibUtils.cpp index 2a4ca8c05a..c1fda01b42 100644 --- a/src/slic3r/Utils/CalibUtils.cpp +++ b/src/slic3r/Utils/CalibUtils.cpp @@ -20,8 +20,6 @@ #include "../GUI/DeviceCore/DevConfig.h" #include "../GUI/DeviceCore/DevExtruderSystem.h" #include "../GUI/DeviceCore/DevManager.h" -#include "../GUI/DeviceCore/DevStorage.h" -#include "libslic3r/FlushVolCalc.hpp" #include "../GUI/Plater.hpp" #include #include "slic3r/GUI/Jobs/Worker.hpp" diff --git a/src/slic3r/Utils/EmbossStyleManager.cpp b/src/slic3r/Utils/EmbossStyleManager.cpp index d873b40cf3..61daab2f77 100644 --- a/src/slic3r/Utils/EmbossStyleManager.cpp +++ b/src/slic3r/Utils/EmbossStyleManager.cpp @@ -365,7 +365,6 @@ void StyleManager::init_trunc_names(float max_width) { #include "slic3r/GUI/Plater.hpp" // for get DPI -#include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/MainFrame.hpp" #include "slic3r/GUI/Gizmos/GizmoObjectManipulation.hpp" @@ -554,8 +553,6 @@ bool StyleManager::set_wx_font(const wxFont &wx_font, std::unique_ptr return true; } -#include -#include "WxFontUtils.hpp" #include "fast_float/fast_float.h" // StylesSerializable diff --git a/src/slic3r/Utils/PresetUpdater.cpp b/src/slic3r/Utils/PresetUpdater.cpp index 344a5f881c..6e498fb718 100644 --- a/src/slic3r/Utils/PresetUpdater.cpp +++ b/src/slic3r/Utils/PresetUpdater.cpp @@ -48,7 +48,6 @@ #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/I18N.hpp" #include "slic3r/GUI/UpdateDialogs.hpp" -#include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/Plater.hpp" #include "slic3r/GUI/format.hpp" #include "slic3r/GUI/NotificationManager.hpp" diff --git a/tests/libslic3r/test_preset_bundle_loading.cpp b/tests/libslic3r/test_preset_bundle_loading.cpp index a116a9021f..e1ae29b473 100644 --- a/tests/libslic3r/test_preset_bundle_loading.cpp +++ b/tests/libslic3r/test_preset_bundle_loading.cpp @@ -24,7 +24,6 @@ #include "test_utils.hpp" -#include #include #include #include From 3fc515f48d63b3b3d051ed9185452561b44a847f Mon Sep 17 00:00:00 2001 From: HanifKoh <76276251+HanifKoh@users.noreply.github.com> Date: Thu, 8 Oct 2026 13:52:09 +0800 Subject: [PATCH 3/6] Prompt for Permission When a Plugin Calls os.exec (#16254) * Prompt for Permission When a Plugin Calls os.exec * Add a ProcessReplace Audit Category for os.exec --- src/slic3r/plugin/PluginAuditManager.cpp | 7 +++++++ src/slic3r/plugin/PluginAuditManager.hpp | 1 + 2 files changed, 8 insertions(+) diff --git a/src/slic3r/plugin/PluginAuditManager.cpp b/src/slic3r/plugin/PluginAuditManager.cpp index 1fe8837c5c..f3bd6c1636 100644 --- a/src/slic3r/plugin/PluginAuditManager.cpp +++ b/src/slic3r/plugin/PluginAuditManager.cpp @@ -115,6 +115,9 @@ static const std::unordered_map audit_event_cat {"subprocess.Popen", AuditEventCategory::ProcessCreate}, {"_winapi.CreateProcess", AuditEventCategory::ProcessCreate}, {"_posixsubprocess.fork_exec", AuditEventCategory::ProcessCreate}, + + // processreplace: exec* replaces the current process image rather than spawning a child + {"os.exec", AuditEventCategory::ProcessReplace}, }; // Returns the category event_name belongs to, or AuditEventCategory::None when it isn't audited. @@ -708,6 +711,7 @@ static const std::unordered_map> audit_targ {"pty.spawn", {0}}, {"_winapi.CreateProcess", {1, 0}}, {"_posixsubprocess.fork_exec", {0}}, + {"os.exec", {0}}, }; AuditEventCategory open_category(PyObject* args) @@ -761,6 +765,7 @@ std::vector* permission_list_for(AuditEventCategory category, Plugi case AuditEventCategory::Http: return &permissions.network_http; case AuditEventCategory::Socket: return &permissions.network_socket; case AuditEventCategory::ProcessCreate: return &permissions.process; + case AuditEventCategory::ProcessReplace: return &permissions.process; default: return nullptr; } } @@ -832,6 +837,8 @@ wxString audit_message(AuditEventCategory category, const wxString& plugin_name, return wxString::Format(_L("Plugin \"%s\" is requesting to open a network connection to:\n%s"), plugin_name, target_list); case AuditEventCategory::ProcessCreate: return wxString::Format(_L("Plugin \"%s\" is requesting to run the following command(s):\n%s"), plugin_name, target_list); + case AuditEventCategory::ProcessReplace: + return wxString::Format(_L("Plugin \"%s\" is requesting to replace the running application with:\n%s"), plugin_name, target_list); default: return wxString::Format(_L("Plugin \"%s\" is requesting permission for the Python audit event \"%s\"."), plugin_name, event_name); } diff --git a/src/slic3r/plugin/PluginAuditManager.hpp b/src/slic3r/plugin/PluginAuditManager.hpp index 76ac5cdd18..49866d2fa9 100644 --- a/src/slic3r/plugin/PluginAuditManager.hpp +++ b/src/slic3r/plugin/PluginAuditManager.hpp @@ -45,6 +45,7 @@ enum class AuditEventCategory { Http, Socket, ProcessCreate, + ProcessReplace, Threading, }; From 30902561c05001466977714b9991539faafc1235 Mon Sep 17 00:00:00 2001 From: HanifKoh <76276251+HanifKoh@users.noreply.github.com> Date: Thu, 8 Oct 2026 13:59:12 +0800 Subject: [PATCH 4/6] Stop Exporting Names Through Usings in the Remaining Headers (#16250) The last headers with a using or namespace alias at namespace scope: - TCPConsole.hpp imported boost::asio::ip::tcp into Slic3r::Utils for two member declarations. The alias is now a private member of the class. - WebSocketClient.hpp declared four namespace aliases and a tcp alias at global scope, each used only by the header. The names are spelled out. - Repair.hpp aliased CGAL::Polygon_mesh_processing as PMP in Slic3r::tex2color. The three functions that use it declare the alias themselves. - PreciseSeam.hpp, Thumbnails.hpp and MarchingSquares.hpp used a using-declaration or directive for one or two spots each; those spots are qualified. Thumbnails.hpp's "PNG"sv default argument becomes "PNG", which converts to the std::string_view parameter the same way. - tests/sla_print/sla_test_utils.hpp had "using namespace Slic3r;" and tests/filament_group/fg_test_serialization.hpp "using json = nlohmann::json;" at global scope. The headers qualify their own names; the two SLA test sources get the directive themselves. Also removed: twelve type aliases in headers that nothing references (ConflictObjName, CircleSqf, CircleSqd, TRawBuffer, DistanceFunction, SamePair, ExtruderNozzleInfos, Vec2dEvent, Vec2dsEvent, Vec3dEvent, t_option, t_optgroups, Plater::fs_path) and a duplicate fn_ft_job_msg_destroy alias in FileTransferUtils.hpp. --- src/libslic3r/GCode/ConflictChecker.hpp | 2 - src/libslic3r/GCode/PreciseSeam.hpp | 5 +- src/libslic3r/GCode/Thumbnails.hpp | 3 +- src/libslic3r/Geometry/Circle.hpp | 2 - src/libslic3r/MarchingSquares.hpp | 7 +- src/libslic3r/SLA/AGGRaster.hpp | 1 - src/libslic3r/TextureToColor/ColorUtils.hpp | 3 - src/libslic3r/TextureToColor/Repair.hpp | 5 +- src/libslic3r/libslic3r.h | 2 - src/slic3r/GUI/DeviceCore/DevDefs.h | 3 - src/slic3r/GUI/GLCanvas3D.hpp | 3 - src/slic3r/GUI/OptionsGroup.hpp | 1 - src/slic3r/GUI/Plater.hpp | 2 - src/slic3r/Utils/FileTransferUtils.hpp | 1 - src/slic3r/Utils/TCPConsole.hpp | 4 +- src/slic3r/Utils/WebSocketClient.hpp | 27 ++-- .../filament_group/fg_test_serialization.hpp | 118 +++++++++--------- tests/sla_print/sla_print_tests.cpp | 2 + tests/sla_print/sla_test_utils.cpp | 2 + tests/sla_print/sla_test_utils.hpp | 74 ++++++----- 20 files changed, 119 insertions(+), 148 deletions(-) diff --git a/src/libslic3r/GCode/ConflictChecker.hpp b/src/libslic3r/GCode/ConflictChecker.hpp index fb1e02ec3f..85fabec585 100644 --- a/src/libslic3r/GCode/ConflictChecker.hpp +++ b/src/libslic3r/GCode/ConflictChecker.hpp @@ -148,8 +148,6 @@ struct ConflictComputeResult using ConflictComputeOpt = std::optional; -using ConflictObjName = std::optional>; - struct ConflictChecker { static ConflictResultOpt find_inter_of_lines_in_diff_objs(PrintObjectPtrs objs, std::optional wtdptr); diff --git a/src/libslic3r/GCode/PreciseSeam.hpp b/src/libslic3r/GCode/PreciseSeam.hpp index bbb4d98532..f9e1b1ddf3 100644 --- a/src/libslic3r/GCode/PreciseSeam.hpp +++ b/src/libslic3r/GCode/PreciseSeam.hpp @@ -22,9 +22,6 @@ namespace Slic3r { namespace PreciseSeam { -// Import EnforcedBlockedSeamPoint from SeamPlacerImpl namespace for convenience -using SeamPlacerImpl::EnforcedBlockedSeamPoint; - // Geometry and its exterior bounds are prepared together, then treated as read-only. struct ModifierRegion { ExPolygon polygon; @@ -137,7 +134,7 @@ SegmentExtraction extract_perimeter_segments(const PreparedPerimeter &prepared, // Result of weak modifier segment processing struct WeakModifierSegment { - EnforcedBlockedSeamPoint type; // Enforced/Blocked/Neutral + SeamPlacerImpl::EnforcedBlockedSeamPoint type; // Enforced/Blocked/Neutral Point left_point; // Coordinates of left (first) point of segment PerimeterPosition left_position; // Position on the source perimeter before insertion/refinement. Point right_point; // Coordinates of right (last) point of segment diff --git a/src/libslic3r/GCode/Thumbnails.hpp b/src/libslic3r/GCode/Thumbnails.hpp index a5fd598519..bbe8039d80 100644 --- a/src/libslic3r/GCode/Thumbnails.hpp +++ b/src/libslic3r/GCode/Thumbnails.hpp @@ -40,8 +40,7 @@ std::string get_error_string(const ThumbnailErrors& errors); typedef std::vector> GCodeThumbnailDefinitionsList; -using namespace std::literals; -std::pair make_and_check_thumbnail_list(const std::string& thumbnails_string, const std::string_view def_ext = "PNG"sv); +std::pair make_and_check_thumbnail_list(const std::string& thumbnails_string, const std::string_view def_ext = "PNG"); std::pair make_and_check_thumbnail_list(const ConfigBase &config); diff --git a/src/libslic3r/Geometry/Circle.hpp b/src/libslic3r/Geometry/Circle.hpp index 8f8655df65..aee93efa83 100644 --- a/src/libslic3r/Geometry/Circle.hpp +++ b/src/libslic3r/Geometry/Circle.hpp @@ -94,8 +94,6 @@ struct Circle { using Circlef = Circle; using Circled = Circle; -using CircleSqf = CircleSq; -using CircleSqd = CircleSq; /// Find the center of the circle corresponding to the vector of Points as an arc. Point circle_center_taubin_newton(const Points::const_iterator& input_start, const Points::const_iterator& input_end, size_t cycles = 20); diff --git a/src/libslic3r/MarchingSquares.hpp b/src/libslic3r/MarchingSquares.hpp index e123dd14e0..73b8f9bd23 100644 --- a/src/libslic3r/MarchingSquares.hpp +++ b/src/libslic3r/MarchingSquares.hpp @@ -154,13 +154,12 @@ template struct _Loop }; // Add Specialization for using ExecutionTBB for parallel loops. -using namespace Slic3r; -template<> struct _Loop +template<> struct _Loop { template static void for_each_idx(It from, It to, Fn&& fn) { - execution::for_each( - ex_tbb, size_t(0), size_t(to - from), [&from, &fn](size_t i) { fn(from[i], i); }, execution::max_concurrency(ex_tbb)); + Slic3r::execution::for_each( + Slic3r::ex_tbb, size_t(0), size_t(to - from), [&from, &fn](size_t i) { fn(from[i], i); }, Slic3r::execution::max_concurrency(Slic3r::ex_tbb)); } }; diff --git a/src/libslic3r/SLA/AGGRaster.hpp b/src/libslic3r/SLA/AGGRaster.hpp index 52c95eae5b..4651454dde 100644 --- a/src/libslic3r/SLA/AGGRaster.hpp +++ b/src/libslic3r/SLA/AGGRaster.hpp @@ -49,7 +49,6 @@ public: using TColor = typename PixelRenderer::color_type; using TValue = typename TColor::value_type; using TPixel = typename PixelRenderer::pixel_type; - using TRawBuffer = agg::rendering_buffer; protected: diff --git a/src/libslic3r/TextureToColor/ColorUtils.hpp b/src/libslic3r/TextureToColor/ColorUtils.hpp index e9b1be3623..efea0ecb36 100644 --- a/src/libslic3r/TextureToColor/ColorUtils.hpp +++ b/src/libslic3r/TextureToColor/ColorUtils.hpp @@ -17,9 +17,6 @@ typedef std::vector ColorList; typedef std::array ColorDouble; typedef std::array RGB; -// Function pointer type that points to a specific color-difference function based on the chosen method. -using DistanceFunction = double (*)(const Color&, const Color&); - // Color space used for computing color differences. enum struct ColorDifferenceMethod : std::size_t { RGB = 0, // Simplest and fastest diff --git a/src/libslic3r/TextureToColor/Repair.hpp b/src/libslic3r/TextureToColor/Repair.hpp index 25ef9cc7ac..93f21b6222 100644 --- a/src/libslic3r/TextureToColor/Repair.hpp +++ b/src/libslic3r/TextureToColor/Repair.hpp @@ -24,8 +24,6 @@ namespace Slic3r { namespace tex2color { -namespace PMP = CGAL::Polygon_mesh_processing; - // Default upper bound on the number of half-edges in any single boundary cycle // that CloseBoundariesAndRepairManifoldness will attempt to triangulate. The // cost of triangulate_hole grows non-linearly with cycle length, so this caps @@ -61,6 +59,7 @@ struct BoundaryEdgeStats // any pre-processing (e.g. stitch_borders) needed for the count to be meaningful. inline BoundaryEdgeStats ComputeBoundaryEdgeStats(const cgalutils::CGALMesh& cgal_mesh) { + namespace PMP = CGAL::Polygon_mesh_processing; using CGALMesh = cgalutils::CGALMesh; using HalfedgeDescriptor = boost::graph_traits::halfedge_descriptor; @@ -87,6 +86,7 @@ inline BoundaryEdgeStats ComputeBoundaryEdgeStats(const cgalutils::CGALMesh& cga // boundary statistics; entering this function always triggers triangulation. inline void CloseBoundariesAndRepairManifoldness(cgalutils::CGALMesh& cgal_mesh) { + namespace PMP = CGAL::Polygon_mesh_processing; using CGALMesh = cgalutils::CGALMesh; using HalfedgeDescriptor = boost::graph_traits::halfedge_descriptor; using FaceDescriptor = boost::graph_traits::face_descriptor; @@ -112,6 +112,7 @@ inline bool RepairMesh(const TriMesh& mesh, AlgoCancelCallback cancel_callback = nullptr, const RepairSetting& setting = RepairSetting{}) { + namespace PMP = CGAL::Polygon_mesh_processing; using Clock = std::chrono::steady_clock; auto elapsed_ms = [](Clock::time_point t0) { return std::chrono::duration_cast(Clock::now() - t0).count(); diff --git a/src/libslic3r/libslic3r.h b/src/libslic3r/libslic3r.h index d3b0faa57f..b0a5250532 100644 --- a/src/libslic3r/libslic3r.h +++ b/src/libslic3r/libslic3r.h @@ -432,8 +432,6 @@ inline IntegerOnly fast_round_up(double a) return a == 0.49999999999999994 ? I(0) : I(floor(a + 0.5)); } -template using SamePair = std::pair; - } // namespace Slic3r #endif diff --git a/src/slic3r/GUI/DeviceCore/DevDefs.h b/src/slic3r/GUI/DeviceCore/DevDefs.h index 6332d6b109..aa12482849 100644 --- a/src/slic3r/GUI/DeviceCore/DevDefs.h +++ b/src/slic3r/GUI/DeviceCore/DevDefs.h @@ -198,6 +198,3 @@ template<> struct std::hash return h1 ^ (h2 + 0x9e3779b9 + (h1 << 6) + (h1 >> 2)); }; }; - -// key(extruder_id) -> { key1(nozzle type info), val1( number of the nozzle type)} -using ExtruderNozzleInfos = std::unordered_map>; \ No newline at end of file diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index faf826ed7c..23fdfbb66d 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -183,13 +183,10 @@ wxDECLARE_EVENT(EVT_GLCANVAS_PLATE_NAME_CHANGE, SimpleEvent); //BBS: declare EVT_GLCANVAS_PLATE_SELECT wxDECLARE_EVENT(EVT_GLCANVAS_PLATE_SELECT, SimpleEvent); -using Vec2dEvent = Event; // _bool_ value is used as a indicator of selection in the 3DScene using RBtnEvent = Event>; using RBtnPlateEvent = Event>; -template using Vec2dsEvent = ArrayEvent; -using Vec3dEvent = Event; template using Vec3dsEvent = ArrayEvent; using HeightProfileSmoothEvent = Event; diff --git a/src/slic3r/GUI/OptionsGroup.hpp b/src/slic3r/GUI/OptionsGroup.hpp index 63ebee7176..0943922925 100644 --- a/src/slic3r/GUI/OptionsGroup.hpp +++ b/src/slic3r/GUI/OptionsGroup.hpp @@ -54,7 +54,6 @@ struct Option { Option(const ConfigOptionDef& _opt, t_config_option_key id) : opt(_opt), opt_id(id) {} }; -using t_option = std::unique_ptr