mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-18 11:02:08 +00:00
ENH: add new config transfer logic for model,region,layer config
jira: NONE Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I995ebb45b992bba3879b71afd3fe21510335f24c (cherry picked from commit d45dacff9a97132c8999b1072c54c10bd0a2d12d) (cherry picked from commit 0b4e224aefbcdbc4b4ed88c3343948f68361a72b)
This commit is contained in:
@@ -8214,6 +8214,128 @@ int DynamicPrintConfig::update_values_from_single_to_multi_2(DynamicPrintConfig&
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int DynamicPrintConfig::update_values_from_multi_to_multi(const std::vector<std::string>& src_extruder_variants, const std::vector<std::string>& dst_extruder_variants, const DynamicPrintConfig& dst_config, const std::set<std::string>& key_sets)
|
||||||
|
{
|
||||||
|
const ConfigDef *config_def = this->def();
|
||||||
|
if (!config_def) {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(", Line %1%: can not find config define")%__LINE__;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto get_same_variant_indices = [](const std::vector<std::string>& extruder_variants, const std::string& variant){
|
||||||
|
std::vector<int> indices;
|
||||||
|
for(int i=0;i<extruder_variants.size();++i)
|
||||||
|
if(extruder_variants[i] == variant)
|
||||||
|
indices.push_back(i);
|
||||||
|
return indices;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<std::vector<int>> same_variant_indices;
|
||||||
|
for(size_t dst_idx =0 ;dst_idx < dst_extruder_variants.size(); ++dst_idx){
|
||||||
|
auto& dst_variant = dst_extruder_variants[dst_idx];
|
||||||
|
auto indices =get_same_variant_indices(src_extruder_variants, dst_variant);
|
||||||
|
same_variant_indices.emplace_back(indices);
|
||||||
|
}
|
||||||
|
|
||||||
|
t_config_option_keys keys = this->keys();
|
||||||
|
for(auto& key : keys){
|
||||||
|
if(key_sets.find(key) == key_sets.end())
|
||||||
|
continue;
|
||||||
|
const ConfigOptionDef* optdef = config_def->get(key);
|
||||||
|
if(!optdef){
|
||||||
|
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: can not find opt define for %2%")%__LINE__%key;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (optdef->type){
|
||||||
|
case coFloats:
|
||||||
|
{
|
||||||
|
ConfigOptionFloatsNullable* opt = this->option<ConfigOptionFloatsNullable>(key);
|
||||||
|
auto src_values = opt->values;
|
||||||
|
auto dst_values = dst_config.option<ConfigOptionFloatsNullable>(key) ->values;
|
||||||
|
for(size_t dst_idx =0; dst_idx < same_variant_indices.size(); ++dst_idx){
|
||||||
|
auto& indices = same_variant_indices[dst_idx];
|
||||||
|
if(indices.empty())
|
||||||
|
continue;
|
||||||
|
bool has_value = false;
|
||||||
|
double target_value = std::numeric_limits<double>::max();
|
||||||
|
for(auto idx : indices){
|
||||||
|
if(opt && !opt->is_nil(idx)){
|
||||||
|
has_value = true;
|
||||||
|
target_value = std::min(target_value, src_values[idx]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(has_value)
|
||||||
|
dst_values[dst_idx] = target_value;
|
||||||
|
}
|
||||||
|
opt->values = dst_values;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case coFloatsOrPercents:
|
||||||
|
{
|
||||||
|
ConfigOptionFloatsOrPercentsNullable* opt = this->option<ConfigOptionFloatsOrPercentsNullable>(key);
|
||||||
|
auto src_values = opt->values;
|
||||||
|
auto dst_values = dst_config.option<ConfigOptionFloatsOrPercentsNullable>(key) ->values;
|
||||||
|
for(size_t dst_idx =0; dst_idx < same_variant_indices.size(); ++dst_idx){
|
||||||
|
auto& indices = same_variant_indices[dst_idx];
|
||||||
|
if(indices.empty())
|
||||||
|
continue;
|
||||||
|
bool has_value = false;
|
||||||
|
FloatOrPercent target_value{9999.f, true};
|
||||||
|
for(auto idx : indices){
|
||||||
|
if(opt && !opt->is_nil(idx)){
|
||||||
|
has_value = true;
|
||||||
|
target_value = src_values[idx].value < target_value.value ? src_values[idx] : target_value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(has_value)
|
||||||
|
dst_values[dst_idx] = target_value;
|
||||||
|
}
|
||||||
|
opt->values = dst_values;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case coBools:
|
||||||
|
{
|
||||||
|
ConfigOptionBoolsNullable* opt = this->option<ConfigOptionBoolsNullable>(key);
|
||||||
|
auto src_values = opt->values;
|
||||||
|
auto dst_values = dst_config.option<ConfigOptionBoolsNullable>(key) ->values;
|
||||||
|
for(size_t dst_idx =0; dst_idx < same_variant_indices.size(); ++dst_idx){
|
||||||
|
auto indices = same_variant_indices[dst_idx];
|
||||||
|
if(indices.empty())
|
||||||
|
continue;
|
||||||
|
bool has_value = false;
|
||||||
|
bool target_value;
|
||||||
|
for(auto idx : indices){
|
||||||
|
if(opt && !opt->is_nil(idx)){
|
||||||
|
has_value = true;
|
||||||
|
target_value = src_values[idx];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(has_value)
|
||||||
|
dst_values[dst_idx] = target_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
opt->values = dst_values;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: unsupported option type for %2%")%__LINE__%key;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int DynamicPrintConfig::update_values_from_multi_to_single(DynamicPrintConfig& single_config, std::set<std::string>& key_set, std::string id_name, std::string variant_name, std::vector<std::string>& extruder_variants)
|
int DynamicPrintConfig::update_values_from_multi_to_single(DynamicPrintConfig& single_config, std::set<std::string>& key_set, std::string id_name, std::string variant_name, std::vector<std::string>& extruder_variants)
|
||||||
{
|
{
|
||||||
int extruder_count = extruder_variants.size();
|
int extruder_count = extruder_variants.size();
|
||||||
|
|||||||
@@ -628,6 +628,8 @@ public:
|
|||||||
int update_values_from_single_to_multi_2(DynamicPrintConfig& multi_config, std::set<std::string>& key_set);
|
int update_values_from_single_to_multi_2(DynamicPrintConfig& multi_config, std::set<std::string>& key_set);
|
||||||
int update_values_from_multi_to_single_2(std::set<std::string>& key_set);
|
int update_values_from_multi_to_single_2(std::set<std::string>& key_set);
|
||||||
|
|
||||||
|
int update_values_from_multi_to_multi(const std::vector<std::string>& src_extruder_variants, const std::vector<std::string>& dst_extruder_variants, const DynamicPrintConfig& dst_config, const std::set<std::string>& key_sets);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// query filament
|
// query filament
|
||||||
std::string get_filament_vendor() const;
|
std::string get_filament_vendor() const;
|
||||||
|
|||||||
@@ -4187,6 +4187,7 @@ void TabPrinter::build_fff()
|
|||||||
|
|
||||||
auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(m_config->option("nozzle_diameter"));
|
auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(m_config->option("nozzle_diameter"));
|
||||||
m_initial_extruders_count = m_extruders_count = nozzle_diameter->values.size();
|
m_initial_extruders_count = m_extruders_count = nozzle_diameter->values.size();
|
||||||
|
m_extruder_variant_list = m_config->option<ConfigOptionStrings>("printer_extruder_variant")->values;
|
||||||
// BBS
|
// BBS
|
||||||
//wxGetApp().obj_list()->update_objects_list_filament_column(m_initial_extruders_count);
|
//wxGetApp().obj_list()->update_objects_list_filament_column(m_initial_extruders_count);
|
||||||
|
|
||||||
@@ -4940,6 +4941,8 @@ void TabPrinter::on_preset_loaded()
|
|||||||
if (m_extruders_count != extruders_count)
|
if (m_extruders_count != extruders_count)
|
||||||
extruders_count_changed(extruders_count);
|
extruders_count_changed(extruders_count);
|
||||||
|
|
||||||
|
m_extruder_variant_list = m_config->option<ConfigOptionStrings>("printer_extruder_variant")->values;
|
||||||
|
|
||||||
if (base_name != m_base_preset_name) {
|
if (base_name != m_base_preset_name) {
|
||||||
bool use_default_nozzle_volume_type = true;
|
bool use_default_nozzle_volume_type = true;
|
||||||
m_base_preset_name = base_name;
|
m_base_preset_name = base_name;
|
||||||
@@ -5231,7 +5234,8 @@ void Tab::load_current_preset()
|
|||||||
{
|
{
|
||||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__<<boost::format(": enter, m_type %1%")%Preset::get_type_string(m_type);
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__<<boost::format(": enter, m_type %1%")%Preset::get_type_string(m_type);
|
||||||
const Preset& preset = m_presets->get_edited_preset();
|
const Preset& preset = m_presets->get_edited_preset();
|
||||||
int previous_extruder_count = 0;
|
std::vector<std::string> prev_variant_list;
|
||||||
|
int prev_extruder_count = 0;
|
||||||
|
|
||||||
update_btns_enabling();
|
update_btns_enabling();
|
||||||
|
|
||||||
@@ -5239,7 +5243,8 @@ void Tab::load_current_preset()
|
|||||||
if (m_type == Slic3r::Preset::TYPE_PRINTER) {
|
if (m_type == Slic3r::Preset::TYPE_PRINTER) {
|
||||||
// For the printer profile, generate the extruder pages.
|
// For the printer profile, generate the extruder pages.
|
||||||
if (preset.printer_technology() == ptFFF) {
|
if (preset.printer_technology() == ptFFF) {
|
||||||
previous_extruder_count = static_cast<TabPrinter*>(this)->m_extruders_count;
|
prev_variant_list = static_cast<TabPrinter*>(this)->m_extruder_variant_list;
|
||||||
|
prev_extruder_count = static_cast<TabPrinter*>(this)->m_extruders_count;
|
||||||
on_preset_loaded();
|
on_preset_loaded();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -5250,10 +5255,12 @@ void Tab::load_current_preset()
|
|||||||
update_extruder_variants();
|
update_extruder_variants();
|
||||||
if (m_type == Preset::TYPE_PRINT) {
|
if (m_type == Preset::TYPE_PRINT) {
|
||||||
if (auto tab = wxGetApp().plate_tab) {
|
if (auto tab = wxGetApp().plate_tab) {
|
||||||
|
tab->m_config->apply(*m_config);
|
||||||
tab->update_extruder_variants();
|
tab->update_extruder_variants();
|
||||||
tab->reload_config();
|
tab->reload_config();
|
||||||
}
|
}
|
||||||
for (auto tab : wxGetApp().model_tabs_list) {
|
for (auto tab : wxGetApp().model_tabs_list) {
|
||||||
|
tab->m_config->apply(*m_config);
|
||||||
tab->update_extruder_variants();
|
tab->update_extruder_variants();
|
||||||
tab->reload_config();
|
tab->reload_config();
|
||||||
}
|
}
|
||||||
@@ -5328,8 +5335,9 @@ void Tab::load_current_preset()
|
|||||||
}
|
}
|
||||||
//update the object config due to extruder count change
|
//update the object config due to extruder count change
|
||||||
DynamicPrintConfig& new_print_config = wxGetApp().preset_bundle->prints.get_edited_preset().config;
|
DynamicPrintConfig& new_print_config = wxGetApp().preset_bundle->prints.get_edited_preset().config;
|
||||||
|
std::vector<std::string> new_variant_list = wxGetApp().preset_bundle->printers.get_edited_preset().config.option<ConfigOptionStrings>("printer_extruder_variant")->values;
|
||||||
int new_extruder_count = wxGetApp().preset_bundle->get_printer_extruder_count();
|
int new_extruder_count = wxGetApp().preset_bundle->get_printer_extruder_count();
|
||||||
if (previous_extruder_count != new_extruder_count)
|
if (prev_extruder_count != new_extruder_count || prev_variant_list.size() != new_variant_list.size())
|
||||||
{
|
{
|
||||||
//process the object params here
|
//process the object params here
|
||||||
Model& model = wxGetApp().plater()->model();
|
Model& model = wxGetApp().plater()->model();
|
||||||
@@ -5338,20 +5346,14 @@ void Tab::load_current_preset()
|
|||||||
ModelObject* object = model.objects[i];
|
ModelObject* object = model.objects[i];
|
||||||
DynamicPrintConfig object_config = object->config.get();
|
DynamicPrintConfig object_config = object->config.get();
|
||||||
if (!object_config.empty()) {
|
if (!object_config.empty()) {
|
||||||
if (previous_extruder_count < new_extruder_count)
|
object_config.update_values_from_multi_to_multi(prev_variant_list,new_variant_list,new_print_config, print_options_with_variant);
|
||||||
object_config.update_values_from_single_to_multi_2(new_print_config, print_options_with_variant);
|
|
||||||
else
|
|
||||||
object_config.update_values_from_multi_to_single_2(print_options_with_variant);
|
|
||||||
object->config.assign_config(std::move(object_config));
|
object->config.assign_config(std::move(object_config));
|
||||||
}
|
}
|
||||||
for (ModelVolume* v : object->volumes) {
|
for (ModelVolume* v : object->volumes) {
|
||||||
if (v->is_model_part() || v->is_modifier()) {
|
if (v->is_model_part() || v->is_modifier()) {
|
||||||
DynamicPrintConfig volume_config = v->config.get();
|
DynamicPrintConfig volume_config = v->config.get();
|
||||||
if (!volume_config.empty()) {
|
if (!volume_config.empty()) {
|
||||||
if (previous_extruder_count < new_extruder_count)
|
volume_config.update_values_from_multi_to_multi(prev_variant_list,new_variant_list,new_print_config, print_options_with_variant);
|
||||||
volume_config.update_values_from_single_to_multi_2(new_print_config, print_options_with_variant);
|
|
||||||
else
|
|
||||||
volume_config.update_values_from_multi_to_single_2(print_options_with_variant);
|
|
||||||
v->config.assign_config(std::move(volume_config));
|
v->config.assign_config(std::move(volume_config));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5361,11 +5363,8 @@ void Tab::load_current_preset()
|
|||||||
ModelConfig& layer_model_config = layer_config_it.second;
|
ModelConfig& layer_model_config = layer_config_it.second;
|
||||||
DynamicPrintConfig layer_config = layer_model_config.get();
|
DynamicPrintConfig layer_config = layer_model_config.get();
|
||||||
if (!layer_config.empty()) {
|
if (!layer_config.empty()) {
|
||||||
if (previous_extruder_count < new_extruder_count)
|
layer_config.update_values_from_multi_to_multi(prev_variant_list,new_variant_list,new_print_config, print_options_with_variant);
|
||||||
layer_config.update_values_from_single_to_multi_2(new_print_config, print_options_with_variant);
|
layer_model_config.assign_config(std::move(layer_config));
|
||||||
else
|
|
||||||
layer_config.update_values_from_multi_to_single_2(print_options_with_variant);
|
|
||||||
layer_model_config.assign_config(std::move(layer_config));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -610,6 +610,7 @@ public:
|
|||||||
size_t m_initial_extruders_count;
|
size_t m_initial_extruders_count;
|
||||||
size_t m_sys_extruders_count;
|
size_t m_sys_extruders_count;
|
||||||
size_t m_cache_extruder_count = 0;
|
size_t m_cache_extruder_count = 0;
|
||||||
|
std::vector<std::string> m_extruder_variant_list;
|
||||||
std::string m_base_preset_name;
|
std::string m_base_preset_name;
|
||||||
|
|
||||||
PrinterTechnology m_printer_technology = ptFFF;
|
PrinterTechnology m_printer_technology = ptFFF;
|
||||||
|
|||||||
Reference in New Issue
Block a user