2017-11-02 15:21:34 +00:00
# include <cassert>
2017-10-30 17:41:50 +00:00
# include "PresetBundle.hpp"
2020-06-16 14:58:41 +00:00
# include "libslic3r.h"
# include "Utils.hpp"
# include "Model.hpp"
2017-10-30 17:41:50 +00:00
2018-03-13 11:39:57 +00:00
# include <algorithm>
2020-06-16 10:57:49 +00:00
# include <set>
2017-10-30 17:41:50 +00:00
# include <fstream>
2019-08-27 14:59:07 +00:00
# include <unordered_set>
2017-10-30 17:41:50 +00:00
# include <boost/filesystem.hpp>
2017-11-01 18:30:05 +00:00
# include <boost/algorithm/clamp.hpp>
2017-10-30 17:41:50 +00:00
# include <boost/algorithm/string/predicate.hpp>
# include <boost/nowide/cenv.hpp>
# include <boost/nowide/cstdio.hpp>
# include <boost/nowide/fstream.hpp>
# include <boost/property_tree/ini_parser.hpp>
# include <boost/property_tree/ptree.hpp>
# include <boost/locale.hpp>
2018-03-07 15:48:28 +00:00
# include <boost/log/trivial.hpp>
2017-10-30 17:41:50 +00:00
2020-02-28 13:29:53 +00:00
2017-12-14 08:40:45 +00:00
// Store the print/filament/printer presets into a "presets" subdirectory of the Slic3rPE config dir.
// This breaks compatibility with the upstream Slic3r if the --datadir is used to switch between the two versions.
// #define SLIC3R_PROFILE_USE_PRESETS_SUBDIR
2017-10-30 17:41:50 +00:00
namespace Slic3r {
2018-04-04 08:18:26 +00:00
static std : : vector < std : : string > s_project_options {
2018-11-07 13:44:47 +00:00
" colorprint_heights " ,
2018-04-04 08:18:26 +00:00
" wiping_volumes_extruders " ,
" wiping_volumes_matrix "
2018-03-14 10:54:11 +00:00
} ;
2019-06-17 14:39:22 +00:00
const char * PresetBundle : : PRUSA_BUNDLE = " PrusaResearch " ;
2017-10-30 17:41:50 +00:00
PresetBundle : : PresetBundle ( ) :
2018-08-03 12:14:25 +00:00
prints ( Preset : : TYPE_PRINT , Preset : : print_options ( ) , static_cast < const HostConfig & > ( FullPrintConfig : : defaults ( ) ) ) ,
filaments ( Preset : : TYPE_FILAMENT , Preset : : filament_options ( ) , static_cast < const HostConfig & > ( FullPrintConfig : : defaults ( ) ) ) ,
sla_materials ( Preset : : TYPE_SLA_MATERIAL , Preset : : sla_material_options ( ) , static_cast < const SLAMaterialConfig & > ( SLAFullPrintConfig : : defaults ( ) ) ) ,
2018-11-16 16:36:23 +00:00
sla_prints ( Preset : : TYPE_SLA_PRINT , Preset : : sla_print_options ( ) , static_cast < const SLAPrintObjectConfig & > ( SLAFullPrintConfig : : defaults ( ) ) ) ,
2020-06-24 06:50:01 +00:00
printers ( Preset : : TYPE_PRINTER , Preset : : printer_options ( ) , static_cast < const HostConfig & > ( FullPrintConfig : : defaults ( ) ) , " - default FFF - " ) ,
physical_printers ( PhysicalPrinter : : printer_options ( ) )
2017-10-30 17:41:50 +00:00
{
2018-06-26 08:50:50 +00:00
// The following keys are handled by the UI, they do not have a counterpart in any StaticPrintConfig derived classes,
// therefore they need to be handled differently. As they have no counterpart in StaticPrintConfig, they are not being
// initialized based on PrintConfigDef(), but to empty values (zeros, empty vectors, empty strings).
//
// "compatible_printers", "compatible_printers_condition", "inherits",
// "print_settings_id", "filament_settings_id", "printer_settings_id",
// "printer_vendor", "printer_model", "printer_variant", "default_print_profile", "default_filament_profile"
// Create the ID config keys, as they are not part of the Static print config classes.
this - > prints . default_preset ( ) . config . optptr ( " print_settings_id " , true ) ;
2018-06-27 14:57:42 +00:00
this - > prints . default_preset ( ) . compatible_printers_condition ( ) ;
this - > prints . default_preset ( ) . inherits ( ) ;
2018-06-26 08:50:50 +00:00
this - > filaments . default_preset ( ) . config . option < ConfigOptionStrings > ( " filament_settings_id " , true ) - > values = { " " } ;
2018-06-27 14:57:42 +00:00
this - > filaments . default_preset ( ) . compatible_printers_condition ( ) ;
this - > filaments . default_preset ( ) . inherits ( ) ;
WIP: Nullable configuration value concept, implemented for
ConfigOptionFloatsNullable, ConfigOptionIntsNullable,
ConfigOptionPercentsNullable, ConfigOptionBoolsNullable.
retract override values were added to the Filament profile:
vector of floats: "retract_length", "retract_lift", "retract_lift_above",
"retract_lift_below", "retract_speed", "deretract_speed",
"retract_restart_extra", "retract_before_travel",
vector of bools: "retract_layer_change", "wipe"
vector of percents: "retract_before_wipe"
2019-07-23 12:15:42 +00:00
// Set all the nullable values to nils.
this - > filaments . default_preset ( ) . config . null_nullables ( ) ;
2018-06-26 08:50:50 +00:00
2018-07-31 13:09:57 +00:00
this - > sla_materials . default_preset ( ) . config . optptr ( " sla_material_settings_id " , true ) ;
this - > sla_materials . default_preset ( ) . compatible_printers_condition ( ) ;
this - > sla_materials . default_preset ( ) . inherits ( ) ;
2018-11-16 16:36:23 +00:00
this - > sla_prints . default_preset ( ) . config . optptr ( " sla_print_settings_id " , true ) ;
2019-05-16 13:55:26 +00:00
this - > sla_prints . default_preset ( ) . config . opt_string ( " output_filename_format " , true ) = " [input_filename_base].sl1 " ;
2018-11-16 16:36:23 +00:00
this - > sla_prints . default_preset ( ) . compatible_printers_condition ( ) ;
this - > sla_prints . default_preset ( ) . inherits ( ) ;
2018-08-03 12:14:25 +00:00
this - > printers . add_default_preset ( Preset : : sla_printer_options ( ) , static_cast < const SLAMaterialConfig & > ( SLAFullPrintConfig : : defaults ( ) ) , " - default SLA - " ) ;
2019-01-10 17:08:38 +00:00
this - > printers . preset ( 1 ) . printer_technology_ref ( ) = ptSLA ;
2018-08-01 09:09:51 +00:00
for ( size_t i = 0 ; i < 2 ; + + i ) {
2018-10-24 12:45:22 +00:00
// The following ugly switch is to avoid printers.preset(0) to return the edited instance, as the 0th default is the current one.
2018-10-31 15:22:36 +00:00
Preset & preset = this - > printers . default_preset ( i ) ;
2018-08-01 09:09:51 +00:00
preset . config . optptr ( " printer_settings_id " , true ) ;
preset . config . optptr ( " printer_vendor " , true ) ;
preset . config . optptr ( " printer_model " , true ) ;
preset . config . optptr ( " printer_variant " , true ) ;
2019-11-15 16:33:31 +00:00
preset . config . optptr ( " thumbnails " , true ) ;
2018-10-31 15:22:36 +00:00
if ( i = = 0 ) {
preset . config . optptr ( " default_print_profile " , true ) ;
preset . config . option < ConfigOptionStrings > ( " default_filament_profile " , true ) - > values = { " " } ;
2018-11-16 16:36:23 +00:00
}
else {
preset . config . optptr ( " default_sla_print_profile " , true ) ;
2018-12-03 12:14:28 +00:00
preset . config . optptr ( " default_sla_material_profile " , true ) ;
2018-11-16 16:36:23 +00:00
}
2018-10-31 15:22:36 +00:00
// default_sla_material_profile
2018-08-01 09:09:51 +00:00
preset . inherits ( ) ;
}
2018-06-26 08:50:50 +00:00
2018-05-22 12:17:27 +00:00
// Re-activate the default presets, so their "edited" preset copies will be updated with the additional configuration values above.
2018-07-31 13:09:57 +00:00
this - > prints . select_preset ( 0 ) ;
2018-11-16 16:36:23 +00:00
this - > sla_prints . select_preset ( 0 ) ;
2018-07-31 13:09:57 +00:00
this - > filaments . select_preset ( 0 ) ;
this - > sla_materials . select_preset ( 0 ) ;
this - > printers . select_preset ( 0 ) ;
2018-03-14 10:54:11 +00:00
this - > project_config . apply_only ( FullPrintConfig : : defaults ( ) , s_project_options ) ;
2017-10-30 17:41:50 +00:00
}
PresetBundle : : ~ PresetBundle ( )
{
}
2017-12-19 18:51:22 +00:00
void PresetBundle : : reset ( bool delete_files )
{
// Clear the existing presets, delete their respective files.
2018-06-06 08:52:19 +00:00
this - > vendors . clear ( ) ;
2018-07-31 13:09:57 +00:00
this - > prints . reset ( delete_files ) ;
2018-11-16 16:36:23 +00:00
this - > sla_prints . reset ( delete_files ) ;
2018-07-31 13:09:57 +00:00
this - > filaments . reset ( delete_files ) ;
this - > sla_materials . reset ( delete_files ) ;
this - > printers . reset ( delete_files ) ;
2017-12-19 18:51:22 +00:00
this - > filament_presets . clear ( ) ;
2018-07-31 13:09:57 +00:00
this - > filament_presets . emplace_back ( this - > filaments . get_selected_preset_name ( ) ) ;
2018-05-16 14:34:07 +00:00
this - > obsolete_presets . prints . clear ( ) ;
2018-11-16 16:36:23 +00:00
this - > obsolete_presets . sla_prints . clear ( ) ;
2018-05-16 14:34:07 +00:00
this - > obsolete_presets . filaments . clear ( ) ;
2018-07-31 13:09:57 +00:00
this - > obsolete_presets . sla_materials . clear ( ) ;
2018-05-16 14:34:07 +00:00
this - > obsolete_presets . printers . clear ( ) ;
2017-12-19 18:51:22 +00:00
}
2017-10-30 17:41:50 +00:00
void PresetBundle : : setup_directories ( )
{
2017-11-30 14:51:51 +00:00
boost : : filesystem : : path data_dir = boost : : filesystem : : path ( Slic3r : : data_dir ( ) ) ;
2017-12-10 21:11:00 +00:00
std : : initializer_list < boost : : filesystem : : path > paths = {
2018-03-09 15:37:33 +00:00
data_dir ,
data_dir / " vendor " ,
2018-04-11 11:12:08 +00:00
data_dir / " cache " ,
2017-12-14 08:40:45 +00:00
# ifdef SLIC3R_PROFILE_USE_PRESETS_SUBDIR
// Store the print/filament/printer presets into a "presets" directory.
2017-12-10 21:11:00 +00:00
data_dir / " presets " ,
data_dir / " presets " / " print " ,
data_dir / " presets " / " filament " ,
2018-11-19 10:10:22 +00:00
data_dir / " presets " / " sla_print " ,
2018-07-31 13:09:57 +00:00
data_dir / " presets " / " sla_material " ,
2020-06-24 06:50:01 +00:00
data_dir / " presets " / " printer " ,
data_dir / " presets " / " physical_printer "
2017-12-14 08:40:45 +00:00
# else
// Store the print/filament/printer presets at the same location as the upstream Slic3r.
data_dir / " print " ,
data_dir / " filament " ,
2018-11-19 10:10:22 +00:00
data_dir / " sla_print " ,
2018-07-31 13:09:57 +00:00
data_dir / " sla_material " ,
2020-06-24 06:50:01 +00:00
data_dir / " printer " ,
data_dir / " physical_printer "
2017-12-14 08:40:45 +00:00
# endif
} ;
2017-11-30 14:51:51 +00:00
for ( const boost : : filesystem : : path & path : paths ) {
boost : : filesystem : : path subdir = path ;
subdir . make_preferred ( ) ;
2017-10-30 17:41:50 +00:00
if ( ! boost : : filesystem : : is_directory ( subdir ) & &
! boost : : filesystem : : create_directory ( subdir ) )
throw std : : runtime_error ( std : : string ( " Slic3r was unable to create its data directory at " ) + subdir . string ( ) ) ;
}
}
2019-06-03 08:15:26 +00:00
void PresetBundle : : load_presets ( AppConfig & config , const std : : string & preferred_model_id )
2017-10-30 17:41:50 +00:00
{
2018-03-09 15:37:33 +00:00
// First load the vendor specific system presets.
std : : string errors_cummulative = this - > load_system_presets ( ) ;
const std : : string dir_user_presets = data_dir ( )
2017-12-14 08:40:45 +00:00
# ifdef SLIC3R_PROFILE_USE_PRESETS_SUBDIR
// Store the print/filament/printer presets into a "presets" directory.
+ " /presets "
# else
// Store the print/filament/printer presets at the same location as the upstream Slic3r.
# endif
;
2017-11-28 09:08:01 +00:00
try {
2018-03-09 15:37:33 +00:00
this - > prints . load_presets ( dir_user_presets , " print " ) ;
2017-11-28 09:08:01 +00:00
} catch ( const std : : runtime_error & err ) {
errors_cummulative + = err . what ( ) ;
}
2018-11-16 16:36:23 +00:00
try {
this - > sla_prints . load_presets ( dir_user_presets , " sla_print " ) ;
} catch ( const std : : runtime_error & err ) {
errors_cummulative + = err . what ( ) ;
}
2017-11-28 09:08:01 +00:00
try {
2018-03-09 15:37:33 +00:00
this - > filaments . load_presets ( dir_user_presets , " filament " ) ;
2017-11-28 09:08:01 +00:00
} catch ( const std : : runtime_error & err ) {
errors_cummulative + = err . what ( ) ;
}
2018-07-31 13:09:57 +00:00
try {
this - > sla_materials . load_presets ( dir_user_presets , " sla_material " ) ;
} catch ( const std : : runtime_error & err ) {
errors_cummulative + = err . what ( ) ;
}
2017-11-28 09:08:01 +00:00
try {
2018-03-09 15:37:33 +00:00
this - > printers . load_presets ( dir_user_presets , " printer " ) ;
2017-11-28 09:08:01 +00:00
} catch ( const std : : runtime_error & err ) {
errors_cummulative + = err . what ( ) ;
}
2020-06-24 06:50:01 +00:00
try {
this - > physical_printers . load_printers ( dir_user_presets , " physical_printer " ) ;
} catch ( const std : : runtime_error & err ) {
errors_cummulative + = err . what ( ) ;
}
2017-10-30 17:41:50 +00:00
this - > update_multi_material_filament_presets ( ) ;
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
this - > update_compatible ( PresetSelectCompatibleType : : Never ) ;
2017-11-28 09:08:01 +00:00
if ( ! errors_cummulative . empty ( ) )
throw std : : runtime_error ( errors_cummulative ) ;
2018-03-09 15:37:33 +00:00
2019-04-26 14:53:04 +00:00
this - > load_selections ( config , preferred_model_id ) ;
2018-03-09 15:37:33 +00:00
}
// Load system presets into this PresetBundle.
// For each vendor, there will be a single PresetBundle loaded.
std : : string PresetBundle : : load_system_presets ( )
{
// Here the vendor specific read only Config Bundles are stored.
boost : : filesystem : : path dir = ( boost : : filesystem : : path ( data_dir ( ) ) / " vendor " ) . make_preferred ( ) ;
std : : string errors_cummulative ;
2018-04-18 11:35:51 +00:00
bool first = true ;
2018-03-09 15:37:33 +00:00
for ( auto & dir_entry : boost : : filesystem : : directory_iterator ( dir ) )
2019-02-03 14:30:37 +00:00
if ( Slic3r : : is_ini_file ( dir_entry ) ) {
2018-03-09 15:37:33 +00:00
std : : string name = dir_entry . path ( ) . filename ( ) . string ( ) ;
// Remove the .ini suffix.
name . erase ( name . size ( ) - 4 ) ;
try {
// Load the config bundle, flatten it.
2018-04-18 11:35:51 +00:00
if ( first ) {
// Reset this PresetBundle and load the first vendor config.
this - > load_configbundle ( dir_entry . path ( ) . string ( ) , LOAD_CFGBNDLE_SYSTEM ) ;
first = false ;
} else {
// Load the other vendor configs, merge them with this PresetBundle.
// Report duplicate profiles.
PresetBundle other ;
other . load_configbundle ( dir_entry . path ( ) . string ( ) , LOAD_CFGBNDLE_SYSTEM ) ;
std : : vector < std : : string > duplicates = this - > merge_presets ( std : : move ( other ) ) ;
if ( ! duplicates . empty ( ) ) {
errors_cummulative + = " Vendor configuration file " + name + " contains the following presets with names used by other vendors: " ;
for ( size_t i = 0 ; i < duplicates . size ( ) ; + + i ) {
if ( i > 0 )
errors_cummulative + = " , " ;
errors_cummulative + = duplicates [ i ] ;
}
}
}
2018-03-09 15:37:33 +00:00
} catch ( const std : : runtime_error & err ) {
errors_cummulative + = err . what ( ) ;
errors_cummulative + = " \n " ;
}
}
2019-09-24 14:01:01 +00:00
if ( first ) {
2018-05-16 08:11:00 +00:00
// No config bundle loaded, reset.
this - > reset ( false ) ;
}
2020-01-23 15:04:17 +00:00
2020-03-14 19:18:31 +00:00
this - > update_system_maps ( ) ;
2018-03-09 15:37:33 +00:00
return errors_cummulative ;
2017-10-30 17:41:50 +00:00
}
2018-04-18 11:35:51 +00:00
// Merge one vendor's presets with the other vendor's presets, report duplicates.
std : : vector < std : : string > PresetBundle : : merge_presets ( PresetBundle & & other )
{
this - > vendors . insert ( other . vendors . begin ( ) , other . vendors . end ( ) ) ;
2018-07-31 13:09:57 +00:00
std : : vector < std : : string > duplicate_prints = this - > prints . merge_presets ( std : : move ( other . prints ) , this - > vendors ) ;
2018-11-16 16:36:23 +00:00
std : : vector < std : : string > duplicate_sla_prints = this - > sla_prints . merge_presets ( std : : move ( other . sla_prints ) , this - > vendors ) ;
2018-07-31 13:09:57 +00:00
std : : vector < std : : string > duplicate_filaments = this - > filaments . merge_presets ( std : : move ( other . filaments ) , this - > vendors ) ;
std : : vector < std : : string > duplicate_sla_materials = this - > sla_materials . merge_presets ( std : : move ( other . sla_materials ) , this - > vendors ) ;
std : : vector < std : : string > duplicate_printers = this - > printers . merge_presets ( std : : move ( other . printers ) , this - > vendors ) ;
append ( this - > obsolete_presets . prints , std : : move ( other . obsolete_presets . prints ) ) ;
2018-11-16 16:36:23 +00:00
append ( this - > obsolete_presets . sla_prints , std : : move ( other . obsolete_presets . sla_prints ) ) ;
2018-07-31 13:09:57 +00:00
append ( this - > obsolete_presets . filaments , std : : move ( other . obsolete_presets . filaments ) ) ;
append ( this - > obsolete_presets . sla_materials , std : : move ( other . obsolete_presets . sla_materials ) ) ;
append ( this - > obsolete_presets . printers , std : : move ( other . obsolete_presets . printers ) ) ;
2018-11-16 16:36:23 +00:00
append ( duplicate_prints , std : : move ( duplicate_sla_prints ) ) ;
2018-05-16 14:34:07 +00:00
append ( duplicate_prints , std : : move ( duplicate_filaments ) ) ;
2018-07-31 13:09:57 +00:00
append ( duplicate_prints , std : : move ( duplicate_sla_materials ) ) ;
2018-04-18 11:35:51 +00:00
append ( duplicate_prints , std : : move ( duplicate_printers ) ) ;
return duplicate_prints ;
}
2020-03-14 19:18:31 +00:00
void PresetBundle : : update_system_maps ( )
{
this - > prints . update_map_system_profile_renamed ( ) ;
this - > sla_prints . update_map_system_profile_renamed ( ) ;
this - > filaments . update_map_system_profile_renamed ( ) ;
this - > sla_materials . update_map_system_profile_renamed ( ) ;
this - > printers . update_map_system_profile_renamed ( ) ;
this - > prints . update_map_alias_to_profile_name ( ) ;
this - > sla_prints . update_map_alias_to_profile_name ( ) ;
this - > filaments . update_map_alias_to_profile_name ( ) ;
this - > sla_materials . update_map_alias_to_profile_name ( ) ;
}
2017-11-02 16:31:24 +00:00
static inline std : : string remove_ini_suffix ( const std : : string & name )
{
std : : string out = name ;
if ( boost : : iends_with ( out , " .ini " ) )
out . erase ( out . end ( ) - 4 , out . end ( ) ) ;
return out ;
}
2018-03-09 15:37:33 +00:00
// Set the "enabled" 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 PresetBundle : : load_installed_printers ( const AppConfig & config )
{
2020-03-14 19:18:31 +00:00
this - > update_system_maps ( ) ;
for ( auto & preset : printers )
2018-03-29 15:54:43 +00:00
preset . set_visible_from_appconfig ( config ) ;
2019-08-27 14:59:07 +00:00
}
2019-11-29 10:02:30 +00:00
const std : : string & PresetBundle : : get_preset_name_by_alias ( const Preset : : Type & preset_type , const std : : string & alias ) const
{
// there are not aliases for Printers profiles
if ( preset_type = = Preset : : TYPE_PRINTER | | preset_type = = Preset : : TYPE_INVALID )
return alias ;
const PresetCollection & presets = preset_type = = Preset : : TYPE_PRINT ? prints :
preset_type = = Preset : : TYPE_SLA_PRINT ? sla_prints :
preset_type = = Preset : : TYPE_FILAMENT ? filaments :
sla_materials ;
return presets . get_preset_name_by_alias ( alias ) ;
}
2019-08-27 14:59:07 +00:00
void PresetBundle : : load_installed_filaments ( AppConfig & config )
{
if ( ! config . has_section ( AppConfig : : SECTION_FILAMENTS ) ) {
2019-12-05 13:48:11 +00:00
// Compatibility with the PrusaSlicer 2.1.1 and older, where the filament profiles were not installable yet.
// Find all filament profiles, which are compatible with installed printers, and act as if these filament profiles
// were installed.
std : : unordered_set < const Preset * > compatible_filaments ;
for ( const Preset & printer : printers )
if ( printer . is_visible & & printer . printer_technology ( ) = = ptFFF ) {
const PresetWithVendorProfile printer_with_vendor_profile = printers . get_preset_with_vendor_profile ( printer ) ;
for ( const Preset & filament : filaments )
2020-03-14 19:18:31 +00:00
if ( filament . is_system & & is_compatible_with_printer ( filaments . get_preset_with_vendor_profile ( filament ) , printer_with_vendor_profile ) )
2019-12-05 13:48:11 +00:00
compatible_filaments . insert ( & filament ) ;
}
// and mark these filaments as installed, therefore this code will not be executed at the next start of the application.
for ( const auto & filament : compatible_filaments )
2019-08-27 14:59:07 +00:00
config . set ( AppConfig : : SECTION_FILAMENTS , filament - > name , " 1 " ) ;
}
2019-04-12 14:18:46 +00:00
2019-12-05 13:48:11 +00:00
for ( auto & preset : filaments )
2019-04-12 14:18:46 +00:00
preset . set_visible_from_appconfig ( config ) ;
2019-08-27 14:59:07 +00:00
}
void PresetBundle : : load_installed_sla_materials ( AppConfig & config )
{
if ( ! config . has_section ( AppConfig : : SECTION_MATERIALS ) ) {
std : : unordered_set < const Preset * > comp_sla_materials ;
2019-12-05 13:48:11 +00:00
// Compatibility with the PrusaSlicer 2.1.1 and older, where the SLA material profiles were not installable yet.
// Find all SLA material profiles, which are compatible with installed printers, and act as if these SLA material profiles
// were installed.
for ( const Preset & printer : printers )
if ( printer . is_visible & & printer . printer_technology ( ) = = ptSLA ) {
const PresetWithVendorProfile printer_with_vendor_profile = printers . get_preset_with_vendor_profile ( printer ) ;
for ( const Preset & material : sla_materials )
2020-03-14 19:18:31 +00:00
if ( material . is_system & & is_compatible_with_printer ( sla_materials . get_preset_with_vendor_profile ( material ) , printer_with_vendor_profile ) )
2019-12-05 13:48:11 +00:00
comp_sla_materials . insert ( & material ) ;
}
// and mark these SLA materials as installed, therefore this code will not be executed at the next start of the application.
for ( const auto & material : comp_sla_materials )
2019-08-27 14:59:07 +00:00
config . set ( AppConfig : : SECTION_MATERIALS , material - > name , " 1 " ) ;
}
2019-04-12 14:18:46 +00:00
2019-12-05 13:48:11 +00:00
for ( auto & preset : sla_materials )
2019-04-12 14:18:46 +00:00
preset . set_visible_from_appconfig ( config ) ;
2018-03-09 15:37:33 +00:00
}
2017-10-30 17:41:50 +00:00
// Load selections (current print, current filaments, current printer) from config.ini
2018-07-23 12:19:40 +00:00
// This is done on application start up or after updates are applied.
2019-08-27 14:59:07 +00:00
void PresetBundle : : load_selections ( AppConfig & config , const std : : string & preferred_model_id )
2017-10-30 17:41:50 +00:00
{
2018-04-13 12:49:33 +00:00
// Update visibility of presets based on application vendor / model / variant configuration.
this - > load_installed_printers ( config ) ;
2019-08-27 14:59:07 +00:00
// Update visibility of filament and sla material presets
this - > load_installed_filaments ( config ) ;
this - > load_installed_sla_materials ( config ) ;
2018-04-13 12:49:33 +00:00
// Parse the initial print / filament / printer profile names.
2018-07-31 13:09:57 +00:00
std : : string initial_print_profile_name = remove_ini_suffix ( config . get ( " presets " , " print " ) ) ;
2018-11-16 16:36:23 +00:00
std : : string initial_sla_print_profile_name = remove_ini_suffix ( config . get ( " presets " , " sla_print " ) ) ;
2018-07-31 13:09:57 +00:00
std : : string initial_filament_profile_name = remove_ini_suffix ( config . get ( " presets " , " filament " ) ) ;
std : : string initial_sla_material_profile_name = remove_ini_suffix ( config . get ( " presets " , " sla_material " ) ) ;
std : : string initial_printer_profile_name = remove_ini_suffix ( config . get ( " presets " , " printer " ) ) ;
2018-04-13 12:49:33 +00:00
2019-04-26 14:53:04 +00:00
// Activate print / filament / printer profiles from either the config,
// or from the preferred_model_id suggestion passed in by ConfigWizard.
// If the printer profile enumerated by the config are not visible, select an alternate preset.
2018-07-02 18:25:37 +00:00
// Do not select alternate profiles for the print / filament profiles as those presets
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
// will be selected by the following call of this->update_compatible(PresetSelectCompatibleType::Always).
2019-04-26 14:53:04 +00:00
const Preset * initial_printer = printers . find_preset ( initial_printer_profile_name ) ;
const Preset * preferred_printer = printers . find_by_model_id ( preferred_model_id ) ;
2019-05-15 15:15:52 +00:00
printers . select_preset_by_name (
( preferred_printer ! = nullptr & & ( initial_printer = = nullptr | | ! initial_printer - > is_visible ) ) ?
preferred_printer - > name :
initial_printer_profile_name ,
true ) ;
// Selects the profile, leaves it to -1 if the initial profile name is empty or if it was not found.
prints . select_preset_by_name_strict ( initial_print_profile_name ) ;
filaments . select_preset_by_name_strict ( initial_filament_profile_name ) ;
sla_prints . select_preset_by_name_strict ( initial_sla_print_profile_name ) ;
sla_materials . select_preset_by_name_strict ( initial_sla_material_profile_name ) ;
// Load the names of the other filament profiles selected for a multi-material printer.
// Load it even if the current printer technology is SLA.
// The possibly excessive filament names will be later removed with this->update_multi_material_filament_presets()
// once the FFF technology gets selected.
this - > filament_presets = { filaments . get_selected_preset_name ( ) } ;
for ( unsigned int i = 1 ; i < 1000 ; + + i ) {
char name [ 64 ] ;
2019-09-06 15:46:55 +00:00
sprintf ( name , " filament_%u " , i ) ;
2019-05-15 15:15:52 +00:00
if ( ! config . has ( " presets " , name ) )
break ;
this - > filament_presets . emplace_back ( remove_ini_suffix ( config . get ( " presets " , name ) ) ) ;
2017-10-30 17:41:50 +00:00
}
2018-03-29 15:54:43 +00:00
2017-11-10 16:27:05 +00:00
// Update visibility of presets based on their compatibility with the active printer.
2017-12-20 10:28:16 +00:00
// Always try to select a compatible print and filament preset to the current printer preset,
// as the application may have been closed with an active "external" preset, which does not
// exist.
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
this - > update_compatible ( PresetSelectCompatibleType : : Always ) ;
2018-07-02 18:25:37 +00:00
this - > update_multi_material_filament_presets ( ) ;
2020-06-24 06:50:01 +00:00
// Parse the initial physical printer name.
std : : string initial_physical_printer_name = remove_ini_suffix ( config . get ( " extras " , " physical_printer " ) ) ;
// Activate physical printer from the config
2020-07-21 14:21:18 +00:00
if ( ! initial_physical_printer_name . empty ( ) )
2020-07-23 10:17:18 +00:00
physical_printers . select_printer ( initial_physical_printer_name ) ;
2017-10-30 17:41:50 +00:00
}
// Export selections (current print, current filaments, current printer) into config.ini
void PresetBundle : : export_selections ( AppConfig & config )
{
2018-10-31 15:22:36 +00:00
assert ( this - > printers . get_edited_preset ( ) . printer_technology ( ) ! = ptFFF | | filament_presets . size ( ) > = 1 ) ;
assert ( this - > printers . get_edited_preset ( ) . printer_technology ( ) ! = ptFFF | | filament_presets . size ( ) > 1 | | filaments . get_selected_preset_name ( ) = = filament_presets . front ( ) ) ;
2017-11-01 18:30:05 +00:00
config . clear_section ( " presets " ) ;
2018-07-31 13:09:57 +00:00
config . set ( " presets " , " print " , prints . get_selected_preset_name ( ) ) ;
config . set ( " presets " , " filament " , filament_presets . front ( ) ) ;
2019-09-06 15:46:55 +00:00
for ( unsigned i = 1 ; i < filament_presets . size ( ) ; + + i ) {
2017-10-30 17:41:50 +00:00
char name [ 64 ] ;
2019-09-06 15:46:55 +00:00
sprintf ( name , " filament_%u " , i ) ;
2017-10-30 17:41:50 +00:00
config . set ( " presets " , name , filament_presets [ i ] ) ;
}
2019-09-06 15:46:55 +00:00
2018-11-19 10:10:22 +00:00
config . set ( " presets " , " sla_print " , sla_prints . get_selected_preset_name ( ) ) ;
2018-07-31 13:09:57 +00:00
config . set ( " presets " , " sla_material " , sla_materials . get_selected_preset_name ( ) ) ;
2018-12-03 12:14:28 +00:00
config . set ( " presets " , " printer " , printers . get_selected_preset_name ( ) ) ;
2020-06-24 06:50:01 +00:00
2020-07-17 12:32:38 +00:00
config . set ( " extras " , " physical_printer " , physical_printers . get_selected_full_printer_name ( ) ) ;
2019-06-03 08:15:26 +00:00
}
2017-10-30 17:41:50 +00:00
DynamicPrintConfig PresetBundle : : full_config ( ) const
2018-07-31 13:09:57 +00:00
{
return ( this - > printers . get_edited_preset ( ) . printer_technology ( ) = = ptFFF ) ?
this - > full_fff_config ( ) :
this - > full_sla_config ( ) ;
}
2018-12-06 13:42:15 +00:00
DynamicPrintConfig PresetBundle : : full_config_secure ( ) const
{
DynamicPrintConfig config = this - > full_config ( ) ;
2019-08-26 14:39:08 +00:00
config . erase ( " print_host " ) ;
2018-12-06 13:42:15 +00:00
config . erase ( " printhost_apikey " ) ;
config . erase ( " printhost_cafile " ) ;
return config ;
}
2018-07-31 13:09:57 +00:00
DynamicPrintConfig PresetBundle : : full_fff_config ( ) const
2017-10-30 17:41:50 +00:00
{
DynamicPrintConfig out ;
2018-08-03 12:14:25 +00:00
out . apply ( FullPrintConfig : : defaults ( ) ) ;
2017-10-30 17:41:50 +00:00
out . apply ( this - > prints . get_edited_preset ( ) . config ) ;
2018-05-23 11:19:25 +00:00
// Add the default filament preset to have the "filament_preset_id" defined.
out . apply ( this - > filaments . default_preset ( ) . config ) ;
out . apply ( this - > printers . get_edited_preset ( ) . config ) ;
2018-03-14 10:54:11 +00:00
out . apply ( this - > project_config ) ;
2017-10-30 17:41:50 +00:00
auto * nozzle_diameter = dynamic_cast < const ConfigOptionFloats * > ( out . option ( " nozzle_diameter " ) ) ;
size_t num_extruders = nozzle_diameter - > values . size ( ) ;
2018-06-26 08:50:50 +00:00
// Collect the "compatible_printers_condition" and "inherits" values over all presets (print, filaments, printers) into a single vector.
std : : vector < std : : string > compatible_printers_condition ;
2018-12-04 16:56:49 +00:00
std : : vector < std : : string > compatible_prints_condition ;
2018-06-26 08:50:50 +00:00
std : : vector < std : : string > inherits ;
2018-06-27 14:57:42 +00:00
compatible_printers_condition . emplace_back ( this - > prints . get_edited_preset ( ) . compatible_printers_condition ( ) ) ;
inherits . emplace_back ( this - > prints . get_edited_preset ( ) . inherits ( ) ) ;
2017-10-30 17:41:50 +00:00
if ( num_extruders < = 1 ) {
out . apply ( this - > filaments . get_edited_preset ( ) . config ) ;
2018-06-27 14:57:42 +00:00
compatible_printers_condition . emplace_back ( this - > filaments . get_edited_preset ( ) . compatible_printers_condition ( ) ) ;
2018-12-04 16:56:49 +00:00
compatible_prints_condition . emplace_back ( this - > filaments . get_edited_preset ( ) . compatible_prints_condition ( ) ) ;
2018-06-27 14:57:42 +00:00
inherits . emplace_back ( this - > filaments . get_edited_preset ( ) . inherits ( ) ) ;
2017-10-30 17:41:50 +00:00
} else {
// Retrieve filament presets and build a single config object for them.
// First collect the filament configurations based on the user selection of this->filament_presets.
2018-05-16 14:34:07 +00:00
// Here this->filaments.find_preset() and this->filaments.first_visible() return the edited copy of the preset if active.
2017-10-30 17:41:50 +00:00
std : : vector < const DynamicPrintConfig * > filament_configs ;
for ( const std : : string & filament_preset_name : this - > filament_presets )
filament_configs . emplace_back ( & this - > filaments . find_preset ( filament_preset_name , true ) - > config ) ;
while ( filament_configs . size ( ) < num_extruders )
filament_configs . emplace_back ( & this - > filaments . first_visible ( ) . config ) ;
2018-06-26 08:50:50 +00:00
for ( const DynamicPrintConfig * cfg : filament_configs ) {
2020-01-03 15:32:56 +00:00
// The compatible_prints/printers_condition() returns a reference to configuration key, which may not yet exist.
DynamicPrintConfig & cfg_rw = * const_cast < DynamicPrintConfig * > ( cfg ) ;
compatible_printers_condition . emplace_back ( Preset : : compatible_printers_condition ( cfg_rw ) ) ;
compatible_prints_condition . emplace_back ( Preset : : compatible_prints_condition ( cfg_rw ) ) ;
inherits . emplace_back ( Preset : : inherits ( cfg_rw ) ) ;
2018-06-26 08:50:50 +00:00
}
2017-10-30 17:41:50 +00:00
// Option values to set a ConfigOptionVector from.
std : : vector < const ConfigOption * > filament_opts ( num_extruders , nullptr ) ;
// loop through options and apply them to the resulting config.
for ( const t_config_option_key & key : this - > filaments . default_preset ( ) . config . keys ( ) ) {
2018-12-04 16:56:49 +00:00
if ( key = = " compatible_prints " | | key = = " compatible_printers " )
2017-11-10 16:27:05 +00:00
continue ;
2017-10-30 17:41:50 +00:00
// Get a destination option.
ConfigOption * opt_dst = out . option ( key , false ) ;
if ( opt_dst - > is_scalar ( ) ) {
// Get an option, do not create if it does not exist.
const ConfigOption * opt_src = filament_configs . front ( ) - > option ( key ) ;
if ( opt_src ! = nullptr )
opt_dst - > set ( opt_src ) ;
} else {
// Setting a vector value from all filament_configs.
for ( size_t i = 0 ; i < filament_opts . size ( ) ; + + i )
filament_opts [ i ] = filament_configs [ i ] - > option ( key ) ;
static_cast < ConfigOptionVectorBase * > ( opt_dst ) - > set ( filament_opts ) ;
}
}
}
2017-12-01 17:55:57 +00:00
2018-06-26 08:50:50 +00:00
// Don't store the "compatible_printers_condition" for the printer profile, there is none.
2018-06-27 14:57:42 +00:00
inherits . emplace_back ( this - > printers . get_edited_preset ( ) . inherits ( ) ) ;
2018-06-26 08:50:50 +00:00
2018-12-04 16:56:49 +00:00
// These value types clash between the print and filament profiles. They should be renamed.
out . erase ( " compatible_prints " ) ;
out . erase ( " compatible_prints_condition " ) ;
2017-12-01 17:55:57 +00:00
out . erase ( " compatible_printers " ) ;
2018-05-23 11:19:25 +00:00
out . erase ( " compatible_printers_condition " ) ;
2018-06-26 08:50:50 +00:00
out . erase ( " inherits " ) ;
2017-10-30 17:41:50 +00:00
static const char * keys [ ] = { " perimeter " , " infill " , " solid_infill " , " support_material " , " support_material_interface " } ;
for ( size_t i = 0 ; i < sizeof ( keys ) / sizeof ( keys [ 0 ] ) ; + + i ) {
std : : string key = std : : string ( keys [ i ] ) + " _extruder " ;
auto * opt = dynamic_cast < ConfigOptionInt * > ( out . option ( key , false ) ) ;
assert ( opt ! = nullptr ) ;
2017-11-01 18:30:05 +00:00
opt - > value = boost : : algorithm : : clamp < int > ( opt - > value , 0 , int ( num_extruders ) ) ;
2017-10-30 17:41:50 +00:00
}
2019-05-22 09:31:36 +00:00
out . option < ConfigOptionString > ( " print_settings_id " , true ) - > value = this - > prints . get_selected_preset_name ( ) ;
2018-06-22 12:17:03 +00:00
out . option < ConfigOptionStrings > ( " filament_settings_id " , true ) - > values = this - > filament_presets ;
2019-05-22 09:31:36 +00:00
out . option < ConfigOptionString > ( " printer_settings_id " , true ) - > value = this - > printers . get_selected_preset_name ( ) ;
2018-06-26 08:50:50 +00:00
// Serialize the collected "compatible_printers_condition" and "inherits" fields.
// There will be 1 + num_exturders fields for "inherits" and 2 + num_extruders for "compatible_printers_condition" stored.
// The vector will not be stored if all fields are empty strings.
auto add_if_some_non_empty = [ & out ] ( std : : vector < std : : string > & & values , const std : : string & key ) {
bool nonempty = false ;
for ( const std : : string & v : values )
if ( ! v . empty ( ) ) {
nonempty = true ;
break ;
}
if ( nonempty )
out . set_key_value ( key , new ConfigOptionStrings ( std : : move ( values ) ) ) ;
} ;
2018-06-28 18:13:01 +00:00
add_if_some_non_empty ( std : : move ( compatible_printers_condition ) , " compatible_printers_condition_cummulative " ) ;
2018-12-04 16:56:49 +00:00
add_if_some_non_empty ( std : : move ( compatible_prints_condition ) , " compatible_prints_condition_cummulative " ) ;
2018-06-28 18:13:01 +00:00
add_if_some_non_empty ( std : : move ( inherits ) , " inherits_cummulative " ) ;
2018-11-08 19:18:40 +00:00
out . option < ConfigOptionEnumGeneric > ( " printer_technology " , true ) - > value = ptFFF ;
2017-10-30 17:41:50 +00:00
return out ;
}
2018-07-31 13:09:57 +00:00
DynamicPrintConfig PresetBundle : : full_sla_config ( ) const
{
DynamicPrintConfig out ;
2018-08-03 12:14:25 +00:00
out . apply ( SLAFullPrintConfig : : defaults ( ) ) ;
2018-11-16 16:36:23 +00:00
out . apply ( this - > sla_prints . get_edited_preset ( ) . config ) ;
2018-07-31 13:09:57 +00:00
out . apply ( this - > sla_materials . get_edited_preset ( ) . config ) ;
out . apply ( this - > printers . get_edited_preset ( ) . config ) ;
// There are no project configuration values as of now, the project_config is reserved for FFF printers.
// out.apply(this->project_config);
2018-11-16 16:36:23 +00:00
// Collect the "compatible_printers_condition" and "inherits" values over all presets (sla_prints, sla_materials, printers) into a single vector.
2018-07-31 13:09:57 +00:00
std : : vector < std : : string > compatible_printers_condition ;
2018-12-04 16:56:49 +00:00
std : : vector < std : : string > compatible_prints_condition ;
2018-07-31 13:09:57 +00:00
std : : vector < std : : string > inherits ;
2018-12-04 16:56:49 +00:00
compatible_printers_condition . emplace_back ( this - > sla_prints . get_edited_preset ( ) . compatible_printers_condition ( ) ) ;
inherits . emplace_back ( this - > sla_prints . get_edited_preset ( ) . inherits ( ) ) ;
compatible_printers_condition . emplace_back ( this - > sla_materials . get_edited_preset ( ) . compatible_printers_condition ( ) ) ;
compatible_prints_condition . emplace_back ( this - > sla_materials . get_edited_preset ( ) . compatible_prints_condition ( ) ) ;
inherits . emplace_back ( this - > sla_materials . get_edited_preset ( ) . inherits ( ) ) ;
2018-07-31 13:09:57 +00:00
inherits . emplace_back ( this - > printers . get_edited_preset ( ) . inherits ( ) ) ;
// These two value types clash between the print and filament profiles. They should be renamed.
out . erase ( " compatible_printers " ) ;
out . erase ( " compatible_printers_condition " ) ;
out . erase ( " inherits " ) ;
2019-05-22 09:31:36 +00:00
out . option < ConfigOptionString > ( " sla_print_settings_id " , true ) - > value = this - > sla_prints . get_selected_preset_name ( ) ;
out . option < ConfigOptionString > ( " sla_material_settings_id " , true ) - > value = this - > sla_materials . get_selected_preset_name ( ) ;
out . option < ConfigOptionString > ( " printer_settings_id " , true ) - > value = this - > printers . get_selected_preset_name ( ) ;
2018-07-31 13:09:57 +00:00
// Serialize the collected "compatible_printers_condition" and "inherits" fields.
// There will be 1 + num_exturders fields for "inherits" and 2 + num_extruders for "compatible_printers_condition" stored.
// The vector will not be stored if all fields are empty strings.
auto add_if_some_non_empty = [ & out ] ( std : : vector < std : : string > & & values , const std : : string & key ) {
bool nonempty = false ;
for ( const std : : string & v : values )
if ( ! v . empty ( ) ) {
nonempty = true ;
break ;
}
if ( nonempty )
out . set_key_value ( key , new ConfigOptionStrings ( std : : move ( values ) ) ) ;
} ;
add_if_some_non_empty ( std : : move ( compatible_printers_condition ) , " compatible_printers_condition_cummulative " ) ;
2018-12-04 16:56:49 +00:00
add_if_some_non_empty ( std : : move ( compatible_prints_condition ) , " compatible_prints_condition_cummulative " ) ;
2018-07-31 13:09:57 +00:00
add_if_some_non_empty ( std : : move ( inherits ) , " inherits_cummulative " ) ;
2018-11-08 19:18:40 +00:00
out . option < ConfigOptionEnumGeneric > ( " printer_technology " , true ) - > value = ptSLA ;
return out ;
2018-07-31 13:09:57 +00:00
}
2017-10-30 17:41:50 +00:00
// 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 PresetBundle : : load_config_file ( const std : : string & path )
2017-11-01 18:30:05 +00:00
{
2017-11-02 15:21:34 +00:00
if ( boost : : iends_with ( path , " .gcode " ) | | boost : : iends_with ( path , " .g " ) ) {
DynamicPrintConfig config ;
config . apply ( FullPrintConfig : : defaults ( ) ) ;
2018-02-13 14:19:55 +00:00
config . load_from_gcode_file ( path ) ;
Preset : : normalize ( config ) ;
2017-12-20 10:28:16 +00:00
load_config_file_config ( path , true , std : : move ( config ) ) ;
2017-11-02 15:21:34 +00:00
return ;
}
2017-11-01 18:30:05 +00:00
// 1) Try to load the config file into a boost property tree.
boost : : property_tree : : ptree tree ;
try {
boost : : nowide : : ifstream ifs ( path ) ;
boost : : property_tree : : read_ini ( ifs , tree ) ;
2017-11-28 09:08:01 +00:00
} catch ( const std : : ifstream : : failure & err ) {
2020-03-07 15:31:14 +00:00
throw std : : runtime_error ( std : : string ( " The Config Bundle cannot be loaded: " ) + path + " \n \t Reason: " + err . what ( ) ) ;
} catch ( const boost : : property_tree : : file_parser_error & err ) {
throw std : : runtime_error ( ( boost : : format ( " Failed loading the Config Bundle \" %1% \" : %2% at line %3% " )
% err . filename ( ) % err . message ( ) % err . line ( ) ) . str ( ) ) ;
2017-11-28 09:08:01 +00:00
} catch ( const std : : runtime_error & err ) {
throw std : : runtime_error ( std : : string ( " Failed loading the preset file: " ) + path + " \n \t Reason: " + err . what ( ) ) ;
2017-11-01 18:30:05 +00:00
}
// 2) Continue based on the type of the configuration file.
ConfigFileType config_file_type = guess_config_file_type ( tree ) ;
switch ( config_file_type ) {
case CONFIG_FILE_TYPE_UNKNOWN :
throw std : : runtime_error ( std : : string ( " Unknown configuration file type: " ) + path ) ;
case CONFIG_FILE_TYPE_APP_CONFIG :
throw std : : runtime_error ( std : : string ( " Invalid configuration file: " ) + path + " . This is an application config file. " ) ;
2017-11-02 15:21:34 +00:00
case CONFIG_FILE_TYPE_CONFIG :
{
// Initialize a config from full defaults.
DynamicPrintConfig config ;
config . apply ( FullPrintConfig : : defaults ( ) ) ;
config . load ( tree ) ;
Preset : : normalize ( config ) ;
2017-12-20 10:28:16 +00:00
load_config_file_config ( path , true , std : : move ( config ) ) ;
2017-11-02 15:21:34 +00:00
break ;
}
2017-11-01 18:30:05 +00:00
case CONFIG_FILE_TYPE_CONFIG_BUNDLE :
2017-11-02 15:21:34 +00:00
load_config_file_config_bundle ( path , tree ) ;
2017-11-01 18:30:05 +00:00
break ;
}
}
// Load a config file from a boost property_tree. This is a private method called from load_config_file.
2017-12-20 10:28:16 +00:00
void PresetBundle : : load_config_file_config ( const std : : string & name_or_path , bool is_external , DynamicPrintConfig & & config )
2017-10-30 17:41:50 +00:00
{
2018-07-31 13:09:57 +00:00
PrinterTechnology printer_technology = Preset : : printer_technology ( config ) ;
2017-12-01 17:55:57 +00:00
// The "compatible_printers" field should not have been exported into a config.ini or a G-code anyway,
// but some of the alpha versions of Slic3r did.
{
ConfigOption * opt_compatible = config . optptr ( " compatible_printers " ) ;
if ( opt_compatible ! = nullptr ) {
assert ( opt_compatible - > type ( ) = = coStrings ) ;
if ( opt_compatible - > type ( ) = = coStrings )
static_cast < ConfigOptionStrings * > ( opt_compatible ) - > values . clear ( ) ;
}
}
2018-07-31 13:09:57 +00:00
size_t num_extruders = ( printer_technology = = ptFFF ) ?
std : : min ( config . option < ConfigOptionFloats > ( " nozzle_diameter " ) - > values . size ( ) ,
config . option < ConfigOptionFloats > ( " filament_diameter " ) - > values . size ( ) ) :
2018-12-03 12:14:28 +00:00
// 1 SLA material
1 ;
2018-06-28 18:13:01 +00:00
// Make a copy of the "compatible_printers_condition_cummulative" and "inherits_cummulative" vectors, which
2018-06-26 08:50:50 +00:00
// accumulate values over all presets (print, filaments, printers).
// These values will be distributed into their particular presets when loading.
2018-06-28 18:13:01 +00:00
std : : vector < std : : string > compatible_printers_condition_values = std : : move ( config . option < ConfigOptionStrings > ( " compatible_printers_condition_cummulative " , true ) - > values ) ;
2018-12-04 16:56:49 +00:00
std : : vector < std : : string > compatible_prints_condition_values = std : : move ( config . option < ConfigOptionStrings > ( " compatible_prints_condition_cummulative " , true ) - > values ) ;
2018-06-28 18:13:01 +00:00
std : : vector < std : : string > inherits_values = std : : move ( config . option < ConfigOptionStrings > ( " inherits_cummulative " , true ) - > values ) ;
std : : string & compatible_printers_condition = Preset : : compatible_printers_condition ( config ) ;
2018-12-04 16:56:49 +00:00
std : : string & compatible_prints_condition = Preset : : compatible_prints_condition ( config ) ;
2018-06-28 18:13:01 +00:00
std : : string & inherits = Preset : : inherits ( config ) ;
compatible_printers_condition_values . resize ( num_extruders + 2 , std : : string ( ) ) ;
2018-12-04 16:56:49 +00:00
compatible_prints_condition_values . resize ( num_extruders , std : : string ( ) ) ;
2018-06-28 18:13:01 +00:00
inherits_values . resize ( num_extruders + 2 , std : : string ( ) ) ;
2018-07-27 07:53:12 +00:00
// The "default_filament_profile" will be later extracted into the printer profile.
2018-12-03 12:14:28 +00:00
switch ( printer_technology ) {
case ptFFF :
config . option < ConfigOptionString > ( " default_print_profile " , true ) ;
config . option < ConfigOptionStrings > ( " default_filament_profile " , true ) - > values . resize ( num_extruders , std : : string ( ) ) ;
break ;
case ptSLA :
config . option < ConfigOptionString > ( " default_sla_print_profile " , true ) ;
config . option < ConfigOptionString > ( " default_sla_material_profile " , true ) ;
break ;
2019-09-03 08:27:16 +00:00
default : break ;
2018-12-03 12:14:28 +00:00
}
2018-06-26 08:50:50 +00:00
2017-11-02 15:21:34 +00:00
// 1) Create a name from the file name.
2017-10-30 17:41:50 +00:00
// Keep the suffix (.ini, .gcode, .amf, .3mf etc) to differentiate it from the normal profiles.
2017-12-20 10:28:16 +00:00
std : : string name = is_external ? boost : : filesystem : : path ( name_or_path ) . filename ( ) . string ( ) : name_or_path ;
2017-10-30 17:41:50 +00:00
2017-11-02 15:21:34 +00:00
// 2) If the loading succeeded, split and load the config into print / filament / printer settings.
2017-10-30 17:41:50 +00:00
// First load the print and printer presets.
2018-11-16 16:36:23 +00:00
2018-12-03 12:14:28 +00:00
auto load_preset =
2018-12-04 16:56:49 +00:00
[ & config , & inherits , & inherits_values ,
& compatible_printers_condition , & compatible_printers_condition_values ,
& compatible_prints_condition , & compatible_prints_condition_values ,
is_external , & name , & name_or_path ]
2018-12-03 12:14:28 +00:00
( PresetCollection & presets , size_t idx , const std : : string & key ) {
// Split the "compatible_printers_condition" and "inherits" values one by one from a single vector to the print & printer profiles.
inherits = inherits_values [ idx ] ;
compatible_printers_condition = compatible_printers_condition_values [ idx ] ;
2018-12-04 16:56:49 +00:00
if ( idx > 0 & & idx - 1 < compatible_prints_condition_values . size ( ) )
compatible_prints_condition = compatible_prints_condition_values [ idx - 1 ] ;
2018-07-17 08:41:17 +00:00
if ( is_external )
2018-12-03 12:14:28 +00:00
presets . load_external_preset ( name_or_path , name , config . opt_string ( key , true ) , config ) ;
else
presets . load_preset ( presets . path_from_name ( name ) , name , config ) . save ( ) ;
} ;
switch ( Preset : : printer_technology ( config ) ) {
case ptFFF :
{
load_preset ( this - > prints , 0 , " print_settings_id " ) ;
load_preset ( this - > printers , num_extruders + 1 , " printer_settings_id " ) ;
2017-10-30 17:41:50 +00:00
2018-07-31 13:09:57 +00:00
// 3) Now load the filaments. If there are multiple filament presets, split them and load them.
auto old_filament_profile_names = config . option < ConfigOptionStrings > ( " filament_settings_id " , true ) ;
old_filament_profile_names - > values . resize ( num_extruders , std : : string ( ) ) ;
2018-06-28 18:13:01 +00:00
2018-07-31 13:09:57 +00:00
if ( num_extruders < = 1 ) {
2018-06-28 18:13:01 +00:00
// Split the "compatible_printers_condition" and "inherits" from the cummulative vectors to separate filament presets.
2018-07-31 13:09:57 +00:00
inherits = inherits_values [ 1 ] ;
compatible_printers_condition = compatible_printers_condition_values [ 1 ] ;
2018-12-04 16:56:49 +00:00
compatible_prints_condition = compatible_prints_condition_values . front ( ) ;
2018-12-03 12:14:28 +00:00
Preset * loaded = nullptr ;
if ( is_external ) {
loaded = & this - > filaments . load_external_preset ( name_or_path , name , old_filament_profile_names - > values . front ( ) , config ) ;
} else {
loaded = & this - > filaments . load_preset ( this - > filaments . path_from_name ( name ) , name , config ) ;
loaded - > save ( ) ;
}
2018-07-31 13:09:57 +00:00
this - > filament_presets . clear ( ) ;
2018-12-03 12:14:28 +00:00
this - > filament_presets . emplace_back ( loaded - > name ) ;
2018-07-31 13:09:57 +00:00
} else {
// Split the filament presets, load each of them separately.
std : : vector < DynamicPrintConfig > configs ( num_extruders , this - > filaments . default_preset ( ) . config ) ;
// loop through options and scatter them into configs.
for ( const t_config_option_key & key : this - > filaments . default_preset ( ) . config . keys ( ) ) {
const ConfigOption * other_opt = config . option ( key ) ;
if ( other_opt = = nullptr )
continue ;
if ( other_opt - > is_scalar ( ) ) {
for ( size_t i = 0 ; i < configs . size ( ) ; + + i )
configs [ i ] . option ( key , false ) - > set ( other_opt ) ;
2018-12-04 16:56:49 +00:00
} else if ( key ! = " compatible_printers " & & key ! = " compatible_prints " ) {
2018-07-31 13:09:57 +00:00
for ( size_t i = 0 ; i < configs . size ( ) ; + + i )
static_cast < ConfigOptionVectorBase * > ( configs [ i ] . option ( key , false ) ) - > set_at ( other_opt , 0 , i ) ;
}
}
// Load the configs into this->filaments and make them active.
2019-08-20 16:45:12 +00:00
this - > filament_presets = std : : vector < std : : string > ( configs . size ( ) ) ;
// To avoid incorrect selection of the first filament preset (means a value of Preset->m_idx_selected)
// in a case when next added preset take a place of previosly selected preset,
// we should add presets from last to first
for ( int i = ( int ) configs . size ( ) - 1 ; i > = 0 ; i - - ) {
2018-07-31 13:09:57 +00:00
DynamicPrintConfig & cfg = configs [ i ] ;
// Split the "compatible_printers_condition" and "inherits" from the cummulative vectors to separate filament presets.
cfg . opt_string ( " compatible_printers_condition " , true ) = compatible_printers_condition_values [ i + 1 ] ;
2018-12-04 16:56:49 +00:00
cfg . opt_string ( " compatible_prints_condition " , true ) = compatible_prints_condition_values [ i ] ;
2018-07-31 13:09:57 +00:00
cfg . opt_string ( " inherits " , true ) = inherits_values [ i + 1 ] ;
// Load all filament presets, but only select the first one in the preset dialog.
Preset * loaded = nullptr ;
if ( is_external )
loaded = & this - > filaments . load_external_preset ( name_or_path , name ,
2019-09-06 15:46:55 +00:00
( i < int ( old_filament_profile_names - > values . size ( ) ) ) ? old_filament_profile_names - > values [ i ] : " " ,
2018-07-31 13:09:57 +00:00
std : : move ( cfg ) , i = = 0 ) ;
else {
// Used by the config wizard when creating a custom setup.
// Therefore this block should only be called for a single extruder.
char suffix [ 64 ] ;
if ( i = = 0 )
suffix [ 0 ] = 0 ;
else
2019-06-10 16:30:54 +00:00
sprintf ( suffix , " %d " , ( int ) i ) ;
2018-07-31 13:09:57 +00:00
std : : string new_name = name + suffix ;
loaded = & this - > filaments . load_preset ( this - > filaments . path_from_name ( new_name ) ,
new_name , std : : move ( cfg ) , i = = 0 ) ;
loaded - > save ( ) ;
}
2019-08-20 16:45:12 +00:00
this - > filament_presets [ i ] = loaded - > name ;
2018-06-26 09:31:01 +00:00
}
2017-10-30 17:41:50 +00:00
}
2018-07-31 13:09:57 +00:00
// 4) Load the project config values (the per extruder wipe matrix etc).
this - > project_config . apply_only ( config , s_project_options ) ;
2019-12-17 12:16:28 +00:00
2018-12-03 12:14:28 +00:00
break ;
}
case ptSLA :
load_preset ( this - > sla_prints , 0 , " sla_print_settings_id " ) ;
load_preset ( this - > sla_materials , 1 , " sla_material_settings_id " ) ;
load_preset ( this - > printers , 2 , " printer_settings_id " ) ;
break ;
2019-09-03 08:27:16 +00:00
default : break ;
2018-07-31 13:09:57 +00:00
}
2018-03-14 10:54:11 +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
this - > update_compatible ( PresetSelectCompatibleType : : Never ) ;
2017-10-30 17:41:50 +00:00
}
2017-11-01 18:30:05 +00:00
// Load the active configuration of a config bundle from a boost property_tree. This is a private method called from load_config_file.
void PresetBundle : : load_config_file_config_bundle ( const std : : string & path , const boost : : property_tree : : ptree & tree )
{
// 1) Load the config bundle into a temp data.
PresetBundle tmp_bundle ;
2017-12-19 18:51:22 +00:00
// Load the config bundle, don't save the loaded presets to user profile directory.
tmp_bundle . load_configbundle ( path , 0 ) ;
2017-11-28 10:57:33 +00:00
std : : string bundle_name = std : : string ( " - " ) + boost : : filesystem : : path ( path ) . filename ( ) . string ( ) ;
2017-11-01 18:30:05 +00:00
// 2) Extract active configs from the config bundle, copy them and activate them in this bundle.
2017-11-28 10:57:33 +00:00
auto load_one = [ this , & path , & bundle_name ] ( PresetCollection & collection_dst , PresetCollection & collection_src , const std : : string & preset_name_src , bool activate ) - > std : : string {
Preset * preset_src = collection_src . find_preset ( preset_name_src , false ) ;
Preset * preset_dst = collection_dst . find_preset ( preset_name_src , false ) ;
assert ( preset_src ! = nullptr ) ;
std : : string preset_name_dst ;
if ( preset_dst ! = nullptr & & preset_dst - > is_default ) {
// No need to copy a default preset, it always exists in collection_dst.
if ( activate )
collection_dst . select_preset ( 0 ) ;
return preset_name_src ;
} else if ( preset_dst ! = nullptr & & preset_src - > config = = preset_dst - > config ) {
2017-11-01 18:30:05 +00:00
// Don't save as the config exists in the current bundle and its content is the same.
2017-11-28 10:57:33 +00:00
return preset_name_src ;
2017-11-01 18:30:05 +00:00
} else {
// Generate a new unique name.
2017-11-28 10:57:33 +00:00
preset_name_dst = preset_name_src + bundle_name ;
Preset * preset_dup = nullptr ;
for ( size_t i = 1 ; ( preset_dup = collection_dst . find_preset ( preset_name_dst , false ) ) ! = nullptr ; + + i ) {
if ( preset_src - > config = = preset_dup - > config )
// The preset has been already copied into collection_dst.
return preset_name_dst ;
// Try to generate another name.
char buf [ 64 ] ;
2019-06-10 17:45:38 +00:00
sprintf ( buf , " (%d) " , ( int ) i ) ;
2017-11-28 10:57:33 +00:00
preset_name_dst = preset_name_src + buf + bundle_name ;
}
2017-11-01 18:30:05 +00:00
}
2017-11-28 10:57:33 +00:00
assert ( ! preset_name_dst . empty ( ) ) ;
// Save preset_src->config into collection_dst under preset_name_dst.
2017-12-01 17:55:57 +00:00
// The "compatible_printers" field should not have been exported into a config.ini or a G-code anyway,
// but some of the alpha versions of Slic3r did.
ConfigOption * opt_compatible = preset_src - > config . optptr ( " compatible_printers " ) ;
if ( opt_compatible ! = nullptr ) {
assert ( opt_compatible - > type ( ) = = coStrings ) ;
if ( opt_compatible - > type ( ) = = coStrings )
static_cast < ConfigOptionStrings * > ( opt_compatible ) - > values . clear ( ) ;
}
2017-11-28 10:57:33 +00:00
collection_dst . load_preset ( path , preset_name_dst , std : : move ( preset_src - > config ) , activate ) . is_external = true ;
return preset_name_dst ;
} ;
2019-05-22 09:31:36 +00:00
load_one ( this - > prints , tmp_bundle . prints , tmp_bundle . prints . get_selected_preset_name ( ) , true ) ;
load_one ( this - > sla_prints , tmp_bundle . sla_prints , tmp_bundle . sla_prints . get_selected_preset_name ( ) , true ) ;
load_one ( this - > filaments , tmp_bundle . filaments , tmp_bundle . filaments . get_selected_preset_name ( ) , true ) ;
load_one ( this - > sla_materials , tmp_bundle . sla_materials , tmp_bundle . sla_materials . get_selected_preset_name ( ) , true ) ;
load_one ( this - > printers , tmp_bundle . printers , tmp_bundle . printers . get_selected_preset_name ( ) , true ) ;
2017-11-28 10:57:33 +00:00
this - > update_multi_material_filament_presets ( ) ;
for ( size_t i = 1 ; i < std : : min ( tmp_bundle . filament_presets . size ( ) , this - > filament_presets . size ( ) ) ; + + i )
this - > filament_presets [ i ] = load_one ( this - > filaments , tmp_bundle . filaments , tmp_bundle . filament_presets [ i ] , false ) ;
2017-12-20 10:28:16 +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
this - > update_compatible ( PresetSelectCompatibleType : : Never ) ;
2017-11-01 18:30:05 +00:00
}
2018-03-07 15:48:28 +00:00
// Process the Config Bundle loaded as a Boost property tree.
// For each print, filament and printer preset (group defined by group_name), apply the inherited presets.
// The presets starting with '*' are considered non-terminal and they are
// removed through the flattening process by this function.
// This function will never fail, but it will produce error messages through boost::log.
2019-01-08 09:52:11 +00:00
// system_profiles will not be flattened, and they will be kept inside the "inherits" field
static void flatten_configbundle_hierarchy ( boost : : property_tree : : ptree & tree , const std : : string & group_name , const std : : vector < std : : string > & system_profiles )
2018-03-07 15:48:28 +00:00
{
namespace pt = boost : : property_tree ;
// 1) For the group given by group_name, initialize the presets.
struct Prst {
Prst ( const std : : string & name , pt : : ptree * node ) : name ( name ) , node ( node ) { }
// Name of this preset. If the name starts with '*', it is an intermediate preset,
// which will not make it into the result.
const std : : string name ;
// Link to the source boost property tree node, owned by tree.
pt : : ptree * node ;
// Link to the presets, from which this preset inherits.
std : : vector < Prst * > inherits ;
// Link to the presets, for which this preset is a direct parent.
std : : vector < Prst * > parent_of ;
// When running the Kahn's Topological sorting algorithm, this counter is decreased from inherits.size() to zero.
// A cycle is indicated, if the number does not drop to zero after the Kahn's algorithm finishes.
size_t num_incoming_edges_left = 0 ;
// Sorting by the name, to be used when inserted into std::set.
bool operator = = ( const Prst & rhs ) const { return this - > name = = rhs . name ; }
bool operator < ( const Prst & rhs ) const { return this - > name < rhs . name ; }
} ;
// Find the presets, store them into a std::map, addressed by their names.
std : : set < Prst > presets ;
std : : string group_name_preset = group_name + " : " ;
for ( auto & section : tree )
if ( boost : : starts_with ( section . first , group_name_preset ) & & section . first . size ( ) > group_name_preset . size ( ) )
presets . emplace ( section . first . substr ( group_name_preset . size ( ) ) , & section . second ) ;
// Fill in the "inherits" and "parent_of" members, report invalid inheritance fields.
for ( const Prst & prst : presets ) {
// Parse the list of comma separated values, possibly enclosed in quotes.
std : : vector < std : : string > inherits_names ;
2019-01-08 09:52:11 +00:00
std : : vector < std : : string > inherits_system ;
2018-03-07 15:48:28 +00:00
if ( Slic3r : : unescape_strings_cstyle ( prst . node - > get < std : : string > ( " inherits " , " " ) , inherits_names ) ) {
// Resolve the inheritance by name.
std : : vector < Prst * > & inherits_nodes = const_cast < Prst & > ( prst ) . inherits ;
for ( const std : : string & node_name : inherits_names ) {
2019-01-08 09:52:11 +00:00
auto it_system = std : : lower_bound ( system_profiles . begin ( ) , system_profiles . end ( ) , node_name ) ;
if ( it_system ! = system_profiles . end ( ) & & * it_system = = node_name ) {
// Loading a user config budnle, this preset is derived from a system profile.
inherits_system . emplace_back ( node_name ) ;
} else {
auto it = presets . find ( Prst ( node_name , nullptr ) ) ;
if ( it = = presets . end ( ) )
BOOST_LOG_TRIVIAL ( error ) < < " flatten_configbundle_hierarchy: The preset " < < prst . name < < " inherits an unknown preset \" " < < node_name < < " \" " ;
else {
inherits_nodes . emplace_back ( const_cast < Prst * > ( & ( * it ) ) ) ;
inherits_nodes . back ( ) - > parent_of . emplace_back ( const_cast < Prst * > ( & prst ) ) ;
}
2018-03-07 15:48:28 +00:00
}
}
} else {
BOOST_LOG_TRIVIAL ( error ) < < " flatten_configbundle_hierarchy: The preset " < < prst . name < < " has an invalid \" inherits \" field " ;
}
2019-01-08 09:52:11 +00:00
// Remove the "inherits" key, it has no meaning outside of the config bundle.
2018-03-07 15:48:28 +00:00
const_cast < pt : : ptree * > ( prst . node ) - > erase ( " inherits " ) ;
2019-01-08 09:52:11 +00:00
if ( ! inherits_system . empty ( ) ) {
// Loaded a user config bundle, where a profile inherits a system profile.
// User profile should be derived from a single system profile only.
assert ( inherits_system . size ( ) = = 1 ) ;
if ( inherits_system . size ( ) > 1 )
BOOST_LOG_TRIVIAL ( error ) < < " flatten_configbundle_hierarchy: The preset " < < prst . name < < " inherits from more than single system preset " ;
prst . node - > put ( " inherits " , Slic3r : : escape_string_cstyle ( inherits_system . front ( ) ) ) ;
}
2018-03-07 15:48:28 +00:00
}
// 2) Create a linear ordering for the directed acyclic graph of preset inheritance.
// https://en.wikipedia.org/wiki/Topological_sorting
// Kahn's algorithm.
std : : vector < Prst * > sorted ;
{
// Initialize S with the set of all nodes with no incoming edge.
std : : deque < Prst * > S ;
for ( const Prst & prst : presets )
if ( prst . inherits . empty ( ) )
S . emplace_back ( const_cast < Prst * > ( & prst ) ) ;
else
const_cast < Prst * > ( & prst ) - > num_incoming_edges_left = prst . inherits . size ( ) ;
while ( ! S . empty ( ) ) {
Prst * n = S . front ( ) ;
S . pop_front ( ) ;
sorted . emplace_back ( n ) ;
for ( Prst * m : n - > parent_of ) {
assert ( m - > num_incoming_edges_left > 0 ) ;
if ( - - m - > num_incoming_edges_left = = 0 ) {
// We have visited all parents of m.
S . emplace_back ( m ) ;
}
}
}
if ( sorted . size ( ) < presets . size ( ) ) {
for ( const Prst & prst : presets )
if ( prst . num_incoming_edges_left )
BOOST_LOG_TRIVIAL ( error ) < < " flatten_configbundle_hierarchy: The preset " < < prst . name < < " has cyclic dependencies " ;
}
}
// Apply the dependencies in their topological ordering.
for ( Prst * prst : sorted ) {
// Merge the preset nodes in their order of application.
// Iterate in a reverse order, so the last change will be placed first in merged.
for ( auto it_inherits = prst - > inherits . rbegin ( ) ; it_inherits ! = prst - > inherits . rend ( ) ; + + it_inherits )
for ( auto it = ( * it_inherits ) - > node - > begin ( ) ; it ! = ( * it_inherits ) - > node - > end ( ) ; + + it )
2020-03-15 07:38:17 +00:00
if ( it - > first = = " renamed_from " ) {
// Don't inherit "renamed_from" flag, it does not make sense. The "renamed_from" flag only makes sense for a concrete preset.
if ( boost : : starts_with ( ( * it_inherits ) - > name , " * " ) )
BOOST_LOG_TRIVIAL ( error ) < < boost : : format ( " Nonpublic intermediate preset %1% contains a \" renamed_from \" field, which is ignored " ) % ( * it_inherits ) - > name ;
} else if ( prst - > node - > find ( it - > first ) = = prst - > node - > not_found ( ) )
2018-03-07 15:48:28 +00:00
prst - > node - > add_child ( it - > first , it - > second ) ;
}
// Remove the "internal" presets from the ptree. These presets are marked with '*'.
group_name_preset + = ' * ' ;
for ( auto it_section = tree . begin ( ) ; it_section ! = tree . end ( ) ; ) {
if ( boost : : starts_with ( it_section - > first , group_name_preset ) & & it_section - > first . size ( ) > group_name_preset . size ( ) )
// Remove the "internal" preset from the ptree.
it_section = tree . erase ( it_section ) ;
else
// Keep the preset.
+ + it_section ;
}
}
2019-01-08 09:52:11 +00:00
// preset_bundle is set when loading user config bundles, which must not overwrite the system profiles.
static void flatten_configbundle_hierarchy ( boost : : property_tree : : ptree & tree , const PresetBundle * preset_bundle )
2018-03-07 15:48:28 +00:00
{
2019-01-08 09:52:11 +00:00
flatten_configbundle_hierarchy ( tree , " print " , preset_bundle ? preset_bundle - > prints . system_preset_names ( ) : std : : vector < std : : string > ( ) ) ;
flatten_configbundle_hierarchy ( tree , " filament " , preset_bundle ? preset_bundle - > filaments . system_preset_names ( ) : std : : vector < std : : string > ( ) ) ;
flatten_configbundle_hierarchy ( tree , " sla_print " , preset_bundle ? preset_bundle - > sla_prints . system_preset_names ( ) : std : : vector < std : : string > ( ) ) ;
flatten_configbundle_hierarchy ( tree , " sla_material " , preset_bundle ? preset_bundle - > sla_materials . system_preset_names ( ) : std : : vector < std : : string > ( ) ) ;
flatten_configbundle_hierarchy ( tree , " printer " , preset_bundle ? preset_bundle - > printers . system_preset_names ( ) : std : : vector < std : : string > ( ) ) ;
2018-03-07 15:48:28 +00:00
}
2017-10-30 17:41:50 +00:00
// Load a config bundle file, into presets and store the loaded presets into separate files
// of the local configuration directory.
2017-12-19 18:51:22 +00:00
size_t PresetBundle : : load_configbundle ( const std : : string & path , unsigned int flags )
2017-10-30 17:41:50 +00:00
{
2018-03-09 15:37:33 +00:00
if ( flags & ( LOAD_CFGBNDLE_RESET_USER_PROFILE | LOAD_CFGBNDLE_SYSTEM ) )
// Reset this bundle, delete user profile files if LOAD_CFGBNDLE_SAVE.
2017-12-19 18:51:22 +00:00
this - > reset ( flags & LOAD_CFGBNDLE_SAVE ) ;
2017-10-30 17:41:50 +00:00
// 1) Read the complete config file into a boost::property_tree.
namespace pt = boost : : property_tree ;
pt : : ptree tree ;
boost : : nowide : : ifstream ifs ( path ) ;
pt : : read_ini ( ifs , tree ) ;
2018-03-09 15:37:33 +00:00
const VendorProfile * vendor_profile = nullptr ;
2018-03-13 11:39:57 +00:00
if ( flags & ( LOAD_CFGBNDLE_SYSTEM | LOAD_CFGBUNDLE_VENDOR_ONLY ) ) {
2018-04-12 18:04:48 +00:00
auto vp = VendorProfile : : from_ini ( tree , path ) ;
2020-03-07 15:31:14 +00:00
if ( vp . models . size ( ) = = 0 ) {
BOOST_LOG_TRIVIAL ( error ) < < boost : : format ( " Vendor bundle: `%1%`: No printer model defined. " ) % path ;
2018-03-09 15:37:33 +00:00
return 0 ;
2020-03-07 15:31:14 +00:00
} else if ( vp . num_variants ( ) = = 0 ) {
BOOST_LOG_TRIVIAL ( error ) < < boost : : format ( " Vendor bundle: `%1%`: No printer variant defined " ) % path ;
2018-03-09 15:37:33 +00:00
return 0 ;
2020-03-07 15:31:14 +00:00
}
2019-06-17 14:39:22 +00:00
vendor_profile = & this - > vendors . insert ( { vp . id , vp } ) . first - > second ;
2018-03-09 15:37:33 +00:00
}
2019-06-17 14:39:22 +00:00
2018-03-13 11:39:57 +00:00
if ( flags & LOAD_CFGBUNDLE_VENDOR_ONLY ) {
return 0 ;
}
// 1.5) Flatten the config bundle by applying the inheritance rules. Internal profiles (with names starting with '*') are removed.
2019-01-08 09:52:11 +00:00
// If loading a user config bundle, do not flatten with the system profiles, but keep the "inherits" flag intact.
flatten_configbundle_hierarchy ( tree , ( ( flags & LOAD_CFGBNDLE_SYSTEM ) = = 0 ) ? this : nullptr ) ;
2018-03-09 15:37:33 +00:00
2017-10-30 17:41:50 +00:00
// 2) Parse the property_tree, extract the active preset names and the profiles, save them into local config files.
2018-05-16 14:34:07 +00:00
// Parse the obsolete preset names, to be deleted when upgrading from the old configuration structure.
2017-10-30 17:41:50 +00:00
std : : vector < std : : string > loaded_prints ;
std : : vector < std : : string > loaded_filaments ;
2018-11-16 16:36:23 +00:00
std : : vector < std : : string > loaded_sla_prints ;
2018-07-31 13:09:57 +00:00
std : : vector < std : : string > loaded_sla_materials ;
2017-10-30 17:41:50 +00:00
std : : vector < std : : string > loaded_printers ;
std : : string active_print ;
std : : vector < std : : string > active_filaments ;
2018-11-16 16:36:23 +00:00
std : : string active_sla_print ;
2018-07-31 13:09:57 +00:00
std : : string active_sla_material ;
2017-10-30 17:41:50 +00:00
std : : string active_printer ;
size_t presets_loaded = 0 ;
for ( const auto & section : tree ) {
PresetCollection * presets = nullptr ;
std : : vector < std : : string > * loaded = nullptr ;
std : : string preset_name ;
if ( boost : : starts_with ( section . first , " print: " ) ) {
2018-03-09 15:37:33 +00:00
presets = & this - > prints ;
2017-10-30 17:41:50 +00:00
loaded = & loaded_prints ;
preset_name = section . first . substr ( 6 ) ;
} else if ( boost : : starts_with ( section . first , " filament: " ) ) {
2018-03-09 15:37:33 +00:00
presets = & this - > filaments ;
2017-10-30 17:41:50 +00:00
loaded = & loaded_filaments ;
preset_name = section . first . substr ( 9 ) ;
2018-11-16 16:36:23 +00:00
} else if ( boost : : starts_with ( section . first , " sla_print: " ) ) {
presets = & this - > sla_prints ;
loaded = & loaded_sla_prints ;
2018-11-19 10:10:22 +00:00
preset_name = section . first . substr ( 10 ) ;
2018-07-31 13:09:57 +00:00
} else if ( boost : : starts_with ( section . first , " sla_material: " ) ) {
presets = & this - > sla_materials ;
loaded = & loaded_sla_materials ;
2018-10-31 15:22:36 +00:00
preset_name = section . first . substr ( 13 ) ;
2017-10-30 17:41:50 +00:00
} else if ( boost : : starts_with ( section . first , " printer: " ) ) {
2018-03-09 15:37:33 +00:00
presets = & this - > printers ;
2017-10-30 17:41:50 +00:00
loaded = & loaded_printers ;
preset_name = section . first . substr ( 8 ) ;
} else if ( section . first = = " presets " ) {
// Load the names of the active presets.
for ( auto & kvp : section . second ) {
if ( kvp . first = = " print " ) {
active_print = kvp . second . data ( ) ;
} else if ( boost : : starts_with ( kvp . first , " filament " ) ) {
int idx = 0 ;
if ( kvp . first = = " filament " | | sscanf ( kvp . first . c_str ( ) , " filament_%d " , & idx ) = = 1 ) {
if ( int ( active_filaments . size ( ) ) < = idx )
active_filaments . resize ( idx + 1 , std : : string ( ) ) ;
active_filaments [ idx ] = kvp . second . data ( ) ;
}
2018-11-16 16:36:23 +00:00
} else if ( kvp . first = = " sla_print " ) {
active_sla_print = kvp . second . data ( ) ;
2018-07-31 13:09:57 +00:00
} else if ( kvp . first = = " sla_material " ) {
active_sla_material = kvp . second . data ( ) ;
2017-10-30 17:41:50 +00:00
} else if ( kvp . first = = " printer " ) {
active_printer = kvp . second . data ( ) ;
}
}
2018-05-16 14:34:07 +00:00
} else if ( section . first = = " obsolete_presets " ) {
// Parse the names of obsolete presets. These presets will be deleted from user's
// profile directory on installation of this vendor preset.
for ( auto & kvp : section . second ) {
std : : vector < std : : string > * dst = nullptr ;
if ( kvp . first = = " print " )
dst = & this - > obsolete_presets . prints ;
else if ( kvp . first = = " filament " )
dst = & this - > obsolete_presets . filaments ;
2018-11-16 16:36:23 +00:00
else if ( kvp . first = = " sla_print " )
dst = & this - > obsolete_presets . sla_prints ;
2018-07-31 13:09:57 +00:00
else if ( kvp . first = = " sla_material " )
dst = & this - > obsolete_presets . sla_materials ;
2018-05-16 14:34:07 +00:00
else if ( kvp . first = = " printer " )
dst = & this - > obsolete_presets . printers ;
if ( dst )
unescape_strings_cstyle ( kvp . second . data ( ) , * dst ) ;
}
2017-10-30 17:41:50 +00:00
} else if ( section . first = = " settings " ) {
// Load the settings.
for ( auto & kvp : section . second ) {
if ( kvp . first = = " autocenter " ) {
}
}
} else
// Ignore an unknown section.
continue ;
if ( presets ! = nullptr ) {
// Load the print, filament or printer preset.
2018-10-31 15:22:36 +00:00
const DynamicPrintConfig * default_config = nullptr ;
DynamicPrintConfig config ;
2020-01-02 15:40:32 +00:00
std : : string alias_name ;
std : : vector < std : : string > renamed_from ;
auto parse_config_section = [ & section , & alias_name , & renamed_from , & path ] ( DynamicPrintConfig & config ) {
for ( auto & kvp : section . second ) {
if ( kvp . first = = " alias " )
alias_name = kvp . second . data ( ) ;
else if ( kvp . first = = " renamed_from " ) {
if ( ! unescape_strings_cstyle ( kvp . second . data ( ) , renamed_from ) ) {
BOOST_LOG_TRIVIAL ( error ) < < " Error in a Vendor Config Bundle \" " < < path < < " \" : The preset \" " < <
section . first < < " \" contains invalid \" renamed_from \" key, which is being ignored. " ;
}
}
config . set_deserialize ( kvp . first , kvp . second . data ( ) ) ;
}
} ;
2018-10-31 15:22:36 +00:00
if ( presets = = & this - > printers ) {
// Select the default config based on the printer_technology field extracted from kvp.
DynamicPrintConfig config_src ;
2020-01-02 15:40:32 +00:00
parse_config_section ( config_src ) ;
2018-10-31 15:22:36 +00:00
default_config = & presets - > default_preset_for ( config_src ) . config ;
config = * default_config ;
config . apply ( config_src ) ;
} else {
default_config = & presets - > default_preset ( ) . config ;
config = * default_config ;
2020-01-02 15:40:32 +00:00
parse_config_section ( config ) ;
2018-10-31 15:22:36 +00:00
}
2017-11-02 15:21:34 +00:00
Preset : : normalize ( config ) ;
2018-05-22 12:17:27 +00:00
// Report configuration fields, which are misplaced into a wrong group.
2018-10-31 15:22:36 +00:00
std : : string incorrect_keys = Preset : : remove_invalid_keys ( config , * default_config ) ;
2018-05-22 12:17:27 +00:00
if ( ! incorrect_keys . empty ( ) )
BOOST_LOG_TRIVIAL ( error ) < < " Error in a Vendor Config Bundle \" " < < path < < " \" : The printer preset \" " < <
section . first < < " \" contains the following incorrect keys: " < < incorrect_keys < < " , which were removed " ;
2018-03-09 15:37:33 +00:00
if ( ( flags & LOAD_CFGBNDLE_SYSTEM ) & & presets = = & printers ) {
// Filter out printer presets, which are not mentioned in the vendor profile.
// These presets are considered not installed.
auto printer_model = config . opt_string ( " printer_model " ) ;
if ( printer_model . empty ( ) ) {
BOOST_LOG_TRIVIAL ( error ) < < " Error in a Vendor Config Bundle \" " < < path < < " \" : The printer preset \" " < <
section . first < < " \" defines no printer model, it will be ignored. " ;
continue ;
}
auto printer_variant = config . opt_string ( " printer_variant " ) ;
if ( printer_variant . empty ( ) ) {
BOOST_LOG_TRIVIAL ( error ) < < " Error in a Vendor Config Bundle \" " < < path < < " \" : The printer preset \" " < <
section . first < < " \" defines no printer variant, it will be ignored. " ;
continue ;
}
2018-03-13 11:39:57 +00:00
auto it_model = std : : find_if ( vendor_profile - > models . cbegin ( ) , vendor_profile - > models . cend ( ) ,
[ & ] ( const VendorProfile : : PrinterModel & m ) { return m . id = = printer_model ; }
) ;
2018-03-09 15:37:33 +00:00
if ( it_model = = vendor_profile - > models . end ( ) ) {
BOOST_LOG_TRIVIAL ( error ) < < " Error in a Vendor Config Bundle \" " < < path < < " \" : The printer preset \" " < <
section . first < < " \" defines invalid printer model \" " < < printer_model < < " \" , it will be ignored. " ;
continue ;
}
auto it_variant = it_model - > variant ( printer_variant ) ;
if ( it_variant = = nullptr ) {
BOOST_LOG_TRIVIAL ( error ) < < " Error in a Vendor Config Bundle \" " < < path < < " \" : The printer preset \" " < <
section . first < < " \" defines invalid printer variant \" " < < printer_variant < < " \" , it will be ignored. " ;
continue ;
}
const Preset * preset_existing = presets - > find_preset ( section . first , false ) ;
if ( preset_existing ! = nullptr ) {
BOOST_LOG_TRIVIAL ( error ) < < " Error in a Vendor Config Bundle \" " < < path < < " \" : The printer preset \" " < <
section . first < < " \" has already been loaded from another Confing Bundle. " ;
continue ;
}
2019-01-03 15:36:45 +00:00
} else if ( ( flags & LOAD_CFGBNDLE_SYSTEM ) = = 0 ) {
// This is a user config bundle.
const Preset * existing = presets - > find_preset ( preset_name , false ) ;
if ( existing ! = nullptr ) {
if ( existing - > is_system ) {
assert ( existing - > vendor ! = nullptr ) ;
BOOST_LOG_TRIVIAL ( error ) < < " Error in a user provided Config Bundle \" " < < path < < " \" : The " < < presets - > name ( ) < < " preset \" " < <
existing - > name < < " \" is a system preset of vendor " < < existing - > vendor - > name < < " and it will be ignored. " ;
continue ;
} else {
assert ( existing - > vendor = = nullptr ) ;
BOOST_LOG_TRIVIAL ( trace ) < < " A " < < presets - > name ( ) < < " preset \" " < < existing - > name < < " \" was overwritten with a preset from user Config Bundle \" " < < path < < " \" " ;
}
} else {
BOOST_LOG_TRIVIAL ( trace ) < < " A new " < < presets - > name ( ) < < " preset \" " < < preset_name < < " \" was imported from user Config Bundle \" " < < path < < " \" " ;
}
2018-03-09 15:37:33 +00:00
}
2017-12-10 21:11:00 +00:00
// Decide a full path to this .ini file.
auto file_name = boost : : algorithm : : iends_with ( preset_name , " .ini " ) ? preset_name : preset_name + " .ini " ;
2017-12-14 08:40:45 +00:00
auto file_path = ( boost : : filesystem : : path ( data_dir ( ) )
# ifdef SLIC3R_PROFILE_USE_PRESETS_SUBDIR
// Store the print/filament/printer presets into a "presets" directory.
/ " presets "
# else
// Store the print/filament/printer presets at the same location as the upstream Slic3r.
# endif
2019-02-03 19:17:55 +00:00
/ presets - > section_name ( ) / file_name ) . make_preferred ( ) ;
2017-10-30 17:41:50 +00:00
// Load the preset into the list of presets, save it to disk.
2017-12-19 18:51:22 +00:00
Preset & loaded = presets - > load_preset ( file_path . string ( ) , preset_name , std : : move ( config ) , false ) ;
if ( flags & LOAD_CFGBNDLE_SAVE )
loaded . save ( ) ;
2018-03-09 15:37:33 +00:00
if ( flags & LOAD_CFGBNDLE_SYSTEM ) {
loaded . is_system = true ;
loaded . vendor = vendor_profile ;
}
2019-11-25 09:40:36 +00:00
2020-01-02 15:40:32 +00:00
// Derive the profile logical name aka alias from the preset name if the alias was not stated explicitely.
if ( alias_name . empty ( ) ) {
2020-03-03 13:52:16 +00:00
size_t end_pos = preset_name . find_first_of ( " @ " ) ;
2020-01-02 15:40:32 +00:00
if ( end_pos ! = std : : string : : npos ) {
alias_name = preset_name . substr ( 0 , end_pos ) ;
if ( renamed_from . empty ( ) )
// Add the preset name with the '@' character removed into the "renamed_from" list.
renamed_from . emplace_back ( alias_name + preset_name . substr ( end_pos + 1 ) ) ;
boost : : trim_right ( alias_name ) ;
}
}
if ( alias_name . empty ( ) )
loaded . alias = preset_name ;
else
loaded . alias = std : : move ( alias_name ) ;
loaded . renamed_from = std : : move ( renamed_from ) ;
2019-11-25 09:40:36 +00:00
2017-10-30 17:41:50 +00:00
+ + presets_loaded ;
}
}
// 3) Activate the presets.
2018-03-09 15:37:33 +00:00
if ( ( flags & LOAD_CFGBNDLE_SYSTEM ) = = 0 ) {
if ( ! active_print . empty ( ) )
prints . select_preset_by_name ( active_print , true ) ;
2018-11-16 16:36:23 +00:00
if ( ! active_sla_print . empty ( ) )
sla_materials . select_preset_by_name ( active_sla_print , true ) ;
2018-07-31 13:09:57 +00:00
if ( ! active_sla_material . empty ( ) )
sla_materials . select_preset_by_name ( active_sla_material , true ) ;
2018-03-09 15:37:33 +00:00
if ( ! active_printer . empty ( ) )
printers . select_preset_by_name ( active_printer , true ) ;
// Activate the first filament preset.
if ( ! active_filaments . empty ( ) & & ! active_filaments . front ( ) . empty ( ) )
filaments . select_preset_by_name ( active_filaments . front ( ) , true ) ;
this - > update_multi_material_filament_presets ( ) ;
for ( size_t i = 0 ; i < std : : min ( this - > filament_presets . size ( ) , active_filaments . size ( ) ) ; + + i )
this - > filament_presets [ i ] = filaments . find_preset ( active_filaments [ i ] , true ) - > name ;
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
this - > update_compatible ( PresetSelectCompatibleType : : Never ) ;
2018-03-09 15:37:33 +00:00
}
2017-12-20 10:28:16 +00:00
2017-10-30 17:41:50 +00:00
return presets_loaded ;
}
void PresetBundle : : update_multi_material_filament_presets ( )
{
2018-08-01 09:09:51 +00:00
if ( printers . get_edited_preset ( ) . printer_technology ( ) ! = ptFFF )
return ;
2017-10-30 17:41:50 +00:00
// Verify and select the filament presets.
2017-11-01 18:30:05 +00:00
auto * nozzle_diameter = static_cast < const ConfigOptionFloats * > ( printers . get_edited_preset ( ) . config . option ( " nozzle_diameter " ) ) ;
2017-10-30 17:41:50 +00:00
size_t num_extruders = nozzle_diameter - > values . size ( ) ;
// Verify validity of the current filament presets.
for ( size_t i = 0 ; i < std : : min ( this - > filament_presets . size ( ) , num_extruders ) ; + + i )
this - > filament_presets [ i ] = this - > filaments . find_preset ( this - > filament_presets [ i ] , true ) - > name ;
// Append the rest of filament presets.
2018-07-02 18:25:37 +00:00
this - > filament_presets . resize ( num_extruders , this - > filament_presets . empty ( ) ? this - > filaments . first_visible ( ) . name : this - > filament_presets . back ( ) ) ;
2018-03-21 08:36:27 +00:00
// Now verify if wiping_volumes_matrix has proper size (it is used to deduce number of extruders in wipe tower generator):
2018-04-04 08:18:26 +00:00
std : : vector < double > old_matrix = this - > project_config . option < ConfigOptionFloats > ( " wiping_volumes_matrix " ) - > values ;
2019-09-06 15:46:55 +00:00
size_t old_number_of_extruders = size_t ( sqrt ( old_matrix . size ( ) ) + EPSILON ) ;
2018-03-21 09:20:36 +00:00
if ( num_extruders ! = old_number_of_extruders ) {
// First verify if purging volumes presets for each extruder matches number of extruders
2018-04-04 08:18:26 +00:00
std : : vector < double > & extruders = this - > project_config . option < ConfigOptionFloats > ( " wiping_volumes_extruders " ) - > values ;
2018-03-21 08:36:27 +00:00
while ( extruders . size ( ) < 2 * num_extruders ) {
2018-03-21 09:20:36 +00:00
extruders . push_back ( extruders . size ( ) > 1 ? extruders [ 0 ] : 50. ) ; // copy the values from the first extruder
extruders . push_back ( extruders . size ( ) > 1 ? extruders [ 1 ] : 50. ) ;
2018-03-21 08:36:27 +00:00
}
while ( extruders . size ( ) > 2 * num_extruders ) {
extruders . pop_back ( ) ;
extruders . pop_back ( ) ;
}
2018-03-21 09:20:36 +00:00
2018-03-21 08:36:27 +00:00
std : : vector < double > new_matrix ;
for ( unsigned int i = 0 ; i < num_extruders ; + + i )
for ( unsigned int j = 0 ; j < num_extruders ; + + j ) {
// append the value for this pair from the old matrix (if it's there):
if ( i < old_number_of_extruders & & j < old_number_of_extruders )
new_matrix . push_back ( old_matrix [ i * old_number_of_extruders + j ] ) ;
else
new_matrix . push_back ( i = = j ? 0. : extruders [ 2 * i ] + extruders [ 2 * j + 1 ] ) ; // so it matches new extruder volumes
}
2018-04-04 08:18:26 +00:00
this - > project_config . option < ConfigOptionFloats > ( " wiping_volumes_matrix " ) - > values = new_matrix ;
2018-03-21 08:36:27 +00:00
}
2017-10-30 17:41:50 +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
void PresetBundle : : update_compatible ( PresetSelectCompatibleType select_other_print_if_incompatible , PresetSelectCompatibleType select_other_filament_if_incompatible )
2017-11-10 16:27:05 +00:00
{
2019-12-05 13:48:11 +00:00
const Preset & printer_preset = this - > printers . get_edited_preset ( ) ;
const PresetWithVendorProfile printer_preset_with_vendor_profile = this - > printers . get_preset_with_vendor_profile ( printer_preset ) ;
2018-08-01 09:09:51 +00:00
2019-03-13 14:44:50 +00:00
switch ( printer_preset . printer_technology ( ) ) {
2018-08-01 09:09:51 +00:00
case ptFFF :
{
2018-12-03 12:14:28 +00:00
assert ( printer_preset . config . has ( " default_print_profile " ) ) ;
assert ( printer_preset . config . has ( " default_filament_profile " ) ) ;
const std : : string & prefered_print_profile = printer_preset . config . opt_string ( " default_print_profile " ) ;
2018-08-01 09:09:51 +00:00
const std : : vector < std : : string > & prefered_filament_profiles = printer_preset . config . option < ConfigOptionStrings > ( " default_filament_profile " ) - > values ;
prefered_print_profile . empty ( ) ?
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
this - > prints . update_compatible ( printer_preset_with_vendor_profile , nullptr , select_other_print_if_incompatible ) :
this - > prints . update_compatible ( printer_preset_with_vendor_profile , nullptr , select_other_print_if_incompatible ,
2018-10-31 11:56:08 +00:00
[ & prefered_print_profile ] ( const std : : string & profile_name ) { return profile_name = = prefered_print_profile ; } ) ;
2019-12-06 15:22:20 +00:00
const PresetWithVendorProfile print_preset_with_vendor_profile = this - > prints . get_edited_preset_with_vendor_profile ( ) ;
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
// Remember whether the filament profiles were compatible before updating the filament compatibility.
std : : vector < char > filament_preset_was_compatible ( this - > filament_presets . size ( ) , false ) ;
for ( size_t idx = 0 ; idx < this - > filament_presets . size ( ) ; + + idx ) {
std : : string & filament_name = this - > filament_presets [ idx ] ;
Preset * preset = this - > filaments . find_preset ( filament_name , false ) ;
filament_preset_was_compatible [ idx ] = preset ! = nullptr & & preset - > is_compatible ;
}
2018-08-01 09:09:51 +00:00
prefered_filament_profiles . empty ( ) ?
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
this - > filaments . update_compatible ( printer_preset_with_vendor_profile , & print_preset_with_vendor_profile , select_other_filament_if_incompatible ) :
this - > filaments . update_compatible ( printer_preset_with_vendor_profile , & print_preset_with_vendor_profile , select_other_filament_if_incompatible ,
2018-08-01 09:09:51 +00:00
[ & prefered_filament_profiles ] ( const std : : string & profile_name )
{ return std : : find ( prefered_filament_profiles . begin ( ) , prefered_filament_profiles . end ( ) , profile_name ) ! = prefered_filament_profiles . end ( ) ; } ) ;
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
if ( select_other_filament_if_incompatible ! = PresetSelectCompatibleType : : Never ) {
2018-08-01 09:09:51 +00:00
// Verify validity of the current filament presets.
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
if ( this - > filament_presets . size ( ) = = 1 ) {
if ( select_other_filament_if_incompatible = = PresetSelectCompatibleType : : Always | | filament_preset_was_compatible . front ( ) )
this - > filament_presets . front ( ) = this - > filaments . get_edited_preset ( ) . name ;
} else {
for ( size_t idx = 0 ; idx < this - > filament_presets . size ( ) ; + + idx ) {
2019-03-18 14:10:40 +00:00
std : : string & filament_name = this - > filament_presets [ idx ] ;
Preset * preset = this - > filaments . find_preset ( filament_name , false ) ;
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
if ( preset = = nullptr | | ( ! preset - > is_compatible & & ( select_other_filament_if_incompatible = = PresetSelectCompatibleType : : Always | | filament_preset_was_compatible [ idx ] ) ) ) {
2019-03-18 14:10:40 +00:00
// Pick a compatible profile. If there are prefered_filament_profiles, use them.
if ( prefered_filament_profiles . empty ( ) )
filament_name = this - > filaments . first_compatible ( ) . name ;
else {
const std : : string & preferred = ( idx < prefered_filament_profiles . size ( ) ) ?
prefered_filament_profiles [ idx ] : prefered_filament_profiles . front ( ) ;
filament_name = this - > filaments . first_compatible (
[ & preferred ] ( const std : : string & profile_name ) { return profile_name = = preferred ; } ) . name ;
}
2018-08-01 09:09:51 +00:00
}
2018-04-13 12:49:33 +00:00
}
}
2017-11-10 16:27:05 +00:00
}
2018-10-31 17:05:25 +00:00
break ;
2017-11-10 16:27:05 +00:00
}
2018-08-01 09:09:51 +00:00
case ptSLA :
{
2018-12-03 12:14:28 +00:00
assert ( printer_preset . config . has ( " default_sla_print_profile " ) ) ;
assert ( printer_preset . config . has ( " default_sla_material_profile " ) ) ;
2019-12-05 13:48:11 +00:00
const PresetWithVendorProfile sla_print_preset_with_vendor_profile = this - > sla_prints . get_edited_preset_with_vendor_profile ( ) ;
const std : : string & prefered_sla_print_profile = printer_preset . config . opt_string ( " default_sla_print_profile " ) ;
2018-12-03 12:14:28 +00:00
( prefered_sla_print_profile . empty ( ) ) ?
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
this - > sla_prints . update_compatible ( printer_preset_with_vendor_profile , nullptr , select_other_print_if_incompatible ) :
this - > sla_prints . update_compatible ( printer_preset_with_vendor_profile , nullptr , select_other_print_if_incompatible ,
2018-12-03 12:14:28 +00:00
[ & prefered_sla_print_profile ] ( const std : : string & profile_name ) { return profile_name = = prefered_sla_print_profile ; } ) ;
const std : : string & prefered_sla_material_profile = printer_preset . config . opt_string ( " default_sla_material_profile " ) ;
2018-10-31 15:22:36 +00:00
prefered_sla_material_profile . empty ( ) ?
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
this - > sla_materials . update_compatible ( printer_preset_with_vendor_profile , & sla_print_preset_with_vendor_profile , select_other_filament_if_incompatible ) :
this - > sla_materials . update_compatible ( printer_preset_with_vendor_profile , & sla_print_preset_with_vendor_profile , select_other_filament_if_incompatible ,
2018-10-31 15:25:55 +00:00
[ & prefered_sla_material_profile ] ( const std : : string & profile_name ) { return profile_name = = prefered_sla_material_profile ; } ) ;
2018-10-31 17:05:25 +00:00
break ;
}
2019-09-03 08:27:16 +00:00
default : break ;
2018-08-01 09:09:51 +00:00
}
2017-11-10 16:27:05 +00:00
}
2018-12-12 17:37:10 +00:00
void PresetBundle : : export_configbundle ( const std : : string & path , bool export_system_settings )
2017-10-30 17:41:50 +00:00
{
boost : : nowide : : ofstream c ;
c . open ( path , std : : ios : : out | std : : ios : : trunc ) ;
// Put a comment at the first line including the time stamp and Slic3r version.
c < < " # " < < Slic3r : : header_slic3r_generated ( ) < < std : : endl ;
// Export the print, filament and printer profiles.
2018-11-16 16:36:23 +00:00
2018-12-12 17:37:10 +00:00
for ( const PresetCollection * presets : {
( const PresetCollection * ) & this - > prints , ( const PresetCollection * ) & this - > filaments ,
( const PresetCollection * ) & this - > sla_prints , ( const PresetCollection * ) & this - > sla_materials ,
( const PresetCollection * ) & this - > printers } ) {
for ( const Preset & preset : ( * presets ) ( ) ) {
if ( preset . is_default | | preset . is_external | | ( preset . is_system & & ! export_system_settings ) )
2017-10-30 17:41:50 +00:00
// Only export the common presets, not external files or the default preset.
continue ;
2019-02-03 19:17:55 +00:00
c < < std : : endl < < " [ " < < presets - > section_name ( ) < < " : " < < preset . name < < " ] " < < std : : endl ;
2017-10-30 17:41:50 +00:00
for ( const std : : string & opt_key : preset . config . keys ( ) )
2019-06-26 11:26:49 +00:00
c < < opt_key < < " = " < < preset . config . opt_serialize ( opt_key ) < < std : : endl ;
2017-10-30 17:41:50 +00:00
}
}
// Export the names of the active presets.
2017-11-01 18:30:05 +00:00
c < < std : : endl < < " [presets] " < < std : : endl ;
2019-05-22 09:31:36 +00:00
c < < " print = " < < this - > prints . get_selected_preset_name ( ) < < std : : endl ;
c < < " sla_print = " < < this - > sla_prints . get_selected_preset_name ( ) < < std : : endl ;
c < < " sla_material = " < < this - > sla_materials . get_selected_preset_name ( ) < < std : : endl ;
c < < " printer = " < < this - > printers . get_selected_preset_name ( ) < < std : : endl ;
2017-10-30 17:41:50 +00:00
for ( size_t i = 0 ; i < this - > filament_presets . size ( ) ; + + i ) {
char suffix [ 64 ] ;
if ( i > 0 )
2019-06-10 16:30:54 +00:00
sprintf ( suffix , " _%d " , ( int ) i ) ;
2017-10-30 17:41:50 +00:00
else
suffix [ 0 ] = 0 ;
c < < " filament " < < suffix < < " = " < < this - > filament_presets [ i ] < < std : : endl ;
}
2017-11-01 18:30:05 +00:00
#if 0
2017-10-30 17:41:50 +00:00
// Export the following setting values from the provided setting repository.
static const char * settings_keys [ ] = { " autocenter " } ;
2017-11-01 18:30:05 +00:00
c < < " [settings] " < < std : : endl ;
2017-10-30 17:41:50 +00:00
for ( size_t i = 0 ; i < sizeof ( settings_keys ) / sizeof ( settings_keys [ 0 ] ) ; + + i )
c < < settings_keys [ i ] < < " = " < < settings . serialize ( settings_keys [ i ] ) < < std : : endl ;
2017-11-01 18:30:05 +00:00
# endif
2017-10-30 17:41:50 +00:00
c . close ( ) ;
}
// 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 PresetBundle : : set_filament_preset ( size_t idx , const std : : string & name )
{
2020-06-16 10:57:49 +00:00
if ( idx > = filament_presets . size ( ) )
2017-10-30 17:41:50 +00:00
filament_presets . resize ( idx + 1 , filaments . default_preset ( ) . name ) ;
filament_presets [ idx ] = Preset : : remove_suffix_modified ( name ) ;
}
void PresetBundle : : set_default_suppressed ( bool default_suppressed )
{
prints . set_default_suppressed ( default_suppressed ) ;
filaments . set_default_suppressed ( default_suppressed ) ;
2018-11-16 16:36:23 +00:00
sla_prints . set_default_suppressed ( default_suppressed ) ;
2018-08-09 07:25:23 +00:00
sla_materials . set_default_suppressed ( default_suppressed ) ;
2017-10-30 17:41:50 +00:00
printers . set_default_suppressed ( default_suppressed ) ;
}
} // namespace Slic3r