diff --git a/src/BambuStudio.cpp b/src/BambuStudio.cpp index 9d265da7c..8dc20c0cf 100644 --- a/src/BambuStudio.cpp +++ b/src/BambuStudio.cpp @@ -5592,8 +5592,8 @@ int CLI::run(int argc, char **argv) if (m_extra_config.option>("filament_map_mode")) mode = m_extra_config.option>("filament_map_mode")->value; else - mode = part_plate->get_filament_map_mode(); - if (mode == FilamentMapMode::fmmAuto) { + mode = part_plate->get_real_filament_map_mode(m_print_config); + if (mode < FilamentMapMode::fmmManual) { part_plate->set_unprintable_filament_ids(unprintable_filament_vec); std::vector conflict_filament_vector; for (int index = 0; index < new_extruder_count; index++) @@ -5631,7 +5631,7 @@ int CLI::run(int argc, char **argv) if (m_extra_config.option("filament_map")) filament_maps = m_extra_config.option("filament_map")->values; else - filament_maps = part_plate->get_filament_maps(); + filament_maps = part_plate->get_real_filament_maps(m_print_config); for (int index = 0; index < filament_maps.size(); index++) { int filament_extruder = filament_maps[index]; @@ -5657,11 +5657,11 @@ int CLI::run(int argc, char **argv) new_print_config.apply(*part_plate->config()); new_print_config.apply(m_extra_config, true); if (new_extruder_count > 1) { - FilamentMapMode map_mode = fmmAuto; + FilamentMapMode map_mode = fmmAutoForFlush; if (new_print_config.option>("filament_map_mode")) map_mode = new_print_config.option>("filament_map_mode")->value; - if (map_mode == fmmAuto) { + if (map_mode < fmmManual) { //set default params for auto map std::vector extruder_ams_count(new_extruder_count, ""); std::vector> extruder_filament_info(new_extruder_count, std::vector()); diff --git a/src/libslic3r/Format/bbs_3mf.cpp b/src/libslic3r/Format/bbs_3mf.cpp index fa404187b..0b2ce65c4 100644 --- a/src/libslic3r/Format/bbs_3mf.cpp +++ b/src/libslic3r/Format/bbs_3mf.cpp @@ -4166,9 +4166,12 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result) } else if (key == FILAMENT_MAP_MODE_ATTR) { - FilamentMapMode map_mode = FilamentMapMode::fmmAuto; - ConfigOptionEnum::from_string(value, map_mode); - m_curr_plater->config.set_key_value("filament_map_mode", new ConfigOptionEnum(map_mode)); + FilamentMapMode map_mode = FilamentMapMode::fmmAutoForFlush; + // handle old versions, only load manual params + if (value != "Auto") { + ConfigOptionEnum::from_string(value, map_mode); + m_curr_plater->config.set_key_value("filament_map_mode", new ConfigOptionEnum(map_mode)); + } } else if (key == FILAMENT_MAP_ATTR) { if (m_curr_plater) @@ -7585,7 +7588,8 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result) stream << " <" << METADATA_TAG << " " << KEY_ATTR << "=\"" << FILAMENT_MAP_MODE_ATTR << "\" " << VALUE_ATTR << "=\"" << filament_map_mode_names[filament_map_mode_opt->getInt()] << "\"/>\n"; ConfigOptionInts* filament_maps_opt = plate_data->config.option("filament_map"); - if (filament_maps_opt != nullptr) { + // filament map override global settings only when group mode overrides the global settings + if (filament_map_mode_opt !=nullptr && filament_maps_opt != nullptr) { stream << " <" << METADATA_TAG << " " << KEY_ATTR << "=\"" << FILAMENT_MAP_ATTR << "\" " << VALUE_ATTR << "=\""; const std::vector& values = filament_maps_opt->values; for (int i = 0; i < values.size(); ++i) { diff --git a/src/libslic3r/GCode/ToolOrdering.cpp b/src/libslic3r/GCode/ToolOrdering.cpp index a50e56d89..5951f5a9e 100644 --- a/src/libslic3r/GCode/ToolOrdering.cpp +++ b/src/libslic3r/GCode/ToolOrdering.cpp @@ -1167,7 +1167,7 @@ void ToolOrdering::reorder_extruders_for_minimum_flush_volume(bool reorder_first } std::vectorfilament_maps(number_of_extruders, 0); - FilamentMapMode map_mode = FilamentMapMode::fmmAuto; + FilamentMapMode map_mode = FilamentMapMode::fmmAutoForFlush; std::vector> layer_filaments; for (auto& lt : m_layer_tools) { @@ -1183,7 +1183,7 @@ void ToolOrdering::reorder_extruders_for_minimum_flush_volume(bool reorder_first map_mode = m_print->get_filament_map_mode(); // only check and map in sequence mode, in by object mode, we check the map in print.cpp if (print_config->print_sequence != PrintSequence::ByObject || m_print->objects().size() == 1) { - if (map_mode == FilamentMapMode::fmmAuto) { + if (map_mode < FilamentMapMode::fmmManual) { const PrintConfig* print_config = m_print_config_ptr; if (!print_config && m_print_object_ptr) { print_config = &(m_print_object_ptr->print()->config()); @@ -1258,7 +1258,7 @@ void ToolOrdering::reorder_extruders_for_minimum_flush_volume(bool reorder_first auto curr_flush_info = calc_filament_change_info_by_toolorder(print_config, filament_maps, nozzle_flush_mtx, filament_sequences); if (nozzle_nums <= 1) m_stats_by_single_extruder = curr_flush_info; - else if (map_mode == fmmAuto) + else if (map_mode < fmmManual) m_stats_by_multi_extruder_auto = curr_flush_info; else if (map_mode == fmmManual) m_stats_by_multi_extruder_manual = curr_flush_info; diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index ef7e7b190..21afc6347 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -41,7 +41,9 @@ static std::vector s_project_options { "wipe_tower_rotation_angle", "curr_bed_type", "flush_multiplier", - "nozzle_volume_type" + "nozzle_volume_type", + "filament_map_mode", + "filament_map" }; //BBS: add BBL as default @@ -1756,7 +1758,9 @@ void PresetBundle::set_num_filaments(unsigned int n, std::string new_color) } ConfigOptionStrings* filament_color = project_config.option("filament_colour"); + ConfigOptionInts* filament_map = project_config.option("filament_map"); filament_color->resize(n); + filament_map->values.resize(n, 1); ams_multi_color_filment.resize(n); //BBS set new filament color to new_color @@ -1778,11 +1782,15 @@ void PresetBundle::update_num_filaments(unsigned int to_del_flament_id) filament_presets.erase(filament_presets.begin() + to_del_flament_id); ConfigOptionStrings *filament_color = project_config.option("filament_colour"); + ConfigOptionInts* filament_map = project_config.option("filament_map"); + if (filament_color->values.size() > to_del_flament_id) { filament_color->values.erase(filament_color->values.begin() + to_del_flament_id); + filament_map->values.erase(filament_map->values.begin() + to_del_flament_id); } else { filament_color->values.resize(to_del_flament_id); + filament_map->values.resize(to_del_flament_id, 1); } if (ams_multi_color_filment.size() > to_del_flament_id){ @@ -2090,14 +2098,14 @@ bool PresetBundle::support_different_extruders() return supported; } -DynamicPrintConfig PresetBundle::full_config(bool apply_extruder, std::vector filament_maps) const +DynamicPrintConfig PresetBundle::full_config(bool apply_extruder, std::optional>filament_maps) const { return (this->printers.get_edited_preset().printer_technology() == ptFFF) ? this->full_fff_config(apply_extruder, filament_maps) : this->full_sla_config(); } -DynamicPrintConfig PresetBundle::full_config_secure(std::vector filament_maps) const +DynamicPrintConfig PresetBundle::full_config_secure(std::optional>filament_maps) const { DynamicPrintConfig config = this->full_fff_config(false, filament_maps); //BBS example: config.erase("print_host"); @@ -2115,7 +2123,7 @@ const std::set ignore_settings_list ={ "print_settings_id", "filament_settings_id", "printer_settings_id" }; -DynamicPrintConfig PresetBundle::full_fff_config(bool apply_extruder, std::vector filament_maps) const +DynamicPrintConfig PresetBundle::full_fff_config(bool apply_extruder, std::optional> filament_maps_new) const { DynamicPrintConfig out; out.apply(FullPrintConfig::defaults()); @@ -2128,6 +2136,9 @@ DynamicPrintConfig PresetBundle::full_fff_config(bool apply_extruder, std::vecto // BBS size_t num_filaments = this->filament_presets.size(); + std::vector filament_maps = out.option("filament_map")->values; + if (filament_maps_new.has_value()) + filament_maps = *filament_maps_new; //in some middle state, they may be different if (filament_maps.size() != num_filaments) { filament_maps.resize(num_filaments, 1); diff --git a/src/libslic3r/PresetBundle.hpp b/src/libslic3r/PresetBundle.hpp index 1b3630550..1dee85422 100644 --- a/src/libslic3r/PresetBundle.hpp +++ b/src/libslic3r/PresetBundle.hpp @@ -7,6 +7,7 @@ #include #include +#include #include #define DEFAULT_USER_FOLDER_NAME "default" @@ -159,9 +160,9 @@ public: bool has_defauls_only() const { return prints.has_defaults_only() && filaments.has_defaults_only() && printers.has_defaults_only(); } - DynamicPrintConfig full_config(bool apply_extruder = true, std::vector filament_maps = std::vector()) const; + DynamicPrintConfig full_config(bool apply_extruder = true, std::optional>filament_maps = std::nullopt) const; // full_config() with the some "useless" config removed. - DynamicPrintConfig full_config_secure(std::vector filament_maps = std::vector()) const; + DynamicPrintConfig full_config_secure(std::optional>filament_maps = std::nullopt) const; //BBS: add some functions for multiple extruders int get_printer_extruder_count() const; @@ -280,7 +281,7 @@ private: /*ConfigSubstitutions load_config_file_config_bundle( const std::string &path, const boost::property_tree::ptree &tree, ForwardCompatibilitySubstitutionRule compatibility_rule);*/ - DynamicPrintConfig full_fff_config(bool apply_extruder, std::vector filament_maps) const; + DynamicPrintConfig full_fff_config(bool apply_extruder, std::optional> filament_maps=std::nullopt) const; DynamicPrintConfig full_sla_config() const; }; diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 3c6f86679..f82c294ea 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -1881,7 +1881,7 @@ void Print::process(std::unordered_map* slice_time, bool std::vectorfilament_maps = this->get_filament_maps(); auto map_mode = get_filament_map_mode(); // get recommended filament map - if (map_mode == FilamentMapMode::fmmAuto) { + if (map_mode < FilamentMapMode::fmmManual) { filament_maps = ToolOrdering::get_recommended_filament_maps(all_filaments, &config(), this, physical_unprintables, geometric_unprintables); std::transform(filament_maps.begin(), filament_maps.end(), filament_maps.begin(), [](int value) { return value + 1; }); update_filament_maps_to_config(filament_maps); diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index 9c3d24042..5bade1fec 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -880,8 +880,6 @@ public: const Calib_Params& calib_params() const { return m_calib_params; } Vec2d translate_to_print_space(const Vec2d& point) const; - bool has_auto_filament_map_result() const { return m_has_auto_filament_map_result; } - void set_auto_filament_map_result(bool has_result) { m_has_auto_filament_map_result = has_result; } // scaled point Vec2d translate_to_print_space(const Point& point) const; diff --git a/src/libslic3r/PrintApply.cpp b/src/libslic3r/PrintApply.cpp index 1d0fec602..8184a3ffe 100644 --- a/src/libslic3r/PrintApply.cpp +++ b/src/libslic3r/PrintApply.cpp @@ -1150,7 +1150,7 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_ if (print_diff_set.find("filament_map_mode") == print_diff_set.end()) { FilamentMapMode map_mode = new_full_config.option>("filament_map_mode", true)->value; - if (map_mode == fmmAuto) { + if (map_mode < fmmManual) { if (print_diff_set.find("filament_map") != print_diff_set.end()) { print_diff_set.erase("filament_map"); //full_config_diff.erase("filament_map"); diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index f48c0044c..0afc71caa 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -389,7 +389,8 @@ static const t_config_enum_values s_keys_map_NozzleVolumeType = { CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(NozzleVolumeType) static const t_config_enum_values s_keys_map_FilamentMapMode = { - { "Auto", fmmAuto }, + { "Auto For Flush", fmmAutoForFlush }, + { "Auto For Match", fmmAutoForMatch }, { "Manual", fmmManual } }; CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(FilamentMapMode) @@ -1656,12 +1657,16 @@ void PrintConfigDef::init_fff_params() def->label = L("filament mapping mode"); def->tooltip = ("filament mapping mode used as plate param"); def->enum_keys_map = &ConfigOptionEnum::get_enum_values(); - def->enum_values.push_back("Auto"); + def->enum_values.push_back("Auto For Flush"); + def->enum_values.push_back("Auto For Match"); def->enum_values.push_back("Manual"); - def->enum_labels.push_back(L("Auto")); + def->enum_values.push_back("Default"); + def->enum_labels.push_back(L("Auto For Flush")); + def->enum_labels.push_back(L("Auto For Match")); def->enum_labels.push_back(L("Manual")); + def->enum_labels.push_back(L("Default")); def->mode = comAdvanced; - def->set_default_value(new ConfigOptionEnum(fmmAuto)); + def->set_default_value(new ConfigOptionEnum(fmmAutoForFlush)); def = this->add("filament_max_volumetric_speed", coFloats); def->label = L("Max volumetric speed"); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index d54f35827..279ee194e 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -302,8 +302,10 @@ enum NozzleVolumeType { }; enum FilamentMapMode { - fmmAuto, - fmmManual + fmmAutoForFlush, + fmmAutoForMatch, + fmmManual, + fmmDefault }; extern std::string get_extruder_variant_string(ExtruderType extruder_type, NozzleVolumeType nozzle_volume_type); diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index ac5c34559..c25308fff 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -1885,8 +1885,9 @@ bool GLVolumeCollection::check_outside_state(const BuildVolume &build_volume, Mo //check per-object error for extruder areas if (object_results && (extruder_count > 1)) { - object_results->mode = curr_plate->get_filament_map_mode(); - if (object_results->mode == FilamentMapMode::fmmAuto) + const auto& project_config = Slic3r::GUI::wxGetApp().preset_bundle->project_config; + object_results->mode = curr_plate->get_real_filament_map_mode(project_config); + if (object_results->mode < FilamentMapMode::fmmManual) { std::vector conflict_filament_vector; for (int index = 0; index < extruder_count; index++ ) @@ -1947,7 +1948,8 @@ bool GLVolumeCollection::check_outside_state(const BuildVolume &build_volume, Mo else { std::set conflict_filaments_set; - std::vector filament_maps = curr_plate->get_filament_maps(); + const auto& project_config = Slic3r::GUI::wxGetApp().preset_bundle->project_config; + std::vector filament_maps = curr_plate->get_real_filament_maps(project_config); for (auto& object_map: objects_unprintable_filaments) { ModelObject *model_object = object_map.first; diff --git a/src/slic3r/GUI/AmsMappingPopup.cpp b/src/slic3r/GUI/AmsMappingPopup.cpp index 95bcf20b6..a5c6ca90b 100644 --- a/src/slic3r/GUI/AmsMappingPopup.cpp +++ b/src/slic3r/GUI/AmsMappingPopup.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include "Plater.hpp" #include "BitmapCache.hpp" #include "BindDialog.hpp" diff --git a/src/slic3r/GUI/BackgroundSlicingProcess.cpp b/src/slic3r/GUI/BackgroundSlicingProcess.cpp index b19948b97..51e204612 100644 --- a/src/slic3r/GUI/BackgroundSlicingProcess.cpp +++ b/src/slic3r/GUI/BackgroundSlicingProcess.cpp @@ -225,10 +225,9 @@ void BackgroundSlicingProcess::process_fff() BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: gcode_result reseted, will start print::process")%__LINE__; m_print->process(); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: after print::process, send slicing complete event to gui...")%__LINE__; - if (m_current_plate->get_filament_map_mode() == FilamentMapMode::fmmAuto) { + if (m_current_plate->get_real_filament_map_mode(preset_bundle.project_config) < FilamentMapMode::fmmManual) { std::vector f_maps = m_fff_print->get_filament_maps(); m_current_plate->set_filament_maps(f_maps); - m_current_plate->set_auto_filament_map_result(m_fff_print->has_auto_filament_map_result()); } wxCommandEvent evt(m_event_slicing_completed_id); // Post the Slicing Finished message for the G-code viewer to update. diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index c4e0b2404..7b87b957b 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -4652,7 +4652,7 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding) if (msg_dlg.ShowModal() == wxID_OK) { PartPlateList &partplate_list = wxGetApp().plater()->get_partplate_list(); PartPlate *plate = partplate_list.get_curr_plate(); - plate->set_filament_map_mode(FilamentMapMode::fmmAuto); + plate->set_filament_map_mode(FilamentMapMode::fmmAutoForFlush); Plater *plater = wxGetApp().plater(); wxPostEvent(plater, SimpleEvent(EVT_GLTOOLBAR_SLICE_PLATE)); } @@ -4665,9 +4665,9 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding) auto config = wxGetApp().plater()->get_partplate_list().get_current_fff_print().config(); auto stats_by_extruder = wxGetApp().plater()->get_partplate_list().get_current_fff_print().statistics_by_extruder(); auto filament_map_mode = config.filament_map_mode.value; - auto is_auto = filament_map_mode == FilamentMapMode::fmmAuto; + auto is_auto = filament_map_mode < FilamentMapMode::fmmManual; bool has_tips = true; - if (filament_map_mode == FilamentMapMode::fmmAuto) { + if (is_auto) { float saved_flush_weight = stats_by_extruder.stats_by_single_extruder.filament_flush_weight - stats_by_extruder.stats_by_multi_extruder_auto.filament_flush_weight; int saved_filament_changed_time = stats_by_extruder.stats_by_single_extruder.filament_change_count - stats_by_extruder.stats_by_multi_extruder_auto.filament_change_count; if (!(saved_flush_weight > EPSILON || saved_filament_changed_time > 0)) has_tips = false; @@ -4744,7 +4744,7 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding) } return static_cast(num); }; - if (filament_map_mode == fmmAuto) { + if (filament_map_mode < fmmManual) { float saved_flush_weight = stats_by_extruder.stats_by_single_extruder.filament_flush_weight - stats_by_extruder.stats_by_multi_extruder_auto.filament_flush_weight; int saved_filament_changed_time = stats_by_extruder.stats_by_single_extruder.filament_change_count - stats_by_extruder.stats_by_multi_extruder_auto.filament_change_count; if (saved_flush_weight > EPSILON || saved_filament_changed_time > 0) { diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index b474351f8..020ace8e7 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1409,7 +1409,7 @@ void GLCanvas3D::construct_error_string(ObjectFilamentResults& object_result, st } if (!object_result.filaments.empty()) { - if (object_result.mode == FilamentMapMode::fmmAuto) { + if (object_result.mode < FilamentMapMode::fmmManual) { error_string += _u8L("In the Filament auto-matching mode, Filament "); for (auto& filament: object_result.filaments) error_string += std::to_string(filament) + " "; diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index a5c1c6c14..203caea42 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -139,8 +139,6 @@ void PartPlate::init() m_print_index = -1; m_print = nullptr; - - m_config.option>("filament_map_mode", true); } BedType PartPlate::get_bed_type(bool load_from_project) const @@ -256,6 +254,32 @@ PrintSequence PartPlate::get_real_print_seq(bool* plate_same_as_global) const return curr_plate_seq; } +std::vector PartPlate::get_real_filament_maps(const DynamicConfig& g_config, bool* use_global_param) const +{ + auto maps = get_filament_maps(); + if (!maps.empty()) { + if (use_global_param) { *use_global_param = false; } + return maps; + } + auto g_maps = g_config.option("filament_map")->values; + if (use_global_param) { *use_global_param = true; } + return g_maps; +} + +FilamentMapMode PartPlate::get_real_filament_map_mode(const DynamicConfig& g_config, bool* use_global_param) const +{ + auto mode = get_filament_map_mode(); + if (FilamentMapMode::fmmDefault != mode) { + if (use_global_param) { *use_global_param = false; }; + return mode; + } + + auto g_mode = g_config.option>("filament_map_mode")->value; + if (use_global_param) { *use_global_param = true; } + return g_mode; +} + + bool PartPlate::has_spiral_mode_config() const { std::string key = "spiral_mode"; @@ -2578,8 +2602,9 @@ int PartPlate::load_gcode_from_file(const std::string& filename) { int ret = 0; + auto& preset_bundle = wxGetApp().preset_bundle; // process gcode - std::vector filament_maps = this->get_filament_maps(); + std::vector filament_maps = this->get_real_filament_maps(preset_bundle->project_config); DynamicPrintConfig full_config = wxGetApp().preset_bundle->full_config(false, filament_maps); full_config.apply(m_config, true); m_print->apply(*m_model, full_config, false); @@ -2876,37 +2901,39 @@ std::map PartPlate::get_diff_plate_setting() return out; } -FilamentMapMode PartPlate::get_filament_map_mode() +FilamentMapMode PartPlate::get_filament_map_mode() const { - return m_config.option>("filament_map_mode", true)->value; + std::string key = "filament_map_mode"; + if(m_config.has(key)) + return m_config.option>(key)->value; + return FilamentMapMode::fmmDefault; } void PartPlate::set_filament_map_mode(const FilamentMapMode& mode) { - m_config.option>("filament_map_mode", true)->value = mode; + m_config.option>("filament_map_mode", true)->value = mode; } -bool PartPlate::has_auto_filament_map_reslut() +std::vector PartPlate::get_filament_maps() const { - return m_has_auto_filament_map_result; -} + std::string key = "filament_map"; + if (m_config.has(key)) + return m_config.option(key)->values; -void PartPlate::set_auto_filament_map_result(bool has_result) -{ - m_has_auto_filament_map_result = has_result; -} - -std::vector PartPlate::get_filament_maps() -{ - std::vector& filament_maps = m_config.option("filament_map", true)->values; - - return filament_maps; + return {}; } void PartPlate::set_filament_maps(const std::vector& f_maps) { - std::vector& filament_maps = m_config.option("filament_map", true)->values; - filament_maps = f_maps; + m_config.option("filament_map", true)->values = f_maps; +} + +void PartPlate::clear_filament_map_info() +{ + if (m_config.has("filament_map")) + m_config.erase("filament_map"); + if (m_config.has("filament_map_mode")) + m_config.erase("filament_map_mode"); } const std::vector>& PartPlate::get_unprintable_filament_ids() @@ -2929,22 +2956,26 @@ void PartPlate::on_extruder_count_changed(int extruder_count) void PartPlate::set_filament_count(int filament_count) { - std::vector& filament_maps = m_config.option("filament_map", true)->values; - filament_maps.resize(filament_count, 1); + if (m_config.has("filament_map")) { + std::vector& filament_maps = m_config.option("filament_map")->values; + filament_maps.resize(filament_count); + } } void PartPlate::on_filament_added() { - std::vector& filament_maps = m_config.option("filament_map", true)->values; - filament_maps.push_back(1); + if (m_config.has("filament_map")) { + std::vector& filament_maps = m_config.option("filament_map")->values; + filament_maps.push_back(1); + } } void PartPlate::on_filament_deleted(int filament_count, int filament_id) { - std::vector& filament_maps = m_config.option("filament_map", true)->values; - - filament_maps.erase(filament_maps.begin()+filament_id); - + if (m_config.has("filament_map")) { + std::vector& filament_maps = m_config.option("filament_map")->values; + filament_maps.erase(filament_maps.begin() + filament_id); + } update_first_layer_print_sequence_when_delete_filament(filament_id); } @@ -5567,6 +5598,7 @@ int PartPlateList::store_to_3mf_structure(PlateDataPtrs& plate_data_list, bool w for (unsigned int i = 0; i < (unsigned int)m_plate_list.size(); ++i) { PlateData* plate_data_item = new PlateData(); + // TODO: write if needed plate_data_item->filament_maps = m_plate_list[i]->get_filament_maps(); plate_data_item->locked = m_plate_list[i]->m_locked; plate_data_item->plate_index = m_plate_list[i]->m_plate_index; diff --git a/src/slic3r/GUI/PartPlate.hpp b/src/slic3r/GUI/PartPlate.hpp index 4f3805fb3..ca2414b43 100644 --- a/src/slic3r/GUI/PartPlate.hpp +++ b/src/slic3r/GUI/PartPlate.hpp @@ -104,7 +104,6 @@ private: bool m_slice_result_valid; bool m_apply_invalid {false}; float m_slice_percent; - bool m_has_auto_filament_map_result{false}; Print *m_print; //Print reference, not own it, no need to serialize GCodeProcessorResult *m_gcode_result; @@ -229,6 +228,19 @@ public: // @return PrintSequence::{ByLayer,ByObject} PrintSequence get_real_print_seq(bool* plate_same_as_global=nullptr) const; + std::vector get_real_filament_maps(const DynamicConfig& g_config, bool* use_global_param = nullptr)const; + FilamentMapMode get_real_filament_map_mode(const DynamicConfig& g_config,bool * use_global_param = nullptr) const; + + FilamentMapMode get_filament_map_mode() const; + void set_filament_map_mode(const FilamentMapMode& mode); + + // get filament map, 0 based filament ids, 1 based extruder ids + std::vector get_filament_maps() const; + void set_filament_maps(const std::vector& f_maps); + + // remove filament map and map mode in profiles + void clear_filament_map_info(); + bool has_spiral_mode_config() const; bool get_spiral_vase_mode() const; void set_spiral_vase_mode(bool spiral_mode, bool as_global); @@ -484,16 +496,6 @@ public: std::map get_diff_object_setting(); std::map get_diff_plate_setting(); - FilamentMapMode get_filament_map_mode(); - void set_filament_map_mode(const FilamentMapMode& mode); - - bool has_auto_filament_map_reslut(); - void set_auto_filament_map_result(bool has_result); - - // get filament map, 0 based filament ids, 1 based extruder ids - std::vector get_filament_maps(); - void set_filament_maps(const std::vector& f_maps); - const std::vector> &get_unprintable_filament_ids(); void set_unprintable_filament_ids(const std::vector> &filament_ids); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index ae90e3aa3..40b539316 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -6235,14 +6235,15 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool } Print::ApplyStatus invalidated; - if (wxGetApp().preset_bundle->get_printer_extruder_count() > 1) { + const auto& preset_bundle = wxGetApp().preset_bundle; + if (preset_bundle->get_printer_extruder_count() > 1) { PartPlate* cur_plate = background_process.get_current_plate(); - std::vector f_maps = cur_plate->get_filament_maps(); - invalidated = background_process.apply(this->model, wxGetApp().preset_bundle->full_config(false, f_maps)); + std::vector f_maps = cur_plate->get_real_filament_maps(preset_bundle->project_config); + invalidated = background_process.apply(this->model, preset_bundle->full_config(false, f_maps)); background_process.fff_print()->set_extruder_filament_info(get_extruder_filament_info()); } else - invalidated = background_process.apply(this->model, wxGetApp().preset_bundle->full_config(false)); + invalidated = background_process.apply(this->model, preset_bundle->full_config(false)); if ((invalidated == Print::APPLY_STATUS_CHANGED) || (invalidated == Print::APPLY_STATUS_INVALIDATED)) // BBS: add only gcode mode @@ -14535,6 +14536,32 @@ std::vector Plater::get_colors_for_color_print(const GCodeProcessor return colors; } +void Plater::set_global_filament_map_mode(FilamentMapMode mode) +{ + auto& project_config = wxGetApp().preset_bundle->project_config; + project_config.option>("filament_map_mode")->value = mode; +} + +void Plater::set_global_filament_map(const std::vector& filament_map) +{ + auto& project_config = wxGetApp().preset_bundle->project_config; + project_config.option("filament_map")->values = filament_map; +} + +std::vector Plater::get_global_filament_map() const +{ + auto& project_config = wxGetApp().preset_bundle->project_config; + return project_config.option("filament_map")->values; +} + + +FilamentMapMode Plater::get_global_filament_map_mode() const +{ + auto& project_config = wxGetApp().preset_bundle->project_config; + return project_config.option>("filament_map_mode")->value; +} + + wxWindow* Plater::get_select_machine_dialog() { return p->m_select_machine_dlg; @@ -14987,14 +15014,15 @@ void Plater::apply_background_progress() PartPlate* part_plate = p->partplate_list.get_curr_plate(); int plate_index = p->partplate_list.get_curr_plate_index(); bool result_valid = part_plate->is_slice_result_valid(); + const auto& preset_bundle = wxGetApp().preset_bundle; //always apply the current plate's print Print::ApplyStatus invalidated; - if (wxGetApp().preset_bundle->get_printer_extruder_count() > 1) { - std::vector f_maps = part_plate->get_filament_maps(); - invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config(false, f_maps)); + if (preset_bundle->get_printer_extruder_count() > 1) { + std::vector f_maps = part_plate->get_real_filament_maps(preset_bundle->project_config); + invalidated = p->background_process.apply(this->model(), preset_bundle->full_config(false, f_maps)); } else - invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config(false)); + invalidated = p->background_process.apply(this->model(), preset_bundle->full_config(false)); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: plate %2%, after apply, invalidated= %3%, previous result_valid %4% ") % __LINE__ % plate_index % invalidated % result_valid; if (invalidated & PrintBase::APPLY_STATUS_INVALIDATED) @@ -15016,6 +15044,7 @@ int Plater::select_plate(int plate_index, bool need_slice) if (is_view3D_shown()) wxGetApp().plater()->canvas3D()->render(); } + const auto& preset_bundle = wxGetApp().preset_bundle; if ((!ret) && (p->background_process.can_switch_print())) { @@ -15033,12 +15062,12 @@ int Plater::select_plate(int plate_index, bool need_slice) part_plate->get_print(&print, &gcode_result, NULL); //always apply the current plate's print - if (wxGetApp().preset_bundle->get_printer_extruder_count() > 1) { - std::vector f_maps = part_plate->get_filament_maps(); - invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config(false, f_maps)); + if (preset_bundle->get_printer_extruder_count() > 1) { + std::vector f_maps = part_plate->get_real_filament_maps(preset_bundle->project_config); + invalidated = p->background_process.apply(this->model(), preset_bundle->full_config(false, f_maps)); } else - invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config(false)); + invalidated = p->background_process.apply(this->model(), preset_bundle->full_config(false)); bool model_fits, validate_err; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: plate %2%, after apply, invalidated= %3%, previous result_valid %4% ")%__LINE__ %plate_index %invalidated %result_valid; @@ -15326,33 +15355,41 @@ void Plater::open_filament_map_setting_dialog(wxCommandEvent &evt) int value = evt.GetInt(); bool is_auto = value & 1; //0000 means manual, 0001 means auto bool need_slice = value & (1 << 1); //0010 means from gcode view, 0000 means not from gcode view + + const auto& project_config = wxGetApp().preset_bundle->project_config; + auto filament_colors = config()->option("filament_colour")->values; + auto plate_filament_maps = curr_plate->get_real_filament_maps(project_config); + auto plate_filament_map_mode = curr_plate->get_filament_map_mode(); + if (plate_filament_maps.size() != filament_colors.size()) // refine it later, save filament map to app config + plate_filament_maps.resize(filament_colors.size(), 1); + FilamentMapDialog filament_dlg(this, config(), - curr_plate->get_filament_maps(), + plate_filament_maps, curr_plate->get_extruders(true), - is_auto, - curr_plate->has_auto_filament_map_reslut() + plate_filament_map_mode < FilamentMapMode::fmmManual, + false ); + if (filament_dlg.ShowModal() == wxID_OK) { std::vector new_filament_maps = filament_dlg.get_filament_maps(); - std::vector old_filament_maps = curr_plate->get_filament_maps(); - FilamentMapMode new_map_mode = filament_dlg.is_auto() ? FilamentMapMode::fmmAuto : FilamentMapMode::fmmManual; + std::vector old_filament_maps = plate_filament_maps; - if (new_map_mode == FilamentMapMode::fmmManual) { - curr_plate->set_auto_filament_map_result(false); - } + FilamentMapMode old_map_mode = plate_filament_map_mode; + FilamentMapMode new_map_mode = filament_dlg.is_auto() ? fmmAutoForFlush : fmmManual; - FilamentMapMode old_map_mode = curr_plate->get_filament_map_mode(); - bool need_invalidate = false; - if (new_map_mode != old_map_mode) { + bool need_invalidate = (old_map_mode != new_map_mode || + old_filament_maps != new_filament_maps); + + if (old_map_mode != new_map_mode) curr_plate->set_filament_map_mode(new_map_mode); - need_invalidate = true; - } - if (new_filament_maps != old_filament_maps) { + + if (old_filament_maps != new_filament_maps && new_map_mode==fmmManual) curr_plate->set_filament_maps(new_filament_maps); - if (new_map_mode == FilamentMapMode::fmmManual) - need_invalidate = true; - } + + if (new_map_mode == fmmDefault) + curr_plate->clear_filament_map_info(); + if (need_invalidate) { if (need_slice) { wxPostEvent(this, SimpleEvent(EVT_GLTOOLBAR_SLICE_PLATE)); @@ -15399,14 +15436,16 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModi GCodeResult* gcode_result = nullptr; Print::ApplyStatus invalidated; + const auto& preset_bundle = wxGetApp().preset_bundle; + part_plate->get_print(&print, &gcode_result, NULL); //always apply the current plate's print - if (wxGetApp().preset_bundle->get_printer_extruder_count() > 1) { - std::vector f_maps = part_plate->get_filament_maps(); - invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config(false, f_maps)); + if (preset_bundle->get_printer_extruder_count() > 1) { + std::vector f_maps = part_plate->get_real_filament_maps(preset_bundle->project_config); + invalidated = p->background_process.apply(this->model(), preset_bundle->full_config(false, f_maps)); } else - invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config(false)); + invalidated = p->background_process.apply(this->model(), preset_bundle->full_config(false)); bool model_fits, validate_err; validate_current_plate(model_fits, validate_err); @@ -15536,7 +15575,7 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModi if (!ret) { PartPlate * curr_plate = p->partplate_list.get_curr_plate(); wxCommandEvent evt(EVT_OPEN_FILAMENT_MAP_SETTINGS_DIALOG); - evt.SetInt(curr_plate->get_filament_map_mode()==FilamentMapMode::fmmAuto ? 1 : 0); + evt.SetInt(curr_plate->get_filament_map_mode() < FilamentMapMode::fmmManual ? 1 : 0); evt.SetEventObject(this); wxPostEvent(this, evt); } else { diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 354b1cc86..907b9e619 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -456,6 +456,11 @@ public: std::vector get_extruder_colors_from_plater_config(const GCodeProcessorResult* const result = nullptr) const; std::vector get_colors_for_color_print(const GCodeProcessorResult* const result = nullptr) const; + void set_global_filament_map_mode(FilamentMapMode mode); + void set_global_filament_map(const std::vector& filament_map); + std::vector get_global_filament_map() const; + FilamentMapMode get_global_filament_map_mode() const; + void update_menus(); // BBS //void show_action_buttons(const bool is_ready_to_slice) const; diff --git a/src/slic3r/GUI/SelectMachine.cpp b/src/slic3r/GUI/SelectMachine.cpp index 815d37843..4de9057b6 100644 --- a/src/slic3r/GUI/SelectMachine.cpp +++ b/src/slic3r/GUI/SelectMachine.cpp @@ -1162,8 +1162,9 @@ bool SelectMachineDialog::do_ams_mapping(MachineObject *obj_) // try color and type mapping const auto& full_config = wxGetApp().preset_bundle->full_config(); + const auto& project_config = wxGetApp().preset_bundle->project_config; size_t nozzle_nums = full_config.option("nozzle_diameter")->values.size(); - m_filaments_map = wxGetApp().plater()->get_partplate_list().get_curr_plate()->get_filament_maps(); + m_filaments_map = wxGetApp().plater()->get_partplate_list().get_curr_plate()->get_real_filament_maps(project_config); int filament_result = 0; std::vector map_opt; //four values: use_left_ams, use_right_ams, use_left_ext, use_right_ext @@ -1479,9 +1480,10 @@ bool SelectMachineDialog::is_nozzle_type_match(ExtderData data) { if (data.total_extder_count <= 1 || data.extders.size() <= 1 || !wxGetApp().preset_bundle) return false; + const auto& project_config = wxGetApp().preset_bundle->project_config; //check nozzle used auto used_filaments = wxGetApp().plater()->get_partplate_list().get_curr_plate()->get_used_extruders(); // 1 based - auto filament_maps = wxGetApp().plater()->get_partplate_list().get_curr_plate()->get_filament_maps(); // 1 based + auto filament_maps = wxGetApp().plater()->get_partplate_list().get_curr_plate()->get_real_filament_maps(project_config); // 1 based std::map used_extruders_flow; std::vector used_extruders; // 0 based for (auto f : used_filaments) { @@ -1966,7 +1968,7 @@ bool SelectMachineDialog::is_same_nozzle_diameters(NozzleType& tag_nozzle_type, machine_nozzle_types[idx] = obj_->m_extder_data.extders[idx].current_nozzle_type; auto used_filaments = wxGetApp().plater()->get_partplate_list().get_curr_plate()->get_used_extruders(); // 1 based - auto filament_maps=wxGetApp().plater()->get_partplate_list().get_curr_plate()->get_filament_maps(); // 1 based + auto filament_maps=wxGetApp().plater()->get_partplate_list().get_curr_plate()->get_real_filament_maps(preset_bundle->project_config); // 1 based std::vectorused_extruders; // 0 based for (auto f : used_filaments) { @@ -3603,7 +3605,8 @@ void SelectMachineDialog::reset_and_sync_ams_list() bool use_double_extruder = nozzle_nums > 1 ? true : false; if (use_double_extruder) { - m_filaments_map = wxGetApp().plater()->get_partplate_list().get_curr_plate()->get_filament_maps(); + const auto& project_config = preset_bundle->project_config; + m_filaments_map = wxGetApp().plater()->get_partplate_list().get_curr_plate()->get_real_filament_maps(project_config); } for (auto i = 0; i < extruders.size(); i++) {