From 99cb8884216b537683f683c77fa3a4c6c5974381 Mon Sep 17 00:00:00 2001 From: "songwei.li" Date: Tue, 15 Jul 2025 10:41:15 +0800 Subject: [PATCH] NEW: Add temperature-hold flag to machine_start_gcode Description:By calculating the total area of the first layer (object, support, wipe tower), the flag is true when the area is greater than 200 and the height is less than 0.3 mm. machine_start_code placeholder: "hold_chamber_temp_for_flat_print" jira: STUDIO-13370 Change-Id: If5982da28afb57e9bbb8a0a1ba69bc45f5cc1c7c (cherry picked from commit eb942df30e6779acbdf1d330cae5c6ebe0010abf) (cherry picked from commit 47a242ecd639cc630f70d9b6cf4d1fd91fd511d4) (cherry picked from commit 87f4741d9caaf33699d647a2ce5b4f60d535f7b1) --- src/libslic3r/GCode.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 5e8e5e5774..91b747853e 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -2785,6 +2785,46 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato this->placeholder_parser().set("scan_first_layer", new ConfigOptionBool(false)); } } + { // hold chamber temp for flat print: Flag + double print_area_sum_threshold = 40000.0, pring_hight_threshold = 0.3; // thresholds in mm^2 and mm as units + + double area_sum_temp = 0.0; + coordf_t max_hight_temp = -1.0; + for (ObjectID print_object_ID_t : print.print_object_ids()) { + const PrintObject *print_object = print.get_object(print_object_ID_t); + // object hight + if (!print_object->layers().empty() && print_object->layers().back()->print_z > max_hight_temp) max_hight_temp = print_object->layers().back()->print_z; + // object area + if (!print_object->layers().empty() && print_object->layers().front()->print_z < print.config().initial_layer_print_height + EPSILON && + !print_object->layers().front()->lslices.empty()) { + ExPolygons temp_Expolys = print_object->layers().front()->lslices; + for (ExPolygon &temp_Expoly : temp_Expolys) { area_sum_temp += temp_Expoly.area(); } + } + // suport area + if (!print_object->support_layers().empty() && print_object->support_layers().front()->print_z < print.config().initial_layer_print_height + EPSILON && + !print_object->support_layers().front()->support_islands.empty()) { + ExPolygons temp_Expolys = print_object->support_layers().front()->support_islands; + for (ExPolygon &temp_Expoly : temp_Expolys) { area_sum_temp += temp_Expoly.area(); } + } + // brim area + if (print.m_brimMap.find(print_object_ID_t) != print.m_brimMap.end() && !print.m_brimMap.at(print_object_ID_t).entities.empty()) { // contain brim + for (const ExtrusionEntity *entities_temp : print.m_brimMap.at(print_object_ID_t).entities) { + Polygons temp_Expolys; + entities_temp->polygons_covered_by_spacing(temp_Expolys, 0.0f); + for (Polygon &temp_Expoly : temp_Expolys) { area_sum_temp += temp_Expoly.area(); } + } + } + } + // wipe tower area + if (has_wipe_tower) { + Polygon temp_Expoly = print.wipe_tower_data().wipe_tower_mesh_data->bottom; + area_sum_temp += temp_Expoly.area(); + } + bool hold_chamber_temp_for_flat_print = max_hight_temp > 0 && max_hight_temp < pring_hight_threshold && area_sum_temp > print_area_sum_threshold * 1.0e10; + this->placeholder_parser().set("hold_chamber_temp_for_flat_print", new ConfigOptionBool(hold_chamber_temp_for_flat_print)); + } + + std::string machine_start_gcode = this->placeholder_parser_process("machine_start_gcode", print.config().machine_start_gcode.value, initial_extruder_id); if (print.config().gcode_flavor != gcfKlipper) { // Set bed temperature if the start G-code does not contain any bed temp control G-codes.