FIX: add dialog of 3mf version newer cloud version

Jira: XXXX

Change-Id: Ia903e58fd37191b957196da5a84de920ac975b07
This commit is contained in:
maosheng.wei 2023-12-11 19:31:17 +08:00 committed by Lane.Wei
parent 87ff0b8da8
commit eddfd4b7b9
4 changed files with 176 additions and 26 deletions

View File

@ -482,6 +482,127 @@ DeleteConfirmDialog::~DeleteConfirmDialog() {}
void DeleteConfirmDialog::on_dpi_changed(const wxRect &suggested_rect) {}
Newer3mfVersionDialog::Newer3mfVersionDialog(wxWindow *parent, const Semver *file_version, const Semver *cloud_version, wxString new_keys)
: DPIDialog(parent ? parent : nullptr, wxID_ANY, wxString(SLIC3R_APP_FULL_NAME " - ") + _L("Newer 3mf version"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
, m_file_version(file_version)
, m_cloud_version(cloud_version)
, m_new_keys(new_keys)
{
this->SetBackgroundColour(*wxWHITE);
std::string icon_path = (boost::format("%1%/images/BambuStudioTitle.ico") % resources_dir()).str();
SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO));
wxBoxSizer *main_sizer = new wxBoxSizer(wxVERTICAL);
// top line
auto m_line_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1), wxTAB_TRAVERSAL);
m_line_top->SetBackgroundColour(wxColour(0xA6, 0xa9, 0xAA));
main_sizer->Add(m_line_top, 0, wxEXPAND, 0);
main_sizer->Add(0, 0, 0, wxTOP, FromDIP(5));
wxBoxSizer * content_sizer = new wxBoxSizer(wxHORIZONTAL);
wxStaticBitmap *info_bitmap = new wxStaticBitmap(this, wxID_ANY, create_scaled_bitmap("info", nullptr, 60), wxDefaultPosition, wxSize(FromDIP(70), FromDIP(70)), 0);
wxBoxSizer * msg_sizer = get_msg_sizer();
content_sizer->Add(info_bitmap, 0, wxEXPAND | wxALL, FromDIP(5));
content_sizer->Add(msg_sizer, 0, wxEXPAND | wxALL, FromDIP(5));
main_sizer->Add(content_sizer, 0, wxEXPAND | wxALL, FromDIP(5));
main_sizer->Add(get_btn_sizer(), 0, wxEXPAND | wxALL, FromDIP(5));
this->SetSizer(main_sizer);
Layout();
Fit();
wxGetApp().UpdateDlgDarkUI(this);
}
wxBoxSizer *Newer3mfVersionDialog::get_msg_sizer()
{
wxBoxSizer *vertical_sizer = new wxBoxSizer(wxVERTICAL);
bool file_version_newer = (*m_file_version) > (*m_cloud_version);
wxStaticText *text1;
wxBoxSizer * horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxString msg_str;
if (file_version_newer) {
text1 = new wxStaticText(this, wxID_ANY, _L("The 3mf file version is in Beta and it is newer than the current Bambu Studio version."));
wxStaticText * text2 = new wxStaticText(this, wxID_ANY, _L("If you would like to try Bambu Studio Beta, you may click to"));
wxHyperlinkCtrl *github_link = new wxHyperlinkCtrl(this, wxID_ANY, _L("Download Beta Version"), "https://github.com/bambulab/BambuStudio/releases");
horizontal_sizer->Add(text2, 0, wxEXPAND, 0);
horizontal_sizer->Add(github_link, 0, wxEXPAND | wxLEFT, 5);
} else {
text1 = new wxStaticText(this, wxID_ANY, _L("The 3mf file version is newer than the current Bambu Studio version."));
wxStaticText *text2 = new wxStaticText(this, wxID_ANY, _L("Update your Bambu Studio could enable all functionality in the 3mf file."));
horizontal_sizer->Add(text2, 0, wxEXPAND, 0);
}
Semver app_version = *(Semver::parse(SLIC3R_VERSION));
wxStaticText *cur_version = new wxStaticText(this, wxID_ANY, _L("Current Version: ") + app_version.to_string());
vertical_sizer->Add(text1, 0, wxEXPAND | wxTOP, FromDIP(5));
vertical_sizer->Add(horizontal_sizer, 0, wxEXPAND | wxTOP, FromDIP(5));
vertical_sizer->Add(cur_version, 0, wxEXPAND | wxTOP, FromDIP(5));
if (!file_version_newer) {
wxStaticText *latest_version = new wxStaticText(this, wxID_ANY, _L("Latest Version: ") + m_cloud_version->to_string());
vertical_sizer->Add(latest_version, 0, wxEXPAND | wxTOP, FromDIP(5));
}
wxStaticText *unrecognized_keys = new wxStaticText(this, wxID_ANY, m_new_keys);
vertical_sizer->Add(unrecognized_keys, 0, wxEXPAND | wxTOP, FromDIP(10));
return vertical_sizer;
}
wxBoxSizer *Newer3mfVersionDialog::get_btn_sizer()
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
horizontal_sizer->Add(0, 0, 1, wxEXPAND, 0);
StateColor btn_bg_green(std::pair<wxColour, int>(wxColour(27, 136, 68), StateColor::Pressed), std::pair<wxColour, int>(wxColour(61, 203, 115), StateColor::Hovered),
std::pair<wxColour, int>(wxColour(0, 174, 66), StateColor::Normal));
StateColor btn_bg_white(std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Pressed), std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Hovered),
std::pair<wxColour, int>(*wxWHITE, StateColor::Normal));
bool file_version_newer = (*m_file_version) > (*m_cloud_version);
if (!file_version_newer) {
m_update_btn = new Button(this, _L("Update"));
m_update_btn->SetBackgroundColor(btn_bg_green);
m_update_btn->SetBorderColor(*wxWHITE);
m_update_btn->SetTextColor(wxColour(0xFFFFFE));
m_update_btn->SetFont(Label::Body_12);
m_update_btn->SetSize(wxSize(FromDIP(58), FromDIP(24)));
m_update_btn->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_update_btn->SetCornerRadius(FromDIP(12));
horizontal_sizer->Add(m_update_btn, 0, wxRIGHT, FromDIP(10));
m_update_btn->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) {
EndModal(wxID_OK);
if (wxGetApp().app_config->has("app", "cloud_software_url")) {
std::string download_url = wxGetApp().app_config->get("app", "cloud_software_url");
wxLaunchDefaultBrowser(download_url);
} else {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "Bambu Studio conf has no cloud_software_url and file_version: " << m_file_version->to_string()
<< " and cloud_version: " << m_cloud_version->to_string();
}
});
}
if (!file_version_newer) {
m_later_btn = new Button(this, _L("Not for new"));
m_later_btn->SetBackgroundColor(btn_bg_white);
m_later_btn->SetBorderColor(wxColour(38, 46, 48));
} else {
m_later_btn = new Button(this, _L("OK"));
m_later_btn->SetBackgroundColor(btn_bg_green);
m_later_btn->SetBorderColor(*wxWHITE);
m_later_btn->SetTextColor(wxColour(0xFFFFFE));
}
m_later_btn->SetFont(Label::Body_12);
m_later_btn->SetSize(wxSize(FromDIP(58), FromDIP(24)));
m_later_btn->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_later_btn->SetCornerRadius(FromDIP(12));
horizontal_sizer->Add(m_later_btn, 0, wxRIGHT, FromDIP(10));
m_later_btn->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) {
EndModal(wxID_OK);
e.Skip();
});
return horizontal_sizer;
}
} // namespace GUI
} // namespace Slic3r

View File

@ -16,6 +16,7 @@
#include "Widgets/TextInput.hpp"
#include "BBLStatusBar.hpp"
#include "BBLStatusBarSend.hpp"
#include "libslic3r/Semver.hpp"
class wxBoxSizer;
class wxCheckBox;
@ -385,6 +386,27 @@ private:
wxStaticText *m_msg_text = nullptr;
};
class Newer3mfVersionDialog : public DPIDialog
{
public:
Newer3mfVersionDialog(wxWindow *parent, const Semver* file_version, const Semver* cloud_version, wxString new_keys);
~Newer3mfVersionDialog(){};
virtual void on_dpi_changed(const wxRect &suggested_rect){};
private:
wxBoxSizer *get_msg_sizer();
wxBoxSizer *get_btn_sizer();
private:
const Semver *m_file_version;
const Semver *m_cloud_version;
wxString m_new_keys;
Button * m_update_btn = nullptr;
Button * m_later_btn = nullptr;
wxStaticText *m_msg_text = nullptr;
};
}
}

View File

@ -3469,46 +3469,33 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
for (ModelVolume *model_volume : model_object->volumes) model_volume->config.reset();
}
} else if (load_config && (file_version > app_version)) {
Semver cloud_ver;
if (wxGetApp().app_config->has("app", "cloud_version")) {
std::string cloud_version = wxGetApp().app_config->get("app", "cloud_version");
cloud_ver = *(Semver::parse(cloud_version));
} else {
cloud_ver = app_version;
}
if (config_substitutions.unrecogized_keys.size() > 0) {
wxString text = wxString::Format(_L("This slicer file version %s is newer than %s's version:"),
file_version.to_string(), std::string(SLIC3R_APP_FULL_NAME));
text += "\n";
bool first = true;
// std::string context = into_u8(text);
wxString context = text;
wxString context;
if (wxGetApp().app_config->get("user_mode") == "develop") {
context = _L("Found following keys unrecognized:\n");
for (auto &key : config_substitutions.unrecogized_keys) {
context += " -";
context += key;
context += ";\n";
first = false;
}
}
wxString append = _L("Would you like to update your Bambu Studio software to enable all functionality in this slicer file?\n");
context += "\n\n";
// context += into_u8(append);
context += append;
MessageDialog msg_window(q, context, wxString(SLIC3R_APP_FULL_NAME " - ") + _L("Newer 3mf version"), wxYES | wxNO | wxICON_INFORMATION);
auto res = msg_window.ShowModal();
if (res == wxID_YES) {
wxGetApp().check_new_version(true, 1);
} else if (res == wxID_NO) {
show_info(q, _L("you can always update Bambu Studio at your convenience. The slicer file will now be loaded without full functionality."));
}
Newer3mfVersionDialog newer_dlg(q, &file_version, &cloud_ver, context);
newer_dlg.ShowModal();
}
else {
//if the minor version is not matched
if (file_version.min() != app_version.min()) {
wxString text = wxString::Format(_L("This slicer file version %s is newer than %s's version.\n\nWould you like to update your Bambu Studio software to enable all functionality in this slicer file?"),
file_version.to_string(), std::string(SLIC3R_APP_FULL_NAME));
text += "\n";
MessageDialog msg_window(q, text, wxString(SLIC3R_APP_FULL_NAME " - ") + _L("Newer 3mf version"), wxYES | wxNO | wxICON_INFORMATION);
auto res = msg_window.ShowModal();
if (res == wxID_YES) {
wxGetApp().check_new_version(true, 1);
} else if (res == wxID_NO) {
show_info(q, _L("you can always update Bambu Studio at your convenience. The slicer file will now be loaded without full functionality."));
}
Newer3mfVersionDialog newer_dlg(q, &file_version, &cloud_ver, "");
auto res = newer_dlg.ShowModal();
}
}
} else if (!load_config) {

View File

@ -747,6 +747,26 @@ void PresetUpdater::priv::sync_config(std::string http_url, const VendorMap vend
}
}
}
json software = j.at("software");
if (software.is_object() && !software.empty()) {
Semver cloud_version;
for (auto iter = software.begin(); iter != software.end(); iter++) {
if (boost::iequals(iter.key(), "version")) {
cloud_version = *(Semver::parse(iter.value()));
GUI::wxGetApp().app_config->set("app", "cloud_version",cloud_version.to_string());
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Bambu Studio has newer version and the version is: " << cloud_version.to_string();
} else if (boost::iequals(iter.key(), "url")) {
std::string url = iter.value();
GUI::wxGetApp().app_config->set("app", "cloud_software_url", url);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Bambu Studio has newer version and download url is: " << url;
}
}
} else {
GUI::wxGetApp().app_config->erase("app", "cloud_version");
GUI::wxGetApp().app_config->erase("app", "cloud_software_url");
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Bambu Studio is newest version.";
}
GUI::wxGetApp().CallAfter([]() { GUI::wxGetApp().app_config->save(); });
}
else {
BOOST_LOG_TRIVIAL(error) << "[BBL Updater]: get version of settings failed, body=" << body;