Correct preset/tabs updating according to the technology

+ some code refactoring
This commit is contained in:
YuSanka 2018-08-08 16:22:56 +02:00
parent da16b28c14
commit adf003f0ed
8 changed files with 64 additions and 83 deletions

View File

@ -177,7 +177,7 @@ sub _init_tabpanel {
$self->{plater}->{"selected_item_$tab_name"} = $tab->get_selected_preset_item;
if ($tab_name eq 'printer') {
# Printer selected at the Printer tab, update "compatible" marks at the print and filament selectors.
for my $tab_name_other (qw(print filament material)) {
for my $tab_name_other (qw(print filament sla_material)) {
# 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.
my $update_action = ($reload_dependent_tabs && (first { $_ eq $tab_name_other } (@{$reload_dependent_tabs})))
@ -193,7 +193,7 @@ sub _init_tabpanel {
});
Slic3r::GUI::create_preset_tabs($self->{no_controller}, $VALUE_CHANGE_EVENT, $PRESETS_CHANGED_EVENT);
$self->{options_tabs} = {};
for my $tab_name (qw(print filament material printer)) {
for my $tab_name (qw(print filament sla_material printer)) {
$self->{options_tabs}{$tab_name} = Slic3r::GUI::get_preset_tab("$tab_name");
}

View File

@ -456,7 +456,7 @@ sub new {
my %group_labels = (
print => L('Print settings'),
filament => L('Filament'),
material => L('SLA material'),
sla_material=> L('SLA material'),
printer => L('Printer'),
);
# UI Combo boxes for a print, multiple filaments, SLA material and a printer.
@ -464,7 +464,7 @@ sub new {
# once a printer preset with multiple extruders is activated.
# $self->{preset_choosers}{$group}[$idx]
$self->{preset_choosers} = {};
for my $group (qw(print filament material printer)) {
for my $group (qw(print filament sla_material printer)) {
my $text = Wx::StaticText->new($self->{right_panel}, -1, "$group_labels{$group}:", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
$text->SetFont($Slic3r::GUI::small_font);
my $choice = Wx::BitmapComboBox->new($self->{right_panel}, -1, "", wxDefaultPosition, wxDefaultSize, [], wxCB_READONLY);
@ -666,10 +666,9 @@ sub update_ui_from_settings
# 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.
sub update_presets {
# $group: one of qw(print filament material printer)
# $group: one of qw(print filament sla_material printer)
# $presets: PresetCollection
my ($self, $group, $presets) = @_;
print "$group \n";
my @choosers = @{$self->{preset_choosers}{$group}};
if ($group eq 'filament') {
my $choice_idx = 0;
@ -683,7 +682,7 @@ sub update_presets {
}
} elsif ($group eq 'print') {
wxTheApp->{preset_bundle}->print->update_platter_ui($choosers[0]);
} elsif ($group eq 'material') {
} elsif ($group eq 'sla_material') {
wxTheApp->{preset_bundle}->sla_material->update_platter_ui($choosers[0]);
} elsif ($group eq 'printer') {
# Update the print choosers to only contain the compatible presets, update the dirty flags.

View File

@ -127,11 +127,6 @@ std::shared_ptr<ConfigOptionsGroup> m_optgroup;
double m_brim_width = 0.0;
wxButton* g_wiping_dialog_button = nullptr;
// Windows, associated with Print, Filament & Material Tabs accordingly
wxWindow *g_PrintTab = nullptr;
wxWindow *g_FilamentTab = nullptr;
wxWindow *g_MaterialTab = nullptr;
static void init_label_colours()
{
auto luma = get_colour_approx_luma(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
@ -501,24 +496,33 @@ void open_preferences_dialog(int event_preferences)
void create_preset_tabs(bool no_controller, int event_value_change, int event_presets_changed)
{
update_label_colours_from_appconfig();
add_created_tab(new TabPrint (g_wxTabPanel, no_controller));
add_created_tab(new TabFilament (g_wxTabPanel, no_controller));
add_created_tab(new TabSLAMaterial (g_wxTabPanel, no_controller));
add_created_tab(new TabPrinter (g_wxTabPanel, no_controller));
for (size_t i = 0; i < g_wxTabPanel->GetPageCount(); ++ i) {
Tab *tab = dynamic_cast<Tab*>(g_wxTabPanel->GetPage(i));
if (! tab )
continue;
tab->set_event_value_change(wxEventType(event_value_change));
tab->set_event_presets_changed(wxEventType(event_presets_changed));
}
add_created_tab(new TabPrint (g_wxTabPanel, no_controller), event_value_change, event_presets_changed);
add_created_tab(new TabFilament (g_wxTabPanel, no_controller), event_value_change, event_presets_changed);
add_created_tab(new TabSLAMaterial (g_wxTabPanel, no_controller), event_value_change, event_presets_changed);
add_created_tab(new TabPrinter (g_wxTabPanel, no_controller), event_value_change, event_presets_changed);
}
std::vector<PresetTab> preset_tabs = {
{ "print", nullptr, ptFFF },
{ "filament", nullptr, ptFFF },
{ "sla_material", nullptr, ptSLA }
};
const std::vector<PresetTab>& get_preset_tabs() {
return preset_tabs;
}
Tab* get_tab(const std::string& name)
{
std::vector<PresetTab>::iterator it = std::find_if(preset_tabs.begin(), preset_tabs.end(),
[name](PresetTab& tab){ return name == tab.name; });
return it != preset_tabs.end() ? it->panel : nullptr;
}
TabIface* get_preset_tab_iface(char *name)
{
if (std::strcmp(name, "print") == 0) return new TabIface(dynamic_cast<Tab*>(g_PrintTab));
if (std::strcmp(name, "filament") == 0) return new TabIface(dynamic_cast<Tab*>(g_FilamentTab));
if (std::strcmp(name, "material") == 0) return new TabIface(dynamic_cast<Tab*>(g_MaterialTab));
Tab* tab = get_tab(name);
if (tab) return new TabIface(tab);
for (size_t i = 0; i < g_wxTabPanel->GetPageCount(); ++ i) {
Tab *tab = dynamic_cast<Tab*>(g_wxTabPanel->GetPage(i));
if (! tab)
@ -636,26 +640,24 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt
}
}
void add_created_tab(Tab* panel)
void add_created_tab(Tab* panel, int event_value_change, int event_presets_changed)
{
panel->create_preset_tab(g_PresetBundle);
// Load the currently selected preset into the GUI, update the preset selection box.
panel->load_current_preset();
panel->set_event_value_change(wxEventType(event_value_change));
panel->set_event_presets_changed(wxEventType(event_presets_changed));
const wxString& tab_name = panel->GetName();
bool add_panel = true;
if (tab_name == "print") {
g_PrintTab = panel;
add_panel = g_PresetBundle->printers.get_edited_preset().printer_technology() == ptFFF;
}
else if (tab_name == "filament") {
g_FilamentTab = panel;
add_panel = g_PresetBundle->printers.get_edited_preset().printer_technology() == ptFFF;
}
else if (tab_name == "material") {
g_MaterialTab = panel;
add_panel = g_PresetBundle->printers.get_edited_preset().printer_technology() == ptSLA;
auto it = std::find_if( preset_tabs.begin(), preset_tabs.end(),
[tab_name](PresetTab& tab){return tab.name == tab_name; });
if (it != preset_tabs.end()) {
it->panel = panel;
add_panel = it->technology == g_PresetBundle->printers.get_edited_preset().printer_technology();
}
if (add_panel)
@ -704,18 +706,6 @@ wxNotebook* get_tab_panel() {
return g_wxTabPanel;
}
wxWindow* get_print_tab() {
return g_PrintTab;
}
wxWindow* get_filament_tab(){
return g_FilamentTab;
}
wxWindow* get_material_tab(){
return g_MaterialTab;
}
const wxColour& get_label_clr_modified() {
return g_color_label_modified;
}

View File

@ -34,6 +34,8 @@ class DynamicPrintConfig;
class TabIface;
class _3DScene;
enum PrinterTechnology;
#define _(s) Slic3r::GUI::I18N::translate((s))
namespace GUI { namespace I18N {
@ -79,6 +81,13 @@ inline t_file_wild_card& get_file_wild_card() {
return FILE_WILDCARDS;
}
struct PresetTab {
std::string name;
Tab* panel;
PrinterTechnology technology;
};
void disable_screensaver();
void enable_screensaver();
bool debugged();
@ -108,9 +117,8 @@ void set_label_clr_sys(const wxColour& clr);
const wxFont& small_font();
const wxFont& bold_font();
wxWindow* get_print_tab();
wxWindow* get_filament_tab();
wxWindow* get_material_tab();
Tab* get_tab(const std::string& name);
const std::vector<PresetTab>& get_preset_tabs();
extern void add_menus(wxMenuBar *menu, int event_preferences_changed, int event_language_change);
@ -134,7 +142,7 @@ void create_preset_tabs(bool no_controller, int event_value_change, int event_pr
TabIface* get_preset_tab_iface(char *name);
// add it at the end of the tab panel.
void add_created_tab(Tab* panel);
void add_created_tab(Tab* panel, int event_value_change, int event_presets_changed);
// Change option value in config
void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index = 0);

View File

@ -1299,7 +1299,7 @@ bool PresetBundle::parse_color(const std::string &scolor, unsigned char *rgb_out
void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, wxBitmapComboBox *ui)
{
if (ui == nullptr)
if (ui == nullptr || this->printers.get_edited_preset().printer_technology() == ptSLA)
return;
unsigned char rgb[3];

View File

@ -567,8 +567,6 @@ void Tab::update_dirty(){
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);
// update_tab_presets(m_cc_presets_choice, m_show_incompatible_presets);
// update_presetsctrl(m_presetctrl, m_show_incompatible_presets);
@ -578,8 +576,6 @@ void Tab::update_tab_ui()
// 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)
{
// if (this == nullptr)
// return; // ys_FIXME
bool modified = 0;
for(auto opt_key : m_config->diff(config)) {
m_config->set_key_value(opt_key, config.option(opt_key)->clone());
@ -714,11 +710,7 @@ void Tab::update_wiping_button_visibility() {
// to uddate number of "filament" selection boxes when the number of extruders change.
void Tab::on_presets_changed()
{
// if (get_preset_bundle()->printers.get_selected_preset().printer_technology() == ptSLA)
// return;
if (m_event_presets_changed > 0
&& get_preset_bundle()->printers.get_selected_preset().printer_technology() != ptSLA // ys_FIXME
) {
if (m_event_presets_changed > 0) {
wxCommandEvent event(m_event_presets_changed);
event.SetString(m_name);
g_wxMainFrame->ProcessWindowEvent(event);
@ -2150,26 +2142,18 @@ void Tab::load_current_preset()
PrinterTechnology& printer_technology = m_presets->get_edited_preset().printer_technology();
if (printer_technology != static_cast<TabPrinter*>(this)->m_printer_technology)
{
wxWindow* del_page = printer_technology == ptFFF ? get_material_tab() : get_print_tab();
int del_page_id = get_tab_panel()->FindPage(del_page);
if (del_page_id != wxNOT_FOUND) {
if (printer_technology == ptFFF)
for (auto& tab : get_preset_tabs()){
if (tab.technology != printer_technology)
{
get_tab_panel()->GetPage(del_page_id)->Show(false);
get_tab_panel()->RemovePage(del_page_id);
get_tab_panel()->InsertPage(del_page_id, get_filament_tab(), static_cast<Tab*>(get_filament_tab())->title());
get_tab_panel()->InsertPage(del_page_id, get_print_tab(), static_cast<Tab*>(get_print_tab())->title());
int page_id = get_tab_panel()->FindPage(tab.panel);
get_tab_panel()->GetPage(page_id)->Show(false);
get_tab_panel()->RemovePage(page_id);
}
else
{
for (int i = 0; i < 2; ++i) {
get_tab_panel()->GetPage(del_page_id)->Show(false);
get_tab_panel()->RemovePage(del_page_id);
}
get_tab_panel()->InsertPage(del_page_id, get_material_tab(), static_cast<Tab*>(get_material_tab())->title());
}
static_cast<TabPrinter*>(this)->m_printer_technology = printer_technology;
get_tab_panel()->InsertPage(get_tab_panel()->FindPage(this), tab.panel, tab.panel->title());
}
static_cast<TabPrinter*>(this)->m_printer_technology = printer_technology;
}
}
@ -2254,8 +2238,7 @@ void Tab::select_preset(std::string preset_name /*= ""*/)
std::vector<PresetUpdate> updates = {
{ "print", &m_preset_bundle->prints, ptFFF },
{ "filament", &m_preset_bundle->filaments, ptFFF },
{ "sla_materials", &m_preset_bundle->sla_materials, ptSLA }
// { "material", &m_preset_bundle->sla_materials, ptSLA }
{ "sla_material", &m_preset_bundle->sla_materials, ptSLA }
};
for (PresetUpdate &pu : updates) {
pu.old_preset_dirty = (old_printer_technology == pu.technology) && pu.presets->current_is_dirty();

View File

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

View File

@ -132,6 +132,7 @@ PresetCollection::arrayref()
Ref<PresetCollection> print() %code%{ RETVAL = &THIS->prints; %};
Ref<PresetCollection> filament() %code%{ RETVAL = &THIS->filaments; %};
Ref<PresetCollection> sla_material() %code%{ RETVAL = &THIS->sla_materials; %};
Ref<PresetCollection> printer() %code%{ RETVAL = &THIS->printers; %};
Ref<DynamicPrintConfig> project_config() %code%{ RETVAL = &THIS->project_config; %};