diff --git a/rtgui/dynamicprofile.cc b/rtgui/dynamicprofile.cc index 749c9b02e..d1a5a0177 100644 --- a/rtgui/dynamicprofile.cc +++ b/rtgui/dynamicprofile.cc @@ -37,7 +37,7 @@ const double EXPCOMP_MAX = 20.0; } // namespace -bool DynamicProfileEntry::Optional::operator()(const Glib::ustring &val) const +bool DynamicProfileRule::Optional::operator()(const Glib::ustring &val) const { if (!enabled) { return true; @@ -53,7 +53,7 @@ bool DynamicProfileEntry::Optional::operator()(const Glib::ustring &val) const } -DynamicProfileEntry::DynamicProfileEntry(): +DynamicProfileRule::DynamicProfileRule(): serial_number(0), iso(0, ISO_MAX), fnumber(0, FNUMBER_MAX), @@ -64,13 +64,13 @@ DynamicProfileEntry::DynamicProfileEntry(): } -bool DynamicProfileEntry::operator<(const DynamicProfileEntry &other) const +bool DynamicProfileRule::operator<(const DynamicProfileRule &other) const { return serial_number < other.serial_number; } -bool DynamicProfileEntry::matches(const rtengine::ImageMetaData *im) +bool DynamicProfileRule::matches(const rtengine::ImageMetaData *im) { return (iso(im->getISOSpeed()) && fnumber(im->getFNumber()) @@ -83,7 +83,7 @@ bool DynamicProfileEntry::matches(const rtengine::ImageMetaData *im) namespace { -void get_int_range(DynamicProfileEntry::Range &dest, +void get_int_range(DynamicProfileRule::Range &dest, const Glib::KeyFile &kf, const Glib::ustring &group, const Glib::ustring &key) { @@ -99,7 +99,7 @@ void get_int_range(DynamicProfileEntry::Range &dest, } -void get_double_range(DynamicProfileEntry::Range &dest, +void get_double_range(DynamicProfileRule::Range &dest, const Glib::KeyFile &kf, const Glib::ustring &group, const Glib::ustring &key) { @@ -115,7 +115,7 @@ void get_double_range(DynamicProfileEntry::Range &dest, } -void get_optional(DynamicProfileEntry::Optional &dest, +void get_optional(DynamicProfileRule::Optional &dest, const Glib::KeyFile &kf, const Glib::ustring &group, const Glib::ustring &key) { @@ -132,7 +132,7 @@ void get_optional(DynamicProfileEntry::Optional &dest, void set_int_range(Glib::KeyFile &kf, const Glib::ustring &group, const Glib::ustring &key, - const DynamicProfileEntry::Range &val) + const DynamicProfileRule::Range &val) { kf.set_integer(group, key + "_min", val.min); kf.set_integer(group, key + "_max", val.max); @@ -140,7 +140,7 @@ void set_int_range(Glib::KeyFile &kf, const Glib::ustring &group, void set_double_range(Glib::KeyFile &kf, const Glib::ustring &group, const Glib::ustring &key, - const DynamicProfileEntry::Range &val) + const DynamicProfileRule::Range &val) { kf.set_double(group, key + "_min", val.min); kf.set_double(group, key + "_max", val.max); @@ -148,7 +148,7 @@ void set_double_range(Glib::KeyFile &kf, const Glib::ustring &group, void set_optional(Glib::KeyFile &kf, const Glib::ustring &group, const Glib::ustring &key, - const DynamicProfileEntry::Optional &val) + const DynamicProfileRule::Optional &val) { kf.set_boolean(group, key + "_enabled", val.enabled); kf.set_string(group, key + "_value", val.value); @@ -157,7 +157,7 @@ void set_optional(Glib::KeyFile &kf, const Glib::ustring &group, } // namespace -bool loadDynamicProfileEntries(std::vector &out) +bool loadDynamicProfileRules(std::vector &out) { out.clear(); Glib::KeyFile kf; @@ -172,29 +172,29 @@ bool loadDynamicProfileEntries(std::vector &out) printf("loading dynamic profiles...\n"); auto groups = kf.get_groups(); for (auto group : groups) { - // groups are of the form "entry N", where N is a positive integer - if (group.find("entry ") != 0) { + // groups are of the form "rule N", where N is a positive integer + if (group.find("rule ") != 0) { return false; } - std::istringstream buf(group.c_str() + 6); + std::istringstream buf(group.c_str() + 5); int serial = 0; if (!(buf >> serial) || !buf.eof()) { return false; } - printf(" loading entry %d\n", serial); + printf(" loading rule %d\n", serial); - out.emplace_back(DynamicProfileEntry()); - DynamicProfileEntry &entry = out.back(); - entry.serial_number = serial; - get_int_range(entry.iso, kf, group, "iso"); - get_double_range(entry.fnumber, kf, group, "fnumber"); - get_double_range(entry.focallen, kf, group, "focallen"); - get_double_range(entry.shutterspeed, kf, group, "shutterspeed"); - get_double_range(entry.expcomp, kf, group, "expcomp"); - get_optional(entry.camera, kf, group, "camera"); - get_optional(entry.lens, kf, group, "lens"); + out.emplace_back(DynamicProfileRule()); + DynamicProfileRule &rule = out.back(); + rule.serial_number = serial; + get_int_range(rule.iso, kf, group, "iso"); + get_double_range(rule.fnumber, kf, group, "fnumber"); + get_double_range(rule.focallen, kf, group, "focallen"); + get_double_range(rule.shutterspeed, kf, group, "shutterspeed"); + get_double_range(rule.expcomp, kf, group, "expcomp"); + get_optional(rule.camera, kf, group, "camera"); + get_optional(rule.lens, kf, group, "lens"); try { - entry.profilepath = kf.get_string(group, "profilepath"); + rule.profilepath = kf.get_string(group, "profilepath"); } catch (Glib::KeyFileError &) { out.pop_back(); } @@ -204,22 +204,22 @@ bool loadDynamicProfileEntries(std::vector &out) } -bool storeDynamicProfileEntries(const std::vector &entries) +bool storeDynamicProfileRules(const std::vector &rules) { printf("saving dynamic profiles...\n"); Glib::KeyFile kf; - for (auto &entry : entries) { + for (auto &rule : rules) { std::ostringstream buf; - buf << "entry " << entry.serial_number; + buf << "rule " << rule.serial_number; Glib::ustring group = buf.str(); - set_int_range(kf, group, "iso", entry.iso); - set_double_range(kf, group, "fnumber", entry.fnumber); - set_double_range(kf, group, "focallen", entry.focallen); - set_double_range(kf, group, "shutterspeed", entry.shutterspeed); - set_double_range(kf, group, "expcomp", entry.expcomp); - set_optional(kf, group, "camera", entry.camera); - set_optional(kf, group, "lens", entry.lens); - kf.set_string(group, "profilepath", entry.profilepath); + set_int_range(kf, group, "iso", rule.iso); + set_double_range(kf, group, "fnumber", rule.fnumber); + set_double_range(kf, group, "focallen", rule.focallen); + set_double_range(kf, group, "shutterspeed", rule.shutterspeed); + set_double_range(kf, group, "expcomp", rule.expcomp); + set_optional(kf, group, "camera", rule.camera); + set_optional(kf, group, "lens", rule.lens); + kf.set_string(group, "profilepath", rule.profilepath); } return kf.save_to_file( Glib::build_filename(Options::rtdir, "dynamicprofile.cfg")); @@ -229,14 +229,14 @@ bool storeDynamicProfileEntries(const std::vector &entries) PartialProfile *loadDynamicProfile(const ImageMetaData *im) { PartialProfile *ret = new PartialProfile(true, true); - std::vector entries; - if (loadDynamicProfileEntries(entries)) { - for (auto &entry : entries) { - if (entry.matches(im)) { + std::vector rules; + if (loadDynamicProfileRules(rules)) { + for (auto &rule : rules) { + if (rule.matches(im)) { printf("found matching profile %s\n", - entry.profilepath.c_str()); + rule.profilepath.c_str()); const PartialProfile *p = - profileStore.getProfile(entry.profilepath); + profileStore.getProfile(rule.profilepath); if (p != nullptr) { p->applyTo(ret->pparams); } else { diff --git a/rtgui/dynamicprofile.h b/rtgui/dynamicprofile.h index 0847cd8ef..c662a51f7 100644 --- a/rtgui/dynamicprofile.h +++ b/rtgui/dynamicprofile.h @@ -24,7 +24,7 @@ #include "options.h" -class DynamicProfileEntry { +class DynamicProfileRule { public: template struct Range { @@ -47,9 +47,9 @@ public: bool operator()(const Glib::ustring &val) const; }; - DynamicProfileEntry(); + DynamicProfileRule(); bool matches(const rtengine::ImageMetaData *im); - bool operator<(const DynamicProfileEntry &other) const; + bool operator<(const DynamicProfileRule &other) const; int serial_number; Range iso; @@ -63,9 +63,9 @@ public: }; -bool loadDynamicProfileEntries(std::vector &out); -bool storeDynamicProfileEntries( - const std::vector &entries); +bool loadDynamicProfileRules(std::vector &out); +bool storeDynamicProfileRules( + const std::vector &rules); rtengine::procparams::PartialProfile *loadDynamicProfile( const rtengine::ImageMetaData *im); diff --git a/rtgui/dynamicprofilepanel.cc b/rtgui/dynamicprofilepanel.cc index 0ac82f7ae..2d8ba638a 100644 --- a/rtgui/dynamicprofilepanel.cc +++ b/rtgui/dynamicprofilepanel.cc @@ -69,40 +69,40 @@ DynamicProfilePanel::EditDialog::EditDialog(const Glib::ustring &title, } -void DynamicProfilePanel::EditDialog::set_entry( - const DynamicProfileEntry &entry) +void DynamicProfilePanel::EditDialog::set_rule( + const DynamicProfileRule &rule) { - iso_min_->set_value(entry.iso.min); - iso_max_->set_value(entry.iso.max); + iso_min_->set_value(rule.iso.min); + iso_max_->set_value(rule.iso.max); - fnumber_min_->set_value(entry.fnumber.min); - fnumber_max_->set_value(entry.fnumber.max); + fnumber_min_->set_value(rule.fnumber.min); + fnumber_max_->set_value(rule.fnumber.max); - focallen_min_->set_value(entry.focallen.min); - focallen_max_->set_value(entry.focallen.max); + focallen_min_->set_value(rule.focallen.min); + focallen_max_->set_value(rule.focallen.max); - shutterspeed_min_->set_value(entry.shutterspeed.min); - shutterspeed_max_->set_value(entry.shutterspeed.max); + shutterspeed_min_->set_value(rule.shutterspeed.min); + shutterspeed_max_->set_value(rule.shutterspeed.max); - expcomp_min_->set_value(entry.expcomp.min); - expcomp_max_->set_value(entry.expcomp.max); + expcomp_min_->set_value(rule.expcomp.min); + expcomp_max_->set_value(rule.expcomp.max); - has_camera_->set_active(entry.camera.enabled); - camera_->set_text(entry.camera.value); + has_camera_->set_active(rule.camera.enabled); + camera_->set_text(rule.camera.value); - has_lens_->set_active(entry.lens.enabled); - lens_->set_text(entry.lens.value); + has_lens_->set_active(rule.lens.enabled); + lens_->set_text(rule.lens.value); profilepath_->updateProfileList(); - if (!profilepath_->setActiveRowFromFullPath(entry.profilepath)) { + if (!profilepath_->setActiveRowFromFullPath(rule.profilepath)) { profilepath_->setInternalEntry(); } } -DynamicProfileEntry DynamicProfilePanel::EditDialog::get_entry() +DynamicProfileRule DynamicProfilePanel::EditDialog::get_rule() { - DynamicProfileEntry ret; + DynamicProfileRule ret; ret.iso.min = iso_min_->get_value_as_int(); ret.iso.max = iso_max_->get_value_as_int(); @@ -131,27 +131,27 @@ DynamicProfileEntry DynamicProfilePanel::EditDialog::get_entry() void DynamicProfilePanel::EditDialog::set_ranges() { - DynamicProfileEntry default_entry; + DynamicProfileRule default_rule; iso_min_->set_digits(0); iso_max_->set_digits(0); iso_min_->set_increments(1, 10); iso_max_->set_increments(1, 10); - iso_min_->set_range(default_entry.iso.min, default_entry.iso.max); - iso_max_->set_range(default_entry.iso.min, default_entry.iso.max); - iso_min_->set_value(default_entry.iso.min); - iso_max_->set_value(default_entry.iso.max); + iso_min_->set_range(default_rule.iso.min, default_rule.iso.max); + iso_max_->set_range(default_rule.iso.min, default_rule.iso.max); + iso_min_->set_value(default_rule.iso.min); + iso_max_->set_value(default_rule.iso.max); #define DOIT_(name) \ name ## _min_->set_digits(1); \ name ## _max_->set_digits(1); \ name ## _min_->set_increments(0.1, 1); \ name ## _max_->set_increments(0.1, 1); \ - name ## _min_->set_range(default_entry. name .min, \ - default_entry. name .max); \ - name ## _max_->set_range(default_entry. name .min, \ - default_entry. name .max); \ - name ## _min_->set_value(default_entry. name .min); \ - name ## _max_->set_value(default_entry. name .max) + name ## _min_->set_range(default_rule. name .min, \ + default_rule. name .max); \ + name ## _max_->set_range(default_rule. name .min, \ + default_rule. name .max); \ + name ## _min_->set_value(default_rule. name .min); \ + name ## _max_->set_value(default_rule. name .max) DOIT_(fnumber); DOIT_(focallen); @@ -308,39 +308,39 @@ DynamicProfilePanel::DynamicProfilePanel(): show_all_children(); - std::vector entries; - if (loadDynamicProfileEntries(entries)) { - for (auto &e : entries) { - add_entry(e); + std::vector rules; + if (loadDynamicProfileRules(rules)) { + for (auto &r : rules) { + add_rule(r); } } } -void DynamicProfilePanel::update_entry(Gtk::TreeModel::Row row, - const DynamicProfileEntry &entry) +void DynamicProfilePanel::update_rule(Gtk::TreeModel::Row row, + const DynamicProfileRule &rule) { - row[columns_.iso] = entry.iso; - row[columns_.fnumber] = entry.fnumber; - row[columns_.focallen] = entry.focallen; - row[columns_.shutterspeed] = entry.shutterspeed; - row[columns_.expcomp] = entry.expcomp; - row[columns_.camera] = entry.camera; - row[columns_.lens] = entry.lens; - row[columns_.profilepath] = entry.profilepath; + row[columns_.iso] = rule.iso; + row[columns_.fnumber] = rule.fnumber; + row[columns_.focallen] = rule.focallen; + row[columns_.shutterspeed] = rule.shutterspeed; + row[columns_.expcomp] = rule.expcomp; + row[columns_.camera] = rule.camera; + row[columns_.lens] = rule.lens; + row[columns_.profilepath] = rule.profilepath; } -void DynamicProfilePanel::add_entry(const DynamicProfileEntry &entry) +void DynamicProfilePanel::add_rule(const DynamicProfileRule &rule) { auto row = *(treemodel_->append()); - update_entry(row, entry); + update_rule(row, rule); } -DynamicProfileEntry DynamicProfilePanel::to_entry(Gtk::TreeModel::Row row, +DynamicProfileRule DynamicProfilePanel::to_rule(Gtk::TreeModel::Row row, int serial) { - DynamicProfileEntry ret; + DynamicProfileRule ret; ret.serial_number = serial; ret.iso = row[columns_.iso]; ret.fnumber = row[columns_.fnumber]; @@ -372,8 +372,8 @@ void DynamicProfilePanel::render_profilepath( #define RENDER_RANGE_(tp, name, prec) \ auto row = *iter; \ Gtk::CellRendererText *ct = static_cast(cell); \ - DynamicProfileEntry::Range r = row[columns_. name]; \ - DynamicProfileEntry dflt; \ + DynamicProfileRule::Range r = row[columns_. name]; \ + DynamicProfileRule dflt; \ if (r.min > dflt.name.min || r.max < dflt.name.max) { \ auto value = to_str(r.min, prec) + " - " + to_str(r.max, prec); \ ct->property_text() = value; \ @@ -420,7 +420,7 @@ void DynamicProfilePanel::render_expcomp( #define RENDER_OPTIONAL_(name) \ auto row = *iter; \ Gtk::CellRendererText *ct = static_cast(cell); \ - DynamicProfileEntry::Optional o = row[columns_. name]; \ + DynamicProfileRule::Optional o = row[columns_. name]; \ if (o.enabled) { \ ct->property_text() = o.value; \ } else { \ @@ -488,8 +488,8 @@ void DynamicProfilePanel::on_button_new() static_cast(*get_toplevel())); int status = d.run(); if (status == 1) { - DynamicProfileEntry entry = d.get_entry(); - add_entry(entry); + DynamicProfileRule rule = d.get_rule(); + add_rule(rule); } } @@ -504,24 +504,24 @@ void DynamicProfilePanel::on_button_edit() static_cast(*get_toplevel())); auto it = s->get_selected(); Gtk::TreeModel::Row row = *(s->get_selected()); - d.set_entry(to_entry(row)); + d.set_rule(to_rule(row)); int status = d.run(); if (status == 1) { - update_entry(row, d.get_entry()); + update_rule(row, d.get_rule()); } } void DynamicProfilePanel::save() { - std::vector entries; + std::vector rules; int serial = 1; for (auto row : treemodel_->children()) { - entries.emplace_back(to_entry(row, serial++)); + rules.emplace_back(to_rule(row, serial++)); } - if (!storeDynamicProfileEntries(entries)) { + if (!storeDynamicProfileRules(rules)) { printf("Error in saving dynamic profile rules\n"); } else { - printf("Saved %d dynamic profile rules\n", int(entries.size())); + printf("Saved %d dynamic profile rules\n", int(rules.size())); } } diff --git a/rtgui/dynamicprofilepanel.h b/rtgui/dynamicprofilepanel.h index 12b68fadc..72ff95b9a 100644 --- a/rtgui/dynamicprofilepanel.h +++ b/rtgui/dynamicprofilepanel.h @@ -29,10 +29,10 @@ public: void save(); private: - void update_entry(Gtk::TreeModel::Row row, - const DynamicProfileEntry &entry); - void add_entry(const DynamicProfileEntry &entry); - DynamicProfileEntry to_entry(Gtk::TreeModel::Row row, int serial=0); + void update_rule(Gtk::TreeModel::Row row, + const DynamicProfileRule &rule); + void add_rule(const DynamicProfileRule &rule); + DynamicProfileRule to_rule(Gtk::TreeModel::Row row, int serial=0); void on_button_quit(); void on_button_up(); @@ -55,13 +55,13 @@ private: add(profilepath); } - Gtk::TreeModelColumn> iso; - Gtk::TreeModelColumn> fnumber; - Gtk::TreeModelColumn> focallen; - Gtk::TreeModelColumn> shutterspeed; - Gtk::TreeModelColumn> expcomp; - Gtk::TreeModelColumn camera; - Gtk::TreeModelColumn lens; + Gtk::TreeModelColumn> iso; + Gtk::TreeModelColumn> fnumber; + Gtk::TreeModelColumn> focallen; + Gtk::TreeModelColumn> shutterspeed; + Gtk::TreeModelColumn> expcomp; + Gtk::TreeModelColumn camera; + Gtk::TreeModelColumn lens; Gtk::TreeModelColumn profilepath; }; @@ -86,8 +86,8 @@ private: class EditDialog: public Gtk::Dialog { public: EditDialog(const Glib::ustring &title, Gtk::Window &parent); - void set_entry(const DynamicProfileEntry &entry); - DynamicProfileEntry get_entry(); + void set_rule(const DynamicProfileRule &rule); + DynamicProfileRule get_rule(); private: void set_ranges();