From 9ddc1b44792d1c6735d0cf3aa9b28e587929ed5d Mon Sep 17 00:00:00 2001 From: David Kocik Date: Fri, 28 Jan 2022 15:01:19 +0100 Subject: [PATCH] common filament profile available for all printers --- src/libslic3r/Preset.cpp | 13 ++++++++++++ src/libslic3r/Preset.hpp | 1 + src/libslic3r/PresetBundle.cpp | 4 ++-- src/slic3r/GUI/ConfigWizard.cpp | 27 ++++++++++++++++++++++++- src/slic3r/GUI/ConfigWizard_private.hpp | 2 +- 5 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index bc293c1a37..a83fd378ed 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -146,6 +146,11 @@ VendorProfile VendorProfile::from_ini(const ptree &tree, const boost::filesystem res.changelog_url = changelog_url->second.data(); } + const auto common_profile = vendor_section.find("common_profile"); + if (common_profile != vendor_section.not_found()) { + res.common_profile = common_profile->second.data() == "1"; + } + if (! load_all) { return res; } @@ -336,6 +341,10 @@ std::string Preset::label() const bool is_compatible_with_print(const PresetWithVendorProfile &preset, const PresetWithVendorProfile &active_print, const PresetWithVendorProfile &active_printer) { + // custom filament profiles are aviable for all prints + if (preset.preset.type == Preset::Type::TYPE_FILAMENT && preset.vendor != nullptr && preset.vendor != active_printer.vendor && preset.vendor->common_profile) + return true; + if (preset.vendor != nullptr && preset.vendor != active_printer.vendor) // The current profile has a vendor assigned and it is different from the active print's vendor. return false; @@ -358,6 +367,10 @@ bool is_compatible_with_print(const PresetWithVendorProfile &preset, const Prese bool is_compatible_with_printer(const PresetWithVendorProfile &preset, const PresetWithVendorProfile &active_printer, const DynamicPrintConfig *extra_config) { + // custom filament profiles are aviable for all printers + if (preset.preset.type == Preset::Type::TYPE_FILAMENT && preset.vendor != nullptr && preset.vendor != active_printer.vendor && preset.vendor->common_profile) + return true; + if (preset.vendor != nullptr && preset.vendor != active_printer.vendor) // The current profile has a vendor assigned and it is different from the active print's vendor. return false; diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index 83723aa19b..bae04c7917 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -34,6 +34,7 @@ public: Semver config_version; std::string config_update_url; std::string changelog_url; + bool common_profile { false }; struct PrinterVariant { PrinterVariant() {} diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 874b775cd2..a6f01fda66 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -1263,10 +1263,10 @@ std::pair PresetBundle::load_configbundle( const VendorProfile *vendor_profile = nullptr; if (flags.has(LoadConfigBundleAttribute::LoadSystem) || flags.has(LoadConfigBundleAttribute::LoadVendorOnly)) { auto vp = VendorProfile::from_ini(tree, path); - if (vp.models.size() == 0) { + if (vp.models.size() == 0 && !vp.common_profile) { BOOST_LOG_TRIVIAL(error) << boost::format("Vendor bundle: `%1%`: No printer model defined.") % path; return std::make_pair(PresetsConfigSubstitutions{}, 0); - } else if (vp.num_variants() == 0) { + } else if (vp.num_variants() == 0 && !vp.common_profile) { BOOST_LOG_TRIVIAL(error) << boost::format("Vendor bundle: `%1%`: No printer variant defined") % path; return std::make_pair(PresetsConfigSubstitutions{}, 0); } diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp index dadf5d8ca3..734b26a376 100644 --- a/src/slic3r/GUI/ConfigWizard.cpp +++ b/src/slic3r/GUI/ConfigWizard.cpp @@ -2140,7 +2140,17 @@ void ConfigWizard::priv::update_materials(Technology technology) filaments.add_printer(&printer); } } - + // common filament bundle has no printers - filament would be never added + if(pair.second.preset_bundle->printers.begin() == pair.second.preset_bundle->printers.end()) + { + if (!filaments.containts(&filament)) { + filaments.push(&filament); + if (!filament.alias.empty()) + aliases_fff[filament.alias].insert(filament.name); + } + + } + } } // count compatible printers @@ -2420,6 +2430,21 @@ bool ConfigWizard::priv::check_and_install_missing_materials(Technology technolo has_material = true; break; } + + // find if preset.first is part of the common profile (up is searching if preset.first is part of printer vendor preset) + for (const auto& bp : bundles) { + if (!bp.second.preset_bundle->vendors.empty() && bp.second.preset_bundle->vendors.begin()->second.common_profile) { + const PresetCollection& common_materials = bp.second.preset_bundle->materials(technology); + const Preset* common_material = common_materials.find_preset(preset.first, false); + if(common_material) { + has_material = true; + break; + } + } + } + if (has_material) + break; + } } if (! has_material) diff --git a/src/slic3r/GUI/ConfigWizard_private.hpp b/src/slic3r/GUI/ConfigWizard_private.hpp index c822a2be81..02701e9516 100644 --- a/src/slic3r/GUI/ConfigWizard_private.hpp +++ b/src/slic3r/GUI/ConfigWizard_private.hpp @@ -136,7 +136,7 @@ struct Materials for (auto preset : presets) { const Preset& prst = *(preset); const Preset& prntr = *printer; - if ((printer == nullptr || is_compatible_with_printer(PresetWithVendorProfile(prst, prst.vendor), PresetWithVendorProfile(prntr, prntr.vendor))) && + if ((printer == nullptr || is_compatible_with_printer(PresetWithVendorProfile(prst, prst.vendor), PresetWithVendorProfile(prntr, prntr.vendor))) && (type.empty() || get_type(preset) == type) && (vendor.empty() || get_vendor(preset) == vendor)) {