Updated back_to_initial_value and fixed some bugs for Extruders
This commit is contained in:
parent
dd7712d4d3
commit
38dca8396f
7 changed files with 69 additions and 17 deletions
|
@ -47,7 +47,7 @@ namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
void Field::on_back_to_initial_value()
|
void Field::on_back_to_initial_value()
|
||||||
{
|
{
|
||||||
if (m_back_to_initial_value != nullptr)
|
if (m_back_to_initial_value != nullptr && m_is_modified_value)
|
||||||
m_back_to_initial_value(m_opt_id);
|
m_back_to_initial_value(m_opt_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,8 @@ public:
|
||||||
|
|
||||||
// This is used to avoid recursive invocation of the field change/update by wxWidgets.
|
// This is used to avoid recursive invocation of the field change/update by wxWidgets.
|
||||||
bool m_disable_change_event {false};
|
bool m_disable_change_event {false};
|
||||||
|
// This is used to avoid recursive invocation of the field change/update by wxWidgets.
|
||||||
|
bool m_is_modified_value {false};
|
||||||
|
|
||||||
/// Copy of ConfigOption for deduction purposes
|
/// Copy of ConfigOption for deduction purposes
|
||||||
const ConfigOptionDef m_opt {ConfigOptionDef()};
|
const ConfigOptionDef m_opt {ConfigOptionDef()};
|
||||||
|
|
|
@ -421,9 +421,13 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b
|
||||||
config.set_key_value(opt_key, new ConfigOptionString(boost::any_cast<std::string>(value)));
|
config.set_key_value(opt_key, new ConfigOptionString(boost::any_cast<std::string>(value)));
|
||||||
break;
|
break;
|
||||||
case coStrings:{
|
case coStrings:{
|
||||||
if (opt_key.compare("compatible_printers") == 0){
|
if (opt_key.compare("compatible_printers") == 0 ||
|
||||||
|
config.def()->get(opt_key)->gui_flags.compare("serialized") == 0){
|
||||||
config.option<ConfigOptionStrings>(opt_key)->values.resize(0);
|
config.option<ConfigOptionStrings>(opt_key)->values.resize(0);
|
||||||
for (auto el : boost::any_cast<std::vector<std::string>>(value))
|
std::vector<std::string> values = boost::any_cast<std::vector<std::string>>(value);
|
||||||
|
if (values.size() == 1 && values[0] == "")
|
||||||
|
break;
|
||||||
|
for (auto el : values)
|
||||||
config.option<ConfigOptionStrings>(opt_key)->values.push_back(el);
|
config.option<ConfigOptionStrings>(opt_key)->values.push_back(el);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <wx/numformatter.h>
|
#include <wx/numformatter.h>
|
||||||
|
#include <boost/algorithm/string/split.hpp>
|
||||||
|
#include <boost/algorithm/string/classification.hpp>
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
|
|
||||||
namespace Slic3r { namespace GUI {
|
namespace Slic3r { namespace GUI {
|
||||||
|
@ -80,6 +82,7 @@ const t_field& OptionsGroup::build_field(const t_config_option_key& id, const Co
|
||||||
if (!this->m_disabled)
|
if (!this->m_disabled)
|
||||||
this->back_to_initial_value(opt_id);
|
this->back_to_initial_value(opt_id);
|
||||||
};
|
};
|
||||||
|
if (!m_is_tab_opt) field->m_Undo_btn->Hide();
|
||||||
|
|
||||||
// assign function objects for callbacks, etc.
|
// assign function objects for callbacks, etc.
|
||||||
return field;
|
return field;
|
||||||
|
@ -255,6 +258,12 @@ void ConfigOptionsGroup::on_change_OG(t_config_option_key opt_id, boost::any val
|
||||||
// # Currently used for the post_process config value only.
|
// # Currently used for the post_process config value only.
|
||||||
// my @values = split / ; / , $field_value;
|
// my @values = split / ; / , $field_value;
|
||||||
// $self->config->set($opt_key, \@values);
|
// $self->config->set($opt_key, \@values);
|
||||||
|
std::string str = boost::any_cast<std::string>(value);
|
||||||
|
if (str.back() == ';')
|
||||||
|
str.pop_back();
|
||||||
|
std::vector<std::string> values;
|
||||||
|
boost::split(values, str, boost::is_any_of(";"));
|
||||||
|
change_opt_value(*m_config, opt_key, values);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (opt_index == -1) {
|
if (opt_index == -1) {
|
||||||
|
@ -279,9 +288,16 @@ void ConfigOptionsGroup::back_to_initial_value(const std::string opt_key)
|
||||||
if (m_get_initial_config == nullptr)
|
if (m_get_initial_config == nullptr)
|
||||||
return;
|
return;
|
||||||
DynamicPrintConfig config = m_get_initial_config();
|
DynamicPrintConfig config = m_get_initial_config();
|
||||||
boost::any value = get_config_value(config, opt_key);
|
boost::any value;
|
||||||
|
if (opt_key == "extruders_count"){
|
||||||
|
auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(config.option("nozzle_diameter"));
|
||||||
|
value = int(nozzle_diameter->values.size());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
value = get_config_value(config, opt_key);
|
||||||
|
|
||||||
set_value(opt_key, value);
|
set_value(opt_key, value);
|
||||||
on_change_OG(opt_key, get_value(opt_key)/*value*/);
|
on_change_OG(opt_key, get_value(opt_key));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigOptionsGroup::reload_config(){
|
void ConfigOptionsGroup::reload_config(){
|
||||||
|
@ -354,6 +370,12 @@ boost::any ConfigOptionsGroup::get_config_value(DynamicPrintConfig& config, std:
|
||||||
case coStrings:
|
case coStrings:
|
||||||
if (config.option<ConfigOptionStrings>(opt_key)->values.empty())
|
if (config.option<ConfigOptionStrings>(opt_key)->values.empty())
|
||||||
ret = text_value;
|
ret = text_value;
|
||||||
|
else if (opt->gui_flags.compare("serialized") == 0){
|
||||||
|
std::vector<std::string> values = config.option<ConfigOptionStrings>(opt_key)->values;
|
||||||
|
for (auto el : values)
|
||||||
|
text_value += el + ";";
|
||||||
|
ret = text_value;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
ret = static_cast<wxString>(config.opt_string(opt_key, static_cast<unsigned int>(idx)));
|
ret = static_cast<wxString>(config.opt_string(opt_key, static_cast<unsigned int>(idx)));
|
||||||
break;
|
break;
|
||||||
|
@ -397,6 +419,9 @@ boost::any ConfigOptionsGroup::get_config_value(DynamicPrintConfig& config, std:
|
||||||
}
|
}
|
||||||
|
|
||||||
Field* ConfigOptionsGroup::get_fieldc(t_config_option_key opt_key, int opt_index){
|
Field* ConfigOptionsGroup::get_fieldc(t_config_option_key opt_key, int opt_index){
|
||||||
|
Field* field = get_field(opt_key);
|
||||||
|
if (field != nullptr)
|
||||||
|
return field;
|
||||||
std::string opt_id = "";
|
std::string opt_id = "";
|
||||||
for (std::map< std::string, std::pair<std::string, int> >::iterator it = m_opt_map.begin(); it != m_opt_map.end(); ++it) {
|
for (std::map< std::string, std::pair<std::string, int> >::iterator it = m_opt_map.begin(); it != m_opt_map.end(); ++it) {
|
||||||
if (opt_key == m_opt_map.at(it->first).first && opt_index == m_opt_map.at(it->first).second){
|
if (opt_key == m_opt_map.at(it->first).first && opt_index == m_opt_map.at(it->first).second){
|
||||||
|
|
|
@ -113,8 +113,8 @@ public:
|
||||||
inline void enable() { for (auto& field : m_fields) field.second->enable(); }
|
inline void enable() { for (auto& field : m_fields) field.second->enable(); }
|
||||||
inline void disable() { for (auto& field : m_fields) field.second->disable(); }
|
inline void disable() { for (auto& field : m_fields) field.second->disable(); }
|
||||||
|
|
||||||
OptionsGroup(wxWindow* _parent, wxString title) :
|
OptionsGroup(wxWindow* _parent, wxString title, bool is_tab_opt=false) :
|
||||||
m_parent(_parent), title(title) {
|
m_parent(_parent), title(title), m_is_tab_opt(is_tab_opt) {
|
||||||
sizer = (staticbox ? new wxStaticBoxSizer(new wxStaticBox(_parent, wxID_ANY, title), wxVERTICAL) : new wxBoxSizer(wxVERTICAL));
|
sizer = (staticbox ? new wxStaticBoxSizer(new wxStaticBox(_parent, wxID_ANY, title), wxVERTICAL) : new wxBoxSizer(wxVERTICAL));
|
||||||
auto num_columns = 1U;
|
auto num_columns = 1U;
|
||||||
if (label_width != 0) num_columns++;
|
if (label_width != 0) num_columns++;
|
||||||
|
@ -136,6 +136,8 @@ protected:
|
||||||
t_optionfield_map m_fields;
|
t_optionfield_map m_fields;
|
||||||
bool m_disabled {false};
|
bool m_disabled {false};
|
||||||
wxGridSizer* m_grid_sizer {nullptr};
|
wxGridSizer* m_grid_sizer {nullptr};
|
||||||
|
// "true" if option is created in preset tabs
|
||||||
|
bool m_is_tab_opt{ false };
|
||||||
|
|
||||||
/// Generate a wxSizer or wxWindow from a configuration option
|
/// Generate a wxSizer or wxWindow from a configuration option
|
||||||
/// Precondition: opt resolves to a known ConfigOption
|
/// Precondition: opt resolves to a known ConfigOption
|
||||||
|
@ -151,8 +153,8 @@ protected:
|
||||||
|
|
||||||
class ConfigOptionsGroup: public OptionsGroup {
|
class ConfigOptionsGroup: public OptionsGroup {
|
||||||
public:
|
public:
|
||||||
ConfigOptionsGroup(wxWindow* parent, wxString title, DynamicPrintConfig* _config = nullptr) :
|
ConfigOptionsGroup(wxWindow* parent, wxString title, DynamicPrintConfig* _config = nullptr, bool is_tab_opt = false) :
|
||||||
OptionsGroup(parent, title), m_config(_config) {}
|
OptionsGroup(parent, title, is_tab_opt), m_config(_config) {}
|
||||||
|
|
||||||
/// reference to libslic3r config, non-owning pointer (?).
|
/// reference to libslic3r config, non-owning pointer (?).
|
||||||
DynamicPrintConfig* m_config {nullptr};
|
DynamicPrintConfig* m_config {nullptr};
|
||||||
|
|
|
@ -144,12 +144,24 @@ void Tab::update_dirty(){
|
||||||
m_presets->update_dirty_ui(m_presets_choice);
|
m_presets->update_dirty_ui(m_presets_choice);
|
||||||
on_presets_changed();
|
on_presets_changed();
|
||||||
auto dirty_options = m_presets->current_dirty_options();
|
auto dirty_options = m_presets->current_dirty_options();
|
||||||
|
|
||||||
|
bool change_extruder_data = false;
|
||||||
|
|
||||||
|
if (name() == "printer"){
|
||||||
|
TabPrinter* tab_printer = static_cast<TabPrinter*>(this);
|
||||||
|
if (tab_printer->m_initial_extruders_count != tab_printer->m_extruders_count){
|
||||||
|
dirty_options.emplace_back("extruders_count");
|
||||||
|
change_extruder_data = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
// Add new dirty options to m_dirty_options
|
// Add new dirty options to m_dirty_options
|
||||||
for (auto opt_key : dirty_options){
|
for (auto opt_key : dirty_options){
|
||||||
Field* field = get_field(opt_key/*, opt_index*/);
|
Field* field = get_field(opt_key/*, opt_index*/);
|
||||||
if (field != nullptr && find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) == m_dirty_options.end()){
|
if (field != nullptr && find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) == m_dirty_options.end()){
|
||||||
field->m_Label->SetForegroundColour(*get_modified_label_clr());
|
if (field->m_Label != nullptr)
|
||||||
|
field->m_Label->SetForegroundColour(*get_modified_label_clr());
|
||||||
field->m_Undo_btn->SetBitmap(wxBitmap(from_u8(wxMSW ? var("action_undo.png") : var("arrow_undo.png")), wxBITMAP_TYPE_PNG));
|
field->m_Undo_btn->SetBitmap(wxBitmap(from_u8(wxMSW ? var("action_undo.png") : var("arrow_undo.png")), wxBITMAP_TYPE_PNG));
|
||||||
|
field->m_is_modified_value = true;
|
||||||
|
|
||||||
m_dirty_options.push_back(opt_key);
|
m_dirty_options.push_back(opt_key);
|
||||||
}
|
}
|
||||||
|
@ -164,7 +176,9 @@ void Tab::update_dirty(){
|
||||||
if (field != nullptr && find(dirty_options.begin(), dirty_options.end(), opt_key) == dirty_options.end())
|
if (field != nullptr && find(dirty_options.begin(), dirty_options.end(), opt_key) == dirty_options.end())
|
||||||
{
|
{
|
||||||
field->m_Undo_btn->SetBitmap(wxBitmap(from_u8(var("Bullet_white.png")), wxBITMAP_TYPE_PNG));
|
field->m_Undo_btn->SetBitmap(wxBitmap(from_u8(var("Bullet_white.png")), wxBITMAP_TYPE_PNG));
|
||||||
field->m_Label->SetForegroundColour(wxSYS_COLOUR_WINDOWTEXT);
|
if (field->m_Label != nullptr)
|
||||||
|
field->m_Label->SetForegroundColour(wxSYS_COLOUR_WINDOWTEXT);
|
||||||
|
field->m_is_modified_value = false;
|
||||||
std::vector<std::string>::iterator itr = find(m_dirty_options.begin(), m_dirty_options.end(), opt_key);
|
std::vector<std::string>::iterator itr = find(m_dirty_options.begin(), m_dirty_options.end(), opt_key);
|
||||||
if (itr != m_dirty_options.end()){
|
if (itr != m_dirty_options.end()){
|
||||||
m_dirty_options.erase(itr);
|
m_dirty_options.erase(itr);
|
||||||
|
@ -200,11 +214,13 @@ void Tab::load_config(DynamicPrintConfig config)
|
||||||
int opt_index = 0;
|
int opt_index = 0;
|
||||||
for(auto opt_key : m_config->diff(config)) {
|
for(auto opt_key : m_config->diff(config)) {
|
||||||
switch ( config.def()->get(opt_key)->type ){
|
switch ( config.def()->get(opt_key)->type ){
|
||||||
case coFloatOrPercent:
|
case coFloatOrPercent:{
|
||||||
value = config.option<ConfigOptionFloatOrPercent>(opt_key)->value;
|
const auto &conf_val = *config.option<ConfigOptionFloatOrPercent>(opt_key);
|
||||||
|
value = conf_val.percent ? std::to_string(int(conf_val.value)) + "%" : std::to_string(conf_val.value);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case coPercent:
|
case coPercent:
|
||||||
value = config.option<ConfigOptionPercent>(opt_key)->value;
|
value = std::to_string(int(config.option<ConfigOptionPercent>(opt_key)->value));
|
||||||
break;
|
break;
|
||||||
case coFloat:
|
case coFloat:
|
||||||
value = config.opt_float(opt_key);
|
value = config.opt_float(opt_key);
|
||||||
|
@ -610,7 +626,8 @@ void TabPrint::update()
|
||||||
DynamicPrintConfig new_conf = *m_config;
|
DynamicPrintConfig new_conf = *m_config;
|
||||||
if (dialog->ShowModal() == wxID_YES) {
|
if (dialog->ShowModal() == wxID_YES) {
|
||||||
const auto &val = *m_config->option<ConfigOptionFloatOrPercent>("first_layer_height");
|
const auto &val = *m_config->option<ConfigOptionFloatOrPercent>("first_layer_height");
|
||||||
new_conf.set_key_value("first_layer_height", new ConfigOptionFloatOrPercent(0.2, val.percent));
|
auto percent = val.percent;
|
||||||
|
new_conf.set_key_value("first_layer_height", new ConfigOptionFloatOrPercent(0.2, percent));
|
||||||
|
|
||||||
if (m_config->opt_float("layer_height") < 0.15) new_conf.set_key_value("layer_height", new ConfigOptionFloat(0.15));
|
if (m_config->opt_float("layer_height") < 0.15) new_conf.set_key_value("layer_height", new ConfigOptionFloat(0.15));
|
||||||
if (m_config->opt_float("layer_height") > 0.35) new_conf.set_key_value("layer_height", new ConfigOptionFloat(0.35));
|
if (m_config->opt_float("layer_height") > 0.35) new_conf.set_key_value("layer_height", new ConfigOptionFloat(0.35));
|
||||||
|
@ -977,7 +994,7 @@ void TabPrinter::build()
|
||||||
auto default_config = m_preset_bundle->full_config();
|
auto default_config = m_preset_bundle->full_config();
|
||||||
|
|
||||||
auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(m_config->option("nozzle_diameter"));
|
auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(m_config->option("nozzle_diameter"));
|
||||||
m_extruders_count = nozzle_diameter->values.size();
|
m_initial_extruders_count = m_extruders_count = nozzle_diameter->values.size();
|
||||||
|
|
||||||
auto page = add_options_page(_(L("General")), "printer_empty.png");
|
auto page = add_options_page(_(L("General")), "printer_empty.png");
|
||||||
auto optgroup = page->new_optgroup(_(L("Size and coordinates")));
|
auto optgroup = page->new_optgroup(_(L("Size and coordinates")));
|
||||||
|
@ -1222,6 +1239,7 @@ void TabPrinter::extruders_count_changed(size_t extruders_count){
|
||||||
m_preset_bundle->printers.get_edited_preset().set_num_extruders(extruders_count);
|
m_preset_bundle->printers.get_edited_preset().set_num_extruders(extruders_count);
|
||||||
m_preset_bundle->update_multi_material_filament_presets();
|
m_preset_bundle->update_multi_material_filament_presets();
|
||||||
build_extruder_pages();
|
build_extruder_pages();
|
||||||
|
reload_config();
|
||||||
on_value_change("extruders_count", extruders_count);
|
on_value_change("extruders_count", extruders_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1771,7 +1789,7 @@ bool Page::set_value(t_config_option_key opt_key, boost::any value){
|
||||||
ConfigOptionsGroupShp Page::new_optgroup(wxString title, int noncommon_label_width /*= -1*/)
|
ConfigOptionsGroupShp Page::new_optgroup(wxString title, int noncommon_label_width /*= -1*/)
|
||||||
{
|
{
|
||||||
//! config_ have to be "right"
|
//! config_ have to be "right"
|
||||||
ConfigOptionsGroupShp optgroup = std::make_shared<ConfigOptionsGroup>(this, title, m_config);
|
ConfigOptionsGroupShp optgroup = std::make_shared<ConfigOptionsGroup>(this, title, m_config, true);
|
||||||
if (noncommon_label_width >= 0)
|
if (noncommon_label_width >= 0)
|
||||||
optgroup->label_width = noncommon_label_width;
|
optgroup->label_width = noncommon_label_width;
|
||||||
|
|
||||||
|
|
|
@ -222,6 +222,7 @@ 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_initial_extruders_count;
|
||||||
std::vector<PageShp> m_extruder_pages;
|
std::vector<PageShp> m_extruder_pages;
|
||||||
|
|
||||||
TabPrinter() {}
|
TabPrinter() {}
|
||||||
|
|
Loading…
Reference in a new issue