NEW:support sending 3mf to farm software

jira:[none]

Change-Id: I16874751acdaba78194fb597bb6e5bb0a18bc7d7
This commit is contained in:
tao wang 2024-11-27 17:21:33 +08:00 committed by Lane.Wei
parent 4905afe6c2
commit 793a8e22fa
5 changed files with 73 additions and 1 deletions

View File

@ -32,6 +32,7 @@ wxDEFINE_EVENT(EVT_GLTOOLBAR_PRINT_SELECT, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_SEND_TO_PRINTER, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_SEND_TO_PRINTER_ALL, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_PRINT_MULTI_MACHINE, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_SEND_MULTI_APP, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_ADD, SimpleEvent);

View File

@ -33,6 +33,7 @@ wxDECLARE_EVENT(EVT_GLTOOLBAR_PRINT_SELECT, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_SEND_TO_PRINTER, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_SEND_TO_PRINTER_ALL, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_PRINT_MULTI_MACHINE, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_SEND_MULTI_APP, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_ADD, SimpleEvent);

View File

@ -1639,6 +1639,8 @@ wxBoxSizer* MainFrame::create_side_tools()
wxPostEvent(m_plater, SimpleEvent(EVT_GLTOOLBAR_SEND_TO_PRINTER));
else if (m_print_select == eSendToPrinterAll)
wxPostEvent(m_plater, SimpleEvent(EVT_GLTOOLBAR_SEND_TO_PRINTER_ALL));
else if (m_print_select == eSendMultiApp)
wxPostEvent(m_plater, SimpleEvent(EVT_GLTOOLBAR_SEND_MULTI_APP));
/* else if (m_print_select == ePrintMultiMachine)
wxPostEvent(m_plater, SimpleEvent(EVT_GLTOOLBAR_PRINT_MULTI_MACHINE));*/
});
@ -1792,12 +1794,24 @@ wxBoxSizer* MainFrame::create_side_tools()
p->Dismiss();
});
SideButton *send_to_multi_app_btn = new SideButton(p, _L("Send to Bambu Farm Manager Client"), "");
send_to_multi_app_btn->SetCornerRadius(0);
send_to_multi_app_btn->Bind(wxEVT_BUTTON, [this, p](wxCommandEvent &) {
m_print_btn->SetLabel(_L("Send to BFMC"));
m_print_select = eSendMultiApp;
m_print_enable = get_enable_print_status();
m_print_btn->Enable(m_print_enable);
this->Layout();
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);
p->append_button(export_sliced_file_btn);
p->append_button(export_all_sliced_file_btn);
p->append_button(send_to_multi_app_btn);
if (enable_multi_machine) {
SideButton* print_multi_machine_btn = new SideButton(p, _L("Send to Multi-device"), "");
print_multi_machine_btn->SetCornerRadius(0);
@ -1959,6 +1973,11 @@ bool MainFrame::get_enable_print_status()
enable = false;
}
enable = enable && !is_all_plates;
}else if (m_print_select == eSendMultiApp) {
if (!current_plate->is_slice_result_ready_for_print()) {
enable = false;
}
enable = enable && !is_all_plates;
}
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": m_print_select %1%, enable= %2% ")%m_print_select %enable;

View File

@ -238,7 +238,8 @@ public:
eSendToPrinterAll = 6,
eUploadGcode = 7,
eExportAllSlicedFile = 8,
ePrintMultiMachine = 9
ePrintMultiMachine = 9,
eSendMultiApp = 10
};
void update_layout();

View File

@ -2693,6 +2693,7 @@ struct Plater::priv
bool PopupObjectTable(int object_id, int volume_id, const wxPoint& position);
void on_action_send_to_printer(bool isall = false);
void on_action_send_to_multi_machine(SimpleEvent&);
void on_action_send_to_multi_app(SimpleEvent&);
int update_print_required_data(Slic3r::DynamicPrintConfig config, Slic3r::Model model, Slic3r::PlateDataPtrs plate_data_list, std::string file_name, std::string file_path);
private:
bool layers_height_allowed() const;
@ -3060,6 +3061,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
q->Bind(EVT_GLTOOLBAR_SEND_TO_PRINTER, &priv::on_action_export_to_sdcard, this);
q->Bind(EVT_GLTOOLBAR_SEND_TO_PRINTER_ALL, &priv::on_action_export_to_sdcard_all, this);
q->Bind(EVT_GLTOOLBAR_PRINT_MULTI_MACHINE, &priv::on_action_send_to_multi_machine, this);
q->Bind(EVT_GLTOOLBAR_SEND_MULTI_APP, &priv::on_action_send_to_multi_app, this);
q->Bind(EVT_GLCANVAS_PLATE_SELECT, &priv::on_plate_selected, this);
q->Bind(EVT_DOWNLOAD_PROJECT, &priv::on_action_download_project, this);
q->Bind(EVT_IMPORT_MODEL_ID, &priv::on_action_request_model_id, this);
@ -7243,6 +7245,54 @@ void Plater::priv::on_action_send_to_multi_machine(SimpleEvent&)
m_send_multi_dlg->ShowModal();
}
void Plater::priv::on_action_send_to_multi_app(SimpleEvent &)
{
#ifdef WIN32
HKEY hKey;
LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Bambulab\\Bambu Farm Manager Client"), 0, KEY_READ, &hKey);
LONG result_backup = RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("HKEY_CLASSES_ROOT\\bambu-farm-client\\shell\\open\\command"), 0, KEY_READ, &hKey);
if (result == ERROR_SUCCESS || result_backup == ERROR_SUCCESS) {
RegCloseKey(hKey);
auto gcodeResult = q->send_gcode(partplate_list.get_curr_plate_index(), [this](int export_stage, int current, int total, bool &cancel) {});
if (gcodeResult != 0) {
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":send_gcode failed\n";
return;
}
PrintPrepareData data;
q->get_print_job_data(&data);
if (data._3mf_path.empty()) {
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":3mf path is empty\n";
return;
}
wxString filename = q->get_export_gcode_filename("", true, partplate_list.get_curr_plate_index() == PLATE_ALL_IDX ? true : false);
wxString filepath = wxString::FromUTF8(data._3mf_path.string());
filepath.Replace("\\", "/");
std::string filePath = "?version=v1.6.0&path=" + filepath.ToStdString() + "&name=" + filename.utf8_string();
wxString url = "bambu-farm-client://upload-file" + Http::url_encode(filePath);
if (!wxLaunchDefaultBrowser(url)) {
GUI::MessageDialog msgdialog(nullptr, _L("Failed to start Bambu Farm Manager Client."), "", wxAPPLY | wxOK);
msgdialog.ShowModal();
}
} else {
GUI::MessageDialog msgdialog(nullptr, _L("No Bambu Farm Manager Client found."), "", wxAPPLY | wxOK);
msgdialog.ShowModal();
}
#endif // WIN32
#ifdef __APPLE__
// todo
#endif //__APPLE__
}
void Plater::priv::on_action_print_plate_from_sdcard(SimpleEvent&)
{
if (q != nullptr) {