Merge branch 'main' into enh-port-edit-gcode-dlg

# Conflicts:
#	src/slic3r/GUI/OG_CustomCtrl.cpp
#	src/slic3r/GUI/OG_CustomCtrl.hpp
This commit is contained in:
Ocraftyone 2024-01-01 10:58:04 -05:00
commit f78d55eac5
No known key found for this signature in database
GPG key ID: 85836ED21AD4D125
265 changed files with 29219 additions and 7128 deletions

View file

@ -4,6 +4,7 @@
#include "GUI_ObjectList.hpp"
#include "GUI_Factories.hpp"
#include "format.hpp"
#include "libslic3r_version.h"
// Localization headers: include libslic3r version first so everything in this file
// uses the slic3r/GUI version (the macros will take precedence over the functions).
@ -369,7 +370,7 @@ public:
// See https://github.com/wxWidgets/wxWidgets/blob/master/src/msw/font.cpp
// void wxNativeFontInfo::SetFractionalPointSize(float pointSizeNew)
wxNativeFontInfo nfi= *font.GetNativeFontInfo();
float pointSizeNew = wxDisplay(this).GetScaleFactor() * scale * font.GetPointSize();
float pointSizeNew = scale * font.GetPointSize();
nfi.lf.lfHeight = nfi.GetLogFontHeightAtPPI(pointSizeNew, get_dpi_for_window(this));
nfi.pointSize = pointSizeNew;
font = wxFont(nfi);
@ -2107,6 +2108,9 @@ void GUI_App::init_app_config()
if (!boost::filesystem::exists(data_dir_path)){
boost::filesystem::create_directory(data_dir_path);
}
// Change current dirtory of application
chdir(encode_path((Slic3r::data_dir() + "/log").c_str()).c_str());
} else {
m_datadir_redefined = true;
}
@ -4290,7 +4294,8 @@ Semver get_version(const std::string& str, const std::regex& regexp) {
void GUI_App::check_new_version_sf(bool show_tips, int by_user)
{
AppConfig* app_config = wxGetApp().app_config;
auto version_check_url = app_config->version_check_url();
bool check_stable_only = app_config->get_bool("check_stable_update_only");
auto version_check_url = app_config->version_check_url(check_stable_only);
Http::get(version_check_url)
.on_error([&](std::string body, std::string error, unsigned http_status) {
(void)body;
@ -4298,25 +4303,22 @@ void GUI_App::check_new_version_sf(bool show_tips, int by_user)
error);
})
.timeout_connect(1)
.on_complete([this,by_user](std::string body, unsigned http_status) {
.on_complete([this,by_user, check_stable_only](std::string body, unsigned http_status) {
// Http response OK
if (http_status != 200)
return;
try {
boost::trim(body);
// SoftFever: parse github release, ported from SS
// Orca: parse github release, inspired by SS
boost::property_tree::ptree root;
std::stringstream json_stream(body);
boost::property_tree::read_json(json_stream, root);
bool i_am_pre = false;
// at least two number, use '.' as separator. can be followed by -Az23 for prereleased and +Az42 for
// metadata
std::regex matcher("[0-9]+\\.[0-9]+(\\.[0-9]+)*(-[A-Za-z0-9]+)?(\\+[A-Za-z0-9]+)?");
Semver current_version = get_version(SoftFever_VERSION, matcher);
Semver current_version = get_version(SoftFever_VERSION, matcher);
Semver best_pre(1, 0, 0);
Semver best_release(1, 0, 0);
std::string best_pre_url;
@ -4324,56 +4326,73 @@ void GUI_App::check_new_version_sf(bool show_tips, int by_user)
std::string best_release_content;
std::string best_pre_content;
const std::regex reg_num("([0-9]+)");
std::string tag = root.get<std::string>("tag_name");
if (tag[0] == 'v')
tag.erase(0, 1);
for (std::regex_iterator it = std::sregex_iterator(tag.begin(), tag.end(), reg_num);
it != std::sregex_iterator(); ++it) {
}
Semver tag_version = get_version(tag, matcher);
if (current_version == tag_version)
i_am_pre = root.get<bool>("prerelease");
if (root.get<bool>("prerelease")) {
if (best_pre < tag_version) {
best_pre = tag_version;
best_pre_url = root.get<std::string>("html_url");
best_pre_content = root.get<std::string>("body");
best_pre.set_prerelease("Preview");
}
if (check_stable_only) {
std::string tag = root.get<std::string>("tag_name");
if (tag[0] == 'v')
tag.erase(0, 1);
for (std::regex_iterator it = std::sregex_iterator(tag.begin(), tag.end(), reg_num); it != std::sregex_iterator(); ++it) {}
Semver tag_version = get_version(tag, matcher);
if (root.get<bool>("prerelease")) {
if (best_pre < tag_version) {
best_pre = tag_version;
best_pre_url = root.get<std::string>("html_url");
best_pre_content = root.get<std::string>("body");
best_pre.set_prerelease("Preview");
}
} else {
if (best_release < tag_version) {
best_release = tag_version;
best_release_url = root.get<std::string>("html_url");
best_release_content = root.get<std::string>("body");
}
}
} else {
if (best_release < tag_version) {
best_release = tag_version;
best_release_url = root.get<std::string>("html_url");
best_release_content = root.get<std::string>("body");
}
for (auto json_version : root) {
std::string tag = json_version.second.get<std::string>("tag_name");
if (tag[0] == 'v')
tag.erase(0, 1);
for (std::regex_iterator it = std::sregex_iterator(tag.begin(), tag.end(), reg_num); it != std::sregex_iterator();
++it) {}
Semver tag_version = get_version(tag, matcher);
if (json_version.second.get<bool>("prerelease")) {
if (best_pre < tag_version) {
best_pre = tag_version;
best_pre_url = json_version.second.get<std::string>("html_url");
best_pre_content = json_version.second.get<std::string>("body");
best_pre.set_prerelease("Preview");
}
} else {
if (best_release < tag_version) {
best_release = tag_version;
best_release_url = json_version.second.get<std::string>("html_url");
best_release_content = json_version.second.get<std::string>("body");
}
}
}
}
// if release is more recent than beta, use release anyway
if (best_pre < best_release) {
best_pre = best_release;
best_pre_url = best_release_url;
best_pre_content = best_release_content;
best_pre = best_release;
best_pre_url = best_release_url;
best_pre_content = best_release_content;
}
// if we're the most recent, don't do anything
if ((i_am_pre ? best_pre : best_release) <= current_version) {
if (by_user != 0)
this->no_new_version();
return;
if ((check_stable_only ? best_release : best_pre) <= current_version) {
if (by_user != 0)
this->no_new_version();
return;
}
// BOOST_LOG_TRIVIAL(info) << format("Got %1% online version: `%2%`. Sending to GUI thread...",
// SLIC3R_APP_NAME, i_am_pre ? best_pre.to_string(): best_release.to_string());
version_info.url = i_am_pre ? best_pre_url : best_release_url;
version_info.version_str = i_am_pre ? best_pre.to_string() : best_release.to_string_sf();
version_info.description = i_am_pre ? best_pre_content : best_release_content;
version_info.url = check_stable_only ? best_release_url : best_pre_url;
version_info.version_str = check_stable_only ? best_release.to_string_sf() : best_pre.to_string();
version_info.description = check_stable_only ? best_release_content : best_pre_content;
version_info.force_upgrade = false;
wxCommandEvent *evt = new wxCommandEvent(EVT_SLIC3R_VERSION_ONLINE);
evt->SetString((i_am_pre ? best_pre : best_release).to_string());
wxCommandEvent* evt = new wxCommandEvent(EVT_SLIC3R_VERSION_ONLINE);
evt->SetString((check_stable_only ? best_release : best_pre).to_string());
GUI::wxGetApp().QueueEvent(evt);
} catch (...) {
}
} catch (...) {}
})
.perform();
}
@ -4591,8 +4610,7 @@ void GUI_App::sync_preset(Preset* preset)
if (http_code >= 400) {
result = 0;
updated_info = "hold";
}
else
} else
result = -1;
}
}
@ -4614,8 +4632,7 @@ void GUI_App::sync_preset(Preset* preset)
auto update_time_str = values_map[BBL_JSON_KEY_UPDATE_TIME];
if (!update_time_str.empty())
update_time = std::atoll(update_time_str.c_str());
}
else {
} else {
BOOST_LOG_TRIVIAL(trace) << "[sync_preset]create: request_setting_id failed, http code "<<http_code;
// do not post new preset this time if http code >= 400
if (http_code >= 400) {
@ -4625,12 +4642,10 @@ void GUI_App::sync_preset(Preset* preset)
else
result = -1;
}
}
else {
} else {
BOOST_LOG_TRIVIAL(trace) << "[sync_preset]create: can not generate differed preset";
}
}
else if (preset->sync_info.compare("update") == 0) {
} else if (preset->sync_info.compare("update") == 0) {
if (!setting_id.empty()) {
int ret = preset_bundle->get_differed_values_to_update(*preset, values_map);
if (!ret) {
@ -4724,7 +4739,7 @@ void GUI_App::start_sync_user_preset(bool with_progress_dlg)
cancelFn = [this, dlg]() {
return m_is_closing || dlg->WasCanceled();
};
finishFn = [this, userid = m_agent->get_user_id(), dlg, t = std::weak_ptr(m_user_sync_token)](bool ok) {
finishFn = [this, userid = m_agent->get_user_id(), dlg, t = std::weak_ptr<int>(m_user_sync_token)](bool ok) {
CallAfter([=]{
dlg->Destroy();
if (ok && m_agent && t.lock() == m_user_sync_token && userid == m_agent->get_user_id()) reload_settings();
@ -4732,7 +4747,7 @@ void GUI_App::start_sync_user_preset(bool with_progress_dlg)
};
}
else {
finishFn = [this, userid = m_agent->get_user_id(), t = std::weak_ptr(m_user_sync_token)](bool ok) {
finishFn = [this, userid = m_agent->get_user_id(), t = std::weak_ptr<int>(m_user_sync_token)](bool ok) {
CallAfter([=] {
if (ok && m_agent && t.lock() == m_user_sync_token && userid == m_agent->get_user_id()) reload_settings();
});
@ -4740,7 +4755,7 @@ void GUI_App::start_sync_user_preset(bool with_progress_dlg)
}
m_sync_update_thread = Slic3r::create_thread(
[this, progressFn, cancelFn, finishFn, t = std::weak_ptr(m_user_sync_token)] {
[this, progressFn, cancelFn, finishFn, t = std::weak_ptr<int>(m_user_sync_token)] {
// get setting list, update setting list
std::string version = preset_bundle->get_vendor_profile_version(PresetBundle::BBL_BUNDLE).to_string();
int ret = m_agent->get_setting_list2(version, [this](auto info) {
@ -5028,7 +5043,7 @@ bool GUI_App::select_language()
// 3) new_language_info->CanonicalName is a safe bet. It points to a valid dictionary name.
app_config->set("language", new_language_info->CanonicalName.ToUTF8().data());
return true;
}
}
}
return false;
@ -5936,18 +5951,15 @@ void GUI_App::MacOpenFiles(const wxArrayString &fileNames)
input_files.push_back(non_gcode_files[i]);
}
this->plater()->load_files(input_files);
}
else {
} else {
for (size_t i = 0; i < files.size(); ++i) {
this->init_params->input_files.emplace_back(files[i]);
}
}
}
else {
} else {
if (m_post_initialized) {
this->plater()->load_gcode(gcode_files.front());
}
else {
} else {
this->init_params->input_gcode = true;
this->init_params->input_files = { into_u8(gcode_files.front()) };
}
@ -6296,8 +6308,7 @@ void GUI_App::gcode_thumbnails_debug()
width = 0;
height = 0;
rows.clear();
}
else if (reading_image)
} else if (reading_image)
row += gcode_line.substr(2);
}
}