Tab preset & value change events
This commit is contained in:
parent
b3c09a9254
commit
f31cf684cb
@ -14,6 +14,7 @@ struct SimpleEvent : public wxEvent
|
||||
{
|
||||
SimpleEvent(wxEventType type, wxObject* origin = nullptr) : wxEvent(0, type)
|
||||
{
|
||||
m_propagationLevel = wxEVENT_PROPAGATE_MAX;
|
||||
SetEventObject(origin);
|
||||
}
|
||||
|
||||
@ -30,6 +31,7 @@ template<class T, size_t N> struct ArrayEvent : public wxEvent
|
||||
ArrayEvent(wxEventType type, std::array<T, N> data, wxObject* origin = nullptr)
|
||||
: wxEvent(0, type), data(std::move(data))
|
||||
{
|
||||
m_propagationLevel = wxEVENT_PROPAGATE_MAX;
|
||||
SetEventObject(origin);
|
||||
}
|
||||
|
||||
@ -45,6 +47,7 @@ template<class T> struct ArrayEvent<T, 1> : public wxEvent
|
||||
ArrayEvent(wxEventType type, T data, wxObject* origin = nullptr)
|
||||
: wxEvent(0, type), data(std::move(data))
|
||||
{
|
||||
m_propagationLevel = wxEVENT_PROPAGATE_MAX;
|
||||
SetEventObject(origin);
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <wx/menu.h>
|
||||
#include <wx/progdlg.h>
|
||||
#include <wx/tooltip.h>
|
||||
#include <wx/debug.h>
|
||||
|
||||
#include "Tab.hpp"
|
||||
#include "PresetBundle.hpp"
|
||||
@ -168,40 +169,10 @@ void MainFrame::init_tabpanel()
|
||||
// m_config->save(Slic3r::GUI::autosave) ;
|
||||
// });
|
||||
|
||||
// The following event is emited by the C++ Tab implementation on preset selection,
|
||||
// The following event is emited by Tab on preset selection,
|
||||
// or when the preset's "modified" status changes.
|
||||
// EVT_COMMAND($self, -1, $PRESETS_CHANGED_EVENT, sub {
|
||||
// my($self, $event) = @_;
|
||||
// auto tab_name = event->GetString;
|
||||
//
|
||||
// Tab* tab = Slic3r::GUI::get_preset_tab(tab_name);
|
||||
// if (m_plater) {
|
||||
// // Update preset combo boxes(Print settings, Filament, Material, Printer) from their respective tabs.
|
||||
// auto presets = tab->get_presets();
|
||||
// if (presets){
|
||||
// auto reload_dependent_tabs = tab->get_dependent_tabs();
|
||||
// m_plater->update_presets(tab_name, reload_dependent_tabs, presets);
|
||||
// m_plater->{"selected_item_$tab_name"} = tab->get_selected_preset_item();
|
||||
// if (tab_name == "printer") {
|
||||
// // Printer selected at the Printer tab, update "compatible" marks at the print and filament selectors.
|
||||
// std::vector<std::string> tab_names_other = { "print", "filament", "sla_materialprinter" };
|
||||
// for (const auto tab_name_other : tab_names_other) {
|
||||
// Tab* cur_tab = m_options_tabs[tab_name_other];
|
||||
// // 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.
|
||||
// if (reload_dependent_tabs.empty() ||
|
||||
// find(reload_dependent_tabs.begin(), reload_dependent_tabs.end(), tab_name_other) ==
|
||||
// reload_dependent_tabs.end() )
|
||||
// cur_tab->update_tab_ui();
|
||||
// else
|
||||
// cur_tab->load_current_preset();
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// m_plater->on_config_change(tab->get_config());
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
Bind(EVT_TAB_PRESETS_CHANGED, &MainFrame::on_presets_changed, this);
|
||||
|
||||
|
||||
// The following event is emited by the C++ Tab implementation on object selection change.
|
||||
// EVT_COMMAND($self, -1, $OBJECT_SELECTION_CHANGED_EVENT, sub {
|
||||
@ -791,6 +762,56 @@ wxMenuItem* MainFrame::append_menu_item(wxMenu* menu,
|
||||
return item;
|
||||
}
|
||||
|
||||
void MainFrame::on_presets_changed(SimpleEvent &event)
|
||||
{
|
||||
auto *tab = dynamic_cast<Tab*>(event.GetEventObject());
|
||||
wxASSERT(tab != nullptr);
|
||||
if (tab == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update preset combo boxes(Print settings, Filament, Material, Printer) from their respective tabs.
|
||||
auto presets = tab->get_presets();
|
||||
if (presets) {
|
||||
auto reload_dependent_tabs = tab->get_dependent_tabs();
|
||||
|
||||
// FIXME: The preset type really should be a property of Tab instead
|
||||
Slic3r::Preset::Type preset_type;
|
||||
if (tab == m_options_tabs["print"]) { preset_type = Slic3r::Preset::TYPE_PRINT; }
|
||||
else if (tab == m_options_tabs["filament"]) { preset_type = Slic3r::Preset::TYPE_FILAMENT; }
|
||||
else if (tab == m_options_tabs["sla_material"]) { preset_type = Slic3r::Preset::TYPE_SLA_MATERIAL; }
|
||||
else if (tab == m_options_tabs["printer"]) { preset_type = Slic3r::Preset::TYPE_PRINTER; }
|
||||
else {
|
||||
wxASSERT(false);
|
||||
return;
|
||||
}
|
||||
|
||||
m_plater->sidebar().update_presets(preset_type);
|
||||
|
||||
// XXX: ???
|
||||
// m_plater->{"selected_item_$tab_name"} = tab->get_selected_preset_item();
|
||||
|
||||
if (preset_type == Slic3r::Preset::TYPE_PRINTER) {
|
||||
// Printer selected at the Printer tab, update "compatible" marks at the print and filament selectors.
|
||||
// XXX: Do this in a more C++ way
|
||||
std::vector<std::string> tab_names_other = { "print", "filament", "sla_material" };
|
||||
for (const auto tab_name_other : tab_names_other) {
|
||||
Tab* cur_tab = m_options_tabs[tab_name_other];
|
||||
// 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.
|
||||
if (reload_dependent_tabs.empty() ||
|
||||
find(reload_dependent_tabs.begin(), reload_dependent_tabs.end(), tab_name_other) ==
|
||||
reload_dependent_tabs.end() )
|
||||
cur_tab->update_tab_ui();
|
||||
else
|
||||
cur_tab->load_current_preset();
|
||||
}
|
||||
}
|
||||
// XXX: ?
|
||||
// m_plater->on_config_change(tab->get_config());
|
||||
}
|
||||
}
|
||||
|
||||
// Called after the Preferences dialog is closed and the program settings are saved.
|
||||
// Update the UI based on the current preferences.
|
||||
void MainFrame::update_ui_from_settings()
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <map>
|
||||
|
||||
#include "Plater.hpp"
|
||||
#include "Event.hpp"
|
||||
|
||||
class wxMenuBar;
|
||||
class wxNotebook;
|
||||
@ -64,6 +65,8 @@ class MainFrame : public wxFrame
|
||||
|
||||
std::string get_base_name(const wxString full_name) const ;
|
||||
std::string get_dir_name(const wxString full_name) const ;
|
||||
|
||||
void on_presets_changed(SimpleEvent&);
|
||||
public:
|
||||
MainFrame() {}
|
||||
MainFrame(const bool no_plater, const bool loaded);
|
||||
|
@ -310,38 +310,37 @@ Sidebar::~Sidebar() {}
|
||||
|
||||
void Sidebar::update_presets(Preset::Type preset_type)
|
||||
{
|
||||
// TODO: wxApp access
|
||||
|
||||
switch (preset_type) {
|
||||
case Preset::TYPE_FILAMENT:
|
||||
// my $choice_idx = 0;
|
||||
if (p->combos_filament.size() == 1) {
|
||||
// Single filament printer, synchronize the filament presets.
|
||||
// wxTheApp->{preset_bundle}->set_filament_preset(0, wxTheApp->{preset_bundle}->filament->get_selected_preset->name);
|
||||
const std::string &name = wxGetApp().preset_bundle->filaments.get_selected_preset().name;
|
||||
wxGetApp().preset_bundle->set_filament_preset(0, name);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < p->combos_filament.size(); i++) {
|
||||
// wxTheApp->{preset_bundle}->update_platter_filament_ui($choice_idx, $choice);
|
||||
wxGetApp().preset_bundle->update_platter_filament_ui(i, p->combos_filament[i]);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case Preset::TYPE_PRINT:
|
||||
// wxTheApp->{preset_bundle}->print->update_platter_ui($choosers[0]);
|
||||
wxGetApp().preset_bundle->prints.update_platter_ui(p->combo_print);
|
||||
break;
|
||||
|
||||
case Preset::TYPE_SLA_MATERIAL:
|
||||
// wxTheApp->{preset_bundle}->sla_material->update_platter_ui($choosers[0]);
|
||||
wxGetApp().preset_bundle->sla_materials.update_platter_ui(p->combo_sla_material);
|
||||
break;
|
||||
|
||||
case Preset::TYPE_PRINTER:
|
||||
// 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]);
|
||||
wxGetApp().preset_bundle->prints.update_platter_ui(p->combo_print);
|
||||
// Update the printer choosers, update the dirty flags.
|
||||
// wxTheApp->{preset_bundle}->printer->update_platter_ui($choosers[0]);
|
||||
wxGetApp().preset_bundle->printers.update_platter_ui(p->combo_printer);
|
||||
// Update the filament choosers to only contain the compatible presets, update the color preview,
|
||||
// update the dirty flags.
|
||||
for (size_t i = 0; i < p->combos_filament.size(); i++) {
|
||||
// wxTheApp->{preset_bundle}->update_platter_filament_ui($choice_idx, $choice);
|
||||
wxGetApp().preset_bundle->update_platter_filament_ui(i, p->combos_filament[i]);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -349,7 +348,7 @@ void Sidebar::update_presets(Preset::Type preset_type)
|
||||
}
|
||||
|
||||
// Synchronize config.ini with the current selections.
|
||||
// wxTheApp->{preset_bundle}->export_selections(wxTheApp->{app_config});
|
||||
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,6 +35,11 @@ namespace GUI {
|
||||
|
||||
static wxString dots("…", wxConvUTF8);
|
||||
|
||||
|
||||
wxDEFINE_EVENT(EVT_TAB_VALUE_CHANGED, wxCommandEvent);
|
||||
wxDEFINE_EVENT(EVT_TAB_PRESETS_CHANGED, SimpleEvent);
|
||||
|
||||
|
||||
// sub new
|
||||
void Tab::create_preset_tab(PresetBundle *preset_bundle)
|
||||
{
|
||||
@ -662,30 +667,27 @@ void Tab::load_key_value(const std::string& opt_key, const boost::any& value, bo
|
||||
update();
|
||||
}
|
||||
|
||||
extern wxFrame *g_wxMainFrame;
|
||||
|
||||
void Tab::on_value_change(const std::string& opt_key, const boost::any& value)
|
||||
{
|
||||
if (m_event_value_change > 0) {
|
||||
wxCommandEvent event(m_event_value_change);
|
||||
std::string str_out = opt_key + " " + m_name;
|
||||
event.SetString(str_out);
|
||||
if (opt_key == "extruders_count")
|
||||
{
|
||||
int val = boost::any_cast<size_t>(value);
|
||||
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);
|
||||
wxCommandEvent event(EVT_TAB_VALUE_CHANGED);
|
||||
event.SetEventObject(this);
|
||||
event.SetString(opt_key);
|
||||
if (opt_key == "extruders_count")
|
||||
{
|
||||
int val = boost::any_cast<size_t>(value);
|
||||
event.SetInt(val);
|
||||
}
|
||||
|
||||
if (opt_key == "printer_technology")
|
||||
{
|
||||
int val = boost::any_cast<PrinterTechnology>(value);
|
||||
event.SetInt(val);
|
||||
wxPostEvent(this, event);
|
||||
return;
|
||||
}
|
||||
|
||||
wxPostEvent(this, event);
|
||||
|
||||
if (opt_key == "fill_density")
|
||||
{
|
||||
boost::any val = get_optgroup(ogFrequentlyChangingParameters)->get_config_value(*m_config, opt_key);
|
||||
@ -734,11 +736,9 @@ 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 (m_event_presets_changed > 0) {
|
||||
wxCommandEvent event(m_event_presets_changed);
|
||||
event.SetString(m_name);
|
||||
g_wxMainFrame->ProcessWindowEvent(event);
|
||||
}
|
||||
wxCommandEvent event(EVT_TAB_PRESETS_CHANGED);
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
update_preset_description_line();
|
||||
}
|
||||
|
||||
|
@ -25,14 +25,15 @@
|
||||
#include <wx/imaglist.h>
|
||||
#include <wx/statbox.h>
|
||||
#include <wx/dataview.h>
|
||||
#include <wx/event.h>
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "BedShapeDialog.hpp"
|
||||
#include "Event.hpp"
|
||||
|
||||
//!enum { ID_TAB_TREE = wxID_HIGHEST + 1 };
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
@ -96,7 +97,10 @@ protected:
|
||||
const wxColour* m_item_color;
|
||||
};
|
||||
|
||||
// Slic3r::GUI::Tab;
|
||||
|
||||
wxDECLARE_EVENT(EVT_TAB_VALUE_CHANGED, wxCommandEvent);
|
||||
wxDECLARE_EVENT(EVT_TAB_PRESETS_CHANGED, SimpleEvent);
|
||||
|
||||
|
||||
using PageShp = std::shared_ptr<Page>;
|
||||
class Tab: public wxPanel
|
||||
@ -178,10 +182,6 @@ protected:
|
||||
|
||||
t_icon_descriptions m_icon_descriptions = {};
|
||||
|
||||
// The two following two event IDs are generated at Plater.pm by calling Wx::NewEventType.
|
||||
wxEventType m_event_value_change = 0;
|
||||
wxEventType m_event_presets_changed = 0;
|
||||
|
||||
bool m_is_modified_values{ false };
|
||||
bool m_is_nonsys_values{ true };
|
||||
bool m_postpone_update_ui {false};
|
||||
@ -211,10 +211,6 @@ public:
|
||||
wxString title() const { return m_title; }
|
||||
std::string name() const { return m_name; }
|
||||
|
||||
// Set the events to the callbacks posted to the main frame window (currently implemented in Perl).
|
||||
void set_event_value_change(wxEventType evt) { m_event_value_change = evt; }
|
||||
void set_event_presets_changed(wxEventType evt) { m_event_presets_changed = evt; }
|
||||
|
||||
void create_preset_tab(PresetBundle *preset_bundle);
|
||||
void load_current_preset();
|
||||
void rebuild_page_tree(bool tree_sel_change_event = false);
|
||||
|
Loading…
Reference in New Issue
Block a user