Correct show_preset_comboboxes

This commit is contained in:
YuSanka 2018-08-07 17:23:48 +02:00
parent 709b898eba
commit da16b28c14
6 changed files with 80 additions and 22 deletions

View file

@ -153,6 +153,10 @@ sub _init_tabpanel {
my $value = $event->GetInt(); my $value = $event->GetInt();
$self->{plater}->on_extruders_change($value); $self->{plater}->on_extruders_change($value);
} }
if ($opt_key eq 'printer_technology'){
my $value = $event->GetInt();# 0 ~ "ptFFF"; 1 ~ "ptSLA"
$self->{plater}->show_preset_comboboxes($value);
}
} }
# don't save while loading for the first time # don't save while loading for the first time
$self->config->save($Slic3r::GUI::autosave) if $Slic3r::GUI::autosave && $self->{loaded}; $self->config->save($Slic3r::GUI::autosave) if $Slic3r::GUI::autosave && $self->{loaded};
@ -165,7 +169,7 @@ sub _init_tabpanel {
my $tab = Slic3r::GUI::get_preset_tab($tab_name); my $tab = Slic3r::GUI::get_preset_tab($tab_name);
if ($self->{plater}) { if ($self->{plater}) {
# Update preset combo boxes (Print settings, Filament, Printer) from their respective tabs. # Update preset combo boxes (Print settings, Filament, Material, Printer) from their respective tabs.
my $presets = $tab->get_presets; my $presets = $tab->get_presets;
if (defined $presets){ if (defined $presets){
my $reload_dependent_tabs = $tab->get_dependent_tabs; my $reload_dependent_tabs = $tab->get_dependent_tabs;
@ -173,7 +177,7 @@ sub _init_tabpanel {
$self->{plater}->{"selected_item_$tab_name"} = $tab->get_selected_preset_item; $self->{plater}->{"selected_item_$tab_name"} = $tab->get_selected_preset_item;
if ($tab_name eq 'printer') { if ($tab_name eq 'printer') {
# Printer selected at the Printer tab, update "compatible" marks at the print and filament selectors. # Printer selected at the Printer tab, update "compatible" marks at the print and filament selectors.
for my $tab_name_other (qw(print filament)) { for my $tab_name_other (qw(print filament material)) {
# If the printer tells us that the print or filament preset has been switched or invalidated, # If the printer tells us that the print or filament preset has been switched or invalidated,
# refresh the print or filament tab page. Otherwise just refresh the combo box. # refresh the print or filament tab page. Otherwise just refresh the combo box.
my $update_action = ($reload_dependent_tabs && (first { $_ eq $tab_name_other } (@{$reload_dependent_tabs}))) my $update_action = ($reload_dependent_tabs && (first { $_ eq $tab_name_other } (@{$reload_dependent_tabs})))
@ -189,7 +193,7 @@ sub _init_tabpanel {
}); });
Slic3r::GUI::create_preset_tabs($self->{no_controller}, $VALUE_CHANGE_EVENT, $PRESETS_CHANGED_EVENT); Slic3r::GUI::create_preset_tabs($self->{no_controller}, $VALUE_CHANGE_EVENT, $PRESETS_CHANGED_EVENT);
$self->{options_tabs} = {}; $self->{options_tabs} = {};
for my $tab_name (qw(print filament printer)) { for my $tab_name (qw(print filament material printer)) {
$self->{options_tabs}{$tab_name} = Slic3r::GUI::get_preset_tab("$tab_name"); $self->{options_tabs}{$tab_name} = Slic3r::GUI::get_preset_tab("$tab_name");
} }
@ -201,10 +205,14 @@ sub _init_tabpanel {
# load initial config # load initial config
my $full_config = wxTheApp->{preset_bundle}->full_config; my $full_config = wxTheApp->{preset_bundle}->full_config;
$self->{plater}->on_config_change($full_config); $self->{plater}->on_config_change($full_config);
#return if $num_extruders is undefined because of SLA printer is selected
return if (!defined $full_config->nozzle_diameter); # ys_FIXME
# Show a correct number of filament fields. # Show a correct number of filament fields.
$self->{plater}->on_extruders_change(int(@{$full_config->nozzle_diameter})); if (defined $full_config->nozzle_diameter){ # nozzle_diameter is undefined when SLA printer is selected
$self->{plater}->on_extruders_change(int(@{$full_config->nozzle_diameter}));
}
# Show correct preset comboboxes according to the printer_technology
$self->{plater}->show_preset_comboboxes(($full_config->printer_technology eq "FFF") ? 0 : 1);
} }
} }

View file

@ -450,20 +450,21 @@ sub new {
{ {
my $presets; my $presets;
{ {
$presets = $self->{presets_sizer} = Wx::FlexGridSizer->new(3, 2, 1, 2); $presets = $self->{presets_sizer} = Wx::FlexGridSizer->new(4, 2, 1, 2);
$presets->AddGrowableCol(1, 1); $presets->AddGrowableCol(1, 1);
$presets->SetFlexibleDirection(wxHORIZONTAL); $presets->SetFlexibleDirection(wxHORIZONTAL);
my %group_labels = ( my %group_labels = (
print => L('Print settings'), print => L('Print settings'),
filament => L('Filament'), filament => L('Filament'),
material => L('SLA material'),
printer => L('Printer'), printer => L('Printer'),
); );
# UI Combo boxes for a print, multiple filaments, and a printer. # UI Combo boxes for a print, multiple filaments, SLA material and a printer.
# Initially a single filament combo box is created, but the number of combo boxes for the filament selection may increase, # Initially a single filament combo box is created, but the number of combo boxes for the filament selection may increase,
# once a printer preset with multiple extruders is activated. # once a printer preset with multiple extruders is activated.
# $self->{preset_choosers}{$group}[$idx] # $self->{preset_choosers}{$group}[$idx]
$self->{preset_choosers} = {}; $self->{preset_choosers} = {};
for my $group (qw(print filament printer)) { for my $group (qw(print filament material printer)) {
my $text = Wx::StaticText->new($self->{right_panel}, -1, "$group_labels{$group}:", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT); my $text = Wx::StaticText->new($self->{right_panel}, -1, "$group_labels{$group}:", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
$text->SetFont($Slic3r::GUI::small_font); $text->SetFont($Slic3r::GUI::small_font);
my $choice = Wx::BitmapComboBox->new($self->{right_panel}, -1, "", wxDefaultPosition, wxDefaultSize, [], wxCB_READONLY); my $choice = Wx::BitmapComboBox->new($self->{right_panel}, -1, "", wxDefaultPosition, wxDefaultSize, [], wxCB_READONLY);
@ -484,7 +485,7 @@ sub new {
$presets->Layout; $presets->Layout;
} }
my $frequently_changed_parameters_sizer = Wx::BoxSizer->new(wxHORIZONTAL); my $frequently_changed_parameters_sizer = $self->{frequently_changed_parameters_sizer} = Wx::BoxSizer->new(wxHORIZONTAL);
Slic3r::GUI::add_frequently_changed_parameters($self->{right_panel}, $frequently_changed_parameters_sizer, $presets); Slic3r::GUI::add_frequently_changed_parameters($self->{right_panel}, $frequently_changed_parameters_sizer, $presets);
my $object_info_sizer; my $object_info_sizer;
@ -655,18 +656,20 @@ sub update_ui_from_settings
} }
} }
# Update preset combo boxes (Print settings, Filament, Printer) from their respective tabs. # Update preset combo boxes (Print settings, Filament, Material, Printer) from their respective tabs.
# Called by # Called by
# Slic3r::GUI::Tab::Print::_on_presets_changed # Slic3r::GUI::Tab::Print::_on_presets_changed
# Slic3r::GUI::Tab::Filament::_on_presets_changed # Slic3r::GUI::Tab::Filament::_on_presets_changed
# Slic3r::GUI::Tab::Material::_on_presets_changed
# Slic3r::GUI::Tab::Printer::_on_presets_changed # Slic3r::GUI::Tab::Printer::_on_presets_changed
# when the presets are loaded or the user selects another preset. # when the presets are loaded or the user selects another preset.
# For Print settings and Printer, synchronize the selection index with their tabs. # For Print settings and Printer, synchronize the selection index with their tabs.
# For Filament, synchronize the selection index for a single extruder printer only, otherwise keep the selection. # For Filament, synchronize the selection index for a single extruder printer only, otherwise keep the selection.
sub update_presets { sub update_presets {
# $group: one of qw(print filament printer) # $group: one of qw(print filament material printer)
# $presets: PresetCollection # $presets: PresetCollection
my ($self, $group, $presets) = @_; my ($self, $group, $presets) = @_;
print "$group \n";
my @choosers = @{$self->{preset_choosers}{$group}}; my @choosers = @{$self->{preset_choosers}{$group}};
if ($group eq 'filament') { if ($group eq 'filament') {
my $choice_idx = 0; my $choice_idx = 0;
@ -680,6 +683,8 @@ sub update_presets {
} }
} elsif ($group eq 'print') { } elsif ($group eq 'print') {
wxTheApp->{preset_bundle}->print->update_platter_ui($choosers[0]); wxTheApp->{preset_bundle}->print->update_platter_ui($choosers[0]);
} elsif ($group eq 'material') {
wxTheApp->{preset_bundle}->sla_material->update_platter_ui($choosers[0]);
} elsif ($group eq 'printer') { } elsif ($group eq 'printer') {
# Update the print choosers to only contain the compatible presets, update the dirty flags. # Update the print choosers to only contain the compatible presets, update the dirty flags.
wxTheApp->{preset_bundle}->print->update_platter_ui($self->{preset_choosers}{print}->[0]); wxTheApp->{preset_bundle}->print->update_platter_ui($self->{preset_choosers}{print}->[0]);
@ -1844,6 +1849,24 @@ sub update {
$self->{preview3D}->reload_print if $self->{preview3D}; $self->{preview3D}->reload_print if $self->{preview3D};
} }
# When a printer technology is changed, the UI needs to be updated to show/hide needed preset combo boxes.
sub show_preset_comboboxes{
my ($self, $showSLA) = @_; #if showSLA is oposite value to "ptFFF"
my $choices = $self->{preset_choosers}{filament};
my $print_filament_ctrls_cnt = 2 + 2 * ($#$choices+1);
foreach (0..$print_filament_ctrls_cnt-1){
$self->{presets_sizer}->Show($_, !$showSLA);
}
$self->{presets_sizer}->Show($print_filament_ctrls_cnt , $showSLA);
$self->{presets_sizer}->Show($print_filament_ctrls_cnt+1, $showSLA);
$self->{frequently_changed_parameters_sizer}->Show(0,!$showSLA);
$self->Layout;
}
# When a number of extruders changes, the UI needs to be updated to show a single filament selection combo box per extruder. # When a number of extruders changes, the UI needs to be updated to show a single filament selection combo box per extruder.
# Also the wxTheApp->{preset_bundle}->filament_presets needs to be resized accordingly # Also the wxTheApp->{preset_bundle}->filament_presets needs to be resized accordingly
# and some reasonable default has to be selected for the additional extruders. # and some reasonable default has to be selected for the additional extruders.

View file

@ -38,6 +38,7 @@ wxString double_to_string(double const value);
class MyButton : public wxButton class MyButton : public wxButton
{ {
bool hidden = false; // never show button if it's hidden ones
public: public:
MyButton() {} MyButton() {}
MyButton(wxWindow* parent, wxWindowID id, const wxString& label = wxEmptyString, MyButton(wxWindow* parent, wxWindowID id, const wxString& label = wxEmptyString,
@ -52,6 +53,12 @@ public:
// overridden from wxWindow base class // overridden from wxWindow base class
virtual bool virtual bool
AcceptsFocusFromKeyboard() const { return false; } AcceptsFocusFromKeyboard() const { return false; }
virtual bool Show(bool show = true) override {
if (!show)
hidden = true;
return wxButton::Show(!hidden);
}
}; };
class Field { class Field {

View file

@ -507,8 +507,7 @@ void create_preset_tabs(bool no_controller, int event_value_change, int event_pr
add_created_tab(new TabPrinter (g_wxTabPanel, no_controller)); add_created_tab(new TabPrinter (g_wxTabPanel, no_controller));
for (size_t i = 0; i < g_wxTabPanel->GetPageCount(); ++ i) { for (size_t i = 0; i < g_wxTabPanel->GetPageCount(); ++ i) {
Tab *tab = dynamic_cast<Tab*>(g_wxTabPanel->GetPage(i)); Tab *tab = dynamic_cast<Tab*>(g_wxTabPanel->GetPage(i));
if (! tab || if (! tab )
tab->GetName() == "sla_material")// ys_FIXME don't set event till doesn't exist material_preset combobox on plater
continue; continue;
tab->set_event_value_change(wxEventType(event_value_change)); tab->set_event_value_change(wxEventType(event_value_change));
tab->set_event_presets_changed(wxEventType(event_presets_changed)); tab->set_event_presets_changed(wxEventType(event_presets_changed));
@ -654,7 +653,7 @@ void add_created_tab(Tab* panel)
g_FilamentTab = panel; g_FilamentTab = panel;
add_panel = g_PresetBundle->printers.get_edited_preset().printer_technology() == ptFFF; add_panel = g_PresetBundle->printers.get_edited_preset().printer_technology() == ptFFF;
} }
else if (tab_name == "sla_material") { else if (tab_name == "material") {
g_MaterialTab = panel; g_MaterialTab = panel;
add_panel = g_PresetBundle->printers.get_edited_preset().printer_technology() == ptSLA; add_panel = g_PresetBundle->printers.get_edited_preset().printer_technology() == ptSLA;
} }

View file

@ -567,6 +567,8 @@ void Tab::update_dirty(){
void Tab::update_tab_ui() void Tab::update_tab_ui()
{ {
// if (this == nullptr)
// return; // ys_FIXME
m_selected_preset_item = m_presets->update_tab_ui(m_presets_choice, m_show_incompatible_presets); m_selected_preset_item = m_presets->update_tab_ui(m_presets_choice, m_show_incompatible_presets);
// update_tab_presets(m_cc_presets_choice, m_show_incompatible_presets); // update_tab_presets(m_cc_presets_choice, m_show_incompatible_presets);
// update_presetsctrl(m_presetctrl, m_show_incompatible_presets); // update_presetsctrl(m_presetctrl, m_show_incompatible_presets);
@ -576,6 +578,8 @@ void Tab::update_tab_ui()
// This could be used for example by setting a Wipe Tower position by interactive manipulation in the 3D view. // This could be used for example by setting a Wipe Tower position by interactive manipulation in the 3D view.
void Tab::load_config(const DynamicPrintConfig& config) void Tab::load_config(const DynamicPrintConfig& config)
{ {
// if (this == nullptr)
// return; // ys_FIXME
bool modified = 0; bool modified = 0;
for(auto opt_key : m_config->diff(config)) { for(auto opt_key : m_config->diff(config)) {
m_config->set_key_value(opt_key, config.option(opt_key)->clone()); m_config->set_key_value(opt_key, config.option(opt_key)->clone());
@ -650,6 +654,15 @@ void Tab::on_value_change(const std::string& opt_key, const boost::any& value)
int val = boost::any_cast<size_t>(value); int val = boost::any_cast<size_t>(value);
event.SetInt(val); event.SetInt(val);
} }
if (opt_key == "printer_technology")
{
int val = boost::any_cast<PrinterTechnology>(value);
event.SetInt(val);
g_wxMainFrame->ProcessWindowEvent(event);
return;
}
g_wxMainFrame->ProcessWindowEvent(event); g_wxMainFrame->ProcessWindowEvent(event);
} }
if (opt_key == "fill_density") if (opt_key == "fill_density")
@ -701,9 +714,11 @@ void Tab::update_wiping_button_visibility() {
// to uddate number of "filament" selection boxes when the number of extruders change. // to uddate number of "filament" selection boxes when the number of extruders change.
void Tab::on_presets_changed() void Tab::on_presets_changed()
{ {
if (get_preset_bundle()->printers.get_selected_preset().printer_technology() == ptSLA) // if (get_preset_bundle()->printers.get_selected_preset().printer_technology() == ptSLA)
return; // ys_FIXME // return;
if (m_event_presets_changed > 0) { if (m_event_presets_changed > 0
&& get_preset_bundle()->printers.get_selected_preset().printer_technology() != ptSLA // ys_FIXME
) {
wxCommandEvent event(m_event_presets_changed); wxCommandEvent event(m_event_presets_changed);
event.SetString(m_name); event.SetString(m_name);
g_wxMainFrame->ProcessWindowEvent(event); g_wxMainFrame->ProcessWindowEvent(event);
@ -1420,6 +1435,8 @@ void TabPrinter::build()
m_printer_technology = m_presets->get_selected_preset().printer_technology(); m_printer_technology = m_presets->get_selected_preset().printer_technology();
m_presets->get_selected_preset().printer_technology() == ptSLA ? build_sla() : build_fff(); m_presets->get_selected_preset().printer_technology() == ptSLA ? build_sla() : build_fff();
// on_value_change("printer_technology", m_printer_technology); // to update show/hide preset ComboBoxes
} }
void TabPrinter::build_fff() void TabPrinter::build_fff()
@ -1987,6 +2004,8 @@ void TabPrinter::update_pages()
m_pages_sla.empty() ? build_sla() : m_pages.swap(m_pages_sla); m_pages_sla.empty() ? build_sla() : m_pages.swap(m_pages_sla);
rebuild_page_tree(true); rebuild_page_tree(true);
on_value_change("printer_technology", m_presets->get_edited_preset().printer_technology()); // to update show/hide preset ComboBoxes
} }
void TabPrinter::update() void TabPrinter::update()
@ -2112,7 +2131,7 @@ void Tab::load_current_preset()
m_bmp_non_system = m_presets->get_selected_preset_parent() ? &m_bmp_value_unlock : &m_bmp_white_bullet; m_bmp_non_system = m_presets->get_selected_preset_parent() ? &m_bmp_value_unlock : &m_bmp_white_bullet;
m_ttg_non_system = m_presets->get_selected_preset_parent() ? &m_ttg_value_unlock : &m_ttg_white_bullet_ns; m_ttg_non_system = m_presets->get_selected_preset_parent() ? &m_ttg_value_unlock : &m_ttg_white_bullet_ns;
m_tt_non_system = m_presets->get_selected_preset_parent() ? &m_tt_value_unlock : &m_ttg_white_bullet_ns; m_tt_non_system = m_presets->get_selected_preset_parent() ? &m_tt_value_unlock : &m_ttg_white_bullet_ns;
m_undo_to_sys_btn->Enable(!preset.is_default); m_undo_to_sys_btn->Enable(!preset.is_default);
@ -2235,7 +2254,8 @@ void Tab::select_preset(std::string preset_name /*= ""*/)
std::vector<PresetUpdate> updates = { std::vector<PresetUpdate> updates = {
{ "print", &m_preset_bundle->prints, ptFFF }, { "print", &m_preset_bundle->prints, ptFFF },
{ "filament", &m_preset_bundle->filaments, ptFFF }, { "filament", &m_preset_bundle->filaments, ptFFF },
{ "sla_materials", &m_preset_bundle->sla_materials, ptSLA } { "sla_materials", &m_preset_bundle->sla_materials, ptSLA }
// { "material", &m_preset_bundle->sla_materials, ptSLA }
}; };
for (PresetUpdate &pu : updates) { for (PresetUpdate &pu : updates) {
pu.old_preset_dirty = (old_printer_technology == pu.technology) && pu.presets->current_is_dirty(); pu.old_preset_dirty = (old_printer_technology == pu.technology) && pu.presets->current_is_dirty();
@ -2974,7 +2994,8 @@ void TabSLAMaterial::build()
void TabSLAMaterial::update() void TabSLAMaterial::update()
{ {
if (get_preset_bundle()->printers.get_selected_preset().printer_technology() == ptFFF)
return; // ys_FIXME
} }
} // GUI } // GUI

View file

@ -357,7 +357,7 @@ class TabSLAMaterial : public Tab
public: public:
TabSLAMaterial() {} TabSLAMaterial() {}
TabSLAMaterial(wxNotebook* parent, bool no_controller) : TabSLAMaterial(wxNotebook* parent, bool no_controller) :
Tab(parent, _(L("SLA Material Settings")), "sla_material", no_controller) {} Tab(parent, _(L("SLA Material Settings")), "material", no_controller) {}
~TabSLAMaterial(){} ~TabSLAMaterial(){}
void build() override; void build() override;