ENH: config: add filament_maps in partplate

Change-Id: I1183830788e703f1d33a8a4b620b58b822283dd4
(cherry picked from commit b0e3ab037e3f5af0851539af5ac15b8f96daf548)
This commit is contained in:
lane.wei
2024-06-20 16:10:16 +08:00
committed by Noisyfox
parent fe09c20725
commit 141af16fa2
11 changed files with 490 additions and 105 deletions

View File

@@ -2661,6 +2661,7 @@ bool GUI_App::on_init_inner()
if (plater_ != nullptr) {
plater_->reset_project_dirty_initial_presets();
plater_->update_project_dirty_from_presets();
plater_->get_partplate_list().set_filament_count(preset_bundle->filament_presets.size());
}
// BBS:

View File

@@ -180,6 +180,8 @@ void PartPlate::init()
m_print_index = -1;
m_print = nullptr;
m_config.option<ConfigOptionEnum<FilamentMapMode>>("filament_map_mode", true);
}
BedType PartPlate::get_bed_type(bool load_from_project) const
@@ -3172,6 +3174,53 @@ void PartPlate::print() const
return;
}
FilamentMapMode PartPlate::get_filament_map_mode()
{
return m_config.option<ConfigOptionEnum<FilamentMapMode>>("filament_map_mode", true)->value;
}
void PartPlate::set_filament_map_mode(FilamentMapMode& mode)
{
m_config.option<ConfigOptionEnum<FilamentMapMode>>("filament_map_mode", true)->value = mode;
}
std::vector<int> PartPlate::get_filament_maps()
{
std::vector<int>& filament_maps = m_config.option<ConfigOptionInts>("filament_map", true)->values;
return filament_maps;
}
void PartPlate::set_filament_maps(std::vector<int>& f_maps)
{
std::vector<int>& filament_maps = m_config.option<ConfigOptionInts>("filament_map", true)->values;
filament_maps = f_maps;
}
void PartPlate::set_filament_count(int filament_count)
{
std::vector<int>& filament_maps = m_config.option<ConfigOptionInts>("filament_map", true)->values;
filament_maps.resize(filament_count, 1);
}
void PartPlate::on_filament_added()
{
std::vector<int>& filament_maps = m_config.option<ConfigOptionInts>("filament_map", true)->values;
filament_maps.push_back(1);
}
void PartPlate::on_filament_deleted(int filament_count, int filament_id)
{
std::vector<int>& filament_maps = m_config.option<ConfigOptionInts>("filament_map", true)->values;
filament_maps.erase(filament_maps.begin()+filament_id);
update_first_layer_print_sequence_when_delete_filament(filament_id);
}
/* PartPlate List related functions*/
PartPlateList::PartPlateList(int width, int depth, int height, Plater* platerObj, Model* modelObj, PrinterTechnology tech)
:m_plate_width(width), m_plate_depth(depth), m_plate_height(height), m_plater(platerObj), m_model(modelObj), printer_technology(tech),
@@ -3607,8 +3656,10 @@ void PartPlateList::reset(bool do_init)
//m_plate_list.clear();
if (do_init)
if (do_init) {
init();
m_plate_list[0]->set_filament_count(m_filament_count);
}
return;
}
@@ -3620,6 +3671,8 @@ void PartPlateList::reinit()
init();
m_plate_list[0]->set_filament_count(m_filament_count);
//reset plate 0's position
Vec2d pos = compute_shape_position(0, m_plate_cols);
m_plate_list[0]->set_shape(m_shape, m_exclude_areas, pos, m_height_to_lid, m_height_to_rod);
@@ -3668,6 +3721,8 @@ int PartPlateList::create_plate(bool adjust_position)
m_print_index++;
}
plate->set_filament_count(m_filament_count);
plate->set_index(new_index);
Vec2d pos = compute_shape_position(new_index, cols);
plate->set_shape(m_shape, m_exclude_areas, pos, m_height_to_lid, m_height_to_rod);
@@ -5385,7 +5440,7 @@ int PartPlateList::store_to_3mf_structure(PlateDataPtrs& plate_data_list, bool w
return ret;
}
int PartPlateList::load_from_3mf_structure(PlateDataPtrs& plate_data_list)
int PartPlateList::load_from_3mf_structure(PlateDataPtrs& plate_data_list, int filament_count)
{
int ret = 0;
@@ -5395,6 +5450,7 @@ int PartPlateList::load_from_3mf_structure(PlateDataPtrs& plate_data_list)
return -1;
}
clear(true, true);
set_filament_count(filament_count);
for (unsigned int i = 0; i < (unsigned int)plate_data_list.size(); ++i)
{
int index = create_plate(false);
@@ -5736,5 +5792,35 @@ void PartPlateList::load_cali_textures()
PartPlateList::is_load_cali_texture = true;
}
void PartPlateList::set_filament_count(int filament_count)
{
m_filament_count = filament_count;
for (unsigned int i = 0; i < (unsigned int)m_plate_list.size(); ++i)
{
m_plate_list[i]->set_filament_count(filament_count);
}
BOOST_LOG_TRIVIAL(info) << boost::format("%1%: filament_count=%2%")% __FUNCTION__ %filament_count;
}
void PartPlateList::on_filament_added(int filament_count)
{
m_filament_count++;
for (unsigned int i = 0; i < (unsigned int)m_plate_list.size(); ++i)
{
m_plate_list[i]->on_filament_added();
}
BOOST_LOG_TRIVIAL(info) << boost::format("%1%: filament_count=%2%")% __FUNCTION__ %filament_count;
}
void PartPlateList::on_filament_deleted(int filament_count, int filament_id)
{
m_filament_count--;
for (unsigned int i = 0; i < (unsigned int)m_plate_list.size(); ++i)
{
m_plate_list[i]->on_filament_deleted(filament_count, filament_id);
}
BOOST_LOG_TRIVIAL(info) << boost::format("%1%: filament_count=%2%, filament_id=%3%")% __FUNCTION__ %filament_count %filament_id;
}
}//end namespace GUI
}//end namespace slic3r

View File

@@ -481,6 +481,16 @@ public:
void print() const;
FilamentMapMode get_filament_map_mode();
void set_filament_map_mode(FilamentMapMode& mode);
std::vector<int> get_filament_maps();
void set_filament_maps(std::vector<int>& f_maps);
void set_filament_count(int filament_count);
void on_filament_added();
void on_filament_deleted(int filament_count, int filament_id);
friend class cereal::access;
friend class UndoRedo::StackImpl;
@@ -573,6 +583,8 @@ class PartPlateList : public ObjectBase
bool m_is_dark = false;
int m_filament_count = 1;
void init();
//compute the origin for printable plate with index i
Vec3d compute_origin(int index, int column_count);
@@ -839,7 +851,7 @@ public:
* if with_gcode = true and specify plate_idx, export plate_idx gcode only
*/
int store_to_3mf_structure(PlateDataPtrs& plate_data_list, bool with_slice_info = true, int plate_idx = -1);
int load_from_3mf_structure(PlateDataPtrs& plate_data_list);
int load_from_3mf_structure(PlateDataPtrs& plate_data_list, int filament_count = 1);
//load gcode files
int load_gcode_files();
@@ -860,6 +872,10 @@ public:
void init_cali_texture_info();
void load_cali_textures();
void set_filament_count(int filament_count);
void on_filament_deleted(int filament_count, int filament_id);
void on_filament_added(int filament_count);
BedTextureInfo bed_texture_info[btCount];
BedTextureInfo cali_texture_info;
BedTextureInfo extruder_only_area_info[(unsigned char) ExtruderOnlyAreaType::btAreaCount];

View File

@@ -1063,7 +1063,7 @@ Sidebar::Sidebar(Plater *parent)
auto& project_config = wxGetApp().preset_bundle->project_config;
const std::vector<double>& init_matrix = (project_config.option<ConfigOptionFloats>("flush_volumes_matrix"))->values;
const std::vector<double>& init_extruders = (project_config.option<ConfigOptionFloats>("flush_volumes_vector"))->values;
const std::vector<std::string> extruder_colours = wxGetApp().plater()->get_extruder_colors_from_plater_config();
const auto& full_config = wxGetApp().preset_bundle->full_config();
const auto& extra_flush_volumes = get_min_flush_volumes(full_config, 0); // todo multi_extruder: always display nozzle 1
@@ -1076,7 +1076,7 @@ Sidebar::Sidebar(Plater *parent)
flush_multiplier = cast<float>(flush_multi_opt->values);
else {
for (size_t nozzle_id = 0; nozzle_id < nozzle_nums; ++nozzle_id) {
flush_multiplier.push_back(1.f);
flush_multiplier.push_back(1.f);
}
}
WipingDialog dlg(parent, cast<float>(init_matrix), cast<float>(init_extruders), extruder_colours, extra_flush_volumes, flush_multiplier, nozzle_nums);
@@ -1930,6 +1930,7 @@ void Sidebar::delete_filament(size_t filament_id) {
}
wxGetApp().preset_bundle->update_num_filaments(filament_id);
wxGetApp().plater()->get_partplate_list().on_filament_deleted(filament_count, filament_id);
wxGetApp().plater()->on_filaments_delete(filament_count, filament_id);
wxGetApp().get_tab(Preset::TYPE_PRINT)->update();
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
@@ -1941,6 +1942,7 @@ void Sidebar::add_custom_filament(wxColour new_col) {
int filament_count = p->combos_filament.size() + 1;
std::string new_color = new_col.GetAsString(wxC2S_HTML_SYNTAX).ToStdString();
wxGetApp().preset_bundle->set_num_filaments(filament_count, new_color);
wxGetApp().plater()->get_partplate_list().on_filament_added(filament_count);
wxGetApp().plater()->on_filaments_change(filament_count);
wxGetApp().get_tab(Preset::TYPE_PRINT)->update();
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
@@ -2306,22 +2308,22 @@ void Sidebar::auto_calc_flushing_volumes(const int modify_id)
const auto& full_config = wxGetApp().preset_bundle->full_config();
auto& ams_multi_color_filament = preset_bundle->ams_multi_color_filment;
size_t nozzle_nums = preset_bundle->full_config().option<ConfigOptionFloats>("nozzle_diameter")->values.size();
size_t nozzle_nums = preset_bundle->get_printer_extruder_count();
for (size_t nozzle_id = 0; nozzle_id < nozzle_nums; ++nozzle_id)
{
std::vector<double> init_matrix = get_flush_volumes_matrix((project_config.option<ConfigOptionFloats>("flush_volumes_matrix"))->values, nozzle_id, nozzle_nums);
const std::vector<int>& min_flush_volumes= get_min_flush_volumes(full_config, nozzle_id);
ConfigOptionFloat* flush_multi_opt = project_config.option<ConfigOptionFloat>("flush_multiplier");
float flush_multiplier = flush_multi_opt ? flush_multi_opt->getFloat() : 1.f;
std::vector<double> matrix = init_matrix;
int m_max_flush_volume = Slic3r::g_max_flush_volume;
unsigned int m_number_of_extruders = (int)(sqrt(init_matrix.size()) + 0.001);
const std::vector<std::string> extruder_colours = wxGetApp().plater()->get_extruder_colors_from_plater_config();
std::vector<std::vector<wxColour>> multi_colours;
// Support for multi-color filament
for (int i = 0; i < extruder_colours.size(); ++i) {
std::vector<wxColour> single_filament;
@@ -2335,11 +2337,11 @@ void Sidebar::auto_calc_flushing_volumes(const int modify_id)
continue;
}
}
single_filament.push_back(wxColour(extruder_colours[i]));
multi_colours.push_back(single_filament);
}
if (modify_id >= 0 && modify_id < multi_colours.size()) {
for (int i = 0; i < multi_colours.size(); ++i) {
// from to modify
@@ -2366,7 +2368,7 @@ void Sidebar::auto_calc_flushing_volumes(const int modify_id)
}
matrix[m_number_of_extruders * from_idx + modify_id] = flushing_volume;
}
// modify to to
int to_idx = i;
if (to_idx != modify_id) {
@@ -2388,7 +2390,7 @@ void Sidebar::auto_calc_flushing_volumes(const int modify_id)
}
if (is_from_support)
flushing_volume = std::max(flushing_volume, Slic3r::g_min_flush_volume_from_support);
matrix[m_number_of_extruders * modify_id + to_idx] = flushing_volume;
}
}
@@ -3896,7 +3898,7 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
bool dlg_cont = true;
bool is_user_cancel = false;
bool translate_old = false;
int current_width = 0, current_depth = 0, current_height = 0;
int current_width = 0, current_depth = 0, current_height = 0, project_filament_count = 1;
if (input_files.empty()) { return std::vector<size_t>(); }
@@ -4177,7 +4179,8 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
//set the size back
partplate_list.reset_size(current_width + Bed3D::Axes::DefaultTipRadius, current_depth + Bed3D::Axes::DefaultTipRadius, current_height, false);
}
partplate_list.load_from_3mf_structure(plate_data);
project_filament_count = config_loaded.option<ConfigOptionStrings>("filament_colour")->size();
partplate_list.load_from_3mf_structure(plate_data, project_filament_count);
partplate_list.update_slice_context_to_current_plate(background_process);
this->preview->update_gcode_result(partplate_list.get_current_slice_result());
release_PlateData_list(plate_data);
@@ -4392,7 +4395,7 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
std::vector<Preset *> project_presets;
bool is_xxx;
Semver file_version;
//ObjImportColorFn obj_color_fun=nullptr;
auto obj_color_fun = [this, &path](std::vector<RGBA> &input_colors, bool is_single_color, std::vector<unsigned char> &filament_ids,
unsigned char &first_extruder_id) {
@@ -4486,7 +4489,7 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
}
if (plate_data.size() > 0) {
partplate_list.load_from_3mf_structure(plate_data);
partplate_list.load_from_3mf_structure(plate_data, project_filament_count);
partplate_list.update_slice_context_to_current_plate(background_process);
this->preview->update_gcode_result(partplate_list.get_current_slice_result());
release_PlateData_list(plate_data);
@@ -5536,7 +5539,15 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool
this->partplate_list.update_slice_context_to_current_plate(background_process);
this->preview->update_gcode_result(partplate_list.get_current_slice_result());
}
Print::ApplyStatus invalidated = background_process.apply(this->model, wxGetApp().preset_bundle->full_config());
Print::ApplyStatus invalidated;
if (wxGetApp().preset_bundle->get_printer_extruder_count() > 1) {
PartPlate* cur_plate = background_process.get_current_plate();
std::vector<int> f_maps = cur_plate->get_filament_maps();
invalidated = background_process.apply(this->model, wxGetApp().preset_bundle->full_config(f_maps));
}
else
invalidated = background_process.apply(this->model, wxGetApp().preset_bundle->full_config());
if ((invalidated == Print::APPLY_STATUS_CHANGED) || (invalidated == Print::APPLY_STATUS_INVALIDATED))
// BBS: add only gcode mode
@@ -13365,11 +13376,12 @@ void Plater::on_filaments_delete(size_t num_filaments, size_t filament_id)
update_filament_colors_in_full_config();
// update fisrt print sequence and other layer sequence
Slic3r::GUI::PartPlateList &plate_list = get_partplate_list();
//move to partplate->on_filament_deleted
/*Slic3r::GUI::PartPlateList &plate_list = get_partplate_list();
for (int i = 0; i < plate_list.get_plate_count(); ++i) {
PartPlate *part_plate = plate_list.get_plate(i);
part_plate->update_first_layer_print_sequence_when_delete_filament(filament_id);
}
}*/
// update mmu info
for (ModelObject *mo : wxGetApp().model().objects) {
@@ -13386,7 +13398,7 @@ void Plater::on_filaments_delete(size_t num_filaments, size_t filament_id)
for (auto key : keys)
if (p->config->has(key) && p->config->opt_int(key) == filament_id + 1)
(*(p->config)).erase(key);
// update object/volume/support(object and volume) filament id
sidebar().obj_list()->update_objects_list_filament_column_when_delete_filament(filament_id, num_filaments);
@@ -13543,7 +13555,7 @@ void Plater::update_flush_volume_matrix(const Slic3r::DynamicPrintConfig& config
auto *printer_model = config.opt<ConfigOptionString>("printer_model");
if (printer_model != nullptr && !printer_model->value.empty()) {
size_t nozzle_nums = wxGetApp().preset_bundle->full_config().option<ConfigOptionFloats>("nozzle_diameter")->values.size();
size_t nozzle_nums = wxGetApp().preset_bundle->get_printer_extruder_count();
if (!is_multi_extruder_printer(old_model_id) && is_multi_extruder_printer(printer_model->value)) {
Slic3r::DynamicPrintConfig *project_config = &wxGetApp().preset_bundle->project_config;
std::vector<double> flush_volume_mtx = get_flush_volumes_matrix(project_config->option<ConfigOptionFloats>("flush_volumes_matrix")->values, -1, nozzle_nums);
@@ -14120,7 +14132,13 @@ void Plater::apply_background_progress()
int plate_index = p->partplate_list.get_curr_plate_index();
bool result_valid = part_plate->is_slice_result_valid();
//always apply the current plate's print
Print::ApplyStatus invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config());
Print::ApplyStatus invalidated;
if (wxGetApp().preset_bundle->get_printer_extruder_count() > 1) {
std::vector<int> f_maps = part_plate->get_filament_maps();
invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config(f_maps));
}
else
invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config());
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)
@@ -14159,7 +14177,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
invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config());
if (wxGetApp().preset_bundle->get_printer_extruder_count() > 1) {
std::vector<int> f_maps = part_plate->get_filament_maps();
invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config(f_maps));
}
else
invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config());
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;
@@ -14465,7 +14488,12 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModi
part_plate->get_print(&print, &gcode_result, NULL);
//always apply the current plate's print
invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config());
if (wxGetApp().preset_bundle->get_printer_extruder_count() > 1) {
std::vector<int> f_maps = part_plate->get_filament_maps();
invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config(f_maps));
}
else
invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config());
bool model_fits, validate_err;
validate_current_plate(model_fits, validate_err);