From e6b82214e5d04e5a293408f48a783dac71b13c04 Mon Sep 17 00:00:00 2001 From: QIDI TECH <893239786@qq.com> Date: Mon, 16 Sep 2024 16:22:16 +0800 Subject: [PATCH] Optimize device --- src/libslic3r/AppConfig.cpp | 7 ++++ src/libslic3r/PresetBundle.cpp | 6 ++-- src/slic3r/Config/Snapshot.cpp | 3 +- src/slic3r/GUI/BitmapCache.cpp | 43 ++++++++++++++++++++++++ src/slic3r/GUI/BitmapCache.hpp | 2 ++ src/slic3r/GUI/PrinterWebView.cpp | 55 +++++++++++++++++++++++++++---- src/slic3r/GUI/PrinterWebView.hpp | 3 ++ src/slic3r/GUI/wxExtensions.cpp | 33 +++++++++++++++++++ src/slic3r/GUI/wxExtensions.hpp | 5 +++ 9 files changed, 148 insertions(+), 9 deletions(-) diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index 12e5ca6..4cde5ab 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -221,6 +221,13 @@ void AppConfig::set_defaults() if (get("user_token").empty()) set("user_token", ""); + //y5 + if(get("user_head_url").empty()) + set("user_head_url", ""); + + if(get("user_head_name").empty()) + set("user_head_name", ""); + if (get("sending_interval").empty()) { set("sending_interval", "5"); } diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 38b44d8..f7b20e5 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -179,7 +179,8 @@ void PresetBundle::setup_directories() data_dir / "sla_print", data_dir / "sla_material", data_dir / "printer", - data_dir / "physical_printer" + data_dir / "physical_printer", + data_dir / "user" // y5 #endif }; for (const boost::filesystem::path &path : paths) { @@ -253,7 +254,8 @@ void PresetBundle::import_newer_configs(const std::string& from) from_data_dir / "sla_print", from_data_dir / "sla_material", from_data_dir / "printer", - from_data_dir / "physical_printer" + from_data_dir / "physical_printer", + from_data_dir / "user" //y5 #endif }; // copy recursively all files diff --git a/src/slic3r/Config/Snapshot.cpp b/src/slic3r/Config/Snapshot.cpp index b5a2a52..c972287 100644 --- a/src/slic3r/Config/Snapshot.cpp +++ b/src/slic3r/Config/Snapshot.cpp @@ -242,7 +242,8 @@ void Snapshot::export_vendor_configs(AppConfig &config) const config.set_vendors(std::move(vendors)); } -static constexpr auto snapshot_subdirs = { "print", "sla_print", "filament", "sla_material", "printer", "physical_printer", "vendor" }; +//y5 +static constexpr auto snapshot_subdirs = { "print", "sla_print", "filament", "sla_material", "printer", "physical_printer", "vendor", "user" }; // Perform a deep compare of the active print / sla_print / filament / sla_material / printer / physical_printer / vendor directories. // Return true if the content of the current print / sla_print / filament / sla_material / printer / physical_printer / vendor directories diff --git a/src/slic3r/GUI/BitmapCache.cpp b/src/slic3r/GUI/BitmapCache.cpp index c647fa4..1fca5b4 100644 --- a/src/slic3r/GUI/BitmapCache.cpp +++ b/src/slic3r/GUI/BitmapCache.cpp @@ -446,6 +446,49 @@ wxBitmapBundle* BitmapCache::from_png(const std::string& bitmap_name, unsigned w return this->insert_bndl(bitmap_key, wxImage_to_wxBitmap_with_alpha(std::move(image))); } +//y5 +wxBitmapBundle *BitmapCache::from_png_of_login(const std::string &bitmap_name, unsigned width, unsigned height) +{ + std::string bitmap_key = bitmap_name + (height != 0 ? "-h" + std::to_string(height) : "-w" + std::to_string(width)); + + auto it = m_bndl_map.find(bitmap_key); + if (it != m_bndl_map.end()) + return it->second; + + wxImage image; + std::string imgge_path = (boost::filesystem::path(Slic3r::data_dir()) / "user" / bitmap_name).make_preferred().string(); + if (!image.LoadFile(imgge_path, wxBITMAP_TYPE_ANY) || image.GetWidth() == 0 || + image.GetHeight() == 0) + return nullptr; + + if (height != 0 && unsigned(image.GetHeight()) != height) + width = unsigned(0.5f + float(image.GetWidth()) * height / image.GetHeight()); + else if (width != 0 && unsigned(image.GetWidth()) != width) + height = unsigned(0.5f + float(image.GetHeight()) * width / image.GetWidth()); + + if (height != 0 && width != 0) + image.Rescale(width, height, wxIMAGE_QUALITY_BILINEAR); + + int radius = height / 2; + int cx = image.GetWidth() / 2; + int cy = image.GetHeight() / 2; + for (int y = 0; y < height; ++y) { + for (int x = 0; x < height; ++x) { + int dx = x - radius; + int dy = y - radius; + if (dx * dx + dy * dy <= radius * radius) { + image.SetRGB(x, y, image.GetRed(cx + dx, cy + dy), image.GetGreen(cx + dx, cy + dy), image.GetBlue(cx + dx, cy + dy)); + image.SetAlpha(x, y, 255); + } else { + image.SetRGB(x, y, 38, 38, 41); + image.SetAlpha(x, y, 0); + } + } + } + return this->insert_bndl(bitmap_key, wxImage_to_wxBitmap_with_alpha(std::move(image))); +} + + wxBitmap* BitmapCache::load_svg(const std::string &bitmap_name, unsigned target_width, unsigned target_height, const bool grayscale/* = false*/, const bool dark_mode/* = false*/, const std::string& new_color /*= ""*/) { diff --git a/src/slic3r/GUI/BitmapCache.hpp b/src/slic3r/GUI/BitmapCache.hpp index 6ba9ae1..d273e82 100644 --- a/src/slic3r/GUI/BitmapCache.hpp +++ b/src/slic3r/GUI/BitmapCache.hpp @@ -51,6 +51,8 @@ public: static void nsvgGetDataFromFileWithReplace(const char* filename, std::string& data_str, const std::map& replaces); wxBitmapBundle* from_svg(const std::string& bitmap_name, unsigned target_width, unsigned target_height, const bool dark_mode, const std::string& new_color = ""); wxBitmapBundle* from_png(const std::string& bitmap_name, unsigned width, unsigned height); + //y5 + wxBitmapBundle *from_png_of_login(const std::string &bitmap_name, unsigned width, unsigned height); // Load svg from resources/icons. bitmap_key is given without the .svg suffix. SVG will be rasterized to provided height/width. wxBitmap* load_svg(const std::string &bitmap_key, unsigned width = 0, unsigned height = 0, const bool grayscale = false, const bool dark_mode = false, const std::string& new_color = ""); diff --git a/src/slic3r/GUI/PrinterWebView.cpp b/src/slic3r/GUI/PrinterWebView.cpp index 23fb431..33b572d 100644 --- a/src/slic3r/GUI/PrinterWebView.cpp +++ b/src/slic3r/GUI/PrinterWebView.cpp @@ -30,6 +30,9 @@ PrinterWebView::PrinterWebView(wxWindow *parent) : wxPanel(parent, wxID_ANY, wxD m_isSimpleMode = wxGetApp().app_config->get_bool("machine_list_minification"); m_isNetMode = wxGetApp().app_config->get_bool("machine_list_net"); m_isloginin = (wxGetApp().app_config->get("user_token") != ""); + //y5 + if (m_isloginin) + m_user_head_name = wxGetApp().app_config->get("user_head_name"); if (m_isloginin) { #if QDT_RELEASE_TO_PUBLIC @@ -162,10 +165,11 @@ wxBoxSizer *PrinterWebView::init_login_bar(wxPanel *Panel) { wxBoxSizer *buttonsizer = new wxBoxSizer(wxHORIZONTAL); + //y5 if (m_isSimpleMode) - staticBitmap = new wxStaticBitmap(Panel, wxID_ANY, ScalableBitmap(this, "user_dark", wxSize(40, 40)).get_bitmap()); - else - staticBitmap = new wxStaticBitmap(Panel, wxID_ANY, ScalableBitmap(this, "user_dark", wxSize(60, 60)).get_bitmap()); + staticBitmap = new wxStaticBitmap(Panel, wxID_ANY, *get_bmp_bundle_of_login(m_user_head_name, 40, 40)); + else + staticBitmap = new wxStaticBitmap(Panel, wxID_ANY, *get_bmp_bundle_of_login(m_user_head_name, 60, 60)); StateColor text_color(std::pair(wxColour(57, 57, 61), StateColor::Disabled), std::pair(wxColour(68, 121, 251), StateColor::Pressed), @@ -309,6 +313,7 @@ void PrinterWebView::CreatThread() { break; if (!m_net_buttons.empty()) { BOOST_LOG_TRIVIAL(error) << "machine IP: " << device.local_ip; + //y5 std::unique_ptr printhost(PrintHost::get_print_host_url(device.url, device.local_ip)); if (!printhost) { BOOST_LOG_TRIVIAL(error) << ("Could not get a valid Printer Host reference"); @@ -459,6 +464,8 @@ void PrinterWebView::SetLoginStatus(bool status) { wxString wxname = from_u8(name); login_button->SetLabel(wxname); std::vector m_devices = m_qidinetwork.get_device_list(msg); + //y5 + m_user_head_name = wxGetApp().app_config->get("user_head_name"); SetPresetChanged(true); #endif m_isloginin = true; @@ -472,6 +479,17 @@ void PrinterWebView::SetLoginStatus(bool status) { //y3 if (webisNetMode == isNetWeb) webisNetMode = isDisconnect; + //y5 + std::string head_name = wxGetApp().app_config->get("user_head_name"); + wxString head_savePath = (boost::filesystem::path(Slic3r::data_dir()) / "user" / head_name).make_preferred().string(); + std::ifstream file(head_savePath); + if (file.good()) { + file.close(); + remove(head_savePath.c_str()); + } + wxGetApp().app_config->set("user_head_url", ""); + wxGetApp().app_config->set("user_head_name", ""); + m_user_head_name = ""; SetPresetChanged(true); UpdateState(); } @@ -595,7 +613,25 @@ void PrinterWebView::AddNetButton(const Device device) machine_button->SetIsSimpleMode(m_isSimpleMode); machine_button->Bind(wxEVT_BUTTON, [this, device](wxCommandEvent &event) { - std::string formattedHost = "http://" + device.url; + //y5 + std::string formattedHost; + if (wxGetApp().app_config->get("dark_color_mode") == "1") + formattedHost = device.link_url + "&theme=dark"; + else + formattedHost = device.link_url + "&theme=light"; + + std::string formattedHost1 = "http://fluidd_" + formattedHost; + std::string formattedHost2 = "http://fluidd2_" + formattedHost; + if (formattedHost1 == m_web || formattedHost2 == m_web) + return; + + if (m_isfluidd_1) { + formattedHost = "http://fluidd_" + formattedHost; + m_isfluidd_1 = false; + } else { + formattedHost = "http://fluidd2_" + formattedHost; + m_isfluidd_1 = true; + } load_net_url(formattedHost, device.local_ip); }); @@ -698,7 +734,8 @@ void PrinterWebView::OnZoomButtonClick(wxCommandEvent &event) m_isSimpleMode = !m_isSimpleMode; if (!m_isSimpleMode) { text_static->Show(); - staticBitmap->SetBitmap(ScalableBitmap(this, "user_dark", wxSize(60, 60)).get_bitmap()); + //y5 + staticBitmap->SetBitmap(*get_bmp_bundle_of_login(m_user_head_name, 60, 60)); login_button->SetIsSimpleMode(m_isSimpleMode); wxGetApp().app_config->set("machine_list_minification", "0"); toggleBar->SetSize(327); @@ -713,7 +750,8 @@ void PrinterWebView::OnZoomButtonClick(wxCommandEvent &event) } } else { text_static->Hide(); - staticBitmap->SetBitmap(ScalableBitmap(this, "user_dark", wxSize(40, 40)).get_bitmap()); + //y5 + staticBitmap->SetBitmap(*get_bmp_bundle_of_login(m_user_head_name, 40, 40)); login_button->SetIsSimpleMode(m_isSimpleMode); wxGetApp().app_config->set("machine_list_minification", "1"); @@ -972,6 +1010,11 @@ void PrinterWebView::UpdateLayout() button->Refresh(); } } + //y5 + if (!m_isSimpleMode) + staticBitmap->SetBitmap(*get_bmp_bundle_of_login(m_user_head_name, 60, 60)); + else + staticBitmap->SetBitmap(*get_bmp_bundle_of_login(m_user_head_name, 40, 40)); } void PrinterWebView::OnScrollup(wxScrollWinEvent &event) { diff --git a/src/slic3r/GUI/PrinterWebView.hpp b/src/slic3r/GUI/PrinterWebView.hpp index 6d82a6c..13dcbb8 100644 --- a/src/slic3r/GUI/PrinterWebView.hpp +++ b/src/slic3r/GUI/PrinterWebView.hpp @@ -164,6 +164,9 @@ private: std::string select_machine_name; WebState webisNetMode = isDisconnect; std::set m_exit_host; + //y5 + std::string m_user_head_name; + bool m_isfluidd_1; }; //y3 diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index a11cc20..1d69372 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -443,6 +443,39 @@ wxBitmapBundle* get_bmp_bundle(const std::string& bmp_name_in, int width/* = 16* return bmp; } +//y5 +wxBitmapBundle *get_bmp_bundle_of_login(const std::string &bmp_name_in, + int width /* = 16*/, + int height /* = -1*/, + const std::string &new_color /* = std::string()*/) +{ +#ifdef __WXGTK2__ + width *= scale(); + if (height > 0) + height *= scale(); +#endif // __WXGTK2__ + + static Slic3r::GUI::BitmapCache cache; + + std::string bmp_name = bmp_name_in; + + if (height < 0) + height = width; + // Try loading an SVG first, then PNG if SVG is not found: + wxBitmapBundle *bmp; + if (!bmp_name.empty()) + bmp = cache.from_png_of_login(bmp_name, width, height); + else + bmp = cache.from_png("user_dark", width, height); + if (bmp == nullptr) { + if (!bmp) + // Neither SVG nor PNG has been found, raise error + throw Slic3r::RuntimeError("Could not load bitmap: " + bmp_name); + } + return bmp; +} + + wxBitmapBundle* get_empty_bmp_bundle(int width, int height) { static Slic3r::GUI::BitmapCache cache; diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index 63d95d3..ceed4cf 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -51,6 +51,11 @@ int em_unit(wxWindow* win); int mode_icon_px_size(); wxBitmapBundle* get_bmp_bundle(const std::string& bmp_name, int width = 16, int height = -1, const std::string& new_color_rgb = std::string()); +//y5 +wxBitmapBundle *get_bmp_bundle_of_login(const std::string &bmp_name, + int width = 16, + int height = -1, + const std::string &new_color_rgb = std::string()); wxBitmapBundle* get_empty_bmp_bundle(int width, int height); wxBitmapBundle* get_solid_bmp_bundle(int width, int height, const std::string& color);