From 7c80b3178ddfdfc621ac4f784ab0ec9ca4845852 Mon Sep 17 00:00:00 2001 From: supermerill Date: Mon, 5 Oct 2020 12:58:28 +0200 Subject: [PATCH] #495 Add bounding_box to placeholders --- src/libslic3r/GCode.cpp | 44 +++++++++++++++++++---------------- src/libslic3r/PrintConfig.cpp | 3 ++- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index b709934bb..1b84b2463 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1322,40 +1322,42 @@ void GCode::_do_export(Print &print, FILE *file) _write_format(file, "; first layer extrusion width = %.2fmm\n", region->flow(frPerimeter, first_layer_height, false, true, -1., *first_object).width); _write_format(file, "\n"); } - if (this->config().gcode_label_objects) { - BoundingBoxf3 global_bounding_box; - for (PrintObject *print_object : print.objects()) { - this->m_ordered_objects.push_back(print_object); - unsigned int copy_id = 0; - for (const PrintInstance &print_instance : print_object->instances()) { - std::string object_name = print_object->model_object()->name; - size_t pos_dot = object_name.find(".", 0); - if (pos_dot != std::string::npos && pos_dot > 0) - object_name = object_name.substr(0, pos_dot); - //get bounding box for the instance - BoundingBoxf3 raw_bbox = print_object->model_object()->raw_mesh_bounding_box(); - BoundingBoxf3 m_bounding_box = print_instance.model_instance->transform_bounding_box(raw_bbox); - if (global_bounding_box.size().norm() == 0) { - global_bounding_box = m_bounding_box; - } else { - global_bounding_box.merge(m_bounding_box); - } + BoundingBoxf3 global_bounding_box; + for (PrintObject *print_object : print.objects()) { + this->m_ordered_objects.push_back(print_object); + unsigned int copy_id = 0; + for (const PrintInstance &print_instance : print_object->instances()) { + std::string object_name = print_object->model_object()->name; + size_t pos_dot = object_name.find(".", 0); + if (pos_dot != std::string::npos && pos_dot > 0) + object_name = object_name.substr(0, pos_dot); + //get bounding box for the instance + BoundingBoxf3 raw_bbox = print_object->model_object()->raw_mesh_bounding_box(); + BoundingBoxf3 m_bounding_box = print_instance.model_instance->transform_bounding_box(raw_bbox); + if (global_bounding_box.size().norm() == 0) { + global_bounding_box = m_bounding_box; + } else { + global_bounding_box.merge(m_bounding_box); + } + if (this->config().gcode_label_objects) { _write_format(file, "; object:{\"name\":\"%s\",\"id\":\"%s id:%d copy %d\",\"object_center\":[%f,%f,%f],\"boundingbox_center\":[%f,%f,%f],\"boundingbox_size\":[%f,%f,%f]}\n", object_name.c_str(), print_object->model_object()->name.c_str(), this->m_ordered_objects.size() - 1, copy_id, m_bounding_box.center().x(), m_bounding_box.center().y(), 0., m_bounding_box.center().x(), m_bounding_box.center().y(), m_bounding_box.center().z(), m_bounding_box.size().x(), m_bounding_box.size().y(), m_bounding_box.size().z() ); - copy_id++; } + copy_id++; } + } + if (this->config().gcode_label_objects) { _write_format(file, "; plater:{\"center\":[%f,%f,%f],\"boundingbox_center\":[%f,%f,%f],\"boundingbox_size\":[%f,%f,%f]}\n", global_bounding_box.center().x(), global_bounding_box.center().y(), 0., global_bounding_box.center().x(), global_bounding_box.center().y(), global_bounding_box.center().z(), global_bounding_box.size().x(), global_bounding_box.size().y(), global_bounding_box.size().z() ); - _write_format(file, "\n"); } + _write_format(file, "\n"); print.throw_if_canceled(); @@ -1465,6 +1467,8 @@ void GCode::_do_export(Print &print, FILE *file) m_placeholder_parser.set("has_wipe_tower", has_wipe_tower); m_placeholder_parser.set("has_single_extruder_multi_material_priming", has_wipe_tower && print.config().single_extruder_multi_material_priming); m_placeholder_parser.set("total_toolchanges", std::max(0, print.wipe_tower_data().number_of_toolchanges)); // Check for negative toolchanges (single extruder mode) and set to 0 (no tool change). + m_placeholder_parser.set("bounding_box", new ConfigOptionFloats({ global_bounding_box.min.x(), global_bounding_box.min.y(), global_bounding_box.max.x(), global_bounding_box.max.y() })); + std::string start_gcode = this->placeholder_parser_process("start_gcode", print.config().start_gcode.value, initial_extruder_id); // Set bed temperature if the start G-code does not contain any bed temp control G-codes. diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 7cbf6f039..4a3bdf665 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -2991,7 +2991,8 @@ void PrintConfigDef::init_fff_params() "such commands will not be prepended automatically so you're free to customize " "the order of heating commands and other custom actions. Note that you can use " "placeholder variables for all Slic3r settings, so you can put " - "a \"M109 S[first_layer_temperature]\" command wherever you want."); + "a \"M109 S[first_layer_temperature]\" command wherever you want." + "\n placeholders: initial_extruder, total_layer_count, has_wipe_tower, has_single_extruder_multi_material_priming, total_toolchanges, bounding_box[minx,miny,maxx,maxy]"); def->multiline = true; def->full_width = true; def->height = 12;