mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-27 15:49:52 -05:00
Outside the Design tab an agent had 175 commands, 50 of them in the tool list. There are now 118, named by what they act on (`object_`, `plate_`, `preset_`, `filament_`, `plugin_` and so on), and 115 are listed. Each takes its target and values in the call, acts on the selection when it names no target and says what it acted on; an old name is refused. Printers and system filaments install and uninstall, preferences read and write, plugins enable, reload, uninstall and refresh, and objects reorder, with no dialog to drive. The Speed Dial keeps its 129 tiles under the same ids. Eight defects in the rows these commands share with the menus are fixed. For a person: an object row that cannot run says why instead of "Select an object first.", rows that failed no longer claim success, Duplicate Plate can be undone, and Refresh Plugins picked while a refresh runs now runs after it instead of beside it.
152 lines
5.5 KiB
C++
152 lines
5.5 KiB
C++
#include "CloneDialog.hpp"
|
|
|
|
#include "GUI_App.hpp"
|
|
#include "MainFrame.hpp"
|
|
#include "slic3r/GUI/GUI_Utils.hpp"
|
|
#include <wx/event.h>
|
|
#include <wx/gdicmn.h>
|
|
#include <wx/toplevel.h>
|
|
#include "slic3r/GUI/Widgets/Label.hpp"
|
|
#include <wx/sizer.h>
|
|
#include "slic3r/GUI/Widgets/SpinInput.hpp"
|
|
#include <wx/string.h>
|
|
#include "slic3r/GUI/Widgets/CheckBox.hpp"
|
|
#include "slic3r/GUI/Widgets/ProgressBar.hpp"
|
|
#include "slic3r/GUI/Widgets/StateColor.hpp"
|
|
#include <wx/colour.h>
|
|
#include "slic3r/GUI/Widgets/DialogButtons.hpp"
|
|
#include "slic3r/GUI/Widgets/Button.hpp"
|
|
#include <wx/utils.h>
|
|
#include "libslic3r/AppConfig.hpp"
|
|
#include "slic3r/GUI/I18N.hpp"
|
|
#include "slic3r/GUI/Operations/ObjectOps.hpp"
|
|
#include "slic3r/GUI/Operations/Outcome.hpp"
|
|
#include "slic3r/GUI/Plater.hpp"
|
|
|
|
class wxWindow;
|
|
|
|
namespace Slic3r { namespace GUI {
|
|
|
|
CloneDialog::CloneDialog(wxWindow *parent)
|
|
: DPIDialog(parent ? parent : static_cast<wxWindow *>(wxGetApp().mainframe), wxID_ANY, _L("Clone"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
|
|
{
|
|
SetBackgroundColour(*wxWHITE);
|
|
SetFont(Label::Body_14);
|
|
|
|
m_plater = wxGetApp().plater();
|
|
m_config = wxGetApp().app_config;
|
|
m_cancel_process = false;
|
|
|
|
auto v_sizer = new wxBoxSizer(wxVERTICAL);
|
|
auto f_sizer = new wxFlexGridSizer(2, 2, FromDIP(4), FromDIP(20));
|
|
|
|
auto count_label = new wxStaticText(this, wxID_ANY, _L("Number of copies:"), wxDefaultPosition, wxDefaultSize, 0);
|
|
m_count_spin = new SpinInput(this, wxEmptyString, "", wxDefaultPosition, wxSize(FromDIP(120), -1), wxSP_ARROW_KEYS, 1, 1000, 1);
|
|
m_count_spin->GetTextCtrl()->SetFocus();
|
|
m_count_spin->Bind(wxEVT_KILL_FOCUS, [this](wxFocusEvent &e) {
|
|
e.SetId(GetId());
|
|
ProcessEventLocally(e);
|
|
e.Skip();
|
|
});
|
|
f_sizer->Add(count_label , 0, wxEXPAND | wxALIGN_CENTER_VERTICAL);
|
|
f_sizer->Add(m_count_spin, 0, wxALIGN_CENTER_VERTICAL);
|
|
|
|
auto arrange_label = new wxStaticText(this, wxID_ANY, _L("Auto arrange plate after cloning") + ":", wxDefaultPosition, wxDefaultSize, 0);
|
|
arrange_label->Wrap(FromDIP(300));
|
|
m_arrange_cb = new ::CheckBox(this);
|
|
m_arrange_cb->SetValue(m_config->get("auto_arrange") == "true");
|
|
|
|
f_sizer->Add(arrange_label, 0, wxEXPAND | wxALIGN_CENTER_VERTICAL);
|
|
f_sizer->Add(m_arrange_cb , 0, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM, FromDIP(5));
|
|
|
|
v_sizer->Add(f_sizer, 1, wxEXPAND | wxALL, FromDIP(10));
|
|
|
|
auto bottom_sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
m_progress = new ProgressBar(this, wxID_ANY, 100);
|
|
m_progress->SetHeight(FromDIP(8));
|
|
m_progress->SetMaxSize(wxSize(-1, FromDIP(8)));
|
|
m_progress->SetProgressForedColour(StateColor::darkModeColorFor(wxColour("#DFDFDF")));
|
|
m_progress->SetDoubleBuffered(true);
|
|
m_progress->Hide();
|
|
bottom_sizer->Add(m_progress, 2, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(10));
|
|
|
|
auto dlg_btns = new DialogButtons(this, {"Fill", "OK", "Cancel"}, "", 1 /*left_aligned*/);
|
|
|
|
// Keep pointer to OK button so we can trigger it manually on Enter.
|
|
Button *ok_btn = dlg_btns->GetOK();
|
|
|
|
dlg_btns->GetFIRST()->SetToolTip(_L("Fill bed with instances"));
|
|
dlg_btns->GetFIRST()->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) {
|
|
m_plater->fill_bed_with_instances();
|
|
EndModal(wxID_OK);
|
|
});
|
|
|
|
dlg_btns->GetOK()->Bind(wxEVT_BUTTON, [this, dlg_btns, v_sizer](wxCommandEvent &e) {
|
|
|
|
m_count_spin->Disable(); // also ensures input box value applied with wxEVT_KILL_FOCUS
|
|
m_arrange_cb->Disable();
|
|
|
|
m_count = m_count_spin->GetValue();
|
|
|
|
m_progress->Show();
|
|
|
|
dlg_btns->GetOK()->Hide();
|
|
dlg_btns->GetFIRST()->Hide();
|
|
|
|
this->Layout();
|
|
v_sizer->Fit(this);
|
|
Refresh();
|
|
|
|
// The selection's copies, the progress bar showing each; Cancel, which ends the dialog, undoes them.
|
|
Ops::CloneObjectsArgs clone;
|
|
clone.targets.from_selection = true;
|
|
clone.count = m_count;
|
|
clone.arrange = m_arrange_cb->GetValue();
|
|
const auto pasted = [this](int done, int count) {
|
|
m_progress->SetValue(static_cast<int>(static_cast<double>(done - 1) / count * 100)); // pass 0 / 100
|
|
wxYield(); // Allow event loop to process updates
|
|
return !m_cancel_process;
|
|
};
|
|
if (Ops::clone_objects(clone, pasted))
|
|
EndModal(wxID_OK);
|
|
});
|
|
|
|
dlg_btns->GetCANCEL()->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
|
|
m_cancel_process = true;
|
|
if (m_plater->IsFrozen())
|
|
m_plater->Thaw();
|
|
EndModal(wxID_CANCEL);
|
|
});
|
|
|
|
bottom_sizer->Add(dlg_btns, 1, wxEXPAND);
|
|
|
|
v_sizer->Add(bottom_sizer, 0, wxEXPAND);
|
|
|
|
this->SetSizerAndFit(v_sizer);
|
|
this->Layout();
|
|
|
|
wxGetApp().UpdateDlgDarkUI(this);
|
|
|
|
// ------------------ ENTER KEY OVERRIDE ------------------
|
|
// This makes Enter inside the spinbox behave EXACTLY like clicking OK.
|
|
Bind(wxEVT_CHAR_HOOK, [this, ok_btn](wxKeyEvent &e)
|
|
{
|
|
const int key = e.GetKeyCode();
|
|
|
|
if ((key == WXK_RETURN || key == WXK_NUMPAD_ENTER) &&
|
|
m_count_spin->GetTextCtrl()->HasFocus())
|
|
{
|
|
// Trigger OK button's handler manually
|
|
wxCommandEvent evt(wxEVT_BUTTON, ok_btn->GetId());
|
|
ok_btn->GetEventHandler()->ProcessEvent(evt);
|
|
} else {
|
|
// Not handled here, process normally
|
|
e.Skip();
|
|
}
|
|
});
|
|
// --------------------------------------------------------
|
|
}
|
|
|
|
CloneDialog::~CloneDialog() {}
|
|
|
|
}} // namespace Slic3r::GUI
|