SPE-2676: Use correct gcode name for each bed when uploading to Connect instead of the one from Connect.

Pass changed filename from Connect.
This commit is contained in:
David Kocik 2025-02-06 16:52:50 +01:00 committed by Lukas Matena
parent 83aa5b123a
commit 4bb316eb25
4 changed files with 46 additions and 18 deletions

View File

@ -6481,11 +6481,12 @@ void Plater::printables_to_connect_gcode(const std::string& url)
} }
std::optional<PrintHostJob> Plater::get_connect_print_host_job() { std::optional<PrintHostJob> Plater::get_connect_print_host_job(bool multiple_beds)
{
assert(p->user_account->is_logged()); assert(p->user_account->is_logged());
std::string dialog_msg; std::string dialog_msg;
{ {
PrinterPickWebViewDialog dialog(this, dialog_msg); PrinterPickWebViewDialog dialog(this, dialog_msg, multiple_beds);
if (dialog.ShowModal() != wxID_OK) { if (dialog.ShowModal() != wxID_OK) {
return std::nullopt; return std::nullopt;
} }
@ -6538,13 +6539,13 @@ std::optional<PrintHostJob> Plater::get_connect_print_host_job() {
void Plater::connect_gcode() void Plater::connect_gcode()
{ {
if (auto upload_job{get_connect_print_host_job()}) { if (auto upload_job{get_connect_print_host_job(false)}) {
p->export_gcode(fs::path(), false, std::move(*upload_job)); p->export_gcode(fs::path(), false, std::move(*upload_job));
} }
} }
void Plater::connect_gcode_all() { void Plater::connect_gcode_all() {
auto optional_upload_job{get_connect_print_host_job()}; auto optional_upload_job{get_connect_print_host_job(true)};
if (!optional_upload_job) { if (!optional_upload_job) {
return; return;
} }
@ -6556,6 +6557,7 @@ void Plater::connect_gcode_all() {
if (print_host_ptr == nullptr) { if (print_host_ptr == nullptr) {
throw std::runtime_error{"Sending to connect requires PrusaConnectNew host."}; throw std::runtime_error{"Sending to connect requires PrusaConnectNew host."};
} }
const PrusaConnectNew connect{*print_host_ptr}; const PrusaConnectNew connect{*print_host_ptr};
std::vector<std::pair< int, std::optional<fs::path> >> paths; std::vector<std::pair< int, std::optional<fs::path> >> paths;
@ -6566,13 +6568,32 @@ void Plater::connect_gcode_all() {
paths.emplace_back(print_index, std::nullopt); paths.emplace_back(print_index, std::nullopt);
continue; continue;
} }
// Prevously, filename from Connect FE was taken and used for each gcode file.
// Now naming is same as in gcode export.
fs::path default_filename{upload_job_template.upload_data.upload_path};
this->with_mocked_fff_background_process(
*print,
this->p->gcode_results[print_index],
print_index,
[&](){
const auto optional_file{this->get_default_output_file()};
if (!optional_file) {
return;
}
if (print_index != s_multiple_beds.get_number_of_beds() - 1 || default_filename.empty()) {
const fs::path &default_file{*optional_file};
default_filename = default_file.filename();
}
}
);
const fs::path filename{upload_job_template.upload_data.upload_path}; const fs::path filename_fixed{
paths.emplace_back(print_index, fs::path{ default_filename.stem().string()
filename.stem().string() + "_bed"
+ "_bed" + std::to_string(print_index + 1) + std::to_string(print_index + 1)
+ filename.extension().string() + default_filename.extension().string()
}); };
paths.emplace_back(print_index, filename_fixed);
} }
BulkExportDialog dialog{paths}; BulkExportDialog dialog{paths};

View File

@ -249,7 +249,7 @@ public:
void send_gcode_inner(DynamicPrintConfig* physical_printer_config); void send_gcode_inner(DynamicPrintConfig* physical_printer_config);
void eject_drive(); void eject_drive();
std::optional<PrintHostJob> get_connect_print_host_job(); std::optional<PrintHostJob> get_connect_print_host_job(bool multiple_beds);
void connect_gcode(); void connect_gcode();
void connect_gcode_all(); void connect_gcode_all();
void printables_to_connect_gcode(const std::string& url); void printables_to_connect_gcode(const std::string& url);

View File

@ -452,13 +452,14 @@ void WebViewDialog::EndModal(int retCode)
wxDialog::EndModal(retCode); wxDialog::EndModal(retCode);
} }
PrinterPickWebViewDialog::PrinterPickWebViewDialog(wxWindow* parent, std::string& ret_val) PrinterPickWebViewDialog::PrinterPickWebViewDialog(wxWindow* parent, std::string& ret_val, bool multiple_beds)
: WebViewDialog(parent : WebViewDialog(parent
, GUI::from_u8(Utils::ServiceConfig::instance().connect_select_printer_url()) , GUI::from_u8(Utils::ServiceConfig::instance().connect_select_printer_url())
, _L("Choose a printer") , _L("Choose a printer")
, wxSize(parent->GetClientSize().x / 4 * 3, parent->GetClientSize().y/ 4 * 3) , wxSize(parent->GetClientSize().x / 4 * 3, parent->GetClientSize().y/ 4 * 3)
,{"_prusaSlicer"} ,{"_prusaSlicer"}
, "connect_loading") , "connect_loading")
, m_multiple_beds(multiple_beds)
, m_ret_val(ret_val) , m_ret_val(ret_val)
{ {
@ -580,7 +581,9 @@ void PrinterPickWebViewDialog::request_compatible_printers_FFF() {
const std::string uuid = wxGetApp().plater()->get_user_account()->get_current_printer_uuid_from_connect(printer_model_serialized); const std::string uuid = wxGetApp().plater()->get_user_account()->get_current_printer_uuid_from_connect(printer_model_serialized);
const std::string filename = wxGetApp().plater()->get_upload_filename(); const std::string filename = wxGetApp().plater()->get_upload_filename();
//filament_abrasive
const std::string multiple_beds_value = m_multiple_beds ? "true" : "false";
std::string request = GUI::format( std::string request = GUI::format(
"{" "{"
"\"printerUuid\": \"%4%\", " "\"printerUuid\": \"%4%\", "
@ -589,9 +592,10 @@ void PrinterPickWebViewDialog::request_compatible_printers_FFF() {
"\"material\": %1%, " "\"material\": %1%, "
"\"filename\": \"%5%\", " "\"filename\": \"%5%\", "
"\"filament_abrasive\": %6%," "\"filament_abrasive\": %6%,"
"\"high_flow\": %7%" "\"high_flow\": %7%,"
"\"multiple_beds\": %8%"
"}" "}"
, filament_type_serialized, nozzle_diameter_serialized, printer_model_serialized, uuid, filename, filament_abrasive_serialized, nozzle_high_flow_serialized); , filament_type_serialized, nozzle_diameter_serialized, printer_model_serialized, uuid, filename, filament_abrasive_serialized, nozzle_high_flow_serialized, multiple_beds_value);
wxString script = GUI::format_wxstr("window._prusaConnect_v2.requestCompatiblePrinter(%1%)", request); wxString script = GUI::format_wxstr("window._prusaConnect_v2.requestCompatiblePrinter(%1%)", request);
run_script(script); run_script(script);
@ -609,13 +613,15 @@ void PrinterPickWebViewDialog::request_compatible_printers_SLA()
const std::string material_type_serialized = selected_material.config.option("material_type")->serialize(); const std::string material_type_serialized = selected_material.config.option("material_type")->serialize();
const std::string uuid = wxGetApp().plater()->get_user_account()->get_current_printer_uuid_from_connect(printer_model_serialized); const std::string uuid = wxGetApp().plater()->get_user_account()->get_current_printer_uuid_from_connect(printer_model_serialized);
const std::string filename = wxGetApp().plater()->get_upload_filename(); const std::string filename = wxGetApp().plater()->get_upload_filename();
const std::string multiple_beds_value = m_multiple_beds ? "true" : "false";
const std::string request = GUI::format( const std::string request = GUI::format(
"{" "{"
"\"printerUuid\": \"%3%\", " "\"printerUuid\": \"%3%\", "
"\"material\": \"%1%\", " "\"material\": \"%1%\", "
"\"printerModel\": \"%2%\", " "\"printerModel\": \"%2%\", "
"\"filename\": \"%4%\" " "\"filename\": \"%4%\", "
"}", material_type_serialized, printer_model_serialized, uuid, filename); "\"multiple_beds\": \"%5%\" "
"}", material_type_serialized, printer_model_serialized, uuid, filename, multiple_beds_value);
wxString script = GUI::format_wxstr("window._prusaConnect_v2.requestCompatiblePrinter(%1%)", request); wxString script = GUI::format_wxstr("window._prusaConnect_v2.requestCompatiblePrinter(%1%)", request);
run_script(script); run_script(script);

View File

@ -95,7 +95,7 @@ protected:
class PrinterPickWebViewDialog : public WebViewDialog, public ConnectRequestHandler class PrinterPickWebViewDialog : public WebViewDialog, public ConnectRequestHandler
{ {
public: public:
PrinterPickWebViewDialog(wxWindow* parent, std::string& ret_val); PrinterPickWebViewDialog(wxWindow* parent, std::string& ret_val, bool multiple_beds);
void on_show(wxShowEvent& evt) override; void on_show(wxShowEvent& evt) override;
void on_script_message(wxWebViewEvent& evt) override; void on_script_message(wxWebViewEvent& evt) override;
protected: protected:
@ -110,6 +110,7 @@ protected:
void on_connect_action_close_dialog(const std::string& message_data) override {assert(false);} void on_connect_action_close_dialog(const std::string& message_data) override {assert(false);}
private: private:
std::string& m_ret_val; std::string& m_ret_val;
bool m_multiple_beds;
}; };
class PrintablesConnectUploadDialog : public WebViewDialog, public ConnectRequestHandler class PrintablesConnectUploadDialog : public WebViewDialog, public ConnectRequestHandler