From 9775bf213d38a09e62294a451fda32a8316beea5 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 17 Mar 2023 13:49:35 +0100 Subject: [PATCH 1/3] Wipe tower: changed the way how initial wipe tower preview depth is calculated --- src/libslic3r/GCode/WipeTower.cpp | 25 +++++++++++++++++++++++++ src/libslic3r/GCode/WipeTower.hpp | 2 +- src/libslic3r/Print.cpp | 25 +++++++++++++++---------- src/slic3r/GUI/3DScene.cpp | 2 -- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index 7fdbb6915..1ac645c93 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -1346,6 +1346,31 @@ std::pair WipeTower::get_wipe_tower_cone_base(double width, doub return std::make_pair(R, support_scale); } +// Static method to extract wipe_volumes[from][to] from the configuration. +std::vector> WipeTower::extract_wipe_volumes(const PrintConfig& config) +{ + // Get wiping matrix to get number of extruders and convert vector to vector: + std::vector wiping_matrix(cast(config.wiping_volumes_matrix.values)); + + // Extract purging volumes for each extruder pair: + std::vector> wipe_volumes; + const unsigned int number_of_extruders = (unsigned int)(sqrt(wiping_matrix.size())+EPSILON); + for (unsigned int i = 0; i(wiping_matrix.begin()+i*number_of_extruders, wiping_matrix.begin()+(i+1)*number_of_extruders)); + + // Also include filament_minimal_purge_on_wipe_tower. This is needed for the preview. + for (unsigned int i = 0; i get_wipe_tower_cone_base(double width, double height, double depth, double angle_deg); + static std::vector> extract_wipe_volumes(const PrintConfig& config); struct Extrusion { diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index f16dadc8c..b93fef1ff 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -1337,11 +1337,22 @@ const WipeTowerData& Print::wipe_tower_data(size_t extruders_cnt) const { // If the wipe tower wasn't created yet, make sure the depth and brim_width members are set to default. if (! is_step_done(psWipeTower) && extruders_cnt !=0) { + const_cast(this)->m_wipe_tower_data.brim_width = m_config.wipe_tower_brim_width; + + // Calculating depth should take into account currently set wiping volumes. + // For a long time, the initial preview would just use 900/width per toolchange (15mm on a 60mm wide tower) + // and it worked well enough. Let's try to do slightly better by accounting for the purging volumes. + std::vector> wipe_volumes = WipeTower::extract_wipe_volumes(m_config); + std::vector max_wipe_volumes; + for (const std::vector& v : wipe_volumes) + max_wipe_volumes.emplace_back(*std::max_element(v.begin(), v.end())); + float maximum = std::accumulate(max_wipe_volumes.begin(), max_wipe_volumes.end(), 0.f); + maximum = maximum * extruders_cnt / max_wipe_volumes.size(); float width = float(m_config.wipe_tower_width); + float layer_height = 0.2f; // just assume fixed value, it will still be better than before. - const_cast(this)->m_wipe_tower_data.depth = (900.f/width) * float(extruders_cnt - 1); - const_cast(this)->m_wipe_tower_data.brim_width = m_config.wipe_tower_brim_width; + const_cast(this)->m_wipe_tower_data.depth = (maximum/layer_height)/width; } return m_wipe_tower_data; @@ -1353,13 +1364,7 @@ void Print::_make_wipe_tower() if (! this->has_wipe_tower()) return; - // Get wiping matrix to get number of extruders and convert vector to vector: - std::vector wiping_matrix(cast(m_config.wiping_volumes_matrix.values)); - // Extract purging volumes for each extruder pair: - std::vector> wipe_volumes; - const unsigned int number_of_extruders = (unsigned int)(sqrt(wiping_matrix.size())+EPSILON); - for (unsigned int i = 0; i(wiping_matrix.begin()+i*number_of_extruders, wiping_matrix.begin()+(i+1)*number_of_extruders)); + std::vector> wipe_volumes = WipeTower::extract_wipe_volumes(m_config); // Let the ToolOrdering class know there will be initial priming extrusions at the start of the print. m_wipe_tower_data.tool_ordering = ToolOrdering(*this, (unsigned int)-1, true); @@ -1412,7 +1417,7 @@ void Print::_make_wipe_tower() //wipe_tower.set_zhop(); // Set the extruder & material properties at the wipe tower object. - for (size_t i = 0; i < number_of_extruders; ++ i) + for (size_t i = 0; i < m_config.nozzle_diameter.size(); ++ i) wipe_tower.set_extruder(i, m_config); m_wipe_tower_data.priming = Slic3r::make_unique>( diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index e8a80bf78..97975404f 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -488,8 +488,6 @@ int GLVolumeCollection::load_wipe_tower_preview( float rotation_angle, bool size_unknown, float brim_width) #endif // ENABLE_OPENGL_ES { - if (depth < 0.01f) - return int(this->volumes.size() - 1); if (height == 0.0f) height = 0.1f; From b14855beda3d1cde60a744f9290bb771ab1042b4 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Thu, 30 Mar 2023 12:41:57 +0200 Subject: [PATCH 2/3] Wipe tower: remove 'Purging volumes' button for printers with separate extruders: the setting really only makes sense for single extruder MM, the others can use filament_minimal_purge_on_wipe_tower --- src/libslic3r/GCode/WipeTower.cpp | 5 +++++ src/slic3r/GUI/Tab.cpp | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index 1ac645c93..54c6199ec 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -1352,6 +1352,11 @@ std::vector> WipeTower::extract_wipe_volumes(const PrintConfi // Get wiping matrix to get number of extruders and convert vector to vector: std::vector wiping_matrix(cast(config.wiping_volumes_matrix.values)); + // The values shall only be used when SEMM is enabled. The purging for other printers + // is determined by filament_minimal_purge_on_wipe_tower. + if (! config.single_extruder_multi_material.value) + std::fill(wiping_matrix.begin(), wiping_matrix.end(), 0.f); + // Extract purging volumes for each extruder pair: std::vector> wipe_volumes; const unsigned int number_of_extruders = (unsigned int)(sqrt(wiping_matrix.size())+EPSILON); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index d31f48913..dd138530d 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1122,10 +1122,11 @@ void Tab::update_wiping_button_visibility() { return; // ys_FIXME bool wipe_tower_enabled = dynamic_cast( (m_preset_bundle->prints.get_edited_preset().config ).option("wipe_tower"))->value; bool multiple_extruders = dynamic_cast((m_preset_bundle->printers.get_edited_preset().config).option("nozzle_diameter"))->values.size() > 1; + bool single_extruder_multi_material = dynamic_cast((m_preset_bundle->printers.get_edited_preset().config).option("single_extruder_multi_material"))->value; auto wiping_dialog_button = wxGetApp().sidebar().get_wiping_dialog_button(); if (wiping_dialog_button) { - wiping_dialog_button->Show(wipe_tower_enabled && multiple_extruders); + wiping_dialog_button->Show(wipe_tower_enabled && multiple_extruders && single_extruder_multi_material); wiping_dialog_button->GetParent()->Layout(); } } From 3d855580cea4ad50d98b2cbe364a390258ea1f15 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Thu, 30 Mar 2023 14:06:23 +0200 Subject: [PATCH 3/3] Wipe tower: fix the height of preview in 3D scene --- src/libslic3r/Print.cpp | 1 + src/slic3r/GUI/GLCanvas3D.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index b93fef1ff..14e77e03f 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -1353,6 +1353,7 @@ const WipeTowerData& Print::wipe_tower_data(size_t extruders_cnt) const float layer_height = 0.2f; // just assume fixed value, it will still be better than before. const_cast(this)->m_wipe_tower_data.depth = (maximum/layer_height)/width; + const_cast(this)->m_wipe_tower_data.height = -1.f; // unknown yet } return m_wipe_tower_data; diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index c169ddfbc..fbdb46d9f 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2133,8 +2133,6 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re const bool co = dynamic_cast(m_config->option("complete_objects"))->value; if (extruders_count > 1 && wt && !co) { - // Height of a print (Show at least a slab) - const double height = std::max(m_model->max_z(), 10.0); const float x = dynamic_cast(m_config->option("wipe_tower_x"))->value; const float y = dynamic_cast(m_config->option("wipe_tower_y"))->value; @@ -2145,6 +2143,10 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re const Print *print = m_process->fff_print(); const float depth = print->wipe_tower_data(extruders_count).depth; + const float height_real = print->wipe_tower_data(extruders_count).height; // -1.f = unknown + + // Height of a print (Show at least a slab). + const double height = height_real < 0.f ? std::max(m_model->max_z(), 10.0) : height_real; #if ENABLE_OPENGL_ES int volume_idx_wipe_tower_new = m_volumes.load_wipe_tower_preview(