More control over "tab/view" automatically switch.

supermerill/SuperSlicer#1338
This commit is contained in:
remi durand 2021-06-26 02:13:15 +02:00
parent ba04b3e75f
commit 37bd6e432d
4 changed files with 79 additions and 20 deletions

View File

@ -165,7 +165,7 @@ void AppConfig::set_defaults()
set("auto_toolbar_size", "100");
if (get("auto_switch_preview").empty())
set("auto_switch_preview", "1");
set("auto_switch_preview", "2");
#if ENABLE_ENVIRONMENT_MAP
if (get("use_environment_map").empty())

View File

@ -3093,14 +3093,23 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool
}
//update tab if needed
if (invalidated != Print::ApplyStatus::APPLY_STATUS_UNCHANGED && wxGetApp().app_config->get("auto_switch_preview") == "1")
// auto_switch_preview == 0 means "no force tab change"
if (invalidated != Print::ApplyStatus::APPLY_STATUS_UNCHANGED && wxGetApp().app_config->get("auto_switch_preview") != "0")
{
if (this->preview->can_display_gcode())
main_frame->select_tab(MainFrame::ETabType::PlaterGcode, true);
else if (this->preview->can_display_volume())
main_frame->select_tab(MainFrame::ETabType::PlaterPreview, true);
else
main_frame->select_tab(MainFrame::ETabType::Plater3D, true);
// auto_switch_preview == 3 means "force tab change only if for gcode"
if(wxGetApp().app_config->get("auto_switch_preview") == "3")
if(this->preview->can_display_gcode())
main_frame->select_tab(MainFrame::ETabType::PlaterGcode, true);
// auto_switch_preview == 1 means "force tab change"
// auto_switch_preview == 2 (the only other one) means "force tab change only if already on a plater one"
else if (wxGetApp().app_config->get("auto_switch_preview") == "1" || main_frame->selected_tab() < MainFrame::ETabType::LastPlater) {
if (this->preview->can_display_gcode())
main_frame->select_tab(MainFrame::ETabType::PlaterGcode, true);
else if (this->preview->can_display_volume())
main_frame->select_tab(MainFrame::ETabType::PlaterPreview, true);
else
main_frame->select_tab(MainFrame::ETabType::Plater3D, true);
}
}
return return_state;
}
@ -3705,8 +3714,13 @@ void Plater::priv::on_slicing_update(SlicingStatusEvent &evt)
void Plater::priv::on_slicing_completed(wxCommandEvent & evt)
{
// auto_switch_preview == 0 means "no force tab change"
// auto_switch_preview == 1 means "force tab change"
// auto_switch_preview == 2 means "force tab change only if already on a plater one"
// auto_switch_preview == 3 means "force tab change only if for gcode"
notification_manager->push_slicing_complete_notification(evt.GetInt(), is_sidebar_collapsed());
if(wxGetApp().app_config->get("auto_switch_preview") == "1" && !this->preview->can_display_gcode())
if( ( wxGetApp().app_config->get("auto_switch_preview") == "1" || (wxGetApp().app_config->get("auto_switch_preview") == "2" && main_frame->selected_tab() < MainFrame::ETabType::LastPlater) )
&& !this->preview->can_display_gcode())
main_frame->select_tab(MainFrame::ETabType::PlaterPreview);
switch (this->printer_technology) {
case ptFFF:
@ -3786,7 +3800,13 @@ void Plater::priv::on_process_completed(SlicingProcessCompletedEvent &evt)
this->background_process.stop();
this->statusbar()->reset_cancel_callback();
this->statusbar()->stop_busy();
if (wxGetApp().app_config->get("auto_switch_preview") == "1")
// auto_switch_preview == 0 means "no force tab change"
// auto_switch_preview == 1 means "force tab change"
// auto_switch_preview == 2 means "force tab change only if already on a plater one"
// auto_switch_preview == 3 means "force tab change only if for gcode"
if (wxGetApp().app_config->get("auto_switch_preview") == "1"
|| (wxGetApp().app_config->get("auto_switch_preview") == "2" && main_frame->selected_tab() < MainFrame::ETabType::LastPlater)
|| wxGetApp().app_config->get("auto_switch_preview") == "3")
main_frame->select_tab(MainFrame::ETabType::PlaterGcode);
// Reset the "export G-code path" name, so that the automatic background processing will be enabled again.

View File

@ -58,7 +58,7 @@ void PreferencesDialog::build()
m_optgroup_general->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
if (opt_key == "default_action_on_close_application" || opt_key == "default_action_on_select_preset")
m_values[opt_key] = boost::any_cast<bool>(value) ? "none" : "discard";
else if (opt_key == "splash_screen_editor" || opt_key == "splash_screen_gcodeviewer")
else if (std::unordered_set<std::string>{ "splash_screen_editor" ,"splash_screen_gcodeviewer" ,"auto_switch_preview" }.count(opt_key) > 0)
m_values[opt_key] = boost::any_cast<std::string>(value);
else
m_values[opt_key] = boost::any_cast<bool>(value) ? "1" : "0";
@ -93,6 +93,30 @@ void PreferencesDialog::build()
option = Option(def, "background_processing");
m_optgroup_general->append_single_option_line(option);
if (is_editor) {
def_combobox_auto_switch_preview.label = L("Switch to Preview when sliced");
def_combobox_auto_switch_preview.type = coStrings;
def_combobox_auto_switch_preview.tooltip = L("Choose an option.");
def_combobox_auto_switch_preview.gui_type = "f_enum_open";
def_combobox_auto_switch_preview.gui_flags = "show_value";
def_combobox_auto_switch_preview.enum_values.push_back(_u8L("Don't switch"));
def_combobox_auto_switch_preview.enum_values.push_back(_u8L("Switch when possible"));
def_combobox_auto_switch_preview.enum_values.push_back(_u8L("Only if on plater"));
def_combobox_auto_switch_preview.enum_values.push_back(_u8L("Only when GCode is ready"));
if(app_config->get("auto_switch_preview") == "0")
def_combobox_auto_switch_preview.set_default_value(new ConfigOptionStrings{ def_combobox_auto_switch_preview.enum_values[0] });
else if (app_config->get("auto_switch_preview") == "1")
def_combobox_auto_switch_preview.set_default_value(new ConfigOptionStrings{ def_combobox_auto_switch_preview.enum_values[1] });
else if (app_config->get("auto_switch_preview") == "2")
def_combobox_auto_switch_preview.set_default_value(new ConfigOptionStrings{ def_combobox_auto_switch_preview.enum_values[2] });
else if (app_config->get("auto_switch_preview") == "3")
def_combobox_auto_switch_preview.set_default_value(new ConfigOptionStrings{ def_combobox_auto_switch_preview.enum_values[3] });
else
def_combobox_auto_switch_preview.set_default_value(new ConfigOptionStrings{ def_combobox_auto_switch_preview.enum_values[2] });
option = Option(def_combobox_auto_switch_preview, "auto_switch_preview");
m_optgroup_general->append_single_option_line(option);
}
// Please keep in sync with ConfigWizard
def.label = L("Check for application updates");
def.type = coBool;
@ -449,15 +473,6 @@ void PreferencesDialog::build()
option.opt.width = 6;
m_optgroup_gui->append_single_option_line(option);
if (is_editor) {
def.label = L("Switch from 3D view to Preview when sliced");
def.type = coBool;
def.tooltip = std::string(L("When an object is sliced, it will switch your view from the 3D view to the previewx (and then gcode-preview) automatically."));
def.set_default_value(new ConfigOptionBool{ app_config->get("auto_switch_preview") == "1" });
option = Option(def, "auto_switch_preview");
m_optgroup_gui->append_single_option_line(option);
}
activate_options_tab(m_optgroup_gui);
if (is_editor) {
@ -528,6 +543,27 @@ void PreferencesDialog::accept()
m_values.erase(it); // we shouldn't change value, if some of those parameters was selected, and then deselected
}
auto it_auto_switch_preview = m_values.find("auto_switch_preview");
if (it_auto_switch_preview != m_values.end()) {
std::vector<std::string> values = def_combobox_auto_switch_preview.enum_values;
for(size_t i=0; i< values.size(); i++)
if (values[i] == it_auto_switch_preview->second)
it_auto_switch_preview->second = std::to_string(i);
}
auto it_background_processing = m_values.find("background_processing");
if (it_background_processing != m_values.end() && it_background_processing->second == "1") {
bool warning = app_config->get("auto_switch_preview") != "0";
if (it_auto_switch_preview != m_values.end())
warning = it_auto_switch_preview->second == "1";
if(warning) {
wxMessageDialog dialog(nullptr, "Using background processing with automatic tab switching may be combersome"
", are-you sure to keep the automatic tab switching?", _L("Are you sure?"), wxOK | wxCANCEL | wxICON_QUESTION);
if (dialog.ShowModal() == wxID_CANCEL)
m_values["auto_switch_preview"] = "0";
}
}
for (std::map<std::string, std::string>::iterator it = m_values.begin(); it != m_values.end(); ++it)
app_config->set(it->first, it->second);

View File

@ -24,6 +24,9 @@ class PreferencesDialog : public DPIDialog
#if ENABLE_ENVIRONMENT_MAP
std::shared_ptr<ConfigOptionsGroup> m_optgroup_render;
#endif // ENABLE_ENVIRONMENT_MAP
ConfigOptionDef def_combobox_auto_switch_preview;
wxSizer* m_icon_size_sizer;
wxRadioBox* m_layout_mode_box;
bool isOSX {false};