ENH: Auxiliary GUI

Change-Id: Iaefd8bb6a2a560f4f2ec8235b21231763d8562fe
This commit is contained in:
liz.li 2022-08-24 20:14:23 +08:00 committed by Lane.Wei
parent 16bbcf6f97
commit 36ca76c2a4
5 changed files with 215 additions and 107 deletions

View file

@ -17,6 +17,8 @@
#include <wx/filedlg.h>
#include <wx/wupdlock.h>
#include <wx/dataview.h>
#include <wx/tokenzr.h>
#include <wx/arrstr.h>
#include <wx/tglbtn.h>
#include "wxExtensions.hpp"
@ -44,18 +46,17 @@ const std::vector<std::string> license_list = {
AuFile::AuFile(wxWindow *parent, fs::path file_path, wxString file_name, AuxiliaryFolderType type, wxWindowID id, const wxPoint &pos, const wxSize &size, long style)
{
wxPanel::Create(parent, id, pos, wxSize(FromDIP(300), FromDIP(340)), style);
SetBackgroundColour(AUFILE_GREY300);
wxBoxSizer *sizer_body = new wxBoxSizer(wxVERTICAL);
SetSize(wxSize(FromDIP(300), FromDIP(340)));
SetMinSize(wxSize(FromDIP(300), FromDIP(340)));
SetMaxSize(wxSize(FromDIP(300), FromDIP(340)));
m_type = type;
m_file_path = file_path;
m_file_name = file_name;
wxSize panel_size = m_type == MODEL_PICTURE ? AUFILE_PICTURES_PANEL_SIZE : AUFILE_PANEL_SIZE;
wxPanel::Create(parent, id, pos, panel_size, style);
SetBackgroundColour(AUFILE_GREY300);
wxBoxSizer *sizer_body = new wxBoxSizer(wxVERTICAL);
SetSize(panel_size);
if (m_type == MODEL_PICTURE) {
if (m_file_path.empty()) { return; }
auto image = new wxImage(encode_path(m_file_path.string().c_str()));
@ -64,19 +65,25 @@ AuFile::AuFile(wxWindow *parent, fs::path file_path, wxString file_name, Auxilia
auto size = wxSize(0, 0);
float proportion = float(image->GetSize().x) / float(image->GetSize().y);
if (proportion >= 1) {
size.x = FromDIP(300);
size.y = FromDIP(300) / proportion;
size.x = AUFILE_PICTURES_SIZE.x;
size.y = AUFILE_PICTURES_SIZE.x / proportion;
} else {
size.y = FromDIP(300);
size.x = FromDIP(300) * proportion;
size.y = AUFILE_PICTURES_SIZE.y;
size.x = AUFILE_PICTURES_SIZE.y * proportion;
}
image->Rescale(size.x, size.y);
m_file_bitmap = wxBitmap(*image);
} else {
<<<<<<< HEAD (40727c FIX: Slicing process crashes when enable timelapse)
m_bitmap_excel = create_scaled_bitmap("placeholder_excel", nullptr, 300);
m_bitmap_pdf = create_scaled_bitmap("placeholder_pdf", nullptr, 300);
m_bitmap_txt = create_scaled_bitmap("placeholder_txt", nullptr, 300);
=======
m_bitmap_excel = ScalableBitmap(this, "placeholder_excel", 168);
m_bitmap_pdf = ScalableBitmap(this, "placeholder_pdf", 168);
m_bitmap_txt = ScalableBitmap(this, "placeholder_txt", 168);
>>>>>>> CHANGE (3c1599 ENH: Auxiliary GUI)
if (m_type == OTHERS) {m_file_bitmap = m_bitmap_txt;}
if (m_type == BILL_OF_MATERIALS) {
@ -90,6 +97,7 @@ AuFile::AuFile(wxWindow *parent, fs::path file_path, wxString file_name, Auxilia
if (m_type == ASSEMBLY_GUIDE) {m_file_bitmap = m_bitmap_pdf;}
}
m_add_file = _L("Add File");
cover_text_left = _L("Set as cover");
cover_text_right = _L("Rename");
cover_text_cover = _L("Cover");
@ -98,15 +106,15 @@ AuFile::AuFile(wxWindow *parent, fs::path file_path, wxString file_name, Auxilia
m_file_edit_mask = ScalableBitmap(this, "auxiliary_edit_mask", 43);
m_file_delete = ScalableBitmap(this, "auxiliary_delete", 28);
auto m_text_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(FromDIP(300), FromDIP(40)), wxTAB_TRAVERSAL);
auto m_text_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(panel_size.x, AUFILE_TEXT_HEIGHT), wxTAB_TRAVERSAL);
m_text_panel->SetBackgroundColour(AUFILE_GREY300);
wxBoxSizer *m_text_sizer = new wxBoxSizer(wxVERTICAL);
m_text_name = new wxStaticText(m_text_panel, wxID_ANY, m_file_name, wxDefaultPosition, wxSize(FromDIP(300), FromDIP(20)), 0);
m_text_name->Wrap(FromDIP(290));
m_text_name = new wxStaticText(m_text_panel, wxID_ANY, m_file_name, wxDefaultPosition, wxSize(panel_size.x, -1), wxST_ELLIPSIZE_END);
m_text_name->Wrap(panel_size.x - FromDIP(10));
m_text_name->SetFont(::Label::Body_14);
m_input_name = new ::TextInput(m_text_panel, wxEmptyString, wxEmptyString, wxEmptyString, wxDefaultPosition, wxSize(FromDIP(300), FromDIP(35)), wxTE_PROCESS_ENTER);
m_input_name = new ::TextInput(m_text_panel, wxEmptyString, wxEmptyString, wxEmptyString, wxDefaultPosition, wxSize(panel_size.x, FromDIP(35)), wxTE_PROCESS_ENTER);
m_input_name->GetTextCtrl()->SetFont(::Label::Body_13);
m_input_name->SetFont(::Label::Body_14);
m_input_name->Hide();
@ -117,7 +125,7 @@ AuFile::AuFile(wxWindow *parent, fs::path file_path, wxString file_name, Auxilia
m_text_panel->SetSizer(m_text_sizer);
m_text_panel->Layout();
sizer_body->Add(0, 0, 0, wxTOP, FromDIP(300));
sizer_body->Add(0, 0, 0, wxTOP, panel_size.y - AUFILE_TEXT_HEIGHT);
sizer_body->Add(m_text_panel, 0, wxALIGN_CENTER, 0);
SetSizer(sizer_body);
@ -149,12 +157,26 @@ void AuFile::exit_rename_mode()
void AuFile::OnPaint(wxPaintEvent &event)
{
//wxPaintDC dc(this);
//render(dc);
wxBufferedPaintDC dc(this);
PrepareDC(dc);
wxPaintDC dc(this);
#ifdef __WXMSW__
wxSize size = GetSize();
wxMemoryDC memdc;
wxBitmap bmp(size.x, size.y);
memdc.SelectObject(bmp);
memdc.Blit({ 0, 0 }, size, &dc, { 0, 0 });
{
wxGCDC dc2(memdc);
PaintBackground(dc2);
PaintForeground(dc2);
}
memdc.SelectObject(wxNullBitmap);
dc.DrawBitmap(bmp, 0, 0);
#else
PaintBackground(dc);
PaintForeground(dc);
#endif
}
void AuFile::PaintBackground(wxDC &dc)
@ -169,20 +191,68 @@ void AuFile::PaintBackground(wxDC &dc)
dc.DrawRectangle(windowRect);
<<<<<<< HEAD (40727c FIX: Slicing process crashes when enable timelapse)
wxSize size = wxSize(FromDIP(300), FromDIP(300));
dc.SetPen(AUFILE_GREY200);
dc.SetBrush(AUFILE_GREY200);
dc.DrawRectangle(0,0,size.x,size.y);
dc.DrawBitmap(m_file_bitmap, (size.x - m_file_bitmap.GetSize().x) / 2, (size.y - m_file_bitmap.GetSize().y) / 2);
=======
wxSize size = m_type == MODEL_PICTURE ? AUFILE_PICTURES_SIZE : AUFILE_SIZE;
if (m_type == AddFileButton)
{
auto pen_width = FromDIP(2);
dc.SetPen(wxPen(AUFILE_GREY500, pen_width));
dc.SetBrush(AUFILE_GREY200);
dc.DrawRoundedRectangle(pen_width / 2, pen_width / 2, size.x - pen_width / 2, size.y - pen_width / 2, AUFILE_ROUNDING);
auto line_length = FromDIP(50);
dc.DrawLine(wxPoint((size.x - line_length) / 2, size.y / 2), wxPoint((size.x + line_length) / 2, size.y / 2));
dc.DrawLine(wxPoint(size.x / 2, (size.y - line_length) / 2), wxPoint(size.x / 2, (size.y + line_length) / 2));
dc.SetFont(Label::Body_16);
auto sizet = dc.GetTextExtent(m_add_file);
auto pos = wxPoint(0, 0);
pos.x = (size.x - sizet.x) / 2;
pos.y = (size.y - 40); // to modify
dc.SetTextForeground(AUFILE_GREY500);
dc.DrawText(m_add_file, pos);
}
else {
dc.SetPen(AUFILE_GREY200);
dc.SetBrush(AUFILE_GREY200);
dc.DrawRoundedRectangle(0, 0, size.x, size.y, AUFILE_ROUNDING);
dc.DrawBitmap(m_file_bitmap.bmp(), (size.x - m_file_bitmap.GetBmpWidth()) / 2, (size.y - m_file_bitmap.GetBmpHeight()) / 2);
}
>>>>>>> CHANGE (3c1599 ENH: Auxiliary GUI)
}
void AuFile::OnEraseBackground(wxEraseEvent &evt) {}
void AuFile::PaintForeground(wxDC &dc)
{
wxSize size = wxSize(FromDIP(300), FromDIP(300));
wxSize size = m_type == MODEL_PICTURE ? AUFILE_PICTURES_SIZE : AUFILE_SIZE;
if (m_hover) {
if (m_type == AddFileButton) {
auto pen_width = FromDIP(2);
dc.SetPen(wxPen(AUFILE_BRAND, pen_width));
dc.SetBrush(AUFILE_BRAND_TRANSPARENT);
dc.DrawRoundedRectangle(pen_width / 2, pen_width / 2, size.x - pen_width / 2, size.y - pen_width / 2, AUFILE_ROUNDING);
auto line_length = FromDIP(50);
dc.DrawLine(wxPoint((size.x - line_length) / 2, size.y / 2), wxPoint((size.x + line_length) / 2, size.y / 2));
dc.DrawLine(wxPoint(size.x / 2, (size.y - line_length) / 2), wxPoint(size.x / 2, (size.y + line_length) / 2));
auto sizet = dc.GetTextExtent(m_add_file);
auto pos = wxPoint(0, 0);
pos.x = (size.x - sizet.x) / 2;
pos.y = (size.y - 40); // to modify
dc.SetTextForeground(AUFILE_BRAND);
dc.DrawText(m_add_file, pos);
return;
}
dc.DrawBitmap(m_file_edit_mask.bmp(), 0, size.y - m_file_edit_mask.GetBmpSize().y);
dc.SetFont(Label::Body_14);
dc.SetTextForeground(*wxWHITE);
@ -246,7 +316,7 @@ void AuFile::on_mouse_leave(wxMouseEvent &evt)
void AuFile::on_input_enter(wxCommandEvent &evt)
{
auto new_file_name = into_u8(m_input_name->GetTextCtrl()->GetValue());
auto new_file_name = m_input_name->GetTextCtrl()->GetValue();
auto m_valid_type = Valid;
wxString info_line;
@ -271,8 +341,8 @@ void AuFile::on_input_enter(wxCommandEvent &evt)
auto new_fullname = new_file_name + m_file_path.extension().string();
auto new_fullname_path = dir.string() + "/" + new_fullname;
fs::path new_dir_path(new_fullname_path.c_str());
wxString new_fullname_path = dir.wstring() + "/" + new_fullname;
fs::path new_dir_path(new_fullname_path);
if (fs::exists(new_dir_path)) existing = true;
@ -314,7 +384,7 @@ void AuFile::on_input_enter(wxCommandEvent &evt)
// post event
auto event = wxCommandEvent(EVT_AUXILIARY_UPDATE_RENAME);
event.SetString(wxString::Format("%s|%s|%s", s_default_folders[m_type], m_file_path.string(), new_dir_path.string()));
event.SetString(wxString::Format("%s|%s|%s", s_default_folders[m_type], m_file_path.wstring(), new_dir_path.wstring()));
event.SetEventObject(m_parent);
wxPostEvent(m_parent, event);
@ -328,12 +398,19 @@ void AuFile::on_input_enter(wxCommandEvent &evt)
void AuFile::on_dclick(wxMouseEvent &evt)
{
wxLaunchDefaultApplication(m_file_path.wstring(), 0);
if (m_type == AddFileButton)
return;
else
wxLaunchDefaultApplication(m_file_path.wstring(), 0);
}
void AuFile::on_mouse_left_up(wxMouseEvent &evt)
{
wxSize size = wxSize(FromDIP(300), FromDIP(300));
if (m_type == AddFileButton) {
return;
}
wxSize size = m_type == MODEL_PICTURE ? AUFILE_PICTURES_SIZE : AUFILE_SIZE;
auto pos = evt.GetPosition();
// set cover
@ -343,21 +420,29 @@ void AuFile::on_mouse_left_up(wxMouseEvent &evt)
auto cover_right = mask_size.x / 2;
auto cover_bottom = size.y;
if (pos.x > cover_left && pos.x < cover_right && pos.y > cover_top && pos.y < cover_bottom) { on_set_cover(); }
if (pos.x > cover_left && pos.x < cover_right && pos.y > cover_top && pos.y < cover_bottom) {
if(m_type == MODEL_PICTURE)
on_set_cover();
else
on_set_rename();
return;
}
// rename
auto rename_left = mask_size.x / 2;
auto rename_top = size.y - mask_size.y;
auto rename_right = mask_size.x;
auto rename_bottom = size.y;
if (pos.x > rename_left && pos.x < rename_right && pos.y > rename_top && pos.y < rename_bottom) { on_set_rename(); }
if (pos.x > rename_left && pos.x < rename_right && pos.y > rename_top && pos.y < rename_bottom) { on_set_rename(); return; }
// close
auto close_left = size.x - m_file_delete.GetBmpSize().x - FromDIP(15);
auto close_top = FromDIP(15);
auto close_right = size.x - FromDIP(15);
auto close_bottom = m_file_delete.GetBmpSize().y + FromDIP(15);
if (pos.x > close_left && pos.x < close_right && pos.y > close_top && pos.y < close_bottom) { on_set_delete(); }
if (pos.x > close_left && pos.x < close_right && pos.y > close_top && pos.y < close_bottom) { on_set_delete(); return; }
exit_rename_mode();
}
void AuFile::on_set_cover()
@ -430,7 +515,7 @@ void AuFile::on_set_delete()
if (is_fine) {
auto evt = wxCommandEvent(EVT_AUXILIARY_UPDATE_DELETE);
evt.SetString(wxString::Format("%s|%s", s_default_folders[m_type], m_file_path.string()));
evt.SetString(wxString::Format("%s|%s", s_default_folders[m_type], m_file_path.wstring()));
evt.SetEventObject(m_parent);
wxPostEvent(m_parent, evt);
}
@ -471,9 +556,15 @@ void AuFile::msw_rescale()
image->Rescale(size.x, size.y);
m_file_bitmap = wxBitmap(*image);
} else {
<<<<<<< HEAD (40727c FIX: Slicing process crashes when enable timelapse)
m_bitmap_excel = create_scaled_bitmap("placeholder_excel", nullptr, 300);
m_bitmap_pdf = create_scaled_bitmap("placeholder_pdf", nullptr, 300);
m_bitmap_txt = create_scaled_bitmap("placeholder_txt", nullptr, 300);
=======
m_bitmap_excel = ScalableBitmap(this, "placeholder_excel", 168);
m_bitmap_pdf = ScalableBitmap(this, "placeholder_pdf", 168);
m_bitmap_txt = ScalableBitmap(this, "placeholder_txt", 168);
>>>>>>> CHANGE (3c1599 ENH: Auxiliary GUI)
if (m_type == OTHERS) { m_file_bitmap = m_bitmap_txt; }
if (m_type == BILL_OF_MATERIALS) { m_file_bitmap = m_bitmap_excel; }
@ -505,7 +596,8 @@ AuFolderPanel::AuFolderPanel(wxWindow *parent, AuxiliaryFolderType type, wxWindo
m_button_add->SetMinSize(wxSize(-1, FromDIP(24)));
m_button_add->SetCornerRadius(FromDIP(12));
m_button_add->SetFont(Label::Body_14);
// m_button_add->Bind(wxEVT_LEFT_UP, &AuxiliaryPanel::on_add, this);
m_big_button_add = new AuFile(m_scrolledWindow, fs::path(), "", AddFileButton, -1);
/*m_button_del = new Button(m_scrolledWindow, _L("Delete"), "auxiliary_delete_file", 12, 12);
m_button_del->SetBackgroundColor(btn_bg_white);
@ -516,12 +608,18 @@ AuFolderPanel::AuFolderPanel(wxWindow *parent, AuxiliaryFolderType type, wxWindo
// m_button_del->Bind(wxEVT_LEFT_UP, &AuxiliaryPanel::on_delete, this);
sizer_top->Add(0, 0, 0, wxLEFT, FromDIP(10));
sizer_top->Add(m_button_add, 0, wxALL, 0);
m_gsizer_content = new wxWrapSizer(wxHORIZONTAL, wxWRAPSIZER_DEFAULT_FLAGS);
if (m_type == MODEL_PICTURE) {
sizer_top->Add(m_button_add, 0, wxALL, 0);
m_big_button_add->Hide();
}
else {
m_gsizer_content->Add(m_big_button_add, 0, wxALL, FromDIP(8));
m_button_add->Hide();
}
// sizer_top->Add(m_button_del, 0, wxALL, 0);
m_gsizer_content = new wxGridSizer(0, 3, FromDIP(18), FromDIP(18));
sizer_body->Add(sizer_top, 0, wxEXPAND | wxTOP, FromDIP(35));
sizer_body->Add(0, 0, 0, wxEXPAND | wxTOP, FromDIP(30));
sizer_body->AddSpacer(FromDIP(14));
sizer_body->Add(m_gsizer_content, 0, 0, 0);
m_scrolledWindow->SetSizer(sizer_body);
m_scrolledWindow->Layout();
@ -530,18 +628,25 @@ AuFolderPanel::AuFolderPanel(wxWindow *parent, AuxiliaryFolderType type, wxWindo
this->SetSizer(sizer_main);
this->Layout();
m_button_add->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(AuFolderPanel::on_add), NULL, this);
// m_button_del->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(AuFolderPanel::on_delete), NULL, this);
m_big_button_add->Bind(wxEVT_LEFT_DOWN, [this](auto& e)
{
auto evt = wxCommandEvent(EVT_AUXILIARY_IMPORT);
evt.SetString(s_default_folders[m_type]);
evt.SetEventObject(m_parent);
wxPostEvent(m_parent, evt);
});
m_button_add->Bind(wxEVT_BUTTON, &AuFolderPanel::on_add, this);
}
void AuFolderPanel::clear()
{
for (auto i = 0; i < m_aufiles_list.GetCount(); i++) {
AuFiles *aufile = m_aufiles_list[i];
if (aufile->file != NULL) { aufile->file->Destroy(); }
if (aufile->file) { aufile->file->Destroy(); }
}
m_aufiles_list.clear();
m_gsizer_content->Layout();
Layout();
Refresh();
}
void AuFolderPanel::update(std::vector<fs::path> paths)
@ -552,7 +657,7 @@ void AuFolderPanel::update(std::vector<fs::path> paths)
auto name = encode_path(temp_name.c_str());
auto aufile = new AuFile(m_scrolledWindow, paths[i], name, m_type, wxID_ANY);
m_gsizer_content->Add(aufile, 0, 0, 0);
m_gsizer_content->Add(aufile, 0, wxALL, FromDIP(8));
auto af = new AuFiles;
af->path = paths[i].string();
af->file = aufile;
@ -571,7 +676,7 @@ void AuFolderPanel::msw_rescale()
}
}
void AuFolderPanel::on_add(wxCommandEvent &event)
void AuFolderPanel::on_add(wxCommandEvent& event)
{
auto evt = wxCommandEvent(EVT_AUXILIARY_IMPORT);
evt.SetString(s_default_folders[m_type]);
@ -583,8 +688,6 @@ void AuFolderPanel::on_delete(wxCommandEvent &event) { clear(); }
AuFolderPanel::~AuFolderPanel()
{
m_button_add->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(AuFolderPanel::on_add), NULL, this);
// m_button_del->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(AuFolderPanel::on_delete), NULL, this);
}
void AuFolderPanel::update_cover()
@ -618,12 +721,19 @@ AuxiliaryPanel::AuxiliaryPanel(wxWindow *parent, wxWindowID id, const wxPoint &p
// delete event
Bind(EVT_AUXILIARY_UPDATE_DELETE, [this](wxCommandEvent &e) {
auto info_str = e.GetString();
auto parems = std::vector<std::string>{};
Split(info_str.ToStdString(), "|", parems);
wxArrayString parems;
wxStringTokenizer tokenizer(info_str, "|");
while (tokenizer.HasMoreTokens()) {
wxString token = tokenizer.GetNextToken();
parems.Add(token);
}
auto model = parems[0];
auto name = parems[1];
auto iter = m_paths_list.find(model);
auto iter = m_paths_list.find(model.ToStdString());
if (iter != m_paths_list.end()) {
auto list = iter->second;
for (auto i = 0; i < list.size(); i++) {
@ -633,7 +743,7 @@ AuxiliaryPanel::AuxiliaryPanel(wxWindow *parent, wxWindowID id, const wxPoint &p
}
}
m_paths_list[model] = list;
m_paths_list[model.ToStdString()] = list;
update_all_panel();
update_all_cover();
}
@ -643,14 +753,18 @@ AuxiliaryPanel::AuxiliaryPanel(wxWindow *parent, wxWindowID id, const wxPoint &p
Bind(EVT_AUXILIARY_UPDATE_RENAME, [this](wxCommandEvent &e) {
auto info_str = e.GetString();
auto parems = std::vector<std::string>{};
Split(info_str.ToStdString(), "|", parems);
wxArrayString parems;
wxStringTokenizer tokenizer(info_str, "|");
while (tokenizer.HasMoreTokens()) {
wxString token = tokenizer.GetNextToken();
parems.Add(token);
}
auto model = parems[0];
auto old_name = parems[1];
auto new_name = parems[2];
auto iter = m_paths_list.find(model);
auto iter = m_paths_list.find(model.ToStdString());
if (iter != m_paths_list.end()) {
auto list = iter->second;
for (auto i = 0; i < list.size(); i++) {
@ -660,7 +774,7 @@ AuxiliaryPanel::AuxiliaryPanel(wxWindow *parent, wxWindowID id, const wxPoint &p
}
}
m_paths_list[model] = list;
m_paths_list[model.ToStdString()] = list;
}
});
}
@ -944,6 +1058,7 @@ void AuxiliaryPanel::update_all_panel()
{
std::map<std::string, std::vector<fs::path>>::iterator mit;
Freeze();
m_pictures_panel->clear();
m_bill_of_materials_panel->clear();
m_assembly_panel->clear();
@ -955,6 +1070,7 @@ void AuxiliaryPanel::update_all_panel()
if (mit->first == "Assembly Guide") { m_assembly_panel->update(mit->second); }
if (mit->first == "Others") { m_others_panel->update(mit->second); }
}
Thaw();
}
void AuxiliaryPanel::update_all_cover()
@ -978,7 +1094,7 @@ void AuxiliaryPanel::update_all_cover()
wxBoxSizer *m_sizer_body = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *m_sizer_designer = new wxBoxSizer(wxHORIZONTAL);
auto m_text_designer = new wxStaticText(this, wxID_ANY, _L("Designer"), wxDefaultPosition, wxSize(120, -1), 0);
auto m_text_designer = new wxStaticText(this, wxID_ANY, _L("Author"), wxDefaultPosition, wxSize(120, -1), 0);
m_text_designer->Wrap(-1);
m_sizer_designer->Add(m_text_designer, 0, wxALIGN_CENTER, 0);