mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-22 14:13:57 -06:00
ENH: preset: add logic to check the modified gcodes when loading 3mf
when the 3mf contains modified gcodes or self defined presets a popup window will be shown JIRA: STUDIO-4628 Change-Id: I975758132ba9d200255e7bf7d3a606fd609da5c8
This commit is contained in:
parent
32198fdafc
commit
6c2ad86415
5 changed files with 127 additions and 55 deletions
|
@ -679,7 +679,7 @@ std::string Preset::get_printer_type(PresetBundle *preset_bundle)
|
||||||
vendor_name = vendor_profile.first;
|
vendor_name = vendor_profile.first;
|
||||||
return vendor_model.model_id;
|
return vendor_model.model_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -1748,28 +1748,33 @@ void PresetCollection::update_after_user_presets_loaded()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//BBS: validate_printers
|
//BBS: validate_preset
|
||||||
bool PresetCollection::validate_printers(const std::string &name, DynamicPrintConfig& config, std::string &inherit)
|
bool PresetCollection::validate_preset(const std::string &preset_name, std::string &inherit_name)
|
||||||
{
|
{
|
||||||
std::string& original_name = config.opt_string("printer_settings_id", true);
|
std::deque<Preset>::iterator it = this->find_preset_internal(preset_name);
|
||||||
std::deque<Preset>::iterator it = this->find_preset_internal(original_name);
|
bool found = (it != m_presets.end()) && (it->name == preset_name) && (it->is_system || it->is_default);
|
||||||
bool found = it != m_presets.end() && it->name == original_name && (it->is_system || it->is_default);
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
it = this->find_preset_renamed(original_name);
|
it = this->find_preset_renamed(preset_name);
|
||||||
found = it != m_presets.end() && (it->is_system || it->is_default);
|
found = it != m_presets.end() && (it->is_system || it->is_default);
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
if (!inherit.empty()) {
|
if (!inherit_name.empty()) {
|
||||||
it = this->find_preset_internal(inherit);
|
it = this->find_preset_internal(inherit_name);
|
||||||
found = it != m_presets.end() && it->name == inherit && (it->is_system || it->is_default);
|
found = it != m_presets.end() && it->name == inherit_name && (it->is_system || it->is_default);
|
||||||
|
if (found)
|
||||||
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": preset_name %1%, inherit_name %2%, found inherit in list")%preset_name %inherit_name;
|
||||||
|
else
|
||||||
|
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": preset_name %1%, inherit_name %2%, can not found preset and inherit in list")%preset_name %inherit_name;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//inherit is null , should not happen , just consider it as valid
|
//inherit is null , should not happen , just consider it as valid
|
||||||
found = false;
|
found = false;
|
||||||
BOOST_LOG_TRIVIAL(warning) << boost::format(": name %1%, printer_settings %2%, no inherit, set to not found")%name %original_name;
|
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": preset_name %1%, no inherit, set to not found")%preset_name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BOOST_LOG_TRIVIAL(warning) << boost::format(": name %1%, printer_settings %2%, inherit %3%, found result %4%")%name %original_name % inherit % found;
|
else {
|
||||||
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": preset_name %1%, found in list")%preset_name;
|
||||||
|
}
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
@ -2152,7 +2157,7 @@ bool PresetCollection::clone_presets_for_filament(std::vector<Preset const *> co
|
||||||
{
|
{
|
||||||
return clone_presets(presets, failures, [filament_name, filament_id, vendor_name](Preset &preset, Preset::Type &type) {
|
return clone_presets(presets, failures, [filament_name, filament_id, vendor_name](Preset &preset, Preset::Type &type) {
|
||||||
preset.name = filament_name + " " + preset.name.substr(preset.name.find_last_of('@'));
|
preset.name = filament_name + " " + preset.name.substr(preset.name.find_last_of('@'));
|
||||||
if (type == Preset::TYPE_FILAMENT)
|
if (type == Preset::TYPE_FILAMENT)
|
||||||
preset.config.option<ConfigOptionStrings>("filament_vendor", true)->values[0] = vendor_name;
|
preset.config.option<ConfigOptionStrings>("filament_vendor", true)->values[0] = vendor_name;
|
||||||
preset.filament_id = filament_id;
|
preset.filament_id = filament_id;
|
||||||
},
|
},
|
||||||
|
|
|
@ -391,8 +391,8 @@ public:
|
||||||
typedef std::function<void(Preset* preset, std::string sync_info)> SyncFunc;
|
typedef std::function<void(Preset* preset, std::string sync_info)> SyncFunc;
|
||||||
//BBS get m_presets begin
|
//BBS get m_presets begin
|
||||||
Iterator lbegin() { return m_presets.begin(); }
|
Iterator lbegin() { return m_presets.begin(); }
|
||||||
//BBS: validate_printers
|
//BBS: validate_preset
|
||||||
bool validate_printers(const std::string &name, DynamicPrintConfig& config, std::string &inherit);
|
bool validate_preset(const std::string &name, std::string &inherit);
|
||||||
|
|
||||||
Iterator begin() { return m_presets.begin() + m_num_default_presets; }
|
Iterator begin() { return m_presets.begin() + m_num_default_presets; }
|
||||||
ConstIterator begin() const { return m_presets.cbegin() + m_num_default_presets; }
|
ConstIterator begin() const { return m_presets.cbegin() + m_num_default_presets; }
|
||||||
|
|
|
@ -707,7 +707,7 @@ PresetsConfigSubstitutions PresetBundle::import_presets(std::vector<std::string>
|
||||||
|
|
||||||
status = mz_zip_reader_extract_to_file(&zip_archive, i, target_file_path.c_str(), MZ_ZIP_FLAG_CASE_SENSITIVE);
|
status = mz_zip_reader_extract_to_file(&zip_archive, i, target_file_path.c_str(), MZ_ZIP_FLAG_CASE_SENSITIVE);
|
||||||
// target file is opened
|
// target file is opened
|
||||||
if (MZ_FALSE == status) {
|
if (MZ_FALSE == status) {
|
||||||
BOOST_LOG_TRIVIAL(info) << "Failed to open target file: " << target_file_path;
|
BOOST_LOG_TRIVIAL(info) << "Failed to open target file: " << target_file_path;
|
||||||
} else {
|
} else {
|
||||||
import_json_presets(substitutions, target_file_path, override_confirm, rule, overwrite, result);
|
import_json_presets(substitutions, target_file_path, override_confirm, rule, overwrite, result);
|
||||||
|
@ -937,26 +937,79 @@ void PresetBundle::update_system_preset_setting_ids(std::map<std::string, std::m
|
||||||
}
|
}
|
||||||
|
|
||||||
//BBS: validate printers from previous project
|
//BBS: validate printers from previous project
|
||||||
bool PresetBundle::validate_printers(const std::string &name, DynamicPrintConfig& config)
|
static std::set<std::string> gcodes_key_set = {"filament_end_gcode", "filament_start_gcode", "change_filament_gcode", "layer_change_gcode", "machine_end_gcode", "machine_pause_gcode", "machine_start_gcode", "template_custom_gcode"};
|
||||||
|
int PresetBundle::validate_presets(const std::string &file_name, DynamicPrintConfig& config, std::set<std::string>& different_gcodes)
|
||||||
{
|
{
|
||||||
// BBS TODO:
|
bool validated = false;
|
||||||
#if 0
|
std::vector<std::string> inherits_values = config.option<ConfigOptionStrings>("inherits_group", true)->values;
|
||||||
std::vector<std::string> inherits_values;
|
std::vector<std::string> filament_preset_name = config.option<ConfigOptionStrings>("filament_settings_id", true)->values;
|
||||||
PrinterTechnology printer_technology = Preset::printer_technology(config);
|
std::string printer_preset = config.option<ConfigOptionString>("printer_settings_id", true)->value;
|
||||||
size_t num_extruders = (printer_technology == ptFFF) ?
|
bool has_different_settings_to_system = config.option("different_settings_to_system")?true:false;
|
||||||
std::min(config.option<ConfigOptionFloats>("nozzle_diameter" )->values.size(),
|
std::vector<std::string> different_values;
|
||||||
config.option<ConfigOptionFloats>("filament_diameter")->values.size()) : 1;
|
int ret = VALIDATE_PRESETS_SUCCESS;
|
||||||
inherits_values.resize(num_extruders + 2, std::string());
|
|
||||||
inherits_values = config.option<ConfigOptionStrings>("inherits_group", true)->values;
|
|
||||||
|
|
||||||
std::string inherits;
|
if (has_different_settings_to_system)
|
||||||
if (inherits_values.size() >= (num_extruders + 2))
|
different_values = config.option<ConfigOptionStrings>("different_settings_to_system", true)->values;
|
||||||
inherits = inherits_values[num_extruders + 1];
|
|
||||||
|
|
||||||
return this->printers.validate_printers(name, config, inherits);
|
//PrinterTechnology printer_technology = Preset::printer_technology(config);
|
||||||
#else
|
size_t filament_count = config.option<ConfigOptionFloats>("filament_diameter")->values.size();
|
||||||
return true;
|
inherits_values.resize(filament_count + 2, std::string());
|
||||||
#endif
|
different_values.resize(filament_count + 2, std::string());
|
||||||
|
filament_preset_name.resize(filament_count, std::string());
|
||||||
|
|
||||||
|
std::string printer_inherits = inherits_values[filament_count + 1];
|
||||||
|
|
||||||
|
validated = this->printers.validate_preset(printer_preset, printer_inherits);
|
||||||
|
if (!validated) {
|
||||||
|
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(":file_name %1%, found the printer preset not inherit from system") % file_name;
|
||||||
|
different_gcodes.emplace(printer_preset);
|
||||||
|
ret = VALIDATE_PRESETS_PRINTER_NOT_FOUND;
|
||||||
|
}
|
||||||
|
for(unsigned int index = 0; index < filament_count; index ++)
|
||||||
|
{
|
||||||
|
std::string filament_preset = filament_preset_name[index];
|
||||||
|
std::string filament_inherits = inherits_values[index+1];
|
||||||
|
|
||||||
|
validated = this->filaments.validate_preset(filament_preset, filament_inherits);
|
||||||
|
if (!validated) {
|
||||||
|
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(":file_name %1%, found the filament %2% preset not inherit from system") % file_name %(index+1);
|
||||||
|
different_gcodes.emplace(filament_preset);
|
||||||
|
ret = VALIDATE_PRESETS_FILAMENTS_NOT_FOUND;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//self defined presets, return directly
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(":file_name %1%, found self defined presets, count %2%") %file_name %different_gcodes.size();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(unsigned int index = 1; index < filament_count+2; index ++)
|
||||||
|
{
|
||||||
|
std::string different_settingss = different_values[index];
|
||||||
|
|
||||||
|
std::vector<std::string> different_keys;
|
||||||
|
|
||||||
|
Slic3r::unescape_strings_cstyle(different_settingss, different_keys);
|
||||||
|
|
||||||
|
for (unsigned int j = 0; j < different_keys.size(); j++) {
|
||||||
|
if (gcodes_key_set.find(different_keys[j]) != gcodes_key_set.end()) {
|
||||||
|
different_gcodes.emplace(different_keys[j]);
|
||||||
|
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(":preset index %1%, different key %2%") %index %different_keys[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!different_gcodes.empty())
|
||||||
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(":file_name %1%, found different gcodes count %2%") %file_name %different_gcodes.size();
|
||||||
|
return VALIDATE_PRESETS_MODIFIED_GCODES;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(":file_name %1%, validate presets success!") % file_name;
|
||||||
|
|
||||||
|
return VALIDATE_PRESETS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PresetBundle::remove_users_preset(AppConfig &config, std::map<std::string, std::map<std::string, std::string>> *my_presets)
|
void PresetBundle::remove_users_preset(AppConfig &config, std::map<std::string, std::map<std::string, std::string>> *my_presets)
|
||||||
|
|
|
@ -12,6 +12,12 @@
|
||||||
#define DEFAULT_USER_FOLDER_NAME "default"
|
#define DEFAULT_USER_FOLDER_NAME "default"
|
||||||
#define BUNDLE_STRUCTURE_JSON_NAME "bundle_structure.json"
|
#define BUNDLE_STRUCTURE_JSON_NAME "bundle_structure.json"
|
||||||
|
|
||||||
|
#define VALIDATE_PRESETS_SUCCESS 0
|
||||||
|
#define VALIDATE_PRESETS_PRINTER_NOT_FOUND 1
|
||||||
|
#define VALIDATE_PRESETS_FILAMENTS_NOT_FOUND 2
|
||||||
|
#define VALIDATE_PRESETS_MODIFIED_GCODES 3
|
||||||
|
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
// Bundle of Print + Filament + Printer presets.
|
// Bundle of Print + Filament + Printer presets.
|
||||||
|
@ -64,7 +70,7 @@ public:
|
||||||
void update_system_preset_setting_ids(std::map<std::string, std::map<std::string, std::string>>& system_presets);
|
void update_system_preset_setting_ids(std::map<std::string, std::map<std::string, std::string>>& system_presets);
|
||||||
|
|
||||||
//BBS: add API to get previous machine
|
//BBS: add API to get previous machine
|
||||||
bool validate_printers(const std::string &name, DynamicPrintConfig& config);
|
int validate_presets(const std::string &file_name, DynamicPrintConfig& config, std::set<std::string>& different_gcodes);
|
||||||
|
|
||||||
//BBS: add function to generate differed preset for save
|
//BBS: add function to generate differed preset for save
|
||||||
//the pointer should be freed by the caller
|
//the pointer should be freed by the caller
|
||||||
|
@ -183,7 +189,7 @@ public:
|
||||||
//void export_current_configbundle(const std::string &path);
|
//void export_current_configbundle(const std::string &path);
|
||||||
//BBS: add a function to export system presets for cloud-slicer
|
//BBS: add a function to export system presets for cloud-slicer
|
||||||
//void export_system_configs(const std::string &path);
|
//void export_system_configs(const std::string &path);
|
||||||
std::vector<std::string> export_current_configs(const std::string &path, std::function<int(std::string const &)> override_confirm,
|
std::vector<std::string> export_current_configs(const std::string &path, std::function<int(std::string const &)> override_confirm,
|
||||||
bool include_modify, bool export_system_settings = false);
|
bool include_modify, bool export_system_settings = false);
|
||||||
|
|
||||||
// Enable / disable the "- default -" preset.
|
// Enable / disable the "- default -" preset.
|
||||||
|
|
|
@ -3491,22 +3491,30 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
|
||||||
Preset::normalize(config);
|
Preset::normalize(config);
|
||||||
PresetBundle *preset_bundle = wxGetApp().preset_bundle;
|
PresetBundle *preset_bundle = wxGetApp().preset_bundle;
|
||||||
// BBS: first validate the printer
|
// BBS: first validate the printer
|
||||||
// TODO: remove it after released""
|
// validate the system profiles
|
||||||
bool validated = preset_bundle->validate_printers(filename.string(), config);
|
std::set<std::string> modified_gcodes;
|
||||||
if (!validated) {
|
int validated = preset_bundle->validate_presets(filename.string(), config, modified_gcodes);
|
||||||
load_config = false;
|
if (validated == VALIDATE_PRESETS_MODIFIED_GCODES) {
|
||||||
load_old_project = true;
|
std::string warning_message = L("The 3mf has following modified G-codes in filament or printer presets:");
|
||||||
// select view to 3D
|
warning_message += "\n";
|
||||||
q->select_view_3D("3D");
|
for (std::set<std::string>::iterator it=modified_gcodes.begin(); it!=modified_gcodes.end(); ++it)
|
||||||
// select plate 0 as default
|
warning_message += "-" + *it + "\n";
|
||||||
q->select_plate(0);
|
warning_message += "\n";
|
||||||
show_info(q, _L("The 3mf is not compatible, load geometry data only!"), _L("Incompatible 3mf"));
|
warning_message += L("Please confirm that these modified G-codes are safe to prevent any damage to the machine!");
|
||||||
for (ModelObject *model_object : model.objects) {
|
show_info(q, warning_message, _L("Modified G-codes"));
|
||||||
model_object->config.reset();
|
}
|
||||||
// Is there any modifier or advanced config data?
|
else if ((validated == VALIDATE_PRESETS_PRINTER_NOT_FOUND) || (validated == VALIDATE_PRESETS_FILAMENTS_NOT_FOUND)) {
|
||||||
for (ModelVolume *model_volume : model_object->volumes) model_volume->config.reset();
|
std::string warning_message = L("The 3mf has following customized filament or printer presets:");
|
||||||
}
|
warning_message += "\n";
|
||||||
} else {
|
for (std::set<std::string>::iterator it=modified_gcodes.begin(); it!=modified_gcodes.end(); ++it)
|
||||||
|
warning_message += "-" + *it + "\n";
|
||||||
|
warning_message += "\n";
|
||||||
|
warning_message += L("Please confirm that the G-codes within these presets are safe to prevent any damage to the machine!");
|
||||||
|
show_info(q, warning_message, _L("Customized Preset"));
|
||||||
|
}
|
||||||
|
|
||||||
|
//always load config
|
||||||
|
{
|
||||||
preset_bundle->load_config_model(filename.string(), std::move(config), file_version);
|
preset_bundle->load_config_model(filename.string(), std::move(config), file_version);
|
||||||
|
|
||||||
ConfigOption* bed_type_opt = preset_bundle->project_config.option("curr_bed_type");
|
ConfigOption* bed_type_opt = preset_bundle->project_config.option("curr_bed_type");
|
||||||
|
@ -4182,9 +4190,9 @@ wxString Plater::priv::get_export_file(GUI::FileType file_type)
|
||||||
out_path += output_file.extension().string();
|
out_path += output_file.extension().string();
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
if (boost::filesystem::exists(into_u8(out_path), ec)) {
|
if (boost::filesystem::exists(into_u8(out_path), ec)) {
|
||||||
auto result = MessageBox(q->GetHandle(),
|
auto result = MessageBox(q->GetHandle(),
|
||||||
wxString::Format(_L("The file %s already exists\nDo you want to replace it?"), out_path),
|
wxString::Format(_L("The file %s already exists\nDo you want to replace it?"), out_path),
|
||||||
_L("Comfirm Save As"),
|
_L("Comfirm Save As"),
|
||||||
MB_YESNO | MB_ICONWARNING);
|
MB_YESNO | MB_ICONWARNING);
|
||||||
if (result != IDYES)
|
if (result != IDYES)
|
||||||
return wxEmptyString;
|
return wxEmptyString;
|
||||||
|
@ -8364,7 +8372,7 @@ void Plater::import_model_id(wxString download_info)
|
||||||
body,
|
body,
|
||||||
http_status,
|
http_status,
|
||||||
error);
|
error);
|
||||||
|
|
||||||
if (retry_count == max_retries) {
|
if (retry_count == max_retries) {
|
||||||
msg = _L("Importing to Bambu Studio failed. Please download the file and manually import it.");
|
msg = _L("Importing to Bambu Studio failed. Please download the file and manually import it.");
|
||||||
cont = false;
|
cont = false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue