diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index 0d4716dc7..ddb16ab95 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -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 diff --git a/src/slic3r/GUI/BedShapeDialog.cpp b/src/slic3r/GUI/BedShapeDialog.cpp index be083cd9b..abd0cf8db 100644 --- a/src/slic3r/GUI/BedShapeDialog.cpp +++ b/src/slic3r/GUI/BedShapeDialog.cpp @@ -13,8 +13,8 @@ #include "libslic3r/Polygon.hpp" #include -#include - +#include "FileHelp.hpp" +#include #include 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(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(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; diff --git a/src/slic3r/GUI/CreatePresetsDialog.cpp b/src/slic3r/GUI/CreatePresetsDialog.cpp index d1d87c331..1c6120d2d 100644 --- a/src/slic3r/GUI/CreatePresetsDialog.cpp +++ b/src/slic3r/GUI/CreatePresetsDialog.cpp @@ -9,7 +9,8 @@ #include "MsgDialog.hpp" #include #include - +#include "FileHelp.hpp" +#include #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) diff --git a/src/slic3r/Utils/FileHelp.cpp b/src/slic3r/Utils/FileHelp.cpp new file mode 100644 index 000000000..5e8d4b010 --- /dev/null +++ b/src/slic3r/Utils/FileHelp.cpp @@ -0,0 +1,20 @@ +#include "FileHelp.hpp" +#include +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(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 \ No newline at end of file diff --git a/src/slic3r/Utils/FileHelp.hpp b/src/slic3r/Utils/FileHelp.hpp new file mode 100644 index 000000000..4fa327852 --- /dev/null +++ b/src/slic3r/Utils/FileHelp.hpp @@ -0,0 +1,13 @@ +#ifndef file_help_hpp_ +#define file_help_hpp_ +#include + +#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_