NEW: add slice all and print all buttons

1. export all sliced files
2. support to print all sliced files

Change-Id: I59345370fb590b4c3c70b9b71385b25342a22e02
Signed-off-by: Stone Li <stone.li@bambulab.com>
This commit is contained in:
Stone Li 2022-10-26 11:27:35 +08:00 committed by Lane.Wei
parent ad636acac7
commit 71acbec38d
8 changed files with 135 additions and 52 deletions

View File

@ -27,6 +27,7 @@ wxDEFINE_EVENT(EVT_GLTOOLBAR_EXPORT_GCODE, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_SEND_GCODE, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_UPLOAD_GCODE, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_EXPORT_SLICED_FILE, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_EXPORT_ALL_SLICED_FILE, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_PRINT_SELECT, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_SEND_TO_PRINTER, SimpleEvent);

View File

@ -27,6 +27,7 @@ wxDECLARE_EVENT(EVT_GLTOOLBAR_EXPORT_GCODE, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_SEND_GCODE, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_UPLOAD_GCODE, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_EXPORT_SLICED_FILE, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_EXPORT_ALL_SLICED_FILE, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_PRINT_SELECT, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_SEND_TO_PRINTER, SimpleEvent);

View File

@ -132,16 +132,21 @@ void PrintJob::process()
return;
}
// task name
std::string project_name = wxGetApp().plater()->get_project_name().ToUTF8().data();
int curr_plate_idx = 0;
if (job_data.plate_idx >= 0)
curr_plate_idx = job_data.plate_idx + 1;
else if (job_data.plate_idx == PLATE_CURRENT_IDX)
curr_plate_idx = m_plater->get_partplate_list().get_curr_plate_index() + 1;
else if (job_data.plate_idx == PLATE_ALL_IDX)
curr_plate_idx = m_plater->get_partplate_list().get_curr_plate_index() + 1;
else
curr_plate_idx = m_plater->get_partplate_list().get_curr_plate_index() + 1;
BBL::PrintParams params;
params.dev_id = m_dev_id;
params.project_name = wxGetApp().plater()->get_project_name().ToUTF8().data();
params.project_name = project_name;
params.preset_name = wxGetApp().preset_bundle->prints.get_selected_preset_name();
params.filename = job_data._3mf_path.string();
params.config_filename = job_data._3mf_config_path.string();

View File

@ -810,6 +810,7 @@ void MainFrame::show_option(bool show)
if (m_slice_btn->IsShown()) {
m_slice_btn->Hide();
m_print_btn->Hide();
m_slice_option_btn->Hide();
m_print_option_btn->Hide();
Layout();
}
@ -817,6 +818,7 @@ void MainFrame::show_option(bool show)
if (!m_slice_btn->IsShown()) {
m_slice_btn->Show();
m_print_btn->Show();
m_slice_option_btn->Show();
m_print_option_btn->Show();
Layout();
}
@ -1156,6 +1158,22 @@ bool MainFrame::can_export_gcode() const
return true;
}
bool MainFrame::can_export_all_gcode() const
{
if (m_plater == nullptr)
return false;
if (m_plater->model().objects.empty())
return false;
if (m_plater->is_export_gcode_scheduled())
return false;
// TODO:: add other filters
PartPlateList& part_plate_list = m_plater->get_partplate_list();
return part_plate_list.is_all_slice_results_ready_for_print();
}
bool MainFrame::can_print_3mf() const
{
if (m_plater && !m_plater->model().objects.empty()) {
@ -1263,11 +1281,14 @@ wxBoxSizer* MainFrame::create_side_tools()
m_print_select = ePrintPlate;
m_slice_btn = new SideButton(this, _L("Slice"), "");
m_slice_option_btn = new SideButton(this, "", "sidebutton_dropdown", 0, FromDIP(14));
m_print_btn = new SideButton(this, _L("Print"), "");
m_print_option_btn = new SideButton(this, "", "sidebutton_dropdown", 0, FromDIP(14));
update_side_button_style();
m_slice_option_btn->Enable();
m_print_option_btn->Enable();
sizer->Add(m_slice_option_btn, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, FromDIP(1));
sizer->Add(m_slice_btn, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, FromDIP(1));
sizer->Add(FromDIP(15), 0, 0, 0, 0);
sizer->Add(m_print_option_btn, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, FromDIP(1));
@ -1312,18 +1333,18 @@ wxBoxSizer* MainFrame::create_side_tools()
wxPostEvent(m_plater, SimpleEvent(EVT_GLTOOLBAR_UPLOAD_GCODE));
else if (m_print_select == eExportSlicedFile)
wxPostEvent(m_plater, SimpleEvent(EVT_GLTOOLBAR_EXPORT_SLICED_FILE));
else if (m_print_select == eExportAllSlicedFile)
wxPostEvent(m_plater, SimpleEvent(EVT_GLTOOLBAR_EXPORT_ALL_SLICED_FILE));
else if (m_print_select == eSendToPrinter)
wxPostEvent(m_plater, SimpleEvent(EVT_GLTOOLBAR_SEND_TO_PRINTER));
});
// only support single plate currently
#if 0
m_slice_option_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent& event)
{
SidePopup* p = new SidePopup(this);
SideButton* slice_all_btn = new SideButton(p, _L("Slice all"), "");
slice_all_btn->SetCornerRadius(0);
SideButton* slice_plate_btn = new SideButton(p, _L("Slice"), "");
SideButton* slice_plate_btn = new SideButton(p, _L("Slice plate"), "");
slice_plate_btn->SetCornerRadius(0);
slice_all_btn->Bind(wxEVT_BUTTON, [this, p](wxCommandEvent&) {
@ -1348,26 +1369,11 @@ wxBoxSizer* MainFrame::create_side_tools()
p->Popup(m_slice_btn);
}
);
#endif
m_print_option_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent& event)
{
SidePopup* p = new SidePopup(this);
#if ENABEL_PRINT_ALL
SideButton* print_all_btn = new SideButton(p, _L("Print all"), "");
print_all_btn->SetCornerRadius(0);
print_all_btn->Bind(wxEVT_BUTTON, [this, p](wxCommandEvent&) {
m_print_btn->SetLabel(_L("Print all"));
m_print_select = ePrintAll;
if (m_print_enable) m_print_enable = get_enable_print_status();
m_print_btn->Enable(m_print_enable);
this->Layout();
p->Dismiss();
});
#endif
#if ENABEL_PRINT_ALL
p->append_button(print_all_btn);
#endif
if (wxGetApp().preset_bundle
&& !wxGetApp().preset_bundle->printers.get_edited_preset().is_bbl_vendor_preset(wxGetApp().preset_bundle)) {
// ThirdParty Buttons
@ -1412,15 +1418,18 @@ wxBoxSizer* MainFrame::create_side_tools()
}
else {
//Bambu Studio Buttons
SideButton* print_plate_btn = new SideButton(p, _L("Print"), "");
SideButton* print_plate_btn = new SideButton(p, _L("Print plate"), "");
print_plate_btn->SetCornerRadius(0);
/*SideButton* send_to_printer_btn = new SideButton(p, _L("Send"), "");
send_to_printer_btn->SetCornerRadius(0);*/
SideButton* export_sliced_file_btn = new SideButton(p, _L("Export sliced file"), "");
SideButton* export_sliced_file_btn = new SideButton(p, _L("Export plate sliced file"), "");
export_sliced_file_btn->SetCornerRadius(0);
SideButton* export_all_sliced_file_btn = new SideButton(p, _L("Export all sliced file"), "");
export_all_sliced_file_btn->SetCornerRadius(0);
print_plate_btn->Bind(wxEVT_BUTTON, [this, p](wxCommandEvent&) {
m_print_btn->SetLabel(_L("Print"));
m_print_select = ePrintPlate;
@ -1430,6 +1439,17 @@ wxBoxSizer* MainFrame::create_side_tools()
p->Dismiss();
});
SideButton* print_all_btn = new SideButton(p, _L("Print all"), "");
print_all_btn->SetCornerRadius(0);
print_all_btn->Bind(wxEVT_BUTTON, [this, p](wxCommandEvent&) {
m_print_btn->SetLabel(_L("Print all"));
m_print_select = ePrintAll;
m_print_enable = get_enable_print_status();
m_print_btn->Enable(m_print_enable);
this->Layout();
p->Dismiss();
});
/*send_to_printer_btn->Bind(wxEVT_BUTTON, [this, p](wxCommandEvent&) {
m_print_btn->SetLabel(_L("Send"));
m_print_select = eSendToPrinter;
@ -1440,16 +1460,28 @@ wxBoxSizer* MainFrame::create_side_tools()
});*/
export_sliced_file_btn->Bind(wxEVT_BUTTON, [this, p](wxCommandEvent&) {
m_print_btn->SetLabel(_L("Export Sliced File"));
m_print_btn->SetLabel(_L("Export plate sliced file"));
m_print_select = eExportSlicedFile;
m_print_enable = get_enable_print_status();
m_print_btn->Enable(m_print_enable);
this->Layout();
p->Dismiss();
});
export_all_sliced_file_btn->Bind(wxEVT_BUTTON, [this, p](wxCommandEvent&) {
m_print_btn->SetLabel(_L("Export all sliced file"));
m_print_select = eExportAllSlicedFile;
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(export_sliced_file_btn);
p->append_button(export_all_sliced_file_btn);
}
p->Popup(m_print_btn);
@ -1565,6 +1597,13 @@ bool MainFrame::get_enable_print_status()
enable = false;
}
}
else if (m_print_select == eExportAllSlicedFile)
{
if (!part_plate_list.is_all_slice_results_ready_for_print())
{
enable = false;
}
}
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": m_print_select %1%, enable= %2% ")%m_print_select %enable;
@ -1576,22 +1615,26 @@ void MainFrame::update_side_button_style()
// BBS
int em = em_unit();
m_slice_btn->SetLayoutStyle(1);
/*m_slice_btn->SetLayoutStyle(1);
m_slice_btn->SetTextLayout(SideButton::EHorizontalOrientation::HO_Center, FromDIP(15));
m_slice_btn->SetMinSize(wxSize(-1, FromDIP(24)));
m_slice_btn->SetCornerRadius(FromDIP(12));
m_slice_btn->SetExtraSize(wxSize(FromDIP(38), FromDIP(10)));
m_slice_btn->SetBottomColour(wxColour(0x3B4446));*/
m_slice_btn->SetTextLayout(SideButton::EHorizontalOrientation::HO_Left, FromDIP(15));
m_slice_btn->SetCornerRadius(FromDIP(12));
m_slice_btn->SetExtraSize(wxSize(FromDIP(38), FromDIP(10)));
m_slice_btn->SetMinSize(wxSize(-1, FromDIP(24)));
m_slice_btn->SetBottomColour(wxColour(0x3B4446));
#if 0
m_slice_option_btn->SetTextLayout(SideButton::EHorizontalOrientation::HO_Center);
m_slice_option_btn->SetCornerRadius(12 * em / 10);
m_slice_option_btn->SetExtraSize(wxSize(10 * em / 10, 10 * em / 10));
m_slice_option_btn->SetIconOffset(2 * em / 10);
m_slice_option_btn->SetMinSize(wxSize(24 * em / 10, 24 * em / 10));
m_slice_option_btn->SetCornerRadius(FromDIP(12));
m_slice_option_btn->SetExtraSize(wxSize(FromDIP(10), FromDIP(10)));
m_slice_option_btn->SetIconOffset(FromDIP(2));
m_slice_option_btn->SetMinSize(wxSize(FromDIP(24), FromDIP(24)));
m_slice_option_btn->SetBottomColour(wxColour(0x3B4446));
#endif
m_print_btn->SetTextLayout(SideButton::EHorizontalOrientation::HO_Left, FromDIP(15));
m_print_btn->SetCornerRadius(FromDIP(12));
m_print_btn->SetExtraSize(wxSize(FromDIP(38), FromDIP(10)));
@ -1958,9 +2001,14 @@ void MainFrame::init_menubar_as_editor()
[this](wxCommandEvent&) { if (m_plater) m_plater->export_core_3mf(); }, "menu_export_sliced_file", nullptr,
[this](){return can_export_model(); }, this);
// BBS export .gcode.3mf
append_menu_item(export_menu, wxID_ANY, _L("Export Sliced File") + dots/* + "\tCtrl+G"*/, _L("Export current Sliced file"),
append_menu_item(export_menu, wxID_ANY, _L("Export plate sliced file") + dots/* + "\tCtrl+G"*/, _L("Export current sliced file"),
[this](wxCommandEvent&) { if (m_plater) wxPostEvent(m_plater, SimpleEvent(EVT_GLTOOLBAR_EXPORT_SLICED_FILE)); }, "menu_export_sliced_file", nullptr,
[this](){return can_export_gcode(); }, this);
append_menu_item(export_menu, wxID_ANY, _L("Export all plate sliced file") + dots/* + "\tCtrl+G"*/, _L("Export all plate sliced file"),
[this](wxCommandEvent&) { if (m_plater) wxPostEvent(m_plater, SimpleEvent(EVT_GLTOOLBAR_EXPORT_SLICED_FILE)); }, "menu_export_sliced_file", nullptr,
[this]() {return can_export_all_gcode(); }, this);
append_menu_item(export_menu, wxID_ANY, _L("Export G-code") + dots/* + "\tCtrl+G"*/, _L("Export current plate as G-code"),
[this](wxCommandEvent&) { if (m_plater) m_plater->export_gcode(false); }, "menu_export_gcode", nullptr,
[this]() {return can_export_gcode(); }, this);

View File

@ -112,6 +112,7 @@ class MainFrame : public DPIFrame
bool can_export_toolpaths() const;
bool can_export_supports() const;
bool can_export_gcode() const;
bool can_export_all_gcode() const;
bool can_print_3mf() const;
bool can_send_gcode() const;
//bool can_export_gcode_sd() const;
@ -169,6 +170,7 @@ class MainFrame : public DPIFrame
ESettingsLayout m_layout{ ESettingsLayout::Unknown };
enum SliceSelectType
{
eSliceAll = 0,
@ -207,7 +209,8 @@ public:
eExportGcode = 3,
eSendGcode = 4,
eSendToPrinter = 5,
eUploadGcode = 6
eUploadGcode = 6,
eExportAllSlicedFile = 7
};
//BBS: add slice&&print status update logic

View File

@ -4056,7 +4056,7 @@ int PartPlateList::store_to_3mf_structure(PlateDataPtrs& plate_data_list, bool w
if (with_slice_info) {
if (m_plate_list[i]->get_slice_result() && m_plate_list[i]->is_slice_result_valid()) {
// BBS only include current palte_idx
if (plate_idx == i || plate_idx == -1) {
if (plate_idx == i || plate_idx == PLATE_CURRENT_IDX || plate_idx == PLATE_ALL_IDX) {
//load calibration thumbnail
if (m_plate_list[i]->cali_thumbnail_data.is_valid())
plate_data_item->pattern_file = "valid_pattern";

View File

@ -1899,6 +1899,7 @@ struct Plater::priv
void on_action_send_gcode(SimpleEvent&);
void on_action_upload_gcode(SimpleEvent&);
void on_action_export_sliced_file(SimpleEvent&);
void on_action_export_all_sliced_file(SimpleEvent&);
void on_action_select_sliced_plate(wxCommandEvent& evt);
void on_update_geometry(Vec3dsEvent<2>&);
@ -1951,7 +1952,7 @@ struct Plater::priv
// returns the path to project file with the given extension (none if extension == wxEmptyString)
// extension should contain the leading dot, i.e.: ".3mf"
wxString get_project_filename(const wxString& extension = wxEmptyString) const;
wxString get_export_gcode_filename(const wxString& extension = wxEmptyString, bool only_filename = false) const;
wxString get_export_gcode_filename(const wxString& extension = wxEmptyString, bool only_filename = false, bool export_all = false) const;
void set_project_filename(const wxString& filename);
//BBS store bbs project name
@ -2290,6 +2291,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
q->Bind(EVT_GLTOOLBAR_SEND_GCODE, &priv::on_action_send_gcode, this);
q->Bind(EVT_GLTOOLBAR_UPLOAD_GCODE, &priv::on_action_upload_gcode, this);
q->Bind(EVT_GLTOOLBAR_EXPORT_SLICED_FILE, &priv::on_action_export_sliced_file, this);
q->Bind(EVT_GLTOOLBAR_EXPORT_ALL_SLICED_FILE, &priv::on_action_export_all_sliced_file, this);
q->Bind(EVT_GLTOOLBAR_SEND_TO_PRINTER, &priv::on_action_export_to_sdcard, this);
q->Bind(EVT_GLCANVAS_PLATE_SELECT, &priv::on_plate_selected, this);
q->Bind(EVT_DOWNLOAD_PROJECT, &priv::on_action_download_project, this);
@ -5788,6 +5790,14 @@ void Plater::priv::on_action_export_sliced_file(SimpleEvent&)
}
}
void Plater::priv::on_action_export_all_sliced_file(SimpleEvent &)
{
if (q != nullptr) {
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received export all sliced file event\n";
q->export_gcode_3mf(true);
}
}
void Plater::priv::on_action_export_to_sdcard(SimpleEvent&)
{
if (q != nullptr) {
@ -6068,19 +6078,31 @@ wxString Plater::priv::get_project_filename(const wxString& extension) const
}
}
wxString Plater::priv::get_export_gcode_filename(const wxString& extension, bool only_filename) const
wxString Plater::priv::get_export_gcode_filename(const wxString& extension, bool only_filename, bool export_all) const
{
std::string plate_index_str = (boost::format("_plate_%1%") % std::to_string(partplate_list.get_curr_plate_index() + 1)).str();
if (!m_project_folder.empty()) {
if (!only_filename) {
auto full_filename = m_project_folder / std::string((m_project_name + plate_index_str + extension).mb_str(wxConvUTF8));
return from_path(full_filename);
if (export_all) {
auto full_filename = m_project_folder / std::string((m_project_name + extension).mb_str(wxConvUTF8));
return from_path(full_filename);
} else {
auto full_filename = m_project_folder / std::string((m_project_name + plate_index_str + extension).mb_str(wxConvUTF8));
return from_path(full_filename);
}
} else {
return m_project_name + wxString(plate_index_str) + extension;
if (export_all)
return m_project_name + wxString(plate_index_str) + extension;
else
return m_project_name + extension;
}
} else {
if (only_filename)
return m_project_name + wxString(plate_index_str) + extension;
if (only_filename) {
if (export_all)
return m_project_name + extension;
else
return m_project_name + wxString(plate_index_str) + extension;
}
else
return "";
}
@ -8617,7 +8639,7 @@ void Plater::send_to_printer()
}
//BBS export gcode 3mf to file
void Plater::export_gcode_3mf()
void Plater::export_gcode_3mf(bool export_all)
{
if (p->model.objects.empty())
return;
@ -8629,11 +8651,11 @@ void Plater::export_gcode_3mf()
fs::path default_output_file;
AppConfig& appconfig = *wxGetApp().app_config;
std::string start_dir;
default_output_file = into_path(get_export_gcode_filename(".3mf"));
default_output_file = into_path(get_export_gcode_filename(".3mf", false, export_all));
if (default_output_file.empty()) {
try {
start_dir = appconfig.get_last_output_dir("", false);
wxString filename = get_export_gcode_filename(".3mf", true);
wxString filename = get_export_gcode_filename(".3mf", true, export_all);
std::string full_filename = start_dir + "/" + filename.utf8_string();
default_output_file = boost::filesystem::path(full_filename);
} catch(...) {
@ -8648,7 +8670,6 @@ void Plater::export_gcode_3mf()
//Get a last save path
start_dir = appconfig.get_last_output_dir(default_output_file.parent_path().string(), false);
fs::path output_path;
{
std::string ext = default_output_file.extension().string();
@ -8674,8 +8695,10 @@ void Plater::export_gcode_3mf()
//BBS do not save last output path
p->last_output_path = output_path.string();
p->last_output_dir_path = output_path.parent_path().string();
int curr_plate_idx = get_partplate_list().get_curr_plate_index();
export_3mf(output_path, SaveStrategy::Silence | SaveStrategy::SplitModel | SaveStrategy::WithGcode | SaveStrategy::SkipModel, curr_plate_idx); // BBS: silence
int plate_idx = get_partplate_list().get_curr_plate_index();
if (export_all)
plate_idx = PLATE_ALL_IDX;
export_3mf(output_path, SaveStrategy::Silence | SaveStrategy::SplitModel | SaveStrategy::WithGcode | SaveStrategy::SkipModel, plate_idx); // BBS: silence
RemovableDriveManager& removable_drive_manager = *wxGetApp().removable_drive_manager();
@ -9307,7 +9330,9 @@ int Plater::send_gcode(int plate_idx, Export3mfProgressFn proFn)
if (plate_idx == PLATE_CURRENT_IDX) {
p->m_print_job_data.plate_idx = get_partplate_list().get_curr_plate_index();
}
else {
else if (plate_idx == PLATE_ALL_IDX) {
p->m_print_job_data.plate_idx = get_partplate_list().get_curr_plate_index();
} else {
p->m_print_job_data.plate_idx = plate_idx;
}
@ -9726,9 +9751,9 @@ wxString Plater::get_project_filename(const wxString& extension) const
return p->get_project_filename(extension);
}
wxString Plater::get_export_gcode_filename(const wxString & extension, bool only_filename) const
wxString Plater::get_export_gcode_filename(const wxString & extension, bool only_filename, bool export_all) const
{
return p->get_export_gcode_filename(extension, only_filename);
return p->get_export_gcode_filename(extension, only_filename, export_all);
}
void Plater::set_project_filename(const wxString& filename)

View File

@ -302,7 +302,7 @@ public:
void send_to_printer();
void export_gcode(bool prefer_removable);
void export_gcode_3mf();
void export_gcode_3mf(bool export_all = false);
void export_core_3mf();
void export_stl(bool extended = false, bool selection_only = false);
//BBS: remove amf
@ -380,7 +380,7 @@ public:
//void show_action_buttons(const bool is_ready_to_slice) const;
wxString get_project_filename(const wxString& extension = wxEmptyString) const;
wxString get_export_gcode_filename(const wxString& extension = wxEmptyString, bool only_filename = false) const;
wxString get_export_gcode_filename(const wxString& extension = wxEmptyString, bool only_filename = false, bool export_all = false) const;
void set_project_filename(const wxString& filename);
bool is_export_gcode_scheduled() const;