Passing filename to Connect PrinterPick

This commit is contained in:
David Kocik 2024-05-15 15:37:12 +02:00
parent 5e5f2c493d
commit 535ecf7b34
4 changed files with 62 additions and 31 deletions

View File

@ -6119,6 +6119,32 @@ void Plater::send_gcode()
send_gcode_inner(physical_printer_config); send_gcode_inner(physical_printer_config);
} }
std::string Plater::get_upload_filename()
{
// Obtain default output path
fs::path default_output_file;
try {
// Update the background processing, so that the placeholder parser will get the correct values for the ouput file template.
// Also if there is something wrong with the current configuration, a pop-up dialog will be shown and the export will not be performed.
unsigned int state = this->p->update_restart_background_process(false, false);
if (state & priv::UPDATE_BACKGROUND_PROCESS_INVALID)
return {};
default_output_file = this->p->background_process.output_filepath_for_project(into_path(get_project_filename(".3mf")));
}
catch (const Slic3r::PlaceholderParserError& ex) {
// Show the error with monospaced font.
show_error(this, ex.what(), true);
return {};
}
catch (const std::exception& ex) {
show_error(this, ex.what(), false);
return {};
}
default_output_file = fs::path(Slic3r::fold_utf8_to_ascii(default_output_file.string()));
return default_output_file.string();
}
void Plater::send_gcode_inner(DynamicPrintConfig* physical_printer_config) void Plater::send_gcode_inner(DynamicPrintConfig* physical_printer_config)
{ {
PrintHostJob upload_job(physical_printer_config); PrintHostJob upload_job(physical_printer_config);

View File

@ -227,6 +227,7 @@ public:
void send_gcode_inner(DynamicPrintConfig* physical_printer_config); void send_gcode_inner(DynamicPrintConfig* physical_printer_config);
void eject_drive(); void eject_drive();
void connect_gcode(); void connect_gcode();
std::string get_upload_filename();
void take_snapshot(const std::string &snapshot_name); void take_snapshot(const std::string &snapshot_name);
void take_snapshot(const wxString &snapshot_name); void take_snapshot(const wxString &snapshot_name);

View File

@ -469,12 +469,13 @@ SourceViewDialog::SourceViewDialog(wxWindow* parent, wxString source) :
ConnectRequestHandler::ConnectRequestHandler() ConnectRequestHandler::ConnectRequestHandler()
{ {
m_actions["REQUEST_ACCESS_TOKEN"] = std::bind(&ConnectRequestHandler::on_request_access_token, this); m_actions["REQUEST_ACCESS_TOKEN"] = std::bind(&ConnectRequestHandler::on_connect_action_request_access_token, this);
m_actions["REQUEST_CONFIG"] = std::bind(&ConnectRequestHandler::on_request_config, this); m_actions["REQUEST_CONFIG"] = std::bind(&ConnectRequestHandler::on_connect_action_request_config, this);
m_actions["WEBAPP_READY"] = std::bind(&ConnectRequestHandler::request_compatible_printers, this); m_actions["WEBAPP_READY"] = std::bind(&ConnectRequestHandler::on_connect_action_webapp_ready, this);
m_actions["SELECT_PRINTER"] = std::bind(&ConnectRequestHandler::on_request_select_printer, this); m_actions["SELECT_PRINTER"] = std::bind(&ConnectRequestHandler::on_connect_action_select_printer, this);
m_actions["PRINT"] = std::bind(&ConnectRequestHandler::on_request_print, this); m_actions["PRINT"] = std::bind(&ConnectRequestHandler::on_connect_action_print, this);
m_actions["REQUEST_SELECTED_PRINTER"] = std::bind(&ConnectRequestHandler::on_request_print, this); // obsolete
//m_actions["REQUEST_SELECTED_PRINTER"] = std::bind(&ConnectRequestHandler::on_connect_action_print, this);
} }
ConnectRequestHandler::~ConnectRequestHandler() ConnectRequestHandler::~ConnectRequestHandler()
{ {
@ -516,17 +517,17 @@ void ConnectRequestHandler::handle_message(const std::string& message)
void ConnectRequestHandler::resend_config() void ConnectRequestHandler::resend_config()
{ {
on_request_config(); on_connect_action_request_config();
} }
void ConnectRequestHandler::on_request_access_token() void ConnectRequestHandler::on_connect_action_request_access_token()
{ {
std::string token = wxGetApp().plater()->get_user_account()->get_access_token(); std::string token = wxGetApp().plater()->get_user_account()->get_access_token();
wxString script = GUI::format_wxstr("window._prusaConnect_v1.setAccessToken(\'%1%\')", token); wxString script = GUI::format_wxstr("window._prusaConnect_v1.setAccessToken(\'%1%\')", token);
run_script_bridge(script); run_script_bridge(script);
} }
void ConnectRequestHandler::on_request_config() void ConnectRequestHandler::on_connect_action_request_config()
{ {
/* /*
accessToken?: string; accessToken?: string;
@ -535,7 +536,6 @@ void ConnectRequestHandler::on_request_config()
language?: ConnectLanguage; language?: ConnectLanguage;
sessionId?: string; sessionId?: string;
*/ */
const std::string token = wxGetApp().plater()->get_user_account()->get_access_token(); const std::string token = wxGetApp().plater()->get_user_account()->get_access_token();
//const std::string sesh = wxGetApp().plater()->get_user_account()->get_shared_session_key(); //const std::string sesh = wxGetApp().plater()->get_user_account()->get_shared_session_key();
const std::string dark_mode = wxGetApp().dark_mode() ? "DARK" : "LIGHT"; const std::string dark_mode = wxGetApp().dark_mode() ? "DARK" : "LIGHT";
@ -569,12 +569,12 @@ void ConnectWebViewPanel::sys_color_changed()
resend_config(); resend_config();
} }
void ConnectWebViewPanel::on_request_select_printer() void ConnectWebViewPanel::on_connect_action_select_printer()
{ {
assert(!m_message_data.empty()); assert(!m_message_data.empty());
wxGetApp().handle_connect_request_printer_select(m_message_data); wxGetApp().handle_connect_request_printer_select(m_message_data);
} }
void ConnectWebViewPanel::on_request_print() void ConnectWebViewPanel::on_connect_action_print()
{ {
// PRINT request is not defined for ConnectWebViewPanel // PRINT request is not defined for ConnectWebViewPanel
assert(true); assert(true);
@ -1066,19 +1066,19 @@ void PrinterPickWebViewDialog::on_script_message(wxWebViewEvent& evt)
handle_message(into_u8(evt.GetString())); handle_message(into_u8(evt.GetString()));
} }
void PrinterPickWebViewDialog::on_request_select_printer() void PrinterPickWebViewDialog::on_connect_action_select_printer()
{ {
// SELECT_PRINTER request is not defined for PrinterPickWebViewDialog // SELECT_PRINTER request is not defined for PrinterPickWebViewDialog
assert(true); assert(true);
} }
void PrinterPickWebViewDialog::on_request_print() void PrinterPickWebViewDialog::on_connect_action_print()
{ {
m_ret_val = m_message_data; m_ret_val = m_message_data;
m_browser->RemoveScriptMessageHandler("_prusaSlicer"); m_browser->RemoveScriptMessageHandler("_prusaSlicer");
this->EndModal(wxID_OK); this->EndModal(wxID_OK);
} }
void PrinterPickWebViewDialog::request_compatible_printers() void PrinterPickWebViewDialog::on_connect_action_webapp_ready()
{ {
if (Preset::printer_technology(wxGetApp().preset_bundle->printers.get_selected_preset().config) == ptFFF) { if (Preset::printer_technology(wxGetApp().preset_bundle->printers.get_selected_preset().config) == ptFFF) {
@ -1094,6 +1094,7 @@ void PrinterPickWebViewDialog::request_compatible_printers_FFF()
//material: Material; //material: Material;
//nozzleDiameter: number; //nozzleDiameter: number;
//printerType: string; //printerType: string;
//filename: string;
//} //}
const Preset& selected_printer = wxGetApp().preset_bundle->printers.get_selected_preset(); const Preset& selected_printer = wxGetApp().preset_bundle->printers.get_selected_preset();
const Preset& selected_filament = wxGetApp().preset_bundle->filaments.get_selected_preset(); const Preset& selected_filament = wxGetApp().preset_bundle->filaments.get_selected_preset();
@ -1102,14 +1103,15 @@ void PrinterPickWebViewDialog::request_compatible_printers_FFF()
const std::string filament_type_serialized = selected_filament.config.option("filament_type")->serialize(); const std::string filament_type_serialized = selected_filament.config.option("filament_type")->serialize();
const std::string printer_model_serialized = selected_printer.config.option("printer_model")->serialize(); const std::string printer_model_serialized = selected_printer.config.option("printer_model")->serialize();
const std::string uuid = wxGetApp().plater()->get_user_account()->get_current_printer_uuid_from_connect(); const std::string uuid = wxGetApp().plater()->get_user_account()->get_current_printer_uuid_from_connect();
const std::string filename = wxGetApp().plater()->get_upload_filename();
const std::string request = GUI::format( const std::string request = GUI::format(
"{" "{"
"\"printerUuid\": \"%4%\", " "\"printerUuid\": \"%4%\", "
"\"printerModel\": \"%3%\", " "\"printerModel\": \"%3%\", "
"\"nozzleDiameter\": %2%, " "\"nozzleDiameter\": %2%, "
"\"material\": \"%1%\" " "\"material\": \"%1%\", "
"}", filament_type_serialized, nozzle_diameter_serialized, printer_model_serialized, uuid); "\"filename\": \"%5%\" "
"}", filament_type_serialized, nozzle_diameter_serialized, printer_model_serialized, uuid, filename);
wxString script = GUI::format_wxstr("window._prusaConnect_v1.requestCompatiblePrinter(%1%)", request); wxString script = GUI::format_wxstr("window._prusaConnect_v1.requestCompatiblePrinter(%1%)", request);
run_script(script); run_script(script);
@ -1121,12 +1123,14 @@ void PrinterPickWebViewDialog::request_compatible_printers_SLA()
const Preset& selected_material = wxGetApp().preset_bundle->sla_materials.get_selected_preset(); const Preset& selected_material = wxGetApp().preset_bundle->sla_materials.get_selected_preset();
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(); const std::string uuid = wxGetApp().plater()->get_user_account()->get_current_printer_uuid_from_connect();
const std::string filename = wxGetApp().plater()->get_upload_filename();
const std::string request = GUI::format( const std::string request = GUI::format(
"{" "{"
"\"printerUuid\": \"%3%\", " "\"printerUuid\": \"%3%\", "
"\"material\": \"%1%\", " "\"material\": \"%1%\", "
"\"printerModel\": \"%2%\" " "\"printerModel\": \"%2%\", "
"}", material_type_serialized, printer_model_serialized, uuid); "\"filename\": \"%4%\" "
"}", material_type_serialized, printer_model_serialized, uuid, filename);
wxString script = GUI::format_wxstr("window._prusaConnect_v1.requestCompatiblePrinter(%1%)", request); wxString script = GUI::format_wxstr("window._prusaConnect_v1.requestCompatiblePrinter(%1%)", request);
run_script(script); run_script(script);

View File

@ -164,12 +164,12 @@ public:
void resend_config(); void resend_config();
protected: protected:
// action callbacs stored in m_actions // action callbacs stored in m_actions
virtual void on_request_access_token(); virtual void on_connect_action_request_access_token();
virtual void on_request_config(); virtual void on_connect_action_request_config();
virtual void on_request_select_printer() = 0; virtual void on_connect_action_select_printer() = 0;
virtual void on_request_print() = 0; virtual void on_connect_action_print() = 0;
virtual void run_script_bridge(const wxString& script) = 0; virtual void run_script_bridge(const wxString& script) = 0;
virtual void request_compatible_printers() = 0; virtual void on_connect_action_webapp_ready() = 0;
std::map<std::string, std::function<void(void)>> m_actions; std::map<std::string, std::function<void(void)>> m_actions;
std::string m_message_data; std::string m_message_data;
@ -184,9 +184,9 @@ public:
void logout(); void logout();
void sys_color_changed() override; void sys_color_changed() override;
protected: protected:
void on_request_select_printer() override; void on_connect_action_select_printer() override;
void on_request_print() override; void on_connect_action_print() override;
void request_compatible_printers() override {} void on_connect_action_webapp_ready() override {}
void run_script_bridge(const wxString& script) override {run_script(script); } void run_script_bridge(const wxString& script) override {run_script(script); }
}; };
@ -234,9 +234,9 @@ public:
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:
void on_request_select_printer() override; void on_connect_action_select_printer() override;
void on_request_print() override; void on_connect_action_print() override;
void request_compatible_printers() override; void on_connect_action_webapp_ready() override;
void request_compatible_printers_FFF(); void request_compatible_printers_FFF();
void request_compatible_printers_SLA(); void request_compatible_printers_SLA();
void run_script_bridge(const wxString& script) override { run_script(script); } void run_script_bridge(const wxString& script) override { run_script(script); }