Autoslice + SliceDelay (#11407)

* Add auto slice after changes option

Introduces a new 'Auto slice after changes' setting in Preferences, allowing OrcaSlicer to automatically re-slice when slicing-related settings change. Implements logic in Plater to schedule auto-reslicing if the option is enabled and conditions are met, and sets the default to false in AppConfig.

* Improve auto-reslice scheduling after slice cancellation

Adds a flag to track when auto-reslice should be triggered after a slicing process is cancelled. Ensures that auto-reslice is scheduled once the current slicing process completes and is not lost if a slice is cancelled mid-operation.

* Add configurable delay for auto slice after change

Introduces a new 'auto_slice_change_delay_seconds' setting to control the delay before auto slicing starts after a change. Updates AppConfig to set a default value, adds a timer and logic in Plater to handle the delay, and exposes the setting in Preferences. This allows users to group multiple edits before triggering auto slicing.

* Combine auto-reslice checkbox and delay input in preferences

Replaces separate auto-reslice and delay settings with a unified UI element in Preferences. The new function create_item_auto_reslice adds both the checkbox and delay input in a single row, improving usability and code organization.

* Move auto reslice option into Control > Behaviour

* Remove 'loop' icon from AutoSlice

* Default disable and 1 Sec
This commit is contained in:
Ian Bassi
2025-12-18 09:44:31 -03:00
committed by GitHub
parent 2be0f0e05e
commit d092d6d9a7
4 changed files with 187 additions and 2 deletions

View File

@@ -677,6 +677,74 @@ wxBoxSizer *PreferencesDialog::create_item_backup(wxString title, wxString toolt
return m_sizer_input;
}
wxBoxSizer *PreferencesDialog::create_item_auto_reslice(wxString title, wxString checkbox_tooltip, wxString delay_tooltip)
{
wxBoxSizer *sizer_row = new wxBoxSizer(wxHORIZONTAL);
sizer_row->AddSpacer(FromDIP(DESIGN_LEFT_MARGIN));
auto checkbox_title = new wxStaticText(m_parent, wxID_ANY, title, wxDefaultPosition, DESIGN_TITLE_SIZE, wxST_NO_AUTORESIZE);
checkbox_title->SetForegroundColour(DESIGN_GRAY900_COLOR);
checkbox_title->SetFont(::Label::Body_14);
checkbox_title->Wrap(DESIGN_TITLE_SIZE.x);
checkbox_title->SetToolTip(checkbox_tooltip);
auto checkbox = new ::CheckBox(m_parent);
checkbox->SetValue(app_config->get_bool("auto_slice_after_change"));
checkbox->SetToolTip(checkbox_tooltip);
wxString delay_value = app_config->get("auto_slice_change_delay_seconds");
if (delay_value.empty())
delay_value = "0";
auto input = new ::TextInput(m_parent, wxEmptyString, _L("sec"), wxEmptyString, wxDefaultPosition, wxSize(FromDIP(97), -1), wxTE_PROCESS_ENTER);
StateColor input_bg(std::pair<wxColour, int>(wxColour("#F0F0F1"), StateColor::Disabled), std::pair<wxColour, int>(*wxWHITE, StateColor::Enabled));
input->SetBackgroundColor(input_bg);
input->GetTextCtrl()->SetValue(delay_value);
wxTextValidator validator(wxFILTER_DIGITS);
input->SetToolTip(delay_tooltip);
input->GetTextCtrl()->SetValidator(validator);
sizer_row->Add(checkbox_title, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, FromDIP(3));
sizer_row->Add(checkbox, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, FromDIP(5));
sizer_row->Add(input, 0, wxALIGN_CENTER_VERTICAL);
auto commit_delay = [this, input]() {
wxString value = input->GetTextCtrl()->GetValue();
long seconds = 0;
if (!value.ToLong(&seconds) || seconds < 0)
seconds = 0;
wxString sanitized = wxString::Format("%ld", seconds);
input->GetTextCtrl()->SetValue(sanitized);
app_config->set("auto_slice_change_delay_seconds", std::string(sanitized.mb_str()));
app_config->save();
};
input->GetTextCtrl()->Bind(wxEVT_TEXT_ENTER, [commit_delay](wxCommandEvent &e) {
commit_delay();
e.Skip();
});
input->GetTextCtrl()->Bind(wxEVT_KILL_FOCUS, [commit_delay](wxFocusEvent &e) {
commit_delay();
e.Skip();
});
checkbox->Bind(wxEVT_TOGGLEBUTTON, [this, checkbox, input](wxCommandEvent &e) {
const bool enabled = checkbox->GetValue();
app_config->set_bool("auto_slice_after_change", enabled);
app_config->save();
input->Enable(enabled);
input->Refresh();
e.Skip();
});
input->Enable(checkbox->GetValue());
input->Refresh();
return sizer_row;
}
wxBoxSizer* PreferencesDialog::create_item_darkmode(wxString title,wxString tooltip, std::string param)
{
wxBoxSizer* m_sizer_checkbox = new wxBoxSizer(wxHORIZONTAL);
@@ -1256,6 +1324,12 @@ void PreferencesDialog::create_items()
auto item_auto_arrange = create_item_checkbox(_L("Auto arrange plate after cloning"), "", "auto_arrange");
g_sizer->Add(item_auto_arrange);
auto item_auto_reslice = create_item_auto_reslice(
_L("Auto slice after changes"),
_L("If enabled, OrcaSlicer will re-slice automatically whenever slicing-related settings change."),
_L("Delay in seconds before auto slicing starts, allowing multiple edits to be grouped. Use 0 to slice immediately."));
g_sizer->Add(item_auto_reslice);
//// CONTROL > Camera
g_sizer->Add(create_item_title(_L("Camera")), 1, wxEXPAND);