ENH:limit file size and collapse long text

Jira: STUDIO-5007
Change-Id: I8b36812c825ff41ade076e6375ed29f357dec814
This commit is contained in:
zhou.xu 2023-10-31 10:34:33 +08:00 committed by Lane.Wei
parent 4a5bca2402
commit 1c416d5781
5 changed files with 88 additions and 9 deletions

View File

@ -432,6 +432,8 @@ set(SLIC3R_GUI_SOURCES
Utils/FixModelByWin10.hpp
Utils/Bonjour.cpp
Utils/Bonjour.hpp
Utils/FileHelp.cpp
Utils/FileHelp.hpp
Utils/PresetUpdater.cpp
Utils/PresetUpdater.hpp
Utils/Process.cpp

View File

@ -13,8 +13,8 @@
#include "libslic3r/Polygon.hpp"
#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem.hpp>
#include "FileHelp.hpp"
#include <wx/dcgraph.h>
#include <algorithm>
namespace Slic3r {
@ -311,7 +311,9 @@ wxPanel *BedShapePanel::init_texture_panel()
}));
filename_lbl->Bind(wxEVT_UPDATE_UI, ([this](wxUpdateUIEvent &e) {
e.SetText(_(boost::filesystem::path(m_custom_texture).filename().string()));
wxGCDC dc;
auto text = wxControl::Ellipsize(_L(boost::filesystem::path(m_custom_texture).filename().string()), dc, wxELLIPSIZE_END, FromDIP(150));
e.SetText(text);
wxStaticText *lbl = dynamic_cast<wxStaticText *>(e.GetEventObject());
if (lbl != nullptr) {
bool exists = (m_custom_texture == NONE) || boost::filesystem::exists(m_custom_texture);
@ -379,7 +381,9 @@ wxPanel *BedShapePanel::init_model_panel()
}));
filename_lbl->Bind(wxEVT_UPDATE_UI, ([this](wxUpdateUIEvent &e) {
e.SetText(_(boost::filesystem::path(m_custom_model).filename().string()));
wxGCDC dc;
auto text = wxControl::Ellipsize(_L(boost::filesystem::path(m_custom_model).filename().string()), dc, wxELLIPSIZE_END, FromDIP(150));
e.SetText(text);
wxStaticText *lbl = dynamic_cast<wxStaticText *>(e.GetEventObject());
if (lbl != nullptr) {
bool exists = (m_custom_model == NONE) || boost::filesystem::exists(m_custom_model);
@ -576,7 +580,15 @@ void BedShapePanel::load_texture()
show_error(this, _L("Invalid file format."));
return;
}
bool try_ok;
if (Utils::is_file_too_large(file_name, try_ok)) {
if (try_ok) {
wxMessageBox(wxString::Format(_L("The file exceeds %d MB, please import again."), STL_SVG_MAX_FILE_SIZE_MB), "Error", wxOK | wxICON_ERROR);
} else {
wxMessageBox(_L("Exception in obtaining file size, please import again."));
}
return;
}
wxBusyCursor wait;
m_custom_texture = file_name;
@ -598,7 +610,15 @@ void BedShapePanel::load_model()
show_error(this, _L("Invalid file format."));
return;
}
bool try_ok;
if (Utils::is_file_too_large(file_name, try_ok)) {
if (try_ok) {
wxMessageBox(wxString::Format(_L("The file exceeds %d MB, please import again."), STL_SVG_MAX_FILE_SIZE_MB), "Error", wxOK | wxICON_ERROR);
} else {
wxMessageBox(_L("Exception in obtaining file size, please import again."));
}
return;
}
wxBusyCursor wait;
m_custom_model = file_name;

View File

@ -9,7 +9,8 @@
#include "MsgDialog.hpp"
#include <openssl/md5.h>
#include <openssl/evp.h>
#include "FileHelp.hpp"
#include <wx/dcgraph.h>
#define NAME_OPTION_COMBOBOX_SIZE wxSize(FromDIP(200), FromDIP(24))
#define FILAMENT_PRESET_COMBOBOX_SIZE wxSize(FromDIP(300), FromDIP(24))
#define OPTION_SIZE wxSize(FromDIP(100), FromDIP(24))
@ -1805,8 +1806,19 @@ void CreatePrinterPresetDialog::load_texture() {
show_error(this, _L("Invalid file format."));
return;
}
bool try_ok;
if (Utils::is_file_too_large(file_name, try_ok)) {
if (try_ok) {
m_upload_svg_tip_text->SetLabelText(wxString::Format(_L("The file exceeds %d MB, please import again."), STL_SVG_MAX_FILE_SIZE_MB));
} else {
m_upload_svg_tip_text->SetLabelText(_L("Exception in obtaining file size, please import again."));
}
return;
}
m_custom_texture = file_name;
m_upload_svg_tip_text->SetLabelText(_L(boost::filesystem::path(file_name).filename().string()));
wxGCDC dc;
auto text = wxControl::Ellipsize(_L(boost::filesystem::path(file_name).filename().string()), dc, wxELLIPSIZE_END, FromDIP(200));
m_upload_svg_tip_text->SetLabelText(text);
}
void CreatePrinterPresetDialog::load_model_stl()
@ -1824,8 +1836,20 @@ void CreatePrinterPresetDialog::load_model_stl()
show_error(this, _L("Invalid file format."));
return;
}
bool try_ok;
if (Utils::is_file_too_large(file_name, try_ok)) {
if (try_ok) {
m_upload_stl_tip_text->SetLabelText(wxString::Format(_L("The file exceeds %d MB, please import again."), STL_SVG_MAX_FILE_SIZE_MB));
}
else {
m_upload_stl_tip_text->SetLabelText(_L("Exception in obtaining file size, please import again."));
}
return;
}
m_custom_model = file_name;
m_upload_stl_tip_text->SetLabelText(_L(boost::filesystem::path(file_name).filename().string()));
wxGCDC dc;
auto text = wxControl::Ellipsize(_L(boost::filesystem::path(file_name).filename().string()), dc, wxELLIPSIZE_END, FromDIP(200));
m_upload_stl_tip_text->SetLabelText(text);
}
bool CreatePrinterPresetDialog::load_system_and_user_presets_with_curr_model(PresetBundle &temp_preset_bundle, bool just_template)

View File

@ -0,0 +1,20 @@
#include "FileHelp.hpp"
#include <boost/filesystem.hpp>
namespace Slic3r {
namespace Utils {
bool is_file_too_large(std::string file_path, bool &try_ok)
{
try {
uintmax_t fileSizeBytes = boost::filesystem::file_size(file_path);
double fileSizeMB = static_cast<double>(fileSizeBytes) / 1024 / 1024;
try_ok = true;
if (fileSizeMB > STL_SVG_MAX_FILE_SIZE_MB) { return true; }
} catch (boost::filesystem::filesystem_error &e) {
try_ok = false;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " error message: " << e.what();
}
return false;
}
}} // namespace Slic3r::Utils

View File

@ -0,0 +1,13 @@
#ifndef file_help_hpp_
#define file_help_hpp_
#include <string>
#define STL_SVG_MAX_FILE_SIZE_MB 3
namespace Slic3r {
namespace Utils {
bool is_file_too_large(std::string file_path, bool &try_ok);
}
}
#endif // file_help_hpp_