mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 08:47:52 -06:00
Cancellation of parameter page build process.
This commit is contained in:
parent
ec8602f8d9
commit
b15023dfa9
4 changed files with 116 additions and 64 deletions
|
@ -362,11 +362,12 @@ void OptionsGroup::activate_line(Line& line)
|
||||||
}
|
}
|
||||||
|
|
||||||
// create all controls for the option group from the m_lines
|
// create all controls for the option group from the m_lines
|
||||||
bool OptionsGroup::activate()
|
bool OptionsGroup::activate(std::function<void()> throw_if_canceled)
|
||||||
{
|
{
|
||||||
if (sizer)//(!sizer->IsEmpty())
|
if (sizer)//(!sizer->IsEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
try {
|
||||||
if (staticbox) {
|
if (staticbox) {
|
||||||
stb = new wxStaticBox(m_parent, wxID_ANY, _(title));
|
stb = new wxStaticBox(m_parent, wxID_ANY, _(title));
|
||||||
if (!wxOSX) stb->SetBackgroundStyle(wxBG_STYLE_PAINT);
|
if (!wxOSX) stb->SetBackgroundStyle(wxBG_STYLE_PAINT);
|
||||||
|
@ -396,8 +397,17 @@ bool OptionsGroup::activate()
|
||||||
sizer->Add(m_grid_sizer, 0, wxEXPAND | wxALL, wxOSX || !staticbox ? 0 : 5);
|
sizer->Add(m_grid_sizer, 0, wxEXPAND | wxALL, wxOSX || !staticbox ? 0 : 5);
|
||||||
|
|
||||||
// activate lines
|
// activate lines
|
||||||
for (Line& line: m_lines)
|
for (Line& line: m_lines) {
|
||||||
|
throw_if_canceled();
|
||||||
activate_line(line);
|
activate_line(line);
|
||||||
|
}
|
||||||
|
} catch (UIBuildCanceled&) {
|
||||||
|
auto p = sizer;
|
||||||
|
this->clear();
|
||||||
|
p->Clear(true);
|
||||||
|
delete p;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
|
|
||||||
namespace Slic3r { namespace GUI {
|
namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
|
// Thrown if the building of a parameter page is canceled.
|
||||||
|
class UIBuildCanceled : public std::exception {};
|
||||||
|
|
||||||
/// Widget type describes a function object that returns a wxWindow (our widget) and accepts a wxWidget (parent window).
|
/// Widget type describes a function object that returns a wxWindow (our widget) and accepts a wxWidget (parent window).
|
||||||
using widget_t = std::function<wxSizer*(wxWindow*)>;//!std::function<wxWindow*(wxWindow*)>;
|
using widget_t = std::function<wxSizer*(wxWindow*)>;//!std::function<wxWindow*(wxWindow*)>;
|
||||||
|
|
||||||
|
@ -124,7 +127,7 @@ public:
|
||||||
void activate_line(Line& line);
|
void activate_line(Line& line);
|
||||||
|
|
||||||
// create all controls for the option group from the m_lines
|
// create all controls for the option group from the m_lines
|
||||||
bool activate();
|
bool activate(std::function<void()> throw_if_canceled = [](){});
|
||||||
// delete all controls from the option group
|
// delete all controls from the option group
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
|
|
@ -297,15 +297,28 @@ void Tab::create_preset_tab()
|
||||||
// This helps to process all the cursor key events on Windows in the tree control,
|
// This helps to process all the cursor key events on Windows in the tree control,
|
||||||
// so that the cursor jumps to the last item.
|
// so that the cursor jumps to the last item.
|
||||||
m_treectrl->Bind(wxEVT_TREE_SEL_CHANGED, [this](wxTreeEvent&) {
|
m_treectrl->Bind(wxEVT_TREE_SEL_CHANGED, [this](wxTreeEvent&) {
|
||||||
if (!m_disable_tree_sel_changed_event && !m_pages.empty())
|
if (!m_disable_tree_sel_changed_event && !m_pages.empty()) {
|
||||||
|
if (m_page_switch_running)
|
||||||
m_page_switch_planned = true;
|
m_page_switch_planned = true;
|
||||||
|
else {
|
||||||
|
m_page_switch_running = true;
|
||||||
|
do {
|
||||||
|
m_page_switch_planned = false;
|
||||||
|
} while (this->tree_sel_change_delayed());
|
||||||
|
m_page_switch_running = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_treectrl->Update();
|
||||||
});
|
});
|
||||||
|
#if 0
|
||||||
m_treectrl->Bind(wxEVT_IDLE, [this](wxIdleEvent&) {
|
m_treectrl->Bind(wxEVT_IDLE, [this](wxIdleEvent&) {
|
||||||
if (m_page_switch_planned) {
|
if (m_page_switch_planned) {
|
||||||
this->tree_sel_change_delayed();
|
do {
|
||||||
m_page_switch_planned = false;
|
m_page_switch_planned = false;
|
||||||
|
} while (this->tree_sel_change_delayed());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
#endif
|
||||||
|
|
||||||
m_treectrl->Bind(wxEVT_KEY_DOWN, &Tab::OnKeyDown, this);
|
m_treectrl->Bind(wxEVT_KEY_DOWN, &Tab::OnKeyDown, this);
|
||||||
|
|
||||||
|
@ -424,7 +437,7 @@ void Tab::OnActivate()
|
||||||
#endif // __WXOSX__
|
#endif // __WXOSX__
|
||||||
|
|
||||||
// create controls on active page
|
// create controls on active page
|
||||||
active_selected_page();
|
activate_selected_page();
|
||||||
// m_active_page->Show();
|
// m_active_page->Show();
|
||||||
m_hsizer->Layout();
|
m_hsizer->Layout();
|
||||||
Refresh();
|
Refresh();
|
||||||
|
@ -2820,9 +2833,9 @@ void TabPrinter::update_pages()
|
||||||
rebuild_page_tree();
|
rebuild_page_tree();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabPrinter::active_selected_page()
|
void TabPrinter::activate_selected_page(std::function<void()> throw_if_canceled)
|
||||||
{
|
{
|
||||||
Tab::active_selected_page();
|
Tab::activate_selected_page(throw_if_canceled);
|
||||||
|
|
||||||
// "extruders_count" doesn't update from the update_config(),
|
// "extruders_count" doesn't update from the update_config(),
|
||||||
// so update it implicitly
|
// so update it implicitly
|
||||||
|
@ -3372,19 +3385,20 @@ void Tab::update_description_lines()
|
||||||
update_preset_description_line();
|
update_preset_description_line();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tab::active_selected_page()
|
void Tab::activate_selected_page(std::function<void()> throw_if_canceled)
|
||||||
{
|
{
|
||||||
if (!m_active_page)
|
if (!m_active_page)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_active_page->activate(m_mode);
|
m_active_page->activate(m_mode, throw_if_canceled);
|
||||||
update_changed_ui();
|
update_changed_ui();
|
||||||
update_description_lines();
|
update_description_lines();
|
||||||
toggle_options();
|
toggle_options();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tab::tree_sel_change_delayed()
|
bool Tab::tree_sel_change_delayed()
|
||||||
{
|
{
|
||||||
|
#if 1
|
||||||
// There is a bug related to Ubuntu overlay scrollbars, see https://github.com/prusa3d/PrusaSlicer/issues/898 and https://github.com/prusa3d/PrusaSlicer/issues/952.
|
// There is a bug related to Ubuntu overlay scrollbars, see https://github.com/prusa3d/PrusaSlicer/issues/898 and https://github.com/prusa3d/PrusaSlicer/issues/952.
|
||||||
// The issue apparently manifests when Show()ing a window with overlay scrollbars while the UI is frozen. For this reason,
|
// The issue apparently manifests when Show()ing a window with overlay scrollbars while the UI is frozen. For this reason,
|
||||||
// we will Thaw the UI prematurely on Linux. This means destroing the no_updates object prematurely.
|
// we will Thaw the UI prematurely on Linux. This means destroing the no_updates object prematurely.
|
||||||
|
@ -3398,6 +3412,7 @@ void Tab::tree_sel_change_delayed()
|
||||||
//#ifdef __WXOSX__ // Use Freeze/Thaw to avoid flickering during clear/activate new page
|
//#ifdef __WXOSX__ // Use Freeze/Thaw to avoid flickering during clear/activate new page
|
||||||
wxWindowUpdateLocker noUpdates(this);
|
wxWindowUpdateLocker noUpdates(this);
|
||||||
//#endif
|
//#endif
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Page* page = nullptr;
|
Page* page = nullptr;
|
||||||
|
@ -3411,18 +3426,30 @@ void Tab::tree_sel_change_delayed()
|
||||||
m_is_modified_values = page->m_is_modified_values;
|
m_is_modified_values = page->m_is_modified_values;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (page == nullptr || m_active_page == page) return;
|
if (page == nullptr || m_active_page == page)
|
||||||
|
return false;
|
||||||
|
|
||||||
// clear pages from the controls
|
// clear pages from the controls
|
||||||
m_active_page = page;
|
m_active_page = page;
|
||||||
|
|
||||||
|
auto throw_if_canceled = std::function<void()>([this](){
|
||||||
|
#ifdef WIN32
|
||||||
|
wxCheckForInterrupt(m_treectrl);
|
||||||
|
if (m_page_switch_planned)
|
||||||
|
throw UIBuildCanceled();
|
||||||
|
#endif // WIN32
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
clear_pages();
|
clear_pages();
|
||||||
|
throw_if_canceled();
|
||||||
|
|
||||||
//for (auto& el : m_pages)
|
//for (auto& el : m_pages)
|
||||||
// el.get()->Hide();
|
// el.get()->Hide();
|
||||||
|
|
||||||
if (wxGetApp().mainframe->is_active_and_shown_tab(this)) {
|
if (wxGetApp().mainframe->is_active_and_shown_tab(this)) {
|
||||||
active_selected_page();
|
activate_selected_page(throw_if_canceled);
|
||||||
// m_active_page->Show();
|
// m_active_page->Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
@ -3430,10 +3457,19 @@ void Tab::tree_sel_change_delayed()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
update_undo_buttons();
|
update_undo_buttons();
|
||||||
|
throw_if_canceled();
|
||||||
|
|
||||||
// m_active_page->Show();
|
// m_active_page->Show();
|
||||||
m_hsizer->Layout();
|
m_hsizer->Layout();
|
||||||
|
throw_if_canceled();
|
||||||
Refresh();
|
Refresh();
|
||||||
|
} catch (const UIBuildCanceled&) {
|
||||||
|
if (m_active_page)
|
||||||
|
m_active_page->clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tab::OnKeyDown(wxKeyEvent& event)
|
void Tab::OnKeyDown(wxKeyEvent& event)
|
||||||
|
@ -3892,16 +3928,17 @@ void Page::update_visibility(ConfigOptionMode mode, bool update_contolls_visibil
|
||||||
m_show = ret_val;
|
m_show = ret_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Page::activate(ConfigOptionMode mode)
|
void Page::activate(ConfigOptionMode mode, std::function<void()> throw_if_canceled)
|
||||||
{
|
{
|
||||||
//if (m_parent)
|
//if (m_parent)
|
||||||
//m_parent->SetSizer(m_vsizer);
|
//m_parent->SetSizer(m_vsizer);
|
||||||
for (auto group : m_optgroups) {
|
for (auto group : m_optgroups) {
|
||||||
if (!group->activate())
|
if (!group->activate(throw_if_canceled))
|
||||||
continue;
|
continue;
|
||||||
m_vsizer->Add(group->sizer, 0, wxEXPAND | wxALL, 10);
|
m_vsizer->Add(group->sizer, 0, wxEXPAND | wxALL, 10);
|
||||||
group->update_visibility(mode);
|
group->update_visibility(mode);
|
||||||
group->reload_config();
|
group->reload_config();
|
||||||
|
throw_if_canceled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ public:
|
||||||
void set_config(DynamicPrintConfig* config_in) { m_config = config_in; }
|
void set_config(DynamicPrintConfig* config_in) { m_config = config_in; }
|
||||||
void reload_config();
|
void reload_config();
|
||||||
void update_visibility(ConfigOptionMode mode, bool update_contolls_visibility);
|
void update_visibility(ConfigOptionMode mode, bool update_contolls_visibility);
|
||||||
void activate(ConfigOptionMode mode);
|
void activate(ConfigOptionMode mode, std::function<void()> throw_if_canceled);
|
||||||
void clear();
|
void clear();
|
||||||
void msw_rescale();
|
void msw_rescale();
|
||||||
void sys_color_changed();
|
void sys_color_changed();
|
||||||
|
@ -239,6 +239,7 @@ protected:
|
||||||
DynamicPrintConfig m_cache_config;
|
DynamicPrintConfig m_cache_config;
|
||||||
|
|
||||||
|
|
||||||
|
bool m_page_switch_running = false;
|
||||||
bool m_page_switch_planned = false;
|
bool m_page_switch_planned = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -294,7 +295,7 @@ public:
|
||||||
|
|
||||||
virtual void clear_pages();
|
virtual void clear_pages();
|
||||||
virtual void update_description_lines();
|
virtual void update_description_lines();
|
||||||
virtual void active_selected_page();
|
virtual void activate_selected_page(std::function<void()> throw_if_canceled);
|
||||||
|
|
||||||
void OnTreeSelChange(wxTreeEvent& event);
|
void OnTreeSelChange(wxTreeEvent& event);
|
||||||
void OnKeyDown(wxKeyEvent& event);
|
void OnKeyDown(wxKeyEvent& event);
|
||||||
|
@ -354,7 +355,8 @@ protected:
|
||||||
void compatible_widget_reload(PresetDependencies &deps);
|
void compatible_widget_reload(PresetDependencies &deps);
|
||||||
void load_key_value(const std::string& opt_key, const boost::any& value, bool saved_value = false);
|
void load_key_value(const std::string& opt_key, const boost::any& value, bool saved_value = false);
|
||||||
|
|
||||||
void tree_sel_change_delayed();
|
// return true if cancelled
|
||||||
|
bool tree_sel_change_delayed();
|
||||||
void on_presets_changed();
|
void on_presets_changed();
|
||||||
void build_preset_description_line(ConfigOptionsGroup* optgroup);
|
void build_preset_description_line(ConfigOptionsGroup* optgroup);
|
||||||
void update_preset_description_line();
|
void update_preset_description_line();
|
||||||
|
@ -447,7 +449,7 @@ public:
|
||||||
void build() override;
|
void build() override;
|
||||||
void build_fff();
|
void build_fff();
|
||||||
void build_sla();
|
void build_sla();
|
||||||
void active_selected_page() override;
|
void activate_selected_page(std::function<void()> throw_if_canceled) override;
|
||||||
void clear_pages() override;
|
void clear_pages() override;
|
||||||
void toggle_options() override;
|
void toggle_options() override;
|
||||||
void update() override;
|
void update() override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue