From e6c361ec5e5053b1a19db5d3f823d2cc6d7b1715 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 20 Jul 2021 11:23:16 +0200 Subject: [PATCH] Added "Modify Shapes Gallery" to the "Window" menu + Fixed a non-MSW build (added missed include) --- src/slic3r/GUI/GUI.cpp | 1 + src/slic3r/GUI/GUI_ObjectList.cpp | 12 ++++++++---- src/slic3r/GUI/GUI_ObjectList.hpp | 1 + src/slic3r/GUI/GalleryDialog.cpp | 10 +++++++--- src/slic3r/GUI/GalleryDialog.hpp | 2 +- src/slic3r/GUI/MainFrame.cpp | 14 ++++++++++++++ 6 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/GUI.cpp b/src/slic3r/GUI/GUI.cpp index 50b28d85b..40c1d5267 100644 --- a/src/slic3r/GUI/GUI.cpp +++ b/src/slic3r/GUI/GUI.cpp @@ -1,5 +1,6 @@ #include "GUI.hpp" #include "GUI_App.hpp" +#include "format.hpp" #include "I18N.hpp" #include "libslic3r/LocalesUtils.hpp" diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 5103e18bb..a013b8dd2 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -1413,7 +1413,7 @@ void ObjectList::load_part(ModelObject& model_object, std::vector& if (from_galery) { GalleryDialog dlg(this); - if (dlg.ShowModal() == wxID_CANCEL) + if (dlg.ShowModal() == wxID_CLOSE) return; dlg.get_input_files(input_files); if (input_files.IsEmpty()) @@ -1472,7 +1472,7 @@ void ObjectList::load_modifier(ModelObject& model_object, std::vector paths; for (const auto& file : input_files) paths.push_back(into_path(file)); assert(!paths.empty()); - wxString snapshot_label = (paths.size() == 1 ? _L("Add Shape") : _L("Add Shapes")) + ": " + + wxString snapshot_label = (paths.size() == 1 ? _L("Add Shape from Gallery") : _L("Add Shapes from Gallery")) + ": " + wxString::FromUTF8(paths.front().filename().string().c_str()); for (size_t i = 1; i < paths.size(); ++i) snapshot_label += ", " + wxString::FromUTF8(paths[i].filename().string().c_str()); diff --git a/src/slic3r/GUI/GUI_ObjectList.hpp b/src/slic3r/GUI/GUI_ObjectList.hpp index 4bfe3e9ff..cc34e348a 100644 --- a/src/slic3r/GUI/GUI_ObjectList.hpp +++ b/src/slic3r/GUI/GUI_ObjectList.hpp @@ -245,6 +245,7 @@ public: void load_generic_subobject(const std::string& type_name, const ModelVolumeType type); void load_shape_object(const std::string &type_name); void load_shape_object_from_gallery(); + void load_shape_object_from_gallery(const wxArrayString& input_files); void load_mesh_object(const TriangleMesh &mesh, const wxString &name, bool center = true); void del_object(const int obj_idx); void del_subobject_item(wxDataViewItem& item); diff --git a/src/slic3r/GUI/GalleryDialog.cpp b/src/slic3r/GUI/GalleryDialog.cpp index 163e33527..6bdbedcb3 100644 --- a/src/slic3r/GUI/GalleryDialog.cpp +++ b/src/slic3r/GUI/GalleryDialog.cpp @@ -64,7 +64,7 @@ bool GalleryDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& f } -GalleryDialog::GalleryDialog(wxWindow* parent) : +GalleryDialog::GalleryDialog(wxWindow* parent, bool modify_gallery/* = false*/) : DPIDialog(parent, wxID_ANY, _L("Shapes Gallery"), wxDefaultPosition, wxSize(45 * wxGetApp().em_unit(), -1), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) { #ifndef _WIN32 @@ -90,9 +90,13 @@ GalleryDialog::GalleryDialog(wxWindow* parent) : }); #endif - wxStdDialogButtonSizer* buttons = this->CreateStdDialogButtonSizer(wxOK | wxCANCEL); + wxStdDialogButtonSizer* buttons = this->CreateStdDialogButtonSizer(wxOK | wxCLOSE); wxButton* ok_btn = static_cast(FindWindowById(wxID_OK, this)); ok_btn->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(!m_selected_items.empty()); }); + if (modify_gallery) { + ok_btn->SetLabel(_L("Add to bed")); + ok_btn->SetToolTip(_L("Add selected shape(s) to the bed")); + } auto add_btn = [this, buttons]( size_t pos, int& ID, wxString title, wxString tooltip, void (GalleryDialog::* method)(wxEvent&), @@ -144,7 +148,7 @@ void GalleryDialog::on_dpi_changed(const wxRect& suggested_rect) { const int& em = em_unit(); - msw_buttons_rescale(this, em, { ID_BTN_ADD_CUSTOM_SHAPE, ID_BTN_DEL_CUSTOM_SHAPE, ID_BTN_REPLACE_CUSTOM_PNG, wxID_OK, wxID_CANCEL }); + msw_buttons_rescale(this, em, { ID_BTN_ADD_CUSTOM_SHAPE, ID_BTN_DEL_CUSTOM_SHAPE, ID_BTN_REPLACE_CUSTOM_PNG, wxID_OK, wxID_CLOSE }); wxSize size = wxSize(55 * em, 35 * em); m_list_ctrl->SetMinSize(size); diff --git a/src/slic3r/GUI/GalleryDialog.hpp b/src/slic3r/GUI/GalleryDialog.hpp index de120512f..8cf3f0096 100644 --- a/src/slic3r/GUI/GalleryDialog.hpp +++ b/src/slic3r/GUI/GalleryDialog.hpp @@ -41,7 +41,7 @@ class GalleryDialog : public DPIDialog void update(); public: - GalleryDialog(wxWindow* parent); + GalleryDialog(wxWindow* parent, bool modify_gallery = false); ~GalleryDialog(); void get_input_files(wxArrayString& input_files); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 561a03f44..6631e4df7 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -43,6 +43,8 @@ #include "MsgDialog.hpp" #include "Notebook.hpp" #include "GUI_Factories.hpp" +#include "GUI_ObjectList.hpp" +#include "GalleryDialog.hpp" #ifdef _WIN32 #include @@ -1394,6 +1396,18 @@ void MainFrame::init_menubar_as_editor() [this](){return can_change_view(); }, this); } + windowMenu->AppendSeparator(); + append_menu_item(windowMenu, wxID_ANY, _L("Modify Shapes Gallery") + "\tCtrl+G", _L("Open the dialog to modify shapes gallery"), + [this](wxCommandEvent&) { + GalleryDialog dlg(this, true); + if (dlg.ShowModal() == wxID_OK) { + wxArrayString input_files; + dlg.get_input_files(input_files); + if (!input_files.IsEmpty()) + m_plater->sidebar().obj_list()->load_shape_object_from_gallery(input_files); + } + }, "cog", nullptr, []() {return true; }, this); + windowMenu->AppendSeparator(); append_menu_item(windowMenu, wxID_ANY, _L("Print &Host Upload Queue") + "\tCtrl+J", _L("Display the Print Host Upload Queue window"), [this](wxCommandEvent&) { m_printhost_queue_dlg->Show(); }, "upload_queue", nullptr, []() {return true; }, this);