From 05bf5c114b3c3d34e9eed46ebb803e05de72722f Mon Sep 17 00:00:00 2001 From: "xun.zhang" Date: Thu, 19 Dec 2024 14:53:42 +0800 Subject: [PATCH] ENH: filament map params switch to global param 1.Add more filament map modes 2.Filament map and mode are set as project config 3.Plate filament map is only valid when plate filament mode is manual jira:NONE Signed-off-by: xun.zhang Change-Id: I33b2f853e0b77b9d605be1f2f1172b44df43da15 (cherry picked from commit e45f8c6dc2146e1e31a1c21e8aaada540af112d0) --- src/OrcaSlicer.cpp | 10 +- src/libslic3r/Format/bbs_3mf.cpp | 12 ++- src/libslic3r/GCode/ToolOrdering.cpp | 6 +- src/libslic3r/PresetBundle.cpp | 19 +++- src/libslic3r/PresetBundle.hpp | 7 +- src/libslic3r/Print.cpp | 2 +- src/libslic3r/Print.hpp | 2 - src/libslic3r/PrintApply.cpp | 2 +- src/libslic3r/PrintConfig.cpp | 13 ++- src/libslic3r/PrintConfig.hpp | 6 +- src/slic3r/GUI/3DScene.cpp | 8 +- src/slic3r/GUI/AmsMappingPopup.cpp | 1 + src/slic3r/GUI/BackgroundSlicingProcess.cpp | 3 +- src/slic3r/GUI/GCodeViewer.cpp | 8 +- src/slic3r/GUI/GLCanvas3D.cpp | 2 +- src/slic3r/GUI/PartPlate.cpp | 87 +++++++++++----- src/slic3r/GUI/PartPlate.hpp | 24 +++-- src/slic3r/GUI/Plater.cpp | 107 +++++++++++++------- src/slic3r/GUI/Plater.hpp | 5 + src/slic3r/GUI/SelectMachine.cpp | 9 +- 20 files changed, 218 insertions(+), 115 deletions(-) diff --git a/src/OrcaSlicer.cpp b/src/OrcaSlicer.cpp index ccd610a590..fb2b37fda7 100644 --- a/src/OrcaSlicer.cpp +++ b/src/OrcaSlicer.cpp @@ -5073,8 +5073,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++) @@ -5112,7 +5112,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]; @@ -5138,11 +5138,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 66ff0c9946..4bfee9c1e1 100644 --- a/src/libslic3r/Format/bbs_3mf.cpp +++ b/src/libslic3r/Format/bbs_3mf.cpp @@ -4230,9 +4230,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) @@ -7695,7 +7698,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 ea3d2ee05c..21bbb8f6e3 100644 --- a/src/libslic3r/GCode/ToolOrdering.cpp +++ b/src/libslic3r/GCode/ToolOrdering.cpp @@ -1194,7 +1194,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) { @@ -1210,7 +1210,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()); @@ -1285,7 +1285,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 02642ad145..4360d54cce 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" }; //Orca: add custom as default @@ -1892,7 +1894,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 @@ -1914,11 +1918,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){ @@ -2199,14 +2207,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); //FIXME legacy, the keys should not be there after conversion to a Physical Printer profile. @@ -2225,7 +2233,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()); @@ -2238,6 +2246,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 742c6de218..8474f010ad 100644 --- a/src/libslic3r/PresetBundle.hpp +++ b/src/libslic3r/PresetBundle.hpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -188,9 +189,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; @@ -321,7 +322,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; // Orca: used for validation only diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 1bbc5636b2..d418a2a6ca 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -2133,7 +2133,7 @@ void Print::process(long long *time_cost_with_cache, bool use_cache) 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 9c2827155c..3fd9d8b8dd 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -1015,8 +1015,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 29983f0fc9..ca37806ff1 100644 --- a/src/libslic3r/PrintApply.cpp +++ b/src/libslic3r/PrintApply.cpp @@ -1154,7 +1154,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 e2731f9d99..91735d0924 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -486,7 +486,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) @@ -2161,12 +2162,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 800faea837..cc3f04be15 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -379,8 +379,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 605233ed04..cb2b6dad58 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -1207,8 +1207,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++ ) @@ -1269,7 +1270,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 bb250eebf9..83411a15de 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 7c9a982178..04331a90e7 100644 --- a/src/slic3r/GUI/BackgroundSlicingProcess.cpp +++ b/src/slic3r/GUI/BackgroundSlicingProcess.cpp @@ -228,10 +228,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 cfc03bb3d0..a56d619eed 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -4436,7 +4436,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)); } @@ -4449,9 +4449,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; @@ -4528,7 +4528,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 6699bb9f46..0a670833f1 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1373,7 +1373,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 db5b1df233..70c7f89687 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -180,8 +180,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 @@ -302,6 +300,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"; @@ -3220,37 +3244,39 @@ void PartPlate::print() const return; } -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() @@ -3273,22 +3299,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); } @@ -5458,6 +5488,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 637df76e0d..565a97d735 100644 --- a/src/slic3r/GUI/PartPlate.hpp +++ b/src/slic3r/GUI/PartPlate.hpp @@ -105,7 +105,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; @@ -246,6 +245,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); @@ -492,16 +504,6 @@ public: void print() const; - 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 5ca129f973..7d40c09a00 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -6178,14 +6178,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 @@ -14514,6 +14515,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; @@ -14954,14 +14981,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) @@ -14983,6 +15011,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())) { @@ -15000,12 +15029,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; @@ -15296,33 +15325,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)); @@ -15369,14 +15406,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); @@ -15499,7 +15538,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 e65de18990..6d2229a941 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -504,6 +504,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 e05f0e7cd1..bf5b1f074c 100644 --- a/src/slic3r/GUI/SelectMachine.cpp +++ b/src/slic3r/GUI/SelectMachine.cpp @@ -1126,8 +1126,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 @@ -1443,9 +1444,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) { @@ -3544,7 +3546,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++) {