FIX: The flushing was not auto-calc when sync ams list
JIRA: STUDIO-5551 1. flushing volume auto-calc when sync ams list 2. flushing volume takes the larger calculation value when filament has multi-colors Signed-off-by: Kunlong Ma <kunlong.ma@bambulab.com> Change-Id: I72e6f9780ea56103a44c2da6068440a4615c254d
This commit is contained in:
parent
4207d1079b
commit
62b872888f
|
@ -1727,6 +1727,7 @@ void PresetBundle::set_num_filaments(unsigned int n, std::string new_color)
|
|||
|
||||
ConfigOptionStrings* filament_color = project_config.option<ConfigOptionStrings>("filament_colour");
|
||||
filament_color->resize(n);
|
||||
ams_multi_color_filment.resize(n);
|
||||
|
||||
//BBS set new filament color to new_color
|
||||
if (old_filament_count < n) {
|
||||
|
@ -1744,15 +1745,18 @@ unsigned int PresetBundle::sync_ams_list(unsigned int &unknowns)
|
|||
{
|
||||
std::vector<std::string> filament_presets;
|
||||
std::vector<std::string> filament_colors;
|
||||
ams_multi_color_filment.clear();
|
||||
for (auto &entry : filament_ams_list) {
|
||||
auto & ams = entry.second;
|
||||
auto filament_id = ams.opt_string("filament_id", 0u);
|
||||
auto filament_color = ams.opt_string("filament_colour", 0u);
|
||||
auto filament_changed = !ams.has("filament_changed") || ams.opt_bool("filament_changed");
|
||||
auto filament_multi_color = ams.opt<ConfigOptionStrings>("filament_multi_colors")->values;
|
||||
if (filament_id.empty()) continue;
|
||||
if (!filament_changed && this->filament_presets.size() > filament_presets.size()) {
|
||||
filament_presets.push_back(this->filament_presets[filament_presets.size()]);
|
||||
filament_colors.push_back(filament_color);
|
||||
ams_multi_color_filment.push_back(filament_multi_color);
|
||||
continue;
|
||||
}
|
||||
auto iter = std::find_if(filaments.begin(), filaments.end(), [this, &filament_id](auto &f) {
|
||||
|
@ -1772,6 +1776,7 @@ unsigned int PresetBundle::sync_ams_list(unsigned int &unknowns)
|
|||
if (filament_presets.size() < this->filament_presets.size()) {
|
||||
filament_presets.push_back(this->filament_presets[filament_presets.size()]);
|
||||
filament_colors.push_back(filament_color);
|
||||
ams_multi_color_filment.push_back(filament_multi_color);
|
||||
++unknowns;
|
||||
continue;
|
||||
}
|
||||
|
@ -1786,6 +1791,7 @@ unsigned int PresetBundle::sync_ams_list(unsigned int &unknowns)
|
|||
}
|
||||
filament_presets.push_back(iter->name);
|
||||
filament_colors.push_back(filament_color);
|
||||
ams_multi_color_filment.push_back(filament_multi_color);
|
||||
}
|
||||
if (filament_presets.empty())
|
||||
return 0;
|
||||
|
|
|
@ -114,6 +114,7 @@ public:
|
|||
std::vector<std::string> filament_presets;
|
||||
// BBS: ams
|
||||
std::map<int, DynamicPrintConfig> filament_ams_list;
|
||||
std::vector<std::vector<std::string>> ams_multi_color_filment;
|
||||
// Calibrate
|
||||
Preset const * calibrate_printer = nullptr;
|
||||
std::set<Preset const *> calibrate_filaments;
|
||||
|
|
|
@ -1591,6 +1591,10 @@ std::map<int, DynamicPrintConfig> Sidebar::build_filament_ams_list(MachineObject
|
|||
vt_tray_config.set_key_value("filament_colour", new ConfigOptionStrings{ into_u8(wxColour("#" + vt_tray.color).GetAsString(wxC2S_HTML_SYNTAX)) });
|
||||
vt_tray_config.set_key_value("filament_exist", new ConfigOptionBools{ true });
|
||||
|
||||
vt_tray_config.set_key_value("filament_multi_colors", new ConfigOptionStrings{});
|
||||
for (int i = 0; i < vt_tray.cols.size(); ++i) {
|
||||
vt_tray_config.opt<ConfigOptionStrings>("filament_multi_colors")->values.push_back(into_u8(wxColour("#" + vt_tray.cols[i]).GetAsString(wxC2S_HTML_SYNTAX)));
|
||||
}
|
||||
filament_ams_list.emplace(VIRTUAL_TRAY_ID, std::move(vt_tray_config));
|
||||
}
|
||||
|
||||
|
@ -1609,6 +1613,10 @@ std::map<int, DynamicPrintConfig> Sidebar::build_filament_ams_list(MachineObject
|
|||
tray_config.set_key_value("filament_colour", new ConfigOptionStrings{ into_u8(wxColour("#" + tray.second->color).GetAsString(wxC2S_HTML_SYNTAX)) });
|
||||
tray_config.set_key_value("filament_exist", new ConfigOptionBools{ tray.second->is_exists });
|
||||
|
||||
tray_config.set_key_value("filament_multi_colors", new ConfigOptionStrings{});
|
||||
for (int i = 0; i < tray.second->cols.size(); ++i) {
|
||||
tray_config.opt<ConfigOptionStrings>("filament_multi_colors")->values.push_back(into_u8(wxColour("#" + tray.second->cols[i]).GetAsString(wxC2S_HTML_SYNTAX)));
|
||||
}
|
||||
filament_ams_list.emplace(((n - 'A') * 4 + t - '1'), std::move(tray_config));
|
||||
}
|
||||
}
|
||||
|
@ -1669,6 +1677,17 @@ void Sidebar::sync_ams_list()
|
|||
ams.set_key_value("filament_changed", new ConfigOptionBool{res == wxID_YES || list2[i] != filament_id});
|
||||
list2[i] = filament_id;
|
||||
}
|
||||
|
||||
// BBS:Record consumables information before synchronization
|
||||
std::vector<string> color_before_sync;
|
||||
std::vector<int> is_support_before;
|
||||
DynamicPrintConfig& project_config = wxGetApp().preset_bundle->project_config;
|
||||
ConfigOptionStrings* color_opt = project_config.option<ConfigOptionStrings>("filament_colour");
|
||||
for (int i = 0; i < p->combos_filament.size(); ++i) {
|
||||
is_support_before.push_back(is_support_filament(i));
|
||||
color_before_sync.push_back(color_opt->values[i]);
|
||||
}
|
||||
|
||||
unsigned int unknowns = 0;
|
||||
auto n = wxGetApp().preset_bundle->sync_ams_list(unknowns);
|
||||
if (n == 0) {
|
||||
|
@ -1687,13 +1706,32 @@ void Sidebar::sync_ams_list()
|
|||
dlg.ShowModal();
|
||||
}
|
||||
wxGetApp().plater()->on_filaments_change(n);
|
||||
for (auto &c : p->combos_filament)
|
||||
for (auto& c : p->combos_filament)
|
||||
c->update();
|
||||
wxGetApp().get_tab(Preset::TYPE_FILAMENT)->select_preset(wxGetApp().preset_bundle->filament_presets[0]);
|
||||
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
|
||||
dynamic_filament_list.update();
|
||||
// Expand filament list
|
||||
p->m_panel_filament_content->SetMaxSize({-1, -1});
|
||||
// BBS:Synchronized consumables information
|
||||
// auto calculation of flushing volumes
|
||||
for (int i = 0; i < p->combos_filament.size(); ++i) {
|
||||
if (i >= color_before_sync.size()) {
|
||||
auto_calc_flushing_volumes(i);
|
||||
}
|
||||
else {
|
||||
// if color changed
|
||||
if (color_before_sync[i] != color_opt->values[i]) {
|
||||
auto_calc_flushing_volumes(i);
|
||||
}
|
||||
// color don't change, but changes between supporting filament and non supporting filament
|
||||
else {
|
||||
bool flag = is_support_filament(i);
|
||||
if (flag != is_support_before[i])
|
||||
auto_calc_flushing_volumes(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
Layout();
|
||||
}
|
||||
|
||||
|
@ -1878,71 +1916,103 @@ void Sidebar::set_is_gcode_file(bool flag)
|
|||
}
|
||||
}
|
||||
|
||||
void Sidebar::auto_calc_flushing_volumes(const int modify_id) {
|
||||
auto& project_config = wxGetApp().preset_bundle->project_config;
|
||||
auto& printer_config = wxGetApp().preset_bundle->printers.get_edited_preset().config;
|
||||
void Sidebar::auto_calc_flushing_volumes(const int modify_id)
|
||||
{
|
||||
auto& preset_bundle = wxGetApp().preset_bundle;
|
||||
auto& project_config = preset_bundle->project_config;
|
||||
auto& printer_config = preset_bundle->printers.get_edited_preset().config;
|
||||
auto& ams_multi_color_filament = preset_bundle->ams_multi_color_filment;
|
||||
auto& ams_filament_list = preset_bundle->filament_ams_list;
|
||||
|
||||
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;
|
||||
ConfigOption* extra_flush_volume_opt = printer_config.option("nozzle_volume");
|
||||
int extra_flush_volume = extra_flush_volume_opt ? (int)extra_flush_volume_opt->getFloat() : 0;
|
||||
ConfigOptionFloat* flush_multi_opt = project_config.option<ConfigOptionFloat>("flush_multiplier");
|
||||
float flush_multiplier = flush_multi_opt ? flush_multi_opt->getFloat() : 1.f;
|
||||
vector<double> matrix = init_matrix;
|
||||
std::vector<double> matrix = init_matrix;
|
||||
int m_min_flush_volume = extra_flush_volume;
|
||||
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();
|
||||
vector<wxColour> m_colours;
|
||||
for (const std::string& color : extruder_colours) {
|
||||
m_colours.push_back(wxColor(color));
|
||||
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;
|
||||
if (i < ams_multi_color_filament.size()) {
|
||||
if (!ams_multi_color_filament[i].empty()) {
|
||||
std::vector<std::string> colors = ams_multi_color_filament[i];
|
||||
for (int j = 0; j < colors.size(); ++j) {
|
||||
single_filament.push_back(wxColour(colors[j]));
|
||||
}
|
||||
multi_colours.push_back(single_filament);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
single_filament.push_back(wxColour(extruder_colours[i]));
|
||||
multi_colours.push_back(single_filament);
|
||||
}
|
||||
if (modify_id >= 0 && modify_id < m_colours.size()) {
|
||||
for (int i = 0; i < m_colours.size(); ++i) {
|
||||
|
||||
if (modify_id >= 0 && modify_id < multi_colours.size()) {
|
||||
for (int i = 0; i < multi_colours.size(); ++i) {
|
||||
|
||||
Slic3r::FlushVolCalculator calculator(m_min_flush_volume, m_max_flush_volume);
|
||||
|
||||
// from to modify
|
||||
int from_idx = i;
|
||||
if (from_idx != modify_id) {
|
||||
const wxColour& from = m_colours[from_idx];
|
||||
bool is_from_support = is_support_filament(from_idx);
|
||||
const wxColour& to = m_colours[modify_id];
|
||||
bool is_to_support = is_support_filament(modify_id);
|
||||
int flushing_volume = 0;
|
||||
bool is_from_support = is_support_filament(from_idx);
|
||||
bool is_to_support = is_support_filament(modify_id);
|
||||
if (is_to_support) {
|
||||
flushing_volume = Slic3r::g_flush_volume_to_support;
|
||||
}
|
||||
else {
|
||||
const wxColour& to = m_colours[modify_id];
|
||||
Slic3r::FlushVolCalculator calculator(m_min_flush_volume, m_max_flush_volume);
|
||||
flushing_volume = calculator.calc_flush_vol(from.Alpha(), from.Red(), from.Green(), from.Blue(), to.Alpha(), to.Red(), to.Green(), to.Blue());
|
||||
if (is_from_support) {
|
||||
flushing_volume = std::max(Slic3r::g_min_flush_volume_from_support, flushing_volume);
|
||||
for (int j = 0; j < multi_colours[from_idx].size(); ++j) {
|
||||
const wxColour& from = multi_colours[from_idx][j];
|
||||
for (int k = 0; k < multi_colours[modify_id].size(); ++k) {
|
||||
const wxColour& to = multi_colours[modify_id][k];
|
||||
int volume = calculator.calc_flush_vol(from.Alpha(), from.Red(), from.Green(), from.Blue(), to.Alpha(), to.Red(), to.Green(), to.Blue());
|
||||
flushing_volume = std::max(flushing_volume, volume);
|
||||
}
|
||||
}
|
||||
if (is_from_support)
|
||||
flushing_volume = std::max(flushing_volume, Slic3r::g_min_flush_volume_from_support);
|
||||
}
|
||||
matrix[m_number_of_extruders * from_idx + modify_id] = flushing_volume;
|
||||
}
|
||||
|
||||
// modify to to
|
||||
int to_idx = i;
|
||||
if (to_idx != modify_id) {
|
||||
const wxColour& from = m_colours[modify_id];
|
||||
bool is_from_support = is_support_filament(modify_id);
|
||||
const wxColour& to = m_colours[to_idx];
|
||||
bool is_to_support = is_support_filament(to_idx);
|
||||
int flushing_volume = 0;
|
||||
if (is_to_support) {
|
||||
flushing_volume = Slic3r::g_flush_volume_to_support;
|
||||
}
|
||||
else {
|
||||
const wxColour& to = m_colours[to_idx];
|
||||
Slic3r::FlushVolCalculator calculator(m_min_flush_volume, m_max_flush_volume);
|
||||
flushing_volume = calculator.calc_flush_vol(from.Alpha(), from.Red(), from.Green(), from.Blue(), to.Alpha(), to.Red(), to.Green(), to.Blue());
|
||||
if (is_from_support) {
|
||||
flushing_volume = std::max(Slic3r::g_min_flush_volume_from_support, flushing_volume);
|
||||
for (int j = 0; j < multi_colours[modify_id].size(); ++j) {
|
||||
const wxColour& from = multi_colours[modify_id][j];
|
||||
for (int k = 0; k < multi_colours[to_idx].size(); ++k) {
|
||||
const wxColour& to = multi_colours[to_idx][k];
|
||||
int volume = calculator.calc_flush_vol(from.Alpha(), from.Red(), from.Green(), from.Blue(), to.Alpha(), to.Red(), to.Green(), to.Blue());
|
||||
flushing_volume = std::max(flushing_volume, volume);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
matrix[m_number_of_extruders * modify_id + to_idx] = flushing_volume;
|
||||
}
|
||||
}
|
||||
}
|
||||
(project_config.option<ConfigOptionFloats>("flush_volumes_matrix"))->values = std::vector<double>(matrix.begin(), matrix.end());
|
||||
|
||||
|
||||
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
|
||||
|
||||
wxGetApp().plater()->update_project_dirty_from_presets();
|
||||
|
@ -6873,10 +6943,14 @@ void Plater::priv::on_filament_color_changed(wxCommandEvent &event)
|
|||
{
|
||||
//q->update_all_plate_thumbnails(true);
|
||||
//q->get_preview_canvas3D()->update_plate_thumbnails();
|
||||
int modify_id = event.GetInt();
|
||||
if (wxGetApp().app_config->get("auto_calculate") == "true") {
|
||||
int modify_id = event.GetInt();
|
||||
sidebar->auto_calc_flushing_volumes(modify_id);
|
||||
}
|
||||
|
||||
auto& ams_multi_color_filment = wxGetApp().preset_bundle->ams_multi_color_filment;
|
||||
if (modify_id >= 0 && modify_id < ams_multi_color_filment.size())
|
||||
ams_multi_color_filment[modify_id].clear();
|
||||
}
|
||||
|
||||
void Plater::priv::install_network_plugin(wxCommandEvent &event)
|
||||
|
|
|
@ -10,7 +10,11 @@
|
|||
#include "Widgets/Button.hpp"
|
||||
#include "slic3r/Utils/ColorSpaceConvert.hpp"
|
||||
#include "MainFrame.hpp"
|
||||
#include "libslic3r/Config.hpp"
|
||||
|
||||
#include <wx/sizer.h>
|
||||
|
||||
using namespace Slic3r;
|
||||
using namespace Slic3r::GUI;
|
||||
|
||||
int scale(const int val) { return val * Slic3r::GUI::wxGetApp().em_unit() / 10; }
|
||||
|
@ -610,10 +614,29 @@ void WipingPanel::update_warning_texts()
|
|||
|
||||
void WipingPanel::calc_flushing_volumes()
|
||||
{
|
||||
for (int from_idx = 0; from_idx < m_colours.size(); from_idx++) {
|
||||
const wxColour& from = m_colours[from_idx];
|
||||
auto& ams_multi_color_filament = wxGetApp().preset_bundle->ams_multi_color_filment;
|
||||
std::vector<std::vector<wxColour>> multi_colors;
|
||||
|
||||
// Support for multi-color filament
|
||||
for (int i = 0; i < m_colours.size(); ++i) {
|
||||
std::vector<wxColour> single_filament;
|
||||
if (i < ams_multi_color_filament.size()) {
|
||||
if (!ams_multi_color_filament[i].empty()) {
|
||||
std::vector<std::string> colors = ams_multi_color_filament[i];
|
||||
for (int j = 0; j < colors.size(); ++j) {
|
||||
single_filament.push_back(wxColour(colors[j]));
|
||||
}
|
||||
multi_colors.push_back(single_filament);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
single_filament.push_back(wxColour(m_colours[i]));
|
||||
multi_colors.push_back(single_filament);
|
||||
}
|
||||
|
||||
for (int from_idx = 0; from_idx < multi_colors.size(); ++from_idx) {
|
||||
bool is_from_support = is_support_filament(from_idx);
|
||||
for (int to_idx = 0; to_idx < m_colours.size(); to_idx++) {
|
||||
for (int to_idx = 0; to_idx < multi_colors.size(); ++to_idx) {
|
||||
bool is_to_support = is_support_filament(to_idx);
|
||||
if (from_idx == to_idx) {
|
||||
edit_boxes[to_idx][from_idx]->SetValue(std::to_string(0));
|
||||
|
@ -624,8 +647,15 @@ void WipingPanel::calc_flushing_volumes()
|
|||
flushing_volume = Slic3r::g_flush_volume_to_support;
|
||||
}
|
||||
else {
|
||||
const wxColour& to = m_colours[to_idx];
|
||||
flushing_volume = calc_flushing_volume(from, to);
|
||||
for (int i = 0; i < multi_colors[from_idx].size(); ++i) {
|
||||
const wxColour& from = multi_colors[from_idx][i];
|
||||
for (int j = 0; j < multi_colors[to_idx].size(); ++j) {
|
||||
const wxColour& to = multi_colors[to_idx][j];
|
||||
int volume = calc_flushing_volume(from, to);
|
||||
flushing_volume = std::max(flushing_volume, volume);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_from_support) {
|
||||
flushing_volume = std::max(Slic3r::g_min_flush_volume_from_support, flushing_volume);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue