Some code rebase
This commit is contained in:
parent
703f367e69
commit
398f15d546
4 changed files with 21 additions and 79 deletions
|
@ -109,20 +109,15 @@ void MainFrame::init_tabpanel()
|
|||
|
||||
m_tabpanel->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED, [this](wxEvent&) {
|
||||
auto panel = m_tabpanel->GetCurrentPage();
|
||||
// panel->OnActivate(); if panel->can('OnActivate');
|
||||
|
||||
if (panel == nullptr)
|
||||
return;
|
||||
|
||||
for (auto& tab_name : { "print", "filament", "printer" }) {
|
||||
if (tab_name == panel->GetName()) {
|
||||
// On GTK, the wxEVT_NOTEBOOK_PAGE_CHANGED event is triggered
|
||||
// before the MainFrame is fully set up.
|
||||
auto it = m_options_tabs.find(tab_name);
|
||||
assert(it != m_options_tabs.end());
|
||||
if (it != m_options_tabs.end())
|
||||
it->second->OnActivate();
|
||||
}
|
||||
auto& tabs_list = wxGetApp().tabs_list;
|
||||
if (find(tabs_list.begin(), tabs_list.end(), panel) != tabs_list.end()) {
|
||||
// On GTK, the wxEVT_NOTEBOOK_PAGE_CHANGED event is triggered
|
||||
// before the MainFrame is fully set up.
|
||||
static_cast<Tab*>(panel)->OnActivate();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -140,9 +135,6 @@ void MainFrame::init_tabpanel()
|
|||
Bind(EVT_TAB_PRESETS_CHANGED, &MainFrame::on_presets_changed, this);
|
||||
|
||||
create_preset_tabs();
|
||||
std::vector<std::string> tab_names = { "print", "filament", "sla_print", "sla_material", "printer" };
|
||||
for (auto tab_name : tab_names)
|
||||
m_options_tabs[tab_name] = get_preset_tab(tab_name.c_str());
|
||||
|
||||
if (m_plater) {
|
||||
// load initial config
|
||||
|
@ -157,46 +149,12 @@ void MainFrame::init_tabpanel()
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<PresetTab> preset_tabs = {
|
||||
{ "print", nullptr, ptFFF },
|
||||
{ "filament", nullptr, ptFFF },
|
||||
{ "sla_print", nullptr, ptSLA },
|
||||
{ "sla_material", nullptr, ptSLA }
|
||||
};
|
||||
|
||||
std::vector<PresetTab>& MainFrame::get_preset_tabs() {
|
||||
return preset_tabs;
|
||||
}
|
||||
|
||||
Tab* MainFrame::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;
|
||||
}
|
||||
|
||||
Tab* MainFrame::get_preset_tab(const std::string& name)
|
||||
{
|
||||
Tab* tab = get_tab(name);
|
||||
if (tab) return tab;
|
||||
|
||||
for (size_t i = 0; i < m_tabpanel->GetPageCount(); ++i) {
|
||||
tab = dynamic_cast<Tab*>(m_tabpanel->GetPage(i));
|
||||
if (!tab)
|
||||
continue;
|
||||
if (tab->name() == name) {
|
||||
return tab;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void MainFrame::create_preset_tabs()
|
||||
{
|
||||
wxGetApp().update_label_colours_from_appconfig();
|
||||
add_created_tab(new TabPrint(m_tabpanel));
|
||||
add_created_tab(new TabSLAPrint(m_tabpanel));
|
||||
add_created_tab(new TabFilament(m_tabpanel));
|
||||
add_created_tab(new TabSLAPrint(m_tabpanel));
|
||||
add_created_tab(new TabSLAMaterial(m_tabpanel));
|
||||
add_created_tab(new TabPrinter(m_tabpanel));
|
||||
}
|
||||
|
@ -205,14 +163,9 @@ void MainFrame::add_created_tab(Tab* panel)
|
|||
{
|
||||
panel->create_preset_tab();
|
||||
|
||||
const wxString& tab_name = panel->GetName();
|
||||
const auto printer_tech = wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology();
|
||||
|
||||
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;
|
||||
|
||||
if (panel->supports_printer_technology(wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology()))
|
||||
if (panel->supports_printer_technology(printer_tech))
|
||||
m_tabpanel->AddPage(panel, panel->title());
|
||||
}
|
||||
|
||||
|
@ -767,8 +720,8 @@ void MainFrame::load_configbundle(wxString file/* = wxEmptyString, const bool re
|
|||
// Also update the platter with the new presets.
|
||||
void MainFrame::load_config(const DynamicPrintConfig& config)
|
||||
{
|
||||
for (auto tab : m_options_tabs)
|
||||
tab.second->load_config(config);
|
||||
for (auto tab : wxGetApp().tabs_list)
|
||||
tab->load_config(config);
|
||||
if (m_plater)
|
||||
m_plater->on_config_change(config);
|
||||
}
|
||||
|
@ -838,11 +791,7 @@ void MainFrame::update_ui_from_settings()
|
|||
{
|
||||
m_menu_item_reslice_now->Enable(wxGetApp().app_config->get("background_processing") == "1");
|
||||
// if (m_plater) m_plater->update_ui_from_settings();
|
||||
/*
|
||||
std::vector<std::string> tab_names = { "print", "filament", "printer" };
|
||||
for (auto tab_name: tab_names)
|
||||
m_options_tabs[tab_name]->update_ui_from_settings();
|
||||
*/
|
||||
|
||||
for (auto tab: wxGetApp().tabs_list)
|
||||
tab->update_ui_from_settings();
|
||||
}
|
||||
|
|
|
@ -53,8 +53,6 @@ class MainFrame : public wxFrame
|
|||
wxString m_qs_last_output_file = wxEmptyString;
|
||||
wxString m_last_config = wxEmptyString;
|
||||
|
||||
std::map<std::string, Tab*> m_options_tabs;
|
||||
|
||||
wxMenuItem* m_menu_item_repeat { nullptr };
|
||||
wxMenuItem* m_menu_item_reslice_now { nullptr };
|
||||
#if !ENABLE_NEW_MENU_LAYOUT
|
||||
|
@ -67,7 +65,6 @@ class MainFrame : public wxFrame
|
|||
|
||||
void on_presets_changed(SimpleEvent&);
|
||||
void on_value_changed(wxCommandEvent&);
|
||||
Tab* get_tab(const std::string& name);
|
||||
|
||||
#if ENABLE_NEW_MENU_LAYOUT
|
||||
bool can_save() const;
|
||||
|
@ -84,8 +81,6 @@ public:
|
|||
Plater* plater() { return m_plater; }
|
||||
|
||||
void init_tabpanel();
|
||||
const std::map<std::string, Tab*>& options_tabs() const { return m_options_tabs; }
|
||||
Tab* get_preset_tab(const std::string& name);
|
||||
void create_preset_tabs();
|
||||
void add_created_tab(Tab* panel);
|
||||
void init_menubar();
|
||||
|
@ -105,8 +100,6 @@ public:
|
|||
void select_tab(size_t tab) const;
|
||||
void select_view(const std::string& direction);
|
||||
|
||||
std::vector<PresetTab>& get_preset_tabs();
|
||||
|
||||
Plater* m_plater { nullptr };
|
||||
wxNotebook* m_tabpanel { nullptr };
|
||||
wxProgressDialog* m_progress_dialog { nullptr };
|
||||
|
|
|
@ -2027,7 +2027,7 @@ void Plater::priv::on_wipetower_moved(Vec3dEvent &evt)
|
|||
DynamicPrintConfig cfg;
|
||||
cfg.opt<ConfigOptionFloat>("wipe_tower_x", true)->value = evt.data(0);
|
||||
cfg.opt<ConfigOptionFloat>("wipe_tower_y", true)->value = evt.data(1);
|
||||
main_frame->get_preset_tab("print")->load_config(cfg);
|
||||
wxGetApp().get_tab(Preset::TYPE_PRINT)->load_config(cfg);
|
||||
}
|
||||
|
||||
void Plater::priv::on_enable_action_buttons(Event<bool>&)
|
||||
|
|
|
@ -765,9 +765,7 @@ void Tab::on_presets_changed()
|
|||
{
|
||||
// If the printer tells us that the print or filament/sla_material preset has been switched or invalidated,
|
||||
// refresh the print or filament/sla_material tab page.
|
||||
Tab* tab = wxGetApp().get_tab(t);
|
||||
if (tab)
|
||||
tab->load_current_preset();
|
||||
wxGetApp().get_tab(t)->load_current_preset();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2251,14 +2249,16 @@ 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)
|
||||
{
|
||||
for (auto& tab : wxGetApp().mainframe->get_preset_tabs()) {
|
||||
if (tab.technology != printer_technology)
|
||||
{
|
||||
int page_id = wxGetApp().tab_panel()->FindPage(tab.panel);
|
||||
for (auto tab : wxGetApp().tabs_list) {
|
||||
if (tab->type() == Preset::TYPE_PRINTER) // Printer tab is shown every time
|
||||
continue;
|
||||
if (tab->supports_printer_technology(printer_technology))
|
||||
wxGetApp().tab_panel()->InsertPage(wxGetApp().tab_panel()->FindPage(this), tab, tab->title());
|
||||
else {
|
||||
int page_id = wxGetApp().tab_panel()->FindPage(tab);
|
||||
wxGetApp().tab_panel()->GetPage(page_id)->Show(false);
|
||||
wxGetApp().tab_panel()->RemovePage(page_id);
|
||||
} else
|
||||
wxGetApp().tab_panel()->InsertPage(wxGetApp().tab_panel()->FindPage(this), tab.panel, tab.panel->title());
|
||||
}
|
||||
}
|
||||
static_cast<TabPrinter*>(this)->m_printer_technology = printer_technology;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue