PresetBundle.hpp 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #ifndef slic3r_PresetBundle_hpp_
  2. #define slic3r_PresetBundle_hpp_
  3. #include "Preset.hpp"
  4. #include "AppConfig.hpp"
  5. #include "enum_bitmask.hpp"
  6. #include <memory>
  7. #include <unordered_map>
  8. #include <boost/filesystem/path.hpp>
  9. namespace Slic3r {
  10. // Bundle of Print + Filament + Printer presets.
  11. class PresetBundle
  12. {
  13. public:
  14. PresetBundle();
  15. ~PresetBundle();
  16. // Remove all the presets but the "-- default --".
  17. // Optionally remove all the files referenced by the presets from the user profile directory.
  18. void reset(bool delete_files);
  19. void setup_directories();
  20. // Load ini files of all types (print, filament, printer) from Slic3r::data_dir() / presets.
  21. // Load selections (current print, current filaments, current printer) from config.ini
  22. // This is done just once on application start up.
  23. PresetsConfigSubstitutions load_presets(AppConfig &config, ForwardCompatibilitySubstitutionRule rule, const std::string &preferred_model_id = "");
  24. // Export selections (current print, current filaments, current printer) into config.ini
  25. void export_selections(AppConfig &config);
  26. PresetCollection fff_prints;
  27. PresetCollection sla_prints;
  28. PresetCollection filaments;
  29. PresetCollection sla_materials;
  30. PresetCollection& prints(PrinterTechnology pt) { return pt == ptFFF ? this->fff_prints : this->sla_prints; }
  31. const PresetCollection& prints(PrinterTechnology pt) const { return pt == ptFFF ? this->fff_prints : this->sla_prints; }
  32. PresetCollection& materials(PrinterTechnology pt) { return pt == ptFFF ? this->filaments : this->sla_materials; }
  33. const PresetCollection& materials(PrinterTechnology pt) const { return pt == ptFFF ? this->filaments : this->sla_materials; }
  34. PrinterPresetCollection printers;
  35. PhysicalPrinterCollection physical_printers;
  36. // Filament preset names for a multi-extruder or multi-material print.
  37. // extruders.size() should be the same as printers.get_edited_preset().config.nozzle_diameter.size()
  38. std::vector<std::string> filament_presets;
  39. // The project configuration values are kept separated from the print/filament/printer preset,
  40. // they are being serialized / deserialized from / to the .amf, .3mf, .config, .gcode,
  41. // and they are being used by slicing core.
  42. DynamicPrintConfig project_config;
  43. // There will be an entry for each system profile loaded,
  44. // and the system profiles will point to the VendorProfile instances owned by PresetBundle::vendors.
  45. VendorMap vendors;
  46. struct ObsoletePresets {
  47. std::vector<std::string> fff_prints;
  48. std::vector<std::string> sla_prints;
  49. std::vector<std::string> filaments;
  50. std::vector<std::string> sla_materials;
  51. std::vector<std::string> printers;
  52. };
  53. ObsoletePresets obsolete_presets;
  54. bool has_defauls_only() const
  55. { return fff_prints.has_defaults_only() && filaments.has_defaults_only() && printers.has_defaults_only(); }
  56. DynamicPrintConfig full_config() const;
  57. // full_config() with the "printhost_apikey" and "printhost_cafile" removed.
  58. DynamicPrintConfig full_config_secure() const;
  59. // Load user configuration and store it into the user profiles.
  60. // This method is called by the configuration wizard.
  61. void load_config_from_wizard(const std::string &name, DynamicPrintConfig config)
  62. { this->load_config_file_config(name, false, std::move(config)); }
  63. // Load configuration that comes from a model file containing configuration, such as 3MF et al.
  64. // This method is called by the Plater.
  65. void load_config_model(const std::string &name, DynamicPrintConfig config)
  66. { this->load_config_file_config(name, true, std::move(config)); }
  67. // Load an external config file containing the print, filament and printer presets.
  68. // Instead of a config file, a G-code may be loaded containing the full set of parameters.
  69. // In the future the configuration will likely be read from an AMF file as well.
  70. // If the file is loaded successfully, its print / filament / printer profiles will be activated.
  71. ConfigSubstitutions load_config_file(const std::string &path, ForwardCompatibilitySubstitutionRule compatibility_rule, bool from_prusa = false);
  72. // Load a config bundle file, into presets and store the loaded presets into separate files
  73. // of the local configuration directory.
  74. // Load settings into the provided settings instance.
  75. // Activate the presets stored in the config bundle.
  76. // Returns the number of presets loaded successfully.
  77. enum LoadConfigBundleAttribute {
  78. // Save the profiles, which have been loaded.
  79. SaveImported,
  80. // Delete all old config profiles before loading.
  81. ResetUserProfile,
  82. // Load a system config bundle.
  83. LoadSystem,
  84. LoadVendorOnly,
  85. //apply import rule from prusa
  86. ConvertFromPrusa,
  87. };
  88. using LoadConfigBundleAttributes = enum_bitmask<LoadConfigBundleAttribute>;
  89. // Load the config bundle based on the flags.
  90. // Don't do any config substitutions when loading a system profile, perform and report substitutions otherwise.
  91. std::pair<PresetsConfigSubstitutions, size_t> load_configbundle(
  92. const std::string &path, LoadConfigBundleAttributes flags, ForwardCompatibilitySubstitutionRule compatibility_rule);
  93. // Export a config bundle file containing all the presets and the names of the active presets.
  94. void export_configbundle(const std::string &path, bool export_system_settings = false, bool export_physical_printers = false);
  95. // Enable / disable the "- default -" preset.
  96. void set_default_suppressed(bool default_suppressed);
  97. // Set the filament preset name. As the name could come from the UI selection box,
  98. // an optional "(modified)" suffix will be removed from the filament name.
  99. void set_filament_preset(size_t idx, const std::string &name);
  100. // Read out the number of extruders from an active printer preset,
  101. // update size and content of filament_presets.
  102. void update_multi_material_filament_presets();
  103. // Update the is_compatible flag of all print and filament presets depending on whether they are marked
  104. // as compatible with the currently selected printer (and print in case of filament presets).
  105. // Also updates the is_visible flag of each preset.
  106. // If select_other_if_incompatible is true, then the print or filament preset is switched to some compatible
  107. // preset if the current print or filament preset is not compatible.
  108. void update_compatible(PresetSelectCompatibleType select_other_print_if_incompatible, PresetSelectCompatibleType select_other_filament_if_incompatible);
  109. void update_compatible(PresetSelectCompatibleType select_other_if_incompatible) { this->update_compatible(select_other_if_incompatible, select_other_if_incompatible); }
  110. // Set the is_visible flag for printer vendors, printer models and printer variants
  111. // based on the user configuration.
  112. // If the "vendor" section is missing, enable all models and variants of the particular vendor.
  113. void load_installed_printers(const AppConfig &config);
  114. const std::string& get_preset_name_by_alias(const Preset::Type& preset_type, const std::string& alias) const;
  115. // Save current preset of a required type under a new name. If the name is different from the old one,
  116. // Unselected option would be reverted to the beginning values
  117. void save_changes_for_preset(const std::string& new_name, Preset::Type type, const std::vector<std::string>& unselected_options);
  118. static const char *PRUSA_BUNDLE;
  119. private:
  120. std::pair<PresetsConfigSubstitutions, std::string> load_system_presets(ForwardCompatibilitySubstitutionRule compatibility_rule);
  121. // Merge one vendor's presets with the other vendor's presets, report duplicates.
  122. std::vector<std::string> merge_presets(PresetBundle &&other);
  123. // Update renamed_from and alias maps of system profiles.
  124. void update_system_maps();
  125. // Set the is_visible flag for filaments and sla materials,
  126. // apply defaults based on enabled printers when no filaments/materials are installed.
  127. void load_installed_filaments(AppConfig &config);
  128. void load_installed_sla_materials(AppConfig &config);
  129. // Load selections (current print, current filaments, current printer) from config.ini
  130. // This is done just once on application start up.
  131. void load_selections(AppConfig &config, const std::string &preferred_model_id = "");
  132. // Load print, filament & printer presets from a config. If it is an external config, then the name is extracted from the external path.
  133. // and the external config is just referenced, not stored into user profile directory.
  134. // If it is not an external config, then the config will be stored into the user profile directory.
  135. void load_config_file_config(const std::string &name_or_path, bool is_external, DynamicPrintConfig &&config);
  136. ConfigSubstitutions load_config_file_config_bundle(
  137. const std::string &path, const boost::property_tree::ptree &tree, ForwardCompatibilitySubstitutionRule compatibility_rule, bool from_prusa = false);
  138. DynamicPrintConfig full_fff_config() const;
  139. DynamicPrintConfig full_sla_config() const;
  140. };
  141. ENABLE_ENUM_BITMASK_OPERATORS(PresetBundle::LoadConfigBundleAttribute)
  142. } // namespace Slic3r
  143. #endif /* slic3r_PresetBundle_hpp_ */