2017-10-30 17:41:50 +00:00
|
|
|
#ifndef slic3r_AppConfig_hpp_
|
|
|
|
#define slic3r_AppConfig_hpp_
|
|
|
|
|
2018-03-28 09:36:36 +00:00
|
|
|
#include <set>
|
2017-10-30 17:41:50 +00:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
2020-03-11 17:12:16 +00:00
|
|
|
#include <boost/algorithm/string/trim_all.hpp>
|
|
|
|
|
2018-03-28 09:36:36 +00:00
|
|
|
#include "libslic3r/Config.hpp"
|
2019-08-09 15:01:37 +00:00
|
|
|
#include "libslic3r/Semver.hpp"
|
2018-03-28 09:36:36 +00:00
|
|
|
|
2017-10-30 17:41:50 +00:00
|
|
|
namespace Slic3r {
|
|
|
|
|
|
|
|
class AppConfig
|
|
|
|
{
|
|
|
|
public:
|
2018-05-17 14:19:40 +00:00
|
|
|
AppConfig() :
|
|
|
|
m_dirty(false),
|
|
|
|
m_orig_version(Semver::invalid()),
|
|
|
|
m_legacy_datadir(false)
|
|
|
|
{
|
|
|
|
this->reset();
|
|
|
|
}
|
2017-10-30 17:41:50 +00:00
|
|
|
|
|
|
|
// Clear and reset to defaults.
|
|
|
|
void reset();
|
|
|
|
// Override missing or keys with their defaults.
|
|
|
|
void set_defaults();
|
|
|
|
|
2017-11-01 18:30:05 +00:00
|
|
|
// Load the slic3r.ini from a user profile directory (or a datadir, if configured).
|
2017-10-30 17:41:50 +00:00
|
|
|
void load();
|
2017-11-01 18:30:05 +00:00
|
|
|
// Store the slic3r.ini into a user profile directory (or a datadir, if configured).
|
2017-10-30 17:41:50 +00:00
|
|
|
void save();
|
|
|
|
|
|
|
|
// Does this config need to be saved?
|
|
|
|
bool dirty() const { return m_dirty; }
|
|
|
|
|
|
|
|
// Const accessor, it will return false if a section or a key does not exist.
|
|
|
|
bool get(const std::string §ion, const std::string &key, std::string &value) const
|
|
|
|
{
|
|
|
|
value.clear();
|
|
|
|
auto it = m_storage.find(section);
|
|
|
|
if (it == m_storage.end())
|
|
|
|
return false;
|
|
|
|
auto it2 = it->second.find(key);
|
|
|
|
if (it2 == it->second.end())
|
|
|
|
return false;
|
|
|
|
value = it2->second;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
std::string get(const std::string §ion, const std::string &key) const
|
|
|
|
{ std::string value; this->get(section, key, value); return value; }
|
|
|
|
std::string get(const std::string &key) const
|
|
|
|
{ std::string value; this->get("", key, value); return value; }
|
|
|
|
void set(const std::string §ion, const std::string &key, const std::string &value)
|
2020-03-11 17:12:16 +00:00
|
|
|
{
|
|
|
|
#ifndef _NDEBUG
|
|
|
|
std::string key_trimmed = key;
|
|
|
|
boost::trim_all(key_trimmed);
|
|
|
|
assert(key_trimmed == key);
|
|
|
|
assert(! key_trimmed.empty());
|
|
|
|
#endif _NDEBUG
|
2017-10-30 17:41:50 +00:00
|
|
|
std::string &old = m_storage[section][key];
|
|
|
|
if (old != value) {
|
|
|
|
old = value;
|
|
|
|
m_dirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void set(const std::string &key, const std::string &value)
|
|
|
|
{ this->set("", key, value); }
|
|
|
|
bool has(const std::string §ion, const std::string &key) const
|
|
|
|
{
|
|
|
|
auto it = m_storage.find(section);
|
|
|
|
if (it == m_storage.end())
|
|
|
|
return false;
|
|
|
|
auto it2 = it->second.find(key);
|
|
|
|
return it2 != it->second.end() && ! it2->second.empty();
|
|
|
|
}
|
|
|
|
bool has(const std::string &key) const
|
|
|
|
{ return this->has("", key); }
|
|
|
|
|
2018-09-17 13:12:13 +00:00
|
|
|
void erase(const std::string §ion, const std::string &key)
|
|
|
|
{
|
|
|
|
auto it = m_storage.find(section);
|
|
|
|
if (it != m_storage.end()) {
|
|
|
|
it->second.erase(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-12 14:18:46 +00:00
|
|
|
bool has_section(const std::string §ion) const
|
|
|
|
{ return m_storage.find(section) != m_storage.end(); }
|
|
|
|
const std::map<std::string, std::string>& get_section(const std::string §ion) const
|
|
|
|
{ return m_storage.find(section)->second; }
|
|
|
|
void set_section(const std::string §ion, const std::map<std::string, std::string>& data)
|
|
|
|
{ m_storage[section] = data; }
|
2017-11-01 18:30:05 +00:00
|
|
|
void clear_section(const std::string §ion)
|
|
|
|
{ m_storage[section].clear(); }
|
|
|
|
|
2018-04-12 18:04:48 +00:00
|
|
|
typedef std::map<std::string, std::map<std::string, std::set<std::string>>> VendorMap;
|
2018-04-06 10:15:28 +00:00
|
|
|
bool get_variant(const std::string &vendor, const std::string &model, const std::string &variant) const;
|
|
|
|
void set_variant(const std::string &vendor, const std::string &model, const std::string &variant, bool enable);
|
|
|
|
void set_vendors(const AppConfig &from);
|
2018-04-12 18:04:48 +00:00
|
|
|
void set_vendors(const VendorMap &vendors) { m_vendors = vendors; m_dirty = true; }
|
|
|
|
void set_vendors(VendorMap &&vendors) { m_vendors = std::move(vendors); m_dirty = true; }
|
|
|
|
const VendorMap& vendors() const { return m_vendors; }
|
2018-03-28 09:36:36 +00:00
|
|
|
|
2017-10-30 17:41:50 +00:00
|
|
|
// return recent/skein_directory or recent/config_directory or empty string.
|
|
|
|
std::string get_last_dir() const;
|
|
|
|
void update_config_dir(const std::string &dir);
|
|
|
|
void update_skein_dir(const std::string &dir);
|
|
|
|
|
2020-01-02 15:30:28 +00:00
|
|
|
//std::string get_last_output_dir(const std::string &alt) const;
|
|
|
|
//void update_last_output_dir(const std::string &dir);
|
|
|
|
std::string get_last_output_dir(const std::string& alt, const bool removable = false) const;
|
|
|
|
void update_last_output_dir(const std::string &dir, const bool removable = false);
|
2017-10-30 17:41:50 +00:00
|
|
|
|
2018-03-14 12:29:50 +00:00
|
|
|
// reset the current print / filament / printer selections, so that
|
|
|
|
// the PresetBundle::load_selections(const AppConfig &config) call will select
|
|
|
|
// the first non-default preset when called.
|
|
|
|
void reset_selections();
|
|
|
|
|
2017-10-30 17:41:50 +00:00
|
|
|
// Get the default config path from Slic3r::data_dir().
|
|
|
|
static std::string config_path();
|
2018-04-25 15:43:01 +00:00
|
|
|
|
|
|
|
// Returns true if the user's data directory comes from before Slic3r 1.40.0 (no updating)
|
2018-04-16 14:52:11 +00:00
|
|
|
bool legacy_datadir() const { return m_legacy_datadir; }
|
2018-05-18 06:46:33 +00:00
|
|
|
void set_legacy_datadir(bool value) { m_legacy_datadir = value; }
|
2017-10-30 17:41:50 +00:00
|
|
|
|
2018-04-25 15:43:01 +00:00
|
|
|
// Get the Slic3r version check url.
|
|
|
|
// This returns a hardcoded string unless it is overriden by "version_check_url" in the ini file.
|
|
|
|
std::string version_check_url() const;
|
|
|
|
|
2018-05-17 14:19:40 +00:00
|
|
|
// Returns the original Slic3r version found in the ini file before it was overwritten
|
|
|
|
// by the current version
|
|
|
|
Semver orig_version() const { return m_orig_version; }
|
|
|
|
|
2017-10-30 17:41:50 +00:00
|
|
|
// Does the config file exist?
|
|
|
|
static bool exists();
|
|
|
|
|
2019-07-12 13:36:01 +00:00
|
|
|
std::vector<std::string> get_recent_projects() const;
|
|
|
|
void set_recent_projects(const std::vector<std::string>& recent_projects);
|
|
|
|
|
2020-03-20 12:09:42 +00:00
|
|
|
void set_mouse_device(const std::string& name, double translation_speed, double translation_deadzone, float rotation_speed, float rotation_deadzone, double zoom_speed, bool swap_yz_translations);
|
2020-03-04 10:36:36 +00:00
|
|
|
std::vector<std::string> get_mouse_device_names() const;
|
|
|
|
bool get_mouse_device_translation_speed(const std::string& name, double& speed) const
|
|
|
|
{ return get_3dmouse_device_numeric_value(name, "translation_speed", speed); }
|
|
|
|
bool get_mouse_device_translation_deadzone(const std::string& name, double& deadzone) const
|
|
|
|
{ return get_3dmouse_device_numeric_value(name, "translation_deadzone", deadzone); }
|
|
|
|
bool get_mouse_device_rotation_speed(const std::string& name, float& speed) const
|
|
|
|
{ return get_3dmouse_device_numeric_value(name, "rotation_speed", speed); }
|
|
|
|
bool get_mouse_device_rotation_deadzone(const std::string& name, float& deadzone) const
|
|
|
|
{ return get_3dmouse_device_numeric_value(name, "rotation_deadzone", deadzone); }
|
|
|
|
bool get_mouse_device_zoom_speed(const std::string& name, double& speed) const
|
|
|
|
{ return get_3dmouse_device_numeric_value(name, "zoom_speed", speed); }
|
2020-03-20 12:09:42 +00:00
|
|
|
bool get_mouse_device_swap_yz_translations(const std::string& name, bool& swap) const
|
|
|
|
{ return get_3dmouse_device_numeric_value(name, "swap_yz_translations", swap); }
|
2019-10-03 08:26:28 +00:00
|
|
|
|
2019-06-03 08:15:26 +00:00
|
|
|
static const std::string SECTION_FILAMENTS;
|
|
|
|
static const std::string SECTION_MATERIALS;
|
2019-10-08 06:44:50 +00:00
|
|
|
|
2017-10-30 17:41:50 +00:00
|
|
|
private:
|
2020-03-04 10:36:36 +00:00
|
|
|
template<typename T>
|
|
|
|
bool get_3dmouse_device_numeric_value(const std::string &device_name, const char *parameter_name, T &out) const
|
|
|
|
{
|
|
|
|
std::string key = std::string("mouse_device:") + device_name;
|
|
|
|
auto it = m_storage.find(key);
|
|
|
|
if (it == m_storage.end())
|
|
|
|
return false;
|
|
|
|
auto it_val = it->second.find(parameter_name);
|
|
|
|
if (it_val == it->second.end())
|
|
|
|
return false;
|
|
|
|
out = T(::atof(it_val->second.c_str()));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-10-30 17:41:50 +00:00
|
|
|
// Map of section, name -> value
|
|
|
|
std::map<std::string, std::map<std::string, std::string>> m_storage;
|
2018-03-28 09:36:36 +00:00
|
|
|
// Map of enabled vendors / models / variants
|
2018-04-12 18:04:48 +00:00
|
|
|
VendorMap m_vendors;
|
2017-10-30 17:41:50 +00:00
|
|
|
// Has any value been modified since the config.ini has been last saved or loaded?
|
|
|
|
bool m_dirty;
|
2018-05-17 14:19:40 +00:00
|
|
|
// Original version found in the ini file before it was overwritten
|
|
|
|
Semver m_orig_version;
|
2018-04-16 14:52:11 +00:00
|
|
|
// Whether the existing version is before system profiles & configuration updating
|
|
|
|
bool m_legacy_datadir;
|
2017-10-30 17:41:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}; // namespace Slic3r
|
|
|
|
|
|
|
|
#endif /* slic3r_AppConfig_hpp_ */
|