Support upload g-code to third-party printers (#2)

* wip

* fix cmake warning

* add UI and config options for Moonraker connection

* wip: copy whole print host UI from PS

* add more needed options

* wip 2

* fix string issue on Mac

* wip3
This commit is contained in:
SoftFever 2022-08-20 15:09:05 +08:00 committed by GitHub
parent 159ff850e4
commit dc5e0eed34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 5543 additions and 19 deletions

View file

@ -90,7 +90,7 @@ PresetBundle::PresetBundle()
for (size_t i = 0; i < 1; ++i) {
// The following ugly switch is to avoid printers.preset(0) to return the edited instance, as the 0th default is the current one.
Preset &preset = this->printers.default_preset(i);
for (const char *key : {"printer_settings_id", "printer_model", "printer_variant"}) preset.config.optptr(key, true);
for (const char *key : {"printer_settings_id", "printer_model", "printer_variant","physical_printer_settings_id"}) preset.config.optptr(key, true);
//if (i == 0) {
preset.config.optptr("default_print_profile", true);
preset.config.option<ConfigOptionStrings>("default_filament_profile", true);
@ -268,6 +268,11 @@ PresetsConfigSubstitutions PresetBundle::load_presets(AppConfig &config, Forward
} catch (const std::runtime_error &err) {
errors_cummulative += err.what();
}
try {
this->physical_printers.load_printers(dir_user_presets, "physical_printer", substitutions, substitution_rule);
} catch (const std::runtime_error &err) {
errors_cummulative += err.what();
}
this->update_multi_material_filament_presets();
this->update_compatible(PresetSelectCompatibleType::Never);
if (! errors_cummulative.empty())
@ -532,7 +537,7 @@ PresetsConfigSubstitutions PresetBundle::load_user_presets(AppConfig &config, st
// First load the vendor specific system presets.
PresetsConfigSubstitutions substitutions;
std::string errors_cummulative;
bool process_added = false, filament_added = false, machine_added = false;
bool process_added = false, filament_added = false, machine_added = false, physical_printer_added = false;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" enter, substitution_rule %1%, preset toltal count %2%")%substitution_rule%my_presets.size();
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" print's selected_idx %1%, selected_name %2%") %prints.get_selected_idx() %prints.get_selected_preset_name();
@ -562,6 +567,11 @@ PresetsConfigSubstitutions PresetBundle::load_user_presets(AppConfig &config, st
preset_collection = &(this->printers);
machine_added |= preset_collection->load_user_preset(name, value_map, substitutions, substitution_rule);
}
else if(type_iter->second == PRESET_IOT_PHYSICAL_PRINTER_TYPE){
preset_collection = &(this->printers);
physical_printer_added |= preset_collection->load_user_preset(name, value_map, substitutions, substitution_rule);
}
else {
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format("invalid type %1% for setting %2%") %type_iter->second %name;
continue;
@ -645,9 +655,6 @@ void PresetBundle::update_system_preset_setting_ids(std::map<std::string, std::m
else if (type_iter->second == PRESET_IOT_PRINTER_TYPE) {
preset_collection = &(this->printers);
}
else if (type_iter->second == PRESET_IOT_PRINTER_TYPE) {
preset_collection = &(this->printers);
}
else {
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format("invalid type %1% for setting %2%") %type_iter->second %name;
continue;
@ -680,7 +687,7 @@ void PresetBundle::update_system_preset_setting_ids(std::map<std::string, std::m
bool PresetBundle::validate_printers(const std::string &name, DynamicPrintConfig& config)
{
// BBS TODO:
#if 0
#if 1
std::vector<std::string> inherits_values;
PrinterTechnology printer_technology = Preset::printer_technology(config);
size_t num_extruders = (printer_technology == ptFFF) ?
@ -1177,7 +1184,7 @@ void PresetBundle::export_selections(AppConfig &config)
// BBS
//config.set("presets", "sla_print", sla_prints.get_selected_preset_name());
//config.set("presets", "sla_material", sla_materials.get_selected_preset_name());
//config.set("presets", "physical_printer", physical_printers.get_selected_full_printer_name());
config.set("presets", "physical_printer", physical_printers.get_selected_full_printer_name());
//BBS: add config related log
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": printer %1%, print %2%, filaments[0] %3% ")%printers.get_selected_preset_name() % prints.get_selected_preset_name() %filament_presets[0];
}
@ -1245,13 +1252,15 @@ DynamicPrintConfig PresetBundle::full_config() const
DynamicPrintConfig PresetBundle::full_config_secure() const
{
DynamicPrintConfig config = this->full_config();
//BBS example: config.erase("print_host");
return config;
//FIXME legacy, the keys should not be there after conversion to a Physical Printer profile.
config.erase("print_host");
config.erase("printhost_apikey");
config.erase("printhost_cafile"); return config;
}
const std::set<std::string> ignore_settings_list ={
"inherits",
"print_settings_id", "filament_settings_id", "printer_settings_id"
"print_settings_id", "filament_settings_id", "printer_settings_id","physical_printer_settings_id"
};
DynamicPrintConfig PresetBundle::full_fff_config() const
@ -1432,6 +1441,7 @@ DynamicPrintConfig PresetBundle::full_fff_config() const
out.option<ConfigOptionStrings>("filament_settings_id", true)->values = this->filament_presets;
out.option<ConfigOptionString >("printer_settings_id", true)->value = this->printers.get_selected_preset_name();
out.option<ConfigOptionStrings>("filament_ids", true)->values = filament_ids;
// out.option<ConfigOptionString >("physical_printer_settings_id", true)->value = this->physical_printers.get_selected_printer_preset_name();
// Serialize the collected "compatible_printers_condition" and "inherits" fields.
// There will be 1 + num_exturders fields for "inherits" and 2 + num_extruders for "compatible_printers_condition" stored.
// The vector will not be stored if all fields are empty strings.
@ -1810,8 +1820,7 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
this->update_compatible(PresetSelectCompatibleType::Never);
//BBS
//const std::string &physical_printer = config.option<ConfigOptionString>("physical_printer_settings_id", true)->value;
const std::string physical_printer;
const std::string &physical_printer = config.option<ConfigOptionString>("physical_printer_settings_id", true)->value;
if (this->printers.get_edited_preset().is_external || physical_printer.empty()) {
this->physical_printers.unselect_printer();
} else {