fix export_to_prusa for object & modifer settings that need the full config as reference

supermerill/SuperSlicer#1503
This commit is contained in:
supermerill 2021-08-24 00:45:51 +02:00
parent 55fdc665ca
commit 92f9b734e6
3 changed files with 125 additions and 119 deletions

View File

@ -2109,8 +2109,8 @@ namespace Slic3r {
bool _add_sla_support_points_file_to_archive(mz_zip_archive& archive, Model& model); bool _add_sla_support_points_file_to_archive(mz_zip_archive& archive, Model& model);
bool _add_sla_drain_holes_file_to_archive(mz_zip_archive& archive, Model& model); bool _add_sla_drain_holes_file_to_archive(mz_zip_archive& archive, Model& model);
bool _add_print_config_file_to_archive(mz_zip_archive& archive, const DynamicPrintConfig &config, const std::string &file_path); bool _add_print_config_file_to_archive(mz_zip_archive& archive, const DynamicPrintConfig &config, const std::string &file_path);
bool _add_model_config_file_to_archive(mz_zip_archive& archive, const Model& model, const IdToObjectDataMap &objects_data, const std::string &file_path); bool _add_model_config_file_to_archive(mz_zip_archive& archive, const Model& model, const DynamicPrintConfig& print_config, const IdToObjectDataMap &objects_data, const std::string &file_path);
bool _add_custom_gcode_per_print_z_file_to_archive(mz_zip_archive& archive, Model& model, const DynamicPrintConfig* config); bool _add_custom_gcode_per_print_z_file_to_archive(mz_zip_archive& archive, Model& model, const DynamicPrintConfig& config);
}; };
bool _3MF_Exporter::save_model_to_file(const std::string& filename, Model& model, const DynamicPrintConfig* config, bool fullpath_sources, const ThumbnailData* thumbnail_data) bool _3MF_Exporter::save_model_to_file(const std::string& filename, Model& model, const DynamicPrintConfig* config, bool fullpath_sources, const ThumbnailData* thumbnail_data)
@ -2211,7 +2211,7 @@ namespace Slic3r {
// Adds custom gcode per height file ("Metadata/Prusa_Slicer_custom_gcode_per_print_z.xml"). // Adds custom gcode per height file ("Metadata/Prusa_Slicer_custom_gcode_per_print_z.xml").
// All custom gcode per height of whole Model are stored here // All custom gcode per height of whole Model are stored here
if (!_add_custom_gcode_per_print_z_file_to_archive(archive, model, config)) if (!_add_custom_gcode_per_print_z_file_to_archive(archive, model, *config))
{ {
close_zip_writer(&archive); close_zip_writer(&archive);
boost::filesystem::remove(filename); boost::filesystem::remove(filename);
@ -2238,21 +2238,21 @@ namespace Slic3r {
// This file contains all the attributes of all ModelObjects and their ModelVolumes (names, parameter overrides). // This file contains all the attributes of all ModelObjects and their ModelVolumes (names, parameter overrides).
// As there is just a single Indexed Triangle Set data stored per ModelObject, offsets of volumes into their respective Indexed Triangle Set data // As there is just a single Indexed Triangle Set data stored per ModelObject, offsets of volumes into their respective Indexed Triangle Set data
// is stored here as well. // is stored here as well.
if (!_add_model_config_file_to_archive(archive, model, objects_data, MODEL_CONFIG_FILE)) if (!_add_model_config_file_to_archive(archive, model, *config, objects_data, MODEL_CONFIG_FILE))
{ {
close_zip_writer(&archive); close_zip_writer(&archive);
boost::filesystem::remove(filename); boost::filesystem::remove(filename);
return false; return false;
} }
// also add prusa // also add prusa
if (!_add_model_config_file_to_archive(archive, model, objects_data, MODEL_PRUSA_CONFIG_FILE)) if (!_add_model_config_file_to_archive(archive, model, *config, objects_data, MODEL_PRUSA_CONFIG_FILE))
{ {
close_zip_writer(&archive); close_zip_writer(&archive);
boost::filesystem::remove(filename); boost::filesystem::remove(filename);
return false; return false;
} }
// also superslicer for backward comp, just for some version from 2.3.56 // also superslicer for backward comp, just for some version from 2.3.56
if (!_add_model_config_file_to_archive(archive, model, objects_data, MODEL_SUPER_CONFIG_FILE)) if (!_add_model_config_file_to_archive(archive, model, *config, objects_data, MODEL_SUPER_CONFIG_FILE))
{ {
close_zip_writer(&archive); close_zip_writer(&archive);
boost::filesystem::remove(filename); boost::filesystem::remove(filename);
@ -2787,7 +2787,7 @@ namespace Slic3r {
return true; return true;
} }
bool _3MF_Exporter::_add_model_config_file_to_archive(mz_zip_archive& archive, const Model& model, const IdToObjectDataMap &objects_data, const std::string &file_path) bool _3MF_Exporter::_add_model_config_file_to_archive(mz_zip_archive& archive, const Model& model, const DynamicPrintConfig& print_config, const IdToObjectDataMap &objects_data, const std::string &file_path)
{ {
std::stringstream stream; std::stringstream stream;
// Store mesh transformation in full precision, as the volumes are stored transformed and they need to be transformed back // Store mesh transformation in full precision, as the volumes are stored transformed and they need to be transformed back
@ -2802,6 +2802,7 @@ namespace Slic3r {
const ModelObject* obj = obj_metadata.second.object; const ModelObject* obj = obj_metadata.second.object;
if (obj != nullptr) if (obj != nullptr)
{ {
DynamicPrintConfig obj_config_wparent; // part of the chain of config, used as reference to convert configs to prusa config
// Output of instances count added because of github #3435, currently not used by PrusaSlicer // Output of instances count added because of github #3435, currently not used by PrusaSlicer
stream << " <" << OBJECT_TAG << " " << ID_ATTR << "=\"" << obj_metadata.first << "\" " << INSTANCESCOUNT_ATTR << "=\"" << obj->instances.size() << "\">\n"; stream << " <" << OBJECT_TAG << " " << ID_ATTR << "=\"" << obj_metadata.first << "\" " << INSTANCESCOUNT_ATTR << "=\"" << obj->instances.size() << "\">\n";
@ -2812,10 +2813,13 @@ namespace Slic3r {
// stores object's config data // stores object's config data
if (file_path == MODEL_PRUSA_CONFIG_FILE) { if (file_path == MODEL_PRUSA_CONFIG_FILE) {
assert(obj->config.get().parent == nullptr);
obj_config_wparent = obj->config.get();
obj_config_wparent.parent = &print_config;
for (std::string key : obj->config.keys()) { for (std::string key : obj->config.keys()) {
// convert to prusa config // convert to prusa config
std::string value = obj->config.opt_serialize(key); std::string value = obj->config.opt_serialize(key);
obj->config.to_prusa(key, value); obj_config_wparent.to_prusa(key, value);
if (!key.empty()) if (!key.empty())
stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << OBJECT_TYPE << "\" " << KEY_ATTR << "=\"" << key << "\" " << VALUE_ATTR << "=\"" << value << "\"/>\n"; stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << OBJECT_TYPE << "\" " << KEY_ATTR << "=\"" << key << "\" " << VALUE_ATTR << "=\"" << value << "\"/>\n";
} }
@ -2884,10 +2888,13 @@ namespace Slic3r {
// stores volume's config data // stores volume's config data
if (file_path == MODEL_PRUSA_CONFIG_FILE) { if (file_path == MODEL_PRUSA_CONFIG_FILE) {
assert(volume->config.get().parent == nullptr);
DynamicPrintConfig copy_config = volume->config.get();
copy_config.parent = &obj_config_wparent;
for (std::string key : volume->config.keys()) { for (std::string key : volume->config.keys()) {
// convert to prusa config // convert to prusa config
std::string value = volume->config.opt_serialize(key); std::string value = volume->config.opt_serialize(key);
volume->config.to_prusa(key, value); copy_config.to_prusa(key, value);
if (!key.empty()) if (!key.empty())
stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << VOLUME_TYPE << "\" " << KEY_ATTR << "=\"" << key << "\" " << VALUE_ATTR << "=\"" << value << "\"/>\n"; stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << VOLUME_TYPE << "\" " << KEY_ATTR << "=\"" << key << "\" " << VALUE_ATTR << "=\"" << value << "\"/>\n";
} }
@ -2918,7 +2925,7 @@ namespace Slic3r {
return true; return true;
} }
bool _3MF_Exporter::_add_custom_gcode_per_print_z_file_to_archive( mz_zip_archive& archive, Model& model, const DynamicPrintConfig* config) bool _3MF_Exporter::_add_custom_gcode_per_print_z_file_to_archive( mz_zip_archive& archive, Model& model, const DynamicPrintConfig& config)
{ {
std::string out = ""; std::string out = "";
@ -2940,9 +2947,9 @@ bool _3MF_Exporter::_add_custom_gcode_per_print_z_file_to_archive( mz_zip_archiv
code_tree.put("<xmlattr>.extra" , code.extra ); code_tree.put("<xmlattr>.extra" , code.extra );
// add gcode field data for the old version of the PrusaSlicer // add gcode field data for the old version of the PrusaSlicer
std::string gcode = code.type == CustomGCode::ColorChange ? config->opt_string("color_change_gcode") : std::string gcode = code.type == CustomGCode::ColorChange ? config.opt_string("color_change_gcode") :
code.type == CustomGCode::PausePrint ? config->opt_string("pause_print_gcode") : code.type == CustomGCode::PausePrint ? config.opt_string("pause_print_gcode") :
code.type == CustomGCode::Template ? config->opt_string("template_custom_gcode") : code.type == CustomGCode::Template ? config.opt_string("template_custom_gcode") :
code.type == CustomGCode::ToolChange ? "tool_change" : code.extra; code.type == CustomGCode::ToolChange ? "tool_change" : code.extra;
code_tree.put("<xmlattr>.gcode" , gcode ); code_tree.put("<xmlattr>.gcode" , gcode );
} }

View File

@ -5497,101 +5497,123 @@ void PrintConfigDef::handle_legacy(t_config_option_key &opt_key, std::string &va
} }
} }
void PrintConfigDef::to_prusa(t_config_option_key& opt_key, std::string& value, const DynamicConfig& all_conf) { std::unordered_set<std::string> prusa_export_to_remove_keys = {
std::unordered_set<std::string> to_remove_keys = {
"thumbnails_color",
"thumbnails_custom_color",
"thumbnails_with_bed",
"thumbnails_with_support",
"allow_empty_layers", "allow_empty_layers",
"avoid_crossing_not_first_layer", "avoid_crossing_not_first_layer",
"top_fan_speed",
"over_bridge_flow_ratio",
"bridge_internal_fan_speed", "bridge_internal_fan_speed",
"bridge_overlap", "bridge_overlap",
"bridge_speed_internal", "bridge_speed_internal",
"brim_inside_holes", "bridged_infill_margin",
"brim_width_interior",
"brim_ears",
"brim_ears_detection_length", "brim_ears_detection_length",
"brim_ears_max_angle", "brim_ears_max_angle",
"brim_ears_pattern", "brim_ears_pattern",
"brim_ears",
"brim_inside_holes",
"brim_offset", "brim_offset",
"brim_width_interior",
"chamber_temperature", "chamber_temperature",
"complete_objects_one_skirt",
"complete_objects_one_brim", "complete_objects_one_brim",
"complete_objects_one_skirt",
"complete_objects_sort", "complete_objects_sort",
"solid_fill_pattern", "curve_smoothing_angle_concave",
"curve_smoothing_angle_convex",
"curve_smoothing_cutoff_dist",
"curve_smoothing_precision",
"enforce_full_fill_volume", "enforce_full_fill_volume",
"exact_last_layer_height",
"external_infill_margin", "external_infill_margin",
"bridged_infill_margin",
"external_perimeter_cut_corners", "external_perimeter_cut_corners",
"external_perimeter_extrusion_spacing",
"external_perimeter_fan_speed", "external_perimeter_fan_speed",
"external_perimeter_overlap", "external_perimeter_overlap",
"perimeter_overlap",
"perimeter_bonding",
"external_perimeters_vase",
"external_perimeters_nothole",
"external_perimeters_hole", "external_perimeters_hole",
"perimeter_loop", "external_perimeters_nothole",
"perimeter_loop_seam", "external_perimeters_vase",
"extra_perimeters_overhangs",
"extra_perimeters_odd_layers", "extra_perimeters_odd_layers",
"only_one_perimeter_top", "extra_perimeters_overhangs",
"only_one_perimeter_top_other_algo",
"extruder_temperature_offset",
"extruder_fan_offset", "extruder_fan_offset",
"print_extrusion_multiplier", "extruder_temperature_offset",
"extrusion_spacing",
"fan_kickstart",
"fan_percentage",
"fan_speedup_overhangs",
"fan_speedup_time",
"feature_gcode",
"filament_cooling_zone_pause",
"filament_dip_extraction_speed",
"filament_dip_insertion_speed",
"filament_enable_toolchange_part_fan",
"filament_enable_toolchange_temp",
"filament_max_speed", "filament_max_speed",
"filament_max_wipe_tower_speed", "filament_max_wipe_tower_speed",
"filament_enable_toolchange_temp",
"filament_use_fast_skinnydip",
"filament_enable_toolchange_part_fan",
"filament_toolchange_part_fan_speed",
"filament_use_skinnydip",
"filament_melt_zone_pause", "filament_melt_zone_pause",
"filament_cooling_zone_pause",
"filament_dip_insertion_speed",
"filament_dip_extraction_speed",
"filament_toolchange_temp",
"filament_skinnydip_distance",
"filament_shrink", "filament_shrink",
"filament_skinnydip_distance",
"filament_toolchange_part_fan_speed",
"filament_toolchange_temp",
"filament_use_fast_skinnydip",
"filament_use_skinnydip",
"filament_wipe_advanced_pigment",
"fill_angle_increment", "fill_angle_increment",
"fill_top_flow_ratio",
"fill_top_flow_ratio",
"first_layer_flow_ratio",
"fill_smooth_width",
"fill_smooth_distribution", "fill_smooth_distribution",
"fill_smooth_width",
"fill_top_flow_ratio",
"fill_top_flow_ratio",
"first_layer_extrusion_spacing",
"first_layer_flow_ratio",
"first_layer_infill_speed", "first_layer_infill_speed",
"first_layer_min_speed", "first_layer_min_speed",
"gap_fill", "first_layer_size_compensation_layers",
"gap_fill_infill",
"gap_fill_min_area", "gap_fill_min_area",
"gap_fill_overlap", "gap_fill_overlap",
"gap_fill_infill", "gap_fill",
"infill_dense", "hole_size_compensation",
"hole_size_threshold",
"hole_to_polyhole_threshold",
"hole_to_polyhole_twisted",
"hole_to_polyhole",
"infill_connection", "infill_connection",
"infill_dense_algo", "infill_dense_algo",
"feature_gcode", "infill_dense",
"exact_last_layer_height", "infill_extrusion_spacing",
"fan_speedup_time",
"fan_speedup_overhangs",
"fan_percentage",
"fan_kickstart",
"machine_max_acceleration_travel", "machine_max_acceleration_travel",
"max_speed_reduction", "max_speed_reduction",
"milling_after_z",
"milling_cutter",
"milling_diameter",
"milling_extra_size",
"milling_offset",
"milling_post_process",
"milling_speed",
"milling_toolchange_end_gcode",
"milling_toolchange_start_gcode",
"milling_z_lift",
"milling_z_offset",
"min_length", "min_length",
"min_width_top_surface", "min_width_top_surface",
"printhost_apikey", "model_precision",
"printhost_cafile", "no_perimeter_unsupported_algo",
"print_host", "only_one_perimeter_top_other_algo",
"only_one_perimeter_top",
"over_bridge_flow_ratio",
"overhangs_reverse_threshold",
"overhangs_reverse",
"overhangs_speed", "overhangs_speed",
"overhangs_width_speed", "overhangs_width_speed",
"overhangs_reverse", "perimeter_bonding",
"overhangs_reverse_threshold", "perimeter_extrusion_spacing",
"no_perimeter_unsupported_algo", "perimeter_loop_seam",
"support_material_solid_first_layer", "perimeter_loop",
"perimeter_overlap",
"perimeter_round_corners",
"print_extrusion_multiplier",
"print_host",
"print_retract_length", "print_retract_length",
"print_retract_lift",
"print_temperature",
"printhost_apikey",
"printhost_cafile",
"retract_lift_first_layer", "retract_lift_first_layer",
"retract_lift_top", "retract_lift_top",
"seam_angle_cost", "seam_angle_cost",
@ -5599,66 +5621,45 @@ void PrintConfigDef::to_prusa(t_config_option_key& opt_key, std::string& value,
"skirt_brim", "skirt_brim",
"skirt_distance_from_brim", "skirt_distance_from_brim",
"skirt_extrusion_width", "skirt_extrusion_width",
"small_perimeter_min_length",
"small_perimeter_max_length", "small_perimeter_max_length",
"curve_smoothing_angle_convex", "small_perimeter_min_length",
"curve_smoothing_angle_concave", "solid_fill_pattern",
"curve_smoothing_precision", "solid_infill_extrusion_spacing",
"curve_smoothing_cutoff_dist", "start_gcode_manual",
"model_precision",
"support_material_contact_distance_type",
"support_material_contact_distance_bottom", "support_material_contact_distance_bottom",
"support_material_contact_distance_type",
"support_material_interface_pattern", "support_material_interface_pattern",
"print_temperature", "support_material_solid_first_layer",
"print_retract_lift",
"thin_perimeters",
"thin_perimeters_all", "thin_perimeters_all",
"thin_perimeters",
"thin_walls_merge",
"thin_walls_min_width", "thin_walls_min_width",
"thin_walls_overlap", "thin_walls_overlap",
"thin_walls_merge",
"thin_walls_speed", "thin_walls_speed",
"thumbnails_color",
"thumbnails_custom_color",
"thumbnails_with_bed",
"thumbnails_with_support",
"time_estimation_compensation", "time_estimation_compensation",
"tool_name", "tool_name",
"wipe_advanced", "top_fan_speed",
"wipe_advanced_nozzle_melted_volume",
"filament_wipe_advanced_pigment",
"wipe_advanced_multiplier",
"wipe_advanced_algo",
"wipe_tower_brim",
"wipe_extra_perimeter",
"xy_inner_size_compensation",
"hole_size_compensation",
"hole_size_threshold",
"hole_to_polyhole",
"hole_to_polyhole_threshold",
"hole_to_polyhole_twisted",
"z_step",
"milling_cutter",
"milling_diameter",
"milling_offset",
"milling_z_offset",
"milling_z_lift",
"milling_toolchange_start_gcode",
"milling_toolchange_end_gcode",
"milling_post_process",
"milling_extra_size",
"milling_after_z",
"milling_speed",
"extrusion_spacing",
"first_layer_extrusion_spacing",
"perimeter_extrusion_spacing",
"external_perimeter_extrusion_spacing",
"infill_extrusion_spacing",
"solid_infill_extrusion_spacing",
"top_infill_extrusion_spacing", "top_infill_extrusion_spacing",
"start_gcode_manual",
"perimeter_round_corners",
"travel_speed_z",
"first_layer_size_compensation_layers",
"travel_acceleration", "travel_acceleration",
}; "travel_speed_z",
"wipe_advanced_algo",
"wipe_advanced_multiplier",
"wipe_advanced_nozzle_melted_volume",
"wipe_advanced",
"wipe_extra_perimeter",
"wipe_tower_brim",
"xy_inner_size_compensation",
"z_step",
};
void PrintConfigDef::to_prusa(t_config_option_key& opt_key, std::string& value, const DynamicConfig& all_conf) {
//looks if it's to be removed, or have to be transformed //looks if it's to be removed, or have to be transformed
if (to_remove_keys.find(opt_key) != to_remove_keys.end()) { if (prusa_export_to_remove_keys.find(opt_key) != prusa_export_to_remove_keys.end()) {
opt_key = ""; opt_key = "";
value = ""; value = "";
} else if (opt_key.find("_pattern") != std::string::npos) { } else if (opt_key.find("_pattern") != std::string::npos) {

View File

@ -1958,8 +1958,6 @@ public:
// Not thread safe! Should not be called from other than the main thread! // Not thread safe! Should not be called from other than the main thread!
void touch() { m_timestamp = ++ s_last_timestamp; } void touch() { m_timestamp = ++ s_last_timestamp; }
void to_prusa(t_config_option_key& opt_key, std::string& value) const
{ m_data.to_prusa(opt_key, value); }
private: private:
friend class cereal::access; friend class cereal::access;
template<class Archive> void serialize(Archive& ar) { ar(m_timestamp); ar(m_data); } template<class Archive> void serialize(Archive& ar) { ar(m_timestamp); ar(m_data); }