PrusaSlicer-NonPlainar/src/libslic3r/PresetBundle.hpp

167 lines
8.9 KiB
C++
Raw Normal View History

#ifndef slic3r_PresetBundle_hpp_
#define slic3r_PresetBundle_hpp_
#include "Preset.hpp"
#include "AppConfig.hpp"
#include <memory>
#include <unordered_map>
#include <boost/filesystem/path.hpp>
namespace Slic3r {
// Bundle of Print + Filament + Printer presets.
class PresetBundle
{
public:
PresetBundle();
DiffPresetDialog, non modal to compare two presets. Added menu item "Window->Compare presets" to compare more than one type of presets. Code refactoring for PresetComboBox: Use suffix "modified" just for PlaterPresetComboBox and TabPresetComboBox Code refactoring. wxDataViewCtrl and related functions extracted from DiffPresetDialog and UnsavedChangesDialog to the separate class DiffViewCtrl Code refactoring, Tab.cpp: Build all unregular pages on a first build of the Printer Settings Squashed commit of the following: commit 91f45a8a2d97d252337c7306dd02db607fd79c00 Author: Vojtech Bubnik <bubnikv@gmail.com> Date: Thu Feb 4 09:34:29 2021 +0100 Fixed after merge commit 09aa502498b08c059ecdf334f5db1567739b4520 Merge: 6df8e83e1 0baa92fab Author: Vojtech Bubnik <bubnikv@gmail.com> Date: Thu Feb 4 09:31:43 2021 +0100 Merge remote-tracking branch 'remotes/origin/master' into ys_diff_dlg commit 6df8e83e1af3ba096ac39d25985b6deb2e0a245b Author: Vojtech Bubnik <bubnikv@gmail.com> Date: Thu Feb 4 09:29:53 2021 +0100 Tiny beautification. commit e781ceaaf7c39bc073476409cc02918d9f182930 Author: Vojtech Bubnik <bubnikv@gmail.com> Date: Wed Feb 3 18:05:19 2021 +0100 Reworked copying of PresetBundles: 1) Simplified by using the default copy constructors and copy operators. 2) Made safer by not allowing PresetCollection and PhysicalPrinterPresetCollection to be copied or instantiated outside of PresetBundle. 3) Fixed Preset::vendor pointers after copying PresetBundle. commit a8f0b7aa5156465cdb3e3dbb86feb66a64bcebc0 Author: YuSanka <yusanka@gmail.com> Date: Mon Jan 25 16:13:53 2021 +0100 DiffPresetsDialog: Show compatibility to print/printer presets selected in DiffPresetDialog commit 597451f930a4330376966d8cf3350056d4f85a73 Merge: cce5b5710 59017a7da Author: YuSanka <yusanka@gmail.com> Date: Thu Jan 21 12:14:48 2021 +0100 Merge remote-tracking branch 'origin/master' into ys_diff_dlg commit cce5b5710d1225c7eaa52d0abb4b3f66fbd3b6a1 Author: YuSanka <yusanka@gmail.com> Date: Thu Jan 21 12:11:40 2021 +0100 DiffPresetDialog: Fixed crash on ASAN build commit ad8d728d89d7a75c2ac136ea8cdbb730ab774cd9 Author: YuSanka <yusanka@gmail.com> Date: Wed Jan 20 16:38:28 2021 +0100 FullCompareDialog improvements commit 316bafbeec9bb63f731b653d296062d9e22dd02f Author: YuSanka <yusanka@gmail.com> Date: Wed Jan 20 09:25:46 2021 +0100 DiffPresetDialog improvements: * Update presets lists after save changes in edited preset or change printer_technology * Tab.cpp: Build all unregular pages on a first build of the Printer Settings commit 01171c8ef50389d0801b0ccc5746ab0c3b731b11 Author: YuSanka <yusanka@gmail.com> Date: Tue Jan 19 17:26:28 2021 +0100 DiffPresetDialog : improvements * This dialog is non-modal now * "Compare presets" menu item is moved from "View" to the "Window" menu group * Added info tooltips for the bitmap buttons between presets * Added "Show all presets" checkbox * Show full difference between printer presets with different count of extruders commit 3d38b62f3c9de8aab352ed3bcff297d5c0239b2e Merge: e50fe6de9 9a2310ae9 Author: YuSanka <yusanka@gmail.com> Date: Mon Jan 18 10:00:18 2021 +0100 Merge remote-tracking branch 'origin/master' into ys_diff_dlg commit e50fe6de984decadfef3d4b952f0eec8ab9e6670 Author: YuSanka <yusanka@gmail.com> Date: Sat Jan 16 02:27:24 2021 +0100 DiffPresetDialog improvements Added menu item "View->Compare presets" to compare more than one type of presets commit bf08b7c8c969ad0ca631b9eeac1bc231f474e72b Author: YuSanka <yusanka@gmail.com> Date: Sat Jan 16 00:28:39 2021 +0100 Code refactoring. wxDataViewCtrl and related functions extracted from DiffPresetDialog and UnsavedChangesDialog to the separate class DiffViewCtrl commit 7aeb63032b0bc2bd06e60990c060008660a5c44f Author: YuSanka <yusanka@gmail.com> Date: Fri Jan 15 21:35:43 2021 +0100 DiffPresetDialog: first implementation commit 2f23d5af9d6b5dd670dfb7d06eedbe0e6d2960c6 Author: YuSanka <yusanka@gmail.com> Date: Thu Jan 14 16:28:43 2021 +0100 Code refactoring for PresetComboBox. Use suffix "modified" just for PlaterPresetComboBox and TabPresetComboBox
2021-02-04 08:42:32 +00:00
PresetBundle(const PresetBundle &rhs);
PresetBundle& operator=(const PresetBundle &rhs);
// Remove all the presets but the "-- default --".
// Optionally remove all the files referenced by the presets from the user profile directory.
void reset(bool delete_files);
void setup_directories();
// Load ini files of all types (print, filament, printer) from Slic3r::data_dir() / presets.
// Load selections (current print, current filaments, current printer) from config.ini
void load_presets(AppConfig &config, const std::string &preferred_model_id = std::string());
// Export selections (current print, current filaments, current printer) into config.ini
void export_selections(AppConfig &config);
PresetCollection prints;
PresetCollection sla_prints;
PresetCollection filaments;
2018-07-31 13:09:57 +00:00
PresetCollection sla_materials;
PresetCollection& materials(PrinterTechnology pt) { return pt == ptFFF ? this->filaments : this->sla_materials; }
const PresetCollection& materials(PrinterTechnology pt) const { return pt == ptFFF ? this->filaments : this->sla_materials; }
PrinterPresetCollection printers;
PhysicalPrinterCollection physical_printers;
// Filament preset names for a multi-extruder or multi-material print.
// extruders.size() should be the same as printers.get_edited_preset().config.nozzle_diameter.size()
std::vector<std::string> filament_presets;
// The project configuration values are kept separated from the print/filament/printer preset,
// they are being serialized / deserialized from / to the .amf, .3mf, .config, .gcode,
// and they are being used by slicing core.
DynamicPrintConfig project_config;
// There will be an entry for each system profile loaded,
// and the system profiles will point to the VendorProfile instances owned by PresetBundle::vendors.
VendorMap vendors;
struct ObsoletePresets {
std::vector<std::string> prints;
std::vector<std::string> sla_prints;
std::vector<std::string> filaments;
2018-07-31 13:09:57 +00:00
std::vector<std::string> sla_materials;
std::vector<std::string> printers;
};
ObsoletePresets obsolete_presets;
bool has_defauls_only() const
2018-08-01 09:09:51 +00:00
{ return prints.has_defaults_only() && filaments.has_defaults_only() && printers.has_defaults_only(); }
DynamicPrintConfig full_config() const;
// full_config() with the "printhost_apikey" and "printhost_cafile" removed.
DynamicPrintConfig full_config_secure() const;
// Load user configuration and store it into the user profiles.
// This method is called by the configuration wizard.
void load_config_from_wizard(const std::string &name, DynamicPrintConfig config)
{ this->load_config_file_config(name, false, std::move(config)); }
2018-09-17 10:15:11 +00:00
// Load configuration that comes from a model file containing configuration, such as 3MF et al.
// This method is called by the Plater.
void load_config_model(const std::string &name, DynamicPrintConfig config)
{ this->load_config_file_config(name, true, std::move(config)); }
// Load an external config file containing the print, filament and printer presets.
// Instead of a config file, a G-code may be loaded containing the full set of parameters.
// In the future the configuration will likely be read from an AMF file as well.
// If the file is loaded successfully, its print / filament / printer profiles will be activated.
void load_config_file(const std::string &path);
// Load a config bundle file, into presets and store the loaded presets into separate files
// of the local configuration directory.
// Load settings into the provided settings instance.
// Activate the presets stored in the config bundle.
// Returns the number of presets loaded successfully.
enum {
// Save the profiles, which have been loaded.
LOAD_CFGBNDLE_SAVE = 1,
// Delete all old config profiles before loading.
LOAD_CFGBNDLE_RESET_USER_PROFILE = 2,
// Load a system config bundle.
LOAD_CFGBNDLE_SYSTEM = 4,
2018-03-13 11:39:57 +00:00
LOAD_CFGBUNDLE_VENDOR_ONLY = 8,
};
// Load the config bundle, store it to the user profile directory by default.
size_t load_configbundle(const std::string &path, unsigned int flags = LOAD_CFGBNDLE_SAVE);
// Export a config bundle file containing all the presets and the names of the active presets.
void export_configbundle(const std::string &path, bool export_system_settings = false, bool export_physical_printers = false);
// Enable / disable the "- default -" preset.
void set_default_suppressed(bool default_suppressed);
// Set the filament preset name. As the name could come from the UI selection box,
// an optional "(modified)" suffix will be removed from the filament name.
void set_filament_preset(size_t idx, const std::string &name);
// Read out the number of extruders from an active printer preset,
// update size and content of filament_presets.
void update_multi_material_filament_presets();
// Update the is_compatible flag of all print and filament presets depending on whether they are marked
// as compatible with the currently selected printer (and print in case of filament presets).
// Also updates the is_visible flag of each preset.
// If select_other_if_incompatible is true, then the print or filament preset is switched to some compatible
// preset if the current print or filament preset is not compatible.
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(PresetSelectCompatibleType select_other_print_if_incompatible, PresetSelectCompatibleType select_other_filament_if_incompatible);
void update_compatible(PresetSelectCompatibleType select_other_if_incompatible) { this->update_compatible(select_other_if_incompatible, select_other_if_incompatible); }
// Set the is_visible flag for printer vendors, printer models and printer variants
// based on the user configuration.
// If the "vendor" section is missing, enable all models and variants of the particular vendor.
void load_installed_printers(const AppConfig &config);
const std::string& get_preset_name_by_alias(const Preset::Type& preset_type, const std::string& alias) const;
// Save current preset of a required type under a new name. If the name is different from the old one,
// Unselected option would be reverted to the beginning values
void save_changes_for_preset(const std::string& new_name, Preset::Type type, const std::vector<std::string>& unselected_options);
static const char *PRUSA_BUNDLE;
private:
std::string load_system_presets();
// Merge one vendor's presets with the other vendor's presets, report duplicates.
std::vector<std::string> merge_presets(PresetBundle &&other);
// Update renamed_from and alias maps of system profiles.
void update_system_maps();
// Set the is_visible flag for filaments and sla materials,
// apply defaults based on enabled printers when no filaments/materials are installed.
void load_installed_filaments(AppConfig &config);
void load_installed_sla_materials(AppConfig &config);
// Load selections (current print, current filaments, current printer) from config.ini
// This is done just once on application start up.
void load_selections(AppConfig &config, const std::string &preferred_model_id = "");
// Load print, filament & printer presets from a config. If it is an external config, then the name is extracted from the external path.
// and the external config is just referenced, not stored into user profile directory.
// If it is not an external config, then the config will be stored into the user profile directory.
void load_config_file_config(const std::string &name_or_path, bool is_external, DynamicPrintConfig &&config);
void load_config_file_config_bundle(const std::string &path, const boost::property_tree::ptree &tree);
2018-07-31 13:09:57 +00:00
DynamicPrintConfig full_fff_config() const;
DynamicPrintConfig full_sla_config() const;
};
} // namespace Slic3r
#endif /* slic3r_PresetBundle_hpp_ */