ENH: add filament_printable and delete unprintable and printable list

jira: none

Change-Id: I643ab11831ceac1fe0793510f64b288cbd16415a
This commit is contained in:
zhimin.zeng 2025-04-12 15:58:50 +08:00 committed by lane.wei
parent c64270f506
commit 3dd5a60154
14 changed files with 122 additions and 177 deletions

View File

@ -5861,27 +5861,6 @@ int CLI::run(int argc, char **argv)
else
filament_maps = part_plate->get_real_filament_maps(m_print_config);
std::vector<std::string>& unprintable_filament_types = m_print_config.option<ConfigOptionStrings>("unprintable_filament_types", true)->values;
std::vector<std::vector<std::string>>unprintable_filament_type_list;
unprintable_filament_type_list.resize(new_extruder_count);
for (int index = 0; index < new_extruder_count; index++)
{
std::vector<std::string> unprintable_list;
if (unprintable_filament_types.size() > index)
unprintable_list = split_string(unprintable_filament_types[index], ',');
unprintable_filament_type_list[index] = unprintable_list;
}
std::vector<std::string> & printable_filament_types = m_print_config.option<ConfigOptionStrings>("printable_filament_types", true)->values;
std::vector<std::vector<std::string>> printable_filament_type_list;
printable_filament_type_list.resize(new_extruder_count);
for (int index = 0; index < new_extruder_count; index++) {
std::vector<std::string> printable_list;
if (printable_filament_types.size() > index)
printable_list = split_string(printable_filament_types[index], ',');
printable_filament_type_list[index] = printable_list;
}
for (int index = 0; index < filament_maps.size(); index++)
{
int filament_extruder = filament_maps[index];
@ -5893,26 +5872,20 @@ int CLI::run(int argc, char **argv)
}
}
for (int f_index = 0; f_index < plate_filaments.size(); f_index++) {
for (int f_index = 0; f_index < plate_filaments.size(); f_index++) {
if (plate_filaments[f_index] <= filament_count) {
int filament_extruder = filament_maps[plate_filaments[f_index] - 1];
std::vector<std::string>& unprintable_list = unprintable_filament_type_list[filament_extruder-1];
std::vector<std::string>& printable_list = printable_filament_type_list[filament_extruder-1];
std::string filament_type;
m_print_config.get_filament_type(filament_type, plate_filaments[f_index] - 1);
if (unprintable_list.size() > 0)
{
auto iter = std::find(unprintable_list.begin(), unprintable_list.end(), filament_type);
if (iter != unprintable_list.end()) {
BOOST_LOG_TRIVIAL(error) << boost::format("plate %1% : filament %2% can not be printed on extruder %3%, under manual mode for multi extruder printer") % (index + 1) %filament_type %filament_extruder;
record_exit_reson(outfile_dir, CLI_FILAMENTS_NOT_SUPPORTED_BY_EXTRUDER, index + 1, cli_errors[CLI_FILAMENTS_NOT_SUPPORTED_BY_EXTRUDER], sliced_info);
flush_and_exit(CLI_FILAMENTS_NOT_SUPPORTED_BY_EXTRUDER);
}
}
if (printable_list.size() > 0) {
auto iter = std::find(printable_list.begin(), printable_list.end(), filament_type);
if (iter == printable_list.end()) {
BOOST_LOG_TRIVIAL(error) << boost::format("plate %1% : filament %2% can not be printed on extruder %3%, under manual mode for multi extruder printer, not in printable filament list") % (index + 1) % filament_type % filament_extruder;
auto *filament_printable_status = dynamic_cast<const ConfigOptionInts *>(m_print_config.option("filament_printable"));
if (filament_printable_status) {
int status = filament_printable_status->values.at(plate_filaments[f_index] - 1);
if (!(status >> filament_extruder & 1)) {
BOOST_LOG_TRIVIAL(error)
<< boost::format(
"plate %1% : filament %2% can not be printed on extruder %3%, under manual mode for multi extruder printer") %
(index + 1) % filament_type % filament_extruder;
record_exit_reson(outfile_dir, CLI_FILAMENTS_NOT_SUPPORTED_BY_EXTRUDER, index + 1,
cli_errors[CLI_FILAMENTS_NOT_SUPPORTED_BY_EXTRUDER], sliced_info);
flush_and_exit(CLI_FILAMENTS_NOT_SUPPORTED_BY_EXTRUDER);
@ -5922,6 +5895,7 @@ int CLI::run(int argc, char **argv)
}
}
}
}
plate_triangle_counts[index] = triangle_count;
plate_object_count[index] = printable_instances;

View File

@ -67,18 +67,14 @@ bool check_filament_printable_after_group(const std::vector<unsigned int> &used_
{
for (unsigned int filament_id : used_filaments) {
std::string filament_type = print_config->filament_type.get_at(filament_id);
for (size_t idx = 0; idx < print_config->unprintable_filament_types.values.size(); ++idx) {
if (filament_maps[filament_id] == idx) {
std::vector<std::string> limit_types = split_string(print_config->unprintable_filament_types.get_at(idx), ',');
auto iter = std::find(limit_types.begin(), limit_types.end(), filament_type);
if (iter != limit_types.end()) {
std::string extruder_name = idx == 0 ? _L("left") : _L("right");
int printable_status = print_config->filament_printable.get_at(filament_id);
int extruder_idx = filament_maps[filament_id];
if (!(printable_status >> extruder_idx & 1)) {
std::string extruder_name = extruder_idx == 0 ? _L("left") : _L("right");
std::string error_msg = _L("Grouping error: ") + filament_type + _L(" can not be placed in the ") + extruder_name + _L(" nozzle");
throw Slic3r::RuntimeError(error_msg);
}
}
}
}
return true;
}

View File

@ -906,8 +906,9 @@ static std::vector<std::string> s_Preset_print_options {
"seam_slope_steps", "seam_slope_inner_walls", "role_base_wipe_speed" /*, "seam_slope_gap"*/, "precise_outer_wall",
"interlocking_beam", "interlocking_orientation", "interlocking_beam_layer_count", "interlocking_depth", "interlocking_boundary_avoidance", "interlocking_beam_width"};
static std::vector<std::string> s_Preset_filament_options {
/*"filament_colour", */ "default_filament_colour","required_nozzle_HRC","filament_diameter", "filament_type", "filament_soluble", "filament_is_support","filament_scarf_seam_type", "filament_scarf_height", "filament_scarf_gap","filament_scarf_length",
static std::vector<std::string> s_Preset_filament_options {/*"filament_colour", */ "default_filament_colour", "required_nozzle_HRC", "filament_diameter", "filament_type",
"filament_soluble", "filament_is_support", "filament_printable", "filament_scarf_seam_type", "filament_scarf_height",
"filament_scarf_gap", "filament_scarf_length",
"filament_max_volumetric_speed", "impact_strength_z", "filament_ramming_volumetric_speed",
"filament_flow_ratio", "filament_density", "filament_adhesiveness_category", "filament_cost", "filament_minimal_purge_on_wipe_tower",
"nozzle_temperature", "nozzle_temperature_initial_layer",
@ -953,7 +954,7 @@ static std::vector<std::string> s_Preset_printer_options {
"single_extruder_multi_material", "machine_start_gcode", "machine_end_gcode","printing_by_object_gcode","before_layer_change_gcode", "layer_change_gcode", "time_lapse_gcode", "change_filament_gcode",
"printer_model", "printer_variant", "printer_extruder_id", "printer_extruder_variant", "extruder_variant_list", "default_nozzle_volume_type",
"printable_height", "extruder_printable_height", "extruder_clearance_dist_to_rod", "extruder_clearance_max_radius","extruder_clearance_height_to_lid", "extruder_clearance_height_to_rod",
"nozzle_height", "printable_filament_types", "unprintable_filament_types","master_extruder_id",
"nozzle_height", "master_extruder_id",
"default_print_profile", "inherits",
"silent_mode",
// BBS

View File

@ -330,7 +330,7 @@ Semver PresetBundle::get_vendor_profile_version(std::string vendor_name)
return result_ver;
}
std::optional<FilamentBaseInfo> PresetBundle::get_filament_by_filament_id(const std::string& filament_id) const
std::optional<FilamentBaseInfo> PresetBundle::get_filament_by_filament_id(const std::string& filament_id, const std::string& printer_name) const
{
if (filament_id.empty())
return std::nullopt;
@ -356,9 +356,20 @@ std::optional<FilamentBaseInfo> PresetBundle::get_filament_by_filament_id(const
info.nozzle_temp_range_high = config.option<ConfigOptionInts>("nozzle_temperature_range_high")->values[0];
if (config.has("nozzle_temperature_range_low"))
info.nozzle_temp_range_low = config.option<ConfigOptionInts>("nozzle_temperature_range_low")->values[0];
if (!printer_name.empty()) {
std::vector<std::string> compatible_printers = config.option<ConfigOptionStrings>("compatible_printers")->values;
auto iter = std::find(compatible_printers.begin(), compatible_printers.end(), printer_name);
if (iter != compatible_printers.end() && config.has("filament_printable")) {
info.filament_printable = config.option<ConfigOptionInts>("filament_printable")->values[0];
return info;
}
}
else {
return info;
}
}
}
return std::nullopt;
}

View File

@ -59,6 +59,7 @@ struct FilamentBaseInfo
int nozzle_temp_range_high{ 220 };
bool is_support{ false };
bool is_system{ true };
int filament_printable = 3;
};
// Bundle of Print + Filament + Printer presets.
@ -122,7 +123,7 @@ public:
//BBS: get vendor's current version
Semver get_vendor_profile_version(std::string vendor_name);
std::optional<FilamentBaseInfo> get_filament_by_filament_id(const std::string& filament_id) const;
std::optional<FilamentBaseInfo> get_filament_by_filament_id(const std::string& filament_id, const std::string& printer_name = std::string()) const;
//BBS: project embedded preset logic
PresetsConfigSubstitutions load_project_embedded_presets(std::vector<Preset*> project_presets, ForwardCompatibilitySubstitutionRule substitution_rule);

View File

@ -307,6 +307,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n
steps.emplace_back(psSkirtBrim);
} else if (opt_key == "filament_soluble"
|| opt_key == "filament_is_support"
|| opt_key == "filament_printable"
|| opt_key == "impact_strength_z"
|| opt_key == "filament_scarf_seam_type"
|| opt_key == "filament_scarf_height"
@ -2531,13 +2532,11 @@ std::vector<std::set<int>> Print::get_physical_unprintable_filaments(const std::
return physical_unprintables;
auto get_unprintable_extruder_id = [&](unsigned int filament_idx) -> int {
if (m_config.unprintable_filament_types.empty())
return -1;
for (int eid = 0; eid < m_config.unprintable_filament_types.values.size(); ++eid) {
std::vector<std::string> extruder_unprintables = split_string(m_config.unprintable_filament_types.values[eid], ',');
auto iter = std::find(extruder_unprintables.begin(), extruder_unprintables.end(), m_config.filament_type.values[filament_idx]);
if (iter != extruder_unprintables.end())
return eid;
int status = m_config.filament_printable.values[filament_idx];
for (int i = 0; i < extruder_num; ++i) {
if (!(status >> i & 1)) {
return i;
}
}
return -1;
};

View File

@ -582,18 +582,6 @@ void PrintConfigDef::init_common_params()
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloatsNullable{0});
def = this->add("unprintable_filament_types", coStrings);
def->label = L("Unprintable filament type");
def->tooltip = L("Unprintable filament type");
def->mode = comDevelop;
def->set_default_value(new ConfigOptionStrings{""});
def = this->add("printable_filament_types", coStrings);
def->label = L("Printable filament type");
def->tooltip = L("Printable filament type");
def->mode = comDevelop;
def->set_default_value(new ConfigOptionStrings{""});
// Options used by physical printers
def = this->add("preset_names", coStrings);
@ -1961,6 +1949,16 @@ void PrintConfigDef::init_fff_params()
def->mode = comDevelop;
def->set_default_value(new ConfigOptionBools{false});
// defined in bits
// 0 means cannot support, 1 means support
// 0 bit: can support in left extruder
// 1 bit: can support in right extruder
def = this->add("filament_printable", coInts);
def->label = L("Filament printable");
def->tooltip = L("The filament is printable in extruder");
def->mode = comDevelop;
def->set_default_value(new ConfigOptionInts{3});
// BBS
def = this->add("filament_prime_volume", coFloats);
def->label = L("Filament prime volume");

View File

@ -1031,6 +1031,7 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionBools, filament_soluble))
((ConfigOptionStrings, filament_ids))
((ConfigOptionBools, filament_is_support))
((ConfigOptionInts, filament_printable))
((ConfigOptionEnumsGeneric, filament_scarf_seam_type))
((ConfigOptionFloatsOrPercents, filament_scarf_height))
((ConfigOptionFloatsOrPercents, filament_scarf_gap))
@ -1134,8 +1135,6 @@ PRINT_CONFIG_CLASS_DERIVED_DEFINE(
((ConfigOptionPoints, bed_exclude_area))
((ConfigOptionPoints, head_wrap_detect_zone))
// BBS
((ConfigOptionStrings, unprintable_filament_types))
((ConfigOptionStrings, printable_filament_types))
((ConfigOptionString, bed_custom_texture))
((ConfigOptionString, bed_custom_model))
((ConfigOptionEnum<BedType>, curr_bed_type))

View File

@ -562,7 +562,7 @@ void AMSMaterialsSetting::on_select_ok(wxCommandEvent &event)
if (vendor && (vendor->values.size() > 0)) {
std::string vendor_name = vendor->values[0];
DeviceManager::check_filaments_in_blacklist(obj->printer_type, vendor_name, filamnt_type, ams_id, slot_id, it->name, in_blacklist, action, info);
DeviceManager::check_filaments_in_blacklist(obj->printer_type, vendor_name, filamnt_type, it->filament_id, ams_id, slot_id, it->name, in_blacklist, action, info);
}
if (in_blacklist) {

View File

@ -1490,7 +1490,7 @@ bool CalibrationPresetPage::is_filament_in_blacklist(int tray_id, Preset* preset
auto vendor = dynamic_cast<ConfigOptionStrings*> (preset->config.option("filament_vendor"));
if (vendor && (vendor->values.size() > 0)) {
std::string vendor_name = vendor->values[0];
DeviceManager::check_filaments_in_blacklist(curr_obj->printer_type, vendor_name, filamnt_type, ams_id, slot_id, "", in_blacklist, action, info);
DeviceManager::check_filaments_in_blacklist(curr_obj->printer_type, vendor_name, filamnt_type, preset->filament_id, ams_id, slot_id, "", in_blacklist, action, info);
}
if (in_blacklist) {

View File

@ -304,6 +304,46 @@ void check_filaments_for_vt_slot(const std::string &tag_vendor, const std::strin
}
}
bool check_filaments_printable(const std::string &tag_vendor, const std::string &tag_type, const std::string& filament_id, int ams_id, bool &in_blacklist, std::string &ac, std::string &info)
{
DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) {
return true;
}
MachineObject *obj = dev->get_selected_machine();
if (obj == nullptr || !obj->is_multi_extruders()) {
return true;
}
Preset *printer_preset = GUI::get_printer_preset(obj);
if (!printer_preset)
return true;
ConfigOptionInts *physical_extruder_map_op = dynamic_cast<ConfigOptionInts *>(printer_preset->config.option("physical_extruder_map"));
if (!physical_extruder_map_op)
return true;
std::vector<int> physical_extruder_maps = physical_extruder_map_op->values;
int extruder_idx = obj->get_extruder_id_by_ams_id(std::to_string(ams_id));
for (int index = 0; index < physical_extruder_maps.size(); ++index) {
if (physical_extruder_maps[index] == extruder_idx) {
extruder_idx = index;
}
}
PresetBundle *preset_bundle = GUI::wxGetApp().preset_bundle;
std::optional<FilamentBaseInfo> filament_info = preset_bundle->get_filament_by_filament_id(filament_id, printer_preset->name);
if (filament_info.has_value() && !(filament_info->filament_printable >> extruder_idx & 1)) {
wxString extruder_name = extruder_idx == 0 ? _L("left") : _L("right");
ac = "prohibition";
info = (wxString::Format(_L("%s is not supported by %s extruder."), tag_type, extruder_name)).ToUTF8().data();
in_blacklist = true;
return false;
}
return true;
}
void AmsTray::update_color_from_str(std::string color)
{
if (color.empty()) return;
@ -7788,73 +7828,24 @@ void DeviceManager::OnSelectedMachineLost() {
GUI::wxGetApp().sidebar().load_ams_list(string(), nullptr);
}
bool DeviceManager::check_filaments_printable(const std::string &tag_vendor, const std::string &tag_type, int ams_id, bool &in_blacklist, std::string &ac, std::string &info)
{
DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) {
return true;
}
MachineObject *obj = dev->get_selected_machine();
if (obj == nullptr || !obj->is_multi_extruders()) {
return true;
}
Preset *printer_preset = GUI::get_printer_preset(obj);
if (!printer_preset)
return true;
ConfigOptionInts *physical_extruder_map_op = dynamic_cast<ConfigOptionInts *>(printer_preset->config.option("physical_extruder_map"));
if (!physical_extruder_map_op)
return true;
std::vector<int> physical_extruder_maps = physical_extruder_map_op->values;
ConfigOptionStrings *unprintable_filament_types_op = dynamic_cast<ConfigOptionStrings *>(printer_preset->config.option("unprintable_filament_types"));
if (unprintable_filament_types_op) {
for (size_t idx = 0; idx < unprintable_filament_types_op->values.size(); ++idx) {
if (physical_extruder_maps[idx] == obj->get_extruder_id_by_ams_id(std::to_string(ams_id))) {
std::vector<std::string> filament_types = split_string(unprintable_filament_types_op->values.at(idx), ',');
auto iter = std::find(filament_types.begin(), filament_types.end(), tag_type);
if (iter != filament_types.end()) {
wxString extruder_name = idx == 0 ? _L("left") : _L("right");
ac = "prohibition";
info = (wxString::Format(_L("%s is not supported by %s extruder."), tag_type, extruder_name)).ToUTF8().data();
in_blacklist = true;
return false;
}
}
}
}
ConfigOptionStrings *printable_filament_types_op = dynamic_cast<ConfigOptionStrings *>(printer_preset->config.option("printable_filament_types"));
if (printable_filament_types_op) {
for (size_t idx = 0; idx < printable_filament_types_op->values.size(); ++idx) {
if (physical_extruder_maps[idx] == obj->get_extruder_id_by_ams_id(std::to_string(ams_id))) {
std::vector<std::string> filament_types = split_string(printable_filament_types_op->values.at(idx), ',');
if (!filament_types.empty()) {
auto iter = std::find(filament_types.begin(), filament_types.end(), tag_type);
if (iter == filament_types.end()) {
wxString extruder_name = idx == 0 ? _L("left") : _L("right");
ac = "prohibition";
info = (wxString::Format(_L("%s is not supported by %s extruder."), tag_type, extruder_name)).ToUTF8().data();
in_blacklist = true;
return false;
}
}
}
}
}
return true;
}
void DeviceManager::check_filaments_in_blacklist(std::string model_id, std::string tag_vendor, std::string tag_type, int ams_id, int slot_id, std::string tag_name, bool& in_blacklist, std::string& ac, std::string& info)
void DeviceManager::check_filaments_in_blacklist(std::string model_id,
std::string tag_vendor,
std::string tag_type,
const std::string &filament_id,
int ams_id,
int slot_id,
std::string tag_name,
bool &in_blacklist,
std::string &ac,
std::string &info)
{
if (ams_id < 0 || slot_id < 0) {
return;
}
if (!check_filaments_printable(tag_vendor, tag_type, ams_id, in_blacklist, ac, info)) {
if (!check_filaments_printable(tag_vendor, tag_type, filament_id, ams_id, in_blacklist, ac, info)) {
return;
}

View File

@ -1488,8 +1488,7 @@ public:
static std::vector<std::string> get_resolution_supported(std::string type_str);
static std::vector<std::string> get_compatible_machine(std::string type_str);
static std::vector<std::string> get_unsupport_auto_cali_filaments(std::string type_str);
static void check_filaments_in_blacklist(std::string model_id, std::string tag_vendor, std::string tag_type, int ams_id, int slot_id, std::string tag_name, bool &in_blacklist, std::string &ac, std::string &info);
static bool check_filaments_printable(const std::string &tag_vendor, const std::string &tag_type, int ams_id, bool &in_blacklist, std::string &ac, std::string &info);
static void check_filaments_in_blacklist(std::string model_id, std::string tag_vendor, std::string tag_type, const std::string& filament_id, int ams_id, int slot_id, std::string tag_name, bool &in_blacklist, std::string &ac, std::string &info);
static boost::bimaps::bimap<std::string, std::string> get_all_model_id_with_name();
static std::string load_gcode(std::string type_str, std::string gcode_file);
static bool is_virtual_slot(int ams_id);

View File

@ -1341,40 +1341,15 @@ bool PartPlate::check_filament_printable(const DynamicPrintConfig &config, wxStr
for (auto filament_idx : used_filaments) {
int filament_id = filament_idx - 1;
std::string filament_type = config.option<ConfigOptionStrings>("filament_type")->values.at(filament_id);
int filament_printable_status = config.option<ConfigOptionInts>("filament_printable")->values.at(filament_id);
std::vector<int> filament_map = get_real_filament_maps(config);
int extruder_idx = filament_map[filament_id] - 1;
std::string filament_types_str;
auto unprintable_filament_opt = config.option<ConfigOptionStrings>("unprintable_filament_types");
if (unprintable_filament_opt) {
auto unprintable_filament_types = unprintable_filament_opt->values;
if (extruder_idx < unprintable_filament_types.size())
filament_types_str = unprintable_filament_types.at(extruder_idx);
std::vector<string> filament_types = split_string(filament_types_str, ',');
auto iter = std::find(filament_types.begin(), filament_types.end(), filament_type);
if (iter != filament_types.end()) {
if (!(filament_printable_status >> extruder_idx & 1)) {
wxString extruder_name = extruder_idx == 0 ? _L("left") : _L("right");
error_message = wxString::Format(_L("The %s nozzle can not print %s."), extruder_name, filament_type);
return false;
}
}
filament_types_str.clear();
auto printable_filament_opt = config.option<ConfigOptionStrings>("printable_filament_types");
if (printable_filament_opt) {
auto printable_filament_types = printable_filament_opt->values;
if (extruder_idx < printable_filament_types.size())
filament_types_str = printable_filament_types.at(extruder_idx);
std::vector<string> filament_types = split_string(filament_types_str, ',');
if (!filament_types.empty()) {
auto iter = std::find(filament_types.begin(), filament_types.end(), filament_type);
if (iter == filament_types.end()) {
wxString extruder_name = extruder_idx == 0 ? _L("left") : _L("right");
error_message = wxString::Format(_L("The %s nozzle can not print %s."), extruder_name, filament_type);
return false;
}
}
}
}
}
return true;
}

View File

@ -1994,7 +1994,8 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event)
std::string action;
std::string info;
DeviceManager::check_filaments_in_blacklist(obj_->printer_type, filament_brand, filament_type, ams_id, slot_id, "", in_blacklist, action, info);
DeviceManager::check_filaments_in_blacklist(obj_->printer_type, filament_brand, filament_type, m_ams_mapping_result[i].filament_id, ams_id, slot_id, "", in_blacklist,
action, info);
if (in_blacklist && action == "warning") {
wxString prohibited_error = wxString::FromUTF8(info);
@ -2072,7 +2073,7 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event)
bool in_blacklist = false;
std::string action;
std::string info;
DeviceManager::check_filaments_in_blacklist(obj_->printer_type, filament_brand, filament_type, ams_id, slot_id, "", in_blacklist, action, info);
DeviceManager::check_filaments_in_blacklist(obj_->printer_type, filament_brand, filament_type, filament_id, ams_id, slot_id, "", in_blacklist, action, info);
if (in_blacklist && action == "prohibition") {
has_prohibited_filament = true;