Optimize device

This commit is contained in:
QIDI TECH
2024-09-16 16:22:16 +08:00
parent 5ed1560c59
commit e6b82214e5
9 changed files with 148 additions and 9 deletions

View File

@@ -221,6 +221,13 @@ void AppConfig::set_defaults()
if (get("user_token").empty()) if (get("user_token").empty())
set("user_token", ""); 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()) { if (get("sending_interval").empty()) {
set("sending_interval", "5"); set("sending_interval", "5");
} }

View File

@@ -179,7 +179,8 @@ void PresetBundle::setup_directories()
data_dir / "sla_print", data_dir / "sla_print",
data_dir / "sla_material", data_dir / "sla_material",
data_dir / "printer", data_dir / "printer",
data_dir / "physical_printer" data_dir / "physical_printer",
data_dir / "user" // y5
#endif #endif
}; };
for (const boost::filesystem::path &path : paths) { 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_print",
from_data_dir / "sla_material", from_data_dir / "sla_material",
from_data_dir / "printer", from_data_dir / "printer",
from_data_dir / "physical_printer" from_data_dir / "physical_printer",
from_data_dir / "user" //y5
#endif #endif
}; };
// copy recursively all files // copy recursively all files

View File

@@ -242,7 +242,8 @@ void Snapshot::export_vendor_configs(AppConfig &config) const
config.set_vendors(std::move(vendors)); 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. // 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 // Return true if the content of the current print / sla_print / filament / sla_material / printer / physical_printer / vendor directories

View File

@@ -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))); 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, 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 /*= ""*/) const bool grayscale/* = false*/, const bool dark_mode/* = false*/, const std::string& new_color /*= ""*/)
{ {

View File

@@ -51,6 +51,8 @@ public:
static void nsvgGetDataFromFileWithReplace(const char* filename, std::string& data_str, const std::map<std::string, std::string>& replaces); static void nsvgGetDataFromFileWithReplace(const char* filename, std::string& data_str, const std::map<std::string, std::string>& 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_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); 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. // 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 = ""); 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 = "");

View File

@@ -30,6 +30,9 @@ PrinterWebView::PrinterWebView(wxWindow *parent) : wxPanel(parent, wxID_ANY, wxD
m_isSimpleMode = wxGetApp().app_config->get_bool("machine_list_minification"); m_isSimpleMode = wxGetApp().app_config->get_bool("machine_list_minification");
m_isNetMode = wxGetApp().app_config->get_bool("machine_list_net"); m_isNetMode = wxGetApp().app_config->get_bool("machine_list_net");
m_isloginin = (wxGetApp().app_config->get("user_token") != ""); 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 (m_isloginin) {
#if QDT_RELEASE_TO_PUBLIC #if QDT_RELEASE_TO_PUBLIC
@@ -162,10 +165,11 @@ wxBoxSizer *PrinterWebView::init_login_bar(wxPanel *Panel)
{ {
wxBoxSizer *buttonsizer = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer *buttonsizer = new wxBoxSizer(wxHORIZONTAL);
//y5
if (m_isSimpleMode) if (m_isSimpleMode)
staticBitmap = new wxStaticBitmap(Panel, wxID_ANY, ScalableBitmap(this, "user_dark", wxSize(40, 40)).get_bitmap()); staticBitmap = new wxStaticBitmap(Panel, wxID_ANY, *get_bmp_bundle_of_login(m_user_head_name, 40, 40));
else 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, 60, 60));
StateColor text_color(std::pair<wxColour, int>(wxColour(57, 57, 61), StateColor::Disabled), StateColor text_color(std::pair<wxColour, int>(wxColour(57, 57, 61), StateColor::Disabled),
std::pair<wxColour, int>(wxColour(68, 121, 251), StateColor::Pressed), std::pair<wxColour, int>(wxColour(68, 121, 251), StateColor::Pressed),
@@ -309,6 +313,7 @@ void PrinterWebView::CreatThread() {
break; break;
if (!m_net_buttons.empty()) { if (!m_net_buttons.empty()) {
BOOST_LOG_TRIVIAL(error) << "machine IP: " << device.local_ip; BOOST_LOG_TRIVIAL(error) << "machine IP: " << device.local_ip;
//y5
std::unique_ptr<PrintHost> printhost(PrintHost::get_print_host_url(device.url, device.local_ip)); std::unique_ptr<PrintHost> printhost(PrintHost::get_print_host_url(device.url, device.local_ip));
if (!printhost) { if (!printhost) {
BOOST_LOG_TRIVIAL(error) << ("Could not get a valid Printer Host reference"); 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); wxString wxname = from_u8(name);
login_button->SetLabel(wxname); login_button->SetLabel(wxname);
std::vector<Device> m_devices = m_qidinetwork.get_device_list(msg); std::vector<Device> m_devices = m_qidinetwork.get_device_list(msg);
//y5
m_user_head_name = wxGetApp().app_config->get("user_head_name");
SetPresetChanged(true); SetPresetChanged(true);
#endif #endif
m_isloginin = true; m_isloginin = true;
@@ -472,6 +479,17 @@ void PrinterWebView::SetLoginStatus(bool status) {
//y3 //y3
if (webisNetMode == isNetWeb) if (webisNetMode == isNetWeb)
webisNetMode = isDisconnect; 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); SetPresetChanged(true);
UpdateState(); UpdateState();
} }
@@ -595,7 +613,25 @@ void PrinterWebView::AddNetButton(const Device device)
machine_button->SetIsSimpleMode(m_isSimpleMode); machine_button->SetIsSimpleMode(m_isSimpleMode);
machine_button->Bind(wxEVT_BUTTON, [this, device](wxCommandEvent &event) { 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); load_net_url(formattedHost, device.local_ip);
}); });
@@ -698,7 +734,8 @@ void PrinterWebView::OnZoomButtonClick(wxCommandEvent &event)
m_isSimpleMode = !m_isSimpleMode; m_isSimpleMode = !m_isSimpleMode;
if (!m_isSimpleMode) { if (!m_isSimpleMode) {
text_static->Show(); 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); login_button->SetIsSimpleMode(m_isSimpleMode);
wxGetApp().app_config->set("machine_list_minification", "0"); wxGetApp().app_config->set("machine_list_minification", "0");
toggleBar->SetSize(327); toggleBar->SetSize(327);
@@ -713,7 +750,8 @@ void PrinterWebView::OnZoomButtonClick(wxCommandEvent &event)
} }
} else { } else {
text_static->Hide(); 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); login_button->SetIsSimpleMode(m_isSimpleMode);
wxGetApp().app_config->set("machine_list_minification", "1"); wxGetApp().app_config->set("machine_list_minification", "1");
@@ -972,6 +1010,11 @@ void PrinterWebView::UpdateLayout()
button->Refresh(); 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) void PrinterWebView::OnScrollup(wxScrollWinEvent &event)
{ {

View File

@@ -164,6 +164,9 @@ private:
std::string select_machine_name; std::string select_machine_name;
WebState webisNetMode = isDisconnect; WebState webisNetMode = isDisconnect;
std::set<std::string> m_exit_host; std::set<std::string> m_exit_host;
//y5
std::string m_user_head_name;
bool m_isfluidd_1;
}; };
//y3 //y3

View File

@@ -443,6 +443,39 @@ wxBitmapBundle* get_bmp_bundle(const std::string& bmp_name_in, int width/* = 16*
return bmp; 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) wxBitmapBundle* get_empty_bmp_bundle(int width, int height)
{ {
static Slic3r::GUI::BitmapCache cache; static Slic3r::GUI::BitmapCache cache;

View File

@@ -51,6 +51,11 @@ int em_unit(wxWindow* win);
int mode_icon_px_size(); 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()); 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_empty_bmp_bundle(int width, int height);
wxBitmapBundle* get_solid_bmp_bundle(int width, int height, const std::string& color); wxBitmapBundle* get_solid_bmp_bundle(int width, int height, const std::string& color);