Update the codes to 01.01.00.10 for the formal release

1. first formal version of macos
2. add the bambu networking plugin install logic
3. auto compute the wipe volume when filament change
4. add the logic of wiping into support
5. refine the GUI layout and icons, improve the gui apperance in lots of
   small places
6. serveral improve to support
7. support AMS auto-mapping
8. disable lots of unstable features: such as params table, media file download, HMS
9. fix serveral kinds of bugs
10. update the document of building
11. ...
This commit is contained in:
lane.wei 2022-07-22 17:46:10 +08:00 committed by Lane.Wei
parent e1528e4299
commit e9e4d75877
267 changed files with 10326 additions and 32228 deletions

View file

@ -83,6 +83,8 @@ struct CurlGlobalInit
std::unique_ptr<CurlGlobalInit> CurlGlobalInit::instance;
std::map<std::string, std::string> extra_headers;
struct Http::priv
{
enum {
@ -454,9 +456,10 @@ void Http::priv::http_perform()
}
}
Http::Http(const std::string &url) : p(new priv(url))
{
;
Http::Http(const std::string &url) : p(new priv(url)) {
for (auto it = extra_headers.begin(); it != extra_headers.end(); it++)
this->header(it->first, it->second);
}
@ -723,6 +726,11 @@ Http Http::del(std::string url)
return http;
}
void Http::set_extra_headers(std::map<std::string, std::string> headers)
{
extra_headers.swap(headers);
}
bool Http::ca_file_supported()
{
::CURL *curl = ::curl_easy_init();

View file

@ -10,6 +10,23 @@
namespace Slic3r {
enum HttpErrorCode
{
HttpErrorResourcesNotFound = 2,
HtttErrorNoDevice = 3,
HttpErrorRequestLogin = 4,
HttpErrorResourcesNotExists = 6,
HttpErrorMQTTError = 7,
HttpErrorResourcesForbidden = 8,
HttpErrorInternalRequestError = 9,
HttpErrorInternalError = 10,
HttpErrorFileFormatError = 11,
HttpErrorResoucesConflict = 12,
HttpErrorTimeout = 13,
HttpErrorResourcesExhaust = 14,
HttpErrorVersionLimited = 15,
};
/// Represetns a Http request
class Http : public std::enable_shared_from_this<Http> {
private:
@ -65,6 +82,9 @@ public:
static Http put2(std::string url);
static Http patch(std::string url);
//BBS set global header for each http request
static void set_extra_headers(std::map<std::string, std::string> headers);
~Http();
Http(const Http &) = delete;

View file

@ -97,3 +97,13 @@ void set_miniaturizable(void * window)
}
@end
@implementation NSTextField (FocusRing)
- (NSFocusRingType) focusRingType
{
return NSFocusRingTypeNone;
}
@end

View file

@ -11,16 +11,24 @@
#include "NetworkAgent.hpp"
using namespace BBL;
namespace Slic3r {
#define BAMBU_SOURCE_LIBRARY "BambuSource"
#if defined(_MSC_VER) || defined(_WIN32)
static HMODULE netwoking_module = NULL;
static HMODULE source_module = NULL;
#else
static void* netwoking_module = NULL;
static void* source_module = NULL;
#endif
func_check_debug_consistent NetworkAgent::check_debug_consistent_ptr = nullptr;
func_get_version NetworkAgent::get_version_ptr = nullptr;
func_create_agent NetworkAgent::create_agent_ptr = nullptr;
func_destroy_agent NetworkAgent::destroy_agent_ptr = nullptr;
func_init_log NetworkAgent::init_log_ptr = nullptr;
@ -103,36 +111,50 @@ int NetworkAgent::initialize_network_module()
{
//int ret = -1;
std::string library;
auto plugin_folder = boost::filesystem::path(wxStandardPaths::Get().GetUserDataDir().ToUTF8().data()) / "plugins";
//first load the library
#if defined(_MSC_VER) || defined(_WIN32)
library = std::string(BAMBU_NETWORK_LIBRARY) + ".dll";
library = plugin_folder.string() + "/" + std::string(BAMBU_NETWORK_LIBRARY) + ".dll";
wchar_t lib_wstr[128];
memset(lib_wstr, 0, sizeof(lib_wstr));
::MultiByteToWideChar(CP_UTF8, NULL, library.c_str(), strlen(library.c_str())+1, lib_wstr, sizeof(lib_wstr) / sizeof(lib_wstr[0]));
netwoking_module = LoadLibrary(lib_wstr);
#elif defined(__WXMAC__)
std::string resource_dir = resources_dir();
library = resource_dir + "/../Library/"+ std::string("lib") + BAMBU_NETWORK_LIBRARY + ".dylib";
/*if (!netwoking_module) {
library = std::string(BAMBU_NETWORK_LIBRARY) + ".dll";
memset(lib_wstr, 0, sizeof(lib_wstr));
::MultiByteToWideChar(CP_UTF8, NULL, library.c_str(), strlen(library.c_str()) + 1, lib_wstr, sizeof(lib_wstr) / sizeof(lib_wstr[0]));
netwoking_module = LoadLibrary(lib_wstr);
}*/
#else
#if defined(__WXMAC__)
library = plugin_folder.string() + "/" + std::string("lib") + std::string(BAMBU_NETWORK_LIBRARY) + ".dylib";
#else
library = plugin_folder.string() + "/" + std::string("lib") + std::string(BAMBU_NETWORK_LIBRARY) + ".so";
#endif
printf("loading network module at %s\n", library.c_str());
netwoking_module = dlopen( library.c_str(), RTLD_LAZY);
if (!netwoking_module) {
/*#if defined(__WXMAC__)
library = std::string("lib") + BAMBU_NETWORK_LIBRARY + ".dylib";
netwoking_module = dlopen( library.c_str(), RTLD_LAZY);
#else
library = std::string("lib") + BAMBU_NETWORK_LIBRARY + ".so";
#endif*/
//netwoking_module = dlopen( library.c_str(), RTLD_LAZY);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", error, dlerror is %1%")%dlerror();
}
printf("after dlopen, network_module is %p\n", netwoking_module);
#else
library = std::string("lib") + BAMBU_NETWORK_LIBRARY + ".so";
netwoking_module = dlopen( library.c_str(), RTLD_LAZY);
#endif
if (!netwoking_module) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", can not Load Library for %1%")%library;
return -1;
}
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", successfully loaded library %1%")%library;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", successfully loaded library %1%, module %2%")%library %netwoking_module;
//load the functions
check_debug_consistent_ptr = reinterpret_cast<func_check_debug_consistent>(get_network_function("bambu_network_check_debug_consistent"));
get_version_ptr = reinterpret_cast<func_get_version>(get_network_function("bambu_network_get_version"));
create_agent_ptr = reinterpret_cast<func_create_agent>(get_network_function("bambu_network_create_agent"));
destroy_agent_ptr = reinterpret_cast<func_destroy_agent>(get_network_function("bambu_network_destroy_agent"));
init_log_ptr = reinterpret_cast<func_init_log>(get_network_function("bambu_network_init_log"));
@ -196,6 +218,140 @@ int NetworkAgent::initialize_network_module()
return 0;
}
int NetworkAgent::unload_network_module()
{
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", network module %1%")%netwoking_module;
#if defined(_MSC_VER) || defined(_WIN32)
if (netwoking_module) {
FreeLibrary(netwoking_module);
netwoking_module = NULL;
}
if (source_module) {
FreeLibrary(source_module);
source_module = NULL;
}
#else
if (netwoking_module) {
dlclose(netwoking_module);
netwoking_module = NULL;
}
if (source_module) {
dlclose(source_module);
source_module = NULL;
}
#endif
check_debug_consistent_ptr = nullptr;
get_version_ptr = nullptr;
create_agent_ptr = nullptr;
destroy_agent_ptr = nullptr;
init_log_ptr = nullptr;
set_config_dir_ptr = nullptr;
set_cert_file_ptr = nullptr;
set_country_code_ptr = nullptr;
start_ptr = nullptr;
set_on_ssdp_msg_fn_ptr = nullptr;
set_on_user_login_fn_ptr = nullptr;
set_on_printer_connected_fn_ptr = nullptr;
set_on_server_connected_fn_ptr = nullptr;
set_on_http_error_fn_ptr = nullptr;
set_get_country_code_fn_ptr = nullptr;
set_on_message_fn_ptr = nullptr;
set_on_local_connect_fn_ptr = nullptr;
set_on_local_message_fn_ptr = nullptr;
connect_server_ptr = nullptr;
is_server_connected_ptr = nullptr;
refresh_connection_ptr = nullptr;
start_subscribe_ptr = nullptr;
stop_subscribe_ptr = nullptr;
send_message_ptr = nullptr;
connect_printer_ptr = nullptr;
disconnect_printer_ptr = nullptr;
send_message_to_printer_ptr = nullptr;
start_discovery_ptr = nullptr;
change_user_ptr = nullptr;
is_user_login_ptr = nullptr;
user_logout_ptr = nullptr;
get_user_id_ptr = nullptr;
get_user_name_ptr = nullptr;
get_user_avatar_ptr = nullptr;
get_user_nickanme_ptr = nullptr;
build_login_cmd_ptr = nullptr;
build_logout_cmd_ptr = nullptr;
build_login_info_ptr = nullptr;
bind_ptr = nullptr;
unbind_ptr = nullptr;
get_bambulab_host_ptr = nullptr;
get_user_selected_machine_ptr = nullptr;
set_user_selected_machine_ptr = nullptr;
start_print_ptr = nullptr;
start_local_print_with_record_ptr = nullptr;
start_local_print_ptr = nullptr;
get_user_presets_ptr = nullptr;
request_setting_id_ptr = nullptr;
put_setting_ptr = nullptr;
get_setting_list_ptr = nullptr;
delete_setting_ptr = nullptr;
get_studio_info_url_ptr = nullptr;
set_extra_http_header_ptr = nullptr;
check_user_task_report_ptr = nullptr;
get_user_print_info_ptr = nullptr;
get_printer_firmware_ptr = nullptr;
get_task_plate_index_ptr = nullptr;
get_slice_info_ptr = nullptr;
query_bind_status_ptr = nullptr;
modify_printer_name_ptr = nullptr;
get_camera_url_ptr = nullptr;
return 0;
}
#if defined(_MSC_VER) || defined(_WIN32)
HMODULE NetworkAgent::get_bambu_source_entry()
#else
void* NetworkAgent::get_bambu_source_entry()
#endif
{
if ((source_module) || (!netwoking_module))
return source_module;
//int ret = -1;
std::string library;
auto plugin_folder = boost::filesystem::path(wxStandardPaths::Get().GetUserDataDir().ToUTF8().data()) / "plugins";
#if defined(_MSC_VER) || defined(_WIN32)
wchar_t lib_wstr[128];
//goto load bambu source
library = plugin_folder.string() + "/" + std::string(BAMBU_SOURCE_LIBRARY) + ".dll";
memset(lib_wstr, 0, sizeof(lib_wstr));
::MultiByteToWideChar(CP_UTF8, NULL, library.c_str(), strlen(library.c_str())+1, lib_wstr, sizeof(lib_wstr) / sizeof(lib_wstr[0]));
source_module = LoadLibrary(lib_wstr);
/*if (!source_module) {
library = std::string(BAMBU_SOURCE_LIBRARY) + ".dll";
memset(lib_wstr, 0, sizeof(lib_wstr));
::MultiByteToWideChar(CP_UTF8, NULL, library.c_str(), strlen(library.c_str()) + 1, lib_wstr, sizeof(lib_wstr) / sizeof(lib_wstr[0]));
source_module = LoadLibrary(lib_wstr);
}*/
#else
#if defined(__WXMAC__)
library = plugin_folder.string() + "/" + std::string("lib") + std::string(BAMBU_SOURCE_LIBRARY) + ".dylib";
#else
library = plugin_folder.string() + "/" + std::string("lib") + std::string(BAMBU_SOURCE_LIBRARY) + ".so";
#endif
source_module = dlopen( library.c_str(), RTLD_LAZY);
/*if (!source_module) {
#if defined(__WXMAC__)
library = std::string("lib") + BAMBU_SOURCE_LIBRARY + ".dylib";
#else
library = std::string("lib") + BAMBU_SOURCE_LIBRARY + ".so";
#endif
source_module = dlopen( library.c_str(), RTLD_LAZY);
}*/
#endif
return source_module;
}
void* NetworkAgent::get_network_function(const char* name)
{
void* function = nullptr;
@ -215,6 +371,28 @@ void* NetworkAgent::get_network_function(const char* name)
return function;
}
std::string NetworkAgent::get_version()
{
bool consistent = true;
//check the debug consistent first
if (check_debug_consistent_ptr) {
#if defined(NDEBUG)
consistent = check_debug_consistent_ptr(false);
#else
consistent = check_debug_consistent_ptr(true);
#endif
}
if (!consistent) {
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", inconsistent libraryreturn 00.00.00.00!");
return "00.00.00.00";
}
if (get_version_ptr) {
return get_version_ptr();
}
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", get_version not supportedreturn 00.00.00.00!");
return "00.00.00.00";
}
int NetworkAgent::init_log()
{
int ret = 0;
@ -737,7 +915,7 @@ int NetworkAgent::check_user_task_report(int* task_id, bool* printable)
int ret = 0;
if (network_agent && check_user_task_report_ptr) {
ret = check_user_task_report_ptr(network_agent, task_id, printable);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" error: network_agent=%1%, ret=%2%, task_id=%3%, printable=%4%")%network_agent %ret %(*task_id) %(*printable);
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" error: network_agent=%1%, ret=%2%, task_id=%3%, printable=%4%")%network_agent %ret %(*task_id) %(*printable);
}
return ret;
}
@ -747,7 +925,7 @@ int NetworkAgent::get_user_print_info(unsigned int* http_code, std::string* http
int ret = 0;
if (network_agent && get_user_print_info_ptr) {
ret = get_user_print_info_ptr(network_agent, http_code, http_body);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" error: network_agent=%1%, ret=%2%, http_code=%3%, http_body=%4%")%network_agent %ret %(*http_code) %(*http_body);
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" error: network_agent=%1%, ret=%2%, http_code=%3%, http_body=%4%")%network_agent %ret %(*http_code) %(*http_body);
}
return ret;
}
@ -757,7 +935,7 @@ int NetworkAgent::get_printer_firmware(std::string dev_id, unsigned* http_code,
int ret = 0;
if (network_agent && get_printer_firmware_ptr) {
ret = get_printer_firmware_ptr(network_agent, dev_id, http_code, http_body);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" : network_agent=%1%, ret=%2%, dev_id=%3%, http_code=%4%, http_body=%5%")
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" : network_agent=%1%, ret=%2%, dev_id=%3%, http_code=%4%, http_body=%5%")
%network_agent %ret %dev_id %(*http_code) %(*http_body);
}
return ret;
@ -779,7 +957,7 @@ int NetworkAgent::get_slice_info(std::string project_id, std::string profile_id,
int ret;
if (network_agent && get_slice_info_ptr) {
ret = get_slice_info_ptr(network_agent, project_id, profile_id, plate_index, slice_json);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" : network_agent=%1%, project_id=%2%, profile_id=%3%, plate_index=%4%, slice_json=%5%")
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" : network_agent=%1%, project_id=%2%, profile_id=%3%, plate_index=%4%, slice_json=%5%")
%network_agent %project_id %profile_id %plate_index %(*slice_json);
}
return ret;

View file

@ -6,7 +6,8 @@
using namespace BBL;
namespace Slic3r {
typedef bool (*func_check_debug_consistent)(bool is_debug);
typedef std::string (*func_get_version)(void);
typedef void* (*func_create_agent)(void);
typedef int (*func_destroy_agent)(void *agent);
typedef int (*func_init_log)(void *agent);
@ -75,6 +76,13 @@ class NetworkAgent
public:
static int initialize_network_module();
static int unload_network_module();
#if defined(_MSC_VER) || defined(_WIN32)
static HMODULE get_bambu_source_entry();
#else
static void* get_bambu_source_entry();
#endif
static std::string get_version();
static void* get_network_function(const char* name);
NetworkAgent();
~NetworkAgent();
@ -141,6 +149,8 @@ private:
void* network_agent { nullptr };
static func_check_debug_consistent check_debug_consistent_ptr;
static func_get_version get_version_ptr;
static func_create_agent create_agent_ptr;
static func_destroy_agent destroy_agent_ptr;
static func_init_log init_log_ptr;

View file

@ -187,7 +187,7 @@ struct Updates
wxDEFINE_EVENT(EVT_SLIC3R_VERSION_ONLINE, wxCommandEvent);
wxDEFINE_EVENT(EVT_SLIC3R_EXPERIMENTAL_VERSION_ONLINE, wxCommandEvent);
wxDEFINE_EVENT(EVT_ENTER_FORCE_UPGRADE, wxCommandEvent);
struct PresetUpdater::priv
{
@ -225,9 +225,9 @@ struct PresetUpdater::priv
void prune_tmps() const;
void sync_version() const;
void parse_version_string(const std::string& body) const;
void sync_resources(std::map<std::string, Resource> &resources);
void sync_config(const VendorMap vendors);
void sync_tooltip();
void sync_resources(std::string http_url, std::map<std::string, Resource> &resources);
void sync_config(std::string http_url, const VendorMap vendors);
void sync_tooltip(std::string http_url);
//BBS: refine preset update logic
bool install_bundles_rsrc(std::vector<std::string> bundles, bool snapshot) const;
@ -401,6 +401,7 @@ void PresetUpdater::priv::sync_version() const
// Version string must contain release version on first line. Follows non-mandatory alpha / beta releases on following lines (alpha=2.0.0-alpha1).
void PresetUpdater::priv::parse_version_string(const std::string& body) const
{
#if 0
// release version
std::string version;
const auto first_nl_pos = body.find_first_of("\n\r");
@ -464,21 +465,17 @@ void PresetUpdater::priv::parse_version_string(const std::string& body) const
evt->SetString(GUI::from_u8(version));
GUI::wxGetApp().QueueEvent(evt);
}
#endif
return;
}
//BBS: refine the Preset Updater logic
// Download vendor indices. Also download new bundles if an index indicates there's a new one available.
// Both are saved in cache.
void PresetUpdater::priv::sync_resources(std::map<std::string, Resource> &resources)
void PresetUpdater::priv::sync_resources(std::string http_url, std::map<std::string, Resource> &resources)
{
std::map<std::string, Resource> resource_list;
NetworkAgent* m_agent = GUI::wxGetApp().getAgent();
if (!m_agent) {
BOOST_LOG_TRIVIAL(error) << "[BBL Updater]: can not get account manager";
return;
}
BOOST_LOG_TRIVIAL(info) << format("[BBL Updater]: get preferred setting version for app version %1%, url: `%2%`", SLIC3R_APP_NAME, version_check_url);
std::string query_params = "?";
@ -494,7 +491,7 @@ void PresetUpdater::priv::sync_resources(std::map<std::string, Resource> &resour
first = false;
}
std::string url = m_agent->get_studio_info_url();
std::string url = http_url;
url += query_params;
Slic3r::Http http = Slic3r::Http::get(url);
http.on_complete([this, &resource_list, resources](std::string body, unsigned) {
@ -606,7 +603,7 @@ void PresetUpdater::priv::sync_resources(std::map<std::string, Resource> &resour
//BBS: refine the Preset Updater logic
// Download vendor indices. Also download new bundles if an index indicates there's a new one available.
// Both are saved in cache.
void PresetUpdater::priv::sync_config(const VendorMap vendors)
void PresetUpdater::priv::sync_config(std::string http_url, const VendorMap vendors)
{
std::map<std::string, std::pair<Semver, std::string>> vendor_list;
std::map<std::string, std::string> vendor_descriptions;
@ -614,12 +611,6 @@ void PresetUpdater::priv::sync_config(const VendorMap vendors)
if (!enabled_config_update) { return; }
NetworkAgent* agent = GUI::wxGetApp().getAgent();
if (!agent) {
BOOST_LOG_TRIVIAL(error) << "[BBL Updater]: can not get account manager";
return;
}
BOOST_LOG_TRIVIAL(info) << format("[BBL Updater]: get preferred setting version for app version %1%, url: `%2%`", SLIC3R_APP_NAME, version_check_url);
std::string query_params = "?";
@ -640,7 +631,7 @@ void PresetUpdater::priv::sync_config(const VendorMap vendors)
query_params += query_vendor;
}
std::string url = agent->get_studio_info_url();
std::string url = http_url;
url += query_params;
Slic3r::Http http = Slic3r::Http::get(url);
http.on_complete(
@ -787,7 +778,7 @@ void PresetUpdater::priv::sync_config(const VendorMap vendors)
}
}
void PresetUpdater::priv::sync_tooltip()
void PresetUpdater::priv::sync_tooltip(std::string http_url)
{
try {
std::string language = GUI::into_u8(GUI::wxGetApp().current_language_code());
@ -805,7 +796,7 @@ void PresetUpdater::priv::sync_tooltip()
{"slicer/tooltip/common", { common_version, "", "", (cache_root / "common").string() }},
{"slicer/tooltip/" + language, { language_version, "", "", (cache_root / language).string() }}
};
sync_resources(resources);
sync_resources(http_url, resources);
for (auto &r : resources) {
if (!r.second.url.empty()) {
GUI::MarkdownTip::Reload();
@ -1063,7 +1054,7 @@ PresetUpdater::~PresetUpdater()
//BBS: change directories by design
//BBS: refine the preset updater logic
void PresetUpdater::sync(PresetBundle *preset_bundle)
void PresetUpdater::sync(std::string http_url, PresetBundle *preset_bundle)
{
//p->set_download_prefs(GUI::wxGetApp().app_config);
if (!p->enabled_version_check && !p->enabled_config_update) { return; }
@ -1073,11 +1064,11 @@ void PresetUpdater::sync(PresetBundle *preset_bundle)
// into the closure (but perhaps the compiler can elide this).
VendorMap vendors = preset_bundle->vendors;
p->thread = std::thread([this, vendors]() {
p->thread = std::thread([this, vendors, http_url]() {
this->p->prune_tmps();
this->p->sync_version();
this->p->sync_config(std::move(vendors));
this->p->sync_tooltip();
this->p->sync_config(http_url, std::move(vendors));
this->p->sync_tooltip(http_url);
});
}

View file

@ -26,7 +26,7 @@ public:
~PresetUpdater();
// If either version check or config updating is enabled, get the appropriate data in the background and cache it.
void sync(PresetBundle *preset_bundle);
void sync(std::string http_url, PresetBundle *preset_bundle);
// If version check is enabled, check if chaced online slic3r version is newer, notify if so.
void slic3r_update_notify();
@ -67,6 +67,7 @@ private:
wxDECLARE_EVENT(EVT_SLIC3R_VERSION_ONLINE, wxCommandEvent);
wxDECLARE_EVENT(EVT_SLIC3R_EXPERIMENTAL_VERSION_ONLINE, wxCommandEvent);
wxDECLARE_EVENT(EVT_ENTER_FORCE_UPGRADE, wxCommandEvent);
}
#endif

View file

@ -36,7 +36,7 @@ namespace BBL {
#define BAMBU_NETWORK_LIBRARY "bambu_networking"
#define BAMBU_NETWORK_AGENT_NAME "bambu_network_agent"
#define BAMBU_NETWORK_AGENT_VERSION "1.0.0.2"
#define BAMBU_NETWORK_AGENT_VERSION "01.01.00.10"
//iot preset type strings