From 00dfb8f69cb1dc565b53f6a21be2d28f9fb9b8b9 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 22 Oct 2021 13:15:42 +0200 Subject: [PATCH] Make sure that we have the lower_layer_edge_grid when placing seams --- src/libslic3r/GCode.cpp | 49 ++++++++++++++++++++++---------------- src/slic3r/GUI/GUI_App.cpp | 1 + 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 97599ca071..8f8d8dbe0b 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -2479,31 +2479,36 @@ std::string GCode::change_layer(coordf_t print_z) +static std::unique_ptr calculate_layer_edge_grid(const Layer& layer) +{ + auto out = make_unique(); + + // Create the distance field for a layer below. + const coord_t distance_field_resolution = coord_t(scale_(1.) + 0.5); + out->create(layer.lslices, distance_field_resolution); + out->calculate_sdf(); +#if 0 + { + static int iRun = 0; + BoundingBox bbox = (*lower_layer_edge_grid)->bbox(); + bbox.min(0) -= scale_(5.f); + bbox.min(1) -= scale_(5.f); + bbox.max(0) += scale_(5.f); + bbox.max(1) += scale_(5.f); + EdgeGrid::save_png(*(*lower_layer_edge_grid), bbox, scale_(0.1f), debug_out_path("GCode_extrude_loop_edge_grid-%d.png", iRun++)); + } +#endif + return out; +} + + std::string GCode::extrude_loop(ExtrusionLoop loop, std::string description, double speed, std::unique_ptr *lower_layer_edge_grid) { // get a copy; don't modify the orientation of the original loop object otherwise // next copies (if any) would not detect the correct orientation - if (m_layer->lower_layer != nullptr && lower_layer_edge_grid != nullptr) { - if (! *lower_layer_edge_grid) { - // Create the distance field for a layer below. - const coord_t distance_field_resolution = coord_t(scale_(1.) + 0.5); - *lower_layer_edge_grid = make_unique(); - (*lower_layer_edge_grid)->create(m_layer->lower_layer->lslices, distance_field_resolution); - (*lower_layer_edge_grid)->calculate_sdf(); - #if 0 - { - static int iRun = 0; - BoundingBox bbox = (*lower_layer_edge_grid)->bbox(); - bbox.min(0) -= scale_(5.f); - bbox.min(1) -= scale_(5.f); - bbox.max(0) += scale_(5.f); - bbox.max(1) += scale_(5.f); - EdgeGrid::save_png(*(*lower_layer_edge_grid), bbox, scale_(0.1f), debug_out_path("GCode_extrude_loop_edge_grid-%d.png", iRun++)); - } - #endif - } - } + if (m_layer->lower_layer && lower_layer_edge_grid != nullptr && ! *lower_layer_edge_grid) + *lower_layer_edge_grid = calculate_layer_edge_grid(*m_layer->lower_layer); // extrude all loops ccw bool was_clockwise = loop.make_counter_clockwise(); @@ -2640,6 +2645,10 @@ std::string GCode::extrude_perimeters(const Print &print, const std::vectorlower_layer && ! lower_layer_edge_grid) + lower_layer_edge_grid = calculate_layer_edge_grid(*m_layer->lower_layer); + m_seam_placer.plan_perimeters(std::vector(region.perimeters.begin(), region.perimeters.end()), *m_layer, m_config.seam_position, this->last_pos(), EXTRUDER_CONFIG(nozzle_diameter), (m_layer == NULL ? nullptr : m_layer->object()), diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 7d6940bd0d..349f179309 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -673,6 +673,7 @@ void GUI_App::post_init() // to popup a modal dialog on start without screwing combo boxes. // This is ugly but I honestly found no better way to do it. // Neither wxShowEvent nor wxWindowCreateEvent work reliably. + assert(this->preset_updater); // FIXME Following condition is probably not neccessary. if (this->preset_updater) { this->check_updates(false); CallAfter([this] {