mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-11 02:57:39 +00: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:
@@ -679,7 +679,7 @@ std::string Preset::get_printer_type(PresetBundle *preset_bundle)
|
||||
vendor_name = vendor_profile.first;
|
||||
return vendor_model.model_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
@@ -1748,28 +1748,33 @@ void PresetCollection::update_after_user_presets_loaded()
|
||||
return;
|
||||
}
|
||||
|
||||
//BBS: validate_printers
|
||||
bool PresetCollection::validate_printers(const std::string &name, DynamicPrintConfig& config, std::string &inherit)
|
||||
//BBS: validate_preset
|
||||
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(original_name);
|
||||
bool found = it != m_presets.end() && it->name == original_name && (it->is_system || it->is_default);
|
||||
std::deque<Preset>::iterator it = this->find_preset_internal(preset_name);
|
||||
bool found = (it != m_presets.end()) && (it->name == preset_name) && (it->is_system || it->is_default);
|
||||
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);
|
||||
}
|
||||
if (!found) {
|
||||
if (!inherit.empty()) {
|
||||
it = this->find_preset_internal(inherit);
|
||||
found = it != m_presets.end() && it->name == inherit && (it->is_system || it->is_default);
|
||||
if (!inherit_name.empty()) {
|
||||
it = this->find_preset_internal(inherit_name);
|
||||
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 {
|
||||
//inherit is null , should not happen , just consider it as valid
|
||||
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;
|
||||
}
|
||||
@@ -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) {
|
||||
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.filament_id = filament_id;
|
||||
},
|
||||
|
||||
@@ -391,8 +391,8 @@ public:
|
||||
typedef std::function<void(Preset* preset, std::string sync_info)> SyncFunc;
|
||||
//BBS get m_presets begin
|
||||
Iterator lbegin() { return m_presets.begin(); }
|
||||
//BBS: validate_printers
|
||||
bool validate_printers(const std::string &name, DynamicPrintConfig& config, std::string &inherit);
|
||||
//BBS: validate_preset
|
||||
bool validate_preset(const std::string &name, std::string &inherit);
|
||||
|
||||
Iterator begin() { return m_presets.begin() + 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);
|
||||
// target file is opened
|
||||
if (MZ_FALSE == status) {
|
||||
if (MZ_FALSE == status) {
|
||||
BOOST_LOG_TRIVIAL(info) << "Failed to open target file: " << target_file_path;
|
||||
} else {
|
||||
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
|
||||
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:
|
||||
#if 0
|
||||
std::vector<std::string> inherits_values;
|
||||
PrinterTechnology printer_technology = Preset::printer_technology(config);
|
||||
size_t num_extruders = (printer_technology == ptFFF) ?
|
||||
std::min(config.option<ConfigOptionFloats>("nozzle_diameter" )->values.size(),
|
||||
config.option<ConfigOptionFloats>("filament_diameter")->values.size()) : 1;
|
||||
inherits_values.resize(num_extruders + 2, std::string());
|
||||
inherits_values = config.option<ConfigOptionStrings>("inherits_group", true)->values;
|
||||
bool validated = false;
|
||||
std::vector<std::string> inherits_values = config.option<ConfigOptionStrings>("inherits_group", true)->values;
|
||||
std::vector<std::string> filament_preset_name = config.option<ConfigOptionStrings>("filament_settings_id", true)->values;
|
||||
std::string printer_preset = config.option<ConfigOptionString>("printer_settings_id", true)->value;
|
||||
bool has_different_settings_to_system = config.option("different_settings_to_system")?true:false;
|
||||
std::vector<std::string> different_values;
|
||||
int ret = VALIDATE_PRESETS_SUCCESS;
|
||||
|
||||
std::string inherits;
|
||||
if (inherits_values.size() >= (num_extruders + 2))
|
||||
inherits = inherits_values[num_extruders + 1];
|
||||
if (has_different_settings_to_system)
|
||||
different_values = config.option<ConfigOptionStrings>("different_settings_to_system", true)->values;
|
||||
|
||||
return this->printers.validate_printers(name, config, inherits);
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
//PrinterTechnology printer_technology = Preset::printer_technology(config);
|
||||
size_t filament_count = config.option<ConfigOptionFloats>("filament_diameter")->values.size();
|
||||
inherits_values.resize(filament_count + 2, std::string());
|
||||
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)
|
||||
|
||||
@@ -12,6 +12,12 @@
|
||||
#define DEFAULT_USER_FOLDER_NAME "default"
|
||||
#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 {
|
||||
|
||||
// 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);
|
||||
|
||||
//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
|
||||
//the pointer should be freed by the caller
|
||||
@@ -183,7 +189,7 @@ public:
|
||||
//void export_current_configbundle(const std::string &path);
|
||||
//BBS: add a function to export system presets for cloud-slicer
|
||||
//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);
|
||||
|
||||
// Enable / disable the "- default -" preset.
|
||||
|
||||
Reference in New Issue
Block a user