diff --git a/src/libslic3r/GCode/ToolOrdering.cpp b/src/libslic3r/GCode/ToolOrdering.cpp index f0b5a53c0..348cc649e 100644 --- a/src/libslic3r/GCode/ToolOrdering.cpp +++ b/src/libslic3r/GCode/ToolOrdering.cpp @@ -288,6 +288,7 @@ static double calc_max_layer_height(const PrintConfig &config, double max_object ToolOrdering::ToolOrdering(const PrintObject &object, unsigned int first_extruder, bool prime_multi_material) { m_print_object_ptr = &object; + m_print = const_cast(object.print()); if (object.layers().empty()) return; @@ -969,14 +970,9 @@ float get_flush_volume(const std::vector &filament_maps, const std::vector< return flush_volume; } -std::vector ToolOrdering::get_recommended_filament_maps() +std::vector ToolOrdering::get_recommended_filament_maps(const std::vector>& layer_filaments, const PrintConfig *print_config) { - const PrintConfig *print_config = m_print_config_ptr; - if (!print_config && m_print_object_ptr) { - print_config = &(m_print_object_ptr->print()->config()); - } - - if (!print_config || m_layer_tools.empty()) + if (!print_config || layer_filaments.empty()) return std::vector(); const unsigned int number_of_extruders = (unsigned int) (print_config->filament_colour.values.size() + EPSILON); @@ -1014,15 +1010,11 @@ std::vector ToolOrdering::get_recommended_filament_maps() return false; }; - - std::vectorused_filaments; - std::vector>layer_filaments; - for (auto& lt : m_layer_tools) { - layer_filaments.emplace_back(lt.extruders); - for (auto& extruder : lt.extruders) { - if (std::find(used_filaments.begin(), used_filaments.end(), extruder) == used_filaments.end()) - used_filaments.emplace_back(extruder); + for (auto& one_layer_filaments : layer_filaments) { + for (unsigned int filament : one_layer_filaments) { + if (std::find(used_filaments.begin(), used_filaments.end(), filament) == used_filaments.end()) + used_filaments.emplace_back(filament); } } std::sort(used_filaments.begin(), used_filaments.end()); @@ -1044,146 +1036,6 @@ std::vector ToolOrdering::get_recommended_filament_maps() return ret; } -// for print by object -std::vector ToolOrdering::get_recommended_filament_maps(const std::vector> all_layer_filaments, const PrintConfig *print_config) -{ - //if (!print_config && m_print_object_ptr) { print_config = &(m_print_object_ptr->print()->config()); } - - if (!print_config || all_layer_filaments.empty()) - return std::vector(); - - const unsigned int number_of_extruders = (unsigned int) (print_config->filament_colour.values.size() + EPSILON); - - // get flush matrix - std::vector nozzle_flush_mtx; - size_t nozzle_nums = print_config->nozzle_diameter.values.size(); - for (size_t nozzle_id = 0; nozzle_id < nozzle_nums; ++nozzle_id) { - std::vector flush_matrix(cast(get_flush_volumes_matrix(print_config->flush_volumes_matrix.values, nozzle_id, nozzle_nums))); - std::vector> wipe_volumes; - for (unsigned int i = 0; i < number_of_extruders; ++i) - wipe_volumes.push_back(std::vector(flush_matrix.begin() + i * number_of_extruders, flush_matrix.begin() + (i + 1) * number_of_extruders)); - - nozzle_flush_mtx.emplace_back(wipe_volumes); - } - - auto extruders_to_hash_key = [](const std::vector &extruders, std::optional initial_extruder_id) -> uint32_t { - uint32_t hash_key = 0; - // high 16 bit define initial extruder ,low 16 bit define extruder set - if (initial_extruder_id) hash_key |= (1 << (16 + *initial_extruder_id)); - for (auto item : extruders) hash_key |= (1 << item); - return hash_key; - }; - - std::vector other_layers_seqs; - const ConfigOptionInts * other_layers_print_sequence_op = print_config->option("other_layers_print_sequence"); - const ConfigOptionInt * other_layers_print_sequence_nums_op = print_config->option("other_layers_print_sequence_nums"); - if (other_layers_print_sequence_op && other_layers_print_sequence_nums_op) { - const std::vector &print_sequence = other_layers_print_sequence_op->values; - int sequence_nums = other_layers_print_sequence_nums_op->value; - other_layers_seqs = get_other_layers_print_sequence(sequence_nums, print_sequence); - } - - // other_layers_seq: the layer_idx and extruder_idx are base on 1 - auto get_custom_seq = [&other_layers_seqs](int layer_idx, std::vector &out_seq) -> bool { - for (size_t idx = other_layers_seqs.size() - 1; idx != size_t(-1); --idx) { - const auto &other_layers_seq = other_layers_seqs[idx]; - if (layer_idx + 1 >= other_layers_seq.first.first && layer_idx + 1 <= other_layers_seq.first.second) { - out_seq = other_layers_seq.second; - return true; - } - } - return false; - }; - - std::set filaments; - for (int i = 0; i < all_layer_filaments.size(); ++i) { - for (unsigned int filament : all_layer_filaments[i]) - filaments.insert(filament); - } - - auto extruder_group = generate_combinations(std::vector(filaments.begin(), filaments.end())); - - std::vector recommended_filament_maps; - float min_flush_volume = std::numeric_limits::max(); - for (auto iter = extruder_group.begin(); iter != extruder_group.end(); ++iter) { - std::vector filament_maps; - filament_maps.resize(number_of_extruders); - for (unsigned int e : iter->first) { - filament_maps[e] = 0; - } - for (unsigned int e : iter->second) { - filament_maps[e] = 1; - } - - std::optional current_extruder_id; - std::vector> nozzle_to_cur_filaments; - nozzle_to_cur_filaments.resize(nozzle_nums); - - float flush_volume_cost = 0; - for (int i = 0; i < all_layer_filaments.size(); ++i) { - std::vector layer_filaments = all_layer_filaments[i]; - if (layer_filaments.empty()) - continue; - - std::vector custom_extruder_seq; - if (get_custom_seq(i, custom_extruder_seq) && !custom_extruder_seq.empty()) { - std::vector unsign_custom_extruder_seq; - for (int extruder : custom_extruder_seq) { - unsigned int unsign_extruder = static_cast(extruder) - 1; - auto it = std::find(layer_filaments.begin(), layer_filaments.end(), unsign_extruder); - if (it != layer_filaments.end()) { - unsign_custom_extruder_seq.emplace_back(unsign_extruder); - nozzle_to_cur_filaments[filament_maps[unsign_extruder]] = unsign_extruder; - } - } - - layer_filaments = unsign_custom_extruder_seq; - current_extruder_id = layer_filaments.back(); - flush_volume_cost += get_flush_volume(filament_maps, layer_filaments, nozzle_flush_mtx, nozzle_nums); - continue; - } - - // The algorithm complexity is O(n2*2^n) - if (i != 0) { - std::vector> nozzle_filaments; - nozzle_filaments.resize(nozzle_nums); - - for (unsigned int filament_id : layer_filaments) - { - nozzle_filaments[filament_maps[filament_id]].emplace_back(filament_id); - } - - for (size_t nozzle_id = 0; nozzle_id < nozzle_nums; ++nozzle_id) { - float f_cost = 0; - nozzle_filaments[nozzle_id] = get_extruders_order(nozzle_flush_mtx[nozzle_id], nozzle_filaments[nozzle_id], nozzle_to_cur_filaments[nozzle_id], &f_cost); - std::vector hash_val; - hash_val.reserve(nozzle_filaments[nozzle_id].size()); - for (auto item : nozzle_filaments[nozzle_id]) hash_val.emplace_back(static_cast(item)); - flush_volume_cost += f_cost; - nozzle_to_cur_filaments[nozzle_id] = nozzle_filaments[nozzle_id].back(); - } - - //layer_filaments.clear(); - //for (size_t nozzle_id = 0; nozzle_id < nozzle_nums; ++nozzle_id) { - // layer_filaments.insert(layer_filaments.end(), nozzle_filaments[nozzle_id].begin(), nozzle_filaments[nozzle_id].end()); - //} - } - current_extruder_id = layer_filaments.back(); - } - - if (flush_volume_cost == 0) { - recommended_filament_maps = filament_maps; - break; - } - - if (flush_volume_cost < min_flush_volume) { - min_flush_volume = flush_volume_cost; - recommended_filament_maps = filament_maps; - } - } - return recommended_filament_maps; -} - void ToolOrdering::reorder_extruders_for_minimum_flush_volume() { const PrintConfig *print_config = m_print_config_ptr; @@ -1207,12 +1059,23 @@ void ToolOrdering::reorder_extruders_for_minimum_flush_volume() nozzle_flush_mtx.emplace_back(wipe_volumes); } - + std::vectorfilament_maps(number_of_extruders, 0); if (nozzle_nums > 1) { filament_maps = m_print->get_filament_maps(); - if (print_config->print_sequence != PrintSequence::ByObject) { - filament_maps = get_recommended_filament_maps(); + if (print_config->print_sequence != PrintSequence::ByObject && m_print->objects().size() == 1) { + const PrintConfig *print_config = m_print_config_ptr; + if (!print_config && m_print_object_ptr) { + print_config = &(m_print_object_ptr->print()->config()); + } + + std::vector> layer_filaments; + for (auto& lt : m_layer_tools) { + layer_filaments.emplace_back(lt.extruders); + } + + filament_maps = ToolOrdering::get_recommended_filament_maps(layer_filaments, print_config); + if (filament_maps.empty()) return; std::transform(filament_maps.begin(), filament_maps.end(), filament_maps.begin(), [](int value) { return value + 1; }); diff --git a/src/libslic3r/GCode/ToolOrdering.hpp b/src/libslic3r/GCode/ToolOrdering.hpp index 4b0b05edc..e512444e3 100644 --- a/src/libslic3r/GCode/ToolOrdering.hpp +++ b/src/libslic3r/GCode/ToolOrdering.hpp @@ -197,7 +197,7 @@ public: std::vector& layer_tools() { return m_layer_tools; } bool has_wipe_tower() const { return ! m_layer_tools.empty() && m_first_printing_extruder != (unsigned int)-1 && m_layer_tools.front().has_wipe_tower; } - static std::vector get_recommended_filament_maps(const std::vector> all_layer_filaments, const PrintConfig *print_config); + static std::vector get_recommended_filament_maps(const std::vector>& layer_filaments, const PrintConfig *print_config); private: void initialize_layers(std::vector &zs); @@ -208,7 +208,7 @@ private: void fill_wipe_tower_partitions(const PrintConfig &config, coordf_t object_bottom_z, coordf_t max_layer_height); void mark_skirt_layers(const PrintConfig &config, coordf_t max_layer_height); void collect_extruder_statistics(bool prime_multi_material); - std::vector get_recommended_filament_maps(); + //std::vector get_recommended_filament_maps(); void reorder_extruders_for_minimum_flush_volume(); // BBS diff --git a/src/libslic3r/PresetBundle.hpp b/src/libslic3r/PresetBundle.hpp index be8f469a2..bcb17c132 100644 --- a/src/libslic3r/PresetBundle.hpp +++ b/src/libslic3r/PresetBundle.hpp @@ -126,8 +126,7 @@ public: std::map filament_ams_list; std::vector> ams_multi_color_filment; - // todo multi_extruders: delete mutable - mutable std::vector extruder_filament_counts; + std::vector extruder_filament_counts; // Calibrate Preset const * calibrate_printer = nullptr; std::set calibrate_filaments; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 963adb490..7a2544ac6 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -10073,7 +10073,6 @@ void Plater::calib_flowrate(int pass) Flow infill_flow = Flow(nozzle_diameter * 1.2f, layer_height, nozzle_diameter); double filament_max_volumetric_speed = filament_config->option("filament_max_volumetric_speed")->get_at(0); double max_infill_speed = filament_max_volumetric_speed / (infill_flow.mm3_per_mm() * (pass == 1 ? 1.2 : 1)); - // todo multi_extruder: double internal_solid_speed = std::floor(std::min(print_config->opt_float("internal_solid_infill_speed", 0), max_infill_speed)); double top_surface_speed = std::floor(std::min(print_config->opt_float("top_surface_speed", 0), max_infill_speed)); diff --git a/src/slic3r/Utils/CalibUtils.cpp b/src/slic3r/Utils/CalibUtils.cpp index 3d3a7238c..8867e3337 100644 --- a/src/slic3r/Utils/CalibUtils.cpp +++ b/src/slic3r/Utils/CalibUtils.cpp @@ -557,7 +557,6 @@ bool CalibUtils::calib_flowrate(int pass, const CalibInfo &calib_info, wxString Flow infill_flow = Flow(nozzle_diameter * 1.2f, layer_height, nozzle_diameter); double filament_max_volumetric_speed = filament_config.option("filament_max_volumetric_speed")->get_at(0); double max_infill_speed = filament_max_volumetric_speed / (infill_flow.mm3_per_mm() * (pass == 1 ? 1.2 : 1)); - // todo multi_extruders: double internal_solid_speed = std::floor(std::min(print_config.opt_float("internal_solid_infill_speed", calib_info.extruder_id), max_infill_speed)); double top_surface_speed = std::floor(std::min(print_config.opt_float("top_surface_speed", calib_info.extruder_id), max_infill_speed)); @@ -1304,6 +1303,9 @@ void CalibUtils::send_to_print(const CalibInfo &calib_info, wxString &error_mess print_job->task_ams_mapping_info = ""; print_job->task_use_ams = select_ams == "[254]" ? false : true; + std::string new_ams_mapping = "[{\"ams_id\":" + std::to_string(calib_info.ams_id) + ", \"slot_id\":" + std::to_string(calib_info.slot_id) + "}]"; + print_job->task_ams_mapping2 = new_ams_mapping; + CalibMode cali_mode = calib_info.params.mode; print_job->m_project_name = get_calib_mode_name(cali_mode, flow_ratio_mode); print_job->set_calibration_task(true);