diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index 149ff5d61..bba7b331f 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -170,10 +170,12 @@ void AppConfig::set_defaults() if (get("reverse_mouse_wheel_zoom").empty()) set_bool("reverse_mouse_wheel_zoom", false); #endif - if (get("enable_append_color_by_sync_ams").empty()) + if (get("enable_append_color_by_sync_ams").empty()) set_bool("enable_append_color_by_sync_ams", false); if (get("enable_merge_color_by_sync_ams").empty()) set_bool("enable_merge_color_by_sync_ams", true); + if (get("ams_sync_match_full_use_color_dist").empty()) + set_bool("ams_sync_match_full_use_color_dist", false); if (get("zoom_to_mouse").empty()) set_bool("zoom_to_mouse", false); diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index 5f1d7db8c..6bd6ef1e9 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -966,17 +966,17 @@ void MachineObject::parse_tray_info(int ams_id, int slot_id, AmsTray tray, Filam } -int MachineObject::ams_filament_mapping(std::vector filaments, std::vector &result, std::vector map_opt, std::vector exclude_id) +int MachineObject::ams_filament_mapping( + std::vector filaments, std::vector &result, std::vector map_opt, std::vector exclude_id, bool nozzle_has_ams_then_ignore_ext) { if (filaments.empty()) return -1; // tray_index : tray_color std::map tray_filaments; - + bool left_nozzle_has_ams = false, right_nozzle_has_ams = false; for (auto ams = amsList.begin(); ams != amsList.end(); ams++) { std::string ams_id = ams->second->id; - FilamentInfo info; for (auto tray = ams->second->trayList.begin(); tray != ams->second->trayList.end(); tray++) { int ams_id = atoi(ams->first.c_str()); int tray_id = atoi(tray->first.c_str()); @@ -987,19 +987,38 @@ int MachineObject::ams_filament_mapping(std::vector filaments, std continue; } // push + FilamentInfo info; if (tray->second->is_tray_info_ready()) parse_tray_info(ams_id, tray_id, *(tray->second), info); //first: left,nozzle=1,map=1 second: right,nozzle=0,map=2 - if ((ams->second->nozzle == 0 && map_opt[MappingOption::USE_RIGHT_AMS]) || (ams->second->nozzle == 1 && map_opt[MappingOption::USE_LEFT_AMS])) + bool right_ams_valid = ams->second->nozzle == 0 && map_opt[MappingOption::USE_RIGHT_AMS]; + bool left_ams_valid = ams->second->nozzle == 1 && map_opt[MappingOption::USE_LEFT_AMS]; + if (right_ams_valid || left_ams_valid) { tray_filaments.emplace(std::make_pair(tray_index, info)); + if (right_ams_valid) { + right_nozzle_has_ams = true; + } + if (left_ams_valid) { + left_nozzle_has_ams = true; + } + } } } if (map_opt[MappingOption::USE_RIGHT_EXT] || map_opt[MappingOption::USE_LEFT_EXT]){ for (auto tray : vt_slot){ - if ((tray.id == std::to_string(VIRTUAL_TRAY_MAIN_ID) && map_opt[MappingOption::USE_RIGHT_EXT]) - || (tray.id == std::to_string(VIRTUAL_TRAY_DEPUTY_ID) && map_opt[MappingOption::USE_LEFT_EXT])){ + bool right_ext_valid = (tray.id == std::to_string(VIRTUAL_TRAY_MAIN_ID) && map_opt[MappingOption::USE_RIGHT_EXT]); + bool left_ext_valid = (tray.id == std::to_string(VIRTUAL_TRAY_DEPUTY_ID) && map_opt[MappingOption::USE_LEFT_EXT]); + if (right_ext_valid || left_ext_valid) { + if (nozzle_has_ams_then_ignore_ext) { + if (right_ext_valid && right_nozzle_has_ams) { + continue; + } + if (left_ext_valid && left_nozzle_has_ams) { + continue; + } + } FilamentInfo info; parse_tray_info(atoi(tray.id.c_str()), 0, tray, info); tray_filaments.emplace(std::make_pair(info.tray_id, info)); diff --git a/src/slic3r/GUI/DeviceManager.hpp b/src/slic3r/GUI/DeviceManager.hpp index 1435a0998..8b8216c7c 100644 --- a/src/slic3r/GUI/DeviceManager.hpp +++ b/src/slic3r/GUI/DeviceManager.hpp @@ -714,7 +714,7 @@ public: void get_ams_colors(std::vector& ams_colors); void parse_tray_info(int ams_id, int sot_id, AmsTray tray, FilamentInfo& result); - int ams_filament_mapping(std::vector filaments, std::vector &result, std::vector map_opt, std::vector exclude_id = std::vector()); + int ams_filament_mapping(std::vector filaments, std::vector &result, std::vector map_opt, std::vector exclude_id = std::vector(),bool nozzle_has_ams_then_ignore_ext =false); bool is_valid_mapping_result(std::vector& result, bool check_empty_slot = false); // exceed index start with 0 bool is_mapping_exceed_filament(std::vector& result, int &exceed_index); diff --git a/src/slic3r/GUI/SyncAmsInfoDialog.cpp b/src/slic3r/GUI/SyncAmsInfoDialog.cpp index 45932dece..181f46684 100644 --- a/src/slic3r/GUI/SyncAmsInfoDialog.cpp +++ b/src/slic3r/GUI/SyncAmsInfoDialog.cpp @@ -1585,66 +1585,16 @@ bool SyncAmsInfoDialog::do_ams_mapping(MachineObject *obj_) int filament_result = 0; std::vector map_opt; // four values: use_left_ams, use_right_ams, use_left_ext, use_right_ext if (nozzle_nums > 1) { - // get nozzle property, the extders are same? - if (false) { - std::vector m_ams_mapping_result_left, m_ams_mapping_result_right; - std::vector m_filament_left, m_filament_right; - for (auto it = m_filaments.begin(); it != m_filaments.end(); it++) { - if (it->id < 0 || it->id > m_filaments_map.size()) { - BOOST_LOG_TRIVIAL(info) << "error: do_ams_mapping: m_filaments[].it" << it->id; - BOOST_LOG_TRIVIAL(info) << "m_filaments_map.size()" << m_filaments_map.size(); - return false; - } - if (m_filaments_map[it->id] == 1) - m_filament_left.push_back(*it); - else if (m_filaments_map[it->id] == 2) - m_filament_right.push_back(*it); - } - - bool has_left_ams = false, has_right_ams = false; - for (auto ams_item : obj_->amsList) { - if (ams_item.second->nozzle == 0) { - if (obj_->is_main_extruder_on_left()) - has_left_ams = true; - else - has_right_ams = true; - } else if (ams_item.second->nozzle == 1) { - if (obj_->is_main_extruder_on_left()) - has_right_ams = true; - else - has_left_ams = true; - } - - if (has_left_ams && has_right_ams) break; - } - - map_opt = {true, false, !has_left_ams, false}; // four values: use_left_ams, use_right_ams, use_left_ext, use_right_ext - int result_first = obj_->ams_filament_mapping(m_filament_left, m_ams_mapping_result_left, map_opt); - map_opt = {false, true, false, !has_right_ams}; - int result_second = obj_->ams_filament_mapping(m_filament_right, m_ams_mapping_result_right, map_opt); - - // m_ams_mapping_result.clear(); - m_ams_mapping_result.resize(m_ams_mapping_result_left.size() + m_ams_mapping_result_right.size()); - std::merge(m_ams_mapping_result_left.begin(), m_ams_mapping_result_left.end(), m_ams_mapping_result_right.begin(), m_ams_mapping_result_right.end(), - m_ams_mapping_result.begin(), [](const FilamentInfo &f1, const FilamentInfo &f2) { - return f1.id < f2.id; // Merge based on age - }); - filament_result = (result_first && result_second); - } - // can hybrid mapping - else { - map_opt = {true, true, true, true}; // four values: use_left_ams, use_right_ams, use_left_ext, use_right_ext - filament_result = obj_->ams_filament_mapping(m_filaments, m_ams_mapping_result, map_opt); - } - // When filaments cannot be matched automatically, whether to use ext for automatic supply - // auto_supply_with_ext(obj_->vt_slot); + map_opt = {true, true, true, true}; // four values: use_left_ams, use_right_ams, use_left_ext, use_right_ext + filament_result = obj_->ams_filament_mapping(m_filaments, m_ams_mapping_result, map_opt, std::vector(), + wxGetApp().app_config->get_bool("ams_sync_match_full_use_color_dist") ? false : true); } - // single nozzle else { if (obj_->is_support_amx_ext_mix_mapping()) { map_opt = {false, true, false, true}; // four values: use_left_ams, use_right_ams, use_left_ext, use_right_ext - filament_result = obj_->ams_filament_mapping(m_filaments, m_ams_mapping_result, map_opt); + filament_result = obj_->ams_filament_mapping(m_filaments, m_ams_mapping_result, map_opt, std::vector(), + wxGetApp().app_config->get_bool("ams_sync_match_full_use_color_dist") ? false : true); // auto_supply_with_ext(obj_->vt_slot); } else { map_opt = {false, true, false, false};