Tech ENABLE_COPY_CUSTOM_BED_MODEL_AND_TEXTURE - 1st installment - Copies custom bed texture and model files to 'data_dir()\printer' folder, if needed, and updates the printer config accordingly

Fixed conflicts after rebase with master
This commit is contained in:
enricoturri1966 2022-01-12 11:29:38 +01:00
parent 78124689c5
commit e8753ee8cd
4 changed files with 46 additions and 2 deletions

View File

@ -1,7 +1,7 @@
#include <cassert>
#include "PresetBundle.hpp"
#include "libslic3r.h"
#include "PresetBundle.hpp"
#include "Utils.hpp"
#include "Model.hpp"
#include "format.hpp"
@ -453,6 +453,11 @@ void PresetBundle::save_changes_for_preset(const std::string& new_name, Preset::
presets.get_edited_preset().config.apply_only(presets.get_selected_preset().config, unselected_options);
}
#if ENABLE_COPY_CUSTOM_BED_MODEL_AND_TEXTURE
if (type == Preset::TYPE_PRINTER)
copy_bed_model_and_texture_if_needed(presets.get_edited_preset().config);
#endif // ENABLE_COPY_CUSTOM_BED_MODEL_AND_TEXTURE
// Save the preset into Slic3r::data_dir / presets / section_name / preset_name.ini
presets.save_current_preset(new_name);
// Mark the print & filament enabled if they are compatible with the currently selected preset.
@ -1860,4 +1865,32 @@ void PresetBundle::set_default_suppressed(bool default_suppressed)
printers.set_default_suppressed(default_suppressed);
}
#if ENABLE_COPY_CUSTOM_BED_MODEL_AND_TEXTURE
void copy_bed_model_and_texture_if_needed(DynamicPrintConfig& config)
{
const boost::filesystem::path user_dir = boost::filesystem::absolute(boost::filesystem::path(data_dir()) / "printer").make_preferred();
const boost::filesystem::path res_dir = boost::filesystem::absolute(boost::filesystem::path(resources_dir()) / "profiles").make_preferred();
auto do_copy = [&user_dir, &res_dir](ConfigOptionString* cfg, const std::string& type) {
if (cfg == nullptr || cfg->value.empty())
return;
const boost::filesystem::path src_dir = boost::filesystem::absolute(boost::filesystem::path(cfg->value)).make_preferred().parent_path();
if (src_dir != user_dir && src_dir.parent_path() != res_dir) {
const std::string dst_value = (user_dir / boost::filesystem::path(cfg->value).filename()).string();
std::string error;
if (copy_file_inner(cfg->value, dst_value, error) == SUCCESS)
cfg->value = dst_value;
else {
BOOST_LOG_TRIVIAL(error) << "Copying from " << cfg->value << " to " << dst_value << " failed. Unable to set custom bed " << type << ". [" << error << "]";
cfg->value = "";
}
}
};
do_copy(config.option<ConfigOptionString>("bed_custom_texture"), "texture");
do_copy(config.option<ConfigOptionString>("bed_custom_model"), "model");
}
#endif // ENABLE_COPY_CUSTOM_BED_MODEL_AND_TEXTURE
} // namespace Slic3r

View File

@ -178,6 +178,12 @@ private:
ENABLE_ENUM_BITMASK_OPERATORS(PresetBundle::LoadConfigBundleAttribute)
#if ENABLE_COPY_CUSTOM_BED_MODEL_AND_TEXTURE
// Copies bed texture and model files to 'data_dir()\printer' folder, if needed
// and updates the config accordingly
extern void copy_bed_model_and_texture_if_needed(DynamicPrintConfig& config);
#endif // ENABLE_COPY_CUSTOM_BED_MODEL_AND_TEXTURE
} // namespace Slic3r
#endif /* slic3r_PresetBundle_hpp_ */

View File

@ -81,6 +81,7 @@
#define ENABLE_USED_FILAMENT_POST_PROCESS (1 && ENABLE_2_5_0_ALPHA1)
// Enable gizmo grabbers to share common models
#define ENABLE_GIZMO_GRABBER_REFACTOR (1 && ENABLE_2_5_0_ALPHA1)
// Enable copy of custom bed model and texture
#define ENABLE_COPY_CUSTOM_BED_MODEL_AND_TEXTURE (1 && ENABLE_2_5_0_ALPHA1)
#endif // _prusaslicer_technologies_h_

View File

@ -2780,6 +2780,10 @@ bool ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese
page_diams->apply_custom_config(*custom_config);
page_temps->apply_custom_config(*custom_config);
#if ENABLE_COPY_CUSTOM_BED_MODEL_AND_TEXTURE
copy_bed_model_and_texture_if_needed(*custom_config);
#endif // ENABLE_COPY_CUSTOM_BED_MODEL_AND_TEXTURE
const std::string profile_name = page_custom->profile_name();
preset_bundle->load_config_from_wizard(profile_name, *custom_config);
}