Fixed bug with update (part of #1801)
This commit is contained in:
parent
73daf085e6
commit
26833ee641
6 changed files with 92 additions and 28 deletions
|
@ -147,11 +147,11 @@ void MainFrame::init_tabpanel()
|
|||
wxGetApp().obj_list()->create_popup_menus();
|
||||
|
||||
// The following event is emited by Tab implementation on config value change.
|
||||
Bind(EVT_TAB_VALUE_CHANGED, &MainFrame::on_value_changed, this);
|
||||
Bind(EVT_TAB_VALUE_CHANGED, &MainFrame::on_value_changed, this); // #ys_FIXME_to_delete
|
||||
|
||||
// The following event is emited by Tab on preset selection,
|
||||
// or when the preset's "modified" status changes.
|
||||
Bind(EVT_TAB_PRESETS_CHANGED, &MainFrame::on_presets_changed, this);
|
||||
Bind(EVT_TAB_PRESETS_CHANGED, &MainFrame::on_presets_changed, this); // #ys_FIXME_to_delete
|
||||
|
||||
create_preset_tabs();
|
||||
|
||||
|
@ -833,6 +833,7 @@ void MainFrame::select_view(const std::string& direction)
|
|||
m_plater->select_view(direction);
|
||||
}
|
||||
|
||||
// #ys_FIXME_to_delete
|
||||
void MainFrame::on_presets_changed(SimpleEvent &event)
|
||||
{
|
||||
auto *tab = dynamic_cast<Tab*>(event.GetEventObject());
|
||||
|
@ -857,6 +858,7 @@ void MainFrame::on_presets_changed(SimpleEvent &event)
|
|||
}
|
||||
}
|
||||
|
||||
// #ys_FIXME_to_delete
|
||||
void MainFrame::on_value_changed(wxCommandEvent& event)
|
||||
{
|
||||
auto *tab = dynamic_cast<Tab*>(event.GetEventObject());
|
||||
|
@ -880,6 +882,20 @@ void MainFrame::on_value_changed(wxCommandEvent& event)
|
|||
}
|
||||
}
|
||||
|
||||
void MainFrame::on_config_changed(DynamicPrintConfig* config) const
|
||||
{
|
||||
if (m_plater) {
|
||||
m_plater->on_config_change(*config); // propagate config change events to the plater
|
||||
}
|
||||
|
||||
// Don't save while loading for the first time.
|
||||
if (m_loaded) {
|
||||
AppConfig &cfg = *wxGetApp().app_config;
|
||||
if (cfg.get("autosave") == "1")
|
||||
cfg.save();
|
||||
}
|
||||
}
|
||||
|
||||
// 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()
|
||||
|
|
|
@ -96,6 +96,8 @@ public:
|
|||
void load_config(const DynamicPrintConfig& config);
|
||||
void select_tab(size_t tab) const;
|
||||
void select_view(const std::string& direction);
|
||||
// Propagate changed configuration from the Tab to the Platter and save changes to the AppConfig
|
||||
void on_config_changed(DynamicPrintConfig* cfg) const ;
|
||||
|
||||
PrintHostQueueDialog* printhost_queue_dlg() { return m_printhost_queue_dlg; }
|
||||
|
||||
|
|
|
@ -510,7 +510,7 @@ struct Sidebar::priv
|
|||
|
||||
void Sidebar::priv::show_preset_comboboxes()
|
||||
{
|
||||
const bool showSLA = plater->printer_technology() == ptSLA;
|
||||
const bool showSLA = wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA;
|
||||
|
||||
wxWindowUpdateLocker noUpdates_scrolled(scrolled->GetParent());
|
||||
|
||||
|
@ -671,11 +671,12 @@ void Sidebar::remove_unused_filament_combos(const int current_extruder_count)
|
|||
void Sidebar::update_presets(Preset::Type preset_type)
|
||||
{
|
||||
PresetBundle &preset_bundle = *wxGetApp().preset_bundle;
|
||||
const auto print_tech = preset_bundle.printers.get_edited_preset().printer_technology();
|
||||
|
||||
switch (preset_type) {
|
||||
case Preset::TYPE_FILAMENT:
|
||||
{
|
||||
const int extruder_cnt = p->plater->printer_technology() != ptFFF ? 1 :
|
||||
const int extruder_cnt = print_tech != ptFFF ? 1 :
|
||||
dynamic_cast<ConfigOptionFloats*>(preset_bundle.printers.get_edited_preset().config.option("nozzle_diameter"))->values.size();
|
||||
const int filament_cnt = p->combos_filament.size() > extruder_cnt ? extruder_cnt : p->combos_filament.size();
|
||||
|
||||
|
@ -707,7 +708,7 @@ void Sidebar::update_presets(Preset::Type preset_type)
|
|||
case Preset::TYPE_PRINTER:
|
||||
{
|
||||
// Update the print choosers to only contain the compatible presets, update the dirty flags.
|
||||
if (p->plater->printer_technology() == ptFFF)
|
||||
if (print_tech == ptFFF)
|
||||
preset_bundle.prints.update_platter_ui(p->combo_print);
|
||||
else {
|
||||
preset_bundle.sla_prints.update_platter_ui(p->combo_sla_print);
|
||||
|
@ -720,7 +721,7 @@ void Sidebar::update_presets(Preset::Type preset_type)
|
|||
p->combo_printer->check_selection();
|
||||
// Update the filament choosers to only contain the compatible presets, update the color preview,
|
||||
// update the dirty flags.
|
||||
if (p->plater->printer_technology() == ptFFF) {
|
||||
if (print_tech == ptFFF) {
|
||||
for (size_t i = 0; i < p->combos_filament.size(); ++ i)
|
||||
preset_bundle.update_platter_filament_ui(i, p->combos_filament[i]);
|
||||
}
|
||||
|
|
|
@ -1435,7 +1435,8 @@ bool PresetBundle::parse_color(const std::string &scolor, unsigned char *rgb_out
|
|||
|
||||
void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, GUI::PresetComboBox *ui)
|
||||
{
|
||||
if (ui == nullptr || this->printers.get_edited_preset().printer_technology() == ptSLA)
|
||||
if (ui == nullptr || this->printers.get_edited_preset().printer_technology() == ptSLA ||
|
||||
this->filament_presets.size() <= idx_extruder )
|
||||
return;
|
||||
|
||||
unsigned char rgb[3];
|
||||
|
|
|
@ -669,7 +669,6 @@ void Tab::load_config(const DynamicPrintConfig& config)
|
|||
bool modified = 0;
|
||||
for(auto opt_key : m_config->diff(config)) {
|
||||
m_config->set_key_value(opt_key, config.option(opt_key)->clone());
|
||||
m_dirty_options.emplace(opt_key);
|
||||
modified = 1;
|
||||
}
|
||||
if (modified) {
|
||||
|
@ -752,8 +751,6 @@ void Tab::load_key_value(const std::string& opt_key, const boost::any& value, bo
|
|||
|
||||
void Tab::on_value_change(const std::string& opt_key, const boost::any& value)
|
||||
{
|
||||
m_dirty_options.erase(opt_key);
|
||||
|
||||
ConfigOptionsGroup* og_freq_chng_params = wxGetApp().sidebar().og_freq_chng_params(supports_printer_technology(ptFFF));
|
||||
if (opt_key == "fill_density" || opt_key == "supports_enable" || opt_key == "pad_enable")
|
||||
{
|
||||
|
@ -778,22 +775,29 @@ void Tab::on_value_change(const std::string& opt_key, const boost::any& value)
|
|||
if (opt_key == "wipe_tower" || opt_key == "single_extruder_multi_material" || opt_key == "extruders_count" )
|
||||
update_wiping_button_visibility();
|
||||
|
||||
if (opt_key == "extruders_count")
|
||||
wxGetApp().plater()->on_extruders_change(boost::any_cast<size_t>(value));
|
||||
|
||||
update();
|
||||
|
||||
// #ys_FIXME_to_delete
|
||||
// Post event to the Plater after updating of the all dirty options
|
||||
// It helps to avoid needless schedule_background_processing
|
||||
if (update_completed()) {
|
||||
wxCommandEvent event(EVT_TAB_VALUE_CHANGED);
|
||||
event.SetEventObject(this);
|
||||
event.SetString(opt_key);
|
||||
if (opt_key == "extruders_count")
|
||||
{
|
||||
const int val = boost::any_cast<size_t>(value);
|
||||
event.SetInt(val);
|
||||
}
|
||||
|
||||
wxPostEvent(this, event);
|
||||
}
|
||||
// if (update_completed())
|
||||
// if (m_update_stack.empty())
|
||||
// {
|
||||
// // wxCommandEvent event(EVT_TAB_VALUE_CHANGED);
|
||||
// // event.SetEventObject(this);
|
||||
// // event.SetString(opt_key);
|
||||
// // if (opt_key == "extruders_count")
|
||||
// // {
|
||||
// // const int val = boost::any_cast<size_t>(value);
|
||||
// // event.SetInt(val);
|
||||
// // }
|
||||
// //
|
||||
// // wxPostEvent(this, event);
|
||||
// wxGetApp().mainframe->on_value_changed(m_config);
|
||||
// }
|
||||
}
|
||||
|
||||
// Show/hide the 'purging volumes' button
|
||||
|
@ -827,9 +831,14 @@ void Tab::on_presets_changed()
|
|||
wxGetApp().get_tab(t)->load_current_preset();
|
||||
}
|
||||
|
||||
wxCommandEvent event(EVT_TAB_PRESETS_CHANGED);
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
// #ys_FIXME_to_delete
|
||||
// wxCommandEvent event(EVT_TAB_PRESETS_CHANGED);
|
||||
// event.SetEventObject(this);
|
||||
// wxPostEvent(this, event);
|
||||
|
||||
// Instead of PostEvent (EVT_TAB_PRESETS_CHANGED) just call update_presets
|
||||
wxGetApp().plater()->sidebar().update_presets(m_type);
|
||||
|
||||
update_preset_description_line();
|
||||
}
|
||||
|
||||
|
@ -1165,6 +1174,7 @@ void TabPrint::update()
|
|||
if (m_preset_bundle->printers.get_selected_preset().printer_technology() == ptSLA)
|
||||
return; // ys_FIXME
|
||||
|
||||
// #ys_FIXME_to_delete
|
||||
//! Temporary workaround for the correct updates of the SpinCtrl (like "perimeters"):
|
||||
// KillFocus() for the wxSpinCtrl use CallAfter function. So,
|
||||
// to except the duplicate call of the update() after dialog->ShowModal(),
|
||||
|
@ -1172,6 +1182,7 @@ void TabPrint::update()
|
|||
// if (is_msg_dlg_already_exist) // ! It looks like a fixed problem after start to using of a m_dirty_options
|
||||
// return; // ! TODO Let delete this part of code after a common aplication testing
|
||||
|
||||
m_update_cnt++;
|
||||
Freeze();
|
||||
|
||||
double fill_density = m_config->option<ConfigOptionPercent>("fill_density")->value;
|
||||
|
@ -1384,6 +1395,10 @@ void TabPrint::update()
|
|||
from_u8(PresetHints::recommended_thin_wall_thickness(*m_preset_bundle)));
|
||||
|
||||
Thaw();
|
||||
m_update_cnt--;
|
||||
|
||||
if (m_update_cnt==0)
|
||||
wxGetApp().mainframe->on_config_changed(m_config);
|
||||
}
|
||||
|
||||
void TabPrint::OnActivate()
|
||||
|
@ -1553,6 +1568,7 @@ void TabFilament::update()
|
|||
if (m_preset_bundle->printers.get_selected_preset().printer_technology() == ptSLA)
|
||||
return; // ys_FIXME
|
||||
|
||||
m_update_cnt++;
|
||||
Freeze();
|
||||
wxString text = from_u8(PresetHints::cooling_description(m_presets->get_edited_preset()));
|
||||
m_cooling_description_line->SetText(text);
|
||||
|
@ -1567,7 +1583,11 @@ void TabFilament::update()
|
|||
|
||||
for (auto el : { "min_fan_speed", "disable_fan_first_layers" })
|
||||
get_field(el)->toggle(fan_always_on);
|
||||
Thaw();
|
||||
Thaw();
|
||||
m_update_cnt--;
|
||||
|
||||
if (m_update_cnt == 0)
|
||||
wxGetApp().mainframe->on_config_changed(m_config);
|
||||
}
|
||||
|
||||
void TabFilament::OnActivate()
|
||||
|
@ -2234,7 +2254,12 @@ void TabPrinter::update_pages()
|
|||
|
||||
void TabPrinter::update()
|
||||
{
|
||||
m_update_cnt++;
|
||||
m_presets->get_edited_preset().printer_technology() == ptFFF ? update_fff() : update_sla();
|
||||
m_update_cnt--;
|
||||
|
||||
if (m_update_cnt == 0)
|
||||
wxGetApp().mainframe->on_config_changed(m_config);
|
||||
}
|
||||
|
||||
void TabPrinter::update_fff()
|
||||
|
@ -3199,6 +3224,14 @@ void TabSLAMaterial::update()
|
|||
{
|
||||
if (m_preset_bundle->printers.get_selected_preset().printer_technology() == ptFFF)
|
||||
return; // #ys_FIXME
|
||||
|
||||
// #ys_FIXME
|
||||
// m_update_cnt++;
|
||||
// ! something to update
|
||||
// m_update_cnt--;
|
||||
//
|
||||
// if (m_update_cnt == 0)
|
||||
wxGetApp().mainframe->on_config_changed(m_config);
|
||||
}
|
||||
|
||||
void TabSLAPrint::build()
|
||||
|
@ -3282,6 +3315,14 @@ void TabSLAPrint::update()
|
|||
{
|
||||
if (m_preset_bundle->printers.get_selected_preset().printer_technology() == ptFFF)
|
||||
return; // #ys_FIXME
|
||||
|
||||
// #ys_FIXME
|
||||
// m_update_cnt++;
|
||||
// ! something to update
|
||||
// m_update_cnt--;
|
||||
//
|
||||
// if (m_update_cnt == 0)
|
||||
wxGetApp().mainframe->on_config_changed(m_config);
|
||||
}
|
||||
|
||||
} // GUI
|
||||
|
|
|
@ -204,7 +204,6 @@ protected:
|
|||
void set_type();
|
||||
|
||||
int m_em_unit;
|
||||
std::set<std::string> m_dirty_options;
|
||||
|
||||
public:
|
||||
PresetBundle* m_preset_bundle;
|
||||
|
@ -213,6 +212,11 @@ public:
|
|||
DynamicPrintConfig* m_config;
|
||||
ogStaticText* m_parent_preset_description_line;
|
||||
wxStaticText* m_colored_Label = nullptr;
|
||||
// Counter for the updating (because of an update() function can have a recursive behavior):
|
||||
// 1. increase value from the very beginning of an update() function
|
||||
// 2. decrease value at the end of an update() function
|
||||
// 3. propagate changed configuration to the Platter when (m_update_cnt == 0) only
|
||||
int m_update_cnt = 0;
|
||||
|
||||
public:
|
||||
Tab(wxNotebook* parent, const wxString& title, const char* name);
|
||||
|
@ -284,7 +288,6 @@ protected:
|
|||
void update_frequently_changed_parameters();
|
||||
void fill_icon_descriptions();
|
||||
void set_tooltips_text();
|
||||
bool update_completed() const { return m_dirty_options.empty(); }
|
||||
};
|
||||
|
||||
class TabPrint : public Tab
|
||||
|
|
Loading…
Reference in a new issue