Added some performance changes

This commit is contained in:
YuSanka 2018-04-18 13:32:21 +02:00
parent d254c39a77
commit 3ca2dfbc1d
8 changed files with 455 additions and 181 deletions

View file

@ -206,6 +206,44 @@ t_config_option_keys ConfigBase::diff(const ConfigBase &other) const
return diff; return diff;
} }
template<class T>
void add_correct_opts_to_diff(const std::string &opt_key, t_config_option_keys& vec, const ConfigBase &other, const ConfigBase *this_c)
{
const T* opt_init = static_cast<const T*>(other.option(opt_key));
const T* opt_cur = static_cast<const T*>(this_c->option(opt_key));
int opt_init_max_id = opt_init->values.size() - 1;
for (int i = 0; i < opt_cur->values.size(); i++)
{
int init_id = i <= opt_init_max_id ? i : 0;
if (opt_cur->values[i] != opt_init->values[init_id])
vec.emplace_back(opt_key + "#" + std::to_string(i));
}
}
t_config_option_keys ConfigBase::deep_diff(const ConfigBase &other) const
{
t_config_option_keys diff;
for (const t_config_option_key &opt_key : this->keys()) {
const ConfigOption *this_opt = this->option(opt_key);
const ConfigOption *other_opt = other.option(opt_key);
if (this_opt != nullptr && other_opt != nullptr && *this_opt != *other_opt)
{
if (opt_key == "bed_shape"){ diff.emplace_back(opt_key); continue; }
switch (other_opt->type())
{
case coInts: add_correct_opts_to_diff<ConfigOptionInts >(opt_key, diff, other, this); break;
case coBools: add_correct_opts_to_diff<ConfigOptionBools >(opt_key, diff, other, this); break;
case coFloats: add_correct_opts_to_diff<ConfigOptionFloats >(opt_key, diff, other, this); break;
case coStrings: add_correct_opts_to_diff<ConfigOptionStrings >(opt_key, diff, other, this); break;
case coPercents:add_correct_opts_to_diff<ConfigOptionPercents >(opt_key, diff, other, this); break;
case coPoints: add_correct_opts_to_diff<ConfigOptionPoints >(opt_key, diff, other, this); break;
default: diff.emplace_back(opt_key); break;
}
}
}
return diff;
}
t_config_option_keys ConfigBase::equal(const ConfigBase &other) const t_config_option_keys ConfigBase::equal(const ConfigBase &other) const
{ {
t_config_option_keys equal; t_config_option_keys equal;

View file

@ -1046,6 +1046,9 @@ public:
void apply_only(const ConfigBase &other, const t_config_option_keys &keys, bool ignore_nonexistent = false); void apply_only(const ConfigBase &other, const t_config_option_keys &keys, bool ignore_nonexistent = false);
bool equals(const ConfigBase &other) const { return this->diff(other).empty(); } bool equals(const ConfigBase &other) const { return this->diff(other).empty(); }
t_config_option_keys diff(const ConfigBase &other) const; t_config_option_keys diff(const ConfigBase &other) const;
// Use deep_diff to correct return of changed options,
// considering individual options for each extruder
t_config_option_keys deep_diff(const ConfigBase &other) const;
t_config_option_keys equal(const ConfigBase &other) const; t_config_option_keys equal(const ConfigBase &other) const;
std::string serialize(const t_config_option_key &opt_key) const; std::string serialize(const t_config_option_key &opt_key) const;
// Set a configuration value from a string, it will call an overridable handle_legacy() // Set a configuration value from a string, it will call an overridable handle_legacy()

View file

@ -179,6 +179,7 @@ AppConfig *g_AppConfig = nullptr;
PresetBundle *g_PresetBundle= nullptr; PresetBundle *g_PresetBundle= nullptr;
wxColour g_color_label_modified; wxColour g_color_label_modified;
wxColour g_color_label_sys; wxColour g_color_label_sys;
wxColour g_color_label_default;
std::vector<Tab *> g_tabs_list; std::vector<Tab *> g_tabs_list;
@ -198,6 +199,7 @@ static void init_label_colours()
g_color_label_modified = wxColour(253, 111, 40); g_color_label_modified = wxColour(253, 111, 40);
g_color_label_sys = wxColour(115, 220, 103); g_color_label_sys = wxColour(115, 220, 103);
} }
g_color_label_default = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
} }
void set_wxapp(wxApp *app) void set_wxapp(wxApp *app)
@ -548,6 +550,10 @@ const wxColour& get_sys_label_clr() {
return g_color_label_sys; return g_color_label_sys;
} }
const wxColour& get_default_label_clr() {
return g_color_label_default;
}
unsigned get_colour_approx_luma(const wxColour &colour) unsigned get_colour_approx_luma(const wxColour &colour)
{ {
double r = colour.Red(); double r = colour.Red();

View file

@ -83,6 +83,7 @@ wxApp* get_app();
const wxColour& get_modified_label_clr(); const wxColour& get_modified_label_clr();
const wxColour& get_sys_label_clr(); const wxColour& get_sys_label_clr();
const wxColour& get_default_label_clr();
unsigned get_colour_approx_luma(const wxColour &colour); unsigned get_colour_approx_luma(const wxColour &colour);
void add_debug_menu(wxMenuBar *menu, int event_language_change); void add_debug_menu(wxMenuBar *menu, int event_language_change);

View file

@ -629,11 +629,13 @@ bool PresetCollection::update_dirty_ui(wxBitmapComboBox *ui)
return was_dirty != is_dirty; return was_dirty != is_dirty;
} }
std::vector<std::string> PresetCollection::dirty_options(const Preset *edited, const Preset *reference) std::vector<std::string> PresetCollection::dirty_options(const Preset *edited, const Preset *reference, const bool is_printer_type /*= false*/)
{ {
std::vector<std::string> changed; std::vector<std::string> changed;
if (edited != nullptr && reference != nullptr) { if (edited != nullptr && reference != nullptr) {
changed = reference->config.diff(edited->config); changed = is_printer_type ?
reference->config.deep_diff(edited->config) :
reference->config.diff(edited->config);
// The "compatible_printers" option key is handled differently from the others: // The "compatible_printers" option key is handled differently from the others:
// It is not mandatory. If the key is missing, it means it is compatible with any printer. // It is not mandatory. If the key is missing, it means it is compatible with any printer.
// If the key exists and it is empty, it means it is compatible with no printer. // If the key exists and it is empty, it means it is compatible with no printer.

View file

@ -253,11 +253,11 @@ public:
// Compare the content of get_selected_preset() with get_edited_preset() configs, return true if they differ. // Compare the content of get_selected_preset() with get_edited_preset() configs, return true if they differ.
bool current_is_dirty() const { return ! this->current_dirty_options().empty(); } bool current_is_dirty() const { return ! this->current_dirty_options().empty(); }
// Compare the content of get_selected_preset() with get_edited_preset() configs, return the list of keys where they differ. // Compare the content of get_selected_preset() with get_edited_preset() configs, return the list of keys where they differ.
std::vector<std::string> current_dirty_options() const std::vector<std::string> current_dirty_options(const bool is_printer_type = false) const
{ return dirty_options(&this->get_edited_preset(), &this->get_selected_preset()); } { return dirty_options(&this->get_edited_preset(), &this->get_selected_preset(), is_printer_type); }
// Compare the content of get_selected_preset() with get_edited_preset() configs, return the list of keys where they differ. // Compare the content of get_selected_preset() with get_edited_preset() configs, return the list of keys where they differ.
std::vector<std::string> current_different_from_parent_options() const std::vector<std::string> current_different_from_parent_options(const bool is_printer_type = false) const
{ return dirty_options(&this->get_edited_preset(), this->get_selected_preset_parent()); } { return dirty_options(&this->get_edited_preset(), this->get_selected_preset_parent(), is_printer_type); }
// Compare the content of get_selected_preset() with get_selected_preset_parent() configs, return the list of keys where they equal. // Compare the content of get_selected_preset() with get_selected_preset_parent() configs, return the list of keys where they equal.
std::vector<std::string> system_equal_options() const; std::vector<std::string> system_equal_options() const;
@ -299,7 +299,7 @@ private:
std::deque<Preset>::const_iterator find_preset_internal(const std::string &name) const std::deque<Preset>::const_iterator find_preset_internal(const std::string &name) const
{ return const_cast<PresetCollection*>(this)->find_preset_internal(name); } { return const_cast<PresetCollection*>(this)->find_preset_internal(name); }
static std::vector<std::string> dirty_options(const Preset *edited, const Preset *reference); static std::vector<std::string> dirty_options(const Preset *edited, const Preset *reference, const bool is_printer_type = false);
// Type of this PresetCollection: TYPE_PRINT, TYPE_FILAMENT or TYPE_PRINTER. // Type of this PresetCollection: TYPE_PRINT, TYPE_FILAMENT or TYPE_PRINTER.
Preset::Type m_type; Preset::Type m_type;

View file

@ -25,6 +25,8 @@
#include "wxExtensions.hpp" #include "wxExtensions.hpp"
#include <wx/wupdlock.h> #include <wx/wupdlock.h>
#include <chrono>
namespace Slic3r { namespace Slic3r {
namespace GUI { namespace GUI {
@ -112,14 +114,14 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle)
m_bmp_value_revert .LoadFile(from_u8(var("action_undo.png")), wxBITMAP_TYPE_PNG); m_bmp_value_revert .LoadFile(from_u8(var("action_undo.png")), wxBITMAP_TYPE_PNG);
m_bmp_white_bullet .LoadFile(from_u8(var("bullet_white.png")), wxBITMAP_TYPE_PNG); m_bmp_white_bullet .LoadFile(from_u8(var("bullet_white.png")), wxBITMAP_TYPE_PNG);
m_undo_btn->SetBitmap(m_bmp_white_bullet); m_undo_btn->SetBitmap(m_bmp_white_bullet);
m_undo_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent){ on_back_to_initial_value(); })); m_undo_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent){ /*on_back_to_initial_value*/on_roll_back_value(); }));
m_undo_to_sys_btn->SetBitmap(m_bmp_white_bullet); m_undo_to_sys_btn->SetBitmap(m_bmp_white_bullet);
m_undo_to_sys_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent){ on_back_to_sys_value(); })); m_undo_to_sys_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent){ /*on_back_to_sys_value*/on_roll_back_value(true); }));
// Colors for ui "decoration" // Colors for ui "decoration"
m_sys_label_clr = get_sys_label_clr(); m_sys_label_clr = get_sys_label_clr();
m_modified_label_clr = get_modified_label_clr(); m_modified_label_clr = get_modified_label_clr();
m_default_text_clr = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); m_default_text_clr = get_default_label_clr();
m_hsizer = new wxBoxSizer(wxHORIZONTAL); m_hsizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(m_hsizer, 0, wxBOTTOM, 3); sizer->Add(m_hsizer, 0, wxBOTTOM, 3);
@ -246,45 +248,108 @@ PageShp Tab::add_options_page(const wxString& title, const std::string& icon, bo
return page; return page;
} }
template<class T> // template<class T>
void add_correct_opts_to_dirty_options(const std::string &opt_key, std::vector<std::string> *vec, TabPrinter *tab) // void add_correct_opts_to_dirty_options(const std::string &opt_key, std::vector<std::string> *vec, TabPrinter *tab)
{ // {
auto opt_init = static_cast<T*>(tab->m_presets->get_selected_preset().config.option(opt_key)); // auto opt_init = static_cast<T*>(tab->m_presets->get_selected_preset().config.option(opt_key));
auto opt_cur = static_cast<T*>(tab->m_config->option(opt_key)); // auto opt_cur = static_cast<T*>(tab->m_config->option(opt_key));
int opt_init_max_id = opt_init->values.size()-1; // int opt_init_max_id = opt_init->values.size()-1;
for (int i = 0; i < opt_cur->values.size(); i++) // for (int i = 0; i < opt_cur->values.size(); i++)
{ // {
int init_id = i <= opt_init_max_id ? i : 0; // int init_id = i <= opt_init_max_id ? i : 0;
if (opt_cur->values[i] != opt_init->values[init_id]) // if (opt_cur->values[i] != opt_init->values[init_id])
vec->emplace_back(opt_key + "#" + std::to_string(i)); // vec->emplace_back(opt_key + "#" + std::to_string(i));
} // }
} // }
//
template<class T> // template<class T>
void add_correct_opts_to_sys_options(const std::string &opt_key, std::vector<std::string> *vec, TabPrinter *tab) // void add_correct_opts_to_sys_options(const std::string &opt_key, std::vector<std::string> *vec, TabPrinter *tab)
{ // {
const Preset* sys_preset = tab->m_presets->get_selected_preset_parent(); // const Preset* sys_preset = tab->m_presets->get_selected_preset_parent();
if (sys_preset == nullptr) // if (sys_preset == nullptr)
return; // return;
T *opt_cur = static_cast<T*>(tab->m_config->option(opt_key)); // T *opt_cur = static_cast<T*>(tab->m_config->option(opt_key));
const T *opt_sys = static_cast<const T*>(sys_preset->config.option(opt_key)); // const T *opt_sys = static_cast<const T*>(sys_preset->config.option(opt_key));
int opt_max_id = opt_sys->values.size()-1; // int opt_max_id = opt_sys->values.size()-1;
for (int i = 0; i < opt_cur->values.size(); i++) // for (int i = 0; i < opt_cur->values.size(); i++)
{ // {
int init_id = i <= opt_max_id ? i : 0; // int init_id = i <= opt_max_id ? i : 0;
if (opt_cur->values[i] == opt_sys->values[init_id]) // if (opt_cur->values[i] == opt_sys->values[init_id])
vec->emplace_back(opt_key + "#" + std::to_string(i)); // vec->emplace_back(opt_key + "#" + std::to_string(i));
} // }
} // }
// Update UI according to changes // Update UI according to changes
void Tab::update_changed_ui() void Tab::update_changed_ui()
{ {
if (m_postpone_update_ui) if (m_postpone_update_ui)
return; return;
auto dirty_options = m_presets->current_dirty_options();
if (name() == "printer"){ const bool is_printer_type = (name() == "printer");
auto m_dirty_options = m_presets->current_dirty_options(is_printer_type);
auto m_nonsys_options = m_presets->current_different_from_parent_options(is_printer_type);
if (is_printer_type){
TabPrinter* tab = static_cast<TabPrinter*>(this);
if (tab->m_initial_extruders_count != tab->m_extruders_count)
m_dirty_options.emplace_back("extruders_count");
if (tab->m_sys_extruders_count != tab->m_extruders_count)
m_nonsys_options.emplace_back("extruders_count");
}
for (auto& it : m_options_list)
it.second = m_opt_status_value;
// auto m_options_list = m_options_list;
for (auto opt_key : m_dirty_options) m_options_list[opt_key] &= ~osInitValue;
for (auto opt_key : m_nonsys_options) m_options_list[opt_key] &= ~osSystemValue;
Freeze();
//update options "decoration"
for (const auto opt : m_options_list/*m_options_list*/)
{
bool is_nonsys_value = false;
bool is_modified_value = true;
const wxBitmap *sys_icon = &m_bmp_value_lock;
const wxBitmap *icon = &m_bmp_value_revert;
const wxColour *color = &m_sys_label_clr;
if ((opt.second & osSystemValue) == 0){
// if (find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end()) {
is_nonsys_value = true;
sys_icon = m_bmp_non_system;
if ((opt.second & osInitValue) != 0)
// if (find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) == m_dirty_options.end())
color = &m_default_text_clr;
else
color = &m_modified_label_clr;
}
if ((opt.second & osInitValue) != 0)
// if (find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) == m_dirty_options.end())
{
is_modified_value = false;
icon = &m_bmp_white_bullet;
}
if (opt.first == "bed_shape" || opt.first == "compatible_printers") {
if (m_colored_Label != nullptr) {
m_colored_Label->SetForegroundColour(*color);
m_colored_Label->Refresh(true);
}
continue;
}
Field* field = get_field(opt.first);
if (field == nullptr) continue;
field->m_is_nonsys_value = is_nonsys_value;
field->m_is_modified_value = is_modified_value;
field->set_undo_bitmap(icon);
field->set_undo_to_sys_bitmap(sys_icon);
field->set_label_colour(color);
}
Thaw();
// m_options_list = m_options_list;
/* auto dirty_options = m_presets->current_dirty_options();
if (){
// Update dirty_options in case changes of Extruder's options // Update dirty_options in case changes of Extruder's options
TabPrinter* tab = static_cast<TabPrinter*>(this); TabPrinter* tab = static_cast<TabPrinter*>(this);
m_dirty_options.resize(0); m_dirty_options.resize(0);
@ -381,71 +446,113 @@ void Tab::update_changed_ui()
field->set_label_colour(color); field->set_label_colour(color);
} }
Thaw(); Thaw();
*/
wxTheApp->CallAfter([this]() { wxTheApp->CallAfter([this]() {
update_changed_tree_ui(); update_changed_tree_ui();
}); });
} }
void Tab::init_options_list()
{
if (!m_options_list.empty())
m_options_list.clear();
for (const auto opt_key : m_config->keys())
m_options_list.emplace(opt_key, m_opt_status_value);
}
template<class T> template<class T>
void add_correct_opts_to_full_options_list(const std::string &opt_key, std::vector<std::string> *vec, TabPrinter *tab) void add_correct_opts_to_options_list(const std::string &opt_key, std::map<std::string, int>& map, TabPrinter *tab, const int& value)
{ {
T *opt_cur = static_cast<T*>(tab->m_config->option(opt_key)); T *opt_cur = static_cast<T*>(tab->m_config->option(opt_key));
for (int i = 0; i < opt_cur->values.size(); i++) for (int i = 0; i < opt_cur->values.size(); i++)
vec->emplace_back(opt_key + "#" + std::to_string(i)); map.emplace(opt_key + "#" + std::to_string(i), value);
} }
void Tab::update_full_options_list() void TabPrinter::init_options_list()
{ {
if (!m_full_options_list.empty()) if (!m_options_list.empty())
m_full_options_list.resize(0); m_options_list.clear();
if (m_name != "printer"){
m_full_options_list = m_config->keys();
return;
}
TabPrinter* tab = static_cast<TabPrinter*>(this);
for (const auto opt_key : m_config->keys()) for (const auto opt_key : m_config->keys())
{ {
if (opt_key == "bed_shape"){ if (opt_key == "bed_shape"){
m_full_options_list.emplace_back(opt_key); m_options_list.emplace(opt_key, m_opt_status_value);
continue; continue;
} }
switch (m_config->option(opt_key)->type()) switch (m_config->option(opt_key)->type())
{ {
case coInts: add_correct_opts_to_full_options_list<ConfigOptionInts >(opt_key, &m_full_options_list, tab); break; case coInts: add_correct_opts_to_options_list<ConfigOptionInts >(opt_key, m_options_list, this, m_opt_status_value); break;
case coBools: add_correct_opts_to_full_options_list<ConfigOptionBools >(opt_key, &m_full_options_list, tab); break; case coBools: add_correct_opts_to_options_list<ConfigOptionBools >(opt_key, m_options_list, this, m_opt_status_value); break;
case coFloats: add_correct_opts_to_full_options_list<ConfigOptionFloats >(opt_key, &m_full_options_list, tab); break; case coFloats: add_correct_opts_to_options_list<ConfigOptionFloats >(opt_key, m_options_list, this, m_opt_status_value); break;
case coStrings: add_correct_opts_to_full_options_list<ConfigOptionStrings >(opt_key, &m_full_options_list, tab); break; case coStrings: add_correct_opts_to_options_list<ConfigOptionStrings >(opt_key, m_options_list, this, m_opt_status_value); break;
case coPercents:add_correct_opts_to_full_options_list<ConfigOptionPercents >(opt_key, &m_full_options_list, tab); break; case coPercents:add_correct_opts_to_options_list<ConfigOptionPercents >(opt_key, m_options_list, this, m_opt_status_value); break;
case coPoints: add_correct_opts_to_full_options_list<ConfigOptionPoints >(opt_key, &m_full_options_list, tab); break; case coPoints: add_correct_opts_to_options_list<ConfigOptionPoints >(opt_key, m_options_list, this, m_opt_status_value); break;
default: m_full_options_list.emplace_back(opt_key); break; default: m_options_list.emplace(opt_key, m_opt_status_value); break;
} }
} }
m_full_options_list.emplace_back("extruders_count"); m_options_list.emplace("extruders_count", m_opt_status_value);
} }
void Tab::update_sys_ui_after_sel_preset()
{ // template<class T>
const wxColour* clr = &m_default_text_clr; // void add_correct_opts_to_full_options_list(const std::string &opt_key, std::vector<std::string> *vec, TabPrinter *tab)
for (const auto opt_key : m_full_options_list){ // {
Field* field = get_field(opt_key); // T *opt_cur = static_cast<T*>(tab->m_config->option(opt_key));
if (field != nullptr){ // for (int i = 0; i < opt_cur->values.size(); i++)
field->set_undo_to_sys_bitmap(m_bmp_non_system); // vec->emplace_back(opt_key + "#" + std::to_string(i));
field->m_is_nonsys_value = true; // }
field->set_label_colour(clr);
} // void Tab::update_full_options_list()
} // {
m_sys_options.resize(0); // if (!m_full_options_list.empty())
} // m_full_options_list.resize(0);
//
// if (m_name != "printer"){
// m_full_options_list = m_config->keys();
// return;
// }
//
// TabPrinter* tab = static_cast<TabPrinter*>(this);
// for (const auto opt_key : m_config->keys())
// {
// if (opt_key == "bed_shape"){
// m_full_options_list.emplace_back(opt_key);
// continue;
// }
// switch (m_config->option(opt_key)->type())
// {
// case coInts: add_correct_opts_to_full_options_list<ConfigOptionInts >(opt_key, &m_full_options_list, tab); break;
// case coBools: add_correct_opts_to_full_options_list<ConfigOptionBools >(opt_key, &m_full_options_list, tab); break;
// case coFloats: add_correct_opts_to_full_options_list<ConfigOptionFloats >(opt_key, &m_full_options_list, tab); break;
// case coStrings: add_correct_opts_to_full_options_list<ConfigOptionStrings >(opt_key, &m_full_options_list, tab); break;
// case coPercents:add_correct_opts_to_full_options_list<ConfigOptionPercents >(opt_key, &m_full_options_list, tab); break;
// case coPoints: add_correct_opts_to_full_options_list<ConfigOptionPoints >(opt_key, &m_full_options_list, tab); break;
// default: m_full_options_list.emplace_back(opt_key); break;
// }
// }
// m_full_options_list.emplace_back("extruders_count");
// }
// void Tab::update_sys_ui_after_sel_preset()
// {
// const wxColour* clr = &m_default_text_clr;
// for (const auto opt_key : m_full_options_list){
// Field* field = get_field(opt_key);
// if (field != nullptr){
// field->set_undo_to_sys_bitmap(m_bmp_non_system);
// field->m_is_nonsys_value = true;
// field->set_label_colour(clr);
// }
// }
// m_sys_options.resize(0);
// }
void Tab::get_sys_and_mod_flags(const std::string& opt_key, bool& sys_page, bool& modified_page) void Tab::get_sys_and_mod_flags(const std::string& opt_key, bool& sys_page, bool& modified_page)
{ {
if (sys_page && find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end()) auto opt = m_options_list.find(opt_key);
sys_page = false; if (sys_page) sys_page = (opt->second & osSystemValue) != 0;
if (!modified_page && find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) != m_dirty_options.end()) if (!modified_page) modified_page = (opt->second & osInitValue) == 0;
modified_page = true;
} }
void Tab::update_changed_tree_ui() void Tab::update_changed_tree_ui()
@ -466,7 +573,7 @@ void Tab::update_changed_tree_ui()
get_sys_and_mod_flags(opt_key, sys_page, modified_page); get_sys_and_mod_flags(opt_key, sys_page, modified_page);
} }
} }
if (title == _("Dependencies")){ if (title == _("Dependencies") && name() != "printer"){
get_sys_and_mod_flags("compatible_printers", sys_page, modified_page); get_sys_and_mod_flags("compatible_printers", sys_page, modified_page);
} }
for (auto group : page->m_optgroups) for (auto group : page->m_optgroups)
@ -478,12 +585,13 @@ void Tab::update_changed_tree_ui()
get_sys_and_mod_flags(opt_key, sys_page, modified_page); get_sys_and_mod_flags(opt_key, sys_page, modified_page);
} }
} }
if (sys_page)
m_treectrl->SetItemTextColour(cur_item, get_sys_label_clr()); const wxColor *clr = sys_page ? &m_sys_label_clr :
else if (modified_page) modified_page ? &m_modified_label_clr :
m_treectrl->SetItemTextColour(cur_item, get_modified_label_clr()); &m_default_text_clr;
else
m_treectrl->SetItemTextColour(cur_item, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); if (page->set_item_colour(clr))
m_treectrl->SetItemTextColour(cur_item, *clr);
page->m_is_nonsys_values = !sys_page; page->m_is_nonsys_values = !sys_page;
page->m_is_modified_values = modified_page; page->m_is_modified_values = modified_page;
@ -506,53 +614,17 @@ void Tab::update_undo_buttons()
m_undo_to_sys_btn->SetBitmap(m_is_nonsys_values ? *m_bmp_non_system : m_bmp_value_lock); m_undo_to_sys_btn->SetBitmap(m_is_nonsys_values ? *m_bmp_non_system : m_bmp_value_lock);
} }
void Tab::on_back_to_initial_value() void Tab::on_roll_back_value(const bool to_sys /*= true*/)
{
if (!m_is_modified_values) return;
m_postpone_update_ui = true;
auto selection = m_treectrl->GetItemText(m_treectrl->GetSelection());
for (auto page : m_pages)
if (page->title() == selection) {
for (auto group : page->m_optgroups){
if (group->title == _("Capabilities")){
if (find(m_dirty_options.begin(), m_dirty_options.end(), "extruders_count") != m_dirty_options.end())
group->back_to_initial_value("extruders_count");
}
if (group->title == _("Size and coordinates")){
if (find(m_dirty_options.begin(), m_dirty_options.end(), "bed_shape") != m_dirty_options.end()){
group->back_to_initial_value("bed_shape");
load_key_value("bed_shape", true/*some value*/, true);
}
}
if (group->title == _("Profile dependencies")){
if (find(m_dirty_options.begin(), m_dirty_options.end(), "compatible_printers") != m_dirty_options.end()){
group->back_to_initial_value("compatible_printers");
load_key_value("compatible_printers", true/*some value*/, true);
bool is_empty = m_config->option<ConfigOptionStrings>("compatible_printers")->values.empty();
m_compatible_printers_checkbox->SetValue(is_empty);
is_empty ? m_compatible_printers_btn->Disable() : m_compatible_printers_btn->Enable();
}
}
for (t_opt_map::iterator it = group->m_opt_map.begin(); it != group->m_opt_map.end(); ++it) {
const std::string& opt_key = it->first;
if (find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) != m_dirty_options.end())
group->back_to_initial_value(opt_key);
}
}
break;
}
m_postpone_update_ui = false;
update_changed_ui();
}
void Tab::on_back_to_sys_value()
{ {
int os;
if (to_sys) {
if (!m_is_nonsys_values) return; if (!m_is_nonsys_values) return;
os = osSystemValue;
}
else {
if (!m_is_modified_values) return;
os = osInitValue;
}
m_postpone_update_ui = true; m_postpone_update_ui = true;
@ -561,18 +633,19 @@ void Tab::on_back_to_sys_value()
if (page->title() == selection) { if (page->title() == selection) {
for (auto group : page->m_optgroups){ for (auto group : page->m_optgroups){
if (group->title == _("Capabilities")){ if (group->title == _("Capabilities")){
if (find(m_sys_options.begin(), m_sys_options.end(), "extruders_count") == m_sys_options.end()) if ((m_options_list["extruders_count"] & os) == 0)
group->back_to_sys_value("extruders_count"); to_sys ? group->back_to_sys_value("extruders_count") : group->back_to_initial_value("extruders_count");
} }
if (group->title == _("Size and coordinates")){ if (group->title == _("Size and coordinates")){
if (find(m_sys_options.begin(), m_sys_options.end(), "bed_shape") == m_sys_options.end()){ if ((m_options_list["bed_shape"] & os) == 0){
group->back_to_sys_value("bed_shape"); to_sys ? group->back_to_sys_value("bed_shape") : group->back_to_initial_value("bed_shape");
load_key_value("bed_shape", true/*some value*/, true); load_key_value("bed_shape", true/*some value*/, true);
} }
} }
if (group->title == _("Profile dependencies")){ if (group->title == _("Profile dependencies") && name() != "printer"){
if (find(m_sys_options.begin(), m_sys_options.end(), "compatible_printers") == m_sys_options.end()){ if ((m_options_list["compatible_printers"] & os) == 0){
group->back_to_sys_value("compatible_printers"); to_sys ? group->back_to_sys_value("compatible_printers") : group->back_to_initial_value("compatible_printers");
load_key_value("compatible_printers", true/*some value*/, true); load_key_value("compatible_printers", true/*some value*/, true);
bool is_empty = m_config->option<ConfigOptionStrings>("compatible_printers")->values.empty(); bool is_empty = m_config->option<ConfigOptionStrings>("compatible_printers")->values.empty();
@ -582,8 +655,8 @@ void Tab::on_back_to_sys_value()
} }
for (t_opt_map::iterator it = group->m_opt_map.begin(); it != group->m_opt_map.end(); ++it) { for (t_opt_map::iterator it = group->m_opt_map.begin(); it != group->m_opt_map.end(); ++it) {
const std::string& opt_key = it->first; const std::string& opt_key = it->first;
if (find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end()) if ((m_options_list[opt_key] & os) == 0)
group->back_to_sys_value(opt_key); to_sys ? group->back_to_sys_value(opt_key) : group->back_to_initial_value(opt_key);
} }
} }
break; break;
@ -593,6 +666,112 @@ void Tab::on_back_to_sys_value()
update_changed_ui(); update_changed_ui();
} }
// void Tab::on_back_to_initial_value()
// {
// if (!m_is_modified_values) return;
// std::chrono::milliseconds ms1 = std::chrono::duration_cast<std::chrono::milliseconds>(
// std::chrono::system_clock::now().time_since_epoch()
// );
//
// m_postpone_update_ui = true;
//
// auto selection = m_treectrl->GetItemText(m_treectrl->GetSelection());
// for (auto page : m_pages)
// if (page->title() == selection) {
// for (auto group : page->m_optgroups){
// if (group->title == _("Capabilities")){
// if (find(m_dirty_options.begin(), m_dirty_options.end(), "extruders_count") != m_dirty_options.end())
// group->back_to_initial_value("extruders_count");
// }
// if (group->title == _("Size and coordinates")){
// if (find(m_dirty_options.begin(), m_dirty_options.end(), "bed_shape") != m_dirty_options.end()){
// group->back_to_initial_value("bed_shape");
// load_key_value("bed_shape", true/*some value*/, true);
// }
//
// }
// if (group->title == _("Profile dependencies")){
// if (find(m_dirty_options.begin(), m_dirty_options.end(), "compatible_printers") != m_dirty_options.end()){
// group->back_to_initial_value("compatible_printers");
// load_key_value("compatible_printers", true/*some value*/, true);
//
// bool is_empty = m_config->option<ConfigOptionStrings>("compatible_printers")->values.empty();
// m_compatible_printers_checkbox->SetValue(is_empty);
// is_empty ? m_compatible_printers_btn->Disable() : m_compatible_printers_btn->Enable();
// }
// }
// for (t_opt_map::iterator it = group->m_opt_map.begin(); it != group->m_opt_map.end(); ++it) {
// const std::string& opt_key = it->first;
// if (find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) != m_dirty_options.end())
// group->back_to_initial_value(opt_key);
// }
// }
// break;
// }
//
// std::chrono::milliseconds ms2 = std::chrono::duration_cast<std::chrono::milliseconds>(
// std::chrono::system_clock::now().time_since_epoch()
// );
//
// m_postpone_update_ui = false;
// update_changed_ui();
//
// std::chrono::milliseconds ms3 = std::chrono::duration_cast<std::chrono::milliseconds>(
// std::chrono::system_clock::now().time_since_epoch()
// );
//
// auto roll_back_duration = std::chrono::microseconds(ms2 - ms1).count();
// auto update_ui_duration = std::chrono::microseconds(ms3 - ms2).count();
// printf("back_to init_duration duration = %lld ms \n", roll_back_duration);
// printf("update_ui_duration duration = %lld ms \n", update_ui_duration);
//
// // m_postpone_update_ui = false;
// // update_changed_ui();
// }
//
// void Tab::on_back_to_sys_value()
// {
// if (!m_is_nonsys_values) return;
//
// m_postpone_update_ui = true;
//
// auto selection = m_treectrl->GetItemText(m_treectrl->GetSelection());
// for (auto page : m_pages)
// if (page->title() == selection) {
// for (auto group : page->m_optgroups) {
// if (group->title == _("Capabilities")){
// if (find(m_sys_options.begin(), m_sys_options.end(), "extruders_count") == m_sys_options.end())
// group->back_to_sys_value("extruders_count");
// }
// if (group->title == _("Size and coordinates")){
// if (find(m_sys_options.begin(), m_sys_options.end(), "bed_shape") == m_sys_options.end()){
// group->back_to_sys_value("bed_shape");
// load_key_value("bed_shape", true/*some value*/, true);
// }
// }
// if (group->title == _("Profile dependencies")){
// if (find(m_sys_options.begin(), m_sys_options.end(), "compatible_printers") == m_sys_options.end()){
// group->back_to_sys_value("compatible_printers");
// load_key_value("compatible_printers", true/*some value*/, true);
//
// bool is_empty = m_config->option<ConfigOptionStrings>("compatible_printers")->values.empty();
// m_compatible_printers_checkbox->SetValue(is_empty);
// is_empty ? m_compatible_printers_btn->Disable() : m_compatible_printers_btn->Enable();
// }
// }
// for (t_opt_map::iterator it = group->m_opt_map.begin(); it != group->m_opt_map.end(); ++it) {
// const std::string& opt_key = it->first;
// if (find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end())
// group->back_to_sys_value(opt_key);
// }
// }
// break;
// }
//
// m_postpone_update_ui = false;
// update_changed_ui();
// }
// Update the combo box label of the selected preset based on its "dirty" state, // Update the combo box label of the selected preset based on its "dirty" state,
// comparing the selected preset config with $self->{config}. // comparing the selected preset config with $self->{config}.
void Tab::update_dirty(){ void Tab::update_dirty(){
@ -1698,12 +1877,34 @@ void TabPrinter::extruders_count_changed(size_t extruders_count){
} }
void TabPrinter::build_extruder_pages(){ void TabPrinter::build_extruder_pages(){
for (auto extruder_idx = m_extruder_pages.size(); extruder_idx < m_extruders_count; ++extruder_idx){ if (m_extruders_count_old == m_extruders_count)
{
// if we have a single extruder MM setup, add a page with configuration options:
for (int i = 0; i < m_pages.size(); ++i) // first make sure it's not there already
if (m_pages[i]->title().find(_(L("Single extruder MM setup"))) != std::string::npos) {
m_pages.erase(m_pages.begin() + i);
break;
}
if (m_extruders_count > 1 && m_config->opt_bool("single_extruder_multi_material")) {
// create a page, but pretend it's an extruder page, so we can add it to m_pages ourselves
auto page = add_options_page(_(L("Single extruder MM setup")), "printer_empty.png", true);
auto optgroup = page->new_optgroup(_(L("Single extruder multimaterial parameters")));
optgroup->append_single_option_line("cooling_tube_retraction");
optgroup->append_single_option_line("cooling_tube_length");
optgroup->append_single_option_line("parking_pos_retraction");
m_pages.insert(m_pages.end()-2, page);
}
rebuild_page_tree();
return;
}
for (auto extruder_idx = m_extruders_count_old; extruder_idx < m_extruders_count; ++extruder_idx){
//# build page //# build page
char buf[MIN_BUF_LENGTH_FOR_L]; char buf[MIN_BUF_LENGTH_FOR_L];
sprintf(buf, _CHB(L("Extruder %d")), extruder_idx + 1); sprintf(buf, _CHB(L("Extruder %d")), extruder_idx + 1);
auto page = add_options_page(from_u8(buf), "funnel.png", true); auto page = add_options_page(from_u8(buf), "funnel.png", true);
m_extruder_pages.push_back(page); m_pages.insert(m_pages.begin() + 2+extruder_idx, page);
// m_extruder_pages.push_back(page);
auto optgroup = page->new_optgroup(_(L("Size"))); auto optgroup = page->new_optgroup(_(L("Size")));
optgroup->append_single_option_line("nozzle_diameter", extruder_idx); optgroup->append_single_option_line("nozzle_diameter", extruder_idx);
@ -1741,36 +1942,31 @@ void TabPrinter::build_extruder_pages(){
} }
// # remove extra pages // # remove extra pages
if (m_extruders_count <= m_extruder_pages.size()) { // if (m_extruders_count <= m_extruders_count_old) {
m_extruder_pages.resize(m_extruders_count); // m_extruder_pages.resize(m_extruders_count);
} // }
if (m_extruders_count < m_extruders_count_old)
m_pages.erase(m_pages.begin() + 2 + m_extruders_count, m_pages.begin() + 2 + m_extruders_count_old);
m_extruders_count_old = m_extruders_count;
// # rebuild page list // # rebuild page list
PageShp page_note = m_pages.back(); // PageShp page_note = m_pages.back();
m_pages.pop_back(); // m_pages.pop_back();
while (m_pages.back()->title().find(_(L("Extruder"))) != std::string::npos) // PageShp page_depend = m_pages.back();
m_pages.pop_back(); // m_pages.pop_back();
for (auto page_extruder : m_extruder_pages) // auto counter = m_extruders_count_old;
m_pages.push_back(page_extruder); // while (counter > m_extruders_count/*m_pages.back()->title().find(_(L("Extruder"))) != std::string::npos*/){
m_pages.push_back(page_note); // m_pages.pop_back();
// --counter;
{ // }
// if we have a single extruder MM setup, add a page with configuration options: // // for (auto page_extruder : m_extruder_pages)
for (int i=0;i<m_pages.size();++i) // first make sure it's not there already // // m_pages.push_back(page_extruder);
if (m_pages[i]->title().find(_(L("Single extruder MM setup"))) != std::string::npos) { // for (auto extruder_idx = m_extruders_count_old; extruder_idx < m_extruders_count; ++extruder_idx)
m_pages.erase(m_pages.begin()+i); // m_pages.push_back(m_extruder_pages[extruder_idx]);
break; // m_pages.push_back(page_note);
} // m_pages.push_back(page_depend);
if ( m_extruder_pages.size()>1 && m_config->opt_bool("single_extruder_multi_material")) {
// create a page, but pretend it's an extruder page, so we can add it to m_pages ourselves
auto page = add_options_page(_(L("Single extruder MM setup")), "printer_empty.png",true);
auto optgroup = page->new_optgroup(_(L("Single extruder multimaterial parameters")));
optgroup->append_single_option_line("cooling_tube_retraction");
optgroup->append_single_option_line("cooling_tube_length");
optgroup->append_single_option_line("parking_pos_retraction");
m_pages.insert(m_pages.begin()+1,page);
}
}
rebuild_page_tree(); rebuild_page_tree();
} }
@ -1899,8 +2095,10 @@ void Tab::load_current_preset()
static_cast<TabPrinter*>(this)->m_sys_extruders_count = parent_preset == nullptr ? 0 : static_cast<TabPrinter*>(this)->m_sys_extruders_count = parent_preset == nullptr ? 0 :
static_cast<const ConfigOptionFloats*>(parent_preset->config.option("nozzle_diameter"))->values.size(); static_cast<const ConfigOptionFloats*>(parent_preset->config.option("nozzle_diameter"))->values.size();
} }
update_sys_ui_after_sel_preset(); // update_sys_ui_after_sel_preset();
update_full_options_list(); // update_full_options_list();
m_opt_status_value = (m_presets->get_selected_preset_parent() ? osSystemValue : 0) | osInitValue;
init_options_list();
update_changed_ui(); update_changed_ui();
}); });
} }
@ -1917,6 +2115,7 @@ void Tab::rebuild_page_tree()
for (auto p : m_pages) for (auto p : m_pages)
{ {
auto itemId = m_treectrl->AppendItem(rootItem, p->title(), p->iconID()); auto itemId = m_treectrl->AppendItem(rootItem, p->title(), p->iconID());
m_treectrl->SetItemTextColour(itemId, p->get_item_colour());
if (p->title() == selected) { if (p->title() == selected) {
m_disable_tree_sel_changed_event = 1; m_disable_tree_sel_changed_event = 1;
m_treectrl->SelectItem(itemId); m_treectrl->SelectItem(itemId);

View file

@ -51,6 +51,7 @@ public:
{ {
Create(m_parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); Create(m_parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
m_vsizer = new wxBoxSizer(wxVERTICAL); m_vsizer = new wxBoxSizer(wxVERTICAL);
m_item_color = &get_default_label_clr();
SetSizer(m_vsizer); SetSizer(m_vsizer);
} }
~Page(){} ~Page(){}
@ -71,6 +72,22 @@ public:
Field* get_field(const t_config_option_key& opt_key, int opt_index = -1) const; Field* get_field(const t_config_option_key& opt_key, int opt_index = -1) const;
bool set_value(const t_config_option_key& opt_key, const boost::any& value); bool set_value(const t_config_option_key& opt_key, const boost::any& value);
ConfigOptionsGroupShp new_optgroup(const wxString& title, int noncommon_label_width = -1); ConfigOptionsGroupShp new_optgroup(const wxString& title, int noncommon_label_width = -1);
bool set_item_colour(const wxColour *clr) {
if (m_item_color != clr) {
m_item_color = clr;
return true;
}
return false;
}
const wxColour get_item_colour() {
return *m_item_color;
}
protected:
// Color of TreeCtrlItem. The wxColour will be updated only if the new wxColour pointer differs from the currently rendered one.
const wxColour* m_item_color;
}; };
// Slic3r::GUI::Tab; // Slic3r::GUI::Tab;
@ -125,9 +142,13 @@ protected:
bool m_no_controller; bool m_no_controller;
std::vector<std::string> m_reload_dependent_tabs = {}; std::vector<std::string> m_reload_dependent_tabs = {};
std::vector<std::string> m_dirty_options = {}; // std::vector<std::string> m_dirty_options = {};
std::vector<std::string> m_sys_options = {}; // std::vector<std::string> m_nonsys_options = {};
std::vector<std::string> m_full_options_list = {}; // std::vector<std::string> m_sys_options = {};
// std::vector<std::string> m_full_options_list = {};
enum OptStatus { osSystemValue = 1, osInitValue = 2 };
std::map<std::string, int> m_options_list;
int m_opt_status_value;
// The two following two event IDs are generated at Plater.pm by calling Wx::NewEventType. // The two following two event IDs are generated at Plater.pm by calling Wx::NewEventType.
wxEventType m_event_value_change = 0; wxEventType m_event_value_change = 0;
@ -182,14 +203,15 @@ public:
void update_show_hide_incompatible_button(); void update_show_hide_incompatible_button();
void update_ui_from_settings(); void update_ui_from_settings();
void update_changed_ui(); void update_changed_ui();
void update_full_options_list(); // void update_full_options_list();
void update_sys_ui_after_sel_preset(); // void update_sys_ui_after_sel_preset();
void get_sys_and_mod_flags(const std::string& opt_key, bool& sys_page, bool& modified_page); void get_sys_and_mod_flags(const std::string& opt_key, bool& sys_page, bool& modified_page);
void update_changed_tree_ui(); void update_changed_tree_ui();
void update_undo_buttons(); void update_undo_buttons();
void on_back_to_initial_value(); void on_roll_back_value(const bool to_sys = false);
void on_back_to_sys_value(); // void on_back_to_initial_value();
// void on_back_to_sys_value();
PageShp add_options_page(const wxString& title, const std::string& icon, bool is_extruder_pages = false); PageShp add_options_page(const wxString& title, const std::string& icon, bool is_extruder_pages = false);
@ -197,6 +219,7 @@ public:
virtual void on_preset_loaded(){} virtual void on_preset_loaded(){}
virtual void build() = 0; virtual void build() = 0;
virtual void update() = 0; virtual void update() = 0;
virtual void init_options_list();
void load_initial_data(); void load_initial_data();
void update_dirty(); void update_dirty();
void update_tab_ui(); void update_tab_ui();
@ -265,9 +288,10 @@ public:
wxButton* m_octoprint_host_test_btn; wxButton* m_octoprint_host_test_btn;
size_t m_extruders_count; size_t m_extruders_count;
size_t m_extruders_count_old = 0;
size_t m_initial_extruders_count; size_t m_initial_extruders_count;
size_t m_sys_extruders_count; size_t m_sys_extruders_count;
std::vector<PageShp> m_extruder_pages; // std::vector<PageShp> m_extruder_pages;
TabPrinter() {} TabPrinter() {}
TabPrinter(wxNotebook* parent, bool no_controller) : Tab(parent, _(L("Printer Settings")), "printer", no_controller) {} TabPrinter(wxNotebook* parent, bool no_controller) : Tab(parent, _(L("Printer Settings")), "printer", no_controller) {}
@ -279,6 +303,7 @@ public:
void extruders_count_changed(size_t extruders_count); void extruders_count_changed(size_t extruders_count);
void build_extruder_pages(); void build_extruder_pages();
void on_preset_loaded() override; void on_preset_loaded() override;
void init_options_list() override;
}; };
class SavePresetWindow :public wxDialog class SavePresetWindow :public wxDialog