2017-09-19 11:55:48 +00:00
|
|
|
#ifndef slic3r_Preset_hpp_
|
|
|
|
#define slic3r_Preset_hpp_
|
|
|
|
|
2017-10-25 10:53:31 +00:00
|
|
|
#include <deque>
|
2019-06-17 14:39:22 +00:00
|
|
|
#include <set>
|
|
|
|
#include <unordered_map>
|
2017-10-25 10:53:31 +00:00
|
|
|
|
2018-04-11 11:12:08 +00:00
|
|
|
#include <boost/filesystem/path.hpp>
|
|
|
|
#include <boost/property_tree/ptree_fwd.hpp>
|
|
|
|
|
2020-06-16 14:58:41 +00:00
|
|
|
#include "PrintConfig.hpp"
|
|
|
|
#include "Semver.hpp"
|
2017-09-19 11:55:48 +00:00
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2018-03-29 15:54:43 +00:00
|
|
|
class AppConfig;
|
2018-04-13 12:49:33 +00:00
|
|
|
class PresetBundle;
|
2018-03-29 15:54:43 +00:00
|
|
|
|
2017-11-01 18:30:05 +00:00
|
|
|
enum ConfigFileType
|
|
|
|
{
|
|
|
|
CONFIG_FILE_TYPE_UNKNOWN,
|
|
|
|
CONFIG_FILE_TYPE_APP_CONFIG,
|
|
|
|
CONFIG_FILE_TYPE_CONFIG,
|
|
|
|
CONFIG_FILE_TYPE_CONFIG_BUNDLE,
|
|
|
|
};
|
|
|
|
|
|
|
|
extern ConfigFileType guess_config_file_type(const boost::property_tree::ptree &tree);
|
|
|
|
|
2018-03-09 15:37:33 +00:00
|
|
|
class VendorProfile
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string name;
|
|
|
|
std::string id;
|
2018-04-11 11:12:08 +00:00
|
|
|
Semver config_version;
|
2018-03-09 15:37:33 +00:00
|
|
|
std::string config_update_url;
|
2019-05-13 16:38:48 +00:00
|
|
|
std::string changelog_url;
|
2018-03-09 15:37:33 +00:00
|
|
|
|
|
|
|
struct PrinterVariant {
|
|
|
|
PrinterVariant() {}
|
|
|
|
PrinterVariant(const std::string &name) : name(name) {}
|
|
|
|
std::string name;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PrinterModel {
|
|
|
|
PrinterModel() {}
|
2018-03-13 11:39:57 +00:00
|
|
|
std::string id;
|
2018-03-09 15:37:33 +00:00
|
|
|
std::string name;
|
2018-07-31 13:09:57 +00:00
|
|
|
PrinterTechnology technology;
|
2019-01-30 14:22:17 +00:00
|
|
|
std::string family;
|
2018-03-09 15:37:33 +00:00
|
|
|
std::vector<PrinterVariant> variants;
|
2020-01-13 15:01:01 +00:00
|
|
|
std::vector<std::string> default_materials;
|
2020-01-07 13:08:21 +00:00
|
|
|
// Vendor & Printer Model specific print bed model & texture.
|
|
|
|
std::string bed_model;
|
|
|
|
std::string bed_texture;
|
2019-01-30 14:22:17 +00:00
|
|
|
|
2018-03-09 15:37:33 +00:00
|
|
|
PrinterVariant* variant(const std::string &name) {
|
|
|
|
for (auto &v : this->variants)
|
|
|
|
if (v.name == name)
|
|
|
|
return &v;
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-01-30 14:22:17 +00:00
|
|
|
|
2018-03-09 15:37:33 +00:00
|
|
|
const PrinterVariant* variant(const std::string &name) const { return const_cast<PrinterModel*>(this)->variant(name); }
|
|
|
|
};
|
2018-03-13 11:39:57 +00:00
|
|
|
std::vector<PrinterModel> models;
|
|
|
|
|
2019-04-12 14:18:46 +00:00
|
|
|
std::set<std::string> default_filaments;
|
|
|
|
std::set<std::string> default_sla_materials;
|
|
|
|
|
2018-04-12 18:04:48 +00:00
|
|
|
VendorProfile() {}
|
|
|
|
VendorProfile(std::string id) : id(std::move(id)) {}
|
2018-04-11 11:12:08 +00:00
|
|
|
|
2019-12-10 14:01:24 +00:00
|
|
|
bool valid() const { return ! name.empty() && ! id.empty() && config_version.valid(); }
|
|
|
|
|
2019-04-12 14:18:46 +00:00
|
|
|
// Load VendorProfile from an ini file.
|
|
|
|
// If `load_all` is false, only the header with basic info (name, version, URLs) is loaded.
|
2018-04-11 11:12:08 +00:00
|
|
|
static VendorProfile from_ini(const boost::filesystem::path &path, bool load_all=true);
|
|
|
|
static VendorProfile from_ini(const boost::property_tree::ptree &tree, const boost::filesystem::path &path, bool load_all=true);
|
2018-03-09 15:37:33 +00:00
|
|
|
|
|
|
|
size_t num_variants() const { size_t n = 0; for (auto &model : models) n += model.variants.size(); return n; }
|
2019-01-30 14:22:17 +00:00
|
|
|
std::vector<std::string> families() const;
|
2018-03-09 15:37:33 +00:00
|
|
|
|
|
|
|
bool operator< (const VendorProfile &rhs) const { return this->id < rhs.id; }
|
|
|
|
bool operator==(const VendorProfile &rhs) const { return this->id == rhs.id; }
|
|
|
|
};
|
|
|
|
|
2019-12-05 13:48:11 +00:00
|
|
|
class Preset;
|
|
|
|
|
|
|
|
// Helper to hold a profile with its vendor definition, where the vendor definition may have been extracted from a parent system preset.
|
|
|
|
// The parent preset is only accessible through PresetCollection, therefore to allow definition of the various is_compatible_with methods
|
|
|
|
// outside of the PresetCollection, this composite is returned by PresetCollection::get_preset_with_vendor_profile() when needed.
|
|
|
|
struct PresetWithVendorProfile {
|
|
|
|
PresetWithVendorProfile(const Preset &preset, const VendorProfile *vendor) : preset(preset), vendor(vendor) {}
|
|
|
|
const Preset &preset;
|
|
|
|
const VendorProfile *vendor;
|
|
|
|
};
|
|
|
|
|
2019-06-17 14:39:22 +00:00
|
|
|
// Note: it is imporant that map is used here rather than unordered_map,
|
|
|
|
// because we need iterators to not be invalidated,
|
|
|
|
// because Preset and the ConfigWizard hold pointers to VendorProfiles.
|
|
|
|
// XXX: maybe set is enough (cf. changes in Wizard)
|
|
|
|
typedef std::map<std::string, VendorProfile> VendorMap;
|
|
|
|
|
2017-09-19 11:55:48 +00:00
|
|
|
class Preset
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
TYPE_INVALID,
|
|
|
|
TYPE_PRINT,
|
2018-11-16 16:36:23 +00:00
|
|
|
TYPE_SLA_PRINT,
|
2017-09-19 11:55:48 +00:00
|
|
|
TYPE_FILAMENT,
|
2018-07-31 13:09:57 +00:00
|
|
|
TYPE_SLA_MATERIAL,
|
2017-09-19 11:55:48 +00:00
|
|
|
TYPE_PRINTER,
|
2020-05-04 19:22:56 +00:00
|
|
|
TYPE_COUNT,
|
2017-09-19 11:55:48 +00:00
|
|
|
};
|
|
|
|
|
2017-09-20 08:03:53 +00:00
|
|
|
Preset(Type type, const std::string &name, bool is_default = false) : type(type), is_default(is_default), name(name) {}
|
2017-09-19 11:55:48 +00:00
|
|
|
|
|
|
|
Type type = TYPE_INVALID;
|
|
|
|
|
|
|
|
// The preset represents a "default" set of properties,
|
|
|
|
// pulled from the default values of the PrintConfig (see PrintConfigDef for their definitions).
|
|
|
|
bool is_default;
|
|
|
|
// External preset points to a configuration, which has been loaded but not imported
|
|
|
|
// into the Slic3r default configuration location.
|
|
|
|
bool is_external = false;
|
2018-03-09 15:37:33 +00:00
|
|
|
// System preset is read-only.
|
|
|
|
bool is_system = false;
|
2018-04-06 11:18:12 +00:00
|
|
|
// Preset is visible, if it is associated with a printer model / variant that is enabled in the AppConfig
|
|
|
|
// or if it has no printer model / variant association.
|
2017-09-19 11:55:48 +00:00
|
|
|
// Also the "default" preset is only visible, if it is the only preset in the list.
|
|
|
|
bool is_visible = true;
|
|
|
|
// Has this preset been modified?
|
|
|
|
bool is_dirty = false;
|
2017-11-10 16:27:05 +00:00
|
|
|
// Is this preset compatible with the currently active printer?
|
|
|
|
bool is_compatible = true;
|
2017-09-19 11:55:48 +00:00
|
|
|
|
2019-03-22 11:11:23 +00:00
|
|
|
bool is_user() const { return ! this->is_default && ! this->is_system; }
|
|
|
|
|
2017-09-19 11:55:48 +00:00
|
|
|
// Name of the preset, usually derived form the file name.
|
|
|
|
std::string name;
|
|
|
|
// File name of the preset. This could be a Print / Filament / Printer preset,
|
2018-03-09 15:37:33 +00:00
|
|
|
// or a Configuration file bundling the Print + Filament + Printer presets (in that case is_external and possibly is_system will be true),
|
2017-09-19 11:55:48 +00:00
|
|
|
// or it could be a G-code (again, is_external will be true).
|
|
|
|
std::string file;
|
2018-03-09 15:37:33 +00:00
|
|
|
// If this is a system profile, then there should be a vendor data available to display at the UI.
|
|
|
|
const VendorProfile *vendor = nullptr;
|
2017-09-19 11:55:48 +00:00
|
|
|
|
|
|
|
// Has this profile been loaded?
|
|
|
|
bool loaded = false;
|
|
|
|
|
|
|
|
// Configuration data, loaded from a file, or set from the defaults.
|
|
|
|
DynamicPrintConfig config;
|
|
|
|
|
2019-11-21 12:12:06 +00:00
|
|
|
// Alias of the preset
|
2020-01-23 15:04:17 +00:00
|
|
|
std::string alias;
|
2020-01-02 15:40:32 +00:00
|
|
|
// List of profile names, from which this profile was renamed at some point of time.
|
|
|
|
// This list is then used to match profiles by their names when loaded from .gcode, .3mf, .amf,
|
|
|
|
// and to match the "inherits" field of user profiles with updated system profiles.
|
|
|
|
std::vector<std::string> renamed_from;
|
2019-11-21 12:12:06 +00:00
|
|
|
|
2017-10-25 10:53:31 +00:00
|
|
|
void save();
|
|
|
|
|
|
|
|
// Return a label of this preset, consisting of a name and a "(modified)" suffix, if this preset is dirty.
|
|
|
|
std::string label() const;
|
|
|
|
|
2017-09-19 11:55:48 +00:00
|
|
|
// Set the is_dirty flag if the provided config is different from the active one.
|
2017-09-20 08:03:53 +00:00
|
|
|
void set_dirty(const DynamicPrintConfig &config) { this->is_dirty = ! this->config.diff(config).empty(); }
|
2017-10-25 10:53:31 +00:00
|
|
|
void set_dirty(bool dirty = true) { this->is_dirty = dirty; }
|
2017-09-19 11:55:48 +00:00
|
|
|
void reset_dirty() { this->is_dirty = false; }
|
2017-10-25 10:53:31 +00:00
|
|
|
|
2018-06-27 14:57:42 +00:00
|
|
|
// Returns the name of the preset, from which this preset inherits.
|
2018-06-28 18:13:01 +00:00
|
|
|
static std::string& inherits(DynamicPrintConfig &cfg) { return cfg.option<ConfigOptionString>("inherits", true)->value; }
|
2018-06-27 14:57:42 +00:00
|
|
|
std::string& inherits() { return Preset::inherits(this->config); }
|
|
|
|
const std::string& inherits() const { return Preset::inherits(const_cast<Preset*>(this)->config); }
|
|
|
|
|
2018-12-04 16:56:49 +00:00
|
|
|
// Returns the "compatible_prints_condition".
|
|
|
|
static std::string& compatible_prints_condition(DynamicPrintConfig &cfg) { return cfg.option<ConfigOptionString>("compatible_prints_condition", true)->value; }
|
|
|
|
std::string& compatible_prints_condition() {
|
|
|
|
assert(this->type == TYPE_FILAMENT || this->type == TYPE_SLA_MATERIAL);
|
|
|
|
return Preset::compatible_prints_condition(this->config);
|
|
|
|
}
|
|
|
|
const std::string& compatible_prints_condition() const { return const_cast<Preset*>(this)->compatible_prints_condition(); }
|
|
|
|
|
2018-06-27 14:57:42 +00:00
|
|
|
// Returns the "compatible_printers_condition".
|
2018-06-28 18:13:01 +00:00
|
|
|
static std::string& compatible_printers_condition(DynamicPrintConfig &cfg) { return cfg.option<ConfigOptionString>("compatible_printers_condition", true)->value; }
|
2018-12-04 16:56:49 +00:00
|
|
|
std::string& compatible_printers_condition() {
|
|
|
|
assert(this->type == TYPE_PRINT || this->type == TYPE_SLA_PRINT || this->type == TYPE_FILAMENT || this->type == TYPE_SLA_MATERIAL);
|
|
|
|
return Preset::compatible_printers_condition(this->config);
|
|
|
|
}
|
|
|
|
const std::string& compatible_printers_condition() const { return const_cast<Preset*>(this)->compatible_printers_condition(); }
|
2018-06-27 14:57:42 +00:00
|
|
|
|
2019-01-10 17:08:38 +00:00
|
|
|
// Return a printer technology, return ptFFF if the printer technology is not set.
|
|
|
|
static PrinterTechnology printer_technology(const DynamicPrintConfig &cfg) {
|
|
|
|
auto *opt = cfg.option<ConfigOptionEnum<PrinterTechnology>>("printer_technology");
|
|
|
|
// The following assert may trigger when importing some legacy profile,
|
|
|
|
// but it is safer to keep it here to capture the cases where the "printer_technology" key is queried, where it should not.
|
2019-01-11 10:15:32 +00:00
|
|
|
// assert(opt != nullptr);
|
2019-01-10 17:08:38 +00:00
|
|
|
return (opt == nullptr) ? ptFFF : opt->value;
|
|
|
|
}
|
|
|
|
PrinterTechnology printer_technology() const { return Preset::printer_technology(this->config); }
|
|
|
|
// This call returns a reference, it may add a new entry into the DynamicPrintConfig.
|
|
|
|
PrinterTechnology& printer_technology_ref() { return this->config.option<ConfigOptionEnum<PrinterTechnology>>("printer_technology", true)->value; }
|
2018-07-31 13:09:57 +00:00
|
|
|
|
2018-03-29 15:54:43 +00:00
|
|
|
// Set is_visible according to application config
|
|
|
|
void set_visible_from_appconfig(const AppConfig &app_config);
|
|
|
|
|
2017-11-01 18:30:05 +00:00
|
|
|
// Resize the extruder specific fields, initialize them with the content of the 1st extruder.
|
2019-10-15 14:31:20 +00:00
|
|
|
void set_num_extruders(unsigned int n) { this->config.set_num_extruders(n); }
|
2017-11-01 18:30:05 +00:00
|
|
|
|
2017-10-25 10:53:31 +00:00
|
|
|
// Sort lexicographically by a preset name. The preset name shall be unique across a single PresetCollection.
|
|
|
|
bool operator<(const Preset &other) const { return this->name < other.name; }
|
2017-10-30 17:41:50 +00:00
|
|
|
|
2017-11-01 18:30:05 +00:00
|
|
|
static const std::vector<std::string>& print_options();
|
|
|
|
static const std::vector<std::string>& filament_options();
|
|
|
|
// Printer options contain the nozzle options.
|
|
|
|
static const std::vector<std::string>& printer_options();
|
|
|
|
// Nozzle options of the printer options.
|
|
|
|
static const std::vector<std::string>& nozzle_options();
|
2018-07-31 13:09:57 +00:00
|
|
|
|
|
|
|
static const std::vector<std::string>& sla_printer_options();
|
|
|
|
static const std::vector<std::string>& sla_material_options();
|
2018-11-16 16:36:23 +00:00
|
|
|
static const std::vector<std::string>& sla_print_options();
|
2018-07-31 13:09:57 +00:00
|
|
|
|
2020-06-16 14:58:41 +00:00
|
|
|
static void update_suffix_modified(const std::string& new_suffix_modified);
|
2019-03-20 09:14:49 +00:00
|
|
|
static const std::string& suffix_modified();
|
2020-03-16 08:57:20 +00:00
|
|
|
static std::string remove_suffix_modified(const std::string& name);
|
2018-10-31 15:22:36 +00:00
|
|
|
static void normalize(DynamicPrintConfig &config);
|
|
|
|
// Report configuration fields, which are misplaced into a wrong group, remove them from the config.
|
|
|
|
static std::string remove_invalid_keys(DynamicPrintConfig &config, const DynamicPrintConfig &default_config);
|
2017-11-01 18:30:05 +00:00
|
|
|
|
2017-10-30 17:41:50 +00:00
|
|
|
protected:
|
|
|
|
friend class PresetCollection;
|
|
|
|
friend class PresetBundle;
|
2017-09-19 11:55:48 +00:00
|
|
|
};
|
|
|
|
|
Various changes in handling of profile compatiblilities
and the "show incompatible profiles" option.
It was not able to select the incompatible Print profile, which is
possible now.
(see Cannot select incompatible printer profile #3715)
When the Printer profile derived from the Prusa3D system profile was
active or a system Prusa3D profile was active, and when the Print profile
with the removed "inherits" field was active (or any other profile
derived from the "-- default --" profile was active), then the filament
selector offered just the profiles with the removed "inherits" field
(or any other profile derived from the "-- default--") profile.
This behavior has been now changed, so that in this scenario the Filament selector
will offer the Prusa3D vendor profiles compatible with the active Print
and Printer profile as well as the user profiles.
Slicer was also changed to keep an incompatible preset selected
at its respective tab if its respective "Red flag" is enabled.
For example, if an incompatible Print preset is selected and a Printer
profile is switched to another one which is not compatible with the active
Print preset that was red already, the active Print preset is
not switched if the Print "Red flag" is active. However, if the Print profile
was compatible before the Printer profile is switched and now the Print
profile becomes incompatible, another compatible Print profile is selected.
A likely bug in wxWidgets was worked around when switching a Print preset
on Plater, if the last item in the Print preset was active and incompatible,
and another Print preset was selected by the user. On Windows, an CBN_EDITCHANGE
is sent just after combo box selection change event and the CBN_EDITCHANGE
holds an index of the combo box item, which will be removed by the 1st event,
therefore leading to an assert in wxWidgets on CBN_EDITCHANGE. The workaround
is to disable processing of CBN_EDITCHANGE on Windows for the Plater
preset selection combo boxes.
2020-02-27 10:44:01 +00:00
|
|
|
bool is_compatible_with_print (const PresetWithVendorProfile &preset, const PresetWithVendorProfile &active_print, const PresetWithVendorProfile &active_printer);
|
2019-12-05 13:48:11 +00:00
|
|
|
bool is_compatible_with_printer(const PresetWithVendorProfile &preset, const PresetWithVendorProfile &active_printer, const DynamicPrintConfig *extra_config);
|
|
|
|
bool is_compatible_with_printer(const PresetWithVendorProfile &preset, const PresetWithVendorProfile &active_printer);
|
|
|
|
|
Various changes in handling of profile compatiblilities
and the "show incompatible profiles" option.
It was not able to select the incompatible Print profile, which is
possible now.
(see Cannot select incompatible printer profile #3715)
When the Printer profile derived from the Prusa3D system profile was
active or a system Prusa3D profile was active, and when the Print profile
with the removed "inherits" field was active (or any other profile
derived from the "-- default --" profile was active), then the filament
selector offered just the profiles with the removed "inherits" field
(or any other profile derived from the "-- default--") profile.
This behavior has been now changed, so that in this scenario the Filament selector
will offer the Prusa3D vendor profiles compatible with the active Print
and Printer profile as well as the user profiles.
Slicer was also changed to keep an incompatible preset selected
at its respective tab if its respective "Red flag" is enabled.
For example, if an incompatible Print preset is selected and a Printer
profile is switched to another one which is not compatible with the active
Print preset that was red already, the active Print preset is
not switched if the Print "Red flag" is active. However, if the Print profile
was compatible before the Printer profile is switched and now the Print
profile becomes incompatible, another compatible Print profile is selected.
A likely bug in wxWidgets was worked around when switching a Print preset
on Plater, if the last item in the Print preset was active and incompatible,
and another Print preset was selected by the user. On Windows, an CBN_EDITCHANGE
is sent just after combo box selection change event and the CBN_EDITCHANGE
holds an index of the combo box item, which will be removed by the 1st event,
therefore leading to an assert in wxWidgets on CBN_EDITCHANGE. The workaround
is to disable processing of CBN_EDITCHANGE on Windows for the Plater
preset selection combo boxes.
2020-02-27 10:44:01 +00:00
|
|
|
enum class PresetSelectCompatibleType {
|
|
|
|
// Never select a compatible preset if the newly selected profile is not compatible.
|
|
|
|
Never,
|
|
|
|
// Only select a compatible preset if the active profile used to be compatible, but it is no more.
|
|
|
|
OnlyIfWasCompatible,
|
|
|
|
// Always select a compatible preset if the active profile is no more compatible.
|
|
|
|
Always
|
|
|
|
};
|
|
|
|
|
2017-09-19 11:55:48 +00:00
|
|
|
// Collections of presets of the same type (one of the Print, Filament or Printer type).
|
|
|
|
class PresetCollection
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Initialize the PresetCollection with the "- default -" preset.
|
2018-08-03 12:14:25 +00:00
|
|
|
PresetCollection(Preset::Type type, const std::vector<std::string> &keys, const Slic3r::StaticPrintConfig &defaults, const std::string &default_name = "- default -");
|
2017-10-25 10:53:31 +00:00
|
|
|
~PresetCollection();
|
|
|
|
|
2018-03-29 15:54:43 +00:00
|
|
|
typedef std::deque<Preset>::iterator Iterator;
|
|
|
|
typedef std::deque<Preset>::const_iterator ConstIterator;
|
2018-08-01 09:09:51 +00:00
|
|
|
Iterator begin() { return m_presets.begin() + m_num_default_presets; }
|
2018-10-31 15:22:36 +00:00
|
|
|
ConstIterator begin() const { return m_presets.cbegin() + m_num_default_presets; }
|
|
|
|
ConstIterator cbegin() const { return m_presets.cbegin() + m_num_default_presets; }
|
2018-08-01 09:09:51 +00:00
|
|
|
Iterator end() { return m_presets.end(); }
|
2018-10-31 15:22:36 +00:00
|
|
|
ConstIterator end() const { return m_presets.cend(); }
|
|
|
|
ConstIterator cend() const { return m_presets.cend(); }
|
2018-03-29 15:54:43 +00:00
|
|
|
|
2017-12-19 18:51:22 +00:00
|
|
|
void reset(bool delete_files);
|
|
|
|
|
2017-10-25 10:53:31 +00:00
|
|
|
Preset::Type type() const { return m_type; }
|
2019-02-03 19:17:55 +00:00
|
|
|
// Name, to be used on the screen and in error messages. Not localized.
|
2017-10-25 10:53:31 +00:00
|
|
|
std::string name() const;
|
2019-02-03 19:17:55 +00:00
|
|
|
// Name, to be used as a section name in config bundle, and as a folder name for presets.
|
|
|
|
std::string section_name() const;
|
2017-10-25 10:53:31 +00:00
|
|
|
const std::deque<Preset>& operator()() const { return m_presets; }
|
2017-09-19 11:55:48 +00:00
|
|
|
|
2018-08-01 09:09:51 +00:00
|
|
|
// Add default preset at the start of the collection, increment the m_default_preset counter.
|
2018-08-03 12:14:25 +00:00
|
|
|
void add_default_preset(const std::vector<std::string> &keys, const Slic3r::StaticPrintConfig &defaults, const std::string &preset_name);
|
2018-08-01 09:09:51 +00:00
|
|
|
|
2017-10-02 15:35:00 +00:00
|
|
|
// Load ini files of the particular type from the provided directory path.
|
|
|
|
void load_presets(const std::string &dir_path, const std::string &subdir);
|
|
|
|
|
2017-10-25 10:53:31 +00:00
|
|
|
// Load a preset from an already parsed config file, insert it into the sorted sequence of presets
|
|
|
|
// and select it, losing previous modifications.
|
|
|
|
Preset& load_preset(const std::string &path, const std::string &name, const DynamicPrintConfig &config, bool select = true);
|
2017-11-02 15:21:34 +00:00
|
|
|
Preset& load_preset(const std::string &path, const std::string &name, DynamicPrintConfig &&config, bool select = true);
|
2017-10-25 10:53:31 +00:00
|
|
|
|
2018-06-22 12:17:03 +00:00
|
|
|
Preset& load_external_preset(
|
|
|
|
// Path to the profile source file (a G-code, an AMF or 3MF file, a config file)
|
|
|
|
const std::string &path,
|
|
|
|
// Name of the profile, derived from the source file name.
|
|
|
|
const std::string &name,
|
|
|
|
// Original name of the profile, extracted from the loaded config. Empty, if the name has not been stored.
|
|
|
|
const std::string &original_name,
|
|
|
|
// Config to initialize the preset from.
|
|
|
|
const DynamicPrintConfig &config,
|
|
|
|
// Select the preset after loading?
|
|
|
|
bool select = true);
|
|
|
|
|
2017-10-26 15:17:39 +00:00
|
|
|
// Save the preset under a new name. If the name is different from the old one,
|
|
|
|
// a new preset is stored into the list of presets.
|
|
|
|
// All presets are marked as not modified and the new preset is activated.
|
2020-03-06 16:41:00 +00:00
|
|
|
void save_current_preset(const std::string &new_name, bool detach = false);
|
2017-10-26 15:17:39 +00:00
|
|
|
|
|
|
|
// Delete the current preset, activate the first visible preset.
|
2019-03-22 11:11:23 +00:00
|
|
|
// returns true if the preset was deleted successfully.
|
|
|
|
bool delete_current_preset();
|
2019-10-02 20:50:55 +00:00
|
|
|
// Delete the current preset, activate the first visible preset.
|
|
|
|
// returns true if the preset was deleted successfully.
|
|
|
|
bool delete_preset(const std::string& name);
|
2017-10-26 15:17:39 +00:00
|
|
|
|
2017-09-19 11:55:48 +00:00
|
|
|
// Enable / disable the "- default -" preset.
|
|
|
|
void set_default_suppressed(bool default_suppressed);
|
2017-11-01 18:30:05 +00:00
|
|
|
bool is_default_suppressed() const { return m_default_suppressed; }
|
2017-09-19 11:55:48 +00:00
|
|
|
|
|
|
|
// Select a preset. If an invalid index is provided, the first visible preset is selected.
|
|
|
|
Preset& select_preset(size_t idx);
|
|
|
|
// Return the selected preset, without the user modifications applied.
|
|
|
|
Preset& get_selected_preset() { return m_presets[m_idx_selected]; }
|
|
|
|
const Preset& get_selected_preset() const { return m_presets[m_idx_selected]; }
|
2019-11-19 11:44:55 +00:00
|
|
|
size_t get_selected_idx() const { return m_idx_selected; }
|
2018-07-31 13:09:57 +00:00
|
|
|
// Returns the name of the selected preset, or an empty string if no preset is selected.
|
2019-11-19 11:44:55 +00:00
|
|
|
std::string get_selected_preset_name() const { return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_preset().name; }
|
2018-03-12 15:04:32 +00:00
|
|
|
// For the current edited preset, return the parent preset if there is one.
|
|
|
|
// If there is no parent preset, nullptr is returned.
|
|
|
|
// The parent preset may be a system preset or a user preset, which will be
|
|
|
|
// reflected by the UI.
|
|
|
|
const Preset* get_selected_preset_parent() const;
|
2020-01-02 15:40:32 +00:00
|
|
|
// Get parent preset for a child preset, based on the "inherits" field of a child,
|
|
|
|
// where the "inherits" profile name is searched for in both m_presets and m_map_system_profile_renamed.
|
2018-04-09 14:50:17 +00:00
|
|
|
const Preset* get_preset_parent(const Preset& child) const;
|
|
|
|
// Return the selected preset including the user modifications.
|
2017-09-19 11:55:48 +00:00
|
|
|
Preset& get_edited_preset() { return m_edited_preset; }
|
|
|
|
const Preset& get_edited_preset() const { return m_edited_preset; }
|
2018-04-06 13:42:52 +00:00
|
|
|
|
2019-12-05 13:48:11 +00:00
|
|
|
// Return vendor of the first parent profile, for which the vendor is defined, or null if such profile does not exist.
|
|
|
|
PresetWithVendorProfile get_preset_with_vendor_profile(const Preset &preset) const;
|
|
|
|
PresetWithVendorProfile get_edited_preset_with_vendor_profile() const { return this->get_preset_with_vendor_profile(this->get_edited_preset()); }
|
|
|
|
|
2020-03-14 17:35:42 +00:00
|
|
|
const std::string& get_preset_name_by_alias(const std::string& alias) const;
|
|
|
|
const std::string* get_preset_name_renamed(const std::string &old_name) const;
|
2019-11-25 14:57:36 +00:00
|
|
|
|
2018-04-06 13:42:52 +00:00
|
|
|
// used to update preset_choice from Tab
|
2019-04-26 14:53:04 +00:00
|
|
|
const std::deque<Preset>& get_presets() const { return m_presets; }
|
2019-11-19 11:44:55 +00:00
|
|
|
size_t get_idx_selected() { return m_idx_selected; }
|
2018-07-23 13:44:01 +00:00
|
|
|
static const std::string& get_suffix_modified();
|
2018-04-06 13:42:52 +00:00
|
|
|
|
2017-09-19 11:55:48 +00:00
|
|
|
// Return a preset possibly with modifications.
|
2018-10-31 15:22:36 +00:00
|
|
|
Preset& default_preset(size_t idx = 0) { assert(idx < m_num_default_presets); return m_presets[idx]; }
|
|
|
|
const Preset& default_preset(size_t idx = 0) const { assert(idx < m_num_default_presets); return m_presets[idx]; }
|
|
|
|
virtual const Preset& default_preset_for(const DynamicPrintConfig & /* config */) const { return this->default_preset(); }
|
2017-10-25 10:53:31 +00:00
|
|
|
// Return a preset by an index. If the preset is active, a temporary copy is returned.
|
2019-11-19 11:44:55 +00:00
|
|
|
Preset& preset(size_t idx) { return (idx == m_idx_selected) ? m_edited_preset : m_presets[idx]; }
|
2017-09-19 11:55:48 +00:00
|
|
|
const Preset& preset(size_t idx) const { return const_cast<PresetCollection*>(this)->preset(idx); }
|
2017-12-13 13:44:27 +00:00
|
|
|
void discard_current_changes() { m_presets[m_idx_selected].reset_dirty(); m_edited_preset = m_presets[m_idx_selected]; }
|
2017-10-25 10:53:31 +00:00
|
|
|
|
|
|
|
// Return a preset by its name. If the preset is active, a temporary copy is returned.
|
|
|
|
// If a preset is not found by its name, null is returned.
|
|
|
|
Preset* find_preset(const std::string &name, bool first_visible_if_not_found = false);
|
|
|
|
const Preset* find_preset(const std::string &name, bool first_visible_if_not_found = false) const
|
|
|
|
{ return const_cast<PresetCollection*>(this)->find_preset(name, first_visible_if_not_found); }
|
|
|
|
|
|
|
|
size_t first_visible_idx() const;
|
2018-04-13 12:49:33 +00:00
|
|
|
// Return index of the first compatible preset. Certainly at least the '- default -' preset shall be compatible.
|
|
|
|
// If one of the prefered_alternates is compatible, select it.
|
|
|
|
template<typename PreferedCondition>
|
|
|
|
size_t first_compatible_idx(PreferedCondition prefered_condition) const
|
|
|
|
{
|
2018-08-01 09:09:51 +00:00
|
|
|
size_t i = m_default_suppressed ? m_num_default_presets : 0;
|
2018-04-13 12:49:33 +00:00
|
|
|
size_t n = this->m_presets.size();
|
|
|
|
size_t i_compatible = n;
|
|
|
|
for (; i < n; ++ i)
|
2020-01-07 14:22:18 +00:00
|
|
|
// Since we use the filament selection from Wizard, it's needed to control the preset visibility too
|
|
|
|
if (m_presets[i].is_compatible && m_presets[i].is_visible) {
|
2018-04-13 12:49:33 +00:00
|
|
|
if (prefered_condition(m_presets[i].name))
|
|
|
|
return i;
|
|
|
|
if (i_compatible == n)
|
|
|
|
// Store the first compatible profile into i_compatible.
|
|
|
|
i_compatible = i;
|
|
|
|
}
|
|
|
|
return (i_compatible == n) ? 0 : i_compatible;
|
|
|
|
}
|
|
|
|
// Return index of the first compatible preset. Certainly at least the '- default -' preset shall be compatible.
|
|
|
|
size_t first_compatible_idx() const { return this->first_compatible_idx([](const std::string&){return true;}); }
|
|
|
|
|
2017-10-25 10:53:31 +00:00
|
|
|
// Return index of the first visible preset. Certainly at least the '- default -' preset shall be visible.
|
|
|
|
// Return the first visible preset. Certainly at least the '- default -' preset shall be visible.
|
2017-11-10 16:27:05 +00:00
|
|
|
Preset& first_visible() { return this->preset(this->first_visible_idx()); }
|
|
|
|
const Preset& first_visible() const { return this->preset(this->first_visible_idx()); }
|
|
|
|
Preset& first_compatible() { return this->preset(this->first_compatible_idx()); }
|
2018-04-13 12:49:33 +00:00
|
|
|
template<typename PreferedCondition>
|
|
|
|
Preset& first_compatible(PreferedCondition prefered_condition) { return this->preset(this->first_compatible_idx(prefered_condition)); }
|
2017-11-10 16:27:05 +00:00
|
|
|
const Preset& first_compatible() const { return this->preset(this->first_compatible_idx()); }
|
2017-10-25 10:53:31 +00:00
|
|
|
|
|
|
|
// Return number of presets including the "- default -" preset.
|
2018-08-01 09:09:51 +00:00
|
|
|
size_t size() const { return m_presets.size(); }
|
|
|
|
bool has_defaults_only() const { return m_presets.size() <= m_num_default_presets; }
|
2017-09-19 11:55:48 +00:00
|
|
|
|
|
|
|
// For Print / Filament presets, disable those, which are not compatible with the printer.
|
2018-04-13 12:49:33 +00:00
|
|
|
template<typename PreferedCondition>
|
Various changes in handling of profile compatiblilities
and the "show incompatible profiles" option.
It was not able to select the incompatible Print profile, which is
possible now.
(see Cannot select incompatible printer profile #3715)
When the Printer profile derived from the Prusa3D system profile was
active or a system Prusa3D profile was active, and when the Print profile
with the removed "inherits" field was active (or any other profile
derived from the "-- default --" profile was active), then the filament
selector offered just the profiles with the removed "inherits" field
(or any other profile derived from the "-- default--") profile.
This behavior has been now changed, so that in this scenario the Filament selector
will offer the Prusa3D vendor profiles compatible with the active Print
and Printer profile as well as the user profiles.
Slicer was also changed to keep an incompatible preset selected
at its respective tab if its respective "Red flag" is enabled.
For example, if an incompatible Print preset is selected and a Printer
profile is switched to another one which is not compatible with the active
Print preset that was red already, the active Print preset is
not switched if the Print "Red flag" is active. However, if the Print profile
was compatible before the Printer profile is switched and now the Print
profile becomes incompatible, another compatible Print profile is selected.
A likely bug in wxWidgets was worked around when switching a Print preset
on Plater, if the last item in the Print preset was active and incompatible,
and another Print preset was selected by the user. On Windows, an CBN_EDITCHANGE
is sent just after combo box selection change event and the CBN_EDITCHANGE
holds an index of the combo box item, which will be removed by the 1st event,
therefore leading to an assert in wxWidgets on CBN_EDITCHANGE. The workaround
is to disable processing of CBN_EDITCHANGE on Windows for the Plater
preset selection combo boxes.
2020-02-27 10:44:01 +00:00
|
|
|
void update_compatible(const PresetWithVendorProfile &active_printer, const PresetWithVendorProfile *active_print, PresetSelectCompatibleType select_other_if_incompatible, PreferedCondition prefered_condition)
|
2018-04-13 12:49:33 +00:00
|
|
|
{
|
2018-12-04 16:56:49 +00:00
|
|
|
if (this->update_compatible_internal(active_printer, active_print, select_other_if_incompatible) == (size_t)-1)
|
2018-04-13 12:49:33 +00:00
|
|
|
// Find some other compatible preset, or the "-- default --" preset.
|
|
|
|
this->select_preset(this->first_compatible_idx(prefered_condition));
|
|
|
|
}
|
Various changes in handling of profile compatiblilities
and the "show incompatible profiles" option.
It was not able to select the incompatible Print profile, which is
possible now.
(see Cannot select incompatible printer profile #3715)
When the Printer profile derived from the Prusa3D system profile was
active or a system Prusa3D profile was active, and when the Print profile
with the removed "inherits" field was active (or any other profile
derived from the "-- default --" profile was active), then the filament
selector offered just the profiles with the removed "inherits" field
(or any other profile derived from the "-- default--") profile.
This behavior has been now changed, so that in this scenario the Filament selector
will offer the Prusa3D vendor profiles compatible with the active Print
and Printer profile as well as the user profiles.
Slicer was also changed to keep an incompatible preset selected
at its respective tab if its respective "Red flag" is enabled.
For example, if an incompatible Print preset is selected and a Printer
profile is switched to another one which is not compatible with the active
Print preset that was red already, the active Print preset is
not switched if the Print "Red flag" is active. However, if the Print profile
was compatible before the Printer profile is switched and now the Print
profile becomes incompatible, another compatible Print profile is selected.
A likely bug in wxWidgets was worked around when switching a Print preset
on Plater, if the last item in the Print preset was active and incompatible,
and another Print preset was selected by the user. On Windows, an CBN_EDITCHANGE
is sent just after combo box selection change event and the CBN_EDITCHANGE
holds an index of the combo box item, which will be removed by the 1st event,
therefore leading to an assert in wxWidgets on CBN_EDITCHANGE. The workaround
is to disable processing of CBN_EDITCHANGE on Windows for the Plater
preset selection combo boxes.
2020-02-27 10:44:01 +00:00
|
|
|
void update_compatible(const PresetWithVendorProfile &active_printer, const PresetWithVendorProfile *active_print, PresetSelectCompatibleType select_other_if_incompatible)
|
2018-12-04 16:56:49 +00:00
|
|
|
{ this->update_compatible(active_printer, active_print, select_other_if_incompatible, [](const std::string&){return true;}); }
|
2017-09-19 11:55:48 +00:00
|
|
|
|
|
|
|
size_t num_visible() const { return std::count_if(m_presets.begin(), m_presets.end(), [](const Preset &preset){return preset.is_visible;}); }
|
2017-10-25 10:53:31 +00:00
|
|
|
|
|
|
|
// Compare the content of get_selected_preset() with get_edited_preset() configs, return true if they differ.
|
2017-12-13 13:44:27 +00:00
|
|
|
bool current_is_dirty() const { return ! this->current_dirty_options().empty(); }
|
2017-10-25 10:53:31 +00:00
|
|
|
// Compare the content of get_selected_preset() with get_edited_preset() configs, return the list of keys where they differ.
|
2018-08-08 15:47:59 +00:00
|
|
|
std::vector<std::string> current_dirty_options(const bool deep_compare = false) const
|
|
|
|
{ return dirty_options(&this->get_edited_preset(), &this->get_selected_preset(), deep_compare); }
|
2018-03-12 15:04:32 +00:00
|
|
|
// Compare the content of get_selected_preset() with get_edited_preset() configs, return the list of keys where they differ.
|
2018-08-08 15:47:59 +00:00
|
|
|
std::vector<std::string> current_different_from_parent_options(const bool deep_compare = false) const
|
|
|
|
{ return dirty_options(&this->get_edited_preset(), this->get_selected_preset_parent(), deep_compare); }
|
2017-10-25 10:53:31 +00:00
|
|
|
|
2019-01-08 09:52:11 +00:00
|
|
|
// Return a sorted list of system preset names.
|
|
|
|
std::vector<std::string> system_preset_names() const;
|
|
|
|
|
2020-06-16 10:57:49 +00:00
|
|
|
// Update a dirty flag of the current preset
|
2017-10-25 10:53:31 +00:00
|
|
|
// Return true if the dirty flag changed.
|
2020-06-16 10:57:49 +00:00
|
|
|
bool update_dirty();
|
2017-10-25 10:53:31 +00:00
|
|
|
|
|
|
|
// Select a profile by its name. Return true if the selection changed.
|
|
|
|
// Without force, the selection is only updated if the index changes.
|
|
|
|
// With force, the changes are reverted if the new index is the same as the old index.
|
|
|
|
bool select_preset_by_name(const std::string &name, bool force);
|
|
|
|
|
2017-12-20 10:28:16 +00:00
|
|
|
// Generate a file path from a profile name. Add the ".ini" suffix if it is missing.
|
|
|
|
std::string path_from_name(const std::string &new_name) const;
|
|
|
|
|
2020-06-16 10:57:49 +00:00
|
|
|
size_t num_default_presets() { return m_num_default_presets; }
|
2019-03-22 16:07:12 +00:00
|
|
|
|
2018-04-13 12:49:33 +00:00
|
|
|
protected:
|
|
|
|
// Select a preset, if it exists. If it does not exist, select an invalid (-1) index.
|
|
|
|
// This is a temporary state, which shall be fixed immediately by the following step.
|
|
|
|
bool select_preset_by_name_strict(const std::string &name);
|
|
|
|
|
2018-04-18 11:35:51 +00:00
|
|
|
// Merge one vendor's presets with the other vendor's presets, report duplicates.
|
2019-06-17 14:39:22 +00:00
|
|
|
std::vector<std::string> merge_presets(PresetCollection &&other, const VendorMap &new_vendors);
|
2018-04-18 11:35:51 +00:00
|
|
|
|
2020-01-23 15:04:17 +00:00
|
|
|
// Update m_map_alias_to_profile_name from loaded system profiles.
|
|
|
|
void update_map_alias_to_profile_name();
|
|
|
|
|
2020-01-02 15:40:32 +00:00
|
|
|
// Update m_map_system_profile_renamed from loaded system profiles.
|
|
|
|
void update_map_system_profile_renamed();
|
|
|
|
|
2017-09-19 11:55:48 +00:00
|
|
|
private:
|
2017-10-25 10:53:31 +00:00
|
|
|
PresetCollection();
|
|
|
|
PresetCollection(const PresetCollection &other);
|
|
|
|
PresetCollection& operator=(const PresetCollection &other);
|
|
|
|
|
2018-06-28 18:13:01 +00:00
|
|
|
// Find a preset position in the sorted list of presets.
|
2017-12-06 15:47:53 +00:00
|
|
|
// The "-- default -- " preset is always the first, so it needs
|
|
|
|
// to be handled differently.
|
2018-06-28 18:13:01 +00:00
|
|
|
// If a preset does not exist, an iterator is returned indicating where to insert a preset with the same name.
|
2017-12-06 15:47:53 +00:00
|
|
|
std::deque<Preset>::iterator find_preset_internal(const std::string &name)
|
|
|
|
{
|
|
|
|
Preset key(m_type, name);
|
2018-08-01 09:09:51 +00:00
|
|
|
auto it = std::lower_bound(m_presets.begin() + m_num_default_presets, m_presets.end(), key);
|
|
|
|
if (it == m_presets.end() || it->name != name) {
|
|
|
|
// Preset has not been not found in the sorted list of non-default presets. Try the defaults.
|
|
|
|
for (size_t i = 0; i < m_num_default_presets; ++ i)
|
|
|
|
if (m_presets[i].name == name) {
|
|
|
|
it = m_presets.begin() + i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return it;
|
2017-12-06 15:47:53 +00:00
|
|
|
}
|
|
|
|
std::deque<Preset>::const_iterator find_preset_internal(const std::string &name) const
|
|
|
|
{ return const_cast<PresetCollection*>(this)->find_preset_internal(name); }
|
2020-01-02 15:40:32 +00:00
|
|
|
std::deque<Preset>::iterator find_preset_renamed(const std::string &name) {
|
|
|
|
auto it_renamed = m_map_system_profile_renamed.find(name);
|
|
|
|
auto it = (it_renamed == m_map_system_profile_renamed.end()) ? m_presets.end() : this->find_preset_internal(it_renamed->second);
|
|
|
|
assert((it_renamed == m_map_system_profile_renamed.end()) || (it != m_presets.end() && it->name == it_renamed->second));
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
std::deque<Preset>::const_iterator find_preset_renamed(const std::string &name) const
|
|
|
|
{ return const_cast<PresetCollection*>(this)->find_preset_renamed(name); }
|
2017-12-06 15:47:53 +00:00
|
|
|
|
Various changes in handling of profile compatiblilities
and the "show incompatible profiles" option.
It was not able to select the incompatible Print profile, which is
possible now.
(see Cannot select incompatible printer profile #3715)
When the Printer profile derived from the Prusa3D system profile was
active or a system Prusa3D profile was active, and when the Print profile
with the removed "inherits" field was active (or any other profile
derived from the "-- default --" profile was active), then the filament
selector offered just the profiles with the removed "inherits" field
(or any other profile derived from the "-- default--") profile.
This behavior has been now changed, so that in this scenario the Filament selector
will offer the Prusa3D vendor profiles compatible with the active Print
and Printer profile as well as the user profiles.
Slicer was also changed to keep an incompatible preset selected
at its respective tab if its respective "Red flag" is enabled.
For example, if an incompatible Print preset is selected and a Printer
profile is switched to another one which is not compatible with the active
Print preset that was red already, the active Print preset is
not switched if the Print "Red flag" is active. However, if the Print profile
was compatible before the Printer profile is switched and now the Print
profile becomes incompatible, another compatible Print profile is selected.
A likely bug in wxWidgets was worked around when switching a Print preset
on Plater, if the last item in the Print preset was active and incompatible,
and another Print preset was selected by the user. On Windows, an CBN_EDITCHANGE
is sent just after combo box selection change event and the CBN_EDITCHANGE
holds an index of the combo box item, which will be removed by the 1st event,
therefore leading to an assert in wxWidgets on CBN_EDITCHANGE. The workaround
is to disable processing of CBN_EDITCHANGE on Windows for the Plater
preset selection combo boxes.
2020-02-27 10:44:01 +00:00
|
|
|
size_t update_compatible_internal(const PresetWithVendorProfile &active_printer, const PresetWithVendorProfile *active_print, PresetSelectCompatibleType unselect_if_incompatible);
|
2018-04-13 12:49:33 +00:00
|
|
|
|
2018-04-18 11:32:21 +00:00
|
|
|
static std::vector<std::string> dirty_options(const Preset *edited, const Preset *reference, const bool is_printer_type = false);
|
2018-03-12 15:04:32 +00:00
|
|
|
|
2017-09-19 11:55:48 +00:00
|
|
|
// Type of this PresetCollection: TYPE_PRINT, TYPE_FILAMENT or TYPE_PRINTER.
|
|
|
|
Preset::Type m_type;
|
|
|
|
// List of presets, starting with the "- default -" preset.
|
2017-10-25 10:53:31 +00:00
|
|
|
// Use deque to force the container to allocate an object per each entry,
|
|
|
|
// so that the addresses of the presets don't change during resizing of the container.
|
|
|
|
std::deque<Preset> m_presets;
|
2020-01-23 15:04:17 +00:00
|
|
|
// System profiles may have aliases. Map to the full profile name.
|
|
|
|
std::vector<std::pair<std::string, std::string>> m_map_alias_to_profile_name;
|
2020-01-02 15:40:32 +00:00
|
|
|
// Map from old system profile name to a current system profile name.
|
|
|
|
std::map<std::string, std::string> m_map_system_profile_renamed;
|
2017-10-25 10:53:31 +00:00
|
|
|
// Initially this preset contains a copy of the selected preset. Later on, this copy may be modified by the user.
|
2017-09-19 11:55:48 +00:00
|
|
|
Preset m_edited_preset;
|
|
|
|
// Selected preset.
|
2019-11-19 11:44:55 +00:00
|
|
|
size_t m_idx_selected;
|
2017-09-19 11:55:48 +00:00
|
|
|
// Is the "- default -" preset suppressed?
|
2018-08-01 09:09:51 +00:00
|
|
|
bool m_default_suppressed = true;
|
|
|
|
size_t m_num_default_presets = 0;
|
2020-06-16 10:57:49 +00:00
|
|
|
|
2017-10-26 15:17:39 +00:00
|
|
|
// Path to the directory to store the config files into.
|
|
|
|
std::string m_dir_path;
|
2018-04-13 12:49:33 +00:00
|
|
|
|
|
|
|
// to access select_preset_by_name_strict()
|
|
|
|
friend class PresetBundle;
|
2017-09-19 11:55:48 +00:00
|
|
|
};
|
|
|
|
|
2018-10-31 15:22:36 +00:00
|
|
|
// Printer supports the FFF and SLA technologies, with different set of configuration values,
|
|
|
|
// therefore this PresetCollection needs to handle two defaults.
|
|
|
|
class PrinterPresetCollection : public PresetCollection
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PrinterPresetCollection(Preset::Type type, const std::vector<std::string> &keys, const Slic3r::StaticPrintConfig &defaults, const std::string &default_name = "- default -") :
|
|
|
|
PresetCollection(type, keys, defaults, default_name) {}
|
|
|
|
const Preset& default_preset_for(const DynamicPrintConfig &config) const override;
|
2019-04-26 14:53:04 +00:00
|
|
|
|
|
|
|
const Preset* find_by_model_id(const std::string &model_id) const;
|
2018-10-31 15:22:36 +00:00
|
|
|
};
|
|
|
|
|
2020-01-13 15:01:01 +00:00
|
|
|
namespace PresetUtils {
|
|
|
|
// PrinterModel of a system profile, from which this preset is derived, or null if it is not derived from a system profile.
|
|
|
|
const VendorProfile::PrinterModel* system_printer_model(const Preset &preset);
|
|
|
|
} // namespace PresetUtils
|
|
|
|
|
2020-06-16 10:57:49 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class PhysicalPrinter
|
|
|
|
{
|
|
|
|
public:
|
2020-06-24 06:50:01 +00:00
|
|
|
PhysicalPrinter() {}
|
|
|
|
PhysicalPrinter(const std::string& name) : name(name){}
|
|
|
|
PhysicalPrinter(const std::string& name, const Preset& preset);
|
2020-06-26 07:58:39 +00:00
|
|
|
void set_name(const std::string &name);
|
|
|
|
void update_full_name();
|
2020-06-16 10:57:49 +00:00
|
|
|
|
|
|
|
// Name of the Physical Printer, usually derived form the file name.
|
|
|
|
std::string name;
|
2020-06-26 07:58:39 +00:00
|
|
|
// Full name of the Physical Printer, included related preset name
|
|
|
|
std::string full_name;
|
2020-06-16 10:57:49 +00:00
|
|
|
// File name of the Physical Printer.
|
|
|
|
std::string file;
|
2020-06-26 07:58:39 +00:00
|
|
|
// Configuration data, loaded from a file, or set from the defaults.
|
|
|
|
DynamicPrintConfig config;
|
2020-07-14 13:34:08 +00:00
|
|
|
// set of presets used with this physical printer
|
|
|
|
std::set<std::string> preset_names;
|
|
|
|
|
|
|
|
static std::string separator();
|
2020-06-16 10:57:49 +00:00
|
|
|
|
|
|
|
// Has this profile been loaded?
|
|
|
|
bool loaded = false;
|
|
|
|
|
2020-07-14 13:34:08 +00:00
|
|
|
static const std::vector<std::string>& printer_options();
|
|
|
|
const std::string& get_preset_name() const;
|
|
|
|
|
|
|
|
const std::set<std::string>& get_preset_names() const;
|
|
|
|
|
2020-06-30 12:12:47 +00:00
|
|
|
bool has_empty_config() const;
|
2020-07-14 13:34:08 +00:00
|
|
|
void update_preset_names_in_config();
|
2020-06-24 06:50:01 +00:00
|
|
|
|
2020-06-16 10:57:49 +00:00
|
|
|
void save() { this->config.save(this->file); }
|
2020-07-14 13:34:08 +00:00
|
|
|
void save(const std::string& file_name_from, const std::string& file_name_to);
|
|
|
|
|
2020-06-24 06:50:01 +00:00
|
|
|
void update_from_preset(const Preset& preset);
|
|
|
|
void update_from_config(const DynamicPrintConfig &new_config);
|
2020-06-16 10:57:49 +00:00
|
|
|
|
2020-07-14 13:34:08 +00:00
|
|
|
// add preset to the preset_names
|
|
|
|
// return false, if preset with this name is already exist in the set
|
|
|
|
bool add_preset(const std::string& preset_name);
|
|
|
|
void reset_presets();
|
|
|
|
|
2020-06-16 10:57:49 +00:00
|
|
|
// Return a printer technology, return ptFFF if the printer technology is not set.
|
|
|
|
static PrinterTechnology printer_technology(const DynamicPrintConfig& cfg) {
|
|
|
|
auto* opt = cfg.option<ConfigOptionEnum<PrinterTechnology>>("printer_technology");
|
|
|
|
// The following assert may trigger when importing some legacy profile,
|
|
|
|
// but it is safer to keep it here to capture the cases where the "printer_technology" key is queried, where it should not.
|
|
|
|
return (opt == nullptr) ? ptFFF : opt->value;
|
|
|
|
}
|
|
|
|
PrinterTechnology printer_technology() const { return printer_technology(this->config); }
|
|
|
|
|
|
|
|
// Sort lexicographically by a preset name. The preset name shall be unique across a single PresetCollection.
|
2020-06-24 06:50:01 +00:00
|
|
|
bool operator<(const PhysicalPrinter& other) const { return this->name < other.name; }
|
2020-06-16 10:57:49 +00:00
|
|
|
|
2020-06-26 07:58:39 +00:00
|
|
|
// get printer name from the full name uncluded preset name
|
|
|
|
static std::string get_short_name(std::string full_name);
|
|
|
|
|
2020-07-14 13:34:08 +00:00
|
|
|
// get preset name from the full name uncluded printer name
|
|
|
|
static std::string get_preset_name(std::string full_name);
|
|
|
|
|
2020-06-16 10:57:49 +00:00
|
|
|
protected:
|
|
|
|
friend class PhysicalPrinterCollection;
|
|
|
|
};
|
2020-06-24 06:50:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------
|
|
|
|
// *** PhysicalPrinterCollection ***
|
|
|
|
// ---------------------------------
|
|
|
|
|
|
|
|
// Collections of physical printers
|
2020-06-16 10:57:49 +00:00
|
|
|
class PhysicalPrinterCollection
|
|
|
|
{
|
|
|
|
public:
|
2020-06-24 06:50:01 +00:00
|
|
|
PhysicalPrinterCollection(const std::vector<std::string>& keys);
|
2020-06-16 10:57:49 +00:00
|
|
|
~PhysicalPrinterCollection() {}
|
|
|
|
|
|
|
|
typedef std::deque<PhysicalPrinter>::iterator Iterator;
|
|
|
|
typedef std::deque<PhysicalPrinter>::const_iterator ConstIterator;
|
|
|
|
Iterator begin() { return m_printers.begin(); }
|
|
|
|
ConstIterator begin() const { return m_printers.cbegin(); }
|
|
|
|
ConstIterator cbegin() const { return m_printers.cbegin(); }
|
|
|
|
Iterator end() { return m_printers.end(); }
|
|
|
|
ConstIterator end() const { return m_printers.cend(); }
|
|
|
|
ConstIterator cend() const { return m_printers.cend(); }
|
|
|
|
|
2020-06-24 06:50:01 +00:00
|
|
|
bool empty() const {return m_printers.empty(); }
|
|
|
|
|
2020-06-16 10:57:49 +00:00
|
|
|
void reset(bool delete_files) {};
|
|
|
|
|
|
|
|
const std::deque<PhysicalPrinter>& operator()() const { return m_printers; }
|
|
|
|
|
|
|
|
// Load ini files of the particular type from the provided directory path.
|
2020-06-24 06:50:01 +00:00
|
|
|
void load_printers(const std::string& dir_path, const std::string& subdir);
|
2020-06-16 10:57:49 +00:00
|
|
|
|
|
|
|
// Save the printer under a new name. If the name is different from the old one,
|
|
|
|
// a new printer is stored into the list of printers.
|
2020-06-24 06:50:01 +00:00
|
|
|
// New printer is activated.
|
2020-07-14 13:34:08 +00:00
|
|
|
void save_printer(const PhysicalPrinter& printer, const std::string& renamed_from);
|
2020-06-16 10:57:49 +00:00
|
|
|
|
|
|
|
// Delete the current preset, activate the first visible preset.
|
|
|
|
// returns true if the preset was deleted successfully.
|
2020-06-24 06:50:01 +00:00
|
|
|
bool delete_printer(const std::string& name);
|
2020-06-24 10:28:00 +00:00
|
|
|
// Delete the selected preset
|
|
|
|
// returns true if the preset was deleted successfully.
|
|
|
|
bool delete_selected_printer();
|
2020-06-16 10:57:49 +00:00
|
|
|
|
|
|
|
// Return the selected preset, without the user modifications applied.
|
2020-06-24 06:50:01 +00:00
|
|
|
PhysicalPrinter& get_selected_printer() { return m_printers[m_idx_selected]; }
|
|
|
|
const PhysicalPrinter& get_selected_printer() const { return m_printers[m_idx_selected]; }
|
2020-06-16 10:57:49 +00:00
|
|
|
size_t get_selected_idx() const { return m_idx_selected; }
|
|
|
|
// Returns the name of the selected preset, or an empty string if no preset is selected.
|
2020-06-24 06:50:01 +00:00
|
|
|
std::string get_selected_printer_name() const { return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().name; }
|
2020-06-26 07:58:39 +00:00
|
|
|
// Returns the full name of the selected preset, or an empty string if no preset is selected.
|
|
|
|
std::string get_selected_full_printer_name() const { return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().full_name; }
|
|
|
|
// Returns the printer model of the selected preset, or an empty string if no preset is selected.
|
|
|
|
std::string get_selected_printer_preset_name() const { return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().get_preset_name(); }
|
|
|
|
// Returns the config of the selected preset, or nullptr if no preset is selected.
|
2020-06-24 06:50:01 +00:00
|
|
|
DynamicPrintConfig* get_selected_printer_config() { return (m_idx_selected == size_t(-1)) ? nullptr : &(this->get_selected_printer().config); }
|
2020-06-16 10:57:49 +00:00
|
|
|
|
2020-06-24 06:50:01 +00:00
|
|
|
// select printer with name and return reference on it
|
2020-06-26 07:58:39 +00:00
|
|
|
PhysicalPrinter& select_printer_by_name(std::string name);
|
2020-06-24 06:50:01 +00:00
|
|
|
bool has_selection() const { return m_idx_selected != size_t(-1); }
|
|
|
|
void unselect_printer() { m_idx_selected = size_t(-1); }
|
2020-06-16 10:57:49 +00:00
|
|
|
|
2020-06-24 06:50:01 +00:00
|
|
|
// Return a printer by an index. If the printer is active, a temporary copy is returned.
|
|
|
|
PhysicalPrinter& printer(size_t idx) { return m_printers[idx]; }
|
2020-06-16 10:57:49 +00:00
|
|
|
const PhysicalPrinter& printer(size_t idx) const { return const_cast<PhysicalPrinterCollection*>(this)->printer(idx); }
|
|
|
|
|
|
|
|
// Return a preset by its name. If the preset is active, a temporary copy is returned.
|
|
|
|
// If a preset is not found by its name, null is returned.
|
|
|
|
PhysicalPrinter* find_printer(const std::string& name, bool first_visible_if_not_found = false);
|
|
|
|
const PhysicalPrinter* find_printer(const std::string& name, bool first_visible_if_not_found = false) const
|
|
|
|
{
|
|
|
|
return const_cast<PhysicalPrinterCollection*>(this)->find_printer(name, first_visible_if_not_found);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a file path from a profile name. Add the ".ini" suffix if it is missing.
|
|
|
|
std::string path_from_name(const std::string& new_name) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
PhysicalPrinterCollection& operator=(const PhysicalPrinterCollection& other);
|
|
|
|
|
|
|
|
// Find a preset position in the sorted list of presets.
|
|
|
|
// The "-- default -- " preset is always the first, so it needs
|
|
|
|
// to be handled differently.
|
|
|
|
// If a preset does not exist, an iterator is returned indicating where to insert a preset with the same name.
|
|
|
|
std::deque<PhysicalPrinter>::iterator find_printer_internal(const std::string& name)
|
|
|
|
{
|
2020-06-24 06:50:01 +00:00
|
|
|
PhysicalPrinter printer(name);
|
|
|
|
auto it = std::lower_bound(m_printers.begin(), m_printers.end(), printer);
|
2020-06-16 10:57:49 +00:00
|
|
|
return it;
|
|
|
|
}
|
|
|
|
std::deque<PhysicalPrinter>::const_iterator find_printer_internal(const std::string& name) const
|
|
|
|
{
|
|
|
|
return const_cast<PhysicalPrinterCollection*>(this)->find_printer_internal(name);
|
|
|
|
}
|
|
|
|
|
2020-06-24 06:50:01 +00:00
|
|
|
// List of printers
|
2020-06-16 10:57:49 +00:00
|
|
|
// Use deque to force the container to allocate an object per each entry,
|
|
|
|
// so that the addresses of the presets don't change during resizing of the container.
|
|
|
|
std::deque<PhysicalPrinter> m_printers;
|
2020-06-24 06:50:01 +00:00
|
|
|
|
|
|
|
// Selected printer.
|
|
|
|
size_t m_idx_selected = size_t(-1);
|
2020-06-16 10:57:49 +00:00
|
|
|
|
|
|
|
// Path to the directory to store the config files into.
|
|
|
|
std::string m_dir_path;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-09-19 11:55:48 +00:00
|
|
|
} // namespace Slic3r
|
|
|
|
|
|
|
|
#endif /* slic3r_Preset_hpp_ */
|