Files
OrcaSlicer/src/slic3r/GUI/CloneDialog.cpp
T
HanifKoh 4895bc03b4 Remove Unused Project Includes and Forward-Declare Where a Type Is Only Referenced (#16099)
* Remove Unused Project Includes and Forward-Declare Where a Type Is Only Referenced

Generated with include-what-you-use and applied conservatively. Only OrcaSlicer's own headers, the ones under src/ and tests/, are removed or forward-declared; standard-library and third-party includes are left alone. An include is removed only when both the Release and the Debug configuration leave it unused, never from inside a conditional block, and never from a file with platform-specific blocks, which only gain includes. Files whose only use of a header sits behind a feature or debug macro (libvgcode's OpenGL ES and marker code, the ARACHNE/TESTS_EXPORT_SVGS debug output) keep their includes.

clonable_ptr.hpp gains #pragma once; it had no include guard and was only safe while Config.hpp was its sole includer.

* Remove Unused Project Includes From Files With Platform-Specific Code

A Linux include-what-you-use run cannot see the code inside _WIN32, __APPLE__ or __linux__ blocks, so its verdict is only taken where nothing the removed header declares, directly or through what it includes, is named inside those blocks. Removals also have to hold in both the Release and Debug configuration and never touch a line inside a conditional block.

* Restore the libslic3r Precompiled Header and Direct Includes Lost in the Platform Pass

The platform-file pass treated pchheader.hpp as an ordinary header and
emptied it, and left GUI_Preview.hpp and 14 other files relying on
headers they no longer reached directly.

* Restore MainFrame.hpp in ParamsDialog.cpp for the Windows-Only Reparent Call

* Include Headers That Files Reached Through Ones the Cleanup Removed

* Drop Includes Duplicated by the Cleanup or by Main's Own Additions

* Leave PreciseSeam.cpp as Main Has It After the Precise Seam Rework
2026-10-05 16:47:17 +08:00

165 lines
5.7 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 "slic3r/GUI/Selection.hpp"
#include <wx/utils.h>
#include "slic3r/GUI/Jobs/Job.hpp"
#include "libslic3r/AppConfig.hpp"
#include "slic3r/GUI/GLCanvas3D.hpp"
#include "slic3r/GUI/I18N.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 copies"));
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();
Selection& sel = m_plater->canvas3D()->get_selection();
m_plater->take_snapshot(std::string("Selection-clone"));
m_plater->Freeze(); // Better to stop rendering canvas while processing
sel.copy_to_clipboard();
for (int i = 0; i < m_count; i++) { // same method with Selection::clone()
m_progress->SetValue(static_cast<int>(static_cast<double>(i) / m_count * 100)); // pass 0 / 100
sel.paste_from_clipboard();
if (m_cancel_process) {
m_plater->undo();
return;
}
wxYield(); // Allow event loop to process updates
}
if (!m_cancel_process) {
if (m_arrange_cb->GetValue()) {
m_plater->set_prepare_state(Job::PREPARE_STATE_MENU);
m_plater->arrange();
}
m_plater->Thaw();
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