NEW: [STUDIO-1868] show model files in printer's sdcard

Change-Id: I48a3e9d4b0422ddae17fc1eeeb671d1051cd7c6f
This commit is contained in:
chunmao.guo 2023-04-27 09:09:45 +08:00 committed by Lane.Wei
parent 904b122878
commit 14836c5f4a
7 changed files with 338 additions and 143 deletions

View file

@ -0,0 +1,4 @@
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M10.5357 11.5462C9.59362 12.2735 8.41309 12.7065 7.13107 12.7065C4.05204 12.7065 1.55566 10.2101 1.55566 7.13107C1.55566 4.05204 4.05204 1.55566 7.13107 1.55566C10.2101 1.55566 12.7065 4.05204 12.7065 7.13107C12.7065 8.01817 12.4993 8.85621 12.1306 9.60123" stroke="#C4C4C4" stroke-miterlimit="10" stroke-linecap="round"/>
<path d="M6.69629 3.75439V7.25203C6.69629 7.40847 6.82314 7.53532 6.97958 7.53532H10.0891" stroke="#C4C4C4" stroke-miterlimit="10" stroke-linecap="round"/>
</svg>

After

Width:  |  Height:  |  Size: 591 B

View file

@ -0,0 +1,6 @@
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M7.54156 4.72495C7.32505 5.50922 7.18694 6.61633 7.18694 7.8555C7.18694 9.09467 7.32505 10.2018 7.54156 10.986C7.65064 11.3811 7.77318 11.6704 7.89182 11.8511C7.9619 11.9579 8.01129 11.9995 8.03554 12.0152C8.03969 12.0125 8.0445 12.009 8.04996 12.0048C8.08868 11.9746 8.14128 11.9181 8.19342 11.829C8.30988 11.63 8.56558 11.5631 8.76456 11.6796C8.96353 11.796 9.03043 12.0518 8.91398 12.2507C8.81947 12.4122 8.70098 12.5561 8.56251 12.6638C8.42695 12.7692 8.24739 12.8582 8.04044 12.8582C7.64645 12.8582 7.36927 12.5765 7.19384 12.3092C7.00772 12.0257 6.85684 11.6431 6.73678 11.2082C6.49502 10.3325 6.35205 9.147 6.35205 7.8555C6.35205 6.564 6.49502 5.37847 6.73678 4.50277C6.85684 4.06788 7.00772 3.68531 7.19384 3.40175C7.36927 3.13445 7.64645 2.85278 8.04044 2.85278C8.424 2.85278 8.70476 3.12518 8.87921 3.39344C9.0049 3.58671 8.95011 3.84528 8.75684 3.97097C8.56356 4.09666 8.30499 4.04187 8.1793 3.84859C8.12564 3.76608 8.07955 3.72108 8.04978 3.6996C8.04606 3.69692 8.0428 3.69474 8.04 3.69298C8.0177 3.70628 7.9665 3.74607 7.89182 3.85986C7.77318 4.04061 7.65064 4.32987 7.54156 4.72495Z" fill="#C4C4C4"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M5.12945 4.60703C4.91294 5.3913 4.77483 6.49841 4.77483 7.73758C4.77483 8.97675 4.91294 10.0839 5.12945 10.8681C5.23853 11.2632 5.36108 11.5525 5.47971 11.7332C5.54979 11.84 5.59918 11.8816 5.62343 11.8973C5.62758 11.8945 5.63239 11.8911 5.63785 11.8868C5.67657 11.8567 5.72917 11.8002 5.78131 11.7111C5.89777 11.5121 6.15348 11.4452 6.35245 11.5617C6.55143 11.6781 6.61832 11.9338 6.50187 12.1328C6.40736 12.2943 6.28887 12.4382 6.1504 12.5459C6.01484 12.6513 5.83528 12.7403 5.62833 12.7403C5.23435 12.7403 4.95716 12.4586 4.78173 12.1913C4.59561 11.9078 4.44473 11.5252 4.32467 11.0903C4.08291 10.2146 3.93994 9.02908 3.93994 7.73758C3.93994 6.44608 4.08291 5.26055 4.32467 4.38485C4.44473 3.94996 4.59561 3.56739 4.78173 3.28383C4.95716 3.01653 5.23435 2.73486 5.62833 2.73486C6.01189 2.73486 6.29265 3.00726 6.46711 3.27552C6.59279 3.46879 6.538 3.72736 6.34473 3.85305C6.15145 3.97874 5.89288 3.92395 5.76719 3.73067C5.71353 3.64816 5.66744 3.60316 5.63767 3.58168C5.63395 3.579 5.63069 3.57682 5.62789 3.57506C5.60559 3.58836 5.5544 3.62815 5.47971 3.74194C5.36108 3.92269 5.23853 4.21195 5.12945 4.60703Z" fill="#C4C4C4"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M10.1283 4.12035C9.87089 5.05906 9.70647 6.37948 9.70647 7.85462C9.70647 9.32977 9.87089 10.6502 10.1283 11.5889C10.2578 12.0612 10.4045 12.4133 10.5499 12.6374C10.6221 12.7489 10.6841 12.8132 10.7291 12.8468C10.7506 12.8628 10.7651 12.8695 10.7725 12.8723C10.7761 12.8736 10.7783 12.8741 10.7791 12.8742L10.7799 12.8744L10.7799 12.8744L10.7799 12.8744L10.7799 12.8744L10.78 12.8744L10.7808 12.8742C10.7816 12.8741 10.7838 12.8736 10.7874 12.8723C10.7947 12.8695 10.8093 12.8628 10.8307 12.8468C10.8757 12.8132 10.9378 12.7489 11.01 12.6374C11.1553 12.4133 11.3021 12.0612 11.4316 11.5889C11.689 10.6502 11.8534 9.32977 11.8534 7.85462C11.8534 6.37948 11.689 5.05906 11.4316 4.12035C11.3021 3.64802 11.1553 3.29599 11.01 3.07181C10.9378 2.96039 10.8757 2.89605 10.8307 2.86247C10.8093 2.84648 10.7947 2.8397 10.7874 2.83698C10.7838 2.83563 10.7816 2.83517 10.7808 2.83501L10.78 2.8349L10.7799 2.83489L10.7799 2.83489L10.7799 2.83489L10.7799 2.8349L10.7791 2.83501C10.7783 2.83517 10.7761 2.83563 10.7725 2.83698C10.7651 2.8397 10.7506 2.84648 10.7291 2.86247C10.6841 2.89605 10.6221 2.96039 10.5499 3.07181C10.4045 3.29599 10.2578 3.64802 10.1283 4.12035ZM9.84933 2.61764C10.0489 2.30973 10.3541 2 10.7799 2C11.2058 2 11.5109 2.30973 11.7105 2.61764C11.9219 2.94374 12.0965 3.38796 12.2368 3.89957C12.519 4.92873 12.6883 6.3269 12.6883 7.85462C12.6883 9.38235 12.519 10.7805 12.2368 11.8097C12.0965 12.3213 11.9219 12.7655 11.7105 13.0916C11.5109 13.3995 11.2058 13.7092 10.7799 13.7092C10.3541 13.7092 10.0489 13.3995 9.84933 13.0916C9.63793 12.7655 9.46341 12.3213 9.32312 11.8097C9.04092 10.7805 8.87158 9.38235 8.87158 7.85462C8.87158 6.3269 9.04092 4.92873 9.32312 3.89957C9.46341 3.38796 9.63793 2.94374 9.84933 2.61764Z" fill="#C4C4C4"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M2.26534 4.10905C2.00338 5.04001 1.83489 6.3532 1.83489 7.82957C1.83489 9.3071 1.9975 10.6275 2.25395 11.5656C2.38298 12.0376 2.52942 12.3889 2.67478 12.6124C2.74698 12.7235 2.80907 12.7876 2.8543 12.8211C2.87585 12.8371 2.8907 12.844 2.89855 12.8468C2.90244 12.8483 2.90492 12.8488 2.90614 12.8491C2.90733 12.8493 2.90797 12.8493 2.90835 12.8493H2.90847C2.91216 12.8493 2.96513 12.8497 3.06709 12.7299C3.17083 12.6081 3.28495 12.4059 3.39934 12.1128C3.48315 11.898 3.72519 11.7918 3.93997 11.8756C4.15475 11.9594 4.26093 12.2015 4.17713 12.4162C4.04711 12.7495 3.89238 13.0485 3.70282 13.2711C3.51271 13.4944 3.248 13.6842 2.90835 13.6842C2.48203 13.6842 2.17586 13.3767 1.97487 13.0676C1.76277 12.7414 1.58842 12.2972 1.44861 11.7858C1.16735 10.7569 1 9.35876 1 7.82957C1 6.2992 1.17368 4.90633 1.46166 3.88291C1.60483 3.37409 1.78273 2.93292 1.99773 2.60928C2.20189 2.30195 2.5096 2 2.9328 2C3.28967 2 3.56218 2.22163 3.74971 2.46002C3.94226 2.70478 4.10133 3.03449 4.23133 3.40764C4.30717 3.62535 4.19217 3.86333 3.97445 3.93918C3.75673 4.01503 3.51875 3.90002 3.44291 3.6823C3.32849 3.35389 3.20649 3.11983 3.09352 2.97622C2.99547 2.85157 2.93923 2.83649 2.93147 2.83496C2.92979 2.83512 2.9265 2.83569 2.92101 2.83768C2.91248 2.84077 2.89707 2.84791 2.87507 2.86396C2.829 2.89755 2.76618 2.96134 2.69316 3.07126C2.54612 3.29259 2.39713 3.64068 2.26534 4.10905Z" fill="#C4C4C4"/>
</svg>

After

Width:  |  Height:  |  Size: 5.5 KiB

View file

@ -5,16 +5,10 @@
#include "I18N.hpp" #include "I18N.hpp"
#include "GUI_App.hpp" #include "GUI_App.hpp"
#include "GUI.hpp" #include "GUI.hpp"
#include "MsgDialog.hpp"
#include <wx/dcgraph.h> #include <wx/dcgraph.h>
#ifdef __WXMSW__ wxDEFINE_EVENT(EVT_ITEM_ACTION, wxCommandEvent);
#include <shellapi.h>
#endif
#ifdef __APPLE__
#include "../Utils/MacDarkMode.hpp"
#endif
BEGIN_EVENT_TABLE(Slic3r::GUI::ImageGrid, wxPanel) BEGIN_EVENT_TABLE(Slic3r::GUI::ImageGrid, wxPanel)
@ -34,14 +28,21 @@ END_EVENT_TABLE()
namespace Slic3r { namespace Slic3r {
namespace GUI { namespace GUI {
static constexpr int SHADOW_WIDTH = 3;
ImageGrid::ImageGrid(wxWindow * parent) ImageGrid::ImageGrid(wxWindow * parent)
: wxWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize) : wxWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)
, m_buttonBackgroundColor(StateColor(
std::make_pair(*wxWHITE, (int) StateColor::Pressed),
std::make_pair(*wxRED, (int) StateColor::Normal)))
, m_buttonTextColor(StateColor( , m_buttonTextColor(StateColor(
std::make_pair(0x3B4446, (int) StateColor::Pressed), std::make_pair(0x3B4446, (int) StateColor::Pressed),
std::make_pair(*wxLIGHT_GREY, (int) StateColor::Hovered), std::make_pair(*wxLIGHT_GREY, (int) StateColor::Hovered),
std::make_pair(*wxWHITE, (int) StateColor::Normal))) std::make_pair(*wxWHITE, (int) StateColor::Normal)))
, m_checked_icon(this, "check_on", 16) , m_checked_icon(this, "check_on", 16)
, m_unchecked_icon(this, "check_off", 16) , m_unchecked_icon(this, "check_off", 16)
, m_model_time_icon(this, "model_time", 14)
, m_model_weight_icon(this, "model_weight", 14)
{ {
SetBackgroundStyle(wxBG_STYLE_PAINT); SetBackgroundStyle(wxBG_STYLE_PAINT);
SetBackgroundColour(0xEEEEEE); SetBackgroundColour(0xEEEEEE);
@ -82,11 +83,11 @@ void ImageGrid::SetStatus(ScalableBitmap const & icon, wxString const &msg)
Refresh(); Refresh();
} }
void Slic3r::GUI::ImageGrid::SetFileType(int type) void Slic3r::GUI::ImageGrid::SetFileType(int type, std::string const &storage)
{ {
if (!m_file_sys) if (!m_file_sys)
return; return;
m_file_sys->SetFileType((PrinterFileSystem::FileType) type); m_file_sys->SetFileType((PrinterFileSystem::FileType) type, storage);
} }
void Slic3r::GUI::ImageGrid::SetGroupMode(int mode) void Slic3r::GUI::ImageGrid::SetGroupMode(int mode)
@ -96,7 +97,7 @@ void Slic3r::GUI::ImageGrid::SetGroupMode(int mode)
wxSize size = GetClientSize(); wxSize size = GetClientSize();
int index = (m_row_offset + 1 < m_row_count || m_row_count == 0) int index = (m_row_offset + 1 < m_row_count || m_row_count == 0)
? m_row_offset / 4 * m_col_count ? m_row_offset / 4 * m_col_count
: ((m_file_sys->GetCount() + m_col_count - 1) / m_col_count - (size.y + m_image_size.GetHeight() - 1) / m_cell_size.GetHeight()) * m_col_count; : ((m_file_sys->GetCount() + m_col_count - 1) / m_col_count - (size.y + m_border_size.GetHeight() - 1) / m_cell_size.GetHeight()) * m_col_count;
auto & file = m_file_sys->GetFile(index); auto & file = m_file_sys->GetFile(index);
m_file_sys->SetGroupMode((PrinterFileSystem::GroupMode) mode); m_file_sys->SetGroupMode((PrinterFileSystem::GroupMode) mode);
index = m_file_sys->GetIndexAtTime(file.time); index = m_file_sys->GetIndexAtTime(file.time);
@ -149,81 +150,33 @@ void Slic3r::GUI::ImageGrid::Select(size_t index)
void Slic3r::GUI::ImageGrid::DoAction(size_t index, int action) void Slic3r::GUI::ImageGrid::DoAction(size_t index, int action)
{ {
if (action == 0) { wxCommandEvent event(EVT_ITEM_ACTION);
if (m_file_sys->GetSelectCount() > 1) { event.SetEventObject(this);
MessageDialog dlg(this, event.SetInt(action);
wxString::Format(_L("You are going to delete %u files. Are you sure to continue?"), m_file_sys->GetSelectCount()), event.SetExtraLong(long(index));
_L("Delete files"), wxYES_NO | wxICON_WARNING); ProcessEventLocally(event);
if (dlg.ShowModal() != wxID_YES)
return;
}
m_file_sys->DeleteFiles(index);
} else if (action == 1) {
if (index != -1) {
auto &file = m_file_sys->GetFile(index);
if (file.IsDownload() && file.progress >= -1) {
if (file.progress >= 100) {
if (!m_file_sys->DownloadCheckFile(index)) {
MessageDialog(this,
wxString::Format(_L("File '%s' was lost! Please download it again."), from_u8(file.name)),
_L("Error"), wxOK).ShowModal();
Refresh();
return;
}
#ifdef __WXMSW__
auto wfile = boost::filesystem::path(file.local_path).wstring();
SHELLEXECUTEINFO info{sizeof(info), 0, NULL, NULL, wfile.c_str(), L"", SW_HIDE};
::ShellExecuteEx(&info);
#else
wxShell("open " + file.local_path);
#endif
} else {
m_file_sys->DownloadCancel(index);
}
return;
}
}
m_file_sys->DownloadFiles(index, wxGetApp().app_config->get("download_path"));
} else if (action == 2) {
if (index != -1) {
auto &file = m_file_sys->GetFile(index);
if (file.IsDownload() && file.progress >= -1) {
if (file.progress >= 100) {
if (!m_file_sys->DownloadCheckFile(index)) {
MessageDialog(this,
wxString::Format(_L("File '%s' was lost! Please download it again."), from_u8(file.name)),
_L("Error"), wxOK).ShowModal();
Refresh();
return;
}
#ifdef __WIN32__
wxExecute(L"explorer.exe /select," + from_u8(file.local_path));
#elif __APPLE__
openFolderForFile(from_u8(file.local_path));
#else
#endif
}
return;
}
}
m_file_sys->DownloadFiles(index, wxGetApp().app_config->get("download_path"));
}
} }
void Slic3r::GUI::ImageGrid::UpdateFileSystem() void Slic3r::GUI::ImageGrid::UpdateFileSystem()
{ {
if (!m_file_sys) return; if (!m_file_sys) return;
wxSize mask_size{0, 60}; if (m_file_sys->GetFileType() < PrinterFileSystem::F_MODEL) {
if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE) { if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE) {
m_image_size.Set(384, 216);
m_cell_size.Set(396, 228); m_cell_size.Set(396, 228);
m_border_size.Set(384, 216);
} }
else { else {
m_image_size.Set(480, 270); m_cell_size.Set(496, 286);
m_cell_size.Set(496, 296); m_border_size.Set(480, 270);
}
} else {
m_cell_size.Set(292, 288);
m_border_size.Set(266, 264);
} }
m_image_size = m_image_size * em_unit(this) / 10;
m_cell_size = m_cell_size * em_unit(this) / 10; m_cell_size = m_cell_size * em_unit(this) / 10;
m_border_size = m_border_size * em_unit(this) / 10;
m_content_rect = wxRect(SHADOW_WIDTH, SHADOW_WIDTH, m_border_size.GetWidth(), m_border_size.GetHeight());
m_border_size += wxSize(SHADOW_WIDTH, SHADOW_WIDTH) * 2;
UpdateLayout(); UpdateLayout();
} }
@ -231,16 +184,16 @@ void ImageGrid::UpdateLayout()
{ {
if (!m_file_sys) return; if (!m_file_sys) return;
wxSize size = GetClientSize(); wxSize size = GetClientSize();
wxSize mask_size{0, 60 * em_unit(this) / 10}; wxSize title_mask_size{0, 60 * em_unit(this) / 10};
if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE) { if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE) {
mask_size.y = 20 * em_unit(this) / 10; title_mask_size.y = 20 * em_unit(this) / 10;
size.y -= mask_size.y; size.y -= title_mask_size.y;
} }
int cell_width = m_cell_size.GetWidth(); int cell_width = m_cell_size.GetWidth();
int cell_height = m_cell_size.GetHeight(); int cell_height = m_cell_size.GetHeight();
int ncol = (size.GetWidth() - cell_width + m_image_size.GetWidth()) / cell_width; int ncol = (size.GetWidth() - cell_width + m_border_size.GetWidth()) / cell_width;
if (ncol <= 0) ncol = 1; if (ncol <= 0) ncol = 1;
int total_height = (m_file_sys->GetCount() + ncol - 1) / ncol * cell_height + cell_height - m_image_size.GetHeight(); int total_height = (m_file_sys->GetCount() + ncol - 1) / ncol * cell_height + cell_height - m_border_size.GetHeight();
int nrow = (total_height - size.GetHeight() + cell_height / 4 - 1) / (cell_height / 4); int nrow = (total_height - size.GetHeight() + cell_height / 4 - 1) / (cell_height / 4);
m_row_offset = m_row_offset * m_col_count / ncol; m_row_offset = m_row_offset * m_col_count / ncol;
m_col_count = ncol; m_col_count = ncol;
@ -250,13 +203,15 @@ void ImageGrid::UpdateLayout()
m_scroll_offset = 0; m_scroll_offset = 0;
// create mask // create mask
if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE) { if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE) {
mask_size.x = (m_col_count - 1) * m_cell_size.GetWidth() + m_image_size.GetWidth(); title_mask_size.x = (m_col_count - 1) * m_cell_size.GetWidth() + m_border_size.GetWidth();
} }
else { else {
mask_size.x = m_image_size.x; title_mask_size.x = m_border_size.x;
} }
if (!m_mask.IsOk() || m_mask.GetSize() != mask_size) if (!m_title_mask.IsOk() || m_title_mask.GetSize() != title_mask_size)
m_mask = createAlphaBitmap(mask_size, 0x6f6f6f, 255, 0); m_title_mask = createAlphaBitmap(title_mask_size, 0x6f6f6f, 255, 0);
if (!m_border_mask.IsOk() || m_border_mask.GetSize() != m_border_size)
m_border_mask = createShadowBorder(m_border_size, GetBackgroundColour(), em_unit(this), 3);
UpdateFocusRange(); UpdateFocusRange();
Refresh(); Refresh();
} }
@ -280,7 +235,7 @@ std::pair<int, size_t> Slic3r::GUI::ImageGrid::HitTest(wxPoint const &pt)
return {HIT_NONE, -1}; return {HIT_NONE, -1};
wxSize size = GetClientSize(); wxSize size = GetClientSize();
if (m_file_sys->GetCount() == 0) { if (m_file_sys->GetCount() == 0) {
if (wxRect({0, 0}, m_image_size).CenterIn(wxRect({0, 0}, size)).Contains(pt)) if (wxRect({0, 0}, m_border_size).CenterIn(wxRect({0, 0}, size)).Contains(pt))
return {HIT_STATUS, 0}; return {HIT_STATUS, 0};
return {HIT_NONE, -1}; return {HIT_NONE, -1};
} }
@ -292,17 +247,21 @@ std::pair<int, size_t> Slic3r::GUI::ImageGrid::HitTest(wxPoint const &pt)
++n; ++n;
off.x -= m_cell_size.GetWidth(); off.x -= m_cell_size.GetWidth();
} }
if (off.x < 0 || off.x >= m_image_size.GetWidth()) { return {HIT_NONE, -1}; }
index += n; index += n;
while (off.y > m_cell_size.GetHeight()) { while (off.y > m_cell_size.GetHeight()) {
index += m_col_count; index += m_col_count;
off.y -= m_cell_size.GetHeight(); off.y -= m_cell_size.GetHeight();
} }
if (index >= m_file_sys->GetCount()) { return {HIT_NONE, -1}; } if (index >= m_file_sys->GetCount()) { return {HIT_NONE, -1}; }
if (!m_content_rect.Contains(off)) { return {HIT_NONE, -1}; }
if (!m_selecting) { if (!m_selecting) {
wxRect hover_rect{0, m_image_size.y - 40, m_image_size.GetWidth(), 40}; wxRect hover_rect{0, m_content_rect.GetHeight() - 40, m_content_rect.GetWidth(), 40};
auto & file = m_file_sys->GetFile(index); auto & file = m_file_sys->GetFile(index);
int btn = file.IsDownload() && file.progress >= 0 ? 3 : 2; int btn = file.IsDownload() && file.progress >= 0 ? 3 : 2;
if (m_file_sys->GetFileType() == PrinterFileSystem::F_MODEL) {
btn = 3;
hover_rect.y -= 64;
}
if (hover_rect.Contains(off.x, off.y)) { return {HIT_ACTION, index * 4 + off.x * btn / hover_rect.GetWidth()}; } // Two buttons if (hover_rect.Contains(off.x, off.y)) { return {HIT_ACTION, index * 4 + off.x * btn / hover_rect.GetWidth()}; } // Two buttons
} }
return {HIT_ITEM, index}; return {HIT_ITEM, index};
@ -425,16 +384,16 @@ size_t Slic3r::GUI::ImageGrid::firstItem(wxSize const &size, wxPoint &off)
{ {
int size_y = size.y; int size_y = size.y;
if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE) if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE)
size_y -= m_mask.GetHeight(); size_y -= m_title_mask.GetHeight();
int offx = (size.x - (m_col_count - 1) * m_cell_size.GetWidth() - m_image_size.GetWidth()) / 2; int offx = (size.x - (m_col_count - 1) * m_cell_size.GetWidth() - m_border_size.GetWidth()) / 2;
int offy = (m_row_offset + 1 < m_row_count || m_row_count == 0) ? int offy = (m_row_offset + 1 < m_row_count || m_row_count == 0) ?
m_cell_size.GetHeight() - m_image_size.GetHeight() - m_row_offset * m_cell_size.GetHeight() / 4 + m_row_offset / 4 * m_cell_size.GetHeight() : m_cell_size.GetHeight() - m_border_size.GetHeight() - m_row_offset * m_cell_size.GetHeight() / 4 + m_row_offset / 4 * m_cell_size.GetHeight() :
size_y - (size_y + m_image_size.GetHeight() - 1) / m_cell_size.GetHeight() * m_cell_size.GetHeight(); size_y - (size_y + m_border_size.GetHeight() - 1) / m_cell_size.GetHeight() * m_cell_size.GetHeight();
int index = (m_row_offset + 1 < m_row_count || m_row_count == 0) ? int index = (m_row_offset + 1 < m_row_count || m_row_count == 0) ?
m_row_offset / 4 * m_col_count : m_row_offset / 4 * m_col_count :
((m_file_sys->GetCount() + m_col_count - 1) / m_col_count - (size_y + m_image_size.GetHeight() - 1) / m_cell_size.GetHeight()) * m_col_count; ((m_file_sys->GetCount() + m_col_count - 1) / m_col_count - (size_y + m_border_size.GetHeight() - 1) / m_cell_size.GetHeight()) * m_col_count;
if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE) if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE)
offy += m_mask.GetHeight(); offy += m_title_mask.GetHeight();
off = wxPoint{offx, offy}; off = wxPoint{offx, offy};
return index; return index;
} }
@ -454,6 +413,38 @@ wxBitmap Slic3r::GUI::ImageGrid::createAlphaBitmap(wxSize size, wxColour color,
return wxBitmap(std::move(image)); return wxBitmap(std::move(image));
} }
wxBitmap Slic3r::GUI::ImageGrid::createShadowBorder(wxSize size, wxColour color, int radius, int shadow)
{
wxImage image(size);
image.InitAlpha();
memset(image.GetAlpha(), 0, size.GetWidth() * size.GetHeight());
wxBitmap bmp(std::move(image));
wxMemoryDC memdc;
memdc.SelectObject(bmp);
#ifdef __WXMSW__
wxGCDC dc2(memdc);
#else
wxDC &dc2(memdc);
#endif
wxRect rc(0, 0, size.x, size.y);
dc2.SetBrush(*wxTRANSPARENT_BRUSH);
auto n = ((radius + shadow) * 1414 / 1000 - radius);
dc2.SetPen(wxPen(color, n | 1));
n = n / 2 - shadow + 1;
rc.Inflate(n, n);
dc2.DrawRoundedRectangle(rc, radius + shadow);
rc.Deflate(n, n);
rc.Deflate(shadow, shadow);
for (int i = 0; i < shadow; ++i) {
rc.Inflate(1, 1);
dc2.SetPen(wxColor(0, 0, 0, 100 - i * 30));
dc2.DrawRoundedRectangle(rc, radius + i);
}
memdc.SelectObject(wxNullBitmap);
return bmp;
}
wxBitmap Slic3r::GUI::ImageGrid::createCircleBitmap(wxSize size, int borderWidth, int percent, wxColour fillColor, wxColour borderColor) wxBitmap Slic3r::GUI::ImageGrid::createCircleBitmap(wxSize size, int borderWidth, int percent, wxColour fillColor, wxColour borderColor)
{ {
wxImage image(size); wxImage image(size);
@ -525,23 +516,33 @@ void ImageGrid::render(wxDC& dc)
wxPoint pt{off.x, off.y}; wxPoint pt{off.x, off.y};
end = (index + m_col_count) < m_file_sys->GetCount() ? index + m_col_count : m_file_sys->GetCount(); end = (index + m_col_count) < m_file_sys->GetCount() ? index + m_col_count : m_file_sys->GetCount();
while (index < end) { while (index < end) {
renderContent(dc, pt, index, hit_image == index); pt += m_content_rect.GetTopLeft();
// Draw content
decltype(&ImageGrid::renderContent1) contentRender[] = {
&ImageGrid::renderContent1,
&ImageGrid::renderContent1,
&ImageGrid::renderContent2
};
(this->*contentRender[m_file_sys->GetFileType()])(dc, pt, index, hit_image == index);
pt -= m_content_rect.GetTopLeft();
// Draw colume spacing at right // Draw colume spacing at right
dc.DrawRectangle({pt.x + m_image_size.GetWidth(), pt.y, m_cell_size.GetWidth() - m_image_size.GetWidth(), m_image_size.GetHeight()}); dc.DrawRectangle({pt.x + m_border_size.GetWidth(), pt.y, m_cell_size.GetWidth() - m_border_size.GetWidth(), m_border_size.GetHeight()});
// Draw overlay border mask
dc.DrawBitmap(m_border_mask, pt.x, pt.y);
++index; ++index;
pt.x += m_cell_size.GetWidth(); pt.x += m_cell_size.GetWidth();
} }
// Draw line fill items // Draw line fill items
if (end < index + m_col_count) if (end < index + m_col_count)
dc.DrawRectangle({pt.x, pt.y, size.x - pt.x - off.x, m_image_size.GetHeight()}); dc.DrawRectangle({pt.x, pt.y, size.x - pt.x - off.x, m_border_size.GetHeight()});
// Draw line spacing at bottom // Draw line spacing at bottom
dc.DrawRectangle({off.x, pt.y + m_image_size.GetHeight(), size.x - off.x * 2, m_cell_size.GetHeight() - m_image_size.GetHeight()}); dc.DrawRectangle({off.x, pt.y + m_border_size.GetHeight(), size.x - off.x * 2, m_cell_size.GetHeight() - m_border_size.GetHeight()});
off.y += m_cell_size.GetHeight(); off.y += m_cell_size.GetHeight();
} }
// Draw floating date range for non-group list // Draw floating date range for non-group list
if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE && m_file_sys->GetCount() > 0) { if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE && m_file_sys->GetCount() > 0) {
//dc.DrawBitmap(m_mask, {off.x, 0}); //dc.DrawBitmap(m_title_mask, {off.x, 0});
dc.DrawRectangle({off.x, 0}, m_mask.GetSize()); dc.DrawRectangle({off.x, 0}, m_title_mask.GetSize());
auto & file1 = m_file_sys->GetFile(start); auto & file1 = m_file_sys->GetFile(start);
auto & file2 = m_file_sys->GetFile(end - 1); auto & file2 = m_file_sys->GetFile(end - 1);
auto date1 = wxDateTime((time_t) file1.time).Format(_L(TIME_FORMATS[m_file_sys->GetGroupMode()])); auto date1 = wxDateTime((time_t) file1.time).Format(_L(TIME_FORMATS[m_file_sys->GetGroupMode()]));
@ -555,7 +556,7 @@ void ImageGrid::render(wxDC& dc)
dc.DrawRectangle({off.x, off.y, size.x - off.x * 2, size.y - off.y}); dc.DrawRectangle({off.x, off.y, size.x - off.x * 2, size.y - off.y});
// Draw position bar // Draw position bar
if (m_timer.IsRunning()) { if (m_timer.IsRunning()) {
int total_height = (m_file_sys->GetCount() + m_col_count - 1) / m_col_count * m_cell_size.GetHeight() + m_cell_size.GetHeight() - m_image_size.GetHeight(); int total_height = (m_file_sys->GetCount() + m_col_count - 1) / m_col_count * m_cell_size.GetHeight() + m_cell_size.GetHeight() - m_border_size.GetHeight();
if (total_height > size.y) { if (total_height > size.y) {
int offset = (m_row_offset + 1 < m_row_count || m_row_count == 0) ? m_row_offset * (m_cell_size.GetHeight() / 4) : total_height - size.y; int offset = (m_row_offset + 1 < m_row_count || m_row_count == 0) ? m_row_offset * (m_cell_size.GetHeight() / 4) : total_height - size.y;
wxRect rect = {size.x - 16, offset * size.y / total_height, 8, wxRect rect = {size.x - 16, offset * size.y / total_height, 8,
@ -566,25 +567,23 @@ void ImageGrid::render(wxDC& dc)
} }
} }
void Slic3r::GUI::ImageGrid::renderContent(wxDC &dc, wxPoint const &pt, int index, bool hit) void Slic3r::GUI::ImageGrid::renderContent1(wxDC &dc, wxPoint const &pt, int index, bool hit)
{ {
bool selected = false; bool selected = false;
auto &file = m_file_sys->GetFile(index, selected); auto &file = m_file_sys->GetFile(index, selected);
// Draw thumbnail // Draw thumbnail
if (file.thumbnail.IsOk()) { if (file.thumbnail.IsOk()) {
float hs = (float) m_image_size.GetWidth() / file.thumbnail.GetWidth(); float hs = (float) m_content_rect.GetWidth() / file.thumbnail.GetWidth();
float vs = (float) m_image_size.GetHeight() / file.thumbnail.GetHeight(); float vs = (float) m_content_rect.GetHeight() / file.thumbnail.GetHeight();
dc.SetUserScale(hs, vs); dc.SetUserScale(hs, vs);
dc.DrawBitmap(file.thumbnail, {(int) (pt.x / hs), (int) (pt.y / vs)}); dc.DrawBitmap(file.thumbnail, {(int) (pt.x / hs), (int) (pt.y / vs)});
dc.SetUserScale(1, 1); dc.SetUserScale(1, 1);
if (m_file_sys->GetGroupMode() != PrinterFileSystem::G_NONE) { if (m_file_sys->GetGroupMode() != PrinterFileSystem::G_NONE) { dc.DrawBitmap(m_title_mask, pt); }
dc.DrawBitmap(m_mask, pt);
}
} }
bool show_download_state_always = true; bool show_download_state_always = true;
// Draw checked icon // Draw checked icon
if (m_selecting && !show_download_state_always) if (m_selecting && !show_download_state_always)
dc.DrawBitmap(selected ? m_checked_icon.bmp() : m_unchecked_icon.bmp(), pt + wxPoint{10, m_image_size.GetHeight() - m_checked_icon.GetBmpHeight() - 10}); dc.DrawBitmap(selected ? m_checked_icon.bmp() : m_unchecked_icon.bmp(), pt + wxPoint{10, m_content_rect.GetHeight() - m_checked_icon.GetBmpHeight() - 10});
// can't handle alpha // can't handle alpha
// dc.GradientFillLinear({pt.x, pt.y, m_border_size.GetWidth(), 60}, wxColour(0x6F, 0x6F, 0x6F, 0x99), wxColour(0x6F, 0x6F, 0x6F, 0), wxBOTTOM); // dc.GradientFillLinear({pt.x, pt.y, m_border_size.GetWidth(), 60}, wxColour(0x6F, 0x6F, 0x6F, 0x99), wxColour(0x6F, 0x6F, 0x6F, 0), wxBOTTOM);
else if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE) { else if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE) {
@ -611,8 +610,13 @@ void Slic3r::GUI::ImageGrid::renderContent(wxDC &dc, wxPoint const &pt, int inde
thirdAction = wxString::Format(L"%d%%...", file.progress); thirdAction = wxString::Format(L"%d%%...", file.progress);
} }
} }
if (m_file_sys->GetFileType() == PrinterFileSystem::F_MODEL) {
if (secondAction != _L("Play"))
thirdAction = secondAction;
secondAction = _L("Print");
}
// Draw buttons on hovered item // Draw buttons on hovered item
wxRect rect{pt.x, pt.y + m_image_size.GetHeight() - m_buttons_background.GetHeight(), m_image_size.GetWidth(), m_buttons_background.GetHeight()}; wxRect rect{pt.x, pt.y + m_content_rect.GetHeight() - m_buttons_background.GetHeight(), m_content_rect.GetWidth(), m_buttons_background.GetHeight()};
if (hit) { if (hit) {
renderButtons(dc, {_L("Delete"), (wxChar const *) secondAction, thirdAction.IsEmpty() ? nullptr : (wxChar const *) thirdAction, nullptr}, rect, renderButtons(dc, {_L("Delete"), (wxChar const *) secondAction, thirdAction.IsEmpty() ? nullptr : (wxChar const *) thirdAction, nullptr}, rect,
m_hit_type == HIT_ACTION ? m_hit_item & 3 : -1, states); m_hit_type == HIT_ACTION ? m_hit_item & 3 : -1, states);
@ -625,7 +629,36 @@ void Slic3r::GUI::ImageGrid::renderContent(wxDC &dc, wxPoint const &pt, int inde
dc.DrawText(date, pt + wxPoint{24, 16}); dc.DrawText(date, pt + wxPoint{24, 16});
} }
if (m_selecting && show_download_state_always) if (m_selecting && show_download_state_always)
dc.DrawBitmap(selected ? m_checked_icon.bmp() : m_unchecked_icon.bmp(), pt + wxPoint{10, m_image_size.GetHeight() - m_checked_icon.GetBmpHeight() - 10}); dc.DrawBitmap(selected ? m_checked_icon.bmp() : m_unchecked_icon.bmp(), pt + wxPoint{10, m_content_rect.GetHeight() - m_checked_icon.GetBmpHeight() - 10});
}
void Slic3r::GUI::ImageGrid::renderContent2(wxDC &dc, wxPoint const &pt, int index, bool hit)
{
auto &file = m_file_sys->GetFile(index);
// Draw thumbnail & buttons
int h = m_content_rect.GetHeight() * 64 / 264;
m_content_rect.SetHeight(m_content_rect.GetHeight() - h);
renderContent1(dc, pt, index, hit);
m_content_rect.SetHeight(m_content_rect.GetHeight() + h);
// Draw info bar
auto br = dc.GetBrush();
dc.SetBrush(*wxWHITE);
dc.DrawRectangle(pt.x, pt.y + m_content_rect.GetHeight() - h, m_content_rect.GetWidth(), h);
dc.SetBrush(br);
// Draw infos
dc.SetFont(Label::Head_16);
dc.SetTextForeground(StateColor::darkModeColorFor("#323A3D"));
auto em = em_unit(this);
wxRect rect{pt.x, pt.y + m_content_rect.GetHeight() - h, m_content_rect.GetWidth(), h / 2};
rect.Deflate(em, 0);
renderText2(dc, from_u8(file.Metadata("Title", file.name)), rect);
rect.Offset(0, h / 2);
rect.SetWidth(rect.GetWidth() / 2 - em);
dc.SetFont(Label::Body_13);
dc.SetTextForeground(StateColor::darkModeColorFor("#6B6B6B"));
renderIconText(dc, m_model_time_icon, file.Metadata("Time", "0m"), rect);
rect.Offset(m_content_rect.GetWidth() / 2, 0);
renderIconText(dc, m_model_weight_icon, file.Metadata("Weight", "0g"), rect);
} }
void Slic3r::GUI::ImageGrid::renderButtons(wxDC &dc, wxStringList const &texts, wxRect const &rect2, size_t hit, int states) void Slic3r::GUI::ImageGrid::renderButtons(wxDC &dc, wxStringList const &texts, wxRect const &rect2, size_t hit, int states)
@ -646,7 +679,9 @@ void Slic3r::GUI::ImageGrid::renderButtons(wxDC &dc, wxStringList const &texts,
// Draw button background // Draw button background
//dc.Blit(rect.GetTopLeft(), rect.GetSize(), &mdc, {m_buttonBackgroundColor.colorIndexForStates(states) * 128, 0}); //dc.Blit(rect.GetTopLeft(), rect.GetSize(), &mdc, {m_buttonBackgroundColor.colorIndexForStates(states) * 128, 0});
//dc.DrawBitmap(m_button_background, rect2.GetTopLeft()); //dc.DrawBitmap(m_button_background, rect2.GetTopLeft());
rect.Deflate(10, 5); //dc.SetBrush(m_buttonBackgroundColor.colorForStates(states2));
//dc.DrawRectangle(rect);
//rect.Deflate(10, 5);
// Draw button splitter // Draw button splitter
auto pen = dc.GetPen(); auto pen = dc.GetPen();
dc.SetPen(wxPen("#616161")); dc.SetPen(wxPen("#616161"));
@ -654,7 +689,7 @@ void Slic3r::GUI::ImageGrid::renderButtons(wxDC &dc, wxStringList const &texts,
dc.SetPen(pen); dc.SetPen(pen);
// Draw button text // Draw button text
renderText(dc, texts[i], rect, states | states2); renderText(dc, texts[i], rect, states | states2);
rect.Inflate(10, 5); //rect.Inflate(10, 5);
rect.Offset(rect.GetWidth(), 0); rect.Offset(rect.GetWidth(), 0);
} }
dc.SetFont(GetFont()); dc.SetFont(GetFont());
@ -668,4 +703,20 @@ void Slic3r::GUI::ImageGrid::renderText(wxDC &dc, wxString const &text, wxRect c
dc.DrawText(text, rc.GetTopLeft()); dc.DrawText(text, rc.GetTopLeft());
} }
void Slic3r::GUI::ImageGrid::renderText2(wxDC &dc, wxString text, wxRect const &rect)
{
wxRect rc({0, 0}, dc.GetTextExtent(text));
rc = rc.CenterIn(rect);
rc.SetLeft(rect.GetLeft());
if (rc.GetWidth() > rect.GetWidth())
text = wxControl::Ellipsize(text, dc, wxELLIPSIZE_END, rect.GetWidth());
dc.DrawText(text, rc.GetTopLeft());
}
void Slic3r::GUI::ImageGrid::renderIconText(wxDC & dc, ScalableBitmap const & icon, wxString text, wxRect const & rect)
{
dc.DrawBitmap(icon.bmp(), rect.x, rect.y + (rect.height - icon.GetBmpHeight()) / 2);
renderText2(dc, text, {rect.x + icon.GetBmpWidth() + 4, rect.y, rect.width - icon.GetBmpWidth() - 4, rect.height});
}
}} }}

View file

@ -19,6 +19,8 @@ class Label;
class PrinterFileSystem; class PrinterFileSystem;
wxDECLARE_EVENT(EVT_ITEM_ACTION, wxCommandEvent);
namespace Slic3r { namespace Slic3r {
class MachineObject; class MachineObject;
@ -36,7 +38,7 @@ public:
boost::shared_ptr<PrinterFileSystem> GetFileSystem() { return m_file_sys; } boost::shared_ptr<PrinterFileSystem> GetFileSystem() { return m_file_sys; }
void SetFileType(int type); void SetFileType(int type, std::string const &storage);
void SetGroupMode(int mode); void SetGroupMode(int mode);
@ -72,15 +74,23 @@ protected:
wxBitmap createAlphaBitmap(wxSize size, wxColour color, int alpha1, int alpha2); wxBitmap createAlphaBitmap(wxSize size, wxColour color, int alpha1, int alpha2);
wxBitmap createShadowBorder(wxSize size, wxColour color, int radius, int shadow);
wxBitmap createCircleBitmap(wxSize size, int borderWidth, int percent, wxColour fillColor, wxColour borderColor = wxTransparentColour); wxBitmap createCircleBitmap(wxSize size, int borderWidth, int percent, wxColour fillColor, wxColour borderColor = wxTransparentColour);
void render(wxDC &dc); void render(wxDC &dc);
void renderContent(wxDC &dc, wxPoint const &pt, int index, bool hit); void renderContent1(wxDC &dc, wxPoint const &pt, int index, bool hit);
void renderContent2(wxDC &dc, wxPoint const &pt, int index, bool hit);
void renderButtons(wxDC &dc, wxStringList const &texts, wxRect const &rect, size_t hit, int states); void renderButtons(wxDC &dc, wxStringList const &texts, wxRect const &rect, size_t hit, int states);
void renderText(wxDC &dc, wxString const & text, wxRect const & rect, int states); void renderText(wxDC &dc, wxString const &text, wxRect const &rect, int states);
void renderText2(wxDC &dc, wxString text, wxRect const &rect);
void renderIconText(wxDC &dc, ScalableBitmap const & icon, wxString text, wxRect const &rect);
// some useful events // some useful events
void mouseMoved(wxMouseEvent& event); void mouseMoved(wxMouseEvent& event);
@ -100,6 +110,8 @@ private:
ScalableBitmap m_checked_icon; ScalableBitmap m_checked_icon;
ScalableBitmap m_unchecked_icon; ScalableBitmap m_unchecked_icon;
ScalableBitmap m_model_time_icon;
ScalableBitmap m_model_weight_icon;
StateColor m_buttonBackgroundColor; StateColor m_buttonBackgroundColor;
StateColor m_buttonTextColor; StateColor m_buttonTextColor;
@ -107,7 +119,8 @@ private:
bool m_pressed = false; bool m_pressed = false;
wxTimer m_timer; wxTimer m_timer;
wxBitmap m_mask; wxBitmap m_title_mask;
wxBitmap m_border_mask;
wxBitmap m_buttons_background; wxBitmap m_buttons_background;
wxBitmap m_buttons_background_checked; wxBitmap m_buttons_background_checked;
// wxBitmap m_button_background; // wxBitmap m_button_background;
@ -128,8 +141,9 @@ private:
int m_row_offset = 0; // 1/4 row height int m_row_offset = 0; // 1/4 row height
int m_row_count = 0; // 1/4 row height int m_row_count = 0; // 1/4 row height
int m_col_count = 1; int m_col_count = 1;
wxSize m_image_size;
wxSize m_cell_size; wxSize m_cell_size;
wxSize m_border_size;
wxRect m_content_rect;
}; };
}} }}

View file

@ -7,6 +7,14 @@
#include "Widgets/SwitchButton.hpp" #include "Widgets/SwitchButton.hpp"
#include "Widgets/Label.hpp" #include "Widgets/Label.hpp"
#include "Printer/PrinterFileSystem.h" #include "Printer/PrinterFileSystem.h"
#include "MsgDialog.hpp"
#ifdef __WXMSW__
#include <shellapi.h>
#endif
#ifdef __APPLE__
#include "../Utils/MacDarkMode.hpp"
#endif
namespace Slic3r { namespace Slic3r {
namespace GUI { namespace GUI {
@ -64,17 +72,20 @@ MediaFilePanel::MediaFilePanel(wxWindow * parent)
m_button_timelapse->SetToolTip(L("Switch to timelapse files.")); m_button_timelapse->SetToolTip(L("Switch to timelapse files."));
m_button_video = new ::Button(m_type_panel, _L("Video"), "", wxBORDER_NONE); m_button_video = new ::Button(m_type_panel, _L("Video"), "", wxBORDER_NONE);
m_button_video->SetToolTip(L("Switch to video files.")); m_button_video->SetToolTip(L("Switch to video files."));
for (auto b : {m_button_timelapse, m_button_video} ) { m_button_model = new ::Button(m_type_panel, _L("Model"), "", wxBORDER_NONE);
m_button_video->SetToolTip(L("Switch to 3mf model files."));
for (auto b : {m_button_timelapse, m_button_video, m_button_model}) {
b->SetBackgroundColor(background); b->SetBackgroundColor(background);
b->SetCanFocus(false); b->SetCanFocus(false);
} }
wxBoxSizer *type_sizer = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer *type_sizer = new wxBoxSizer(wxHORIZONTAL);
type_sizer->Add(m_button_timelapse, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 24); type_sizer->Add(m_button_timelapse, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 24);
type_sizer->Add(m_button_video, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 24); //type_sizer->Add(m_button_video, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 24);
m_button_video->Hide();
type_sizer->Add(m_button_model, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 24);
m_type_panel->SetSizer(type_sizer); m_type_panel->SetSizer(type_sizer);
m_type_panel->Hide(); top_sizer->Add(m_type_panel, 0, wxALIGN_CENTER_VERTICAL);
// top_sizer->Add(m_type_panel, 0, wxALIGN_CENTER_VERTICAL);
// File management // File management
m_manage_panel = new ::StaticBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); m_manage_panel = new ::StaticBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
@ -109,6 +120,7 @@ MediaFilePanel::MediaFilePanel(wxWindow * parent)
sizer->Add(top_sizer, 0, wxEXPAND); sizer->Add(top_sizer, 0, wxEXPAND);
m_image_grid = new ImageGrid(this); m_image_grid = new ImageGrid(this);
m_image_grid->Bind(EVT_ITEM_ACTION, [this](wxCommandEvent &e) { doAction(size_t(e.GetExtraLong()), e.GetInt()); });
m_image_grid->SetStatus(m_bmp_failed, _L("No printers.")); m_image_grid->SetStatus(m_bmp_failed, _L("No printers."));
sizer->Add(m_image_grid, 1, wxEXPAND); sizer->Add(m_image_grid, 1, wxEXPAND);
@ -130,19 +142,20 @@ MediaFilePanel::MediaFilePanel(wxWindow * parent)
// File type // File type
auto type_button_clicked = [this](wxEvent &e) { auto type_button_clicked = [this](wxEvent &e) {
auto type = PrinterFileSystem::F_TIMELAPSE; Button *buttons[]{m_button_timelapse, m_button_video, m_button_model};
auto b = dynamic_cast<Button *>(e.GetEventObject()); auto type = std::find(buttons, buttons + sizeof(buttons) / sizeof(buttons[0]), e.GetEventObject()) - buttons;
if (b == m_button_video)
type = PrinterFileSystem::F_VIDEO;
if (m_last_type == type) if (m_last_type == type)
return; return;
m_image_grid->SetFileType(type); m_image_grid->SetFileType(type, m_external ? "" : "internal");
buttons[m_last_type]->SetValue(!buttons[m_last_type]->GetValue());
m_last_type = type; m_last_type = type;
m_button_timelapse->SetValue(!m_button_timelapse->GetValue()); buttons[m_last_type]->SetValue(!buttons[m_last_type]->GetValue());
m_button_video->SetValue(!m_button_video->GetValue()); if (type == PrinterFileSystem::F_MODEL)
m_image_grid->SetGroupMode(PrinterFileSystem::G_NONE);
}; };
m_button_video->Bind(wxEVT_COMMAND_BUTTON_CLICKED, type_button_clicked);
m_button_timelapse->Bind(wxEVT_COMMAND_BUTTON_CLICKED, type_button_clicked); m_button_timelapse->Bind(wxEVT_COMMAND_BUTTON_CLICKED, type_button_clicked);
m_button_video->Bind(wxEVT_COMMAND_BUTTON_CLICKED, type_button_clicked);
m_button_model->Bind(wxEVT_COMMAND_BUTTON_CLICKED, type_button_clicked);
m_button_timelapse->SetValue(true); m_button_timelapse->SetValue(true);
// File management // File management
@ -162,8 +175,10 @@ MediaFilePanel::MediaFilePanel(wxWindow * parent)
auto onShowHide = [this](auto &e) { auto onShowHide = [this](auto &e) {
e.Skip(); e.Skip();
if (m_isBeingDeleted) return; if (m_isBeingDeleted) return;
CallAfter([this] {
auto fs = m_image_grid ? m_image_grid->GetFileSystem() : nullptr; auto fs = m_image_grid ? m_image_grid->GetFileSystem() : nullptr;
if (fs) IsShownOnScreen() ? fs->Start() : fs->Stop(); if (fs) IsShownOnScreen() ? fs->Start() : fs->Stop();
});
}; };
Bind(wxEVT_SHOW, onShowHide); Bind(wxEVT_SHOW, onShowHide);
parent->GetParent()->Bind(wxEVT_SHOW, onShowHide); parent->GetParent()->Bind(wxEVT_SHOW, onShowHide);
@ -208,13 +223,15 @@ void MediaFilePanel::SetMachineObject(MachineObject* obj)
} else { } else {
boost::shared_ptr<PrinterFileSystem> fs(new PrinterFileSystem); boost::shared_ptr<PrinterFileSystem> fs(new PrinterFileSystem);
fs->Attached(); fs->Attached();
m_image_grid->SetFileType(m_last_type);
m_image_grid->SetFileSystem(fs); m_image_grid->SetFileSystem(fs);
m_image_grid->SetFileType(m_last_type, m_external ? "" : "internal");
fs->Bind(EVT_FILE_CHANGED, [this, wfs = boost::weak_ptr(fs)](auto &e) { fs->Bind(EVT_FILE_CHANGED, [this, wfs = boost::weak_ptr(fs)](auto &e) {
e.Skip(); e.Skip();
boost::shared_ptr fs(wfs.lock()); boost::shared_ptr fs(wfs.lock());
if (m_image_grid->GetFileSystem() != fs) // canceled if (m_image_grid->GetFileSystem() != fs) // canceled
return; return;
m_time_panel->Show(fs->GetFileType() < PrinterFileSystem::F_MODEL);
//m_manage_panel->Show(fs->GetFileType() < PrinterFileSystem::F_MODEL);
m_button_management->Enable(fs->GetCount() > 0); m_button_management->Enable(fs->GetCount() > 0);
if (fs->GetCount() == 0) if (fs->GetCount() == 0)
SetSelecting(false); SetSelecting(false);
@ -301,6 +318,22 @@ void MediaFilePanel::SetMachineObject(MachineObject* obj)
modeChanged(e); modeChanged(e);
} }
void MediaFilePanel::SwitchStorage(bool external)
{
if (m_external == external)
return;
m_external = external;
m_type_panel->Show(external);
if (!external) {
Button *buttons[]{m_button_timelapse, m_button_video, m_button_model};
auto button = buttons[PrinterFileSystem::F_MODEL];
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId());
event.SetEventObject(button);
wxPostEvent(button, event);
}
m_image_grid->SetFileType(m_last_type, m_external ? "" : "internal");
}
void MediaFilePanel::Rescale() void MediaFilePanel::Rescale()
{ {
m_bmp_loading.msw_rescale(); m_bmp_loading.msw_rescale();
@ -315,6 +348,7 @@ void MediaFilePanel::Rescale()
m_button_video->Rescale(); m_button_video->Rescale();
m_button_timelapse->Rescale(); m_button_timelapse->Rescale();
m_button_model->Rescale();
m_type_panel->SetMinSize({-1, 48 * em_unit(this) / 10}); m_type_panel->SetMinSize({-1, 48 * em_unit(this) / 10});
m_button_download->Rescale(); m_button_download->Rescale();
@ -384,6 +418,80 @@ void MediaFilePanel::fetchUrl(boost::weak_ptr<PrinterFileSystem> wfs)
} }
} }
void Slic3r::GUI::MediaFilePanel::doAction(size_t index, int action)
{
auto fs = m_image_grid->GetFileSystem();
if (action == 0) {
if (fs->GetSelectCount() > 1) {
MessageDialog dlg(this,
wxString::Format(_L("You are going to delete %u files. Are you sure to continue?"), fs->GetSelectCount()),
_L("Delete files"), wxYES_NO | wxICON_WARNING);
if (dlg.ShowModal() != wxID_YES)
return;
}
fs->DeleteFiles(index);
} else if (action == 1) {
if (fs->GetFileType() == PrinterFileSystem::F_MODEL) {
if (index != -1) {
fs->FetchModel(index, [](std::string const & data) {
// TODO: print gcode 3mf
});
}
return;
}
if (index != -1) {
auto &file = fs->GetFile(index);
if (file.IsDownload() && file.progress >= -1) {
if (file.progress >= 100) {
if (!fs->DownloadCheckFile(index)) {
MessageDialog(this,
wxString::Format(_L("File '%s' was lost! Please download it again."), from_u8(file.name)),
_L("Error"), wxOK).ShowModal();
Refresh();
return;
}
#ifdef __WXMSW__
auto wfile = boost::filesystem::path(file.local_path).wstring();
SHELLEXECUTEINFO info{sizeof(info), 0, NULL, NULL, wfile.c_str(), L"", SW_HIDE};
::ShellExecuteEx(&info);
#else
wxShell("open " + file.local_path);
#endif
} else {
fs->DownloadCancel(index);
}
return;
}
}
fs->DownloadFiles(index, wxGetApp().app_config->get("download_path"));
} else if (action == 2) {
if (index != -1) {
auto &file = fs->GetFile(index);
if (file.IsDownload() && file.progress >= -1) {
if (file.progress >= 100) {
if (!fs->DownloadCheckFile(index)) {
MessageDialog(this,
wxString::Format(_L("File '%s' was lost! Please download it again."), from_u8(file.name)),
_L("Error"), wxOK).ShowModal();
Refresh();
return;
}
#ifdef __WIN32__
wxExecute(L"explorer.exe /select," + from_u8(file.local_path));
#elif __APPLE__
openFolderForFile(from_u8(file.local_path));
#else
#endif
} else if (fs->GetFileType() == PrinterFileSystem::F_MODEL) {
fs->DownloadCancel(index);
}
return;
}
}
fs->DownloadFiles(index, wxGetApp().app_config->get("download_path"));
}
}
MediaFileFrame::MediaFileFrame(wxWindow* parent) MediaFileFrame::MediaFileFrame(wxWindow* parent)
: DPIFrame(parent, wxID_ANY, "Media Files", wxDefaultPosition, { 1600, 900 }) : DPIFrame(parent, wxID_ANY, "Media Files", wxDefaultPosition, { 1600, 900 })
{ {

View file

@ -36,6 +36,8 @@ public:
void SetMachineObject(MachineObject * obj); void SetMachineObject(MachineObject * obj);
void SwitchStorage(bool external);
public: public:
void Rescale(); void Rescale();
@ -46,6 +48,8 @@ private:
void fetchUrl(boost::weak_ptr<PrinterFileSystem> fs); void fetchUrl(boost::weak_ptr<PrinterFileSystem> fs);
void doAction(size_t index, int action);
private: private:
ScalableBitmap m_bmp_loading; ScalableBitmap m_bmp_loading;
ScalableBitmap m_bmp_failed; ScalableBitmap m_bmp_failed;
@ -60,12 +64,17 @@ private:
::StaticBox * m_type_panel = nullptr; ::StaticBox * m_type_panel = nullptr;
::Button * m_button_video = nullptr; ::Button * m_button_video = nullptr;
::Button * m_button_timelapse = nullptr; ::Button * m_button_timelapse = nullptr;
::Button * m_button_model = nullptr;
::StaticBox *m_manage_panel = nullptr; ::StaticBox *m_manage_panel = nullptr;
::Button * m_button_delete = nullptr; ::Button * m_button_delete = nullptr;
::Button *m_button_download = nullptr; ::Button *m_button_download = nullptr;
::Button *m_button_management = nullptr; ::Button *m_button_management = nullptr;
ImageGrid * m_image_grid = nullptr;
bool m_external = true;
std::string m_machine; std::string m_machine;
std::string m_lan_ip; std::string m_lan_ip;
std::string m_lan_user; std::string m_lan_user;
@ -74,8 +83,6 @@ private:
bool m_lan_mode = false; bool m_lan_mode = false;
bool m_tutk_support = false; bool m_tutk_support = false;
ImageGrid * m_image_grid = nullptr;
int m_last_mode = 0; int m_last_mode = 0;
int m_last_type = 0; int m_last_type = 0;
}; };

View file

@ -197,15 +197,20 @@ MonitorPanel::~MonitorPanel()
m_tabpanel = new Tabbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, sizer_side_tools, wxNB_LEFT | wxTAB_TRAVERSAL | wxNB_NOPAGETHEME); m_tabpanel = new Tabbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, sizer_side_tools, wxNB_LEFT | wxTAB_TRAVERSAL | wxNB_NOPAGETHEME);
m_tabpanel->SetBackgroundColour(wxColour("#FEFFFF")); m_tabpanel->SetBackgroundColour(wxColour("#FEFFFF"));
m_tabpanel->Bind(wxEVT_BOOKCTRL_PAGE_CHANGED, [this](wxBookCtrlEvent& e) { m_tabpanel->Bind(wxEVT_BOOKCTRL_PAGE_CHANGED, [this](wxBookCtrlEvent& e) {
; auto page = m_tabpanel->GetCurrentPage();
}); if (page == m_media_file_panel) {
auto title = m_tabpanel->GetPageText(m_tabpanel->GetSelection());
m_media_file_panel->SwitchStorage(title == _L("SD Card"));
}
}, m_tabpanel->GetId());
//m_status_add_machine_panel = new AddMachinePanel(m_tabpanel); //m_status_add_machine_panel = new AddMachinePanel(m_tabpanel);
m_status_info_panel = new StatusPanel(m_tabpanel); m_status_info_panel = new StatusPanel(m_tabpanel);
m_tabpanel->AddPage(m_status_info_panel, _L("Status"), "", true); m_tabpanel->AddPage(m_status_info_panel, _L("Status"), "", true);
m_media_file_panel = new MediaFilePanel(m_tabpanel); m_media_file_panel = new MediaFilePanel(m_tabpanel);
m_tabpanel->AddPage(m_media_file_panel, _L("Media"), "", false); m_tabpanel->AddPage(m_media_file_panel, _L("SD Card"), "", false);
m_tabpanel->AddPage(m_media_file_panel, _L("Internal Storage"), "", false);
m_upgrade_panel = new UpgradePanel(m_tabpanel); m_upgrade_panel = new UpgradePanel(m_tabpanel);
m_tabpanel->AddPage(m_upgrade_panel, _L("Update"), "", false); m_tabpanel->AddPage(m_upgrade_panel, _L("Update"), "", false);