From 3cbb2f7524836189a52895ea5c487af00f3dc464 Mon Sep 17 00:00:00 2001 From: supermerill Date: Tue, 12 Feb 2019 19:11:02 +0100 Subject: [PATCH] Octoprint-Cancelobject : more reliable (i think) and add header for object bounding box. --- src/libslic3r/GCode.cpp | 26 +++++++++++++++++++++++--- src/libslic3r/GCode.hpp | 3 +++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index e1e428096..e843d34c9 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -704,6 +704,23 @@ 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) { + for (PrintObject *print_object : print.objects()) { + this->m_ordered_objects.push_back(print_object); + unsigned int copy_id = 0; + for (const Point &pos : print_object->copies()) { + _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]}", + print_object->model_object()->name.substr(0, print_object->model_object()->name.find(".", 0)), print_object->model_object()->name, this->m_ordered_objects.size() - 1, copy_id, + print_object->model_object()->bounding_box().center().x(), print_object->model_object()->bounding_box().center().y(), 0, + print_object->model_object()->bounding_box().center().x(), print_object->model_object()->bounding_box().center().y(), print_object->model_object()->bounding_box().center().z(), + print_object->model_object()->bounding_box().size().x(), print_object->model_object()->bounding_box().size().y(), print_object->model_object()->bounding_box().size().z() + ); + copy_id++; + } + } + _write_format(file, "\n"); + } + print.throw_if_canceled(); // adds tags for time estimators @@ -948,7 +965,6 @@ void GCode::_do_export(Print &print, FILE *file) m_wipe_tower.reset(new WipeTowerIntegration(print.config(), *print.wipe_tower_data().priming.get(), print.wipe_tower_data().tool_changes, *print.wipe_tower_data().final_purge.get())); _write(file, m_writer.travel_to_z(first_layer_height + m_config.z_offset.value, "Move to the first layer height")); if (print.config().single_extruder_multi_material_priming) { - //m_wipe_tower->next_layer(); _write(file, m_wipe_tower->prime(*this)); // Verify, whether the print overaps the priming extrusions. BoundingBoxf bbox_print(get_print_extrusions_extents(print)); @@ -1629,7 +1645,9 @@ void GCode::process_layer( unsigned int copy_id = 0; for (const Point © : copies) { if (this->config().gcode_label_objects) - gcode += std::string("; printing object ") + print_object->model_object()->name + " id:" + std::to_string(layer_id) + " copy " + std::to_string(copy_id) + "\n"; + gcode += std::string("; printing object ") + print_object->model_object()->name + + " id:" + std::to_string(std::find(this->m_ordered_objects.begin(), this->m_ordered_objects.end(), print_object) - this->m_ordered_objects.begin()) + + " copy " + std::to_string(copy_id) + "\n"; // When starting a new object, use the external motion planner for the first travel move. std::pair this_object_copy(print_object, copy); if (m_last_obj_copy != this_object_copy) @@ -1651,7 +1669,9 @@ void GCode::process_layer( gcode += this->extrude_infill(print, by_region_specific, false); } if (this->config().gcode_label_objects) - gcode += std::string("; stop printing object ") + print_object->model_object()->name + " id:" + std::to_string(layer_id) + " copy " + std::to_string(copy_id) + "\n"; + gcode += std::string("; stop printing object ") + print_object->model_object()->name + + " id:" + std::to_string((std::find(this->m_ordered_objects.begin(), this->m_ordered_objects.end(), print_object) - this->m_ordered_objects.begin())) + + " copy " + std::to_string(copy_id) + "\n"; ++ copy_id; } } diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index 48604af37..1bd112de5 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -326,6 +326,9 @@ protected: // so no toolchange occurs twice. std::vector m_colorprint_heights; + // ordered list of object, to give them a unique id. + std::vector m_ordered_objects; + // Time estimators GCodeTimeEstimator m_normal_time_estimator; GCodeTimeEstimator m_silent_time_estimator;