Skip to content

Commit

Permalink
detect changes to settings, for multi-setting selector UI
Browse files Browse the repository at this point in the history
also optimise emissions of various signals only for when a change.
remove a certain amount of cut-n-paste [!]
  • Loading branch information
Michael Meeks committed Jun 24, 2012
1 parent 31d217e commit 539ef96
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 53 deletions.
8 changes: 4 additions & 4 deletions TODO
Expand Up @@ -61,10 +61,10 @@
+ cd. render.cpp - on_button_release_event // click only + cd. render.cpp - on_button_release_event // click only


* Multi-model selector ... * Multi-model selector ...
+ have pre-canned settings GUI + leave the single mode's "settings" object
+ use a simple scrolled area: + detect changes, and show those in the existing UI
+ containing buttons + load and save new settings as we switch
+ containing an Image - and label underneath (!?) + prompt to save changes on selection ...


* Serial * Serial
+ libreprap: + libreprap:
Expand Down
129 changes: 81 additions & 48 deletions src/settings.cpp
Expand Up @@ -534,13 +534,24 @@ Settings::Settings ()
{ {
GCode.m_impl = new GCodeImpl(); GCode.m_impl = new GCodeImpl();
set_defaults(); set_defaults();
m_user_changed = false;
} }


Settings::~Settings() Settings::~Settings()
{ {
delete GCode.m_impl; delete GCode.m_impl;
} }


void
Settings::assign_from(Settings *pSettings)
{
// default copy operators can be simply wonderful
*this = *pSettings;
m_user_changed = false;
m_signal_visual_settings_changed.emit();
m_signal_update_settings_gui.emit();
}

void Settings::set_defaults () void Settings::set_defaults ()
{ {
for (uint i = 0; i < G_N_ELEMENTS (settings); i++) { for (uint i = 0; i < G_N_ELEMENTS (settings); i++) {
Expand Down Expand Up @@ -692,6 +703,7 @@ void Settings::load_settings (Glib::RefPtr<Gio::File> file)
} catch (const Glib::KeyFileError &err) { } catch (const Glib::KeyFileError &err) {
} }


m_user_changed = false;
m_signal_visual_settings_changed.emit(); m_signal_visual_settings_changed.emit();
m_signal_update_settings_gui.emit(); m_signal_update_settings_gui.emit();
} }
Expand Down Expand Up @@ -739,7 +751,7 @@ void Settings::save_settings(Glib::RefPtr<Gio::File> file)
cfg.set_string("Misc", "WindowPosY", os.str()); cfg.set_string("Misc", "WindowPosY", os.str());


GCode.m_impl->saveSettings (cfg); GCode.m_impl->saveSettings (cfg);

string CBgroup="CustomButtons"; string CBgroup="CustomButtons";
for (guint i=0; i<CustomButtonLabel.size(); i++) { for (guint i=0; i<CustomButtonLabel.size(); i++) {
string s = CustomButtonLabel[i]; string s = CustomButtonLabel[i];
Expand All @@ -749,6 +761,9 @@ void Settings::save_settings(Glib::RefPtr<Gio::File> file)


Glib::ustring contents = cfg.to_data(); Glib::ustring contents = cfg.to_data();
Glib::file_set_contents (file->get_path(), contents); Glib::file_set_contents (file->get_path(), contents);

// all changes safely saved
m_user_changed = false;
} }




Expand Down Expand Up @@ -855,6 +870,7 @@ void Settings::set_filltypes_to_gui (Builder &builder)


void Settings::get_from_gui (Builder &builder, int i) void Settings::get_from_gui (Builder &builder, int i)
{ {
bool is_changed = false;
const char *glade_name = settings[i].glade_name; const char *glade_name = settings[i].glade_name;
SettingType t = settings[i].type; SettingType t = settings[i].type;


Expand All @@ -867,8 +883,10 @@ void Settings::get_from_gui (Builder &builder, int i)
builder->get_widget (glade_name, check); builder->get_widget (glade_name, check);
if (!check) if (!check)
std::cerr << _("Missing boolean config item ") << glade_name << "\n"; std::cerr << _("Missing boolean config item ") << glade_name << "\n";
else else {
is_changed = *PTR_BOOL(this, i) != check->get_active();
*PTR_BOOL(this, i) = check->get_active(); *PTR_BOOL(this, i) = check->get_active();
}
break; break;
} }
case T_INT: case T_INT:
Expand All @@ -881,25 +899,31 @@ void Settings::get_from_gui (Builder &builder, int i)
break; break;
} }


double value = 0.0;
Gtk::SpinButton *spin = dynamic_cast<Gtk::SpinButton *>(w); Gtk::SpinButton *spin = dynamic_cast<Gtk::SpinButton *>(w);
if (spin) { if (spin)
if (t == T_INT) value = spin->get_value();
*PTR_INT(this, i) = spin->get_value();
else if (t == T_FLOAT)
*PTR_FLOAT(this, i) = spin->get_value();
else
*PTR_DOUBLE(this, i) = spin->get_value();
break;
}

Gtk::Range *range = dynamic_cast<Gtk::Range *>(w); Gtk::Range *range = dynamic_cast<Gtk::Range *>(w);
if (range) { if (range)
value = range->get_value();

if (range || spin)
{
if (t == T_INT) if (t == T_INT)
*PTR_INT(this, i) = range->get_value(); {
is_changed = *PTR_INT(this, i) != (int)value;
*PTR_INT(this, i) = value;
}
else if (t == T_FLOAT) else if (t == T_FLOAT)
*PTR_FLOAT(this, i) = range->get_value(); {
is_changed = *PTR_FLOAT(this, i) != (float)value;
*PTR_FLOAT(this, i) = value;
}
else else
*PTR_DOUBLE(this, i) = range->get_value(); {
is_changed = *PTR_DOUBLE(this, i) != value;
*PTR_DOUBLE(this, i) = value;
}
} }
break; break;
} }
Expand All @@ -921,52 +945,55 @@ void Settings::get_from_gui (Builder &builder, int i)
break; break;
} }


m_user_changed |= true; // is_changed;

// bit of a hack ... // bit of a hack ...
if (!strcmp (settings[i].config_name, "CommsDebug")) if (!strcmp (settings[i].config_name, "CommsDebug"))
m_signal_core_settings_changed.emit(); m_signal_core_settings_changed.emit();


if (settings[i].triggers_redraw) if (settings[i].triggers_redraw && is_changed)
m_signal_visual_settings_changed.emit(); m_signal_visual_settings_changed.emit();
} }


void Settings::get_filltypes_from_gui (Builder &builder) static bool get_filltype(Builder &builder, const char *combo_name, int *type)
{ {
// cerr <<"Get_filltypes " << endl;
Gtk::ComboBox *combo = NULL; Gtk::ComboBox *combo = NULL;
bool is_changed = false;
builder->get_widget ("Slicing.NormalFilltype", combo); builder->get_widget ("Slicing.NormalFilltype", combo);
if (combo) { if (combo) {
Slicing.NormalFilltype = combo->get_active_row_number (); int value = combo->get_active_row_number ();
} is_changed |= *type != value;
else cerr << "no Slicing.NormalFilltype combo" << endl; *type = value;
builder->get_widget ("Slicing.FullFilltype", combo);
if (combo) {
Slicing.FullFilltype = combo->get_active_row_number ();
} }
else cerr << "no Slicing.FullFilltype combo" << endl; else
builder->get_widget ("Slicing.SupportFilltype", combo); cerr << "no " << combo_name << "combo" << endl;
if (combo){ return is_changed;
Slicing.SupportFilltype = combo->get_active_row_number (); }
}
else cerr << "no Slicing.SupportFilltype combo" << endl; void Settings::get_filltypes_from_gui (Builder &builder)
builder->get_widget ("Slicing.DecorFilltype", combo); {
if (combo){ bool is_changed = false;
Slicing.DecorFilltype = combo->get_active_row_number (); // cerr <<"Get_filltypes " << endl;
} is_changed |= get_filltype(builder, "Slicing.NormalFilltype", &Slicing.NormalFilltype);
else cerr << "no Slicing.DecorFilltype combo" << endl; is_changed |= get_filltype(builder, "Slicing.FullFilltype", &Slicing.NormalFilltype);
// cerr << "read combos: " << Slicing.NormalFilltype is_changed |= get_filltype(builder, "Slicing.SupportFilltype", &Slicing.SupportFilltype);
// << " / " << Slicing.FullFilltype is_changed |= get_filltype(builder, "Slicing.DecorFilltype", &Slicing.DecorFilltype);
// cerr << "read combos: " << Slicing.NormalFilltype
// << " / " << Slicing.FullFilltype
// << " / " << Slicing.SupportFilltype << endl; // << " / " << Slicing.SupportFilltype << endl;
m_signal_visual_settings_changed.emit(); m_user_changed |= is_changed;
if (is_changed)
m_signal_visual_settings_changed.emit();
} }


string combobox_get_active_value(Gtk::ComboBox *combo){ string combobox_get_active_value(Gtk::ComboBox *combo){
#if GTK_VERSION_GE(2, 24) #if GTK_VERSION_GE(2, 24)
if (combo->get_has_entry()) if (combo->get_has_entry())
{ {
Gtk::Entry *entry = combo->get_entry(); Gtk::Entry *entry = combo->get_entry();
if (entry) if (entry)
return string(entry->get_text()); return string(entry->get_text());
} else } else
#endif #endif
{ {
uint c = combo->get_active_row_number(); uint c = combo->get_active_row_number();
Expand All @@ -978,7 +1005,8 @@ string combobox_get_active_value(Gtk::ComboBox *combo){
return ""; return "";
} }


bool combobox_set_to(Gtk::ComboBox *combo, string value){ bool combobox_set_to(Gtk::ComboBox *combo, string value)
{
Glib::ustring val(value); Glib::ustring val(value);
Glib::RefPtr<Gtk::TreeModel> model = combo->get_model(); Glib::RefPtr<Gtk::TreeModel> model = combo->get_model();
uint nch = model->children().size(); uint nch = model->children().size();
Expand Down Expand Up @@ -1011,7 +1039,8 @@ bool combobox_set_to(Gtk::ComboBox *combo, string value){


void set_up_combobox(Gtk::ComboBox *combo, vector<string> values) void set_up_combobox(Gtk::ComboBox *combo, vector<string> values)
{ {
if (combo->get_model()) return; if (combo->get_model())
return;
//cerr << "setup " ; //cerr << "setup " ;
Gtk::TreeModelColumn<Glib::ustring> column; Gtk::TreeModelColumn<Glib::ustring> column;
Gtk::TreeModelColumnRecord record; Gtk::TreeModelColumnRecord record;
Expand All @@ -1037,18 +1066,21 @@ void Settings::get_port_speed_from_gui (Builder &builder)
// Gtk::ComboBoxEntryText *tcombo = NULL; // Gtk::ComboBoxEntryText *tcombo = NULL;
// builder->get_widget_derived ("Hardware.SerialSpeed", tcombo); // builder->get_widget_derived ("Hardware.SerialSpeed", tcombo);
builder->get_widget ("Hardware.SerialSpeed", combo); builder->get_widget ("Hardware.SerialSpeed", combo);
int serial_speed = Hardware.SerialSpeed;
if (combo) { if (combo) {
#if GTK_VERSION_GE(2, 24) #if GTK_VERSION_GE(2, 24)
if (combo->get_has_entry()) { if (combo->get_has_entry()) {
Gtk::Entry *entry = combo->get_entry(); Gtk::Entry *entry = combo->get_entry();
if (entry) { if (entry) {
Hardware.SerialSpeed = atoi(entry->get_text().c_str()); serial_speed = atoi(entry->get_text().c_str());
} }
} }
else else
#endif #endif
Hardware.SerialSpeed = atoi(combobox_get_active_value(combo).c_str()); serial_speed = atoi(combobox_get_active_value(combo).c_str());
} }
m_user_changed |= Hardware.SerialSpeed != serial_speed;
Hardware.SerialSpeed = serial_speed;
} }


void Settings::get_colour_from_gui (Builder &builder, int i) void Settings::get_colour_from_gui (Builder &builder, int i)
Expand All @@ -1062,6 +1094,8 @@ void Settings::get_colour_from_gui (Builder &builder, int i)
if (!w) return; if (!w) return;


c = w->get_color(); c = w->get_color();

// FIXME: detect 'changed' etc.
dest->r() = c.get_red_p(); dest->r() = c.get_red_p();
dest->g() = c.get_green_p(); dest->g() = c.get_green_p();
dest->b() = c.get_blue_p(); dest->b() = c.get_blue_p();
Expand Down Expand Up @@ -1256,16 +1290,15 @@ double Settings::HardwareSettings::RoundedLinewidthCorrection(double extr_width,


double Settings::HardwareSettings::GetExtrudedMaterialWidth(double layerheight) const double Settings::HardwareSettings::GetExtrudedMaterialWidth(double layerheight) const
{ {
// ExtrudedMaterialWidthRatio is preset by user // ExtrudedMaterialWidthRatio is preset by user
return min(max((double)MinimumLineWidth, return min(max((double)MinimumLineWidth,
ExtrudedMaterialWidthRatio * layerheight), ExtrudedMaterialWidthRatio * layerheight),
(double)MaximumLineWidth); (double)MaximumLineWidth);
} }


// TODO This depends whether lines are packed or not - ellipsis/rectangle // TODO This depends whether lines are packed or not - ellipsis/rectangle



// how much mm filament material per extruded line length mm -> E gcode
// how much mm filament material per extruded line length mm -> E gcode
double Settings::HardwareSettings::GetExtrudeFactor(double layerheight) const double Settings::HardwareSettings::GetExtrudeFactor(double layerheight) const
{ {
double f = ExtrusionFactor; // overall factor double f = ExtrusionFactor; // overall factor
Expand Down
7 changes: 6 additions & 1 deletion src/settings.h
Expand Up @@ -34,6 +34,8 @@ class Builder : public Glib::RefPtr<Gtk::Builder>
}; };


class Settings { class Settings {
bool m_user_changed;

public: public:


std::string Name; std::string Name;
Expand Down Expand Up @@ -295,9 +297,12 @@ class Settings {
void set_defaults (); void set_defaults ();
public: public:


Settings (); Settings();
~Settings(); ~Settings();


bool has_user_changed() const { return m_user_changed; }
void assign_from(Settings *pSettings);

Matrix4d getBasicTransformation(Matrix4d T) const; Matrix4d getBasicTransformation(Matrix4d T) const;


// return real mm depending on hardware extrusion width setting // return real mm depending on hardware extrusion width setting
Expand Down

0 comments on commit 539ef96

Please sign in to comment.