Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various improvements to SimplyPrint integration #4831

Merged
merged 25 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
37ed6fc
Allow using BBL's device tab when 3rd party print host is used
Noisyfox Apr 1, 2024
ca11e8d
Add option to open SimplyPrint panel in device tab after uploading
Noisyfox Apr 1, 2024
674b2b3
Fix default print host for prusa connect
Noisyfox Apr 1, 2024
a7ed530
Do not set api key in device view when SimplyPrint is used
Noisyfox Apr 1, 2024
79e7c10
Sending 3mf file to SimplyPrint when using BBL printers
Noisyfox Apr 1, 2024
7f4fda2
Fix file extension when uploading 3mf
Noisyfox Apr 1, 2024
88a93f3
Prepare for large file uploading
Noisyfox Apr 5, 2024
1994118
Implement chunk upload
Noisyfox Apr 5, 2024
612ed77
Fix file uploading exceeding content size
Noisyfox Apr 9, 2024
995731e
Fix wrong field type
Noisyfox Apr 9, 2024
3630ad7
Add `temp=true` to all chunk upload calls
Noisyfox Apr 9, 2024
d9e2973
Add macro to enable test api
Noisyfox Apr 9, 2024
8ff0ff8
Merge branch 'main' into dev/simplyprint-improve
Noisyfox Apr 9, 2024
de1bc99
Fix another missing `temp=true`
Noisyfox Apr 9, 2024
b9ffa5b
Add delete token
Noisyfox Apr 10, 2024
0ccbb48
Try fixing build error on *nix systems
Noisyfox Apr 10, 2024
026e606
Merge branch 'main' into dev/simplyprint-improve
SoftFever Apr 15, 2024
aecff2c
Merge branch 'main' into dev/simplyprint-improve
Noisyfox Apr 19, 2024
0307bfb
Merge remote-tracking branch 'remote/main' into dev/simplyprint-improve
Noisyfox Apr 28, 2024
168dad8
Move the `bbl_use_print_host_webui` option to print host dialog. Also…
Noisyfox Apr 28, 2024
ea295d9
Merge branch 'main' into dev/simplyprint-improve
Noisyfox May 4, 2024
3b4ec68
Merge branch 'main' into dev/simplyprint-improve
Noisyfox Jun 18, 2024
25a51b5
Use a more generic option instead of SimplyPrint specific
Noisyfox Jun 18, 2024
4190b8f
Merge branch 'main' into dev/simplyprint-improve
SoftFever Jun 21, 2024
3e5590c
Merge branch 'main' into dev/simplyprint-improve
SoftFever Jun 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/libslic3r/Preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ static std::vector<std::string> s_Preset_printer_options {
"best_object_pos","head_wrap_detect_zone",
//SoftFever
"host_type", "print_host", "printhost_apikey", "bbl_use_printhost",
"print_host_webui",
"print_host_webui", "bbl_use_print_host_webui", "simplyprint_post_upload_action",
Noisyfox marked this conversation as resolved.
Show resolved Hide resolved
"printhost_cafile","printhost_port","printhost_authorization_type",
"printhost_user", "printhost_password", "printhost_ssl_ignore_revoke", "thumbnails", "thumbnails_format",
"use_firmware_retraction", "use_relative_e_distances", "printer_notes",
Expand Down Expand Up @@ -3022,6 +3022,8 @@ static std::vector<std::string> s_PhysicalPrinter_opts {
"host_type",
"print_host",
"print_host_webui",
"bbl_use_print_host_webui",
"simplyprint_post_upload_action",
"printhost_apikey",
"printhost_cafile",
"printhost_port",
Expand Down
13 changes: 13 additions & 0 deletions src/libslic3r/PresetBundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,19 @@ bool PresetBundle::use_bbl_network()
return use_bbl_network;
}

bool PresetBundle::use_bbl_device_tab() {
if (!is_bbl_vendor()) {
return false;
}

if (use_bbl_network()) {
return true;
}

const auto cfg = printers.get_edited_preset().config;
return !cfg.opt_bool("bbl_use_print_host_webui");
}

//BBS: load project embedded presets
PresetsConfigSubstitutions PresetBundle::load_project_embedded_presets(std::vector<Preset*> project_presets, ForwardCompatibilitySubstitutionRule substitution_rule)
{
Expand Down
3 changes: 3 additions & 0 deletions src/libslic3r/PresetBundle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ class PresetBundle
VendorType get_current_vendor_type();
// Vendor related handy functions
bool is_bbl_vendor() { return get_current_vendor_type() == VendorType::Marlin_BBL; }
// Whether using bbl network for print upload
bool use_bbl_network();
// Whether using bbl's device tab
bool use_bbl_device_tab();

//BBS: project embedded preset logic
PresetsConfigSubstitutions load_project_embedded_presets(std::vector<Preset*> project_presets, ForwardCompatibilitySubstitutionRule substitution_rule);
Expand Down
24 changes: 24 additions & 0 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ static t_config_enum_values s_keys_map_PrintHostType {
};
CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(PrintHostType)

static t_config_enum_values s_keys_map_SimplyPrintPostUploadAction{
{ "external", int(SimplyPrintPostUploadAction::OpenExternalBrowser) },
{ "device", int(SimplyPrintPostUploadAction::SwitchToDeviceTab) },
};
CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(SimplyPrintPostUploadAction)

static t_config_enum_values s_keys_map_AuthorizationType {
{ "key", atKeyPassword },
{ "user", atUserPassword }
Expand Down Expand Up @@ -567,6 +573,24 @@ void PrintConfigDef::init_common_params()
def->cli = ConfigOptionDef::nocli;
def->set_default_value(new ConfigOptionString(""));

def = this->add("bbl_use_print_host_webui", coBool);
def->label = L("View print host webui in Device tab");
def->tooltip = L("Replace the BambuLab's device tab with print host webui");
def->mode = comAdvanced;
def->cli = ConfigOptionDef::nocli;
def->set_default_value(new ConfigOptionBool(false));

def = this->add("simplyprint_post_upload_action", coEnum);
def->label = L("Send exported prints to SimplyPrint in");
def->tooltip = L("After uploading the print to SimplyPrint, whether open the SimplyPrint panel in external browser or directly in the device tab");
def->enum_keys_map = &ConfigOptionEnum<SimplyPrintPostUploadAction>::get_enum_values();
def->enum_values.push_back("external");
def->enum_values.push_back("device");
def->enum_labels.push_back(L("External browser"));
def->enum_labels.push_back(L("Device tab"));
def->mode = comAdvanced;
def->cli = ConfigOptionDef::nocli;
def->set_default_value(new ConfigOptionEnum<SimplyPrintPostUploadAction>(SimplyPrintPostUploadAction::OpenExternalBrowser));

def = this->add("printhost_apikey", coString);
def->label = L("API Key / Password");
Expand Down
7 changes: 7 additions & 0 deletions src/libslic3r/PrintConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ enum PrintHostType {
htPrusaLink, htPrusaConnect, htOctoPrint, htDuet, htFlashAir, htAstroBox, htRepetier, htMKS, htObico, htFlashforge, htSimplyPrint
};

enum class SimplyPrintPostUploadAction
{
OpenExternalBrowser,
SwitchToDeviceTab,
};

enum AuthorizationType {
atKeyPassword, atUserPassword
};
Expand Down Expand Up @@ -415,6 +421,7 @@ CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(ForwardCompatibilitySubstitutionRule)
CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(GCodeThumbnailsFormat)
CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(CounterboreHoleBridgingOption)
CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(PrintHostType)
CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(SimplyPrintPostUploadAction)
CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(AuthorizationType)
CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(PerimeterGeneratorType)
#undef CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS
Expand Down
26 changes: 15 additions & 11 deletions src/slic3r/GUI/BackgroundSlicingProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,17 +841,21 @@ void BackgroundSlicingProcess::prepare_upload()
/ boost::filesystem::unique_path("." SLIC3R_APP_KEY ".upload.%%%%-%%%%-%%%%-%%%%");

if (m_print == m_fff_print) {
m_print->set_status(95, _utf8(L("Running post-processing scripts")));
std::string error_message;
if (copy_file(m_temp_output_path, source_path.string(), error_message) != SUCCESS)
throw Slic3r::RuntimeError(_utf8(L("Copying of the temporary G-code to the output G-code failed")));
m_upload_job.upload_data.upload_path = m_fff_print->print_statistics().finalize_output_path(m_upload_job.upload_data.upload_path.string());
// Make a copy of the source path, as run_post_process_scripts() is allowed to change it when making a copy of the source file
// (not here, but when the final target is a file).
std::string source_path_str = source_path.string();
std::string output_name_str = m_upload_job.upload_data.upload_path.string();
if (run_post_process_scripts(source_path_str, false, m_upload_job.printhost->get_name(), output_name_str, m_fff_print->full_print_config()))
m_upload_job.upload_data.upload_path = output_name_str;
if (m_upload_job.upload_data.use_3mf) {
source_path = m_upload_job.upload_data.source_path;
} else {
m_print->set_status(95, _utf8(L("Running post-processing scripts")));
std::string error_message;
if (copy_file(m_temp_output_path, source_path.string(), error_message) != SUCCESS)
throw Slic3r::RuntimeError(_utf8(L("Copying of the temporary G-code to the output G-code failed")));
m_upload_job.upload_data.upload_path = m_fff_print->print_statistics().finalize_output_path(m_upload_job.upload_data.upload_path.string());
// Make a copy of the source path, as run_post_process_scripts() is allowed to change it when making a copy of the source file
// (not here, but when the final target is a file).
std::string source_path_str = source_path.string();
std::string output_name_str = m_upload_job.upload_data.upload_path.string();
if (run_post_process_scripts(source_path_str, false, m_upload_job.printhost->get_name(), output_name_str, m_fff_print->full_print_config()))
m_upload_job.upload_data.upload_path = output_name_str;
}
} else {
m_upload_job.upload_data.upload_path = m_sla_print->print_statistics().finalize_output_path(m_upload_job.upload_data.upload_path.string());

Expand Down
37 changes: 30 additions & 7 deletions src/slic3r/GUI/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,7 @@ wxBoxSizer* MainFrame::create_side_tools()
SidePopup* p = new SidePopup(this);

if (wxGetApp().preset_bundle
&& !wxGetApp().preset_bundle->use_bbl_network()) {
&& !wxGetApp().preset_bundle->is_bbl_vendor()) {
// ThirdParty Buttons
SideButton* export_gcode_btn = new SideButton(p, _L("Export G-code file"), "");
export_gcode_btn->SetCornerRadius(0);
Expand Down Expand Up @@ -1712,9 +1712,32 @@ wxBoxSizer* MainFrame::create_side_tools()
p->Dismiss();
});
p->append_button(print_plate_btn);
p->append_button(print_all_btn);
p->append_button(send_to_printer_btn);
p->append_button(send_to_printer_all_btn);

bool support_send = true;
bool support_print_all = true;

const auto preset_bundle = wxGetApp().preset_bundle;
if (preset_bundle) {
if (preset_bundle->use_bbl_network()) {
// BBL network support everything
} else {
support_send = false; // All 3rd print hosts do not have the send options

auto cfg = preset_bundle->printers.get_edited_preset().config;
const auto host_type = cfg.option<ConfigOptionEnum<PrintHostType>>("host_type")->value;

// Only simply print support uploading all plates
support_print_all = host_type == PrintHostType::htSimplyPrint;
}
}

if (support_print_all) {
p->append_button(print_all_btn);
}
if (support_send) {
p->append_button(send_to_printer_btn);
p->append_button(send_to_printer_all_btn);
}
p->append_button(export_sliced_file_btn);
p->append_button(export_all_sliced_file_btn);
p->append_button(export_gcode_btn);
Expand Down Expand Up @@ -3587,14 +3610,14 @@ void MainFrame::load_printer_url(wxString url, wxString apikey)
void MainFrame::load_printer_url()
{
PresetBundle &preset_bundle = *wxGetApp().preset_bundle;
if (preset_bundle.use_bbl_network())
if (preset_bundle.use_bbl_device_tab())
return;

auto cfg = preset_bundle.printers.get_edited_preset().config;
wxString url = cfg.opt_string("print_host_webui").empty() ? cfg.opt_string("print_host") : cfg.opt_string("print_host_webui");
wxString apikey;
if (cfg.has("printhost_apikey") && (cfg.option<ConfigOptionEnum<PrintHostType>>("host_type")->value == htPrusaLink ||
cfg.option<ConfigOptionEnum<PrintHostType>>("host_type")->value == htPrusaConnect))
const auto host_type = cfg.option<ConfigOptionEnum<PrintHostType>>("host_type")->value;
if (cfg.has("printhost_apikey") && (host_type == htPrusaLink || host_type == htPrusaConnect))
apikey = cfg.opt_string("printhost_apikey");
if (!url.empty()) {
if (!url.Lower().starts_with("http"))
Expand Down
9 changes: 9 additions & 0 deletions src/slic3r/GUI/PhysicalPrinterDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr
option.opt.width = Field::def_width_wider();
m_optgroup->append_single_option_line(option);

m_optgroup->append_single_option_line("simplyprint_post_upload_action");

m_optgroup->append_single_option_line("printhost_authorization_type");

option = m_optgroup->get_option("printhost_apikey");
Expand Down Expand Up @@ -510,6 +512,8 @@ void PhysicalPrinterDialog::update(bool printer_change)
if (m_printhost_cafile_browse_btn)
m_printhost_cafile_browse_btn->Enable();

m_optgroup->hide_field("simplyprint_post_upload_action");

// hide pre-configured address, in case user switched to a different host type
if (Field* printhost_field = m_optgroup->get_field("print_host"); printhost_field) {
if (wxTextCtrl* temp = dynamic_cast<TextCtrl*>(printhost_field)->text_ctrl(); temp) {
Expand Down Expand Up @@ -548,6 +552,7 @@ void PhysicalPrinterDialog::update(bool printer_change)
if (Field* printhost_field = m_optgroup->get_field("print_host"); printhost_field) {
if (wxTextCtrl* temp = dynamic_cast<TextCtrl*>(printhost_field)->text_ctrl(); temp && temp->GetValue().IsEmpty()) {
temp->SetValue(L"https://connect.prusa3d.com");
m_config->opt_string("print_host") = "https://connect.prusa3d.com";
}
}
} else if (opt->value == htObico) { // automatically show default obico address
Expand Down Expand Up @@ -578,6 +583,10 @@ void PhysicalPrinterDialog::update(bool printer_change)
m_optgroup->disable_field("printhost_ssl_ignore_revoke");
if (m_printhost_cafile_browse_btn)
m_printhost_cafile_browse_btn->Disable();

if (!wxGetApp().preset_bundle->use_bbl_device_tab()) {
m_optgroup->show_field("simplyprint_post_upload_action");
}
}
}

Expand Down
68 changes: 49 additions & 19 deletions src/slic3r/GUI/Plater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1167,14 +1167,13 @@ void Sidebar::update_all_preset_comboboxes()
const auto print_tech = preset_bundle.printers.get_edited_preset().printer_technology();

bool is_bbl_vendor = preset_bundle.is_bbl_vendor();
const bool use_bbl_network = preset_bundle.use_bbl_network();

// Orca:: show device tab based on vendor type
auto p_mainframe = wxGetApp().mainframe;
p_mainframe->show_device(use_bbl_network);
p_mainframe->show_device(preset_bundle.use_bbl_device_tab());
auto cfg = preset_bundle.printers.get_edited_preset().config;

if (use_bbl_network) {
if (preset_bundle.use_bbl_network()) {
//only show connection button for not-BBL printer
connection_btn->Hide();
//only show sync-ams button for BBL printer
Expand All @@ -1192,9 +1191,10 @@ void Sidebar::update_all_preset_comboboxes()
else {
if (!url.Lower().starts_with("http"))
url = wxString::Format("http://%s", url);
if (cfg.has("printhost_apikey"))
const auto host_type = cfg.option<ConfigOptionEnum<PrintHostType>>("host_type")->value;
if (cfg.has("printhost_apikey") && (host_type != htSimplyPrint))
apikey = cfg.opt_string("printhost_apikey");
print_btn_type = MainFrame::PrintSelectType::eSendGcode;
print_btn_type = preset_bundle.is_bbl_vendor() ? MainFrame::PrintSelectType::ePrintPlate : MainFrame::PrintSelectType::eSendGcode;
}

p_mainframe->load_printer_url(url, apikey);
Expand Down Expand Up @@ -6949,12 +6949,18 @@ void Plater::priv::on_action_print_plate(SimpleEvent&)
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received print plate event\n" ;
}

//BBS
if (!m_select_machine_dlg) m_select_machine_dlg = new SelectMachineDialog(q);
m_select_machine_dlg->set_print_type(PrintFromType::FROM_NORMAL);
m_select_machine_dlg->prepare(partplate_list.get_curr_plate_index());
m_select_machine_dlg->ShowModal();
record_start_print_preset("print_plate");
PresetBundle& preset_bundle = *wxGetApp().preset_bundle;
if (preset_bundle.use_bbl_network()) {
// BBS
if (!m_select_machine_dlg)
m_select_machine_dlg = new SelectMachineDialog(q);
m_select_machine_dlg->set_print_type(PrintFromType::FROM_NORMAL);
m_select_machine_dlg->prepare(partplate_list.get_curr_plate_index());
m_select_machine_dlg->ShowModal();
record_start_print_preset("print_plate");
} else {
q->send_gcode_legacy(PLATE_CURRENT_IDX, nullptr, true);
}
}

void Plater::priv::on_action_print_plate_from_sdcard(SimpleEvent&)
Expand All @@ -6976,7 +6982,7 @@ void Plater::priv::on_tab_selection_changing(wxBookCtrlEvent& e)
sidebar_layout.show = new_sel == MainFrame::tp3DEditor || new_sel == MainFrame::tpPreview;
update_sidebar();
int old_sel = e.GetOldSelection();
if (wxGetApp().preset_bundle && wxGetApp().preset_bundle->use_bbl_network() && new_sel == MainFrame::tpMonitor) {
if (wxGetApp().preset_bundle && wxGetApp().preset_bundle->use_bbl_device_tab() && new_sel == MainFrame::tpMonitor) {
if (!wxGetApp().getAgent()) {
e.Veto();
BOOST_LOG_TRIVIAL(info) << boost::format("skipped tab switch from %1% to %2%, lack of network plugins") % old_sel % new_sel;
Expand Down Expand Up @@ -7030,12 +7036,18 @@ void Plater::priv::on_action_print_all(SimpleEvent&)
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received print all event\n" ;
}

//BBS
if (!m_select_machine_dlg) m_select_machine_dlg = new SelectMachineDialog(q);
m_select_machine_dlg->set_print_type(PrintFromType::FROM_NORMAL);
m_select_machine_dlg->prepare(PLATE_ALL_IDX);
m_select_machine_dlg->ShowModal();
record_start_print_preset("print_all");
PresetBundle& preset_bundle = *wxGetApp().preset_bundle;
if (preset_bundle.use_bbl_network()) {
// BBS
if (!m_select_machine_dlg)
m_select_machine_dlg = new SelectMachineDialog(q);
m_select_machine_dlg->set_print_type(PrintFromType::FROM_NORMAL);
m_select_machine_dlg->prepare(PLATE_ALL_IDX);
m_select_machine_dlg->ShowModal();
record_start_print_preset("print_all");
} else {
q->send_gcode_legacy(PLATE_ALL_IDX, nullptr, true);
}
}

void Plater::priv::on_action_export_gcode(SimpleEvent&)
Expand Down Expand Up @@ -11908,7 +11920,7 @@ void Plater::reslice_SLA_until_step(SLAPrintObjectStep step, const ModelObject &
// and let the background processing start.
this->p->restart_background_process(state | priv::UPDATE_BACKGROUND_PROCESS_FORCE_RESTART);
}
void Plater::send_gcode_legacy(int plate_idx, Export3mfProgressFn proFn)
void Plater::send_gcode_legacy(int plate_idx, Export3mfProgressFn proFn, bool use_3mf)
{
// if physical_printer is selected, send gcode for this printer
// DynamicPrintConfig* physical_printer_config = wxGetApp().preset_bundle->physical_printers.get_selected_printer_config();
Expand All @@ -11920,6 +11932,8 @@ void Plater::send_gcode_legacy(int plate_idx, Export3mfProgressFn proFn)
if (upload_job.empty())
return;

upload_job.upload_data.use_3mf = use_3mf;

// Obtain default output path
fs::path default_output_file;
try {
Expand All @@ -11938,6 +11952,9 @@ void Plater::send_gcode_legacy(int plate_idx, Export3mfProgressFn proFn)
return;
}
default_output_file = fs::path(Slic3r::fold_utf8_to_ascii(default_output_file.string()));
if (use_3mf) {
default_output_file.replace_extension("3mf");
}

// Repetier specific: Query the server for the list of file groups.
wxArrayString groups;
Expand Down Expand Up @@ -11973,6 +11990,19 @@ void Plater::send_gcode_legacy(int plate_idx, Export3mfProgressFn proFn)
return;
}

if (use_3mf) {
// Process gcode
const int result = send_gcode(plate_idx, nullptr);

if (result < 0) {
wxString msg = _L("Abnormal print file data. Please slice again");
show_error(this, msg, false);
return;
}

upload_job.upload_data.source_path = p->m_print_job_data._3mf_path;
}

p->export_gcode(fs::path(), false, std::move(upload_job));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/Plater.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ class Plater: public wxPanel
/* -1: send current gcode if not specified
* -2: send all gcode to target machine */
int send_gcode(int plate_idx = -1, Export3mfProgressFn proFn = nullptr);
void send_gcode_legacy(int plate_idx = -1, Export3mfProgressFn proFn = nullptr);
void send_gcode_legacy(int plate_idx = -1, Export3mfProgressFn proFn = nullptr, bool use_3mf = false);
int export_config_3mf(int plate_idx = -1, Export3mfProgressFn proFn = nullptr);
//BBS jump to nonitor after print job finished
void send_calibration_job_finished(wxCommandEvent &evt);
Expand Down
Loading
Loading